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
|
|
|
},{
|
2017-06-07 05:23:02 -05: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,
|
|
|
|
applies: ['file'], callback: 'change_password',
|
2017-06-07 05:23:02 -05:00
|
|
|
label: gettext('Change Password...'),
|
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',
|
|
|
|
}]);
|
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',
|
|
|
|
success: function(res) {
|
|
|
|
if (res.success == 1) {
|
2018-01-12 01:29:51 -06:00
|
|
|
Alertify.success(res.info);
|
2016-08-29 01:22:50 -05:00
|
|
|
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) {
|
2018-01-12 01:29:51 -06:00
|
|
|
delete pgBrowser.serverInfo[d._id];
|
2016-04-18 07:39:25 -05:00
|
|
|
}
|
2017-04-10 03:35:21 -05:00
|
|
|
pgBrowser.enable_disable_menus(i);
|
2017-04-12 09:46:31 -05:00
|
|
|
// Trigger server disconnect event
|
|
|
|
pgBrowser.Events.trigger(
|
|
|
|
'pgadmin:server:disconnect',
|
|
|
|
{item: i, data: d}, false
|
|
|
|
);
|
2016-08-29 01:22:50 -05:00
|
|
|
}
|
|
|
|
else {
|
2015-10-20 02:03:18 -05:00
|
|
|
try {
|
2018-01-12 01:29:51 -06:00
|
|
|
Alertify.error(res.errormsg);
|
|
|
|
} catch (e) {
|
|
|
|
console.warn(e.stack || e);
|
|
|
|
}
|
2015-10-20 02:03:18 -05:00
|
|
|
t.unload(i);
|
|
|
|
}
|
2016-08-29 01:22:50 -05:00
|
|
|
},
|
2018-01-12 01:29:51 -06:00
|
|
|
error: function(xhr) {
|
2016-08-29 01:22:50 -05:00
|
|
|
try {
|
|
|
|
var err = $.parseJSON(xhr.responseText);
|
|
|
|
if (err.success == 0) {
|
2018-01-12 01:29:51 -06:00
|
|
|
Alertify.error(err.errormsg);
|
2016-08-29 01:22:50 -05:00
|
|
|
}
|
2018-01-12 01:29:51 -06:00
|
|
|
} catch (e) {
|
|
|
|
console.warn(e.stack || e);
|
|
|
|
}
|
2016-08-29 01:22:50 -05:00
|
|
|
t.unload(i);
|
2018-01-12 01:29:51 -06: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',
|
|
|
|
success: function(res) {
|
|
|
|
if (res.data.status) {
|
2018-01-12 01:29:51 -06:00
|
|
|
Alertify.success(res.data.result);
|
2016-05-06 09:08:22 -05:00
|
|
|
}
|
|
|
|
else {
|
2018-01-12 01:29:51 -06:00
|
|
|
Alertify.error(res.data.result);
|
2016-05-06 09:08:22 -05:00
|
|
|
}
|
|
|
|
},
|
2018-01-12 01:29:51 -06:00
|
|
|
error: function(xhr) {
|
2016-05-06 09:08:22 -05:00
|
|
|
try {
|
|
|
|
var err = $.parseJSON(xhr.responseText);
|
|
|
|
if (err.success == 0) {
|
2018-01-12 01:29:51 -06:00
|
|
|
Alertify.error(err.errormsg);
|
2016-05-06 09:08:22 -05:00
|
|
|
}
|
2018-01-12 01:29:51 -06:00
|
|
|
} catch (e) {
|
|
|
|
console.warn(e.stack || e);
|
|
|
|
}
|
2016-05-06 09:08:22 -05:00
|
|
|
t.unload(i);
|
2018-01-12 01:29:51 -06:00
|
|
|
},
|
2016-05-06 09:08:22 -05:00
|
|
|
});
|
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) },
|
|
|
|
success: function(res) {
|
|
|
|
Alertify.success(res.data.result, 10);
|
|
|
|
},
|
|
|
|
error: function(xhr) {
|
|
|
|
try {
|
|
|
|
var err = $.parseJSON(xhr.responseText);
|
|
|
|
if (err.success == 0) {
|
|
|
|
Alertify.error(err.errormsg, 10);
|
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
console.warn(e.stack || e);
|
2016-05-11 10:13:04 -05:00
|
|
|
}
|
2018-01-12 01:29:51 -06:00
|
|
|
t.unload(i);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
} 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: [{
|
2017-12-13 07:28:07 -06:00
|
|
|
text: gettext('Ok'), key: 13, className: 'btn btn-primary',
|
2018-01-12 01:29:51 -06:00
|
|
|
attrs:{name:'submit'},
|
2017-12-13 07:28:07 -06:00
|
|
|
},{
|
|
|
|
text: gettext('Cancel'), key: 27, className: 'btn btn-danger',
|
2018-01-12 01:29:51 -06:00
|
|
|
attrs:{name:'cancel'},
|
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
|
2016-05-13 02:51:20 -05:00
|
|
|
this.__internal.buttons[0].element.disabled = true;
|
|
|
|
|
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 == '') {
|
|
|
|
self.__internal.buttons[0].element.disabled = true;
|
|
|
|
} else if (newPassword != confirmPassword) {
|
|
|
|
self.__internal.buttons[0].element.disabled = true;
|
|
|
|
|
|
|
|
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();
|
|
|
|
self.__internal.buttons[0].element.disabled = false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
// 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) },
|
|
|
|
success: function(res) {
|
|
|
|
if (res.success) {
|
2017-12-13 07:28:07 -06:00
|
|
|
// Notify user to update pgpass file
|
|
|
|
if(is_pgpass_file_used) {
|
2018-01-12 01:29:51 -06:00
|
|
|
Alertify.alert(
|
|
|
|
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')
|
2017-12-13 07:28:07 -06:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-01-12 01:29:51 -06:00
|
|
|
Alertify.success(res.info);
|
2016-05-13 02:51:20 -05:00
|
|
|
self.close();
|
|
|
|
} else {
|
2018-01-12 01:29:51 -06:00
|
|
|
Alertify.error(res.errormsg);
|
2016-05-13 02:51:20 -05:00
|
|
|
}
|
|
|
|
},
|
2018-01-12 01:29:51 -06:00
|
|
|
error: function(xhr) {
|
2016-05-13 02:51:20 -05:00
|
|
|
try {
|
|
|
|
var err = $.parseJSON(xhr.responseText);
|
|
|
|
if (err.success == 0) {
|
2018-01-12 01:29:51 -06:00
|
|
|
Alertify.error(err.errormsg);
|
2016-05-13 02:51:20 -05:00
|
|
|
}
|
2018-01-12 01:29:51 -06:00
|
|
|
} catch (e) {
|
|
|
|
console.warn(e.stack || e);
|
|
|
|
}
|
|
|
|
},
|
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',
|
|
|
|
success: function(res) {
|
|
|
|
if (res.success && res.data.is_pgpass) {
|
|
|
|
is_pgpass_file_used = true;
|
|
|
|
}
|
2018-01-12 01:29:51 -06:00
|
|
|
Alertify.changeServerPassword(d).resizeTo('40%','52%');
|
2017-12-13 07:28:07 -06:00
|
|
|
},
|
2018-01-12 01:29:51 -06:00
|
|
|
error: function(xhr) {
|
2017-12-13 07:28:07 -06:00
|
|
|
try {
|
|
|
|
var err = $.parseJSON(xhr.responseText);
|
|
|
|
if (err.success == 0) {
|
2018-01-12 01:29:51 -06:00
|
|
|
Alertify.error(err.errormsg);
|
2017-12-13 07:28:07 -06:00
|
|
|
}
|
2018-01-12 01:29:51 -06:00
|
|
|
} catch (e) {
|
|
|
|
console.warn(e.stack || e);
|
|
|
|
}
|
|
|
|
},
|
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',
|
2016-05-13 15:09:39 -05:00
|
|
|
success: function(res) {
|
|
|
|
if (res.success == 1) {
|
2018-01-12 01:29:51 -06:00
|
|
|
Alertify.success(res.info);
|
2016-05-13 15:09:39 -05:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
},
|
2018-01-12 01:29:51 -06:00
|
|
|
error: function(xhr) {
|
2016-05-13 15:09:39 -05:00
|
|
|
try {
|
|
|
|
var err = $.parseJSON(xhr.responseText);
|
|
|
|
if (err.success == 0) {
|
2018-01-12 01:29:51 -06:00
|
|
|
Alertify.error(err.errormsg);
|
2016-05-13 15:09:39 -05:00
|
|
|
}
|
2018-01-12 01:29:51 -06:00
|
|
|
} catch (e) {
|
|
|
|
console.warn(e.stack || e);
|
|
|
|
}
|
2016-05-13 15:09:39 -05:00
|
|
|
t.unload(i);
|
2018-01-12 01:29:51 -06: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',
|
2016-05-13 15:09:39 -05:00
|
|
|
success: function(res) {
|
|
|
|
if (res.success == 1) {
|
2018-01-12 01:29:51 -06:00
|
|
|
Alertify.success(res.info);
|
2016-05-13 15:09:39 -05:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
},
|
2018-01-12 01:29:51 -06:00
|
|
|
error: function(xhr) {
|
2016-05-13 15:09:39 -05:00
|
|
|
try {
|
|
|
|
var err = $.parseJSON(xhr.responseText);
|
|
|
|
if (err.success == 0) {
|
2018-01-12 01:29:51 -06:00
|
|
|
Alertify.error(err.errormsg);
|
2016-05-13 15:09:39 -05:00
|
|
|
}
|
2018-01-12 01:29:51 -06:00
|
|
|
} catch (e) {
|
|
|
|
console.warn(e.stack || e);
|
|
|
|
}
|
2016-05-13 15:09:39 -05:00
|
|
|
t.unload(i);
|
2018-01-12 01:29:51 -06:00
|
|
|
},
|
|
|
|
});
|
|
|
|
},
|
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,
|
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': {
|
2017-11-06 18:49:11 -06:00
|
|
|
'onText': gettext('True'), 'offText': gettext('False'), 'onColor': 'success',
|
2018-01-12 01:29:51 -06:00
|
|
|
'offColor': 'danger', 'size': 'small',
|
|
|
|
},
|
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-01-12 01:29:51 -06:00
|
|
|
mode: ['properties', 'edit', 'create'], disabled: 'isConnected', min: 1024, 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'],
|
2016-06-14 11:23:25 -05:00
|
|
|
visible: function(m) {
|
|
|
|
return m.get('connect_now') && m.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'],
|
|
|
|
deps: ['connect_now'], visible: function(m) {
|
2016-08-03 09:55:45 -05:00
|
|
|
return m.get('connect_now') && m.isNew();
|
2017-03-31 19:14:37 -05:00
|
|
|
},
|
2018-01-12 01:29:51 -06:00
|
|
|
disabled: function() {
|
2017-07-06 07:33:46 -05:00
|
|
|
return !current_user.allow_save_password;
|
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'),
|
2017-11-06 18:49:11 -06:00
|
|
|
'options': { 'onText': gettext('True'), 'offText': gettext('False'),
|
2018-01-12 01:29:51 -06:00
|
|
|
'onColor': 'success', 'offColor': 'danger', 'size': 'small'},
|
|
|
|
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'],
|
|
|
|
visible: function(m) {
|
|
|
|
var sslcert = m.get('sslcert');
|
|
|
|
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'],
|
|
|
|
visible: function(m) {
|
|
|
|
var sslkey = m.get('sslkey');
|
|
|
|
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'],
|
|
|
|
visible: function(m) {
|
|
|
|
var sslrootcert = m.get('sslrootcert');
|
|
|
|
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'],
|
|
|
|
visible: function(m) {
|
|
|
|
var sslcrl = m.get('sslcrl');
|
|
|
|
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'),
|
2017-11-06 18:49:11 -06:00
|
|
|
'options': { 'onText': gettext('True'), 'offText': gettext('False'),
|
2018-01-12 01:29:51 -06:00
|
|
|
'onColor': 'success', 'offColor': 'danger', 'size': 'small'},
|
2017-09-28 04:02:33 -05:00
|
|
|
deps: ['sslmode'], visible: function(m) {
|
|
|
|
var sslmode = m.get('sslmode');
|
|
|
|
return _.indexOf(SSL_MODES, sslmode) != -1;
|
2018-01-12 01:29:51 -06: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'],
|
|
|
|
visible: function(m) {
|
|
|
|
var passfile = m.get('passfile');
|
|
|
|
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'),
|
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() {
|
|
|
|
Alertify.dlgServerPass(
|
|
|
|
gettext('Connect to Server'),
|
|
|
|
msg, _node, _data, _tree, _item, _wasConnected
|
|
|
|
).resizeTo();
|
|
|
|
}, 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:[{
|
|
|
|
text: gettext('OK'), key: 13, className: 'btn btn-primary',
|
|
|
|
},{
|
|
|
|
text: gettext('Cancel'), className: 'btn btn-danger',
|
|
|
|
}],
|
|
|
|
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(),
|
|
|
|
success: function(res) {
|
2016-08-29 01:22:50 -05:00
|
|
|
return _onSuccess(
|
|
|
|
res, _node, _data, _tree, _item, _status
|
2018-01-12 01:29:51 -06:00
|
|
|
);
|
2015-10-20 02:03:18 -05:00
|
|
|
},
|
|
|
|
error: function(xhr, status, error) {
|
2016-08-29 01:22:50 -05:00
|
|
|
return _onFailure(
|
|
|
|
xhr, status, error, _node, _data, _tree, _item, _status
|
2018-01-12 01:29:51 -06:00
|
|
|
);
|
|
|
|
},
|
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'];
|
|
|
|
});
|