diff --git a/agents/meshcore.js b/agents/meshcore.js index 27e48504..1d759b96 100644 --- a/agents/meshcore.js +++ b/agents/meshcore.js @@ -1608,6 +1608,10 @@ function onTunnelData(data) { if ((data.length > 3) && (data[0] == '{')) { onTunnelControlData(data, this); return; } this.httprequest.protocol = parseInt(data); if (typeof this.httprequest.protocol != 'number') { this.httprequest.protocol = 0; } + + // See if this protocol request is allowed. + if ((this.httprequest.soptions != null) && (this.httprequest.soptions.usages != null) && (this.httprequest.soptions.usages.indexOf(this.httprequest.protocol) == -1)) { this.httprequest.protocol = 0; } + if (this.httprequest.protocol == 10) { // // Basic file transfer @@ -1882,7 +1886,7 @@ function onTunnelData(data) { } else if (this.httprequest.protocol == 2) { // - // Remote KVM + // Remote Desktop // // Check user access rights for desktop diff --git a/meshrelay.js b/meshrelay.js index 72f997f3..6c94488a 100644 --- a/meshrelay.js +++ b/meshrelay.js @@ -771,7 +771,17 @@ function CreateMeshRelayEx(parent, ws, req, domain, user, cookie) { // Send connection request to agent if (obj.id == null) { obj.id = ('' + Math.random()).substring(2); } const rcookie = parent.parent.encodeCookie({ ruserid: user._id, nodeid: node._id }, parent.parent.loginCookieEncryptionKey); - const command = { nodeid: node._id, action: 'msg', type: 'tunnel', userid: user._id, value: '*/meshrelay.ashx?p=' + cookie.p + '&id=' + obj.id + '&rauth=' + rcookie + '&nodeid=' + node._id, soptions: {}, usage: 2, rights: cookie.r, guestname: cookie.gn, consent: cookie.cf, remoteaddr: cleanRemoteAddr(obj.req.clientIp) }; + const command = { nodeid: node._id, action: 'msg', type: 'tunnel', userid: user._id, value: '*/meshrelay.ashx?p=' + cookie.p + '&id=' + obj.id + '&rauth=' + rcookie + '&nodeid=' + node._id, soptions: {}, rights: cookie.r, guestname: cookie.gn, consent: cookie.cf, remoteaddr: cleanRemoteAddr(obj.req.clientIp) }; + + // Limit what this relay connection can do + if (typeof cookie.p == 'number') { + var usages = []; + if (cookie.p & 1) { usages.push(1); usages.push(6); usages.push(8); usages.push(9); } // Terminal + if (cookie.p & 2) { usages.push(2); } // Desktop + if (cookie.p & 4) { usages.push(5); usages.push(10); } // Files + command.soptions.usages = usages; + } + if (typeof domain.consentmessages == 'object') { if (typeof domain.consentmessages.title == 'string') { command.soptions.consentTitle = domain.consentmessages.title; } if (typeof domain.consentmessages.desktop == 'string') { command.soptions.consentMsgDesktop = domain.consentmessages.desktop; } diff --git a/meshuser.js b/meshuser.js index 35f13296..1088b778 100644 --- a/meshuser.js +++ b/meshuser.js @@ -5015,7 +5015,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use else if ((command.start != null) && (typeof command.start != 'number')) { err = 'Invalid start time'; } // Check the start time in seconds else if ((command.end != null) && (typeof command.end != 'number')) { err = 'Invalid end time'; } // Check the end time in seconds else if (common.validateInt(command.consent, 0, 256) == false) { err = 'Invalid flags'; } // Check the flags - else if (common.validateInt(command.p, 1, 2) == false) { err = 'Invalid protocol'; } // Check the protocol, 1 = Terminal, 2 = Desktop + else if (common.validateInt(command.p, 1, 7) == false) { err = 'Invalid protocol'; } // Check the protocol, 1 = Terminal, 2 = Desktop, 4 = Files else if ((command.expire == null) && ((command.start == null) || (command.end == null) || (command.start > command.end))) { err = 'No time specified'; } // Check that a time range is present else { if (command.nodeid.split('/').length == 1) { command.nodeid = 'node/' + domain.id + '/' + command.nodeid; } @@ -5047,13 +5047,25 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use } // If we are limited to no terminal, don't allow terminal sharing - if ((command.p == 1) && (rights != MESHRIGHT_ADMIN) && ((rights & MESHRIGHT_NOTERMINAL) != 0)) { + if (((command.p & 1) != 0) && (rights != MESHRIGHT_ADMIN) && ((rights & MESHRIGHT_NOTERMINAL) != 0)) { if (command.responseid != null) { try { ws.send(JSON.stringify({ action: 'deviceShares', responseid: command.responseid, result: 'Access denied' })); } catch (ex) { } } - return; + return; + } + + // If we are limited to no desktop, don't allow desktop sharing + if (((command.p & 2) != 0) && (rights != MESHRIGHT_ADMIN) && ((rights & MESHRIGHT_NODESKTOP) != 0)) { + if (command.responseid != null) { try { ws.send(JSON.stringify({ action: 'deviceShares', responseid: command.responseid, result: 'Access denied' })); } catch (ex) { } } + return; + } + + // If we are limited to no files, don't allow file sharing + if (((command.p & 4) != 0) && (rights != MESHRIGHT_ADMIN) && ((rights & MESHRIGHT_NOFILES) != 0)) { + if (command.responseid != null) { try { ws.send(JSON.stringify({ action: 'deviceShares', responseid: command.responseid, result: 'Access denied' })); } catch (ex) { } } + return; } // If we have view only remote desktop rights, force view-only on the guest share. - if ((rights != MESHRIGHT_ADMIN) && ((rights & MESHRIGHT_REMOTEVIEWONLY) != 0)) { command.viewOnly = true; } + if ((rights != MESHRIGHT_ADMIN) && ((rights & MESHRIGHT_REMOTEVIEWONLY) != 0)) { command.viewOnly = true; command.p = (command.p & 1); } // Create cookie var publicid = getRandomPassword(), startTime, expireTime; @@ -5079,8 +5091,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use var httpsPort = ((args.aliasport == null) ? args.port : args.aliasport); // Use HTTPS alias port is specified var xdomain = (domain.dns == null) ? domain.id : ''; if (xdomain != '') xdomain += '/'; - var page = (command.p == 1) ? 'terminal' : 'desktop'; - var url = 'https://' + serverName + ':' + httpsPort + '/' + xdomain + page + '?c=' + inviteCookie; + var url = 'https://' + serverName + ':' + httpsPort + '/' + xdomain + 'sharing?c=' + inviteCookie; if (serverName.split('.') == 1) { url = '/' + xdomain + page + '?c=' + inviteCookie; } command.url = url; if (command.responseid != null) { command.result = 'OK'; } diff --git a/views/default.handlebars b/views/default.handlebars index 6eab24e6..a03228d3 100644 --- a/views/default.handlebars +++ b/views/default.handlebars @@ -626,7 +626,7 @@ -
+