1
0
Fork 0
mirror of https://github.com/Ylianst/MeshCentral.git synced 2025-02-13 03:21:50 +00:00
MeshCentral/agents/modules_meshcore_min/monitor-info.min.js

1 line
7.4 KiB
JavaScript
Raw Normal View History

var promise=require("promise");var PPosition=4;var PSize=8;var _NET_WM_STATE_REMOVE=0;var _NET_WM_STATE_ADD=1;var _NET_WM_STATE_TOGGLE=2;var SubstructureRedirectMask=(1<<20);var SubstructureNotifyMask=(1<<19);function getLibInfo(f){if(process.platform!="linux"){throw ("Only supported on linux")}var a=require("child_process").execFile("/bin/sh",["sh"]);a.stdout.str="";a.stdout.on("data",function(i){this.str+=i.toString()});a.stdin.write("ldconfig -p | grep '"+f+".so.'\nexit\n");a.waitExit();var l=[];var g=a.stdout.str.split("\n");for(var b in g){if(g[b]){var c=g[b].split("=>");var k=c[1].trim();var e=c[0].trim().split(" ");var d=e[0];var h=e[1].substring(1,e[1].length-1).split(",");if(d.startsWith(f+".so.")){l.push({lib:d,path:k,info:h})}}}return(l)}function monitorinfo(){this._ObjectID="monitor-info";this._gm=require("_GenericMarshal");if(process.platform=="win32"){this._user32=this._gm.CreateNativeProxy("user32.dll");this._user32.CreateMethod("EnumDisplayMonitors");this._kernel32=this._gm.CreateNativeProxy("kernel32.dll");this._kernel32.CreateMethod("GetLastError");this.getInfo=function h(){var e=this;return(new promise(function(v,u){this._monitorinfo={resolver:v,rejector:u,self:e,callback:e._gm.GetGenericGlobalCallback(4)};this._monitorinfo.callback.info=this._monitorinfo;this._monitorinfo.dwData=e._gm.ObjectToPtr(this._monitorinfo);this._monitorinfo.callback.results=[];this._monitorinfo.callback.on("GlobalCallback",function i(x,w,y,A){if(this.ObjectToPtr_Verify(this.info,A)){var z=y.Deref(0,16).toBuffer();this.results.push({left:z.readInt32LE(0),top:z.readInt32LE(4),right:z.readInt32LE(8),bottom:z.readInt32LE(12)});var y=this.info.self._gm.CreateInteger();y.Val=1;return(y)}});if(e._user32.EnumDisplayMonitors(0,0,this._monitorinfo.callback,this._monitorinfo.dwData).Val==0){u("LastError="+e._kernel32.GetLastError().Val);return}else{v(this._monitorinfo.callback.results)}}))}}else{if(process.platform=="linux"){var a=false;try{if(require("user-sessions").isRoot()){a=true}}catch(b){}if(a){var r=getLibInfo("libX11");var t=getLibInfo("libXtst");var s=getLibInfo("libXext");var n;for(n in r){try{this._gm.CreateNativeProxy(r[n].path);Object.defineProperty(this,"Location_X11LIB",{value:r[n].path});break}catch(c){}}for(n in t){try{this._gm.CreateNativeProxy(t[n].path);Object.defineProperty(this,"Location_X11TST",{value:t[n].path});break}catch(c){}}for(n in s){try{this._gm.CreateNativeProxy(s[n].path);Object.defineProperty(this,"Location_X11EXT",{value:s[n].path});break}catch(c){}}}else{var g=require("fs");var d=g.readdirSync("/usr/lib");var f;for(var l in d){try{if(d[l].split("libX11.so.").length>1&&d[l].split(".").length==3){Object.defineProperty(this,"Location_X11LIB",{value:"/usr/lib/"+d[l]})}if(d[l].split("libXtst.so.").length>1&&d[l].split(".").length==3){Object.defineProperty(this,"Location_X11TST",{value:"/usr/lib/"+d[l]})}if(d[l].split("libXext.so.").length>1&&d[l].split(".").length==3){Object.defineProperty(this,"Location_X11EXT",{value:"/usr/lib/"+d[l]})}if(d[l].split("-linux-").length>1){f=g.readdirSync("/usr/lib/"+d[l]);for(j in f){if(f[j].split("libX11.so.").length>1&&f[j].split(".").length==3){Object.defineProperty(this,"Location_X11LIB",{value:"/usr/lib/"+d[l]+"/"+f[j]})}if(f[j].split("libXtst.so.").length>1&&f[j].split(".").length==3){Object.defineProperty(this,"Location_X11TST",{value:"/usr/lib/"+d[l]+"/"+f[j]})}if(f[j].split("libXext.so.").length>1&&f[j].split(".").length==3){Object.defineProperty(this,"Location_X11EXT",{value:"/usr/lib/"+d[l]+"/"+f[j]})}}}}catch(c){}}}Object.defineProperty(this,"kvm_x11_support",{value:(this.Location_X11LIB&&this.Location_X11TST&&this.Location_X11EXT)?true:false});if(this.Location_X11LIB){this._X11=this._gm.CreateNativeProxy(this.Location_X11LIB);this._X11.CreateMethod("XChangeProperty");this._X11.CreateMethod("XCloseDisplay");this._X11.CreateMethod("XConnectionNumber");this._X11.CreateMethod("XConvertSelection");this._X11.CreateMethod("XCreateGC");this._X11.CreateMethod("XCreateWindow");this._X11.CreateMethod("XCreateSimpleWindow");this._X11.CreateMethod("XDefaultColormap");th