function for getting a list of values in the specified context
optionally filter this list, based on the list from third parameter
public static getWMI ( $wmi, string $strClass, array $strValue = [] ) : array | ||
$wmi | holds the COM object that we pull the WMI data from | |
$strClass | string | name of the class where the values are stored |
$strValue | array | filter out only needed values, if not set all values of the class are returned |
Résultat | array | content of the class stored in an array |
/** * fill the private content var */ public function __construct() { parent::__construct(); if (PSI_OS == 'WINNT') { $_wmi = null; // don't set this params for local connection, it will not work $strHostname = ''; $strUser = ''; $strPassword = ''; try { // initialize the wmi object $objLocator = new COM('WbemScripting.SWbemLocator'); if ($strHostname == "") { $_wmi = $objLocator->ConnectServer($strHostname, 'root\\WMI'); } else { $_wmi = $objLocator->ConnectServer($strHostname, 'root\\WMI', $strHostname . '\\' . $strUser, $strPassword); } } catch (Exception $e) { $this->error->addError("WMI connect error", "PhpSysInfo can not connect to the WMI interface for ThermalZone data."); } if ($_wmi) { $this->_buf = CommonFunctions::getWMI($_wmi, 'MSAcpi_ThermalZoneTemperature', array('InstanceName', 'CriticalTripPoint', 'CurrentTemperature')); } } }
/** * read the data into an internal array and also call the parent constructor * * @param String $enc target encoding */ public function __construct($enc) { parent::__construct(__CLASS__, $enc); switch (strtolower(PSI_PLUGIN_PSSTATUS_ACCESS)) { case 'command': if (PSI_OS == 'WINNT') { try { $objLocator = new COM('WbemScripting.SWbemLocator'); $wmi = $objLocator->ConnectServer('', 'root\\CIMv2'); $process_wmi = CommonFunctions::getWMI($wmi, 'Win32_Process', array('Caption', 'ProcessId')); foreach ($process_wmi as $process) { $this->_filecontent[] = array(strtolower(trim($process['Caption'])), trim($process['ProcessId'])); } } catch (Exception $e) { } } else { if (defined('PSI_PLUGIN_PSSTATUS_PROCESSES') && is_string(PSI_PLUGIN_PSSTATUS_PROCESSES)) { if (preg_match(ARRAY_EXP, PSI_PLUGIN_PSSTATUS_PROCESSES)) { $processes = eval(PSI_PLUGIN_PSSTATUS_PROCESSES); } else { $processes = array(PSI_PLUGIN_PSSTATUS_PROCESSES); } if (defined('PSI_PLUGIN_PSSTATUS_USE_REGEX') && PSI_PLUGIN_PSSTATUS_USE_REGEX === true) { foreach ($processes as $process) { CommonFunctions::executeProgram("pgrep", "-n -x " . $process, $buffer, PSI_DEBUG); if (strlen($buffer) > 0) { $this->_filecontent[] = array($process, $buffer); } } } else { foreach ($processes as $process) { CommonFunctions::executeProgram("pidof", "-s " . $process, $buffer, PSI_DEBUG); if (strlen($buffer) > 0) { $this->_filecontent[] = array($process, $buffer); } } } } } break; case 'data': CommonFunctions::rfts(APP_ROOT . "/data/psstatus.txt", $buffer); $processes = preg_split("/\n/", $buffer, -1, PREG_SPLIT_NO_EMPTY); foreach ($processes as $process) { $ps = preg_split("/[\\s]?\\|[\\s]?/", $process, -1, PREG_SPLIT_NO_EMPTY); if (count($ps) == 2) { $this->_filecontent[] = array(trim($ps[0]), trim($ps[1])); } } break; default: $this->global_error->addError("switch(PSI_PLUGIN_PSSTATUS_ACCESS)", "Bad psstatus configuration in phpsysinfo.ini"); break; } }
/** * fill the private content var */ public function __construct() { parent::__construct(); $_wmi = null; try { // initialize the wmi object $objLocator = new COM('WbemScripting.SWbemLocator'); $_wmi = $objLocator->ConnectServer('', 'root\\OpenHardwareMonitor'); } catch (Exception $e) { $this->error->addError("WMI connect error", "PhpSysInfo can not connect to the WMI interface for OpenHardwareMonitor data."); } if ($_wmi) { $this->_buf = CommonFunctions::getWMI($_wmi, 'Sensor', array('Parent', 'Name', 'SensorType', 'Value')); } }
/** * fill the private content var */ public function __construct() { parent::__construct(); if (PSI_OS == 'WINNT') { $_wmi = null; try { // initialize the wmi object $objLocator = new COM('WbemScripting.SWbemLocator'); $_wmi = $objLocator->ConnectServer('', 'root\\WMI'); } catch (Exception $e) { $this->error->addError("WMI connect error", "PhpSysInfo can not connect to the WMI interface for ThermalZone data."); } if ($_wmi) { $this->_buf = CommonFunctions::getWMI($_wmi, 'MSAcpi_ThermalZoneTemperature', array('InstanceName', 'CriticalTripPoint', 'CurrentTemperature')); } } }
/** * fill the private content var */ public function __construct() { parent::__construct(); // don't set this params for local connection, it will not work $strHostname = ''; $strUser = ''; $strPassword = ''; try { // initialize the wmi object $objLocator = new COM('WbemScripting.SWbemLocator'); if ($strHostname == "") { $this->_wmi = $objLocator->ConnectServer($strHostname, 'root\\OpenHardwareMonitor'); } else { $this->_wmi = $objLocator->ConnectServer($strHostname, 'root\\OpenHardwareMonitor', $strHostname . '\\' . $strUser, $strPassword); } } catch (Exception $e) { $this->error->addError("WMI connect error", "PhpSysInfo can not connect to the WMI interface for security reasons.\nCheck an authentication mechanism for the directory where phpSysInfo is installed."); } $this->_buf = CommonFunctions::getWMI($this->_wmi, 'Sensor', array('Parent', 'Name', 'SensorType', 'Value')); }
/** * fill the private content var */ public function __construct() { parent::__construct(); $_wmi = null; // don't set this params for local connection, it will not work $strHostname = ''; $strUser = ''; $strPassword = ''; try { // initialize the wmi object $objLocator = new COM('WbemScripting.SWbemLocator'); if ($strHostname == "") { $_wmi = $objLocator->ConnectServer($strHostname, 'root\\OpenHardwareMonitor'); } else { $_wmi = $objLocator->ConnectServer($strHostname, 'root\\OpenHardwareMonitor', $strHostname . '\\' . $strUser, $strPassword); } } catch (Exception $e) { $this->error->addError("WMI connect error", "PhpSysInfo can not connect to the WMI interface for OpenHardwareMonitor data."); } if ($_wmi) { $this->_buf = CommonFunctions::getWMI($_wmi, 'Sensor', array('Parent', 'Name', 'SensorType', 'Value')); } }
/** * filesystem information * * @return void */ private function _filesystems() { $typearray = array('Unknown', 'No Root Directory', 'Removable Disk', 'Local Disk', 'Network Drive', 'Compact Disc', 'RAM Disk'); $floppyarray = array('Unknown', '5 1/4 in.', '3 1/2 in.', '3 1/2 in.', '3 1/2 in.', '3 1/2 in.', '5 1/4 in.', '5 1/4 in.', '5 1/4 in.', '5 1/4 in.', '5 1/4 in.', 'Other', 'HD', '3 1/2 in.', '3 1/2 in.', '5 1/4 in.', '5 1/4 in.', '3 1/2 in.', '3 1/2 in.', '5 1/4 in.', '3 1/2 in.', '3 1/2 in.', '8 in.'); $buffer = CommonFunctions::getWMI($this->_wmi, 'Win32_LogicalDisk', array('Name', 'Size', 'FreeSpace', 'FileSystem', 'DriveType', 'MediaType')); foreach ($buffer as $filesystem) { $dev = new DiskDevice(); $dev->setMountPoint($filesystem['Name']); $dev->setFsType($filesystem['FileSystem']); if ($filesystem['Size'] > 0) { $dev->setTotal($filesystem['Size']); $dev->setFree($filesystem['FreeSpace']); $dev->setUsed($filesystem['Size'] - $filesystem['FreeSpace']); } if ($filesystem['MediaType'] != "" && $filesystem['DriveType'] == 2) { $dev->setName($typearray[$filesystem['DriveType']] . " (" . $floppyarray[$filesystem['MediaType']] . ")"); } else { $dev->setName($typearray[$filesystem['DriveType']]); } $this->sys->setDiskDevices($dev); } if (!$buffer && $this->sys->getDistribution() == "ReactOS") { // test for command 'free' on current disk if (CommonFunctions::executeProgram("cmd", "/c free 2>nul", $out_value, true)) { for ($letter = 'A'; $letter != 'AA'; $letter++) { if (CommonFunctions::executeProgram("cmd", "/c free " . $letter . ": 2>nul", $out_value, false)) { if (preg_match('/\\n\\s*([\\d\\.\\,]+).*\\n\\s*([\\d\\.\\,]+).*\\n\\s*([\\d\\.\\,]+).*$/', $out_value, $out_dig)) { $size = preg_replace('/(\\.)|(\\,)/', '', $out_dig[1]); $used = preg_replace('/(\\.)|(\\,)/', '', $out_dig[2]); $free = preg_replace('/(\\.)|(\\,)/', '', $out_dig[3]); if ($used + $free == $size) { $dev = new DiskDevice(); $dev->setMountPoint($letter . ":"); $dev->setFsType('Unknown'); $dev->setTotal($size); $dev->setFree($free); $dev->setUsed($used); $this->sys->setDiskDevices($dev); } } } } } } }
/** * read the data into an internal array and also call the parent constructor * * @param String $enc encoding */ public function __construct($enc) { parent::__construct(__CLASS__, $enc); switch (strtolower(PSI_PLUGIN_BAT_ACCESS)) { case 'command': if (PSI_OS == 'WINNT') { $_cim = null; //root\CIMv2 $_wmi = null; //root\WMI // don't set this params for local connection, it will not work $strHostname = ''; $strUser = ''; $strPassword = ''; try { // initialize the wmi object $objLocatorCIM = new COM('WbemScripting.SWbemLocator'); if ($strHostname == "") { $_cim = $objLocatorCIM->ConnectServer(); } else { $_cim = $objLocatorCIM->ConnectServer($strHostname, 'root\\CIMv2', $strHostname . '\\' . $strUser, $strPassword); } // initialize the wmi object $objLocatorWMI = new COM('WbemScripting.SWbemLocator'); if ($strHostname == "") { $_wmi = $objLocatorWMI->ConnectServer($strHostname, 'root\\WMI'); } else { $_wmi = $objLocatorWMI->ConnectServer($strHostname, 'root\\WMI', $strHostname . '\\' . $strUser, $strPassword); } } catch (Exception $e) { $this->error->addError("WMI connect error", "PhpSysInfo can not connect to the WMI interface for security reasons.\nCheck an authentication mechanism for the directory where phpSysInfo is installed."); } $buffer_info = ''; $buffer_state = ''; $bufferWB = CommonFunctions::getWMI($_cim, 'Win32_Battery', array('EstimatedChargeRemaining', 'DesignVoltage', 'BatteryStatus', 'Chemistry')); if (sizeof($bufferWB) > 0) { $capacity = ''; if (isset($bufferWB[0]['EstimatedChargeRemaining'])) { $capacity = $bufferWB[0]['EstimatedChargeRemaining']; } if (isset($bufferWB[0]['BatteryStatus'])) { switch ($bufferWB[0]['BatteryStatus']) { case 1: $batstat = 'Discharging'; break; case 2: $batstat = 'AC connected'; break; case 3: $batstat = 'Fully Charged'; break; case 4: $batstat = 'Low'; break; case 5: $batstat = 'Critical'; break; case 6: $batstat = 'Charging'; break; case 7: $batstat = 'Charging and High'; break; case 8: $batstat = 'Charging and Low'; break; case 9: $batstat = 'Charging and Critical'; break; case 10: $batstat = 'Undefined'; break; case 11: $batstat = 'Partially Charged'; break; default: $batstat = ''; } if ($batstat != '') { $buffer_state .= 'POWER_SUPPLY_STATUS=' . $batstat . "\n"; } } $techn = ''; if (isset($bufferWB[0]['Chemistry'])) { switch ($bufferWB[0]['Chemistry']) { case 1: $techn = 'Other'; break; case 2: $techn = 'Unknown'; break; case 3: $techn = 'PbAc'; break; case 4: $techn = 'NiCd'; break; case 5: $techn = 'NiMH'; break; case 6: $techn = 'Li-ion'; break; case 7: $techn = 'Zinc-air'; break; case 8: $techn = 'Li-poly'; break; } } $bufferWPB = CommonFunctions::getWMI($_cim, 'Win32_PortableBattery', array('DesignVoltage', 'Chemistry', 'DesignCapacity', 'FullChargeCapacity')); if (isset($bufferWPB[0]['DesignVoltage'])) { $buffer_info .= 'POWER_SUPPLY_VOLTAGE_MIN_DESIGN=' . $bufferWPB[0]['DesignVoltage'] * 1000 . "\n"; } // sometimes Chemistry from Win32_Battery returns 2 but Win32_PortableBattery returns e.g. 6 if (($techn == '' || $techn == 'Unknown') && isset($bufferWPB[0]['Chemistry'])) { switch ($bufferWPB[0]['Chemistry']) { case 1: $techn = 'Other'; break; case 2: $techn = 'Unknown'; break; case 3: $techn = 'PbAc'; break; case 4: $techn = 'NiCd'; break; case 5: $techn = 'NiMH'; break; case 6: $techn = 'Li-ion'; break; case 7: $techn = 'Zinc-air'; break; case 8: $techn = 'Li-poly'; break; } } if ($techn != '') { $buffer_info .= 'POWER_SUPPLY_TECHNOLOGY=' . $techn . "\n"; } $bufferBS = CommonFunctions::getWMI($_wmi, 'BatteryStatus', array('RemainingCapacity', 'Voltage')); if (sizeof($bufferBS) > 0) { if (isset($bufferBS[0]['RemainingCapacity']) && $bufferBS[0]['RemainingCapacity'] > 0) { $buffer_state .= 'POWER_SUPPLY_ENERGY_NOW=' . $bufferBS[0]['RemainingCapacity'] * 1000 . "\n"; $capacity = ''; } if (isset($bufferBS[0]['Voltage']) && $bufferBS[0]['Voltage'] > 0) { $buffer_state .= 'POWER_SUPPLY_VOLTAGE_NOW=' . $bufferBS[0]['Voltage'] * 1000 . "\n"; } elseif (isset($bufferWB[0]['DesignVoltage'])) { $buffer_state .= 'POWER_SUPPLY_VOLTAGE_NOW=' . $bufferWB[0]['DesignVoltage'] * 1000 . "\n"; } } if (!isset($bufferWPB[0]['FullChargeCapacity'])) { $bufferBFCC = CommonFunctions::getWMI($_wmi, 'BatteryFullChargedCapacity', array('FullChargedCapacity')); if (sizeof($bufferBFCC) > 0 && isset($bufferBFCC[0]['FullChargedCapacity'])) { $bufferWPB[0]['FullChargeCapacity'] = $bufferBFCC[0]['FullChargedCapacity']; } } if (isset($bufferWPB[0]['FullChargeCapacity'])) { $buffer_info .= 'POWER_SUPPLY_ENERGY_FULL=' . $bufferWPB[0]['FullChargeCapacity'] * 1000 . "\n"; if ($capacity != '') { $buffer_state .= 'POWER_SUPPLY_ENERGY_NOW=' . (round($capacity * $bufferWPB[0]['FullChargeCapacity'] * 10) . "\n"); } if (isset($bufferWPB[0]['DesignCapacity']) && $bufferWPB[0]['DesignCapacity'] != 0) { $buffer_info .= 'POWER_SUPPLY_ENERGY_FULL_DESIGN=' . $bufferWPB[0]['DesignCapacity'] * 1000 . "\n"; } } elseif (isset($bufferWPB[0]['DesignCapacity'])) { $buffer_info .= 'POWER_SUPPLY_ENERGY_FULL_DESIGN=' . $bufferWPB[0]['DesignCapacity'] * 1000 . "\n"; if ($capacity != '') { $buffer_state .= 'POWER_SUPPLY_ENERGY_NOW=' . (round($capacity * $bufferWPB[0]['DesignCapacity'] * 10) . "\n"); } } else { if ($capacity != '') { $buffer_state .= 'POWER_SUPPLY_CAPACITY=' . $capacity . "\n"; } } $bufferBCC = CommonFunctions::getWMI($_wmi, 'BatteryCycleCount', array('CycleCount')); if (sizeof($bufferBCC) > 0 && isset($bufferBCC[0]['CycleCount']) && $bufferBCC[0]['CycleCount'] > 0) { $buffer_info .= 'POWER_SUPPLY_CYCLE_COUNT=' . $bufferBCC[0]['CycleCount'] . "\n"; } } } elseif (PSI_OS == 'Darwin') { $buffer_info = ''; $buffer_state = ''; CommonFunctions::executeProgram('ioreg', '-w0 -l -n AppleSmartBattery -r', $buffer_info, false); } elseif (PSI_OS == 'FreeBSD') { $buffer_info = ''; $buffer_state = ''; CommonFunctions::executeProgram('acpiconf', '-i batt', $buffer_info, false); } else { $buffer_info = ''; $buffer_state = ''; $bat_name = PSI_PLUGIN_BAT_DEVICE; $rfts_bi = CommonFunctions::rfts('/proc/acpi/battery/' . $bat_name . '/info', $buffer_info, 0, 4096, false); $rfts_bs = CommonFunctions::rfts('/proc/acpi/battery/' . $bat_name . '/state', $buffer_state, 0, 4096, false); if (!$rfts_bi && !$rfts_bs) { $buffer_info = ''; $buffer_state = ''; if (!CommonFunctions::rfts('/sys/class/power_supply/' . $bat_name . '/uevent', $buffer_info, 0, 4096, false)) { if (CommonFunctions::rfts('/sys/class/power_supply/battery/uevent', $buffer_info, 0, 4096, false)) { $bat_name = 'battery'; } else { CommonFunctions::rfts('/sys/class/power_supply/' . $bat_name . '/uevent', $buffer_info, 0, 4096, PSI_DEBUG); // Once again but with debug } } if (CommonFunctions::rfts('/sys/class/power_supply/' . $bat_name . '/voltage_min_design', $buffer1, 1, 4096, false)) { $buffer_state .= 'POWER_SUPPLY_VOLTAGE_MIN_DESIGN=' . $buffer1 . "\n"; } if (CommonFunctions::rfts('/sys/class/power_supply/' . $bat_name . '/voltage_max_design', $buffer1, 1, 4096, false)) { $buffer_state .= 'POWER_SUPPLY_VOLTAGE_MAX_DESIGN=' . $buffer1 . "\n"; } if (CommonFunctions::rfts('/sys/class/power_supply/' . $bat_name . '/voltage_now', $buffer1, 1, 4096, false)) { $buffer_state .= 'POWER_SUPPLY_VOLTAGE_NOW=' . $buffer1 . "\n"; } if (CommonFunctions::rfts('/sys/class/power_supply/' . $bat_name . '/energy_full', $buffer1, 1, 4096, false)) { $buffer_state .= 'POWER_SUPPLY_ENERGY_FULL=' . $buffer1 . "\n"; } if (CommonFunctions::rfts('/sys/class/power_supply/' . $bat_name . '/energy_now', $buffer1, 1, 4096, false)) { $buffer_state .= 'POWER_SUPPLY_ENERGY_NOW=' . $buffer1 . "\n"; } if (CommonFunctions::rfts('/sys/class/power_supply/' . $bat_name . '/charge_full', $buffer1, 1, 4096, false)) { $buffer_state .= 'POWER_SUPPLY_CHARGE_FULL=' . $buffer1 . "\n"; } if (CommonFunctions::rfts('/sys/class/power_supply/' . $bat_name . '/charge_now', $buffer1, 1, 4096, false)) { $buffer_state .= 'POWER_SUPPLY_CHARGE_NOW=' . $buffer1 . "\n"; } if (CommonFunctions::rfts('/sys/class/power_supply/' . $bat_name . '/capacity', $buffer1, 1, 4096, false)) { $buffer_state .= 'POWER_SUPPLY_CAPACITY=' . $buffer1; } if (CommonFunctions::rfts('/sys/class/power_supply/' . $bat_name . '/technology', $buffer1, 1, 4096, false)) { $buffer_state .= 'POWER_SUPPLY_TECHNOLOGY=' . $buffer1; } if (CommonFunctions::rfts('/sys/class/power_supply/' . $bat_name . '/status', $buffer1, 1, 4096, false)) { $buffer_state .= 'POWER_SUPPLY_STATUS=' . $buffer1; } if (CommonFunctions::rfts('/sys/class/power_supply/' . $bat_name . '/batt_temp', $buffer1, 1, 4096, false)) { $buffer_state .= 'POWER_SUPPLY_TEMP=' . $buffer1; } if (CommonFunctions::rfts('/sys/class/power_supply/' . $bat_name . '/batt_vol', $buffer1, 1, 4096, false)) { $buffer_state .= 'POWER_SUPPLY_VOLTAGE_NOW=' . $buffer1; } if (CommonFunctions::rfts('/sys/class/power_supply/' . $bat_name . '/health', $buffer1, 1, 4096, false)) { $buffer_state .= 'POWER_SUPPLY_HEALTH=' . $buffer1; } } } break; case 'data': CommonFunctions::rfts(APP_ROOT . "/data/bat_info.txt", $buffer_info); CommonFunctions::rfts(APP_ROOT . "/data/bat_state.txt", $buffer_state); break; default: $this->global_error->addConfigError("__construct()", "PSI_PLUGIN_BAT_ACCESS"); break; } $this->_filecontent['info'] = preg_split("/\n/", $buffer_info, -1, PREG_SPLIT_NO_EMPTY); $this->_filecontent['state'] = preg_split("/\n/", $buffer_state, -1, PREG_SPLIT_NO_EMPTY); }
public function _processes() { $processes['*'] = 0; $buffer = CommonFunctions::getWMI($this->_wmi, 'Win32_Process', array('Caption')); foreach ($buffer as $process) { $processes['*']++; } $processes[' '] = $processes['*']; $this->sys->setProcesses($processes); }
public function _processes() { $processes['*'] = 0; if (CommonFunctions::executeProgram("qprocess", "*", $strBuf, false) && strlen(trim($strBuf)) > 0) { $lines = preg_split('/\\n/', $strBuf); $processes['*'] = count($lines) - 1 - 3; //correction for process "qprocess *" } if ($processes['*'] <= 0) { $buffer = CommonFunctions::getWMI($this->_wmi, 'Win32_Process', array('Caption')); $processes['*'] = count($buffer); } $processes[' '] = $processes['*']; $this->sys->setProcesses($processes); }
/** * read the data into an internal array and also call the parent constructor * * @param String $enc encoding */ public function __construct($enc) { parent::__construct(__CLASS__, $enc); switch (strtolower(PSI_PLUGIN_PS_ACCESS)) { case 'command': if (PSI_OS == 'WINNT') { try { $objLocator = new COM('WbemScripting.SWbemLocator'); $wmi = $objLocator->ConnectServer('', 'root\\CIMv2'); $os_wmi = CommonFunctions::getWMI($wmi, 'Win32_OperatingSystem', array('TotalVisibleMemorySize')); foreach ($os_wmi as $os) { $memtotal = $os['TotalVisibleMemorySize'] * 1024; } $process_wmi = CommonFunctions::getWMI($wmi, 'Win32_Process', array('Caption', 'CommandLine', 'ProcessId', 'ParentProcessId', 'WorkingSetSize')); foreach ($process_wmi as $process) { if (strlen(trim($process['CommandLine'])) > 0) { $ps = trim($process['CommandLine']); } else { $ps = trim($process['Caption']); } if (trim($process['ProcessId']) != 0) { $memusage = round(trim($process['WorkingSetSize']) * 100 / $memtotal, 1); //ParentProcessId //Unique identifier of the process that creates a process. Process identifier numbers are reused, so they //only identify a process for the lifetime of that process. It is possible that the process identified by //ParentProcessId is terminated, so ParentProcessId may not refer to a running process. It is also //possible that ParentProcessId incorrectly refers to a process that reuses a process identifier. You can //use the CreationDate property to determine whether the specified parent was created after the process //represented by this Win32_Process instance was created. //=> subtrees of processes may be missing (WHAT TODO?!?) $this->_filecontent[] = trim($process['ProcessId']) . " " . trim($process['ParentProcessId']) . " " . $memusage . " " . $ps; } } } catch (Exception $e) { } } else { CommonFunctions::executeProgram("ps", "axo pid,ppid,pmem,args", $buffer, PSI_DEBUG); if ((PSI_OS == 'Linux' || PSI_OS == 'Android') && !preg_match("/^[^\n]+\n\\s*\\d+\\s+\\d+\\s+[\\d\\.]+\\s+.+/", $buffer)) { //alternative method if no data if (CommonFunctions::rfts('/proc/meminfo', $mbuf)) { $bufe = preg_split("/\n/", $mbuf, -1, PREG_SPLIT_NO_EMPTY); $totalmem = 0; foreach ($bufe as $buf) { if (preg_match('/^MemTotal:\\s+(.*)\\s*kB/i', $buf, $ar_buf)) { $totalmem = $ar_buf[1]; break; } } $buffer = " PID PPID %MEM COMMAND\n"; $processlist = glob('/proc/*/status', GLOB_NOSORT); if (($total = count($processlist)) > 0) { natsort($processlist); //first sort $prosess = array(); foreach ($processlist as $processitem) { //second sort $process[] = $processitem; } $buf = ""; for ($i = 0; $i < $total; $i++) { if (CommonFunctions::rfts($process[$i], $buf, 0, 4096, false)) { if ($totalmem != 0 && preg_match('/^VmRSS:\\s+(\\d+)\\s+kB/m', $buf, $tmppmem)) { $pmem = round(100 * $tmppmem[1] / $totalmem, 1); } else { $pmem = 0; } $name = null; if (CommonFunctions::rfts(substr($process[$i], 0, strlen($process[$i]) - 6) . "cmdline", $namebuf, 0, 4096, false)) { $name = str_replace(chr(0), ' ', trim($namebuf)); } if (preg_match('/^Pid:\\s+(\\d+)/m', $buf, $tmppid) && preg_match('/^PPid:\\s+(\\d+)/m', $buf, $tmpppid) && preg_match('/^Name:\\s+(.+)/m', $buf, $tmpargs)) { $pid = $tmppid[1]; $ppid = $tmpppid[1]; $args = $tmpargs[1]; if ($name !== null) { if ($name !== "") { $args = $name; } else { $args = "[" . $args . "]"; } } $buffer .= $pid . " " . $ppid . " " . $pmem . " " . $args . "\n"; } } } } } } } break; case 'data': CommonFunctions::rfts(APP_ROOT . "/data/ps.txt", $buffer); break; default: $this->global_error->addConfigError("__construct()", "PSI_PLUGIN_PS_ACCESS"); break; } if (PSI_OS != 'WINNT') { if (trim($buffer) != "") { $this->_filecontent = preg_split("/\n/", $buffer, -1, PREG_SPLIT_NO_EMPTY); unset($this->_filecontent[0]); } else { $this->_filecontent = array(); } } }
/** * read the data into an internal array and also call the parent constructor * * @param String $enc encoding */ public function __construct($enc) { parent::__construct(__CLASS__, $enc); switch (strtolower(PSI_PLUGIN_BAT_ACCESS)) { case 'command': if (PSI_OS == 'Android') { CommonFunctions::rfts('/sys/class/power_supply/battery/uevent', $buffer_info, 0, 4096, PSI_DEBUG); $buffer_state = ''; if (CommonFunctions::rfts('/sys/class/power_supply/battery/capacity', $buffer1, 1, 4096, false)) { $buffer_state .= 'POWER_SUPPLY_CAPACITY=' . $buffer1; } if (CommonFunctions::rfts('/sys/class/power_supply/battery/batt_temp', $buffer1, 1, 4096, false)) { $buffer_state .= 'POWER_SUPPLY_TEMP=' . $buffer1; } if (CommonFunctions::rfts('/sys/class/power_supply/battery/batt_vol', $buffer1, 1, 4096, false)) { if ($buffer1 < 100000) { // uV or mV detection $buffer1 = $buffer1 * 1000; } $buffer_state .= 'POWER_SUPPLY_VOLTAGE_NOW=' . $buffer1 . "\n"; } if (CommonFunctions::rfts('/sys/class/power_supply/battery/voltage_max_design', $buffer1, 1, 4096, false)) { if ($buffer1 < 100000) { // uV or mV detection $buffer1 = $buffer1 * 1000; } $buffer_state .= 'POWER_SUPPLY_VOLTAGE_MAX_DESIGN=' . $buffer1 . "\n"; } if (CommonFunctions::rfts('/sys/class/power_supply/battery/technology', $buffer1, 1, 4096, false)) { $buffer_state .= 'POWER_SUPPLY_TECHNOLOGY=' . $buffer1; } if (CommonFunctions::rfts('/sys/class/power_supply/battery/status', $buffer1, 1, 4096, false)) { $buffer_state .= 'POWER_SUPPLY_STATUS=' . $buffer1; } if (CommonFunctions::rfts('/sys/class/power_supply/battery/health', $buffer1, 1, 4096, false)) { $buffer_state .= 'POWER_SUPPLY_HEALTH=' . $buffer1; } } elseif (PSI_OS == 'WINNT') { // don't set this params for local connection, it will not work $strHostname = ''; $strUser = ''; $strPassword = ''; try { // initialize the wmi object $objLocator = new COM('WbemScripting.SWbemLocator'); if ($strHostname == "") { $this->_wmi = $objLocator->ConnectServer(); } else { $this->_wmi = $objLocator->ConnectServer($strHostname, 'rootcimv2', $strHostname . '\\' . $strUser, $strPassword); } } catch (Exception $e) { $this->error->addError("WMI connect error", "PhpSysInfo can not connect to the WMI interface for security reasons.\nCheck an authentication mechanism for the directory where phpSysInfo is installed."); } $buffer_info = ''; $buffer_state = ''; $buffer = CommonFunctions::getWMI($this->_wmi, 'Win32_Battery', array('EstimatedChargeRemaining', 'DesignVoltage', 'BatteryStatus', 'Chemistry')); $capacity = ''; if (isset($buffer[0]['EstimatedChargeRemaining'])) { $capacity = $buffer[0]['EstimatedChargeRemaining']; } if (isset($buffer[0]['DesignVoltage'])) { $buffer_state .= 'POWER_SUPPLY_VOLTAGE_NOW=' . 1000 * $buffer[0]['DesignVoltage'] . "\n"; } if (isset($buffer[0]['BatteryStatus'])) { switch ($buffer[0]['BatteryStatus']) { case 1: $batstat = 'Discharging'; break; case 2: $batstat = 'AC connected'; break; case 3: $batstat = 'Fully Charged'; break; case 4: $batstat = 'Low'; break; case 5: $batstat = 'Critical'; break; case 6: $batstat = 'Charging'; break; case 7: $batstat = 'Charging and High'; break; case 8: $batstat = 'Charging and Low'; break; case 9: $batstat = 'Charging and Critical'; break; case 10: $batstat = 'Undefined'; break; case 11: $batstat = 'Partially Charged'; break; default: $batstat = ''; } if ($batstat != '') { $buffer_state .= 'POWER_SUPPLY_STATUS=' . $batstat . "\n"; } } $techn = ''; if (isset($buffer[0]['Chemistry'])) { switch ($buffer[0]['Chemistry']) { case 1: $techn = 'Other'; break; case 2: $techn = 'Unknown'; break; case 3: $techn = 'PbAc'; break; case 4: $techn = 'NiCd'; break; case 5: $techn = 'NiMH'; break; case 6: $techn = 'Li-ion'; break; case 7: $techn = 'Zinc-air'; break; case 8: $techn = 'Li-poly'; break; } } $buffer = CommonFunctions::getWMI($this->_wmi, 'Win32_PortableBattery', array('DesignVoltage', 'Chemistry', 'DesignCapacity')); if (isset($buffer[0]['DesignVoltage'])) { $buffer_info .= 'POWER_SUPPLY_VOLTAGE_MAX_DESIGN=' . 1000 * $buffer[0]['DesignVoltage'] . "\n"; } // sometimes Chemistry from Win32_Battery returns 2 but Win32_PortableBattery returns e.g. 6 if (($techn == '' || $techn == 'Unknown') && isset($buffer[0]['Chemistry'])) { switch ($buffer[0]['Chemistry']) { case 1: $techn = 'Other'; break; case 2: $techn = 'Unknown'; break; case 3: $techn = 'PbAc'; break; case 4: $techn = 'NiCd'; break; case 5: $techn = 'NiMH'; break; case 6: $techn = 'Li-ion'; break; case 7: $techn = 'Zinc-air'; break; case 8: $techn = 'Li-poly'; break; } } if ($techn != '') { $buffer_info .= 'POWER_SUPPLY_TECHNOLOGY=' . $techn . "\n"; } if (isset($buffer[0]['DesignCapacity'])) { $buffer_info .= 'design capacity:' . $buffer[0]['DesignCapacity']; if ($capacity != '') { $buffer_state .= 'remaining capacity:' . round($capacity * $buffer[0]['DesignCapacity'] / 100); } } else { if ($capacity != '') { $buffer_state .= 'POWER_SUPPLY_CAPACITY=' . $capacity . "\n"; } } } else { $rfts_bi = CommonFunctions::rfts('/proc/acpi/battery/' . PSI_PLUGIN_BAT_DEVICE . '/info', $buffer_info, 0, 4096, false); $rfts_bs = CommonFunctions::rfts('/proc/acpi/battery/' . PSI_PLUGIN_BAT_DEVICE . '/state', $buffer_state, 0, 4096, false); if (!$rfts_bi && !$rfts_bs) { CommonFunctions::rfts('/sys/class/power_supply/' . PSI_PLUGIN_BAT_DEVICE . '/uevent', $buffer_info, 0, 4096, PSI_DEBUG); $buffer_state = ''; if (CommonFunctions::rfts('/sys/class/power_supply/' . PSI_PLUGIN_BAT_DEVICE . '/voltage_min_design', $buffer1, 1, 4096, false)) { $buffer_state .= 'POWER_SUPPLY_VOLTAGE_MIN_DESIGN=' . $buffer1 . "\n"; } if (CommonFunctions::rfts('/sys/class/power_supply/' . PSI_PLUGIN_BAT_DEVICE . '/voltage_now', $buffer1, 1, 4096, false)) { $buffer_state .= 'POWER_SUPPLY_VOLTAGE_NOW=' . $buffer1 . "\n"; } if (CommonFunctions::rfts('/sys/class/power_supply/' . PSI_PLUGIN_BAT_DEVICE . '/energy_full', $buffer1, 1, 4096, false)) { $buffer_state .= 'POWER_SUPPLY_ENERGY_FULL=' . $buffer1 . "\n"; } if (CommonFunctions::rfts('/sys/class/power_supply/' . PSI_PLUGIN_BAT_DEVICE . '/energy_now', $buffer1, 1, 4096, false)) { $buffer_state .= 'POWER_SUPPLY_ENERGY_NOW=' . $buffer1 . "\n"; } if (CommonFunctions::rfts('/sys/class/power_supply/' . PSI_PLUGIN_BAT_DEVICE . '/charge_full', $buffer1, 1, 4096, false)) { $buffer_state .= 'POWER_SUPPLY_ENERGY_FULL=' . $buffer1 . "\n"; } if (CommonFunctions::rfts('/sys/class/power_supply/' . PSI_PLUGIN_BAT_DEVICE . '/charge_now', $buffer1, 1, 4096, false)) { $buffer_state .= 'POWER_SUPPLY_ENERGY_NOW=' . $buffer1 . "\n"; } if (CommonFunctions::rfts('/sys/class/power_supply/' . PSI_PLUGIN_BAT_DEVICE . '/capacity', $buffer1, 1, 4096, false)) { $buffer_state .= 'POWER_SUPPLY_CAPACITY=' . $buffer1; } if (CommonFunctions::rfts('/sys/class/power_supply/' . PSI_PLUGIN_BAT_DEVICE . '/technology', $buffer1, 1, 4096, false)) { $buffer_state .= 'POWER_SUPPLY_TECHNOLOGY=' . $buffer1; } if (CommonFunctions::rfts('/sys/class/power_supply/' . PSI_PLUGIN_BAT_DEVICE . '/status', $buffer1, 1, 4096, false)) { $buffer_state .= 'POWER_SUPPLY_STATUS=' . $buffer1; } } } break; case 'data': CommonFunctions::rfts(APP_ROOT . "/data/bat_info.txt", $buffer_info); CommonFunctions::rfts(APP_ROOT . "/data/bat_state.txt", $buffer_state); break; default: $this->global_error->addConfigError("__construct()", "PSI_PLUGIN_BAT_ACCESS"); break; } $this->_filecontent['info'] = preg_split("/\n/", $buffer_info, -1, PREG_SPLIT_NO_EMPTY); $this->_filecontent['state'] = preg_split("/\n/", $buffer_state, -1, PREG_SPLIT_NO_EMPTY); }