From acb9a5bb6e169962249a5ef14fa145ed3a53fec9 Mon Sep 17 00:00:00 2001 From: Ylian Saint-Hilaire Date: Thu, 14 Jul 2022 15:18:41 -0700 Subject: [PATCH] Fixed Web-RDP when used with non-default domain (#4271) --- apprelays.js | 3 ++- public/scripts/agent-rdp-0.0.1.js | 6 +++--- views/default.handlebars | 2 +- webserver.js | 7 ++++--- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/apprelays.js b/apprelays.js index 24a03a13..b899a58c 100644 --- a/apprelays.js +++ b/apprelays.js @@ -775,7 +775,8 @@ module.exports.CreateMstscRelay = function (parent, db, ws, req, args, domain) { const protocol = (args.tlsoffload) ? 'ws' : 'wss'; var domainadd = ''; if ((domain.dns == null) && (domain.id != '')) { domainadd = domain.id + '/' } - const url = protocol + '://localhost:' + args.port + '/' + domainadd + (((obj.mtype == 3) && (obj.relaynodeid == null)) ? 'local' : 'mesh') + 'relay.ashx?p=10&auth=' + obj.infos.ip; // Protocol 10 is Web-RDP + var url = protocol + '://localhost:' + args.port + '/' + domainadd + (((obj.mtype == 3) && (obj.relaynodeid == null)) ? 'local' : 'mesh') + 'relay.ashx?p=10&auth=' + obj.infos.ip; // Protocol 10 is Web-RDP + if (domain.id != '') { url += '&domainid=' + domain.id; } // Since we are using "localhost", we are going to signal what domain we are on using a URL argument. parent.parent.debug('relay', 'RDP: Connection websocket to ' + url); obj.wsClient = new WebSocket(url, options); obj.wsClient.on('open', function () { parent.parent.debug('relay', 'RDP: Relay websocket open'); }); diff --git a/public/scripts/agent-rdp-0.0.1.js b/public/scripts/agent-rdp-0.0.1.js index 9c298870..affa3e45 100644 --- a/public/scripts/agent-rdp-0.0.1.js +++ b/public/scripts/agent-rdp-0.0.1.js @@ -5,9 +5,9 @@ */ // Construct a RDP remote desktop object -var CreateRDPDesktop = function (canvasid) { +var CreateRDPDesktop = function (canvasid, domainUrl) { var obj = {} - obj.m = { KeyAction: { "NONE": 0, "DOWN": 1, "UP": 2, "SCROLL": 3, "EXUP": 4, "EXDOWN": 5, "DBLCLICK": 6 } }; + obj.m = { KeyAction: { 'NONE': 0, 'DOWN': 1, 'UP': 2, 'SCROLL': 3, 'EXUP': 4, 'EXDOWN': 5, 'DBLCLICK': 6 } }; obj.State = 0; obj.canvas = Q(canvasid); obj.CanvasId = canvasid; @@ -41,7 +41,7 @@ var CreateRDPDesktop = function (canvasid) { delete credentials.height; } obj.render = new Mstsc.Canvas.create(obj.canvas); - obj.socket = new WebSocket('wss://' + window.location.host + '/mstscrelay.ashx'); // TODO: Support domains + obj.socket = new WebSocket('wss://' + window.location.host + domainUrl + 'mstscrelay.ashx'); obj.socket.binaryType = 'arraybuffer'; obj.socket.onopen = function () { changeState(2); // Setup state diff --git a/views/default.handlebars b/views/default.handlebars index 4522344f..b4e8c9fd 100644 --- a/views/default.handlebars +++ b/views/default.handlebars @@ -8686,7 +8686,7 @@ meshserver.send({ action: 'msg', type: 'userSessions', nodeid: currentNode._id, tag: consent }); } else if (contype == 4) { // Setup RDP remote desktop - desktop = CreateRDPDesktop('Desk'); + desktop = CreateRDPDesktop('Desk', domainUrl); desktop.onStateChanged = onDesktopStateChange; desktop.m.onScreenSizeChange = mdeskAdjust; desktop.m.onClipboardChanged = function(text) { if ((text != null) && (desktopsettings.rdpautoclipboard) && (navigator.clipboard != null)) { navigator.clipboard.writeText(text).then(function() { }).catch(function(err) { console.log(err); }) } } // Put remote clipboard data into our clipboard diff --git a/webserver.js b/webserver.js index 9050e83a..7ac0ae21 100644 --- a/webserver.js +++ b/webserver.js @@ -754,10 +754,11 @@ module.exports.CreateWebServer = function (parent, db, args, certificates, doneF // Request or connection says open regardless of the response function getDomain(req) { if (req.xdomain != null) { return req.xdomain; } // Domain already set for this request, return it. - if (req.headers.host != null) { var d = obj.dnsDomains[req.headers.host.split(':')[0].toLowerCase()]; if (d != null) return d; } // If this is a DNS name domain, return it here. - var x = req.url.split('/'); + if ((req.hostname == 'localhost') && (req.query.domainid != null)) { const d = parent.config.domains[req.query.domainid]; if (d != null) return d; } // This is a localhost access with the domainid specified in the URL + if (req.hostname != null) { const d = obj.dnsDomains[req.hostname.toLowerCase()]; if (d != null) return d; } // If this is a DNS name domain, return it here. + const x = req.url.split('/'); if (x.length < 2) return parent.config.domains['']; - var y = parent.config.domains[x[1].toLowerCase()]; + const y = parent.config.domains[x[1].toLowerCase()]; if ((y != null) && (y.dns == null)) { return parent.config.domains[x[1].toLowerCase()]; } return parent.config.domains['']; }