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';
|
2021-06-29 04:03:36 -05:00
|
|
|
|
2017-06-12 01:31:22 -05:00
|
|
|
define('pgadmin.node.server', [
|
2018-01-12 01:29:51 -06:00
|
|
|
'sources/gettext', 'sources/url_for', 'jquery', 'underscore', 'backbone',
|
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',
|
2018-03-13 13:47:32 -05:00
|
|
|
'pgadmin.alertifyjs', 'pgadmin.backform',
|
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(
|
2019-10-10 01:35:28 -05:00
|
|
|
gettext, url_for, $, _, Backbone, pgAdmin, pgBrowser,
|
2021-06-29 04:03:36 -05:00
|
|
|
current_user, Alertify, Backform, 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, '') == '') {
|
2019-12-17 01:52:36 -06:00
|
|
|
var 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){
|
|
|
|
var 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){
|
|
|
|
var serverOwner = node.user_id;
|
|
|
|
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){
|
2016-05-10 07:46:08 -05:00
|
|
|
var input = args || {},
|
|
|
|
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) {
|
2016-05-10 07:46:08 -05:00
|
|
|
var input = args || {},
|
|
|
|
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
|
|
|
|
2020-07-30 03:34:22 -05:00
|
|
|
var disconnect = function() {
|
|
|
|
$.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]);
|
2021-09-27 06:14:26 -05:00
|
|
|
t.close(i);
|
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){
|
2016-05-10 05:34:47 -05:00
|
|
|
var input = args || {},
|
|
|
|
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) {
|
2016-05-10 05:34:47 -05:00
|
|
|
var input = args || {},
|
|
|
|
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;
|
|
|
|
|
2018-01-12 01:29:51 -06:00
|
|
|
Alertify.prompt(
|
|
|
|
gettext('Enter the name of the restore point to add'), '',
|
|
|
|
// We will execute this function when user clicks on the OK button
|
|
|
|
function(evt, value) {
|
|
|
|
// If user has provided a value, send it to the server
|
|
|
|
if(!_.isUndefined(value) && !_.isNull(value) && value !== ''
|
2016-05-10 05:34:47 -05:00
|
|
|
&& String(value).replace(/^\s+|\s+$/g, '') !== '') {
|
2018-01-12 01:29:51 -06:00
|
|
|
$.ajax({
|
|
|
|
url: obj.generate_url(i, 'restore_point', d, true),
|
|
|
|
method:'POST',
|
|
|
|
data:{ 'value': JSON.stringify(value) },
|
2018-07-09 07:54:00 -05:00
|
|
|
})
|
2019-03-14 10:11:16 -05:00
|
|
|
.done(function(res) {
|
2021-12-02 04:35:52 -06:00
|
|
|
Notify.success(res.data.result, 10000);
|
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);
|
2019-03-14 10:11:16 -05:00
|
|
|
t.unload(i);
|
|
|
|
});
|
2018-01-12 01:29:51 -06:00
|
|
|
} else {
|
2016-05-10 05:34:47 -05:00
|
|
|
evt.cancel = true;
|
2021-12-02 04:35:52 -06:00
|
|
|
Notify.error(gettext('Please enter a valid name.'), 10000);
|
2018-01-12 01:29:51 -06:00
|
|
|
}
|
|
|
|
},
|
|
|
|
// We will execute this function when user clicks on the Cancel
|
|
|
|
// button. Do nothing just close it.
|
|
|
|
function(evt) { evt.cancel = false; }
|
|
|
|
).set({'title': gettext('Restore point name')});
|
2016-05-13 02:51:20 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
/* Change password */
|
|
|
|
change_password: function(args){
|
|
|
|
var input = args || {},
|
|
|
|
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
|
|
|
url = obj.generate_url(i, 'change_password', d, true),
|
|
|
|
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) {
|
|
|
|
if(!Alertify.changeServerPassword) {
|
|
|
|
var newPasswordModel = Backbone.Model.extend({
|
|
|
|
defaults: {
|
|
|
|
user_name: undefined,
|
|
|
|
password: undefined,
|
|
|
|
newPassword: undefined,
|
|
|
|
confirmPassword: undefined,
|
|
|
|
},
|
|
|
|
validate: function() {
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
passwordChangeFields = [{
|
|
|
|
name: 'user_name', label: gettext('User'),
|
|
|
|
type: 'text', readonly: true, control: 'input',
|
|
|
|
},{
|
|
|
|
name: 'password', label: gettext('Current Password'),
|
|
|
|
type: 'password', disabled: function() { return is_pgpass_file_used; },
|
|
|
|
control: 'input', required: true,
|
|
|
|
},{
|
|
|
|
name: 'newPassword', label: gettext('New Password'),
|
|
|
|
type: 'password', disabled: false, control: 'input',
|
|
|
|
required: true,
|
|
|
|
},{
|
|
|
|
name: 'confirmPassword', label: gettext('Confirm Password'),
|
|
|
|
type: 'password', disabled: false, control: 'input',
|
|
|
|
required: true,
|
|
|
|
}];
|
|
|
|
|
|
|
|
|
|
|
|
Alertify.dialog('changeServerPassword' ,function factory() {
|
|
|
|
return {
|
|
|
|
main: function(params) {
|
|
|
|
var title = gettext('Change Password');
|
|
|
|
this.set('title', title);
|
|
|
|
this.user_name = params.user.name;
|
|
|
|
},
|
|
|
|
setup:function() {
|
|
|
|
return {
|
|
|
|
buttons: [{
|
|
|
|
text: gettext('Cancel'), key: 27,
|
|
|
|
className: 'btn btn-secondary fa fa-times pg-alertify-button', attrs: {name: 'cancel'},
|
|
|
|
},{
|
|
|
|
text: gettext('OK'), key: 13, className: 'btn btn-primary fa fa-check pg-alertify-button',
|
|
|
|
attrs: {name:'submit'},
|
|
|
|
}],
|
|
|
|
// Set options for dialog
|
|
|
|
options: {
|
|
|
|
padding : !1,
|
|
|
|
overflow: !1,
|
|
|
|
modal:false,
|
|
|
|
resizable: true,
|
|
|
|
maximizable: true,
|
|
|
|
pinnable: false,
|
|
|
|
closableByDimmer: false,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
},
|
|
|
|
hooks: {
|
|
|
|
// triggered when the dialog is closed
|
|
|
|
onclose: function() {
|
|
|
|
if (this.view) {
|
|
|
|
this.view.remove({data: true, internal: true, silent: true});
|
|
|
|
}
|
2018-01-12 01:29:51 -06:00
|
|
|
},
|
|
|
|
},
|
2020-07-30 03:34:22 -05:00
|
|
|
prepare: function() {
|
|
|
|
var self = this;
|
|
|
|
// Disable Ok button until user provides input
|
|
|
|
this.__internal.buttons[1].element.disabled = true;
|
|
|
|
|
|
|
|
var $container = $('<div class=\'change_password\'></div>'),
|
|
|
|
newpasswordmodel = new newPasswordModel(
|
|
|
|
{'user_name': self.user_name}
|
|
|
|
),
|
|
|
|
view = this.view = new Backform.Form({
|
|
|
|
el: $container,
|
|
|
|
model: newpasswordmodel,
|
|
|
|
fields: passwordChangeFields,
|
|
|
|
});
|
2018-07-09 07:54:00 -05:00
|
|
|
|
2020-07-30 03:34:22 -05:00
|
|
|
view.render();
|
|
|
|
|
|
|
|
this.elements.content.appendChild($container.get(0));
|
|
|
|
|
|
|
|
// Listen to model & if filename is provided then enable Backup button
|
|
|
|
this.view.model.on('change', function() {
|
|
|
|
var that = this,
|
|
|
|
password = this.get('password'),
|
|
|
|
newPassword = this.get('newPassword'),
|
|
|
|
confirmPassword = this.get('confirmPassword');
|
|
|
|
|
|
|
|
// Only check password field if pgpass file is not available
|
|
|
|
if ((!is_pgpass_file_used &&
|
|
|
|
(_.isUndefined(password) || _.isNull(password) || password == '')) ||
|
|
|
|
_.isUndefined(newPassword) || _.isNull(newPassword) || newPassword == '' ||
|
|
|
|
_.isUndefined(confirmPassword) || _.isNull(confirmPassword) || confirmPassword == '') {
|
|
|
|
self.__internal.buttons[1].element.disabled = true;
|
|
|
|
} else if (newPassword != confirmPassword) {
|
|
|
|
self.__internal.buttons[1].element.disabled = true;
|
|
|
|
|
|
|
|
this.errorTimeout && clearTimeout(this.errorTimeout);
|
|
|
|
this.errorTimeout = setTimeout(function() {
|
|
|
|
that.errorModel.set('confirmPassword', gettext('Passwords do not match.'));
|
|
|
|
} ,400);
|
|
|
|
}else {
|
|
|
|
that.errorModel.clear();
|
|
|
|
self.__internal.buttons[1].element.disabled = false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
// Callback functions when click on the buttons of the Alertify dialogs
|
|
|
|
callback: function(e) {
|
|
|
|
if (e.button.element.name == 'submit') {
|
|
|
|
var self = this,
|
|
|
|
alertArgs = this.view.model.toJSON();
|
|
|
|
|
|
|
|
e.cancel = true;
|
|
|
|
|
|
|
|
$.ajax({
|
|
|
|
url: url,
|
|
|
|
method:'POST',
|
|
|
|
data:{'data': JSON.stringify(alertArgs) },
|
2019-03-14 10:11:16 -05:00
|
|
|
})
|
2020-07-30 03:34:22 -05:00
|
|
|
.done(function(res) {
|
|
|
|
if (res.success) {
|
|
|
|
// Notify user to update pgpass file
|
|
|
|
if(is_pgpass_file_used) {
|
2021-12-07 07:22:40 -06:00
|
|
|
Notify.alert(
|
2020-07-30 03:34:22 -05:00
|
|
|
gettext('Change Password'),
|
|
|
|
gettext('Please make sure to disconnect the server'
|
|
|
|
+ ' and update the new password in the pgpass file'
|
|
|
|
+ ' before performing any other operation')
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-12-02 04:35:52 -06:00
|
|
|
Notify.success(res.info);
|
2020-07-30 03:34:22 -05:00
|
|
|
self.close();
|
|
|
|
} else {
|
2021-12-02 04:35:52 -06:00
|
|
|
Notify.error(res.errormsg);
|
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
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
};
|
|
|
|
});
|
|
|
|
}
|
2016-05-13 02:51:20 -05:00
|
|
|
|
2020-07-30 03:34:22 -05:00
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
Alertify.changeServerPassword(d).resizeTo('40%','52%');
|
|
|
|
})
|
|
|
|
.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) {
|
2016-08-29 01:22:50 -05:00
|
|
|
var 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) {
|
2016-08-29 01:22:50 -05:00
|
|
|
var 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){
|
2018-07-27 04:06:42 -05:00
|
|
|
var input = args || {},
|
|
|
|
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){
|
|
|
|
var input = args || {},
|
|
|
|
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) {
|
|
|
|
var input = args || {},
|
|
|
|
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) {
|
|
|
|
var 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;
|
|
|
|
|
|
|
|
var disconnect = function(_sid) {
|
|
|
|
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
|
|
|
|
2018-01-12 01:29:51 -06:00
|
|
|
var connect_to_server = function(obj, data, tree, item, reconnect) {
|
2020-09-03 02:29:28 -05:00
|
|
|
// Open properties dialog in edit mode
|
|
|
|
var server_url = obj.generate_url(item, 'obj', data, true);
|
|
|
|
// 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(
|
|
|
|
pgAdmin.Browser.Nodes[tree.itemData(item)._type], {action: 'edit'}
|
|
|
|
);
|
|
|
|
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) {
|
|
|
|
$.ajax({
|
|
|
|
type: 'GET',
|
|
|
|
timeout: 30000,
|
|
|
|
url: url_for('cloud.update_cloud_process', {'sid': res.id}),
|
|
|
|
cache: false,
|
|
|
|
async: true,
|
|
|
|
contentType: 'application/json',
|
|
|
|
})
|
|
|
|
.done(function() {
|
|
|
|
pgAdmin.Browser.BackgroundProcessObsorver.update_process_list();
|
|
|
|
})
|
|
|
|
.fail(function() {
|
|
|
|
console.warn(arguments);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return;
|
2020-09-03 02:29:28 -05:00
|
|
|
}).always(function(){
|
|
|
|
data.is_connecting = false;
|
|
|
|
});
|
|
|
|
|
2016-08-29 01:22:50 -05:00
|
|
|
var 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);
|
|
|
|
} else {
|
|
|
|
Alertify.dlgServerPass(
|
|
|
|
gettext('Connect to Server'),
|
|
|
|
msg, _node, _data, _tree, _item, _wasConnected
|
|
|
|
).resizeTo();
|
|
|
|
}
|
|
|
|
}, 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
|
|
|
|
2018-01-12 01:29:51 -06:00
|
|
|
var serverInfo = pgBrowser.serverInfo =
|
|
|
|
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
|
|
|
|
|
|
|
// Ask Password and send it back to the connect server
|
2018-01-12 01:29:51 -06:00
|
|
|
if (!Alertify.dlgServerPass) {
|
|
|
|
Alertify.dialog('dlgServerPass', function factory() {
|
2015-10-20 02:03:18 -05:00
|
|
|
return {
|
2016-08-29 01:22:50 -05:00
|
|
|
main: function(
|
2020-06-16 00:17:40 -05:00
|
|
|
title, message, node, _data, _tree, _item,
|
2016-08-29 01:22:50 -05:00
|
|
|
_status, _onSuccess, _onFailure, _onCancel
|
|
|
|
) {
|
2015-10-20 02:03:18 -05:00
|
|
|
this.set('title', title);
|
|
|
|
this.message = message;
|
2020-06-16 00:17:40 -05:00
|
|
|
this.tree = _tree;
|
|
|
|
this.nodeData = _data;
|
|
|
|
this.nodeItem = _item;
|
2016-08-29 01:22:50 -05:00
|
|
|
this.node= node;
|
|
|
|
this.connected = _status;
|
|
|
|
this.onSuccess = _onSuccess || onSuccess;
|
|
|
|
this.onFailure = _onFailure || onFailure;
|
|
|
|
this.onCancel = _onCancel || onCancel;
|
2015-10-20 02:03:18 -05:00
|
|
|
},
|
|
|
|
setup:function() {
|
|
|
|
return {
|
2018-01-12 01:29:51 -06:00
|
|
|
buttons:[{
|
Improvement in the look and feel of the whole application
Changed the SCSS/CSS for the below third party libraries to adopt the
new look 'n' feel:
- wcDocker
- Alertify dialogs, and notifications
- AciTree
- Bootstrap Navbar
- Bootstrap Tabs
- Bootstrap Drop-Down menu
- Backgrid
- Select2
Adopated the new the look 'n' feel for the dialogs, wizard, properties,
tab panels, tabs, fieldset, subnode control, spinner control, HTML
table, and other form controls.
- Font is changed to Roboto
- Using SCSS variables to define the look 'n' feel
- Designer background images for the Login, and Forget password pages in
'web' mode
- Improved the look 'n' feel for the key selection in the preferences
dialog
- Table classes consistency changes across the application
- File Open and Save dialog list view changes
Author(s): Aditya Toshniwal & Khushboo Vashi
2018-12-21 05:44:55 -06:00
|
|
|
text: gettext('Cancel'), className: 'btn btn-secondary fa fa-times pg-alertify-button',
|
2018-04-24 08:27:31 -05:00
|
|
|
key: 27,
|
Improvement in the look and feel of the whole application
Changed the SCSS/CSS for the below third party libraries to adopt the
new look 'n' feel:
- wcDocker
- Alertify dialogs, and notifications
- AciTree
- Bootstrap Navbar
- Bootstrap Tabs
- Bootstrap Drop-Down menu
- Backgrid
- Select2
Adopated the new the look 'n' feel for the dialogs, wizard, properties,
tab panels, tabs, fieldset, subnode control, spinner control, HTML
table, and other form controls.
- Font is changed to Roboto
- Using SCSS variables to define the look 'n' feel
- Designer background images for the Login, and Forget password pages in
'web' mode
- Improved the look 'n' feel for the key selection in the preferences
dialog
- Table classes consistency changes across the application
- File Open and Save dialog list view changes
Author(s): Aditya Toshniwal & Khushboo Vashi
2018-12-21 05:44:55 -06:00
|
|
|
},{
|
|
|
|
text: gettext('OK'), key: 13, className: 'btn btn-primary fa fa-check pg-alertify-button',
|
2018-01-12 01:29:51 -06:00
|
|
|
}],
|
|
|
|
focus: {element: '#password', select: true},
|
2015-10-20 02:03:18 -05:00
|
|
|
options: {
|
2018-01-12 01:29:51 -06:00
|
|
|
modal: 0, resizable: false, maximizable: false, pinnable: false,
|
|
|
|
},
|
2015-10-20 02:03:18 -05:00
|
|
|
};
|
|
|
|
},
|
2022-01-12 07:29:21 -06:00
|
|
|
build:function() {/*This is intentional (SonarQube)*/},
|
2015-10-20 02:03:18 -05:00
|
|
|
prepare:function() {
|
|
|
|
this.setContent(this.message);
|
|
|
|
},
|
|
|
|
callback: function(closeEvent) {
|
2016-08-29 01:22:50 -05:00
|
|
|
var _tree = this.tree,
|
2018-01-12 01:29:51 -06:00
|
|
|
_item = this.nodeItem,
|
|
|
|
_node = this.node,
|
|
|
|
_data = this.nodeData,
|
|
|
|
_status = this.connected,
|
|
|
|
_onSuccess = this.onSuccess,
|
|
|
|
_onFailure = this.onFailure,
|
|
|
|
_onCancel = this.onCancel;
|
2015-10-20 02:03:18 -05:00
|
|
|
|
2018-01-12 01:29:51 -06:00
|
|
|
if (closeEvent.button.text == gettext('OK')) {
|
2015-10-20 02:03:18 -05:00
|
|
|
|
2016-08-29 01:22:50 -05:00
|
|
|
var _url = _node.generate_url(_item, 'connect', _data, true);
|
2015-10-20 02:03:18 -05:00
|
|
|
|
2016-08-29 01:22:50 -05:00
|
|
|
if (!_status) {
|
|
|
|
_tree.setLeaf(_item);
|
|
|
|
_tree.removeIcon(_item);
|
|
|
|
_tree.addIcon(_item, {icon: 'icon-server-connecting'});
|
|
|
|
}
|
2015-10-20 02:03:18 -05:00
|
|
|
|
|
|
|
$.ajax({
|
|
|
|
type: 'POST',
|
|
|
|
timeout: 30000,
|
|
|
|
url: _url,
|
|
|
|
data: $('#frmPassword').serialize(),
|
2018-07-09 07:54:00 -05:00
|
|
|
})
|
2019-03-14 10:11:16 -05:00
|
|
|
.done(function(res) {
|
|
|
|
return _onSuccess(
|
|
|
|
res, _node, _data, _tree, _item, _status
|
|
|
|
);
|
|
|
|
})
|
|
|
|
.fail(function(xhr, status, error) {
|
|
|
|
return _onFailure(
|
|
|
|
xhr, status, error, _node, _data, _tree, _item, _status
|
|
|
|
);
|
|
|
|
});
|
2015-10-20 02:03:18 -05:00
|
|
|
} else {
|
2018-01-12 01:29:51 -06:00
|
|
|
_onCancel && typeof(_onCancel) == 'function' &&
|
|
|
|
_onCancel(_tree, _item, _data, _status);
|
2015-10-20 02:03:18 -05:00
|
|
|
}
|
2018-01-12 01:29:51 -06:00
|
|
|
},
|
2015-10-20 02:03:18 -05:00
|
|
|
};
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-08-29 01:22:50 -05:00
|
|
|
var onCancel = function(_tree, _item, _data, _status) {
|
|
|
|
_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'});
|
2018-01-12 01:29:51 -06:00
|
|
|
var 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;
|
|
|
|
});
|
|
|
|
};
|
|
|
|
var fetch_connection_status = function(obj, data, tree, item) {
|
|
|
|
var url = obj.generate_url(item, 'connect', data, true);
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
var serverInfo = pgBrowser.serverInfo = pgBrowser.serverInfo || {};
|
|
|
|
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'];
|
|
|
|
});
|