Updated agents, shift-device click will now open a new browser tab.

Ylian Saint-Hilaire committed Jan 29, 2019 at 14:08 UTC b0394da585563dbf6616089fe7c8ce34eb2b7c81
27 files changed +206 -57
agents/MeshCmd-signed.exe
Binary files a/agents/MeshCmd-signed.exe and b/agents/MeshCmd-signed.exe differ
agents/MeshCmd64-signed.exe
Binary files a/agents/MeshCmd64-signed.exe and b/agents/MeshCmd64-signed.exe differ
agents/MeshService-signed.exe
Binary files a/agents/MeshService-signed.exe and b/agents/MeshService-signed.exe differ
agents/MeshService.exe
Binary files a/agents/MeshService.exe and b/agents/MeshService.exe differ
agents/MeshService64-signed.exe
Binary files a/agents/MeshService64-signed.exe and b/agents/MeshService64-signed.exe differ
agents/MeshService64.exe
Binary files a/agents/MeshService64.exe and b/agents/MeshService64.exe differ
agents/meshagent_arm
Binary files a/agents/meshagent_arm and b/agents/meshagent_arm differ
agents/meshagent_arm-linaro
Binary files a/agents/meshagent_arm-linaro and b/agents/meshagent_arm-linaro differ
agents/meshagent_armhf
Binary files a/agents/meshagent_armhf and b/agents/meshagent_armhf differ
agents/meshagent_mips
Binary files a/agents/meshagent_mips and b/agents/meshagent_mips differ
agents/meshagent_pogo
Binary files a/agents/meshagent_pogo and b/agents/meshagent_pogo differ
agents/meshagent_poky
Binary files a/agents/meshagent_poky and b/agents/meshagent_poky differ
agents/meshagent_poky64
Binary files a/agents/meshagent_poky64 and b/agents/meshagent_poky64 differ
agents/meshagent_x86
Binary files a/agents/meshagent_x86 and b/agents/meshagent_x86 differ
agents/meshagent_x86-64
Binary files a/agents/meshagent_x86-64 and b/agents/meshagent_x86-64 differ
agents/meshagent_x86-64_nokvm
Binary files a/agents/meshagent_x86-64_nokvm and b/agents/meshagent_x86-64_nokvm differ
agents/meshagent_x86_nokvm
Binary files a/agents/meshagent_x86_nokvm and b/agents/meshagent_x86_nokvm differ
agents/modules_meshcmd/user-sessions.js
+25
@@ -92,6 +92,11 @@ function UserSessions()
92 {
93 }
94
95 + this._advapi = this._marshal.CreateNativeProxy('Advapi32.dll');
96 + this._advapi.CreateMethod('AllocateAndInitializeSid');
97 + this._advapi.CreateMethod('CheckTokenMembership');
98 + this._advapi.CreateMethod('FreeSid');
99 +
100 this._user32 = this._marshal.CreateNativeProxy('user32.dll');
101 this._user32.CreateMethod({ method: 'RegisterPowerSettingNotification', threadDispatch: 1});
102 this._user32.CreateMethod('UnregisterPowerSettingNotification');
@@ -150,6 +155,26 @@ function UserSessions()
155 'WTSIsRemoteSession': 29
156 };
157
158 + this.isRoot = function isRoot()
159 + {
160 + var NTAuthority = this._marshal.CreateVariable(6);
161 + NTAuthority.toBuffer().writeInt8(5, 5);
162 +
163 + var AdministratorsGroup = this._marshal.CreatePointer();
164 + var admin = false;
165 +
166 + if (this._advapi.AllocateAndInitializeSid(NTAuthority, 2, 32, 544, 0, 0, 0, 0, 0, 0, AdministratorsGroup).Val != 0)
167 + {
168 + var member = this._marshal.CreateInteger();
169 + if (this._advapi.CheckTokenMembership(0, AdministratorsGroup.Deref(), member).Val != 0)
170 + {
171 + if (member.toBuffer().readUInt32LE() != 0) { admin = true; }
172 + }
173 + this._advapi.FreeSid(AdministratorsGroup.Deref());
174 + }
175 + return admin;
176 + }
177 +
178 this.getSessionAttribute = function getSessionAttribute(sessionId, attr)
179 {
180 var buffer = this._marshal.CreatePointer();
agents/modules_meshcmd_min/user-sessions.min.js
+1 -1
@@ -1 +1 @@
1 -var NOTIFY_FOR_THIS_SESSION=0;var NOTIFY_FOR_ALL_SESSIONS=1;var WM_WTSSESSION_CHANGE=689;var WM_POWERBROADCAST=536;var PBT_POWERSETTINGCHANGE=32787;var PBT_APMSUSPEND=4;var PBT_APMRESUMESUSPEND=7;var PBT_APMRESUMEAUTOMATIC=18;var PBT_APMPOWERSTATUSCHANGE=10;var WTS_CONSOLE_CONNECT=(1);var WTS_CONSOLE_DISCONNECT=(2);var WTS_REMOTE_CONNECT=(3);var WTS_REMOTE_DISCONNECT=(4);var WTS_SESSION_LOGON=(5);var WTS_SESSION_LOGOFF=(6);var WTS_SESSION_LOCK=(7);var WTS_SESSION_UNLOCK=(8);var WTS_SESSION_REMOTE_CONTROL=(9);var WTS_SESSION_CREATE=(10);var WTS_SESSION_TERMINATE=(11);var GUID_ACDC_POWER_SOURCE;var GUID_BATTERY_PERCENTAGE_REMAINING;var GUID_CONSOLE_DISPLAY_STATE;function UserSessions(){this._ObjectID="user-sessions";require("events").EventEmitter.call(this,true).createEvent("changed").createEvent("locked").createEvent("unlocked");this.enumerateUsers=function h(){var s=require("promise");var r=new s(function(t,p){this.__resolver=t;this.__rejector=p});r.__handler=function o(p){r.__resolver(p)};try{this.Current(r.__handler)}catch(q){r.__rejector(q)}r.parent=this;return(r)};if(process.platform=="win32"){this._serviceHooked=false;this._marshal=require("_GenericMarshal");this._kernel32=this._marshal.CreateNativeProxy("Kernel32.dll");this._kernel32.CreateMethod("GetLastError");try{this._wts=this._marshal.CreateNativeProxy("Wtsapi32.dll");this._wts.CreateMethod("WTSEnumerateSessionsA");this._wts.CreateMethod("WTSQuerySessionInformationA");this._wts.CreateMethod("WTSRegisterSessionNotification");this._wts.CreateMethod("WTSUnRegisterSessionNotification");this._wts.CreateMethod("WTSFreeMemory")}catch(i){}this._user32=this._marshal.CreateNativeProxy("user32.dll");this._user32.CreateMethod({method:"RegisterPowerSettingNotification",threadDispatch:1});this._user32.CreateMethod("UnregisterPowerSettingNotification");this._rpcrt=this._marshal.CreateNativeProxy("Rpcrt4.dll");this._rpcrt.CreateMethod("UuidFromStringA");this._rpcrt.StringToUUID=function n(o){var p=n.us._marshal.CreateVariable(16);if(n.us._rpcrt.UuidFromStringA(n.us._marshal.CreateVariable(o),p).Val==0){return(p)}else{throw ("Could not convert string to UUID")}};this._rpcrt.StringToUUID.us=this;GUID_ACDC_POWER_SOURCE=this._rpcrt.StringToUUID("5d3e9a59-e9D5-4b00-a6bd-ff34ff516548");GUID_BATTERY_PERCENTAGE_REMAINING=this._rpcrt.StringToUUID("a7ad8041-b45a-4cae-87a3-eecbb468a9e1");GUID_CONSOLE_DISPLAY_STATE=this._rpcrt.StringToUUID("6fe69556-704a-47a0-8f24-c28d936fda47");this.SessionStates=["Active","Connected","ConnectQuery","Shadow","Disconnected","Idle","Listening","Reset","Down","Init"];this.InfoClass={WTSInitialProgram:0,WTSApplicationName:1,WTSWorkingDirectory:2,WTSOEMId:3,WTSSessionId:4,WTSUserName:5,WTSWinStationName:6,WTSDomainName:7,WTSConnectState:8,WTSClientBuildNumber:9,WTSClientName:10,WTSClientDirectory:11,WTSClientProductId:12,WTSClientHardwareId:13,WTSClientAddress:14,WTSClientDisplay:15,WTSClientProtocolType:16,WTSIdleTime:17,WTSLogonTime:18,WTSIncomingBytes:19,WTSOutgoingBytes:20,WTSIncomingFrames:21,WTSOutgoingFrames:22,WTSClientInfo:23,WTSSessionInfo:24,WTSSessionInfoEx:25,WTSConfigInfo:26,WTSValidationInfo:27,WTSSessionAddressV4:28,WTSIsRemoteSession:29};this.getSessionAttribute=function j(s,o){var p=this._marshal.CreatePointer();var q=this._marshal.CreateVariable(4);if(this._wts.WTSQuerySessionInformationA(0,s,o,p,q).Val==0){throw ("Error calling WTSQuerySessionInformation: "+this._kernel32.GetLastError.Val)}var r=p.Deref().String;this._wts.WTSFreeMemory(p.Deref());return(r)};this.Current=function f(o){var u={};var t=this._marshal.CreatePointer();var p=this._marshal.CreateVariable(4);if(this._wts.WTSEnumerateSessionsA(0,0,1,t,p).Val==0){throw ("Error calling WTSEnumerateSessionsA: "+this._kernel32.GetLastError().Val)}for(var q=0;q<p.toBuffer().readUInt32LE();++q){var r=t.Deref().Deref(q*(this._marshal.PointerSize==4?12:24),this._marshal.PointerSize==4?12:24);var s={SessionId:r.toBuffer().readUInt32LE()};s.StationName=r.Deref(this._marshal.PointerSize==4?4:8,this._marshal.PointerSize).Deref().String;s.State=this.SessionStates[r.Deref(this._marshal.PointerSize==4?8:16,4).toBuffer().readUInt32LE()];if(s.State=="Active"){s.Username=this.getSessionAttribute(s.SessionId,this.InfoClass.WTSUserName);s.Domain=this.getSessionAttribute(s.SessionId,this.InfoClass.WTSDomainName)}u[s.SessionId]=s}this._wts.WTSFreeMemory(t.Deref());Object.defineProperty(u,"Active",{value:showActiveOnly(u)});if(o){o(u)}return(u)};var l=require("win-message-pump");this._messagepump=new l({filter:WM_WTSSESSION_CHANGE});this._messagepump.parent=this;this._messagepump.on("exit",function(o){this.parent._wts.WTSUnRegisterSessionNotification(this.parent.hwnd)});this._messagepump.on("hwnd",function(o){this.parent.hwnd=o;this.immediate=setImmediate(function(p){if(p.parent._wts){p.parent._wts.WTSRegisterSessionNotification(p.parent.hwnd,NOTIFY_FOR_ALL_SESSIONS)}p.parent._user32.ACDC_H=p.parent._user32.RegisterPowerSettingNotification(p.parent.hwnd,GUID_ACDC_POWER_SOURCE,0);p.parent._user32.BATT_H=p.parent._user32.RegisterPowerSettingNotification(p.parent.hwnd,GUID_BATTERY_PERCENTAGE_REMAINING,0);p.parent._user32.DISP_H=p.parent._user32.RegisterPowerSettingNotification(p.parent.hwnd,GUID_CONSOLE_DISPLAY_STATE,0)},this)});this._messagepump.on("message",function(q){switch(q.message){case WM_WTSSESSION_CHANGE:switch(q.wparam){case WTS_SESSION_LOCK:this.parent.enumerateUsers().then(function(r){if(r[q.lparam]){this.parent.emit("locked",r[q.lparam])}});break;case WTS_SESSION_UNLOCK:this.parent.enumerateUsers().then(function(r){if(r[q.lparam]){this.parent.emit("unlocked",r[q.lparam])}});break;case WTS_SESSION_LOGON:case WTS_SESSION_LOGOFF:this.parent.emit("changed");break}break;case WM_POWERBROADCAST:switch(q.wparam){default:console.log("WM_POWERBROADCAST [UNKNOWN wparam]: "+q.wparam);break;case PBT_APMSUSPEND:require("power-monitor").emit("sx","SLEEP");break;case PBT_APMRESUMEAUTOMATIC:require("power-monitor").emit("sx","RESUME_NON_INTERACTIVE");break;case PBT_APMRESUMESUSPEND:require("power-monitor").emit("sx","RESUME_INTERACTIVE");break;case PBT_APMPOWERSTATUSCHANGE:require("power-monitor").emit("changed");break;case PBT_POWERSETTINGCHANGE:var p=this.parent._marshal.CreatePointer(Buffer.from(q.lparam_hex,"hex"));var o=p.Deref(20,p.Deref(16,4).toBuffer().readUInt32LE(0)).toBuffer();switch(p.Deref(0,16).toBuffer().toString("hex")){case GUID_ACDC_POWER_SOURCE.Deref(0,16).toBuffer().toString("hex"):switch(o.readUInt32LE(0)){case 0:require("power-monitor").emit("acdc","AC");break;case 1:require("power-monitor").emit("acdc","BATTERY");break;case 2:require("power-monitor").emit("acdc","HOT");break}break;case GUID_BATTERY_PERCENTAGE_REMAINING.Deref(0,16).toBuffer().toString("hex"):require("power-monitor").emit("batteryLevel",o.readUInt32LE(0));break;case GUID_CONSOLE_DISPLAY_STATE.Deref(0,16).toBuffer().toString("hex"):switch(o.readUInt32LE(0)){case 0:require("power-monitor").emit("display","OFF");break;case 1:require("power-monitor").emit("display","ON");break;case 2:require("power-monitor").emit("display","DIMMED");break}break}break}break;default:break}})}else{if(process.platform=="linux"){var g=require("linux-dbus");this._linuxWatcher=require("fs").watch("/var/run/utmp");this._linuxWatcher.user_session=this;this._linuxWatcher.on("change",function(o,p){this.user_session.emit("changed")});this._users=function d(){var o=require("child_process").execFile("/bin/sh",["sh"]);o.stdout.str="";o.stdout.on("data",function(t){this.str+=t.toString()});o.stdin.write("awk -F: '($3 >= 0) {printf \"%s:%s\\n\", $1, $3}' /etc/passwd\nexit\n");o.waitExit();var p=o.stdout.str.split("\n");var r={},s;for(var q in p){s=p[q].split(":");if(s[0]){r[s[0]]=s[1]}}return(r)};this._uids=function c(){var o=require("child_process").execFile("/bin/sh",["sh"]);o.stdout.str="";o.stdout.on("data",function(t){this.str+=t.toString()});o.stdin.write("awk -F: '($3 >= 0) {printf \"%s:%s\\n\", $1, $3}' /etc/passwd\nexit\n");o.waitExit();var p=o.stdout.str.split("\n");var r={},s;for(var q in p){s=p[q].split(":");if(s[0]){r[s[1]]=s[0]}}return(r)};this.Self=function m(){var q=require("promise");var o=new q(function(r,p){this.__resolver=r;this.__rejector=p;this.__child=require("child_process").execFile("/usr/bin/id",["id","-u"]);this.__child.promise=this;this.__child.stdout._txt="";this.__child.stdout.on("data",function(s){this._txt+=s.toString()});this.__child.on("exit",function(s){try{parseInt(this.stdout._txt)}catch(t){this.promise.__rejector("invalid uid");return}var u=parseInt(this.stdout._txt);this.promise.__resolver(u)})});return(o)};this.Current=function f(o){var p={};p._ObjectID="UserSession";Object.defineProperty(p,"_callback",{value:o});Object.defineProperty(p,"_child",{value:require("child_process").execFile("/usr/bin/last",["last","-f","/var/run/utmp"])});p._child.Parent=p;p._child._txt="";p._child.on("exit",function(q){var u=this._txt.split("\n");var A=[];var D={};for(var t in u){if(u[t]){var B=getTokens(u[t]);var z={Username:B[0],SessionId:B[1]};if(B[3].includes("still logged in")){z.State="Active"}else{z.LastActive=B[3]}A.push(z)}}A.pop();var C={};var y=[];for(var t in A){if(A[t].Username!="reboot"){D[A[t].SessionId]=A[t];if(C[A[t].Username]==null){C[A[t].Username]=-1}}}try{require("promise")}catch(r){Object.defineProperty(D,"Active",{value:showActiveOnly(D)});if(this.Parent._callback){this.Parent._callback.call(this.Parent,D)}return}var x=require("promise");for(var v in C){var w=new x(function(E,s){this.__username=v;this.__resolver=E;this.__rejector=s;this.__child=require("child_process").execFile("/usr/bin/id",["id","-u",v]);this.__child.promise=this;this.__child.stdout._txt="";this.__child.stdout.on("data",function(F){this._txt+=F.toString()});this.__child.on("exit",function(F){try{parseInt(this.stdout._txt)}catch(G){this.promise.__rejector("invalid uid");return}var H=parseInt(this.stdout._txt);this.promise.__resolver(H)})});y.push(w)}x.all(y).then(function(E){var F={};for(var s in E){F[E[s].__username]=E[s]._internal.completedArgs[0]}for(var s in D){D[s].uid=F[D[s].Username]}Object.defineProperty(D,"Active",{value:showActiveOnly(D)});if(p._callback){p._callback.call(p,D)}},function(s){Object.defineProperty(D,"Active",{value:showActiveOnly(D)});if(p._callback){p._callback.call(p,D)}})});p._child.stdout.Parent=p._child;p._child.stdout.on("data",function(q){this.Parent._txt+=q.toString()});return(p)};this._recheckLoggedInUsers=function a(){this.enumerateUsers().then(function(o){if(o.Active.length>0){if(this.parent._linux_lock_watcher!=null&&this.parent._linux_lock_watcher.uid!=o.Active[0].uid){delete this.parent._linux_lock_watcher}this.parent._linux_lock_watcher=new g(process.env.XDG_CURRENT_DESKTOP=="Unity"?"com.ubuntu.Upstart0_6":"org.gnome.ScreenSaver",o.Active[0].uid);this.parent._linux_lock_watcher.user_session=this.parent;this.parent._linux_lock_watcher.on("signal",function(r){var q=this.user_session.enumerateUsers();q.signalData=r.data[0];q.then(function(p){switch(this.signalData){case true:case"desktop-lock":this.parent.emit("locked",p.Active[0]);break;case false:case"desktop-unlock":this.parent.emit("unlocked",p.Active[0]);break}})})}else{if(this.parent._linux_lock_watcher!=null){delete this.parent._linux_lock_watcher}}})};this.on("changed",this._recheckLoggedInUsers);this._recheckLoggedInUsers()}else{if(process.platform=="darwin"){this._users=function(){var o=require("child_process").execFile("/usr/bin/dscl",["dscl",".","list","/Users","UniqueID"]);o.stdout.str="";o.stdout.on("data",function(t){this.str+=t.toString()});o.stdin.write("exit\n");o.waitExit();var q=o.stdout.str.split("\n");var r,p;var s={};for(p=0;p<q.length;++p){r=q[p].split(" ");if(r[0]){s[r[0]]=r[r.length-1]}}return(s)};this._uids=function(){var o=require("child_process").execFile("/usr/bin/dscl",["dscl",".","list","/Users","UniqueID"]);o.stdout.str="";o.stdout.on("data",function(t){this.str+=t.toString()});o.stdin.write("exit\n");o.waitExit();var q=o.stdout.str.split("\n");var r,p;var s={};for(p=0;p<q.length;++p){r=q[p].split(" ");if(r[0]){s[r[r.length-1]]=r[0]}}return(s)};this._idTable=function(){var v={};var o=require("child_process").execFile("/usr/bin/id",["id"]);o.stdout.str="";o.stdout.on("data",function(y){this.str+=y.toString()});o.waitExit();var t=o.stdout.str.split("\n")[0].split(" ");for(var p=0;p<t.length;++p){var x=t[p].split("=");var w=x[1].split(",");v[x[0]]={};for(var s in w){var r=w[s].split("(");var q=r[0];var u=r[1].substring(0,r[1].length-1).trim();v[x[0]][u]=q;v[x[0]][q]=u}}return(v)};this.Current=function(o){var u={};var t=this._idTable();var p=require("child_process").execFile("/usr/bin/last",["last"]);p.stdout.str="";p.stdout.on("data",function(v){this.str+=v.toString()});p.waitExit();var s=p.stdout.str.split("\n");for(var r=0;r<s.length&&s[r].length>0;++r){if(!u[s[r].split(" ")[0]]){try{u[s[r].split(" ")[0]]={Username:s[r].split(" ")[0],State:s[r].split("still logged in").length>1?"Active":"Inactive",uid:t.uid[s[r].split(" ")[0]]}}catch(q){}}else{if(u[s[r].split(" ")[0]].State!="Active"&&s[r].split("still logged in").length>1){u[s[r].split(" ")[0]].State="Active"}}}Object.defineProperty(u,"Active",{value:showActiveOnly(u)});if(o){o.call(this,u)}}}}}if(process.platform=="linux"||process.platform=="darwin"){this._self=function b(){var o=require("child_process").execFile("/usr/bin/id",["id","-u"]);o.stdout.str="";o.stdout.on("data",function(p){this.str+=p.toString()});o.waitExit();return(parseInt(o.stdout.str))};this.isRoot=function k(){return(this._self()==0)};this.consoleUid=function e(){var o=process.platform=="darwin"?"console":((process.env.DISPLAY)?process.env.DISPLAY:":0");var p=require("child_process").execFile("/bin/sh",["sh"]);p.stdout.str="";p.stdout.on("data",function(u){this.str+=u.toString()});p.stdin.write("who\nexit\n");p.waitExit();var s=p.stdout.str.split("\n");var t,q,r;for(q in s){t=s[q].split(" ");for(r=1;r<t.length;++r){if(t[r].length>0&&(t[r]==o||t[r]==("("+o+")"))){return(parseInt(this._users()[t[0]]))}}}throw ("nobody logged into console")}}}function showActiveOnly(c){var b=[];var e={};var f=[];var d;for(var a in c){if(c[a].State=="Active"){b.push(c[a]);d=(c[a].Domain?(c[a].Domain+"\\"):"")+c[a].Username;if(!e[d]){e[d]=d}}}for(var a in e){f.push(a)}Object.defineProperty(b,"usernames",{value:f});return(b)}function getTokens(d){var a=[];var b;a.push(d.substring(0,(b=d.indexOf(" "))));while(d[++b]==" "){}a.push(d.substring(b,(b=d.substring(b).indexOf(" ")+b)));while(d[++b]==" "){}a.push(d.substring(b,(b=d.substring(b).indexOf(" ")+b)));while(d[++b]==" "){}var c=d.substring(b).trim();a.push(c);return(a)}module.exports=new UserSessions();
\ No newline at end of file
1 +var NOTIFY_FOR_THIS_SESSION=0;var NOTIFY_FOR_ALL_SESSIONS=1;var WM_WTSSESSION_CHANGE=689;var WM_POWERBROADCAST=536;var PBT_POWERSETTINGCHANGE=32787;var PBT_APMSUSPEND=4;var PBT_APMRESUMESUSPEND=7;var PBT_APMRESUMEAUTOMATIC=18;var PBT_APMPOWERSTATUSCHANGE=10;var WTS_CONSOLE_CONNECT=(1);var WTS_CONSOLE_DISCONNECT=(2);var WTS_REMOTE_CONNECT=(3);var WTS_REMOTE_DISCONNECT=(4);var WTS_SESSION_LOGON=(5);var WTS_SESSION_LOGOFF=(6);var WTS_SESSION_LOCK=(7);var WTS_SESSION_UNLOCK=(8);var WTS_SESSION_REMOTE_CONTROL=(9);var WTS_SESSION_CREATE=(10);var WTS_SESSION_TERMINATE=(11);var GUID_ACDC_POWER_SOURCE;var GUID_BATTERY_PERCENTAGE_REMAINING;var GUID_CONSOLE_DISPLAY_STATE;function UserSessions(){this._ObjectID="user-sessions";require("events").EventEmitter.call(this,true).createEvent("changed").createEvent("locked").createEvent("unlocked");this.enumerateUsers=function h(){var s=require("promise");var r=new s(function(t,p){this.__resolver=t;this.__rejector=p});r.__handler=function o(p){r.__resolver(p)};try{this.Current(r.__handler)}catch(q){r.__rejector(q)}r.parent=this;return(r)};if(process.platform=="win32"){this._serviceHooked=false;this._marshal=require("_GenericMarshal");this._kernel32=this._marshal.CreateNativeProxy("Kernel32.dll");this._kernel32.CreateMethod("GetLastError");try{this._wts=this._marshal.CreateNativeProxy("Wtsapi32.dll");this._wts.CreateMethod("WTSEnumerateSessionsA");this._wts.CreateMethod("WTSQuerySessionInformationA");this._wts.CreateMethod("WTSRegisterSessionNotification");this._wts.CreateMethod("WTSUnRegisterSessionNotification");this._wts.CreateMethod("WTSFreeMemory")}catch(i){}this._advapi=this._marshal.CreateNativeProxy("Advapi32.dll");this._advapi.CreateMethod("AllocateAndInitializeSid");this._advapi.CreateMethod("CheckTokenMembership");this._advapi.CreateMethod("FreeSid");this._user32=this._marshal.CreateNativeProxy("user32.dll");this._user32.CreateMethod({method:"RegisterPowerSettingNotification",threadDispatch:1});this._user32.CreateMethod("UnregisterPowerSettingNotification");this._rpcrt=this._marshal.CreateNativeProxy("Rpcrt4.dll");this._rpcrt.CreateMethod("UuidFromStringA");this._rpcrt.StringToUUID=function n(o){var p=n.us._marshal.CreateVariable(16);if(n.us._rpcrt.UuidFromStringA(n.us._marshal.CreateVariable(o),p).Val==0){return(p)}else{throw ("Could not convert string to UUID")}};this._rpcrt.StringToUUID.us=this;GUID_ACDC_POWER_SOURCE=this._rpcrt.StringToUUID("5d3e9a59-e9D5-4b00-a6bd-ff34ff516548");GUID_BATTERY_PERCENTAGE_REMAINING=this._rpcrt.StringToUUID("a7ad8041-b45a-4cae-87a3-eecbb468a9e1");GUID_CONSOLE_DISPLAY_STATE=this._rpcrt.StringToUUID("6fe69556-704a-47a0-8f24-c28d936fda47");this.SessionStates=["Active","Connected","ConnectQuery","Shadow","Disconnected","Idle","Listening","Reset","Down","Init"];this.InfoClass={WTSInitialProgram:0,WTSApplicationName:1,WTSWorkingDirectory:2,WTSOEMId:3,WTSSessionId:4,WTSUserName:5,WTSWinStationName:6,WTSDomainName:7,WTSConnectState:8,WTSClientBuildNumber:9,WTSClientName:10,WTSClientDirectory:11,WTSClientProductId:12,WTSClientHardwareId:13,WTSClientAddress:14,WTSClientDisplay:15,WTSClientProtocolType:16,WTSIdleTime:17,WTSLogonTime:18,WTSIncomingBytes:19,WTSOutgoingBytes:20,WTSIncomingFrames:21,WTSOutgoingFrames:22,WTSClientInfo:23,WTSSessionInfo:24,WTSSessionInfoEx:25,WTSConfigInfo:26,WTSValidationInfo:27,WTSSessionAddressV4:28,WTSIsRemoteSession:29};this.isRoot=function k(){var r=this._marshal.CreateVariable(6);r.toBuffer().writeInt8(5,5);var p=this._marshal.CreatePointer();var o=false;if(this._advapi.AllocateAndInitializeSid(r,2,32,544,0,0,0,0,0,0,p).Val!=0){var q=this._marshal.CreateInteger();if(this._advapi.CheckTokenMembership(0,p.Deref(),q).Val!=0){if(q.toBuffer().readUInt32LE()!=0){o=true}}this._advapi.FreeSid(p.Deref())}return o};this.getSessionAttribute=function j(s,o){var p=this._marshal.CreatePointer();var q=this._marshal.CreateVariable(4);if(this._wts.WTSQuerySessionInformationA(0,s,o,p,q).Val==0){throw ("Error calling WTSQuerySessionInformation: "+this._kernel32.GetLastError.Val)}var r=p.Deref().String;this._wts.WTSFreeMemory(p.Deref());return(r)};this.Current=function f(o){var u={};var t=this._marshal.CreatePointer();var p=this._marshal.CreateVariable(4);if(this._wts.WTSEnumerateSessionsA(0,0,1,t,p).Val==0){throw ("Error calling WTSEnumerateSessionsA: "+this._kernel32.GetLastError().Val)}for(var q=0;q<p.toBuffer().readUInt32LE();++q){var r=t.Deref().Deref(q*(this._marshal.PointerSize==4?12:24),this._marshal.PointerSize==4?12:24);var s={SessionId:r.toBuffer().readUInt32LE()};s.StationName=r.Deref(this._marshal.PointerSize==4?4:8,this._marshal.PointerSize).Deref().String;s.State=this.SessionStates[r.Deref(this._marshal.PointerSize==4?8:16,4).toBuffer().readUInt32LE()];if(s.State=="Active"){s.Username=this.getSessionAttribute(s.SessionId,this.InfoClass.WTSUserName);s.Domain=this.getSessionAttribute(s.SessionId,this.InfoClass.WTSDomainName)}u[s.SessionId]=s}this._wts.WTSFreeMemory(t.Deref());Object.defineProperty(u,"Active",{value:showActiveOnly(u)});if(o){o(u)}return(u)};var l=require("win-message-pump");this._messagepump=new l({filter:WM_WTSSESSION_CHANGE});this._messagepump.parent=this;this._messagepump.on("exit",function(o){this.parent._wts.WTSUnRegisterSessionNotification(this.parent.hwnd)});this._messagepump.on("hwnd",function(o){this.parent.hwnd=o;this.immediate=setImmediate(function(p){if(p.parent._wts){p.parent._wts.WTSRegisterSessionNotification(p.parent.hwnd,NOTIFY_FOR_ALL_SESSIONS)}p.parent._user32.ACDC_H=p.parent._user32.RegisterPowerSettingNotification(p.parent.hwnd,GUID_ACDC_POWER_SOURCE,0);p.parent._user32.BATT_H=p.parent._user32.RegisterPowerSettingNotification(p.parent.hwnd,GUID_BATTERY_PERCENTAGE_REMAINING,0);p.parent._user32.DISP_H=p.parent._user32.RegisterPowerSettingNotification(p.parent.hwnd,GUID_CONSOLE_DISPLAY_STATE,0)},this)});this._messagepump.on("message",function(q){switch(q.message){case WM_WTSSESSION_CHANGE:switch(q.wparam){case WTS_SESSION_LOCK:this.parent.enumerateUsers().then(function(r){if(r[q.lparam]){this.parent.emit("locked",r[q.lparam])}});break;case WTS_SESSION_UNLOCK:this.parent.enumerateUsers().then(function(r){if(r[q.lparam]){this.parent.emit("unlocked",r[q.lparam])}});break;case WTS_SESSION_LOGON:case WTS_SESSION_LOGOFF:this.parent.emit("changed");break}break;case WM_POWERBROADCAST:switch(q.wparam){default:console.log("WM_POWERBROADCAST [UNKNOWN wparam]: "+q.wparam);break;case PBT_APMSUSPEND:require("power-monitor").emit("sx","SLEEP");break;case PBT_APMRESUMEAUTOMATIC:require("power-monitor").emit("sx","RESUME_NON_INTERACTIVE");break;case PBT_APMRESUMESUSPEND:require("power-monitor").emit("sx","RESUME_INTERACTIVE");break;case PBT_APMPOWERSTATUSCHANGE:require("power-monitor").emit("changed");break;case PBT_POWERSETTINGCHANGE:var p=this.parent._marshal.CreatePointer(Buffer.from(q.lparam_hex,"hex"));var o=p.Deref(20,p.Deref(16,4).toBuffer().readUInt32LE(0)).toBuffer();switch(p.Deref(0,16).toBuffer().toString("hex")){case GUID_ACDC_POWER_SOURCE.Deref(0,16).toBuffer().toString("hex"):switch(o.readUInt32LE(0)){case 0:require("power-monitor").emit("acdc","AC");break;case 1:require("power-monitor").emit("acdc","BATTERY");break;case 2:require("power-monitor").emit("acdc","HOT");break}break;case GUID_BATTERY_PERCENTAGE_REMAINING.Deref(0,16).toBuffer().toString("hex"):require("power-monitor").emit("batteryLevel",o.readUInt32LE(0));break;case GUID_CONSOLE_DISPLAY_STATE.Deref(0,16).toBuffer().toString("hex"):switch(o.readUInt32LE(0)){case 0:require("power-monitor").emit("display","OFF");break;case 1:require("power-monitor").emit("display","ON");break;case 2:require("power-monitor").emit("display","DIMMED");break}break}break}break;default:break}})}else{if(process.platform=="linux"){var g=require("linux-dbus");this._linuxWatcher=require("fs").watch("/var/run/utmp");this._linuxWatcher.user_session=this;this._linuxWatcher.on("change",function(o,p){this.user_session.emit("changed")});this._users=function d(){var o=require("child_process").execFile("/bin/sh",["sh"]);o.stdout.str="";o.stdout.on("data",function(t){this.str+=t.toString()});o.stdin.write("awk -F: '($3 >= 0) {printf \"%s:%s\\n\", $1, $3}' /etc/passwd\nexit\n");o.waitExit();var p=o.stdout.str.split("\n");var r={},s;for(var q in p){s=p[q].split(":");if(s[0]){r[s[0]]=s[1]}}return(r)};this._uids=function c(){var o=require("child_process").execFile("/bin/sh",["sh"]);o.stdout.str="";o.stdout.on("data",function(t){this.str+=t.toString()});o.stdin.write("awk -F: '($3 >= 0) {printf \"%s:%s\\n\", $1, $3}' /etc/passwd\nexit\n");o.waitExit();var p=o.stdout.str.split("\n");var r={},s;for(var q in p){s=p[q].split(":");if(s[0]){r[s[1]]=s[0]}}return(r)};this.Self=function m(){var q=require("promise");var o=new q(function(r,p){this.__resolver=r;this.__rejector=p;this.__child=require("child_process").execFile("/usr/bin/id",["id","-u"]);this.__child.promise=this;this.__child.stdout._txt="";this.__child.stdout.on("data",function(s){this._txt+=s.toString()});this.__child.on("exit",function(s){try{parseInt(this.stdout._txt)}catch(t){this.promise.__rejector("invalid uid");return}var u=parseInt(this.stdout._txt);this.promise.__resolver(u)})});return(o)};this.Current=function f(o){var p={};p._ObjectID="UserSession";Object.defineProperty(p,"_callback",{value:o});Object.defineProperty(p,"_child",{value:require("child_process").execFile("/usr/bin/last",["last","-f","/var/run/utmp"])});p._child.Parent=p;p._child._txt="";p._child.on("exit",function(q){var u=this._txt.split("\n");var A=[];var D={};for(var t in u){if(u[t]){var B=getTokens(u[t]);var z={Username:B[0],SessionId:B[1]};if(B[3].includes("still logged in")){z.State="Active"}else{z.LastActive=B[3]}A.push(z)}}A.pop();var C={};var y=[];for(var t in A){if(A[t].Username!="reboot"){D[A[t].SessionId]=A[t];if(C[A[t].Username]==null){C[A[t].Username]=-1}}}try{require("promise")}catch(r){Object.defineProperty(D,"Active",{value:showActiveOnly(D)});if(this.Parent._callback){this.Parent._callback.call(this.Parent,D)}return}var x=require("promise");for(var v in C){var w=new x(function(E,s){this.__username=v;this.__resolver=E;this.__rejector=s;this.__child=require("child_process").execFile("/usr/bin/id",["id","-u",v]);this.__child.promise=this;this.__child.stdout._txt="";this.__child.stdout.on("data",function(F){this._txt+=F.toString()});this.__child.on("exit",function(F){try{parseInt(this.stdout._txt)}catch(G){this.promise.__rejector("invalid uid");return}var H=parseInt(this.stdout._txt);this.promise.__resolver(H)})});y.push(w)}x.all(y).then(function(E){var F={};for(var s in E){F[E[s].__username]=E[s]._internal.completedArgs[0]}for(var s in D){D[s].uid=F[D[s].Username]}Object.defineProperty(D,"Active",{value:showActiveOnly(D)});if(p._callback){p._callback.call(p,D)}},function(s){Object.defineProperty(D,"Active",{value:showActiveOnly(D)});if(p._callback){p._callback.call(p,D)}})});p._child.stdout.Parent=p._child;p._child.stdout.on("data",function(q){this.Parent._txt+=q.toString()});return(p)};this._recheckLoggedInUsers=function a(){this.enumerateUsers().then(function(o){if(o.Active.length>0){if(this.parent._linux_lock_watcher!=null&&this.parent._linux_lock_watcher.uid!=o.Active[0].uid){delete this.parent._linux_lock_watcher}this.parent._linux_lock_watcher=new g(process.env.XDG_CURRENT_DESKTOP=="Unity"?"com.ubuntu.Upstart0_6":"org.gnome.ScreenSaver",o.Active[0].uid);this.parent._linux_lock_watcher.user_session=this.parent;this.parent._linux_lock_watcher.on("signal",function(r){var q=this.user_session.enumerateUsers();q.signalData=r.data[0];q.then(function(p){switch(this.signalData){case true:case"desktop-lock":this.parent.emit("locked",p.Active[0]);break;case false:case"desktop-unlock":this.parent.emit("unlocked",p.Active[0]);break}})})}else{if(this.parent._linux_lock_watcher!=null){delete this.parent._linux_lock_watcher}}})};this.on("changed",this._recheckLoggedInUsers);this._recheckLoggedInUsers()}else{if(process.platform=="darwin"){this._users=function(){var o=require("child_process").execFile("/usr/bin/dscl",["dscl",".","list","/Users","UniqueID"]);o.stdout.str="";o.stdout.on("data",function(t){this.str+=t.toString()});o.stdin.write("exit\n");o.waitExit();var q=o.stdout.str.split("\n");var r,p;var s={};for(p=0;p<q.length;++p){r=q[p].split(" ");if(r[0]){s[r[0]]=r[r.length-1]}}return(s)};this._uids=function(){var o=require("child_process").execFile("/usr/bin/dscl",["dscl",".","list","/Users","UniqueID"]);o.stdout.str="";o.stdout.on("data",function(t){this.str+=t.toString()});o.stdin.write("exit\n");o.waitExit();var q=o.stdout.str.split("\n");var r,p;var s={};for(p=0;p<q.length;++p){r=q[p].split(" ");if(r[0]){s[r[r.length-1]]=r[0]}}return(s)};this._idTable=function(){var v={};var o=require("child_process").execFile("/usr/bin/id",["id"]);o.stdout.str="";o.stdout.on("data",function(y){this.str+=y.toString()});o.waitExit();var t=o.stdout.str.split("\n")[0].split(" ");for(var p=0;p<t.length;++p){var x=t[p].split("=");var w=x[1].split(",");v[x[0]]={};for(var s in w){var r=w[s].split("(");var q=r[0];var u=r[1].substring(0,r[1].length-1).trim();v[x[0]][u]=q;v[x[0]][q]=u}}return(v)};this.Current=function(o){var u={};var t=this._idTable();var p=require("child_process").execFile("/usr/bin/last",["last"]);p.stdout.str="";p.stdout.on("data",function(v){this.str+=v.toString()});p.waitExit();var s=p.stdout.str.split("\n");for(var r=0;r<s.length&&s[r].length>0;++r){if(!u[s[r].split(" ")[0]]){try{u[s[r].split(" ")[0]]={Username:s[r].split(" ")[0],State:s[r].split("still logged in").length>1?"Active":"Inactive",uid:t.uid[s[r].split(" ")[0]]}}catch(q){}}else{if(u[s[r].split(" ")[0]].State!="Active"&&s[r].split("still logged in").length>1){u[s[r].split(" ")[0]].State="Active"}}}Object.defineProperty(u,"Active",{value:showActiveOnly(u)});if(o){o.call(this,u)}}}}}if(process.platform=="linux"||process.platform=="darwin"){this._self=function b(){var o=require("child_process").execFile("/usr/bin/id",["id","-u"]);o.stdout.str="";o.stdout.on("data",function(p){this.str+=p.toString()});o.waitExit();return(parseInt(o.stdout.str))};this.isRoot=function k(){return(this._self()==0)};this.consoleUid=function e(){var o=process.platform=="darwin"?"console":((process.env.DISPLAY)?process.env.DISPLAY:":0");var p=require("child_process").execFile("/bin/sh",["sh"]);p.stdout.str="";p.stdout.on("data",function(u){this.str+=u.toString()});p.stdin.write("who\nexit\n");p.waitExit();var s=p.stdout.str.split("\n");var t,q,r;for(q in s){t=s[q].split(" ");for(r=1;r<t.length;++r){if(t[r].length>0&&(t[r]==o||t[r]==("("+o+")"))){return(parseInt(this._users()[t[0]]))}}}throw ("nobody logged into console")}}}function showActiveOnly(c){var b=[];var e={};var f=[];var d;for(var a in c){if(c[a].State=="Active"){b.push(c[a]);d=(c[a].Domain?(c[a].Domain+"\\"):"")+c[a].Username;if(!e[d]){e[d]=d}}}for(var a in e){f.push(a)}Object.defineProperty(b,"usernames",{value:f});return(b)}function getTokens(d){var a=[];var b;a.push(d.substring(0,(b=d.indexOf(" "))));while(d[++b]==" "){}a.push(d.substring(b,(b=d.substring(b).indexOf(" ")+b)));while(d[++b]==" "){}a.push(d.substring(b,(b=d.substring(b).indexOf(" ")+b)));while(d[++b]==" "){}var c=d.substring(b).trim();a.push(c);return(a)}module.exports=new UserSessions();
\ No newline at end of file
agents/modules_meshcore/user-sessions.js
+25
@@ -92,6 +92,11 @@ function UserSessions()
92 {
93 }
94
95 + this._advapi = this._marshal.CreateNativeProxy('Advapi32.dll');
96 + this._advapi.CreateMethod('AllocateAndInitializeSid');
97 + this._advapi.CreateMethod('CheckTokenMembership');
98 + this._advapi.CreateMethod('FreeSid');
99 +
100 this._user32 = this._marshal.CreateNativeProxy('user32.dll');
101 this._user32.CreateMethod({ method: 'RegisterPowerSettingNotification', threadDispatch: 1});
102 this._user32.CreateMethod('UnregisterPowerSettingNotification');
@@ -150,6 +155,26 @@ function UserSessions()
155 'WTSIsRemoteSession': 29
156 };
157
158 + this.isRoot = function isRoot()
159 + {
160 + var NTAuthority = this._marshal.CreateVariable(6);
161 + NTAuthority.toBuffer().writeInt8(5, 5);
162 +
163 + var AdministratorsGroup = this._marshal.CreatePointer();
164 + var admin = false;
165 +
166 + if (this._advapi.AllocateAndInitializeSid(NTAuthority, 2, 32, 544, 0, 0, 0, 0, 0, 0, AdministratorsGroup).Val != 0)
167 + {
168 + var member = this._marshal.CreateInteger();
169 + if (this._advapi.CheckTokenMembership(0, AdministratorsGroup.Deref(), member).Val != 0)
170 + {
171 + if (member.toBuffer().readUInt32LE() != 0) { admin = true; }
172 + }
173 + this._advapi.FreeSid(AdministratorsGroup.Deref());
174 + }
175 + return admin;
176 + }
177 +
178 this.getSessionAttribute = function getSessionAttribute(sessionId, attr)
179 {
180 var buffer = this._marshal.CreatePointer();
agents/modules_meshcore/win-registry.js
+55 -4
@@ -1,5 +1,5 @@
1 /*
2 -Copyright 2018-2019 Intel Corporation
2 +Copyright 2018 Intel Corporation
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
@@ -15,6 +15,7 @@ limitations under the License.
15 */
16
17 var KEY_QUERY_VALUE = 0x0001;
18 +var KEY_ENUMERATE_SUB_KEYS = 0x0008;
19 var KEY_WRITE = 0x20006;
20
21 var KEY_DATA_TYPES =
@@ -39,7 +40,10 @@ function windows_registry()
40 this._marshal = require('_GenericMarshal');
41 this._AdvApi = this._marshal.CreateNativeProxy('Advapi32.dll');
42 this._AdvApi.CreateMethod('RegCreateKeyExA');
43 + this._AdvApi.CreateMethod('RegEnumKeyExA');
44 + this._AdvApi.CreateMethod('RegEnumValueA');
45 this._AdvApi.CreateMethod('RegOpenKeyExA');
46 + this._AdvApi.CreateMethod('RegQueryInfoKeyA');
47 this._AdvApi.CreateMethod('RegQueryValueExA');
48 this._AdvApi.CreateMethod('RegCloseKey');
49 this._AdvApi.CreateMethod('RegDeleteKeyA');
@@ -49,18 +53,65 @@ function windows_registry()
53
54 this.QueryKey = function QueryKey(hkey, path, key)
55 {
56 + var err;
57 var h = this._marshal.CreatePointer();
58 var len = this._marshal.CreateVariable(4);
59 var valType = this._marshal.CreateVariable(4);
55 - key = this._marshal.CreateVariable(key);
60 var HK = this._marshal.CreatePointer(hkey);
61 var retVal = null;
62 + if (key) { key = this._marshal.CreateVariable(key); }
63 + if (!path) { path = ''; }
64
59 - if (this._AdvApi.RegOpenKeyExA(HK, this._marshal.CreateVariable(path), 0, KEY_QUERY_VALUE, h).Val != 0)
65 +
66 + if ((err = this._AdvApi.RegOpenKeyExA(HK, this._marshal.CreateVariable(path), 0, KEY_QUERY_VALUE | KEY_ENUMERATE_SUB_KEYS, h).Val) != 0)
67 {
61 - throw ('Error Opening Registry Key: ' + path);
68 + throw ('Opening Registry Key: ' + path + ' => Returned Error: ' + err);
69 }
70
71 + if ((path == '' && !key) || !key)
72 + {
73 + var result = { subkeys: [], values: [] };
74 +
75 + // Enumerate keys
76 + var achClass = this._marshal.CreateVariable(1024);
77 + var achKey = this._marshal.CreateVariable(1024);
78 + var achValue = this._marshal.CreateVariable(32768);
79 + var achValueSize = this._marshal.CreateVariable(4);
80 + var nameSize = this._marshal.CreateVariable(4);
81 + var achClassSize = this._marshal.CreateVariable(4); achClassSize.toBuffer().writeUInt32LE(1024);
82 + var numSubKeys = this._marshal.CreateVariable(4);
83 + var numValues = this._marshal.CreateVariable(4);
84 + var longestSubkeySize = this._marshal.CreateVariable(4);
85 + var longestClassString = this._marshal.CreateVariable(4);
86 + var longestValueName = this._marshal.CreateVariable(4);
87 + var longestValueData = this._marshal.CreateVariable(4);
88 + var securityDescriptor = this._marshal.CreateVariable(4);
89 + var lastWriteTime = this._marshal.CreateVariable(8);
90 +
91 + retVal = this._AdvApi.RegQueryInfoKeyA(h.Deref(), achClass, achClassSize, 0,
92 + numSubKeys, longestSubkeySize, longestClassString, numValues,
93 + longestValueName, longestValueData, securityDescriptor, lastWriteTime);
94 + if (retVal.Val != 0) { throw ('RegQueryInfoKeyA() returned error: ' + retVal.Val); }
95 + for(var i = 0; i < numSubKeys.toBuffer().readUInt32LE(); ++i)
96 + {
97 + nameSize.toBuffer().writeUInt32LE(1024);
98 + retVal = this._AdvApi.RegEnumKeyExA(h.Deref(), i, achKey, nameSize, 0, 0, 0, lastWriteTime);
99 + if(retVal.Val == 0)
100 + {
101 + result.subkeys.push(achKey.String);
102 + }
103 + }
104 + for (var i = 0; i < numValues.toBuffer().readUInt32LE() ; ++i)
105 + {
106 + achValueSize.toBuffer().writeUInt32LE(32768);
107 + if(this._AdvApi.RegEnumValueA(h.Deref(), i, achValue, achValueSize, 0, 0, 0, 0).Val == 0)
108 + {
109 + result.values.push(achValue.String);
110 + }
111 + }
112 + return (result);
113 + }
114 +
115 if(this._AdvApi.RegQueryValueExA(h.Deref(), key, 0, 0, 0, len).Val == 0)
116 {
117 var data = this._marshal.CreateVariable(len.toBuffer().readUInt32LE());
agents/modules_meshcore_min/user-sessions.min.js
+1 -1
@@ -1 +1 @@
1 -var NOTIFY_FOR_THIS_SESSION=0;var NOTIFY_FOR_ALL_SESSIONS=1;var WM_WTSSESSION_CHANGE=689;var WM_POWERBROADCAST=536;var PBT_POWERSETTINGCHANGE=32787;var PBT_APMSUSPEND=4;var PBT_APMRESUMESUSPEND=7;var PBT_APMRESUMEAUTOMATIC=18;var PBT_APMPOWERSTATUSCHANGE=10;var WTS_CONSOLE_CONNECT=(1);var WTS_CONSOLE_DISCONNECT=(2);var WTS_REMOTE_CONNECT=(3);var WTS_REMOTE_DISCONNECT=(4);var WTS_SESSION_LOGON=(5);var WTS_SESSION_LOGOFF=(6);var WTS_SESSION_LOCK=(7);var WTS_SESSION_UNLOCK=(8);var WTS_SESSION_REMOTE_CONTROL=(9);var WTS_SESSION_CREATE=(10);var WTS_SESSION_TERMINATE=(11);var GUID_ACDC_POWER_SOURCE;var GUID_BATTERY_PERCENTAGE_REMAINING;var GUID_CONSOLE_DISPLAY_STATE;function UserSessions(){this._ObjectID="user-sessions";require("events").EventEmitter.call(this,true).createEvent("changed").createEvent("locked").createEvent("unlocked");this.enumerateUsers=function h(){var s=require("promise");var r=new s(function(t,p){this.__resolver=t;this.__rejector=p});r.__handler=function o(p){r.__resolver(p)};try{this.Current(r.__handler)}catch(q){r.__rejector(q)}r.parent=this;return(r)};if(process.platform=="win32"){this._serviceHooked=false;this._marshal=require("_GenericMarshal");this._kernel32=this._marshal.CreateNativeProxy("Kernel32.dll");this._kernel32.CreateMethod("GetLastError");try{this._wts=this._marshal.CreateNativeProxy("Wtsapi32.dll");this._wts.CreateMethod("WTSEnumerateSessionsA");this._wts.CreateMethod("WTSQuerySessionInformationA");this._wts.CreateMethod("WTSRegisterSessionNotification");this._wts.CreateMethod("WTSUnRegisterSessionNotification");this._wts.CreateMethod("WTSFreeMemory")}catch(i){}this._user32=this._marshal.CreateNativeProxy("user32.dll");this._user32.CreateMethod({method:"RegisterPowerSettingNotification",threadDispatch:1});this._user32.CreateMethod("UnregisterPowerSettingNotification");this._rpcrt=this._marshal.CreateNativeProxy("Rpcrt4.dll");this._rpcrt.CreateMethod("UuidFromStringA");this._rpcrt.StringToUUID=function n(o){var p=n.us._marshal.CreateVariable(16);if(n.us._rpcrt.UuidFromStringA(n.us._marshal.CreateVariable(o),p).Val==0){return(p)}else{throw ("Could not convert string to UUID")}};this._rpcrt.StringToUUID.us=this;GUID_ACDC_POWER_SOURCE=this._rpcrt.StringToUUID("5d3e9a59-e9D5-4b00-a6bd-ff34ff516548");GUID_BATTERY_PERCENTAGE_REMAINING=this._rpcrt.StringToUUID("a7ad8041-b45a-4cae-87a3-eecbb468a9e1");GUID_CONSOLE_DISPLAY_STATE=this._rpcrt.StringToUUID("6fe69556-704a-47a0-8f24-c28d936fda47");this.SessionStates=["Active","Connected","ConnectQuery","Shadow","Disconnected","Idle","Listening","Reset","Down","Init"];this.InfoClass={WTSInitialProgram:0,WTSApplicationName:1,WTSWorkingDirectory:2,WTSOEMId:3,WTSSessionId:4,WTSUserName:5,WTSWinStationName:6,WTSDomainName:7,WTSConnectState:8,WTSClientBuildNumber:9,WTSClientName:10,WTSClientDirectory:11,WTSClientProductId:12,WTSClientHardwareId:13,WTSClientAddress:14,WTSClientDisplay:15,WTSClientProtocolType:16,WTSIdleTime:17,WTSLogonTime:18,WTSIncomingBytes:19,WTSOutgoingBytes:20,WTSIncomingFrames:21,WTSOutgoingFrames:22,WTSClientInfo:23,WTSSessionInfo:24,WTSSessionInfoEx:25,WTSConfigInfo:26,WTSValidationInfo:27,WTSSessionAddressV4:28,WTSIsRemoteSession:29};this.getSessionAttribute=function j(s,o){var p=this._marshal.CreatePointer();var q=this._marshal.CreateVariable(4);if(this._wts.WTSQuerySessionInformationA(0,s,o,p,q).Val==0){throw ("Error calling WTSQuerySessionInformation: "+this._kernel32.GetLastError.Val)}var r=p.Deref().String;this._wts.WTSFreeMemory(p.Deref());return(r)};this.Current=function f(o){var u={};var t=this._marshal.CreatePointer();var p=this._marshal.CreateVariable(4);if(this._wts.WTSEnumerateSessionsA(0,0,1,t,p).Val==0){throw ("Error calling WTSEnumerateSessionsA: "+this._kernel32.GetLastError().Val)}for(var q=0;q<p.toBuffer().readUInt32LE();++q){var r=t.Deref().Deref(q*(this._marshal.PointerSize==4?12:24),this._marshal.PointerSize==4?12:24);var s={SessionId:r.toBuffer().readUInt32LE()};s.StationName=r.Deref(this._marshal.PointerSize==4?4:8,this._marshal.PointerSize).Deref().String;s.State=this.SessionStates[r.Deref(this._marshal.PointerSize==4?8:16,4).toBuffer().readUInt32LE()];if(s.State=="Active"){s.Username=this.getSessionAttribute(s.SessionId,this.InfoClass.WTSUserName);s.Domain=this.getSessionAttribute(s.SessionId,this.InfoClass.WTSDomainName)}u[s.SessionId]=s}this._wts.WTSFreeMemory(t.Deref());Object.defineProperty(u,"Active",{value:showActiveOnly(u)});if(o){o(u)}return(u)};var l=require("win-message-pump");this._messagepump=new l({filter:WM_WTSSESSION_CHANGE});this._messagepump.parent=this;this._messagepump.on("exit",function(o){this.parent._wts.WTSUnRegisterSessionNotification(this.parent.hwnd)});this._messagepump.on("hwnd",function(o){this.parent.hwnd=o;this.immediate=setImmediate(function(p){if(p.parent._wts){p.parent._wts.WTSRegisterSessionNotification(p.parent.hwnd,NOTIFY_FOR_ALL_SESSIONS)}p.parent._user32.ACDC_H=p.parent._user32.RegisterPowerSettingNotification(p.parent.hwnd,GUID_ACDC_POWER_SOURCE,0);p.parent._user32.BATT_H=p.parent._user32.RegisterPowerSettingNotification(p.parent.hwnd,GUID_BATTERY_PERCENTAGE_REMAINING,0);p.parent._user32.DISP_H=p.parent._user32.RegisterPowerSettingNotification(p.parent.hwnd,GUID_CONSOLE_DISPLAY_STATE,0)},this)});this._messagepump.on("message",function(q){switch(q.message){case WM_WTSSESSION_CHANGE:switch(q.wparam){case WTS_SESSION_LOCK:this.parent.enumerateUsers().then(function(r){if(r[q.lparam]){this.parent.emit("locked",r[q.lparam])}});break;case WTS_SESSION_UNLOCK:this.parent.enumerateUsers().then(function(r){if(r[q.lparam]){this.parent.emit("unlocked",r[q.lparam])}});break;case WTS_SESSION_LOGON:case WTS_SESSION_LOGOFF:this.parent.emit("changed");break}break;case WM_POWERBROADCAST:switch(q.wparam){default:console.log("WM_POWERBROADCAST [UNKNOWN wparam]: "+q.wparam);break;case PBT_APMSUSPEND:require("power-monitor").emit("sx","SLEEP");break;case PBT_APMRESUMEAUTOMATIC:require("power-monitor").emit("sx","RESUME_NON_INTERACTIVE");break;case PBT_APMRESUMESUSPEND:require("power-monitor").emit("sx","RESUME_INTERACTIVE");break;case PBT_APMPOWERSTATUSCHANGE:require("power-monitor").emit("changed");break;case PBT_POWERSETTINGCHANGE:var p=this.parent._marshal.CreatePointer(Buffer.from(q.lparam_hex,"hex"));var o=p.Deref(20,p.Deref(16,4).toBuffer().readUInt32LE(0)).toBuffer();switch(p.Deref(0,16).toBuffer().toString("hex")){case GUID_ACDC_POWER_SOURCE.Deref(0,16).toBuffer().toString("hex"):switch(o.readUInt32LE(0)){case 0:require("power-monitor").emit("acdc","AC");break;case 1:require("power-monitor").emit("acdc","BATTERY");break;case 2:require("power-monitor").emit("acdc","HOT");break}break;case GUID_BATTERY_PERCENTAGE_REMAINING.Deref(0,16).toBuffer().toString("hex"):require("power-monitor").emit("batteryLevel",o.readUInt32LE(0));break;case GUID_CONSOLE_DISPLAY_STATE.Deref(0,16).toBuffer().toString("hex"):switch(o.readUInt32LE(0)){case 0:require("power-monitor").emit("display","OFF");break;case 1:require("power-monitor").emit("display","ON");break;case 2:require("power-monitor").emit("display","DIMMED");break}break}break}break;default:break}})}else{if(process.platform=="linux"){var g=require("linux-dbus");this._linuxWatcher=require("fs").watch("/var/run/utmp");this._linuxWatcher.user_session=this;this._linuxWatcher.on("change",function(o,p){this.user_session.emit("changed")});this._users=function d(){var o=require("child_process").execFile("/bin/sh",["sh"]);o.stdout.str="";o.stdout.on("data",function(t){this.str+=t.toString()});o.stdin.write("awk -F: '($3 >= 0) {printf \"%s:%s\\n\", $1, $3}' /etc/passwd\nexit\n");o.waitExit();var p=o.stdout.str.split("\n");var r={},s;for(var q in p){s=p[q].split(":");if(s[0]){r[s[0]]=s[1]}}return(r)};this._uids=function c(){var o=require("child_process").execFile("/bin/sh",["sh"]);o.stdout.str="";o.stdout.on("data",function(t){this.str+=t.toString()});o.stdin.write("awk -F: '($3 >= 0) {printf \"%s:%s\\n\", $1, $3}' /etc/passwd\nexit\n");o.waitExit();var p=o.stdout.str.split("\n");var r={},s;for(var q in p){s=p[q].split(":");if(s[0]){r[s[1]]=s[0]}}return(r)};this.Self=function m(){var q=require("promise");var o=new q(function(r,p){this.__resolver=r;this.__rejector=p;this.__child=require("child_process").execFile("/usr/bin/id",["id","-u"]);this.__child.promise=this;this.__child.stdout._txt="";this.__child.stdout.on("data",function(s){this._txt+=s.toString()});this.__child.on("exit",function(s){try{parseInt(this.stdout._txt)}catch(t){this.promise.__rejector("invalid uid");return}var u=parseInt(this.stdout._txt);this.promise.__resolver(u)})});return(o)};this.Current=function f(o){var p={};p._ObjectID="UserSession";Object.defineProperty(p,"_callback",{value:o});Object.defineProperty(p,"_child",{value:require("child_process").execFile("/usr/bin/last",["last","-f","/var/run/utmp"])});p._child.Parent=p;p._child._txt="";p._child.on("exit",function(q){var u=this._txt.split("\n");var A=[];var D={};for(var t in u){if(u[t]){var B=getTokens(u[t]);var z={Username:B[0],SessionId:B[1]};if(B[3].includes("still logged in")){z.State="Active"}else{z.LastActive=B[3]}A.push(z)}}A.pop();var C={};var y=[];for(var t in A){if(A[t].Username!="reboot"){D[A[t].SessionId]=A[t];if(C[A[t].Username]==null){C[A[t].Username]=-1}}}try{require("promise")}catch(r){Object.defineProperty(D,"Active",{value:showActiveOnly(D)});if(this.Parent._callback){this.Parent._callback.call(this.Parent,D)}return}var x=require("promise");for(var v in C){var w=new x(function(E,s){this.__username=v;this.__resolver=E;this.__rejector=s;this.__child=require("child_process").execFile("/usr/bin/id",["id","-u",v]);this.__child.promise=this;this.__child.stdout._txt="";this.__child.stdout.on("data",function(F){this._txt+=F.toString()});this.__child.on("exit",function(F){try{parseInt(this.stdout._txt)}catch(G){this.promise.__rejector("invalid uid");return}var H=parseInt(this.stdout._txt);this.promise.__resolver(H)})});y.push(w)}x.all(y).then(function(E){var F={};for(var s in E){F[E[s].__username]=E[s]._internal.completedArgs[0]}for(var s in D){D[s].uid=F[D[s].Username]}Object.defineProperty(D,"Active",{value:showActiveOnly(D)});if(p._callback){p._callback.call(p,D)}},function(s){Object.defineProperty(D,"Active",{value:showActiveOnly(D)});if(p._callback){p._callback.call(p,D)}})});p._child.stdout.Parent=p._child;p._child.stdout.on("data",function(q){this.Parent._txt+=q.toString()});return(p)};this._recheckLoggedInUsers=function a(){this.enumerateUsers().then(function(o){if(o.Active.length>0){if(this.parent._linux_lock_watcher!=null&&this.parent._linux_lock_watcher.uid!=o.Active[0].uid){delete this.parent._linux_lock_watcher}this.parent._linux_lock_watcher=new g(process.env.XDG_CURRENT_DESKTOP=="Unity"?"com.ubuntu.Upstart0_6":"org.gnome.ScreenSaver",o.Active[0].uid);this.parent._linux_lock_watcher.user_session=this.parent;this.parent._linux_lock_watcher.on("signal",function(r){var q=this.user_session.enumerateUsers();q.signalData=r.data[0];q.then(function(p){switch(this.signalData){case true:case"desktop-lock":this.parent.emit("locked",p.Active[0]);break;case false:case"desktop-unlock":this.parent.emit("unlocked",p.Active[0]);break}})})}else{if(this.parent._linux_lock_watcher!=null){delete this.parent._linux_lock_watcher}}})};this.on("changed",this._recheckLoggedInUsers);this._recheckLoggedInUsers()}else{if(process.platform=="darwin"){this._users=function(){var o=require("child_process").execFile("/usr/bin/dscl",["dscl",".","list","/Users","UniqueID"]);o.stdout.str="";o.stdout.on("data",function(t){this.str+=t.toString()});o.stdin.write("exit\n");o.waitExit();var q=o.stdout.str.split("\n");var r,p;var s={};for(p=0;p<q.length;++p){r=q[p].split(" ");if(r[0]){s[r[0]]=r[r.length-1]}}return(s)};this._uids=function(){var o=require("child_process").execFile("/usr/bin/dscl",["dscl",".","list","/Users","UniqueID"]);o.stdout.str="";o.stdout.on("data",function(t){this.str+=t.toString()});o.stdin.write("exit\n");o.waitExit();var q=o.stdout.str.split("\n");var r,p;var s={};for(p=0;p<q.length;++p){r=q[p].split(" ");if(r[0]){s[r[r.length-1]]=r[0]}}return(s)};this._idTable=function(){var v={};var o=require("child_process").execFile("/usr/bin/id",["id"]);o.stdout.str="";o.stdout.on("data",function(y){this.str+=y.toString()});o.waitExit();var t=o.stdout.str.split("\n")[0].split(" ");for(var p=0;p<t.length;++p){var x=t[p].split("=");var w=x[1].split(",");v[x[0]]={};for(var s in w){var r=w[s].split("(");var q=r[0];var u=r[1].substring(0,r[1].length-1).trim();v[x[0]][u]=q;v[x[0]][q]=u}}return(v)};this.Current=function(o){var u={};var t=this._idTable();var p=require("child_process").execFile("/usr/bin/last",["last"]);p.stdout.str="";p.stdout.on("data",function(v){this.str+=v.toString()});p.waitExit();var s=p.stdout.str.split("\n");for(var r=0;r<s.length&&s[r].length>0;++r){if(!u[s[r].split(" ")[0]]){try{u[s[r].split(" ")[0]]={Username:s[r].split(" ")[0],State:s[r].split("still logged in").length>1?"Active":"Inactive",uid:t.uid[s[r].split(" ")[0]]}}catch(q){}}else{if(u[s[r].split(" ")[0]].State!="Active"&&s[r].split("still logged in").length>1){u[s[r].split(" ")[0]].State="Active"}}}Object.defineProperty(u,"Active",{value:showActiveOnly(u)});if(o){o.call(this,u)}}}}}if(process.platform=="linux"||process.platform=="darwin"){this._self=function b(){var o=require("child_process").execFile("/usr/bin/id",["id","-u"]);o.stdout.str="";o.stdout.on("data",function(p){this.str+=p.toString()});o.waitExit();return(parseInt(o.stdout.str))};this.isRoot=function k(){return(this._self()==0)};this.consoleUid=function e(){var o=process.platform=="darwin"?"console":((process.env.DISPLAY)?process.env.DISPLAY:":0");var p=require("child_process").execFile("/bin/sh",["sh"]);p.stdout.str="";p.stdout.on("data",function(u){this.str+=u.toString()});p.stdin.write("who\nexit\n");p.waitExit();var s=p.stdout.str.split("\n");var t,q,r;for(q in s){t=s[q].split(" ");for(r=1;r<t.length;++r){if(t[r].length>0&&(t[r]==o||t[r]==("("+o+")"))){return(parseInt(this._users()[t[0]]))}}}throw ("nobody logged into console")}}}function showActiveOnly(c){var b=[];var e={};var f=[];var d;for(var a in c){if(c[a].State=="Active"){b.push(c[a]);d=(c[a].Domain?(c[a].Domain+"\\"):"")+c[a].Username;if(!e[d]){e[d]=d}}}for(var a in e){f.push(a)}Object.defineProperty(b,"usernames",{value:f});return(b)}function getTokens(d){var a=[];var b;a.push(d.substring(0,(b=d.indexOf(" "))));while(d[++b]==" "){}a.push(d.substring(b,(b=d.substring(b).indexOf(" ")+b)));while(d[++b]==" "){}a.push(d.substring(b,(b=d.substring(b).indexOf(" ")+b)));while(d[++b]==" "){}var c=d.substring(b).trim();a.push(c);return(a)}module.exports=new UserSessions();
\ No newline at end of file
1 +var NOTIFY_FOR_THIS_SESSION=0;var NOTIFY_FOR_ALL_SESSIONS=1;var WM_WTSSESSION_CHANGE=689;var WM_POWERBROADCAST=536;var PBT_POWERSETTINGCHANGE=32787;var PBT_APMSUSPEND=4;var PBT_APMRESUMESUSPEND=7;var PBT_APMRESUMEAUTOMATIC=18;var PBT_APMPOWERSTATUSCHANGE=10;var WTS_CONSOLE_CONNECT=(1);var WTS_CONSOLE_DISCONNECT=(2);var WTS_REMOTE_CONNECT=(3);var WTS_REMOTE_DISCONNECT=(4);var WTS_SESSION_LOGON=(5);var WTS_SESSION_LOGOFF=(6);var WTS_SESSION_LOCK=(7);var WTS_SESSION_UNLOCK=(8);var WTS_SESSION_REMOTE_CONTROL=(9);var WTS_SESSION_CREATE=(10);var WTS_SESSION_TERMINATE=(11);var GUID_ACDC_POWER_SOURCE;var GUID_BATTERY_PERCENTAGE_REMAINING;var GUID_CONSOLE_DISPLAY_STATE;function UserSessions(){this._ObjectID="user-sessions";require("events").EventEmitter.call(this,true).createEvent("changed").createEvent("locked").createEvent("unlocked");this.enumerateUsers=function h(){var s=require("promise");var r=new s(function(t,p){this.__resolver=t;this.__rejector=p});r.__handler=function o(p){r.__resolver(p)};try{this.Current(r.__handler)}catch(q){r.__rejector(q)}r.parent=this;return(r)};if(process.platform=="win32"){this._serviceHooked=false;this._marshal=require("_GenericMarshal");this._kernel32=this._marshal.CreateNativeProxy("Kernel32.dll");this._kernel32.CreateMethod("GetLastError");try{this._wts=this._marshal.CreateNativeProxy("Wtsapi32.dll");this._wts.CreateMethod("WTSEnumerateSessionsA");this._wts.CreateMethod("WTSQuerySessionInformationA");this._wts.CreateMethod("WTSRegisterSessionNotification");this._wts.CreateMethod("WTSUnRegisterSessionNotification");this._wts.CreateMethod("WTSFreeMemory")}catch(i){}this._advapi=this._marshal.CreateNativeProxy("Advapi32.dll");this._advapi.CreateMethod("AllocateAndInitializeSid");this._advapi.CreateMethod("CheckTokenMembership");this._advapi.CreateMethod("FreeSid");this._user32=this._marshal.CreateNativeProxy("user32.dll");this._user32.CreateMethod({method:"RegisterPowerSettingNotification",threadDispatch:1});this._user32.CreateMethod("UnregisterPowerSettingNotification");this._rpcrt=this._marshal.CreateNativeProxy("Rpcrt4.dll");this._rpcrt.CreateMethod("UuidFromStringA");this._rpcrt.StringToUUID=function n(o){var p=n.us._marshal.CreateVariable(16);if(n.us._rpcrt.UuidFromStringA(n.us._marshal.CreateVariable(o),p).Val==0){return(p)}else{throw ("Could not convert string to UUID")}};this._rpcrt.StringToUUID.us=this;GUID_ACDC_POWER_SOURCE=this._rpcrt.StringToUUID("5d3e9a59-e9D5-4b00-a6bd-ff34ff516548");GUID_BATTERY_PERCENTAGE_REMAINING=this._rpcrt.StringToUUID("a7ad8041-b45a-4cae-87a3-eecbb468a9e1");GUID_CONSOLE_DISPLAY_STATE=this._rpcrt.StringToUUID("6fe69556-704a-47a0-8f24-c28d936fda47");this.SessionStates=["Active","Connected","ConnectQuery","Shadow","Disconnected","Idle","Listening","Reset","Down","Init"];this.InfoClass={WTSInitialProgram:0,WTSApplicationName:1,WTSWorkingDirectory:2,WTSOEMId:3,WTSSessionId:4,WTSUserName:5,WTSWinStationName:6,WTSDomainName:7,WTSConnectState:8,WTSClientBuildNumber:9,WTSClientName:10,WTSClientDirectory:11,WTSClientProductId:12,WTSClientHardwareId:13,WTSClientAddress:14,WTSClientDisplay:15,WTSClientProtocolType:16,WTSIdleTime:17,WTSLogonTime:18,WTSIncomingBytes:19,WTSOutgoingBytes:20,WTSIncomingFrames:21,WTSOutgoingFrames:22,WTSClientInfo:23,WTSSessionInfo:24,WTSSessionInfoEx:25,WTSConfigInfo:26,WTSValidationInfo:27,WTSSessionAddressV4:28,WTSIsRemoteSession:29};this.isRoot=function k(){var r=this._marshal.CreateVariable(6);r.toBuffer().writeInt8(5,5);var p=this._marshal.CreatePointer();var o=false;if(this._advapi.AllocateAndInitializeSid(r,2,32,544,0,0,0,0,0,0,p).Val!=0){var q=this._marshal.CreateInteger();if(this._advapi.CheckTokenMembership(0,p.Deref(),q).Val!=0){if(q.toBuffer().readUInt32LE()!=0){o=true}}this._advapi.FreeSid(p.Deref())}return o};this.getSessionAttribute=function j(s,o){var p=this._marshal.CreatePointer();var q=this._marshal.CreateVariable(4);if(this._wts.WTSQuerySessionInformationA(0,s,o,p,q).Val==0){throw ("Error calling WTSQuerySessionInformation: "+this._kernel32.GetLastError.Val)}var r=p.Deref().String;this._wts.WTSFreeMemory(p.Deref());return(r)};this.Current=function f(o){var u={};var t=this._marshal.CreatePointer();var p=this._marshal.CreateVariable(4);if(this._wts.WTSEnumerateSessionsA(0,0,1,t,p).Val==0){throw ("Error calling WTSEnumerateSessionsA: "+this._kernel32.GetLastError().Val)}for(var q=0;q<p.toBuffer().readUInt32LE();++q){var r=t.Deref().Deref(q*(this._marshal.PointerSize==4?12:24),this._marshal.PointerSize==4?12:24);var s={SessionId:r.toBuffer().readUInt32LE()};s.StationName=r.Deref(this._marshal.PointerSize==4?4:8,this._marshal.PointerSize).Deref().String;s.State=this.SessionStates[r.Deref(this._marshal.PointerSize==4?8:16,4).toBuffer().readUInt32LE()];if(s.State=="Active"){s.Username=this.getSessionAttribute(s.SessionId,this.InfoClass.WTSUserName);s.Domain=this.getSessionAttribute(s.SessionId,this.InfoClass.WTSDomainName)}u[s.SessionId]=s}this._wts.WTSFreeMemory(t.Deref());Object.defineProperty(u,"Active",{value:showActiveOnly(u)});if(o){o(u)}return(u)};var l=require("win-message-pump");this._messagepump=new l({filter:WM_WTSSESSION_CHANGE});this._messagepump.parent=this;this._messagepump.on("exit",function(o){this.parent._wts.WTSUnRegisterSessionNotification(this.parent.hwnd)});this._messagepump.on("hwnd",function(o){this.parent.hwnd=o;this.immediate=setImmediate(function(p){if(p.parent._wts){p.parent._wts.WTSRegisterSessionNotification(p.parent.hwnd,NOTIFY_FOR_ALL_SESSIONS)}p.parent._user32.ACDC_H=p.parent._user32.RegisterPowerSettingNotification(p.parent.hwnd,GUID_ACDC_POWER_SOURCE,0);p.parent._user32.BATT_H=p.parent._user32.RegisterPowerSettingNotification(p.parent.hwnd,GUID_BATTERY_PERCENTAGE_REMAINING,0);p.parent._user32.DISP_H=p.parent._user32.RegisterPowerSettingNotification(p.parent.hwnd,GUID_CONSOLE_DISPLAY_STATE,0)},this)});this._messagepump.on("message",function(q){switch(q.message){case WM_WTSSESSION_CHANGE:switch(q.wparam){case WTS_SESSION_LOCK:this.parent.enumerateUsers().then(function(r){if(r[q.lparam]){this.parent.emit("locked",r[q.lparam])}});break;case WTS_SESSION_UNLOCK:this.parent.enumerateUsers().then(function(r){if(r[q.lparam]){this.parent.emit("unlocked",r[q.lparam])}});break;case WTS_SESSION_LOGON:case WTS_SESSION_LOGOFF:this.parent.emit("changed");break}break;case WM_POWERBROADCAST:switch(q.wparam){default:console.log("WM_POWERBROADCAST [UNKNOWN wparam]: "+q.wparam);break;case PBT_APMSUSPEND:require("power-monitor").emit("sx","SLEEP");break;case PBT_APMRESUMEAUTOMATIC:require("power-monitor").emit("sx","RESUME_NON_INTERACTIVE");break;case PBT_APMRESUMESUSPEND:require("power-monitor").emit("sx","RESUME_INTERACTIVE");break;case PBT_APMPOWERSTATUSCHANGE:require("power-monitor").emit("changed");break;case PBT_POWERSETTINGCHANGE:var p=this.parent._marshal.CreatePointer(Buffer.from(q.lparam_hex,"hex"));var o=p.Deref(20,p.Deref(16,4).toBuffer().readUInt32LE(0)).toBuffer();switch(p.Deref(0,16).toBuffer().toString("hex")){case GUID_ACDC_POWER_SOURCE.Deref(0,16).toBuffer().toString("hex"):switch(o.readUInt32LE(0)){case 0:require("power-monitor").emit("acdc","AC");break;case 1:require("power-monitor").emit("acdc","BATTERY");break;case 2:require("power-monitor").emit("acdc","HOT");break}break;case GUID_BATTERY_PERCENTAGE_REMAINING.Deref(0,16).toBuffer().toString("hex"):require("power-monitor").emit("batteryLevel",o.readUInt32LE(0));break;case GUID_CONSOLE_DISPLAY_STATE.Deref(0,16).toBuffer().toString("hex"):switch(o.readUInt32LE(0)){case 0:require("power-monitor").emit("display","OFF");break;case 1:require("power-monitor").emit("display","ON");break;case 2:require("power-monitor").emit("display","DIMMED");break}break}break}break;default:break}})}else{if(process.platform=="linux"){var g=require("linux-dbus");this._linuxWatcher=require("fs").watch("/var/run/utmp");this._linuxWatcher.user_session=this;this._linuxWatcher.on("change",function(o,p){this.user_session.emit("changed")});this._users=function d(){var o=require("child_process").execFile("/bin/sh",["sh"]);o.stdout.str="";o.stdout.on("data",function(t){this.str+=t.toString()});o.stdin.write("awk -F: '($3 >= 0) {printf \"%s:%s\\n\", $1, $3}' /etc/passwd\nexit\n");o.waitExit();var p=o.stdout.str.split("\n");var r={},s;for(var q in p){s=p[q].split(":");if(s[0]){r[s[0]]=s[1]}}return(r)};this._uids=function c(){var o=require("child_process").execFile("/bin/sh",["sh"]);o.stdout.str="";o.stdout.on("data",function(t){this.str+=t.toString()});o.stdin.write("awk -F: '($3 >= 0) {printf \"%s:%s\\n\", $1, $3}' /etc/passwd\nexit\n");o.waitExit();var p=o.stdout.str.split("\n");var r={},s;for(var q in p){s=p[q].split(":");if(s[0]){r[s[1]]=s[0]}}return(r)};this.Self=function m(){var q=require("promise");var o=new q(function(r,p){this.__resolver=r;this.__rejector=p;this.__child=require("child_process").execFile("/usr/bin/id",["id","-u"]);this.__child.promise=this;this.__child.stdout._txt="";this.__child.stdout.on("data",function(s){this._txt+=s.toString()});this.__child.on("exit",function(s){try{parseInt(this.stdout._txt)}catch(t){this.promise.__rejector("invalid uid");return}var u=parseInt(this.stdout._txt);this.promise.__resolver(u)})});return(o)};this.Current=function f(o){var p={};p._ObjectID="UserSession";Object.defineProperty(p,"_callback",{value:o});Object.defineProperty(p,"_child",{value:require("child_process").execFile("/usr/bin/last",["last","-f","/var/run/utmp"])});p._child.Parent=p;p._child._txt="";p._child.on("exit",function(q){var u=this._txt.split("\n");var A=[];var D={};for(var t in u){if(u[t]){var B=getTokens(u[t]);var z={Username:B[0],SessionId:B[1]};if(B[3].includes("still logged in")){z.State="Active"}else{z.LastActive=B[3]}A.push(z)}}A.pop();var C={};var y=[];for(var t in A){if(A[t].Username!="reboot"){D[A[t].SessionId]=A[t];if(C[A[t].Username]==null){C[A[t].Username]=-1}}}try{require("promise")}catch(r){Object.defineProperty(D,"Active",{value:showActiveOnly(D)});if(this.Parent._callback){this.Parent._callback.call(this.Parent,D)}return}var x=require("promise");for(var v in C){var w=new x(function(E,s){this.__username=v;this.__resolver=E;this.__rejector=s;this.__child=require("child_process").execFile("/usr/bin/id",["id","-u",v]);this.__child.promise=this;this.__child.stdout._txt="";this.__child.stdout.on("data",function(F){this._txt+=F.toString()});this.__child.on("exit",function(F){try{parseInt(this.stdout._txt)}catch(G){this.promise.__rejector("invalid uid");return}var H=parseInt(this.stdout._txt);this.promise.__resolver(H)})});y.push(w)}x.all(y).then(function(E){var F={};for(var s in E){F[E[s].__username]=E[s]._internal.completedArgs[0]}for(var s in D){D[s].uid=F[D[s].Username]}Object.defineProperty(D,"Active",{value:showActiveOnly(D)});if(p._callback){p._callback.call(p,D)}},function(s){Object.defineProperty(D,"Active",{value:showActiveOnly(D)});if(p._callback){p._callback.call(p,D)}})});p._child.stdout.Parent=p._child;p._child.stdout.on("data",function(q){this.Parent._txt+=q.toString()});return(p)};this._recheckLoggedInUsers=function a(){this.enumerateUsers().then(function(o){if(o.Active.length>0){if(this.parent._linux_lock_watcher!=null&&this.parent._linux_lock_watcher.uid!=o.Active[0].uid){delete this.parent._linux_lock_watcher}this.parent._linux_lock_watcher=new g(process.env.XDG_CURRENT_DESKTOP=="Unity"?"com.ubuntu.Upstart0_6":"org.gnome.ScreenSaver",o.Active[0].uid);this.parent._linux_lock_watcher.user_session=this.parent;this.parent._linux_lock_watcher.on("signal",function(r){var q=this.user_session.enumerateUsers();q.signalData=r.data[0];q.then(function(p){switch(this.signalData){case true:case"desktop-lock":this.parent.emit("locked",p.Active[0]);break;case false:case"desktop-unlock":this.parent.emit("unlocked",p.Active[0]);break}})})}else{if(this.parent._linux_lock_watcher!=null){delete this.parent._linux_lock_watcher}}})};this.on("changed",this._recheckLoggedInUsers);this._recheckLoggedInUsers()}else{if(process.platform=="darwin"){this._users=function(){var o=require("child_process").execFile("/usr/bin/dscl",["dscl",".","list","/Users","UniqueID"]);o.stdout.str="";o.stdout.on("data",function(t){this.str+=t.toString()});o.stdin.write("exit\n");o.waitExit();var q=o.stdout.str.split("\n");var r,p;var s={};for(p=0;p<q.length;++p){r=q[p].split(" ");if(r[0]){s[r[0]]=r[r.length-1]}}return(s)};this._uids=function(){var o=require("child_process").execFile("/usr/bin/dscl",["dscl",".","list","/Users","UniqueID"]);o.stdout.str="";o.stdout.on("data",function(t){this.str+=t.toString()});o.stdin.write("exit\n");o.waitExit();var q=o.stdout.str.split("\n");var r,p;var s={};for(p=0;p<q.length;++p){r=q[p].split(" ");if(r[0]){s[r[r.length-1]]=r[0]}}return(s)};this._idTable=function(){var v={};var o=require("child_process").execFile("/usr/bin/id",["id"]);o.stdout.str="";o.stdout.on("data",function(y){this.str+=y.toString()});o.waitExit();var t=o.stdout.str.split("\n")[0].split(" ");for(var p=0;p<t.length;++p){var x=t[p].split("=");var w=x[1].split(",");v[x[0]]={};for(var s in w){var r=w[s].split("(");var q=r[0];var u=r[1].substring(0,r[1].length-1).trim();v[x[0]][u]=q;v[x[0]][q]=u}}return(v)};this.Current=function(o){var u={};var t=this._idTable();var p=require("child_process").execFile("/usr/bin/last",["last"]);p.stdout.str="";p.stdout.on("data",function(v){this.str+=v.toString()});p.waitExit();var s=p.stdout.str.split("\n");for(var r=0;r<s.length&&s[r].length>0;++r){if(!u[s[r].split(" ")[0]]){try{u[s[r].split(" ")[0]]={Username:s[r].split(" ")[0],State:s[r].split("still logged in").length>1?"Active":"Inactive",uid:t.uid[s[r].split(" ")[0]]}}catch(q){}}else{if(u[s[r].split(" ")[0]].State!="Active"&&s[r].split("still logged in").length>1){u[s[r].split(" ")[0]].State="Active"}}}Object.defineProperty(u,"Active",{value:showActiveOnly(u)});if(o){o.call(this,u)}}}}}if(process.platform=="linux"||process.platform=="darwin"){this._self=function b(){var o=require("child_process").execFile("/usr/bin/id",["id","-u"]);o.stdout.str="";o.stdout.on("data",function(p){this.str+=p.toString()});o.waitExit();return(parseInt(o.stdout.str))};this.isRoot=function k(){return(this._self()==0)};this.consoleUid=function e(){var o=process.platform=="darwin"?"console":((process.env.DISPLAY)?process.env.DISPLAY:":0");var p=require("child_process").execFile("/bin/sh",["sh"]);p.stdout.str="";p.stdout.on("data",function(u){this.str+=u.toString()});p.stdin.write("who\nexit\n");p.waitExit();var s=p.stdout.str.split("\n");var t,q,r;for(q in s){t=s[q].split(" ");for(r=1;r<t.length;++r){if(t[r].length>0&&(t[r]==o||t[r]==("("+o+")"))){return(parseInt(this._users()[t[0]]))}}}throw ("nobody logged into console")}}}function showActiveOnly(c){var b=[];var e={};var f=[];var d;for(var a in c){if(c[a].State=="Active"){b.push(c[a]);d=(c[a].Domain?(c[a].Domain+"\\"):"")+c[a].Username;if(!e[d]){e[d]=d}}}for(var a in e){f.push(a)}Object.defineProperty(b,"usernames",{value:f});return(b)}function getTokens(d){var a=[];var b;a.push(d.substring(0,(b=d.indexOf(" "))));while(d[++b]==" "){}a.push(d.substring(b,(b=d.substring(b).indexOf(" ")+b)));while(d[++b]==" "){}a.push(d.substring(b,(b=d.substring(b).indexOf(" ")+b)));while(d[++b]==" "){}var c=d.substring(b).trim();a.push(c);return(a)}module.exports=new UserSessions();
\ No newline at end of file
agents/modules_meshcore_min/win-registry.min.js
+1 -1
@@ -1 +1 @@
1 -var KEY_QUERY_VALUE=1;var KEY_WRITE=131078;var KEY_DATA_TYPES={REG_NONE:0,REG_SZ:1,REG_EXPAND_SZ:2,REG_BINARY:3,REG_DWORD:4,REG_DWORD_BIG_ENDIAN:5,REG_LINK:6,REG_MULTI_SZ:7,REG_RESOURCE_LIST:8,REG_FULL_RESOURCE_DESCRIPTOR:9,REG_RESOURCE_REQUIREMENTS_LIST:10,REG_QWORD:11};function windows_registry(){this._ObjectId="win-registry";this._marshal=require("_GenericMarshal");this._AdvApi=this._marshal.CreateNativeProxy("Advapi32.dll");this._AdvApi.CreateMethod("RegCreateKeyExA");this._AdvApi.CreateMethod("RegOpenKeyExA");this._AdvApi.CreateMethod("RegQueryValueExA");this._AdvApi.CreateMethod("RegCloseKey");this._AdvApi.CreateMethod("RegDeleteKeyA");this._AdvApi.CreateMethod("RegDeleteValueA");this._AdvApi.CreateMethod("RegSetValueExA");this.HKEY={Root:Buffer.from("80000000","hex").swap32(),CurrentUser:Buffer.from("80000001","hex").swap32(),LocalMachine:Buffer.from("80000002","hex").swap32(),Users:Buffer.from("80000003","hex").swap32()};this.QueryKey=function b(g,k,i){var e=this._marshal.CreatePointer();var j=this._marshal.CreateVariable(4);var m=this._marshal.CreateVariable(4);i=this._marshal.CreateVariable(i);var f=this._marshal.CreatePointer(g);var l=null;if(this._AdvApi.RegOpenKeyExA(f,this._marshal.CreateVariable(k),0,KEY_QUERY_VALUE,e).Val!=0){throw ("Error Opening Registry Key: "+k)}if(this._AdvApi.RegQueryValueExA(e.Deref(),i,0,0,0,j).Val==0){var d=this._marshal.CreateVariable(j.toBuffer().readUInt32LE());if(this._AdvApi.RegQueryValueExA(e.Deref(),i,0,m,d,j).Val==0){switch(m.toBuffer().readUInt32LE()){case KEY_DATA_TYPES.REG_DWORD:l=d.toBuffer().readUInt32LE();break;case KEY_DATA_TYPES.REG_DWORD_BIG_ENDIAN:l=d.toBuffer().readUInt32BE();break;case KEY_DATA_TYPES.REG_SZ:l=d.String;break;case KEY_DATA_TYPES.REG_BINARY:default:l=d.toBuffer();l._data=d;break}}}else{this._AdvApi.RegCloseKey(e.Deref());throw ("Not Found")}this._AdvApi.RegCloseKey(e.Deref());return(l)};this.WriteKey=function c(g,j,i,l){var k;var f=this._marshal.CreatePointer();if(this._AdvApi.RegCreateKeyExA(this._marshal.CreatePointer(g),this._marshal.CreateVariable(j),0,0,0,KEY_WRITE,0,f,0).Val!=0){throw ("Error Opening Registry Key: "+j)}var d;var e;switch(typeof(l)){case"boolean":e=KEY_DATA_TYPES.REG_DWORD;d=this._marshal.CreateVariable(4);d.toBuffer().writeUInt32LE(l?1:0);break;case"number":e=KEY_DATA_TYPES.REG_DWORD;d=this._marshal.CreateVariable(4);d.toBuffer().writeUInt32LE(l);break;case"string":e=KEY_DATA_TYPES.REG_SZ;d=this._marshal.CreateVariable(l);break;default:e=KEY_DATA_TYPES.REG_BINARY;d=this._marshal.CreateVariable(l.length);l.copy(d.toBuffer());break}if(this._AdvApi.RegSetValueExA(f.Deref(),this._marshal.CreateVariable(i),0,e,d,d._size).Val!=0){this._AdvApi.RegCloseKey(f.Deref());throw ("Error writing reg key: "+i)}this._AdvApi.RegCloseKey(f.Deref())};this.DeleteKey=function a(e,g,f){if(!f){if(this._AdvApi.RegDeleteKeyA(this._marshal.CreatePointer(e),this._marshal.CreateVariable(g)).Val!=0){throw ("Error Deleting Key: "+g)}}else{var d=this._marshal.CreatePointer();var i;if(this._AdvApi.RegOpenKeyExA(this._marshal.CreatePointer(e),this._marshal.CreateVariable(g),0,KEY_QUERY_VALUE|KEY_WRITE,d).Val!=0){throw ("Error Opening Registry Key: "+g)}if((i=this._AdvApi.RegDeleteValueA(d.Deref(),this._marshal.CreateVariable(f)).Val)!=0){this._AdvApi.RegCloseKey(d.Deref());throw ("Error["+i+"] Deleting Key: "+g+"."+f)}this._AdvApi.RegCloseKey(d.Deref())}}}module.exports=new windows_registry();
\ No newline at end of file
1 +var KEY_QUERY_VALUE=1;var KEY_ENUMERATE_SUB_KEYS=8;var KEY_WRITE=131078;var KEY_DATA_TYPES={REG_NONE:0,REG_SZ:1,REG_EXPAND_SZ:2,REG_BINARY:3,REG_DWORD:4,REG_DWORD_BIG_ENDIAN:5,REG_LINK:6,REG_MULTI_SZ:7,REG_RESOURCE_LIST:8,REG_FULL_RESOURCE_DESCRIPTOR:9,REG_RESOURCE_REQUIREMENTS_LIST:10,REG_QWORD:11};function windows_registry(){this._ObjectId="win-registry";this._marshal=require("_GenericMarshal");this._AdvApi=this._marshal.CreateNativeProxy("Advapi32.dll");this._AdvApi.CreateMethod("RegCreateKeyExA");this._AdvApi.CreateMethod("RegEnumKeyExA");this._AdvApi.CreateMethod("RegEnumValueA");this._AdvApi.CreateMethod("RegOpenKeyExA");this._AdvApi.CreateMethod("RegQueryInfoKeyA");this._AdvApi.CreateMethod("RegQueryValueExA");this._AdvApi.CreateMethod("RegCloseKey");this._AdvApi.CreateMethod("RegDeleteKeyA");this._AdvApi.CreateMethod("RegDeleteValueA");this._AdvApi.CreateMethod("RegSetValueExA");this.HKEY={Root:Buffer.from("80000000","hex").swap32(),CurrentUser:Buffer.from("80000001","hex").swap32(),LocalMachine:Buffer.from("80000002","hex").swap32(),Users:Buffer.from("80000003","hex").swap32()};this.QueryKey=function b(o,A,q){var l;var m=this._marshal.CreatePointer();var s=this._marshal.CreateVariable(4);var E=this._marshal.CreateVariable(4);var n=this._marshal.CreatePointer(o);var C=null;if(q){q=this._marshal.CreateVariable(q)}if(!A){A=""}if((l=this._AdvApi.RegOpenKeyExA(n,this._marshal.CreateVariable(A),0,KEY_QUERY_VALUE|KEY_ENUMERATE_SUB_KEYS,m).Val)!=0){throw ("Opening Registry Key: "+A+" => Returned Error: "+l)}if((A==""&&!q)||!q){var B={subkeys:[],values:[]};var d=this._marshal.CreateVariable(1024);var f=this._marshal.CreateVariable(1024);var g=this._marshal.CreateVariable(32768);var j=this._marshal.CreateVariable(4);var x=this._marshal.CreateVariable(4);var e=this._marshal.CreateVariable(4);e.toBuffer().writeUInt32LE(1024);var y=this._marshal.CreateVariable(4);var z=this._marshal.CreateVariable(4);var u=this._marshal.CreateVariable(4);var t=this._marshal.CreateVariable(4);var w=this._marshal.CreateVariable(4);var v=this._marshal.CreateVariable(4);var D=this._marshal.CreateVariable(4);var r=this._marshal.CreateVariable(8);C=this._AdvApi.RegQueryInfoKeyA(m.Deref(),d,e,0,y,u,t,z,w,v,D,r);if(C.Val!=0){throw ("RegQueryInfoKeyA() returned error: "+C.Val)}for(var p=0;p<y.toBuffer().readUInt32LE();++p){x.toBuffer().writeUInt32LE(1024);C=this._AdvApi.RegEnumKeyExA(m.Deref(),p,f,x,0,0,0,r);if(C.Val==0){B.subkeys.push(f.String)}}for(var p=0;p<z.toBuffer().readUInt32LE();++p){j.toBuffer().writeUInt32LE(32768);if(this._AdvApi.RegEnumValueA(m.Deref(),p,g,j,0,0,0,0).Val==0){B.values.push(g.String)}}return(B)}if(this._AdvApi.RegQueryValueExA(m.Deref(),q,0,0,0,s).Val==0){var k=this._marshal.CreateVariable(s.toBuffer().readUInt32LE());if(this._AdvApi.RegQueryValueExA(m.Deref(),q,0,E,k,s).Val==0){switch(E.toBuffer().readUInt32LE()){case KEY_DATA_TYPES.REG_DWORD:C=k.toBuffer().readUInt32LE();break;case KEY_DATA_TYPES.REG_DWORD_BIG_ENDIAN:C=k.toBuffer().readUInt32BE();break;case KEY_DATA_TYPES.REG_SZ:C=k.String;break;case KEY_DATA_TYPES.REG_BINARY:default:C=k.toBuffer();C._data=k;break}}}else{this._AdvApi.RegCloseKey(m.Deref());throw ("Not Found")}this._AdvApi.RegCloseKey(m.Deref());return(C)};this.WriteKey=function c(g,j,i,l){var k;var f=this._marshal.CreatePointer();if(this._AdvApi.RegCreateKeyExA(this._marshal.CreatePointer(g),this._marshal.CreateVariable(j),0,0,0,KEY_WRITE,0,f,0).Val!=0){throw ("Error Opening Registry Key: "+j)}var d;var e;switch(typeof(l)){case"boolean":e=KEY_DATA_TYPES.REG_DWORD;d=this._marshal.CreateVariable(4);d.toBuffer().writeUInt32LE(l?1:0);break;case"number":e=KEY_DATA_TYPES.REG_DWORD;d=this._marshal.CreateVariable(4);d.toBuffer().writeUInt32LE(l);break;case"string":e=KEY_DATA_TYPES.REG_SZ;d=this._marshal.CreateVariable(l);break;default:e=KEY_DATA_TYPES.REG_BINARY;d=this._marshal.CreateVariable(l.length);l.copy(d.toBuffer());break}if(this._AdvApi.RegSetValueExA(f.Deref(),this._marshal.CreateVariable(i),0,e,d,d._size).Val!=0){this._AdvApi.RegCloseKey(f.Deref());throw ("Error writing reg key: "+i)}this._AdvApi.RegCloseKey(f.Deref())};this.DeleteKey=function a(e,g,f){if(!f){if(this._AdvApi.RegDeleteKeyA(this._marshal.CreatePointer(e),this._marshal.CreateVariable(g)).Val!=0){throw ("Error Deleting Key: "+g)}}else{var d=this._marshal.CreatePointer();var i;if(this._AdvApi.RegOpenKeyExA(this._marshal.CreatePointer(e),this._marshal.CreateVariable(g),0,KEY_QUERY_VALUE|KEY_WRITE,d).Val!=0){throw ("Error Opening Registry Key: "+g)}if((i=this._AdvApi.RegDeleteValueA(d.Deref(),this._marshal.CreateVariable(f)).Val)!=0){this._AdvApi.RegCloseKey(d.Deref());throw ("Error["+i+"] Deleting Key: "+g+"."+f)}this._AdvApi.RegCloseKey(d.Deref())}}}module.exports=new windows_registry();
\ No newline at end of file
db.js
+1 -1
@@ -151,7 +151,7 @@ module.exports.CreateDB = function (parent) {
151 obj.Get = function (id, func) { obj.file.find({ _id: id }, func); };
152 obj.GetAll = function (func) { obj.file.find({}, func); };
153 obj.GetAllTypeNoTypeField = function (type, domain, func) { obj.file.find({ type: type, domain: domain }, { type: 0 }, func); };
154 - obj.GetAllTypeNoTypeFieldMeshFiltered = function (meshes, domain, type, func) { obj.file.find({ type: type, domain: domain, meshid: { $in: meshes } }, { type: 0 }, func); };
154 + obj.GetAllTypeNoTypeFieldMeshFiltered = function (meshes, domain, type, id, func) { var x = { type: type, domain: domain, meshid: { $in: meshes } }; if (id) { x._id = id; } obj.file.find(x, { type: 0 }, func); };
155 obj.GetAllType = function (type, func) { obj.file.find({ type: type }, func); };
156 obj.GetAllIdsOfType = function (ids, domain, type, func) { obj.file.find({ type: type, domain: domain, _id: { $in: ids } }, func); };
157 obj.GetUserWithEmail = function (domain, email, func) { obj.file.find({ type: 'user', domain: domain, email: email }, { type: 0 }, func); };
meshuser.js
+7 -1
@@ -230,6 +230,12 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
230
231 switch (command.action) {
232 case 'ping': { try { ws.send(JSON.stringify({ action: 'pong' })); } catch (ex) { } break; }
233 + case 'authcookie':
234 + {
235 + // Renew the authentication cookie
236 + try { ws.send(JSON.stringify({ action: 'authcookie', cookie: obj.parent.parent.encodeCookie({ userid: user._id, domainid: domain.id }, obj.parent.loginCookieEncryptionKey) })); } catch (ex) { }
237 + break;
238 + }
239 case 'serverstats':
240 {
241 if ((user.siteadmin) != 0) {
@@ -267,7 +273,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
273 }
274
275 // Request a list of all nodes
270 - obj.db.GetAllTypeNoTypeFieldMeshFiltered(links, domain.id, 'node', function (err, docs) {
276 + obj.db.GetAllTypeNoTypeFieldMeshFiltered(links, domain.id, 'node', command.id, function (err, docs) {
277 var r = {};
278 for (i in docs) {
279 // Add the connection state
package.json
+1 -1
@@ -1,6 +1,6 @@
1 {
2 "name": "meshcentral",
3 - "version": "0.2.7-a",
3 + "version": "0.2.7-b",
4 "keywords": [
5 "Remote Management",
6 "Intel AMT",
views/default.handlebars
+89 -47
@@ -33,21 +33,21 @@
33 </head>
34 <body id="body" onload="if (typeof(startup) !== 'undefined') startup();" oncontextmenu="handleContextMenu(event)" style="display:none">
35 <!-- right click menu -->
36 - <div id="contextMenu" class="contextMenu" style="display:none">
37 - <div id="cxinfo" class="cmtext" onclick="cmaction(1)"><b>Information</b></div>
38 - <div id="cxdesktop" class="cmtext" onclick="cmaction(3)">Desktop</div>
39 - <div id="cxterminal" class="cmtext" onclick="cmaction(2)">Terminal</div>
40 - <div id="cxfiles" class="cmtext" onclick="cmaction(4)">Files</div>
41 - <div id="cxevents" class="cmtext" onclick="cmaction(5)">Events</div>
42 - <div id="cxconsole" class="cmtext" onclick="cmaction(6)">Console</div>
36 + <div id="contextMenu" class="contextMenu noselect" style="display:none">
37 + <div id="cxinfo" class="cmtext" onclick="cmaction(1,event)"><b>Information</b></div>
38 + <div id="cxdesktop" class="cmtext" onclick="cmaction(3,event)">Desktop</div>
39 + <div id="cxterminal" class="cmtext" onclick="cmaction(2,event)">Terminal</div>
40 + <div id="cxfiles" class="cmtext" onclick="cmaction(4,event)">Files</div>
41 + <div id="cxevents" class="cmtext" onclick="cmaction(5,event)">Events</div>
42 + <div id="cxconsole" class="cmtext" onclick="cmaction(6,event)">Console</div>
43 <hr id="cxmgroupsplit" />
44 - <div id="cxmdesktop" class="cmtext" onclick="cmaction(7)" style=display:none>Multi-Desktop</div>
44 + <div id="cxmdesktop" class="cmtext" onclick="cmaction(7,event)" style=display:none>Multi-Desktop</div>
45 </div>
46 - <div id="meshContextMenu" class="contextMenu" style="display: none; min-width: 0px">
47 - <div id="cxselectall" class="cmtext" onclick="cmmeshaction(1)">Select All</div>
48 - <div id="cxselectnone" class="cmtext" onclick="cmmeshaction(2)">Select None</div>
46 + <div id="meshContextMenu" class="contextMenu,noselect" style="display: none; min-width: 0px">
47 + <div id="cxselectall" class="cmtext" onclick="cmmeshaction(1,event)">Select All</div>
48 + <div id="cxselectnone" class="cmtext" onclick="cmmeshaction(2,event)">Select None</div>
49 <hr id="cxmgroupsplit2" style=display:none />
50 - <div id="cxmmdesktop" class="cmtext" style=display:none onclick="cmmeshaction(3)">Multi-Desktop</div>
50 + <div id="cxmmdesktop" class="cmtext" style=display:none onclick="cmmeshaction(3,event)">Multi-Desktop</div>
51 </div>
52 <!-- main page -->
53 <div id=container style=max-height:100vh;position:relative>
@@ -156,7 +156,7 @@
156 <div id=devViewButton3 class=viewSelector onclick=onDeviceViewChange(3) title="Desktops"><div class="viewSelector3"></div></div>
157 <div id=devViewButton4 class=viewSelector onclick=onDeviceViewChange(4) title="Map"><div class="viewSelector4"></div></div>
158 </div><div><h1>My Devices</h1></div>
159 - <table style=width:100%;height:24px;background-color:#d3d9d6;vertical-align:middle;border-spacing:0>
159 + <table class="noselect" style=width:100%;height:24px;background-color:#d3d9d6;vertical-align:middle;border-spacing:0>
160 <tr>
161 <td class=h1></td>
162 <td id=devListToolbar class=style14 style=display:none>
@@ -221,7 +221,7 @@
221 </tr>
222 </table>
223 </div>
224 - <div id="xdevices" style="max-height:calc(100vh - 239px);overflow-y:auto;overflow-x:hidden;-webkit-overflow-scrolling:touch;display:none"></div>
224 + <div id="xdevices" class="noselect" style="max-height:calc(100vh - 239px);overflow-y:auto;overflow-x:hidden;-webkit-overflow-scrolling:touch;display:none"></div>
225 <div id="xdevicesmap" style="height:calc(100vh - 239px);width:100%;overflow:hidden;position:relative;display:none">
226 <div id=xmapSearchResultsDlg style="position:absolute;display:none;max-height:280px;left:5px;top:5px;max-width:250px;z-index:1000;background-color:#EEE;box-shadow:0px 0px 15px #666">
227 <div style="width:100%;background-color:#003366;color:#FFF;border-radius:5px 5px 0 0">
@@ -371,7 +371,7 @@
371 <tr>
372 <td style=width:auto valign=top>
373 <div id=p10title>
374 - <div style="float:left"><div class="backButton" onclick=goBack() title="Back"><div class="backButtonEx"></div></div></div>
374 + <div id="p10BackButton" style="float:left"><div class="backButton" onclick=goBack() title="Back"><div class="backButtonEx"></div></div></div>
375 <h1>General - <span id=p10deviceName></span></h1>
376 </div>
377 <div id=p10html></div>
@@ -389,7 +389,7 @@
389 <div id=p11 class=noselect style=display:none>
390 <div id="p11title">
391 <div id=p11deviceNameHeader>
392 - <div style="float:left"><div class="backButton" onclick=goBack() title="Back"><div class="backButtonEx"></div></div></div>
392 + <div id="p11BackButton" style="float:left"><div class="backButton" onclick=goBack() title="Back"><div class="backButtonEx"></div></div></div>
393 <div style="float:right" id="devListToolbarViewIcons"><div class="viewSelector" onclick=deskToggleFull(event) title="Full Screen. Hold shift to browser full screen."><div class="viewSelector5"></div></div></div>
394 <h1>Desktop - <span id=p11deviceName></span></h1>
395 </div>
@@ -475,7 +475,7 @@
475 </div>
476 <div id=p12 style="display:none">
477 <div id="p12title">
478 - <div style="float:left"><div class="backButton" onclick=goBack() title="Back"><div class="backButtonEx"></div></div></div>
478 + <div id="p12BackButton" style="float:left"><div class="backButton" onclick=goBack() title="Back"><div class="backButtonEx"></div></div></div>
479 <h1>Terminal - <span id=p12deviceName></span></h1>
480 </div>
481 <div id="p12warning" style='max-width:100%;display:none;cursor:pointer;margin-bottom:5px' onclick=showFeaturesDlg()>
@@ -536,7 +536,7 @@
536 </div>
537 <div id=p13 style=display:none>
538 <div id="p13title">
539 - <div style="float:left"><div class="backButton" onclick=goBack() title="Back"><div class="backButtonEx"></div></div></div>
539 + <div id="p13BackButton" style="float:left"><div class="backButton" onclick=goBack() title="Back"><div class="backButtonEx"></div></div></div>
540 <h1>Files - <span id=p13deviceName></span></h1>
541 </div>
542 <table id="p13toolbar" style="width: 100%" cellpadding="0" cellspacing="0">
@@ -596,14 +596,14 @@
596 </div>
597 <div id=p14 style=display:none>
598 <div id="p14title">
599 - <div style="float:left"><div class="backButton" onclick=goBack() title="Back"><div class="backButtonEx"></div></div></div>
599 + <div id="p14BackButton" style="float:left"><div class="backButton" onclick=goBack() title="Back"><div class="backButtonEx"></div></div></div>
600 <h1>Intel&reg; AMT - <span id=p14deviceName></span></h1>
601 </div>
602 <iframe id=p14iframe style="width:100%;height:calc(100vh - 242px);border:0;overflow:hidden" src="/commander.htm"></iframe>
603 </div>
604 <div id=p15 style=display:none>
605 <div id="p15title">
606 - <div style="float:left"><div class="backButton" onclick=goBack() title="Back"><div class="backButtonEx"></div></div></div>
606 + <div id="p15BackButton" style="float:left"><div class="backButton" onclick=goBack() title="Back"><div class="backButtonEx"></div></div></div>
607 <h1>Console - <span id=p15deviceName></span></h1>
608 </div>
609 <table cellpadding=0 cellspacing=0 style="width:100%;padding:0px;padding:0px;margin-top:0px">
@@ -643,7 +643,7 @@
643 </div>
644 <div id=p16 style=display:none>
645 <div id="p16title">
646 - <div style="float:left"><div class="backButton" onclick=goBack() title="Back"><div class="backButtonEx"></div></div></div>
646 + <div id="p16BackButton" style="float:left"><div class="backButton" onclick=goBack() title="Back"><div class="backButtonEx"></div></div></div>
647 <h1>Events - <span id=p16deviceName></span></h1>
648 </div>
649 <div style=width:100%;height:24px;background-color:#d3d9d6;margin-bottom:4px>
@@ -849,7 +849,7 @@
849 var meshserver = null;
850 var meshes = {};
851 var meshcount = 0;
852 - var nodes = [];
852 + var nodes = null;
853 var filetree = {};
854 var userinfo = null;
855 var serverinfo = null;
@@ -868,6 +868,7 @@
868 var domain = "{{{domain}}}";
869 var domainUrl = "{{{domainurl}}}";
870 var authCookie = "{{{authCookie}}}";
871 + var authCookieRenewTimer = null;
872 var multiDesktop = {};
873 var multiDesktopFilter = null;
874 var serverPublicNamePort = "{{{serverDnsName}}}:{{{serverPublicPort}}}";
@@ -889,8 +890,6 @@
890 if (top != self && (loc == null || top.active == false)) { top.location = self.location; return; }
891 }
892
892 - toggleFullScreen();
893 -
893 // Check if we are in debug mode
894 args = parseUriArgs();
895 debugmode = args.debug;
@@ -899,12 +898,13 @@
898 QV('autoconnectbutton2', debugmode); // Terminal
899 QV('autoconnectbutton1', debugmode); // Desktop
900
901 + toggleFullScreen();
902 +
903 // Setup page visuals
904 if (args.hide) {
905 var hide = parseInt(args.hide);
906 QV('masthead', !(hide & 1));
907 QV('topbarmaster', !(hide & 2));
907 - QV('page_leftbar', !(hide & 2));
908 QV('footer', !(hide & 4));
909 QV('p10title', !(hide & 8));
910 QV('p11title', !(hide & 8));
@@ -913,6 +913,21 @@
913 QV('p14title', !(hide & 8));
914 QV('p15title', !(hide & 8));
915 QV('p16title', !(hide & 8));
916 + if (hide & 16) {
917 + QV('page_leftbar', false);
918 + QS('page_content').left = '0px';
919 + }
920 + }
921 +
922 + // We are looking at a single device, remove all the back buttons
923 + if ('{{currentNode}}' != '') {
924 + QV('p10BackButton', false);
925 + QV('p11BackButton', false);
926 + QV('p12BackButton', false);
927 + QV('p13BackButton', false);
928 + QV('p14BackButton', false);
929 + QV('p15BackButton', false);
930 + QV('p16BackButton', false);
931 }
932 p1updateInfo();
933
@@ -980,6 +995,8 @@
995 // Toggle the web page to full screen
996 function toggleFullScreen(toggle) {
997 if (toggle === 1) { webPageFullScreen = !webPageFullScreen; putstore('webPageFullScreen', webPageFullScreen); }
998 + var hide = 0;
999 + if (args.hide) { hide = parseInt(args.hide); }
1000 if (webPageFullScreen == false) {
1001 QS('container').width = '960px';
1002 QS('container')['border-right'] = '1px solid #b7b7b7';
@@ -1007,7 +1024,7 @@
1024 QS('container')['overflow'] = 'hidden';
1025 QS('page_content').position = 'absolute';
1026 QS('page_content').top = '66px';
1010 - QS('page_content').left = '90px';
1027 + QS('page_content').left = (hide & 16)?'0px':'90px';
1028 QS('page_content').right = '0px';
1029 QS('page_content').bottom = '0px';
1030 QS('column_l').height = 'calc(100vh - 135px)';
@@ -1016,14 +1033,14 @@
1033 QS('column_l')["max-height"] = 'calc(100vh - 135px)';
1034 QV('MainMenuSpan', false);
1035 QV('UserDummyMenuSpan', (xxcurrentView < 10) && webPageFullScreen);
1019 - QV('page_leftbar', true);
1036 + QV('page_leftbar', !(hide & 16));
1037 }
1038 //center();
1039 masterUpdate(512);
1040 QV('body', true);
1041 }
1042
1026 - function getNodeFromId(id) { for (var i in nodes) { if (nodes[i]._id == id) return nodes[i]; } return null; }
1043 + function getNodeFromId(id) { if (nodes != null) { for (var i in nodes) { if (nodes[i]._id == id) return nodes[i]; } } return null; }
1044 function reload() { window.location.href = window.location.href; }
1045
1046 function onStateChanged(server, state, prevState, errorCode) {
@@ -1043,12 +1060,14 @@
1060 QV('logoutControl', false);
1061 if (errorCode == 'noauth') { QH('p0span', 'Unable to perform authentication'); return; }
1062 if (prevState == 2) { setTimeout(serverPoll, 5000); } else { QH('p0span', 'Unable to connect web socket'); }
1063 + if (authCookieRenewTimer != null) { clearInterval(authCookieRenewTimer); authCookieRenewTimer = null; }
1064 } else if (state == 2) {
1065 // Fetch list of meshes, nodes, files
1066 meshserver.send({ action: 'meshes' });
1049 - meshserver.send({ action: 'nodes' });
1050 - meshserver.send({ action: 'files' });
1067 + meshserver.send({ action: 'nodes', id: '{{currentNode}}' });
1068 + if ('{{currentNode}}' == '') { meshserver.send({ action: 'files' }); }
1069 go(1);
1070 + authCookieRenewTimer = setInterval(function () { meshserver.send({ action: 'authcookie' }); }, 1800000); // Request a cookie refresh every 30 minutes.
1071 }
1072 }
1073
@@ -1140,6 +1159,11 @@
1159 updateServerStats(message);
1160 break;
1161 }
1162 + case 'authcookie': {
1163 + // Got an authentication cookie refresh
1164 + authCookie = message.cookie;
1165 + break;
1166 + }
1167 case 'serverinfo': {
1168 serverinfo = message.serverinfo;
1169 break;
@@ -1221,7 +1245,7 @@
1245 // Check if this is a message from a node
1246 if (message.nodeid != null) {
1247 var index = -1;
1224 - for (var i in nodes) { if (nodes[i]._id == message.nodeid) { index = i; break; } }
1248 + if (nodes != null) { for (var i in nodes) { if (nodes[i]._id == message.nodeid) { index = i; break; } } }
1249 if (index != -1) {
1250 // Node was found, dispatch the message
1251 if (message.type == 'console') { p15consoleReceive(nodes[index], message.value); } // This is a console message.
@@ -1444,7 +1468,7 @@
1468
1469 // Delete all nodes in that mesh
1470 var newnodes = [];
1447 - for (var i in nodes) { if (nodes[i].meshid != message.event.meshid) { newnodes.push(nodes[i]); } }
1471 + if (nodes != null) { for (var i in nodes) { if (nodes[i].meshid != message.event.meshid) { newnodes.push(nodes[i]); } } }
1472 nodes = newnodes;
1473 masterUpdate(4);
1474
@@ -1464,6 +1488,7 @@
1488 node.state = 0;
1489 if (!node.icon) node.icon = 1;
1490 node.ident = ++nodeShortIdent;
1491 + if (nodes == null) { }
1492 nodes.push(node);
1493
1494 // Web page update
@@ -1753,6 +1778,7 @@
1778 var deviceHeaders = {};
1779 var oldviewmode = 0;
1780 function updateDevices() {
1781 + if (nodes == null) { return; }
1782 var r = '', c = 0, current = null, count = 0, displayedMeshes = {}, view = Q('viewselect').value, groups = {}, groupCount = {};
1783 QV('xdevices', view < 4);
1784 QV('xdevicesmap', view == 4);
@@ -1842,19 +1868,19 @@
1868 var nodestate = NodeStateStr(nodes[i]);
1869 if ((!nodes[i].conn) || (nodes[i].conn == 0)) { icon += ' gray'; }
1870 if (view == 1) {
1845 - r += '<div id=devs onmouseover=devMouseHover(this,1) onmouseout=devMouseHover(this,0) style=display:inline-block;width:' + deviceBoxWidth + 'px;height:50px;padding-top:1px;padding-bottom:1px><div style=width:22px;height:50%;float:left;padding-top:12px><input class="' + nodes[i].meshid + ' DeviceCheckbox" onclick=p1updateInfo() value=devid_' + nodes[i]._id + ' type=checkbox></div><div style=height:100%;cursor:pointer onclick=gotoDevice(\'' + nodes[i]._id + '\')><div class="i' + icon + '" style=width:50px;float:left></div><div style=height:100%><div class=g1></div><div class=e2><div class=e1 style=width:' + (deviceBoxWidth - 100) + 'px title="' + title + '">' + name + '</div><div>' + nodestate + '</div></div><div class=g2></div></div></div></div>';
1871 + r += '<div id=devs onmouseover=devMouseHover(this,1) onmouseout=devMouseHover(this,0) style=display:inline-block;width:' + deviceBoxWidth + 'px;height:50px;padding-top:1px;padding-bottom:1px><div style=width:22px;height:50%;float:left;padding-top:12px><input class="' + nodes[i].meshid + ' DeviceCheckbox" onclick=p1updateInfo() value=devid_' + nodes[i]._id + ' type=checkbox></div><div style=height:100%;cursor:pointer onclick=gotoDevice(\'' + nodes[i]._id + '\',null,null,event)><div class="i' + icon + '" style=width:50px;float:left></div><div style=height:100%><div class=g1></div><div class=e2><div class=e1 style=width:' + (deviceBoxWidth - 100) + 'px title="' + title + '">' + name + '</div><div>' + nodestate + '</div></div><div class=g2></div></div></div></div>';
1872 } else if (view == 2) {
1873 r += '<tr><td><div id=devs class=bar18 onmouseover=devMouseHover(this,1) onmouseout=devMouseHover(this,0) style=height:18px;width:100%;font-size:medium>';
1874 r += '<div style=width:22px;float:left;background-color:white><input class="' + nodes[i].meshid + ' DeviceCheckbox" onclick=p1updateInfo() value=devid_' + nodes[i]._id + ' type=checkbox></div>';
1849 - r += '<div style=float:left;height:18px;width:18px;background-color:white onclick=gotoDevice(\'' + nodes[i]._id + '\')><div class=j' + icon + ' style=width:16px;margin-top:1px;margin-left:2px;height:16px></div></div>';
1875 + r += '<div style=float:left;height:18px;width:18px;background-color:white onclick=gotoDevice(\'' + nodes[i]._id + '\',null,null,event)><div class=j' + icon + ' style=width:16px;margin-top:1px;margin-left:2px;height:16px></div></div>';
1876 r += '<div class=g1 style=height:18px;float:left></div><div class=g2 style=height:18px;float:right></div>';
1851 - r += '<div style=cursor:pointer;font-size:14px title="' + title + '" onclick=gotoDevice(\'' + nodes[i]._id + '\')><span style=float:right>' + nodestate + '</span><span style=width:300px>' + name + '</span></div></div></td></tr>';
1877 + r += '<div style=cursor:pointer;font-size:14px title="' + title + '" onclick=gotoDevice(\'' + nodes[i]._id + '\',null,null,event)><span style=float:right>' + nodestate + '</span><span style=width:300px>' + name + '</span></div></div></td></tr>';
1878 } else if ((view == 3) && (nodes[i].conn & 1) && (((meshrights & 8) || (meshrights & 256)) != 0) && ((nodes[i].agent.caps & 1) != 0)) { // Check if we have rights and agent is capable of KVM.
1879 if ((multiDesktopFilter.length == 0) || (multiDesktopFilter.indexOf('devid_' + nodes[i]._id) >= 0)) {
1854 - r += '<div id=devs style=display:inline-block;margin:1px;background-color:lightgray;border-radius:5px;position:relative><div style=padding:3px;cursor:pointer onclick=gotoDevice(\'' + nodes[i]._id + '\',11)>';
1880 + r += '<div id=devs style=display:inline-block;margin:1px;background-color:lightgray;border-radius:5px;position:relative><div style=padding:3px;cursor:pointer onclick=gotoDevice(\'' + nodes[i]._id + '\',11,null,event)>';
1881 //r += '<input class="' + nodes[i].meshid + ' DeviceCheckbox" onclick=p1updateInfo() value=devid_' + nodes[i]._id + ' type=checkbox style=float:left>';
1882 r += '<div class="j' + icon + '" style=width:16px;float:left></div>&nbsp;' + name + '</div>';
1857 - r += '<span onclick=gotoDevice(\'' + nodes[i]._id + '\')></span><div id=xkvmid_' + nodes[i]._id.split('/')[2] + '><div id=skvmid_' + nodes[i]._id.split('/')[2] + ' style="position:absolute;color:white;left:5px;top:27px;text-shadow:0px 0px 5px #000;z-index:1000;cursor:default" onclick=toggleKvmDevice(\'' + nodes[i]._id + '\')>Disconnected</div></div>';
1883 + r += '<span onclick=gotoDevice(\'' + nodes[i]._id + '\',null,null,event)></span><div id=xkvmid_' + nodes[i]._id.split('/')[2] + '><div id=skvmid_' + nodes[i]._id.split('/')[2] + ' style="position:absolute;color:white;left:5px;top:27px;text-shadow:0px 0px 5px #000;z-index:1000;cursor:default" onclick=toggleKvmDevice(\'' + nodes[i]._id + '\')>Disconnected</div></div>';
1884 r += '</div>';
1885 kvmDivs.push(nodes[i]._id);
1886 }
@@ -2479,7 +2505,7 @@
2505
2506 // Get the node and set the menu options
2507 var nodeid = contextelement.children[1].attributes.onclick.value;
2482 - var node = getNodeFromId(nodeid.substring(12, nodeid.length - 2));
2508 + var node = getNodeFromId(nodeid.substring(12, nodeid.length - 18));
2509 var mesh = meshes[node.meshid];
2510 var meshlinks = mesh.links['user/' + domain + '/' + userinfo.name.toLowerCase()];
2511 var meshrights = meshlinks.rights;
@@ -2493,16 +2519,20 @@
2519 return haltEvent(event);
2520 }
2521
2496 - function cmaction(action) {
2522 + function cmaction(action,event) {
2523 var nodeid = contextelement.children[1].attributes.onclick.value;
2498 - nodeid = nodeid.substring(12, nodeid.length - 2);
2499 - if (action == 1) gotoDevice(nodeid, 10); // General
2500 - if (action == 2) gotoDevice(nodeid, 12); // Desktop
2501 - if (action == 3) gotoDevice(nodeid, 11); // Terminal
2502 - if (action == 4) gotoDevice(nodeid, 13); // Files
2503 - if (action == 5) gotoDevice(nodeid, 16); // Events
2504 - if (action == 6) gotoDevice(nodeid, 15); // Console
2524 + nodeid = nodeid.substring(12, nodeid.length - 18);
2525 if (action == 7) { Q('viewselect').value = 3; Q('viewselect').onchange(); Q('autoConnectDesktopCheckbox').checked = true; Q('autoConnectDesktopCheckbox').onclick(); } // Multi-Desktop
2526 + if ((action > 0) && (action < 7)) {
2527 + var panel = [0, 10, 12, 11, 13, 16, 15][action]; // (invalid), General, Desktop, Terminal, Files, Events, Console
2528 + if (event && (event.shiftKey == true)) {
2529 + // Open the device in a different tab
2530 + window.open(window.location.origin + '?node=' + nodeid.split('/')[2] + '&viewmode=' + panel + '&hide=16', 'meshcentral:' + nodeid);
2531 + } else {
2532 + // Go to the right panel
2533 + gotoDevice(nodeid, panel);
2534 + }
2535 + }
2536 }
2537
2538 function cmmeshaction(action) {
@@ -3145,7 +3175,13 @@
3175 var powerTimelineUpdate = null;
3176 var powerTimeline = null;
3177 function getCurrentNode() { return currentNode; };
3148 - function gotoDevice(nodeid, panel, refresh) {
3178 + function gotoDevice(nodeid, panel, refresh, event) {
3179 + if (event && (event.shiftKey == true)) {
3180 + // Open the device in a different tab
3181 + window.open(window.location.origin + '?node=' + nodeid.split('/')[2] + '&viewmode=10&hide=16', 'meshcentral:' + nodeid);
3182 + return;
3183 + }
3184 +
3185 //disconnectAllKvmFunction();
3186 var node = getNodeFromId(nodeid);
3187 var mesh = meshes[node.meshid];
@@ -3355,6 +3391,9 @@
3391
3392 // Ask for device events
3393 refreshDeviceEvents();
3394 +
3395 + // Update the web page title
3396 + if ((currentNode) && (xxcurrentView >= 10) && (xxcurrentView < 20)) { document.title = 'MeshCentral - ' + currentNode.name; } else { document.title = 'MeshCentral'; }
3397 }
3398 setupDesktop(); // Always refresh the desktop, even if we are on the same device, we need to do some canvas switching.
3399 if (!panel) panel = 10;
@@ -6605,6 +6644,9 @@
6644 }
6645
6646 if (x == 1) masterUpdate(4);
6647 +
6648 + // Update the web page title
6649 + if ((currentNode) && (x >= 10) && (x < 20)) { document.title = 'MeshCentral - ' + currentNode.name; } else { document.title = 'MeshCentral'; }
6650 }
6651
6652 // Generic methods