提交 c5e30fe2 编写于 作者: R rsercano

resolves #347, and improved tunnelSSH

上级 1d7ca582
......@@ -331,7 +331,7 @@
class="form-control">
<span class="input-group-addon"> Seconds</span>
</div>
<span class="help-block m-b-none">Enter to override <b>default</b> connection timeout <b>from settings</b></span>
<span class="help-block m-b-none">Enter to override <b>default</b> connection timeout <b>from settings</b>, <b>0</b> is infinite</span>
</div>
</div>
......@@ -347,7 +347,7 @@
class="form-control">
<span class="input-group-addon"> Seconds</span>
</div>
<span class="help-block m-b-none">Enter to override <b>default</b> socket timeout <b>from settings</b></span>
<span class="help-block m-b-none">Enter to override <b>default</b> socket timeout <b>from settings</b>, <b>0</b> is infinite</span>
</div>
</div>
......@@ -419,6 +419,26 @@
class="form-control">
</div>
</div>
<div class="form-group"><label class="col-lg-2 control-label">Destination Port</label>
<div class="col-lg-10"><input id="inputSshDestinationPort"
data-required="true"
min="1"
type="number"
placeholder="Destination port"
class="form-control">
<span class="help-block m-b-none">Remote <b>mongod/mongos</b> instance's port</span>
</div>
</div>
<div class="form-group"><label class="col-lg-2 control-label">Local Port</label>
<div class="col-lg-10"><input id="inputSshLocalPort"
data-required="true"
min="1"
type="number"
placeholder="Local port"
class="form-control">
<span class="help-block m-b-none">By default it's same as <b>MongoDB</b> port in the first tab, you can optionally set another port to <b>here</b> and <b>first tab</b></span>
</div>
</div>
<div class="form-group"><label
class="col-lg-2 control-label">Username</label>
<div class="col-lg-10"><input id="inputSshUsername"
......
......@@ -146,6 +146,8 @@ const fillFormBasicAuth = function (obj) {
const fillFormSsh = function (connection) {
$('#inputSshHostname').val(connection.ssh.host);
$('#inputSshPort').val(connection.ssh.port);
$('#inputSshLocalPort').val(connection.ssh.localPort);
$('#inputSshDestinationPort').val(connection.ssh.destinationPort);
$('#inputSshUsername').val(connection.ssh.username);
const certificateForm = $('#formSshCertificateAuth');
......@@ -355,11 +357,15 @@ const loadCertificate = function (currentVal, input, done) {
const fillSsh = function (connection) {
const port = $('#inputSshPort').val();
const localPort = $('#inputSshLocalPort').val();
const destinationPort = $('#inputSshDestinationPort').val();
connection.ssh = {
enabled: $('#inputUseSSH').iCheck('update')[0].checked,
host: $('#inputSshHostname').val(),
port: port ? parseInt(port) : '',
localPort: localPort ? parseInt(localPort) : '',
destinationPort: destinationPort ? parseInt(destinationPort) : '',
username: $('#inputSshUsername').val(),
certificateFileName: $('#inputSshCertificate').siblings('.bootstrap-filestyle').children('input').val(),
passPhrase: $('#inputSshPassPhrase').val(),
......@@ -440,7 +446,7 @@ const resetForm = function () {
$('#inputConnectionName, #inputUrl, #inputKerberosUsername, #inputKerberosPassword, #inputKerberosServiceName, ' +
'#inputLdapUsername, #inputLdapPassword, #inputConnectionTimeout, #inputSocketTimeout, #inputSshHostname, ' +
'#inputSshPort, #inputSshUsername, #inputSshPassPhrase, #inputSshPassword, #inputUser, #inputPassword, ' +
'#inputSshPort, #inputSshLocalPort, #inputSshDestinationPort, #inputSshUsername, #inputSshPassPhrase, #inputSshPassword, #inputUser, #inputPassword, ' +
'#inputAuthenticationDB, #inputPassPhrase, #inputX509Username').val('');
$('#inputDatabaseName').val('test');
$('#cmbAuthenticationType, #cmbSshAuthType, #cmbReadPreference').find('option').prop('selected', false).trigger('chosen:updated');
......
......@@ -687,7 +687,8 @@ Template.databaseStats.onDestroyed(function () {
Template.databaseStats.helpers({
isSubscribed (){
return Settings.findOne().subscribed;
const settings = Settings.findOne();
return settings ? settings.subscribed : false;
},
getServerStatus () {
......
......@@ -68,6 +68,7 @@ export const parseUrl = function (connection) {
};
const checkConnection = function (connection) {
LOGGER.info('[checkConnection]', JSON.stringify(connection));
if (connection.url) connection = parseUrl(connection);
if (connection.servers.length === 0) throw new Meteor.Error('At least one server is required !');
......@@ -81,6 +82,7 @@ const checkConnection = function (connection) {
if (connection.ssl && !connection.ssl.enabled) delete connection.ssl;
if (connection.ssh) {
if (!connection.ssh.enabled) delete connection.ssh;
if (!connection.ssh.destinationPort)throw new Meteor.Error('Destination port is required for SSH !');
if (!connection.ssh.username) throw new Meteor.Error('Username is required for SSH !');
if (!connection.ssh.host) throw new Meteor.Error('Host is required for SSH !');
if (!connection.ssh.port) throw new Meteor.Error('Port is required for SSH !');
......
......@@ -20,6 +20,7 @@ const os = require('os');
export let database;
let spawnedShell;
let tunnel;
const connectToShell = function (connectionId) {
try {
......@@ -103,6 +104,10 @@ const proceedConnectingMongodb = function (dbName, connectionUrl, connectionOpti
LOGGER.error(mainError, db);
done(mainError, db);
if (db) db.close();
if (tunnel) {
tunnel.close();
tunnel = null;
}
return;
}
database = db.db(dbName);
......@@ -113,10 +118,11 @@ const proceedConnectingMongodb = function (dbName, connectionUrl, connectionOpti
catch (ex) {
LOGGER.error('[connect]', ex);
done(new Meteor.Error(ex.message), null);
if (db) {
db.close();
if (db) db.close();
if (tunnel) {
tunnel.close();
tunnel = null;
}
}
});
};
......@@ -288,7 +294,8 @@ Meteor.methods({
try {
if (connection.ssh && connection.ssh.enabled) {
let config = {
dstPort: connection.port,
dstPort: connection.ssh.destinationPort,
localPort: connection.ssh.localPort ? connection.ssh.localPort : connection.servers[0].port,
host: connection.ssh.host,
port: connection.ssh.port,
username: connection.ssh.username
......@@ -298,7 +305,8 @@ Meteor.methods({
if (connection.ssh.passPhrase) config.passphrase = connection.ssh.passPhrase;
if (connection.ssh.password) config.password = connection.ssh.password;
const tunnel = tunnelSsh(config, Meteor.bindEnvironment(function (error) {
LOGGER.info('[connect]', '[ssh]', 'ssh is enabled, config is ' + JSON.stringify(config));
tunnel = tunnelSsh(config, Meteor.bindEnvironment(function (error) {
if (error) {
done(new Meteor.Error(error.message), null);
return;
......@@ -309,8 +317,10 @@ Meteor.methods({
}));
tunnel.on('error', function (err) {
if (err) {
done(new Meteor.Error(err.message), null);
if (err) done(new Meteor.Error(err.message), null);
if (tunnel) {
tunnel.close();
tunnel = null;
}
});
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册