2019-01-02 04:24:12 -06:00
|
|
|
/////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// pgAdmin 4 - PostgreSQL Tools
|
|
|
|
//
|
|
|
|
// Copyright (C) 2013 - 2019, The pgAdmin Development Team
|
|
|
|
// This software is released under the PostgreSQL Licence
|
|
|
|
//
|
|
|
|
//////////////////////////////////////////////////////////////
|
|
|
|
|
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',
|
2017-08-08 22:02:16 -05:00
|
|
|
'underscore.string', 'sources/pgadmin', 'pgadmin.browser',
|
2018-01-12 01:29:51 -06:00
|
|
|
'pgadmin.server.supported_servers', 'pgadmin.user_management.current_user',
|
2018-03-13 13:47:32 -05:00
|
|
|
'pgadmin.alertifyjs', 'pgadmin.backform',
|
|
|
|
'sources/browser/server_groups/servers/model_validation',
|
|
|
|
'pgadmin.browser.server.privilege',
|
2017-06-22 05:26:45 -05:00
|
|
|
], function(
|
2018-01-12 01:29:51 -06:00
|
|
|
gettext, url_for, $, _, Backbone, S, pgAdmin, pgBrowser,
|
2018-03-13 13:47:32 -05:00
|
|
|
supported_servers, current_user, Alertify, Backform,
|
|
|
|
modelValidation
|
2017-06-22 05:26:45 -05:00
|
|
|
) {
|
2015-06-30 00:51:55 -05:00
|
|
|
|
|
|
|
if (!pgBrowser.Nodes['server']) {
|
2017-09-28 04:02:33 -05:00
|
|
|
var SSL_MODES = ['prefer', 'require', 'verify-ca', 'verify-full'];
|
2016-05-29 04:49:34 -05:00
|
|
|
|
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();
|
2016-05-29 04:49:34 -05:00
|
|
|
|
2016-06-06 07:37:12 -05:00
|
|
|
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, '') == '') {
|
|
|
|
var errmsg = gettext('Label must be specified.');
|
|
|
|
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'),
|
2016-01-07 07:21:56 -06:00
|
|
|
canDrop: true,
|
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',
|
2017-06-07 05:23:02 -05:00
|
|
|
category: 'create', priority: 1, label: gettext('Server...'),
|
2018-01-12 01:29:51 -06:00
|
|
|
data: {action: 'create'}, icon: 'wcTabIcon icon-server',
|
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',
|
2017-06-07 05:23:02 -05:00
|
|
|
category: 'create', priority: 3, label: gettext('Server...'),
|
2018-01-12 01:29:51 -06:00
|
|
|
data: {action: 'create'}, icon: 'wcTabIcon icon-server',
|
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'),
|
2018-01-12 01:29:51 -06:00
|
|
|
icon: 'fa fa-link', enable : 'is_not_connected',
|
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',
|
2017-06-07 05:23:02 -05:00
|
|
|
category: 'drop', priority: 5, label: gettext('Disconnect Server'),
|
2018-01-12 01:29:51 -06:00
|
|
|
icon: 'fa fa-chain-broken', enable : 'is_connected',
|
2016-05-11 10:13:04 -05:00
|
|
|
},{
|
2016-05-06 09:08:22 -05:00
|
|
|
name: 'reload_configuration', node: 'server', module: this,
|
|
|
|
applies: ['tools', 'context'], callback: 'reload_configuration',
|
2017-06-07 05:23:02 -05:00
|
|
|
category: 'reload', priority: 6, label: gettext('Reload Configuration'),
|
2018-01-12 01:29:51 -06:00
|
|
|
icon: 'fa fa-repeat', enable : 'enable_reload_config',
|
2016-05-11 10:13:04 -05:00
|
|
|
},{
|
|
|
|
name: 'restore_point', node: 'server', module: this,
|
|
|
|
applies: ['tools', 'context'], callback: 'restore_point',
|
2017-06-07 05:23:02 -05:00
|
|
|
category: 'restore', priority: 9, label: gettext('Add Named Restore Point...'),
|
2018-01-12 01:29:51 -06:00
|
|
|
icon: 'fa fa-anchor', enable : 'is_applicable',
|
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,
|
2018-01-12 01:29:51 -06:00
|
|
|
icon: 'fa fa-lock', enable : 'is_connected',
|
2016-05-13 15:09:39 -05:00
|
|
|
},{
|
|
|
|
name: 'wal_replay_pause', node: 'server', module: this,
|
|
|
|
applies: ['tools', 'context'], callback: 'pause_wal_replay',
|
2017-06-07 05:23:02 -05:00
|
|
|
category: 'wal_replay_pause', priority: 7, label: gettext('Pause Replay of WAL'),
|
2018-01-12 01:29:51 -06:00
|
|
|
icon: 'fa fa-pause-circle', enable : 'wal_pause_enabled',
|
2016-05-13 15:09:39 -05:00
|
|
|
},{
|
|
|
|
name: 'wal_replay_resume', node: 'server', module: this,
|
|
|
|
applies: ['tools', 'context'], callback: 'resume_wal_replay',
|
2017-06-07 05:23:02 -05:00
|
|
|
category: 'wal_replay_resume', priority: 8, label: gettext('Resume Replay of WAL'),
|
2018-01-12 01:29:51 -06:00
|
|
|
icon: 'fa fa-play-circle', enable : 'wal_resume_enabled',
|
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;
|
|
|
|
},
|
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);
|
|
|
|
},
|
|
|
|
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(),
|
|
|
|
d = i && i.length == 1 ? t.itemData(i) : undefined;
|
2015-10-20 02:03:18 -05:00
|
|
|
|
|
|
|
if (!d)
|
|
|
|
return false;
|
|
|
|
|
2016-08-29 01:22:50 -05:00
|
|
|
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(),
|
|
|
|
d = i && i.length == 1 ? t.itemData(i) : undefined;
|
2015-10-20 02:03:18 -05:00
|
|
|
|
|
|
|
if (!d)
|
|
|
|
return false;
|
|
|
|
|
2016-08-29 01:22:50 -05:00
|
|
|
notify = notify || _.isUndefined(notify) || _.isNull(notify);
|
|
|
|
|
|
|
|
var disconnect = function() {
|
|
|
|
$.ajax({
|
|
|
|
url: obj.generate_url(i, 'connect', d, true),
|
|
|
|
type:'DELETE',
|
2018-07-09 07:54:00 -05:00
|
|
|
})
|
2019-03-14 10:11:16 -05:00
|
|
|
.done(function(res) {
|
|
|
|
if (res.success == 1) {
|
|
|
|
Alertify.success(res.info);
|
|
|
|
d = t.itemData(i);
|
|
|
|
t.removeIcon(i);
|
|
|
|
d.connected = false;
|
|
|
|
d.icon = 'icon-server-not-connected';
|
|
|
|
t.addIcon(i, {icon: d.icon});
|
|
|
|
obj.callbacks.refresh.apply(obj, [null, i]);
|
|
|
|
if (pgBrowser.serverInfo && d._id in pgBrowser.serverInfo) {
|
|
|
|
delete pgBrowser.serverInfo[d._id];
|
|
|
|
}
|
|
|
|
pgBrowser.enable_disable_menus(i);
|
|
|
|
// Trigger server disconnect event
|
|
|
|
pgBrowser.Events.trigger(
|
|
|
|
'pgadmin:server:disconnect',
|
|
|
|
{item: i, data: d}, false
|
|
|
|
);
|
2016-08-29 01:22:50 -05:00
|
|
|
}
|
2019-03-14 10:11:16 -05:00
|
|
|
else {
|
|
|
|
try {
|
|
|
|
Alertify.error(res.errormsg);
|
|
|
|
} catch (e) {
|
|
|
|
console.warn(e.stack || e);
|
|
|
|
}
|
|
|
|
t.unload(i);
|
2015-10-20 02:03:18 -05:00
|
|
|
}
|
2019-03-14 10:11:16 -05:00
|
|
|
})
|
|
|
|
.fail(function(xhr, status, error) {
|
|
|
|
Alertify.pgRespErrorNotify(xhr, error);
|
2016-08-29 01:22:50 -05:00
|
|
|
t.unload(i);
|
2019-03-14 10:11:16 -05:00
|
|
|
});
|
2016-08-29 01:22:50 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
if (notify) {
|
2018-01-12 01:29:51 -06:00
|
|
|
Alertify.confirm(
|
2017-06-07 05:23:02 -05:00
|
|
|
gettext('Disconnect server'),
|
|
|
|
gettext(
|
|
|
|
'Are you sure you want to disconnect the server %(server)s?',
|
|
|
|
{server: d.label}
|
|
|
|
),
|
2018-01-12 01:29:51 -06:00
|
|
|
function() { disconnect(); },
|
|
|
|
function() { return true;}
|
2017-06-07 05:23:02 -05:00
|
|
|
);
|
2016-08-29 01:22:50 -05:00
|
|
|
} else {
|
|
|
|
disconnect();
|
|
|
|
}
|
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);
|
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(),
|
|
|
|
d = i && i.length == 1 ? t.itemData(i) : undefined;
|
2016-05-06 09:08:22 -05:00
|
|
|
|
|
|
|
if (!d)
|
|
|
|
return false;
|
|
|
|
|
2018-01-12 01:29:51 -06:00
|
|
|
Alertify.confirm(
|
2017-06-07 05:23:02 -05:00
|
|
|
gettext('Reload server configuration'),
|
2018-01-12 01:29:51 -06:00
|
|
|
S(
|
|
|
|
gettext('Are you sure you want to reload the server configuration on %s?')
|
|
|
|
).sprintf(d.label).value(),
|
|
|
|
function() {
|
2016-05-06 09:08:22 -05:00
|
|
|
$.ajax({
|
|
|
|
url: obj.generate_url(i, 'reload', d, true),
|
|
|
|
method:'GET',
|
2018-07-09 07:54:00 -05:00
|
|
|
})
|
2019-03-14 10:11:16 -05:00
|
|
|
.done(function(res) {
|
|
|
|
if (res.data.status) {
|
|
|
|
Alertify.success(res.data.result);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
Alertify.error(res.data.result);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.fail(function(xhr, status, error) {
|
|
|
|
Alertify.pgRespErrorNotify(xhr, error);
|
|
|
|
t.unload(i);
|
|
|
|
});
|
2018-01-12 01:29:51 -06:00
|
|
|
},
|
|
|
|
function() { return true; }
|
|
|
|
);
|
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(),
|
|
|
|
d = i && i.length == 1 ? 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) {
|
|
|
|
Alertify.success(res.data.result, 10);
|
|
|
|
})
|
|
|
|
.fail(function(xhr, status, error) {
|
|
|
|
Alertify.pgRespErrorNotify(xhr, error);
|
|
|
|
t.unload(i);
|
|
|
|
});
|
2018-01-12 01:29:51 -06:00
|
|
|
} else {
|
2016-05-10 05:34:47 -05:00
|
|
|
evt.cancel = true;
|
2018-01-12 01:29:51 -06:00
|
|
|
Alertify.error( gettext('Please enter a valid name.'), 10);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
// 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(),
|
|
|
|
d = i && i.length == 1 ? 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
|
|
|
|
|
|
|
if (!d)
|
|
|
|
return false;
|
|
|
|
|
2018-01-12 01:29:51 -06:00
|
|
|
if(!Alertify.changeServerPassword) {
|
2016-05-13 02:51:20 -05:00
|
|
|
var newPasswordModel = Backbone.Model.extend({
|
|
|
|
defaults: {
|
|
|
|
user_name: undefined,
|
|
|
|
password: undefined,
|
|
|
|
newPassword: undefined,
|
2018-01-12 01:29:51 -06:00
|
|
|
confirmPassword: undefined,
|
2016-05-13 02:51:20 -05:00
|
|
|
},
|
|
|
|
validate: function() {
|
|
|
|
return null;
|
2018-01-12 01:29:51 -06:00
|
|
|
},
|
2016-05-13 02:51:20 -05:00
|
|
|
}),
|
|
|
|
passwordChangeFields = [{
|
2018-01-12 01:29:51 -06:00
|
|
|
name: 'user_name', label: gettext('User'),
|
|
|
|
type: 'text', disabled: 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() {
|
2016-05-13 02:51:20 -05:00
|
|
|
return {
|
2018-01-12 01:29:51 -06:00
|
|
|
main: function(params) {
|
2017-06-07 05:23:02 -05:00
|
|
|
var title = gettext('Change Password ');
|
2016-05-13 02:51:20 -05:00
|
|
|
this.set('title', title);
|
|
|
|
this.user_name = params.user.name;
|
2018-01-12 01:29:51 -06:00
|
|
|
},
|
|
|
|
setup:function() {
|
2016-05-13 02:51:20 -05:00
|
|
|
return {
|
|
|
|
buttons: [{
|
2018-04-24 08:27:31 -05:00
|
|
|
text: gettext('Cancel'), 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
|
|
|
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'},
|
2016-05-13 02:51:20 -05:00
|
|
|
}],
|
|
|
|
// Set options for dialog
|
|
|
|
options: {
|
|
|
|
padding : !1,
|
|
|
|
overflow: !1,
|
2017-01-08 04:35:34 -06:00
|
|
|
modal:false,
|
2016-05-13 02:51:20 -05:00
|
|
|
resizable: true,
|
|
|
|
maximizable: true,
|
|
|
|
pinnable: false,
|
2018-01-12 01:29:51 -06:00
|
|
|
closableByDimmer: false,
|
|
|
|
},
|
2016-05-13 02:51:20 -05:00
|
|
|
};
|
|
|
|
},
|
|
|
|
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
|
|
|
},
|
2016-05-13 02:51:20 -05:00
|
|
|
},
|
|
|
|
prepare: function() {
|
|
|
|
var self = this;
|
2017-12-13 07:28:07 -06:00
|
|
|
// Disable Ok button until user provides input
|
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
|
|
|
this.__internal.buttons[1].element.disabled = true;
|
2016-05-13 02:51:20 -05:00
|
|
|
|
2018-01-12 01:29:51 -06:00
|
|
|
var $container = $('<div class=\'change_password\'></div>'),
|
2017-12-13 07:28:07 -06:00
|
|
|
newpasswordmodel = new newPasswordModel(
|
|
|
|
{'user_name': self.user_name}
|
|
|
|
),
|
|
|
|
view = this.view = new Backform.Form({
|
|
|
|
el: $container,
|
|
|
|
model: newpasswordmodel,
|
2018-01-12 01:29:51 -06:00
|
|
|
fields: passwordChangeFields,
|
2017-12-13 07:28:07 -06:00
|
|
|
});
|
2016-05-13 02:51:20 -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,
|
2018-01-12 01:29:51 -06:00
|
|
|
password = this.get('password'),
|
|
|
|
newPassword = this.get('newPassword'),
|
|
|
|
confirmPassword = this.get('confirmPassword');
|
2016-05-13 02:51:20 -05:00
|
|
|
|
2017-12-13 07:28:07 -06:00
|
|
|
// Only check password field if pgpass file is not available
|
|
|
|
if ((!is_pgpass_file_used &&
|
2018-01-12 01:29:51 -06:00
|
|
|
(_.isUndefined(password) || _.isNull(password) || password == '')) ||
|
2016-05-13 02:51:20 -05:00
|
|
|
_.isUndefined(newPassword) || _.isNull(newPassword) || newPassword == '' ||
|
|
|
|
_.isUndefined(confirmPassword) || _.isNull(confirmPassword) || confirmPassword == '') {
|
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
|
|
|
self.__internal.buttons[1].element.disabled = true;
|
2016-05-13 02:51:20 -05:00
|
|
|
} else if (newPassword != confirmPassword) {
|
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
|
|
|
self.__internal.buttons[1].element.disabled = true;
|
2016-05-13 02:51:20 -05:00
|
|
|
|
|
|
|
this.errorTimeout && clearTimeout(this.errorTimeout);
|
|
|
|
this.errorTimeout = setTimeout(function() {
|
2017-06-07 05:23:02 -05:00
|
|
|
that.errorModel.set('confirmPassword', gettext('Passwords do not match.'));
|
2018-01-12 01:29:51 -06:00
|
|
|
} ,400);
|
2016-05-13 02:51:20 -05:00
|
|
|
}else {
|
|
|
|
that.errorModel.clear();
|
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
|
|
|
self.__internal.buttons[1].element.disabled = false;
|
2016-05-13 02:51:20 -05:00
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
// Callback functions when click on the buttons of the Alertify dialogs
|
|
|
|
callback: function(e) {
|
2018-01-12 01:29:51 -06:00
|
|
|
if (e.button.element.name == 'submit') {
|
2016-05-13 02:51:20 -05:00
|
|
|
var self = this,
|
2018-01-12 01:29:51 -06:00
|
|
|
args = this.view.model.toJSON();
|
2016-05-13 02:51:20 -05:00
|
|
|
|
|
|
|
e.cancel = true;
|
|
|
|
|
|
|
|
$.ajax({
|
|
|
|
url: url,
|
|
|
|
method:'POST',
|
|
|
|
data:{'data': JSON.stringify(args) },
|
2018-07-09 07:54:00 -05:00
|
|
|
})
|
2019-03-14 10:11:16 -05:00
|
|
|
.done(function(res) {
|
|
|
|
if (res.success) {
|
2018-07-09 07:54:00 -05:00
|
|
|
// Notify user to update pgpass file
|
2019-03-14 10:11:16 -05:00
|
|
|
if(is_pgpass_file_used) {
|
|
|
|
Alertify.alert(
|
|
|
|
gettext('Change Password'),
|
|
|
|
gettext('Please make sure to disconnect the server'
|
2018-07-09 07:54:00 -05:00
|
|
|
+ ' and update the new password in the pgpass file'
|
|
|
|
+ ' before performing any other operation')
|
2019-03-14 10:11:16 -05:00
|
|
|
);
|
|
|
|
}
|
2018-07-09 07:54:00 -05:00
|
|
|
|
2019-03-14 10:11:16 -05:00
|
|
|
Alertify.success(res.info);
|
|
|
|
self.close();
|
|
|
|
} else {
|
|
|
|
Alertify.error(res.errormsg);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.fail(function(xhr, status, error) {
|
|
|
|
Alertify.pgRespErrorNotify(xhr, error);
|
|
|
|
});
|
2016-05-13 02:51:20 -05:00
|
|
|
}
|
2018-01-12 01:29:51 -06:00
|
|
|
},
|
2016-05-13 02:51:20 -05:00
|
|
|
};
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-12-13 07:28:07 -06:00
|
|
|
// Call to check if server is using pgpass file or not
|
|
|
|
$.ajax({
|
|
|
|
url: check_pgpass_url,
|
|
|
|
method:'GET',
|
2018-07-09 07:54:00 -05:00
|
|
|
})
|
2019-03-14 10:11:16 -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) {
|
|
|
|
Alertify.pgRespErrorNotify(xhr, error);
|
|
|
|
});
|
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
|
|
|
|
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(),
|
|
|
|
d = i && i.length == 1 ? 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) {
|
|
|
|
if (res.success == 1) {
|
|
|
|
Alertify.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);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.fail(function(xhr, status, error) {
|
|
|
|
Alertify.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(),
|
|
|
|
d = i && i.length == 1 ? 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) {
|
|
|
|
if (res.success == 1) {
|
|
|
|
Alertify.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);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.fail(function(xhr, status, error) {
|
|
|
|
Alertify.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(),
|
|
|
|
d = i && i.length == 1 ? t.itemData(i) : undefined;
|
|
|
|
|
|
|
|
if (!d)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
Alertify.confirm(
|
2018-08-03 06:11:01 -05:00
|
|
|
gettext('Clear saved password'),
|
2018-07-27 04:06:42 -05:00
|
|
|
S(
|
2018-08-03 06:11:01 -05:00
|
|
|
gettext('Are you sure you want to clear the saved password for server %s?')
|
2018-07-27 04:06:42 -05:00
|
|
|
).sprintf(d.label).value(),
|
|
|
|
function() {
|
|
|
|
$.ajax({
|
2018-08-03 06:11:01 -05:00
|
|
|
url: obj.generate_url(i, 'clear_saved_password', d, true),
|
2018-07-27 04:06:42 -05:00
|
|
|
method:'PUT',
|
|
|
|
})
|
2019-03-14 10:11:16 -05:00
|
|
|
.done(function(res) {
|
|
|
|
if (res.success == 1) {
|
|
|
|
Alertify.success(res.info);
|
|
|
|
t.itemData(i).is_password_saved=res.data.is_password_saved;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
Alertify.error(res.info);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.fail(function(xhr, status, error) {
|
|
|
|
Alertify.pgRespErrorNotify(xhr, error);
|
|
|
|
});
|
2018-07-27 04:06:42 -05:00
|
|
|
},
|
|
|
|
function() { return true; }
|
|
|
|
);
|
|
|
|
|
|
|
|
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(),
|
|
|
|
d = i && i.length == 1 ? t.itemData(i) : undefined;
|
|
|
|
|
|
|
|
if (!d)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
Alertify.confirm(
|
|
|
|
gettext('Clear SSH Tunnel password'),
|
|
|
|
S(
|
|
|
|
gettext('Are you sure you want to clear the saved password of SSH Tunnel for server %s?')
|
|
|
|
).sprintf(d.label).value(),
|
|
|
|
function() {
|
|
|
|
$.ajax({
|
|
|
|
url: obj.generate_url(i, 'clear_sshtunnel_password', d, true),
|
|
|
|
method:'PUT',
|
|
|
|
})
|
2019-03-14 10:11:16 -05:00
|
|
|
.done(function(res) {
|
|
|
|
if (res.success == 1) {
|
|
|
|
Alertify.success(res.info);
|
|
|
|
t.itemData(i).is_tunnel_password_saved=res.data.is_tunnel_password_saved;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
Alertify.error(res.info);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.fail(function(xhr, status, error) {
|
|
|
|
Alertify.pgRespErrorNotify(xhr, error);
|
|
|
|
});
|
2018-08-06 05:26:46 -05:00
|
|
|
},
|
|
|
|
function() { return true; }
|
|
|
|
);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
},
|
2015-06-30 00:51:55 -05:00
|
|
|
},
|
|
|
|
model: pgAdmin.Browser.Node.Model.extend({
|
|
|
|
defaults: {
|
2016-05-05 10:42:16 -05:00
|
|
|
gid: undefined,
|
2015-06-30 00:51:55 -05:00
|
|
|
id: undefined,
|
2016-06-02 19:59:23 -05:00
|
|
|
name: '',
|
2015-10-20 02:03:18 -05:00
|
|
|
sslmode: 'prefer',
|
2016-06-02 19:59:23 -05:00
|
|
|
host: '',
|
2017-06-26 14:48:59 -05:00
|
|
|
hostaddr: '',
|
2015-10-20 02:03:18 -05:00
|
|
|
port: 5432,
|
2016-03-10 09:58:17 -06:00
|
|
|
db: 'postgres',
|
2017-06-22 05:26:45 -05:00
|
|
|
username: current_user.name,
|
2016-06-14 11:23:25 -05:00
|
|
|
role: null,
|
|
|
|
connect_now: true,
|
2016-08-03 09:55:45 -05:00
|
|
|
password: undefined,
|
2017-07-21 06:44:57 -05:00
|
|
|
save_password: false,
|
2017-09-28 04:02:33 -05:00
|
|
|
db_res: '',
|
|
|
|
passfile: undefined,
|
|
|
|
sslcompression: false,
|
|
|
|
sslcert: undefined,
|
|
|
|
sslkey: undefined,
|
|
|
|
sslrootcert: undefined,
|
2018-01-12 01:29:51 -06:00
|
|
|
sslcrl: undefined,
|
2018-03-12 15:45:56 -05:00
|
|
|
service: undefined,
|
2018-05-04 05:27:27 -05:00
|
|
|
use_ssh_tunnel: 0,
|
|
|
|
tunnel_host: undefined,
|
|
|
|
tunnel_port: 22,
|
|
|
|
tunnel_username: undefined,
|
|
|
|
tunnel_identity_file: undefined,
|
|
|
|
tunnel_password: undefined,
|
|
|
|
tunnel_authentication: 0,
|
2018-08-06 05:26:46 -05:00
|
|
|
save_tunnel_password: false,
|
2018-06-19 18:58:46 -05:00
|
|
|
connect_timeout: 0,
|
2015-02-18 21:06:12 -06:00
|
|
|
},
|
2016-05-05 10:42:16 -05:00
|
|
|
// Default values!
|
|
|
|
initialize: function(attrs, args) {
|
|
|
|
var isNew = (_.size(attrs) === 0);
|
|
|
|
|
|
|
|
if (isNew) {
|
2017-07-27 06:55:07 -05:00
|
|
|
this.set({'gid': args.node_info['server_group']._id});
|
2016-05-05 10:42:16 -05:00
|
|
|
}
|
|
|
|
pgAdmin.Browser.Node.Model.prototype.initialize.apply(this, arguments);
|
|
|
|
},
|
2015-06-30 00:51:55 -05:00
|
|
|
schema: [{
|
2018-01-12 01:29:51 -06:00
|
|
|
id: 'id', label: gettext('ID'), type: 'int', mode: ['properties'],
|
2015-06-30 00:51:55 -05:00
|
|
|
},{
|
2017-06-07 05:23:02 -05:00
|
|
|
id: 'name', label: gettext('Name'), type: 'text',
|
2018-01-12 01:29:51 -06:00
|
|
|
mode: ['properties', 'edit', 'create'],
|
2016-03-16 04:58:14 -05:00
|
|
|
},{
|
2017-06-07 05:23:02 -05:00
|
|
|
id: 'gid', label: gettext('Server group'), type: 'int',
|
2017-07-27 06:55:07 -05:00
|
|
|
control: 'node-list-by-id', node: 'server_group',
|
2018-01-12 01:29:51 -06:00
|
|
|
mode: ['create', 'edit'], select2: {allowClear: false},
|
2016-08-03 09:55:45 -05:00
|
|
|
},{
|
2017-06-07 05:23:02 -05:00
|
|
|
id: 'server_type', label: gettext('Server type'), type: 'options',
|
2016-03-16 04:58:14 -05:00
|
|
|
mode: ['properties'], visible: 'isConnected',
|
2018-01-12 01:29:51 -06:00
|
|
|
'options': supported_servers,
|
2015-06-30 00:51:55 -05:00
|
|
|
},{
|
2017-06-07 05:23:02 -05:00
|
|
|
id: 'connected', label: gettext('Connected?'), type: 'switch',
|
|
|
|
mode: ['properties'], group: gettext('Connection'), 'options': {
|
2019-02-04 00:01:48 -06:00
|
|
|
'onText': gettext('True'), 'offText': gettext('False'), 'size': 'mini',
|
2018-01-12 01:29:51 -06:00
|
|
|
},
|
2015-06-30 00:51:55 -05:00
|
|
|
},{
|
2017-06-07 05:23:02 -05:00
|
|
|
id: 'version', label: gettext('Version'), type: 'text', group: null,
|
2018-01-12 01:29:51 -06:00
|
|
|
mode: ['properties'], visible: 'isConnected',
|
2017-11-21 10:28:01 -06:00
|
|
|
},{
|
|
|
|
id: 'bgcolor', label: gettext('Background'), type: 'color',
|
|
|
|
group: null, mode: ['edit', 'create'], disabled: 'isfgColorSet',
|
2018-01-12 01:29:51 -06:00
|
|
|
deps: ['fgcolor'],
|
2017-11-21 10:28:01 -06:00
|
|
|
},{
|
|
|
|
id: 'fgcolor', label: gettext('Foreground'), type: 'color',
|
|
|
|
group: null, mode: ['edit', 'create'], disabled: 'isConnected',
|
2016-06-14 11:23:25 -05:00
|
|
|
},{
|
2017-06-07 05:23:02 -05:00
|
|
|
id: 'connect_now', controlLabel: gettext('Connect now?'), type: 'checkbox',
|
2018-01-12 01:29:51 -06:00
|
|
|
group: null, mode: ['create'],
|
2015-06-30 00:51:55 -05:00
|
|
|
},{
|
2017-06-07 05:23:02 -05:00
|
|
|
id: 'comment', label: gettext('Comments'), type: 'multiline', group: null,
|
2018-01-12 01:29:51 -06:00
|
|
|
mode: ['properties', 'edit', 'create'],
|
2015-06-30 00:51:55 -05:00
|
|
|
},{
|
2017-06-07 05:23:02 -05:00
|
|
|
id: 'host', label: gettext('Host name/address'), type: 'text', group: gettext('Connection'),
|
2018-01-12 01:29:51 -06:00
|
|
|
mode: ['properties', 'edit', 'create'], disabled: 'isConnected',
|
2015-06-30 00:51:55 -05:00
|
|
|
},{
|
2017-06-07 05:23:02 -05:00
|
|
|
id: 'port', label: gettext('Port'), type: 'int', group: gettext('Connection'),
|
2018-05-18 05:12:38 -05:00
|
|
|
mode: ['properties', 'edit', 'create'], disabled: 'isConnected', min: 1, max: 65535,
|
2015-06-30 00:51:55 -05:00
|
|
|
},{
|
2017-06-07 05:23:02 -05:00
|
|
|
id: 'db', label: gettext('Maintenance database'), type: 'text', group: gettext('Connection'),
|
2018-01-12 01:29:51 -06:00
|
|
|
mode: ['properties', 'edit', 'create'], disabled: 'isConnected',
|
2015-06-30 00:51:55 -05:00
|
|
|
},{
|
2017-06-07 05:23:02 -05:00
|
|
|
id: 'username', label: gettext('Username'), type: 'text', group: gettext('Connection'),
|
2018-01-12 01:29:51 -06:00
|
|
|
mode: ['properties', 'edit', 'create'], disabled: 'isConnected',
|
2016-06-14 11:23:25 -05:00
|
|
|
},{
|
2017-06-07 05:23:02 -05:00
|
|
|
id: 'password', label: gettext('Password'), type: 'password',
|
|
|
|
group: gettext('Connection'), control: 'input', mode: ['create'], deps: ['connect_now'],
|
2018-05-04 05:27:27 -05:00
|
|
|
visible: function(model) {
|
|
|
|
return model.get('connect_now') && model.isNew();
|
2018-01-12 01:29:51 -06:00
|
|
|
},
|
2016-08-03 09:55:45 -05:00
|
|
|
},{
|
2018-01-12 01:29:51 -06:00
|
|
|
id: 'save_password', controlLabel: gettext('Save password?'),
|
|
|
|
type: 'checkbox', group: gettext('Connection'), mode: ['create'],
|
2018-08-06 05:26:46 -05:00
|
|
|
deps: ['connect_now'], visible: function(model) {
|
2018-05-04 05:27:27 -05:00
|
|
|
return model.get('connect_now') && model.isNew();
|
2017-03-31 19:14:37 -05:00
|
|
|
},
|
2018-08-06 05:26:46 -05:00
|
|
|
disabled: function() {
|
2018-05-04 05:27:27 -05:00
|
|
|
if (!current_user.allow_save_password)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
2018-01-12 01:29:51 -06:00
|
|
|
},
|
2015-06-30 00:51:55 -05:00
|
|
|
},{
|
2017-06-07 05:23:02 -05:00
|
|
|
id: 'role', label: gettext('Role'), type: 'text', group: gettext('Connection'),
|
2018-01-12 01:29:51 -06:00
|
|
|
mode: ['properties', 'edit', 'create'], disabled: 'isConnected',
|
2015-10-20 02:03:18 -05:00
|
|
|
},{
|
2017-09-28 04:02:33 -05:00
|
|
|
id: 'sslmode', label: gettext('SSL mode'), type: 'options', group: gettext('SSL'),
|
2015-10-20 02:03:18 -05:00
|
|
|
mode: ['properties', 'edit', 'create'], disabled: 'isConnected',
|
|
|
|
'options': [
|
2017-11-05 07:32:26 -06:00
|
|
|
{label: gettext('Allow'), value: 'allow'},
|
|
|
|
{label: gettext('Prefer'), value: 'prefer'},
|
|
|
|
{label: gettext('Require'), value: 'require'},
|
|
|
|
{label: gettext('Disable'), value: 'disable'},
|
|
|
|
{label: gettext('Verify-CA'), value: 'verify-ca'},
|
2018-01-12 01:29:51 -06:00
|
|
|
{label: gettext('Verify-Full'), value: 'verify-full'},
|
|
|
|
],
|
2017-09-28 04:02:33 -05:00
|
|
|
},{
|
|
|
|
id: 'sslcert', label: gettext('Client certificate'), type: 'text',
|
|
|
|
group: gettext('SSL'), mode: ['edit', 'create'],
|
|
|
|
disabled: 'isSSL', control: Backform.FileControl,
|
|
|
|
dialog_type: 'select_file', supp_types: ['*'],
|
2018-01-12 01:29:51 -06:00
|
|
|
deps: ['sslmode'],
|
2017-09-28 04:02:33 -05:00
|
|
|
},{
|
|
|
|
id: 'sslkey', label: gettext('Client certificate key'), type: 'text',
|
|
|
|
group: gettext('SSL'), mode: ['edit', 'create'],
|
|
|
|
disabled: 'isSSL', control: Backform.FileControl,
|
|
|
|
dialog_type: 'select_file', supp_types: ['*'],
|
2018-01-12 01:29:51 -06:00
|
|
|
deps: ['sslmode'],
|
2017-09-28 04:02:33 -05:00
|
|
|
},{
|
|
|
|
id: 'sslrootcert', label: gettext('Root certificate'), type: 'text',
|
|
|
|
group: gettext('SSL'), mode: ['edit', 'create'],
|
|
|
|
disabled: 'isSSL', control: Backform.FileControl,
|
|
|
|
dialog_type: 'select_file', supp_types: ['*'],
|
2018-01-12 01:29:51 -06:00
|
|
|
deps: ['sslmode'],
|
2017-09-28 04:02:33 -05:00
|
|
|
},{
|
|
|
|
id: 'sslcrl', label: gettext('Certificate revocation list'), type: 'text',
|
|
|
|
group: gettext('SSL'), mode: ['edit', 'create'],
|
|
|
|
disabled: 'isSSL', control: Backform.FileControl,
|
|
|
|
dialog_type: 'select_file', supp_types: ['*'],
|
2018-01-12 01:29:51 -06:00
|
|
|
deps: ['sslmode'],
|
2017-09-28 04:02:33 -05:00
|
|
|
},{
|
|
|
|
id: 'sslcompression', label: gettext('SSL compression?'), type: 'switch',
|
|
|
|
mode: ['edit', 'create'], group: gettext('SSL'),
|
2019-02-04 00:01:48 -06:00
|
|
|
'options': {'size': 'mini'},
|
2018-01-12 01:29:51 -06:00
|
|
|
deps: ['sslmode'], disabled: 'isSSL',
|
2017-09-28 04:02:33 -05:00
|
|
|
},{
|
|
|
|
id: 'sslcert', label: gettext('Client certificate'), type: 'text',
|
|
|
|
group: gettext('SSL'), mode: ['properties'],
|
|
|
|
deps: ['sslmode'],
|
2018-05-04 05:27:27 -05:00
|
|
|
visible: function(model) {
|
|
|
|
var sslcert = model.get('sslcert');
|
2017-09-28 04:02:33 -05:00
|
|
|
return !_.isUndefined(sslcert) && !_.isNull(sslcert);
|
2018-01-12 01:29:51 -06:00
|
|
|
},
|
2017-09-28 04:02:33 -05:00
|
|
|
},{
|
|
|
|
id: 'sslkey', label: gettext('Client certificate key'), type: 'text',
|
|
|
|
group: gettext('SSL'), mode: ['properties'],
|
|
|
|
deps: ['sslmode'],
|
2018-05-04 05:27:27 -05:00
|
|
|
visible: function(model) {
|
|
|
|
var sslkey = model.get('sslkey');
|
2017-09-28 04:02:33 -05:00
|
|
|
return !_.isUndefined(sslkey) && !_.isNull(sslkey);
|
2018-01-12 01:29:51 -06:00
|
|
|
},
|
2017-09-28 04:02:33 -05:00
|
|
|
},{
|
|
|
|
id: 'sslrootcert', label: gettext('Root certificate'), type: 'text',
|
|
|
|
group: gettext('SSL'), mode: ['properties'],
|
|
|
|
deps: ['sslmode'],
|
2018-05-04 05:27:27 -05:00
|
|
|
visible: function(model) {
|
|
|
|
var sslrootcert = model.get('sslrootcert');
|
2017-09-28 04:02:33 -05:00
|
|
|
return !_.isUndefined(sslrootcert) && !_.isNull(sslrootcert);
|
2018-01-12 01:29:51 -06:00
|
|
|
},
|
2017-09-28 04:02:33 -05:00
|
|
|
},{
|
|
|
|
id: 'sslcrl', label: gettext('Certificate revocation list'), type: 'text',
|
|
|
|
group: gettext('SSL'), mode: ['properties'],
|
|
|
|
deps: ['sslmode'],
|
2018-05-04 05:27:27 -05:00
|
|
|
visible: function(model) {
|
|
|
|
var sslcrl = model.get('sslcrl');
|
2017-09-28 04:02:33 -05:00
|
|
|
return !_.isUndefined(sslcrl) && !_.isNull(sslcrl);
|
2018-01-12 01:29:51 -06:00
|
|
|
},
|
2017-09-28 04:02:33 -05:00
|
|
|
},{
|
|
|
|
id: 'sslcompression', label: gettext('SSL compression?'), type: 'switch',
|
|
|
|
mode: ['properties'], group: gettext('SSL'),
|
2019-02-04 00:01:48 -06:00
|
|
|
'options': {'size': 'mini'},
|
2018-05-04 05:27:27 -05:00
|
|
|
deps: ['sslmode'], visible: function(model) {
|
|
|
|
var sslmode = model.get('sslmode');
|
2017-09-28 04:02:33 -05:00
|
|
|
return _.indexOf(SSL_MODES, sslmode) != -1;
|
2018-01-12 01:29:51 -06:00
|
|
|
},
|
2017-09-28 04:02:33 -05:00
|
|
|
},{
|
2018-05-04 05:27:27 -05:00
|
|
|
id: 'use_ssh_tunnel', label: gettext('Use SSH tunneling'), type: 'switch',
|
|
|
|
mode: ['properties', 'edit', 'create'], group: gettext('SSH Tunnel'),
|
2019-02-04 00:01:48 -06:00
|
|
|
'options': {'size': 'mini'},
|
2018-05-04 05:27:27 -05:00
|
|
|
disabled: function(model) {
|
|
|
|
if (!pgAdmin.Browser.utils.support_ssh_tunnel) {
|
|
|
|
setTimeout(function() {
|
|
|
|
model.set('use_ssh_tunnel', 0);
|
|
|
|
}, 10);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return model.get('connected');
|
|
|
|
},
|
|
|
|
},{
|
|
|
|
id: 'tunnel_host', label: gettext('Tunnel host'), type: 'text', group: gettext('SSH Tunnel'),
|
|
|
|
mode: ['properties', 'edit', 'create'], deps: ['use_ssh_tunnel'],
|
|
|
|
disabled: function(model) {
|
2019-06-05 01:37:24 -05:00
|
|
|
return !model.get('use_ssh_tunnel') || model.get('connected');
|
2018-05-04 05:27:27 -05:00
|
|
|
},
|
|
|
|
},{
|
|
|
|
id: 'tunnel_port', label: gettext('Tunnel port'), type: 'int', group: gettext('SSH Tunnel'),
|
|
|
|
mode: ['properties', 'edit', 'create'], deps: ['use_ssh_tunnel'], max: 65535,
|
|
|
|
disabled: function(model) {
|
2019-06-05 01:37:24 -05:00
|
|
|
return !model.get('use_ssh_tunnel') || model.get('connected');
|
2018-05-04 05:27:27 -05:00
|
|
|
},
|
|
|
|
},{
|
|
|
|
id: 'tunnel_username', label: gettext('Username'), type: 'text', group: gettext('SSH Tunnel'),
|
|
|
|
mode: ['properties', 'edit', 'create'], deps: ['use_ssh_tunnel'],
|
|
|
|
disabled: function(model) {
|
2019-06-05 01:37:24 -05:00
|
|
|
return !model.get('use_ssh_tunnel') || model.get('connected');
|
2018-05-04 05:27:27 -05:00
|
|
|
},
|
|
|
|
},{
|
|
|
|
id: 'tunnel_authentication', label: gettext('Authentication'), type: 'switch',
|
|
|
|
mode: ['properties', 'edit', 'create'], group: gettext('SSH Tunnel'),
|
|
|
|
'options': {'onText': gettext('Identity file'),
|
2019-02-04 00:01:48 -06:00
|
|
|
'offText': gettext('Password'), 'size': 'mini', width: '90'},
|
2018-05-04 05:27:27 -05:00
|
|
|
deps: ['use_ssh_tunnel'],
|
|
|
|
disabled: function(model) {
|
2019-06-05 01:37:24 -05:00
|
|
|
return !model.get('use_ssh_tunnel') || model.get('connected');
|
2018-05-04 05:27:27 -05:00
|
|
|
},
|
|
|
|
}, {
|
|
|
|
id: 'tunnel_identity_file', label: gettext('Identity file'), type: 'text',
|
|
|
|
group: gettext('SSH Tunnel'), mode: ['edit', 'create'],
|
|
|
|
control: Backform.FileControl, dialog_type: 'select_file', supp_types: ['*'],
|
|
|
|
deps: ['tunnel_authentication', 'use_ssh_tunnel'],
|
|
|
|
disabled: function(model) {
|
2018-05-31 09:10:43 -05:00
|
|
|
let file = model.get('tunnel_identity_file');
|
|
|
|
if (!model.get('tunnel_authentication') && file) {
|
2018-05-04 05:27:27 -05:00
|
|
|
setTimeout(function() {
|
2018-05-31 09:10:43 -05:00
|
|
|
model.set('tunnel_identity_file', null);
|
2018-05-04 05:27:27 -05:00
|
|
|
}, 10);
|
|
|
|
}
|
2018-05-17 06:48:00 -05:00
|
|
|
return !model.get('tunnel_authentication') || !model.get('use_ssh_tunnel');
|
2018-05-04 05:27:27 -05:00
|
|
|
},
|
|
|
|
},{
|
|
|
|
id: 'tunnel_identity_file', label: gettext('Identity file'), type: 'text',
|
|
|
|
group: gettext('SSH Tunnel'), mode: ['properties'],
|
|
|
|
},{
|
|
|
|
id: 'tunnel_password', label: gettext('Password'), type: 'password',
|
|
|
|
group: gettext('SSH Tunnel'), control: 'input', mode: ['create'],
|
|
|
|
deps: ['use_ssh_tunnel'],
|
|
|
|
disabled: function(model) {
|
2019-06-05 01:37:24 -05:00
|
|
|
return !model.get('use_ssh_tunnel') || model.get('connected');
|
2018-05-04 05:27:27 -05:00
|
|
|
},
|
2018-08-06 05:26:46 -05:00
|
|
|
}, {
|
|
|
|
id: 'save_tunnel_password', controlLabel: gettext('Save password?'),
|
|
|
|
type: 'checkbox', group: gettext('SSH Tunnel'), mode: ['create'],
|
|
|
|
deps: ['connect_now', 'use_ssh_tunnel'], visible: function(model) {
|
|
|
|
return model.get('connect_now') && model.isNew();
|
|
|
|
},
|
|
|
|
disabled: function(model) {
|
|
|
|
if (!current_user.allow_save_tunnel_password ||
|
|
|
|
!model.get('use_ssh_tunnel'))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
},
|
2018-05-04 05:27:27 -05:00
|
|
|
}, {
|
2017-09-28 04:02:33 -05:00
|
|
|
id: 'hostaddr', label: gettext('Host address'), type: 'text', group: gettext('Advanced'),
|
2018-01-12 01:29:51 -06:00
|
|
|
mode: ['properties', 'edit', 'create'], disabled: 'isConnected',
|
2017-09-28 04:02:33 -05:00
|
|
|
},{
|
|
|
|
id: 'db_res', label: gettext('DB restriction'), type: 'select2', group: gettext('Advanced'),
|
|
|
|
mode: ['properties', 'edit', 'create'], disabled: 'isConnected', select2: {multiple: true, allowClear: false,
|
2018-01-12 01:29:51 -06:00
|
|
|
tags: true, tokenSeparators: [','], first_empty: false, selectOnClose: true, emptyOptions: true},
|
2017-09-28 04:02:33 -05:00
|
|
|
},{
|
2017-12-13 08:59:15 -06:00
|
|
|
id: 'passfile', label: gettext('Password file'), type: 'text',
|
2017-09-28 04:02:33 -05:00
|
|
|
group: gettext('Advanced'), mode: ['edit', 'create'],
|
2017-10-10 03:31:27 -05:00
|
|
|
disabled: 'isConnectedWithValidLib', control: Backform.FileControl,
|
2018-01-12 01:29:51 -06:00
|
|
|
dialog_type: 'select_file', supp_types: ['*'],
|
2017-09-28 04:02:33 -05:00
|
|
|
},{
|
2017-12-13 08:59:15 -06:00
|
|
|
id: 'passfile', label: gettext('Password file'), type: 'text',
|
2017-09-28 04:02:33 -05:00
|
|
|
group: gettext('Advanced'), mode: ['properties'],
|
2018-05-04 05:27:27 -05:00
|
|
|
visible: function(model) {
|
|
|
|
var passfile = model.get('passfile');
|
2017-09-28 04:02:33 -05:00
|
|
|
return !_.isUndefined(passfile) && !_.isNull(passfile);
|
2018-01-12 01:29:51 -06:00
|
|
|
},
|
2018-03-12 15:45:56 -05:00
|
|
|
},{
|
|
|
|
id: 'service', label: gettext('Service'), type: 'text',
|
|
|
|
mode: ['properties', 'edit', 'create'], disabled: 'isConnected',
|
|
|
|
group: gettext('Connection'),
|
2018-06-19 18:58:46 -05:00
|
|
|
},{
|
|
|
|
id: 'connect_timeout', label: gettext('Connection timeout (seconds)'),
|
|
|
|
type: 'int', group: gettext('Advanced'),
|
|
|
|
mode: ['properties', 'edit', 'create'], disabled: 'isConnected',
|
|
|
|
min: 0,
|
2015-06-30 00:51:55 -05:00
|
|
|
}],
|
2015-12-04 04:03:16 -06:00
|
|
|
validate: function() {
|
2018-03-13 13:47:32 -05:00
|
|
|
const validateModel = new modelValidation.ModelValidation(this);
|
|
|
|
return validateModel.validate();
|
2015-06-30 00:51:55 -05:00
|
|
|
},
|
2015-10-20 02:03:18 -05:00
|
|
|
isConnected: function(model) {
|
|
|
|
return model.get('connected');
|
2017-09-28 04:02:33 -05:00
|
|
|
},
|
2017-11-21 10:28:01 -06:00
|
|
|
isfgColorSet: function(model) {
|
|
|
|
var bgcolor = model.get('bgcolor'),
|
2018-01-12 01:29:51 -06:00
|
|
|
fgcolor = model.get('fgcolor');
|
2017-11-21 10:28:01 -06:00
|
|
|
|
|
|
|
if(model.get('connected')) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
// If fgcolor is set and bgcolor is not set then force bgcolor
|
|
|
|
// to set as white
|
|
|
|
if(_.isUndefined(bgcolor) || _.isNull(bgcolor) || !bgcolor) {
|
|
|
|
if(fgcolor) {
|
|
|
|
model.set('bgcolor', '#ffffff');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
},
|
2017-09-28 04:02:33 -05:00
|
|
|
isSSL: function(model) {
|
|
|
|
var ssl_mode = model.get('sslmode');
|
|
|
|
// If server is not connected and have required SSL option
|
|
|
|
if(model.get('connected')) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return _.indexOf(SSL_MODES, ssl_mode) == -1;
|
2017-10-10 03:31:27 -05:00
|
|
|
},
|
|
|
|
isConnectedWithValidLib: function(model) {
|
|
|
|
if(model.get('connected')) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
// older version of libpq do not support 'passfile' parameter in
|
|
|
|
// connect method, valid libpq must have version >= 100000
|
|
|
|
return pgBrowser.utils.pg_libpq_version < 100000;
|
2018-01-12 01:29:51 -06: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
|
|
|
|
);
|
2018-01-12 01:29:51 -06:00
|
|
|
Alertify.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
|
|
|
});
|
2018-01-12 01:29:51 -06:00
|
|
|
var connect_to_server = function(obj, data, tree, item, reconnect) {
|
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) {
|
|
|
|
tree.setInode(_item);
|
|
|
|
tree.addIcon(_item, {icon: 'icon-server-not-connected'});
|
|
|
|
}
|
2016-08-29 01:22:50 -05:00
|
|
|
|
2018-01-12 01:29:51 -06:00
|
|
|
Alertify.pgNotifier('error', xhr, error, function(msg) {
|
|
|
|
setTimeout(function() {
|
2019-05-28 01:30:18 -05:00
|
|
|
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();
|
|
|
|
}
|
2018-01-12 01:29:51 -06:00
|
|
|
}, 100);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
onSuccess = function(res, node, data, tree, item, _wasConnected) {
|
|
|
|
if (res && res.data) {
|
|
|
|
if (typeof res.data.icon == 'string') {
|
|
|
|
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
|
|
|
|
2018-01-12 01:29:51 -06: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 || {};
|
|
|
|
serverInfo[data._id] = _.extend({}, data);
|
2016-01-11 11:22:13 -06:00
|
|
|
|
2018-01-12 01:29:51 -06:00
|
|
|
Alertify.success(res.info);
|
|
|
|
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(
|
|
|
|
'pgadmin:server:connected', data._id, item, data
|
|
|
|
);
|
|
|
|
// Generate the event that database is connected
|
|
|
|
pgBrowser.Events.trigger(
|
|
|
|
'pgadmin:database:connected', data._id, data.db, item, data
|
|
|
|
);
|
2016-03-15 08:30:58 -05:00
|
|
|
|
2018-01-12 01:29:51 -06:00
|
|
|
// We're not reconnecting
|
|
|
|
if (!_wasConnected) {
|
|
|
|
tree.setInode(item);
|
|
|
|
tree.deselect(item);
|
2016-08-29 01:22:50 -05:00
|
|
|
|
2018-01-12 01:29:51 -06:00
|
|
|
setTimeout(function() {
|
|
|
|
tree.select(item);
|
|
|
|
tree.open(item);
|
|
|
|
}, 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(
|
|
|
|
title, message, node, data, tree, item,
|
|
|
|
_status, _onSuccess, _onFailure, _onCancel
|
|
|
|
) {
|
2015-10-20 02:03:18 -05:00
|
|
|
this.set('title', title);
|
|
|
|
this.message = message;
|
|
|
|
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
|
|
|
};
|
|
|
|
},
|
|
|
|
build:function() {},
|
|
|
|
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);
|
|
|
|
_tree.addIcon(_item, {icon: 'icon-server-not-connected'});
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
data.is_connecting = true;
|
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
|
|
|
);
|
2018-01-12 01:29:51 -06:00
|
|
|
});
|
|
|
|
};
|
2015-06-30 00:51:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return pgBrowser.Nodes['server'];
|
|
|
|
});
|