meshcentral
Version:
Web based remote computer management server
1 lines • 5.54 kB
JavaScript
var not_supported,promise=require("promise");function qfe(){for(var e=require("child_process").execFile(process.env.windir+"\\System32\\wbem\\wmic.exe",["wmic","qfe","list","full","/FORMAT:CSV"]),t=(e.stdout.str="",e.stdout.on("data",function(e){this.str+=e.toString()}),e.stderr.str="",e.stderr.on("data",function(e){this.str+=e.toString()}),e.waitExit(),e.stdout.str.trim().split("\r\n")),r=t[0].split(","),i=[],s=1;s<t.length;++s){for(var o={},n=t[s].split(","),a=0;a<r.length;++a)n[a]&&(o[r[a]]=n[a]);i.push(o)}return i}function av(){var e=require("child_process").execFile(process.env.windir+"\\System32\\WindowsPowerShell\\v1.0\\powershell.exe",["powershell","-noprofile","-nologo","-command","-"],{});if(null==e)return[];if(e.descriptorMetadata="process-manager",e.stdout.str="",e.stdout.on("data",function(e){this.str+=e.toString()}),e.stderr.str="",e.stderr.on("data",function(e){this.str+=e.toString()}),e.stdin.write('[reflection.Assembly]::LoadWithPartialName("system.core")\r\n'),e.stdin.write('Get-WmiObject -Namespace "root/SecurityCenter2" -Class AntiVirusProduct | '),e.stdin.write("ForEach-Object -Process { "),e.stdin.write("$Bytes = [System.Text.Encoding]::UTF8.GetBytes($_.displayName); "),e.stdin.write("$EncodedText =[Convert]::ToBase64String($Bytes); "),e.stdin.write('Write-Host ("{0},{1}" -f $_.productState,$EncodedText); }\r\n'),e.stdin.write("exit\r\n"),e.waitExit(),""==e.stdout.str)return[];var t=e.stdout.str.trim().split("\r\n"),r=[];for(i=0;i<t.length;++i){var s,o=t[i].split(",");2==o.length&&((s={}).product=Buffer.from(o[1],"base64").toString(),s.updated=0==(16&parseInt(o[0])),s.enabled=4096==(4096&parseInt(o[0])),r.push(s))}return r}function defrag(e){var t=new promise(function(e,t){this._res=e,this._rej=t});switch(require("os").arch()){case"x64":if(4==require("_GenericMarshal").PointerSize)return t._rej("Cannot defrag volume on 64 bit Windows from 32 bit application"),t;process.env.windir;break;case"ia32":process.env.windir;break;default:return t._rej(require("os").arch()+" not supported"),t}return t.child=require("child_process").execFile(process.env.windir+"\\System32\\defrag.exe",["defrag",e.volume+" /A"]),(t.child.promise=t).child.promise.options=e,t.child.stdout.str="",t.child.stdout.on("data",function(e){this.str+=e.toString()}),t.child.stderr.str="",t.child.stderr.on("data",function(e){this.str+=e.toString()}),t.child.on("exit",function(e){var t,r=this.stdout.str.trim().split("\r\n"),i={volume:this.promise.options.volume};for(t in r){var s=r[t].split("=");if(2==s.length)switch(s[0].trim().toLowerCase()){case"volume size":i.size=s[1];break;case"free space":i.free=s[1];break;case"total fragmented space":i.fragmented=s[1];break;case"largest free space size":i.largestFragment=s[1]}}this.promise._res(i)}),t}function regQuery(e,t,r){try{return require("win-registry").QueryKey(e,t,r)}catch(e){return null}}function pendingReboot(){var e,t=null,r=require("win-registry").HKEY;return null!=regQuery(r.LocalMachine,"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Component Based Servicing","RebootPending")?t="Component Based Servicing":regQuery(r.LocalMachine,"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\WindowsUpdate","RebootRequired")?t="Windows Update":null!=(e=regQuery(r.LocalMachine,"SYSTEM\\CurrentControlSet\\Control\\Session Manager","PendingFileRenameOperations"))&&0!=e&&""!=e?t="File Rename":regQuery(r.LocalMachine,"SYSTEM\\CurrentControlSet\\Control\\ComputerName\\ActiveComputerName","ComputerName")!=regQuery(r.LocalMachine,"SYSTEM\\CurrentControlSet\\Control\\ComputerName\\ComputerName","ComputerName")&&(t="System Rename"),t}function installedApps(){var e=new(require("promise"))(function(e,t){this._resolve=e,this._reject=t});return e.child=require("child_process").execFile(process.execPath,[process.execPath.split("\\").pop().split(".exe")[0],"-exec \" var reg = require('win-registry'); var result = []; var val, tmp; var items = reg.QueryKey(reg.HKEY.LocalMachine, 'SOFTWARE\\\\Microsoft\\\\Windows\\\\CurrentVersion\\\\Uninstall'); for (var key in items.subkeys) { val = {}; try { val.name = reg.QueryKey(reg.HKEY.LocalMachine, 'SOFTWARE\\\\Microsoft\\\\Windows\\\\CurrentVersion\\\\Uninstall\\\\' + items.subkeys[key], 'DisplayName'); } catch(e) { continue; } try { val.version = reg.QueryKey(reg.HKEY.LocalMachine, 'SOFTWARE\\\\Microsoft\\\\Windows\\\\CurrentVersion\\\\Uninstall\\\\' + items.subkeys[key], 'DisplayVersion'); if (val.version == '') { delete val.version; } } catch(e) { } try { val.location = reg.QueryKey(reg.HKEY.LocalMachine, 'SOFTWARE\\\\Microsoft\\\\Windows\\\\CurrentVersion\\\\Uninstall\\\\' + items.subkeys[key], 'InstallLocation'); if (val.location == '') { delete val.location; } } catch(e) { } result.push(val); } console.log(JSON.stringify(result,'', 1));process.exit();\""]),(e.child.promise=e).child.stdout.str="",e.child.stdout.on("data",function(e){this.str+=e.toString()}),e.child.on("exit",function(e){this.promise._resolve(JSON.parse(this.stdout.str.trim()))}),e}"win32"==process.platform?module.exports={qfe:qfe,av:av,defrag:defrag,pendingReboot:pendingReboot,installedApps:installedApps}:(not_supported=function(){throw process.platform+" not supported"},module.exports={qfe:not_supported,av:not_supported,defrag:not_supported,pendingReboot:not_supported,installedApps:not_supported})