diff --git a/apprelays.js b/apprelays.js index d02ba1ce..0cb0c7be 100644 --- a/apprelays.js +++ b/apprelays.js @@ -455,6 +455,8 @@ module.exports.CreateSshTerminalRelay = function (parent, db, ws, req, domain, u obj.sshShell.on('close', function () { obj.close(); }); obj.sshShell.on('data', function (data) { obj.ws.send('~' + data.toString()); }); }); + + obj.connected = true; obj.ws.send('c'); }); obj.sshClient.on('error', function (err) { @@ -479,7 +481,10 @@ module.exports.CreateSshTerminalRelay = function (parent, db, ws, req, domain, u if ((data.length > 0) && (obj.ser != null)) { try { obj.ser.updateBuffer(data); } catch (ex) { console.log(ex); } } } }); - obj.wsClient.on('close', function () { parent.parent.debug('relay', 'SSH: Relay websocket closed'); obj.close(); }); + obj.wsClient.on('close', function () { + if (obj.connected !== true) { try { obj.ws.send(JSON.stringify({ action: 'connectionerror' })); } catch (ex) { } } + parent.parent.debug('relay', 'SSH: Relay websocket closed'); obj.close(); + }); obj.wsClient.on('error', function (err) { parent.parent.debug('relay', 'SSH: Relay websocket error: ' + err); obj.close(); }); } catch (ex) { console.log(ex); @@ -700,11 +705,13 @@ module.exports.CreateSshFilesRelay = function (parent, db, ws, req, domain, user if (obj.keep === true) saveSshCredentials(); obj.sshClient.sftp(function(err, sftp) { if (err) { obj.close(); return; } + obj.connected = true; obj.sftp = sftp; obj.ws.send('c'); }); }); obj.sshClient.on('error', function (err) { + console.log('error', err); if (err.level == 'client-authentication') { try { obj.ws.send(JSON.stringify({ action: 'autherror' })); } catch (ex) { } } if (err.level == 'client-timeout') { try { obj.ws.send(JSON.stringify({ action: 'sessiontimeout' })); } catch (ex) { } } obj.close(); @@ -726,7 +733,10 @@ module.exports.CreateSshFilesRelay = function (parent, db, ws, req, domain, user if ((data.length > 0) && (obj.ser != null)) { try { obj.ser.updateBuffer(data); } catch (ex) { console.log(ex); } } } }); - obj.wsClient.on('close', function () { parent.parent.debug('relay', 'SSH: Files relay websocket closed'); obj.close(); }); + obj.wsClient.on('close', function () { + if (obj.connected !== true) { try { obj.ws.send(JSON.stringify({ action: 'connectionerror' })); } catch (ex) { } } + parent.parent.debug('relay', 'SSH: Files relay websocket closed'); obj.close(); + }); obj.wsClient.on('error', function (err) { parent.parent.debug('relay', 'SSH: Files relay websocket error: ' + err); obj.close(); }); } catch (ex) { console.log(ex); @@ -736,7 +746,7 @@ module.exports.CreateSshFilesRelay = function (parent, db, ws, req, domain, user // When data is received from the web socket // SSH default port is 22 ws.on('message', function (msg) { - if ((obj.firstMessage === true) && (msg != 5)) { obj.close(); return; } else { delete obj.firstMessage; } + //if ((obj.firstMessage === true) && (msg != 5)) { obj.close(); return; } else { delete obj.firstMessage; } try { if (typeof msg != 'string') { if (msg[0] == 123) { @@ -904,9 +914,8 @@ module.exports.CreateSshFilesRelay = function (parent, db, ws, req, domain, user // Verify inputs if ((typeof msg.username != 'string') || (typeof msg.password != 'string')) break; - if ((typeof msg.rows != 'number') || (typeof msg.cols != 'number') || (typeof msg.height != 'number') || (typeof msg.width != 'number')) break; - obj.keep = msg.keep; // If true, keep store credentials on the server if the SSH tunnel connected succesfully. + obj.keep = (msg.keep === true); // If true, keep store credentials on the server if the SSH tunnel connected succesfully. obj.username = msg.username; obj.password = msg.password; diff --git a/views/default.handlebars b/views/default.handlebars index 781e65ff..1b1b1d5c 100644 --- a/views/default.handlebars +++ b/views/default.handlebars @@ -699,8 +699,8 @@
 ✖
-   -   + + Disconnected @@ -7830,6 +7830,17 @@ } } + function p13setConsoleMsg(msg, timeout) { + if (msg) { + Q('p13FilesConsoleMsg').innerHTML += msg; + QV('p13FilesConsoleMsg', true); + if (p13FilesConsoleMsgTimer != null) { clearTimeout(p13FilesConsoleMsgTimer); } + if (timeout) { p13FilesConsoleMsgTimer = setTimeout(p13clearConsoleMsg, timeout); } + } else { + p13clearConsoleMsg(); + } + } + var webRtcDesktop = null; function webRtcDesktopReset() { if (webRtcDesktop == null) return; @@ -8715,6 +8726,7 @@ terminal.socket.send(JSON.stringify({ action: 'sshautoauth', cols: xterm.cols, rows: xterm.rows, width: Q('termarea3xdiv').offsetWidth, height: Q('termarea3xdiv').offsetHeight })); break; } + case 'connectionerror': { p12setConsoleMsg("Connection Error", 5000); break; } case 'autherror': { p12setConsoleMsg("Authentication Error", 5000); break; } case 'sessionerror': { p12setConsoleMsg("Session expired", 5000); break; } case 'sessiontimeout': { p12setConsoleMsg("Session timeout", 5000); break; } @@ -9053,6 +9065,23 @@ // Process file upload commands if ((data.action != null) && (data.action.startsWith('upload'))) { p13gotUploadData(data); return; } + // Process any SSH actions + switch (data.action) { + case 'sshauth': { + var x = ''; + x += addHtmlValue("Username", ''); + x += addHtmlValue("Password", ''); + x += addHtmlValue('', ''); + setDialogMode(2, "Authentication", 11, p13sshConnectEx, x, 'ssh'); + setTimeout(sshAuthKeyUp, 50); + return; + } + case 'autherror': { p13setConsoleMsg("Authentication Error", 5000); return; } + case 'connectionerror': { p13setConsoleMsg("Connection Error", 5000); return; } + case 'sessionerror': { p13setConsoleMsg("Session expired", 5000); return; } + case 'sessiontimeout': { p13setConsoleMsg("Session timeout", 5000); return; } + } + // Display a dialog message if (data.action == 'dialogmessage') { if ((data.msg == null) && (xxdialogTag == 'fileMsgDialog')) { @@ -9091,6 +9120,14 @@ } } + function p13sshConnectEx(b) { + if (b == 0) { + if (files != null) { connectFiles(); } // Disconnect + } else { + files.socket.send(JSON.stringify({ action: 'sshauth', username: Q('dp2user').value, password: Q('dp2pass').value, keep: Q('dp2keep').checked })); + } + } + function p13getCheckedNames() { // Save all existing checked boxes var checkedNames = [], checkboxes = document.getElementsByName('fd');