Added MeshCentral Router local port support.

Ylian Saint-Hilaire committed May 12, 2021 at 12:05 UTC 02fd8751b069b14943ae00b03eb7222ec6594558
3 files changed +7 -46
agents/MeshCentralRouter.exe
Binary files a/agents/MeshCentralRouter.exe and b/agents/MeshCentralRouter.exe differ
meshuser.js
+3 -2
@@ -4335,8 +4335,9 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
4335 // Add a user authentication cookie to a url
4336 var cookieContent = { userid: user._id, domainid: user.domain };
4337 if (command.nodeid) { cookieContent.nodeid = command.nodeid; }
4338 - if (command.tcpaddr) { cookieContent.tcpaddr = command.tcpaddr; } // Indicates the browser want to agent to TCP connect to a remote address
4339 - if (command.tcpport) { cookieContent.tcpport = command.tcpport; } // Indicates the browser want to agent to TCP connect to a remote port
4338 + if (command.tcpaddr) { cookieContent.tcpaddr = command.tcpaddr; } // Indicates the browser want the agent to TCP connect to a remote address
4339 + if (command.tcpport) { cookieContent.tcpport = command.tcpport; } // Indicates the browser want the agent to TCP connect to a remote port
4340 + //if (command.localport) { cookieContent.localport = command.localport; } // Indicates the browser want MeshCenral Router to use a local port
4341 if (command.ip) { cookieContent.ip = command.ip; } // Indicates the browser want to agent to relay a TCP connection to a IP:port
4342 if (node.mtype == 3) { cookieContent.lc = 1; command.localRelay = true; } // Indicate this is for a local connection
4343 command.cookie = parent.parent.encodeCookie(cookieContent, parent.parent.loginCookieEncryptionKey);
views/default.handlebars
+4 -44
@@ -2482,6 +2482,7 @@
2482 if (message.nodeid != null) { url += ('&nodeid=' + message.nodeid); }
2483 if (message.tcpport != null) { url += ('&protocol=1&remoteport=' + message.tcpport); }
2484 if (message.localRelay) { url += '&local=1'; }
2485 + if (message.localport) { url += '&localport=' + message.localport; }
2486 if (message.ip != null) { url += ('&remoteip=' + message.ip); }
2487 url += ('&appid=' + message.protocol + '&autoexit=1'); // Protocol: 0 = Custom, 1 = HTTP, 2 = HTTPS, 3 = RDP, 4 = PuTTY, 5 = WinSCP
2488 downloadFile(url, '');
@@ -4191,47 +4192,6 @@
4192 }
4193 }
4194
4194 - // Return HTML with a list of MeshCentral Router links
4195 - function getShortRouterLinks(node) {
4196 - var x = '', meshrights = GetNodeRights(node);
4197 -
4198 - // RDP link, show this link only of the remote machine is Windows.
4199 - if (((node.conn & 1) != 0) && (node.agent) && ((meshrights & 8) != 0) && (node.agent.id != 14)) {
4200 - if ((node.agent.id > 0) && (node.agent.id < 5)) {
4201 - if (navigator.platform.toLowerCase() == 'win32') {
4202 - if ((serverinfo.devicemeshrouterlinks == null) || (serverinfo.devicemeshrouterlinks.rdp != false)) {
4203 - x += '<a href=# cmenu=altPortContextMenu id=rdpMCRouterLink onclick=p10MCRouter("' + node._id + '",3)>' + "RDP" + '</a>&nbsp;';
4204 - }
4205 - }
4206 - }
4207 - if (node.agent.id > 4) {
4208 - if ((navigator.platform.toLowerCase() == 'win32') || (navigator.platform.toLowerCase() == 'macintel')) {
4209 - if ((serverinfo.devicemeshrouterlinks == null) || (serverinfo.devicemeshrouterlinks.ssh != false)) {
4210 - x += '<a href=# onclick=p10MCRouter("' + node._id + '",4,22)>' + "SSH" + '</a>&nbsp;';
4211 - }
4212 - }
4213 - if (navigator.platform.toLowerCase() == 'win32') {
4214 - if ((serverinfo.devicemeshrouterlinks == null) || (serverinfo.devicemeshrouterlinks.scp != false)) {
4215 - x += '<a href=# onclick=p10MCRouter("' + node._id + '",5,22)>' + "SCP" + '</a>&nbsp;';
4216 - }
4217 - }
4218 - }
4219 - if ((navigator.platform.toLowerCase() == 'win32') || (navigator.platform.toLowerCase() == 'macintel')) {
4220 - if ((serverinfo.devicemeshrouterlinks != null) && (Array.isArray(serverinfo.devicemeshrouterlinks.extralinks))) {
4221 - for (var i in serverinfo.devicemeshrouterlinks.extralinks) {
4222 - var r = serverinfo.devicemeshrouterlinks.extralinks[i], p = 0;
4223 - if (doesDeviceMatchFilterTags(node, r.filter)) {
4224 - if (typeof r.protocol == 'number') { p = r.protocol; } else if (r.protocol == 'http') { p = 1; } else if (r.protocol == 'https') { p = 2; } else if (r.protocol == 'rdp') { p = 3; } else if (r.protocol == 'ssh') { p = 4; } else if (r.protocol == 'scp') { p = 5; }
4225 - x += '<a href=# onclick=p10MCRouter("' + node._id + '",' + p + ',' + r.port + (r.ip?(',\"' + r.ip + '\"'):'') + ')>' + r.name + '</a>&nbsp;';
4226 - }
4227 - }
4228 - }
4229 - }
4230 - }
4231 -
4232 - return x;
4233 - }
4234 -
4195 // Check if this device matches any of the given filters
4196 function doesDeviceMatchFilterTags(node, filter) {
4197 if (filter == null) return true; // No filters, every device matches.
@@ -6493,7 +6453,7 @@
6453 var r = serverinfo.devicemeshrouterlinks.extralinks[i], p = 0;
6454 if (doesDeviceMatchFilterTags(node, r.filter)) {
6455 if (typeof r.protocol == 'number') { p = r.protocol; } else if (r.protocol == 'http') { p = 1; } else if (r.protocol == 'https') { p = 2; } else if (r.protocol == 'rdp') { p = 3; } else if (r.protocol == 'ssh') { p = 4; } else if (r.protocol == 'scp') { p = 5; }
6496 - x += '<a href=# onclick=p10MCRouter("' + node._id + '",' + p + ',' + r.port + (r.ip?(',\"' + r.ip + '\"'):'') + ') title="' + "Requires installation of MeshCentral Router." + '">' + r.name + '</a>&nbsp;';
6456 + x += '<a href=# onclick=p10MCRouter("' + node._id + '",' + p + ',' + r.port + (r.ip?(',\"' + r.ip + '\"'):',null') + ',' + (r.localport?r.localport:0) + ') title="' + "Requires installation of MeshCentral Router." + '">' + r.name + '</a>&nbsp;';
6457 }
6458 }
6459 }
@@ -7274,10 +7234,10 @@
7234 meshserver.send({ action: 'removedevices', nodeids: [ nodeid ] });
7235 }
7236
7277 - function p10MCRouter(nodeid, protocol, port, ip) {
7237 + function p10MCRouter(nodeid, protocol, port, ip, localport) {
7238 var node = getNodeFromId(nodeid);
7239 if ((protocol == 3) && (port == null)) { if (node.rdpport != null) { port = node.rdpport; } else { port = 3389; } }
7280 - meshserver.send({ action: 'getcookie', nodeid: nodeid, tcpport: port, ip: ip, tag: 'MCRouter', protocol: protocol }); // Protocol: 0 = Custom, 1 = HTTP, 2 = HTTPS, 3 = RDP, 4 = PuTTY, 5 = WinSCP
7240 + meshserver.send({ action: 'getcookie', nodeid: nodeid, tcpport: port, ip: ip, tag: 'MCRouter', protocol: protocol, localport: localport }); // Protocol: 0 = Custom, 1 = HTTP, 2 = HTTPS, 3 = RDP, 4 = PuTTY, 5 = WinSCP
7241 return false;
7242 }
7243