Added full agent ping/pong support on RDP sessions.

Ylian Saint-Hilaire committed May 5, 2022 at 13:17 UTC 93e8f2cdcf1067634908aabeb607a227404ccfbc
2 files changed +186 -161
apprelays.js
+184 -161
@@ -116,7 +116,16 @@ module.exports.CreateMstscRelay = function (parent, db, ws, req, args, domain) {
116 obj.relaySocket.resume();
117 }
118 } else {
119 - if (typeof data == 'string') return; // Only process binary data, this will include ping/ping
119 + if (typeof data == 'string') {
120 + // Forward any ping/pong commands to the browser
121 + var cmd = null;
122 + try { cmd = JSON.parse(data); } catch (ex) { }
123 + if ((cmd != null) && (cmd.ctrlChannel == '102938')) {
124 + if (cmd.type == 'ping') { send(['ping']); }
125 + else if (cmd.type == 'pong') { send(['pong']); }
126 + }
127 + return;
128 + }
129 obj.wsClient._socket.pause();
130 try {
131 obj.relaySocket.write(data, function () {
@@ -280,6 +289,8 @@ module.exports.CreateMstscRelay = function (parent, db, ws, req, args, domain) {
289 case 'wheel': { if (rdpClient) { rdpClient.sendWheelEvent(msg[1], msg[2], msg[3], msg[4]); } break; }
290 case 'scancode': { if (rdpClient) { rdpClient.sendKeyEventScancode(msg[1], msg[2]); } break; }
291 case 'unicode': { if (rdpClient) { rdpClient.sendKeyEventUnicode(msg[1], msg[2]); } break; }
292 + case 'ping': { try { obj.wsClient.send('{"ctrlChannel":102938,"type":"ping"}'); } catch (ex) { } break; }
293 + case 'pong': { try { obj.wsClient.send('{"ctrlChannel":102938,"type":"pong"}'); } catch (ex) { } break; }
294 case 'disconnect': { obj.close(); break; }
295 }
296 } catch (ex) {
@@ -416,70 +427,74 @@ module.exports.CreateSshRelay = function (parent, db, ws, req, args, domain) {
427 const protocol = (args.tlsoffload) ? 'ws' : 'wss';
428 var domainadd = '';
429 if ((domain.dns == null) && (domain.id != '')) { domainadd = domain.id + '/' }
419 - const url = protocol + '://localhost:' + args.port + '/' + domainadd + (((obj.mtype == 3) && (obj.relaynodeid == null)) ? 'local' : 'mesh') + 'relay.ashx?noping=1&p=11&auth=' + obj.xcookie; // Protocol 11 is Web-SSH
430 + const url = protocol + '://localhost:' + args.port + '/' + domainadd + (((obj.mtype == 3) && (obj.relaynodeid == null)) ? 'local' : 'mesh') + 'relay.ashx?p=11&auth=' + obj.xcookie; // Protocol 11 is Web-SSH
431 parent.parent.debug('relay', 'SSH: Connection websocket to ' + url);
432 obj.wsClient = new WebSocket(url, options);
433 obj.wsClient.on('open', function () { parent.parent.debug('relay', 'SSH: Relay websocket open'); });
434 obj.wsClient.on('message', function (data) { // Make sure to handle flow control.
424 - if ((obj.relayActive == false) && (data == 'c')) {
425 - obj.relayActive = true;
426 -
427 - // Create a serial tunnel && SSH module
428 - obj.ser = new SerialTunnel();
429 - const Client = require('ssh2').Client;
430 - obj.sshClient = new Client();
431 - obj.sshClient.on('ready', function () { // Authentication was successful.
432 - // If requested, save the credentials
433 - if (obj.keep === true) saveSshCredentials();
434 - obj.sessionid = Buffer.from(parent.crypto.randomBytes(9), 'binary').toString('base64');
435 - obj.startTime = Date.now();
436 -
437 - // Event start of session
438 - try {
439 - const user = parent.users[obj.cookie.userid];
440 - const username = (user != null) ? user.name : null;
441 - const event = { etype: 'relay', action: 'relaylog', domain: domain.id, nodeid: obj.nodeid, userid: user._id, username: user.name, msgid: 148, msgArgs: [obj.sessionid], msg: "Started Web-SSH session \"" + obj.sessionid + "\".", protocol: PROTOCOL_WEBSSH };
442 - parent.parent.DispatchEvent(['*', obj.nodeid, user._id, obj.meshid], obj, event);
443 - } catch (ex) { console.log(ex); }
444 -
445 - obj.sshClient.shell(function (err, stream) { // Start a remote shell
446 - if (err) { obj.close(); return; }
447 - obj.sshShell = stream;
448 - obj.sshShell.setWindow(obj.termSize.rows, obj.termSize.cols, obj.termSize.height, obj.termSize.width);
449 - obj.sshShell.on('close', function () { obj.close(); });
450 - obj.sshShell.on('data', function (data) { obj.ws.send('~' + data.toString()); });
435 + if (obj.relayActive == false) {
436 + if ((data == 'c') || (data == 'cr')) {
437 + obj.relayActive = true;
438 +
439 + // Create a serial tunnel && SSH module
440 + obj.ser = new SerialTunnel();
441 + const Client = require('ssh2').Client;
442 + obj.sshClient = new Client();
443 + obj.sshClient.on('ready', function () { // Authentication was successful.
444 + // If requested, save the credentials
445 + if (obj.keep === true) saveSshCredentials();
446 + obj.sessionid = Buffer.from(parent.crypto.randomBytes(9), 'binary').toString('base64');
447 + obj.startTime = Date.now();
448 +
449 + // Event start of session
450 + try {
451 + const user = parent.users[obj.cookie.userid];
452 + const username = (user != null) ? user.name : null;
453 + const event = { etype: 'relay', action: 'relaylog', domain: domain.id, nodeid: obj.nodeid, userid: user._id, username: user.name, msgid: 148, msgArgs: [obj.sessionid], msg: "Started Web-SSH session \"" + obj.sessionid + "\".", protocol: PROTOCOL_WEBSSH };
454 + parent.parent.DispatchEvent(['*', obj.nodeid, user._id, obj.meshid], obj, event);
455 + } catch (ex) { console.log(ex); }
456 +
457 + obj.sshClient.shell(function (err, stream) { // Start a remote shell
458 + if (err) { obj.close(); return; }
459 + obj.sshShell = stream;
460 + obj.sshShell.setWindow(obj.termSize.rows, obj.termSize.cols, obj.termSize.height, obj.termSize.width);
461 + obj.sshShell.on('close', function () { obj.close(); });
462 + obj.sshShell.on('data', function (data) { obj.ws.send('~' + data.toString()); });
463 + });
464 + obj.ws.send(JSON.stringify({ action: 'connected' }));
465 + });
466 + obj.sshClient.on('error', function (err) {
467 + if (err.level == 'client-authentication') { try { obj.ws.send(JSON.stringify({ action: 'autherror' })); } catch (ex) { } }
468 + if (err.level == 'client-timeout') { try { obj.ws.send(JSON.stringify({ action: 'sessiontimeout' })); } catch (ex) { } }
469 + obj.close();
470 });
452 - obj.ws.send(JSON.stringify({ action: 'connected' }));
453 - });
454 - obj.sshClient.on('error', function (err) {
455 - if (err.level == 'client-authentication') { try { obj.ws.send(JSON.stringify({ action: 'autherror' })); } catch (ex) { } }
456 - if (err.level == 'client-timeout') { try { obj.ws.send(JSON.stringify({ action: 'sessiontimeout' })); } catch (ex) { } }
457 - obj.close();
458 - });
471
460 - // Setup the serial tunnel, SSH ---> Relay WS
461 - obj.ser.forwardwrite = function (data) { if ((data.length > 0) && (obj.wsClient != null)) { try { obj.wsClient.send(data); } catch (ex) { } } };
462 -
463 - // Connect the SSH module to the serial tunnel
464 - const connectionOptions = { sock: obj.ser }
465 - if (typeof obj.username == 'string') { connectionOptions.username = obj.username; }
466 - if (typeof obj.password == 'string') { connectionOptions.password = obj.password; }
467 - if (typeof obj.privateKey == 'string') { connectionOptions.privateKey = obj.privateKey; }
468 - if (typeof obj.privateKeyPass == 'string') { connectionOptions.passphrase = obj.privateKeyPass; }
469 - try {
470 - obj.sshClient.connect(connectionOptions);
471 - } catch (ex) {
472 - // Exception, this is generally because we did not provide proper credentials. Ask again.
473 - obj.relayActive = false;
474 - delete obj.sshClient;
475 - delete obj.ser.forwardwrite;
476 - obj.close();
477 - return;
478 - }
472 + // Setup the serial tunnel, SSH ---> Relay WS
473 + obj.ser.forwardwrite = function (data) { if ((data.length > 0) && (obj.wsClient != null)) { try { obj.wsClient.send(data); } catch (ex) { } } };
474 +
475 + // Connect the SSH module to the serial tunnel
476 + const connectionOptions = { sock: obj.ser }
477 + if (typeof obj.username == 'string') { connectionOptions.username = obj.username; }
478 + if (typeof obj.password == 'string') { connectionOptions.password = obj.password; }
479 + if (typeof obj.privateKey == 'string') { connectionOptions.privateKey = obj.privateKey; }
480 + if (typeof obj.privateKeyPass == 'string') { connectionOptions.passphrase = obj.privateKeyPass; }
481 + try {
482 + obj.sshClient.connect(connectionOptions);
483 + } catch (ex) {
484 + // Exception, this is generally because we did not provide proper credentials. Ask again.
485 + obj.relayActive = false;
486 + delete obj.sshClient;
487 + delete obj.ser.forwardwrite;
488 + obj.close();
489 + return;
490 + }
491
480 - // We are all set, start receiving data
481 - ws._socket.resume();
492 + // We are all set, start receiving data
493 + ws._socket.resume();
494 + }
495 } else {
496 + if (typeof data == 'string') return; // Only process binary data, this will include ping/ping
497 +
498 // Relay WS --> SSH
499 if ((data.length > 0) && (obj.ser != null)) { try { obj.ser.updateBuffer(data); } catch (ex) { console.log(ex); } }
500 }
@@ -708,71 +723,75 @@ module.exports.CreateSshTerminalRelay = function (parent, db, ws, req, domain, u
723 const protocol = (args.tlsoffload) ? 'ws' : 'wss';
724 var domainadd = '';
725 if ((domain.dns == null) && (domain.id != '')) { domainadd = domain.id + '/' }
711 - const url = protocol + '://localhost:' + args.port + '/' + domainadd + (((obj.mtype == 3) && (obj.relaynodeid == null)) ? 'local' : 'mesh') + 'relay.ashx?noping=1&p=11&auth=' + authCookie // Protocol 11 is Web-SSH
726 + const url = protocol + '://localhost:' + args.port + '/' + domainadd + (((obj.mtype == 3) && (obj.relaynodeid == null)) ? 'local' : 'mesh') + 'relay.ashx?p=11&auth=' + authCookie // Protocol 11 is Web-SSH
727 parent.parent.debug('relay', 'SSH: Connection websocket to ' + url);
728 obj.wsClient = new WebSocket(url, options);
729 obj.wsClient.on('open', function () { parent.parent.debug('relay', 'SSH: Relay websocket open'); });
730 obj.wsClient.on('message', function (data) { // Make sure to handle flow control.
716 - if ((obj.relayActive == false) && (data == 'c')) {
717 - obj.relayActive = true;
718 -
719 - // Create a serial tunnel && SSH module
720 - obj.ser = new SerialTunnel();
721 - const Client = require('ssh2').Client;
722 - obj.sshClient = new Client();
723 - obj.sshClient.on('ready', function () { // Authentication was successful.
724 - // If requested, save the credentials
725 - if (obj.keep === true) saveSshCredentials();
726 - obj.sessionid = Buffer.from(parent.crypto.randomBytes(9), 'binary').toString('base64');
727 - obj.startTime = Date.now();
731 + if (obj.relayActive == false) {
732 + if ((data == 'c') || (data == 'cr')) {
733 + obj.relayActive = true;
734 +
735 + // Create a serial tunnel && SSH module
736 + obj.ser = new SerialTunnel();
737 + const Client = require('ssh2').Client;
738 + obj.sshClient = new Client();
739 + obj.sshClient.on('ready', function () { // Authentication was successful.
740 + // If requested, save the credentials
741 + if (obj.keep === true) saveSshCredentials();
742 + obj.sessionid = Buffer.from(parent.crypto.randomBytes(9), 'binary').toString('base64');
743 + obj.startTime = Date.now();
744 +
745 + try {
746 + // Event start of session
747 + const event = { etype: 'relay', action: 'relaylog', domain: domain.id, nodeid: obj.nodeid, userid: user._id, username: user.name, msgid: 148, msgArgs: [obj.sessionid], msg: "Started Web-SSH session \"" + obj.sessionid + "\".", protocol: PROTOCOL_WEBSSH };
748 + parent.parent.DispatchEvent(['*', obj.nodeid, user._id, obj.meshid], obj, event);
749 + } catch (ex) {
750 + console.log(ex);
751 + }
752
729 - try {
730 - // Event start of session
731 - const event = { etype: 'relay', action: 'relaylog', domain: domain.id, nodeid: obj.nodeid, userid: user._id, username: user.name, msgid: 148, msgArgs: [obj.sessionid], msg: "Started Web-SSH session \"" + obj.sessionid + "\".", protocol: PROTOCOL_WEBSSH };
732 - parent.parent.DispatchEvent(['*', obj.nodeid, user._id, obj.meshid], obj, event);
733 - } catch (ex) {
734 - console.log(ex);
735 - }
753 + obj.sshClient.shell(function (err, stream) { // Start a remote shell
754 + if (err) { obj.close(); return; }
755 + obj.sshShell = stream;
756 + obj.sshShell.setWindow(obj.termSize.rows, obj.termSize.cols, obj.termSize.height, obj.termSize.width);
757 + obj.sshShell.on('close', function () { obj.close(); });
758 + obj.sshShell.on('data', function (data) { obj.ws.send('~' + data.toString()); });
759 + });
760
737 - obj.sshClient.shell(function (err, stream) { // Start a remote shell
738 - if (err) { obj.close(); return; }
739 - obj.sshShell = stream;
740 - obj.sshShell.setWindow(obj.termSize.rows, obj.termSize.cols, obj.termSize.height, obj.termSize.width);
741 - obj.sshShell.on('close', function () { obj.close(); });
742 - obj.sshShell.on('data', function (data) { obj.ws.send('~' + data.toString()); });
761 + obj.connected = true;
762 + obj.ws.send('c');
763 + });
764 + obj.sshClient.on('error', function (err) {
765 + if (err.level == 'client-authentication') { try { obj.ws.send(JSON.stringify({ action: 'autherror' })); } catch (ex) { } }
766 + if (err.level == 'client-timeout') { try { obj.ws.send(JSON.stringify({ action: 'sessiontimeout' })); } catch (ex) { } }
767 + obj.close();
768 });
769
745 - obj.connected = true;
746 - obj.ws.send('c');
747 - });
748 - obj.sshClient.on('error', function (err) {
749 - if (err.level == 'client-authentication') { try { obj.ws.send(JSON.stringify({ action: 'autherror' })); } catch (ex) { } }
750 - if (err.level == 'client-timeout') { try { obj.ws.send(JSON.stringify({ action: 'sessiontimeout' })); } catch (ex) { } }
751 - obj.close();
752 - });
770 + // Setup the serial tunnel, SSH ---> Relay WS
771 + obj.ser.forwardwrite = function (data) { if ((data.length > 0) && (obj.wsClient != null)) { try { obj.wsClient.send(data); } catch (ex) { } } };
772
754 - // Setup the serial tunnel, SSH ---> Relay WS
755 - obj.ser.forwardwrite = function (data) { if ((data.length > 0) && (obj.wsClient != null)) { try { obj.wsClient.send(data); } catch (ex) { } } };
756 -
757 - // Connect the SSH module to the serial tunnel
758 - const connectionOptions = { sock: obj.ser }
759 - if (typeof obj.username == 'string') { connectionOptions.username = obj.username; }
760 - if (typeof obj.password == 'string') { connectionOptions.password = obj.password; }
761 - if (typeof obj.privateKey == 'string') { connectionOptions.privateKey = obj.privateKey; }
762 - if (typeof obj.privateKeyPass == 'string') { connectionOptions.passphrase = obj.privateKeyPass; }
763 - try {
764 - obj.sshClient.connect(connectionOptions);
765 - } catch (ex) {
766 - // Exception, this is generally because we did not provide proper credentials. Ask again.
767 - obj.relayActive = false;
768 - delete obj.sshClient;
769 - delete obj.ser.forwardwrite;
770 - try { ws.send(JSON.stringify({ action: 'sshauth' })) } catch (ex) { }
771 - }
773 + // Connect the SSH module to the serial tunnel
774 + const connectionOptions = { sock: obj.ser }
775 + if (typeof obj.username == 'string') { connectionOptions.username = obj.username; }
776 + if (typeof obj.password == 'string') { connectionOptions.password = obj.password; }
777 + if (typeof obj.privateKey == 'string') { connectionOptions.privateKey = obj.privateKey; }
778 + if (typeof obj.privateKeyPass == 'string') { connectionOptions.passphrase = obj.privateKeyPass; }
779 + try {
780 + obj.sshClient.connect(connectionOptions);
781 + } catch (ex) {
782 + // Exception, this is generally because we did not provide proper credentials. Ask again.
783 + obj.relayActive = false;
784 + delete obj.sshClient;
785 + delete obj.ser.forwardwrite;
786 + try { ws.send(JSON.stringify({ action: 'sshauth' })) } catch (ex) { }
787 + }
788
773 - // We are all set, start receiving data
774 - ws._socket.resume();
789 + // We are all set, start receiving data
790 + ws._socket.resume();
791 + }
792 } else {
793 + if (typeof data == 'string') return; // Only process binary data, this will include ping/ping
794 +
795 // Relay WS --> SSH
796 if ((data.length > 0) && (obj.ser != null)) { try { obj.ser.updateBuffer(data); } catch (ex) { console.log(ex); } }
797 }
@@ -1015,65 +1034,69 @@ module.exports.CreateSshFilesRelay = function (parent, db, ws, req, domain, user
1034 const protocol = (args.tlsoffload) ? 'ws' : 'wss';
1035 var domainadd = '';
1036 if ((domain.dns == null) && (domain.id != '')) { domainadd = domain.id + '/' }
1018 - const url = protocol + '://localhost:' + args.port + '/' + domainadd + (((obj.mtype == 3) && (obj.relaynodeid == null)) ? 'local' : 'mesh') + 'relay.ashx?noping=1&p=13&auth=' + authCookie // Protocol 13 is Web-SSH-Files
1037 + const url = protocol + '://localhost:' + args.port + '/' + domainadd + (((obj.mtype == 3) && (obj.relaynodeid == null)) ? 'local' : 'mesh') + 'relay.ashx?p=13&auth=' + authCookie // Protocol 13 is Web-SSH-Files
1038 parent.parent.debug('relay', 'SSH: Connection websocket to ' + url);
1039 obj.wsClient = new WebSocket(url, options);
1040 obj.wsClient.on('open', function () { parent.parent.debug('relay', 'SSH: Relay websocket open'); });
1041 obj.wsClient.on('message', function (data) { // Make sure to handle flow control.
1023 - if ((obj.relayActive == false) && (data == 'c')) {
1024 - obj.relayActive = true;
1025 -
1026 - // Create a serial tunnel && SSH module
1027 - obj.ser = new SerialTunnel();
1028 - const Client = require('ssh2').Client;
1029 - obj.sshClient = new Client();
1030 - obj.sshClient.on('ready', function () { // Authentication was successful.
1031 - // If requested, save the credentials
1032 - if (obj.keep === true) saveSshCredentials();
1033 - obj.sessionid = Buffer.from(parent.crypto.randomBytes(9), 'binary').toString('base64');
1034 - obj.startTime = Date.now();
1035 -
1036 - // Event start of session
1037 - try {
1038 - const event = { etype: 'relay', action: 'relaylog', domain: domain.id, nodeid: obj.nodeid, userid: user._id, username: user.name, msgid: 149, msgArgs: [obj.sessionid], msg: "Started Web-SFTP session \"" + obj.sessionid + "\".", protocol: PROTOCOL_WEBSFTP };
1039 - parent.parent.DispatchEvent(['*', obj.nodeid, user._id, obj.meshid], obj, event);
1040 - } catch (ex) { console.log(ex); }
1042 + if (obj.relayActive == false) {
1043 + if ((data == 'c') || (data == 'cr')) {
1044 + obj.relayActive = true;
1045 +
1046 + // Create a serial tunnel && SSH module
1047 + obj.ser = new SerialTunnel();
1048 + const Client = require('ssh2').Client;
1049 + obj.sshClient = new Client();
1050 + obj.sshClient.on('ready', function () { // Authentication was successful.
1051 + // If requested, save the credentials
1052 + if (obj.keep === true) saveSshCredentials();
1053 + obj.sessionid = Buffer.from(parent.crypto.randomBytes(9), 'binary').toString('base64');
1054 + obj.startTime = Date.now();
1055
1042 - obj.sshClient.sftp(function(err, sftp) {
1043 - if (err) { obj.close(); return; }
1044 - obj.connected = true;
1045 - obj.sftp = sftp;
1046 - obj.ws.send('c');
1056 + // Event start of session
1057 + try {
1058 + const event = { etype: 'relay', action: 'relaylog', domain: domain.id, nodeid: obj.nodeid, userid: user._id, username: user.name, msgid: 149, msgArgs: [obj.sessionid], msg: "Started Web-SFTP session \"" + obj.sessionid + "\".", protocol: PROTOCOL_WEBSFTP };
1059 + parent.parent.DispatchEvent(['*', obj.nodeid, user._id, obj.meshid], obj, event);
1060 + } catch (ex) { console.log(ex); }
1061 +
1062 + obj.sshClient.sftp(function (err, sftp) {
1063 + if (err) { obj.close(); return; }
1064 + obj.connected = true;
1065 + obj.sftp = sftp;
1066 + obj.ws.send('c');
1067 + });
1068 + });
1069 + obj.sshClient.on('error', function (err) {
1070 + if (err.level == 'client-authentication') { try { obj.ws.send(JSON.stringify({ action: 'autherror' })); } catch (ex) { } }
1071 + if (err.level == 'client-timeout') { try { obj.ws.send(JSON.stringify({ action: 'sessiontimeout' })); } catch (ex) { } }
1072 + obj.close();
1073 });
1048 - });
1049 - obj.sshClient.on('error', function (err) {
1050 - if (err.level == 'client-authentication') { try { obj.ws.send(JSON.stringify({ action: 'autherror' })); } catch (ex) { } }
1051 - if (err.level == 'client-timeout') { try { obj.ws.send(JSON.stringify({ action: 'sessiontimeout' })); } catch (ex) { } }
1052 - obj.close();
1053 - });
1074
1055 - // Setup the serial tunnel, SSH ---> Relay WS
1056 - obj.ser.forwardwrite = function (data) { if ((data.length > 0) && (obj.wsClient != null)) { try { obj.wsClient.send(data); } catch (ex) { } } };
1057 -
1058 - // Connect the SSH module to the serial tunnel
1059 - const connectionOptions = { sock: obj.ser }
1060 - if (typeof obj.username == 'string') { connectionOptions.username = obj.username; }
1061 - if (typeof obj.password == 'string') { connectionOptions.password = obj.password; }
1062 - if (typeof obj.privateKey == 'string') { connectionOptions.privateKey = obj.privateKey; }
1063 - if (typeof obj.privateKeyPass == 'string') { connectionOptions.passphrase = obj.privateKeyPass; }
1064 - try {
1065 - obj.sshClient.connect(connectionOptions);
1066 - } catch (ex) {
1067 - // Exception, this is generally because we did not provide proper credentials. Ask again.
1068 - obj.relayActive = false;
1069 - delete obj.sshClient;
1070 - delete obj.ser.forwardwrite;
1071 - try { ws.send(JSON.stringify({ action: 'sshauth' })) } catch (ex) { }
1072 - }
1075 + // Setup the serial tunnel, SSH ---> Relay WS
1076 + obj.ser.forwardwrite = function (data) { if ((data.length > 0) && (obj.wsClient != null)) { try { obj.wsClient.send(data); } catch (ex) { } } };
1077
1074 - // We are all set, start receiving data
1075 - ws._socket.resume();
1078 + // Connect the SSH module to the serial tunnel
1079 + const connectionOptions = { sock: obj.ser }
1080 + if (typeof obj.username == 'string') { connectionOptions.username = obj.username; }
1081 + if (typeof obj.password == 'string') { connectionOptions.password = obj.password; }
1082 + if (typeof obj.privateKey == 'string') { connectionOptions.privateKey = obj.privateKey; }
1083 + if (typeof obj.privateKeyPass == 'string') { connectionOptions.passphrase = obj.privateKeyPass; }
1084 + try {
1085 + obj.sshClient.connect(connectionOptions);
1086 + } catch (ex) {
1087 + // Exception, this is generally because we did not provide proper credentials. Ask again.
1088 + obj.relayActive = false;
1089 + delete obj.sshClient;
1090 + delete obj.ser.forwardwrite;
1091 + try { ws.send(JSON.stringify({ action: 'sshauth' })) } catch (ex) { }
1092 + }
1093 +
1094 + // We are all set, start receiving data
1095 + ws._socket.resume();
1096 + }
1097 } else {
1098 + if (typeof data == 'string') return; // Only process binary data, this will include ping/ping
1099 +
1100 // Relay WS --> SSH
1101 if ((data.length > 0) && (obj.ser != null)) { try { obj.ser.updateBuffer(data); } catch (ex) { console.log(ex); } }
1102 }
public/scripts/agent-rdp-0.0.1.js
+2
@@ -83,6 +83,8 @@ var CreateRDPDesktop = function (canvasid) {
83 obj.Stop();
84 break;
85 }
86 + case 'ping': { obj.socket.send('["pong"]'); break; }
87 + case 'pong': { break; }
88 }
89 } else {
90 // This is binary bitmap data, store it.