Added RDP viewonly and limited input.

Ylian Saint-Hilaire committed May 7, 2022 at 15:47 UTC fa8680c14e58686e17ebaad79c7ebbd810b1def2
3 files changed +74 -12
apprelays.js
+43 -8
@@ -34,6 +34,29 @@ const PROTOCOL_WEBSSH = 202;
34 const PROTOCOL_WEBSFTP = 203;
35 const PROTOCOL_WEBVNC = 204;
36
37 +// Mesh Rights
38 +const MESHRIGHT_EDITMESH = 0x00000001; // 1
39 +const MESHRIGHT_MANAGEUSERS = 0x00000002; // 2
40 +const MESHRIGHT_MANAGECOMPUTERS = 0x00000004; // 4
41 +const MESHRIGHT_REMOTECONTROL = 0x00000008; // 8
42 +const MESHRIGHT_AGENTCONSOLE = 0x00000010; // 16
43 +const MESHRIGHT_SERVERFILES = 0x00000020; // 32
44 +const MESHRIGHT_WAKEDEVICE = 0x00000040; // 64
45 +const MESHRIGHT_SETNOTES = 0x00000080; // 128
46 +const MESHRIGHT_REMOTEVIEWONLY = 0x00000100; // 256
47 +const MESHRIGHT_NOTERMINAL = 0x00000200; // 512
48 +const MESHRIGHT_NOFILES = 0x00000400; // 1024
49 +const MESHRIGHT_NOAMT = 0x00000800; // 2048
50 +const MESHRIGHT_DESKLIMITEDINPUT = 0x00001000; // 4096
51 +const MESHRIGHT_LIMITEVENTS = 0x00002000; // 8192
52 +const MESHRIGHT_CHATNOTIFY = 0x00004000; // 16384
53 +const MESHRIGHT_UNINSTALL = 0x00008000; // 32768
54 +const MESHRIGHT_NODESKTOP = 0x00010000; // 65536
55 +const MESHRIGHT_REMOTECOMMAND = 0x00020000; // 131072
56 +const MESHRIGHT_RESETOFF = 0x00040000; // 262144
57 +const MESHRIGHT_GUESTSHARING = 0x00080000; // 524288
58 +const MESHRIGHT_DEVICEDETAILS = 0x00100000; // 1048576
59 +const MESHRIGHT_ADMIN = 0xFFFFFFFF;
60
61 // Construct a MSTSC Relay object, called upon connection
62 // This implementation does not have TLS support
@@ -233,11 +256,12 @@ module.exports.CreateMstscRelay = function (parent, db, ws, req, args, domain) {
256 obj.userid = obj.cookie.userid;
257 }
258
236 - // Get node
237 - parent.parent.db.Get(obj.nodeid, function (err, nodes) {
259 + // Get node and rights
260 + parent.GetNodeWithRights(domain, obj.userid, obj.nodeid, function (node, rights, visible) {
261 if (obj.ws == null) return; // obj has been cleaned up, just exit.
239 - if ((err != null) || (nodes == null) || (nodes.length != 1)) { obj.close(); return; }
240 - const node = nodes[0];
262 + if ((node == null) || (visible == false) || ((rights & MESHRIGHT_REMOTECONTROL) == 0)) { obj.close(); return; }
263 + if ((rights != MESHRIGHT_ADMIN) && ((rights & MESHRIGHT_REMOTEVIEWONLY) != 0)) { obj.viewonly = true; }
264 + if ((rights != MESHRIGHT_ADMIN) && ((rights & MESHRIGHT_DESKLIMITEDINPUT) != 0)) { obj.limitedinput = true; }
265 obj.mtype = node.mtype; // Store the device group type
266 obj.meshid = node.meshid; // Store the MeshID
267
@@ -287,10 +311,21 @@ module.exports.CreateMstscRelay = function (parent, db, ws, req, args, domain) {
311 });
312 break;
313 }
290 - case 'mouse': { if (rdpClient) { rdpClient.sendPointerEvent(msg[1], msg[2], msg[3], msg[4]); } break; }
291 - case 'wheel': { if (rdpClient) { rdpClient.sendWheelEvent(msg[1], msg[2], msg[3], msg[4]); } break; }
292 - case 'scancode': { if (rdpClient) { rdpClient.sendKeyEventScancode(msg[1], msg[2]); } break; }
293 - case 'unicode': { if (rdpClient) { rdpClient.sendKeyEventUnicode(msg[1], msg[2]); } break; }
314 + case 'mouse': { if (rdpClient && (obj.viewonly != true)) { rdpClient.sendPointerEvent(msg[1], msg[2], msg[3], msg[4]); } break; }
315 + case 'wheel': { if (rdpClient && (obj.viewonly != true)) { rdpClient.sendWheelEvent(msg[1], msg[2], msg[3], msg[4]); } break; }
316 + case 'scancode': {
317 + if (obj.limitedinput == true) { // Limit keyboard input
318 + var ok = false, k = msg[1];
319 + if ((k >= 2) && (k <= 11)) { ok = true; } // Number keys 1 to 0
320 + if ((k >= 16) && (k <= 25)) { ok = true; } // First keyboard row
321 + if ((k >= 30) && (k <= 38)) { ok = true; } // Second keyboard row
322 + if ((k >= 44) && (k <= 50)) { ok = true; } // Third keyboard row
323 + if ((k == 14) || (k == 28)) { ok = true; } // Enter and backspace
324 + if (ok == false) return;
325 + }
326 + if (rdpClient && (obj.viewonly != true)) { rdpClient.sendKeyEventScancode(msg[1], msg[2]); } break;
327 + }
328 + case 'unicode': { if (rdpClient && (obj.viewonly != true)) { rdpClient.sendKeyEventUnicode(msg[1], msg[2]); } break; }
329 case 'utype': {
330 if (!rdpClient) return;
331 obj.utype = msg[1];
public/scripts/agent-rdp-0.0.1.js
+28 -1
@@ -7,7 +7,7 @@
7 // Construct a RDP remote desktop object
8 var CreateRDPDesktop = function (canvasid) {
9 var obj = {}
10 - obj.m = {};
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;
@@ -153,12 +153,14 @@ var CreateRDPDesktop = function (canvasid) {
153 }
154 obj.m.handleKeyUp = function (e) {
155 if (!obj.socket || (obj.State != 3)) return;
156 + console.log('handleKeyUp', Mstsc.scancode(e));
157 obj.socket.send(JSON.stringify(['scancode', Mstsc.scancode(e), false]));
158 e.preventDefault();
159 return false;
160 }
161 obj.m.handleKeyDown = function (e) {
162 if (!obj.socket || (obj.State != 3)) return;
163 + console.log('handleKeyDown', Mstsc.scancode(e));
164 obj.socket.send(JSON.stringify(['scancode', Mstsc.scancode(e), true]));
165 e.preventDefault();
166 return false;
@@ -178,6 +180,31 @@ var CreateRDPDesktop = function (canvasid) {
180 if (!obj.socket || (obj.State != 3)) return;
181 obj.socket.send(JSON.stringify(['utype', txt]));
182 }
183 + obj.m.SendKeyMsgKC = function (action, kc, extendedKey) {
184 + if (obj.State != 3) return;
185 +
186 + console.log('SendKeyMsgKC', action);
187 +
188 + /*
189 + if (typeof action == 'object') { for (var i in action) { obj.m.SendKeyMsgKC(action[i][0], action[i][1], action[i][2]); } }
190 + else {
191 + console.log(action, kc, extendedKey);
192 + obj.socket.send(JSON.stringify(['scancode', kc, (action == 1)]));
193 +
194 + if (action == 1) { // Key Down
195 + if (obj.pressedKeys.indexOf(kc) == -1) { obj.pressedKeys.unshift(kc); } // Add key press to start of array
196 + } else if (action == 2) { // Key Up
197 + var i = obj.pressedKeys.indexOf(kc);
198 + if (i != -1) { obj.pressedKeys.splice(i, 1); } // Remove the key press from the pressed array
199 + }
200 + if (obj.debugmode > 0) { console.log('Sending Key ' + kc + ', action ' + action); }
201 +
202 + var up = (action - 1);
203 + if (extendedKey) { if (up == 1) { up = 3; } else { up = 4; } }
204 + obj.send(String.fromCharCode(0x00, obj.InputType.KEY, 0x00, 0x06, up, kc));
205 + }
206 + */
207 + }
208 obj.m.mousedblclick = function () { }
209 obj.m.handleKeyPress = function () { }
210 obj.m.setRotation = function () { }
views/default.handlebars
+3 -3
@@ -8330,12 +8330,12 @@
8330 QV('DeskClip', (inputAllowed) && (currentNode.agent) && ((features2 & 0x1800) != 0x1800) && (currentNode.agent.id != 11) && (currentNode.agent.id != 16) && ((desktop == null) || (desktop.contype != 2)) && ((desktopsettings.autoclipboard != true) || (navigator.clipboard == null) || (navigator.clipboard.readText == null))); // Clipboard not supported on macOS
8331 QE('DeskESC', (deskState == 3) && (desktop.contype != 4));
8332 QV('DeskESC', browserfullscreen && inputAllowed);
8333 - QE('DeskType', (deskState == 3)); // && (desktop.contype != 4)
8333 + QE('DeskType', deskState == 3);
8334 QV('DeskType', inputAllowed);
8335 - QE('DeskWD', (deskState == 3) && (desktop.contype != 4));
8335 + QE('DeskWD', deskState == 3);
8336 QV('DeskWD', inputAllowed);
8337 QV('deskkeys', inputAllowed);
8338 - QE('deskkeys', (desktop != null) && (desktop.contype != 4));
8338 + QE('deskkeys', desktop != null);
8339 QV('DeskTimer', deskState == 3);
8340
8341 // Enable browser clipboard read if supported