2019-01-02 04:24:12 -06:00
|
|
|
/////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// pgAdmin 4 - PostgreSQL Tools
|
|
|
|
//
|
2022-01-04 02:24:25 -06:00
|
|
|
// Copyright (C) 2013 - 2022, The pgAdmin Development Team
|
2019-01-02 04:24:12 -06:00
|
|
|
// This software is released under the PostgreSQL Licence
|
|
|
|
//
|
|
|
|
//////////////////////////////////////////////////////////////
|
|
|
|
|
2021-06-29 04:03:36 -05:00
|
|
|
import { getNodeListById } from '../../../../static/js/node_ajax';
|
|
|
|
import ServerSchema from './server.ui';
|
2021-12-02 04:35:52 -06:00
|
|
|
import Notify from '../../../../../static/js/helpers/Notifier';
|
2022-08-05 03:35:53 -05:00
|
|
|
import { showServerPassword, showChangeServerPassword, showNamedRestorePoint } from '../../../../../static/js/Dialogs/index';
|
2022-09-08 04:46:48 -05:00
|
|
|
import _ from 'lodash';
|
2021-06-29 04:03:36 -05:00
|
|
|
|
2017-06-12 01:31:22 -05:00
|
|
|
define('pgadmin.node.server', [
|
2022-09-08 04:46:48 -05:00
|
|
|
'sources/gettext', 'sources/url_for', 'jquery',
|
2019-10-10 01:35:28 -05:00
|
|
|
'sources/pgadmin', 'pgadmin.browser',
|
2021-06-29 04:03:36 -05:00
|
|
|
'pgadmin.user_management.current_user',
|
2021-05-03 05:40:45 -05:00
|
|
|
'pgadmin.authenticate.kerberos',
|
2018-03-13 13:47:32 -05:00
|
|
|
'pgadmin.browser.server.privilege',
|
2017-06-22 05:26:45 -05:00
|
|
|
], function(
|
2022-09-08 04:46:48 -05:00
|
|
|
gettext, url_for, $, pgAdmin, pgBrowser,
|
2022-07-11 03:09:09 -05:00
|
|
|
current_user, Kerberos,
|
2017-06-22 05:26:45 -05:00
|
|
|
) {
|
2015-06-30 00:51:55 -05:00
|
|
|
|
|
|
|
if (!pgBrowser.Nodes['server']) {
|
2018-01-12 01:29:51 -06:00
|
|
|
pgBrowser.SecLabelModel = pgBrowser.Node.Model.extend({
|
2016-05-29 04:49:34 -05:00
|
|
|
defaults: {
|
|
|
|
provider: undefined,
|
2018-01-12 01:29:51 -06:00
|
|
|
label: undefined,
|
2016-05-29 04:49:34 -05:00
|
|
|
},
|
|
|
|
schema: [{
|
2017-06-07 05:23:02 -05:00
|
|
|
id: 'provider', label: gettext('Provider'),
|
2016-05-29 04:49:34 -05:00
|
|
|
type: 'text', editable: true,
|
2018-01-12 01:29:51 -06:00
|
|
|
cellHeaderClasses:'width_percent_50',
|
2016-05-29 04:49:34 -05:00
|
|
|
},{
|
2019-03-05 08:08:16 -06:00
|
|
|
id: 'label', label: gettext('Security label'),
|
2016-05-29 04:49:34 -05:00
|
|
|
type: 'text', editable: true,
|
2018-01-12 01:29:51 -06:00
|
|
|
cellHeaderClasses:'override_label_class_font_size',
|
2016-05-29 04:49:34 -05:00
|
|
|
}],
|
|
|
|
validate: function() {
|
2016-06-06 07:37:12 -05:00
|
|
|
this.errorModel.clear();
|
|
|
|
if (_.isUndefined(this.get('label')) ||
|
|
|
|
_.isNull(this.get('label')) ||
|
2018-01-12 01:29:51 -06:00
|
|
|
String(this.get('label')).replace(/^\s+|\s+$/g, '') == '') {
|
2022-09-08 07:38:58 -05:00
|
|
|
let errmsg = gettext('Security label must be specified.');
|
2018-01-12 01:29:51 -06:00
|
|
|
this.errorModel.set('label', errmsg);
|
|
|
|
return errmsg;
|
2016-06-06 07:37:12 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
2018-01-12 01:29:51 -06:00
|
|
|
},
|
2016-05-29 04:49:34 -05:00
|
|
|
});
|
|
|
|
|
2015-06-30 00:51:55 -05:00
|
|
|
pgAdmin.Browser.Nodes['server'] = pgAdmin.Browser.Node.extend({
|
2017-07-27 06:55:07 -05:00
|
|
|
parent_type: 'server_group',
|
2015-06-30 00:51:55 -05:00
|
|
|
type: 'server',
|
2017-06-12 01:31:22 -05:00
|
|
|
dialogHelp: url_for('help.static', {'filename': 'server_dialog.html'}),
|
2017-06-07 05:23:02 -05:00
|
|
|
label: gettext('Server'),
|
2020-09-03 02:29:28 -05:00
|
|
|
canDrop: function(node){
|
2022-09-08 07:38:58 -05:00
|
|
|
let serverOwner = node.user_id;
|
2020-09-24 00:28:30 -05:00
|
|
|
if (serverOwner != current_user.id && !_.isUndefined(serverOwner))
|
2020-09-03 02:29:28 -05:00
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
},
|
2019-12-03 00:22:02 -06:00
|
|
|
dropAsRemove: true,
|
|
|
|
dropPriority: 5,
|
2016-04-14 06:15:32 -05:00
|
|
|
hasStatistics: true,
|
|
|
|
hasCollectiveStatistics: true,
|
2016-08-29 09:36:48 -05:00
|
|
|
can_expand: function(d) {
|
|
|
|
return d && d.connected;
|
|
|
|
},
|
2015-06-30 00:51:55 -05:00
|
|
|
Init: function() {
|
|
|
|
/* Avoid multiple registration of same menus */
|
|
|
|
if (this.initialized)
|
|
|
|
return;
|
|
|
|
|
|
|
|
this.initialized = true;
|
|
|
|
|
|
|
|
pgBrowser.add_menus([{
|
2017-07-27 06:55:07 -05:00
|
|
|
name: 'create_server_on_sg', node: 'server_group', module: this,
|
2015-06-30 00:51:55 -05:00
|
|
|
applies: ['object', 'context'], callback: 'show_obj_properties',
|
2022-02-14 00:43:48 -06:00
|
|
|
category: 'register', priority: 1, label: gettext('Server...'),
|
|
|
|
data: {action: 'create'}, icon: 'wcTabIcon icon-server',
|
|
|
|
enable: 'canCreate',
|
2016-05-11 10:13:04 -05:00
|
|
|
},{
|
2015-06-30 00:51:55 -05:00
|
|
|
name: 'create_server', node: 'server', module: this,
|
|
|
|
applies: ['object', 'context'], callback: 'show_obj_properties',
|
2022-02-14 00:43:48 -06:00
|
|
|
category: 'register', priority: 3, label: gettext('Server...'),
|
|
|
|
data: {action: 'create'}, icon: 'wcTabIcon icon-server',
|
|
|
|
enable: 'canCreate',
|
2015-10-20 02:03:18 -05:00
|
|
|
},{
|
|
|
|
name: 'connect_server', node: 'server', module: this,
|
|
|
|
applies: ['object', 'context'], callback: 'connect_server',
|
2017-06-07 05:23:02 -05:00
|
|
|
category: 'connect', priority: 4, label: gettext('Connect Server'),
|
2021-02-03 00:45:37 -06:00
|
|
|
icon: 'fa fa-link', enable : 'is_not_connected',data: {
|
2022-02-07 04:42:30 -06:00
|
|
|
data_disabled: gettext('Database server is already connected.'),
|
2021-02-03 00:45:37 -06:00
|
|
|
},
|
2016-05-11 10:13:04 -05:00
|
|
|
},{
|
2015-10-20 02:03:18 -05:00
|
|
|
name: 'disconnect_server', node: 'server', module: this,
|
|
|
|
applies: ['object', 'context'], callback: 'disconnect_server',
|
2022-02-07 04:42:30 -06:00
|
|
|
category: 'drop', priority: 5, label: gettext('Disconnect from server'),
|
2021-02-03 00:45:37 -06:00
|
|
|
icon: 'fa fa-unlink', enable : 'is_connected',data: {
|
2022-02-07 04:42:30 -06:00
|
|
|
data_disabled: gettext('Database server is already disconnected.'),
|
2021-02-03 00:45:37 -06:00
|
|
|
},
|
2021-05-25 09:42:57 -05:00
|
|
|
},
|
|
|
|
{
|
2016-05-06 09:08:22 -05:00
|
|
|
name: 'reload_configuration', node: 'server', module: this,
|
|
|
|
applies: ['tools', 'context'], callback: 'reload_configuration',
|
2021-12-16 06:59:44 -06:00
|
|
|
category: 'reload', priority: 10, label: gettext('Reload Configuration'),
|
2021-02-02 03:17:58 -06:00
|
|
|
icon: 'fa fa-redo-alt', enable : 'enable_reload_config',data: {
|
2021-02-03 00:45:37 -06:00
|
|
|
data_disabled: gettext('Please select a server from the browser tree to reload the configuration files.'),
|
2021-02-02 03:17:58 -06:00
|
|
|
},
|
2016-05-11 10:13:04 -05:00
|
|
|
},{
|
|
|
|
name: 'restore_point', node: 'server', module: this,
|
|
|
|
applies: ['tools', 'context'], callback: 'restore_point',
|
2021-12-16 06:59:44 -06:00
|
|
|
category: 'restore', priority: 7, label: gettext('Add Named Restore Point...'),
|
2021-02-02 03:17:58 -06:00
|
|
|
icon: 'fa fa-anchor', enable : 'is_applicable',data: {
|
2021-02-03 00:45:37 -06:00
|
|
|
data_disabled: gettext('Please select any server from the browser tree to Add Named Restore Point.'),
|
2021-02-02 03:17:58 -06:00
|
|
|
},
|
2016-05-13 02:51:20 -05:00
|
|
|
},{
|
|
|
|
name: 'change_password', node: 'server', module: this,
|
2018-08-03 06:11:01 -05:00
|
|
|
applies: ['object'], callback: 'change_password',
|
|
|
|
label: gettext('Change Password...'), priority: 10,
|
2021-02-03 00:45:37 -06:00
|
|
|
icon: 'fa fa-lock', enable : 'is_connected',data: {
|
2021-06-24 00:45:50 -05:00
|
|
|
data_disabled: gettext('Please connect server to enable change password.'),
|
2021-02-03 00:45:37 -06:00
|
|
|
},
|
2016-05-13 15:09:39 -05:00
|
|
|
},{
|
|
|
|
name: 'wal_replay_pause', node: 'server', module: this,
|
|
|
|
applies: ['tools', 'context'], callback: 'pause_wal_replay',
|
2021-12-16 06:59:44 -06:00
|
|
|
category: 'wal_replay_pause', priority: 8, label: gettext('Pause Replay of WAL'),
|
2021-02-02 03:17:58 -06:00
|
|
|
icon: 'fa fa-pause-circle', enable : 'wal_pause_enabled',data: {
|
2021-02-03 00:45:37 -06:00
|
|
|
data_disabled: gettext('Please select a connected database as a Super user and run in Recovery mode to Pause Replay of WAL.'),
|
2021-02-02 03:17:58 -06:00
|
|
|
},
|
2016-05-13 15:09:39 -05:00
|
|
|
},{
|
|
|
|
name: 'wal_replay_resume', node: 'server', module: this,
|
|
|
|
applies: ['tools', 'context'], callback: 'resume_wal_replay',
|
2021-12-16 06:59:44 -06:00
|
|
|
category: 'wal_replay_resume', priority: 9, label: gettext('Resume Replay of WAL'),
|
2021-02-02 03:17:58 -06:00
|
|
|
icon: 'fa fa-play-circle', enable : 'wal_resume_enabled',data: {
|
2021-02-03 00:45:37 -06:00
|
|
|
data_disabled: gettext('Please select a connected database as a Super user and run in Recovery mode to Resume Replay of WAL.'),
|
2021-02-02 03:17:58 -06:00
|
|
|
},
|
2018-07-27 04:06:42 -05:00
|
|
|
},{
|
2018-08-03 06:11:01 -05:00
|
|
|
name: 'clear_saved_password', node: 'server', module: this,
|
|
|
|
applies: ['object', 'context'], callback: 'clear_saved_password',
|
|
|
|
label: gettext('Clear Saved Password'), icon: 'fa fa-eraser',
|
|
|
|
priority: 11,
|
2018-07-27 04:06:42 -05:00
|
|
|
enable: function(node) {
|
|
|
|
if (node && node._type === 'server' &&
|
2018-08-03 06:11:01 -05:00
|
|
|
node.is_password_saved) {
|
2018-07-27 04:06:42 -05:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
},
|
2018-08-06 05:26:46 -05:00
|
|
|
},{
|
|
|
|
name: 'clear_sshtunnel_password', node: 'server', module: this,
|
|
|
|
applies: ['object', 'context'], callback: 'clear_sshtunnel_password',
|
|
|
|
label: gettext('Clear SSH Tunnel Password'), icon: 'fa fa-eraser',
|
|
|
|
priority: 12,
|
|
|
|
enable: function(node) {
|
|
|
|
if (node && node._type === 'server' &&
|
|
|
|
node.is_tunnel_password_saved) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
},
|
2021-02-02 03:17:58 -06:00
|
|
|
data: {
|
2021-02-03 00:45:37 -06:00
|
|
|
data_disabled: gettext('SSH Tunnel password is not saved for selected server.'),
|
2021-02-02 03:17:58 -06:00
|
|
|
},
|
2018-01-12 01:29:51 -06:00
|
|
|
}]);
|
2016-03-15 08:30:58 -05:00
|
|
|
|
2016-08-29 01:22:50 -05:00
|
|
|
_.bindAll(this, 'connection_lost');
|
|
|
|
pgBrowser.Events.on(
|
|
|
|
'pgadmin:server:connection:lost', this.connection_lost
|
|
|
|
);
|
2015-06-30 00:51:55 -05:00
|
|
|
},
|
2015-10-20 02:03:18 -05:00
|
|
|
is_not_connected: function(node) {
|
|
|
|
return (node && node.connected != true);
|
|
|
|
},
|
2020-09-03 02:29:28 -05:00
|
|
|
canCreate: function(node){
|
2022-09-08 07:38:58 -05:00
|
|
|
let serverOwner = node.user_id;
|
2020-09-03 02:29:28 -05:00
|
|
|
if (serverOwner == current_user.id || _.isUndefined(serverOwner))
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
|
|
|
|
},
|
2015-10-20 02:03:18 -05:00
|
|
|
is_connected: function(node) {
|
|
|
|
return (node && node.connected == true);
|
|
|
|
},
|
2016-05-09 12:52:35 -05:00
|
|
|
enable_reload_config: function(node) {
|
2016-05-11 10:13:04 -05:00
|
|
|
// Must be connected & is Super user
|
2018-01-12 01:29:51 -06:00
|
|
|
if (node && node._type == 'server' &&
|
|
|
|
node.connected && node.user.is_superuser) {
|
|
|
|
return true;
|
2016-05-11 10:13:04 -05:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
is_applicable: function(node) {
|
|
|
|
// Must be connected & super user & not in recovery mode
|
2018-01-12 01:29:51 -06:00
|
|
|
if (node && node._type == 'server' &&
|
|
|
|
node.connected && node.user.is_superuser
|
2016-05-11 10:13:04 -05:00
|
|
|
&& node.in_recovery == false) {
|
2018-01-12 01:29:51 -06:00
|
|
|
return true;
|
2016-05-09 12:52:35 -05:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
},
|
2016-05-13 15:09:39 -05:00
|
|
|
wal_pause_enabled: function(node) {
|
|
|
|
// Must be connected & is Super user & in Recovery mode
|
2018-01-12 01:29:51 -06:00
|
|
|
if (node && node._type == 'server' &&
|
|
|
|
node.connected && node.user.is_superuser
|
2016-05-13 15:09:39 -05:00
|
|
|
&& node.in_recovery == true
|
|
|
|
&& node.wal_pause == false) {
|
2018-01-12 01:29:51 -06:00
|
|
|
return true;
|
2016-05-13 15:09:39 -05:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
wal_resume_enabled: function(node) {
|
|
|
|
// Must be connected & is Super user & in Recovery mode
|
2018-01-12 01:29:51 -06:00
|
|
|
if (node && node._type == 'server' &&
|
|
|
|
node.connected && node.user.is_superuser
|
2016-05-13 15:09:39 -05:00
|
|
|
&& node.in_recovery == true
|
|
|
|
&& node.wal_pause == true) {
|
2018-01-12 01:29:51 -06:00
|
|
|
return true;
|
2016-05-13 15:09:39 -05:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
},
|
2015-06-30 00:51:55 -05:00
|
|
|
callbacks: {
|
2015-10-20 02:03:18 -05:00
|
|
|
/* Connect the server */
|
|
|
|
connect_server: function(args){
|
2022-09-08 07:38:58 -05:00
|
|
|
let input = args || {},
|
2016-05-10 07:46:08 -05:00
|
|
|
obj = this,
|
|
|
|
t = pgBrowser.tree,
|
|
|
|
i = input.item || t.selected(),
|
2021-09-27 06:14:26 -05:00
|
|
|
d = i ? t.itemData(i) : undefined;
|
2015-10-20 02:03:18 -05:00
|
|
|
|
2020-07-30 03:34:22 -05:00
|
|
|
if (d) {
|
|
|
|
connect_to_server(obj, d, t, i, false);
|
|
|
|
}
|
2015-10-20 02:03:18 -05:00
|
|
|
return false;
|
|
|
|
},
|
|
|
|
/* Disconnect the server */
|
2016-08-29 01:22:50 -05:00
|
|
|
disconnect_server: function(args, notify) {
|
2022-09-08 07:38:58 -05:00
|
|
|
let input = args || {},
|
2016-05-10 07:46:08 -05:00
|
|
|
obj = this,
|
|
|
|
t = pgBrowser.tree,
|
|
|
|
i = 'item' in input ? input.item : t.selected(),
|
2021-09-27 06:14:26 -05:00
|
|
|
d = i ? t.itemData(i) : undefined;
|
2015-10-20 02:03:18 -05:00
|
|
|
|
2020-07-30 03:34:22 -05:00
|
|
|
if (d) {
|
|
|
|
notify = notify || _.isUndefined(notify) || _.isNull(notify);
|
2016-08-29 01:22:50 -05:00
|
|
|
|
2022-09-08 07:38:58 -05:00
|
|
|
let disconnect = function() {
|
2020-07-30 03:34:22 -05:00
|
|
|
$.ajax({
|
|
|
|
url: obj.generate_url(i, 'connect', d, true),
|
|
|
|
type:'DELETE',
|
|
|
|
})
|
|
|
|
.done(function(res) {
|
|
|
|
if (res.success == 1) {
|
2021-12-02 04:35:52 -06:00
|
|
|
Notify.success(res.info);
|
2020-07-30 03:34:22 -05:00
|
|
|
d = t.itemData(i);
|
|
|
|
t.removeIcon(i);
|
|
|
|
d.connected = false;
|
2020-09-07 23:39:16 -05:00
|
|
|
if (d.shared && pgAdmin.server_mode == 'True'){
|
2020-09-03 02:29:28 -05:00
|
|
|
d.icon = 'icon-shared-server-not-connected';
|
|
|
|
}else{
|
|
|
|
d.icon = 'icon-server-not-connected';
|
|
|
|
}
|
2020-07-30 03:34:22 -05:00
|
|
|
t.addIcon(i, {icon: d.icon});
|
|
|
|
obj.callbacks.refresh.apply(obj, [null, i]);
|
2022-03-31 07:58:36 -05:00
|
|
|
setTimeout(() => {
|
2022-04-26 07:46:33 -05:00
|
|
|
t.close(i);
|
2022-03-31 07:58:36 -05:00
|
|
|
}, 10);
|
2020-07-30 03:34:22 -05:00
|
|
|
if (pgBrowser.serverInfo && d._id in pgBrowser.serverInfo) {
|
|
|
|
delete pgBrowser.serverInfo[d._id];
|
|
|
|
}
|
2020-09-03 02:29:28 -05:00
|
|
|
else {
|
|
|
|
try {
|
2021-12-02 04:35:52 -06:00
|
|
|
Notify.error(res.errormsg);
|
2020-09-03 02:29:28 -05:00
|
|
|
} catch (e) {
|
|
|
|
console.warn(e.stack || e);
|
|
|
|
}
|
|
|
|
t.unload(i);
|
2020-07-30 03:34:22 -05:00
|
|
|
}
|
2020-09-03 02:29:28 -05:00
|
|
|
}})
|
2020-07-30 03:34:22 -05:00
|
|
|
.fail(function(xhr, status, error) {
|
2021-12-02 04:35:52 -06:00
|
|
|
Notify.pgRespErrorNotify(xhr, error);
|
2019-03-14 10:11:16 -05:00
|
|
|
t.unload(i);
|
2020-07-30 03:34:22 -05:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
if (notify) {
|
2021-12-07 07:22:40 -06:00
|
|
|
Notify.confirm(
|
2022-02-07 04:42:30 -06:00
|
|
|
gettext('Disconnect from server'),
|
|
|
|
gettext('Are you sure you want to disconnect from the server %s?', d.label),
|
2020-07-30 03:34:22 -05:00
|
|
|
function() { disconnect(); },
|
2021-12-07 07:22:40 -06:00
|
|
|
function() { return true;},
|
|
|
|
);
|
2020-07-30 03:34:22 -05:00
|
|
|
} else {
|
|
|
|
disconnect();
|
|
|
|
}
|
2016-08-29 01:22:50 -05:00
|
|
|
}
|
2015-10-20 02:03:18 -05:00
|
|
|
|
|
|
|
return false;
|
2015-02-18 21:06:12 -06:00
|
|
|
},
|
2015-06-30 00:51:55 -05:00
|
|
|
/* Connect the server (if not connected), before opening this node */
|
2015-11-19 11:45:48 -06:00
|
|
|
beforeopen: function(item, data) {
|
2016-01-11 11:22:13 -06:00
|
|
|
|
2015-06-30 00:51:55 -05:00
|
|
|
if(!data || data._type != 'server') {
|
|
|
|
return false;
|
|
|
|
}
|
2015-10-20 02:03:18 -05:00
|
|
|
|
2015-11-19 11:45:48 -06:00
|
|
|
pgBrowser.tree.addIcon(item, {icon: data.icon});
|
2015-06-30 00:51:55 -05:00
|
|
|
if (!data.connected) {
|
2016-08-29 01:22:50 -05:00
|
|
|
connect_to_server(this, data, pgBrowser.tree, item, false);
|
2016-01-11 11:22:13 -06:00
|
|
|
|
2015-06-30 00:51:55 -05:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
2015-11-19 11:45:48 -06:00
|
|
|
},
|
2016-01-11 11:22:13 -06:00
|
|
|
added: function(item, data) {
|
|
|
|
|
2015-11-19 11:45:48 -06:00
|
|
|
pgBrowser.serverInfo = pgBrowser.serverInfo || {};
|
|
|
|
pgBrowser.serverInfo[data._id] = _.extend({}, data);
|
2016-01-11 11:22:13 -06:00
|
|
|
|
2016-08-09 06:17:02 -05:00
|
|
|
// Call added method of node.js
|
|
|
|
pgAdmin.Browser.Node.callbacks.added.apply(this, arguments);
|
2019-11-25 21:34:41 -06:00
|
|
|
|
|
|
|
if(data.was_connected) {
|
|
|
|
fetch_connection_status(this, data, pgBrowser.tree, item);
|
|
|
|
}
|
2016-01-11 11:22:13 -06:00
|
|
|
return true;
|
2016-05-06 09:08:22 -05:00
|
|
|
},
|
|
|
|
/* Reload configuration */
|
|
|
|
reload_configuration: function(args){
|
2022-09-08 07:38:58 -05:00
|
|
|
let input = args || {},
|
2016-05-10 05:34:47 -05:00
|
|
|
obj = this,
|
|
|
|
t = pgBrowser.tree,
|
|
|
|
i = input.item || t.selected(),
|
2021-09-27 06:14:26 -05:00
|
|
|
d = i ? t.itemData(i) : undefined;
|
2016-05-06 09:08:22 -05:00
|
|
|
|
2020-07-30 03:34:22 -05:00
|
|
|
if (d) {
|
2021-12-07 07:22:40 -06:00
|
|
|
Notify.confirm(
|
2020-07-30 03:34:22 -05:00
|
|
|
gettext('Reload server configuration'),
|
|
|
|
gettext('Are you sure you want to reload the server configuration on %s?', d.label),
|
|
|
|
function() {
|
|
|
|
$.ajax({
|
|
|
|
url: obj.generate_url(i, 'reload', d, true),
|
|
|
|
method:'GET',
|
2019-03-14 10:11:16 -05:00
|
|
|
})
|
2020-07-30 03:34:22 -05:00
|
|
|
.done(function(res) {
|
|
|
|
if (res.data.status) {
|
2021-12-02 04:35:52 -06:00
|
|
|
Notify.success(res.data.result);
|
2020-07-30 03:34:22 -05:00
|
|
|
}
|
|
|
|
else {
|
2021-12-02 04:35:52 -06:00
|
|
|
Notify.error(res.data.result);
|
2020-07-30 03:34:22 -05:00
|
|
|
}
|
|
|
|
})
|
|
|
|
.fail(function(xhr, status, error) {
|
2021-12-02 04:35:52 -06:00
|
|
|
Notify.pgRespErrorNotify(xhr, error);
|
2020-07-30 03:34:22 -05:00
|
|
|
t.unload(i);
|
|
|
|
});
|
|
|
|
},
|
2021-12-07 07:22:40 -06:00
|
|
|
function() { return true; },
|
2020-07-30 03:34:22 -05:00
|
|
|
);
|
|
|
|
}
|
2016-05-06 09:08:22 -05:00
|
|
|
|
|
|
|
return false;
|
2016-05-11 10:13:04 -05:00
|
|
|
},
|
|
|
|
/* Add restore point */
|
|
|
|
restore_point: function(args) {
|
2022-09-08 07:38:58 -05:00
|
|
|
let input = args || {},
|
2016-05-10 05:34:47 -05:00
|
|
|
obj = this,
|
|
|
|
t = pgBrowser.tree,
|
|
|
|
i = input.item || t.selected(),
|
2021-09-27 06:14:26 -05:00
|
|
|
d = i ? t.itemData(i) : undefined;
|
2016-05-11 10:13:04 -05:00
|
|
|
|
|
|
|
if (!d)
|
|
|
|
return false;
|
|
|
|
|
2022-07-11 03:09:09 -05:00
|
|
|
showNamedRestorePoint(gettext('Restore point name'), d, obj, i);
|
2016-05-13 02:51:20 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
/* Change password */
|
|
|
|
change_password: function(args){
|
2022-09-08 07:38:58 -05:00
|
|
|
let input = args || {},
|
2016-05-13 02:51:20 -05:00
|
|
|
obj = this,
|
|
|
|
t = pgBrowser.tree,
|
|
|
|
i = input.item || t.selected(),
|
2021-09-27 06:14:26 -05:00
|
|
|
d = i ? t.itemData(i) : undefined,
|
2017-12-13 07:28:07 -06:00
|
|
|
is_pgpass_file_used = false,
|
|
|
|
check_pgpass_url = obj.generate_url(i, 'check_pgpass', d, true);
|
2016-05-13 02:51:20 -05:00
|
|
|
|
2020-07-30 03:34:22 -05:00
|
|
|
if (d) {
|
|
|
|
// Call to check if server is using pgpass file or not
|
|
|
|
$.ajax({
|
|
|
|
url: check_pgpass_url,
|
|
|
|
method:'GET',
|
2019-03-14 10:11:16 -05:00
|
|
|
})
|
2020-07-30 03:34:22 -05:00
|
|
|
.done(function(res) {
|
|
|
|
if (res.success && res.data.is_pgpass) {
|
|
|
|
is_pgpass_file_used = true;
|
|
|
|
}
|
2022-07-11 03:09:09 -05:00
|
|
|
showChangeServerPassword(gettext('Change Password'), d, obj, i, is_pgpass_file_used);
|
2020-07-30 03:34:22 -05:00
|
|
|
})
|
|
|
|
.fail(function(xhr, status, error) {
|
2021-12-02 04:35:52 -06:00
|
|
|
Notify.pgRespErrorNotify(xhr, error);
|
2020-07-30 03:34:22 -05:00
|
|
|
});
|
|
|
|
}
|
2017-12-13 07:28:07 -06:00
|
|
|
|
2016-05-13 02:51:20 -05:00
|
|
|
return false;
|
2016-05-13 15:09:39 -05:00
|
|
|
},
|
2016-08-29 01:22:50 -05:00
|
|
|
|
2022-01-25 08:40:31 -06:00
|
|
|
on_done: function(res, t, i) {
|
|
|
|
if (res.success == 1) {
|
|
|
|
Notify.success(res.info);
|
|
|
|
t.itemData(i).wal_pause=res.data.wal_pause;
|
|
|
|
t.unload(i);
|
|
|
|
t.setInode(i);
|
|
|
|
t.deselect(i);
|
|
|
|
// Fetch updated data from server
|
|
|
|
setTimeout(function() {
|
|
|
|
t.select(i);
|
|
|
|
}, 10);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2016-05-13 15:09:39 -05:00
|
|
|
/* Pause WAL Replay */
|
|
|
|
pause_wal_replay: function(args) {
|
2022-09-08 07:38:58 -05:00
|
|
|
let input = args || {},
|
2018-01-12 01:29:51 -06:00
|
|
|
obj = this,
|
|
|
|
t = pgBrowser.tree,
|
|
|
|
i = input.item || t.selected(),
|
2021-09-27 06:14:26 -05:00
|
|
|
d = i ? t.itemData(i) : undefined;
|
2016-05-13 15:09:39 -05:00
|
|
|
|
|
|
|
if (!d)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
$.ajax({
|
|
|
|
url: obj.generate_url(i, 'wal_replay' , d, true),
|
|
|
|
type:'DELETE',
|
2018-01-12 01:29:51 -06:00
|
|
|
dataType: 'json',
|
2018-07-09 07:54:00 -05:00
|
|
|
})
|
2019-03-14 10:11:16 -05:00
|
|
|
.done(function(res) {
|
2022-01-25 08:40:31 -06:00
|
|
|
obj.on_done(res, t, i);
|
2019-03-14 10:11:16 -05:00
|
|
|
})
|
|
|
|
.fail(function(xhr, status, error) {
|
2021-12-02 04:35:52 -06:00
|
|
|
Notify.pgRespErrorNotify(xhr, error);
|
2016-05-13 15:09:39 -05:00
|
|
|
t.unload(i);
|
2019-03-14 10:11:16 -05:00
|
|
|
});
|
2016-05-13 15:09:39 -05:00
|
|
|
},
|
2016-08-29 01:22:50 -05:00
|
|
|
|
2016-05-13 15:09:39 -05:00
|
|
|
/* Resume WAL Replay */
|
|
|
|
resume_wal_replay: function(args) {
|
2022-09-08 07:38:58 -05:00
|
|
|
let input = args || {},
|
2018-01-12 01:29:51 -06:00
|
|
|
obj = this,
|
|
|
|
t = pgBrowser.tree,
|
|
|
|
i = input.item || t.selected(),
|
2021-09-27 06:14:26 -05:00
|
|
|
d = i ? t.itemData(i) : undefined;
|
2016-05-13 15:09:39 -05:00
|
|
|
|
|
|
|
if (!d)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
$.ajax({
|
|
|
|
url: obj.generate_url(i, 'wal_replay' , d, true),
|
|
|
|
type:'PUT',
|
2018-01-12 01:29:51 -06:00
|
|
|
dataType: 'json',
|
2018-07-09 07:54:00 -05:00
|
|
|
})
|
2019-03-14 10:11:16 -05:00
|
|
|
.done(function(res) {
|
2022-01-25 08:40:31 -06:00
|
|
|
obj.on_done(res, t, i);
|
2019-03-14 10:11:16 -05:00
|
|
|
})
|
|
|
|
.fail(function(xhr, status, error) {
|
2021-12-02 04:35:52 -06:00
|
|
|
Notify.pgRespErrorNotify(xhr, error);
|
2016-05-13 15:09:39 -05:00
|
|
|
t.unload(i);
|
2019-03-14 10:11:16 -05:00
|
|
|
});
|
2018-01-12 01:29:51 -06:00
|
|
|
},
|
2018-07-27 04:06:42 -05:00
|
|
|
|
2018-08-03 06:11:01 -05:00
|
|
|
/* Cleat saved database server password */
|
|
|
|
clear_saved_password: function(args){
|
2022-09-08 07:38:58 -05:00
|
|
|
let input = args || {},
|
2018-07-27 04:06:42 -05:00
|
|
|
obj = this,
|
|
|
|
t = pgBrowser.tree,
|
|
|
|
i = input.item || t.selected(),
|
2021-09-27 06:14:26 -05:00
|
|
|
d = i ? t.itemData(i) : undefined;
|
2018-07-27 04:06:42 -05:00
|
|
|
|
2020-07-30 03:34:22 -05:00
|
|
|
if (d) {
|
2021-12-07 07:22:40 -06:00
|
|
|
Notify.confirm(
|
2020-07-30 03:34:22 -05:00
|
|
|
gettext('Clear saved password'),
|
|
|
|
gettext('Are you sure you want to clear the saved password for server %s?', d.label),
|
|
|
|
function() {
|
|
|
|
$.ajax({
|
|
|
|
url: obj.generate_url(i, 'clear_saved_password', d, true),
|
|
|
|
method:'PUT',
|
2019-03-14 10:11:16 -05:00
|
|
|
})
|
2020-07-30 03:34:22 -05:00
|
|
|
.done(function(res) {
|
|
|
|
if (res.success == 1) {
|
2021-12-02 04:35:52 -06:00
|
|
|
Notify.success(res.info);
|
2020-07-30 03:34:22 -05:00
|
|
|
t.itemData(i).is_password_saved=res.data.is_password_saved;
|
|
|
|
}
|
|
|
|
else {
|
2021-12-02 04:35:52 -06:00
|
|
|
Notify.error(res.info);
|
2020-07-30 03:34:22 -05:00
|
|
|
}
|
|
|
|
})
|
|
|
|
.fail(function(xhr, status, error) {
|
2021-12-02 04:35:52 -06:00
|
|
|
Notify.pgRespErrorNotify(xhr, error);
|
2020-07-30 03:34:22 -05:00
|
|
|
});
|
|
|
|
},
|
|
|
|
function() { return true; }
|
|
|
|
);
|
|
|
|
}
|
2018-07-27 04:06:42 -05:00
|
|
|
|
|
|
|
return false;
|
|
|
|
},
|
2018-08-06 05:26:46 -05:00
|
|
|
|
|
|
|
/* Reset stored ssh tunnel password */
|
|
|
|
clear_sshtunnel_password: function(args){
|
2022-09-08 07:38:58 -05:00
|
|
|
let input = args || {},
|
2018-08-06 05:26:46 -05:00
|
|
|
obj = this,
|
|
|
|
t = pgBrowser.tree,
|
|
|
|
i = input.item || t.selected(),
|
2021-09-27 06:14:26 -05:00
|
|
|
d = i ? t.itemData(i) : undefined;
|
2018-08-06 05:26:46 -05:00
|
|
|
|
2020-07-30 03:34:22 -05:00
|
|
|
if (d) {
|
2021-12-07 07:22:40 -06:00
|
|
|
Notify.confirm(
|
2020-07-30 03:34:22 -05:00
|
|
|
gettext('Clear SSH Tunnel password'),
|
|
|
|
gettext('Are you sure you want to clear the saved password of SSH Tunnel for server %s?', d.label),
|
|
|
|
function() {
|
|
|
|
$.ajax({
|
|
|
|
url: obj.generate_url(i, 'clear_sshtunnel_password', d, true),
|
|
|
|
method:'PUT',
|
2019-03-14 10:11:16 -05:00
|
|
|
})
|
2020-07-30 03:34:22 -05:00
|
|
|
.done(function(res) {
|
|
|
|
if (res.success == 1) {
|
2021-12-02 04:35:52 -06:00
|
|
|
Notify.success(res.info);
|
2020-07-30 03:34:22 -05:00
|
|
|
t.itemData(i).is_tunnel_password_saved=res.data.is_tunnel_password_saved;
|
|
|
|
}
|
|
|
|
else {
|
2021-12-02 04:35:52 -06:00
|
|
|
Notify.error(res.info);
|
2020-07-30 03:34:22 -05:00
|
|
|
}
|
|
|
|
})
|
|
|
|
.fail(function(xhr, status, error) {
|
2021-12-02 04:35:52 -06:00
|
|
|
Notify.pgRespErrorNotify(xhr, error);
|
2020-07-30 03:34:22 -05:00
|
|
|
});
|
|
|
|
},
|
|
|
|
function() { return true; }
|
|
|
|
);
|
|
|
|
}
|
2018-08-06 05:26:46 -05:00
|
|
|
|
|
|
|
return false;
|
|
|
|
},
|
2021-05-25 09:42:57 -05:00
|
|
|
/* Open psql tool for server*/
|
|
|
|
server_psql_tool: function(args) {
|
2022-09-08 07:38:58 -05:00
|
|
|
let input = args || {},
|
2021-05-25 09:42:57 -05:00
|
|
|
t = pgBrowser.tree,
|
|
|
|
i = input.item || t.selected(),
|
2021-09-27 06:14:26 -05:00
|
|
|
d = i ? t.itemData(i) : undefined;
|
2021-05-25 09:42:57 -05:00
|
|
|
pgBrowser.psql.psql_tool(d, i, true);
|
|
|
|
}
|
2015-06-30 00:51:55 -05:00
|
|
|
},
|
2021-06-29 04:03:36 -05:00
|
|
|
getSchema: (treeNodeInfo, itemNodeData)=>{
|
2022-01-17 02:26:01 -06:00
|
|
|
return new ServerSchema(
|
2021-06-29 04:03:36 -05:00
|
|
|
getNodeListById(pgBrowser.Nodes['server_group'], treeNodeInfo, itemNodeData),
|
2021-09-28 04:35:32 -05:00
|
|
|
itemNodeData.user_id,
|
2021-06-29 04:03:36 -05:00
|
|
|
{
|
|
|
|
gid: treeNodeInfo['server_group']._id,
|
2020-09-03 02:29:28 -05:00
|
|
|
}
|
2021-06-29 04:03:36 -05:00
|
|
|
);
|
|
|
|
},
|
2016-08-29 01:22:50 -05:00
|
|
|
connection_lost: function(i, resp) {
|
|
|
|
if (pgBrowser.tree) {
|
2022-09-08 07:38:58 -05:00
|
|
|
let t = pgBrowser.tree,
|
2018-01-12 01:29:51 -06:00
|
|
|
d = i && t.itemData(i),
|
|
|
|
self = this;
|
2015-10-20 02:03:18 -05:00
|
|
|
|
2016-08-29 01:22:50 -05:00
|
|
|
while (d && d._type != 'server') {
|
|
|
|
i = t.parent(i);
|
|
|
|
d = i && t.itemData(i);
|
|
|
|
}
|
2015-11-19 11:45:48 -06:00
|
|
|
|
2016-08-29 01:22:50 -05:00
|
|
|
if (i && d && d._type == 'server') {
|
|
|
|
if (_.isUndefined(d.is_connecting) || !d.is_connecting) {
|
|
|
|
d.is_connecting = true;
|
|
|
|
|
2022-09-08 07:38:58 -05:00
|
|
|
let disconnect = function(_sid) {
|
2016-08-29 01:22:50 -05:00
|
|
|
if (d._id == _sid) {
|
|
|
|
d.is_connecting = false;
|
|
|
|
// Stop listening to the connection cancellation event
|
|
|
|
pgBrowser.Events.off(
|
|
|
|
'pgadmin:server:connect:cancelled', disconnect
|
|
|
|
);
|
|
|
|
|
|
|
|
// Connection to the database will also be cancelled
|
|
|
|
pgBrowser.Events.trigger(
|
|
|
|
'pgadmin:database:connect:cancelled',_sid,
|
|
|
|
resp.data.database || d.db
|
|
|
|
);
|
|
|
|
|
|
|
|
// Make sure - the server is disconnected properly
|
|
|
|
pgBrowser.Events.trigger(
|
|
|
|
'pgadmin:server:disconnect',
|
2018-01-12 01:29:51 -06:00
|
|
|
{item: i, data: d}, false
|
2016-08-29 01:22:50 -05:00
|
|
|
);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// Listen for the server connection cancellation event
|
|
|
|
pgBrowser.Events.on(
|
|
|
|
'pgadmin:server:connect:cancelled', disconnect
|
|
|
|
);
|
2021-12-07 07:22:40 -06:00
|
|
|
Notify.confirm(
|
2017-06-07 05:23:02 -05:00
|
|
|
gettext('Connection lost'),
|
|
|
|
gettext('Would you like to reconnect to the database?'),
|
2016-08-29 01:22:50 -05:00
|
|
|
function() {
|
|
|
|
connect_to_server(self, d, t, i, true);
|
|
|
|
},
|
|
|
|
function() {
|
|
|
|
d.is_connecting = false;
|
|
|
|
t.unload(i);
|
|
|
|
t.setInode(i);
|
|
|
|
t.addIcon(i, {icon: 'icon-database-not-connected'});
|
|
|
|
pgBrowser.Events.trigger(
|
|
|
|
'pgadmin:server:connect:cancelled', i, d, self
|
|
|
|
);
|
|
|
|
t.select(i);
|
|
|
|
});
|
|
|
|
}
|
2015-10-20 02:03:18 -05:00
|
|
|
}
|
2016-08-29 01:22:50 -05:00
|
|
|
}
|
2018-01-12 01:29:51 -06:00
|
|
|
},
|
2016-08-29 01:22:50 -05:00
|
|
|
});
|
2020-09-03 02:29:28 -05:00
|
|
|
|
2022-09-08 07:38:58 -05:00
|
|
|
let connect_to_server = function(obj, data, tree, item, reconnect) {
|
2020-09-03 02:29:28 -05:00
|
|
|
// Open properties dialog in edit mode
|
2022-08-11 00:19:45 -05:00
|
|
|
let server_url = obj.generate_url(item, 'obj', data, true);
|
2020-09-03 02:29:28 -05:00
|
|
|
// Fetch the updated data
|
|
|
|
$.get(server_url)
|
|
|
|
.done(function(res) {
|
2022-02-14 00:43:48 -06:00
|
|
|
if (res.shared && _.isNull(res.username) && data.user_id != current_user.id) {
|
|
|
|
if (!res.service) {
|
2020-09-03 02:29:28 -05:00
|
|
|
pgAdmin.Browser.Node.callbacks.show_obj_properties.call(
|
2022-08-11 02:40:18 -05:00
|
|
|
pgAdmin.Browser.Nodes[tree.itemData(item)._type], {action: 'edit', 'item': item}
|
2020-09-03 02:29:28 -05:00
|
|
|
);
|
|
|
|
data.is_connecting = false;
|
|
|
|
tree.unload(item);
|
|
|
|
tree.setInode(item);
|
|
|
|
tree.addIcon(item, {icon: 'icon-shared-server-not-connected'});
|
2021-12-02 04:35:52 -06:00
|
|
|
Notify.info('Please enter the server details to connect to the server. This server is a shared server.');
|
2022-02-14 00:43:48 -06:00
|
|
|
} else {
|
2020-09-03 02:29:28 -05:00
|
|
|
data.is_connecting = false;
|
|
|
|
tree.unload(item);
|
|
|
|
tree.setInode(item);
|
|
|
|
tree.addIcon(item, {icon: 'icon-shared-server-not-connected'});
|
|
|
|
}
|
|
|
|
}
|
2022-02-14 00:43:48 -06:00
|
|
|
else if (res.cloud_status == -1) {
|
2022-08-11 00:19:45 -05:00
|
|
|
pgAdmin.Browser.BgProcessManager.recheckCloudServer(data._id);
|
2022-02-14 00:43:48 -06:00
|
|
|
}
|
2020-09-03 02:29:28 -05:00
|
|
|
}).always(function(){
|
|
|
|
data.is_connecting = false;
|
|
|
|
});
|
|
|
|
|
2022-09-08 07:38:58 -05:00
|
|
|
let wasConnected = reconnect || data.connected,
|
2018-01-12 01:29:51 -06:00
|
|
|
onFailure = function(
|
|
|
|
xhr, status, error, _node, _data, _tree, _item, _wasConnected
|
|
|
|
) {
|
|
|
|
data.connected = false;
|
|
|
|
|
|
|
|
// It should be attempt to reconnect.
|
|
|
|
// Let's not change the status of the tree node now.
|
|
|
|
if (!_wasConnected) {
|
2021-09-27 06:14:26 -05:00
|
|
|
tree.close(_item);
|
2020-09-24 00:28:30 -05:00
|
|
|
if (_data.shared && pgAdmin.server_mode == 'True'){
|
2020-09-03 02:29:28 -05:00
|
|
|
tree.addIcon(_item, {icon: 'icon-shared-server-not-connected'});
|
|
|
|
}else{
|
|
|
|
tree.addIcon(_item, {icon: 'icon-server-not-connected'});
|
|
|
|
}
|
|
|
|
|
2018-01-12 01:29:51 -06:00
|
|
|
}
|
2021-05-03 05:40:45 -05:00
|
|
|
if (xhr.status != 200 && xhr.responseText.search('Ticket expired') !== -1) {
|
|
|
|
tree.addIcon(_item, {icon: 'icon-server-connecting'});
|
|
|
|
let fetchTicket = Kerberos.fetch_ticket();
|
|
|
|
fetchTicket.then(
|
|
|
|
function() {
|
2019-05-28 01:30:18 -05:00
|
|
|
connect_to_server(_node, _data, _tree, _item, _wasConnected);
|
2021-05-03 05:40:45 -05:00
|
|
|
},
|
|
|
|
function() {
|
|
|
|
tree.addIcon(_item, {icon: 'icon-server-not-connected'});
|
2021-12-02 04:35:52 -06:00
|
|
|
Notify.pgNotifier('Connection error', xhr, gettext('Connect to server.'));
|
2019-05-28 01:30:18 -05:00
|
|
|
}
|
2021-05-03 05:40:45 -05:00
|
|
|
);
|
|
|
|
} else {
|
2021-12-02 04:35:52 -06:00
|
|
|
Notify.pgNotifier('error', xhr, error, function(msg) {
|
2021-05-03 05:40:45 -05:00
|
|
|
setTimeout(function() {
|
|
|
|
if (msg == 'CRYPTKEY_SET') {
|
|
|
|
connect_to_server(_node, _data, _tree, _item, _wasConnected);
|
2022-04-05 06:31:12 -05:00
|
|
|
} else if (msg != 'CRYPTKEY_NOT_SET') {
|
2022-05-16 05:51:14 -05:00
|
|
|
showServerPassword(
|
2021-05-03 05:40:45 -05:00
|
|
|
gettext('Connect to Server'),
|
2022-05-16 05:51:14 -05:00
|
|
|
msg, _node, _data, _tree, _item, _wasConnected, onSuccess,
|
|
|
|
onFailure, onCancel
|
|
|
|
);
|
2021-05-03 05:40:45 -05:00
|
|
|
}
|
|
|
|
}, 100);
|
|
|
|
});
|
|
|
|
}
|
2018-01-12 01:29:51 -06:00
|
|
|
},
|
2020-06-16 00:17:40 -05:00
|
|
|
onSuccess = function(res, node, _data, _tree, _item, _wasConnected) {
|
2018-01-12 01:29:51 -06:00
|
|
|
if (res && res.data) {
|
|
|
|
if (typeof res.data.icon == 'string') {
|
2020-06-16 00:17:40 -05:00
|
|
|
_tree.removeIcon(_item);
|
|
|
|
_data.icon = res.data.icon;
|
|
|
|
_tree.addIcon(_item, {icon: _data.icon});
|
2016-08-29 01:22:50 -05:00
|
|
|
}
|
2016-05-13 15:09:39 -05:00
|
|
|
|
2020-06-16 00:17:40 -05:00
|
|
|
_.extend(_data, res.data);
|
|
|
|
_data.is_connecting = false;
|
2015-10-20 02:03:18 -05:00
|
|
|
|
2022-09-08 07:38:58 -05:00
|
|
|
let serverInfo = pgBrowser.serverInfo =
|
2018-01-12 01:29:51 -06:00
|
|
|
pgBrowser.serverInfo || {};
|
2020-06-16 00:17:40 -05:00
|
|
|
serverInfo[_data._id] = _.extend({}, _data);
|
2016-01-11 11:22:13 -06:00
|
|
|
|
2020-08-25 11:18:43 -05:00
|
|
|
if (_data.version < 90500) {
|
2021-12-02 04:35:52 -06:00
|
|
|
Notify.warning(gettext('You have connected to a server version that is older ' +
|
2020-08-25 11:18:43 -05:00
|
|
|
'than is supported by pgAdmin. This may cause pgAdmin to break in strange and ' +
|
|
|
|
'unpredictable ways. Or a plague of frogs. Either way, you have been warned!') +
|
|
|
|
'<br /><br />' +
|
2021-12-02 04:35:52 -06:00
|
|
|
res.info, null);
|
2020-08-25 11:18:43 -05:00
|
|
|
} else {
|
2021-12-02 04:35:52 -06:00
|
|
|
Notify.success(res.info);
|
2020-08-25 11:18:43 -05:00
|
|
|
}
|
|
|
|
|
2020-06-16 00:17:40 -05:00
|
|
|
obj.trigger('connected', obj, _item, _data);
|
2015-11-19 12:11:58 -06:00
|
|
|
|
2018-01-12 01:29:51 -06:00
|
|
|
// Generate the event that server is connected
|
|
|
|
pgBrowser.Events.trigger(
|
2020-06-16 00:17:40 -05:00
|
|
|
'pgadmin:server:connected', _data._id, _item, _data
|
2018-01-12 01:29:51 -06:00
|
|
|
);
|
|
|
|
// Generate the event that database is connected
|
|
|
|
pgBrowser.Events.trigger(
|
2020-06-16 00:17:40 -05:00
|
|
|
'pgadmin:database:connected', _data._id, _data.db, _item, _data
|
2018-01-12 01:29:51 -06:00
|
|
|
);
|
2016-03-15 08:30:58 -05:00
|
|
|
|
2021-10-14 00:54:43 -05:00
|
|
|
// Load dashboard
|
|
|
|
pgBrowser.Events.trigger('pgadmin-browser:tree:selected', _item, _data, node);
|
2022-03-07 03:58:28 -06:00
|
|
|
|
|
|
|
/* Call enable/disable menu function after database is connected.
|
|
|
|
To make sure all the menus for database is in the right state */
|
|
|
|
pgBrowser.enable_disable_menus.apply(pgBrowser, [_item]);
|
|
|
|
|
2018-01-12 01:29:51 -06:00
|
|
|
// We're not reconnecting
|
|
|
|
if (!_wasConnected) {
|
2020-06-16 00:17:40 -05:00
|
|
|
_tree.setInode(_item);
|
2016-08-29 01:22:50 -05:00
|
|
|
|
2018-01-12 01:29:51 -06:00
|
|
|
setTimeout(function() {
|
2020-06-16 00:17:40 -05:00
|
|
|
_tree.select(_item);
|
|
|
|
_tree.open(_item);
|
2018-01-12 01:29:51 -06:00
|
|
|
}, 10);
|
|
|
|
} else {
|
|
|
|
// We just need to refresh the tree now.
|
|
|
|
setTimeout(function() {
|
|
|
|
node.callbacks.refresh.apply(node, [true]);
|
|
|
|
}, 10);
|
2016-08-29 01:22:50 -05:00
|
|
|
}
|
2018-01-12 01:29:51 -06:00
|
|
|
}
|
|
|
|
};
|
2015-10-20 02:03:18 -05:00
|
|
|
|
2022-09-08 07:38:58 -05:00
|
|
|
let onCancel = function(_tree, _item, _data, _status) {
|
2016-08-29 01:22:50 -05:00
|
|
|
_data.is_connecting = false;
|
|
|
|
_tree.unload(_item);
|
|
|
|
_tree.setInode(_item);
|
|
|
|
_tree.removeIcon(_item);
|
2020-09-07 23:39:16 -05:00
|
|
|
if (_data.shared && pgAdmin.server_mode == 'True'){
|
2020-09-03 02:29:28 -05:00
|
|
|
_tree.addIcon(_item, {icon: 'icon-shared-server-not-connected'});
|
|
|
|
}else{
|
|
|
|
_tree.addIcon(_item, {icon: 'icon-server-not-connected'});
|
|
|
|
}
|
2016-08-29 01:22:50 -05:00
|
|
|
obj.trigger('connect:cancelled', data._id, data.db, obj, _item, _data);
|
|
|
|
pgBrowser.Events.trigger(
|
|
|
|
'pgadmin:server:connect:cancelled', data._id, _item, _data, obj
|
|
|
|
);
|
|
|
|
pgBrowser.Events.trigger(
|
|
|
|
'pgadmin:database:connect:cancelled', data._id, data.db, _item, _data, obj
|
|
|
|
);
|
|
|
|
if (_status) {
|
|
|
|
_tree.select(_item);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-11-25 21:34:41 -06:00
|
|
|
/* Wait till the existing request completes */
|
2022-02-14 00:43:48 -06:00
|
|
|
if(data.is_connecting || data.cloud_status == -1) {
|
2019-11-25 21:34:41 -06:00
|
|
|
return;
|
|
|
|
}
|
2016-08-29 01:22:50 -05:00
|
|
|
data.is_connecting = true;
|
2019-11-25 21:34:41 -06:00
|
|
|
tree.setLeaf(item);
|
|
|
|
tree.removeIcon(item);
|
|
|
|
tree.addIcon(item, {icon: 'icon-server-connecting'});
|
2022-09-08 07:38:58 -05:00
|
|
|
let url = obj.generate_url(item, 'connect', data, true);
|
2016-02-12 10:46:56 -06:00
|
|
|
$.post(url)
|
2018-01-12 01:29:51 -06:00
|
|
|
.done(function(res) {
|
|
|
|
if (res.success == 1) {
|
|
|
|
return onSuccess(
|
|
|
|
res, obj, data, tree, item, wasConnected
|
|
|
|
);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.fail(function(xhr, status, error) {
|
|
|
|
return onFailure(
|
|
|
|
xhr, status, error, obj, data, tree, item, wasConnected
|
2016-08-29 01:22:50 -05:00
|
|
|
);
|
2019-11-25 21:34:41 -06:00
|
|
|
})
|
|
|
|
.always(function(){
|
|
|
|
data.is_connecting = false;
|
|
|
|
});
|
|
|
|
};
|
2022-09-08 07:38:58 -05:00
|
|
|
let fetch_connection_status = function(obj, data, tree, item) {
|
|
|
|
let url = obj.generate_url(item, 'connect', data, true);
|
2019-11-25 21:34:41 -06:00
|
|
|
|
|
|
|
tree.setLeaf(item);
|
|
|
|
tree.removeIcon(item);
|
|
|
|
tree.addIcon(item, {icon: 'icon-server-connecting'});
|
|
|
|
$.get(url)
|
|
|
|
.done(function(res) {
|
|
|
|
tree.setInode(item);
|
|
|
|
if (res && res.data) {
|
|
|
|
if (typeof res.data.icon == 'string') {
|
|
|
|
tree.removeIcon(item);
|
|
|
|
data.icon = res.data.icon;
|
|
|
|
tree.addIcon(item, {icon: data.icon});
|
|
|
|
}
|
|
|
|
_.extend(data, res.data);
|
|
|
|
|
2022-09-08 07:38:58 -05:00
|
|
|
let serverInfo = pgBrowser.serverInfo = pgBrowser.serverInfo || {};
|
2019-11-25 21:34:41 -06:00
|
|
|
serverInfo[data._id] = _.extend({}, data);
|
|
|
|
|
|
|
|
if(data.errmsg) {
|
2021-12-02 04:35:52 -06:00
|
|
|
Notify.error(data.errmsg);
|
2019-11-25 21:34:41 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.fail(function(xhr, status, error) {
|
|
|
|
tree.setInode(item);
|
2020-09-07 23:39:16 -05:00
|
|
|
if (data.shared && pgAdmin.server_mode == 'True'){
|
2020-09-03 02:29:28 -05:00
|
|
|
tree.addIcon(item, {icon: 'icon-shared-server-not-connected'});
|
|
|
|
}else{
|
|
|
|
tree.addIcon(item, {icon: 'icon-server-not-connected'});
|
|
|
|
}
|
2021-12-02 04:35:52 -06:00
|
|
|
Notify.pgRespErrorNotify(xhr, error);
|
2018-01-12 01:29:51 -06:00
|
|
|
});
|
|
|
|
};
|
2015-06-30 00:51:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return pgBrowser.Nodes['server'];
|
|
|
|
});
|