* Mon May 12 2025 Brian Read <brianr@koozali.org> 11.0.0-1.sme
- Adding SM2 panel [SME: 13004] - Upgrade to phpsysinfo 3.4.4 - Add code to delete inline styles and add css to make it look better. - version saved / built uses the static version, which means no drops downs and choices.
This commit is contained in:
@@ -1,19 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* PS Plugin
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* @category PHP
|
||||
* @package PSI_Plugin_PS
|
||||
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
|
||||
* @copyright 2009 phpSysInfo
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
|
||||
* @version SVN: $Id: class.ps.inc.php 692 2012-09-08 17:12:08Z namiltd $
|
||||
* @link http://phpsysinfo.sourceforge.net
|
||||
*/
|
||||
/**
|
||||
* process Plugin, which displays all running processes
|
||||
* PS Plugin, which displays all running processes
|
||||
* a simple tree view which is filled with the running processes which are determined by
|
||||
* calling the "ps" command line utility, another way is to provide
|
||||
* a file with the output of the ps utility, so there is no need to run a execute by the
|
||||
@@ -24,7 +11,7 @@
|
||||
* @package PSI_Plugin_PS
|
||||
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
|
||||
* @copyright 2009 phpSysInfo
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License version 2, or (at your option) any later version
|
||||
* @version Release: 3.0
|
||||
* @link http://phpsysinfo.sourceforge.net
|
||||
*/
|
||||
@@ -43,30 +30,43 @@ class PS extends PSI_Plugin
|
||||
/**
|
||||
* read the data into an internal array and also call the parent constructor
|
||||
*
|
||||
* @param String $enc encoding
|
||||
* @param string $enc encoding
|
||||
*/
|
||||
public function __construct($enc)
|
||||
{
|
||||
parent::__construct(__CLASS__, $enc);
|
||||
$buffer = "";
|
||||
switch (strtolower(PSI_PLUGIN_PS_ACCESS)) {
|
||||
case 'command':
|
||||
if (PSI_OS == 'WINNT') {
|
||||
if (((PSI_OS == 'WINNT') && !defined('PSI_EMU_HOSTNAME')) || (defined('PSI_EMU_HOSTNAME') && !defined('PSI_EMU_PORT'))) {
|
||||
try {
|
||||
$objLocator = new COM("WbemScripting.SWbemLocator");
|
||||
$wmi = $objLocator->ConnectServer();
|
||||
$os_wmi = $wmi->InstancesOf('Win32_OperatingSystem');
|
||||
$os_wmi = WINNT::_get_Win32_OperatingSystem();
|
||||
$memtotal = 0;
|
||||
foreach ($os_wmi as $os) {
|
||||
$memtotal = $os->TotalVisibleMemorySize * 1024;
|
||||
$memtotal = $os['TotalVisibleMemorySize'] * 1024;
|
||||
break;
|
||||
}
|
||||
$process_wmi = $wmi->InstancesOf('Win32_Process');
|
||||
$wmi = WINNT::getcimv2wmi();
|
||||
$perf_wmi = WINNT::getWMI($wmi, 'Win32_PerfFormattedData_PerfProc_Process', array('IDProcess', 'CreatingProcessID', 'PercentProcessorTime'));
|
||||
$proccpu = array();
|
||||
foreach ($perf_wmi as $perf) {
|
||||
$proccpu[trim($perf['IDProcess'])] = array('ParentProcessId'=>trim($perf['CreatingProcessID']), 'PercentProcessorTime'=>trim($perf['PercentProcessorTime']));
|
||||
}
|
||||
|
||||
$process_wmi = WINNT::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);
|
||||
if (isset($process['CommandLine']) && strlen(trim($process['CommandLine'])) > 0) {
|
||||
$ps = trim($process['CommandLine']);
|
||||
} else {
|
||||
$ps = trim($process->Caption);
|
||||
$ps = trim($process['Caption']);
|
||||
}
|
||||
if (trim($process->ProcessId) != 0) {
|
||||
$memusage = round(trim($process->WorkingSetSize) * 100 / $memtotal, 1);
|
||||
if (($procid = trim($process['ProcessId'])) != 0) {
|
||||
$memusage = round(trim($process['WorkingSetSize']) * 100 / $memtotal, 1);
|
||||
$parentid = trim($process['ParentProcessId']);
|
||||
$cpu = 0;
|
||||
if (isset($proccpu[$procid]) && ($proccpu[$procid]['ParentProcessId'] == $parentid)) {
|
||||
$cpu = $proccpu[$procid]['PercentProcessorTime'];
|
||||
}
|
||||
//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
|
||||
@@ -75,29 +75,29 @@ class PS extends PSI_Plugin
|
||||
//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;
|
||||
$this->_filecontent[] = $procid." ".$parentid." ".$memusage." ".$cpu." ".$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.+/", $buffer))) { //alternative method if no data
|
||||
} elseif ((PSI_OS != 'WINNT') && (!defined('PSI_EMU_HOSTNAME') || defined('PSI_EMU_PORT'))) {
|
||||
CommonFunctions::executeProgram("ps", "axo pid,ppid,pmem,pcpu,args", $buffer, PSI_DEBUG);
|
||||
if (((PSI_OS == 'Linux') || (PSI_OS == 'Android')) && (!preg_match("/^[^\n]+\n\s*\d+\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)) {
|
||||
if (preg_match('/^MemTotal:\s+(\d+)\s*kB/i', $buf, $ar_buf)) {
|
||||
$totalmem = $ar_buf[1];
|
||||
break;
|
||||
}
|
||||
}
|
||||
$buffer = " PID PPID %MEM COMMAND\n";
|
||||
$buffer = " PID PPID %MEM %CPU COMMAND\n";
|
||||
|
||||
$processlist = glob('/proc/*/status', GLOB_NOSORT);
|
||||
if (($total = count($processlist)) > 0) {
|
||||
$processlist = CommonFunctions::findglob('/proc/*/status', GLOB_NOSORT);
|
||||
if (is_array($processlist) && (($total = count($processlist)) > 0)) {
|
||||
natsort($processlist); //first sort
|
||||
$prosess = array();
|
||||
$process = array();
|
||||
foreach ($processlist as $processitem) { //second sort
|
||||
$process[] = $processitem;
|
||||
}
|
||||
@@ -129,7 +129,7 @@ class PS extends PSI_Plugin
|
||||
$args = "[".$args."]";
|
||||
}
|
||||
}
|
||||
$buffer .= $pid." ".$ppid." ".$pmem." ".$args."\n";
|
||||
$buffer .= $pid." ".$ppid." ".$pmem." 0.0 ".$args."\n";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -140,19 +140,16 @@ class PS extends PSI_Plugin
|
||||
}
|
||||
break;
|
||||
case 'data':
|
||||
CommonFunctions::rfts(APP_ROOT."/data/ps.txt", $buffer);
|
||||
if (!defined('PSI_EMU_HOSTNAME')) {
|
||||
CommonFunctions::rftsdata("ps.tmp", $buffer);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
$this->global_error->addConfigError("__construct()", "PSI_PLUGIN_PS_ACCESS");
|
||||
break;
|
||||
$this->global_error->addConfigError("__construct()", "[ps] ACCESS");
|
||||
}
|
||||
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();
|
||||
}
|
||||
if (trim($buffer) != "") {
|
||||
$this->_filecontent = preg_split("/\n/", $buffer, -1, PREG_SPLIT_NO_EMPTY);
|
||||
unset($this->_filecontent[0]);
|
||||
}
|
||||
}
|
||||
/**
|
||||
@@ -167,9 +164,10 @@ class PS extends PSI_Plugin
|
||||
if (empty($this->_filecontent)) {
|
||||
return;
|
||||
}
|
||||
$items = array();
|
||||
foreach ($this->_filecontent as $roworig) {
|
||||
$row = preg_split("/[\s]+/", trim($roworig), 4);
|
||||
if (count($row) != 4) {
|
||||
$row = preg_split("/[\s]+/", trim($roworig), 5);
|
||||
if (count($row) != 5) {
|
||||
break;
|
||||
}
|
||||
foreach ($row as $key=>$val) {
|
||||
@@ -187,7 +185,8 @@ class PS extends PSI_Plugin
|
||||
$items[$zombie]["0"] = $zombie;
|
||||
$items[$zombie]["1"] = "0";
|
||||
$items[$zombie]["2"] = "0";
|
||||
$items[$zombie]["3"] = "unknown";
|
||||
$items[$zombie]["3"] = "0";
|
||||
$items[$zombie]["4"] = "unknown";
|
||||
$items[0]['childs'][$zombie] = &$items[$zombie];
|
||||
}
|
||||
break; //first is sufficient
|
||||
@@ -197,7 +196,7 @@ class PS extends PSI_Plugin
|
||||
if (isset($items[0])) {
|
||||
$this->_result = $items[0];
|
||||
} else {
|
||||
$_result = array();
|
||||
$this->_result = array();
|
||||
}
|
||||
}
|
||||
/**
|
||||
@@ -217,9 +216,9 @@ class PS extends PSI_Plugin
|
||||
/**
|
||||
* recursive function to allow appending child processes to a parent process
|
||||
*
|
||||
* @param Array $child part of the array which should be appended to the XML
|
||||
* @param array $child part of the array which should be appended to the XML
|
||||
* @param SimpleXMLExtended $xml XML-Object to which the array content is appended
|
||||
* @param Array &$positions array with parent positions in xml structure
|
||||
* @param array &$positions array with parent positions in xml structure
|
||||
*
|
||||
* @return SimpleXMLExtended Object with the appended array content
|
||||
*/
|
||||
@@ -233,15 +232,17 @@ class PS extends PSI_Plugin
|
||||
$parentid = array_search($value[1], $positions);
|
||||
$xmlnode->addAttribute('ParentID', $parentid);
|
||||
$xmlnode->addAttribute('PPID', $value[1]);
|
||||
$xmlnode->addAttribute('MemoryUsage', $value[2]);
|
||||
$xmlnode->addAttribute('Name', str_replace("...","",$value[3]));
|
||||
if (PSI_OS !== 'WINNT') {
|
||||
if ($parentid === 1){
|
||||
$xmlnode->addAttribute('Expanded', 0);
|
||||
}
|
||||
if (defined('PSI_PLUGIN_PS_SHOW_KTHREADD_EXPANDED') && (PSI_PLUGIN_PS_SHOW_KTHREADD_EXPANDED === false) && ($value[3] === "[kthreadd]")) {
|
||||
$xmlnode->addAttribute('Expanded', 0);
|
||||
}
|
||||
if (!defined('PSI_PLUGIN_PS_MEMORY_USAGE') || (PSI_PLUGIN_PS_MEMORY_USAGE !== false)) {
|
||||
$xmlnode->addAttribute('MemoryUsage', str_replace(',', '.', $value[2]));
|
||||
}
|
||||
if (!defined('PSI_PLUGIN_PS_CPU_USAGE') || (PSI_PLUGIN_PS_CPU_USAGE !== false)) {
|
||||
$xmlnode->addAttribute('CPUUsage', str_replace(',', '.', $value[3]));
|
||||
}
|
||||
$xmlnode->addAttribute('Name', $value[4]);
|
||||
if ((PSI_OS != 'WINNT') && !defined('PSI_EMU_HOSTNAME') &&
|
||||
((($parentid === 1) && (!defined('PSI_PLUGIN_PS_SHOW_PID1CHILD_EXPANDED') || (PSI_PLUGIN_PS_SHOW_PID1CHILD_EXPANDED === false)))
|
||||
|| ((!defined('PSI_PLUGIN_PS_SHOW_KTHREADD_EXPANDED') || (PSI_PLUGIN_PS_SHOW_KTHREADD_EXPANDED === false)) && ($value[4] === "[kthreadd]")))) {
|
||||
$xmlnode->addAttribute('Expanded', 0);
|
||||
}
|
||||
}
|
||||
if (isset($value['childs'])) {
|
||||
|
Reference in New Issue
Block a user