Improved SSH error messages.
Ylian Saint-Hilaire committed
May 24, 2021 at 19:22 UTC
5757811b9c976a05e5ad09075ac7c940de78706d
2 files changed
+53
-7
apprelays.js
+14
-5
@@ -455,6 +455,8 @@ module.exports.CreateSshTerminalRelay = function (parent, db, ws, req, domain, u
455
obj.sshShell.on('close', function () { obj.close(); });
456
obj.sshShell.on('data', function (data) { obj.ws.send('~' + data.toString()); });
457
});
458
+
459
+ obj.connected = true;
460
obj.ws.send('c');
461
});
462
obj.sshClient.on('error', function (err) {
@@ -479,7 +481,10 @@ module.exports.CreateSshTerminalRelay = function (parent, db, ws, req, domain, u
481
if ((data.length > 0) && (obj.ser != null)) { try { obj.ser.updateBuffer(data); } catch (ex) { console.log(ex); } }
482
}
483
});
482
- obj.wsClient.on('close', function () { parent.parent.debug('relay', 'SSH: Relay websocket closed'); obj.close(); });
484
+ obj.wsClient.on('close', function () {
485
+ if (obj.connected !== true) { try { obj.ws.send(JSON.stringify({ action: 'connectionerror' })); } catch (ex) { } }
486
+ parent.parent.debug('relay', 'SSH: Relay websocket closed'); obj.close();
487
+ });
488
obj.wsClient.on('error', function (err) { parent.parent.debug('relay', 'SSH: Relay websocket error: ' + err); obj.close(); });
489
} catch (ex) {
490
console.log(ex);
@@ -700,11 +705,13 @@ module.exports.CreateSshFilesRelay = function (parent, db, ws, req, domain, user
705
if (obj.keep === true) saveSshCredentials();
706
obj.sshClient.sftp(function(err, sftp) {
707
if (err) { obj.close(); return; }
708
+ obj.connected = true;
709
obj.sftp = sftp;
710
obj.ws.send('c');
711
});
712
});
713
obj.sshClient.on('error', function (err) {
714
+ console.log('error', err);
715
if (err.level == 'client-authentication') { try { obj.ws.send(JSON.stringify({ action: 'autherror' })); } catch (ex) { } }
716
if (err.level == 'client-timeout') { try { obj.ws.send(JSON.stringify({ action: 'sessiontimeout' })); } catch (ex) { } }
717
obj.close();
@@ -726,7 +733,10 @@ module.exports.CreateSshFilesRelay = function (parent, db, ws, req, domain, user
733
if ((data.length > 0) && (obj.ser != null)) { try { obj.ser.updateBuffer(data); } catch (ex) { console.log(ex); } }
734
}
735
});
729
- obj.wsClient.on('close', function () { parent.parent.debug('relay', 'SSH: Files relay websocket closed'); obj.close(); });
736
+ obj.wsClient.on('close', function () {
737
+ if (obj.connected !== true) { try { obj.ws.send(JSON.stringify({ action: 'connectionerror' })); } catch (ex) { } }
738
+ parent.parent.debug('relay', 'SSH: Files relay websocket closed'); obj.close();
739
+ });
740
obj.wsClient.on('error', function (err) { parent.parent.debug('relay', 'SSH: Files relay websocket error: ' + err); obj.close(); });
741
} catch (ex) {
742
console.log(ex);
@@ -736,7 +746,7 @@ module.exports.CreateSshFilesRelay = function (parent, db, ws, req, domain, user
746
// When data is received from the web socket
747
// SSH default port is 22
748
ws.on('message', function (msg) {
739
- if ((obj.firstMessage === true) && (msg != 5)) { obj.close(); return; } else { delete obj.firstMessage; }
749
+ //if ((obj.firstMessage === true) && (msg != 5)) { obj.close(); return; } else { delete obj.firstMessage; }
750
try {
751
if (typeof msg != 'string') {
752
if (msg[0] == 123) {
@@ -904,9 +914,8 @@ module.exports.CreateSshFilesRelay = function (parent, db, ws, req, domain, user
914
915
// Verify inputs
916
if ((typeof msg.username != 'string') || (typeof msg.password != 'string')) break;
907
- if ((typeof msg.rows != 'number') || (typeof msg.cols != 'number') || (typeof msg.height != 'number') || (typeof msg.width != 'number')) break;
917
909
- obj.keep = msg.keep; // If true, keep store credentials on the server if the SSH tunnel connected succesfully.
918
+ obj.keep = (msg.keep === true); // If true, keep store credentials on the server if the SSH tunnel connected succesfully.
919
obj.username = msg.username;
920
obj.password = msg.password;
921
views/default.handlebars
+39
-2
@@ -699,8 +699,8 @@
699
<div id="idx_termFullBtn2" onclick=deskToggleFull(event)> ✖</div>
700
<input type="button" id="autoconnectbutton2" value="AutoConnect" onclick=autoConnectTerminal(event) onkeypress="return false" onkeydown="return false" style="display:none" />
701
<span id="connectbutton2span"><input type="button" id="connectbutton2" cmenu="termConnectButton" value="Connect" onclick=connectTerminal(event,1) onkeypress="return false" onkeydown="return false" disabled="disabled" /></span>
702
- <span id="connectbutton2hspan"> <input type="button" id="connectbutton2h" value="HW Connect" title="Connect using Intel® AMT hardware KVM" onclick=connectTerminal(event,2) onkeypress="return false" onkeydown="return false" disabled="disabled" /></span>
703
- <span id="disconnectbutton2span"> <input type="button" id="disconnectbutton2" value="Disconnect" onclick=connectTerminal(event,0) onkeypress="return false" onkeydown="return false" /></span>
702
+ <span id="connectbutton2hspan"><input type="button" id="connectbutton2h" value="HW Connect" title="Connect using Intel® AMT hardware KVM" onclick=connectTerminal(event,2) onkeypress="return false" onkeydown="return false" disabled="disabled" /></span>
703
+ <span id="disconnectbutton2span"><input type="button" id="disconnectbutton2" value="Disconnect" onclick=connectTerminal(event,0) onkeypress="return false" onkeydown="return false" /></span>
704
<span id="termstatus" style="line-height:22px">Disconnected</span><span id="termtitle"></span>
705
</div>
706
</td>
@@ -7830,6 +7830,17 @@
7830
}
7831
}
7832
7833
+ function p13setConsoleMsg(msg, timeout) {
7834
+ if (msg) {
7835
+ Q('p13FilesConsoleMsg').innerHTML += msg;
7836
+ QV('p13FilesConsoleMsg', true);
7837
+ if (p13FilesConsoleMsgTimer != null) { clearTimeout(p13FilesConsoleMsgTimer); }
7838
+ if (timeout) { p13FilesConsoleMsgTimer = setTimeout(p13clearConsoleMsg, timeout); }
7839
+ } else {
7840
+ p13clearConsoleMsg();
7841
+ }
7842
+ }
7843
+
7844
var webRtcDesktop = null;
7845
function webRtcDesktopReset() {
7846
if (webRtcDesktop == null) return;
@@ -8715,6 +8726,7 @@
8726
terminal.socket.send(JSON.stringify({ action: 'sshautoauth', cols: xterm.cols, rows: xterm.rows, width: Q('termarea3xdiv').offsetWidth, height: Q('termarea3xdiv').offsetHeight }));
8727
break;
8728
}
8729
+ case 'connectionerror': { p12setConsoleMsg("Connection Error", 5000); break; }
8730
case 'autherror': { p12setConsoleMsg("Authentication Error", 5000); break; }
8731
case 'sessionerror': { p12setConsoleMsg("Session expired", 5000); break; }
8732
case 'sessiontimeout': { p12setConsoleMsg("Session timeout", 5000); break; }
@@ -9053,6 +9065,23 @@
9065
// Process file upload commands
9066
if ((data.action != null) && (data.action.startsWith('upload'))) { p13gotUploadData(data); return; }
9067
9068
+ // Process any SSH actions
9069
+ switch (data.action) {
9070
+ case 'sshauth': {
9071
+ var x = '';
9072
+ x += addHtmlValue("Username", '<input id=dp2user style=width:230px maxlength=64 autocomplete=off onkeyup=sshAuthKeyUp(event) />');
9073
+ x += addHtmlValue("Password", '<input type=password id=dp2pass style=width:230px maxlength=64 autocomplete=off onkeyup=sshAuthKeyUp(event) />');
9074
+ x += addHtmlValue('', '<label><input id=dp2keep type=checkbox>' + "Remember credentials" + '</label>');
9075
+ setDialogMode(2, "Authentication", 11, p13sshConnectEx, x, 'ssh');
9076
+ setTimeout(sshAuthKeyUp, 50);
9077
+ return;
9078
+ }
9079
+ case 'autherror': { p13setConsoleMsg("Authentication Error", 5000); return; }
9080
+ case 'connectionerror': { p13setConsoleMsg("Connection Error", 5000); return; }
9081
+ case 'sessionerror': { p13setConsoleMsg("Session expired", 5000); return; }
9082
+ case 'sessiontimeout': { p13setConsoleMsg("Session timeout", 5000); return; }
9083
+ }
9084
+
9085
// Display a dialog message
9086
if (data.action == 'dialogmessage') {
9087
if ((data.msg == null) && (xxdialogTag == 'fileMsgDialog')) {
@@ -9091,6 +9120,14 @@
9120
}
9121
}
9122
9123
+ function p13sshConnectEx(b) {
9124
+ if (b == 0) {
9125
+ if (files != null) { connectFiles(); } // Disconnect
9126
+ } else {
9127
+ files.socket.send(JSON.stringify({ action: 'sshauth', username: Q('dp2user').value, password: Q('dp2pass').value, keep: Q('dp2keep').checked }));
9128
+ }
9129
+ }
9130
+
9131
function p13getCheckedNames() {
9132
// Save all existing checked boxes
9133
var checkedNames = [], checkboxes = document.getElementsByName('fd');