Added SSH support in terminal tab for local devices.

Ylian Saint-Hilaire committed May 8, 2021 at 18:09 UTC 9b85a51f6758d78f024249c5838b61d0684ff6ef
6 files changed +273 -19
apprelays.js
+200 -2
@@ -229,6 +229,7 @@ module.exports.CreateSshRelay = function (parent, db, ws, req, args, domain) {
229 // Decode the authentication cookie
230 obj.cookie = parent.parent.decodeCookie(req.query.auth, parent.parent.loginCookieEncryptionKey);
231 if (obj.cookie == null) { obj.ws.send(JSON.stringify({ action: 'sessionerror' })); obj.close(); return; }
232 + console.log(obj.cookie);
233
234 // Start the looppback server
235 function startRelayConnection() {
@@ -258,7 +259,7 @@ module.exports.CreateSshRelay = function (parent, db, ws, req, args, domain) {
259 obj.sshShell = stream;
260 obj.sshShell.setWindow(obj.termSize.rows, obj.termSize.cols, obj.termSize.height, obj.termSize.width);
261 obj.sshShell.on('close', function () { obj.close(); });
261 - obj.sshShell.on('data', function (data) { obj.ws.send('~' + data); });
262 + obj.sshShell.on('data', function (data) { obj.ws.send('~' + data.toString()); });
263 });
264 obj.ws.send(JSON.stringify({ action: 'connected' }));
265 });
@@ -301,6 +302,7 @@ module.exports.CreateSshRelay = function (parent, db, ws, req, args, domain) {
302 if (typeof msg.action != 'string') return;
303 switch (msg.action) {
304 case 'connect': {
305 + // TODO: Verify inputs
306 obj.termSize = msg;
307 obj.username = msg.username;
308 obj.password = msg.password;
@@ -327,4 +329,200 @@ module.exports.CreateSshRelay = function (parent, db, ws, req, args, domain) {
329 ws.on('close', function (req) { parent.parent.debug('relay', 'SSH: Browser websocket closed'); obj.close(); });
330
331 return obj;
330 -};
\ No newline at end of file
332 +};
333 +
334 +
335 +// Construct a SSH Terminal Relay object, called upon connection
336 +module.exports.CreateSshTerminalRelay = function (parent, db, ws, req, domain, user, cookie, args) {
337 + const Net = require('net');
338 + const WebSocket = require('ws');
339 +
340 + // SerialTunnel object is used to embed SSH within another connection.
341 + function SerialTunnel(options) {
342 + var obj = new require('stream').Duplex(options);
343 + obj.forwardwrite = null;
344 + obj.updateBuffer = function (chunk) { this.push(chunk); };
345 + obj._write = function (chunk, encoding, callback) { if (obj.forwardwrite != null) { obj.forwardwrite(chunk); } if (callback) callback(); }; // Pass data written to forward
346 + obj._read = function (size) { }; // Push nothing, anything to read should be pushed from updateBuffer()
347 + obj.destroy = function () { delete obj.forwardwrite; }
348 + return obj;
349 + }
350 +
351 + const obj = {};
352 + obj.ws = ws;
353 + obj.relayActive = false;
354 +
355 + parent.parent.debug('relay', 'SSH: Request for SSH relay (' + req.clientIp + ')');
356 +
357 + // Disconnect
358 + obj.close = function (arg) {
359 + if (obj.ws == null) return;
360 +
361 + // Collect how many raw bytes where received and sent.
362 + // We sum both the websocket and TCP client in this case.
363 + //var inTraffc = obj.ws._socket.bytesRead, outTraffc = obj.ws._socket.bytesWritten;
364 + //if (obj.wsClient != null) { inTraffc += obj.wsClient._socket.bytesRead; outTraffc += obj.wsClient._socket.bytesWritten; }
365 + //console.log('WinSSH - in', inTraffc, 'out', outTraffc);
366 +
367 + if (obj.sshShell) {
368 + obj.sshShell.destroy();
369 + obj.sshShell.removeAllListeners('data');
370 + obj.sshShell.removeAllListeners('close');
371 + try { obj.sshShell.end(); } catch (ex) { console.log(ex); }
372 + delete obj.sshShell;
373 + }
374 + if (obj.sshClient) {
375 + obj.sshClient.destroy();
376 + obj.sshClient.removeAllListeners('ready');
377 + try { obj.sshClient.end(); } catch (ex) { console.log(ex); }
378 + delete obj.sshClient;
379 + }
380 + if (obj.wsClient) {
381 + obj.wsClient.removeAllListeners('open');
382 + obj.wsClient.removeAllListeners('message');
383 + obj.wsClient.removeAllListeners('close');
384 + try { obj.wsClient.close(); } catch (ex) { console.log(ex); }
385 + delete obj.wsClient;
386 + }
387 +
388 + if ((arg == 1) || (arg == null)) { try { ws.close(); } catch (e) { console.log(e); } } // Soft close, close the websocket
389 + if (arg == 2) { try { ws._socket._parent.end(); } catch (e) { console.log(e); } } // Hard close, close the TCP socket
390 + obj.ws.removeAllListeners();
391 +
392 + obj.relayActive = false;
393 + delete obj.termSize;
394 + delete obj.cookie;
395 + delete obj.ws;
396 + };
397 +
398 + // Start the looppback server
399 + function startRelayConnection(authCookie) {
400 + try {
401 + // Setup the correct URL with domain and use TLS only if needed.
402 + var options = { rejectUnauthorized: false };
403 + if (domain.dns != null) { options.servername = domain.dns; }
404 + var protocol = 'wss';
405 + if (args.tlsoffload) { protocol = 'ws'; }
406 + var domainadd = '';
407 + if ((domain.dns == null) && (domain.id != '')) { domainadd = domain.id + '/' }
408 + var url = protocol + '://127.0.0.1:' + args.port + '/' + domainadd + ((obj.mtype == 3) ? 'local' : 'mesh') + 'relay.ashx?noping=1&p=11&auth=' + authCookie // Protocol 11 is Web-SSH
409 + parent.parent.debug('relay', 'SSH: Connection websocket to ' + url);
410 + obj.wsClient = new WebSocket(url, options);
411 + obj.wsClient.on('open', function () { parent.parent.debug('relay', 'SSH: Relay websocket open'); });
412 + obj.wsClient.on('message', function (data) { // Make sure to handle flow control.
413 + if ((obj.relayActive == false) && (data == 'c')) {
414 + obj.relayActive = true;
415 +
416 + // Create a serial tunnel && SSH module
417 + obj.ser = new SerialTunnel();
418 + const Client = require('ssh2').Client;
419 + obj.sshClient = new Client();
420 + obj.sshClient.on('ready', function () { // Authentication was successful.
421 + obj.sshClient.shell(function (err, stream) { // Start a remote shell
422 + if (err) { obj.close(); return; }
423 + obj.sshShell = stream;
424 + obj.sshShell.setWindow(obj.termSize.rows, obj.termSize.cols, obj.termSize.height, obj.termSize.width);
425 + obj.sshShell.on('close', function () { obj.close(); });
426 + obj.sshShell.on('data', function (data) { obj.ws.send('~' + data.toString()); });
427 + });
428 + obj.ws.send('c');
429 + });
430 + obj.sshClient.on('error', function (err) {
431 + if (err.level == 'client-authentication') { obj.ws.send(JSON.stringify({ action: 'autherror' })); }
432 + obj.close();
433 + });
434 +
435 + // Setup the serial tunnel, SSH ---> Relay WS
436 + obj.ser.forwardwrite = function (data) { if ((data.length > 0) && (obj.wsClient != null)) { try { obj.wsClient.send(data); } catch (ex) { } } };
437 +
438 + // Connect the SSH module to the serial tunnel
439 + var connectionOptions = { sock: obj.ser }
440 + if (typeof obj.username == 'string') { connectionOptions.username = obj.username; delete obj.username; }
441 + if (typeof obj.password == 'string') { connectionOptions.password = obj.password; delete obj.password; }
442 + obj.sshClient.connect(connectionOptions);
443 +
444 + // We are all set, start receiving data
445 + ws._socket.resume();
446 + } else {
447 + // Relay WS --> SSH
448 + if ((data.length > 0) && (obj.ser != null)) { try { obj.ser.updateBuffer(data); } catch (ex) { console.log(ex); } }
449 + }
450 + });
451 + obj.wsClient.on('close', function () { parent.parent.debug('relay', 'SSH: Relay websocket closed'); obj.close(); });
452 + obj.wsClient.on('error', function (err) { parent.parent.debug('relay', 'SSH: Relay websocket error: ' + err); obj.close(); });
453 + } catch (ex) {
454 + console.log(ex);
455 + }
456 + }
457 +
458 + // When data is received from the web socket
459 + // SSH default port is 22
460 + ws.on('message', function (msg) {
461 + try {
462 + if (typeof msg != 'string') return;
463 + if (msg[0] == '{') {
464 + // Control data
465 + msg = JSON.parse(msg);
466 + if (typeof msg.action != 'string') return;
467 + switch (msg.action) {
468 + case 'sshauth': {
469 + // TODO: Verify inputs
470 + obj.termSize = msg;
471 + obj.username = msg.username;
472 + obj.password = msg.password;
473 +
474 + // Create a mesh relay authentication cookie
475 + var cookieContent = { userid: user._id, domainid: user.domain, nodeid: obj.nodeid, tcpport: obj.tcpport };
476 + if (obj.mtype == 3) { cookieContent.lc = 1; } // This is a local device
477 + startRelayConnection(parent.parent.encodeCookie(cookieContent, parent.parent.loginCookieEncryptionKey));
478 + break;
479 + }
480 + case 'resize': {
481 + obj.termSize = msg;
482 + if (obj.sshShell != null) { obj.sshShell.setWindow(obj.termSize.rows, obj.termSize.cols, obj.termSize.height, obj.termSize.width); }
483 + break;
484 + }
485 + }
486 + } else if (msg[0] == '~') {
487 + // Terminal data
488 + if (obj.sshShell != null) { obj.sshShell.write(msg.substring(1)); }
489 + }
490 + } catch (ex) { obj.close(); }
491 + });
492 +
493 + // If error, do nothing
494 + ws.on('error', function (err) { parent.parent.debug('relay', 'SSH: Browser websocket error: ' + err); obj.close(); });
495 +
496 + // If the web socket is closed
497 + ws.on('close', function (req) { parent.parent.debug('relay', 'SSH: Browser websocket closed'); obj.close(); });
498 +
499 + // Decode the authentication cookie
500 + var userCookie = parent.parent.decodeCookie(req.query.auth, parent.parent.loginCookieEncryptionKey);
501 + if ((userCookie == null) || (userCookie.a != null)) { obj.close(); return; } // Invalid cookie
502 +
503 + // Fetch the user
504 + var user = parent.users[userCookie.userid]
505 + if (user == null) { obj.close(); return; } // Invalid userid
506 +
507 + // Check that we have a nodeid
508 + if (req.query.nodeid == null) { obj.close(); return; } // Invalid nodeid
509 + parent.GetNodeWithRights(domain, user, req.query.nodeid, function (node, rights, visible) {
510 + // Check permissions
511 + if ((rights & 8) == 0) { obj.close(); return; } // No MESHRIGHT_REMOTECONTROL rights
512 + if ((rights != 0xFFFFFFFF) && (rights & 0x00000200)) { obj.close(); return; } // MESHRIGHT_NOTERMINAL is set
513 + obj.mtype = node.mtype; // Store the device group type
514 + obj.nodeid = node._id; // Store the NodeID
515 +
516 + // Check the SSH port
517 + obj.tcpport = 22;
518 + if (typeof node.sshport == 'number') { obj.tcpport = node.sshport; }
519 +
520 + // We are all set, start receiving data
521 + ws._socket.resume();
522 +
523 + // Send a request for SSH authentication
524 + try { ws.send(JSON.stringify({ action:'sshauth' })) } catch (ex) { }
525 + });
526 +
527 + return obj;
528 +};
public/mstsc/client.js
+1 -1
@@ -150,7 +150,7 @@
150 connect : function (ip, domain, username, password, next) {
151 // Start connection
152 var self = this;
153 - this.socket = new WebSocket('wss://' + window.location.host + '/mstsc/relay.ashx');
153 + this.socket = new WebSocket('wss://' + window.location.host + '/mstscrelay.ashx');
154 this.socket.binaryType = 'arraybuffer';
155 this.socket.onopen = function () {
156 //console.log("WS-OPEN");
public/scripts/agent-redir-ws-0.1.1.js
+3 -2
@@ -28,6 +28,7 @@ var CreateAgentRedirect = function (meshserver, module, serverPublicNamePort, au
28 obj.webrtc = null;
29 obj.debugmode = 0;
30 obj.serverIsRecording = false;
31 + obj.urlname = 'meshrelay.ashx';
32 obj.latency = { lastSend: null, current: -1, callback: null };
33 if (domainUrl == null) { domainUrl = '/'; }
34
@@ -43,7 +44,7 @@ var CreateAgentRedirect = function (meshserver, module, serverPublicNamePort, au
44 //obj.debug = function (msg) { console.log(msg); }
45
46 obj.Start = function (nodeid) {
46 - var url2, url = window.location.protocol.replace('http', 'ws') + '//' + window.location.host + window.location.pathname.substring(0, window.location.pathname.lastIndexOf('/')) + '/meshrelay.ashx?browser=1&p=' + obj.protocol + (nodeid?('&nodeid=' + nodeid):'') + '&id=' + obj.tunnelid;
47 + var url2, url = window.location.protocol.replace('http', 'ws') + '//' + window.location.host + window.location.pathname.substring(0, window.location.pathname.lastIndexOf('/')) + '/' + obj.urlname + '?browser=1&p=' + obj.protocol + (nodeid?('&nodeid=' + nodeid):'') + '&id=' + obj.tunnelid;
48 //if (serverPublicNamePort) { url2 = window.location.protocol.replace('http', 'ws') + '//' + serverPublicNamePort + '/meshrelay.ashx?id=' + obj.tunnelid; } else { url2 = url; }
49 if ((authCookie != null) && (authCookie != '')) { url += '&auth=' + authCookie; }
50 if ((urlargs != null) && (urlargs.slowrelay != null)) { url += '&slowrelay=' + urlargs.slowrelay; }
@@ -170,7 +171,7 @@ var CreateAgentRedirect = function (meshserver, module, serverPublicNamePort, au
171 // Control messages, most likely WebRTC setup
172 //console.log('New data', e.data.byteLength);
173 if (typeof e.data == 'string') {
173 - obj.xxOnControlCommand(e.data);
174 + if (e.data[0] == '~') { obj.m.ProcessData(e.data); } else { obj.xxOnControlCommand(e.data); }
175 } else {
176 // Send the data to the module
177 if (obj.m.ProcessBinaryCommand) {
views/default.handlebars
+58 -10
@@ -6265,7 +6265,11 @@
6265 }
6266
6267 // Attribute: Mesh Agent
6268 - if ((node.agent != null) && (node.agent.id != null) && (node.agent.ver != null)) {
6268 + if ((node.agent != null) && (node.agent.id != null) && (mesh.mtype == 3)) {
6269 + if (node.agent.id == 4) { x += addDeviceAttribute("Device Type", "Windows"); }
6270 + if (node.agent.id == 6) { x += addDeviceAttribute("Device Type", "Linux"); }
6271 + if (node.agent.id == 29) { x += addDeviceAttribute("Device Type", "macOS"); }
6272 + } else if ((node.agent != null) && (node.agent.id != null) && (node.agent.ver != null)) {
6273 var str = '';
6274 if (node.agent.id <= agentsStr.length) { str = agentsStr[node.agent.id]; } else { str = agentsStr[0]; }
6275 if (node.agent.ver != 0) { str += ' v' + node.agent.ver; }
@@ -6549,6 +6553,9 @@
6553 var consoleRights = ((meshrights & 16) != 0);
6554 if (consoleRights) { setupConsole(); } else { if (panel == 15) { panel = 10; } }
6555
6556 + // If we are looking at a local non-windows device, enable terminal capability.
6557 + if ((mesh.mtype == 3) && (node.agent != null) && (node.agent.id > 4)) { node.agent.caps = 2; }
6558 +
6559 // Show or hide the tabs
6560 // mesh.mtype: 1 = Intel AMT only, 2 = Mesh Agent, 3 = Local Device
6561 // node.agent.caps (bitmask): 1 = Desktop, 2 = Terminal, 4 = Files, 8 = Console
@@ -8541,13 +8548,12 @@
8548
8549 // Show and enable the right buttons
8550 function updateTerminalButtons() {
8544 - var mtype = (currentNode.agent == 1) ? 1 : 2;
8551 var termState = ((terminal != null) && (terminal.state != 0));
8552
8553 // Show the right buttons
8554 QV('disconnectbutton2span', (termState == true));
8555 QV('connectbutton2span', (termState == false) && (currentNode.agent != null) && (currentNode.agent.caps & 2));
8550 - if (mtype == 1) {
8556 + if (currentNode.mtype == 1) {
8557 QV('connectbutton2hspan', (termState == false) && (terminalNode.intelamt != null) && (terminalNode.intelamt.state == 2));
8558 QV('terminalSizeDropDown', (termState == false) && (terminalNode.intelamt != null) && (terminalNode.intelamt.state == 2));
8559 } else {
@@ -8555,8 +8561,11 @@
8561 QV('terminalSizeDropDown', (termState == false) && (terminalNode.intelamt != null) && (terminalNode.intelamt.state == 2) && (terminalNode.intelamt.ver != null));
8562 }
8563
8564 + // Enable action button if mesh type is not "local devices"
8565 + QV('termActionsBtn', currentNode.mtype != 3);
8566 +
8567 // Enable buttons
8559 - var online = ((terminalNode.conn & 1) != 0); // If Agent (1) connected, enable Terminal
8568 + var online = ((terminalNode.conn & 1) != 0) || (currentNode.mtype == 3); // If Agent (1) connected, enable Terminal
8569 QE('connectbutton2', online);
8570 var hwonline = ((terminalNode.conn & 6) != 0); // If CIRA (2) or AMT (4) connected, enable hardware terminal
8571 QE('connectbutton2h', hwonline);
@@ -8640,12 +8649,40 @@
8649 return obj;
8650 }
8651
8643 - function tunnelUpdate(data) { if (typeof data == 'string') { xterm.writeUtf8(data); } else { xterm.writeUtf8(new Uint8Array(data)); } }
8652 + function tunnelUpdate(data) {
8653 + if (typeof data == 'string') { xterm.writeUtf8(data); } else { xterm.writeUtf8(new Uint8Array(data)); }
8654 + }
8655 +
8656 + function sshTunnelUpdate(data) {
8657 + if (typeof data == 'string') {
8658 + if (data[0] == '{') {
8659 + var j = JSON.parse(data);
8660 + switch (j.action) {
8661 + case 'sshauth': {
8662 + var x = '';
8663 + x += addHtmlValue("Username", '<input id=dp2user style=width:230px maxlength=64 autocomplete=off onkeyup=sshAuthKeyUp(event) />');
8664 + x += addHtmlValue("Password", '<input type=password id=dp2pass style=width:230px maxlength=64 autocomplete=off onkeyup=sshAuthKeyUp(event) />');
8665 + setDialogMode(2, "Authentication", 3, sshConnectEx, x);
8666 + setTimeout(sshAuthKeyUp, 50);
8667 + }
8668 + }
8669 + } else if (data[0] == '~') { xterm.writeUtf8(data.substring(1)); }
8670 + }
8671 + }
8672 +
8673 + function sshAuthKeyUp(e) { QE('idx_dlgOkButton', (Q('dp2user').value.length > 0) && (Q('dp2pass').value.length > 0)); }
8674 + function sshConnectEx() { terminal.socket.send(JSON.stringify({ action: 'sshauth', username: Q('dp2user').value, password: Q('dp2pass').value, cols: xterm.cols, rows: xterm.rows, width: Q('termarea3xdiv').offsetWidth, height: Q('termarea3xdiv').offsetHeight })); }
8675
8676 // Send the new terminal size to the agent
8677 function xTermSendResize() {
8678 xtermResizeTimer = null;
8648 - if ((xterm != null) && (terminal != null) && (terminal.sendCtrlMsg != null)) { terminal.sendCtrlMsg(JSON.stringify({ ctrlChannel: '102938', type: 'termsize', cols: xterm.cols, rows: xterm.rows })); }
8679 + if ((xterm != null) && (terminal != null) && (terminal.sendCtrlMsg != null)) {
8680 + if (terminal.urlname == 'sshterminalrelay.ashx') {
8681 + terminal.socket.send(JSON.stringify({ action: 'resize', cols: xterm.cols, rows: xterm.rows, width: Q('termarea3xdiv').offsetWidth, height: Q('termarea3xdiv').offsetHeight }));
8682 + } else {
8683 + terminal.sendCtrlMsg(JSON.stringify({ ctrlChannel: '102938', type: 'termsize', cols: xterm.cols, rows: xterm.rows }));
8684 + }
8685 + }
8686 }
8687
8688 function connectTerminal(e, contype, options) {
@@ -8714,7 +8751,7 @@
8751 xterm = new Terminal();
8752 if (xtermfit) { xterm.loadAddon(xtermfit); }
8753 xterm.open(Q('termarea3xdiv')); // termarea3x
8717 - xterm.onData(function (data) { if (terminal != null) { terminal.sendText(data); } })
8754 + xterm.onData(function (data) { if (terminal != null) { if (terminal.urlname == 'sshterminalrelay.ashx') { terminal.socket.send('~' + data); } else { terminal.sendText(data); } } })
8755 if (xtermfit) { xtermfit.fit(); }
8756 xterm.onTitleChange(function (title) { QH('termtitle', ' - ' + EscapeHtml(title)); });
8757 xterm.onResize(function (size) {
@@ -8724,7 +8761,8 @@
8761 });
8762
8763 // Setup a terminal tunnel to the agent
8727 - terminal = CreateAgentRedirect(meshserver, CreateRemoteTunnel(tunnelUpdate, termoptions), serverPublicNamePort, authCookie, authRelayCookie, domainUrl);
8764 + terminal = CreateAgentRedirect(meshserver, CreateRemoteTunnel((currentNode.mtype == 3)? sshTunnelUpdate : tunnelUpdate, termoptions), serverPublicNamePort, authCookie, authRelayCookie, domainUrl);
8765 + if (currentNode.mtype == 3) { terminal.urlname = 'sshterminalrelay.ashx'; } // If this is a SSH session, change the URL to the SSH application relay.
8766 terminal.debugmode = debugmode;
8767 terminal.m.debugmode = debugmode;
8768 terminal.options = termoptions;
@@ -8808,7 +8846,10 @@
8846 function termSendKey(key, id) {
8847 if (!terminal || xxdialogMode) return;
8848 if (xterm != null) {
8811 - if (terminal.sendText) {
8849 + if (terminal.urlname == 'sshterminalrelay.ashx') {
8850 + // SSH
8851 + terminal.socket.send('~' + String.fromCharCode(key));
8852 + } else if (terminal.sendText) {
8853 // MeshAgent
8854 terminal.sendText(String.fromCharCode(key));
8855 } else {
@@ -8837,9 +8878,16 @@
8878 // Send special key
8879 function sendSpecialKey() {
8880 if (xterm != null) {
8840 - terminal.sendText(String.fromCharCode(Q('specialkeylist').value));
8881 + if (terminal.urlname == 'sshterminalrelay.ashx') {
8882 + // SSH
8883 + terminal.socket.send('~' + String.fromCharCode(Q('specialkeylist').value));
8884 + } else {
8885 + // Agent terminal
8886 + terminal.sendText(String.fromCharCode(Q('specialkeylist').value));
8887 + }
8888 xterm.focus();
8889 } else if (terminal != null) {
8890 + // Legacy terminal
8891 terminal.m.TermSendKey(Q('specialkeylist').value);
8892 Q('specialkeylist').blur();
8893 Q('specialkeylistinput').blur();
views/ssh.handlebars
+1 -1
@@ -138,7 +138,7 @@
138 user = Q('dp2user').value;
139 pass = Q('dp2pass').value;
140 state = 1;
141 - var url = window.location.protocol.replace('http', 'ws') + '//' + window.location.host + domainurl + 'ssh/relay.ashx?auth=' + cookie + (urlargs.key ? ('&key=' + urlargs.key) : '');
141 + var url = window.location.protocol.replace('http', 'ws') + '//' + window.location.host + domainurl + 'sshrelay.ashx?auth=' + cookie + (urlargs.key ? ('&key=' + urlargs.key) : '');
142 socket = new WebSocket(url);
143 socket.onopen = function (e) {
144 state = 2;
webserver.js
+10 -3
@@ -1901,12 +1901,14 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) {
1901 if ((obj.GetNodeRights(user, node.meshid, node._id) & MESHRIGHT_REMOTECONTROL) == 0) { res.sendStatus(401); return; }
1902
1903 // Figure out the target port
1904 - var port = 3389;
1904 + var port = 0;
1905 if (page == 'ssh') {
1906 // SSH port
1907 port = 22;
1908 + if (typeof node.sshport == 'number') { port = node.sshport; }
1909 } else {
1910 // RDP port
1911 + port = 3389;
1912 if (typeof node.rdpport == 'number') { port = node.rdpport; }
1913 }
1914 if (req.query.port != null) { var qport = 0; try { qport = parseInt(req.query.port); } catch (ex) { } if ((typeof qport == 'number') && (qport > 0) && (qport < 65536)) { port = qport; } }
@@ -5553,7 +5555,7 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) {
5555 // Setup MSTSC.js if needed
5556 if (domain.mstsc === true) {
5557 obj.app.get(url + 'mstsc.html', function (req, res) { handleMSTSCRequest(req, res, 'mstsc'); });
5556 - obj.app.ws(url + 'mstsc/relay.ashx', function (ws, req) {
5558 + obj.app.ws(url + 'mstscrelay.ashx', function (ws, req) {
5559 const domain = getDomain(req);
5560 if (domain == null) { parent.debug('web', 'mstsc: failed checks.'); try { ws.close(); } catch (e) { } return; }
5561 require('./apprelays.js').CreateMstscRelay(obj, obj.db, ws, req, obj.args, domain);
@@ -5563,13 +5565,18 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) {
5565 // Setup SSH if needed
5566 if (domain.ssh === true) {
5567 obj.app.get(url + 'ssh.html', function (req, res) { handleMSTSCRequest(req, res, 'ssh'); });
5566 - obj.app.ws(url + 'ssh/relay.ashx', function (ws, req) {
5568 + obj.app.ws(url + 'sshrelay.ashx', function (ws, req) {
5569 const domain = getDomain(req);
5570 if (domain == null) { parent.debug('web', 'ssh: failed checks.'); try { ws.close(); } catch (e) { } return; }
5571 try {
5572 require('./apprelays.js').CreateSshRelay(obj, obj.db, ws, req, obj.args, domain);
5573 } catch (ex) { console.log(ex); }
5574 });
5575 + obj.app.ws(url + 'sshterminalrelay.ashx', function (ws, req) {
5576 + PerformWSSessionAuth(ws, req, true, function (ws1, req1, domain, user, cookie) {
5577 + require('./apprelays.js').CreateSshTerminalRelay(obj, obj.db, ws1, req1, domain, user, cookie, obj.args);
5578 + });
5579 + });
5580 }
5581
5582 // Setup firebase push only server