Added TCP/UDP routing indication.

Ylian Saint-Hilaire committed Jul 24, 2020 at 14:00 UTC ddcbee0cc4cb0d69278b3d2315064368bb694093
6 files changed +48 -11
agents/meshcore.js
+24 -2
@@ -341,7 +341,7 @@ function createMeshCore(agent) {
341 var nextTunnelIndex = 1;
342 var amtPolicy = null;
343 var apftunnel = null;
344 - var tunnelUserCount = { terminal: {}, files: {} }; // List of userid->count sessions for terminal and files.
344 + var tunnelUserCount = { terminal: {}, files: {}, tcp: {}, udp: {} }; // List of userid->count sessions for terminal, files and TCP/UDP routing
345
346 // Add to the server event log
347 function MeshServerLog(msg, state) {
@@ -1127,7 +1127,6 @@ function createMeshCore(agent) {
1127 });
1128 }
1129
1130 -
1130 //sendConsoleText('onTunnelUpgrade - ' + this.tcpport + ' - ' + this.udpport);
1131
1132 if (this.tcpport != null) {
@@ -1138,6 +1137,12 @@ function createMeshCore(agent) {
1137 if (this.tcpaddr != null) { connectionOptions.host = this.tcpaddr; } else { connectionOptions.host = '127.0.0.1'; }
1138 s.tcprelay = net.createConnection(connectionOptions, onTcpRelayTargetTunnelConnect);
1139 s.tcprelay.peerindex = this.index;
1140 +
1141 + // Add the TCP session to the count and update the server
1142 + if (s.httprequest.userid != null) {
1143 + if (tunnelUserCount.tcp[s.httprequest.userid] == null) { tunnelUserCount.tcp[s.httprequest.userid] = 1; } else { tunnelUserCount.tcp[s.httprequest.userid]++; }
1144 + try { mesh.SendCommand({ action: 'sessions', type: 'tcp', value: tunnelUserCount.tcp }); } catch (ex) { }
1145 + }
1146 } if (this.udpport != null) {
1147 // This is a UDP relay connection, get the UDP socket setup. // TODO: ***************
1148 s.data = onUdpRelayServerTunnelData;
@@ -1148,6 +1153,12 @@ function createMeshCore(agent) {
1153 s.udprelay.udpport = this.udpport;
1154 s.udprelay.udpaddr = this.udpaddr;
1155 s.udprelay.first = true;
1156 +
1157 + // Add the UDP session to the count and update the server
1158 + if (s.httprequest.userid != null) {
1159 + if (tunnelUserCount.udp[s.httprequest.userid] == null) { tunnelUserCount.udp[s.httprequest.userid] = 1; } else { tunnelUserCount.udp[s.httprequest.userid]++; }
1160 + try { mesh.SendCommand({ action: 'sessions', type: 'udp', value: tunnelUserCount.tcp }); } catch (ex) { }
1161 + }
1162 } else {
1163 // This is a normal connect for KVM/Terminal/Files
1164 s.data = onTunnelData;
@@ -1189,6 +1200,17 @@ function createMeshCore(agent) {
1200 var tunnel = tunnels[this.httprequest.index];
1201 if (tunnel == null) return; // Stop duplicate calls.
1202
1203 + // If this is a routing session, clean up and send the new session counts.
1204 + if (this.httprequest.userid != null) {
1205 + if (this.httprequest.tcpport != null) {
1206 + if (tunnelUserCount.tcp[this.httprequest.userid] != null) { tunnelUserCount.tcp[this.httprequest.userid]--; if (tunnelUserCount.tcp[this.httprequest.userid] <= 0) { delete tunnelUserCount.tcp[this.httprequest.userid]; } }
1207 + try { mesh.SendCommand({ action: 'sessions', type: 'tcp', value: tunnelUserCount.tcp }); } catch (ex) { }
1208 + } else if (this.httprequest.udpport != null) {
1209 + if (tunnelUserCount.udp[this.httprequest.userid] != null) { tunnelUserCount.udp[this.httprequest.userid]--; if (tunnelUserCount.udp[this.httprequest.userid] <= 0) { delete tunnelUserCount.udp[this.httprequest.userid]; } }
1210 + try { mesh.SendCommand({ action: 'sessions', type: 'udp', value: tunnelUserCount.udp }); } catch (ex) { }
1211 + }
1212 + }
1213 +
1214 // Sent tunnel statistics to the server, only send this if compression was used.
1215 if (this.bytesSent_uncompressed.toString() != this.bytesSent_actual.toString()) {
1216 mesh.SendCommand({
meshagent.js
+2
@@ -1375,6 +1375,8 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) {
1375 if (command.type == 'kvm') { obj.sessions.kvm = command.value; }
1376 else if (command.type == 'terminal') { obj.sessions.terminal = command.value; }
1377 else if (command.type == 'files') { obj.sessions.files = command.value; }
1378 + else if (command.type == 'tcp') { obj.sessions.tcp = command.value; }
1379 + else if (command.type == 'udp') { obj.sessions.udp = command.value; }
1380 obj.updateSessions();
1381 break;
1382 }
meshrelay.js
+3 -3
@@ -494,7 +494,7 @@ module.exports.CreateMeshRelay = function (parent, ws, req, domain, user, cookie
494 // Send connection request to agent
495 const rcookie = parent.parent.encodeCookie({ ruserid: user._id }, parent.parent.loginCookieEncryptionKey);
496 if (obj.id == undefined) { obj.id = ('' + Math.random()).substring(2); } // If there is no connection id, generate one.
497 - const command = { nodeid: cookie.nodeid, action: 'msg', type: 'tunnel', value: '*/meshrelay.ashx?id=' + obj.id + '&rauth=' + rcookie, tcpport: cookie.tcpport, tcpaddr: cookie.tcpaddr, soptions: {} };
497 + const command = { nodeid: cookie.nodeid, action: 'msg', type: 'tunnel', userid: user._id, value: '*/meshrelay.ashx?id=' + obj.id + '&rauth=' + rcookie, tcpport: cookie.tcpport, tcpaddr: cookie.tcpaddr, soptions: {} };
498 if (typeof domain.consentmessages == 'object') {
499 if (typeof domain.consentmessages.title == 'string') { command.soptions.consentTitle = domain.consentmessages.title; }
500 if (typeof domain.consentmessages.desktop == 'string') { command.soptions.consentMsgDesktop = domain.consentmessages.desktop; }
@@ -526,7 +526,7 @@ module.exports.CreateMeshRelay = function (parent, ws, req, domain, user, cookie
526 const rcookie = parent.parent.encodeCookie({ ruserid: user._id }, parent.parent.loginCookieEncryptionKey);
527
528 if (obj.req.query.tcpport != null) {
529 - const command = { nodeid: obj.req.query.nodeid, action: 'msg', type: 'tunnel', value: '*/meshrelay.ashx?id=' + obj.id + '&rauth=' + rcookie, tcpport: obj.req.query.tcpport, tcpaddr: ((obj.req.query.tcpaddr == null) ? '127.0.0.1' : obj.req.query.tcpaddr), soptions: {} };
529 + const command = { nodeid: obj.req.query.nodeid, action: 'msg', type: 'tunnel', userid: user._id, value: '*/meshrelay.ashx?id=' + obj.id + '&rauth=' + rcookie, tcpport: obj.req.query.tcpport, tcpaddr: ((obj.req.query.tcpaddr == null) ? '127.0.0.1' : obj.req.query.tcpaddr), soptions: {} };
530 if (typeof domain.consentmessages == 'object') {
531 if (typeof domain.consentmessages.title == 'string') { command.soptions.consentTitle = domain.consentmessages.title; }
532 if (typeof domain.consentmessages.desktop == 'string') { command.soptions.consentMsgDesktop = domain.consentmessages.desktop; }
@@ -542,7 +542,7 @@ module.exports.CreateMeshRelay = function (parent, ws, req, domain, user, cookie
542 parent.parent.debug('relay', 'Relay: Sending agent TCP tunnel command: ' + JSON.stringify(command));
543 if (obj.sendAgentMessage(command, user._id, domain.id) == false) { delete obj.id; parent.parent.debug('relay', 'Relay: Unable to contact this agent (' + obj.req.clientIp + ')'); }
544 } else if (obj.req.query.udpport != null) {
545 - const command = { nodeid: obj.req.query.nodeid, action: 'msg', type: 'tunnel', value: '*/meshrelay.ashx?id=' + obj.id + '&rauth=' + rcookie, udpport: obj.req.query.udpport, udpaddr: ((obj.req.query.udpaddr == null) ? '127.0.0.1' : obj.req.query.udpaddr), soptions: {} };
545 + const command = { nodeid: obj.req.query.nodeid, action: 'msg', type: 'tunnel', userid: user._id, value: '*/meshrelay.ashx?id=' + obj.id + '&rauth=' + rcookie, udpport: obj.req.query.udpport, udpaddr: ((obj.req.query.udpaddr == null) ? '127.0.0.1' : obj.req.query.udpaddr), soptions: {} };
546 if (typeof domain.consentmessages == 'object') {
547 if (typeof domain.consentmessages.title == 'string') { command.soptions.consentTitle = domain.consentmessages.title; }
548 if (typeof domain.consentmessages.desktop == 'string') { command.soptions.consentMsgDesktop = domain.consentmessages.desktop; }
meshuser.js
+3
@@ -1219,6 +1219,9 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
1219 if (typeof domain.notificationmessages.files == 'string') { command.soptions.notifyMsgFiles = domain.notificationmessages.files; }
1220 }
1221
1222 + // Add userid
1223 + command.userid = user._id;
1224 +
1225 // Add tunnel pre-message deflate
1226 if (typeof parent.parent.config.settings.agentwscompression == 'boolean') { command.perMessageDeflate = parent.parent.config.settings.agentwscompression; }
1227 }
package.json
+8 -4
@@ -2,10 +2,14 @@
2 "name": "meshcentral",
3 "version": "0.5.94",
4 "keywords": [
5 - "Remote Management",
6 - "Intel AMT",
7 - "Active Management",
8 - "Remote Desktop"
5 + "Remote Device Management",
6 + "Remote Device Monitoring",
7 + "Remote Desktop",
8 + "Remote Terminal",
9 + "Remote File Access",
10 + "KVM",
11 + "Intel Active Management Technology",
12 + "Intel AMT"
13 ],
14 "homepage": "http://meshcommander.com",
15 "description": "Web based remote computer management and file server",
views/default.handlebars
+8 -2
@@ -3341,7 +3341,7 @@
3341 var devNotify = '';
3342 if (node.sessions != null) {
3343 // Sessions are active
3344 - if ((node.sessions.kvm != null) || (node.sessions.terminal != null) || (node.sessions.files != null)) {
3344 + if ((node.sessions.kvm != null) || (node.sessions.terminal != null) || (node.sessions.files != null) || (node.sessions.tcp != null) || (node.sessions.udp != null)) {
3345 if (view == 2) {
3346 devNotify = '<img onclick=showDeviceSessions(\'' + node._id + '\',null,event) class=deviceNotifySmallDot src=images/icon-relay-notify10.png width=10 height=10>';
3347 } else {
@@ -3632,6 +3632,12 @@
3632 } else if (i == 'files') {
3633 x += '<u>' + "Files" + '</u>';
3634 for (var j in node.sessions.files) { x += addHtmlValue4(getUserName(j), ((node.sessions.files[j] == 1)?"1 session":nobreak(format("{0} sessions", node.sessions.files[j])))); }
3635 + } else if (i == 'tcp') {
3636 + x += '<u>' + "TCP Routing" + '</u>';
3637 + for (var j in node.sessions.tcp) { x += addHtmlValue4(getUserName(j), ((node.sessions.tcp[j] == 1)?"1 session":nobreak(format("{0} sessions", node.sessions.tcp[j])))); }
3638 + } else if (i == 'udp') {
3639 + x += '<u>' + "UDP Routing" + '</u>';
3640 + for (var j in node.sessions.udp) { x += addHtmlValue4(getUserName(j), ((node.sessions.udp[j] == 1)?"1 session":nobreak(format("{0} sessions", node.sessions.udp[j])))); }
3641 }
3642 }
3643 if (x != '') setDialogMode(2, "Sessions" + ' - ' + EscapeHtml(node.name), 1, null, x, 'SESSIONS-' + node._id);
@@ -5262,7 +5268,7 @@
5268 currentNode = node;
5269
5270 // Device Notification
5265 - QV('p10deviceNotify', (currentNode.sessions != null) && ((currentNode.sessions.kvm != null) || (currentNode.sessions.terminal != null) || (currentNode.sessions.files != null)));
5271 + QV('p10deviceNotify', (currentNode.sessions != null) && ((currentNode.sessions.kvm != null) || (currentNode.sessions.terminal != null) || (currentNode.sessions.files != null) || (currentNode.sessions.tcp != null) || (currentNode.sessions.udp != null)));
5272
5273 // Device Battery
5274 QV('p10deviceBattery', false);