* 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
|
||||
/**
|
||||
* PSStatus Plugin
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* @category PHP
|
||||
* @package PSI_Plugin_PSStatus
|
||||
* @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.psstatus.inc.php 692 2012-09-08 17:12:08Z namiltd $
|
||||
* @link http://phpsysinfo.sourceforge.net
|
||||
*/
|
||||
/**
|
||||
* process Plugin, which displays the status of configured processes
|
||||
* PSStatus Plugin, which displays the status of configured processes
|
||||
* a simple view which shows a process name and the status
|
||||
* status determined by calling the "pidof" command line utility, another way is to provide
|
||||
* a file with the output of the pidof utility, so there is no need to run a executeable by the
|
||||
@@ -25,7 +12,7 @@
|
||||
* @package PSI_Plugin_PSStatus
|
||||
* @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,6 +30,12 @@ class PSStatus extends PSI_Plugin
|
||||
*/
|
||||
private $_result = array();
|
||||
|
||||
/**
|
||||
* variable, which holds the current codepage
|
||||
* @var string
|
||||
*/
|
||||
private $_enc;
|
||||
|
||||
/**
|
||||
* read the data into an internal array and also call the parent constructor
|
||||
*
|
||||
@@ -51,56 +44,85 @@ class PSStatus extends PSI_Plugin
|
||||
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();
|
||||
$process_wmi = $wmi->InstancesOf('Win32_Process');
|
||||
foreach ($process_wmi as $process) {
|
||||
$this->_filecontent[] = array(strtolower(trim($process->Caption)), trim($process->ProcessId));
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
$this->_enc = $enc;
|
||||
if (defined('PSI_PLUGIN_PSSTATUS_PROCESSES') && is_string(PSI_PLUGIN_PSSTATUS_PROCESSES)) {
|
||||
switch (strtolower(PSI_PLUGIN_PSSTATUS_ACCESS)) {
|
||||
case 'command':
|
||||
if (preg_match(ARRAY_EXP, PSI_PLUGIN_PSSTATUS_PROCESSES)) {
|
||||
$processes = eval(PSI_PLUGIN_PSSTATUS_PROCESSES);
|
||||
} else {
|
||||
$processes = array(PSI_PLUGIN_PSSTATUS_PROCESSES);
|
||||
}
|
||||
} 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) {
|
||||
if (((PSI_OS == 'WINNT') && !defined('PSI_EMU_HOSTNAME')) || (defined('PSI_EMU_HOSTNAME') && !defined('PSI_EMU_PORT'))) {
|
||||
$short = true;
|
||||
if (strcasecmp($enc, "UTF-8") == 0) {
|
||||
foreach ($processes as $process) {
|
||||
CommonFunctions::executeProgram("pgrep", "-n -x ".$process, $buffer, PSI_DEBUG);
|
||||
if (strlen(trim($buffer)) > 0) {
|
||||
$this->_filecontent[] = array($process, trim($buffer));
|
||||
if (mb_strlen($process, "UTF-8") > 15) {
|
||||
$short = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
foreach ($processes as $process) {
|
||||
CommonFunctions::executeProgram("pidof", "-s ".$process, $buffer, PSI_DEBUG);
|
||||
if (strlen(trim($buffer)) > 0) {
|
||||
$this->_filecontent[] = array($process, trim($buffer));
|
||||
if (strlen($process) > 15) {
|
||||
$short = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!defined('PSI_EMU_HOSTNAME') && $short && CommonFunctions::executeProgram('qprocess', '*', $strBuf, false) && (strlen($strBuf) > 0)) {
|
||||
$psdata = preg_split("/\r?\n/", $strBuf, -1, PREG_SPLIT_NO_EMPTY);
|
||||
if (!empty($psdata)) foreach ($psdata as $psline) {
|
||||
$psvalues = preg_split("/ /", $psline, -1, PREG_SPLIT_NO_EMPTY);
|
||||
if ((count($psvalues) == 5) && is_numeric($psvalues[3])) {
|
||||
$this->_filecontent[] = array(strtolower($psvalues[4]), $psvalues[3]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!$short || (count($this->_filecontent) == 0)) {
|
||||
try {
|
||||
$wmi = WINNT::getcimv2wmi();
|
||||
$process_wmi = WINNT::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) {
|
||||
}
|
||||
}
|
||||
} elseif ((PSI_OS != 'WINNT') && (!defined('PSI_EMU_HOSTNAME') || defined('PSI_EMU_PORT'))) {
|
||||
if (defined('PSI_PLUGIN_PSSTATUS_USE_REGEX') && PSI_PLUGIN_PSSTATUS_USE_REGEX) {
|
||||
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 -x \"".$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;
|
||||
case 'data':
|
||||
if (!defined('PSI_EMU_HOSTNAME')) {
|
||||
CommonFunctions::rftsdata("psstatus.tmp", $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->addConfigError("__construct()", "[psstatus] ACCESS");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
$this->global_error->addError("switch(PSI_PLUGIN_PSSTATUS_ACCESS)", "Bad psstatus configuration in phpsysinfo.ini");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -113,30 +135,31 @@ class PSStatus extends PSI_Plugin
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
if (empty($this->_filecontent)) {
|
||||
return;
|
||||
}
|
||||
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 ((PSI_OS == 'WINNT') && (strtolower(PSI_PLUGIN_PSSTATUS_ACCESS) == 'command')) {
|
||||
if ((((PSI_OS == 'WINNT') && !defined('PSI_EMU_HOSTNAME')) || (defined('PSI_EMU_HOSTNAME') && !defined('PSI_EMU_PORT'))) &&
|
||||
(strtolower(PSI_PLUGIN_PSSTATUS_ACCESS) == 'command')) {
|
||||
$strBuf = PSI_PLUGIN_PSSTATUS_PROCESSES;
|
||||
if (defined('PSI_EMU_HOSTNAME')) {
|
||||
WINNT::convertCP($strBuf, $this->_enc);
|
||||
}
|
||||
if (preg_match(ARRAY_EXP, $strBuf)) {
|
||||
$processes = eval($strBuf);
|
||||
} else {
|
||||
$processes = array($strBuf);
|
||||
}
|
||||
|
||||
foreach ($processes as $process) {
|
||||
if ($this->_recursiveinarray(strtolower($process), $this->_filecontent)) {
|
||||
$this->_result[] = array($process, true);
|
||||
} else {
|
||||
$this->_result[] = array($process, false);
|
||||
}
|
||||
$this->_result[] = array($process, $this->process_inarray(strtolower($process), $this->_filecontent));
|
||||
}
|
||||
} else {
|
||||
if (preg_match(ARRAY_EXP, PSI_PLUGIN_PSSTATUS_PROCESSES)) {
|
||||
$processes = eval(PSI_PLUGIN_PSSTATUS_PROCESSES);
|
||||
} else {
|
||||
$processes = array(PSI_PLUGIN_PSSTATUS_PROCESSES);
|
||||
}
|
||||
|
||||
foreach ($processes as $process) {
|
||||
if ($this->_recursiveinarray($process, $this->_filecontent)) {
|
||||
$this->_result[] = array($process, true);
|
||||
} else {
|
||||
$this->_result[] = array($process, false);
|
||||
}
|
||||
$this->_result[] = array($process, $this->process_inarray($process, $this->_filecontent));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -149,7 +172,7 @@ class PSStatus extends PSI_Plugin
|
||||
*/
|
||||
public function xml()
|
||||
{
|
||||
foreach ($this->_result as $ps) {
|
||||
if (!defined('PSI_EMU_HOSTNAME') || defined('PSI_EMU_PORT') || !empty($this->_filecontent)) foreach ($this->_result as $ps) {
|
||||
$xmlps = $this->xml->addChild("Process");
|
||||
$xmlps->addAttribute("Name", $ps[0]);
|
||||
$xmlps->addAttribute("Status", $ps[1] ? 1 : 0);
|
||||
@@ -159,17 +182,17 @@ class PSStatus extends PSI_Plugin
|
||||
}
|
||||
|
||||
/**
|
||||
* checks an array recursive if an value is in, extended version of in_array()
|
||||
* checks an array if process name is in
|
||||
*
|
||||
* @param mixed $needle what to find
|
||||
* @param array $haystack where to find
|
||||
*
|
||||
* @return boolean true - found<br>false - not found
|
||||
*/
|
||||
private function _recursiveinarray($needle, $haystack)
|
||||
private function process_inarray($needle, $haystack)
|
||||
{
|
||||
foreach ($haystack as $stalk) {
|
||||
if ($needle == $stalk || (is_array($stalk) && $this->_recursiveinarray($needle, $stalk))) {
|
||||
if ($needle === $stalk[0]) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user