From f2bebe004d36f5987cd1e6ae54b2c851b9674440 Mon Sep 17 00:00:00 2001 From: Ylian Saint-Hilaire Date: Thu, 4 Mar 2021 17:03:25 -0800 Subject: [PATCH] Added relay mapping support to deviceMeshRouterLinks. --- meshcentral-config-schema.json | 4 ++++ meshuser.js | 1 + sample-config-advanced.json | 1 + views/default.handlebars | 7 ++++--- 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/meshcentral-config-schema.json b/meshcentral-config-schema.json index ecf181dc..c63236b0 100644 --- a/meshcentral-config-schema.json +++ b/meshcentral-config-schema.json @@ -248,6 +248,10 @@ "description": "The port on the remote device.", "type": "number" }, + "ip": { + "description": "Target IP address. If not specified, the target of the connection is the remote device running the MeshAgent.", + "type": "string" + }, "filter": { "description": "Array of node/domain/id or mesh/domain/id strings. When set, the link will only show up for the specified devices or device groups.", "type": "array", diff --git a/meshuser.js b/meshuser.js index aae2ef48..e8545cdc 100644 --- a/meshuser.js +++ b/meshuser.js @@ -4160,6 +4160,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use if (command.nodeid) { cookieContent.nodeid = command.nodeid; } if (command.tcpaddr) { cookieContent.tcpaddr = command.tcpaddr; } // Indicates the browser want to agent to TCP connect to a remote address if (command.tcpport) { cookieContent.tcpport = command.tcpport; } // Indicates the browser want to agent to TCP connect to a remote port + if (command.ip) { cookieContent.ip = command.ip; } // Indicates the browser want to agent to relay a TCP connection to a IP:port command.cookie = parent.parent.encodeCookie(cookieContent, parent.parent.loginCookieEncryptionKey); command.trustedCert = parent.isTrustedCert(domain); try { ws.send(JSON.stringify(command)); } catch (ex) { } diff --git a/sample-config-advanced.json b/sample-config-advanced.json index 29999e2f..8a3caad7 100644 --- a/sample-config-advanced.json +++ b/sample-config-advanced.json @@ -158,6 +158,7 @@ "name": "HTTP", "protocol": "http", "port": 80, + "_ip": "192.168.1.100", "_filter": [ "mesh//xxxx", "node//xxxx" ] }, { diff --git a/views/default.handlebars b/views/default.handlebars index cec4115b..b51bdbb9 100644 --- a/views/default.handlebars +++ b/views/default.handlebars @@ -2419,6 +2419,7 @@ var url = 'mcrouter://' + servername + portStr + domainUrl + 'control.ashx?c=' + authCookie + '&t=' + serverinfo.tlshash + '&l={{{lang}}}' + (urlargs.key?('&key=' + urlargs.key):''); if (message.nodeid != null) { url += ('&nodeid=' + message.nodeid); } if (message.tcpport != null) { url += ('&protocol=1&remoteport=' + message.tcpport); } + if (message.ip != null) { url += ('&remoteip=' + message.ip); } url += ('&appid=' + message.protocol + '&autoexit=1'); // Protocol: 0 = Custom, 1 = HTTP, 2 = HTTPS, 3 = RDP, 4 = PuTTY, 5 = WinSCP downloadFile(url, ''); } else if (message.tag == 'novnc') { @@ -6146,7 +6147,7 @@ var r = serverinfo.devicemeshrouterlinks.extralinks[i], p = 0; if ((r.filter == null) || (Array.isArray(r.filter) && ((r.filter.indexOf(mesh._id) >= 0) || (r.filter.indexOf(node._id) >= 0)))) { 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; } - x += '' + r.name + ' '; + x += '' + r.name + ' '; } } } @@ -6820,9 +6821,9 @@ meshserver.send({ action: 'removedevices', nodeids: [ nodeid ] }); } - function p10MCRouter(nodeid, protocol, port) { + function p10MCRouter(nodeid, protocol, port, ip) { if ((protocol == 3) && (port == null)) { if (currentNode.rdpport != null) { port = currentNode.rdpport; } else { port = 3389; } } - meshserver.send({ action: 'getcookie', nodeid: nodeid, tcpport: port, tag: 'MCRouter', protocol: protocol }); // Protocol: 0 = Custom, 1 = HTTP, 2 = HTTPS, 3 = RDP, 4 = PuTTY, 5 = WinSCP + 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 return false; }