mirror of
https://github.com/Ylianst/MeshCentral.git
synced 2025-02-12 11:01:52 +00:00
parent
6637f08fe7
commit
15ff7d12a1
1 changed files with 27 additions and 30 deletions
37
apprelays.js
37
apprelays.js
|
@ -1,4 +1,4 @@
|
||||||
/**
|
/**
|
||||||
* @description MeshCentral MSTSC & SSH relay
|
* @description MeshCentral MSTSC & SSH relay
|
||||||
* @author Ylian Saint-Hilaire & Bryan Roe
|
* @author Ylian Saint-Hilaire & Bryan Roe
|
||||||
* @copyright Intel Corporation 2018-2022
|
* @copyright Intel Corporation 2018-2022
|
||||||
|
@ -845,13 +845,14 @@ module.exports.CreateMstscRelay = function (parent, db, ws, req, args, domain) {
|
||||||
if (typeof data == 'string') {
|
if (typeof data == 'string') {
|
||||||
// Forward any ping/pong commands to the browser
|
// Forward any ping/pong commands to the browser
|
||||||
var cmd = null;
|
var cmd = null;
|
||||||
try { cmd = JSON.parse(data); } catch (ex) { }
|
try { // Forward any ping/pong commands to the browser
|
||||||
|
cmd = JSON.parse(data);
|
||||||
if ((cmd != null) && (cmd.ctrlChannel == '102938')) {
|
if ((cmd != null) && (cmd.ctrlChannel == '102938')) {
|
||||||
if (cmd.type == 'ping') { send(['ping']); }
|
if (cmd.type == 'ping') { send(['ping']); }
|
||||||
else if (cmd.type == 'pong') { send(['pong']); }
|
else if (cmd.type == 'pong') { send(['pong']); }
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
} catch (ex) { // You are not JSON data so just send over relaySocket
|
||||||
obj.wsClient._socket.pause();
|
obj.wsClient._socket.pause();
|
||||||
try {
|
try {
|
||||||
obj.relaySocket.write(data, function () {
|
obj.relaySocket.write(data, function () {
|
||||||
|
@ -859,6 +860,7 @@ module.exports.CreateMstscRelay = function (parent, db, ws, req, args, domain) {
|
||||||
});
|
});
|
||||||
} catch (ex) { console.log(ex); obj.close(); }
|
} catch (ex) { console.log(ex); obj.close(); }
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
obj.wsClient.on('close', function () { parent.parent.debug('relay', 'RDP: Relay websocket closed'); obj.close(); });
|
obj.wsClient.on('close', function () { parent.parent.debug('relay', 'RDP: Relay websocket closed'); obj.close(); });
|
||||||
obj.wsClient.on('error', function (err) { parent.parent.debug('relay', 'RDP: Relay websocket error: ' + err); obj.close(); });
|
obj.wsClient.on('error', function (err) { parent.parent.debug('relay', 'RDP: Relay websocket error: ' + err); obj.close(); });
|
||||||
|
@ -1281,17 +1283,15 @@ module.exports.CreateSshRelay = function (parent, db, ws, req, args, domain) {
|
||||||
ws._socket.resume();
|
ws._socket.resume();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (typeof data == 'string') {
|
try { // Forward any ping/pong commands to the browser
|
||||||
// Forward any ping/pong commands to the browser
|
|
||||||
var cmd = null;
|
var cmd = null;
|
||||||
try { cmd = JSON.parse(data); } catch (ex) { }
|
cmd = JSON.parse(data);
|
||||||
if ((cmd != null) && (cmd.ctrlChannel == '102938') && ((cmd.type == 'ping') || (cmd.type == 'pong'))) { obj.ws.send(data); }
|
if ((cmd != null) && (cmd.ctrlChannel == '102938') && ((cmd.type == 'ping') || (cmd.type == 'pong'))) { obj.ws.send(data); }
|
||||||
return;
|
return;
|
||||||
}
|
} catch(ex) { // Relay WS --> SSH instead
|
||||||
|
|
||||||
// Relay WS --> SSH
|
|
||||||
if ((data.length > 0) && (obj.ser != null)) { try { obj.ser.updateBuffer(data); } catch (ex) { console.log(ex); } }
|
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 () { 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(); });
|
obj.wsClient.on('error', function (err) { parent.parent.debug('relay', 'SSH: Relay websocket error: ' + err); obj.close(); });
|
||||||
|
@ -1621,17 +1621,15 @@ module.exports.CreateSshTerminalRelay = function (parent, db, ws, req, domain, u
|
||||||
ws._socket.resume();
|
ws._socket.resume();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (typeof data == 'string') {
|
try { // Forward any ping/pong commands to the browser
|
||||||
// Forward any ping/pong commands to the browser
|
|
||||||
var cmd = null;
|
var cmd = null;
|
||||||
try { cmd = JSON.parse(data); } catch (ex) { }
|
cmd = JSON.parse(data);
|
||||||
if ((cmd != null) && (cmd.ctrlChannel == '102938') && ((cmd.type == 'ping') || (cmd.type == 'pong'))) { try { obj.ws.send(data); } catch (ex) { console.log(ex); } }
|
if ((cmd != null) && (cmd.ctrlChannel == '102938') && ((cmd.type == 'ping') || (cmd.type == 'pong'))) { try { obj.ws.send(data); } catch (ex) { console.log(ex); } }
|
||||||
return;
|
return;
|
||||||
}
|
} catch (ex) { // Relay WS --> SSH
|
||||||
|
|
||||||
// Relay WS --> SSH
|
|
||||||
if ((data.length > 0) && (obj.ser != null)) { try { obj.ser.updateBuffer(data); } catch (ex) { console.log(ex); } }
|
if ((data.length > 0) && (obj.ser != null)) { try { obj.ser.updateBuffer(data); } catch (ex) { console.log(ex); } }
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
obj.wsClient.on('close', function () {
|
obj.wsClient.on('close', function () {
|
||||||
if (obj.connected !== true) { try { obj.ws.send(JSON.stringify({ action: 'connectionerror' })); } catch (ex) { } }
|
if (obj.connected !== true) { try { obj.ws.send(JSON.stringify({ action: 'connectionerror' })); } catch (ex) { } }
|
||||||
|
@ -1969,17 +1967,16 @@ module.exports.CreateSshFilesRelay = function (parent, db, ws, req, domain, user
|
||||||
ws._socket.resume();
|
ws._socket.resume();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (typeof data == 'string') {
|
try {
|
||||||
// Forward any ping/pong commands to the browser
|
// Forward any ping/pong commands to the browser
|
||||||
var cmd = null;
|
var cmd = null;
|
||||||
try { cmd = JSON.parse(data); } catch (ex) { }
|
cmd = JSON.parse(data);
|
||||||
if ((cmd != null) && (cmd.ctrlChannel == '102938') && ((cmd.type == 'ping') || (cmd.type == 'pong'))) { obj.ws.send(data); }
|
if ((cmd != null) && (cmd.ctrlChannel == '102938') && ((cmd.type == 'ping') || (cmd.type == 'pong'))) { obj.ws.send(data); }
|
||||||
return;
|
return;
|
||||||
}
|
} catch (ex) { // Relay WS --> SSH
|
||||||
|
|
||||||
// Relay WS --> SSH
|
|
||||||
if ((data.length > 0) && (obj.ser != null)) { try { obj.ser.updateBuffer(data); } catch (ex) { console.log(ex); } }
|
if ((data.length > 0) && (obj.ser != null)) { try { obj.ser.updateBuffer(data); } catch (ex) { console.log(ex); } }
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
obj.wsClient.on('close', function () {
|
obj.wsClient.on('close', function () {
|
||||||
if (obj.connected !== true) { try { obj.ws.send(JSON.stringify({ action: 'connectionerror' })); } catch (ex) { } }
|
if (obj.connected !== true) { try { obj.ws.send(JSON.stringify({ action: 'connectionerror' })); } catch (ex) { } }
|
||||||
|
|
Loading…
Reference in a new issue