Fixed Web-RDP when used with non-default domain (#4271)
Ylian Saint-Hilaire committed
Jul 14, 2022 at 15:18 UTC
acb9a5bb6e169962249a5ef14fa145ed3a53fec9
4 files changed
+10
-8
apprelays.js
+2
-1
@@ -775,7 +775,8 @@ module.exports.CreateMstscRelay = function (parent, db, ws, req, args, domain) {
775
const protocol = (args.tlsoffload) ? 'ws' : 'wss';
776
var domainadd = '';
777
if ((domain.dns == null) && (domain.id != '')) { domainadd = domain.id + '/' }
778
- 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
778
+ 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
779
+ 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.
780
parent.parent.debug('relay', 'RDP: Connection websocket to ' + url);
781
obj.wsClient = new WebSocket(url, options);
782
obj.wsClient.on('open', function () { parent.parent.debug('relay', 'RDP: Relay websocket open'); });
public/scripts/agent-rdp-0.0.1.js
+3
-3
@@ -5,9 +5,9 @@
5
*/
6
7
// Construct a RDP remote desktop object
8
-var CreateRDPDesktop = function (canvasid) {
8
+var CreateRDPDesktop = function (canvasid, domainUrl) {
9
var obj = {}
10
- obj.m = { KeyAction: { "NONE": 0, "DOWN": 1, "UP": 2, "SCROLL": 3, "EXUP": 4, "EXDOWN": 5, "DBLCLICK": 6 } };
10
+ obj.m = { KeyAction: { 'NONE': 0, 'DOWN': 1, 'UP': 2, 'SCROLL': 3, 'EXUP': 4, 'EXDOWN': 5, 'DBLCLICK': 6 } };
11
obj.State = 0;
12
obj.canvas = Q(canvasid);
13
obj.CanvasId = canvasid;
@@ -41,7 +41,7 @@ var CreateRDPDesktop = function (canvasid) {
41
delete credentials.height;
42
}
43
obj.render = new Mstsc.Canvas.create(obj.canvas);
44
- obj.socket = new WebSocket('wss://' + window.location.host + '/mstscrelay.ashx'); // TODO: Support domains
44
+ obj.socket = new WebSocket('wss://' + window.location.host + domainUrl + 'mstscrelay.ashx');
45
obj.socket.binaryType = 'arraybuffer';
46
obj.socket.onopen = function () {
47
changeState(2); // Setup state
views/default.handlebars
+1
-1
@@ -8686,7 +8686,7 @@
8686
meshserver.send({ action: 'msg', type: 'userSessions', nodeid: currentNode._id, tag: consent });
8687
} else if (contype == 4) {
8688
// Setup RDP remote desktop
8689
- desktop = CreateRDPDesktop('Desk');
8689
+ desktop = CreateRDPDesktop('Desk', domainUrl);
8690
desktop.onStateChanged = onDesktopStateChange;
8691
desktop.m.onScreenSizeChange = mdeskAdjust;
8692
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
webserver.js
+4
-3
@@ -754,10 +754,11 @@ module.exports.CreateWebServer = function (parent, db, args, certificates, doneF
754
// Request or connection says open regardless of the response
755
function getDomain(req) {
756
if (req.xdomain != null) { return req.xdomain; } // Domain already set for this request, return it.
757
- 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.
758
- var x = req.url.split('/');
757
+ 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
758
+ 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.
759
+ const x = req.url.split('/');
760
if (x.length < 2) return parent.config.domains[''];
760
- var y = parent.config.domains[x[1].toLowerCase()];
761
+ const y = parent.config.domains[x[1].toLowerCase()];
762
if ((y != null) && (y.dns == null)) { return parent.config.domains[x[1].toLowerCase()]; }
763
return parent.config.domains[''];
764
}