Fixed desktop multiplexor view-only mode.

Ylian Saint-Hilaire committed Jun 30, 2021 at 00:01 UTC 85f8db041b51755e9d8c9c50bb4b5c2e00350e2a
3 files changed +60 -38
agents/meshcore.js
+1 -1
@@ -2156,7 +2156,7 @@ function onTunnelData(data) {
2156 this.pipe(this.httprequest.desktop.kvm, { dataTypeSkip: 1, end: false }); // 0 = Binary, 1 = Text. Pipe the Browser --> KVM input.
2157 } else {
2158 // We need to only pipe non-mouse & non-keyboard inputs.
2159 - //sendConsoleText('Warning: No Remote Desktop Input Rights.');
2159 + // sendConsoleText('Warning: No Remote Desktop Input Rights.');
2160 // TODO!!!
2161 }
2162
meshdesktopmultiplex.js
+27 -5
@@ -339,6 +339,12 @@ function CreateDesktopMultiplexor(parent, domain, nodeid, func) {
339 for (var i in obj.viewers) { obj.sendToViewer(obj.viewers[i], data); }
340 }
341
342 + // Send this command to all viewers
343 + obj.sendToAllInputViewers = function (data) {
344 + if (obj.viewers == null) return;
345 + for (var i in obj.viewers) { if (obj.viewers[i].viewOnly != true) { obj.sendToViewer(obj.viewers[i], data); } }
346 + }
347 +
348 // Send data to the viewer or queue it up for sending
349 obj.sendToViewer = function (viewer, data) {
350 if ((viewer == null) || (obj.viewers == null)) return;
@@ -665,10 +671,10 @@ function CreateDesktopMultiplexor(parent, domain, nodeid, func) {
671 case 11: // GetDisplays
672 // Store and send this to all viewers right away
673 obj.lastDisplayInfoData = data;
668 - obj.sendToAllViewers(data);
674 + obj.sendToAllInputViewers(data);
675 break;
676 case 12: // SetDisplay
671 - obj.sendToAllViewers(data);
677 + obj.sendToAllInputViewers(data);
678 break;
679 case 14: // KVM_INIT_TOUCH
680 break;
@@ -688,16 +694,16 @@ function CreateDesktopMultiplexor(parent, domain, nodeid, func) {
694 // Display information
695 if ((data.length < 14) || (((data.length - 4) % 10) != 0)) break; // Command must be 14 bytes and have header + 10 byte for each display.
696 obj.lastDisplayLocationData = data;
691 - obj.sendToAllViewers(data);
697 + obj.sendToAllInputViewers(data);
698 break;
699 case 87: // MNG_KVM_INPUT_LOCK
700 // Send this to all viewers right away
701 // This will update all views on the current state of the input lock
696 - obj.sendToAllViewers(data);
702 + obj.sendToAllInputViewers(data);
703 break;
704 case 88: // MNG_KVM_MOUSE_CURSOR
705 // Send this to all viewers right away
700 - obj.sendToAllViewers(data);
706 + obj.sendToAllInputViewers(data);
707 break;
708 default:
709 console.log('Un-handled agent command: ' + command);
@@ -915,6 +921,22 @@ function CreateMeshRelayEx2(parent, ws, req, domain, user, cookie) {
921 // If there is no authentication, drop this connection
922 if ((obj.id != null) && (obj.user == null) && (obj.ruserid == null)) { try { ws.close(); parent.parent.debug('relay', 'DesktopRelay: Connection with no authentication (' + obj.req.clientIp + ')'); } catch (e) { console.log(e); } return; }
923
924 + // Check if this user has input access on the device
925 + if ((obj.user != null) && (obj.viewOnly == false)) {
926 + obj.viewOnly = true; // Set a view only for now until we figure out otherwise
927 + parent.db.Get(obj.nodeid, function (err, docs) {
928 + if (obj.req == null) return; // This connection was closed.
929 + if (docs.length == 0) { console.log('ERR: Node not found'); try { obj.close(); } catch (e) { } return; } // Disconnect websocket
930 + const node = docs[0];
931 +
932 + // Check if this user has permission to manage this computer
933 + const rights = parent.GetNodeRights(obj.user, node.meshid, node._id);
934 + if ((rights & 0x00000008) == 0) { try { obj.close(); } catch (e) { } return; } // Check MESHRIGHT_ADMIN or MESHRIGHT_REMOTECONTROL
935 + if ((rights != 0xFFFFFFFF) && ((rights & 0x00010000) != 0)) { try { obj.close(); } catch (e) { } return; } // Check MESHRIGHT_NODESKTOP
936 + if ((rights == 0xFFFFFFFF) || ((rights & 0x00000100) == 0)) { obj.viewOnly = false; } // Check MESHRIGHT_REMOTEVIEWONLY
937 + });
938 + }
939 +
940 // Relay session count (we may remove this in the future)
941 obj.relaySessionCounted = true;
942 parent.relaySessionCount++;
meshuser.js
+32 -32
@@ -31,41 +31,41 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
31 const USERCONSENT_ShowConnectionToolbar = 64;
32
33 // Mesh Rights
34 - const MESHRIGHT_EDITMESH = 0x00000001;
35 - const MESHRIGHT_MANAGEUSERS = 0x00000002;
36 - const MESHRIGHT_MANAGECOMPUTERS = 0x00000004;
37 - const MESHRIGHT_REMOTECONTROL = 0x00000008;
38 - const MESHRIGHT_AGENTCONSOLE = 0x00000010;
39 - const MESHRIGHT_SERVERFILES = 0x00000020;
40 - const MESHRIGHT_WAKEDEVICE = 0x00000040;
41 - const MESHRIGHT_SETNOTES = 0x00000080;
42 - const MESHRIGHT_REMOTEVIEWONLY = 0x00000100;
43 - const MESHRIGHT_NOTERMINAL = 0x00000200;
44 - const MESHRIGHT_NOFILES = 0x00000400;
45 - const MESHRIGHT_NOAMT = 0x00000800;
46 - const MESHRIGHT_DESKLIMITEDINPUT = 0x00001000;
47 - const MESHRIGHT_LIMITEVENTS = 0x00002000;
48 - const MESHRIGHT_CHATNOTIFY = 0x00004000;
49 - const MESHRIGHT_UNINSTALL = 0x00008000;
50 - const MESHRIGHT_NODESKTOP = 0x00010000;
51 - const MESHRIGHT_REMOTECOMMAND = 0x00020000;
52 - const MESHRIGHT_RESETOFF = 0x00040000;
53 - const MESHRIGHT_GUESTSHARING = 0x00080000;
34 + const MESHRIGHT_EDITMESH = 0x00000001; // 1
35 + const MESHRIGHT_MANAGEUSERS = 0x00000002; // 2
36 + const MESHRIGHT_MANAGECOMPUTERS = 0x00000004; // 4
37 + const MESHRIGHT_REMOTECONTROL = 0x00000008; // 8
38 + const MESHRIGHT_AGENTCONSOLE = 0x00000010; // 16
39 + const MESHRIGHT_SERVERFILES = 0x00000020; // 32
40 + const MESHRIGHT_WAKEDEVICE = 0x00000040; // 64
41 + const MESHRIGHT_SETNOTES = 0x00000080; // 128
42 + const MESHRIGHT_REMOTEVIEWONLY = 0x00000100; // 256
43 + const MESHRIGHT_NOTERMINAL = 0x00000200; // 512
44 + const MESHRIGHT_NOFILES = 0x00000400; // 1024
45 + const MESHRIGHT_NOAMT = 0x00000800; // 2048
46 + const MESHRIGHT_DESKLIMITEDINPUT = 0x00001000; // 4096
47 + const MESHRIGHT_LIMITEVENTS = 0x00002000; // 8192
48 + const MESHRIGHT_CHATNOTIFY = 0x00004000; // 16384
49 + const MESHRIGHT_UNINSTALL = 0x00008000; // 32768
50 + const MESHRIGHT_NODESKTOP = 0x00010000; // 65536
51 + const MESHRIGHT_REMOTECOMMAND = 0x00020000; // 131072
52 + const MESHRIGHT_RESETOFF = 0x00040000; // 262144
53 + const MESHRIGHT_GUESTSHARING = 0x00080000; // 524288
54 const MESHRIGHT_ADMIN = 0xFFFFFFFF;
55
56 // Site rights
57 - const SITERIGHT_SERVERBACKUP = 0x00000001;
58 - const SITERIGHT_MANAGEUSERS = 0x00000002;
59 - const SITERIGHT_SERVERRESTORE = 0x00000004;
60 - const SITERIGHT_FILEACCESS = 0x00000008;
61 - const SITERIGHT_SERVERUPDATE = 0x00000010;
62 - const SITERIGHT_LOCKED = 0x00000020;
63 - const SITERIGHT_NONEWGROUPS = 0x00000040;
64 - const SITERIGHT_NOMESHCMD = 0x00000080;
65 - const SITERIGHT_USERGROUPS = 0x00000100;
66 - const SITERIGHT_RECORDINGS = 0x00000200;
67 - const SITERIGHT_LOCKSETTINGS = 0x00000400;
68 - const SITERIGHT_ALLEVENTS = 0x00000800;
57 + const SITERIGHT_SERVERBACKUP = 0x00000001; // 1
58 + const SITERIGHT_MANAGEUSERS = 0x00000002; // 2
59 + const SITERIGHT_SERVERRESTORE = 0x00000004; // 4
60 + const SITERIGHT_FILEACCESS = 0x00000008; // 8
61 + const SITERIGHT_SERVERUPDATE = 0x00000010; // 16
62 + const SITERIGHT_LOCKED = 0x00000020; // 32
63 + const SITERIGHT_NONEWGROUPS = 0x00000040; // 64
64 + const SITERIGHT_NOMESHCMD = 0x00000080; // 128
65 + const SITERIGHT_USERGROUPS = 0x00000100; // 256
66 + const SITERIGHT_RECORDINGS = 0x00000200; // 512
67 + const SITERIGHT_LOCKSETTINGS = 0x00000400; // 1024
68 + const SITERIGHT_ALLEVENTS = 0x00000800; // 2048
69 const SITERIGHT_ADMIN = 0xFFFFFFFF;
70
71 // Events