Function do_command ($ commandName, $ args ){
$ Buffer = "";
If (false = ($ command = find_command ($ commandName) return false;
If ($ fp = @ popen ("$ command $ args", 'R ')){
While (! @ Feof ($ fp )){
$ Buffer. = @ fgets ($ fp, 4096 );
}
Return trim ($ buffer );
}
Return false;
}
// Windows system detection
Function sys_windows (){
$ ObjLocator = new COM ("WbemScripting. SWbemLocator ");
$ Wmi = $ objLocator-> ConnectServer ();
$ Prop = $ wmi-> get ("Win32_PnPEntity ");
// CPU
$ Cpuinfo = GetWMI ($ wmi, "Win32_Processor", array ("Name", "L2CacheSize", "NumberOfCores "));
$ Res ['cpu '] ['num'] = $ cpuinfo [0] ['numberofcores'];
If (null = $ res ['cpu '] ['num']) {
$ Res ['cpu '] ['num'] = 1;
}
For ($ I = 0; $ I <$ res ['cpu '] ['num']; $ I ++ ){
$ Res ['cpu '] ['model']. = $ cpuinfo [0] ['name']. "<br> ";
$ Res ['cpu '] ['cache']. = $ cpuinfo [0] ['l2cachesize']. "<br> ";
}
// SYSINFO
$ Sysinfo = GetWMI ($ wmi, "Win32_OperatingSystem", array ('lastbootuptime', 'totalvisiblememorysize', 'freephysicalmemory ', 'caption', 'sdversion', 'serialnumber ', 'installdate '));
$ Res ['win _ n'] = $ sysinfo [0] ['caption ']. "". $ sysinfo [0] ['sdversion']. "<B> serial number </B>: {$ sysinfo [0] ['serialnumber']} on ". date ('y, m, D, H: I: s', strtotime (substr ($ sysinfo [0] ['installdate ))). "installation ";
// UPTIME
$ Res ['uptime'] = $ sysinfo [0] ['lastbootuptime'];
$ Sys_ticks = 3600*8 + time ()-strtotime (substr ($ res ['uptime'], 0, 14 ));
$ Min = $ sys_ticks/60;
$ Hours = $ min/60;
$ Days = floor ($ hours/24 );
$ Hours = floor ($ hours-($ days * 24 ));
$ Min = floor ($ min-($ days * 60*24)-($ hours * 60 ));
If ($ days! = 0) $ res ['uptime'] = $ days. "day ";
If ($ hours! = 0) $ res ['uptime']. = $ hours. "Hour ";
$ Res ['uptime']. = $ min. "Minute ";
// MEMORY
$ Res ['memtotal'] = $ sysinfo [0] ['totalvisiblememorysize'];
$ Res ['memfree'] = $ sysinfo [0] ['freephysicalmemory '];
$ Res ['memused'] = $ res ['memtotal']-$ res ['memfree'];
$ Res ['mempercent '] = round ($ res ['memused']/$ res ['memtotal );
$ Swapinfo = GetWMI ($ wmi, "Win32_PageFileUsage", array ('allocatedbasesize', 'currentusage '));
// Obtain the TODO swp Area
$ Res ['swaptotal'] = $ swapinfo [0] [AllocatedBaseSize];
$ Res ['swapused'] = $ swapinfo [0] [CurrentUsage];
$ Res ['swapfree'] = $ res ['swaptotal']-$ res ['swapused'];
$ Res ['swappercent '] = (floatval ($ res ['swaptotal'])! = 0 )? Round ($ res ['swapused']/$ res ['swaptotal'] * 100,2): 0;
// LoadPercentage
$ Loadinfo = GetWMI ($ wmi, "Win32_Processor", array ("LoadPercentage "));
$ Res ['loadavg'] = $ loadinfo [0] ['loadpercentage'];
Return $ res;
}
Function GetWMI ($ wmi, $ strClass, $ strValue = array ()){
$ ArrData = array ();
$ ObjWEBM = $ wmi-> Get ($ strClass );
$ ArrProp = $ objWEBM-> Properties _;
$ ArrWEBMCol = $ objWEBM-> Instances _();
Foreach ($ arrWEBMCol as $ objItem ){
@ Reset ($ arrProp );
$ ArrInstance = array ();
Foreach ($ arrProp as $ propItem ){
Eval ("$ value = $ objItem->". $ propItem-> Name .";");
If (empty ($ strValue )){
$ ArrInstance [$ propItem-> Name] = trim ($ value );
} Else {
If (in_array ($ propItem-> Name, $ strValue )){
$ ArrInstance [$ propItem-> Name] = trim ($ value );
}
}
}
$ ArrData [] = $ arrInstance;
}
Return $ arrData;
}