fix agentping (#5786)
Signed-off-by: si458 <simonsmith5521@gmail.com>
Simon Smith committed
Feb 11, 2024 at 01:03 UTC
15ff7d12a1e4e5d78936b473ea207b7e02b8ff26
1 file changed
+27
-30
apprelays.js
+27
-30
@@ -1,4 +1,4 @@
1
-/**
1
+/**
2
* @description MeshCentral MSTSC & SSH relay
3
* @author Ylian Saint-Hilaire & Bryan Roe
4
* @copyright Intel Corporation 2018-2022
@@ -845,19 +845,21 @@ module.exports.CreateMstscRelay = function (parent, db, ws, req, args, domain) {
845
if (typeof data == 'string') {
846
// Forward any ping/pong commands to the browser
847
var cmd = null;
848
- try { cmd = JSON.parse(data); } catch (ex) { }
849
- if ((cmd != null) && (cmd.ctrlChannel == '102938')) {
850
- if (cmd.type == 'ping') { send(['ping']); }
851
- else if (cmd.type == 'pong') { send(['pong']); }
848
+ try { // Forward any ping/pong commands to the browser
849
+ cmd = JSON.parse(data);
850
+ if ((cmd != null) && (cmd.ctrlChannel == '102938')) {
851
+ if (cmd.type == 'ping') { send(['ping']); }
852
+ else if (cmd.type == 'pong') { send(['pong']); }
853
+ }
854
+ return;
855
+ } catch (ex) { // You are not JSON data so just send over relaySocket
856
+ obj.wsClient._socket.pause();
857
+ try {
858
+ obj.relaySocket.write(data, function () {
859
+ if (obj.wsClient && obj.wsClient._socket) { try { obj.wsClient._socket.resume(); } catch (ex) { console.log(ex); } }
860
+ });
861
+ } catch (ex) { console.log(ex); obj.close(); }
862
}
853
- return;
854
- }
855
- obj.wsClient._socket.pause();
856
- try {
857
- obj.relaySocket.write(data, function () {
858
- if (obj.wsClient && obj.wsClient._socket) { try { obj.wsClient._socket.resume(); } catch (ex) { console.log(ex); } }
859
- });
860
- } catch (ex) { console.log(ex); obj.close(); }
863
}
864
});
865
obj.wsClient.on('close', function () { parent.parent.debug('relay', 'RDP: Relay websocket closed'); obj.close(); });
@@ -1281,16 +1283,14 @@ module.exports.CreateSshRelay = function (parent, db, ws, req, args, domain) {
1283
ws._socket.resume();
1284
}
1285
} else {
1284
- if (typeof data == 'string') {
1285
- // Forward any ping/pong commands to the browser
1286
+ try { // Forward any ping/pong commands to the browser
1287
var cmd = null;
1287
- try { cmd = JSON.parse(data); } catch (ex) { }
1288
+ cmd = JSON.parse(data);
1289
if ((cmd != null) && (cmd.ctrlChannel == '102938') && ((cmd.type == 'ping') || (cmd.type == 'pong'))) { obj.ws.send(data); }
1290
return;
1291
+ } catch(ex) { // Relay WS --> SSH instead
1292
+ if ((data.length > 0) && (obj.ser != null)) { try { obj.ser.updateBuffer(data); } catch (ex) { console.log(ex); } }
1293
}
1291
-
1292
- // Relay WS --> SSH
1293
- if ((data.length > 0) && (obj.ser != null)) { try { obj.ser.updateBuffer(data); } catch (ex) { console.log(ex); } }
1294
}
1295
});
1296
obj.wsClient.on('close', function () { parent.parent.debug('relay', 'SSH: Relay websocket closed'); obj.close(); });
@@ -1621,16 +1621,14 @@ module.exports.CreateSshTerminalRelay = function (parent, db, ws, req, domain, u
1621
ws._socket.resume();
1622
}
1623
} else {
1624
- if (typeof data == 'string') {
1625
- // Forward any ping/pong commands to the browser
1624
+ try { // Forward any ping/pong commands to the browser
1625
var cmd = null;
1627
- try { cmd = JSON.parse(data); } catch (ex) { }
1626
+ cmd = JSON.parse(data);
1627
if ((cmd != null) && (cmd.ctrlChannel == '102938') && ((cmd.type == 'ping') || (cmd.type == 'pong'))) { try { obj.ws.send(data); } catch (ex) { console.log(ex); } }
1628
return;
1629
+ } catch (ex) { // Relay WS --> SSH
1630
+ if ((data.length > 0) && (obj.ser != null)) { try { obj.ser.updateBuffer(data); } catch (ex) { console.log(ex); } }
1631
}
1631
-
1632
- // Relay WS --> SSH
1633
- if ((data.length > 0) && (obj.ser != null)) { try { obj.ser.updateBuffer(data); } catch (ex) { console.log(ex); } }
1632
}
1633
});
1634
obj.wsClient.on('close', function () {
@@ -1969,16 +1967,15 @@ module.exports.CreateSshFilesRelay = function (parent, db, ws, req, domain, user
1967
ws._socket.resume();
1968
}
1969
} else {
1972
- if (typeof data == 'string') {
1970
+ try {
1971
// Forward any ping/pong commands to the browser
1972
var cmd = null;
1975
- try { cmd = JSON.parse(data); } catch (ex) { }
1973
+ cmd = JSON.parse(data);
1974
if ((cmd != null) && (cmd.ctrlChannel == '102938') && ((cmd.type == 'ping') || (cmd.type == 'pong'))) { obj.ws.send(data); }
1975
return;
1976
+ } catch (ex) { // Relay WS --> SSH
1977
+ if ((data.length > 0) && (obj.ser != null)) { try { obj.ser.updateBuffer(data); } catch (ex) { console.log(ex); } }
1978
}
1979
-
1980
- // Relay WS --> SSH
1981
- if ((data.length > 0) && (obj.ser != null)) { try { obj.ser.updateBuffer(data); } catch (ex) { console.log(ex); } }
1979
}
1980
});
1981
obj.wsClient.on('close', function () {