Added desktop lock on disconnect feature, #3082.

Ylian Saint-Hilaire committed Sep 1, 2021 at 12:07 UTC ce1d2053d063ae5f711731f9548697e60324d005
5 files changed +47 -5
MeshCentralServer.njsproj
-1
@@ -207,7 +207,6 @@
207 <Content Include="agents\compressModules.bat" />
208 <Content Include="agents\MeshAgentOSXPackager.zip" />
209 <Content Include="agents\meshagent_arm" />
210 - <Content Include="agents\meshagent_arm64" />
210 <Content Include="agents\meshagent_armhf" />
211 <Content Include="agents\meshagent_mips" />
212 <Content Include="agents\meshagent_osx-x86-64" />
agents/meshcore.js
+24
@@ -1702,6 +1702,22 @@ function onTunnelClosed() {
1702 var tunnel = tunnels[this.httprequest.index];
1703 if (tunnel == null) return; // Stop duplicate calls.
1704
1705 + // Perform display locking on disconnect
1706 + if ((this.httprequest.protocol == 2) && (this.httprequest.autolock === true)) {
1707 + // Look for a TSID
1708 + var tsid = null;
1709 + if ((this.httprequest.xoptions != null) && (typeof this.httprequest.xoptions.tsid == 'number')) { tsid = this.httprequest.xoptions.tsid; }
1710 +
1711 + // Lock the current user out of the desktop
1712 + try {
1713 + if (process.platform == 'win32') {
1714 + MeshServerLogEx(53, null, "Locking remote user out of desktop", this.httprequest);
1715 + var child = require('child_process');
1716 + child.execFile(process.env['windir'] + '\\system32\\cmd.exe', ['/c', 'RunDll32.exe user32.dll,LockWorkStation'], { type: 1, uid: tsid });
1717 + }
1718 + } catch (ex) { }
1719 + }
1720 +
1721 // If this is a routing session, clean up and send the new session counts.
1722 if (this.httprequest.userid != null) {
1723 if (this.httprequest.tcpport != null) {
@@ -2734,6 +2750,11 @@ function onTunnelControlData(data, ws) {
2750 } catch (e) { }
2751 break;
2752 }
2753 + case 'autolock': {
2754 + // Set the session to auto lock on disconnect
2755 + if (obj.value === true) { ws.httprequest.autolock = true; } else { delete ws.httprequest.autolock; }
2756 + break;
2757 + }
2758 case 'options': {
2759 // These are additional connection options passed in the control channel.
2760 //sendConsoleText('options: ' + JSON.stringify(obj));
@@ -2743,6 +2764,9 @@ function onTunnelControlData(data, ws) {
2764 // Set additional user consent options if present
2765 if ((obj != null) && (typeof obj.consent == 'number')) { ws.httprequest.consent |= obj.consent; }
2766
2767 + // Set autolock
2768 + if ((obj != null) && (obj.autolock === true)) { ws.httprequest.autolock = true; }
2769 +
2770 break;
2771 }
2772 case 'close': {
meshdesktopmultiplex.js
+5 -1
@@ -93,6 +93,7 @@ function CreateDesktopMultiplexor(parent, domain, nodeid, func) {
93 obj.recordingFileWriting = false; // Set to true is we are in the process if writing to the recording file.
94 obj.startTime = null; // Starting time of the multiplex session.
95 obj.userIds = []; // List of userid's that have intertracted with this session.
96 + //obj.autoLock = false; // Automatically lock the remote device once disconnected
97
98 // Accounting
99 parent.trafficStats.desktopMultiplex.sessions++;
@@ -471,7 +472,10 @@ function CreateDesktopMultiplexor(parent, domain, nodeid, func) {
472 try { json = JSON.parse(data); } catch (ex) { }
473 if (json == null) return;
474 if ((json.type == 'options') && (obj.protocolOptions == null)) { obj.protocolOptions = json; }
474 - if ((json.ctrlChannel == '102938') && (json.type == 'lock') && (viewer.viewOnly == false)) { obj.sendToAgent('{"ctrlChannel":"102938","type":"lock"}'); } // Account lock support
475 + if (json.ctrlChannel == '102938') {
476 + if ((json.type == 'lock') && (viewer.viewOnly == false)) { obj.sendToAgent('{"ctrlChannel":"102938","type":"lock"}'); } // Account lock support
477 + if ((json.type == 'autolock') && (viewer.viewOnly == false) && (typeof json.value == 'boolean')) { obj.sendToAgent('{"ctrlChannel":"102938","type":"autolock","value":' + json.value + '}'); } // Lock on disconnect
478 + }
479 return;
480 }
481
views/default-mobile.handlebars
+12 -2
@@ -1148,6 +1148,12 @@
1148 </select>
1149 </td>
1150 </tr>
1151 + <tr>
1152 + <td></td>
1153 + <td>
1154 + <label style="display:block" id="d7deskAutoLockLabel"><input type="checkbox" id="d7deskAutoLock" />Lock on Disconnect</label>
1155 + </td>
1156 + </tr>
1157 </table>
1158 </div>
1159 <div id="d7amtkvm">
@@ -3909,7 +3915,7 @@
3915
3916 var desktop;
3917 var desktopNode;
3912 - var desktopsettings = { encoding: 2, showfocus: false, showmouse: true, showcad: true, quality: 40, scaling: 1024, framerate: 50 };
3918 + var desktopsettings = { encoding: 2, showfocus: false, showmouse: true, showcad: true, quality: 40, scaling: 1024, framerate: 50, autolock: false };
3919 function setupDesktop() {
3920 // Setup the remote desktop
3921 if ((desktopNode != currentNode) && (desktop != null)) { desktop.Stop(); desktopNode = null; desktop = null; }
@@ -4015,6 +4021,7 @@
4021 desktop.options = {};
4022 if (tsid != null) { desktop.options.tsid = tsid; }
4023 if (consent != null) { desktop.options.consent = consent; }
4024 + if (desktopsettings.autolock == true) { desktop.options.autolock = true; }
4025 desktop.onStateChanged = onDesktopStateChange;
4026 if ((features2 & 0x2000) != 0) desktop.m.stopInput = true;
4027 desktop.onConsoleMessageChange = function () {
@@ -4110,11 +4117,13 @@
4117 desktopsettings.quality = d7bitmapquality.value;
4118 desktopsettings.scaling = d7bitmapscaling.value;
4119 desktopsettings.framerate = d7framelimiter.value;
4120 + desktopsettings.autolock = d7deskAutoLock.checked;
4121 localStorage.setItem('desktopsettings', JSON.stringify(desktopsettings));
4122 applyDesktopSettings();
4123 if (desktop) {
4124 if (desktop.contype == 1) {
4117 - if (desktop.State != 0) { desktop.m.SendCompressionLevel(webpSupport?4:1, desktopsettings.quality, desktopsettings.scaling, desktopsettings.framerate); }
4125 + if (desktop.State != 0) { desktop.m.SendCompressionLevel(webpSupport ? 4 : 1, desktopsettings.quality, desktopsettings.scaling, desktopsettings.framerate); }
4126 + desktop.sendCtrlMsg('{"ctrlChannel":"102938","type":"autolock","value":' + desktopsettings.autolock + '}');
4127 }
4128 if (desktop.contype == 2) {
4129 if (desktop.State != 0) { desktop.Stop(); setTimeout(function () { connectDesktop(null, 2); }, 50); }
@@ -4131,6 +4140,7 @@
4140 if (ops.indexOf(parseInt(desktopsettings.quality)) >= 0) { d7bitmapquality.value = desktopsettings.quality; }
4141 d7bitmapscaling.value = desktopsettings.scaling;
4142 if (desktopsettings.framerate) { d7framelimiter.value = desktopsettings.framerate; }
4143 + if (desktopsettings.autolock != null) { d7deskAutoLock.checked = desktopsettings.autolock; }
4144 }
4145
4146
views/default.handlebars
+6 -1
@@ -1252,6 +1252,7 @@
1252 <label style="display:block"><input type="checkbox" id="d7deskSwapMouse" />Swap Mouse Buttons</label>
1253 <label style="display:block"><input type="checkbox" id="d7deskRemoteKeyMap" />Use Remote Keyboard Map</label>
1254 <label style="display:block" id="d7deskAutoClipboardLabel"><input type="checkbox" id="d7deskAutoClipboard" />Automatic Clipboard</label>
1255 + <label style="display:block" id="d7deskAutoLockLabel"><input type="checkbox" id="d7deskAutoLock" />Lock on Disconnect</label>
1256 </div>
1257 </div>
1258 </div>
@@ -1325,7 +1326,7 @@
1326 var stars = {}; // Devices that have been "stared" by the user.
1327 var nodeShortIdent = 0;
1328 var desktop;
1328 - var desktopsettings = { encoding: 2, showfocus: false, showmouse: true, showcad: true, quality: 40, scaling: 1024, framerate: 50, localkeymap: false, swapmouse: false, remotekeymap: false };
1329 + var desktopsettings = { encoding: 2, showfocus: false, showmouse: true, showcad: true, quality: 40, scaling: 1024, framerate: 50, localkeymap: false, swapmouse: false, remotekeymap: false, autoclipboard: false, autolock: false };
1330 var multidesktopsettings = { quality: 20, scaling: 128, framerate: 1000 };
1331 var terminal;
1332 var files;
@@ -7997,6 +7998,7 @@
7998 desktop.options = {};
7999 if (tsid != null) { desktop.options.tsid = tsid; }
8000 if (consent != null) { desktop.options.consent = consent; }
8001 + if (desktopsettings.autolock == true) { desktop.options.autolock = true; }
8002 desktop.onStateChanged = onDesktopStateChange;
8003 if ((features2 & 0x2000) != 0) desktop.m.stopInput = true;
8004 desktop.m.onRemoteInputLockChanged = function(obj, state) { QV('DeskInputLockedButton', state); QV('DeskInputUnLockedButton', !state); }
@@ -8206,6 +8208,7 @@
8208 desktopsettings.swapmouse = d7deskSwapMouse.checked;
8209 desktopsettings.remotekeymap = d7deskRemoteKeyMap.checked;
8210 desktopsettings.autoclipboard = d7deskAutoClipboard.checked;
8211 + desktopsettings.autolock = d7deskAutoLock.checked;
8212 desktopsettings.localkeymap = d7localKeyMap.checked;
8213 localStorage.setItem('desktopsettings', JSON.stringify(desktopsettings));
8214 applyDesktopSettings();
@@ -8216,6 +8219,7 @@
8219 desktop.m.remoteKeyMap = desktopsettings.remotekeymap;
8220 if (desktop.State != 0) {
8221 desktop.m.SendCompressionLevel(webpSupport?4:1, desktopsettings.quality, desktopsettings.scaling, desktopsettings.framerate);
8222 + desktop.sendCtrlMsg('{"ctrlChannel":"102938","type":"autolock","value":' + desktopsettings.autolock + '}');
8223 }
8224 }
8225 if (desktop.contype == 2) {
@@ -8239,6 +8243,7 @@
8243 if (desktopsettings.swapmouse != null) { d7deskSwapMouse.checked = desktopsettings.swapmouse; }
8244 if (desktopsettings.remotekeymap != null) { d7deskRemoteKeyMap.checked = desktopsettings.remotekeymap; }
8245 if (desktopsettings.autoclipboard != null) { d7deskAutoClipboard.checked = desktopsettings.autoclipboard; }
8246 + if (desktopsettings.autolock != null) { d7deskAutoLock.checked = desktopsettings.autolock; }
8247 if (desktopsettings.localkeymap) { d7localKeyMap.checked = desktopsettings.localkeymap; }
8248 QV('deskFocusBtn', (desktop != null) && (desktop.contype == 2) && (desktop.state != 0) && (desktopsettings.showfocus));
8249 }