Added support for locking user desktop on Windows.

Ylian Saint-Hilaire committed Apr 26, 2021 at 18:27 UTC 3a92c077b91650fc761d64e52a392c211ebba661
2 files changed +20 -26
agents/meshcore.js
+17 -22
@@ -1610,7 +1610,7 @@ function onTunnelClosed() {
1610 function onTunnelSendOk() { /*sendConsoleText("Tunnel #" + this.index + " SendOK.", this.sessionid);*/ }
1611 function onTunnelData(data) {
1612 //console.log("OnTunnelData");
1613 - //sendConsoleText('OnTunnelData, ' + data.length + ', ' + typeof data + ', ' + data);
1613 + sendConsoleText('OnTunnelData, ' + data.length + ', ' + typeof data + ', ' + data);
1614
1615 // If this is upload data, save it to file
1616 if ((this.httprequest.uploadFile) && (typeof data == 'object') && (data[0] != 123)) {
@@ -2547,30 +2547,25 @@ function onTunnelControlData(data, ws) {
2547 if (ws == null) { ws = this; }
2548 if (typeof data == 'string') { try { obj = JSON.parse(data); } catch (e) { sendConsoleText('Invalid control JSON: ' + data); return; } }
2549 else if (typeof data == 'object') { obj = data; } else { return; }
2550 - //sendConsoleText('onTunnelControlData(' + ws.httprequest.protocol + '): ' + JSON.stringify(data));
2550 + sendConsoleText('onTunnelControlData(' + ws.httprequest.protocol + '): ' + JSON.stringify(data));
2551 //console.log('onTunnelControlData: ' + JSON.stringify(data));
2552
2553 - if (obj.action) {
2554 - switch (obj.action) {
2555 - case 'lock': {
2556 - // Lock the current user out of the desktop
2557 - try {
2558 - if (process.platform == 'win32') {
2559 - MeshServerLogEx(53, null, "Locking remote user out of desktop", ws.httprequest);
2560 - var child = require('child_process');
2561 - child.execFile(process.env['windir'] + '\\system32\\cmd.exe', ['/c', 'RunDll32.exe user32.dll,LockWorkStation'], { type: 1 });
2562 - }
2563 - } catch (e) { }
2564 - break;
2565 - }
2566 - default:
2567 - // Unknown action, ignore it.
2568 - break;
2569 - }
2570 - return;
2571 - }
2572 -
2553 switch (obj.type) {
2554 + case 'lock': {
2555 + // Look for a TSID
2556 + var tsid = null;
2557 + if ((ws.httprequest.xoptions != null) && (typeof ws.httprequest.xoptions.tsid == 'number')) { tsid = ws.httprequest.xoptions.tsid; }
2558 +
2559 + // Lock the current user out of the desktop
2560 + try {
2561 + if (process.platform == 'win32') {
2562 + MeshServerLogEx(53, null, "Locking remote user out of desktop", ws.httprequest);
2563 + var child = require('child_process');
2564 + child.execFile(process.env['windir'] + '\\system32\\cmd.exe', ['/c', 'RunDll32.exe user32.dll,LockWorkStation'], { type: 1, uid: tsid });
2565 + }
2566 + } catch (e) { }
2567 + break;
2568 + }
2569 case 'options': {
2570 // These are additional connection options passed in the control channel.
2571 //sendConsoleText('options: ' + JSON.stringify(obj));
views/default.handlebars
+3 -4
@@ -6762,9 +6762,9 @@
6762 meshserver.send({ action: 'toast', nodeids: [ currentNode._id ], title: decodeURIComponent('{{{extitle}}}'), msg: Q('d2devToast').value });
6763 }
6764
6765 + // Lock desktop
6766 function deviceLockFunction() {
6766 - if (xxdialogMode) return;
6767 - if ((desktop != null) && (desktop.contype == 1)) { desktop.sendCtrlMsg('{"action":"lock"}'); } // Lock desktop
6767 + if ((xxdialogMode == null) && (desktop != null) && (desktop.contype == 1)) { setDialogMode(2, "Lock Desktop", 3, function() { if ((desktop != null) && (desktop.contype == 1)) { desktop.sendCtrlMsg('{"ctrlChannel":"102938","type":"lock"}'); } }, "Lock user desktop?"); }
6768 }
6769
6770 function showShareDevice() {
@@ -7465,8 +7465,7 @@
7465 QV('DeskRecordButton', (deskState == 3) && (Q('Desk')['toBlob'] != null) && (desktop.m.StartRecording != null));
7466 QV('DeskChatButton', ((rights & 16384) != 0) && (browserfullscreen == false) && (inputAllowed) && (currentNode.agent) && online);
7467 QV('DeskNotifyButton', ((rights & 16384) != 0) && (browserfullscreen == false) && (currentNode.agent) && (currentNode.agent.id < 5) && (inputAllowed) && (currentNode.agent) && online);
7468 - //QV('DeskLockButton', ((rights & 16384) != 0) && (browserfullscreen == false) && (currentNode.agent) && (currentNode.agent.id < 5) && (inputAllowed) && (currentNode.agent) && (deskState == 3));
7469 - QV('DeskLockButton', false); // TODO: Work on adding remote desktop lock feature.
7468 + QV('DeskLockButton', ((rights & 16384) != 0) && (browserfullscreen == false) && (currentNode.agent) && (currentNode.agent.id < 5) && (inputAllowed) && (currentNode.agent) && (deskState == 3));
7469 QV('DeskToolsButton', (deskState == 3) && (currentNode.agent) && online);
7470 QE('DeskToolsButton', inputAllowed);
7471 QV('DeskOpenWebButton', (browserfullscreen == false) && (inputAllowed) && (currentNode.agent) && online);