* 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:
2025-05-14 16:14:01 +01:00
parent 80b1da5fa5
commit c8ce77259d
952 changed files with 51341 additions and 28699 deletions

View File

@@ -8,7 +8,7 @@
* @package PSI
* @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 SVN: $Id: autoloader.inc.php 660 2012-08-27 11:08:40Z namiltd $
* @link http://phpsysinfo.sourceforge.net
*/
@@ -22,7 +22,7 @@ error_reporting(E_ALL | E_STRICT);
*
* @return void
*/
function __autoload($class_name)
function psi_autoload($class_name)
{
//$class_name = str_replace('-', '', $class_name);
@@ -30,8 +30,8 @@ function __autoload($class_name)
$dirs = array('/plugins/'.strtolower($class_name).'/', '/includes/mb/', '/includes/ups/');
foreach ($dirs as $dir) {
if (file_exists(APP_ROOT.$dir.'class.'.strtolower($class_name).'.inc.php')) {
include_once APP_ROOT.$dir.'class.'.strtolower($class_name).'.inc.php';
if (file_exists(PSI_APP_ROOT.$dir.'class.'.strtolower($class_name).'.inc.php')) {
include_once PSI_APP_ROOT.$dir.'class.'.strtolower($class_name).'.inc.php';
return;
}
@@ -41,19 +41,21 @@ function __autoload($class_name)
$dirs = array('/includes/', '/includes/interface/', '/includes/to/', '/includes/to/device/', '/includes/os/', '/includes/plugin/', '/includes/xml/', '/includes/web/', '/includes/error/', '/includes/js/', '/includes/output/');
foreach ($dirs as $dir) {
if (file_exists(APP_ROOT.$dir.'class.'.$class_name.'.inc.php')) {
include_once APP_ROOT.$dir.'class.'.$class_name.'.inc.php';
if (file_exists(PSI_APP_ROOT.$dir.'class.'.$class_name.'.inc.php')) {
include_once PSI_APP_ROOT.$dir.'class.'.$class_name.'.inc.php';
return;
}
}
$error = Error::singleton();
$error = PSI_Error::singleton();
$error->addError("_autoload(\"".$class_name."\")", "autoloading of class file (class.".$class_name.".inc.php) failed!");
$error->addError("psi_autoload(\"".$class_name."\")", "autoloading of class file (class.".$class_name.".inc.php) failed!");
$error->errorsAsXML();
}
spl_autoload_register('psi_autoload');
/**
* sets a user-defined error handler function
*
@@ -66,8 +68,10 @@ function __autoload($class_name)
*/
function errorHandlerPsi($level, $message, $file, $line)
{
$error = Error::singleton();
$error->addPhpError("errorHandlerPsi : ", "Level : ".$level." Message : ".$message." File : ".$file." Line : ".$line);
$error = PSI_Error::singleton();
if ((PSI_DEBUG && !preg_match("/^fgets\(|^stream_select\(/", $message)) || (($level !== 2) && ($level !== 8)) || !preg_match("/^[^:]*: open_basedir |^fopen\(|^fwrite\(|^is_readable\(|^file_exists\(|^fgets\(|^stream_select\(/", $message)) { // disable open_basedir, fopen, is_readable, file_exists, fgets and stream_select warnings and notices
$error->addPhpError("errorHandlerPsi : ", "Level : ".$level." Message : ".$message." File : ".$file." Line : ".$line);
}
}
set_error_handler('errorHandlerPsi');

View File

@@ -8,7 +8,7 @@
* @package PSI
* @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 SVN: $Id: class.CommonFunctions.inc.php 699 2012-09-15 11:57:13Z namiltd $
* @link http://phpsysinfo.sourceforge.net
*/
@@ -19,12 +19,19 @@
* @package PSI
* @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
*/
class CommonFunctions
{
/**
* holds dmi memory data
*
* @var array
*/
private static $_dmimd = null;
private static function _parse_log_file($string)
{
if (defined('PSI_LOG') && is_string(PSI_LOG) && (strlen(PSI_LOG)>0) && ((substr(PSI_LOG, 0, 1)=="-") || (substr(PSI_LOG, 0, 1)=="+"))) {
@@ -56,24 +63,32 @@ class CommonFunctions
*
* @param string $strProgram name of the program
*
* @return string complete path and name of the program
* @return string|null complete path and name of the program
*/
private static function _findProgram($strProgram)
public static function _findProgram($strProgram)
{
$path_parts = pathinfo($strProgram);
if (empty($path_parts['basename'])) {
return;
return null;
}
$arrPath = array();
if ((PSI_OS == 'WINNT') && empty($path_parts['extension'])) {
$strProgram .= '.exe';
$path_parts = pathinfo($strProgram);
}
if (empty($path_parts['dirname']) || ($path_parts['dirname'] == '.')) {
if ((PSI_OS == 'WINNT') && empty($path_parts['extension'])) {
$strProgram .= '.exe';
$path_parts = pathinfo($strProgram);
}
if (PSI_OS == 'WINNT') {
$arrPath = preg_split('/;/', getenv("Path"), -1, PREG_SPLIT_NO_EMPTY);
if (self::readenv('Path', $serverpath)) {
$arrPath = preg_split('/;/', $serverpath, -1, PREG_SPLIT_NO_EMPTY);
}
} else {
$arrPath = preg_split('/:/', getenv("PATH"), -1, PREG_SPLIT_NO_EMPTY);
if (self::readenv('PATH', $serverpath)) {
$arrPath = preg_split('/:/', $serverpath, -1, PREG_SPLIT_NO_EMPTY);
}
}
if (defined('PSI_UNAMEO') && (PSI_UNAMEO === 'Android') && !empty($arrPath)) {
array_push($arrPath, '/system/bin'); // Termux patch
}
if (defined('PSI_ADD_PATHS') && is_string(PSI_ADD_PATHS)) {
if (preg_match(ARRAY_EXP, PSI_ADD_PATHS)) {
@@ -82,13 +97,13 @@ class CommonFunctions
$arrPath = array_merge(array(PSI_ADD_PATHS), $arrPath); // In this order so $addpaths is before $arrPath when looking for a program
}
}
} else {
} else { //directory defined
array_push($arrPath, $path_parts['dirname']);
$strProgram = $path_parts['basename'];
}
//add some default paths if we still have no paths here
if (empty($arrPath) && PSI_OS != 'WINNT') {
if (empty($arrPath) && (PSI_OS != 'WINNT')) {
if (PSI_OS == 'Android') {
array_push($arrPath, '/system/bin');
} else {
@@ -97,97 +112,74 @@ class CommonFunctions
}
$exceptPath = "";
if ((PSI_OS == 'WINNT') && (($windir = getenv("WinDir")) !== false)) {
$windir = strtolower($windir);
if ((PSI_OS == 'WINNT') && self::readenv('WinDir', $windir)) {
foreach ($arrPath as $strPath) {
if ((strtolower($strPath) == $windir."\\system32") && is_dir($windir."\\SysWOW64")) {
$exceptPath = $windir."\\sysnative";
if ((strtolower($strPath) == strtolower($windir)."\\system32") && is_dir($windir."\\SysWOW64")) {
if (is_dir($windir."\\sysnative\\drivers")) { // or strlen(decbin(~0)) == 32; is_dir($windir."\\sysnative") sometimes does not work
$exceptPath = $windir."\\sysnative"; //32-bit PHP on 64-bit Windows
} else {
$exceptPath = $windir."\\SysWOW64"; //64-bit PHP on 64-bit Windows
}
array_push($arrPath, $exceptPath);
break;
}
}
} else if (PSI_OS == 'Android') {
$exceptPath = '/system/bin';
} elseif (PSI_OS == 'Android') {
$exceptPath = '/system/bin';
}
// If open_basedir defined, fill the $open_basedir array with authorized paths,. (Not tested when no open_basedir restriction)
if ((bool) ini_get('open_basedir')) {
if (PSI_OS == 'WINNT') {
$open_basedir = preg_split('/;/', ini_get('open_basedir'), -1, PREG_SPLIT_NO_EMPTY);
} else {
$open_basedir = preg_split('/:/', ini_get('open_basedir'), -1, PREG_SPLIT_NO_EMPTY);
}
}
foreach ($arrPath as $strPath) {
// Path with trailing slash
// Path with and without trailing slash
if (PSI_OS == 'WINNT') {
$strPathS = rtrim($strPath, "\\")."\\";
$strPath = rtrim($strPath, "\\");
$strPathS = $strPath."\\";
} else {
$strPathS = rtrim($strPath, "/")."/";
}
// To avoid "open_basedir restriction in effect" error when testing paths if restriction is enabled
if (isset($open_basedir)) {
$inBaseDir = false;
if (PSI_OS == 'WINNT') {
foreach ($open_basedir as $openbasedir) {
if (substr($openbasedir, -1)=="\\") {
$str_Path = $strPathS;
} else {
$str_Path = $strPath;
}
if (stripos($str_Path, $openbasedir) === 0) {
$inBaseDir = true;
break;
}
}
} else {
foreach ($open_basedir as $openbasedir) {
if (substr($openbasedir, -1)=="/") {
$str_Path = $strPathS;
} else {
$str_Path = $strPath;
}
if (strpos($str_Path, $openbasedir) === 0) {
$inBaseDir = true;
break;
}
}
}
if ($inBaseDir == false) {
continue;
}
$strPath = rtrim($strPath, "/");
$strPathS = $strPath."/";
}
if (($strPath !== $exceptPath) && !is_dir($strPath)) {
continue;
}
if (PSI_OS == 'WINNT') {
$strProgrammpath = rtrim($strPath, "\\")."\\".$strProgram;
} else {
$strProgrammpath = rtrim($strPath, "/")."/".$strProgram;
}
if (is_executable($strProgrammpath)) {
$strProgrammpath = $strPathS.$strProgram;
if (is_executable($strProgrammpath) || ((PSI_OS == 'WINNT') && (strtolower($path_parts['extension']) == 'py') && is_file($strProgrammpath))) {
return $strProgrammpath;
}
}
return null;
}
/**
* Execute a system program. return a trim()'d result.
* does very crude pipe checking. you need ' | ' for it to work
* does very crude pipe and multiple commands (on WinNT) checking. you need ' | ' or ' & ' for it to work
* ie $program = CommonFunctions::executeProgram('netstat', '-anp | grep LIST');
* NOT $program = CommonFunctions::executeProgram('netstat', '-anp|grep LIST');
*
* @param string $strProgramname name of the program
* @param string $strArgs arguments to the program
* @param string $strArguments arguments to the program
* @param string &$strBuffer output of the command
* @param boolean $booErrorRep en- or disables the reporting of errors which should be logged
* @param int $timeout timeout value in seconds (default value is PSI_EXEC_TIMEOUT_INT)
*
* @return boolean command successfull or not
*/
public static function executeProgram($strProgramname, $strArgs, &$strBuffer, $booErrorRep = true)
public static function executeProgram($strProgramname, $strArguments, &$strBuffer, $booErrorRep = true, $timeout = PSI_EXEC_TIMEOUT_INT, $separator = '')
{
if (PSI_ROOT_FILESYSTEM !== '') { // disabled if ROOTFS defined
return false;
}
if ((PSI_OS != 'WINNT') && preg_match('/^([^=]+=[^ \t]+)[ \t]+(.*)$/', $strProgramname, $strmatch)) {
$strSet = $strmatch[1].' ';
$strProgramname = $strmatch[2];
} else {
$strSet = '';
}
$strAll = trim($strSet.$strProgramname.' '.$strArguments);
if (defined('PSI_LOG') && is_string(PSI_LOG) && (strlen(PSI_LOG)>0) && ((substr(PSI_LOG, 0, 1)=="-") || (substr(PSI_LOG, 0, 1)=="+"))) {
$out = self::_parse_log_file("Executing: ".trim($strProgramname.' '.$strArgs));
$out = self::_parse_log_file("Executing: ".$strAll);
if ($out == false) {
if (substr(PSI_LOG, 0, 1)=="-") {
$strBuffer = '';
@@ -201,42 +193,164 @@ class CommonFunctions
}
}
$strBuffer = '';
$strError = '';
$pipes = array();
$PathStr = '';
if (defined('PSI_EMU_PORT') && !in_array($strProgramname, array('ping', 'snmpwalk'))) {
if (defined('PSI_SUDO_COMMANDS') && is_string(PSI_SUDO_COMMANDS)) {
if (preg_match(ARRAY_EXP, PSI_SUDO_COMMANDS)) {
$sudocommands = eval(PSI_SUDO_COMMANDS);
} else {
$sudocommands = array(PSI_SUDO_COMMANDS);
}
if (in_array($strProgramname, $sudocommands)) {
$strAll = 'sudo '.$strAll;
}
}
$strSet = '';
$strProgramname = 'sshpass';
$strOptions = '';
if (defined('PSI_EMU_ADD_OPTIONS') && is_string(PSI_EMU_ADD_OPTIONS)) {
if (preg_match(ARRAY_EXP, PSI_EMU_ADD_OPTIONS)) {
$arrParams = eval(PSI_EMU_ADD_OPTIONS);
} else {
$arrParams = array(PSI_EMU_ADD_OPTIONS);
}
foreach ($arrParams as $Params) if (preg_match('/(\S+)\s*\=\s*(\S+)/', $Params, $obuf)) {
$strOptions = $strOptions.'-o '.$obuf[1].'='.$obuf[2].' ';
}
}
if (defined('PSI_EMU_ADD_PATHS') && is_string(PSI_EMU_ADD_PATHS)) {
if (preg_match(ARRAY_EXP, PSI_EMU_ADD_PATHS)) {
$arrPath = eval(PSI_EMU_ADD_PATHS);
} else {
$arrPath = array(PSI_EMU_ADD_PATHS);
}
foreach ($arrPath as $Path) {
if ($PathStr === '') {
$PathStr = $Path;
} else {
$PathStr = $PathStr.':'.$Path;
}
}
if ($separator === '') {
$strArguments = '-e ssh -Tq '.$strOptions.'-o ConnectTimeout='.$timeout.' -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null '.PSI_EMU_USER.'@'.PSI_EMU_HOSTNAME.' -p '.PSI_EMU_PORT.' "PATH=\''.$PathStr.':$PATH\' '.$strAll.'"' ;
} else {
$strArguments = '-e ssh -Tq '.$strOptions.'-o ConnectTimeout='.$timeout.' -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null '.PSI_EMU_USER.'@'.PSI_EMU_HOSTNAME.' -p '.PSI_EMU_PORT;
}
} else {
if ($separator === '') {
$strArguments = '-e ssh -Tq '.$strOptions.'-o ConnectTimeout='.$timeout.' -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null '.PSI_EMU_USER.'@'.PSI_EMU_HOSTNAME.' -p '.PSI_EMU_PORT.' "'.$strAll.'"' ;
} else {
$strArguments = '-e ssh -Tq '.$strOptions.'-o ConnectTimeout='.$timeout.' -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null '.PSI_EMU_USER.'@'.PSI_EMU_HOSTNAME.' -p '.PSI_EMU_PORT;
}
}
$externally = true;
} else {
$externally = false;
}
$strProgram = self::_findProgram($strProgramname);
$error = Error::singleton();
$error = PSI_Error::singleton();
if (!$strProgram) {
if ($booErrorRep) {
$error->addError('find_program('.$strProgramname.')', 'program not found on the machine');
if ($booErrorRep || $externally) {
$error->addError('find_program("'.$strProgramname.'")', 'program not found on the machine');
}
return false;
} else {
if (preg_match('/\s/', $strProgram)) {
$strProgram = '"'.$strProgram.'"';
}
}
// see if we've gotten a |, if we have we need to do path checking on the cmd
if ($strArgs) {
$arrArgs = preg_split('/ /', $strArgs, -1, PREG_SPLIT_NO_EMPTY);
for ($i = 0, $cnt_args = count($arrArgs); $i < $cnt_args; $i++) {
if ($arrArgs[$i] == '|') {
$strCmd = $arrArgs[$i + 1];
$strNewcmd = self::_findProgram($strCmd);
$strArgs = preg_replace("/\| ".$strCmd.'/', '| "'.$strNewcmd.'"', $strArgs);
if ((PSI_OS != 'WINNT') && !defined('PSI_EMU_HOSTNAME') && defined('PSI_SUDO_COMMANDS') && is_string(PSI_SUDO_COMMANDS)) {
if (preg_match(ARRAY_EXP, PSI_SUDO_COMMANDS)) {
$sudocommands = eval(PSI_SUDO_COMMANDS);
} else {
$sudocommands = array(PSI_SUDO_COMMANDS);
}
if (in_array($strProgramname, $sudocommands)) {
$sudoProgram = self::_findProgram("sudo");
if (!$sudoProgram) {
$error->addError('find_program("sudo")', 'program not found on the machine');
return false;
} else {
if (preg_match('/\s/', $sudoProgram)) {
$strProgram = '"'.$sudoProgram.'" '.$strProgram;
} else {
$strProgram = $sudoProgram.' '.$strProgram;
}
}
}
}
$strArgs = $strArguments;
// see if we've gotten a | or &, if we have we need to do path checking on the cmd
if ($strArgs) {
$arrArgs = preg_split('/ /', $strArgs, -1, PREG_SPLIT_NO_EMPTY);
for ($i = 0, $cnt_args = count($arrArgs); $i < $cnt_args; $i++) {
if (($arrArgs[$i] == '|') || ($arrArgs[$i] == '&')) {
$strCmd = $arrArgs[$i + 1];
$strNewcmd = self::_findProgram($strCmd);
if (!$strNewcmd) {
if ($booErrorRep || $externally) {
$error->addError('find_program("'.$strCmd.'")', 'program not found on the machine');
}
return false;
}
if (preg_match('/\s/', $strNewcmd)) {
if ($arrArgs[$i] == '|') {
$strArgs = preg_replace('/\| '.$strCmd.'/', '| "'.$strNewcmd.'"', $strArgs);
} else {
$strArgs = preg_replace('/& '.$strCmd.'/', '& "'.$strNewcmd.'"', $strArgs);
}
} else {
if ($arrArgs[$i] == '|') {
$strArgs = preg_replace('/\| '.$strCmd.'/', '| '.$strNewcmd, $strArgs);
} else {
$strArgs = preg_replace('/& '.$strCmd.'/', '& '.$strNewcmd, $strArgs);
}
}
}
}
$strArgs = ' '.$strArgs;
}
$strBuffer = '';
$strError = '';
$pipes = array();
$descriptorspec = array(0=>array("pipe", "r"), 1=>array("pipe", "w"), 2=>array("pipe", "w"));
if (defined("PSI_MODE_POPEN") && PSI_MODE_POPEN === true) {
if ($externally) {
putenv('SSHPASS='.PSI_EMU_PASSWORD);
}
if (defined("PSI_MODE_POPEN") && PSI_MODE_POPEN) {
if ($separator !== '') {
$error->addError('executeProgram', 'wrong execution mode');
return false;
}
if (PSI_OS == 'WINNT') {
$process = $pipes[1] = popen('"'.$strProgram.'" '.$strArgs." 2>nul", "r");
$process = $pipes[1] = popen($strSet.$strProgram.$strArgs." 2>nul", "r");
} else {
$process = $pipes[1] = popen('"'.$strProgram.'" '.$strArgs." 2>/dev/null", "r");
$process = $pipes[1] = popen($strSet.$strProgram.$strArgs." 2>/dev/null", "r");
}
} else {
$process = proc_open('"'.$strProgram.'" '.$strArgs, $descriptorspec, $pipes);
$process = proc_open($strSet.$strProgram.$strArgs, $descriptorspec, $pipes);
if ($separator !== '') {
if ($PathStr === '') {
fwrite($pipes[0], $strAll."\n "); // spaces at end for handling 'more'
} else {
fwrite($pipes[0], 'PATH=\''.$PathStr.':$PATH\' '.$strAll."\n");
}
}
}
if ($externally) {
putenv('SSHPASS');
}
if (is_resource($process)) {
self::_timeoutfgets($pipes, $strBuffer, $strError);
if (defined("PSI_MODE_POPEN") && PSI_MODE_POPEN === true) {
$te = self::_timeoutfgets($pipes, $strBuffer, $strError, $timeout, $separator);
if (defined("PSI_MODE_POPEN") && PSI_MODE_POPEN) {
$return_value = pclose($pipes[1]);
} else {
fclose($pipes[0]);
@@ -244,7 +358,12 @@ class CommonFunctions
fclose($pipes[2]);
// It is important that you close any pipes before calling
// proc_close in order to avoid a deadlock
$return_value = proc_close($process);
if ($te) {
proc_terminate($process); // proc_close tends to hang if the process is timing out
$return_value = 0;
} else {
$return_value = proc_close($process);
}
}
} else {
if ($booErrorRep) {
@@ -256,7 +375,7 @@ class CommonFunctions
$strError = trim($strError);
$strBuffer = trim($strBuffer);
if (defined('PSI_LOG') && is_string(PSI_LOG) && (strlen(PSI_LOG)>0) && (substr(PSI_LOG, 0, 1)!="-") && (substr(PSI_LOG, 0, 1)!="+")) {
error_log("---".gmdate('r T')."--- Executing: ".trim($strProgramname.' '.$strArgs)."\n".$strBuffer."\n", 3, PSI_LOG);
error_log("---".gmdate('r T')."--- Executing: ".$strAll."\n".$strBuffer."\n", 3, PSI_LOG);
}
if (! empty($strError)) {
if ($booErrorRep) {
@@ -269,19 +388,74 @@ class CommonFunctions
return true;
}
/**
* read a one-line value from a file with a similar name
*
* @return value if successfull or null if not
*/
public static function rolv($similarFileName, $match = "//", $replace = "")
{
if (defined('PSI_EMU_PORT')) {
return null;
}
$filename = preg_replace($match, $replace, $similarFileName);
if (self::fileexists($filename) && self::rfts($filename, $buf, 1, 4096, false) && (($buf=trim($buf)) != "")) {
return $buf;
} else {
return null;
}
}
/**
* read data from array $_SERVER
*
* @param string $strElem element of array
* @param string &$strBuffer output of the command
*
* @return string
*/
public static function readenv($strElem, &$strBuffer)
{
$strBuffer = '';
if (PSI_OS == 'WINNT') { //case insensitive
if (isset($_SERVER)) {
foreach ($_SERVER as $index=>$value) {
if (is_string($value) && (trim($value) !== '') && (strtolower($index) === strtolower($strElem))) {
$strBuffer = $value;
return true;
}
}
}
} else {
if (isset($_SERVER[$strElem]) && is_string($value = $_SERVER[$strElem]) && (trim($value) !== '')) {
$strBuffer = $value;
return true;
}
}
return false;
}
/**
* read a file and return the content as a string
*
* @param string $strFileName name of the file which should be read
* @param string &$strRet content of the file (reference)
* @param integer $intLines control how many lines should be read
* @param integer $intBytes control how many bytes of each line should be read
* @param int $intLines control how many lines should be read
* @param int $intBytes control how many bytes of each line should be read
* @param boolean $booErrorRep en- or disables the reporting of errors which should be logged
*
* @return boolean command successfull or not
*/
public static function rfts($strFileName, &$strRet, $intLines = 0, $intBytes = 4096, $booErrorRep = true)
{
if (defined('PSI_EMU_PORT')) {
return false;
}
if (defined('PSI_LOG') && is_string(PSI_LOG) && (strlen(PSI_LOG)>0) && ((substr(PSI_LOG, 0, 1)=="-") || (substr(PSI_LOG, 0, 1)=="+"))) {
$out = self::_parse_log_file("Reading: ".$strFileName);
if ($out == false) {
@@ -297,12 +471,18 @@ class CommonFunctions
}
}
if (PSI_ROOT_FILESYSTEM !== '') {
$rfsinfo = "[".PSI_ROOT_FILESYSTEM."]";
} else {
$rfsinfo = '';
}
$strFile = "";
$intCurLine = 1;
$error = Error::singleton();
if (file_exists($strFileName)) {
if (is_readable($strFileName)) {
if ($fd = fopen($strFileName, 'r')) {
$error = PSI_Error::singleton();
if (file_exists(PSI_ROOT_FILESYSTEM.$strFileName)) {
if (is_readable(PSI_ROOT_FILESYSTEM.$strFileName)) {
if ($fd = fopen(PSI_ROOT_FILESYSTEM.$strFileName, 'r')) {
while (!feof($fd)) {
$strFile .= fgets($fd, $intBytes);
if ($intLines <= $intCurLine && $intLines != 0) {
@@ -322,21 +502,21 @@ class CommonFunctions
}
} else {
if ($booErrorRep) {
$error->addError('fopen('.$strFileName.')', 'file can not read by phpsysinfo');
$error->addError('fopen('.$rfsinfo.$strFileName.')', 'file can not read by phpsysinfo');
}
return false;
}
} else {
if ($booErrorRep) {
$error->addError('fopen('.$strFileName.')', 'file permission error');
}
if ($booErrorRep) {
$error->addError('fopen('.$rfsinfo.$strFileName.')', 'file permission error');
}
return false;
return false;
}
} else {
if ($booErrorRep) {
$error->addError('file_exists('.$strFileName.')', 'the file does not exist on your machine');
$error->addError('file_exists('.$rfsinfo.$strFileName.')', 'the file does not exist on your machine');
}
return false;
@@ -345,6 +525,76 @@ class CommonFunctions
return true;
}
/**
* read a data file and return the content as a string
*
* @param string $strDataFileName name of the data file which should be read
* @param string &$strRet content of the data file (reference)
*
* @return boolean command successfull or not
*/
public static function rftsdata($strDataFileName, &$strRet)
{
$strFile = "";
$strFileName = PSI_APP_ROOT."/data/".$strDataFileName;
$error = PSI_Error::singleton();
if (file_exists($strFileName)) {
if (is_readable($strFileName)) {
if ($fd = fopen($strFileName, 'r')) {
while (!feof($fd)) {
$strFile .= fgets($fd, 4096);
}
fclose($fd);
$strRet = $strFile;
} else {
$error->addError('fopen('.$strFileName.')', 'file can not read by phpsysinfo');
return false;
}
} else {
$error->addError('fopen('.$strFileName.')', 'file permission error');
return false;
}
} else {
$error->addError('file_exists('.$strFileName.')', 'the file does not exist on your machine');
return false;
}
return true;
}
/**
* Find pathnames matching a pattern
*
* @param string $pattern the pattern. No tilde expansion or parameter substitution is done.
* @param int $flags
*
* @return an array containing the matched files/directories, an empty array if no file matched or false on error
*/
public static function findglob($pattern, $flags = 0)
{
if (defined('PSI_EMU_PORT')) {
return false;
}
$outarr = glob(PSI_ROOT_FILESYSTEM.$pattern, $flags);
if (PSI_ROOT_FILESYSTEM == '') {
return $outarr;
} elseif ($outarr === false) {
return false;
} else {
$len = strlen(PSI_ROOT_FILESYSTEM);
$newoutarr = array();
foreach ($outarr as $out) {
$newoutarr[] = substr($out, $len); // path without ROOTFS
}
return $newoutarr;
}
}
/**
* file exists
*
@@ -354,6 +604,10 @@ class CommonFunctions
*/
public static function fileexists($strFileName)
{
if (defined('PSI_EMU_PORT')) {
return false;
}
if (defined('PSI_LOG') && is_string(PSI_LOG) && (strlen(PSI_LOG)>0) && ((substr(PSI_LOG, 0, 1)=="-") || (substr(PSI_LOG, 0, 1)=="+"))) {
$log_file = substr(PSI_LOG, 1);
if (file_exists($log_file)
@@ -367,7 +621,14 @@ class CommonFunctions
}
}
return file_exists($strFileName);
$exists = file_exists(PSI_ROOT_FILESYSTEM.$strFileName);
if (defined('PSI_LOG') && is_string(PSI_LOG) && (strlen(PSI_LOG)>0) && (substr(PSI_LOG, 0, 1)!="-") && (substr(PSI_LOG, 0, 1)!="+")) {
if ((substr($strFileName, 0, 5) === "/dev/") && $exists) {
error_log("---".gmdate('r T')."--- Reading: ".$strFileName."\ndevice exists\n", 3, PSI_LOG);
}
}
return $exists;
}
/**
@@ -381,7 +642,7 @@ class CommonFunctions
public static function gdc($strPath, $booErrorRep = true)
{
$arrDirectoryContent = array();
$error = Error::singleton();
$error = PSI_Error::singleton();
if (is_dir($strPath)) {
if ($handle = opendir($strPath)) {
while (($strFile = readdir($handle)) !== false) {
@@ -419,12 +680,12 @@ class CommonFunctions
*/
public static function checkForExtensions($arrExt = array())
{
if ((strcasecmp(PSI_SYSTEM_CODEPAGE, "UTF-8") == 0) || (strcasecmp(PSI_SYSTEM_CODEPAGE, "CP437") == 0))
if (defined('PSI_SYSTEM_CODEPAGE') && (PSI_SYSTEM_CODEPAGE !== null) && ((strcasecmp(PSI_SYSTEM_CODEPAGE, "UTF-8") == 0) || (strcasecmp(PSI_SYSTEM_CODEPAGE, "CP437") == 0)))
$arrReq = array('simplexml', 'pcre', 'xml', 'dom');
elseif (PSI_OS == "WINNT")
$arrReq = array('simplexml', 'pcre', 'xml', 'mbstring', 'dom', 'com_dotnet');
elseif (PSI_OS == 'WINNT')
$arrReq = array('simplexml', 'pcre', 'xml', 'dom', 'mbstring', 'com_dotnet');
else
$arrReq = array('simplexml', 'pcre', 'xml', 'mbstring', 'dom');
$arrReq = array('simplexml', 'pcre', 'xml', 'dom', 'mbstring');
$extensions = array_merge($arrExt, $arrReq);
$text = "";
$error = false;
@@ -441,7 +702,7 @@ class CommonFunctions
$text .= " </Error>\n";
$text .= "</phpsysinfo>";
if ($error) {
header("Content-Type: text/xml\n\n");
header('Content-Type: text/xml');
echo $text;
die();
}
@@ -450,19 +711,20 @@ class CommonFunctions
/**
* get the content of stdout/stderr with the option to set a timeout for reading
*
* @param array $pipes array of file pointers for stdin, stdout, stderr (proc_open())
* @param string &$out target string for the output message (reference)
* @param string &$err target string for the error message (reference)
* @param integer $timeout timeout value in seconds (default value is 30)
* @param array $pipes array of file pointers for stdin, stdout, stderr (proc_open())
* @param string &$out target string for the output message (reference)
* @param string &$err target string for the error message (reference)
* @param int $timeout timeout value in seconds
*
* @return void
* @return boolean timeout expired or not
*/
private static function _timeoutfgets($pipes, &$out, &$err, $timeout = 30)
private static function _timeoutfgets($pipes, &$out, &$err, $timeout, $separator = '')
{
$w = null;
$e = null;
$te = false;
if (defined("PSI_MODE_POPEN") && PSI_MODE_POPEN === true) {
if (defined("PSI_MODE_POPEN") && PSI_MODE_POPEN) {
$pipe2 = false;
} else {
$pipe2 = true;
@@ -481,66 +743,30 @@ class CommonFunctions
break;
} elseif ($n === 0) {
error_log('stream_select: timeout expired !');
// if ($separator !== '') {
// fwrite($pipes[0], "q");
// }
$te = true;
break;
}
foreach ($read as $r) {
if ($r == $pipes[1]) {
$out .= fread($r, 4096);
} else if (feof($pipes[1]) && $pipe2 && ($r == $pipes[2])) {//read STDERR after STDOUT
} elseif (feof($pipes[1]) && $pipe2 && ($r == $pipes[2])) {//read STDERR after STDOUT
$err .= fread($r, 4096);
}
}
}
}
/**
* function for getting a list of values in the specified context
* optionally filter this list, based on the list from third parameter
*
* @param $wmi holds the COM object that we pull the WMI data from
* @param string $strClass name of the class where the values are stored
* @param array $strValue filter out only needed values, if not set all values of the class are returned
*
* @return array content of the class stored in an array
*/
public static function getWMI($wmi, $strClass, $strValue = array())
{
$arrData = array();
if ($wmi) {
$value = "";
try {
$objWEBM = $wmi->Get($strClass);
$arrProp = $objWEBM->Properties_;
$arrWEBMCol = $objWEBM->Instances_();
foreach ($arrWEBMCol as $objItem) {
if (is_array($arrProp)) {
reset($arrProp);
}
$arrInstance = array();
foreach ($arrProp as $propItem) {
$value = $objItem->{$propItem->Name}; //instead exploitable eval("\$value = \$objItem->".$propItem->Name.";");
if (empty($strValue)) {
if (is_string($value)) $arrInstance[$propItem->Name] = trim($value);
else $arrInstance[$propItem->Name] = $value;
} else {
if (in_array($propItem->Name, $strValue)) {
if (is_string($value)) $arrInstance[$propItem->Name] = trim($value);
else $arrInstance[$propItem->Name] = $value;
}
}
}
$arrData[] = $arrInstance;
}
} catch (Exception $e) {
if (PSI_DEBUG) {
$error = Error::singleton();
$error->addError($e->getCode(), $e->getMessage());
}
// if (($separator !== '') && preg_match('/'.$separator.'[^'.$separator.']+'.$separator.'/', $out)) {
if (($separator !== '') && preg_match('/'.$separator.'[\s\S]+'.$separator.'/', $out)) {
fwrite($pipes[0], "quit\n");
$separator = ''; //only one time
// $te = true;
// break;
}
}
return $arrData;
return $te;
}
/**
@@ -560,4 +786,111 @@ class CommonFunctions
return array();
}
}
/**
* name natural compare function
*
* @return comprasion result
*/
public static function name_natural_compare($a, $b)
{
return strnatcmp($a->getName(), $b->getName());
}
/**
* get virtualizer from dmi data
*
* @return string|null
*/
public static function decodevirtualizer($vendor_data)
{
if (gettype($vendor_data) === "array") {
$vendarray = array(
'KVM' => 'kvm', // KVM
'OpenStack' => 'kvm', // Detect OpenStack instance as KVM in non x86 architecture
'KubeVirt' => 'kvm', // Detect KubeVirt instance as KVM in non x86 architecture
'Amazon EC2' => 'amazon', // Amazon EC2 Nitro using Linux KVM
'QEMU' => 'qemu', // QEMU
'VMware' => 'vmware', // VMware https://kb.vmware.com/s/article/1009458
'VMW' => 'vmware',
'innotek GmbH' => 'oracle', // Oracle VM VirtualBox
'VirtualBox' => 'oracle',
'Xen' => 'xen', // Xen hypervisor
'Bochs' => 'bochs', // Bochs
'Parallels' => 'parallels', // Parallels
// https://wiki.freebsd.org/bhyve
'BHYVE' => 'bhyve', // bhyve
'Hyper-V' => 'microsoft', // Hyper-V
'Apple Virtualization' => 'apple', // Apple Virtualization.framework guests
'Microsoft Corporation Virtual Machine' => 'microsoft' // Hyper-V
);
for ($i = 0; $i < count($vendor_data); $i++) {
foreach ($vendarray as $vend=>$virt) {
if (preg_match('/^'.$vend.'/', $vendor_data[$i])) {
return $virt;
}
}
}
} elseif (gettype($vendor_data) === "string") {
$vidarray = array(
'bhyvebhyve' => 'bhyve', // bhyve
'KVMKVMKVM' => 'kvm', // KVM
'LinuxKVMHv' => 'hv-kvm', // KVM (KVM + HyperV Enlightenments)
'MicrosoftHv' => 'microsoft', // Hyper-V
'lrpepyhvr' => 'parallels', // Parallels
'UnisysSpar64' => 'spar', // Unisys sPar
'VMwareVMware' => 'vmware', // VMware
'XenVMMXenVMM' => 'xen', // Xen hypervisor
'ACRNACRNACRN' => 'acrn', // ACRN hypervisor
'TCGTCGTCGTCG' => 'qemu', // QEMU
'QNXQVMBSQG' => 'qnx', // QNX hypervisor
'VBoxVBoxVBox' => 'oracle', // Oracle VM VirtualBox
'SRESRESRESRE' => 'sre' // LMHS SRE hypervisor
);
$shortvendorid = trim(preg_replace('/[\s!\.]/', '', $vendor_data));
if (($shortvendorid !== "") && isset($vidarray[$shortvendorid])) {
return $vidarray[$shortvendorid];
}
}
return null;
}
/**
* readdmimemdata function
*
* @return array
*/
public static function readdmimemdata()
{
if ((PSI_OS != 'WINNT') && (!defined('PSI_EMU_HOSTNAME') || defined('PSI_EMU_PORT')) && (self::$_dmimd === null)) {
self::$_dmimd = array();
$buffer = '';
if (defined('PSI_DMIDECODE_ACCESS') && (strtolower(PSI_DMIDECODE_ACCESS)==='data')) {
self::rftsdata('dmidecode.tmp', $buffer);
} elseif (self::_findProgram('dmidecode')) {
self::executeProgram('dmidecode', '-t 17', $buffer, PSI_DEBUG);
}
if (!empty($buffer)) {
$banks = preg_split('/^(?=Handle\s)/m', $buffer, -1, PREG_SPLIT_NO_EMPTY);
foreach ($banks as $bank) if (preg_match('/^Handle\s/', $bank)) {
$lines = preg_split("/\n/", $bank, -1, PREG_SPLIT_NO_EMPTY);
$mem = array();
foreach ($lines as $line) if (preg_match('/^\s+([^:]+):(.+)/', $line, $params)) {
if (preg_match('/^0x([A-F\d]+)/', $params2 = trim($params[2]), $buff)) {
$mem[trim($params[1])] = trim($buff[1]);
} elseif ($params2 != '') {
$mem[trim($params[1])] = $params2;
}
}
if (!empty($mem)) {
self::$_dmimd[] = $mem;
}
}
}
}
return self::$_dmimd;
}
}

View File

@@ -8,7 +8,7 @@
* @package PSI
* @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 SVN: $Id: class.Parser.inc.php 604 2012-07-10 07:31:34Z namiltd $
* @link http://phpsysinfo.sourceforge.net
*/
@@ -19,7 +19,7 @@
* @package PSI
* @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
*/
@@ -28,22 +28,44 @@ class Parser
/**
* parsing the output of lspci command
*
* @return Array
* @param bool $debug
* @return array
*/
public static function lspci($debug = PSI_DEBUG)
{
$arrResults = array();
if (CommonFunctions::executeProgram("lspci", "", $strBuf, $debug)) {
if (CommonFunctions::executeProgram("lspci", (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS)?"-m":"", $strBuf, $debug)) {
$arrLines = preg_split("/\n/", $strBuf, -1, PREG_SPLIT_NO_EMPTY);
foreach ($arrLines as $strLine) {
$arrParams = preg_split('/ /', trim($strLine), 2);
if (count($arrParams) == 2)
$strName = $arrParams[1];
else
$strName = "unknown";
$strName = preg_replace('/\(.*\)/', '', $strName);
$dev = new HWDevice();
$dev->setName($strName);
$arrParams = preg_split('/(\"? ")|(\" (?=-))/', trim($strLine));
if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS && ($cp = count($arrParams)) >= 6) {
$arrParams[$cp-1] = trim($arrParams[$cp-1], '"'); // remove last "
$dev->setName($arrParams[1].': '.$arrParams[2].' '.$arrParams[3]);
if (preg_match('/^-/', $arrParams[4])) {
if (($arrParams[5] !== "") && !preg_match('/^Unknown vendor/', $arrParams[5])) {
$dev->setManufacturer(trim($arrParams[5]));
}
if (($arrParams[6] !== "") && !preg_match('/^Device /', $arrParams[6])) {
$dev->setProduct(trim($arrParams[6]));
}
} else {
if (($arrParams[4] !== "") && !preg_match('/^Unknown vendor/', $arrParams[4])) {
$dev->setManufacturer(trim($arrParams[4]));
}
if (($arrParams[5] !== "") && !preg_match('/^Device /', $arrParams[5])) {
$dev->setProduct(trim($arrParams[5]));
}
}
} else {
$strLine=trim(preg_replace('/(")|( -\S+)/', '', $strLine));
$arrParams = preg_split('/ /', trim($strLine), 2);
if (count($arrParams) == 2)
$strName = preg_replace('/\(rev\s[^\)]+\)/', '', $arrParams[1]);
else
$strName = "unknown";
$dev->setName($strName);
}
$arrResults[] = $dev;
}
}
@@ -54,48 +76,66 @@ class Parser
/**
* parsing the output of df command
*
* @param string $df_param additional parameter for df command
* @param string $df_param additional parameter for df command
* @param bool $get_inodes
*
* @return array
*/
public static function df($df_param = "")
public static function df($df_param = "", $get_inodes = true)
{
$arrResult = array();
if (CommonFunctions::executeProgram('mount', '', $mount, PSI_DEBUG)) {
$mount = preg_split("/\n/", $mount, -1, PREG_SPLIT_NO_EMPTY);
foreach ($mount as $mount_line) {
if (preg_match("/(\S+) on ([\S ]+) type (.*) \((.*)\)/", $mount_line, $mount_buf)) {
$mount_parm[$mount_buf[2]]['fstype'] = $mount_buf[3];
$mount_parm[$mount_buf[2]]['name'] = $mount_buf[1];
if (PSI_SHOW_MOUNT_OPTION) $mount_parm[$mount_buf[2]]['options'] = $mount_buf[4];
$parm = array();
$parm['mountpoint'] = trim($mount_buf[2]);
$parm['fstype'] = $mount_buf[3];
$parm['name'] = $mount_buf[1];
if (PSI_SHOW_MOUNT_OPTION) $parm['options'] = $mount_buf[4];
$mount_parm[] = $parm;
} elseif (preg_match("/(\S+) is (.*) mounted on (\S+) \(type (.*)\)/", $mount_line, $mount_buf)) {
$mount_parm[$mount_buf[3]]['fstype'] = $mount_buf[4];
$mount_parm[$mount_buf[3]]['name'] = $mount_buf[1];
if (PSI_SHOW_MOUNT_OPTION) $mount_parm[$mount_buf[3]]['options'] = $mount_buf[2];
$parm = array();
$parm['mountpoint'] = trim($mount_buf[3]);
$parm['fstype'] = $mount_buf[4];
$parm['name'] = $mount_buf[1];
if (PSI_SHOW_MOUNT_OPTION) $parm['options'] = $mount_buf[2];
$mount_parm[] = $parm;
} elseif (preg_match("/(\S+) (.*) on (\S+) \((.*)\)/", $mount_line, $mount_buf)) {
$mount_parm[$mount_buf[3]]['fstype'] = $mount_buf[2];
$mount_parm[$mount_buf[3]]['name'] = $mount_buf[1];
if (PSI_SHOW_MOUNT_OPTION) $mount_parm[$mount_buf[3]]['options'] = $mount_buf[4];
$parm = array();
$parm['mountpoint'] = trim($mount_buf[3]);
$parm['fstype'] = $mount_buf[2];
$parm['name'] = $mount_buf[1];
if (PSI_SHOW_MOUNT_OPTION) $parm['options'] = $mount_buf[4];
$mount_parm[] = $parm;
} elseif (preg_match("/(\S+) on ([\S ]+) \((\S+)(,\s(.*))?\)/", $mount_line, $mount_buf)) {
$mount_parm[$mount_buf[2]]['fstype'] = $mount_buf[3];
$mount_parm[$mount_buf[2]]['name'] = $mount_buf[1];
if (PSI_SHOW_MOUNT_OPTION) $mount_parm[$mount_buf[2]]['options'] = isset($mount_buf[5]) ? $mount_buf[5] : '';
$parm = array();
$parm['mountpoint'] = trim($mount_buf[2]);
$parm['fstype'] = $mount_buf[3];
$parm['name'] = $mount_buf[1];
if (PSI_SHOW_MOUNT_OPTION) $parm['options'] = isset($mount_buf[5]) ? $mount_buf[5] : '';
$mount_parm[] = $parm;
}
}
} elseif (CommonFunctions::rfts("/etc/mtab", $mount)) {
} elseif (CommonFunctions::rfts(((PSI_ROOT_FILESYSTEM === '')||(PSI_OS !== 'Linux'))?"/etc/mtab":"/proc/1/mounts", $mount)) {
$mount = preg_split("/\n/", $mount, -1, PREG_SPLIT_NO_EMPTY);
foreach ($mount as $mount_line) {
if (preg_match("/(\S+) (\S+) (\S+) (\S+) ([0-9]+) ([0-9]+)/", $mount_line, $mount_buf)) {
$parm = array();
$mount_point = preg_replace("/\\\\040/i", ' ', $mount_buf[2]); //space as \040
$mount_parm[$mount_point]['fstype'] = $mount_buf[3];
$mount_parm[$mount_point]['name'] = $mount_buf[1];
if (PSI_SHOW_MOUNT_OPTION) $mount_parm[$mount_point]['options'] = $mount_buf[4];
$parm['mountpoint'] = $mount_point;
$parm['fstype'] = $mount_buf[3];
$parm['name'] = $mount_buf[1];
if (PSI_SHOW_MOUNT_OPTION) $parm['options'] = $mount_buf[4];
$mount_parm[] = $parm;
}
}
}
if (CommonFunctions::executeProgram('df', '-k '.$df_param, $df, PSI_DEBUG)) {
$df = "";
CommonFunctions::executeProgram('df', '-k '.$df_param, $df, PSI_DEBUG);
if ($df!=="") {
$df = preg_split("/\n/", $df, -1, PREG_SPLIT_NO_EMPTY);
if (PSI_SHOW_INODES) {
if ($get_inodes && PSI_SHOW_INODES) {
if (CommonFunctions::executeProgram('df', '-i '.$df_param, $df2, PSI_DEBUG)) {
$df2 = preg_split("/\n/", $df2, -1, PREG_SPLIT_NO_EMPTY);
// Store inode use% in an associative array (df_inodes) for later use
@@ -133,13 +173,103 @@ class Parser
}
if (PSI_SHOW_MOUNT_POINT) $dev->setMountPoint($df_buf[5]);
if (isset($mount_parm[$df_buf[5]])) {
$dev->setFsType($mount_parm[$df_buf[5]]['fstype']);
$notwas = true;
if (isset($mount_parm)) {
foreach ($mount_parm as $mount_param) { //name and mountpoint find
if (($mount_param['name']===trim($df_buf[0])) && ($mount_param['mountpoint']===$df_buf[5])) {
$dev->setFsType($mount_param['fstype']);
if (PSI_SHOW_MOUNT_OPTION && (trim($mount_param['options'])!=="")) {
if (PSI_SHOW_MOUNT_CREDENTIALS) {
$dev->setOptions($mount_param['options']);
} else {
$mpo=$mount_param['options'];
$mpo=preg_replace('/(^guest,)|(^guest$)|(,guest$)/i', '', $mpo);
$mpo=preg_replace('/,guest,/i', ',', $mpo);
$mpo=preg_replace('/(^user=[^,]*,)|(^user=[^,]*$)|(,user=[^,]*$)/i', '', $mpo);
$mpo=preg_replace('/,user=[^,]*,/i', ',', $mpo);
$mpo=preg_replace('/(^username=[^,]*,)|(^username=[^,]*$)|(,username=[^,]*$)/i', '', $mpo);
$mpo=preg_replace('/,username=[^,]*,/i', ',', $mpo);
$mpo=preg_replace('/(^password=[^,]*,)|(^password=[^,]*$)|(,password=[^,]*$)/i', '', $mpo);
$mpo=preg_replace('/,password=[^,]*,/i', ',', $mpo);
$dev->setOptions($mpo);
}
}
$notwas = false;
break;
}
}
if ($notwas) foreach ($mount_parm as $mount_param) { //mountpoint find
if ($mount_param['mountpoint']===$df_buf[5]) {
$dev->setFsType($mount_param['fstype']);
if (PSI_SHOW_MOUNT_OPTION && (trim($mount_param['options'])!=="")) {
if (PSI_SHOW_MOUNT_CREDENTIALS) {
$dev->setOptions($mount_param['options']);
} else {
$mpo=$mount_param['options'];
$mpo=preg_replace('/(^guest,)|(^guest$)|(,guest$)/i', '', $mpo);
$mpo=preg_replace('/,guest,/i', ',', $mpo);
$mpo=preg_replace('/(^user=[^,]*,)|(^user=[^,]*$)|(,user=[^,]*$)/i', '', $mpo);
$mpo=preg_replace('/,user=[^,]*,/i', ',', $mpo);
$mpo=preg_replace('/(^username=[^,]*,)|(^username=[^,]*$)|(,username=[^,]*$)/i', '', $mpo);
$mpo=preg_replace('/,username=[^,]*,/i', ',', $mpo);
$mpo=preg_replace('/(^password=[^,]*,)|(^password=[^,]*$)|(,password=[^,]*$)/i', '', $mpo);
$mpo=preg_replace('/,password=[^,]*,/i', ',', $mpo);
$dev->setOptions($mpo);
}
}
$notwas = false;
break;
}
}
}
if ($notwas) {
$dev->setFsType('unknown');
}
if ($get_inodes && PSI_SHOW_INODES && isset($df_inodes[trim($df_buf[0])])) {
$dev->setPercentInodesUsed($df_inodes[trim($df_buf[0])]);
}
$arrResult[] = $dev;
}
}
}
} else {
if (isset($mount_parm)) {
foreach ($mount_parm as $mount_param) {
if (is_dir($mount_param['mountpoint'])) {
$total = disk_total_space($mount_param['mountpoint']);
if (($mount_param['fstype'] != 'none') && ($total > 0)) {
$dev = new DiskDevice();
$dev->setName($mount_param['name']);
$dev->setFsType($mount_param['fstype']);
if (PSI_SHOW_MOUNT_POINT) $dev->setMountPoint($mount_param['mountpoint']);
$dev->setTotal($total);
$free = disk_free_space($mount_param['mountpoint']);
if ($free > 0) {
$dev->setFree($free);
} else {
$free = 0;
}
if ($total > $free) $dev->setUsed($total - $free);
if (PSI_SHOW_MOUNT_OPTION) {
if (PSI_SHOW_MOUNT_CREDENTIALS) {
$dev->setOptions($mount_parm[$df_buf[5]]['options']);
$dev->setOptions($mount_param['options']);
} else {
$mpo=$mount_parm[$df_buf[5]]['options'];
$mpo=$mount_param['options'];
$mpo=preg_replace('/(^guest,)|(^guest$)|(,guest$)/i', '', $mpo);
$mpo=preg_replace('/,guest,/i', ',', $mpo);
@@ -156,56 +286,8 @@ class Parser
$dev->setOptions($mpo);
}
}
$arrResult[] = $dev;
}
if (PSI_SHOW_INODES && isset($df_inodes[trim($df_buf[0])])) {
$dev->setPercentInodesUsed($df_inodes[trim($df_buf[0])]);
}
$arrResult[] = $dev;
}
}
}
} else {
if (isset($mount_parm)) {
foreach ($mount_parm as $mount_point=>$mount_param) {
$total = disk_total_space($mount_point);
if (($mount_param['fstype'] != 'none') && ($total > 0)) {
$dev = new DiskDevice();
$dev->setName($mount_param['name']);
$dev->setFsType($mount_param['fstype']);
if (PSI_SHOW_MOUNT_POINT) $dev->setMountPoint($mount_point);
$dev->setTotal($total);
$free = disk_free_space($mount_point);
if ($free > 0) {
$dev->setFree($free);
} else {
$free = 0;
}
if ($total > $free) $dev->setUsed($total - $free);
if (PSI_SHOW_MOUNT_OPTION) {
if (PSI_SHOW_MOUNT_CREDENTIALS) {
$dev->setOptions($mount_param['options']);
} else {
$mpo=$mount_param['options'];
$mpo=preg_replace('/(^guest,)|(^guest$)|(,guest$)/i', '', $mpo);
$mpo=preg_replace('/,guest,/i', ',', $mpo);
$mpo=preg_replace('/(^user=[^,]*,)|(^user=[^,]*$)|(,user=[^,]*$)/i', '', $mpo);
$mpo=preg_replace('/,user=[^,]*,/i', ',', $mpo);
$mpo=preg_replace('/(^username=[^,]*,)|(^username=[^,]*$)|(,username=[^,]*$)/i', '', $mpo);
$mpo=preg_replace('/,username=[^,]*,/i', ',', $mpo);
$mpo=preg_replace('/(^password=[^,]*,)|(^password=[^,]*$)|(,password=[^,]*$)/i', '', $mpo);
$mpo=preg_replace('/,password=[^,]*,/i', ',', $mpo);
$dev->setOptions($mpo);
}
}
$arrResult[] = $dev;
}
}
}

View File

@@ -1,6 +1,6 @@
<?php
/**
* Error class
* PSI_Error class
*
* PHP version 5
*
@@ -8,7 +8,7 @@
* @package PSI_Error
* @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 SVN: $Id: class.Error.inc.php 569 2012-04-16 06:08:18Z namiltd $
* @link http://phpsysinfo.sourceforge.net
*/
@@ -19,17 +19,17 @@
* @package PSI_Error
* @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
*/
class Error
class PSI_Error
{
/**
* holds the instance of this class
*
* @static
* @var object
* @var PSI_Error
*/
private static $_instance;
@@ -59,7 +59,7 @@ class Error
/**
* Singleton function
*
* @return Error instance of the class
* @return PSI_Error instance of the class
*/
public static function singleton()
{
@@ -113,8 +113,8 @@ class Error
/**
* add a config error to the internal list
*
* @param object $strCommand Command, which cause the Error
* @param object $strMessage additional Message, to describe the Error
* @param string $strCommand Command, which cause the Error
* @param string $strMessage additional Message, to describe the Error
*
* @return void
*/
@@ -126,8 +126,8 @@ class Error
/**
* add a php error to the internal list
*
* @param object $strCommand Command, which cause the Error
* @param object $strMessage additional Message, to describe the Error
* @param string $strCommand Command, which cause the Error
* @param string $strMessage additional Message, to describe the Error
*
* @return void
*/
@@ -171,8 +171,8 @@ class Error
$error->addAttribute('Message', $arrLine['message']);
$error->addAttribute('Function', $arrLine['command']);
}
header("Cache-Control: no-cache, must-revalidate\n");
header("Content-Type: text/xml\n\n");
header('Cache-Control: no-cache, must-revalidate');
header('Content-Type: text/xml');
echo $xml->getSimpleXmlElement()->asXML();
exit();
}
@@ -229,7 +229,9 @@ class Error
if ($val == $arrTrace[count($arrTrace) - 1]) {
break;
}
$strBacktrace .= str_replace(APP_ROOT, ".", $val['file']).' on line '.$val['line'];
if (isset($val['file'])) {
$strBacktrace .= str_replace(PSI_APP_ROOT, ".", $val['file']).' on line '.$val['line'];
}
if ($strFunc) {
$strBacktrace .= ' in function '.$strFunc;
}
@@ -238,10 +240,14 @@ class Error
} else {
$strFunc = $val['function'].'(';
if (isset($val['args'][0])) {
if (($val['function'] == 'executeProgram') && ($val['args'][0] == 'sshpass')
&& isset($val['args'][1]) && preg_match('/"([^"]+)"$/', $val['args'][1], $tmpout)) {
$val['args'][1] = 'ssh: '. $tmpout[1];
}
$strFunc .= ' ';
$strComma = '';
foreach ($val['args'] as $val) {
$strFunc .= $strComma.$this->_printVar($val);
foreach ($val['args'] as $valArgs) {
$strFunc .= $strComma.$this->_printVar($valArgs);
$strComma = ', ';
}
$strFunc .= ' ';

View File

@@ -8,7 +8,7 @@
* @package PSI_Interfaces
* @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 SVN: $Id: class.PSI_Interface_OS.inc.php 263 2009-06-22 13:01:52Z bigmichi1 $
* @link http://phpsysinfo.sourceforge.net
*/
@@ -21,7 +21,7 @@
* @package PSI_Interfaces
* @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
*/
@@ -47,4 +47,11 @@ interface PSI_Interface_OS
* @return System
*/
public function getSys();
/**
* get os specific language
*
* @return string
*/
public function getLanguage();
}

View File

@@ -8,7 +8,7 @@
* @package PSI_Interfaces
* @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 SVN: $Id: class.PSI_Interface_Output.inc.php 214 2009-05-25 08:32:40Z bigmichi1 $
* @link http://phpsysinfo.sourceforge.net
*/
@@ -20,7 +20,7 @@
* @package PSI_Interfaces
* @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
*/

View File

@@ -8,7 +8,7 @@
* @package PSI_Interfaces
* @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 SVN: $Id: class.PSI_Interface_Plugin.inc.php 273 2009-06-24 11:40:09Z bigmichi1 $
* @link http://phpsysinfo.sourceforge.net
*/
@@ -21,7 +21,7 @@
* @package PSI_Interfaces
* @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
*/
@@ -37,7 +37,7 @@ interface PSI_Interface_Plugin
/**
* build the xml
*
* @return SimpleXMLObject entire XML content for the plugin which than can be appended to the main XML
* @return SimpleXMLElement entire XML content for the plugin which than can be appended to the main XML
*/
public function xml();
}

View File

@@ -8,7 +8,7 @@
* @package PSI_Interfaces
* @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 SVN: $Id: class.PSI_Interface_Sensor.inc.php 263 2009-06-22 13:01:52Z bigmichi1 $
* @link http://phpsysinfo.sourceforge.net
*/
@@ -21,7 +21,7 @@
* @package PSI_Interfaces
* @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
*/

View File

@@ -8,7 +8,7 @@
* @package PSI_Interfaces
* @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 SVN: $Id: class.PSI_Interface_UPS.inc.php 263 2009-06-22 13:01:52Z bigmichi1 $
* @link http://phpsysinfo.sourceforge.net
*/
@@ -20,7 +20,7 @@
* @package PSI_Interfaces
* @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
*/

View File

@@ -159,8 +159,9 @@ class JavaScriptPacker
{
$parser = new ParseMaster();
// replace: $name -> n, $$name -> na
$parser->add('/((\\x24+)([a-zA-Z$_]+))(\\d*)/',
array('fn' => '_replace_name')
$parser->add(
'/((\\x24+)([a-zA-Z$_]+))(\\d*)/',
array('fn' => '_replace_name')
);
// replace: _name -> _0, double-underscore (__name) is ignored
$regexp = '/\\b_[A-Za-z\\d]\\w*/';
@@ -169,7 +170,8 @@ class JavaScriptPacker
// quick ref
$encoded = $keywords['encoded'];
$parser->add($regexp,
$parser->add(
$regexp,
array(
'fn' => '_replace_encoded',
'data' => $encoded
@@ -194,7 +196,8 @@ class JavaScriptPacker
$encoded = $keywords['encoded'];
// encode
$parser->add($regexp,
$parser->add(
$regexp,
array(
'fn' => '_replace_encoded',
'data' => $encoded
@@ -521,7 +524,7 @@ class JavaScriptPacker
';
//};
/*
' if (!\'\'.replace(/^/, String)) {
' if (!\'\'.replace(/^/, String)) {
// decode all the values we need
while ($count--) $decode[$encode($count)] = $keywords[$count] || $encode($count);
// global replacement function

View File

@@ -1,62 +0,0 @@
<?php
/**
* coretemp sensor class
*
* PHP version 5
*
* @category PHP
* @package PSI_Sensor
* @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.coretemp.inc.php 661 2012-08-27 11:26:39Z namiltd $
* @link http://phpsysinfo.sourceforge.net
*/
/**
* getting hardware temperature information through sysctl
*
* @category PHP
* @package PSI_Sensor
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @author William Johansson <radar@radhuset.org>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @version Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
class Coretemp extends Sensors
{
/**
* get temperature information
*
* @return void
*/
private function _temperature()
{
$smp = 1;
CommonFunctions::executeProgram('sysctl', '-n kern.smp.cpus', $smp);
for ($i = 0; $i < $smp; $i++) {
$temp = 0;
if (CommonFunctions::executeProgram('sysctl', '-n dev.cpu.'.$i.'.temperature', $temp)) {
$temp = preg_replace('/C/', '', $temp);
$dev = new SensorDevice();
$dev->setName("CPU ".($i + 1));
$dev->setValue($temp);
$dev->setMax(70);
$this->mbinfo->setMbTemp($dev);
}
}
}
/**
* get the information
*
* @see PSI_Interface_Sensor::build()
*
* @return Void
*/
public function build()
{
$this->_temperature();
}
}

View File

@@ -0,0 +1,96 @@
<?php
/**
* cpumem sensor class, getting hardware sensors information of CPU and memory
*
* PHP version 5
*
* @category PHP
* @package PSI_Sensor
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @author William Johansson <radar@radhuset.org>
* @copyright 2009 phpSysInfo
* @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
*/
class CpuMem extends Hwmon
{
/**
* get the information
*
* @see PSI_Interface_Sensor::build()
*
* @return void
*/
public function build()
{
if ((PSI_OS == 'Linux') && !defined('PSI_EMU_HOSTNAME')) {
$hwpaths = CommonFunctions::findglob("/sys/devices/platform/coretemp.*/", GLOB_NOSORT);
if (is_array($hwpaths) && (count($hwpaths) > 0)) {
$hwpaths2 = CommonFunctions::findglob("/sys/devices/platform/coretemp.*/hwmon/hwmon*/", GLOB_NOSORT);
if (is_array($hwpaths2) && (count($hwpaths2) > 0)) {
$hwpaths = array_merge($hwpaths, $hwpaths2);
}
$totalh = count($hwpaths);
for ($h = 0; $h < $totalh; $h++) {
$this->_temperature($hwpaths[$h]);
}
}
} elseif (PSI_OS == 'FreeBSD') {
$smp = 1;
CommonFunctions::executeProgram('sysctl', '-n kern.smp.cpus', $smp);
for ($i = 0; $i < $smp; $i++) {
$temp = 0;
if (CommonFunctions::executeProgram('sysctl', '-n dev.cpu.'.$i.'.temperature', $temp)) {
$temp = preg_replace('/,/', '.', preg_replace('/C/', '', $temp));
$dev = new SensorDevice();
$dev->setName("CPU ".($i + 1));
$dev->setValue($temp);
// $dev->setMax(70);
$this->mbinfo->setMbTemp($dev);
}
}
} elseif ((PSI_OS == 'WINNT') || defined('PSI_EMU_HOSTNAME')) {
$allCpus = WINNT::_get_Win32_Processor();
foreach ($allCpus as $oneCpu) if (isset($oneCpu['CurrentVoltage']) && ($oneCpu['CurrentVoltage'] > 0)) {
$dev = new SensorDevice();
$dev->setName($oneCpu['DeviceID']);
$dev->setValue($oneCpu['CurrentVoltage']/10);
$this->mbinfo->setMbVolt($dev);
}
$allMems = WINNT::_get_Win32_PhysicalMemory();
$counter = 0;
foreach ($allMems as $oneMem) if (isset($oneMem['ConfiguredVoltage']) && ($oneMem['ConfiguredVoltage'] > 0)) {
$dev = new SensorDevice();
$dev->setName('Mem'.($counter++));
$dev->setValue($oneMem['ConfiguredVoltage']/1000);
if (isset($oneMem['MaxVoltage']) && ($oneMem['MaxVoltage'] > 0)) {
$dev->setMax($oneMem['MaxVoltage']/1000);
}
if (isset($oneMem['MinVoltage']) && ($oneMem['MinVoltage'] > 0)) {
$dev->setMin($oneMem['MinVoltage']/1000);
}
$this->mbinfo->setMbVolt($dev);
}
}
if ((PSI_OS != 'WINNT') && (!defined('PSI_EMU_HOSTNAME') || defined('PSI_EMU_PORT'))) {
$dmimd = CommonFunctions::readdmimemdata();
$counter = 0;
foreach ($dmimd as $mem) {
if (isset($mem['Size']) && preg_match('/^(\d+)\s(M|G)B$/', $mem['Size'], $size) && ($size[1] > 0)
&& isset($mem['Configured Voltage']) && preg_match('/^([\d\.]+)\sV$/', $mem['Configured Voltage'], $voltage) && ($voltage[1] > 0)) {
$dev = new SensorDevice();
$dev->setName('Mem'.($counter++));
$dev->setValue($voltage[1]);
if (isset($mem['Minimum Voltage']) && preg_match('/^([\d\.]+)\sV$/', $mem['Minimum Voltage'], $minv) && ($minv[1] > 0)) {
$dev->setMin($minv[1]);
}
if (isset($mem['Maximum Voltage']) && preg_match('/^([\d\.]+)\sV$/', $mem['Maximum Voltage'], $maxv) && ($maxv[1] > 0)) {
$dev->setMax($maxv[1]);
}
$this->mbinfo->setMbVolt($dev);
}
}
}
}
}

View File

@@ -0,0 +1,122 @@
<?php
/**
* fortisensor sensor class, getting hardware sensors information from Fortinet devices
*
* PHP version 5
*
* @category PHP
* @package PSI_Sensor
* @author Mieczyslaw Nalewaj <namiltd@users.sourceforge.net>
* @copyright 2022 phpSysInfo
* @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
*/
class FortiSensor extends Sensors
{
/**
* content to parse
*
* @var array
*/
private $_lines = array();
/**
* fill the private array
*/
public function __construct()
{
parent::__construct();
$lines = "";
if (defined('PSI_EMU_PORT') && CommonFunctions::executeProgram('execute', 'sensor list', $resulte, false) && ($resulte !== "")
&& preg_match('/^(.*[\$#]\s*)/', $resulte, $resulto, PREG_OFFSET_CAPTURE)) {
$resulti = substr($resulte, strlen($resulto[1][0]));
if (preg_match('/(\n.*[\$#])$/', $resulti, $resulto, PREG_OFFSET_CAPTURE)) {
$lines = substr($resulti, 0, $resulto[1][1]);
}
}
$this->_lines = preg_split("/\n/", $lines, -1, PREG_SPLIT_NO_EMPTY);
}
/**
* get temperature information
*
* @return void
*/
private function _temperature()
{
foreach ($this->_lines as $line) {
if (preg_match('/^\s*\d+\s(.+)\sTemperature\s+([\d\.]+)\s\S*C\s*$/', $line, $data)) {
$dev = new SensorDevice();
$dev->setName($data[1]);
$dev->setValue($data[2]);
$this->mbinfo->setMbTemp($dev);
} elseif (preg_match('/^\s*\d+\s(.+)\s+alarm=(\d)\s+value=(\d+)\s/', $line, $data)
&& !preg_match('/fan| vin/i', $data[1])) {
$dev = new SensorDevice();
$dev->setName(trim($data[1]));
$dev->setValue($data[3]);
if ($data[2] != 0) {
$dev->setEvent("Alarm");
}
$this->mbinfo->setMbTemp($dev);
}
}
}
/**
* get voltage information
*
* @return void
*/
private function _voltage()
{
foreach ($this->_lines as $line) {
if (preg_match('/^\s*\d+\s(.+)\s+alarm=(\d)\s+value=([\d\.]+)\s/', $line, $data)
&& preg_match('/\./', $data[3])
&& !preg_match('/fan|temp/i', $data[1])) {
$dev = new SensorDevice();
$dev->setName(trim($data[1]));
$dev->setValue($data[3]);
if ($data[2] != 0) {
$dev->setEvent("Alarm");
}
$this->mbinfo->setMbVolt($dev);
}
}
}
/**
* get fan information
*
* @return void
*/
private function _fans()
{
foreach ($this->_lines as $line) {
if (preg_match('/^\s*\d+\s(.+)\s+alarm=(\d)\s+value=(\d+)\s/', $line, $data)
&& preg_match('/fan/i', $data[1])) {
$dev = new SensorDevice();
$dev->setName(trim($data[1]));
$dev->setValue($data[3]);
if ($data[2] != 0) {
$dev->setEvent("Alarm");
}
$this->mbinfo->setMbFan($dev);
}
}
}
/**
* get the information
*
* @see PSI_Interface_Sensor::build()
*
* @return void
*/
public function build()
{
$this->_temperature();
$this->_voltage();
$this->_fans();
}
}

View File

@@ -1,25 +1,14 @@
<?php
/**
* freeipmi sensor class
* freeipmi sensor class, getting information from ipmi-sensors
*
* PHP version 5
*
* @category PHP
* @package PSI_Sensor
* @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.freeipmi.inc.php 661 2012-08-27 11:26:39Z namiltd $
* @link http://phpsysinfo.sourceforge.net
*/
/**
* getting information from ipmi-sensors
*
* @category PHP
* @package PSI_Sensor
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @author Mieczyslaw Nalewaj <namiltd@users.sourceforge.net>
* @copyright 2014 phpSysInfo
* @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
*/
@@ -33,24 +22,23 @@ class FreeIPMI extends Sensors
private $_lines = array();
/**
* fill the private content var through tcp or file access
* fill the private content var through command or data access
*/
public function __construct()
{
parent::__construct();
switch (strtolower(PSI_SENSOR_ACCESS)) {
if ((PSI_OS != 'WINNT') && (!defined('PSI_EMU_HOSTNAME') || defined('PSI_EMU_PORT'))) switch (defined('PSI_SENSOR_FREEIPMI_ACCESS')?strtolower(PSI_SENSOR_FREEIPMI_ACCESS):'command') {
case 'command':
CommonFunctions::executeProgram('ipmi-sensors', '--output-sensor-thresholds', $lines);
$this->_lines = preg_split("/\n/", $lines, -1, PREG_SPLIT_NO_EMPTY);
$this->_lines = preg_split("/\r?\n/", $lines, -1, PREG_SPLIT_NO_EMPTY);
break;
case 'file':
if (CommonFunctions::rfts(APP_ROOT.'/data/freeipmi.txt', $lines)) {
$this->_lines = preg_split("/\n/", $lines, -1, PREG_SPLIT_NO_EMPTY);
case 'data':
if (!defined('PSI_EMU_PORT') && CommonFunctions::rftsdata('freeipmi.tmp', $lines)) {
$this->_lines = preg_split("/\r?\n/", $lines, -1, PREG_SPLIT_NO_EMPTY);
}
break;
default:
$this->error->addConfigError('__construct()', 'PSI_SENSOR_ACCESS');
break;
$this->error->addConfigError('__construct()', '[sensor_freeipmi] ACCESS');
}
}
@@ -152,6 +140,7 @@ class FreeIPMI extends Sensors
$dev = new SensorDevice();
$dev->setName($buffer[1]);
$dev->setValue($buffer[3]);
if ($buffer[6] != "N/A") $dev->setMin($buffer[6]);
if ($buffer[9] != "N/A") $dev->setMax($buffer[9]);
if ($buffer[11] != "'OK'") $dev->setEvent(trim($buffer[11], "'"));
$this->mbinfo->setMbCurrent($dev);
@@ -159,12 +148,31 @@ class FreeIPMI extends Sensors
}
}
/**
* get other information
*
* @return void
*/
private function _other()
{
foreach ($this->_lines as $line) {
$buffer = preg_split("/\s*\|\s*/", $line);
if ($buffer[4] == "N/A"
&& $buffer[2] != "OEM Reserved" && $buffer[11] != "N/A") {
$dev = new SensorDevice();
$dev->setName($buffer[1].' ('.$buffer[2].')');
$dev->setValue(trim($buffer[11], '\''));
$this->mbinfo->setMbOther($dev);
}
}
}
/**
* get the information
*
* @see PSI_Interface_Sensor::build()
*
* @return Void
* @return void
*/
public function build()
{
@@ -173,5 +181,6 @@ class FreeIPMI extends Sensors
$this->_fans();
$this->_power();
$this->_current();
$this->_other();
}
}

View File

@@ -1,26 +1,15 @@
<?php
/**
* hddtemp sensor class
* hddtemp sensor class, getting information from hddtemp
*
* PHP version 5
*
* @category PHP
* @package PSI_Sensor
* @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.hddtemp.inc.php 661 2012-08-27 11:26:39Z namiltd $
* @link http://phpsysinfo.sourceforge.net
*/
/**
* getting information from hddtemp
*
* @category PHP
* @package PSI_Sensor
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @author T.A. van Roermund <timo@van-roermund.nl>
* @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
*/
@@ -30,16 +19,16 @@ class HDDTemp extends Sensors
* get the temperature information from hddtemp
* access is available through tcp or command
*
* @return array temperatures in array
* @return void
*/
private function _temperature()
{
$ar_buf = array();
switch (strtolower(PSI_HDD_TEMP)) {
case "tcp":
if ((PSI_OS == 'Linux') && (!defined('PSI_EMU_HOSTNAME') || defined('PSI_EMU_PORT'))) switch (defined('PSI_SENSOR_HDDTEMP_ACCESS')?strtolower(PSI_SENSOR_HDDTEMP_ACCESS):'command') {
case 'tcp':
$lines = '';
// Timo van Roermund: connect to the hddtemp daemon, use a 5 second timeout.
$fp = @fsockopen('localhost', 7634, $errno, $errstr, 5);
$fp = @fsockopen(defined('PSI_EMU_HOSTNAME')?PSI_EMU_HOSTNAME:'localhost', 7634, $errno, $errstr, 5);
// if connected, read the output of the hddtemp daemon
if ($fp) {
while (!feof($fp)) {
@@ -52,7 +41,7 @@ class HDDTemp extends Sensors
$lines = str_replace("||", "|\n|", $lines);
$ar_buf = preg_split("/\n/", $lines, -1, PREG_SPLIT_NO_EMPTY);
break;
case "command":
case 'command':
$strDrives = "";
$strContent = "";
$hddtemp_value = "";
@@ -100,8 +89,7 @@ class HDDTemp extends Sensors
}
break;
default:
$this->error->addConfigError("temperature()", "PSI_HDD_TEMP");
break;
$this->error->addConfigError("temperature()", "[sensor_hddtemp] ACCESS");
}
// Timo van Roermund: parse the info from the hddtemp daemon.
foreach ($ar_buf as $line) {
@@ -114,7 +102,7 @@ class HDDTemp extends Sensors
if (is_numeric($data[3])) {
$dev->setValue($data[3]);
}
$dev->setMax(60);
// $dev->setMax(60);
$this->mbinfo->setMbTemp($dev);
}
}
@@ -126,7 +114,7 @@ class HDDTemp extends Sensors
*
* @see PSI_Interface_Sensor::build()
*
* @return Void
* @return void
*/
public function build()
{

View File

@@ -1,6 +1,6 @@
<?php
/**
* healthd sensor class
* healthd sensor class, getting information from healthd
*
* PHP version 5
*
@@ -8,18 +8,7 @@
* @package PSI_Sensor
* @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.healthd.inc.php 661 2012-08-27 11:26:39Z namiltd $
* @link http://phpsysinfo.sourceforge.net
*/
/**
* getting information from healthd
*
* @category PHP
* @package PSI_Sensor
* @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
*/
@@ -30,28 +19,33 @@ class Healthd extends Sensors
*
* @var array
*/
private $_lines = array();
private $_values = array();
/**
* fill the private content var through tcp or file access
* fill the private content var through command or data access
*/
public function __construct()
{
parent::__construct();
switch (strtolower(PSI_SENSOR_ACCESS)) {
if (PSI_OS == 'FreeBSD') switch (defined('PSI_SENSOR_HEALTHD_ACCESS')?strtolower(PSI_SENSOR_HEALTHD_ACCESS):'command') {
case 'command':
$lines = "";
CommonFunctions::executeProgram('healthdc', '-t', $lines);
$this->_lines = preg_split("/\n/", $lines, -1, PREG_SPLIT_NO_EMPTY);
if (CommonFunctions::executeProgram('healthdc', '-t', $lines)) {
$lines0 = preg_split("/\n/", $lines, 1, PREG_SPLIT_NO_EMPTY);
if (count($lines0) == 1) {
$this->_values = preg_split("/\t+/", $lines0[0]);
}
}
break;
case 'file':
if (CommonFunctions::rfts(APP_ROOT.'/data/healthd.txt', $lines)) {
$this->_lines = preg_split("/\n/", $lines, -1, PREG_SPLIT_NO_EMPTY);
case 'data':
if (!defined('PSI_EMU_PORT') && CommonFunctions::rftsdata('healthd.tmp', $lines)) {
$lines0 = preg_split("/\n/", $lines, 1, PREG_SPLIT_NO_EMPTY);
if (count($lines0) == 1) {
$this->_values = preg_split("/\t+/", $lines0[0]);
}
}
break;
default:
$this->error->addConfigError('__construct()', 'PSI_SENSOR_ACCESS');
break;
$this->error->addConfigError('__construct()', '[sensor_healthd] ACCESS');
}
}
@@ -62,22 +56,23 @@ class Healthd extends Sensors
*/
private function _temperature()
{
$ar_buf = preg_split("/\t+/", $this->_lines);
$dev1 = new SensorDevice();
$dev1->setName('temp1');
$dev1->setValue($ar_buf[1]);
$dev1->setMax(70);
$this->mbinfo->setMbTemp($dev1);
$dev2 = new SensorDevice();
$dev2->setName('temp1');
$dev2->setValue($ar_buf[2]);
$dev2->setMax(70);
$this->mbinfo->setMbTemp($dev2);
$dev3 = new SensorDevice();
$dev3->setName('temp1');
$dev3->setValue($ar_buf[3]);
$dev3->setMax(70);
$this->mbinfo->setMbTemp($dev3);
if (count($this->_values) == 14) {
$dev1 = new SensorDevice();
$dev1->setName('temp1');
$dev1->setValue($this->_values[1]);
// $dev1->setMax(70);
$this->mbinfo->setMbTemp($dev1);
$dev2 = new SensorDevice();
$dev2->setName('temp1');
$dev2->setValue($this->_values[2]);
// $dev2->setMax(70);
$this->mbinfo->setMbTemp($dev2);
$dev3 = new SensorDevice();
$dev3->setName('temp1');
$dev3->setValue($this->_values[3]);
// $dev3->setMax(70);
$this->mbinfo->setMbTemp($dev3);
}
}
/**
@@ -87,60 +82,62 @@ class Healthd extends Sensors
*/
private function _fans()
{
$ar_buf = preg_split("/\t+/", $this->_lines);
$dev1 = new SensorDevice();
$dev1->setName('fan1');
$dev1->setValue($ar_buf[4]);
$dev1->setMin(3000);
$this->mbinfo->setMbFan($dev1);
$dev2 = new SensorDevice();
$dev2->setName('fan2');
$dev2->setValue($ar_buf[5]);
$dev2->setMin(3000);
$this->mbinfo->setMbFan($dev2);
$dev3 = new SensorDevice();
$dev3->setName('fan3');
$dev3->setValue($ar_buf[6]);
$dev3->setMin(3000);
$this->mbinfo->setMbFan($dev3);
if (count($this->_values) == 14) {
$dev1 = new SensorDevice();
$dev1->setName('fan1');
$dev1->setValue($this->_values[4]);
// $dev1->setMin(3000);
$this->mbinfo->setMbFan($dev1);
$dev2 = new SensorDevice();
$dev2->setName('fan2');
$dev2->setValue($this->_values[5]);
// $dev2->setMin(3000);
$this->mbinfo->setMbFan($dev2);
$dev3 = new SensorDevice();
$dev3->setName('fan3');
$dev3->setValue($this->_values[6]);
// $dev3->setMin(3000);
$this->mbinfo->setMbFan($dev3);
}
}
/**
* get voltage information
*
* @return array voltage in array with lable
* @return void
*/
private function _voltage()
{
$ar_buf = preg_split("/\t+/", $this->_lines);
$dev1 = new SensorDevice();
$dev1->setName('Vcore1');
$dev1->setValue($ar_buf[7]);
$this->mbinfo->setMbVolt($dev1);
$dev2 = new SensorDevice();
$dev2->setName('Vcore2');
$dev2->setValue($ar_buf[8]);
$this->mbinfo->setMbVolt($dev2);
$dev3 = new SensorDevice();
$dev3->setName('3volt');
$dev3->setValue($ar_buf[9]);
$this->mbinfo->setMbVolt($dev3);
$dev4 = new SensorDevice();
$dev4->setName('+5Volt');
$dev4->setValue($ar_buf[10]);
$this->mbinfo->setMbVolt($dev4);
$dev5 = new SensorDevice();
$dev5->setName('+12Volt');
$dev5->setValue($ar_buf[11]);
$this->mbinfo->setMbVolt($dev5);
$dev6 = new SensorDevice();
$dev6->setName('-12Volt');
$dev6->setValue($ar_buf[12]);
$this->mbinfo->setMbVolt($dev6);
$dev7 = new SensorDevice();
$dev7->setName('-5Volt');
$dev7->setValue($ar_buf[13]);
$this->mbinfo->setMbVolt($dev7);
if (count($this->_values) == 14) {
$dev1 = new SensorDevice();
$dev1->setName('Vcore1');
$dev1->setValue($this->_values[7]);
$this->mbinfo->setMbVolt($dev1);
$dev2 = new SensorDevice();
$dev2->setName('Vcore2');
$dev2->setValue($this->_values[8]);
$this->mbinfo->setMbVolt($dev2);
$dev3 = new SensorDevice();
$dev3->setName('3volt');
$dev3->setValue($this->_values[9]);
$this->mbinfo->setMbVolt($dev3);
$dev4 = new SensorDevice();
$dev4->setName('+5Volt');
$dev4->setValue($this->_values[10]);
$this->mbinfo->setMbVolt($dev4);
$dev5 = new SensorDevice();
$dev5->setName('+12Volt');
$dev5->setValue($this->_values[11]);
$this->mbinfo->setMbVolt($dev5);
$dev6 = new SensorDevice();
$dev6->setName('-12Volt');
$dev6->setValue($this->_values[12]);
$this->mbinfo->setMbVolt($dev6);
$dev7 = new SensorDevice();
$dev7->setName('-5Volt');
$dev7->setValue($this->_values[13]);
$this->mbinfo->setMbVolt($dev7);
}
}
/**
@@ -148,7 +145,7 @@ class Healthd extends Sensors
*
* @see PSI_Interface_Sensor::build()
*
* @return Void
* @return void
*/
public function build()
{

View File

@@ -0,0 +1,267 @@
<?php
/**
* hwmon sensor class, getting hardware sensors information from /sys/class/hwmon/hwmon
*
* PHP version 5
*
* @category PHP
* @package PSI_Sensor
* @author Mieczyslaw Nalewaj <namiltd@users.sourceforge.net>
* @copyright 2016 phpSysInfo
* @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
*/
class Hwmon extends Sensors
{
/**
* get temperature information
*
* @param string $hwpath
* @return void
*/
protected function _temperature($hwpath)
{
$sensor = CommonFunctions::findglob($hwpath."temp*_input", GLOB_NOSORT);
if (is_array($sensor) && (($total = count($sensor)) > 0)) {
$buf = "";
for ($i = 0; $i < $total; $i++) if (($buf = CommonFunctions::rolv($sensor[$i]))!==null) {
$dev = new SensorDevice();
$dev->setValue($buf/1000);
if (($buf = CommonFunctions::rolv($sensor[$i], "/\/[^\/]*_input$/", "/name"))!==null) {
$name = " (".$buf.")";
} else {
$name = "";
}
if (($buf = CommonFunctions::rolv($sensor[$i], "/_input$/", "_label"))!==null) {
$dev->setName($buf.$name);
} else {
$labelname = trim(preg_replace("/_input$/", "", pathinfo($sensor[$i], PATHINFO_BASENAME)));
if (($name == " (drivetemp)") && (count($buf = CommonFunctions::gdc($hwpath . "device/block", false)))) {
$labelname = "/dev/" . $buf[0];
if (($buf = CommonFunctions::rolv($hwpath . "device/model"))!==null) {
$labelname .= " (".$buf.")";
$name = "";
}
}
if ($labelname !== "") {
$dev->setName($labelname.$name);
} else {
$dev->setName('unknown'.$name);
}
}
if (($buf = CommonFunctions::rolv($sensor[$i], "/_input$/", "_crit"))!==null) {
$dev->setMax($buf/1000);
if (CommonFunctions::rolv($sensor[$i], "/_input$/", "_crit_alarm")==="1") {
$dev->setEvent("Critical Alarm");
}
} elseif (($buf = CommonFunctions::rolv($sensor[$i], "/_input$/", "_max"))!==null) {
$dev->setMax($buf/1000);
}
$this->mbinfo->setMbTemp($dev);
}
}
}
/**
* get voltage information
*
* @param string $hwpath
* @return void
*/
private function _voltage($hwpath)
{
$sensor = CommonFunctions::findglob($hwpath."in*_input", GLOB_NOSORT);
if (is_array($sensor) && (($total = count($sensor)) > 0)) {
$buf = "";
for ($i = 0; $i < $total; $i++) if (($buf = CommonFunctions::rolv($sensor[$i]))!==null) {
$dev = new SensorDevice();
$dev->setValue($buf/1000);
if (($buf = CommonFunctions::rolv($sensor[$i], "/\/[^\/]*_input$/", "/name"))!==null) {
$name = " (".$buf.")";
} else {
$name = "";
}
if (($buf = CommonFunctions::rolv($sensor[$i], "/_input$/", "_label"))!==null) {
$dev->setName($buf.$name);
} else {
$labelname = trim(preg_replace("/_input$/", "", pathinfo($sensor[$i], PATHINFO_BASENAME)));
if ($labelname !== "") {
$dev->setName($labelname.$name);
} else {
$dev->setName('unknown'.$name);
}
}
if (($buf = CommonFunctions::rolv($sensor[$i], "/_input$/", "_max"))!==null) {
$dev->setMax($buf/1000);
}
if (($buf = CommonFunctions::rolv($sensor[$i], "/_input$/", "_min"))!==null) {
$dev->setMin($buf/1000);
}
if (($buf = CommonFunctions::rolv($sensor[$i], "/_input$/", "_alarm"))==="1") {
$dev->setEvent("Alarm");
}
$this->mbinfo->setMbVolt($dev);
}
}
}
/**
* get fan information
*
* @param string $hwpath
* @return void
*/
protected function _fans($hwpath)
{
$sensor = CommonFunctions::findglob($hwpath."fan*_input", GLOB_NOSORT);
if (is_array($sensor) && (($total = count($sensor)) > 0)) {
$buf = "";
for ($i = 0; $i < $total; $i++) if (($buf = CommonFunctions::rolv($sensor[$i]))!==null) {
$dev = new SensorDevice();
$dev->setValue($buf);
if (($buf = CommonFunctions::rolv($sensor[$i], "/\/[^\/]*_input$/", "/name"))!==null) {
$name = " (".$buf.")";
} else {
$name = "";
}
if (($buf = CommonFunctions::rolv($sensor[$i], "/_input$/", "_label"))!==null) {
$dev->setName($buf.$name);
} else {
$labelname = trim(preg_replace("/_input$/", "", pathinfo($sensor[$i], PATHINFO_BASENAME)));
if ($labelname !== "") {
$dev->setName($labelname.$name);
} else {
$dev->setName('unknown'.$name);
}
}
if (($buf = CommonFunctions::rolv($sensor[$i], "/_input$/", "_full_speed"))!==null) {
$dev->setMax($buf);
} elseif (($buf = CommonFunctions::rolv($sensor[$i], "/_input$/", "_max"))!==null) {
$dev->setMax($buf);
}
if (($buf = CommonFunctions::rolv($sensor[$i], "/_input$/", "_min"))!==null) {
$dev->setMin($buf);
}
if (($buf = CommonFunctions::rolv($sensor[$i], "/_input$/", "_alarm"))==="1") {
$dev->setEvent("Alarm");
}
$this->mbinfo->setMbFan($dev);
}
}
}
/**
* get power information
*
* @param string $hwpath
* @return void
*/
private function _power($hwpath)
{
$sensor = CommonFunctions::findglob($hwpath."power*_input", GLOB_NOSORT);
if (is_array($sensor) && (($total = count($sensor)) > 0)) {
$buf = "";
for ($i = 0; $i < $total; $i++) if (($buf = CommonFunctions::rolv($sensor[$i]))!==null) {
$dev = new SensorDevice();
$dev->setValue($buf/1000000);
if (($buf = CommonFunctions::rolv($sensor[$i], "/\/[^\/]*_input$/", "/name"))!==null) {
$name = " (".$buf.")";
} else {
$name = "";
}
if (($buf = CommonFunctions::rolv($sensor[$i], "/_input$/", "_label"))!==null) {
$dev->setName($buf.$name);
} else {
$labelname = trim(preg_replace("/_input$/", "", pathinfo($sensor[$i], PATHINFO_BASENAME)));
if ($labelname !== "") {
$dev->setName($labelname.$name);
} else {
$dev->setName('unknown'.$name);
}
}
if (($buf = CommonFunctions::rolv($sensor[$i], "/_input$/", "_max"))!==null) {
$dev->setMax($buf/1000000);
}
if (($buf = CommonFunctions::rolv($sensor[$i], "/_input$/", "_min"))!==null) {
$dev->setMin($buf/1000000);
}
if (($buf = CommonFunctions::rolv($sensor[$i], "/_input$/", "_alarm"))==="1") {
$dev->setEvent("Alarm");
}
$this->mbinfo->setMbPower($dev);
}
}
}
/**
* get current information
*
* @param string $hwpath
* @return void
*/
private function _current($hwpath)
{
$sensor = CommonFunctions::findglob($hwpath."curr*_input", GLOB_NOSORT);
if (is_array($sensor) && (($total = count($sensor)) > 0)) {
$buf = "";
for ($i = 0; $i < $total; $i++) if (($buf = CommonFunctions::rolv($sensor[$i]))!==null) {
$dev = new SensorDevice();
$dev->setValue($buf/1000);
if (($buf = CommonFunctions::rolv($sensor[$i], "/\/[^\/]*_input$/", "/name"))!==null) {
$name = " (".$buf.")";
} else {
$name = "";
}
if (($buf = CommonFunctions::rolv($sensor[$i], "/_input$/", "_label"))!==null) {
$dev->setName($buf.$name);
} else {
$labelname = trim(preg_replace("/_input$/", "", pathinfo($sensor[$i], PATHINFO_BASENAME)));
if ($labelname !== "") {
$dev->setName($labelname.$name);
} else {
$dev->setName('unknown'.$name);
}
}
if (($buf = CommonFunctions::rolv($sensor[$i], "/_input$/", "_max"))!==null) {
$dev->setMax($buf/1000);
}
if (($buf = CommonFunctions::rolv($sensor[$i], "/_input$/", "_min"))!==null) {
$dev->setMin($buf/1000);
}
if (($buf = CommonFunctions::rolv($sensor[$i], "/_input$/", "_alarm"))==="1") {
$dev->setEvent("Alarm");
}
$this->mbinfo->setMbCurrent($dev);
}
}
}
/**
* get the information
*
* @see PSI_Interface_Sensor::build()
*
* @return void
*/
public function build()
{
if ((PSI_OS == 'Linux') && (!defined('PSI_EMU_HOSTNAME') || defined('PSI_EMU_PORT'))) {
$hwpaths = CommonFunctions::findglob("/sys/class/hwmon/hwmon*/", GLOB_NOSORT);
if (is_array($hwpaths) && (count($hwpaths) > 0)) {
$hwpaths2 = CommonFunctions::findglob("/sys/class/hwmon/hwmon*/device/", GLOB_NOSORT);
if (is_array($hwpaths2) && (count($hwpaths2) > 0)) {
$hwpaths = array_merge($hwpaths, $hwpaths2);
}
$totalh = count($hwpaths);
for ($h = 0; $h < $totalh; $h++) {
$this->_temperature($hwpaths[$h]);
$this->_voltage($hwpaths[$h]);
$this->_fans($hwpaths[$h]);
$this->_power($hwpaths[$h]);
$this->_current($hwpaths[$h]);
}
}
}
}
}

View File

@@ -1,6 +1,6 @@
<?php
/**
* hwsensors sensor class
* hwsensors sensor class, getting information from hwsensors
*
* PHP version 5
*
@@ -8,18 +8,7 @@
* @package PSI_Sensor
* @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.hwsensors.inc.php 661 2012-08-27 11:26:39Z namiltd $
* @link http://phpsysinfo.sourceforge.net
*/
/**
* getting information from hwsensors
*
* @category PHP
* @package PSI_Sensor
* @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
*/
@@ -33,15 +22,17 @@ class HWSensors extends Sensors
private $_lines = array();
/**
* fill the private content var through tcp or file access
* fill the private content var through command
*/
public function __construct()
{
parent::__construct();
$lines = "";
// CommonFunctions::executeProgram('sysctl', '-w hw.sensors', $lines);
CommonFunctions::executeProgram('sysctl', 'hw.sensors', $lines);
$this->_lines = preg_split("/\n/", $lines, -1, PREG_SPLIT_NO_EMPTY);
if (PSI_OS == 'OpenBSD') {
$lines = "";
// CommonFunctions::executeProgram('sysctl', '-w hw.sensors', $lines);
CommonFunctions::executeProgram('sysctl', 'hw.sensors', $lines);
$this->_lines = preg_split("/\n/", $lines, -1, PREG_SPLIT_NO_EMPTY);
}
}
/**
@@ -145,7 +136,7 @@ class HWSensors extends Sensors
*
* @see PSI_Interface_Sensor::build()
*
* @return Void
* @return void
*/
public function build()
{

View File

@@ -1,197 +0,0 @@
<?php
/**
* ipmi sensor class
*
* PHP version 5
*
* @category PHP
* @package PSI_Sensor
* @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.ipmi.inc.php 661 2012-08-27 11:26:39Z namiltd $
* @link http://phpsysinfo.sourceforge.net
*/
/**
* getting information from ipmitool
*
* @category PHP
* @package PSI_Sensor
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @version Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
class IPMI extends Sensors
{
/**
* content to parse
*
* @var array
*/
private $_lines = array();
/**
* fill the private content var through tcp or file access
*/
public function __construct()
{
parent::__construct();
switch (strtolower(PSI_SENSOR_ACCESS)) {
case 'command':
CommonFunctions::executeProgram('ipmitool', 'sensor', $lines);
$this->_lines = preg_split("/\n/", $lines, -1, PREG_SPLIT_NO_EMPTY);
break;
case 'file':
if (CommonFunctions::rfts(APP_ROOT.'/data/ipmi.txt', $lines)) {
$this->_lines = preg_split("/\n/", $lines, -1, PREG_SPLIT_NO_EMPTY);
}
break;
default:
$this->error->addConfigError('__construct()', 'PSI_SENSOR_ACCESS');
break;
}
}
/**
* get temperature information
*
* @return void
*/
private function _temperature()
{
foreach ($this->_lines as $line) {
$buffer = preg_split("/\s*\|\s*/", $line);
if ($buffer[2] == "degrees C" && $buffer[3] != "na") {
$dev = new SensorDevice();
$dev->setName($buffer[0]);
$dev->setValue($buffer[1]);
if ($buffer[8] != "na") $dev->setMax($buffer[8]);
switch ($buffer[3]) {
case "nr": $dev->setEvent("Non-Recoverable"); break;
case "cr": $dev->setEvent("Critical"); break;
case "nc": $dev->setEvent("Non-Critical"); break;
}
$this->mbinfo->setMbTemp($dev);
}
}
}
/**
* get voltage information
*
* @return void
*/
private function _voltage()
{
foreach ($this->_lines as $line) {
$buffer = preg_split("/\s*\|\s*/", $line);
if ($buffer[2] == "Volts" && $buffer[3] != "na") {
$dev = new SensorDevice();
$dev->setName($buffer[0]);
$dev->setValue($buffer[1]);
if ($buffer[5] != "na") $dev->setMin($buffer[5]);
if ($buffer[8] != "na") $dev->setMax($buffer[8]);
switch ($buffer[3]) {
case "nr": $dev->setEvent("Non-Recoverable"); break;
case "cr": $dev->setEvent("Critical"); break;
case "nc": $dev->setEvent("Non-Critical"); break;
}
$this->mbinfo->setMbVolt($dev);
}
}
}
/**
* get fan information
*
* @return void
*/
private function _fans()
{
foreach ($this->_lines as $line) {
$buffer = preg_split("/\s*\|\s*/", $line);
if ($buffer[2] == "RPM" && $buffer[3] != "na") {
$dev = new SensorDevice();
$dev->setName($buffer[0]);
$dev->setValue($buffer[1]);
if ($buffer[8] != "na") {
$dev->setMin($buffer[8]);
} elseif (($buffer[5] != "na") && ($buffer[5]<$buffer[1])) { //max instead min issue
$dev->setMin($buffer[5]);
}
switch ($buffer[3]) {
case "nr": $dev->setEvent("Non-Recoverable"); break;
case "cr": $dev->setEvent("Critical"); break;
case "nc": $dev->setEvent("Non-Critical"); break;
}
$this->mbinfo->setMbFan($dev);
}
}
}
/**
* get power information
*
* @return void
*/
private function _power()
{
foreach ($this->_lines as $line) {
$buffer = preg_split("/\s*\|\s*/", $line);
if ($buffer[2] == "Watts" && $buffer[3] != "na") {
$dev = new SensorDevice();
$dev->setName($buffer[0]);
$dev->setValue($buffer[1]);
if ($buffer[8] != "na") $dev->setMax($buffer[8]);
switch ($buffer[3]) {
case "nr": $dev->setEvent("Non-Recoverable"); break;
case "cr": $dev->setEvent("Critical"); break;
case "nc": $dev->setEvent("Non-Critical"); break;
}
$this->mbinfo->setMbPower($dev);
}
}
}
/**
* get current information
*
* @return void
*/
private function _current()
{
foreach ($this->_lines as $line) {
$buffer = preg_split("/\s*\|\s*/", $line);
if ($buffer[2] == "Amps" && $buffer[3] != "na") {
$dev = new SensorDevice();
$dev->setName($buffer[0]);
$dev->setValue($buffer[1]);
if ($buffer[8] != "na") $dev->setMax($buffer[8]);
switch ($buffer[3]) {
case "nr": $dev->setEvent("Non-Recoverable"); break;
case "cr": $dev->setEvent("Critical"); break;
case "nc": $dev->setEvent("Non-Critical"); break;
}
$this->mbinfo->setMbCurrent($dev);
}
}
}
/**
* get the information
*
* @see PSI_Interface_Sensor::build()
*
* @return Void
*/
public function build()
{
$this->_temperature();
$this->_voltage();
$this->_fans();
$this->_power();
$this->_current();
}
}

View File

@@ -0,0 +1,321 @@
<?php
/**
* ipmicfg sensor class, getting information from ipmicfg -sdr
*
* PHP version 5
*
* @category PHP
* @package PSI_Sensor
* @author Mieczyslaw Nalewaj <namiltd@users.sourceforge.net>
* @copyright 2021 phpSysInfo
* @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
*/
class IPMIcfg extends Sensors
{
/**
* content to parse
*
* @var array
*/
private $_lines = array();
/**
* fill the private content var through command or data access
*/
public function __construct()
{
parent::__construct();
if (!defined('PSI_EMU_HOSTNAME') || defined('PSI_EMU_PORT')) switch (defined('PSI_SENSOR_IPMICFG_ACCESS')?strtolower(PSI_SENSOR_IPMICFG_ACCESS):'command') {
case 'command':
if ((!defined('PSI_SENSOR_IPMICFG_SDR') || (PSI_SENSOR_IPMICFG_SDR!==false)) ||
(!defined('PSI_SENSOR_IPMICFG_PSFRUINFO') || (PSI_SENSOR_IPMICFG_PSFRUINFO!==false)) ||
(!defined('PSI_SENSOR_IPMICFG_PMINFO') || (PSI_SENSOR_IPMICFG_PMINFO!==false))) {
$lines='';
$first=true;
if (!defined('PSI_SENSOR_IPMICFG_SDR') || (PSI_SENSOR_IPMICFG_SDR!==false)) {
$linestmp='';
if (CommonFunctions::executeProgram('ipmicfg', '-sdr', $linestmp)) {
$lines=$linestmp;
}
$first=false;
}
if (!defined('PSI_SENSOR_IPMICFG_PSFRUINFO') || (PSI_SENSOR_IPMICFG_PSFRUINFO!==false)) {
$linestmp='';
if (CommonFunctions::executeProgram('ipmicfg', '-psfruinfo', $linestmp, $first || PSI_DEBUG)) {
$lines.=$linestmp;
}
$first=false;
}
if (!defined('PSI_SENSOR_IPMICFG_PMINFO') || (PSI_SENSOR_IPMICFG_PMINFO!==false)) {
$linestmp='';
if (CommonFunctions::executeProgram('ipmicfg', '-pminfo', $linestmp, $first || PSI_DEBUG)) {
$lines.=$linestmp;
}
}
$this->_lines = preg_split("/\r?\n/", $lines, -1, PREG_SPLIT_NO_EMPTY);
} else {
$this->error->addConfigError('__construct()', '[sensor_ipmicfg] Not defined: SDR or PSFRUINFO or PMINFO');
}
break;
case 'data':
if (!defined('PSI_EMU_PORT') && CommonFunctions::rftsdata('ipmicfg.tmp', $lines)) {
$this->_lines = preg_split("/\r?\n/", $lines, -1, PREG_SPLIT_NO_EMPTY);
}
break;
default:
$this->error->addConfigError('__construct()', '[sensor_ipmicfg] ACCESS');
}
if ($this->_lines===false) {
$this->_lines = array();
} else {
$pmbus=false;
for ($licz=count($this->_lines); $licz--; $licz>0) {
$line=$this->_lines[$licz];
if (preg_match("/^\s*PMBus Revision\s*\|/", $line)) {
$pmbus=true;
} else if (preg_match("/^(\s*\[SlaveAddress = [\da..fA..F]+h\] \[)(Module )(\d+\])/", $line, $tmpbuf)) {
$this->_lines[$licz]=$tmpbuf[1].($pmbus?"PMBus ":"SMBus ").$tmpbuf[3];
$pmbus=false;
} else {
$this->_lines[$licz]=preg_replace("/\|\s*$/", "", $line);
}
}
}
}
/**
* get temperature information
*
* @return void
*/
private function _temperature()
{
$mdid='';
foreach ($this->_lines as $line) {
if (preg_match("/^\s*\[SlaveAddress = [\da..fA..F]+h\] \[((PMBus \d+)|(SMBus \d+))\]/", $line, $mdidtmp)) {
$mdid=$mdidtmp[1];
continue;
}
$buffer = preg_split("/\s*\|\s*/", $line);
if (($mdid=='') && (count($buffer)==5) && preg_match("/^\s*\(\d+\)\s(.*)\s*$/", $buffer[1], $namebuff) && preg_match("/^\s*([-\d]+)C\/[-\d]+F\s*$/", $buffer[2], $valbuff)) {
$dev = new SensorDevice();
$dev->setName($namebuff[1]);
if ($valbuff[1]<-128) $valbuff[1]+=256; //+256 correction
$dev->setValue($valbuff[1]);
if (preg_match("/^\s*([-\d]+)C\/[-\d]+F\s*$/", $buffer[3], $valbuffmin)) {
if ($valbuffmin[1]<-128) $valbuffmin[1]+=256; //+256 correction
}
if (preg_match("/^\s*([-\d]+)C\/[-\d]+F\s*$/", $buffer[4], $valbuffmax)) {
if ($valbuffmax[1]<-128) $valbuffmax[1]+=256; //+256 correction
$dev->setMax($valbuffmax[1]);
}
if ((isset($valbuffmin[1]) && ($valbuff[1]<=$valbuffmin[1])) || (isset($valbuffmax[1]) && ($valbuff[1]>=$valbuffmax[1]))) { //own range test due to errors with +256 correction
$dev->setEvent("Alarm");
}
$this->mbinfo->setMbTemp($dev);
} elseif (($mdid!='') && (count($buffer)==2) && preg_match("/^\s*([-\d]+)C\/[-\d]+F\s*$/", $buffer[1], $valbuff)) {
$dev = new SensorDevice();
$dev->setName(trim($buffer[0])." (".$mdid.")");
$dev->setValue($valbuff[1]);
$this->mbinfo->setMBTemp($dev);
}
}
}
/**
* get voltage information
*
* @return void
*/
private function _voltage()
{
$mdid='';
foreach ($this->_lines as $line) {
if (preg_match("/^\s*\[SlaveAddress = [\da..fA..F]+h\] \[((PMBus \d+)|(SMBus \d+))\]/", $line, $mdidtmp)) {
$mdid=$mdidtmp[1];
continue;
}
$buffer = preg_split("/\s*\|\s*/", $line);
if (($mdid=='') && (count($buffer)==5) && preg_match("/^\s*\(\d+\)\s(.*)\s*$/", $buffer[1], $namebuff) && preg_match("/^\s*([\d\.]+)\sV\s*$/", $buffer[2], $valbuff)) {
$dev = new SensorDevice();
$dev->setName($namebuff[1]);
$dev->setValue($valbuff[1]);
if (preg_match("/^\s*([\d\.].+)\sV\s*$/", $buffer[3], $valbuffmin)) {
$dev->setMin($valbuffmin[1]);
}
if (preg_match("/^\s*([\d\.].+)\sV\s*$/", $buffer[4], $valbuffmax)) {
$dev->setMax($valbuffmax[1]);
}
if (trim($buffer[0]) != "OK") $dev->setEvent(trim($buffer[0]));
$this->mbinfo->setMbVolt($dev);
} elseif (($mdid!='') && (count($buffer)==2) && preg_match("/^\s*([\d\.]+)\sV\s*$/", $buffer[1], $valbuff)) {
$dev = new SensorDevice();
$dev->setName(trim($buffer[0])." (".$mdid.")");
$dev->setValue($valbuff[1]);
$this->mbinfo->setMBVolt($dev);
}
}
}
/**
* get fan information
*
* @return void
*/
private function _fans()
{
$mdid='';
foreach ($this->_lines as $line) {
if (preg_match("/^\s*\[SlaveAddress = [\da..fA..F]+h\] \[((PMBus \d+)|(SMBus \d+))\]/", $line, $mdidtmp)) {
$mdid=$mdidtmp[1];
continue;
}
$buffer = preg_split("/\s*\|\s*/", $line);
if (($mdid=='') && (count($buffer)==5) && preg_match("/^\s*\(\d+\)\s(.*)\s*$/", $buffer[1], $namebuff) && preg_match("/^\s*(\d+)\sRPM\s*$/", $buffer[2], $valbuff)) {
$dev = new SensorDevice();
$dev->setName($namebuff[1]);
$dev->setValue($valbuff[1]);
if (preg_match("/^\s*(\d+)\sRPM\s*$/", $buffer[3], $valbuffmin)) {
$dev->setMin($valbuffmin[1]);
}
if ((trim($buffer[0]) != "OK") && isset($valbuffmin[1])) {
$dev->setEvent(trim($buffer[0]));
}
$this->mbinfo->setMbFan($dev);
} elseif (($mdid!='') && (count($buffer)==2) && preg_match("/^\s*(\d+)\sRPM\s*$/", $buffer[1], $valbuff)) {
$dev = new SensorDevice();
$dev->setName(trim($buffer[0])." (".$mdid.")");
$dev->setValue($valbuff[1]);
$this->mbinfo->setMBFan($dev);
}
}
}
/**
* get power information
*
* @return void
*/
private function _power()
{
$mdid='';
foreach ($this->_lines as $line) {
if (preg_match("/^\s*\[SlaveAddress = [\da..fA..F]+h\] \[((PMBus \d+)|(SMBus \d+))\]/", $line, $mdidtmp)) {
$mdid=$mdidtmp[1];
continue;
}
$buffer = preg_split("/\s*\|\s*/", $line);
if (($mdid=='') && (count($buffer)==5) && preg_match("/^\s*\(\d+\)\s(.*)\s*$/", $buffer[1], $namebuff) && preg_match("/^\s*(\d+)\sWatts\s*$/", $buffer[2], $valbuff)) {
$dev = new SensorDevice();
$dev->setName($namebuff[1]);
$dev->setValue($valbuff[1]);
if (preg_match("/^\s*(\d+)\sWatts\s*$/", $buffer[4], $valbuffmax)) {
$dev->setMax($valbuffmax[1]);
}
if (trim($buffer[0]) != "OK") $dev->setEvent(trim($buffer[0]));
$this->mbinfo->setMbPower($dev);
} elseif (($mdid!='') && (count($buffer)==2) && preg_match("/^\s*(\d+)\sW\s*$/", $buffer[1], $valbuff)) {
$dev = new SensorDevice();
$dev->setName(trim($buffer[0])." (".$mdid.")");
$dev->setValue($valbuff[1]);
$this->mbinfo->setMBPower($dev);
}
}
}
/**
* get current information
*
* @return void
*/
private function _current()
{
$mdid='';
foreach ($this->_lines as $line) {
if (preg_match("/^\s*\[SlaveAddress = [\da..fA..F]+h\] \[((PMBus \d+)|(SMBus \d+))\]/", $line, $mdidtmp)) {
$mdid=$mdidtmp[1];
continue;
}
$buffer = preg_split("/\s*\|\s*/", $line);
if (($mdid=='') && (count($buffer)==5) && preg_match("/^\s*\(\d+\)\s(.*)\s*$/", $buffer[1], $namebuff) && preg_match("/^\s*([\d\.]+)\sAmps\s*$/", $buffer[2], $valbuff)) {
$dev = new SensorDevice();
$dev->setName($namebuff[1]);
$dev->setValue($valbuff[1]);
if (preg_match("/^\s*([\d\.].+)\sAmps\s*$/", $buffer[3], $valbuffmin)) {
$dev->setMin($valbuffmin[1]);
}
if (preg_match("/^\s*([\d\.].+)\sAmps\s*$/", $buffer[4], $valbuffmax)) {
$dev->setMax($valbuffmax[1]);
}
if (trim($buffer[0]) != "OK") $dev->setEvent(trim($buffer[0]));
$this->mbinfo->setMbCurrent($dev);
} elseif (($mdid!='') && (count($buffer)==2) && preg_match("/^\s*([\d\.]+)\sA\s*$/", $buffer[1], $valbuff)) {
$dev = new SensorDevice();
$dev->setName(trim($buffer[0])." (".$mdid.")");
$dev->setValue($valbuff[1]);
$this->mbinfo->setMBCurrent($dev);
}
}
}
/**
* get other information
*
* @return void
*/
private function _other()
{
$mdid='';
foreach ($this->_lines as $line) {
if (preg_match("/^\s*\[SlaveAddress = [\da..fA..F]+h\] \[((PMBus \d+)|(SMBus \d+))\]/", $line, $mdidtmp)) {
$mdid=$mdidtmp[1];
continue;
}
$buffer = preg_split("/\s*\|\s*/", $line);
if (($mdid=='') && (count($buffer)>=3) && preg_match("/^\s*\(\d+\)\s(.*)\s*$/", $buffer[1], $namebuff)) {
$buffer[2]=trim($buffer[2]);
if ((count($buffer)==3) &&
($buffer[2]!=="Correctable ECC / other correctable memory error") &&
($buffer[2]!=="Not Present") &&
($buffer[2]!=="N/A") &&
(trim($buffer[0]) != "")) {
$dev = new SensorDevice();
$dev->setName($namebuff[1]);
$dev->setValue($buffer[2]);
if (trim($buffer[0]) != "OK") $dev->setEvent(trim($buffer[0]));
$this->mbinfo->setMbOther($dev);
} elseif ((count($buffer)==5)&& preg_match("/(^\s*[\d\.]+\s*$)|(^\s*[\da-fA-F]{2}\s+[\da-fA-F]{2}\s+[\da-fA-F]{2}\s+[\da-fA-F]{2}\s*$)/", $buffer[2], $valbuff)) {
$dev = new SensorDevice();
$dev->setName($namebuff[1]);
$dev->setValue($buffer[0]);
$this->mbinfo->setMbOther($dev);
}
} elseif (($mdid!='') && (count($buffer)==2) && ((trim($buffer[0])=="Status") || (trim($buffer[0])=="Current Sharing Control"))) {
$dev = new SensorDevice();
$dev->setName(trim($buffer[0])." (".$mdid.")");
$dev->setValue($buffer[1]);
$this->mbinfo->setMbOther($dev);
}
}
}
/**
* get the information
*
* @see PSI_Interface_Sensor::build()
*
* @return void
*/
public function build()
{
$this->_temperature();
$this->_voltage();
$this->_fans();
$this->_power();
$this->_current();
$this->_other();
}
}

View File

@@ -0,0 +1,320 @@
<?php
/**
* ipmitool sensor class, getting information from ipmitool
*
* PHP version 5
*
* @category PHP
* @package PSI_Sensor
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @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
*/
class IPMItool extends Sensors
{
/**
* content to parse
*
* @var array
*/
private $_buf = array();
/**
* fill the private content var through command or data access
*/
public function __construct()
{
parent::__construct();
$lines = "";
if (!defined('PSI_EMU_HOSTNAME') || defined('PSI_EMU_PORT')) switch (defined('PSI_SENSOR_IPMITOOL_ACCESS')?strtolower(PSI_SENSOR_IPMITOOL_ACCESS):'command') {
case 'command':
CommonFunctions::executeProgram('ipmitool', 'sensor -v', $lines);
break;
case 'data':
if (!defined('PSI_EMU_PORT')) {
CommonFunctions::rftsdata('ipmitool.tmp', $lines);
}
break;
default:
$this->error->addConfigError('__construct()', '[sensor_ipmitool] ACCESS');
}
if (trim($lines) !== "") {
if (preg_match("/^Sensor ID\s+/", $lines)) { //new data format ('ipmitool sensor -v')
$lines = preg_replace("/\n?Unable to read sensor/", "\nUnable to read sensor", $lines);
$sensors = preg_split("/Sensor ID\s+/", $lines, -1, PREG_SPLIT_NO_EMPTY);
foreach ($sensors as $sensor) {
if (preg_match("/^:\s*(.+)\s\((0x[a-f\d]+)\)\r?\n/", $sensor, $name) && (($name1 = trim($name[1])) !== "")) {
$sensorvalues = preg_split("/\r?\n/", $sensor, -1, PREG_SPLIT_NO_EMPTY);
unset($sensorvalues[0]); //skip first
$sens = array();
$was = false;
foreach ($sensorvalues as $sensorvalue) {
if (preg_match("/^\s+\[(.+)\]$/", $sensorvalue, $buffer) && (($buffer1 = trim($buffer[1])) !== "")) {
if (isset($sens['State'])) {
$sens['State'] .= ', '.$buffer1;
} else {
$sens['State'] = $buffer1;
}
$was = true;
} elseif (preg_match("/^([^:]+):(.+)$/", $sensorvalue, $buffer)
&& (($buffer1 = trim($buffer[1])) !== "")
&& (($buffer2 = trim($buffer[2])) !== "")) {
$sens[$buffer1] = $buffer2;
$was = true;
}
}
if ($was && !isset($sens['Unable to read sensor'])) {
$sens['Sensor'] = $name1;
if (isset($sens['Sensor Reading'])
&& preg_match("/^([\d\.]+)\s+\([^\)]*\)\s+(.+)$/", $sens['Sensor Reading'], $buffer)
&& (($buffer2 = trim($buffer[2])) !== "")) {
$sens['Value'] = $buffer[1];
$sens['Unit'] = $buffer2;
}
$this->_buf[intval($name[2], 0)] = $sens;
}
}
}
} else {
$lines = preg_split("/\r?\n/", $lines, -1, PREG_SPLIT_NO_EMPTY);
if (count($lines)>0) {
$buffer = preg_split("/\s*\|\s*/", $lines[0]);
if (count($buffer)>8) { //old data format ('ipmitool sensor')
foreach ($lines as $line) {
$buffer = preg_split("/\s*\|\s*/", $line);
if (count($buffer)>8) {
$sens = array();
$sens['Sensor'] = $buffer[0];
switch ($buffer[2]) {
case 'degrees C':
$sens['Value'] = $buffer[1];
$sens['Unit'] = $buffer[2];
$sens['Upper Critical'] = $buffer[8];
$sens['Sensor Type (Threshold)'] = 'Temperature';
break;
case 'Volts':
$sens['Value'] = $buffer[1];
$sens['Unit'] = $buffer[2];
$sens['Lower Critical'] = $buffer[5];
$sens['Upper Critical'] = $buffer[8];
$sens['Sensor Type (Threshold)'] = 'Voltage';
break;
case 'RPM':
$sens['Value'] = $buffer[1];
$sens['Unit'] = $buffer[2];
$sens['Lower Critical'] = $buffer[5];
$sens['Upper Critical'] = $buffer[8];
$sens['Sensor Type (Threshold)'] = 'Fan';
break;
case 'Watts':
$sens['Value'] = $buffer[1];
$sens['Unit'] = $buffer[2];
$sens['Upper Critical'] = $buffer[8];
$sens['Sensor Type (Threshold)'] = 'Current';
break;
case 'Amps':
$sens['Value'] = $buffer[1];
$sens['Unit'] = $buffer[2];
$sens['Lower Critical'] = $buffer[5];
$sens['Upper Critical'] = $buffer[8];
$sens['Sensor Type (Threshold)'] = 'Current';
break;
case 'discrete':
if (($buffer[1]==='0x0') || ($buffer[1]==='0x1')) {
$sens['State'] = $buffer[1];
$sens['Sensor Type (Discrete)'] = '';
$sens['State'] = $buffer[1];
}
}
$this->_buf[] = $sens;
}
}
}
}
}
}
}
/**
* get temperature information
*
* @return void
*/
private function _temperature()
{
foreach ($this->_buf as $sensor) {
if (((isset($sensor['Sensor Type (Threshold)']) && ($sensor['Sensor Type (Threshold)'] == 'Temperature'))
||(isset($sensor['Sensor Type (Analog)']) && ($sensor['Sensor Type (Analog)'] == 'Temperature')))
&& isset($sensor['Unit']) && ($sensor['Unit'] == 'degrees C')
&& isset($sensor['Value'])) {
$dev = new SensorDevice();
$dev->setName($sensor['Sensor']);
$dev->setValue($sensor['Value']);
if (isset($sensor['Upper Critical']) && (($max = $sensor['Upper Critical']) != "na")) {
$dev->setMax($max);
}
if (isset($sensor['Status']) && (($status = $sensor['Status']) != "ok")) {
$dev->setEvent($status);
}
$this->mbinfo->setMbTemp($dev);
}
}
}
/**
* get voltage information
*
* @return void
*/
private function _voltage()
{
foreach ($this->_buf as $sensor) {
if (((isset($sensor['Sensor Type (Threshold)']) && ($sensor['Sensor Type (Threshold)'] == 'Voltage'))
||(isset($sensor['Sensor Type (Analog)']) && ($sensor['Sensor Type (Analog)'] == 'Voltage')))
&& isset($sensor['Unit']) && ($sensor['Unit'] == 'Volts')
&& isset($sensor['Value'])) {
$dev = new SensorDevice();
$dev->setName($sensor['Sensor']);
$dev->setValue($sensor['Value']);
if (isset($sensor['Upper Critical']) && (($max = $sensor['Upper Critical']) != "na")) {
$dev->setMax($max);
}
if (isset($sensor['Lower Critical']) && (($min = $sensor['Lower Critical']) != "na")) {
$dev->setMin($min);
}
if (isset($sensor['Status']) && (($status = $sensor['Status']) != "ok")) {
$dev->setEvent($status);
}
$this->mbinfo->setMbVolt($dev);
}
}
}
/**
* get fan information
*
* @return void
*/
private function _fans()
{
foreach ($this->_buf as $sensor) {
if (((isset($sensor['Sensor Type (Threshold)']) && ($sensor['Sensor Type (Threshold)'] == 'Fan'))
||(isset($sensor['Sensor Type (Analog)']) && ($sensor['Sensor Type (Analog)'] == 'Fan')))
&& isset($sensor['Unit']) && ($sensor['Unit'] == 'RPM')
&& isset($sensor['Value'])) {
$dev = new SensorDevice();
$dev->setName($sensor['Sensor']);
$dev->setValue($value = $sensor['Value']);
if (isset($sensor['Lower Critical']) && (($min = $sensor['Lower Critical']) != "na")) {
$dev->setMin($min);
} elseif (isset($sensor['Upper Critical']) && (($max = $sensor['Upper Critical']) != "na")
&& ($max < $value)) { // max instead min issue
$dev->setMin($max);
}
if (isset($sensor['Status']) && (($status = $sensor['Status']) != "ok")) {
$dev->setEvent($status);
}
$this->mbinfo->setMbFan($dev);
}
}
}
/**
* get power information
*
* @return void
*/
private function _power()
{
foreach ($this->_buf as $sensor) {
if (((isset($sensor['Sensor Type (Threshold)']) && ($sensor['Sensor Type (Threshold)'] == 'Current'))
||(isset($sensor['Sensor Type (Analog)']) && ($sensor['Sensor Type (Analog)'] == 'Current')))
&& isset($sensor['Unit']) && ($sensor['Unit'] == 'Watts')
&& isset($sensor['Value'])) {
$dev = new SensorDevice();
$dev->setName($sensor['Sensor']);
$dev->setValue($sensor['Value']);
if (isset($sensor['Upper Critical']) && (($max = $sensor['Upper Critical']) != "na")) {
$dev->setMax($max);
}
if (isset($sensor['Status']) && (($status = $sensor['Status']) != "ok")) {
$dev->setEvent($status);
}
$this->mbinfo->setMbPower($dev);
}
}
}
/**
* get current information
*
* @return void
*/
private function _current()
{
foreach ($this->_buf as $sensor) {
if (((isset($sensor['Sensor Type (Threshold)']) && ($sensor['Sensor Type (Threshold)'] == 'Current'))
||(isset($sensor['Sensor Type (Analog)']) && ($sensor['Sensor Type (Analog)'] == 'Current')))
&& isset($sensor['Unit']) && ($sensor['Unit'] == 'Amps')
&& isset($sensor['Value'])) {
$dev = new SensorDevice();
$dev->setName($sensor['Sensor']);
$dev->setValue($sensor['Value']);
if (isset($sensor['Upper Critical']) && (($max = $sensor['Upper Critical']) != "na")) {
$dev->setMax($max);
}
if (isset($sensor['Lower Critical']) && (($min = $sensor['Lower Critical']) != "na")) {
$dev->setMin($min);
}
if (isset($sensor['Status']) && (($status = $sensor['Status']) != "ok")) {
$dev->setEvent($status);
}
$this->mbinfo->setMbCurrent($dev);
}
}
}
/**
* get other information
*
* @return void
*/
private function _other()
{
foreach ($this->_buf as $sensor) {
if (isset($sensor['Sensor Type (Discrete)'])) {
$dev = new SensorDevice();
if ($sensor['Sensor Type (Discrete)']!=='') {
$dev->setName($sensor['Sensor'].' ('.$sensor['Sensor Type (Discrete)'].')');
} else {
$dev->setName($sensor['Sensor']);
}
if (isset($sensor['State'])) {
$dev->setValue($sensor['State']);
} else {
$dev->setValue('0x0');
}
$this->mbinfo->setMbOther($dev);
}
}
}
/**
* get the information
*
* @see PSI_Interface_Sensor::build()
*
* @return void
*/
public function build()
{
$this->_temperature();
$this->_voltage();
$this->_fans();
$this->_power();
$this->_current();
$this->_other();
}
}

View File

@@ -1,25 +1,14 @@
<?php
/**
* ipmiutil sensor class
* ipmiutil sensor class, getting information from ipmi-sensors
*
* PHP version 5
*
* @category PHP
* @package PSI_Sensor
* @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.ipmiutil.inc.php 661 2012-08-27 11:26:39Z namiltd $
* @link http://phpsysinfo.sourceforge.net
*/
/**
* getting information from ipmi-sensors
*
* @category PHP
* @package PSI_Sensor
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @author Mieczyslaw Nalewaj <namiltd@users.sourceforge.net>
* @copyright 2014 phpSysInfo
* @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
*/
@@ -33,24 +22,23 @@ class IPMIutil extends Sensors
private $_lines = array();
/**
* fill the private content var through tcp or file access
* fill the private content var through command or data access
*/
public function __construct()
{
parent::__construct();
switch (strtolower(PSI_SENSOR_ACCESS)) {
if (!defined('PSI_EMU_HOSTNAME') || defined('PSI_EMU_PORT')) switch (defined('PSI_SENSOR_IPMIUTIL_ACCESS')?strtolower(PSI_SENSOR_IPMIUTIL_ACCESS):'command') {
case 'command':
CommonFunctions::executeProgram('ipmiutil', 'sensor -stw', $lines);
$this->_lines = preg_split("/\r?\n/", $lines, -1, PREG_SPLIT_NO_EMPTY);
break;
case 'file':
if (CommonFunctions::rfts(APP_ROOT.'/data/ipmiutil.txt', $lines)) {
case 'data':
if (!defined('PSI_EMU_PORT') && CommonFunctions::rftsdata('ipmiutil.tmp', $lines)) {
$this->_lines = preg_split("/\r?\n/", $lines, -1, PREG_SPLIT_NO_EMPTY);
}
break;
default:
$this->error->addConfigError('__construct()', 'PSI_SENSOR_ACCESS');
break;
$this->error->addConfigError('__construct()', '[sensor_ipmiutil] ACCESS');
}
}
@@ -63,7 +51,10 @@ class IPMIutil extends Sensors
{
foreach ($this->_lines as $line) {
$buffer = preg_split("/\s*\|\s*/", $line);
if (isset($buffer[2]) && $buffer[2] == "Temperature" && $buffer[1] == "Full" && isset($buffer[6]) && preg_match("/^(\S+)\sC$/", $buffer[6], $value)) {
if (isset($buffer[2]) && $buffer[2] == "Temperature"
&& $buffer[1] == "Full"
&& isset($buffer[6]) && preg_match("/^(\S+)\sC$/", $buffer[6], $value)
&& $buffer[5] !== "Init") {
$dev = new SensorDevice();
$dev->setName($buffer[4]);
$dev->setValue($value[1]);
@@ -90,7 +81,10 @@ class IPMIutil extends Sensors
{
foreach ($this->_lines as $line) {
$buffer = preg_split("/\s*\|\s*/", $line);
if (isset($buffer[2]) && $buffer[2] == "Voltage" && $buffer[1] == "Full" && isset($buffer[6]) && preg_match("/^(\S+)\sV$/", $buffer[6], $value)) {
if (isset($buffer[2]) && $buffer[2] == "Voltage"
&& $buffer[1] == "Full"
&& isset($buffer[6]) && preg_match("/^(\S+)\sV$/", $buffer[6], $value)
&& $buffer[5] !== "Init") {
$dev = new SensorDevice();
$dev->setName($buffer[4]);
$dev->setValue($value[1]);
@@ -123,7 +117,10 @@ class IPMIutil extends Sensors
{
foreach ($this->_lines as $line) {
$buffer = preg_split("/\s*\|\s*/", $line);
if (isset($buffer[2]) && $buffer[2] == "Fan" && $buffer[1] == "Full" && isset($buffer[6]) && preg_match("/^(\S+)\sRPM$/", $buffer[6], $value)) {
if (isset($buffer[2]) && $buffer[2] == "Fan"
&& $buffer[1] == "Full"
&& isset($buffer[6]) && preg_match("/^(\S+)\sRPM$/", $buffer[6], $value)
&& $buffer[5] !== "Init") {
$dev = new SensorDevice();
$dev->setName($buffer[4]);
$dev->setValue($value[1]);
@@ -157,7 +154,10 @@ class IPMIutil extends Sensors
{
foreach ($this->_lines as $line) {
$buffer = preg_split("/\s*\|\s*/", $line);
if (isset($buffer[2]) && $buffer[2] == "Current" && $buffer[1] == "Full" && isset($buffer[6]) && preg_match("/^(\S+)\sW$/", $buffer[6], $value)) {
if (isset($buffer[2]) && $buffer[2] == "Current"
&& $buffer[1] == "Full"
&& isset($buffer[6]) && preg_match("/^(\S+)\sW$/", $buffer[6], $value)
&& $buffer[5] !== "Init") {
$dev = new SensorDevice();
$dev->setName($buffer[4]);
$dev->setValue($value[1]);
@@ -184,11 +184,20 @@ class IPMIutil extends Sensors
{
foreach ($this->_lines as $line) {
$buffer = preg_split("/\s*\|\s*/", $line);
if (isset($buffer[2]) && $buffer[2] == "Current" && $buffer[1] == "Full" && isset($buffer[6]) && preg_match("/^(\S+)\sA$/", $buffer[6], $value)) {
if (isset($buffer[2]) && $buffer[2] == "Current"
&& $buffer[1] == "Full"
&& isset($buffer[6]) && preg_match("/^(\S+)\sA$/", $buffer[6], $value)
&& $buffer[5] !== "Init") {
$dev = new SensorDevice();
$dev->setName($buffer[4]);
$dev->setValue($value[1]);
if (isset($buffer[7]) && $buffer[7] == "Thresholds") {
if ((isset($buffer[8]) && preg_match("/^lo-crit\s(\S+)\s*$/", $buffer[8], $limits))
||(isset($buffer[9]) && preg_match("/^lo-crit\s(\S+)\s*$/", $buffer[9], $limits))
||(isset($buffer[10]) && preg_match("/^lo-crit\s(\S+)\s*$/", $buffer[10], $limits))
||(isset($buffer[11]) && preg_match("/^lo-crit\s(\S+)\s*$/", $buffer[11], $limits))) {
$dev->setMin($limits[1]);
}
if ((isset($buffer[8]) && preg_match("/^hi-crit\s(\S+)\s*$/", $buffer[8], $limits))
||(isset($buffer[9]) && preg_match("/^hi-crit\s(\S+)\s*$/", $buffer[9], $limits))
||(isset($buffer[10]) && preg_match("/^hi-crit\s(\S+)\s*$/", $buffer[10], $limits))
@@ -202,12 +211,50 @@ class IPMIutil extends Sensors
}
}
/**
* get other information
*
* @return void
*/
private function _other()
{
foreach ($this->_lines as $line) {
$buffer = preg_split("/\s*\|\s*/", $line);
if (isset($buffer[1]) && $buffer[1] == "Compact"
&& $buffer[5] !== "Init"
&& $buffer[5] !== "Unknown"
&& $buffer[5] !== "NotAvailable") {
$dev = new SensorDevice();
$dev->setName($buffer[4].' ('.$buffer[2].')');
$buffer5s = preg_split("/\s+/", $buffer5 = $buffer[5]);
if (isset($buffer5s[1])) {
if (preg_match('/^[0-9A-Fa-f]+$/', $buffer5s[0])) {
$value = hexdec($buffer5s[0]) & 0xff;
if ($buffer5s[1] === 'DiscreteEvt') {
$dev->setValue('0x'.dechex($value));
} elseif (($buffer5s[1] === 'DiscreteUnit') && ($value > 0)) {
$dev->setValue('0x'.dechex($value - 1));
} else {
$dev->setValue($buffer5);
}
} else {
$dev->setValue($buffer5);
}
} else {
$dev->setValue($buffer5);
}
$this->mbinfo->setMbOther($dev);
}
}
}
/**
* get the information
*
* @see PSI_Interface_Sensor::build()
*
* @return Void
* @return void
*/
public function build()
{
@@ -216,5 +263,6 @@ class IPMIutil extends Sensors
$this->_fans();
$this->_power();
$this->_current();
$this->_other();
}
}

View File

@@ -1,6 +1,6 @@
<?php
/**
* K8Temp sensor class
* K8Temp sensor class, getting information from k8temp
*
* PHP version 5
*
@@ -8,18 +8,7 @@
* @package PSI_Sensor
* @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.k8temp.inc.php 661 2012-08-27 11:26:39Z namiltd $
* @link http://phpsysinfo.sourceforge.net
*/
/**
* getting information from k8temp
*
* @category PHP
* @package PSI_Sensor
* @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
*/
@@ -38,20 +27,19 @@ class K8Temp extends Sensors
public function __construct()
{
parent::__construct();
switch (strtolower(PSI_SENSOR_ACCESS)) {
if ((PSI_OS != 'WINNT') && (!defined('PSI_EMU_HOSTNAME') || defined('PSI_EMU_PORT'))) switch (defined('PSI_SENSOR_K8TEMP_ACCESS')?strtolower(PSI_SENSOR_K8TEMP_ACCESS):'command') {
case 'command':
$lines = "";
CommonFunctions::executeProgram('k8temp', '', $lines);
$this->_lines = preg_split("/\n/", $lines, -1, PREG_SPLIT_NO_EMPTY);
break;
case 'file':
if (CommonFunctions::rfts(APP_ROOT.'/data/k8temp.txt', $lines)) {
case 'data':
if (!defined('PSI_EMU_PORT') && CommonFunctions::rftsdata('k8temp.tmp', $lines)) {
$this->_lines = preg_split("/\n/", $lines, -1, PREG_SPLIT_NO_EMPTY);
}
break;
default:
$this->error->addConfigError('__construct()', 'PSI_SENSOR_ACCESS');
break;
$this->error->addConfigError('__construct()', '[sensor_k8temp] ACCESS');
}
}
@@ -67,7 +55,7 @@ class K8Temp extends Sensors
if ($data[2] > 0) {
$dev = new SensorDevice();
$dev->setName($data[1]);
$dev->setMax('70.0');
// $dev->setMax('70.0');
if ($data[2] < 250) {
$dev->setValue($data[2]);
}
@@ -82,7 +70,7 @@ class K8Temp extends Sensors
*
* @see PSI_Interface_Sensor::build()
*
* @return Void
* @return void
*/
public function build()
{

View File

@@ -1,6 +1,6 @@
<?php
/**
* lmsensor sensor class
* lmsensor sensor class, getting information from lmsensor
*
* PHP version 5
*
@@ -8,56 +8,122 @@
* @package PSI_Sensor
* @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.lmsensors.inc.php 661 2012-08-27 11:26:39Z namiltd $
* @link http://phpsysinfo.sourceforge.net
*/
/**
* getting information from lmsensor
*
* @category PHP
* @package PSI_Sensor
* @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
*/
class LMSensors extends Sensors
{
/**
* content to parse
* array of values
*
* @var array
*/
private $_lines = array();
private $_values = array();
/**
* fill the private content var through tcp or file access
* fill the private content var through command or data access
*/
public function __construct()
{
parent::__construct();
switch (strtolower(PSI_SENSOR_ACCESS)) {
$lines = "";
if ((PSI_OS == 'Linux') && (!defined('PSI_EMU_HOSTNAME') || defined('PSI_EMU_PORT'))) switch (defined('PSI_SENSOR_LMSENSORS_ACCESS')?strtolower(PSI_SENSOR_LMSENSORS_ACCESS):'command') {
case 'command':
if (CommonFunctions::executeProgram("sensors", "", $lines)) {
// Martijn Stolk: Dirty fix for misinterpreted output of sensors,
// where info could come on next line when the label is too long.
$lines = str_replace(":\n", ":", $lines);
$lines = str_replace("\n\n", "\n", $lines);
$this->_lines = preg_split("/\n/", $lines, -1, PREG_SPLIT_NO_EMPTY);
}
CommonFunctions::executeProgram("sensors", "", $lines);
break;
case 'file':
if (CommonFunctions::rfts(APP_ROOT.'/data/lmsensors.txt', $lines)) {
$lines = str_replace(":\n", ":", $lines);
$lines = str_replace("\n\n", "\n", $lines);
$this->_lines = preg_split("/\n/", $lines, -1, PREG_SPLIT_NO_EMPTY);
case 'data':
if (!defined('PSI_EMU_PORT')) {
CommonFunctions::rftsdata('lmsensors.tmp', $lines);
}
break;
default:
$this->error->addConfigError('__construct()', 'PSI_SENSOR_ACCESS');
break;
$this->error->addConfigError('__construct()', '[sensor_lmsensors] ACCESS');
}
if (trim($lines) !== "") {
$lines = str_replace("\r\n", "\n", $lines);
$lines = str_replace(":\n", ":", $lines);
$lines = str_replace("\n\n", "\n", $lines);
$lines = preg_replace("/\n\s+\(/m", " (", $lines);
$_lines = preg_split("/\n/", $lines, -1, PREG_SPLIT_NO_EMPTY);
$applearray1 = array(
"A" => "Ambient",
"B" => "Battery",
"C" => "CPU",
"G" => "GPU",
"H" => "Harddisk Bay",
"h" => "Heatpipe",
"L" => "LCD",
"M" => "Memory",
"m" => "Memory Contr.",
"N" => "Northbridge",
"O" => "Optical Drive",
"p" => "Power supply",
"S" => "Slot",
"s" => "Slot",
"W" => "Airport"
);
$applearray3 = array(
"H" => "Heatsink",
"P" => "Proximity",
"D" => "Die"
);
$tmpvalue=array();
$applesmc = false;
$sname = '';
foreach ($_lines as $line) {
if ((trim($line) !== "") && (strpos($line, ':') === false)) {
if (sizeof($tmpvalue)>0) {
$this->_values[] = $tmpvalue;
$tmpvalue = array();
}
$sname = trim($line);
$applesmc = ($sname === "applesmc-isa-0300");
if (preg_match('/^([^-]+)-/', $sname, $snamebuf)) {
$sname = $snamebuf[1];
} else {
$sname = '';
}
} else {
if (preg_match("/^(.+):(.+)$/", trim($line), $data) && ($data[1]!=="Adapter")) {
if ($applesmc && (strlen($data[1]) == 4) && ($data[1][0] == "T")) {
if (isset($applearray1[$data[1][1]])) $data[1] .= " ".$applearray1[$data[1][1]];
if (isset($applearray3[$data[1][3]])) $data[1] .= " ".$applearray3[$data[1][3]];
}
$arrtemp=array();
if ($sname !== "" ) {
$arrtemp["name"] = $data[1]." (".$sname.")";
} else {
$arrtemp["name"] = $data[1];
}
if (preg_match("/^([^\(]+)\s+\(/", $data[2], $tmp) || preg_match("/^(.+)\s+ALARM$/", $data[2], $tmp)) {
if (($tmp[1] = trim($tmp[1])) == "") {
$arrtemp["value"] = "ALARM";
} else {
$arrtemp["value"] = $tmp[1];
}
if (preg_match("/\s(ALARM)\s*$/", $data[2]) || preg_match("/\s(ALARM)\s+\(/", $data[2]) || preg_match("/\s(ALARM)\s+sensor\s+=/", $data[2])) {
$arrtemp["alarm"]="ALARM";
}
if (preg_match_all("/\(([^\)]+\s+=\s+[^\)]+)\)/", $data[2], $tmp2)) foreach ($tmp2[1] as $tmp3) {
$arrtmp3 = preg_split('/,/', $tmp3);
foreach ($arrtmp3 as $tmp4) if (preg_match("/^(\S+)\s+=\s+(.*)$/", trim($tmp4), $tmp5)) {
$arrtemp[$tmp5[1]]=trim($tmp5[2]);
}
}
} else {
$arrtemp["value"] = trim($data[2]);
}
$tmpvalue[] = $arrtemp;
}
}
}
if (sizeof($tmpvalue)>0) $this->_values[] = $tmpvalue;
}
}
@@ -68,88 +134,35 @@ class LMSensors extends Sensors
*/
private function _temperature()
{
$ar_buf = array();
foreach ($this->_lines as $line) {
$data = array();
if (preg_match("/(.*):(.*)\((.*)=(.*),(.*)=(.*)\)(.*)/", $line, $data)) {
;
} elseif (preg_match("/(.*):(.*)\((.*)=(.*)\)(.*)/", $line, $data)) {
;
} else {
preg_match("/(.*):(.*)/", $line, $data);
}
if (count($data) > 1) {
$temp = substr(trim($data[2]), -1);
switch ($temp) {
case "C":
// case "F":
array_push($ar_buf, $line);
}
}
}
foreach ($ar_buf as $line) {
$data = array();
if (preg_match("/(.*):(.*).C[ ]*\((.*)=(.*).C,(.*)=(.*).C\)(.*)\)/", $line, $data)) {
;
} elseif (preg_match("/(.*):(.*).C[ ]*\((.*)=(.*).C,(.*)=(.*).C\)(.*)/", $line, $data)) {
;
} elseif (preg_match("/(.*):(.*).C[ ]*\((.*)=(.*).C\)(.*)/", $line, $data)) {
;
} elseif (preg_match("/(.*):(.*).C[ \t]+/", $line, $data)) {
;
} else {
preg_match("/(.*):(.*).C$/", $line, $data);
}
foreach ($data as $key=>$value) {
if (preg_match("/^\+?(-?[0-9\.]+).?$/", trim($value), $newvalue)) {
$data[$key] = 0+trim($newvalue[1]);
} else {
$data[$key] = trim($value);
}
}
$dev = new SensorDevice();
if (strlen($data[1]) == 4) {
if ($data[1][0] == "T") {
if ($data[1][1] == "A") {
$data[1] = $data[1] . " Ambient";
} elseif ($data[1][1] == "C") {
$data[1] = $data[1] . " CPU";
} elseif ($data[1][1] == "G") {
$data[1] = $data[1] . " GPU";
} elseif ($data[1][1] == "H") {
$data[1] = $data[1] . " Harddisk";
} elseif ($data[1][1] == "L") {
$data[1] = $data[1] . " LCD";
} elseif ($data[1][1] == "O") {
$data[1] = $data[1] . " ODD";
} elseif ($data[1][1] == "B") {
$data[1] = $data[1] . " Battery";
foreach ($this->_values as $sensors) foreach ($sensors as $sensor){
if (isset($sensor["value"])) {
$limit = "";
if (preg_match("/^\+?(-?[\d\.]+)[^\w\r\n\t]+C$/", $sensor["value"], $tmpbuf) ||
((isset($sensor[$limit="crit"]) || isset($sensor[$limit="high"]) || isset($sensor[$limit="hyst"])) && preg_match("/^\+?(-?[\d\.]+)[^\w\r\n\t]+C$/", $sensor[$limit]))) {
$dev = new SensorDevice();
$dev->setName($sensor["name"]);
if ($limit != "") {
$dev->setValue($sensor["value"]);
$dev->setEvent("FAULT");
} else {
if ($tmpbuf[1] == -110.8) {
$dev->setValue("FAULT");
$dev->setEvent("FAULT");
} else {
$dev->setValue(floatval($tmpbuf[1]));
if (isset($sensor["alarm"])) $dev->setEvent("ALARM");
}
}
if ($data[1][3] == "H") {
$data[1] = $data[1] . " Heatsink";
} elseif ($data[1][3] == "P") {
$data[1] = $data[1] . " Proximity";
} elseif ($data[1][3] == "D") {
$data[1] = $data[1] . " Die";
if (isset($sensor[$limit="crit"]) && preg_match("/^\+?(-?[\d\.]+)[^\w\r\n\t]+C$/", $sensor[$limit], $tmpbuf) && (($tmpbuf[1]=floatval($tmpbuf[1])) > 0)) {
$dev->setMax(floatval($tmpbuf[1]));
} elseif (isset($sensor[$limit="high"]) && preg_match("/^\+?(-?[\d\.]+)[^\w\r\n\t]+C$/", $sensor[$limit], $tmpbuf) && (($tmpbuf[1]=floatval($tmpbuf[1])) > 0) && ($tmpbuf[1]<65261.8)) {
$dev->setMax(floatval($tmpbuf[1]));
}
$this->mbinfo->setMbTemp($dev);
}
}
$dev->setName($data[1]);
$dev->setValue($data[2]);
if (isset($data[6]) && $data[2] <= $data[6]) {
$dev->setMax(max($data[4], $data[6]));
} elseif (isset($data[4]) && $data[2] <= $data[4]) {
$dev->setMax($data[4]);
}
if (preg_match("/\sALARM(\s*)$/", $line)) {
$dev->setEvent("Alarm");
}
$this->mbinfo->setMbTemp($dev);
}
}
@@ -160,50 +173,32 @@ class LMSensors extends Sensors
*/
private function _fans()
{
$ar_buf = array();
foreach ($this->_lines as $line) {
$data = array();
if (preg_match("/(.*):(.*)\((.*)=(.*),(.*)=(.*)\)(.*)/", $line, $data)) {
;
} elseif (preg_match("/(.*):(.*)\((.*)=(.*)\)(.*)/", $line, $data)) {
;
} else {
preg_match("/(.*):(.*)/", $line, $data);
}
if (count($data) > 1) {
$temp = substr(trim($data[2]), -4);
switch ($temp) {
case " RPM":
array_push($ar_buf, $line);
foreach ($this->_values as $sensors) foreach ($sensors as $sensor){
if (isset($sensor["value"])) {
$limit = "";
if (preg_match("/^(\d+) RPM$/", $sensor["value"], $tmpbuf) ||
((isset($sensor[$limit="min"]) || isset($sensor[$limit="max"])) && preg_match("/^(\d+) RPM$/", $sensor[$limit]))) {
$dev = new SensorDevice();
$dev->setName($sensor["name"]);
if ($limit != "") {
$dev->setValue($sensor["value"]);
$dev->setEvent("FAULT");
} else {
$dev->setValue($tmpbuf[1]);
}
if (isset($sensor["alarm"])) $dev->setEvent("ALARM");
if (isset($sensor[$limit="min"]) && preg_match("/^(\d+) RPM$/", $sensor[$limit], $tmpbuf) && ($tmpbuf[1] > 0)) {
$dev->setMin($tmpbuf[1]);
}
$this->mbinfo->setMbFan($dev);
}
}
}
foreach ($ar_buf as $line) {
$data = array();
if (preg_match("/(.*):(.*) RPM[ ]*\((.*)=(.*) RPM,(.*)=(.*)\)(.*)\)/", $line, $data)) {
;
} elseif (preg_match("/(.*):(.*) RPM[ ]*\((.*)=(.*) RPM,(.*)=(.*)\)(.*)/", $line, $data)) {
;
} elseif (preg_match("/(.*):(.*) RPM[ ]*\((.*)=(.*) RPM\)(.*)/", $line, $data)) {
;
} elseif (preg_match("/(.*):(.*) RPM[ \t]+/", $line, $data)) {
;
} else {
preg_match("/(.*):(.*) RPM$/", $line, $data);
}
$dev = new SensorDevice();
$dev->setName(trim($data[1]));
$dev->setValue(trim($data[2]));
if (isset($data[4])) {
$dev->setMin(trim($data[4]));
}
if (preg_match("/\sALARM(\s*)$/", $line)) {
$dev->setEvent("Alarm");
}
$this->mbinfo->setMbFan($dev);
}
}
/**
* get voltage information
*
@@ -211,58 +206,37 @@ class LMSensors extends Sensors
*/
private function _voltage()
{
$ar_buf = array();
foreach ($this->_lines as $line) {
$data = array();
if (preg_match("/(.*):(.*)\((.*)=(.*),(.*)=(.*)\)(.*)/", $line, $data)) {
;
} elseif (preg_match("/(.*):(.*)\(/", $line, $data)) {
;
} else {
preg_match("/(.*):(.*)/", $line, $data);
}
if (count($data) > 1) {
$temp = substr(trim($data[2]), -2);
switch ($temp) {
case " V":
array_push($ar_buf, $line);
foreach ($this->_values as $sensors) foreach ($sensors as $sensor){
if (isset($sensor["value"])) {
$limit = "";
if (preg_match("/^\+?(-?[\d\.]+) (m?)V$/", $sensor["value"], $tmpbuf) ||
((isset($sensor[$limit="min"]) || isset($sensor[$limit="max"])) && preg_match("/^\+?(-?[\d\.]+) (m?)V$/", $sensor[$limit]))) {
$dev = new SensorDevice();
$dev->setName($sensor["name"]);
if ($limit != "") {
$dev->setValue($sensor["value"]);
$dev->setEvent("FAULT");
} else {
if ($tmpbuf[2] == "m") {
$dev->setValue(floatval($tmpbuf[1])/1000);
} else {
$dev->setValue(floatval($tmpbuf[1]));
}
}
if (isset($sensor["alarm"])) $dev->setEvent("ALARM");
if (isset($sensor[$limit="min"]) && preg_match("/^\+?(-?[\d\.]+) (m?)V$/", $sensor[$limit], $tmpbuf)) {
$dev->setMin(floatval($tmpbuf[1]));
}
if (isset($sensor[$limit="max"]) && preg_match("/^\+?(-?[\d\.]+) (m?)V$/", $sensor[$limit], $tmpbuf)) {
$dev->setMax(floatval($tmpbuf[1]));
}
$this->mbinfo->setMbVolt($dev);
}
}
}
foreach ($ar_buf as $line) {
$data = array();
if (preg_match("/(.*):(.*) V[ ]*\((.*)=(.*) V,(.*)=(.*) V\)(.*)\)/", $line, $data)) {
;
} elseif (preg_match("/(.*):(.*) V[ ]*\((.*)=(.*) V,(.*)=(.*) V\)(.*)/", $line, $data)) {
;
} elseif (preg_match("/(.*):(.*) V[ \t]+/", $line, $data)) {
;
} else {
preg_match("/(.*):(.*) V$/", $line, $data);
}
foreach ($data as $key=>$value) {
if (preg_match("/^\+?(-?[0-9\.]+)$/", trim($value), $newvalue)) {
$data[$key] = 0+trim($newvalue[1]);
} else {
$data[$key] = trim($value);
}
}
if (isset($data[1])) {
$dev = new SensorDevice();
$dev->setName($data[1]);
$dev->setValue($data[2]);
if (isset($data[4])) {
$dev->setMin($data[4]);
}
if (isset($data[6])) {
$dev->setMax($data[6]);
}
if (preg_match("/\sALARM(\s*)$/", $line)) {
$dev->setEvent("Alarm");
}
$this->mbinfo->setMbVolt($dev);
}
}
}
/**
@@ -272,63 +246,32 @@ class LMSensors extends Sensors
*/
private function _power()
{
$ar_buf = array();
foreach ($this->_lines as $line) {
$data = array();
if (preg_match("/(.*):(.*)\((.*)=(.*),(.*)=(.*)\)(.*)/", $line, $data)) {
;
} elseif (preg_match("/(.*):(.*)\((.*)=(.*)\)(.*)/", $line, $data)) {
;
} else {
preg_match("/(.*):(.*)/", $line, $data);
}
if (count($data) > 1) {
$temp = substr(trim($data[2]), -2);
switch ($temp) {
case " W":
array_push($ar_buf, $line);
}
}
}
foreach ($ar_buf as $line) {
$data = array();
/* not tested yet
if (preg_match("/(.*):(.*) W[ ]*\((.*)=(.*) W,(.*)=(.*) W\)(.*)\)/", $line, $data)) {
;
} elseif (preg_match("/(.*):(.*) W[ ]*\((.*)=(.*) W,(.*)=(.*) W\)(.*)/", $line, $data)) {
;
} else
*/
if (preg_match("/(.*):(.*) W[ ]*\((.*)=(.*) W\)(.*)/", $line, $data)) {
;
} elseif (preg_match("/(.*):(.*) W[ \t]+/", $line, $data)) {
;
} else {
preg_match("/(.*):(.*) W$/", $line, $data);
}
foreach ($data as $key=>$value) {
if (preg_match("/^\+?([0-9\.]+).?$/", trim($value), $newvalue)) {
$data[$key] = trim($newvalue[1]);
} else {
$data[$key] = trim($value);
}
}
$dev = new SensorDevice();
$dev->setName($data[1]);
$dev->setValue($data[2]);
foreach ($this->_values as $sensors) foreach ($sensors as $sensor){
if (isset($sensor["value"])) {
$limit = "";
if (preg_match("/^\+?(-?[\d\.]+) W$/", $sensor["value"], $tmpbuf) ||
(isset($sensor[$limit="crit"]) && preg_match("/^\+?(-?[\d\.]+) W$/", $sensor[$limit]))) {
$dev = new SensorDevice();
$dev->setName($sensor["name"]);
if ($limit != "") {
$dev->setValue($sensor["value"]);
$dev->setEvent("FAULT");
} else {
$dev->setValue(floatval($tmpbuf[1]));
}
if (isset($sensor["alarm"])) $dev->setEvent("ALARM");
if (isset($data[6]) && $data[2] <= $data[6]) {
$dev->setMax(max($data[4], $data[6]));
} elseif (isset($data[4]) && $data[2] <= $data[4]) {
$dev->setMax($data[4]);
if (isset($sensor[$limit="crit"]) && preg_match("/^\+?(-?[\d\.]+) W$/", $sensor[$limit], $tmpbuf)) {
$dev->setMax(floatval($tmpbuf[1]));
}
$this->mbinfo->setMbPower($dev);
}
}
if (preg_match("/\sALARM(\s*)$/", $line)) {
$dev->setEvent("Alarm");
}
$this->mbinfo->setMbPower($dev);
}
}
/**
* get current information
*
@@ -336,60 +279,54 @@ class LMSensors extends Sensors
*/
private function _current()
{
$ar_buf = array();
foreach ($this->_lines as $line) {
$data = array();
if (preg_match("/(.*):(.*)\((.*)=(.*),(.*)=(.*)\)(.*)/", $line, $data)) {
;
} elseif (preg_match("/(.*):(.*)\((.*)=(.*)\)(.*)/", $line, $data)) {
;
} else {
preg_match("/(.*):(.*)/", $line, $data);
}
if (count($data) > 1) {
$temp = substr(trim($data[2]), -2);
switch ($temp) {
case " A":
array_push($ar_buf, $line);
foreach ($this->_values as $sensors) foreach ($sensors as $sensor){
if (isset($sensor["value"])) {
$limit = "";
if (preg_match("/^\+?(-?[\d\.]+) A$/", $sensor["value"], $tmpbuf) ||
(isset($sensor[$limit="crit"]) && preg_match("/^\+?(-?[\d\.]+) A$/", $sensor[$limit]))) {
$dev = new SensorDevice();
$dev->setName($sensor["name"]);
if ($limit != "") {
$dev->setValue($sensor["value"]);
$dev->setEvent("FAULT");
} else {
$dev->setValue(floatval($tmpbuf[1]));
}
if (isset($sensor["alarm"])) $dev->setEvent("ALARM");
if (isset($sensor[$limit="min"]) && preg_match("/^\+?(-?[\d\.]+) A$/", $sensor[$limit], $tmpbuf)) {
$dev->setMin(floatval($tmpbuf[1]));
}
if (isset($sensor[$limit="max"]) && preg_match("/^\+?(-?[\d\.]+) A$/", $sensor[$limit], $tmpbuf)) {
$dev->setMax(floatval($tmpbuf[1]));
}
$this->mbinfo->setMbCurrent($dev);
}
}
}
foreach ($ar_buf as $line) {
$data = array();
/* not tested yet
if (preg_match("/(.*):(.*) A[ ]*\((.*)=(.*) A,(.*)=(.*) A\)(.*)\)/", $line, $data)) {
;
} elseif (preg_match("/(.*):(.*) A[ ]*\((.*)=(.*) A,(.*)=(.*) A\)(.*)/", $line, $data)) {
;
} else
*/
if (preg_match("/(.*):(.*) A[ ]*\((.*)=(.*) A\)(.*)/", $line, $data)) {
;
} elseif (preg_match("/(.*):(.*) A[ \t]+/", $line, $data)) {
;
} else {
preg_match("/(.*):(.*) A$/", $line, $data);
}
foreach ($data as $key=>$value) {
if (preg_match("/^\+?([0-9\.]+).?$/", trim($value), $newvalue)) {
$data[$key] = trim($newvalue[1]);
} else {
$data[$key] = trim($value);
}
/**
* get other information
*
* @return void
*/
private function _other()
{
foreach ($this->_values as $sensors) foreach ($sensors as $sensor){
if (isset($sensor["value"])) {
if ((preg_match("/^[^\-\+\d]/", $sensor["value"]) || preg_match("/^\d+$/", $sensor["value"])) && ($sensor["value"] !== 'failed') &&
!isset($sensor[$limit="min"]) && !isset($sensor[$limit="max"]) && !isset($sensor[$limit="crit"]) && !isset($sensor[$limit="high"]) && !isset($sensor[$limit="hyst"])) {
$dev = new SensorDevice();
$dev->setName($sensor["name"]);
$dev->setValue($sensor["value"]);
if (isset($sensor["alarm"])) $dev->setEvent("ALARM");
$this->mbinfo->setMbOther($dev);
}
}
$dev = new SensorDevice();
$dev->setName($data[1]);
$dev->setValue($data[2]);
if (isset($data[6]) && $data[2] <= $data[6]) {
$dev->setMax(max($data[4], $data[6]));
} elseif (isset($data[4]) && $data[2] <= $data[4]) {
$dev->setMax($data[4]);
}
if (preg_match("/\sALARM(\s*)$/", $line)) {
$dev->setEvent("Alarm");
}
$this->mbinfo->setMbCurrent($dev);
}
}
@@ -398,14 +335,15 @@ class LMSensors extends Sensors
*
* @see PSI_Interface_Sensor::build()
*
* @return Void
* @return void
*/
public function build()
{
$this->_temperature();
$this->_voltage();
$this->_fans();
$this->_voltage();
$this->_power();
$this->_current();
$this->_other();
}
}

View File

@@ -1,6 +1,6 @@
<?php
/**
* MBM5 sensor class
* MBM5 sensor class, getting information from Motherboard Monitor 5 information retrival through csv file
*
* PHP version 5
*
@@ -8,19 +8,7 @@
* @package PSI_Sensor
* @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.mbm5.inc.php 661 2012-08-27 11:26:39Z namiltd $
* @link http://phpsysinfo.sourceforge.net
*/
/**
* getting information from Motherboard Monitor 5
* information retrival through csv file
*
* @category PHP
* @package PSI_Sensor
* @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
*/
@@ -46,20 +34,15 @@ class MBM5 extends Sensors
public function __construct()
{
parent::__construct();
switch (strtolower(PSI_SENSOR_ACCESS)) {
case 'file':
if ((PSI_OS == 'WINNT') && !defined('PSI_EMU_HOSTNAME')) {
$delim = "/;/";
CommonFunctions::rfts(APP_ROOT."/data/MBM5.csv", $buffer);
CommonFunctions::rftsdata("MBM5.csv", $buffer);
if (strpos($buffer, ";") === false) {
$delim = "/,/";
}
$buffer = preg_split("/\n/", $buffer, -1, PREG_SPLIT_NO_EMPTY);
$this->_buf_label = preg_split($delim, substr($buffer[0], 0, -2), -1, PREG_SPLIT_NO_EMPTY);
$this->_buf_value = preg_split($delim, substr($buffer[1], 0, -2), -1, PREG_SPLIT_NO_EMPTY);
break;
default:
$this->error->addConfigError('__construct()', 'PSI_SENSOR_ACCESS');
break;
}
}
@@ -78,7 +61,7 @@ class MBM5 extends Sensors
$dev = new SensorDevice();
$dev->setName($this->_buf_label[$intPosi]);
$dev->setValue($hits[0]);
$dev->setMax(70);
// $dev->setMax(70);
$this->mbinfo->setMbTemp($dev);
}
}
@@ -98,7 +81,7 @@ class MBM5 extends Sensors
$dev = new SensorDevice();
$dev->setName($this->_buf_label[$intPosi]);
$dev->setValue($hits[0]);
$dev->setMin(3000);
// $dev->setMin(3000);
$this->mbinfo->setMbFan($dev);
}
}
@@ -127,7 +110,7 @@ class MBM5 extends Sensors
*
* @see PSI_Interface_Sensor::build()
*
* @return Void
* @return void
*/
public function build()
{

View File

@@ -1,6 +1,6 @@
<?php
/**
* mbmon sensor class
* mbmon sensor class, getting information from mbmon
*
* PHP version 5
*
@@ -8,18 +8,7 @@
* @package PSI_Sensor
* @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.mbmon.inc.php 661 2012-08-27 11:26:39Z namiltd $
* @link http://phpsysinfo.sourceforge.net
*/
/**
* getting information from mbmon
*
* @category PHP
* @package PSI_Sensor
* @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
*/
@@ -33,14 +22,14 @@ class MBMon extends Sensors
private $_lines = array();
/**
* fill the private content var through tcp or file access
* fill the private content var through tcp, command or data access
*/
public function __construct()
{
parent::__construct();
switch (strtolower(PSI_SENSOR_ACCESS)) {
if ((PSI_OS != 'WINNT') && (!defined('PSI_EMU_HOSTNAME') || defined('PSI_EMU_PORT'))) switch (defined('PSI_SENSOR_MBMON_ACCESS')?strtolower(PSI_SENSOR_MBMON_ACCESS):'command') {
case 'tcp':
$fp = fsockopen("localhost", 411, $errno, $errstr, 5);
$fp = fsockopen(defined('PSI_EMU_HOSTNAME')?PSI_EMU_HOSTNAME:'localhost', 411, $errno, $errstr, 5);
if ($fp) {
$lines = "";
while (!feof($fp)) {
@@ -55,14 +44,13 @@ class MBMon extends Sensors
CommonFunctions::executeProgram('mbmon', '-c 1 -r', $lines, PSI_DEBUG);
$this->_lines = preg_split("/\n/", $lines, -1, PREG_SPLIT_NO_EMPTY);
break;
case 'file':
if (CommonFunctions::rfts(APP_ROOT.'/data/mbmon.txt', $lines)) {
case 'data':
if (!defined('PSI_EMU_PORT') && CommonFunctions::rftsdata('mbmon.tmp', $lines)) {
$this->_lines = preg_split("/\n/", $lines, -1, PREG_SPLIT_NO_EMPTY);
}
break;
default:
$this->error->addConfigError('__construct()', 'PSI_SENSOR_ACCESS');
break;
$this->error->addConfigError('__construct()', '[sensor_mbmon] ACCESS');
}
}
@@ -78,7 +66,7 @@ class MBMon extends Sensors
if ($data[2] <> '0') {
$dev = new SensorDevice();
$dev->setName($data[1]);
$dev->setMax(70);
// $dev->setMax(70);
if ($data[2] < 250) {
$dev->setValue($data[2]);
}
@@ -101,7 +89,7 @@ class MBMon extends Sensors
$dev = new SensorDevice();
$dev->setName($data[1]);
$dev->setValue($data[2]);
$dev->setMax(3000);
// $dev->setMax(3000);
$this->mbinfo->setMbFan($dev);
}
}

View File

@@ -0,0 +1,136 @@
<?php
/**
* nvidiasmi sensor class, getting hardware temperature information and fan speed from nvidia-smi utility
*
* PHP version 5
*
* @category PHP
* @package PSI_Sensor
* @author Mieczyslaw Nalewaj <namiltd@users.sourceforge.net>
* @copyright 2020 phpSysInfo
* @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
*/
class NvidiaSMI extends Sensors
{
/**
* content to parse
*
* @var array
*/
private $_gpus = array();
/**
* fill the private array
*/
public function __construct()
{
parent::__construct();
if (!defined('PSI_EMU_HOSTNAME') || defined('PSI_EMU_PORT')) switch (defined('PSI_SENSOR_NVIDIASMI_ACCESS')?strtolower(PSI_SENSOR_NVIDIASMI_ACCESS):'command') {
case 'command':
if (PSI_OS == 'WINNT') {
$winnt_exe = (defined('PSI_SENSOR_NVIDIASMI_EXE_PATH') && is_string(PSI_SENSOR_NVIDIASMI_EXE_PATH))?strtolower(PSI_SENSOR_NVIDIASMI_EXE_PATH):"c:\\Program Files\\NVIDIA Corporation\\NVSMI\\nvidia-smi.exe";
if (($_exe=realpath(trim($winnt_exe))) && preg_match("/^([a-zA-Z]:\\\\[^\\\\]+)/", $_exe, $out)) {
CommonFunctions::executeProgram('cmd', "/c set ProgramFiles=".$out[1]."^&\"".$_exe."\" -q", $lines);
} else {
$this->error->addConfigError('__construct()', '[sensor_nvidiasmi] EXE_PATH="'.$winnt_exe.'"');
}
} else {
CommonFunctions::executeProgram('nvidia-smi', '-q', $lines);
}
$this->_gpus = preg_split("/^(?=GPU )/m", $lines, -1, PREG_SPLIT_NO_EMPTY);
break;
case 'data':
if (!defined('PSI_EMU_PORT') && CommonFunctions::rftsdata('nvidiasmi.tmp', $lines)) {
$this->_gpus = preg_split("/^(?=GPU )/m", $lines, -1, PREG_SPLIT_NO_EMPTY);
}
break;
default:
$this->error->addConfigError('__construct()', '[sensor_nvidiasmi] ACCESS');
}
}
/**
* get the information
*
* @see PSI_Interface_Sensor::build()
*
* @return void
*/
public function build()
{
$gpuc=count($this->_gpus);
switch ($gpuc) {
case 0:
$this->error->addError("nvidia-smi", "No values");
break;
case 1:
$this->error->addError("nvidia-smi", "Error: ".$this->_gpus[0]);
break;
default:
for ($c = 0; $c < $gpuc; $c++) {
if (preg_match("/^\s+GPU Current Temp\s+:\s*(\d+)\s*C\s*$/m", $this->_gpus[$c], $out)) {
$dev = new SensorDevice();
$dev->setName("GPU ".($c)." (nvidiasmi)");
$dev->setValue($out[1]);
if (preg_match("/^\s+GPU Shutdown Temp\s+:\s*(\d+)\s*C\s*$/m", $this->_gpus[$c], $out)) {
$dev->setMax($out[1]);
}
$this->mbinfo->setMbTemp($dev);
}
if (preg_match("/^\s+Power Draw\s+:\s*([\d\.]+)\s*W\s*$/m", $this->_gpus[$c], $out)) {
$dev = new SensorDevice();
$dev->setName("GPU ".($c)." (nvidiasmi)");
$dev->setValue($out[1]);
if (preg_match("/^\s+Power Limit\s+:\s*([\d\.]+)\s*W\s*$/m", $this->_gpus[$c], $out)) {
$dev->setMax($out[1]);
}
$this->mbinfo->setMbPower($dev);
}
if (preg_match("/^\s+Fan Speed\s+:\s*(\d+)\s*%\s*$/m", $this->_gpus[$c], $out)) {
$dev = new SensorDevice();
$dev->setName("GPU ".($c)." (nvidiasmi)");
$dev->setValue($out[1]);
$dev->setUnit("%");
$this->mbinfo->setMbFan($dev);
}
if (preg_match("/^\s+Performance State\s+:\s*(\S+)\s*$/m", $this->_gpus[$c], $out)) {
$dev = new SensorDevice();
$dev->setName("GPU ".($c)." Performance State (nvidiasmi)");
$dev->setValue($out[1]);
$this->mbinfo->setMbOther($dev);
}
if (preg_match("/^\s+Gpu\s+:\s*(\d+)\s*%\s*$/m", $this->_gpus[$c], $out)) {
$dev = new SensorDevice();
$dev->setName("GPU ".($c)." Utilization (nvidiasmi)");
$dev->setValue($out[1]);
$dev->setUnit("%");
$this->mbinfo->setMbOther($dev);
}
if (preg_match("/^\s+Memory\s+:\s*(\d+)\s*%\s*$/m", $this->_gpus[$c], $out)) {
$dev = new SensorDevice();
$dev->setName("GPU ".($c)." Memory Utilization (nvidiasmi)");
$dev->setValue($out[1]);
$dev->setUnit("%");
$this->mbinfo->setMbOther($dev);
}
if (preg_match("/^\s+Encoder\s+:\s*(\d+)\s*%\s*$/m", $this->_gpus[$c], $out)) {
$dev = new SensorDevice();
$dev->setName("GPU ".($c)." Encoder Utilization (nvidiasmi)");
$dev->setValue($out[1]);
$dev->setUnit("%");
$this->mbinfo->setMbOther($dev);
}
if (preg_match("/^\s+Decoder\s+:\s*(\d+)\s*%\s*$/m", $this->_gpus[$c], $out)) {
$dev = new SensorDevice();
$dev->setName("GPU ".($c)." Decoder Utilization (nvidiasmi)");
$dev->setValue($out[1]);
$dev->setUnit("%");
$this->mbinfo->setMbOther($dev);
}
}
}
}
}

View File

@@ -1,25 +1,14 @@
<?php
/**
* Open Hardware Monitor sensor class
* Open Hardware Monitor sensor class, getting information from Open Hardware Monitor
*
* PHP version 5
*
* @category PHP
* @package PSI_Sensor
* @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.ohm.inc.php 661 2012-08-27 11:26:39Z namiltd $
* @link http://phpsysinfo.sourceforge.net
*/
/**
* getting information from Open Hardware Monitor
*
* @category PHP
* @package PSI_Sensor
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @author Mieczyslaw Nalewaj <namiltd@users.sourceforge.net>
* @copyright 2014 phpSysInfo
* @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
*/
@@ -38,25 +27,16 @@ class OHM extends Sensors
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);
if ((PSI_OS == 'WINNT') || (defined('PSI_EMU_HOSTNAME') && !defined('PSI_EMU_PORT'))) {
$_wmi = WINNT::initWMI('root\OpenHardwareMonitor', true);
if ($_wmi) {
$tmpbuf = WINNT::getWMI($_wmi, 'Sensor', array('Parent', 'Name', 'SensorType', 'Value'));
if ($tmpbuf) foreach ($tmpbuf as $buffer) {
if (!isset($this->_buf[$buffer['SensorType']]) || !isset($this->_buf[$buffer['SensorType']][$buffer['Parent'].' '.$buffer['Name']])) { // avoid duplicates
$this->_buf[$buffer['SensorType']][$buffer['Parent'].' '.$buffer['Name']] = $buffer['Value'];
}
}
}
} 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'));
}
}
@@ -67,13 +47,11 @@ class OHM extends Sensors
*/
private function _temperature()
{
if ($this->_buf) foreach ($this->_buf as $buffer) {
if ($buffer['SensorType'] == "Temperature") {
$dev = new SensorDevice();
$dev->setName($buffer['Parent'].' '.$buffer['Name']);
$dev->setValue($buffer['Value']);
$this->mbinfo->setMbTemp($dev);
}
if (isset($this->_buf['Temperature'])) foreach ($this->_buf['Temperature'] as $name=>$value) {
$dev = new SensorDevice();
$dev->setName($name);
$dev->setValue($value);
$this->mbinfo->setMbTemp($dev);
}
}
@@ -84,13 +62,11 @@ class OHM extends Sensors
*/
private function _voltage()
{
if ($this->_buf) foreach ($this->_buf as $buffer) {
if ($buffer['SensorType'] == "Voltage") {
$dev = new SensorDevice();
$dev->setName($buffer['Parent'].' '.$buffer['Name']);
$dev->setValue($buffer['Value']);
$this->mbinfo->setMbVolt($dev);
}
if (isset($this->_buf['Voltage'])) foreach ($this->_buf['Voltage'] as $name=>$value) {
$dev = new SensorDevice();
$dev->setName($name);
$dev->setValue($value);
$this->mbinfo->setMbVolt($dev);
}
}
@@ -101,13 +77,11 @@ class OHM extends Sensors
*/
private function _fans()
{
if ($this->_buf) foreach ($this->_buf as $buffer) {
if ($buffer['SensorType'] == "Fan") {
$dev = new SensorDevice();
$dev->setName($buffer['Parent'].' '.$buffer['Name']);
$dev->setValue($buffer['Value']);
$this->mbinfo->setMbFan($dev);
}
if (isset($this->_buf['Fan'])) foreach ($this->_buf['Fan'] as $name=>$value) {
$dev = new SensorDevice();
$dev->setName($name);
$dev->setValue($value);
$this->mbinfo->setMbFan($dev);
}
}
@@ -118,13 +92,11 @@ class OHM extends Sensors
*/
private function _power()
{
if ($this->_buf) foreach ($this->_buf as $buffer) {
if ($buffer['SensorType'] == "Power") {
$dev = new SensorDevice();
$dev->setName($buffer['Parent'].' '.$buffer['Name']);
$dev->setValue($buffer['Value']);
$this->mbinfo->setMbPower($dev);
}
if (isset($this->_buf['Power'])) foreach ($this->_buf['Power'] as $name=>$value) {
$dev = new SensorDevice();
$dev->setName($name);
$dev->setValue($value);
$this->mbinfo->setMbPower($dev);
}
}
@@ -133,7 +105,7 @@ class OHM extends Sensors
*
* @see PSI_Interface_Sensor::build()
*
* @return Void
* @return void
*/
public function build()
{

View File

@@ -7,8 +7,10 @@
* @category PHP
* @package PSI_Sensor
* @author Marc Hillesheim <hawkeyexp@gmail.com>
* @copyright 2012 Marc Hillesheim
* @link http://pi.no-ip.biz
* @copyright 2012 phpSysInfo
* @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
*/
class PiTemp extends Sensors
{
@@ -16,15 +18,15 @@ class PiTemp extends Sensors
{
$temp = null;
$temp_max = null;
if (!CommonFunctions::rfts('/sys/devices/platform/sunxi-i2c.0/i2c-0/0-0034/temp1_input', $temp, 0, 4096, false)) { // Not Banana Pi
CommonFunctions::rfts('/sys/class/thermal/thermal_zone0/temp', $temp);
CommonFunctions::rfts('/sys/class/thermal/thermal_zone0/trip_point_0_temp', $temp_max, 0, 4096, PSI_DEBUG);
if (!CommonFunctions::rfts('/sys/devices/platform/sunxi-i2c.0/i2c-0/0-0034/temp1_input', $temp, 1, 4096, false)) { // Not Banana Pi
CommonFunctions::rfts('/sys/class/thermal/thermal_zone0/temp', $temp, 1);
CommonFunctions::rfts('/sys/class/thermal/thermal_zone0/trip_point_0_temp', $temp_max, 1, 4096, PSI_DEBUG);
}
if (!is_null($temp) && (trim($temp) != "")) {
if (($temp !== null) && (($temp = trim($temp)) != "")) {
$dev = new SensorDevice();
$dev->setName("CPU 1");
$dev->setValue($temp / 1000);
if (!is_null($temp_max) && (trim($temp_max) != "") && ($temp_max > 0)) {
if (($temp_max !== null) && (($temp_max = trim($temp_max)) != "") && ($temp_max > 0)) {
$dev->setMax($temp_max / 1000);
}
$this->mbinfo->setMbTemp($dev);
@@ -34,7 +36,7 @@ class PiTemp extends Sensors
private function _voltage()
{
$volt = null;
if (CommonFunctions::rfts('/sys/devices/platform/sunxi-i2c.0/i2c-0/0-0034/axp20-supplyer.28/power_supply/ac/voltage_now', $volt, 0, 4096, false) && !is_null($volt) && (trim($volt) != "")) { // Banana Pi
if (CommonFunctions::rfts('/sys/devices/platform/sunxi-i2c.0/i2c-0/0-0034/axp20-supplyer.28/power_supply/ac/voltage_now', $volt, 1, 4096, false) && ($volt !== null) && (($volt = trim($volt)) != "")) { // Banana Pi
$dev = new SensorDevice();
$dev->setName("Voltage 1");
$dev->setValue($volt / 1000000);
@@ -45,7 +47,7 @@ class PiTemp extends Sensors
private function _current()
{
$current = null;
if (CommonFunctions::rfts('/sys/devices/platform/sunxi-i2c.0/i2c-0/0-0034/axp20-supplyer.28/power_supply/ac/current_now', $current, 0, 4096, false) && !is_null($current) && (trim($current) != "")) { // Banana Pi
if (CommonFunctions::rfts('/sys/devices/platform/sunxi-i2c.0/i2c-0/0-0034/axp20-supplyer.28/power_supply/ac/current_now', $current, 1, 4096, false) && ($current !== null) && (($current = trim($current)) != "")) { // Banana Pi
$dev = new SensorDevice();
$dev->setName("Current 1");
$dev->setValue($current / 1000000);
@@ -55,8 +57,10 @@ class PiTemp extends Sensors
public function build()
{
$this->_temperature();
$this->_voltage();
$this->_current();
if ((PSI_OS == 'Linux') && !defined('PSI_EMU_HOSTNAME')) {
$this->_temperature();
$this->_voltage();
$this->_current();
}
}
}

View File

@@ -0,0 +1,93 @@
<?php
/**
* qtstemp sensor class, getting hardware temperature information through snmpwalk
*
* PHP version 5
*
* @category PHP
* @package PSI_Sensor
* @author Mieczyslaw Nalewaj <namiltd@users.sourceforge.net>
* @copyright 2016 phpSysInfo
* @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
*/
class QTSsnmp extends Sensors
{
/**
* get temperature information
*
* @return void
*/
private function _temperature()
{
if (!defined('PSI_EMU_PORT')) {
$address = '127.0.0.1';
} else {
$address = PSI_EMU_HOSTNAME;
}
if (CommonFunctions::executeProgram("snmpwalk", "-Ona -c public -v 1 -t ".PSI_SNMP_TIMEOUT_INT." -r ".PSI_SNMP_RETRY_INT." ".$address." .1.3.6.1.4.1.24681.1.2.5.0", $buffer, PSI_DEBUG)
&& preg_match('/^[\.\d]+ = STRING:\s\"?(\d+)\sC/', $buffer, $data)) {
$dev = new SensorDevice();
$dev->setName("CPU");
$dev->setValue($data[1]);
$this->mbinfo->setMbTemp($dev);
}
if (CommonFunctions::executeProgram("snmpwalk", "-Ona -c public -v 1 -t ".PSI_SNMP_TIMEOUT_INT." -r ".PSI_SNMP_RETRY_INT." ".$address." .1.3.6.1.4.1.24681.1.2.6.0", $buffer, PSI_DEBUG)
&& preg_match('/^[\.\d]+ = STRING:\s\"?(\d+)\sC/', $buffer, $data)) {
$dev = new SensorDevice();
$dev->setName("System");
$dev->setValue($data[1]);
$this->mbinfo->setMbTemp($dev);
}
if (CommonFunctions::executeProgram("snmpwalk", "-Ona -c public -v 1 -t ".PSI_SNMP_TIMEOUT_INT." -r ".PSI_SNMP_RETRY_INT." ".$address." .1.3.6.1.4.1.24681.1.2.11.1.3", $buffer, PSI_DEBUG)) {
$lines = preg_split('/\r?\n/', $buffer);
foreach ($lines as $line) if (preg_match('/^[\.\d]+\.(\d+) = STRING:\s\"?(\d+)\sC/', $line, $data)) {
$dev = new SensorDevice();
$dev->setName("HDD ".$data[1]);
$dev->setValue($data[2]);
$this->mbinfo->setMbTemp($dev);
}
}
}
/**
* get fan information
*
* @return void
*/
private function _fans()
{
if (!defined('PSI_EMU_PORT')) {
$address = '127.0.0.1';
} else {
$address = PSI_EMU_HOSTNAME;
}
if (CommonFunctions::executeProgram("snmpwalk", "-Ona -c public -v 1 -t ".PSI_SNMP_TIMEOUT_INT." -r ".PSI_SNMP_RETRY_INT." ".$address." .1.3.6.1.4.1.24681.1.2.15.1.3", $buffer, PSI_DEBUG)) {
$lines = preg_split('/\r?\n/', $buffer);
foreach ($lines as $line) if (preg_match('/^[\.\d]+\.(\d+) = STRING:\s\"?(\d+)\sRPM/', $line, $data)) {
$dev = new SensorDevice();
$dev->setName("Fan ".$data[1]);
$dev->setValue($data[2]);
$this->mbinfo->setMbFan($dev);
}
}
}
/**
* get the information
*
* @see PSI_Interface_Sensor::build()
*
* @return void
*/
public function build()
{
if ((PSI_OS == 'Linux') && (!defined('PSI_EMU_HOSTNAME') || defined('PSI_EMU_PORT'))) {
$this->_temperature();
$this->_fans();
}
}
}

View File

@@ -8,7 +8,7 @@
* @package PSI sensors class
* @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 SVN: $Id: class.sensors.inc.php 661 2012-08-27 11:26:39Z namiltd $
* @link http://phpsysinfo.sourceforge.net
*/
@@ -19,7 +19,7 @@
* @package PSI sensors class
* @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
*/
@@ -28,7 +28,7 @@ abstract class Sensors implements PSI_Interface_Sensor
/**
* object for error handling
*
* @var Error
* @var PSI_Error
*/
protected $error;
@@ -44,7 +44,7 @@ abstract class Sensors implements PSI_Interface_Sensor
*/
public function __construct()
{
$this->error = Error::singleton();
$this->error = PSI_Error::singleton();
$this->mbinfo = new MBInfo();
}

View File

@@ -0,0 +1,125 @@
<?php
/**
* speedfan sensor class, getting hardware information through SpeedFanGet
*
* PHP version 5
*
* @category PHP
* @package PSI_Sensor
* @author Mieczyslaw Nalewaj <namiltd@users.sourceforge.net>
* @copyright 2016 phpSysInfo
* @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
*/
class SpeedFan extends Sensors
{
/*
* variable, which holds the content of the command
* @var array
*/
private $_filecontent = array();
public function __construct()
{
parent::__construct();
if ((PSI_OS == 'WINNT') && !defined('PSI_EMU_HOSTNAME')) switch (defined('PSI_SENSOR_SPEEDFAN_ACCESS')?strtolower(PSI_SENSOR_SPEEDFAN_ACCESS):'command') {
case 'command':
if (CommonFunctions::executeProgram("SpeedFanGet.exe", "", $buffer, PSI_DEBUG) && (strlen($buffer) > 0)) {
if (preg_match("/^Temperatures:\s+(.+)$/m", $buffer, $out)) {
$this->_filecontent["temp"] = $out[1];
}
if (preg_match("/^Fans:\s+(.+)$/m", $buffer, $out)) {
$this->_filecontent["fans"] = $out[1];
}
if (preg_match("/^Voltages:\s+(.+)$/m", $buffer, $out)) {
$this->_filecontent["volt"] = $out[1];
}
}
break;
case 'data':
if (CommonFunctions::rftsdata('speedfan.tmp', $buffer) && (strlen($buffer) > 0)) {
if (preg_match("/^Temperatures:\s+(.+)$/m", $buffer, $out)) {
$this->_filecontent["temp"] = $out[1];
}
if (preg_match("/^Fans:\s+(.+)$/m", $buffer, $out)) {
$this->_filecontent["fans"] = $out[1];
}
if (preg_match("/^Voltages:\s+(.+)$/m", $buffer, $out)) {
$this->_filecontent["volt"] = $out[1];
}
}
break;
default:
$this->error->addConfigError('__construct()', '[sensor_speedfan] ACCESS');
}
}
/**
* get temperature information
*
* @return void
*/
private function _temperature()
{
if (isset($this->_filecontent["temp"]) && (trim($this->_filecontent["temp"]) !== "")) {
$values = preg_split("/ /", trim($this->_filecontent["temp"]));
foreach ($values as $id=>$value) {
$dev = new SensorDevice();
$dev->setName("temp".$id);
$dev->setValue($value);
$this->mbinfo->setMbTemp($dev);
}
}
}
/**
* get fan information
*
* @return void
*/
private function _fans()
{
if (isset($this->_filecontent["fans"]) && (trim($this->_filecontent["fans"]) !== "")) {
$values = preg_split("/ /", trim($this->_filecontent["fans"]));
foreach ($values as $id=>$value) {
$dev = new SensorDevice();
$dev->setName("fan".$id);
$dev->setValue($value);
$this->mbinfo->setMbFan($dev);
}
}
}
/**
* get voltage information
*
* @return void
*/
private function _voltage()
{
if (isset($this->_filecontent["volt"]) && (trim($this->_filecontent["volt"]) !== "")) {
$values = preg_split("/ /", trim($this->_filecontent["volt"]));
foreach ($values as $id=>$value) {
$dev = new SensorDevice();
$dev->setName("in".$id);
$dev->setValue($value);
$this->mbinfo->setMbVolt($dev);
}
}
}
/**
* get the information
*
* @see PSI_Interface_Sensor::build()
*
* @return void
*/
public function build()
{
$this->_temperature();
$this->_fans();
$this->_voltage();
}
}

View File

@@ -1,31 +1,20 @@
<?php
/**
* Thermal Zone sensor class
* Thermal Zone sensor class, getting information from Thermal Zone WMI class
*
* PHP version 5
*
* @category PHP
* @package PSI_Sensor
* @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.ohm.inc.php 661 2012-08-27 11:26:39Z namiltd $
* @link http://phpsysinfo.sourceforge.net
*/
/**
* getting information from Thermal Zone WMI class
*
* @category PHP
* @package PSI_Sensor
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @author Mieczyslaw Nalewaj <namiltd@users.sourceforge.net>
* @copyright 2014 phpSysInfo
* @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
*/
class ThermalZone extends Sensors
{
/**
/**
* holds the COM object that we pull all the WMI data from
*
* @var Object
@@ -38,27 +27,39 @@ class ThermalZone extends Sensors
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');
switch (defined('PSI_SENSOR_THERMALZONE_ACCESS')?strtolower(PSI_SENSOR_THERMALZONE_ACCESS):'command') {
case 'command':
if ((PSI_OS == 'WINNT') || (defined('PSI_EMU_HOSTNAME') && !defined('PSI_EMU_PORT'))) {
if (defined('PSI_EMU_HOSTNAME') || WINNT::isAdmin()) {
$_wmi = WINNT::initWMI('root\WMI', true);
if ($_wmi) {
$this->_buf = WINNT::getWMI($_wmi, 'MSAcpi_ThermalZoneTemperature', array('InstanceName', 'CriticalTripPoint', 'CurrentTemperature'));
}
} else {
$_wmi = $objLocator->ConnectServer($strHostname, 'root\WMI', $strHostname.'\\'.$strUser, $strPassword);
$_wmi = WINNT::getcimv2wmi();
if ($_wmi) {
$this->_buf = WINNT::getWMI($_wmi, 'Win32_PerfFormattedData_Counters_ThermalZoneInformation', array('Name', 'HighPrecisionTemperature', 'Temperature'));
}
if (!$this->_buf || PSI_DEBUG) {
$this->error->addError("Error reading data from thermalzone sensor", "Allowed only for systems with administrator privileges (run as administrator)");
}
}
} 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'));
break;
case 'data':
if (!defined('PSI_EMU_HOSTNAME') && CommonFunctions::rftsdata('thermalzone.tmp', $lines)) { //output of "wmic /namespace:\\root\wmi PATH MSAcpi_ThermalZoneTemperature get CriticalTripPoint,CurrentTemperature,InstanceName"
$lines = trim(preg_replace('/[\x00-\x09\x0b-\x1F]/', '', $lines));
$lines = preg_split("/\n/", $lines, -1, PREG_SPLIT_NO_EMPTY);
if ((($clines=count($lines)) > 1) && preg_match("/CriticalTripPoint\s+CurrentTemperature\s+InstanceName/i", $lines[0])) for ($i = 1; $i < $clines; $i++) {
$values = preg_split("/\s+/", trim($lines[$i]), -1, PREG_SPLIT_NO_EMPTY);
if (count($values)==3) {
$this->_buf[] = array('CriticalTripPoint'=>trim($values[0]), 'CurrentTemperature'=>trim($values[1]), 'InstanceName'=>trim($values[2]));
}
}
}
break;
default:
$this->error->addConfigError('__construct()', '[sensor_thermalzone] ACCESS');
}
}
@@ -69,7 +70,9 @@ class ThermalZone extends Sensors
*/
private function _temperature()
{
if (PSI_OS == 'WINNT') {
$mode = defined('PSI_SENSOR_THERMALZONE_ACCESS')?strtolower(PSI_SENSOR_THERMALZONE_ACCESS):'command';
if ((($mode == 'command') && ((PSI_OS == 'WINNT') || defined('PSI_EMU_HOSTNAME')))
|| (($mode == 'data') && !defined('PSI_EMU_HOSTNAME'))) {
if ($this->_buf) foreach ($this->_buf as $buffer) {
if (isset($buffer['CurrentTemperature']) && (($value = ($buffer['CurrentTemperature'] - 2732)/10) > -100)) {
$dev = new SensorDevice();
@@ -83,34 +86,73 @@ class ThermalZone extends Sensors
$dev->setMax($maxvalue);
}
$this->mbinfo->setMbTemp($dev);
} else {
if ((isset($buffer['HighPrecisionTemperature']) && (($value = ($buffer['HighPrecisionTemperature'] - 2732)/10) > -100))
|| (isset($buffer['Temperature']) && (($value = ($buffer['Temperature'] - 273)) > -100))) {
$dev = new SensorDevice();
if (isset($buffer['Name']) && preg_match("/([^\\\\\. ]+)$/", $buffer['Name'], $outbuf)) {
$dev->setName('ThermalZone '.$outbuf[1]);
} else {
$dev->setName('ThermalZone THM0');
}
$dev->setValue($value);
$this->mbinfo->setMbTemp($dev);
}
}
}
} else {
foreach (glob('/sys/class/thermal/thermal_zone*/') as $thermalzone) {
} elseif (($mode == 'command') && (PSI_OS != 'WINNT') && !defined('PSI_EMU_HOSTNAME')) {
$notwas = true;
$thermalzones = CommonFunctions::findglob('/sys/class/thermal/thermal_zone*/');
if (is_array($thermalzones) && (count($thermalzones) > 0)) foreach ($thermalzones as $thermalzone) {
$thermalzonetemp = $thermalzone.'temp';
$temp = null;
if (CommonFunctions::rfts($thermalzonetemp, $temp, 0, 4096, false) && !is_null($temp) && (trim($temp) != "")) {
if (CommonFunctions::rfts($thermalzonetemp, $temp, 1, 4096, false) && ($temp !== null) && (($temp = trim($temp)) != "")) {
if ($temp >= 1000) {
$temp = $temp / 1000;
$div = 1000;
} elseif ($temp >= 200) {
$div = 10;
} else {
$div = 1;
}
$temp = $temp / $div;
if ($temp > -40) {
$dev = new SensorDevice();
$dev->setValue($temp);
$temp_type = null;
if (CommonFunctions::rfts($thermalzone.'type', $temp_type, 0, 4096, false) && !is_null($temp_type) && (trim($temp_type) != "")) {
if (CommonFunctions::rfts($thermalzone.'type', $temp_type, 1, 4096, false) && ($temp_type !== null) && (($temp_type = trim($temp_type)) != "")) {
$dev->setName($temp_type);
} else {
$dev->setName("ThermalZone");
}
$temp_max = null;
if (CommonFunctions::rfts($thermalzone.'trip_point_0_temp', $temp_max, 0, 4096, false) && !is_null($temp_max) && (trim($temp_max) != "") && ($temp_max > 0)) {
if ($temp_max >= 1000) {
$temp_max = $temp_max / 1000;
if (CommonFunctions::rfts($thermalzone.'trip_point_0_temp', $temp_max, 1, 4096, false) && ($temp_max !== null) && (($temp_max = trim($temp_max)) != "") && ($temp_max > -40)) {
$temp_max = $temp_max / $div;
if (($temp_max != 0) || ($temp != 0)) { // if non-zero values
$dev->setMax($temp_max);
$this->mbinfo->setMbTemp($dev);
}
$dev->setMax($temp_max);
} else {
$this->mbinfo->setMbTemp($dev);
}
$notwas = false;
}
}
}
if ($notwas) {
$thermalzones = (PSI_ROOT_FILESYSTEM.'/proc/acpi/thermal_zone/TH*/temperature');
if (is_array($thermalzones) && (count($thermalzones) > 0)) foreach ($thermalzones as $thermalzone) {
$temp = null;
if (CommonFunctions::rfts($thermalzone, $temp, 1, 4096, false) && ($temp !== null) && (($temp = trim($temp)) != "")) {
$dev = new SensorDevice();
if (preg_match("/^\/proc\/acpi\/thermal_zone\/(.+)\/temperature$/", $thermalzone, $name)) {
$dev->setName("ThermalZone ".$name[1]);
} else {
$dev->setName("ThermalZone");
}
$dev->setValue(trim(substr($temp, 23, 4)));
$this->mbinfo->setMbTemp($dev);
}
}
@@ -123,7 +165,7 @@ class ThermalZone extends Sensors
*
* @see PSI_Interface_Sensor::build()
*
* @return Void
* @return void
*/
public function build()
{

View File

@@ -0,0 +1,41 @@
<?php
/**
* thinkpad sensor class, getting hardware temperature information and fan speed from /sys/devices/platform/thinkpad_hwmon/
*
* PHP version 5
*
* @category PHP
* @package PSI_Sensor
* @author Mieczyslaw Nalewaj <namiltd@users.sourceforge.net>
* @copyright 2017 phpSysInfo
* @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
*/
class Thinkpad extends Hwmon
{
/**
* get the information
*
* @see PSI_Interface_Sensor::build()
*
* @return void
*/
public function build()
{
if ((PSI_OS == 'Linux') && !defined('PSI_EMU_HOSTNAME')) {
$hwpaths = CommonFunctions::findglob("/sys/devices/platform/thinkpad_hwmon/", GLOB_NOSORT);
if (is_array($hwpaths) && (count($hwpaths) == 1)) {
$hwpaths2 = CommonFunctions::findglob("/sys/devices/platform/thinkpad_hwmon/hwmon/hwmon*/", GLOB_NOSORT);
if (is_array($hwpaths2) && (count($hwpaths2) > 0)) {
$hwpaths = array_merge($hwpaths, $hwpaths2);
}
$totalh = count($hwpaths);
for ($h = 0; $h < $totalh; $h++) {
$this->_temperature($hwpaths[$h]);
$this->_fans($hwpaths[$h]);
}
}
}
}
}

View File

@@ -8,7 +8,7 @@
* @package PSI AIX OS class
* @author Krzysztof Paz (kpaz@gazeta.pl) based on HPUX of Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2011 Krzysztof Paz
* @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 SVN: $Id: class.AIX.inc.php 287 2009-06-26 12:11:59Z Krzysztof Paz, IBM POLSKA
* @link http://phpsysinfo.sourceforge.net
*/
@@ -20,13 +20,20 @@
* @package PSI AIX OS class
* @author Krzysztof Paz (kpaz@gazeta.pl) based on Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2011 Krzysztof Paz
* @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
*/
class AIX extends OS
{
/**
* uptime command result.
*/
private $_uptime = null;
/**
* prtconf command result.
*/
private $_aixdata = array();
/**
@@ -35,34 +42,17 @@ class AIX extends OS
*/
private function _hostname()
{
/* if (PSI_USE_VHOST === true) {
$this->sys->setHostname(getenv('SERVER_NAME'));
/* if (PSI_USE_VHOST) {
if (CommonFunctions::readenv('SERVER_NAME', $hnm)) $this->sys->setHostname($hnm);
} else {
if (CommonFunctions::executeProgram('hostname', '', $ret)) {
$this->sys->setHostname($ret);
}
} */
$this->sys->setHostname(getenv('SERVER_NAME'));
if (CommonFunctions::readenv('SERVER_NAME', $hnm)) $this->sys->setHostname($hnm);
}
/**
* IP of the Virtual Host Name
* @return void
*/
private function _ip()
{
if (PSI_USE_VHOST === true) {
$this->sys->setIp(gethostbyname($this->sys->getHostname()));
} else {
if (!($result = getenv('SERVER_ADDR'))) {
$this->sys->setIp(gethostbyname($this->sys->getHostname()));
} else {
$this->sys->setIp($result);
}
}
}
/**
* IBM AIX Version
* @return void
@@ -81,8 +71,8 @@ class AIX extends OS
*/
private function _uptime()
{
if (CommonFunctions::executeProgram('uptime', '', $buf)) {
if (preg_match("/up (\d+) days,\s*(\d+):(\d+),/", $buf, $ar_buf) || preg_match("/up (\d+) day,\s*(\d+):(\d+),/", $buf, $ar_buf)) {
if (($this->_uptime !== null) || CommonFunctions::executeProgram('uptime', '', $this->_uptime)) {
if (preg_match("/up (\d+) day[s]?,\s*(\d+):(\d+),/", $this->_uptime, $ar_buf)) {
$min = $ar_buf[3];
$hours = $ar_buf[2];
$days = $ar_buf[1];
@@ -91,17 +81,6 @@ class AIX extends OS
}
}
/**
* Number of Users
* @return void
*/
private function _users()
{
if (CommonFunctions::executeProgram('who', '| wc -l', $buf, PSI_DEBUG)) {
$this->sys->setUsers($buf);
}
}
/**
* Processor Load
* optionally create a loadbar
@@ -109,8 +88,8 @@ class AIX extends OS
*/
private function _loadavg()
{
if (CommonFunctions::executeProgram('uptime', '', $buf)) {
if (preg_match("/average: (.*), (.*), (.*)$/", $buf, $ar_buf)) {
if (($this->_uptime !== null) || CommonFunctions::executeProgram('uptime', '', $this->_uptime)) {
if (preg_match("/average: (.*), (.*), (.*)$/", $this->_uptime, $ar_buf)) {
$this->sys->setLoad($ar_buf[1].' '.$ar_buf[2].' '.$ar_buf[3]);
}
}
@@ -305,7 +284,7 @@ class AIX extends OS
$mounts = preg_split("/\n/", $df, -1, PREG_SPLIT_NO_EMPTY);
if (CommonFunctions::executeProgram('mount', '-v', $s, PSI_DEBUG)) {
$lines = preg_split("/\n/", $s, -1, PREG_SPLIT_NO_EMPTY);
while (list(, $line) = each($lines)) {
foreach ($lines as $line) {
$a = preg_split('/ /', $line, -1, PREG_SPLIT_NO_EMPTY);
$fsdev[$a[0]] = $a[4];
}
@@ -339,7 +318,7 @@ class AIX extends OS
/**
* IBM AIX informations by K.PAZ
* @return void
* @return array
*/
private function readaixdata()
{
@@ -357,25 +336,34 @@ class AIX extends OS
*
* @see PSI_Interface_OS::build()
*
* @return Void
* @return void
*/
public function build()
{
$this->error->addError("WARN", "The AIX version of phpSysInfo is a work in progress, some things currently don't work");
$this->_distro();
$this->_hostname();
$this->_ip();
$this->_kernel();
$this->_uptime();
$this->_users();
$this->_loadavg();
$this->_cpuinfo();
$this->_pci();
$this->_ide();
$this->_scsi();
$this->_usb();
$this->_network();
$this->_memory();
$this->_filesystems();
$this->error->addWarning("The AIX version of phpSysInfo is a work in progress, some things currently don't work");
if (!$this->blockname || $this->blockname==='vitals') {
$this->_distro();
$this->_hostname();
$this->_kernel();
$this->_uptime();
$this->_users();
$this->_loadavg();
}
if (!$this->blockname || $this->blockname==='hardware') {
$this->_cpuinfo();
$this->_pci();
$this->_ide();
$this->_scsi();
$this->_usb();
}
if (!$this->blockname || $this->blockname==='memory') {
$this->_memory();
}
if (!$this->blockname || $this->blockname==='filesystem') {
$this->_filesystems();
}
if (!$this->blockname || $this->blockname==='network') {
$this->_network();
}
}
}

View File

@@ -8,7 +8,7 @@
* @package PSI Android OS class
* @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 SVN: $Id: class.Linux.inc.php 712 2012-12-05 14:09:18Z namiltd $
* @link http://phpsysinfo.sourceforge.net
*/
@@ -20,18 +20,33 @@
* @package PSI Android OS class
* @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
*/
class Android extends Linux
{
/**
* call parent constructor
* holds the data from /system/build.prop file
*
* @var string
*/
public function __construct()
private $_buildprop = null;
/**
* reads the data from /system/build.prop file
*
* @return string
*/
private function _get_buildprop()
{
parent::__construct();
if ($this->_buildprop === null) {
if (!CommonFunctions::rfts('/system/build.prop', $this->_buildprop, 0, 4096, false)) {
CommonFunctions::rfts('/system//build.prop', $this->_buildprop, 0, 4096, false); //fix some access issues
}
}
return $this->_buildprop;
}
/**
@@ -39,16 +54,25 @@ class Android extends Linux
*
* @return void
*/
private function _kernel()
protected function _kernel()
{
if (CommonFunctions::rfts('/proc/version', $strBuf, 1)) {
if (preg_match('/version (.*?) /', $strBuf, $ar_buf)) {
$result = $ar_buf[1];
if (CommonFunctions::executeProgram('uname', '-r', $strBuf, false)) {
$result = $strBuf;
if (CommonFunctions::executeProgram('uname', '-v', $strBuf, PSI_DEBUG)) {
if (preg_match('/SMP/', $strBuf)) {
$result .= ' (SMP)';
}
$this->sys->setKernel($result);
}
if (CommonFunctions::executeProgram('uname', '-m', $strBuf, PSI_DEBUG)) {
$result .= ' '.$strBuf;
}
$this->sys->setKernel($result);
} elseif (CommonFunctions::rfts('/proc/version', $strBuf, 1) && preg_match('/version\s+(\S+)/', $strBuf, $ar_buf)) {
$result = $ar_buf[1];
if (preg_match('/SMP/', $strBuf)) {
$result .= ' (SMP)';
}
$this->sys->setKernel($result);
}
}
@@ -57,7 +81,7 @@ class Android extends Linux
*
* @return void
*/
private function _users()
protected function _users()
{
$this->sys->setUsers(1);
}
@@ -67,9 +91,10 @@ class Android extends Linux
*
* @return void
*/
private function _filesystems()
protected function _filesystems()
{
if (CommonFunctions::executeProgram('df', '2>/dev/null ', $df, PSI_DEBUG)) {
$notwas = true;
if (CommonFunctions::executeProgram('df', '2>/dev/null ', $df, PSI_DEBUG) && preg_match("/\s+[0-9\.]+[KMGT]\s+/", $df)) {
$df = preg_split("/\n/", $df, -1, PREG_SPLIT_NO_EMPTY);
if (CommonFunctions::executeProgram('mount', '', $mount, PSI_DEBUG)) {
$mount = preg_split("/\n/", $mount, -1, PREG_SPLIT_NO_EMPTY);
@@ -130,10 +155,17 @@ class Android extends Linux
}
}
$this->sys->setDiskDevices($dev);
$notwas = false;
}
}
}
}
if ($notwas) { // try Linux df style
$arrResult = Parser::df("-P 2>/dev/null", false);
foreach ($arrResult as $dev) {
$this->sys->setDiskDevices($dev);
}
}
}
/**
@@ -141,18 +173,17 @@ class Android extends Linux
*
* @return void
*/
private function _distro()
protected function _distro()
{
$buf = "";
if (CommonFunctions::rfts('/system/build.prop', $lines, 0, 4096, false)
&& preg_match('/^ro\.build\.version\.release=([^\n]+)/m', $lines, $ar_buf)) {
if (($lines = $this->_get_buildprop()) && preg_match('/^ro\.build\.version\.release=([^\n]+)/m', $lines, $ar_buf)) {
$buf = trim($ar_buf[1]);
}
if (is_null($buf) || ($buf == "")) {
if (($buf === null) || ($buf == "")) {
$this->sys->setDistribution('Android');
} else {
if (preg_match('/^(\d+\.\d+)/', $buf, $ver)
&& ($list = @parse_ini_file(APP_ROOT."/data/osnames.ini", true))
&& ($list = @parse_ini_file(PSI_APP_ROOT."/data/osnames.ini", true))
&& isset($list['Android'][$ver[1]])) {
$buf.=' '.$list['Android'][$ver[1]];
}
@@ -166,14 +197,14 @@ class Android extends Linux
*
* @return void
*/
private function _machine()
protected function _machine()
{
if (CommonFunctions::rfts('/system/build.prop', $lines, 0, 4096, false)) {
if ($lines = $this->_get_buildprop()) {
$buf = "";
if (preg_match('/^ro\.product\.manufacturer=([^\n]+)/m', $lines, $ar_buf)) {
if (preg_match('/^ro\.product\.manufacturer=([^\n]+)/m', $lines, $ar_buf) && (trim($ar_buf[1]) !== "unknown")) {
$buf .= ' '.trim($ar_buf[1]);
}
if (preg_match('/^ro\.product\.model=([^\n]+)/m', $lines, $ar_buf) && (trim($buf) !== trim($ar_buf[1]))) {
if (preg_match('/^ro\.product\.model=([^\n]+)/m', $lines, $ar_buf) && (trim($ar_buf[1]) !== trim($buf))) {
$buf .= ' '.trim($ar_buf[1]);
}
if (preg_match('/^ro\.semc\.product\.name=([^\n]+)/m', $lines, $ar_buf)) {
@@ -188,7 +219,7 @@ class Android extends Linux
/**
* PCI devices
*
* @return array
* @return void
*/
private function _pci()
{
@@ -205,50 +236,40 @@ class Android extends Linux
}
}
/**
* USB devices
*
* @return array
*/
private function _usb()
{
if (file_exists('/dev/bus/usb') && CommonFunctions::executeProgram('lsusb', '', $bufr, false)) {
$bufe = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
foreach ($bufe as $buf) {
$device = preg_split("/ /", $buf, 6);
if (isset($device[5]) && trim($device[5]) != "") {
$dev = new HWDevice();
$dev->setName(trim($device[5]));
$this->sys->setUsbDevices($dev);
}
}
}
}
/**
* get the information
*
* @see PSI_Interface_OS::build()
*
* @return Void
* @return void
*/
public function build()
{
$this->_distro();
$this->_hostname();
$this->_ip();
$this->_kernel();
$this->_machine();
$this->_uptime();
$this->_users();
$this->_cpuinfo();
$this->_pci();
$this->_usb();
$this->_i2c();
$this->_network();
$this->_memory();
$this->_filesystems();
$this->_loadavg();
$this->_processes();
if (!$this->blockname || $this->blockname==='vitals') {
$this->_distro();
$this->_hostname();
$this->_kernel();
$this->_uptime();
$this->_users();
$this->_loadavg();
$this->_processes();
}
if (!$this->blockname || $this->blockname==='hardware') {
$this->_machine();
$this->_cpuinfo();
$this->_virtualizer();
$this->_pci();
$this->_usb();
$this->_i2c();
}
if (!$this->blockname || $this->blockname==='memory') {
$this->_memory();
}
if (!$this->blockname || $this->blockname==='filesystem') {
$this->_filesystems();
}
if (!$this->blockname || $this->blockname==='network') {
$this->_network();
}
}
}

View File

@@ -8,7 +8,7 @@
* @package PSI BSDCommon OS class
* @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 SVN: $Id: class.BSDCommon.inc.php 621 2012-07-29 18:49:04Z namiltd $
* @link http://phpsysinfo.sourceforge.net
*/
@@ -21,68 +21,72 @@
* @package PSI BSDCommon OS class
* @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
*/
abstract class BSDCommon extends OS
{
/**
* Assoc array of all CPUs loads.
*/
private $_cpu_loads = null;
/**
* content of the syslog
*
* @var array
*/
private $_dmesg = array();
private $_dmesg = null;
/**
* regexp1 for cpu information out of the syslog
*
* @var string
*/
private $_CPURegExp1 = "";
private $_CPURegExp1 = "//";
/**
* regexp2 for cpu information out of the syslog
*
* @var string
*/
private $_CPURegExp2 = "";
private $_CPURegExp2 = "//";
/**
* regexp1 for scsi information out of the syslog
*
* @var string
*/
private $_SCSIRegExp1 = "";
private $_SCSIRegExp1 = "//";
/**
* regexp2 for scsi information out of the syslog
*
* @var string
*/
private $_SCSIRegExp2 = "";
private $_SCSIRegExp2 = "//";
/**
* regexp3 for scsi information out of the syslog
*
* @var string
*/
private $_SCSIRegExp3 = "//";
/**
* regexp1 for pci information out of the syslog
*
* @var string
*/
private $_PCIRegExp1 = "";
private $_PCIRegExp1 = "//";
/**
* regexp1 for pci information out of the syslog
*
* @var string
*/
private $_PCIRegExp2 = "";
/**
* call parent constructor
*/
public function __construct()
{
parent::__construct();
}
private $_PCIRegExp2 = "//";
/**
* setter for cpuregexp1
@@ -132,6 +136,18 @@ abstract class BSDCommon extends OS
$this->_SCSIRegExp2 = $value;
}
/**
* setter for scsiregexp3
*
* @param string $value value to set
*
* @return void
*/
protected function setSCSIRegExp3($value)
{
$this->_SCSIRegExp3 = $value;
}
/**
* setter for pciregexp1
*
@@ -163,12 +179,12 @@ abstract class BSDCommon extends OS
*/
protected function readdmesg()
{
if (count($this->_dmesg) === 0) {
if (PSI_OS != "Darwin") {
if (CommonFunctions::rfts('/var/run/dmesg.boot', $buf, 0, 4096, false) || CommonFunctions::rfts('/var/log/dmesg.boot', $buf, 0, 4096, false) || CommonFunctions::rfts('/var/run/dmesg.boot', $buf)) { // Once again but with debug
$parts = preg_split("/rebooting|Uptime/", $buf, -1, PREG_SPLIT_NO_EMPTY);
$this->_dmesg = preg_split("/\n/", $parts[count($parts) - 1], -1, PREG_SPLIT_NO_EMPTY);
}
if ($this->_dmesg === null) {
if ((PSI_OS != 'Darwin') && (CommonFunctions::rfts('/var/run/dmesg.boot', $buf, 0, 4096, false) || CommonFunctions::rfts('/var/log/dmesg.boot', $buf, 0, 4096, false) || CommonFunctions::rfts('/var/run/dmesg.boot', $buf))) { // Once again but with debug
$parts = preg_split("/rebooting|Uptime/", $buf, -1, PREG_SPLIT_NO_EMPTY);
$this->_dmesg = preg_split("/\n/", $parts[count($parts) - 1], -1, PREG_SPLIT_NO_EMPTY);
} else {
$this->_dmesg = array();
}
}
@@ -199,8 +215,8 @@ abstract class BSDCommon extends OS
*/
protected function hostname()
{
if (PSI_USE_VHOST === true) {
$this->sys->setHostname(getenv('SERVER_NAME'));
if (PSI_USE_VHOST) {
if (CommonFunctions::readenv('SERVER_NAME', $hnm)) $this->sys->setHostname($hnm);
} else {
if (CommonFunctions::executeProgram('hostname', '', $buf, PSI_DEBUG)) {
$this->sys->setHostname($buf);
@@ -208,24 +224,6 @@ abstract class BSDCommon extends OS
}
}
/**
* IP of the Canonical Host Name
*
* @return void
*/
protected function ip()
{
if (PSI_USE_VHOST === true) {
$this->sys->setIp(gethostbyname($this->sys->getHostname()));
} else {
if (!($result = getenv('SERVER_ADDR'))) {
$this->sys->setIp(gethostbyname($this->sys->getHostname()));
} else {
$this->sys->setIp($result);
}
}
}
/**
* Kernel Version
*
@@ -234,19 +232,98 @@ abstract class BSDCommon extends OS
protected function kernel()
{
$s = $this->grabkey('kern.version');
$a = preg_split('/:/', $s);
$this->sys->setKernel($a[0].$a[1].':'.$a[2]);
$a = preg_split('/:/', $s, 4);
if (isset($a[3])) {
if (preg_match('/^(\d{2} [A-Z]{3});/', $a[3], $abuf) // eg. 19:58 GMT;...
|| preg_match('/^(\d{2} [A-Z]{3} \d{4})/', $a[3], $abuf)) { // eg. 26:31 PDT 2019...
$this->sys->setKernel($a[0].$a[1].':'.$a[2].':'.$abuf[1]);
} else {
$this->sys->setKernel($a[0].$a[1].':'.$a[2]);
}
} elseif (isset($a[2])) {
$this->sys->setKernel($a[0].$a[1].':'.$a[2]);
} else {
$this->sys->setKernel($s);
}
}
/**
* Number of Users
* Virtualizer info
*
* @return void
*/
protected function users()
private function virtualizer()
{
if (CommonFunctions::executeProgram('who', '| wc -l', $buf, PSI_DEBUG)) {
$this->sys->setUsers($buf);
if (defined('PSI_SHOW_VIRTUALIZER_INFO') && PSI_SHOW_VIRTUALIZER_INFO) {
$testvirt = $this->sys->getVirtualizer();
$novm = true;
foreach ($testvirt as $virtkey=>$virtvalue) if ($virtvalue) {
$novm = false;
break;
}
// Detect QEMU cpu
if ($novm && isset($testvirt["cpuid:QEMU"])) {
$this->sys->setVirtualizer('qemu'); // QEMU
$novm = false;
}
if ($novm && isset($testvirt["hypervisor"])) {
$this->sys->setVirtualizer('unknown');
}
}
}
/**
* CPU usage
*
* @return void
*/
protected function cpuusage()
{
if (($this->_cpu_loads === null)) {
$this->_cpu_loads = array();
if (PSI_OS != 'Darwin') {
if ($fd = $this->grabkey('kern.cp_time')) {
// Find out the CPU load
// user + sys = load
// total = total
if (preg_match($this->_CPURegExp2, $fd, $res) && (sizeof($res) > 4)) {
$load = $res[2] + $res[3] + $res[4]; // cpu.user + cpu.sys
$total = $res[2] + $res[3] + $res[4] + $res[5]; // cpu.total
// we need a second value, wait 1 second befor getting (< 1 second no good value will occour)
sleep(1);
$fd = $this->grabkey('kern.cp_time');
if (preg_match($this->_CPURegExp2, $fd, $res) && (sizeof($res) > 4)) {
$load2 = $res[2] + $res[3] + $res[4];
$total2 = $res[2] + $res[3] + $res[4] + $res[5];
if ($total2 != $total) {
$this->_cpu_loads['cpu'] = (100 * ($load2 - $load)) / ($total2 - $total);
} else {
$this->_cpu_loads['cpu'] = 0;
}
}
}
}
} else {
$ncpu = $this->grabkey('hw.ncpu');
if (($ncpu !== "") && ($ncpu >= 1) && CommonFunctions::executeProgram('ps', "-A -o %cpu", $pstable, false) && !empty($pstable)) {
$pslines = preg_split("/\n/", $pstable, -1, PREG_SPLIT_NO_EMPTY);
if (!empty($pslines) && (count($pslines)>1) && (trim($pslines[0])==="%CPU")) {
array_shift($pslines);
$sum = 0;
foreach ($pslines as $psline) {
$sum+=str_replace(',', '.', trim($psline));
}
$this->_cpu_loads['cpu'] = min($sum/$ncpu, 100);
}
}
}
}
if (isset($this->_cpu_loads['cpu'])) {
return $this->_cpu_loads['cpu'];
} else {
return null;
}
}
@@ -261,23 +338,11 @@ abstract class BSDCommon extends OS
$s = $this->grabkey('vm.loadavg');
$s = preg_replace('/{ /', '', $s);
$s = preg_replace('/ }/', '', $s);
$s = str_replace(',', '.', $s);
$this->sys->setLoad($s);
if (PSI_LOAD_BAR && (PSI_OS != "Darwin")) {
if ($fd = $this->grabkey('kern.cp_time')) {
// Find out the CPU load
// user + sys = load
// total = total
preg_match($this->_CPURegExp2, $fd, $res);
$load = $res[2] + $res[3] + $res[4]; // cpu.user + cpu.sys
$total = $res[2] + $res[3] + $res[4] + $res[5]; // cpu.total
// we need a second value, wait 1 second befor getting (< 1 second no good value will occour)
sleep(1);
$fd = $this->grabkey('kern.cp_time');
preg_match($this->_CPURegExp2, $fd, $res);
$load2 = $res[2] + $res[3] + $res[4];
$total2 = $res[2] + $res[3] + $res[4] + $res[5];
$this->sys->setLoadPercent((100 * ($load2 - $load)) / ($total2 - $total));
}
if (PSI_LOAD_BAR) {
$this->sys->setLoadPercent($this->cpuusage());
}
}
@@ -289,37 +354,153 @@ abstract class BSDCommon extends OS
protected function cpuinfo()
{
$dev = new CpuDevice();
$dev->setModel($this->grabkey('hw.model'));
$cpumodel = $this->grabkey('hw.model');
$dev->setModel($cpumodel);
if (defined('PSI_SHOW_VIRTUALIZER_INFO') && PSI_SHOW_VIRTUALIZER_INFO && preg_match('/^QEMU Virtual CPU version /', $cpumodel)) {
$this->sys->setVirtualizer("cpuid:QEMU", false);
}
$notwas = true;
foreach ($this->readdmesg() as $line) {
if ($notwas) {
if (preg_match("/".$this->_CPURegExp1."/", $line, $ar_buf)) {
$dev->setCpuSpeed(round($ar_buf[2]));
$notwas = false;
$regexps = preg_split("/\n/", $this->_CPURegExp1, -1, PREG_SPLIT_NO_EMPTY); // multiple regexp separated by \n
foreach ($regexps as $regexp) {
if (preg_match($regexp, $line, $ar_buf) && (sizeof($ar_buf) > 2)) {
if ($dev->getCpuSpeed() == 0) {
$dev->setCpuSpeed(round($ar_buf[2]));
}
$notwas = false;
break;
}
}
} else {
if (preg_match("/ Origin| Features/", $line, $ar_buf)) {
if (preg_match("/ Features2[ ]*=.*<(.*)>/", $line, $ar_buf)) {
if (preg_match("/^\s+Origin| Features/", $line, $ar_buf)) {
if (preg_match("/^\s+Origin[ ]*=[ ]*\"(.+)\"/", $line, $ar_buf)) {
$dev->setVendorId($ar_buf[1]);
} elseif (preg_match("/ Features2[ ]*=.*<(.+)>/", $line, $ar_buf)) {
$feats = preg_split("/,/", strtolower(trim($ar_buf[1])), -1, PREG_SPLIT_NO_EMPTY);
foreach ($feats as $feat) {
if (($feat=="vmx") || ($feat=="svm")) {
$dev->setVirt($feat);
break 2;
} elseif ($feat=="hv") {
if ($dev->getVirt() === null) {
$dev->setVirt('hypervisor');
}
if (defined('PSI_SHOW_VIRTUALIZER_INFO') && PSI_SHOW_VIRTUALIZER_INFO) {
$this->sys->setVirtualizer("hypervisor", false);
}
}
}
break;
}
} else break;
}
}
$ncpu = $this->grabkey('hw.ncpu');
if (is_null($ncpu) || (trim($ncpu) == "") || (!($ncpu >= 1)))
if (($ncpu === "") || !($ncpu >= 1)) {
$ncpu = 1;
}
if (($ncpu == 1) && PSI_LOAD_BAR) {
$dev->setLoad($this->cpuusage());
}
for ($ncpu ; $ncpu > 0 ; $ncpu--) {
$this->sys->setCpus($dev);
}
}
/**
* Machine information
*
* @return void
*/
private function machine()
{
if ((PSI_OS == 'NetBSD') || (PSI_OS == 'OpenBSD')) {
$buffer = array();
if (PSI_OS == 'NetBSD') { // NetBSD
$buffer['Manufacturer'] = $this->grabkey('machdep.dmi.system-vendor');
$buffer['Model'] = $this->grabkey('machdep.dmi.system-product');
$buffer['Product'] = $this->grabkey('machdep.dmi.board-product');
$buffer['SMBIOSBIOSVersion'] = $this->grabkey('machdep.dmi.bios-version');
$buffer['ReleaseDate'] = $this->grabkey('machdep.dmi.bios-date');
} else { // OpenBSD
$buffer['Manufacturer'] = $this->grabkey('hw.vendor');
$buffer['Model'] = $this->grabkey('hw.product');
$buffer['Product'] = "";
$buffer['SMBIOSBIOSVersion'] = "";
$buffer['ReleaseDate'] = "";
}
if (defined('PSI_SHOW_VIRTUALIZER_INFO') && PSI_SHOW_VIRTUALIZER_INFO) {
$vendor_array = array();
$vendor_array[] = $buffer['Model'];
$vendor_array[] = trim($buffer['Manufacturer']." ".$buffer['Model']);
if (PSI_OS == 'NetBSD') { // NetBSD
$vendor_array[] = $this->grabkey('machdep.dmi.board-vendor');
$vendor_array[] = $this->grabkey('machdep.dmi.bios-vendor');
}
$virt = CommonFunctions::decodevirtualizer($vendor_array);
if ($virt !== null) {
$this->sys->setVirtualizer($virt);
}
}
$buf = "";
if (($buffer['Manufacturer'] !== "") && !preg_match("/^To be filled by O\.E\.M\.$|^System manufacturer$|^Not Specified$/i", $buf2=trim($buffer['Manufacturer'])) && ($buf2 !== "")) {
$buf .= ' '.$buf2;
}
if (($buffer['Model'] !== "") && !preg_match("/^To be filled by O\.E\.M\.$|^System Product Name$|^Not Specified$/i", $buf2=trim($buffer['Model'])) && ($buf2 !== "")) {
$model = $buf2;
$buf .= ' '.$buf2;
}
if (($buffer['Product'] !== "") && !preg_match("/^To be filled by O\.E\.M\.$|^BaseBoard Product Name$|^Not Specified$|^Default string$/i", $buf2=trim($buffer['Product'])) && ($buf2 !== "")) {
if ($buf2 !== $model) {
$buf .= '/'.$buf2;
} elseif (isset($buffer['SystemFamily']) && !preg_match("/^To be filled by O\.E\.M\.$|^System Family$|^Not Specified$/i", $buf2=trim($buffer['SystemFamily'])) && ($buf2 !== "")) {
$buf .= '/'.$buf2;
}
}
$bver = "";
$brel = "";
if (($buf2=trim($buffer['SMBIOSBIOSVersion'])) !== "") {
$bver .= ' '.$buf2;
}
if ($buffer['ReleaseDate'] !== "") {
if (preg_match("/^(\d{4})(\d{2})(\d{2})$/", $buffer['ReleaseDate'], $dateout)) {
$brel .= ' '.$dateout[2].'/'.$dateout[3].'/'.$dateout[1];
} elseif (preg_match("/^\d{2}\/\d{2}\/\d{4}$/", $buffer['ReleaseDate'])) {
$brel .= ' '.$buffer['ReleaseDate'];
}
}
if ((trim($bver) !== "") || (trim($brel) !== "")) {
$buf .= ', BIOS'.$bver.$brel;
}
if (trim($buf) !== "") {
$this->sys->setMachine(trim($buf));
}
} elseif ((PSI_OS == 'FreeBSD') && defined('PSI_SHOW_VIRTUALIZER_INFO') && PSI_SHOW_VIRTUALIZER_INFO) {
$vendorid = $this->grabkey('hw.hv_vendor');
if (trim($vendorid) === "") {
foreach ($this->readdmesg() as $line) if (preg_match("/^Hypervisor: Origin = \"(.+)\"/", $line, $ar_buf)) {
if (trim($ar_buf[1]) !== "") {
$vendorid = $ar_buf[1];
}
break;
}
}
if (trim($vendorid) !== "") {
$virt = CommonFunctions::decodevirtualizer($vendorid);
if ($virt !== null) {
$this->sys->setVirtualizer($virt);
} else {
$this->sys->setVirtualizer('unknown');
}
}
}
}
/**
* SCSI devices
* get the scsi device information out of dmesg
@@ -329,16 +510,22 @@ abstract class BSDCommon extends OS
protected function scsi()
{
foreach ($this->readdmesg() as $line) {
if (preg_match("/".$this->_SCSIRegExp1."/", $line, $ar_buf)) {
if (preg_match($this->_SCSIRegExp1, $line, $ar_buf) && (sizeof($ar_buf) > 2)) {
$dev = new HWDevice();
$dev->setName($ar_buf[1].": ".$ar_buf[2]);
$dev->setName($ar_buf[1].": ".trim($ar_buf[2]));
$this->sys->setScsiDevices($dev);
} elseif (preg_match("/".$this->_SCSIRegExp2."/", $line, $ar_buf)) {
} elseif (preg_match($this->_SCSIRegExp2, $line, $ar_buf) && (sizeof($ar_buf) > 1)) {
/* duplication security */
$notwas = true;
foreach ($this->sys->getScsiDevices() as $finddev) {
if ($notwas && (substr($finddev->getName(), 0, strpos($finddev->getName(), ': ')) == $ar_buf[1])) {
$finddev->setCapacity($ar_buf[2] * 2048 * 1.049);
if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS) {
if (isset($ar_buf[3]) && ($ar_buf[3]==="G")) {
$finddev->setCapacity($ar_buf[2] * 1024 * 1024 * 1024);
} elseif (isset($ar_buf[2])) {
$finddev->setCapacity($ar_buf[2] * 1024 * 1024);
}
}
$notwas = false;
break;
}
@@ -346,15 +533,43 @@ abstract class BSDCommon extends OS
if ($notwas) {
$dev = new HWDevice();
$dev->setName($ar_buf[1]);
$dev->setCapacity($ar_buf[2] * 2048 * 1.049);
if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS) {
if (isset($ar_buf[3]) && ($ar_buf[3]==="G")) {
$dev->setCapacity($ar_buf[2] * 1024 * 1024 * 1024);
} elseif (isset($ar_buf[2])) {
$dev->setCapacity($ar_buf[2] * 1024 * 1024);
}
}
$this->sys->setScsiDevices($dev);
}
} elseif (preg_match($this->_SCSIRegExp3, $line, $ar_buf) && (sizeof($ar_buf) > 1)) {
/* duplication security */
$notwas = true;
foreach ($this->sys->getScsiDevices() as $finddev) {
if ($notwas && (substr($finddev->getName(), 0, strpos($finddev->getName(), ': ')) == $ar_buf[1])) {
if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS
&& defined('PSI_SHOW_DEVICES_SERIAL') && PSI_SHOW_DEVICES_SERIAL) {
if (isset($ar_buf[2])) $finddev->setSerial(trim($ar_buf[2]));
}
$notwas = false;
break;
}
}
if ($notwas) {
$dev = new HWDevice();
$dev->setName($ar_buf[1]);
if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS
&& defined('PSI_SHOW_DEVICES_SERIAL') && PSI_SHOW_DEVICES_SERIAL) {
if (isset($ar_buf[2])) $dev->setSerial(trim($ar_buf[2]));
}
$this->sys->setScsiDevices($dev);
}
}
}
/* cleaning */
foreach ($this->sys->getScsiDevices() as $finddev) {
if (strpos($finddev->getName(), ': ') !== false)
$finddev->setName(substr(strstr($finddev->getName(), ': '), 2));
if (strpos($finddev->getName(), ': ') !== false)
$finddev->setName(substr(strstr($finddev->getName(), ': '), 2));
}
}
@@ -412,13 +627,13 @@ abstract class BSDCommon extends OS
*/
protected function pci()
{
if (!is_array($results = Parser::lspci(false)) || !is_array($results = $this->pciconf())) {
if ((!$results = Parser::lspci(false)) && (!$results = $this->pciconf())) {
foreach ($this->readdmesg() as $line) {
if (preg_match("/".$this->_PCIRegExp1."/", $line, $ar_buf)) {
if (preg_match($this->_PCIRegExp1, $line, $ar_buf) && (sizeof($ar_buf) > 2)) {
$dev = new HWDevice();
$dev->setName($ar_buf[1].": ".$ar_buf[2]);
$results[] = $dev;
} elseif (preg_match("/".$this->_PCIRegExp2."/", $line, $ar_buf)) {
} elseif (preg_match($this->_PCIRegExp2, $line, $ar_buf) && (sizeof($ar_buf) > 2)) {
$dev = new HWDevice();
$dev->setName($ar_buf[1].": ".$ar_buf[2]);
$results[] = $dev;
@@ -441,23 +656,27 @@ abstract class BSDCommon extends OS
foreach ($this->readdmesg() as $line) {
if (preg_match('/^(ad[0-9]+): (.*)MB <(.*)> (.*) (.*)/', $line, $ar_buf)) {
$dev = new HWDevice();
$dev->setName($ar_buf[1].": ".$ar_buf[3]);
$dev->setCapacity($ar_buf[2] * 1024);
$dev->setName($ar_buf[1].": ".trim($ar_buf[3]));
if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS) {
$dev->setCapacity($ar_buf[2] * 1024 * 1024);
}
$this->sys->setIdeDevices($dev);
} elseif (preg_match('/^(acd[0-9]+): (.*) <(.*)> (.*)/', $line, $ar_buf)) {
$dev = new HWDevice();
$dev->setName($ar_buf[1].": ".$ar_buf[3]);
$dev->setName($ar_buf[1].": ".trim($ar_buf[3]));
$this->sys->setIdeDevices($dev);
} elseif (preg_match('/^(ada[0-9]+): <(.*)> (.*)/', $line, $ar_buf)) {
$dev = new HWDevice();
$dev->setName($ar_buf[1].": ".$ar_buf[2]);
$dev->setName($ar_buf[1].": ".trim($ar_buf[2]));
$this->sys->setIdeDevices($dev);
} elseif (preg_match('/^(ada[0-9]+): (.*)MB \((.*)\)/', $line, $ar_buf)) {
/* duplication security */
$notwas = true;
foreach ($this->sys->getIdeDevices() as $finddev) {
if ($notwas && (substr($finddev->getName(), 0, strpos($finddev->getName(), ': ')) == $ar_buf[1])) {
$finddev->setCapacity($ar_buf[2] * 1024);
if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS) {
$finddev->setCapacity($ar_buf[2] * 1024 * 1024);
}
$notwas = false;
break;
}
@@ -465,7 +684,31 @@ abstract class BSDCommon extends OS
if ($notwas) {
$dev = new HWDevice();
$dev->setName($ar_buf[1]);
$dev->setCapacity($ar_buf[2] * 1024);
if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS) {
$dev->setCapacity($ar_buf[2] * 1024 * 1024);
}
$this->sys->setIdeDevices($dev);
}
} elseif (preg_match('/^(ada[0-9]+): Serial Number (.*)/', $line, $ar_buf)) {
/* duplication security */
$notwas = true;
foreach ($this->sys->getIdeDevices() as $finddev) {
if ($notwas && (substr($finddev->getName(), 0, strpos($finddev->getName(), ': ')) == $ar_buf[1])) {
if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS
&& defined('PSI_SHOW_DEVICES_SERIAL') && PSI_SHOW_DEVICES_SERIAL) {
$finddev->setSerial(trim($ar_buf[2]));
}
$notwas = false;
break;
}
}
if ($notwas) {
$dev = new HWDevice();
$dev->setName($ar_buf[1]);
if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS
&& defined('PSI_SHOW_DEVICES_SERIAL') && PSI_SHOW_DEVICES_SERIAL) {
$finddev->setSerial(trim($ar_buf[2]));
}
$this->sys->setIdeDevices($dev);
}
}
@@ -530,7 +773,19 @@ abstract class BSDCommon extends OS
*/
protected function usb()
{
foreach ($this->readdmesg() as $line) {
$notwas = true;
if ((PSI_OS == 'FreeBSD') && CommonFunctions::executeProgram('usbconfig', '', $bufr, false)) {
$lines = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
foreach ($lines as $line) {
if (preg_match('/^(ugen[0-9]+\.[0-9]+): <([^,]*)(.*)> at (usbus[0-9]+)/', $line, $ar_buf)) {
$notwas = false;
$dev = new HWDevice();
$dev->setName($ar_buf[2]);
$this->sys->setUSBDevices($dev);
}
}
}
if ($notwas) foreach ($this->readdmesg() as $line) {
// if (preg_match('/^(ugen[0-9\.]+): <(.*)> (.*) (.*)/', $line, $ar_buf)) {
// $dev->setName($ar_buf[1].": ".$ar_buf[2]);
if (preg_match('/^(u[a-z]+[0-9]+): <([^,]*)(.*)> on (usbus[0-9]+)/', $line, $ar_buf)) {
@@ -566,27 +821,60 @@ abstract class BSDCommon extends OS
}
}
/**
* UpTime
* time the system is running
*
* @return void
*/
private function uptime()
{
if ($kb = $this->grabkey('kern.boottime')) {
if (preg_match("/sec = ([0-9]+)/", $kb, $buf)) { // format like: { sec = 1096732600, usec = 885425 } Sat Oct 2 10:56:40 2004
$this->sys->setUptime(time() - $buf[1]);
} else {
date_default_timezone_set('UTC');
$kbt = strtotime($kb);
if (($kbt !== false) && ($kbt != -1)) {
$this->sys->setUptime(time() - $kbt); // format like: Sat Oct 2 10:56:40 2004
} else {
$this->sys->setUptime(time() - $kb); // format like: 1096732600
}
}
}
}
/**
* get the information
*
* @see PSI_Interface_OS::build()
*
* @return Void
* @return void
*/
public function build()
{
$this->distro();
$this->memory();
$this->ide();
$this->pci();
$this->cpuinfo();
$this->filesystems();
$this->kernel();
$this->users();
$this->loadavg();
$this->hostname();
$this->ip();
$this->scsi();
$this->usb();
if (!$this->blockname || $this->blockname==='vitals') {
$this->distro();
$this->hostname();
$this->kernel();
$this->_users();
$this->loadavg();
$this->uptime();
}
if (!$this->blockname || $this->blockname==='hardware') {
$this->machine();
$this->cpuinfo();
$this->virtualizer();
$this->pci();
$this->ide();
$this->scsi();
$this->usb();
}
if (!$this->blockname || $this->blockname==='memory') {
$this->memory();
}
if (!$this->blockname || $this->blockname==='filesystem') {
$this->filesystems();
}
}
}

View File

@@ -8,7 +8,7 @@
* @package PSI Darwin OS class
* @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 SVN: $Id: class.Darwin.inc.php 638 2012-08-24 09:40:48Z namiltd $
* @link http://phpsysinfo.sourceforge.net
*/
@@ -21,7 +21,7 @@
* @package PSI Darwin OS class
* @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
*/
@@ -30,13 +30,13 @@ class Darwin extends BSDCommon
/**
* define the regexp for log parser
*/
/* public function __construct()
/* public function __construct($blockname = false)
{
parent::__construct();
parent::__construct($blockname);
$this->error->addWarning("The Darwin version of phpSysInfo is a work in progress, some things currently don't work!");
$this->setCPURegExp1("CPU: (.*) \((.*)-MHz (.*)\)");
$this->setCPURegExp1("/CPU: (.*) \((.*)-MHz (.*)\)/");
$this->setCPURegExp2("/(.*) ([0-9]+) ([0-9]+) ([0-9]+) ([0-9]+)/");
$this->setSCSIRegExp1("^(.*): <(.*)> .*SCSI.*device");
$this->setSCSIRegExp1("/^(.*): <(.*)> .*SCSI.*device/");
} */
/**
@@ -89,25 +89,6 @@ class Darwin extends BSDCommon
}
}
/**
* UpTime
* time the system is running
*
* @return void
*/
private function _uptime()
{
if (CommonFunctions::executeProgram('sysctl', '-n kern.boottime', $a, PSI_DEBUG)) {
$tmp = explode(" ", $a);
if ($tmp[0]=="{") { /* kern.boottime= { sec = 1096732600, usec = 885425 } Sat Oct 2 10:56:40 2004 */
$data = trim($tmp[3], ",");
$this->sys->setUptime(time() - $data);
} else { /* kern.boottime= 1096732600 */
$this->sys->setUptime(time() - $a);
}
}
}
/**
* get CPU information
*
@@ -116,12 +97,12 @@ class Darwin extends BSDCommon
protected function cpuinfo()
{
$dev = new CpuDevice();
if (CommonFunctions::executeProgram('hostinfo', '| grep "Processor type"', $buf, PSI_DEBUG)) {
$dev->setModel(preg_replace('/Processor type: /', '', $buf));
if (CommonFunctions::executeProgram('hostinfo', '', $buf, PSI_DEBUG) && ($buf !== '') && preg_match('/^Processor type:[ ]+(.+)$/m', $buf, $proc) && (($proc[1] = trim($proc[1])) !== '')) {
$dev->setModel($proc[1]);
$buf=$this->grabkey('hw.model');
if (!is_null($buf) && (trim($buf) != "")) {
if (($buf !== null) && (trim($buf) != "")) {
$this->sys->setMachine(trim($buf));
if (CommonFunctions::rfts(APP_ROOT.'/data/ModelTranslation.txt', $buffer)) {
if (CommonFunctions::rftsdata('ModelTranslation.txt', $buffer)) {
$buffer = preg_split("/\n/", $buffer, -1, PREG_SPLIT_NO_EMPTY);
foreach ($buffer as $line) {
$ar_buf = preg_split("/:/", $line, 3);
@@ -134,12 +115,12 @@ class Darwin extends BSDCommon
}
}
$buf=$this->grabkey('machdep.cpu.brand_string');
if (!is_null($buf) && (trim($buf) != "") &&
if (($buf !== null) && (trim($buf) != "") &&
((trim($buf) != "i486 (Intel 80486)") || ($dev->getModel() == ""))) {
$dev->setModel(trim($buf));
}
$buf=$this->grabkey('machdep.cpu.features');
if (!is_null($buf) && (trim($buf) != "")) {
if (($buf !== null) && (trim($buf) != "")) {
if (preg_match("/ VMX/", $buf)) {
$dev->setVirt("vmx");
} elseif (preg_match("/ SVM/", $buf)) {
@@ -151,17 +132,21 @@ class Darwin extends BSDCommon
$dev->setBusSpeed(round($this->grabkey('hw.busfrequency') / 1000000));
$bufn=$this->grabkey('hw.cpufrequency_min');
$bufx=$this->grabkey('hw.cpufrequency_max');
if (!is_null($bufn) && (trim($bufn) != "") && !is_null($bufx) && (trim($bufx) != "") && ($bufn != $bufx)) {
if (($bufn !== null) && (trim($bufn) != "") && ($bufx !== null) && (trim($bufx) != "") && ($bufn != $bufx)) {
$dev->setCpuSpeedMin(round($bufn / 1000000));
$dev->setCpuSpeedMax(round($bufx / 1000000));
}
$buf=$this->grabkey('hw.l2cachesize');
if (!is_null($buf) && (trim($buf) != "")) {
if ($buf !== "") {
$dev->setCache(round($buf));
}
$ncpu = $this->grabkey('hw.ncpu');
if (is_null($ncpu) || (trim($ncpu) == "") || (!($ncpu >= 1)))
if (($ncpu === "") || !($ncpu >= 1)) {
$ncpu = 1;
}
if (($ncpu == 1) && PSI_LOAD_BAR) {
$dev->setLoad($this->cpuusage());
}
for ($ncpu ; $ncpu > 0 ; $ncpu--) {
$this->sys->setCpus($dev);
}
@@ -238,6 +223,18 @@ class Darwin extends BSDCommon
if (!preg_match('/"USB Product Name" = "([^"]*)"/', $line, $ar_buf))
$ar_buf = preg_split("/[\s@]+/", $line, 19);
$dev->setName(trim($ar_buf[1]));
if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS) {
if (preg_match('/"USB Vendor Name" = "([^"]*)"/', $line, $ar_buf)) {
$dev->setManufacturer(trim($ar_buf[1]));
}
if (preg_match('/"USB Product Name" = "([^"]*)"/', $line, $ar_buf)) {
$dev->setProduct(trim($ar_buf[1]));
}
if (defined('PSI_SHOW_DEVICES_SERIAL') && PSI_SHOW_DEVICES_SERIAL
&& preg_match('/"USB Serial Number" = "([^"]*)"/', $line, $ar_buf)) {
$dev->setSerial(trim($ar_buf[1]));
}
}
$this->sys->setUsbDevices($dev);
}
}
@@ -267,60 +264,63 @@ class Darwin extends BSDCommon
*/
protected function memory()
{
$s = $this->grabkey('hw.memsize');
if (CommonFunctions::executeProgram('vm_stat', '', $pstat, PSI_DEBUG)) {
// calculate free memory from page sizes (each page = 4096)
if (preg_match('/^Pages free:\s+(\S+)/m', $pstat, $free_buf)) {
if (preg_match('/^Anonymous pages:\s+(\S+)/m', $pstat, $anon_buf)
&& preg_match('/^Pages wired down:\s+(\S+)/m', $pstat, $wire_buf)
&& preg_match('/^File-backed pages:\s+(\S+)/m', $pstat, $fileb_buf)) {
// OS X 10.9 or never
$this->sys->setMemFree($free_buf[1] * 4 * 1024);
$this->sys->setMemApplication(($anon_buf[1]+$wire_buf[1]) * 4 * 1024);
$this->sys->setMemCache($fileb_buf[1] * 4 * 1024);
if (preg_match('/^Pages occupied by compressor:\s+(\S+)/m', $pstat, $compr_buf)) {
$this->sys->setMemBuffer($compr_buf[1] * 4 * 1024);
}
} else {
if (preg_match('/^Pages speculative:\s+(\S+)/m', $pstat, $spec_buf)) {
$this->sys->setMemFree(($free_buf[1]+$spec_buf[1]) * 4 * 1024);
if (($s = $this->grabkey('hw.memsize')) > 0) {
$this->sys->setMemTotal($s);
if (CommonFunctions::executeProgram('vm_stat', '', $pstat, PSI_DEBUG)) {
// calculate free memory from page sizes (each page = 4096)
if (preg_match('/^Pages free:\s+(\S+)/m', $pstat, $free_buf)) {
if (preg_match('/^Anonymous pages:\s+(\S+)/m', $pstat, $anon_buf)
&& preg_match('/^Pages wired down:\s+(\S+)/m', $pstat, $wire_buf)
&& preg_match('/^File-backed pages:\s+(\S+)/m', $pstat, $fileb_buf)) {
// OS X 10.9 or never
$this->sys->setMemFree($free_buf[1] * 4 * 1024);
$this->sys->setMemApplication(($anon_buf[1]+$wire_buf[1]) * 4 * 1024);
$this->sys->setMemCache($fileb_buf[1] * 4 * 1024);
if (preg_match('/^Pages occupied by compressor:\s+(\S+)/m', $pstat, $compr_buf)) {
$this->sys->setMemBuffer($compr_buf[1] * 4 * 1024);
}
} else {
$this->sys->setMemFree($free_buf[1] * 4 * 1024);
}
$appMemory = 0;
if (preg_match('/^Pages wired down:\s+(\S+)/m', $pstat, $wire_buf)) {
$appMemory += $wire_buf[1] * 4 * 1024;
}
if (preg_match('/^Pages active:\s+(\S+)/m', $pstat, $active_buf)) {
$appMemory += $active_buf[1] * 4 * 1024;
}
$this->sys->setMemApplication($appMemory);
if (preg_match('/^Pages speculative:\s+(\S+)/m', $pstat, $spec_buf)) {
$this->sys->setMemFree(($free_buf[1]+$spec_buf[1]) * 4 * 1024);
} else {
$this->sys->setMemFree($free_buf[1] * 4 * 1024);
}
$appMemory = 0;
if (preg_match('/^Pages wired down:\s+(\S+)/m', $pstat, $wire_buf)) {
$appMemory += $wire_buf[1] * 4 * 1024;
}
if (preg_match('/^Pages active:\s+(\S+)/m', $pstat, $active_buf)) {
$appMemory += $active_buf[1] * 4 * 1024;
}
$this->sys->setMemApplication($appMemory);
if (preg_match('/^Pages inactive:\s+(\S+)/m', $pstat, $inactive_buf)) {
$this->sys->setMemCache($inactive_buf[1] * 4 * 1024);
if (preg_match('/^Pages inactive:\s+(\S+)/m', $pstat, $inactive_buf)) {
$this->sys->setMemCache($inactive_buf[1] * 4 * 1024);
}
}
} else {
$lines = preg_split("/\n/", $pstat, -1, PREG_SPLIT_NO_EMPTY);
$ar_buf = preg_split("/\s+/", $lines[1], 19);
$this->sys->setMemFree($ar_buf[2] * 4 * 1024);
}
} else {
$lines = preg_split("/\n/", $pstat, -1, PREG_SPLIT_NO_EMPTY);
$ar_buf = preg_split("/\s+/", $lines[1], 19);
$this->sys->setMemFree($ar_buf[2] * 4 * 1024);
$this->sys->setMemUsed($this->sys->getMemTotal() - $this->sys->getMemFree());
}
$this->sys->setMemTotal($s);
$this->sys->setMemUsed($this->sys->getMemTotal() - $this->sys->getMemFree());
if (CommonFunctions::executeProgram('sysctl', 'vm.swapusage | colrm 1 22', $swapBuff, PSI_DEBUG)) {
$swap1 = preg_split('/M/', $swapBuff);
$swap2 = preg_split('/=/', $swap1[1]);
$swap3 = preg_split('/=/', $swap1[2]);
$dev = new DiskDevice();
$dev->setName('SWAP');
$dev->setMountPoint('SWAP');
$dev->setFsType('swap');
$dev->setTotal($swap1[0] * 1024 * 1024);
$dev->setUsed($swap2[1] * 1024 * 1024);
$dev->setFree($swap3[1] * 1024 * 1024);
$this->sys->setSwapDevices($dev);
if (($swap = $this->grabkey("vm.swapusage")) > 0) {
$swap0 = preg_split('/M/', $swap);
$swap1 = preg_split('/=/', $swap0[0]);
$swap2 = preg_split('/=/', $swap0[1]);
$swap3 = preg_split('/=/', $swap0[2]);
if (($swap=str_replace(',', '.', trim($swap1[1]))) > 0) {
$dev = new DiskDevice();
$dev->setName('SWAP');
$dev->setMountPoint('SWAP');
$dev->setFsType('swap');
$dev->setTotal($swap * 1024 * 1024);
$dev->setUsed(str_replace(',', '.', trim($swap2[1])) * 1024 * 1024);
$dev->setFree(str_replace(',', '.', trim($swap3[1])) * 1024 * 1024);
$this->sys->setSwapDevices($dev);
}
}
}
}
@@ -354,7 +354,7 @@ class Darwin extends BSDCommon
$lines = preg_split("/\n/", $netstat, -1, PREG_SPLIT_NO_EMPTY);
foreach ($lines as $line) {
$ar_buf = preg_split("/\s+/", $line, 10);
if (! empty($ar_buf[0])) {
if (!empty($ar_buf[0])) {
$dev = new NetDevice();
$dev->setName($ar_buf[0]);
$dev->setTxBytes($ar_buf[8]);
@@ -366,14 +366,25 @@ class Darwin extends BSDCommon
if (defined('PSI_SHOW_NETWORK_INFOS') && (PSI_SHOW_NETWORK_INFOS) && (CommonFunctions::executeProgram('ifconfig', $ar_buf[0].' 2>/dev/null', $bufr2, PSI_DEBUG))) {
$bufe2 = preg_split("/\n/", $bufr2, -1, PREG_SPLIT_NO_EMPTY);
foreach ($bufe2 as $buf2) {
if (preg_match('/^\s+ether\s+(\S+)/i', $buf2, $ar_buf2))
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').preg_replace('/:/', '-', $ar_buf2[1]));
elseif (preg_match('/^\s+inet\s+(\S+)\s+netmask/i', $buf2, $ar_buf2))
if (preg_match('/^\s+ether\s+(\S+)/i', $buf2, $ar_buf2)) {
if (!defined('PSI_HIDE_NETWORK_MACADDR') || !PSI_HIDE_NETWORK_MACADDR) $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').preg_replace('/:/', '-', strtoupper($ar_buf2[1])));
} elseif (preg_match('/^\s+inet\s+(\S+)\s+netmask/i', $buf2, $ar_buf2)) {
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$ar_buf2[1]);
elseif ((preg_match('/^\s+inet6\s+([^\s%]+)\s+prefixlen/i', $buf2, $ar_buf2)
} elseif ((preg_match('/^\s+inet6\s+([^\s%]+)\s+prefixlen/i', $buf2, $ar_buf2)
|| preg_match('/^\s+inet6\s+([^\s%]+)%\S+\s+prefixlen/i', $buf2, $ar_buf2))
&& !preg_match('/^fe80::/i', $ar_buf2[1]))
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$ar_buf2[1]);
&& ($ar_buf2[1]!="::") && !preg_match('/^fe80::/i', $ar_buf2[1])) {
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').strtolower($ar_buf2[1]));
} elseif (preg_match('/^\s+media:\s+/i', $buf2) && preg_match('/[\(\s](\d+)(G*)base/i', $buf2, $ar_buf2)) {
if (isset($ar_buf2[2]) && strtoupper($ar_buf2[2])=="G") {
$unit = "G";
} else {
$unit = "M";
}
if (preg_match('/[<\s]([^\s<]+)-duplex/i', $buf2, $ar_buf3))
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$ar_buf2[1].$unit.'b/s '.strtolower($ar_buf3[1]));
else
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$ar_buf2[1].$unit.'b/s');
}
}
}
$this->sys->setNetDevices($dev);
@@ -390,28 +401,37 @@ class Darwin extends BSDCommon
protected function distro()
{
$this->sys->setDistributionIcon('Darwin.png');
if (!CommonFunctions::executeProgram('system_profiler', 'SPSoftwareDataType', $buffer, PSI_DEBUG)) {
if ((!CommonFunctions::executeProgram('system_profiler', 'SPSoftwareDataType', $buffer, PSI_DEBUG) || !preg_match('/\n\s*System Version:/', $buffer))
&& (!CommonFunctions::executeProgram('sw_vers', '', $buffer, PSI_DEBUG) || !preg_match('/^ProductName:/', $buffer))) {
parent::distro();
} else {
$arrBuff = preg_split("/\n/", $buffer, -1, PREG_SPLIT_NO_EMPTY);
foreach ($arrBuff as $line) {
$arrLine = preg_split("/:/", $line, -1, PREG_SPLIT_NO_EMPTY);
if (trim($arrLine[0]) === "System Version") {
$distro = trim($arrLine[1]);
if (preg_match('/(^Mac OS)|(^OS X)/', $distro)) {
$this->sys->setDistributionIcon('Apple.png');
if (preg_match('/((^Mac OS X Server)|(^Mac OS X)|(^OS X Server)|(^OS X)) (\d+\.\d+)/', $distro, $ver)
&& ($list = @parse_ini_file(APP_ROOT."/data/osnames.ini", true))
&& isset($list['OS X'][$ver[6]])) {
$distro.=' '.$list['OS X'][$ver[6]];
$distro_tmp = preg_split("/\n/", $buffer, -1, PREG_SPLIT_NO_EMPTY);
foreach ($distro_tmp as $info) {
$info_tmp = preg_split('/:/', $info, 2);
if (isset($distro_tmp[0]) && ($distro_tmp[0] !== null) && (trim($distro_tmp[0]) != "") &&
isset($distro_tmp[1]) && ($distro_tmp[1] !== null) && (trim($distro_tmp[1]) != "")) {
$distro_arr[trim($info_tmp[0])] = trim($info_tmp[1]);
}
}
if (isset($distro_arr['ProductName']) && isset($distro_arr['ProductVersion']) && isset($distro_arr['BuildVersion'])) {
$distro_arr['System Version'] = $distro_arr['ProductName'].' '.$distro_arr['ProductVersion'].' ('.$distro_arr['BuildVersion'].')';
}
if (isset($distro_arr['System Version'])) {
$distro = $distro_arr['System Version'];
if (preg_match('/^Mac OS |^OS X |^macOS |^iPhone OS |^Mac OS$|^OS X$|^macOS$|^iPhone OS$/', $distro)) {
$this->sys->setDistributionIcon('Apple.png');
if (preg_match('/(^Mac OS X Server|^Mac OS X|^OS X Server|^OS X|^macOS Server|^macOS) ((\d+)\.\d+)/', $distro, $ver)
&& ($list = @parse_ini_file(PSI_APP_ROOT."/data/osnames.ini", true))) {
if (isset($list['macOS'][$ver[2]])) {
$distro.=' '.$list['macOS'][$ver[2]];
} elseif (isset($list['macOS'][$ver[3]])) {
$distro.=' '.$list['macOS'][$ver[3]];
}
}
$this->sys->setDistribution($distro);
return;
}
$this->sys->setDistribution($distro);
} else {
parent::distro();
}
}
}
@@ -451,14 +471,19 @@ class Darwin extends BSDCommon
*
* @see PSI_Interface_OS::build()
*
* @return Void
* @return void
*/
public function build()
{
parent::build();
$this->_uptime();
$this->_network();
$this->_processes();
$this->_tb();
if (!$this->blockname || $this->blockname==='vitals') {
$this->_processes();
}
if (!$this->blockname || $this->blockname==='hardware') {
$this->_tb();
}
if (!$this->blockname || $this->blockname==='network') {
$this->_network();
}
}
}

View File

@@ -8,7 +8,7 @@
* @package PSI DragonFly OS class
* @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 SVN: $Id: class.DragonFly.inc.php 287 2009-06-26 12:11:59Z bigmichi1 $
* @link http://phpsysinfo.sourceforge.net
*/
@@ -20,7 +20,7 @@
* @package PSI DragonFly OS class
* @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
*/
@@ -29,33 +29,20 @@ class DragonFly extends BSDCommon
/**
* define the regexp for log parser
*/
public function __construct()
public function __construct($blockname = false)
{
parent::__construct();
$this->setCPURegExp1("^cpu(.*)\, (.*) MHz");
$this->setCPURegExp2("^(.*) at scsibus.*: <(.*)> .*");
$this->setSCSIRegExp2("^(da[0-9]): (.*)MB ");
$this->setPCIRegExp1("/(.*): <(.*)>(.*) (pci|legacypci)[0-9]$/");
parent::__construct($blockname);
$this->setCPURegExp1("/^cpu(.*)\, (.*) MHz/\n/^CPU: (.*) \((.*)-MHz (.*)\)/"); // multiple regexp separated by \n
$this->setCPURegExp2("/^(.*) at scsibus.*: <(.*)> .*/");
$this->setSCSIRegExp2("/^(da[0-9]+): (.*)MB /");
$this->setPCIRegExp1("/(.*): <(.*)>(.*) (pci|legacypci)[0-9]+$/");
$this->setPCIRegExp2("/(.*): <(.*)>.* at [0-9\.]+$/");
}
/**
* UpTime
* time the system is running
*
* @return void
*/
private function _uptime()
{
$a = $this->grab_key('kern.boottime');
preg_match("/sec = ([0-9]+)/", $a, $buf);
$this->sys->setUptime(time() - $buf[1]);
}
/**
* get network information
*
* @return array
* @return void
*/
private function _network()
{
@@ -66,7 +53,7 @@ class DragonFly extends BSDCommon
for ($i = 0, $max = sizeof($lines_b); $i < $max; $i++) {
$ar_buf_b = preg_split("/\s+/", $lines_b[$i]);
$ar_buf_n = preg_split("/\s+/", $lines_n[$i]);
if (! empty($ar_buf_b[0]) && ! empty($ar_buf_n[3])) {
if (!empty($ar_buf_b[0]) && (!empty($ar_buf_n[5]) || ($ar_buf_n[5] === "0"))) {
$dev = new NetDevice();
$dev->setName($ar_buf_b[0]);
$dev->setTxBytes($ar_buf_b[8]);
@@ -81,16 +68,16 @@ class DragonFly extends BSDCommon
/**
* get the ide information
*
* @return array
* @return void
*/
protected function ide()
{
foreach ($this->readdmesg() as $line) {
if (preg_match('/^(.*): (.*) <(.*)> at (ata[0-9]\-(.*)) (.*)/', $line, $ar_buf)) {
if (preg_match('/^(.*): (.*) <(.*)> at (ata[0-9]+\-(.*)) (.*)/', $line, $ar_buf)) {
$dev = new HWDevice();
$dev->setName($ar_buf[1]);
if (!preg_match("/^acd[0-9](.*)/", $ar_buf[1])) {
$dev->setCapacity($ar_buf[2] * 1024);
if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS && !preg_match("/^acd[0-9]+(.*)/", $ar_buf[1])) {
$dev->setCapacity($ar_buf[2] * 1024 * 1024);
}
$this->sys->setIdeDevices($dev);
}
@@ -140,14 +127,17 @@ class DragonFly extends BSDCommon
*
* @see BSDCommon::build()
*
* @return Void
* @return void
*/
public function build()
{
parent::build();
$this->_distroicon();
$this->_network();
$this->_uptime();
$this->_processes();
if (!$this->blockname || $this->blockname==='vitals') {
$this->_distroicon();
$this->_processes();
}
if (!$this->blockname || $this->blockname==='network') {
$this->_network();
}
}
}

View File

@@ -8,7 +8,7 @@
* @package PSI FreeBSD OS class
* @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 SVN: $Id: class.FreeBSD.inc.php 696 2012-09-09 11:24:04Z namiltd $
* @link http://phpsysinfo.sourceforge.net
*/
@@ -20,7 +20,7 @@
* @package PSI FreeBSD OS class
* @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
*/
@@ -29,30 +29,18 @@ class FreeBSD extends BSDCommon
/**
* define the regexp for log parser
*/
public function __construct()
public function __construct($blockname = false)
{
parent::__construct();
$this->setCPURegExp1("CPU: (.*) \((.*)-MHz (.*)\)");
parent::__construct($blockname);
$this->setCPURegExp1("/CPU: (.*) \((.*)-MHz (.*)\)/");
$this->setCPURegExp2("/(.*) ([0-9]+) ([0-9]+) ([0-9]+) ([0-9]+)/");
$this->setSCSIRegExp1("^(.*): <(.*)> .*SCSI.*device");
$this->setSCSIRegExp2("^(da[0-9]): (.*)MB ");
$this->setPCIRegExp1("/(.*): <(.*)>(.*) pci[0-9]$/");
$this->setSCSIRegExp1("/^(.*): <(.*)> .*SCSI.*device/");
$this->setSCSIRegExp2("/^(da[0-9]+): (.*)MB /");
$this->setSCSIRegExp3("/^(da[0-9]+|cd[0-9]+): Serial Number (.*)/");
$this->setPCIRegExp1("/(.*): <(.*)>(.*) pci[0-9]+$/");
$this->setPCIRegExp2("/(.*): <(.*)>.* at [.0-9]+ irq/");
}
/**
* UpTime
* time the system is running
*
* @return void
*/
private function _uptime()
{
$s = preg_split('/ /', $this->grabkey('kern.boottime'));
$a = preg_replace('/,/', '', $s[3]);
$this->sys->setUptime(time() - $a);
}
/**
* get network information
*
@@ -65,11 +53,11 @@ class FreeBSD extends BSDCommon
$lines = preg_split("/\n/", $netstat, -1, PREG_SPLIT_NO_EMPTY);
foreach ($lines as $line) {
$ar_buf = preg_split("/\s+/", $line);
if (! empty($ar_buf[0])) {
if (!empty($ar_buf[0])) {
if (preg_match('/^<Link/i', $ar_buf[2])) {
$dev = new NetDevice();
$dev->setName($ar_buf[0]);
if (strlen($ar_buf[3]) < 17) { /* no Address */
if ((strlen($ar_buf[3]) < 17) && ($ar_buf[0] != $ar_buf[3])) { /* no MAC or dev name*/
if (isset($ar_buf[11]) && (trim($ar_buf[11]) != '')) { /* Idrop column exist*/
$dev->setTxBytes($ar_buf[9]);
$dev->setRxBytes($ar_buf[6]);
@@ -97,14 +85,25 @@ class FreeBSD extends BSDCommon
if (defined('PSI_SHOW_NETWORK_INFOS') && (PSI_SHOW_NETWORK_INFOS) && (CommonFunctions::executeProgram('ifconfig', $ar_buf[0].' 2>/dev/null', $bufr2, PSI_DEBUG))) {
$bufe2 = preg_split("/\n/", $bufr2, -1, PREG_SPLIT_NO_EMPTY);
foreach ($bufe2 as $buf2) {
if (preg_match('/^\s+ether\s+(\S+)/i', $buf2, $ar_buf2))
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').preg_replace('/:/', '-', $ar_buf2[1]));
elseif (preg_match('/^\s+inet\s+(\S+)\s+netmask/i', $buf2, $ar_buf2))
if (preg_match('/^\s+ether\s+(\S+)/i', $buf2, $ar_buf2)) {
if (!defined('PSI_HIDE_NETWORK_MACADDR') || !PSI_HIDE_NETWORK_MACADDR) $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').preg_replace('/:/', '-', strtoupper($ar_buf2[1])));
} elseif (preg_match('/^\s+inet\s+(\S+)\s+netmask/i', $buf2, $ar_buf2)) {
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$ar_buf2[1]);
elseif ((preg_match('/^\s+inet6\s+([^\s%]+)\s+prefixlen/i', $buf2, $ar_buf2)
} elseif ((preg_match('/^\s+inet6\s+([^\s%]+)\s+prefixlen/i', $buf2, $ar_buf2)
|| preg_match('/^\s+inet6\s+([^\s%]+)%\S+\s+prefixlen/i', $buf2, $ar_buf2))
&& !preg_match('/^fe80::/i', $ar_buf2[1]))
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$ar_buf2[1]);
&& ($ar_buf2[1]!="::") && !preg_match('/^fe80::/i', $ar_buf2[1])) {
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').strtolower($ar_buf2[1]));
} elseif (preg_match('/^\s+media:\s+/i', $buf2) && preg_match('/[\(\s](\d+)(G*)base/i', $buf2, $ar_buf2)) {
if (isset($ar_buf2[2]) && strtoupper($ar_buf2[2])=="G") {
$unit = "G";
} else {
$unit = "M";
}
if (preg_match('/[<\s]([^\s<]+)-duplex/i', $buf2, $ar_buf3))
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$ar_buf2[1].$unit.'b/s '.strtolower($ar_buf3[1]));
else
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$ar_buf2[1].$unit.'b/s');
}
}
}
$this->sys->setNetDevices($dev);
@@ -121,9 +120,19 @@ class FreeBSD extends BSDCommon
*/
private function _distroicon()
{
if (extension_loaded('pfSense') && CommonFunctions::rfts('/etc/version', $version, 1, 4096, false) && (trim($version) != '')) { // pfSense detection
$this->sys->setDistribution('pfSense '. trim($version));
$this->sys->setDistributionIcon('pfSense.png');
if (CommonFunctions::rfts('/etc/version', $version, 1, 4096, false) && (($version=trim($version)) != '')) {
if (extension_loaded('pfSense')) { // pfSense detection
$this->sys->setDistribution('pfSense '. $version);
$this->sys->setDistributionIcon('pfSense.png');
} elseif (preg_match('/^FreeNAS/i', $version)) { // FreeNAS detection
$this->sys->setDistribution($version);
$this->sys->setDistributionIcon('FreeNAS.png');
} elseif (preg_match('/^TrueNAS/i', $version)) { // TrueNAS detection
$this->sys->setDistribution($version);
$this->sys->setDistributionIcon('TrueNAS.png');
} else {
$this->sys->setDistributionIcon('FreeBSD.png');
}
} else {
$this->sys->setDistributionIcon('FreeBSD.png');
}
@@ -176,15 +185,20 @@ class FreeBSD extends BSDCommon
*
* @see BSDCommon::build()
*
* @return Void
* @return void
*/
public function build()
{
parent::build();
$this->_memoryadditional();
$this->_distroicon();
$this->_network();
$this->_uptime();
$this->_processes();
if (!$this->blockname || $this->blockname==='vitals') {
$this->_distroicon();
$this->_processes();
}
if (!$this->blockname || $this->blockname==='memory') {
$this->_memoryadditional();
}
if (!$this->blockname || $this->blockname==='network') {
$this->_network();
}
}
}

View File

@@ -0,0 +1,118 @@
<?php
/**
* GNU Class
*
* PHP version 5
*
* @category PHP
* @package PSI GNU class
* @author Mieczyslaw Nalewaj <namiltd@users.sourceforge.net>
* @copyright 2012 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License version 2, or (at your option) any later version
* @version SVN: $Id: class.GNU.inc.php 687 2012-09-06 20:54:49Z namiltd $
* @link http://phpsysinfo.sourceforge.net
*/
/**
* GNU sysinfo class
* get all the required information from GNU
*
* @category PHP
* @package PSI GNU class
* @author Mieczyslaw Nalewaj <namiltd@users.sourceforge.net>
* @copyright 2022 phpSysInfo
* @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
*/
class GNU extends Linux
{
/**
* Network devices
* includes also rx/tx bytes
*
* @return void
*/
protected function _network($bufr = null)
{
if ($this->sys->getOS() == 'GNU') {
if (CommonFunctions::executeProgram('ifconfig', '-a', $bufr, PSI_DEBUG)) {
$lines = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
$was = false;
$macaddr = "";
$dev = null;
foreach ($lines as $line) {
if (preg_match("/^\/dev\/([^\s:]+)/", $line, $ar_buf) || preg_match("/^([^\s:]+)/", $line, $ar_buf)) {
if ($was) {
if ($macaddr != "") {
$dev->setInfo($macaddr.($dev->getInfo()?';'.$dev->getInfo():''));
}
$this->sys->setNetDevices($dev);
}
$macaddr = "";
$dev = new NetDevice();
$dev->setName($ar_buf[1]);
$was = true;
} else {
if ($was) {
if (defined('PSI_SHOW_NETWORK_INFOS') && (PSI_SHOW_NETWORK_INFOS)) {
if (preg_match('/^\s+inet address\s+(\S+)$/', $line, $ar_buf)) {
$dev->setInfo($ar_buf[1]);
} elseif (preg_match('/^\s+hardware addr\s+(\S+)$/', $line, $ar_buf)) {
if (!defined('PSI_HIDE_NETWORK_MACADDR') || !PSI_HIDE_NETWORK_MACADDR) {
$macaddr = preg_replace('/:/', '-', strtoupper($ar_buf[1]));
if ($macaddr === '00-00-00-00-00-00') { // empty
$macaddr = "";
}
}
}
}
}
}
}
if ($was) {
if ($macaddr != "") {
$dev->setInfo($macaddr.($dev->getInfo()?';'.$dev->getInfo():''));
}
$this->sys->setNetDevices($dev);
}
}
} else {
parent::_network($bufr);
}
}
/**
* Number of Users
*
* @return void
*/
protected function _users()
{
if ($this->sys->getOS() == 'GNU') {
if (CommonFunctions::executeProgram('who', '', $strBuf, PSI_DEBUG)) {
if (strlen($strBuf) > 0) {
$lines = preg_split('/\n/', $strBuf);
preg_match_all('/^login\s+/m', $strBuf, $ttybuf);
if (($who = count($lines)-count($ttybuf[0])) > 0) {
$this->sys->setUsers($who);
}
}
}
} else {
parent::_users();
}
}
/**
* get the information
*
* @return void
*/
public function build()
{
if ($this->sys->getOS() == 'GNU') {
$this->error->addWarning("The GNU Hurd version of phpSysInfo is a work in progress, some things currently don't work");
}
parent::build();
}
}

View File

@@ -8,7 +8,7 @@
* @package PSI HPUX OS class
* @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 SVN: $Id: class.HPUX.inc.php 596 2012-07-05 19:37:48Z namiltd $
* @link http://phpsysinfo.sourceforge.net
*/
@@ -20,12 +20,17 @@
* @package PSI HPUX OS class
* @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
*/
class HPUX extends OS
{
/**
* uptime command result.
*/
private $_uptime = null;
/**
* Virtual Host Name
*
@@ -33,8 +38,8 @@ class HPUX extends OS
*/
private function _hostname()
{
if (PSI_USE_VHOST === true) {
$this->sys->setHostname(getenv('SERVER_NAME'));
if (PSI_USE_VHOST) {
if (CommonFunctions::readenv('SERVER_NAME', $hnm)) $this->sys->setHostname($hnm);
} else {
if (CommonFunctions::executeProgram('hostname', '', $ret)) {
$this->sys->setHostname($ret);
@@ -42,24 +47,6 @@ class HPUX extends OS
}
}
/**
* IP of the Virtual Host Name
*
* @return void
*/
private function _ip()
{
if (PSI_USE_VHOST === true) {
$this->sys->setIp(gethostbyname($this->sys->getHostname()));
} else {
if (!($result = getenv('SERVER_ADDR'))) {
$this->sys->setIp(gethostbyname($this->sys->getHostname()));
} else {
$this->sys->setIp($result);
}
}
}
/**
* HP-UX Version
*
@@ -80,8 +67,8 @@ class HPUX extends OS
*/
private function _uptime()
{
if (CommonFunctions::executeProgram('uptime', '', $buf)) {
if (preg_match("/up (\d+) days,\s*(\d+):(\d+),/", $buf, $ar_buf)) {
if (($this->_uptime !== null) || CommonFunctions::executeProgram('uptime', '', $this->_uptime)) {
if (preg_match("/up (\d+) days,\s*(\d+):(\d+),/", $this->_uptime, $ar_buf)) {
$min = $ar_buf[3];
$hours = $ar_buf[2];
$days = $ar_buf[1];
@@ -90,19 +77,6 @@ class HPUX extends OS
}
}
/**
* Number of Users
*
* @return void
*/
private function _users()
{
if (CommonFunctions::executeProgram('who', '-q', $ret)) {
$who = preg_split('/=/', $ret, -1, PREG_SPLIT_NO_EMPTY);
$this->sys->setUsers($who[1]);
}
}
/**
* Processor Load
* optionally create a loadbar
@@ -111,8 +85,8 @@ class HPUX extends OS
*/
private function _loadavg()
{
if (CommonFunctions::executeProgram('uptime', '', $buf)) {
if (preg_match("/average: (.*), (.*), (.*)$/", $buf, $ar_buf)) {
if (($this->_uptime !== null) || CommonFunctions::executeProgram('uptime', '', $this->_uptime)) {
if (preg_match("/average: (.*), (.*), (.*)$/", $this->_uptime, $ar_buf)) {
$this->sys->setLoad($ar_buf[1].' '.$ar_buf[2].' '.$ar_buf[3]);
}
}
@@ -132,31 +106,29 @@ class HPUX extends OS
$dev = new CpuDevice();
$details = preg_split("/\n/", $processor, -1, PREG_SPLIT_NO_EMPTY);
foreach ($details as $detail) {
$arrBuff = preg_split('/\s+:\s+/', trim($detail));
if (count($arrBuff) == 2) {
switch (strtolower($arrBuff[0])) {
if (preg_match('/^([^:]+):(.+)$/', trim($detail) , $arrBuff) && (($arrBuff2 = trim($arrBuff[2])) !== '')) {
switch (strtolower(trim($arrBuff[1]))) {
case 'model name':
case 'cpu':
$dev->setModel($arrBuff[1]);
$dev->setModel($arrBuff2);
break;
case 'cpu mhz':
case 'clock':
$dev->setCpuSpeed($arrBuff[1]);
$dev->setCpuSpeed($arrBuff2);
break;
case 'cycle frequency [hz]':
$dev->setCpuSpeed($arrBuff[1] / 1000000);
$dev->setCpuSpeed($arrBuff2 / 1000000);
break;
case 'cpu0clktck':
$dev->setCpuSpeed(hexdec($arrBuff[1]) / 1000000); // Linux sparc64
$dev->setCpuSpeed(hexdec($arrBuff2) / 1000000); // Linux sparc64
break;
case 'l2 cache':
case 'cache size':
$dev->setCache(preg_replace("/[a-zA-Z]/", "", $arrBuff[1]) * 1024);
$dev->setCache(preg_replace("/[a-zA-Z]/", "", $arrBuff2) * 1024);
break;
case 'bogomips':
case 'cpu0bogo':
$dev->setBogomips($arrBuff[1]);
break;
$dev->setBogomips($arrBuff2);
}
}
}
@@ -172,19 +144,25 @@ class HPUX extends OS
private function _pci()
{
if (CommonFunctions::rfts('/proc/pci', $bufr)) {
$device = false;
$bufe = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
foreach ($bufe as $buf) {
if (preg_match('/Bus/', $buf)) {
if (preg_match('/^\s*Bus\s/', $buf)) {
$device = true;
continue;
}
if ($device) {
$dev = new HWDevice();
$dev->setName(preg_replace('/\([^\)]+\)\.$/', '', trim($buf)));
$this->sys->setPciDevices($dev);
/*
list($key, $value) = preg_split('/: /', $buf, 2);
if (!preg_match('/bridge/i', $key) && !preg_match('/USB/i', $key)) {
$dev = new HWDevice();
$dev->setName(preg_replace('/\([^\)]+\)\.$/', '', trim($value)));
$this->sys->setPciDevices($dev);
}
*/
$device = false;
}
}
@@ -203,10 +181,10 @@ class HPUX extends OS
if (preg_match('/^hd/', $file)) {
$dev = new HWDevice();
$dev->setName(trim($file));
if (CommonFunctions::rfts("/proc/ide/".$file."/media", $buf, 1)) {
if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS && CommonFunctions::rfts("/proc/ide/".$file."/media", $buf, 1)) {
if (trim($buf) == 'disk') {
if (CommonFunctions::rfts("/proc/ide/".$file."/capacity", $buf, 1, 4096, false)) {
$dev->setCapacity(trim($buf) * 512 / 1024);
$dev->setCapacity(trim($buf) * 512);
}
}
}
@@ -250,9 +228,11 @@ class HPUX extends OS
{
if (CommonFunctions::rfts('/proc/bus/usb/devices', $bufr, 0, 4096, false)) {
$bufe = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
$devnum = -1;
$results = array();
foreach ($bufe as $buf) {
if (preg_match('/^T/', $buf)) {
$devnum += 1;
$devnum++;
$results[$devnum] = "";
} elseif (preg_match('/^S:/', $buf)) {
list($key, $value) = preg_split('/: /', $buf, 2);
@@ -344,7 +324,7 @@ class HPUX extends OS
$mounts = preg_split("/\n/", $df, -1, PREG_SPLIT_NO_EMPTY);
if (CommonFunctions::executeProgram('mount', '-v', $s, PSI_DEBUG)) {
$lines = preg_split("/\n/", $s, -1, PREG_SPLIT_NO_EMPTY);
while (list(, $line) = each($lines)) {
foreach ($lines as $line) {
$a = preg_split('/ /', $line, -1, PREG_SPLIT_NO_EMPTY);
$fsdev[$a[0]] = $a[4];
}
@@ -381,24 +361,33 @@ class HPUX extends OS
*
* @see PSI_Interface_OS::build()
*
* @return Void
* @return void
*/
public function build()
{
$this->_distro();
$this->_hostname();
$this->_ip();
$this->_kernel();
$this->_uptime();
$this->_users();
$this->_loadavg();
$this->_cpuinfo();
$this->_pci();
$this->_ide();
$this->_scsi();
$this->_usb();
$this->_network();
$this->_memory();
$this->_filesystems();
if (!$this->blockname || $this->blockname==='vitals') {
$this->_distro();
$this->_hostname();
$this->_kernel();
$this->_uptime();
$this->_users();
$this->_loadavg();
}
if (!$this->blockname || $this->blockname==='hardware') {
$this->_cpuinfo();
$this->_pci();
$this->_ide();
$this->_scsi();
$this->_usb();
}
if (!$this->blockname || $this->blockname==='memory') {
$this->_memory();
}
if (!$this->blockname || $this->blockname==='filesystem') {
$this->_filesystems();
}
if (!$this->blockname || $this->blockname==='network') {
$this->_network();
}
}
}

View File

@@ -8,7 +8,7 @@
* @package PSI Haiku OS class
* @author Mieczyslaw Nalewaj <namiltd@users.sourceforge.net>
* @copyright 2012 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 SVN: $Id: class.Haiku.inc.php 687 2012-09-06 20:54:49Z namiltd $
* @link http://phpsysinfo.sourceforge.net
*/
@@ -20,24 +20,16 @@
* @package PSI Haiku OS class
* @author Mieczyslaw Nalewaj <namiltd@users.sourceforge.net>
* @copyright 2012 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
*/
class Haiku extends OS
{
/**
* call parent constructor
*/
public function __construct()
{
parent::__construct();
}
/**
* get the cpu information
*
* @return array
* @return void
*/
protected function _cpuinfo()
{
@@ -53,21 +45,22 @@ class Haiku extends OS
$dev->setModel($ar_buf[1]);
$arrLines = preg_split("/\n/", $cpu, -1, PREG_SPLIT_NO_EMPTY);
foreach ($arrLines as $Line) {
if (preg_match("/^\s+Data TLB:\s+(.*)K-byte/", $Line, $Line_buf)) {
$dev->setCache(max($Line_buf[1]*1024, $dev->getCache()));
} elseif (preg_match("/^\s+Data TLB:\s+(.*)M-byte/", $Line, $Line_buf)) {
$dev->setCache(max($Line_buf[1]*1024*1024, $dev->getCache()));
} elseif (preg_match("/^\s+Data TLB:\s+(.*)G-byte/", $Line, $Line_buf)) {
$dev->setCache(max($Line_buf[1]*1024*1024*1024, $dev->getCache()));
if (preg_match("/^\s+Data TLB:\s+(.*)K-byte/", $Line, $Line_buf) || preg_match("/^\s+L0 Data TLB:\s+(.*)K-byte/", $Line, $Line_buf)) {
$dev->setCache(max(intval($Line_buf[1])*1024, $dev->getCache()));
} elseif (preg_match("/^\s+Data TLB:\s+(.*)M-byte/", $Line, $Line_buf) || preg_match("/^\s+L0 Data TLB:\s+(.*)M-byte/", $Line, $Line_buf)) {
$dev->setCache(max(intval($Line_buf[1])*1024*1024, $dev->getCache()));
} elseif (preg_match("/^\s+Data TLB:\s+(.*)G-byte/", $Line, $Line_buf) || preg_match("/^\s+L0 Data TLB:\s+(.*)G-byte/", $Line, $Line_buf)) {
$dev->setCache(max(intval($Line_buf[1])*1024*1024*1024, $dev->getCache()));
} elseif (preg_match("/\s+VMX/", $Line, $Line_buf)) {
$dev->setVirt("vmx");
} elseif (preg_match("/\s+SVM/", $Line, $Line_buf)) {
$dev->setVirt("svm");
}
}
if ($cpuspeed != "")$dev->setCpuSpeed($cpuspeed);
if ($cpuspeed != "") {
$dev->setCpuSpeed($cpuspeed);
}
$this->sys->setCpus($dev);
//echo ">>>>>".$cpu;
}
}
}
@@ -136,7 +129,7 @@ class Haiku extends OS
private function _kernel()
{
if (CommonFunctions::executeProgram('uname', '-rvm', $ret)) {
$this->sys->setKernel($ret);
$this->sys->setKernel($ret);
}
}
@@ -163,19 +156,28 @@ class Haiku extends OS
*/
private function _uptime()
{
if (CommonFunctions::executeProgram('uptime', '-u', $buf)) {
if (preg_match("/^up (\d+) minute[s]?/", $buf, $ar_buf)) {
$min = $ar_buf[1];
$this->sys->setUptime($min * 60);
} elseif (preg_match("/^up (\d+) hour[s]?, (\d+) minute[s]?/", $buf, $ar_buf)) {
$min = $ar_buf[2];
$hours = $ar_buf[1];
$this->sys->setUptime($hours * 3600 + $min * 60);
} elseif (preg_match("/^up (\d+) day[s]?, (\d+) hour[s]?, (\d+) minute[s]?/", $buf, $ar_buf)) {
if (CommonFunctions::executeProgram('uptime', '', $buf)) {
if (preg_match("/up (\d+) day[s]?,[ ]+(\d+):(\d+),/", $buf, $ar_buf)) {
$min = $ar_buf[3];
$hours = $ar_buf[2];
$days = $ar_buf[1];
$this->sys->setUptime($days * 86400 + $hours * 3600 + $min * 60);
} elseif (preg_match("/up[ ]+(\d+):(\d+),/", $buf, $ar_buf)) {
$min = $ar_buf[2];
$hours = $ar_buf[1];
$this->sys->setUptime($hours * 3600 + $min * 60);
} elseif (preg_match("/up (\d+) day[s]?, (\d+) hour[s]?, (\d+) minute[s]?$/", $buf, $ar_buf)) {
$min = $ar_buf[3];
$hours = $ar_buf[2];
$days = $ar_buf[1];
$this->sys->setUptime($days * 86400 + $hours * 3600 + $min * 60);
} elseif (preg_match("/up (\d+) hour[s]?, (\d+) minute[s]?$/", $buf, $ar_buf)) {
$min = $ar_buf[2];
$hours = $ar_buf[1];
$this->sys->setUptime($hours * 3600 + $min * 60);
} elseif (preg_match("/up (\d+) minute[s]?$/", $buf, $ar_buf)) {
$min = $ar_buf[1];
$this->sys->setUptime($min * 60);
}
}
}
@@ -203,7 +205,7 @@ class Haiku extends OS
*
* @return void
*/
private function _users()
protected function _users()
{
$this->sys->setUsers(1);
}
@@ -215,8 +217,8 @@ class Haiku extends OS
*/
private function _hostname()
{
if (PSI_USE_VHOST === true) {
$this->sys->setHostname(getenv('SERVER_NAME'));
if (PSI_USE_VHOST) {
if (CommonFunctions::readenv('SERVER_NAME', $hnm)) $this->sys->setHostname($hnm);
} else {
if (CommonFunctions::executeProgram('uname', '-n', $result, PSI_DEBUG)) {
$ip = gethostbyname($result);
@@ -227,24 +229,6 @@ class Haiku extends OS
}
}
/**
* IP of the Virtual Host Name
*
* @return void
*/
private function _ip()
{
if (PSI_USE_VHOST === true) {
$this->sys->setIp(gethostbyname($this->sys->getHostname()));
} else {
if (!($result = getenv('SERVER_ADDR'))) {
$this->sys->setIp(gethostbyname($this->sys->getHostname()));
} else {
$this->sys->setIp($result);
}
}
}
/**
* Physical memory information and Swap Space information
*
@@ -256,7 +240,7 @@ class Haiku extends OS
if (preg_match("/(.*)bytes free\s+\(used\/max\s+(.*)\s+\/\s+(.*)\)\s*\n\s+\(cached\s+(.*)\)/", $bufr, $ar_buf)) {
$this->sys->setMemTotal($ar_buf[3]);
$this->sys->setMemFree($ar_buf[1]);
$this->sys->setMemCache($ar_buf[4]);
$this->sys->setMemCache(min($ar_buf[4], $ar_buf[2]));
$this->sys->setMemUsed($ar_buf[2]);
}
}
@@ -310,10 +294,13 @@ class Haiku extends OS
{
if (CommonFunctions::executeProgram('ifconfig', '', $bufr, PSI_DEBUG)) {
$lines = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
$notwas = true;
$was = false;
$errors = 0;
$drops = 0;
$dev = null;
foreach ($lines as $line) {
if (preg_match("/^(\S+)/", $line, $ar_buf)) {
if (!$notwas) {
if ($was) {
$dev->setErrors($errors);
$dev->setDrops($drops);
$this->sys->setNetDevices($dev);
@@ -322,9 +309,9 @@ class Haiku extends OS
$drops = 0;
$dev = new NetDevice();
$dev->setName($ar_buf[1]);
$notwas = false;
$was = true;
} else {
if (!$notwas) {
if ($was) {
if (preg_match('/\sReceive:\s\d+\spackets,\s(\d+)\serrors,\s(\d+)\sbytes,\s\d+\smcasts,\s(\d+)\sdropped/i', $line, $ar_buf2)) {
$errors +=$ar_buf2[1];
$drops +=$ar_buf2[3];
@@ -336,18 +323,19 @@ class Haiku extends OS
}
if (defined('PSI_SHOW_NETWORK_INFOS') && (PSI_SHOW_NETWORK_INFOS)) {
if (preg_match('/\sEthernet,\s+Address:\s(\S*)/i', $line, $ar_buf2))
$dev->setInfo(preg_replace('/:/', '-', $ar_buf2[1]));
elseif (preg_match('/^\s+inet\saddr:\s(\S*),/i', $line, $ar_buf2))
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$ar_buf2[1]);
elseif (preg_match('/^\s+inet6\saddr:\s(\S*),/i', $line, $ar_buf2))
if (!preg_match('/^fe80::/i', $ar_buf2[1]))
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$ar_buf2[1]);
if (preg_match('/\sEthernet,\s+Address:\s(\S*)/i', $line, $ar_buf2)) {
if (!defined('PSI_HIDE_NETWORK_MACADDR') || !PSI_HIDE_NETWORK_MACADDR) $dev->setInfo(preg_replace('/:/', '-', strtoupper($ar_buf2[1])));
} elseif (preg_match('/^\s+inet\saddr:\s(\S*),/i', $line, $ar_buf2)) {
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$ar_buf2[1]);
} elseif (preg_match('/^\s+inet6\saddr:\s(\S*),/i', $line, $ar_buf2)
&& ($ar_buf2[1]!="::") && !preg_match('/^fe80::/i', $ar_buf2[1])) {
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').strtolower($ar_buf2[1]));
}
}
}
}
}
if (!$notwas) {
if ($was) {
$dev->setErrors($errors);
$dev->setDrops($drops);
$this->sys->setNetDevices($dev);
@@ -380,24 +368,33 @@ class Haiku extends OS
/**
* get the information
*
* @return Void
* @return void
*/
public function build()
{
$this->error->addError("WARN", "The Haiku version of phpSysInfo is a work in progress, some things currently don't work");
$this->_distro();
$this->_hostname();
$this->_ip();
$this->_kernel();
$this->_uptime();
$this->_users();
$this->_loadavg();
$this->_pci();
$this->_usb();
$this->_cpuinfo();
$this->_memory();
$this->_filesystems();
$this->_network();
$this->_processes();
$this->error->addWarning("The Haiku version of phpSysInfo is a work in progress, some things currently don't work");
if (!$this->blockname || $this->blockname==='vitals') {
$this->_distro();
$this->_hostname();
$this->_kernel();
$this->_uptime();
$this->_users();
$this->_loadavg();
$this->_processes();
}
if (!$this->blockname || $this->blockname==='hardware') {
$this->_cpuinfo();
$this->_pci();
$this->_usb();
}
if (!$this->blockname || $this->blockname==='memory') {
$this->_memory();
}
if (!$this->blockname || $this->blockname==='filesystem') {
$this->_filesystems();
}
if (!$this->blockname || $this->blockname==='network') {
$this->_network();
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -8,7 +8,7 @@
* @package PSI Minix OS class
* @author Mieczyslaw Nalewaj <namiltd@users.sourceforge.net>
* @copyright 2012 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 SVN: $Id: class.Minix.inc.php 687 2012-09-06 20:54:49Z namiltd $
* @link http://phpsysinfo.sourceforge.net
*/
@@ -20,26 +20,23 @@
* @package PSI Minix OS class
* @author Mieczyslaw Nalewaj <namiltd@users.sourceforge.net>
* @copyright 2012 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
*/
class Minix extends OS
{
/**
* uptime command result.
*/
private $_uptime = null;
/**
* content of the syslog
*
* @var array
*/
private $_dmesg = array();
/**
* call parent constructor
*/
public function __construct()
{
parent::__construct();
}
private $_dmesg = null;
/**
* read /var/log/messages, but only if we haven't already
@@ -48,11 +45,13 @@ class Minix extends OS
*/
protected function readdmesg()
{
if (count($this->_dmesg) === 0) {
if ($this->_dmesg === null) {
if (CommonFunctions::rfts('/var/log/messages', $buf)) {
$parts = preg_split("/kernel: APIC/", $buf, -1, PREG_SPLIT_NO_EMPTY);
// $parts = preg_split("/ syslogd: restart\n/", $buf, -1, PREG_SPLIT_NO_EMPTY);
$blocks = preg_replace("/\s(kernel: MINIX \d+\.\d+\.\d+\.)/", '<BLOCK>$1', $buf);
$parts = preg_split("/<BLOCK>/", $blocks, -1, PREG_SPLIT_NO_EMPTY);
$this->_dmesg = preg_split("/\n/", $parts[count($parts) - 1], -1, PREG_SPLIT_NO_EMPTY);
} else {
$this->_dmesg = array();
}
}
@@ -62,7 +61,7 @@ class Minix extends OS
/**
* get the cpu information
*
* @return array
* @return void
*/
protected function _cpuinfo()
{
@@ -73,31 +72,32 @@ class Minix extends OS
$dev = new CpuDevice();
$details = preg_split("/\n/", $processor, -1, PREG_SPLIT_NO_EMPTY);
foreach ($details as $detail) {
$arrBuff = preg_split('/\s+:\s+/', trim($detail));
if (count($arrBuff) == 2) {
switch (strtolower($arrBuff[0])) {
if (preg_match('/^([^:]+):(.+)$/', trim($detail) , $arrBuff) && (($arrBuff2 = trim($arrBuff[2])) !== '')) {
switch (strtolower(trim($arrBuff[1]))) {
case 'model name':
$_n = $arrBuff[1];
$_n = $arrBuff2;
break;
case 'cpu mhz':
$dev->setCpuSpeed($arrBuff[1]);
$dev->setCpuSpeed($arrBuff2);
break;
case 'cpu family':
$_f = $arrBuff[1];
$_f = $arrBuff2;
break;
case 'model':
$_m = $arrBuff[1];
$_m = $arrBuff2;
break;
case 'stepping':
$_s = $arrBuff[1];
$_s = $arrBuff2;
break;
case 'flags':
if (preg_match("/ vmx/", $arrBuff[1])) {
if (preg_match("/ vmx/", $arrBuff2)) {
$dev->setVirt("vmx");
} elseif (preg_match("/ svm/", $arrBuff[1])) {
} elseif (preg_match("/ svm/", $arrBuff2)) {
$dev->setVirt("svm");
}
break;
break;
case 'vendor_id':
$dev->setVendorId($arrBuff2);
}
}
}
@@ -129,6 +129,7 @@ class Minix extends OS
{
if (CommonFunctions::rfts('/proc/pci', $strBuf, 0, 4096, false)) {
$arrLines = preg_split("/\n/", $strBuf, -1, PREG_SPLIT_NO_EMPTY);
$arrResults = array();
foreach ($arrLines as $strLine) {
$arrParams = preg_split('/\s+/', trim($strLine), 4);
if (count($arrParams) == 4)
@@ -144,7 +145,7 @@ class Minix extends OS
$this->sys->setPciDevices($dev);
}
}
if (!(isset($arrResults) && is_array($arrResults)) && is_array($results = Parser::lspci())) {
if (!(isset($arrResults) && is_array($arrResults)) && ($results = Parser::lspci())) {
/* if access error: chmod 4755 /usr/bin/lspci */
foreach ($results as $dev) {
$this->sys->setPciDevices($dev);
@@ -159,12 +160,13 @@ class Minix extends OS
*/
private function _kernel()
{
foreach ($this->readdmesg() as $line) {
if (preg_match('/kernel: MINIX (.*) \((.*)\)/', $line, $ar_buf)) {
$branch = $ar_buf[2];
}
}
if (CommonFunctions::executeProgram('uname', '-rvm', $ret)) {
foreach ($this->readdmesg() as $line) {
if (preg_match('/kernel: MINIX (\d+\.\d+\.\d+)\. \((.+)\)/', $line, $ar_buf)) {
$branch = $ar_buf[2];
break;
}
}
if (isset($branch))
$this->sys->setKernel($ret.' ('.$branch.')');
else
@@ -195,13 +197,13 @@ class Minix extends OS
*/
private function _uptime()
{
if (CommonFunctions::executeProgram('uptime', '', $buf)) {
if (preg_match("/up (\d+) days,\s*(\d+):(\d+),/", $buf, $ar_buf)) {
if (($this->_uptime !== null) || CommonFunctions::executeProgram('uptime', '', $this->_uptime)) {
if (preg_match("/up (\d+) day[s]?,\s*(\d+):(\d+),/", $this->_uptime, $ar_buf)) {
$min = $ar_buf[3];
$hours = $ar_buf[2];
$days = $ar_buf[1];
$this->sys->setUptime($days * 86400 + $hours * 3600 + $min * 60);
} elseif (preg_match("/up (\d+):(\d+),/", $buf, $ar_buf)) {
} elseif (preg_match("/up (\d+):(\d+),/", $this->_uptime, $ar_buf)) {
$min = $ar_buf[2];
$hours = $ar_buf[1];
$this->sys->setUptime($hours * 3600 + $min * 60);
@@ -217,27 +219,13 @@ class Minix extends OS
*/
private function _loadavg()
{
if (CommonFunctions::executeProgram('uptime', '', $buf)) {
if (preg_match("/load averages: (.*), (.*), (.*)$/", $buf, $ar_buf)) {
if (($this->_uptime !== null) || CommonFunctions::executeProgram('uptime', '', $this->_uptime)) {
if (preg_match("/load averages: (.*), (.*), (.*)$/", $this->_uptime, $ar_buf)) {
$this->sys->setLoad($ar_buf[1].' '.$ar_buf[2].' '.$ar_buf[3]);
}
}
}
/**
* Number of Users
*
* @return void
*/
private function _users()
{
if (CommonFunctions::executeProgram('uptime', '', $buf)) {
if (preg_match("/, (.*) users, load averages: (.*), (.*), (.*)$/", $buf, $ar_buf)) {
$this->sys->setUsers($ar_buf[1]);
}
}
}
/**
* Virtual Host Name
*
@@ -245,8 +233,8 @@ class Minix extends OS
*/
private function _hostname()
{
if (PSI_USE_VHOST === true) {
$this->sys->setHostname(getenv('SERVER_NAME'));
if (PSI_USE_VHOST) {
if (CommonFunctions::readenv('SERVER_NAME', $hnm)) $this->sys->setHostname($hnm);
} else {
if (CommonFunctions::executeProgram('uname', '-n', $result, PSI_DEBUG)) {
$ip = gethostbyname($result);
@@ -257,23 +245,6 @@ class Minix extends OS
}
}
/**
* IP of the Virtual Host Name
*
* @return void
*/
private function _ip()
{
if (PSI_USE_VHOST === true) {
$this->sys->setIp(gethostbyname($this->sys->getHostname()));
} else {
if (!($result = getenv('SERVER_ADDR'))) {
$this->sys->setIp(gethostbyname($this->sys->getHostname()));
} else {
$this->sys->setIp($result);
}
}
}
/**
* Physical memory information and Swap Space information
@@ -360,23 +331,32 @@ class Minix extends OS
/**
* get the information
*
* @return Void
* @return void
*/
public function build()
{
$this->error->addError("WARN", "The Minix version of phpSysInfo is a work in progress, some things currently don't work");
$this->_distro();
$this->_hostname();
$this->_ip();
$this->_kernel();
$this->_uptime();
$this->_users();
$this->_loadavg();
$this->_pci();
$this->_cpuinfo();
$this->_memory();
$this->_filesystems();
$this->_network();
$this->_processes();
$this->error->addWarning("The Minix version of phpSysInfo is a work in progress, some things currently don't work");
if (!$this->blockname || $this->blockname==='vitals') {
$this->_distro();
$this->_hostname();
$this->_kernel();
$this->_uptime();
$this->_users();
$this->_loadavg();
$this->_processes();
}
if (!$this->blockname || $this->blockname==='hardware') {
$this->_pci();
$this->_cpuinfo();
}
if (!$this->blockname || $this->blockname==='memory') {
$this->_memory();
}
if (!$this->blockname || $this->blockname==='filesystem') {
$this->_filesystems();
}
if (!$this->blockname || $this->blockname==='network') {
$this->_network();
}
}
}

View File

@@ -8,7 +8,7 @@
* @package PSI NetBSD OS class
* @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 SVN: $Id: class.NetBSD.inc.php 287 2009-06-26 12:11:59Z bigmichi1 $
* @link http://phpsysinfo.sourceforge.net
*/
@@ -20,7 +20,7 @@
* @package PSI NetBSD OS class
* @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
*/
@@ -29,29 +29,17 @@ class NetBSD extends BSDCommon
/**
* define the regexp for log parser
*/
public function __construct()
public function __construct($blockname = false)
{
parent::__construct();
$this->setCPURegExp1("^cpu(.*)\, (.*) MHz");
parent::__construct($blockname);
//$this->setCPURegExp1("/^cpu(.*)\, (.*) MHz/");
$this->setCPURegExp2("/user = (.*), nice = (.*), sys = (.*), intr = (.*), idle = (.*)/");
$this->setSCSIRegExp1("^(.*) at scsibus.*: <(.*)> .*");
$this->setSCSIRegExp2("^(da[0-9]): (.*)MB ");
$this->setPCIRegExp1("/(.*) at pci[0-9] dev [0-9]* function [0-9]*: (.*)$/");
$this->setSCSIRegExp1("/^(.*) at scsibus.*: <(.*)> .*/");
$this->setSCSIRegExp2("/^(sd[0-9]+): (.*)([MG])B,/");
$this->setPCIRegExp1("/(.*) at pci[0-9]+ dev [0-9]* function [0-9]*: (.*)$/");
$this->setPCIRegExp2("/\"(.*)\" (.*).* at [.0-9]+ irq/");
}
/**
* UpTime
* time the system is running
*
* @return void
*/
private function _uptime()
{
$a = $this->grabkey('kern.boottime');
$this->sys->setUptime(time() - $a);
}
/**
* get network information
*
@@ -66,13 +54,39 @@ class NetBSD extends BSDCommon
for ($i = 0, $max = sizeof($lines_b); $i < $max; $i++) {
$ar_buf_b = preg_split("/\s+/", $lines_b[$i]);
$ar_buf_n = preg_split("/\s+/", $lines_n[$i]);
if (! empty($ar_buf_b[0]) && ! empty($ar_buf_n[3])) {
if (!empty($ar_buf_b[0]) && (!empty($ar_buf_n[3]) || ($ar_buf_n[3] === "0"))) {
$dev = new NetDevice();
$dev->setName($ar_buf_b[0]);
$dev->setTxBytes($ar_buf_b[4]);
$dev->setRxBytes($ar_buf_b[3]);
$dev->setDrops($ar_buf_n[8]);
$dev->setErrors($ar_buf_n[4] + $ar_buf_n[6]);
if (defined('PSI_SHOW_NETWORK_INFOS') && (PSI_SHOW_NETWORK_INFOS) && (CommonFunctions::executeProgram('ifconfig', $ar_buf_b[0].' 2>/dev/null', $bufr2, PSI_DEBUG))) {
$speedinfo = "";
$bufe2 = preg_split("/\n/", $bufr2, -1, PREG_SPLIT_NO_EMPTY);
foreach ($bufe2 as $buf2) {
if (preg_match('/^\s+address:\s+(\S+)/i', $buf2, $ar_buf2)) {
if (!defined('PSI_HIDE_NETWORK_MACADDR') || !PSI_HIDE_NETWORK_MACADDR) $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').preg_replace('/:/', '-', strtoupper($ar_buf2[1])));
} elseif (preg_match('/^\s+inet\s+(\S+)\s+netmask/i', $buf2, $ar_buf2)) {
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$ar_buf2[1]);
} elseif ((preg_match('/^\s+inet6\s+([^\s%]+)\s+prefixlen/i', $buf2, $ar_buf2)
|| preg_match('/^\s+inet6\s+([^\s%]+)%\S+\s+prefixlen/i', $buf2, $ar_buf2))
&& ($ar_buf2[1]!="::") && !preg_match('/^fe80::/i', $ar_buf2[1])) {
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').strtolower($ar_buf2[1]));
} elseif (preg_match('/^\s+media:\s+/i', $buf2) && preg_match('/[\(\s](\d+)(G*)base/i', $buf2, $ar_buf2)) {
if (isset($ar_buf2[2]) && strtoupper($ar_buf2[2])=="G") {
$unit = "G";
} else {
$unit = "M";
}
if (preg_match('/\s(\S+)-duplex/i', $buf2, $ar_buf3))
$speedinfo = $ar_buf2[1].$unit.'b/s '.strtolower($ar_buf3[1]);
else
$speedinfo = $ar_buf2[1].$unit.'b/s';
}
}
if ($speedinfo != "") $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$speedinfo);
}
$this->sys->setNetDevices($dev);
}
}
@@ -86,15 +100,34 @@ class NetBSD extends BSDCommon
protected function ide()
{
foreach ($this->readdmesg() as $line) {
if (preg_match('/^(.*) at (pciide|wdc|atabus|atapibus)[0-9] (.*): <(.*)>/', $line, $ar_buf)) {
if (preg_match('/^(.*) at (pciide|wdc|atabus|atapibus)[0-9]+ (.*): <(.*)>/', $line, $ar_buf)
|| preg_match('/^(.*) at (pciide|wdc|atabus|atapibus)[0-9]+ /', $line, $ar_buf)) {
$dev = new HWDevice();
$dev->setName($ar_buf[1]);
// now loop again and find the capacity
foreach ($this->readdmesg() as $line2) {
if (preg_match("/^(".$ar_buf[1]."): (.*), (.*), (.*)MB, .*$/", $line2, $ar_buf_n)) {
$dev->setCapacity($ar_buf_n[4] * 2048 * 1.049);
} elseif (preg_match("/^(".$ar_buf[1]."): (.*) MB, (.*), (.*), .*$/", $line2, $ar_buf_n)) {
$dev->setCapacity($ar_buf_n[2] * 2048);
if (isset($ar_buf[4])) {
$dev->setName($ar_buf[4]);
} else {
$dev->setName($ar_buf[1]);
// now loop again and find the name
foreach ($this->readdmesg() as $line2) {
if (preg_match("/^(".$ar_buf[1]."): <(.*)>$/", $line2, $ar_buf_n)) {
$dev->setName($ar_buf_n[2]);
break;
}
}
}
if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS) {
// now loop again and find the capacity
foreach ($this->readdmesg() as $line2) {
if (preg_match("/^(".$ar_buf[1]."): (.*), (.*), (.*)MB, .*$/", $line2, $ar_buf_n)) {
$dev->setCapacity($ar_buf_n[4] * 1024 * 1024);
break;
} elseif (preg_match("/^(".$ar_buf[1]."): (.*) MB, (.*), (.*), .*$/", $line2, $ar_buf_n)) {
$dev->setCapacity($ar_buf_n[2] * 1024 * 1024);
break;
} elseif (preg_match("/^(".$ar_buf[1]."): (.*) GB, (.*), (.*), .*$/", $line2, $ar_buf_n)) {
$dev->setCapacity($ar_buf_n[2] * 1024 * 1024 * 1024);
break;
}
}
}
$this->sys->setIdeDevices($dev);
@@ -102,6 +135,77 @@ class NetBSD extends BSDCommon
}
}
/**
* CPU information
*
* @return void
*/
protected function cpuinfo()
{
$was = false;
$cpuarray = array();
foreach ($this->readdmesg() as $line) {
if (preg_match("/^cpu([0-9])+: (.*)/", $line, $ar_buf)) {
$was = true;
$ar_buf[2] = trim($ar_buf[2]);
if (preg_match("/^(.+), ([\d\.]+) MHz/", $ar_buf[2], $ar_buf2)) {
if (($model = trim($ar_buf2[1])) !== "") {
$cpuarray[$ar_buf[1]]['model'] = $model;
}
if (($speed = trim($ar_buf2[2])) > 0) {
$cpuarray[$ar_buf[1]]['speed'] = $speed;
}
} elseif (preg_match("/^L2 cache (\d+) ([KM])B /", $ar_buf[2], $ar_buf2)) {
if ($ar_buf2[2]=="M") {
$cpuarray[$ar_buf[1]]['cache'] = $ar_buf2[1]*1024*1024;
} elseif ($ar_buf2[2]=="K") {
$cpuarray[$ar_buf[1]]['cache'] = $ar_buf2[1]*1024;
}
}
} elseif (!preg_match("/^cpu[0-9]+ /", $line) && $was) {
break;
}
}
$ncpu = $this->grabkey('hw.ncpu');
if (($ncpu === "") || !($ncpu >= 1)) {
$ncpu = 1;
}
$ncpu = max($ncpu, count($cpuarray));
$model = $this->grabkey('machdep.cpu_brand');
$model2 = $this->grabkey('hw.model');
if ($cpuspeed = $this->grabkey('machdep.tsc_freq')) {
$speed = round($cpuspeed / 1000000);
} else {
$speed = "";
}
for ($cpu = 0 ; $cpu < $ncpu ; $cpu++) {
$dev = new CpuDevice();
if (isset($cpuarray[$cpu]['model'])) {
$dev->setModel($cpuarray[$cpu]['model']);
} elseif ($model !== "") {
$dev->setModel($model);
} elseif ($model2 !== "") {
$dev->setModel($model2);
}
if (isset($cpuarray[$cpu]['speed'])) {
$dev->setCpuSpeed($cpuarray[$cpu]['speed']);
} elseif ($speed !== "") {
$dev->setCpuSpeed($speed);
}
if (isset($cpuarray[$cpu]['cache'])) {
$dev->setCache($cpuarray[$cpu]['cache']);
}
if (($ncpu == 1) && PSI_LOAD_BAR) {
$dev->setLoad($this->cpuusage());
}
$this->sys->setCpus($dev);
}
}
/**
* get icon name
*
@@ -146,14 +250,17 @@ class NetBSD extends BSDCommon
*
* @see BSDCommon::build()
*
* @return Void
* @return void
*/
public function build()
{
parent::build();
$this->_distroicon();
$this->_network();
$this->_uptime();
$this->_processes();
if (!$this->blockname || $this->blockname==='vitals') {
$this->_distroicon();
$this->_processes();
}
if (!$this->blockname || $this->blockname==='network') {
$this->_network();
}
}
}

View File

@@ -8,7 +8,7 @@
* @package PSI OS class
* @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 SVN: $Id: class.OS.inc.php 699 2012-09-15 11:57:13Z namiltd $
* @link http://phpsysinfo.sourceforge.net
*/
@@ -19,7 +19,7 @@
* @package PSI OS class
* @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
*/
@@ -28,10 +28,17 @@ abstract class OS implements PSI_Interface_OS
/**
* object for error handling
*
* @var Error
* @var PSI_Error
*/
protected $error;
/**
* block name
*
* @var string
*/
protected $blockname = false;
/**
* @var System
*/
@@ -40,10 +47,12 @@ abstract class OS implements PSI_Interface_OS
/**
* build the global Error object
*/
public function __construct()
public function __construct($blockname = false)
{
$this->error = Error::singleton();
$this->error = PSI_Error::singleton();
$this->sys = new System();
$this->blockname = $blockname;
$this->sys->setOS(get_class($this));
}
/**
@@ -57,6 +66,7 @@ abstract class OS implements PSI_Interface_OS
{
return PSI_SYSTEM_CODEPAGE;
}
/**
* get os specific language
*
@@ -69,6 +79,180 @@ abstract class OS implements PSI_Interface_OS
return PSI_SYSTEM_LANG;
}
/**
* get block name
*
* @see PSI_Interface_OS::getBlockName()
*
* @return string
*/
public function getBlockName()
{
return $this->blockname;
}
/**
* Number of Users
*
* @return void
*/
protected function _users()
{
if (CommonFunctions::executeProgram('who', '', $strBuf, PSI_DEBUG)) {
if (strlen($strBuf) > 0) {
$lines = preg_split('/\n/', $strBuf);
$this->sys->setUsers(count($lines));
}
} elseif (CommonFunctions::executeProgram('uptime', '', $buf, PSI_DEBUG) && preg_match("/,\s+(\d+)\s+user[s]?,/", $buf, $ar_buf)) {
//} elseif (CommonFunctions::executeProgram('uptime', '', $buf) && preg_match("/,\s+(\d+)\s+user[s]?,\s+load average[s]?:\s+(.*),\s+(.*),\s+(.*)$/", $buf, $ar_buf)) {
$this->sys->setUsers($ar_buf[1]);
} else {
$processlist = CommonFunctions::findglob('/proc/*/cmdline', GLOB_NOSORT);
if (is_array($processlist) && (($total = count($processlist)) > 0)) {
$count = 0;
$buf = "";
for ($i = 0; $i < $total; $i++) {
if (CommonFunctions::rfts($processlist[$i], $buf, 0, 4096, false)) {
$name = str_replace(chr(0), ' ', trim($buf));
if (preg_match("/^-/", $name)) {
$count++;
}
}
}
if ($count > 0) {
$this->sys->setUsers($count);
}
}
}
}
/**
* IP of the Host
*
* @return void
*/
protected function _ip()
{
if (PSI_USE_VHOST && !defined('PSI_EMU_HOSTNAME')) {
if ((CommonFunctions::readenv('SERVER_ADDR', $result) || CommonFunctions::readenv('LOCAL_ADDR', $result)) //is server address defined
&& !strstr($result, '.') && strstr($result, ':')) { //is IPv6, quick version of preg_match('/\(([[0-9A-Fa-f\:]+)\)/', $result)
$dnsrec = dns_get_record($this->sys->getHostname(), DNS_AAAA);
if (isset($dnsrec[0]['ipv6'])) { //is DNS IPv6 record
$this->sys->setIp($dnsrec[0]['ipv6']); //from DNS (avoid IPv6 NAT translation)
} else {
$this->sys->setIp(preg_replace('/^::ffff:/i', '', $result)); //from SERVER_ADDR or LOCAL_ADDR
}
} else {
$this->sys->setIp(gethostbyname($this->sys->getHostname())); //IPv4 only
}
} elseif (((PSI_OS != 'WINNT') && !defined('PSI_EMU_HOSTNAME')) && (CommonFunctions::readenv('SERVER_ADDR', $result) || CommonFunctions::readenv('LOCAL_ADDR', $result))) {
$this->sys->setIp(preg_replace('/^::ffff:/i', '', $result));
} else {
//$this->sys->setIp(gethostbyname($this->sys->getHostname()));
$hn = $this->sys->getHostname();
$ghbn = gethostbyname($hn);
if (defined('PSI_EMU_HOSTNAME') && ($hn === $ghbn)) {
$this->sys->setIp(PSI_EMU_HOSTNAME);
} else {
$this->sys->setIp($ghbn);
}
}
}
/**
* MEM information from dmidecode
*
* @return void
*/
protected function _dmimeminfo()
{
$dmimd = CommonFunctions::readdmimemdata();
if (!empty($dmimd)) {
foreach ($dmimd as $mem) {
if (isset($mem['Size']) && preg_match('/^(\d+)\s(M|G)B$/', $mem['Size'], $size) && ($size[1] > 0)) {
$dev = new HWDevice();
$name = '';
if (isset($mem['Part Number']) && !preg_match("/^PartNum\d+$/", $part = $mem['Part Number']) && ($part != 'None') && ($part != 'N/A') && ($part != 'Not Specified') && ($part != 'NOT AVAILABLE')) {
$name = $part;
}
if (isset($mem['Locator']) && (($dloc = $mem['Locator']) != 'None') && ($dloc != 'N/A') && ($dloc != 'Not Specified')) {
if ($name != '') {
$name .= ' - '.$dloc;
} else {
$name = $dloc;
}
}
if (isset($mem['Bank Locator']) && (($bank = $mem['Bank Locator']) != 'None') && ($bank != 'N/A') && ($bank != 'Not Specified')) {
if ($name != '') {
$name .= ' in '.$bank;
} else {
$name = 'Physical Memory in '.$bank;
}
}
if ($name != '') {
$dev->setName(trim($name));
} else {
$dev->setName('Physical Memory');
}
if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS) {
if (isset($mem['Manufacturer']) && !preg_match("/^([A-F\d]{4}|[A-F\d]{12}|[A-F\d]{16})$/", $manufacturer = $mem['Manufacturer']) && !preg_match("/^Manufacturer\d+$/", $manufacturer) && !preg_match("/^Mfg \d+$/", $manufacturer) && !preg_match("/^JEDEC ID:/", $manufacturer) && ($manufacturer != 'None') && ($manufacturer != 'N/A') && ($manufacturer != 'Not Specified') && ($manufacturer != 'UNKNOWN')) {
$dev->setManufacturer($manufacturer);
}
if ($size[2] == 'G') {
$dev->setCapacity($size[1]*1024*1024*1024);
} else {
$dev->setCapacity($size[1]*1024*1024);
}
$memtype = '';
if (isset($mem['Type']) && (($type = $mem['Type']) != 'None') && ($type != 'N/A') && ($type != 'Not Specified') && ($type != 'Other') && ($type != 'Unknown') && ($type != '<OUT OF SPEC>')) {
if (isset($mem['Speed']) && preg_match('/^(\d+)\s(MHz|MT\/s)/', $mem['Speed'], $speed) && ($speed[1] > 0) && (preg_match('/^(DDR\d*)(.*)/', $type, $dr) || preg_match('/^(SDR)AM(.*)/', $type, $dr))) {
if (isset($mem['Minimum Voltage']) && isset($mem['Maximum Voltage']) &&
preg_match('/^([\d\.]+)\sV$/', $mem['Minimum Voltage'], $minv) && preg_match('/^([\d\.]+)\sV$/', $mem['Maximum Voltage'], $maxv) &&
($minv[1] > 0) && ($maxv[1] >0) && ($minv[1] < $maxv[1])) {
$lv = 'L';
} else {
$lv = '';
}
if (isset($dr[2])) {
$memtype = $dr[1].$lv.'-'.$speed[1].' '.$dr[2];
} else {
$memtype = $dr[1].$lv.'-'.$speed[1];
}
} else {
$memtype = $type;
}
}
if (isset($mem['Form Factor']) && (($form = $mem['Form Factor']) != 'None') && ($form != 'N/A') && ($form != 'Not Specified') && ($form != 'Other') && ($form != 'Unknown') && !preg_match('/ '.$form.'$/', $memtype)) {
$memtype .= ' '.$form;
}
if (isset($mem['Data Width']) && isset($mem['Total Width']) &&
preg_match('/^(\d+)\sbits$/', $mem['Data Width'], $dataw) && preg_match('/^(\d+)\sbits$/', $mem['Total Width'], $totalw) &&
($dataw[1] > 0) && ($totalw[1] >0) && ($dataw[1] < $totalw[1])) {
$memtype .= ' ECC';
}
if (isset($mem['Type Detail']) && preg_match('/Registered/', $mem['Type Detail'])) {
$memtype .= ' REG';
}
if (($memtype = trim($memtype)) != '') {
$dev->setProduct($memtype);
}
if (isset($mem['Configured Clock Speed']) && preg_match('/^(\d+)\s(MHz|MT\/s)$/', $mem['Configured Clock Speed'], $clock) && ($clock[1] > 0)) {
$dev->setSpeed($clock[1]);
}
if (isset($mem['Configured Voltage']) && preg_match('/^([\d\.]+)\sV$/', $mem['Configured Voltage'], $voltage) && ($voltage[1] > 0)) {
$dev->setVoltage($voltage[1]);
}
if (defined('PSI_SHOW_DEVICES_SERIAL') && PSI_SHOW_DEVICES_SERIAL &&
isset($mem['Serial Number']) && !preg_match("/^SerNum\d+$/", $serial = $mem['Serial Number']) && ($serial != 'None') && ($serial != 'Not Specified')) {
$dev->setSerial($serial);
}
}
$this->sys->setMemDevices($dev);
}
}
}
}
/**
* get the filled or unfilled (with default values) System object
*
@@ -79,6 +263,12 @@ abstract class OS implements PSI_Interface_OS
final public function getSys()
{
$this->build();
if (!$this->blockname || $this->blockname==='vitals') {
$this->_ip();
}
if ((!$this->blockname || $this->blockname==='hardware') && (PSI_OS != 'WINNT') && !defined('PSI_EMU_HOSTNAME')) {
$this->_dmimeminfo();
}
return $this->sys;
}

View File

@@ -8,7 +8,7 @@
* @package PSI OpenBSD OS class
* @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 SVN: $Id: class.OpenBSD.inc.php 621 2012-07-29 18:49:04Z namiltd $
* @link http://phpsysinfo.sourceforge.net
*/
@@ -20,7 +20,7 @@
* @package PSI OpenBSD OS class
* @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
*/
@@ -29,29 +29,17 @@ class OpenBSD extends BSDCommon
/**
* define the regexp for log parser
*/
public function __construct()
public function __construct($blockname = false)
{
parent::__construct();
$this->setCPURegExp1("^cpu(.*) (.*) MHz");
parent::__construct($blockname);
// $this->setCPURegExp1("/^cpu(.*) (.*) MHz/");
$this->setCPURegExp2("/(.*),(.*),(.*),(.*),(.*)/");
$this->setSCSIRegExp1("^(.*) at scsibus.*: <(.*)> .*");
$this->setSCSIRegExp2("^(da[0-9]): (.*)MB ");
$this->setPCIRegExp1("/(.*) at pci[0-9] .* \"(.*)\"/");
$this->setSCSIRegExp1("/^(.*) at scsibus.*: <(.*)> .*/");
$this->setSCSIRegExp2("/^(sd[0-9]+): (.*)MB,/");
$this->setPCIRegExp1("/(.*) at pci[0-9]+ .* \"(.*)\"/");
$this->setPCIRegExp2("/\"(.*)\" (.*).* at [.0-9]+ irq/");
}
/**
* UpTime
* time the system is running
*
* @return void
*/
private function _uptime()
{
$a = $this->grabkey('kern.boottime');
$this->sys->setUptime(time() - $a);
}
/**
* get network information
*
@@ -66,13 +54,43 @@ class OpenBSD extends BSDCommon
for ($i = 0, $max = sizeof($lines_b); $i < $max; $i++) {
$ar_buf_b = preg_split("/\s+/", $lines_b[$i]);
$ar_buf_n = preg_split("/\s+/", $lines_n[$i]);
if (! empty($ar_buf_b[0]) && ! empty($ar_buf_n[3])) {
if (!empty($ar_buf_b[0]) && (!empty($ar_buf_n[3]) || ($ar_buf_n[3] === "0"))) {
$dev = new NetDevice();
$dev->setName($ar_buf_b[0]);
$dev->setTxBytes($ar_buf_b[4]);
$dev->setRxBytes($ar_buf_b[3]);
$dev->setErrors($ar_buf_n[4] + $ar_buf_n[6]);
$dev->setDrops($ar_buf_n[8]);
if (sizeof($ar_buf_n) == 9) {
$dev->setErrors($ar_buf_n[4] + $ar_buf_n[6]);
$dev->setDrops($ar_buf_n[8]);
} elseif (sizeof($ar_buf_n) == 8) {
$dev->setDrops($ar_buf_n[4] + $ar_buf_n[6]);
}
if (defined('PSI_SHOW_NETWORK_INFOS') && (PSI_SHOW_NETWORK_INFOS) && (CommonFunctions::executeProgram('ifconfig', $ar_buf_b[0].' 2>/dev/null', $bufr2, PSI_DEBUG))) {
$speedinfo = "";
$bufe2 = preg_split("/\n/", $bufr2, -1, PREG_SPLIT_NO_EMPTY);
foreach ($bufe2 as $buf2) {
if (preg_match('/^\s+lladdr\s+(\S+)/i', $buf2, $ar_buf2)) {
if (!defined('PSI_HIDE_NETWORK_MACADDR') || !PSI_HIDE_NETWORK_MACADDR) $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').preg_replace('/:/', '-', strtoupper($ar_buf2[1])));
} elseif (preg_match('/^\s+inet\s+(\S+)\s+netmask/i', $buf2, $ar_buf2)) {
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$ar_buf2[1]);
} elseif ((preg_match('/^\s+inet6\s+([^\s%]+)\s+prefixlen/i', $buf2, $ar_buf2)
|| preg_match('/^\s+inet6\s+([^\s%]+)%\S+\s+prefixlen/i', $buf2, $ar_buf2))
&& ($ar_buf2[1]!="::") && !preg_match('/^fe80::/i', $ar_buf2[1])) {
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').strtolower($ar_buf2[1]));
} elseif (preg_match('/^\s+media:\s+/i', $buf2) && preg_match('/[\(\s](\d+)(G*)base/i', $buf2, $ar_buf2)) {
if (isset($ar_buf2[2]) && strtoupper($ar_buf2[2])=="G") {
$unit = "G";
} else {
$unit = "M";
}
if (preg_match('/\s(\S+)-duplex/i', $buf2, $ar_buf3))
$speedinfo = $ar_buf2[1].$unit.'b/s '.strtolower($ar_buf3[1]);
else
$speedinfo = $ar_buf2[1].$unit.'b/s';
}
}
if ($speedinfo != "") $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$speedinfo);
}
$this->sys->setNetDevices($dev);
}
}
@@ -86,13 +104,16 @@ class OpenBSD extends BSDCommon
protected function ide()
{
foreach ($this->readdmesg() as $line) {
if (preg_match('/^(.*) at pciide[0-9] (.*): <(.*)>/', $line, $ar_buf)) {
if (preg_match('/^(.*) at pciide[0-9]+ (.*): <(.*)>/', $line, $ar_buf)) {
$dev = new HWDevice();
$dev->setName($ar_buf[0]);
// now loop again and find the capacity
foreach ($this->readdmesg() as $line2) {
if (preg_match("/^(".$ar_buf[0]."): (.*), (.*), (.*)MB, .*$/", $line2, $ar_buf_n)) {
$dev->setCapacity($ar_buf_n[4] * 2048 * 1.049);
$dev->setName($ar_buf[3]);
if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS) {
// now loop again and find the capacity
foreach ($this->readdmesg() as $line2) {
if (preg_match("/^(".$ar_buf[1]."): (.*), (.*), (.*)MB, .*$/", $line2, $ar_buf_n)) {
$dev->setCapacity($ar_buf_n[4] * 1024 * 1024);
break;
}
}
}
$this->sys->setIdeDevices($dev);
@@ -107,13 +128,81 @@ class OpenBSD extends BSDCommon
*/
protected function cpuinfo()
{
$dev = new CpuDevice();
$dev->setModel($this->grabkey('hw.model'));
$dev->setCpuSpeed($this->grabkey('hw.cpuspeed'));
$was = false;
$cpuarray = array();
foreach ($this->readdmesg() as $line) {
if (preg_match("/^cpu([0-9])+: (.*)/", $line, $ar_buf)) {
$was = true;
$ar_buf[2] = trim($ar_buf[2]);
if (preg_match("/^(.+), ([\d\.]+) MHz/", $ar_buf[2], $ar_buf2)) {
if (($model = trim($ar_buf2[1])) !== "") {
$cpuarray[$ar_buf[1]]['model'] = $model;
}
if (($speed = trim($ar_buf2[2])) > 0) {
$cpuarray[$ar_buf[1]]['speed'] = $speed;
}
} elseif (preg_match("/(\d+)([KM])B \S+ \S+ L[23] cache$/", $ar_buf[2], $ar_buf2)) {
if ($ar_buf2[2]=="M") {
$cpuarray[$ar_buf[1]]['cache'] = $ar_buf2[1]*1024*1024;
} elseif ($ar_buf2[2]=="K") {
$cpuarray[$ar_buf[1]]['cache'] = $ar_buf2[1]*1024;
}
} else {
$feats = preg_split("/,/", strtolower($ar_buf[2]), -1, PREG_SPLIT_NO_EMPTY);
foreach ($feats as $feat) {
if (($feat=="vmx") || ($feat=="svm")) {
$cpuarray[$ar_buf[1]]['virt'] = $feat;
} elseif ($feat=="hv") {
if (!isset($cpuarray[$ar_buf[1]]['virt'])) {
$cpuarray[$ar_buf[1]]['virt'] = 'hypervisor';
}
if (defined('PSI_SHOW_VIRTUALIZER_INFO') && PSI_SHOW_VIRTUALIZER_INFO) {
$this->sys->setVirtualizer("hypervisor", false);
}
}
}
}
} elseif (!preg_match("/^cpu[0-9]+|^mtrr: |^acpitimer[0-9]+: /", $line) && $was) {
break;
}
}
$ncpu = $this->grabkey('hw.ncpu');
if (is_null($ncpu) || (trim($ncpu) == "") || (!($ncpu >= 1)))
if (($ncpu === "") || !($ncpu >= 1)) {
$ncpu = 1;
for ($ncpu ; $ncpu > 0 ; $ncpu--) {
}
$ncpu = max($ncpu, count($cpuarray));
$model = $this->grabkey('hw.model');
$speed = $this->grabkey('hw.cpuspeed');
$vendor = $this->grabkey('machdep.cpuvendor');
for ($cpu = 0 ; $cpu < $ncpu ; $cpu++) {
$dev = new CpuDevice();
if (isset($cpuarray[$cpu]['model'])) {
$dev->setModel($cpuarray[$cpu]['model']);
} elseif ($model !== "") {
$dev->setModel($model);
}
if (isset($cpuarray[$cpu]['speed'])) {
$dev->setCpuSpeed($cpuarray[$cpu]['speed']);
} elseif ($speed !== "") {
$dev->setCpuSpeed($speed);
}
if (isset($cpuarray[$cpu]['cache'])) {
$dev->setCache($cpuarray[$cpu]['cache']);
}
if (isset($cpuarray[$cpu]['virt'])) {
$dev->setVirt($cpuarray[$cpu]['virt']);
}
if ($vendor !== "") {
$dev->setVendorId($vendor);
}
if (($ncpu == 1) && PSI_LOAD_BAR) {
$dev->setLoad($this->cpuusage());
}
$this->sys->setCpus($dev);
}
}
@@ -161,14 +250,17 @@ class OpenBSD extends BSDCommon
*
* @see BSDCommon::build()
*
* @return Void
* @return void
*/
public function build()
{
parent::build();
$this->_distroicon();
$this->_network();
$this->_uptime();
$this->_processes();
if (!$this->blockname || $this->blockname==='vitals') {
$this->_distroicon();
$this->_processes();
}
if (!$this->blockname || $this->blockname==='network') {
$this->_network();
}
}
}

View File

@@ -8,7 +8,7 @@
* @package PSI QNX OS class
* @author Mieczyslaw Nalewaj <namiltd@users.sourceforge.net>
* @copyright 2012 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 SVN: $Id: class.QNX.inc.php 687 2012-09-06 20:54:49Z namiltd $
* @link http://phpsysinfo.sourceforge.net
*/
@@ -20,31 +20,16 @@
* @package PSI QNX OS class
* @author Mieczyslaw Nalewaj <namiltd@users.sourceforge.net>
* @copyright 2012 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
*/
class QNX extends OS
{
/**
* content of the syslog
*
* @var array
*/
private $_dmesg = array();
/**
* call parent constructor
*/
public function __construct()
{
parent::__construct();
}
/**
* get the cpu information
*
* @return array
* @return void
*/
protected function _cpuinfo()
{
@@ -103,23 +88,9 @@ class QNX extends OS
if (CommonFunctions::executeProgram('pidin', 'info', $buf)
&& preg_match('/^.* BootTime:(.*)/', $buf, $bstart)
&& CommonFunctions::executeProgram('date', '', $bstop)) {
/* default error handler */
if (function_exists('errorHandlerPsi')) {
restore_error_handler();
}
/* fatal errors only */
$old_err_rep = error_reporting();
error_reporting(E_ERROR);
date_default_timezone_set('UTC');
$uptime = strtotime($bstop)-strtotime($bstart[1]);
if ($uptime > 0) $this->sys->setUptime($uptime);
/* restore error level */
error_reporting($old_err_rep);
/* restore error handler */
if (function_exists('errorHandlerPsi')) {
set_error_handler('errorHandlerPsi');
}
}
}
@@ -128,7 +99,7 @@ class QNX extends OS
*
* @return void
*/
private function _users()
protected function _users()
{
$this->sys->setUsers(1);
}
@@ -140,8 +111,8 @@ class QNX extends OS
*/
private function _hostname()
{
if (PSI_USE_VHOST === true) {
$this->sys->setHostname(getenv('SERVER_NAME'));
if (PSI_USE_VHOST) {
if (CommonFunctions::readenv('SERVER_NAME', $hnm)) $this->sys->setHostname($hnm);
} else {
if (CommonFunctions::executeProgram('uname', '-n', $result, PSI_DEBUG)) {
$ip = gethostbyname($result);
@@ -152,24 +123,6 @@ class QNX extends OS
}
}
/**
* IP of the Virtual Host Name
*
* @return void
*/
private function _ip()
{
if (PSI_USE_VHOST === true) {
$this->sys->setIp(gethostbyname($this->sys->getHostname()));
} else {
if (!($result = getenv('SERVER_ADDR'))) {
$this->sys->setIp(gethostbyname($this->sys->getHostname()));
} else {
$this->sys->setIp($result);
}
}
}
/**
* Physical memory information and Swap Space information
*
@@ -207,20 +160,21 @@ class QNX extends OS
{
if (CommonFunctions::executeProgram('ifconfig', '', $bufr, PSI_DEBUG)) {
$lines = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
$notwas = true;
$was = false;
$dev = null;
foreach ($lines as $line) {
if (preg_match("/^([^\s:]+)/", $line, $ar_buf)) {
if (!$notwas) {
if ($was) {
$this->sys->setNetDevices($dev);
}
$dev = new NetDevice();
$dev->setName($ar_buf[1]);
$notwas = false;
$was = true;
} else {
if (!$notwas) {
if ($was) {
if (defined('PSI_SHOW_NETWORK_INFOS') && (PSI_SHOW_NETWORK_INFOS)) {
if (preg_match('/^\s+address:\s*(\S+)/i', $line, $ar_buf2)) {
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$ar_buf2[1]);
if (!defined('PSI_HIDE_NETWORK_MACADDR') || !PSI_HIDE_NETWORK_MACADDR) $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').preg_replace('/:/', '-', strtoupper($ar_buf2[1])));
} elseif (preg_match('/^\s+inet\s+(\S+)\s+netmask/i', $line, $ar_buf2))
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$ar_buf2[1]);
@@ -228,7 +182,7 @@ class QNX extends OS
}
}
}
if (!$notwas) {
if ($was) {
$this->sys->setNetDevices($dev);
}
}
@@ -237,20 +191,29 @@ class QNX extends OS
/**
* get the information
*
* @return Void
* @return void
*/
public function build()
{
$this->error->addError("WARN", "The QNX version of phpSysInfo is a work in progress, some things currently don't work");
$this->_distro();
$this->_hostname();
$this->_ip();
$this->_kernel();
$this->_uptime();
$this->_users();
$this->_cpuinfo();
$this->_memory();
$this->_filesystems();
$this->_network();
$this->error->addWarning("The QNX version of phpSysInfo is a work in progress, some things currently don't work");
if (!$this->blockname || $this->blockname==='vitals') {
$this->_distro();
$this->_hostname();
$this->_kernel();
$this->_uptime();
$this->_users();
}
if (!$this->blockname || $this->blockname==='hardware') {
$this->_cpuinfo();
}
if (!$this->blockname || $this->blockname==='memory') {
$this->_memory();
}
if (!$this->blockname || $this->blockname==='filesystem') {
$this->_filesystems();
}
if (!$this->blockname || $this->blockname==='network') {
$this->_network();
}
}
}

View File

@@ -0,0 +1,857 @@
<?php
/**
* SSH Class
*
* PHP version 5
*
* @category PHP
* @package PSI SSH class
* @author Mieczyslaw Nalewaj <namiltd@users.sourceforge.net>
* @copyright 2012 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License version 2, or (at your option) any later version
* @version SVN: $Id: class.SSH.inc.php 687 2012-09-06 20:54:49Z namiltd $
* @link http://phpsysinfo.sourceforge.net
*/
/**
* SSH sysinfo class
* get all the required information from SSH
*
* @category PHP
* @package PSI SSH class
* @author Mieczyslaw Nalewaj <namiltd@users.sourceforge.net>
* @copyright 2022 phpSysInfo
* @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
*/
class SSH extends GNU
{
/**
* content of the system status
*
* @var string
*/
private $_sysstatus = null;
/**
* content of the system performance status
*
* @var string
*/
private $_sysperformance = null;
/**
* content of the sys ver systeminfo
*
* @var string
*/
private $_sysversysteminfo = null;
/**
* content of the show status
*
* @var string
*/
private $_showstatus = null;
/**
* OS type
*
* @var string
*/
private $_ostype = null;
/**
* check system type
*/
public function __construct($blockname = false)
{
parent::__construct($blockname);
$this->_ostype = $this->sys->getOS();
switch ($this->_ostype) {
case '4.2BSD':
case 'AIX':
case 'Darwin':
case 'DragonFly':
case 'FreeBSD':
case 'HI-UX/MPP':
case 'Haiku':
case 'Minix':
case 'NetBSD':
case 'OpenBSD':
case 'QNX':
case 'SunOS':
$this->error->addError("__construct()", "OS ".$this->_ostype. " is not supported via SSH");
break;
case 'GNU':
case 'Linux':
break;
case 'SSH':
$this->error->addError("__construct()", "SSH connection error");
break;
default:
if ($this->getSystemStatus() !== '') {
$this->_ostype = 'FortiOS';
$this->sys->setOS('Linux');
} elseif ($this->getSysVerSysteminfo() !== '') {
$this->_ostype = 'DrayOS';
$this->sys->setOS('DrayOS');
}
}
}
/**
* get os specific encoding
*
* @see PSI_Interface_OS::getEncoding()
*
* @return string
*/
public function getEncoding()
{
// if (($this->_ostype === 'FortiOS') || ($this->_ostype === 'DrayOS') || ($this->_ostype === 'SSH')) {
// return 'UTF-8';
// }
//return null;
}
/**
* get os specific language
*
* @see PSI_Interface_OS::getLanguage()
*
* @return string
*/
public function getLanguage()
{
//return null;
}
private function getSystemStatus()
{
if ($this->_sysstatus === null) {
if (CommonFunctions::executeProgram('get', 'system status', $resulte, false) && ($resulte !== "")
&& preg_match('/^(.*[\$#]\s*)/', $resulte, $resulto, PREG_OFFSET_CAPTURE)) {
$this->_sysstatus = substr($resulte, strlen($resulto[1][0]));
} else {
$this->_sysstatus = '';
}
}
return $this->_sysstatus;
}
private function getSystemPerformance()
{
if ($this->_sysperformance === null) {
if (CommonFunctions::executeProgram('get', 'system performance status', $resulte, false) && ($resulte !== "")
&& preg_match('/^(.*[\$#]\s*)/', $resulte, $resulto, PREG_OFFSET_CAPTURE)) {
$this->_sysperformance = substr($resulte, strlen($resulto[1][0]));
} else {
$this->_sysperformance = '';
}
}
return $this->_sysperformance;
}
private function getSysVerSysteminfo()
{
if ($this->_sysversysteminfo === null) {
if (CommonFunctions::executeProgram('sys', 'ver systeminfo', $resulte, false, PSI_EXEC_TIMEOUT_INT, '>') && ($resulte !== "")
&& preg_match('/([\s\S]+> sys ver systeminfo)/', $resulte, $resulto, PREG_OFFSET_CAPTURE)) {
$this->_sysversysteminfo = substr($resulte, strlen($resulto[1][0]));
} else {
$this->_sysversysteminfo = '';
}
}
return $this->_sysversysteminfo;
}
private function getShowStatus()
{
if ($this->_showstatus === null) {
if (CommonFunctions::executeProgram('show', 'status', $resulte, false, PSI_EXEC_TIMEOUT_INT, '>') && ($resulte !== "")
&& preg_match('/([\s\S]+> show status)/', $resulte, $resulto, PREG_OFFSET_CAPTURE)) {
$this->_showstatus = substr($resulte, strlen($resulto[1][0]));
} else {
$this->_showstatus = '';
}
}
return $this->_showstatus;
}
/**
* Physical memory information and Swap Space information
*
* @return void
*/
protected function _memory($mbuf = null, $sbuf = null)
{
switch ($this->_ostype) {
case 'FortiOS':
if (CommonFunctions::executeProgram('get', 'hardware memory', $resulte, false) && ($resulte !== "")
&& preg_match('/^(.*[\$#]\s*)/', $resulte, $resulto, PREG_OFFSET_CAPTURE)) {
parent::_memory(substr($resulte, strlen($resulto[1][0])));
}
break;
case 'DrayOS':
if (($sysstat = $this->getSysVerSysteminfo()) !== '') {
$machine= '';
if (preg_match("/ Total memory usage : \d+ % \((\d+)K\/(\d+)K\)/", $sysstat, $buf)) {
$this->sys->setMemTotal($buf[2]*1024);
$this->sys->setMemUsed($buf[1]*1024);
$this->sys->setMemFree(($buf[2]-$buf[1])*1024);
}
}
break;
case 'GNU':
case 'Linux':
if (!CommonFunctions::executeProgram('cat', '/proc/meminfo', $mbuf, false) || ($mbuf === "")) {
$mbuf = null;
}
if (!CommonFunctions::executeProgram('cat', '/proc/swaps', $sbuf, false) || ($sbuf === "")) {
$sbuf = null;
}
if (($mbuf !== null) || ($sbuf !== null)) {
parent::_memory($mbuf, $sbuf);
}
}
}
/**
* USB devices
*
* @return void
*/
protected function _usb($bufu = null)
{
switch ($this->_ostype) {
case 'FortiOS':
$bufr = '';
if (CommonFunctions::executeProgram('fnsysctl', 'cat /proc/bus/usb/devices', $resulte, false) && ($resulte !== "")
&& preg_match('/^(.*[\$#]\s*)/', $resulte, $resulto, PREG_OFFSET_CAPTURE)) {
$resulti = substr($resulte, strlen($resulto[1][0]));
if (preg_match('/(\n.*[\$#])$/', $resulti, $resulto, PREG_OFFSET_CAPTURE)) {
$bufr = substr($resulti, 0, $resulto[1][1]);
if (count(preg_split('/\n/', $bufr, -1, PREG_SPLIT_NO_EMPTY)) >= 2) {
parent::_usb($bufr);
}
}
}
break;
case 'GNU':
case 'Linux':
parent::_usb();
}
}
/**
* Network devices
* includes also rx/tx bytes
*
* @return void
*/
protected function _network($bufr = null)
{
switch ($this->_ostype) {
case 'FortiOS':
$bufr = '';
if (CommonFunctions::executeProgram('fnsysctl', 'ifconfig', $resulte, false) && ($resulte !== "")
&& preg_match('/^(.*[\$#]\s*)/', $resulte, $resulto, PREG_OFFSET_CAPTURE)) {
$resulti = substr($resulte, strlen($resulto[1][0]));
if (preg_match('/(\n.*[\$#])$/', $resulti, $resulto, PREG_OFFSET_CAPTURE)) {
$bufr = substr($resulti, 0, $resulto[1][1]);
if (count(preg_split('/\n/', $bufr, -1, PREG_SPLIT_NO_EMPTY)) < 2) {
$bufr = '';
}
}
}
if ($bufr !== '') {
parent::_network($bufr);
} else {
$netdevs = array();
if (CommonFunctions::executeProgram('diagnose', 'ip address list', $resulte, false) && ($resulte !== "")
&& preg_match('/^(.*[\$#]\s*)/', $resulte, $resulto, PREG_OFFSET_CAPTURE)) {
$strBuf = substr($resulte, strlen($resulto[1][0]));
$lines = preg_split('/\n/', $strBuf, -1, PREG_SPLIT_NO_EMPTY);
foreach ($lines as $line) if (preg_match('/^IP=(\S+)->.+ devname=(\S+)$/', $line, $buf)) {
if (!isset($netdevs[$buf[2]])) {
$netdevs[$buf[2]] = $buf[1];
} else {
$netdevs[$buf[2]] .= ';'.$buf[1];
}
}
}
if (CommonFunctions::executeProgram('diagnose', 'ipv6 address list', $resulte, false) && ($resulte !== "")
&& preg_match('/^(.*[\$#]\s*)/', $resulte, $resulto, PREG_OFFSET_CAPTURE)) {
$strBuf = substr($resulte, strlen($resulto[1][0]));
$lines = preg_split('/\n/', $strBuf, -1, PREG_SPLIT_NO_EMPTY);
foreach ($lines as $line) if (preg_match('/ devname=(\S+) .+ addr=(\S+)/', $line, $buf)) {
if (!preg_match('/^fe80::/i', $buf[2])) {
if (!isset($netdevs[$buf[1]])) {
$netdevs[$buf[1]] = $buf[2];
} else {
$netdevs[$buf[1]] .= ';'.$buf[2];
}
}
}
}
foreach ($netdevs as $netname=>$netinfo) {
if (!preg_match('/^vsys_/i', $netname)) {
$dev = new NetDevice();
// if ($netname === 'root') {
// $dev->setName('lo');
// } else {
$dev->setName($netname);
// }
$this->sys->setNetDevices($dev);
$dev->setInfo($netinfo);
}
}
}
break;
case 'DrayOS':
$macarray = array();
if (defined('PSI_SHOW_NETWORK_INFOS') && (PSI_SHOW_NETWORK_INFOS) && (!defined('PSI_HIDE_NETWORK_MACADDR') || !PSI_HIDE_NETWORK_MACADDR)) {
if (CommonFunctions::executeProgram('sys', 'iface', $resulte, false, PSI_EXEC_TIMEOUT_INT, '>') && ($resulte !== "")
&& preg_match('/([\s\S]+> sys iface)/', $resulte, $resulto, PREG_OFFSET_CAPTURE)) {
$lines = preg_split("/\n/", substr($resulte, strlen($resulto[1][0])), -1, PREG_SPLIT_NO_EMPTY);
$ipaddr = 'LAN';
foreach ($lines as $line) {
if (preg_match("/^IP Address:\s+([\d\.]+)\s/", trim($line), $ar_buf)) {
if ($ipaddr === false) {
$ipaddr = $ar_buf[1];
}
} elseif (preg_match("/^MAC:\s+([\d\-A-F]+)/", trim($line), $ar_buf)) {
if ($ipaddr !== '0.0.0.0') {
$macarray[$ipaddr] = $ar_buf[1];
}
$ipaddr = false;
}
}
}
}
$lantxrate = false;
$lanrxrate = false;
if (defined('PSI_SHOW_NETWORK_ACTIVE_SPEED') && PSI_SHOW_NETWORK_ACTIVE_SPEED) {
if ((($bufr = $this->getShowStatus()) !== '') && preg_match('/IP Address:[\d\.]+[ ]+Tx Rate:(\d+)[ ]+Rx Rate:(\d+)/m', $bufr, $ar_buf)) {
$lantxrate = $ar_buf[1];
$lanrxrate = $ar_buf[2];
}
}
$notwaslan = true;
if (CommonFunctions::executeProgram('show', 'lan', $resulte, false, PSI_EXEC_TIMEOUT_INT, '>') && ($resulte !== "")
&& preg_match('/([\s\S]+> show lan)/', $resulte, $resulto, PREG_OFFSET_CAPTURE)) {
$lines = preg_split("/\n/", substr($resulte, strlen($resulto[1][0])), -1, PREG_SPLIT_NO_EMPTY);
foreach ($lines as $line) {
if (preg_match("/^\[V\](\S+)\s+([\d\.]+)\s/", trim($line), $ar_buf)) {
$dev = new NetDevice();
$dev->setName($ar_buf[1]);
if (defined('PSI_SHOW_NETWORK_INFOS') && (PSI_SHOW_NETWORK_INFOS)) {
$dev->setInfo($ar_buf[2]);
if (isset($macarray['LAN'])) {
$dev->setInfo($macarray['LAN'].';'.$ar_buf[2]);
} else {
$dev->setInfo($ar_buf[2]);
}
}
if ($lantxrate !== false) {
$dev->setTxRate($lantxrate);
}
if ($lanrxrate !== false) {
$dev->setRxRate($lanrxrate);
}
$this->sys->setNetDevices($dev);
if (preg_match('/^LAN/', $ar_buf[1])) {
$notwaslan = false;
}
}
}
}
if (($bufr = $this->getShowStatus()) !== '') {
$lines = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
$last = false;
$dev = null;
foreach ($lines as $line) {
if (preg_match("/^(.+) Status/", trim($line), $ar_buf)) {
if (($last !== false) && (($last !== 'LAN') || $notwaslan)) {
$this->sys->setNetDevices($dev);
}
$dev = new NetDevice();
$last = preg_replace('/\s+/', '', $ar_buf[1]);
$dev->setName($last);
} else {
if ($last !== false) {
if (preg_match('/ IP:([\d\.]+)[ ]+GW/', $line, $ar_buf) || preg_match('/IP Address:([\d\.]+)[ ]+Tx/', $line, $ar_buf)) {
if (defined('PSI_SHOW_NETWORK_INFOS') && (PSI_SHOW_NETWORK_INFOS)) {
if ($last === 'LAN') {
if (isset($macarray['LAN'])) {
$dev->setInfo($macarray['LAN'].';'.$ar_buf[1]);
}
if ($lantxrate !== false) {
$dev->setTxRate($lantxrate);
}
if ($lanrxrate !== false) {
$dev->setRxRate($lanrxrate);
}
} elseif (isset($macarray[$ar_buf[1]])) {
$dev->setInfo($macarray[$ar_buf[1]].';'.$ar_buf[1]);
} else {
$dev->setInfo($ar_buf[1]);
}
}
} elseif (preg_match('/TX Packets:\d+[ ]+TX Rate\(bps\):(\d+)[ ]+RX Packets:\d+[ ]+RX Rate\(bps\):(\d+)/', $line, $ar_buf)) {
if (defined('PSI_SHOW_NETWORK_ACTIVE_SPEED') && PSI_SHOW_NETWORK_ACTIVE_SPEED) {
$dev->setTxRate($ar_buf[1]);
$dev->setRxRate($ar_buf[2]);
}
}
}
}
}
if (($last !== false) && (($last !== 'LAN') || $notwaslan)) {
$this->sys->setNetDevices($dev);
}
}
break;
case 'GNU':
case 'Linux':
parent::_network();
}
}
/**
* CPU information
* All of the tags here are highly architecture dependant.
*
* @return void
*/
protected function _cpuinfo($bufr = null)
{
switch ($this->_ostype) {
case 'FortiOS':
if (CommonFunctions::executeProgram('get', 'hardware cpu', $resulte, false) && ($resulte !== "")
&& preg_match('/^(.*[\$#]\s*)/', $resulte, $resulto, PREG_OFFSET_CAPTURE)) {
parent::_cpuinfo(substr($resulte, strlen($resulto[1][0])));
}
break;
case 'DrayOS':
if (preg_match_all("/CPU(\d+) speed:[ ]*(\d+) MHz/m", $sysinfo = $this->getSysVerSysteminfo(), $bufarr)) {
foreach ($bufarr[1] as $index=>$nr) {
$dev = new CpuDevice();
$dev->setModel('CPU'.$nr);
$dev->setCpuSpeed($bufarr[2][$index]);
if (PSI_LOAD_BAR) {
$dev->setLoad($this->_parseProcStat('cpu'.$nr));
}
$this->sys->setCpus($dev);
}
// $this->_cpu_loads['cpu'] = $buf[1];
// if (preg_match("/CPU1 speed/", $sysinfo)) {
// $this->_cpu_loads['cpu0'] = $buf[1];
// }
}
break;
case 'GNU':
case 'Linux':
if (CommonFunctions::executeProgram('cat', '/proc/cpuinfo', $resulte, false) && ($resulte !== "")) {
parent::_cpuinfo($resulte);
}
}
}
/**
* Machine
*
* @return void
*/
protected function _machine()
{
switch ($this->_ostype) {
case 'FortiOS':
if (($sysstat = $this->getSystemStatus()) !== '') {
$machine= '';
if (preg_match("/^Version: (\S+) v/", $sysstat, $buf)) {
$machine = $buf[1];
}
if (preg_match("/\nSystem Part-Number: (\S+)\n/", $sysstat, $buf)) {
$machine .= ' '.$buf[1];
}
if (preg_match("/\nBIOS version: (\S+)\n/", $sysstat, $buf)) {
if (trim($machine) !== '') {
$machine .= ', BIOS '.$buf[1];
} else {
$machine = 'BIOS '.$buf[1];
}
}
$machine = trim($machine);
if ($machine !== '') {
$this->sys->setMachine($machine);
}
}
break;
case 'DrayOS':
if (($sysstat = $this->getSysVerSysteminfo()) !== '') {
$machine= '';
if (preg_match("/[\r\n]Router Model: (\S+) /", $sysstat, $buf)) {
$machine = $buf[1];
}
if (preg_match("/[\r\n]Revision: (.+)[\r\n]/", $sysstat, $buf)) {
$machine .= ' '.$buf[1];
}
$machine = trim($machine);
if ($machine !== '') {
$this->sys->setMachine($machine);
}
}
break;
case 'GNU':
case 'Linux':
parent::_machine();
}
}
/**
* Hostname
*
* @return void
*/
protected function _hostname()
{
switch ($this->_ostype) {
case 'FortiOS':
// $hostname = PSI_EMU_HOSTNAME;
if (preg_match("/\nHostname: ([^\n]+)\n/", $this->getSystemStatus(), $buf)) {
$this->sys->setHostname(trim($buf[1]));
// $hostname = trim($buf[1]);
}
// $ip = gethostbyname($hostname);
// if ($ip != $hostname) {
// $this->sys->setHostname(gethostbyaddr($ip));
// } else {
// $this->sys->setHostname($hostname);
// }
break;
case 'DrayOS':
if (preg_match("/[\r\n]Router Name: ([^\n\r]+)[\r\n]/", $this->getSysVerSysteminfo(), $buf)) {
$this->sys->setHostname(trim($buf[1]));
}
break;
case 'GNU':
case 'Linux':
parent::_hostname();
}
}
/**
* filesystem information
*
* @return void
*/
protected function _filesystems()
{
switch ($this->_ostype) {
case 'FortiOS':
if (CommonFunctions::executeProgram('fnsysctl', 'df -k', $resulte, false) && ($resulte !== "")
&& preg_match('/^(.*[\$#]\s*)/', $resulte, $resulto, PREG_OFFSET_CAPTURE)) {
$resulti = substr($resulte, $resulto[1][1]);
$df = preg_split("/\n/", $resulti, -1, PREG_SPLIT_NO_EMPTY);
foreach ($df as $df_line) {
$df_buf1 = preg_split("/(\%\s)/", $df_line, 3);
if (count($df_buf1) != 2) {
continue;
}
if (preg_match("/(.*)(\s+)(([0-9]+)(\s+)([0-9]+)(\s+)([\-0-9]+)(\s+)([0-9]+)$)/", $df_buf1[0], $df_buf2)) {
$df_buf = array($df_buf2[1], $df_buf2[4], $df_buf2[6], $df_buf2[8], $df_buf2[10], $df_buf1[1]);
if (count($df_buf) == 6) {
$df_buf[5] = trim($df_buf[5]);
$dev = new DiskDevice();
$dev->setName(trim($df_buf[0]));
if ($df_buf[2] < 0) {
$dev->setTotal($df_buf[3] * 1024);
$dev->setUsed($df_buf[3] * 1024);
} else {
$dev->setTotal($df_buf[1] * 1024);
$dev->setUsed($df_buf[2] * 1024);
if ($df_buf[3]>0) {
$dev->setFree($df_buf[3] * 1024);
}
}
if (PSI_SHOW_MOUNT_POINT) $dev->setMountPoint($df_buf[5]);
$dev->setFsType('unknown');
$this->sys->setDiskDevices($dev);
}
}
}
}
break;
case 'DrayOS':
if (CommonFunctions::executeProgram('nand', 'usage', $resulte, false, PSI_EXEC_TIMEOUT_INT, '>') && ($resulte !== "")
&& preg_match('/([\s\S]+> nand usage)/', $resulte, $resulto, PREG_OFFSET_CAPTURE)) {
$df = substr($resulte, strlen($resulto[1][0]));
if (preg_match('/Usecfg/', $df)) { // fix for Vigor2135ac v4.4.2
$df = preg_replace("/(cfg|bin)/", "\n$1", substr($resulte, strlen($resulto[1][0])));
$percent = '';
} else {
$percent = '%';
}
$df = preg_split("/\n/", $df, -1, PREG_SPLIT_NO_EMPTY);
foreach ($df as $df_line) {
if (preg_match("/^(\S+)[ ]+(\d+)[ ]+(\d+)[ ]+(\d+)[ ]+(\d+)".$percent."/", trim($df_line), $df_buf)) {
$dev = new DiskDevice();
$dev->setName($df_buf[1]);
$dev->setTotal($df_buf[2]);
$dev->setUsed($df_buf[3]);
$dev->setFree($df_buf[4]);
$dev->setFsType('NAND');
$this->sys->setDiskDevices($dev);
}
}
}
break;
case 'GNU':
case 'Linux':
parent::_filesystems();
}
}
/**
* Distribution
*
* @return void
*/
protected function _distro()
{
switch ($this->_ostype) {
case 'SSH':
$this->sys->setOS('Unknown');
$this->sys->setDistributionIcon('Unknown.png');
break;
case 'FortiOS':
if (preg_match("/^Version: \S+ (v[^\n]+)\n/", $this->getSystemStatus(), $buf)) {
$this->sys->setDistribution('FortiOS '.trim($buf[1]));
}
$this->sys->setDistributionIcon('FortiOS.png');
break;
case 'DrayOS':
if (preg_match("/ Version: ([^\n]+)\n/", $this->getSysVerSysteminfo(), $buf)) {
$this->sys->setDistribution('DrayOS '.trim($buf[1]));
}
$this->sys->setDistributionIcon('DrayOS.png');
break;
case 'GNU':
case 'Linux':
parent::_distro();
}
// if ($this->_ostype !== null) {
// $this->sys->setDistributionIcon($this->_ostype);
// }
}
/**
* fill the load for a individual cpu, through parsing /proc/stat for the specified cpu
*
* @param String $cpuline cpu for which load should be meassured
*
* @return int
*/
protected function _parseProcStat($cpuline)
{
if ($this->_cpu_loads === null) {
$this->_cpu_loads = array();
switch ($this->_ostype) {
case 'FortiOS':
if (($strBuf = $this->getSystemPerformance()) !== '') {
$lines = preg_split('/\n/', $strBuf, -1, PREG_SPLIT_NO_EMPTY);
foreach ($lines as $line) if (preg_match('/^CPU(\d*) states: \d+% user \d+% system \d+% nice (\d+)% idle /', $line, $buf)) {
$this->_cpu_loads['cpu'.$buf[1]] = 100-$buf[2];
}
}
break;
case 'DrayOS':
if (preg_match("/CPU usage :[ ]*(\d+) %/", $sysinfo = $this->getSysVerSysteminfo(), $buf)) {
$this->_cpu_loads['cpu'] = $buf[1];
if (preg_match("/CPU1 speed/", $sysinfo) && !preg_match("/CPU2 speed/", $sysinfo)) { //only one cpu
$this->_cpu_loads['cpu1'] = $buf[1];
}
}
}
}
if (isset($this->_cpu_loads[$cpuline])) {
return $this->_cpu_loads[$cpuline];
} else {
return null;
}
}
/**
* Processor Load
* optionally create a loadbar
*
* @return void
*/
protected function _loadavg($bufr = null)
{
switch ($this->_ostype) {
case 'FortiOS':
if (CommonFunctions::executeProgram('fnsysctl', 'cat /proc/loadavg', $resulte, false) && ($resulte !== "")
&& preg_match('/^(.*[\$#]\s*)/', $resulte, $resulto, PREG_OFFSET_CAPTURE)) {
parent::_loadavg(substr($resulte, strlen($resulto[1][0])));
}
break;
case 'DrayOS':
if (PSI_LOAD_BAR) {
$this->sys->setLoadPercent($this->_parseProcStat('cpu'));
}
break;
case 'GNU':
case 'Linux':
parent::_loadavg();
}
}
/**
* UpTime
* time the system is running
*
* @return void
*/
protected function _uptime($bufu = null)
{
switch ($this->_ostype) {
case 'FortiOS':
if (preg_match("/\nUptime: ([^\n]+)\n/", $this->getSystemPerformance(), $buf)) {
parent::_uptime('up '.trim($buf[1]));
}
break;
case 'DrayOS':
if (preg_match("/System Uptime:([\d:]+)/", $this->getShowStatus(), $buf)) {
parent::_uptime('up '.trim($buf[1]));
}
break;
case 'GNU':
case 'Linux':
if (CommonFunctions::executeProgram('cat', '/proc/uptime', $resulte, false) && ($resulte !== "")) {
$ar_buf = preg_split('/ /', $resulte);
$this->sys->setUptime(trim($ar_buf[0]));
} else {
parent::_uptime();
}
}
}
/**
* Kernel Version
*
* @return void
*/
protected function _kernel()
{
switch ($this->_ostype) {
case 'FortiOS':
if (CommonFunctions::executeProgram('fnsysctl', 'cat /proc/version', $resulte, false) && ($resulte !== "")
&& preg_match('/^(.*[\$#]\s*)/', $resulte, $resulto, PREG_OFFSET_CAPTURE)) {
$strBuf = substr($resulte, $resulto[1][1]);
if (preg_match('/version\s+(\S+)/', $strBuf, $ar_buf)) {
$verBuf = $ar_buf[1];
if (preg_match('/ SMP /', $strBuf)) {
$verBuf .= ' (SMP)';
}
$this->sys->setKernel($verBuf);
}
}
break;
case 'GNU':
case 'Linux':
parent::_kernel();
}
}
/**
* get the information
*
* @return void
*/
public function build()
{
$this->error->addWarning("The SSH version of phpSysInfo is a work in progress, some things currently don't work");
switch ($this->_ostype) {
case 'SSH':
$this->_distro();
break;
case 'FortiOS':
if (!$this->blockname || $this->blockname==='vitals') {
$this->_distro();
$this->_hostname();
$this->_kernel();
$this->_uptime();
// $this->_users();
$this->_loadavg();
// $this->_processes();
}
if (!$this->blockname || $this->blockname==='hardware') {
$this->_machine();
$this->_cpuinfo();
//$this->_virtualizer();
// $this->_pci();
$this->_usb();
// $this->_i2c();
}
if (!$this->blockname || $this->blockname==='memory') {
$this->_memory();
}
if (!$this->blockname || $this->blockname==='filesystem') {
$this->_filesystems();
}
if (!$this->blockname || $this->blockname==='network') {
$this->_network();
}
break;
case 'DrayOS':
if (!$this->blockname || $this->blockname==='vitals') {
$this->_distro();
$this->_hostname();
// $this->_kernel();
$this->_uptime();
//// $this->_users();
$this->_loadavg();
//// $this->_processes();
}
if (!$this->blockname || $this->blockname==='hardware') {
$this->_machine();
$this->_cpuinfo();
// //$this->_virtualizer();
//// $this->_pci();
// $this->_usb();
//// $this->_i2c();
}
if (!$this->blockname || $this->blockname==='memory') {
$this->_memory();
}
if (!$this->blockname || $this->blockname==='filesystem') {
$this->_filesystems();
}
if (!$this->blockname || $this->blockname==='network') {
$this->_network();
}
break;
case 'GNU':
case 'Linux':
parent::build();
}
}
}

View File

@@ -8,7 +8,7 @@
* @package PSI SunOS OS class
* @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 SVN: $Id: class.SunOS.inc.php 687 2012-09-06 20:54:49Z namiltd $
* @link http://phpsysinfo.sourceforge.net
*/
@@ -20,12 +20,89 @@
* @package PSI SunOS OS class
* @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
*/
class SunOS extends OS
{
/**
* content of prtconf -v
*
* @var array
*/
private $_prtconf = null;
/**
* Execute prtconf -v and save ass array
*
* @return array
*/
protected function prtconf()
{
if ($this->_prtconf === null) {
$this->_prtconf = array();
if (CommonFunctions::executeProgram('prtconf', '-v', $buf, PSI_DEBUG) && ($buf!="")) {
$blocks = preg_split('/\n(?= \S)/', $buf, -1, PREG_SPLIT_NO_EMPTY);
if (!empty($blocks) && (count($blocks)>2)) {
array_shift($blocks);
foreach ($blocks as $block) {
if (preg_match('/^ (\S+) /', $block, $ar_buf)) {
$group = trim($ar_buf[1], ',');
$grouparr = array();
$blocks1 = preg_split('/\n(?= \S)/', $block, -1, PREG_SPLIT_NO_EMPTY);
if (!empty($blocks1) && count($blocks1)) {
array_shift($blocks1);
foreach ($blocks1 as $block1) {
if (!preg_match('/^ name=\'([^\']+)\'/', $block1)
&& preg_match('/^ (\S+) /', $block1, $ar_buf)) {
$device = trim($ar_buf[1], ',');
$devicearr = array();
$blocks2 = preg_split('/\n(?= \S)/', $block1, -1, PREG_SPLIT_NO_EMPTY);
if (!empty($blocks2) && count($blocks2)) {
array_shift($blocks2);
foreach ($blocks2 as $block2) {
if (!preg_match('/^ name=\'([^\']+)\'/', $block2)
&& preg_match('/^ (\S+) /', $block2, $ar_buf)) {
$subdev = trim($ar_buf[1], ',');
$subdevarr = array();
$blocks3 = preg_split('/\n(?= \S)/', $block2, -1, PREG_SPLIT_NO_EMPTY);
if (!empty($blocks3) && count($blocks3)) {
array_shift($blocks3);
foreach ($blocks3 as $block3) {
if (preg_match('/^ name=\'([^\']+)\' [\s\S]+ value=\'?([^\']+)\'?/m', $block3, $ar_buf)) {
if ($subdev==='Hardware') {
$subdevarr[$ar_buf[1]] = $ar_buf[2];
$subdevarr['device'] = $device;
}
}
}
if (count($subdevarr)) {
$devicearr = $subdevarr;
}
}
}
}
}
if (count($devicearr)) {
$grouparr[$device][] = $devicearr;
}
}
}
}
if (count($grouparr)) {
$this->_prtconf[$group][] = $grouparr;
}
}
}
}
}
}
return $this->_prtconf;
}
/**
* Extract kernel values via kstat() interface
*
@@ -35,11 +112,10 @@ class SunOS extends OS
*/
private function _kstat($key)
{
if (CommonFunctions::executeProgram('kstat', '-p d '.$key, $m, PSI_DEBUG) &&
!is_null($m) && (trim($m)!=="")) {
list($key, $value) = preg_split("/\t/", trim($m), 2);
if (CommonFunctions::executeProgram('kstat', '-p d '.$key, $m, PSI_DEBUG) && ($m!=="")) {
list($key, $value) = preg_split("/\t/", $m, 2);
return $value;
return trim($value);
} else {
return '';
}
@@ -52,8 +128,8 @@ class SunOS extends OS
*/
private function _hostname()
{
if (PSI_USE_VHOST === true) {
$this->sys->setHostname(getenv('SERVER_NAME'));
if (PSI_USE_VHOST) {
if (CommonFunctions::readenv('SERVER_NAME', $hnm)) $this->sys->setHostname($hnm);
} else {
if (CommonFunctions::executeProgram('uname', '-n', $result, PSI_DEBUG)) {
$ip = gethostbyname($result);
@@ -64,24 +140,6 @@ class SunOS extends OS
}
}
/**
* IP of the Virtual Host Name
*
* @return void
*/
private function _ip()
{
if (PSI_USE_VHOST === true) {
$this->sys->setIp(gethostbyname($this->sys->getHostname()));
} else {
if (!($result = getenv('SERVER_ADDR'))) {
$this->sys->setIp(gethostbyname($this->sys->getHostname()));
} else {
$this->sys->setIp($result);
}
}
}
/**
* Kernel Version
*
@@ -89,12 +147,17 @@ class SunOS extends OS
*/
private function _kernel()
{
if (CommonFunctions::executeProgram('uname', '-s', $os, PSI_DEBUG)) {
if (CommonFunctions::executeProgram('uname', '-r', $version, PSI_DEBUG)) {
$this->sys->setKernel($os.' '.$version);
} else {
$this->sys->setKernel($os);
if (CommonFunctions::executeProgram('uname', '-s', $kernel, PSI_DEBUG) && ($kernel != "")) {
if (CommonFunctions::executeProgram('uname', '-r', $version, PSI_DEBUG) && ($version != "")) {
$kernel.=' '.$version;
}
if (CommonFunctions::executeProgram('uname', '-v', $subversion, PSI_DEBUG) && ($subversion != "")) {
$kernel.=' ('.$subversion.')';
}
if (CommonFunctions::executeProgram('uname', '-i', $platform, PSI_DEBUG) && ($platform != "")) {
$kernel.=' '.$platform;
}
$this->sys->setKernel($kernel);
}
}
@@ -109,19 +172,6 @@ class SunOS extends OS
$this->sys->setUptime(time() - $this->_kstat('unix:0:system_misc:boot_time'));
}
/**
* Number of Users
*
* @return void
*/
private function _users()
{
if (CommonFunctions::executeProgram('who', '-q', $buf, PSI_DEBUG)) {
$who = preg_split('/=/', $buf);
$this->sys->setUsers($who[1]);
}
}
/**
* Processor Load
* optionally create a loadbar
@@ -143,13 +193,75 @@ class SunOS extends OS
*/
private function _cpuinfo()
{
$dev = new CpuDevice();
if (CommonFunctions::executeProgram('uname', '-i', $buf, PSI_DEBUG)) {
$dev->setModel(trim($buf));
if (CommonFunctions::executeProgram('kstat', '-p d cpu_info:*:cpu_info*:core_id', $m, PSI_DEBUG) && ($m!=="")) {
$cpuc = count(preg_split('/\n/', $m, -1, PREG_SPLIT_NO_EMPTY));
for ($cpu=0; $cpu < $cpuc; $cpu++) {
$dev = new CpuDevice();
if (($buf = $this->_kstat('cpu_info:'.$cpu.':cpu_info'.$cpu.':current_clock_Hz')) !== "") {
$dev->setCpuSpeed($buf/1000000);
} elseif (($buf = $this->_kstat('cpu_info:'.$cpu.':cpu_info'.$cpu.':clock_MHz')) !== "") {
$dev->setCpuSpeed($buf);
}
if (($buf = $this->_kstat('cpu_info:'.$cpu.':cpu_info'.$cpu.':supported_frequencies_Hz')) !== "") {
$cpuarr = preg_split('/:/', $buf, -1, PREG_SPLIT_NO_EMPTY);
if (($cpuarrc=count($cpuarr))>1) {
$dev->setCpuSpeedMin($cpuarr[0]/1000000);
$dev->setCpuSpeedMax($cpuarr[$cpuarrc-1]/1000000);
}
}
if (($buf =$this->_kstat('cpu_info:'.$cpu.':cpu_info'.$cpu.':brand')) !== "") {
$dev->setModel($buf);
} elseif (($buf =$this->_kstat('cpu_info:'.$cpu.':cpu_info'.$cpu.':cpu_type')) !== "") {
$dev->setModel($buf);
} elseif (CommonFunctions::executeProgram('uname', '-p', $buf, PSI_DEBUG) && ($buf!="")) {
$dev->setModel($buf);
} elseif (CommonFunctions::executeProgram('uname', '-i', $buf, PSI_DEBUG) && ($buf!="")) {
$dev->setModel($buf);
}
$this->sys->setCpus($dev);
}
}
}
/**
* PCI devices
*
* @return void
*/
protected function _pci()
{
$prtconf = $this->prtconf();
if ((count($prtconf)>1) && isset($prtconf['pci'])) {
foreach ($prtconf['pci'] as $prt) {
foreach ($prt as $pci) {
foreach ($pci as $pcidev) {
if (isset($pcidev['device'])) {
$dev = new HWDevice();
if (isset($pcidev['model'])) {
$name = $pcidev['model'];
} else {
$name = $pcidev['device'];
}
if (isset($pcidev['device-name'])) {
$name .= ': '.$pcidev['device-name'];
}
$dev->setName($name);
if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS) {
if (isset($pcidev['subsystem-name']) && ($pcidev['subsystem-name']!=='unknown subsystem')) {
$dev->setProduct($pcidev['subsystem-name']);
}
if (isset($pcidev['vendor-name'])) {
$dev->setManufacturer($pcidev['vendor-name']);
}
}
$this->sys->setPciDevices($dev);
}
}
}
}
}
$dev->setCpuSpeed($this->_kstat('cpu_info:0:cpu_info0:clock_MHz'));
$dev->setCache($this->_kstat('cpu_info:0:cpu_info0:cpu_type') * 1024);
$this->sys->setCpus($dev);
}
/**
@@ -189,23 +301,22 @@ class SunOS extends OS
}
}
if (defined('PSI_SHOW_NETWORK_INFOS') && (PSI_SHOW_NETWORK_INFOS)) {
if (CommonFunctions::executeProgram('ifconfig', $ar_buf[0], $bufr2, PSI_DEBUG)
&& !is_null($bufr2) && (trim($bufr2) !== "")) {
if (CommonFunctions::executeProgram('ifconfig', $ar_buf[0], $bufr2, PSI_DEBUG) && ($bufr2!=="")) {
$bufe2 = preg_split("/\n/", $bufr2, -1, PREG_SPLIT_NO_EMPTY);
foreach ($bufe2 as $buf2) {
if (preg_match('/^\s+ether\s+(\S+)/i', $buf2, $ar_buf2))
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').preg_replace('/:/', '-', $ar_buf2[1]));
elseif (preg_match('/^\s+inet\s+(\S+)\s+netmask/i', $buf2, $ar_buf2))
if (preg_match('/^\s+ether\s+(\S+)/i', $buf2, $ar_buf2)) {
if (!defined('PSI_HIDE_NETWORK_MACADDR') || !PSI_HIDE_NETWORK_MACADDR) $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').preg_replace('/:/', '-', strtoupper($ar_buf2[1])));
} elseif (preg_match('/^\s+inet\s+(\S+)\s+netmask/i', $buf2, $ar_buf2)) {
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$ar_buf2[1]);
}
}
}
if (CommonFunctions::executeProgram('ifconfig', $ar_buf[0].' inet6', $bufr2, PSI_DEBUG)
&& !is_null($bufr2) && (trim($bufr2) !== "")) {
if (CommonFunctions::executeProgram('ifconfig', $ar_buf[0].' inet6', $bufr2, PSI_DEBUG) && ($bufr2!=="")) {
$bufe2 = preg_split("/\n/", $bufr2, -1, PREG_SPLIT_NO_EMPTY);
foreach ($bufe2 as $buf2) {
if (preg_match('/^\s+inet6\s+([^\s\/]+)/i', $buf2, $ar_buf2)
&& !preg_match('/^fe80::/i', $ar_buf2[1]))
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$ar_buf2[1]);
&& ($ar_buf2[1]!="::") && !preg_match('/^fe80::/i', $ar_buf2[1]))
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').strtolower($ar_buf2[1]));
}
}
}
@@ -227,14 +338,16 @@ class SunOS extends OS
$this->sys->setMemTotal($this->_kstat('unix:0:system_pages:pagestotal') * $pagesize);
$this->sys->setMemUsed($this->_kstat('unix:0:system_pages:pageslocked') * $pagesize);
$this->sys->setMemFree($this->_kstat('unix:0:system_pages:pagesfree') * $pagesize);
$dev = new DiskDevice();
$dev->setName('SWAP');
$dev->setFsType('swap');
$dev->setMountPoint('SWAP');
$dev->setTotal($this->_kstat('unix:0:vminfo:swap_avail') / 1024);
$dev->setUsed($this->_kstat('unix:0:vminfo:swap_alloc') / 1024);
$dev->setFree($this->_kstat('unix:0:vminfo:swap_free') / 1024);
$this->sys->setSwapDevices($dev);
if (($swap=$this->_kstat('unix:0:vminfo:swap_avail')) > 0) {
$dev = new DiskDevice();
$dev->setName('SWAP');
$dev->setFsType('swap');
$dev->setMountPoint('SWAP');
$dev->setTotal($swap / 1024);
$dev->setUsed($this->_kstat('unix:0:vminfo:swap_alloc') / 1024);
$dev->setFree($this->_kstat('unix:0:vminfo:swap_free') / 1024);
$this->sys->setSwapDevices($dev);
}
}
/**
@@ -289,8 +402,21 @@ class SunOS extends OS
*/
private function _distro()
{
$this->sys->setDistribution('SunOS');
$this->sys->setDistributionIcon('SunOS.png');
if (CommonFunctions::rfts('/etc/release', $buf, 1, 4096, false) && (trim($buf)!="")) {
$this->sys->setDistribution(trim($buf));
$list = @parse_ini_file(PSI_APP_ROOT."/data/distros.ini", true);
if ($list && preg_match('/^(\S+)\s*/', preg_replace('/^open\s+/', 'open', preg_replace('/^oracle\s+/', 'oracle', strtolower(trim($buf)))), $id_buf) && isset($list[$distid=(trim($id_buf[1].' sunos'))]['Image'])) {
$this->sys->setDistributionIcon($list[$distid]['Image']);
if (isset($list[trim($distid)]['Name'])) {
$this->sys->setDistribution(trim($list[$distid]['Name']).' '.$this->sys->getDistribution());
}
} else {
$this->sys->setDistributionIcon('SunOS.png');
}
} else {
$this->sys->setDistribution('SunOS');
$this->sys->setDistributionIcon('SunOS.png');
}
}
/**
@@ -328,22 +454,32 @@ class SunOS extends OS
*
* @see PSI_Interface_OS::build()
*
* @return Void
* @return void
*/
public function build()
{
$this->error->addError("WARN", "The SunOS version of phpSysInfo is a work in progress, some things currently don't work");
$this->_distro();
$this->_hostname();
$this->_ip();
$this->_kernel();
$this->_uptime();
$this->_users();
$this->_loadavg();
$this->_cpuinfo();
$this->_network();
$this->_memory();
$this->_filesystems();
$this->_processes();
$this->error->addWarning("The SunOS version of phpSysInfo is a work in progress, some things currently don't work");
if (!$this->blockname || $this->blockname==='vitals') {
$this->_distro();
$this->_hostname();
$this->_kernel();
$this->_uptime();
$this->_users();
$this->_loadavg();
$this->_processes();
}
if (!$this->blockname || $this->blockname==='hardware') {
$this->_cpuinfo();
$this->_pci();
}
if (!$this->blockname || $this->blockname==='memory') {
$this->_memory();
}
if (!$this->blockname || $this->blockname==='filesystem') {
$this->_filesystems();
}
if (!$this->blockname || $this->blockname==='network') {
$this->_network();
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -8,7 +8,7 @@
* @package PSI_Output
* @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 SVN: $Id: class.Output.inc.php 569 2012-04-16 06:08:18Z namiltd $
* @link http://phpsysinfo.sourceforge.net
*/
@@ -19,7 +19,7 @@
* @package PSI_Output
* @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
*/
@@ -28,7 +28,7 @@ abstract class Output
/**
* error object for logging errors
*
* @var Error
* @var PSI_Error
*/
protected $error;
@@ -37,11 +37,9 @@ abstract class Output
*/
public function __construct()
{
$this->error = Error::singleton();
$this->error = PSI_Error::singleton();
$this->_checkConfig();
CommonFunctions::checkForExtensions();
// $this->error = Error::singleton();
// $this->_checkConfig();
}
/**
@@ -51,7 +49,7 @@ abstract class Output
*/
private function _checkConfig()
{
include_once APP_ROOT.'/read_config.php';
include_once PSI_APP_ROOT.'/read_config.php';
if ($this->error->errorsExist()) {
$this->error->errorsAsXML();

View File

@@ -8,7 +8,7 @@
* @package PSI_Output
* @author Damien Roth <iysaak@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 SVN: $Id: class.Output.inc.php 315 2009-09-02 15:48:31Z bigmichi1 $
* @link http://phpsysinfo.sourceforge.net
*/
@@ -19,7 +19,7 @@
* @package PSI_Output
* @author Damien Roth <iysaak@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
*/
@@ -28,14 +28,14 @@ class Template
/**
* Vars used in the template
*
* @Array
* @var array
*/
private $_vars;
/**
* Template file
*
* @String
* @var string
*/
private $_file;
@@ -53,8 +53,8 @@ class Template
/**
* Set a template variable.
*
* @param string variable name
* @param string variable value
* @param string $name variable name
* @param string|array|Template $value variable value
*/
public function set($name, $value)
{
@@ -80,7 +80,7 @@ class Template
// Start output buffering
ob_start();
include(APP_ROOT.$file);
include(PSI_APP_ROOT.$file);
// Get the contents of the buffer
$contents = ob_get_contents();

View File

@@ -8,7 +8,7 @@
* @package PSI_Web
* @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 SVN: $Id: class.Webpage.inc.php 661 2012-08-27 11:26:39Z namiltd $
* @link http://phpsysinfo.sourceforge.net
*/
@@ -19,45 +19,82 @@
* @package PSI_Web
* @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
*/
class Webpage extends Output implements PSI_Interface_Output
{
/**
* configured indexname
*
* @var string
*/
private $_indexname;
/**
* configured language
*
* @var String
* @var string
*/
private $_language;
/**
* configured template
*
* @var String
* @var string
*/
private $_template;
/**
* all available templates
*
* @var Array
* @var array
*/
private $_templates = array();
/**
* configured bootstrap template
*
* @var string
*/
private $_bootstrap_template;
/**
* all available bootstrap templates
*
* @var array
*/
private $_bootstrap_templates = array();
/**
* all available languages
*
* @var Array
* @var array
*/
private $_languages = array();
/**
* check for all extensions that are needed, initialize needed vars and read phpsysinfo.ini
* configured show picklist language
*
* @var boolean
*/
public function __construct()
private $_pick_language;
/**
* configured show picklist template
*
* @var boolean
*/
private $_pick_template;
/**
* check for all extensions that are needed, initialize needed vars and read phpsysinfo.ini
* @param string $indexname
*/
public function __construct($indexname="dynamic")
{
$this->_indexname = $indexname;
parent::__construct();
$this->_getTemplateList();
$this->_getLanguageList();
@@ -71,15 +108,18 @@ class Webpage extends Output implements PSI_Interface_Output
*/
private function _checkTemplateLanguage()
{
$this->_template = trim(strtolower(PSI_DEFAULT_TEMPLATE));
if (!file_exists(APP_ROOT.'/templates/'.$this->_template.".css")) {
if (!defined("PSI_DEFAULT_TEMPLATE") || (($this->_template = strtolower(trim(PSI_DEFAULT_TEMPLATE))) == "") || !file_exists(PSI_APP_ROOT.'/templates/'.$this->_template.".css")) {
$this->_template = 'phpsysinfo';
}
if (!defined("PSI_DEFAULT_BOOTSTRAP_TEMPLATE") || (($this->_bootstrap_template = strtolower(trim(PSI_DEFAULT_BOOTSTRAP_TEMPLATE))) == "") || !file_exists(PSI_APP_ROOT.'/templates/'.$this->_bootstrap_template."_bootstrap.css")) {
$this->_bootstrap_template = 'phpsysinfo';
}
$this->_pick_template = !defined("PSI_SHOW_PICKLIST_TEMPLATE") || (PSI_SHOW_PICKLIST_TEMPLATE !== false);
$this->_language = trim(strtolower(PSI_DEFAULT_LANG));
if (!file_exists(APP_ROOT.'/language/'.$this->_language.".xml")) {
if (!defined("PSI_DEFAULT_LANG") || (($this->_language = strtolower(trim(PSI_DEFAULT_LANG))) == "") || !file_exists(PSI_APP_ROOT.'/language/'.$this->_language.".xml")) {
$this->_language = 'en';
}
$this->_pick_language = !defined("PSI_SHOW_PICKLIST_LANG") || (PSI_SHOW_PICKLIST_LANG !== false);
}
/**
@@ -89,13 +129,17 @@ class Webpage extends Output implements PSI_Interface_Output
*/
private function _getTemplateList()
{
$dirlist = CommonFunctions::gdc(APP_ROOT.'/templates/');
$dirlist = CommonFunctions::gdc(PSI_APP_ROOT.'/templates/');
sort($dirlist);
foreach ($dirlist as $file) {
$tpl_ext = substr($file, strlen($file) - 4);
$tpl_name = substr($file, 0, strlen($file) - 4);
if (($tpl_ext === ".css") && ($tpl_name !== "phpsysinfo_bootstrap")) {
array_push($this->_templates, $tpl_name);
if ($tpl_ext === ".css") {
if (preg_match("/(\S+)_bootstrap$/", $tpl_name, $ar_buf)) {
array_push($this->_bootstrap_templates, $ar_buf[1]);
} else {
array_push($this->_templates, $tpl_name);
}
}
}
}
@@ -107,11 +151,11 @@ class Webpage extends Output implements PSI_Interface_Output
*/
private function _getLanguageList()
{
$dirlist = CommonFunctions::gdc(APP_ROOT.'/language/');
$dirlist = CommonFunctions::gdc(PSI_APP_ROOT.'/language/');
sort($dirlist);
foreach ($dirlist as $file) {
$lang_ext = substr($file, strlen($file) - 4);
$lang_name = substr($file, 0, strlen($file) - 4);
$lang_ext = strtolower(substr($file, strlen($file) - 4));
$lang_name = strtolower(substr($file, 0, strlen($file) - 4));
if ($lang_ext == ".xml") {
array_push($this->_languages, $lang_name);
}
@@ -127,12 +171,52 @@ class Webpage extends Output implements PSI_Interface_Output
{
$this->_checkTemplateLanguage();
$tpl = new Template("/templates/html/index_dynamic.html");
$tpl = new Template("/templates/html/index_".$this->_indexname.".html");
$tpl->set("template", $this->_template);
$tpl->set("templates", $this->_templates);
$tpl->set("bootstraptemplate", $this->_bootstrap_template);
$tpl->set("bootstraptemplates", $this->_bootstrap_templates);
$tpl->set("picktemplate", $this->_pick_template);
$tpl->set("language", $this->_language);
$tpl->set("languages", $this->_languages);
$tpl->set("picklanguage", $this->_pick_language);
$tpl->set("showCPUListExpanded", defined('PSI_SHOW_CPULIST_EXPANDED') ? (PSI_SHOW_CPULIST_EXPANDED ? 'true' : 'false') : 'true');
$tpl->set("showCPUInfoExpanded", defined('PSI_SHOW_CPUINFO_EXPANDED') ? (PSI_SHOW_CPUINFO_EXPANDED ? 'true' : 'false') : 'false');
$tpl->set("showNetworkInfosExpanded", defined('PSI_SHOW_NETWORK_INFOS_EXPANDED') ? (PSI_SHOW_NETWORK_INFOS_EXPANDED ? 'true' : 'false') : 'false');
$tpl->set("showMemoryInfosExpanded", defined('PSI_SHOW_MEMORY_INFOS_EXPANDED') ? (PSI_SHOW_MEMORY_INFOS_EXPANDED ? 'true' : 'false') : 'false');
$tpl->set("showNetworkActiveSpeed", defined('PSI_SHOW_NETWORK_ACTIVE_SPEED') ? (PSI_SHOW_NETWORK_ACTIVE_SPEED ? ((strtolower(PSI_SHOW_NETWORK_ACTIVE_SPEED) === 'bps') ? 'bps' :'true') : 'false') : 'false');
$tpl->set("showCPULoadCompact", defined('PSI_LOAD_BAR') ? ((strtolower(PSI_LOAD_BAR) === 'compact') ? 'true' :'false') : 'false');
$tpl->set("hideBootstrapLoader", defined('PSI_HIDE_BOOTSTRAP_LOADER') ? (PSI_HIDE_BOOTSTRAP_LOADER ? 'true' : 'false') : 'false');
$tpl->set("increaseWidth", defined('PSI_INCREASE_WIDTH') ? ((intval(PSI_INCREASE_WIDTH)>0) ? intval(PSI_INCREASE_WIDTH) : 0) : 0);
$tpl->set("hideTotals", defined('PSI_HIDE_TOTALS') ? (PSI_HIDE_TOTALS ? 'true' : 'false') : 'false');
if (defined('PSI_BLOCKS')) {
if (is_string(PSI_BLOCKS)) {
if (preg_match(ARRAY_EXP, PSI_BLOCKS)) {
$blocks = eval(strtolower(PSI_BLOCKS));
} else {
$blocks = array(strtolower(PSI_BLOCKS));
}
$blocklist = '';
$validblocks = array('vitals','hardware','memory','filesystem','network','voltage','current','temperature','fans','power','other','ups');
foreach ($blocks as $block) {
if (in_array($block, $validblocks)) {
if (empty($blocklist)) {
$blocklist = $block;
} else {
$blocklist .= ','.$block;
}
}
}
if (!empty($blocklist)) {
$tpl->set("blocks", $blocklist);
}
} elseif (PSI_BLOCKS) {
$tpl->set("blocks", 'true');
}
} else {
$tpl->set("blocks", 'true');
}
echo $tpl->fetch();
}

View File

@@ -8,7 +8,7 @@
* @package PSI_XML
* @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 SVN: $Id: class.WebpageXML.inc.php 661 2012-08-27 11:26:39Z namiltd $
* @link http://phpsysinfo.sourceforge.net
*/
@@ -19,7 +19,7 @@
* @package PSI_XML
* @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
*/
@@ -32,13 +32,6 @@ class WebpageXML extends Output implements PSI_Interface_Output
*/
private $_xml;
/**
* only plugin xml
*
* @var boolean
*/
private $_pluginRequest = false;
/**
* complete xml
*
@@ -53,6 +46,13 @@ class WebpageXML extends Output implements PSI_Interface_Output
*/
private $_pluginName = null;
/**
* name of the block
*
* @var string
*/
private $_blockName = null;
/**
* generate the output
*
@@ -60,82 +60,161 @@ class WebpageXML extends Output implements PSI_Interface_Output
*/
private function _prepare()
{
if (!$this->_pluginRequest) {
// Figure out which OS we are running on, and detect support
if (!file_exists(APP_ROOT.'/includes/os/class.'.PSI_OS.'.inc.php')) {
$this->error->addError("file_exists(class.".PSI_OS.".inc.php)", PSI_OS." is not currently supported");
if ($this->_pluginName === null) {
if ((PSI_OS == 'Linux') && defined('PSI_SSH_HOSTNAME') && defined('PSI_SSH_USER') && defined('PSI_SSH_PASSWORD')) {
$fgthost = preg_split("/:/", PSI_SSH_HOSTNAME, -1, PREG_SPLIT_NO_EMPTY);
define('PSI_EMU_HOSTNAME', trim($fgthost[0]));
if (isset($fgthost[1]) && (trim($fgthost[1] !== ''))) {
define('PSI_EMU_PORT', trim($fgthost[1]));
} else {
define('PSI_EMU_PORT', 22);
}
define('PSI_EMU_USER', PSI_SSH_USER);
define('PSI_EMU_PASSWORD', PSI_SSH_PASSWORD);
if (defined('PSI_SSH_ADD_PATHS')) {
define('PSI_EMU_ADD_PATHS', PSI_SSH_ADD_PATHS);
}
if (defined('PSI_SSH_ADD_OPTIONS')) {
define('PSI_EMU_ADD_OPTIONS', PSI_SSH_ADD_OPTIONS);
}
if (!file_exists(PSI_APP_ROOT.'/includes/os/class.Linux.inc.php')) {
$this->error->addError("file_exists(class.Linux.inc.php)", "Linux is not currently supported");
}
} elseif (((PSI_OS == 'WINNT') || (PSI_OS == 'Linux')) && defined('PSI_WMI_HOSTNAME')) {
define('PSI_EMU_HOSTNAME', PSI_WMI_HOSTNAME);
if (defined('PSI_WMI_USER') && defined('PSI_WMI_PASSWORD')) {
define('PSI_EMU_USER', PSI_WMI_USER);
define('PSI_EMU_PASSWORD', PSI_WMI_PASSWORD);
} else {
define('PSI_EMU_USER', null);
define('PSI_EMU_PASSWORD', null);
}
if (!file_exists(PSI_APP_ROOT.'/includes/os/class.WINNT.inc.php')) {
$this->error->addError("file_exists(class.WINNT.inc.php)", "WINNT is not currently supported");
}
} else {
// Figure out which OS we are running on, and detect support
if (!file_exists(PSI_APP_ROOT.'/includes/os/class.'.PSI_OS.'.inc.php')) {
$this->error->addError("file_exists(class.".PSI_OS.".inc.php)", PSI_OS." is not currently supported");
}
}
// check if there is a valid sensor configuration in phpsysinfo.ini
$foundsp = array();
if (defined('PSI_SENSOR_PROGRAM') && is_string(PSI_SENSOR_PROGRAM)) {
if (preg_match(ARRAY_EXP, PSI_SENSOR_PROGRAM)) {
$sensorprograms = eval(strtolower(PSI_SENSOR_PROGRAM));
} else {
$sensorprograms = array(strtolower(PSI_SENSOR_PROGRAM));
}
foreach ($sensorprograms as $sensorprogram) {
if (!file_exists(APP_ROOT.'/includes/mb/class.'.$sensorprogram.'.inc.php')) {
$this->error->addError("file_exists(class.".htmlspecialchars($sensorprogram).".inc.php)", "specified sensor program is not supported");
if (!defined('PSI_MBINFO') && (!$this->_blockName || in_array($this->_blockName, array('mbinfo','voltage','current','temperature','fans','power','other')))) {
// check if there is a valid sensor configuration in phpsysinfo.ini
$foundsp = array();
if (defined('PSI_SENSOR_PROGRAM') && is_string(PSI_SENSOR_PROGRAM)) {
if (preg_match(ARRAY_EXP, PSI_SENSOR_PROGRAM)) {
$sensorprograms = eval(strtolower(PSI_SENSOR_PROGRAM));
} else {
$foundsp[] = $sensorprogram;
$sensorprograms = array(strtolower(PSI_SENSOR_PROGRAM));
}
foreach ($sensorprograms as $sensorprogram) {
if (!file_exists(PSI_APP_ROOT.'/includes/mb/class.'.$sensorprogram.'.inc.php')) {
$this->error->addError("file_exists(class.".htmlspecialchars($sensorprogram).".inc.php)", "specified sensor program is not supported");
} else {
$foundsp[] = $sensorprogram;
}
}
}
/**
* motherboard information
*
* @var string serialized array
*/
define('PSI_MBINFO', serialize($foundsp));
}
/**
* motherboard information
*
* @var serialized array
*/
define('PSI_MBINFO', serialize($foundsp));
// check if there is a valid hddtemp configuration in phpsysinfo.ini
$found = false;
if (PSI_HDD_TEMP !== false) {
$found = true;
}
/**
* hddtemp information available or not
*
* @var boolean
*/
define('PSI_HDDTEMP', $found);
// check if there is a valid ups configuration in phpsysinfo.ini
$foundup = array();
if (defined('PSI_UPS_PROGRAM') && is_string(PSI_UPS_PROGRAM)) {
if (preg_match(ARRAY_EXP, PSI_UPS_PROGRAM)) {
$upsprograms = eval(strtolower(PSI_UPS_PROGRAM));
} else {
$upsprograms = array(strtolower(PSI_UPS_PROGRAM));
}
foreach ($upsprograms as $upsprogram) {
if (!file_exists(APP_ROOT.'/includes/ups/class.'.$upsprogram.'.inc.php')) {
$this->error->addError("file_exists(class.".htmlspecialchars($upsprogram).".inc.php)", "specified UPS program is not supported");
if (!defined('PSI_UPSINFO') && (!$this->_blockName || ($this->_blockName==='ups'))) {
// check if there is a valid ups configuration in phpsysinfo.ini
$foundup = array();
if (defined('PSI_UPS_PROGRAM') && is_string(PSI_UPS_PROGRAM)) {
if (preg_match(ARRAY_EXP, PSI_UPS_PROGRAM)) {
$upsprograms = eval(strtolower(PSI_UPS_PROGRAM));
} else {
$foundup[] = $upsprogram;
$upsprograms = array(strtolower(PSI_UPS_PROGRAM));
}
foreach ($upsprograms as $upsprogram) {
if (!file_exists(PSI_APP_ROOT.'/includes/ups/class.'.$upsprogram.'.inc.php')) {
$this->error->addError("file_exists(class.".htmlspecialchars($upsprogram).".inc.php)", "specified UPS program is not supported");
} else {
$foundup[] = $upsprogram;
}
}
}
/**
* ups information
*
* @var string serialized array
*/
define('PSI_UPSINFO', serialize($foundup));
}
/**
* ups information
*
* @var serialized array
*/
define('PSI_UPSINFO', serialize($foundup));
// if there are errors stop executing the script until they are fixed
if ($this->error->errorsExist()) {
$this->error->errorsAsXML();
}
}
// Create the XML
if ($this->_pluginRequest) {
$this->_xml = new XML(false, $this->_pluginName);
// Create the XML
$this->_xml = new XML($this->_completeXML, '', $this->_blockName);
} else {
$this->_xml = new XML($this->_completeXML);
if ((PSI_OS == 'WINNT') || (PSI_OS == 'Linux')) {
$plugname = strtoupper(trim($this->_pluginName));
if ((PSI_OS == 'Linux') && defined('PSI_PLUGIN_'.$plugname.'_SSH_HOSTNAME') && defined('PSI_PLUGIN_'.$plugname.'_SSH_USER') && defined('PSI_PLUGIN_'.$plugname.'_SSH_PASSWORD')) {
$fgthost = preg_split("/:/", constant('PSI_PLUGIN_'.$plugname.'_SSH_HOSTNAME'), -1, PREG_SPLIT_NO_EMPTY);
define('PSI_EMU_HOSTNAME', trim($fgthost[0]));
if (isset($fgthost[1]) && (trim($fgthost[1] !== ''))) {
define('PSI_EMU_PORT', trim($fgthost[1]));
} else {
define('PSI_EMU_PORT', 22);
}
define('PSI_EMU_USER', constant('PSI_PLUGIN_'.$plugname.'_SSH_USER'));
define('PSI_EMU_PASSWORD', constant('PSI_PLUGIN_'.$plugname.'_SSH_PASSWORD'));
if (defined('PSI_PLUGIN_'.$plugname.'_SSH_ADD_PATHS')) {
define('PSI_EMU_ADD_PATHS', constant('PSI_PLUGIN_'.$plugname.'_SSH_ADD_PATHS'));
}
if (defined('PSI_PLUGIN_'.$plugname.'_SSH_ADD_OPTIONS')) {
define('PSI_EMU_ADD_OPTIONS', constant('PSI_PLUGIN_'.$plugname.'_SSH_ADD_OPTIONS'));
}
} elseif (defined('PSI_PLUGIN_'.$plugname.'_WMI_HOSTNAME')) {
define('PSI_EMU_HOSTNAME', constant('PSI_PLUGIN_'.$plugname.'_WMI_HOSTNAME'));
if (defined('PSI_PLUGIN_'.$plugname.'_WMI_USER') && defined('PSI_PLUGIN_'.$plugname.'_WMI_PASSWORD')) {
define('PSI_EMU_USER', constant('PSI_PLUGIN_'.$plugname.'_WMI_USER'));
define('PSI_EMU_PASSWORD', constant('PSI_PLUGIN_'.$plugname.'_WMI_PASSWORD'));
} else {
define('PSI_EMU_USER', null);
define('PSI_EMU_PASSWORD', null);
}
} elseif ((PSI_OS == 'Linux') && defined('PSI_SSH_HOSTNAME') && defined('PSI_SSH_USER') && defined('PSI_SSH_PASSWORD')) {
$fgthost = preg_split("/:/", PSI_SSH_HOSTNAME, -1, PREG_SPLIT_NO_EMPTY);
define('PSI_EMU_HOSTNAME', trim($fgthost[0]));
if (isset($fgthost[1]) && (trim($fgthost[1] !== ''))) {
define('PSI_EMU_PORT', trim($fgthost[1]));
} else {
define('PSI_EMU_PORT', 22);
}
define('PSI_EMU_USER', PSI_SSH_USER);
define('PSI_EMU_PASSWORD', PSI_SSH_PASSWORD);
if (defined('PSI_SSH_ADD_PATHS')) {
define('PSI_EMU_ADD_PATHS', PSI_SSH_ADD_PATHS);
}
if (defined('PSI_SSH_ADD_OPTIONS')) {
define('PSI_EMU_ADD_OPTIONS', PSI_SSH_ADD_OPTIONS);
}
} elseif (defined('PSI_WMI_HOSTNAME')) {
define('PSI_EMU_HOSTNAME', PSI_WMI_HOSTNAME);
if (defined('PSI_WMI_USER') && defined('PSI_WMI_PASSWORD')) {
define('PSI_EMU_USER', PSI_WMI_USER);
define('PSI_EMU_PASSWORD', PSI_WMI_PASSWORD);
} else {
define('PSI_EMU_USER', null);
define('PSI_EMU_PASSWORD', null);
}
}
}
// Create the XML
$this->_xml = new XML(false, $this->_pluginName);
}
}
@@ -146,8 +225,8 @@ class WebpageXML extends Output implements PSI_Interface_Output
*/
public function run()
{
header("Cache-Control: no-cache, must-revalidate\n");
header("Content-Type: text/xml\n\n");
header('Cache-Control: no-cache, must-revalidate');
header('Content-Type: text/xml');
$xml = $this->_xml->getXml();
echo $xml->asXML();
}
@@ -164,24 +243,52 @@ class WebpageXML extends Output implements PSI_Interface_Output
return $xml->asXML();
}
/**
* get json string
*
* @return string
*/
public function getJsonString()
{
if (defined('PSI_JSON_ISSUE') && (PSI_JSON_ISSUE)) {
return json_encode(simplexml_load_string(str_replace(">", ">\n", $this->getXMLString()))); // solving json_encode issue
} else {
return json_encode(simplexml_load_string($this->getXMLString()));
}
}
/**
* get array
*
* @return array
*/
public function getArray()
{
return json_decode($this->getJsonString());
}
/**
* set parameters for the XML generation process
*
* @param boolean $completeXML switch for complete xml with all plugins
* @param string $plugin name of the plugin
* @param string $plugin name of the plugin, block or 'complete' for all plugins
*
* @return void
*/
public function __construct($completeXML, $plugin = null)
public function __construct($plugin = "")
{
parent::__construct();
if ($completeXML) {
$this->_completeXML = true;
}
if ($plugin) {
if (in_array(strtolower($plugin), CommonFunctions::getPlugins())) {
if (is_string($plugin) && ($plugin !== "")) {
if (preg_match('/[^A-Za-z]/', $plugin)) {
$this->_blockName = ' '; // mask wrong plugin name
} elseif (($plugin = strtolower($plugin)) === "complete") {
$this->_completeXML = true;
} elseif (in_array($plugin, array('vitals','hardware','memory','filesystem','network','mbinfo','voltage','current','temperature','fans','power','other','ups'))) {
$this->_blockName = $plugin;
} elseif (in_array($plugin, CommonFunctions::getPlugins())) {
$this->_pluginName = $plugin;
$this->_pluginRequest = true;
} else {
$this->_blockName = ' '; // disable all blocks
}
}
$this->_prepare();

View File

@@ -8,7 +8,7 @@
* @package PSI_Web
* @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 SVN: $Id: class.WebpageXSLT.inc.php 569 2012-04-16 06:08:18Z namiltd $
* @link http://phpsysinfo.sourceforge.net
*/
@@ -19,7 +19,7 @@
* @package PSI_Web
* @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
*/
@@ -30,7 +30,7 @@ class WebpageXSLT extends WebpageXML implements PSI_Interface_Output
*/
public function __construct()
{
parent::__construct(false, null);
parent::__construct();
}
/**
@@ -49,6 +49,7 @@ class WebpageXSLT extends WebpageXML implements PSI_Interface_Output
$domxsl->load($xslfile);
$xsltproc = new XSLTProcessor;
$xsltproc->importStyleSheet($domxsl);
header('Cache-Control: no-cache, must-revalidate');
echo $xsltproc->transformToXML($domxml);
}
}

View File

@@ -8,7 +8,7 @@
* @package PSI_Plugin
* @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 SVN: $Id: class.PSI_Plugin.inc.php 661 2012-08-27 11:26:39Z namiltd $
* @link http://phpsysinfo.sourceforge.net
*/
@@ -23,7 +23,7 @@
* @package PSI_Plugin
* @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
*/
@@ -61,17 +61,16 @@ abstract class PSI_Plugin implements PSI_Interface_Plugin
* build the global Error object, read the configuration and check if all files are available
* for a minimalistic function of the plugin
*
* @param String $plugin_name name of the plugin
* @param String $enc target encoding
*
* @param string $plugin_name name of the plugin
* @param string $enc target encoding
* @return void
*/
public function __construct($plugin_name, $enc)
{
$this->global_error = Error::Singleton();
$this->global_error = PSI_Error::Singleton();
if (trim($plugin_name) != "") {
$this->_plugin_name = $plugin_name;
$this->_plugin_base = APP_ROOT."/plugins/".strtolower($this->_plugin_name)."/";
$this->_plugin_base = PSI_APP_ROOT."/plugins/".strtolower($this->_plugin_name)."/";
$this->_checkfiles();
$this->_getconfig();
} else {
@@ -87,9 +86,11 @@ abstract class PSI_Plugin implements PSI_Interface_Plugin
*/
private function _getconfig()
{
if ((!defined('PSI_PLUGIN_'.strtoupper($this->_plugin_name).'_ACCESS')) &&
(!defined('PSI_PLUGIN_'.strtoupper($this->_plugin_name).'_FILE'))) {
$this->global_error->addError("config.ini", "Config for plugin ".$this->_plugin_name." not exist!");
if ((strtoupper($this->_plugin_name) !== 'DISKLOAD') &&
(!defined('PSI_PLUGIN_'.strtoupper($this->_plugin_name).'_ACCESS')) &&
(!defined('PSI_PLUGIN_'.strtoupper($this->_plugin_name).'_FILE')) &&
(!defined('PSI_PLUGIN_'.strtoupper($this->_plugin_name).'_SHOW_SERIAL'))) {
$this->global_error->addError("phpsysinfo.ini", "Config for plugin ".$this->_plugin_name." not exist!");
}
}
@@ -120,9 +121,9 @@ abstract class PSI_Plugin implements PSI_Interface_Plugin
/**
* create the xml template where plugin information are added to
*
* @param String $enc target encoding
* @param string $enc target encoding
*
* @return Void
* @return void
*/
private function _createXml($enc)
{
@@ -130,5 +131,13 @@ abstract class PSI_Plugin implements PSI_Interface_Plugin
$root = $dom->createElement("Plugin_".$this->_plugin_name);
$dom->appendChild($root);
$this->xml = new SimpleXMLExtended(simplexml_import_dom($dom), $enc);
$plugname = strtoupper($this->_plugin_name);
if ((PSI_OS == 'Linux') && defined('PSI_PLUGIN_'.$plugname.'_SSH_HOSTNAME') &&
(!defined('PSI_SSH_HOSTNAME') || (PSI_SSH_HOSTNAME != constant('PSI_PLUGIN_'.strtoupper($this->_plugin_name).'_SSH_HOSTNAME')))) {
$this->xml->addAttribute('Hostname', constant('PSI_PLUGIN_'.strtoupper($this->_plugin_name).'_SSH_HOSTNAME'));
} elseif (((PSI_OS == 'WINNT') || (PSI_OS == 'Linux')) && defined('PSI_PLUGIN_'.$plugname.'_WMI_HOSTNAME') &&
(!defined('PSI_WMI_HOSTNAME') || (PSI_WMI_HOSTNAME != constant('PSI_PLUGIN_'.strtoupper($this->_plugin_name).'_WMI_HOSTNAME')))) {
$this->xml->addAttribute('Hostname', constant('PSI_PLUGIN_'.strtoupper($this->_plugin_name).'_WMI_HOSTNAME'));
}
}
}

View File

@@ -8,7 +8,7 @@
* @package PSI_TO
* @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 SVN: $Id: class.MBInfo.inc.php 253 2009-06-17 13:07:50Z bigmichi1 $
* @link http://phpsysinfo.sourceforge.net
*/
@@ -19,7 +19,7 @@
* @package PSI_TO
* @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
*/
@@ -30,7 +30,7 @@ class MBInfo
*
* @see SensorDevice
*
* @var Array
* @var array
*/
private $_mbTemp = array();
@@ -39,7 +39,7 @@ class MBInfo
*
* @see SensorDevice
*
* @var Array
* @var array
*/
private $_mbFan = array();
@@ -48,7 +48,7 @@ class MBInfo
*
* @see SensorDevice
*
* @var Array
* @var array
*/
private $_mbVolt = array();
@@ -57,7 +57,7 @@ class MBInfo
*
* @see SensorDevice
*
* @var Array
* @var array
*/
private $_mbPower = array();
@@ -66,19 +66,32 @@ class MBInfo
*
* @see SensorDevice
*
* @var Array
* @var array
*/
private $_mbCurrent = array();
/**
* array with SensorDevices for other
*
* @see SensorDevice
*
* @var array
*/
private $_mbOther = array();
/**
* Returns $_mbFan.
*
* @see System::$_mbFan
*
* @return Array
* @return array
*/
public function getMbFan()
{
if (defined('PSI_SORT_SENSORS_LIST') && PSI_SORT_SENSORS_LIST) {
usort($this->_mbFan, array('CommonFunctions', 'name_natural_compare'));
}
return $this->_mbFan;
}
@@ -89,7 +102,7 @@ class MBInfo
*
* @see System::$_mbFan
*
* @return Void
* @return void
*/
public function setMbFan($mbFan)
{
@@ -101,21 +114,25 @@ class MBInfo
*
* @see System::$_mbTemp
*
* @return Array
* @return array
*/
public function getMbTemp()
{
if (defined('PSI_SORT_SENSORS_LIST') && PSI_SORT_SENSORS_LIST) {
usort($this->_mbTemp, array('CommonFunctions', 'name_natural_compare'));
}
return $this->_mbTemp;
}
/**
* Sets $_mbTemp.
*
* @param Sensor $mbTemp temp device
* @param SensorDevice $mbTemp temp device
*
* @see System::$_mbTemp
*
* @return Void
* @return void
*/
public function setMbTemp($mbTemp)
{
@@ -127,21 +144,25 @@ class MBInfo
*
* @see System::$_mbVolt
*
* @return Array
* @return array
*/
public function getMbVolt()
{
if (defined('PSI_SORT_SENSORS_LIST') && PSI_SORT_SENSORS_LIST) {
usort($this->_mbVolt, array('CommonFunctions', 'name_natural_compare'));
}
return $this->_mbVolt;
}
/**
* Sets $_mbVolt.
*
* @param Sensor $mbVolt voltage device
* @param SensorDevice $mbVolt voltage device
*
* @see System::$_mbVolt
*
* @return Void
* @return void
*/
public function setMbVolt($mbVolt)
{
@@ -153,49 +174,88 @@ class MBInfo
*
* @see System::$_mbPower
*
* @return Array
* @return array
*/
public function getMbPower()
{
if (defined('PSI_SORT_SENSORS_LIST') && PSI_SORT_SENSORS_LIST) {
usort($this->_mbPower, array('CommonFunctions', 'name_natural_compare'));
}
return $this->_mbPower;
}
/**
* Sets $_mbPower.
*
* @param Sensor $mbPower power device
* @param SensorDevice $mbPower power device
*
* @see System::$_mbPower
*
* @return Void
* @return void
*/
public function setMbPower($mbPower)
{
array_push($this->_mbPower, $mbPower);
}
/**
* Returns $_mbCurrent.
*
* @see System::$_mbCurrent
*
* @return Array
* @return array
*/
public function getMbCurrent()
{
if (defined('PSI_SORT_SENSORS_LIST') && PSI_SORT_SENSORS_LIST) {
usort($this->_mbCurrent, array('CommonFunctions', 'name_natural_compare'));
}
return $this->_mbCurrent;
}
/**
* Sets $_mbCurrent.
*
* @param Sensor $mbCurrent current device
* @param SensorDevice $mbCurrent current device
*
* @see System::$_mbCurrent
*
* @return Void
* @return void
*/
public function setMbCurrent($mbCurrent)
{
array_push($this->_mbCurrent, $mbCurrent);
}
/**
* Returns $_mbOther.
*
* @see System::$_mbOther
*
* @return array
*/
public function getMbOther()
{
if (defined('PSI_SORT_SENSORS_LIST') && PSI_SORT_SENSORS_LIST) {
usort($this->_mbOther, array('CommonFunctions', 'name_natural_compare'));
}
return $this->_mbOther;
}
/**
* Sets $_mbOther.
*
* @param SensorDevice $mbOther other device
*
* @see System::$_mbOther
*
* @return void
*/
public function setMbOther($mbOther)
{
array_push($this->_mbOther, $mbOther);
}
}

View File

@@ -8,7 +8,7 @@
* @package PSI_TO
* @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 SVN: $Id: class.System.inc.php 255 2009-06-17 13:39:41Z bigmichi1 $
* @link http://phpsysinfo.sourceforge.net
*/
@@ -19,7 +19,7 @@
* @package PSI_TO
* @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
*/
@@ -28,70 +28,70 @@ class System
/**
* name of the host where phpSysInfo runs
*
* @var String
* @var string
*/
private $_hostname = "localhost";
/**
* ip of the host where phpSysInfo runs
*
* @var String
* @var string
*/
private $_ip = "127.0.0.1";
/**
* detailed Information about the kernel
* detailed information about the kernel
*
* @var String
* @var string
*/
private $_kernel = "Unknown";
/**
* name of the distribution
*
* @var String
* @var string
*/
private $_distribution = "Unknown";
/**
* icon of the distribution (must be available in phpSysInfo)
*
* @var String
* @var string
*/
private $_distributionIcon = "unknown.png";
/**
* detailed Information about the machine name
*
* @var String
* @var string
*/
private $_machine = "";
/**
* time in sec how long the system is running
*
* @var Integer
* @var int
*/
private $_uptime = 0;
/**
* count of users that are currently logged in
*
* @var Integer
* @var int
*/
private $_users = 0;
/**
* load of the system
*
* @var String
* @var string
*/
private $_load = "";
/**
* load of the system in percent (all cpus, if more than one)
*
* @var Integer
* @var int
*/
private $_loadPercent = null;
@@ -100,7 +100,7 @@ class System
*
* @see CpuDevice
*
* @var Array
* @var array
*/
private $_cpus = array();
@@ -109,7 +109,7 @@ class System
*
* @see NetDevice
*
* @var Array
* @var array
*/
private $_netDevices = array();
@@ -118,7 +118,7 @@ class System
*
* @see HWDevice
*
* @var Array
* @var array
*/
private $_pciDevices = array();
@@ -127,7 +127,7 @@ class System
*
* @see HWDevice
*
* @var Array
* @var array
*/
private $_ideDevices = array();
@@ -136,7 +136,7 @@ class System
*
* @see HWDevice
*
* @var Array
* @var array
*/
private $_scsiDevices = array();
@@ -145,7 +145,7 @@ class System
*
* @see HWDevice
*
* @var Array
* @var array
*/
private $_usbDevices = array();
@@ -154,7 +154,7 @@ class System
*
* @see HWDevice
*
* @var Array
* @var array
*/
private $_tbDevices = array();
@@ -163,58 +163,76 @@ class System
*
* @see HWDevice
*
* @var Array
* @var array
*/
private $_i2cDevices = array();
/**
* array with NVMe devices
*
* @see HWDevice
*
* @var array
*/
private $_nvmeDevices = array();
/**
* array with Mem devices
*
* @see HWDevice
*
* @var array
*/
private $_memDevices = array();
/**
* array with disk devices
*
* @see DiskDevice
*
* @var Array
* @var array
*/
private $_diskDevices = array();
/**
* free memory in bytes
*
* @var Integer
* @var int
*/
private $_memFree = 0;
/**
* total memory in bytes
*
* @var Integer
* @var int
*/
private $_memTotal = 0;
/**
* used memory in bytes
*
* @var Integer
* @var int
*/
private $_memUsed = 0;
/**
* used memory by applications in bytes
*
* @var Integer
* @var int
*/
private $_memApplication = null;
/**
* used memory for buffers in bytes
*
* @var Integer
* @var int
*/
private $_memBuffer = null;
/**
* used memory for cache in bytes
*
* @var Integer
* @var int
*/
private $_memCache = null;
@@ -223,25 +241,39 @@ class System
*
* @see DiskDevice
*
* @var Array
* @var array
*/
private $_swapDevices = array();
/**
* array of types of processes
*
* @var Array
* @var array
*/
private $_processes = array();
/**
* array with Virtualizer information
*
* @var array
*/
private $_virtualizer = array();
/**
* operating system type
*
* @var string
*/
private $_OS = "";
/**
* remove duplicate Entries and Count
*
* @param Array $arrDev list of HWDevices
* @param array $arrDev list of HWDevices
*
* @see HWDevice
*
* @return Array
* @return array
*/
public static function removeDupsAndCount($arrDev)
{
@@ -273,7 +305,7 @@ class System
* @see System::_memUsed
* @see System::_memTotal
*
* @return Integer
* @return int
*/
public function getMemPercentUsed()
{
@@ -290,7 +322,7 @@ class System
* @see System::_memApplication
* @see System::_memTotal
*
* @return Integer
* @return int
*/
public function getMemPercentApplication()
{
@@ -311,7 +343,7 @@ class System
* @see System::_memCache
* @see System::_memTotal
*
* @return Integer
* @return int
*/
public function getMemPercentCache()
{
@@ -336,7 +368,7 @@ class System
* @see System::_memBuffer
* @see System::_memTotal
*
* @return Integer
* @return int
*/
public function getMemPercentBuffer()
{
@@ -367,7 +399,7 @@ class System
* @see System::_swapDevices
* @see DiskDevice::getFree()
*
* @return Integer
* @return int
*/
public function getSwapFree()
{
@@ -389,7 +421,7 @@ class System
* @see System::_swapDevices
* @see DiskDevice::getTotal()
*
* @return Integer
* @return int
*/
public function getSwapTotal()
{
@@ -411,7 +443,7 @@ class System
* @see System::_swapDevices
* @see DiskDevice::getUsed()
*
* @return Integer
* @return int
*/
public function getSwapUsed()
{
@@ -433,7 +465,7 @@ class System
* @see System::getSwapUsed()
* @see System::getSwapTotal()
*
* @return Integer
* @return int
*/
public function getSwapPercentUsed()
{
@@ -467,7 +499,7 @@ class System
*
* @see System::$_distribution
*
* @return Void
* @return void
*/
public function setDistribution($distribution)
{
@@ -493,7 +525,7 @@ class System
*
* @see System::$_distributionIcon
*
* @return Void
* @return void
*/
public function setDistributionIcon($distributionIcon)
{
@@ -519,7 +551,7 @@ class System
*
* @see System::$_hostname
*
* @return Void
* @return void
*/
public function setHostname($hostname)
{
@@ -545,7 +577,7 @@ class System
*
* @see System::$_ip
*
* @return Void
* @return void
*/
public function setIp($ip)
{
@@ -571,7 +603,7 @@ class System
*
* @see System::$_kernel
*
* @return Void
* @return void
*/
public function setKernel($kernel)
{
@@ -597,7 +629,7 @@ class System
*
* @see System::$_load
*
* @return Void
* @return void
*/
public function setLoad($load)
{
@@ -609,7 +641,7 @@ class System
*
* @see System::$_loadPercent
*
* @return Integer
* @return int
*/
public function getLoadPercent()
{
@@ -619,11 +651,11 @@ class System
/**
* Sets $_loadPercent.
*
* @param Integer $loadPercent load percent
* @param int $loadPercent load percent
*
* @see System::$_loadPercent
*
* @return Void
* @return void
*/
public function setLoadPercent($loadPercent)
{
@@ -645,11 +677,11 @@ class System
/**
* Sets $_machine.
*
* @param Interger $machine machine
* @param string $machine machine
*
* @see System::$_machine
*
* @return Void
* @return void
*/
public function setMachine($machine)
{
@@ -661,7 +693,7 @@ class System
*
* @see System::$_uptime
*
* @return Integer
* @return int
*/
public function getUptime()
{
@@ -671,11 +703,11 @@ class System
/**
* Sets $_uptime.
*
* @param Interger $uptime uptime
* @param integer $uptime uptime
*
* @see System::$_uptime
*
* @return Void
* @return void
*/
public function setUptime($uptime)
{
@@ -687,7 +719,7 @@ class System
*
* @see System::$_users
*
* @return Integer
* @return int
*/
public function getUsers()
{
@@ -697,11 +729,11 @@ class System
/**
* Sets $_users.
*
* @param Integer $users user count
* @param int $users user count
*
* @see System::$_users
*
* @return Void
* @return void
*/
public function setUsers($users)
{
@@ -713,7 +745,7 @@ class System
*
* @see System::$_cpus
*
* @return Array
* @return array
*/
public function getCpus()
{
@@ -723,12 +755,12 @@ class System
/**
* Sets $_cpus.
*
* @param Cpu $cpus cpu device
* @param CpuDevice $cpus cpu device
*
* @see System::$_cpus
* @see CpuDevice
*
* @return Void
* @return void
*/
public function setCpus($cpus)
{
@@ -740,10 +772,14 @@ class System
*
* @see System::$_netDevices
*
* @return Array
* @return array
*/
public function getNetDevices()
{
if (defined('PSI_SORT_NETWORK_INTERFACES_LIST') && PSI_SORT_NETWORK_INTERFACES_LIST) {
usort($this->_netDevices, array('CommonFunctions', 'name_natural_compare'));
}
return $this->_netDevices;
}
@@ -755,7 +791,7 @@ class System
* @see System::$_netDevices
* @see NetDevice
*
* @return Void
* @return void
*/
public function setNetDevices($netDevices)
{
@@ -767,7 +803,7 @@ class System
*
* @see System::$_pciDevices
*
* @return Array
* @return array
*/
public function getPciDevices()
{
@@ -782,7 +818,7 @@ class System
* @see System::$_pciDevices
* @see HWDevice
*
* @return Void
* @return void
*/
public function setPciDevices($pciDevices)
{
@@ -794,7 +830,7 @@ class System
*
* @see System::$_ideDevices
*
* @return Array
* @return array
*/
public function getIdeDevices()
{
@@ -809,7 +845,7 @@ class System
* @see System::$_ideDevices
* @see HWDevice
*
* @return Void
* @return void
*/
public function setIdeDevices($ideDevices)
{
@@ -821,7 +857,7 @@ class System
*
* @see System::$_scsiDevices
*
* @return Array
* @return array
*/
public function getScsiDevices()
{
@@ -836,7 +872,7 @@ class System
* @see System::$_scsiDevices
* @see HWDevice
*
* @return Void
* @return void
*/
public function setScsiDevices($scsiDevices)
{
@@ -848,7 +884,7 @@ class System
*
* @see System::$_usbDevices
*
* @return Array
* @return array
*/
public function getUsbDevices()
{
@@ -863,7 +899,7 @@ class System
* @see System::$_usbDevices
* @see HWDevice
*
* @return Void
* @return void
*/
public function setUsbDevices($usbDevices)
{
@@ -875,7 +911,7 @@ class System
*
* @see System::$_tbDevices
*
* @return Array
* @return array
*/
public function getTbDevices()
{
@@ -890,7 +926,7 @@ class System
* @see System::$_tbDevices
* @see HWDevice
*
* @return Void
* @return void
*/
public function setTbDevices($tbDevices)
{
@@ -902,7 +938,7 @@ class System
*
* @see System::$_i2cDevices
*
* @return Array
* @return array
*/
public function getI2cDevices()
{
@@ -917,19 +953,73 @@ class System
* @see System::$_i2cDevices
* @see HWDevice
*
* @return Void
* @return void
*/
public function setI2cDevices($i2cDevices)
{
array_push($this->_i2cDevices, $i2cDevices);
}
/**
* Returns $_nvmeDevices.
*
* @see System::$_nvmeDevices
*
* @return array
*/
public function getNvmeDevices()
{
return $this->_nvmeDevices;
}
/**
* Sets $_nvmeDevices.
*
* @param HWDevice $nvmeDevices NVMe device
*
* @see System::$_nvmeDevices
* @see HWDevice
*
* @return void
*/
public function setNvmeDevices($nvmeDevices)
{
array_push($this->_nvmeDevices, $nvmeDevices);
}
/**
* Returns $_memDevices.
*
* @see System::$_memDevices
*
* @return array
*/
public function getMemDevices()
{
return $this->_memDevices;
}
/**
* Sets $_memDevices.
*
* @param HWDevice $memDevices mem device
*
* @see System::$_memDevices
* @see HWDevice
*
* @return void
*/
public function setMemDevices($memDevices)
{
array_push($this->_memDevices, $memDevices);
}
/**
* Returns $_diskDevices.
*
* @see System::$_diskDevices
*
* @return Array
* @return array
*/
public function getDiskDevices()
{
@@ -956,7 +1046,7 @@ class System
*
* @see System::$_memApplication
*
* @return Integer
* @return int
*/
public function getMemApplication()
{
@@ -966,11 +1056,11 @@ class System
/**
* Sets $_memApplication.
*
* @param Integer $memApplication application memory
* @param int $memApplication application memory
*
* @see System::$_memApplication
*
* @return Void
* @return void
*/
public function setMemApplication($memApplication)
{
@@ -982,7 +1072,7 @@ class System
*
* @see System::$_memBuffer
*
* @return Integer
* @return int
*/
public function getMemBuffer()
{
@@ -992,11 +1082,11 @@ class System
/**
* Sets $_memBuffer.
*
* @param Integer $memBuffer buffer memory
* @param int $memBuffer buffer memory
*
* @see System::$_memBuffer
*
* @return Void
* @return void
*/
public function setMemBuffer($memBuffer)
{
@@ -1008,7 +1098,7 @@ class System
*
* @see System::$_memCache
*
* @return Integer
* @return int
*/
public function getMemCache()
{
@@ -1018,11 +1108,11 @@ class System
/**
* Sets $_memCache.
*
* @param Integer $memCache cache memory
* @param int $memCache cache memory
*
* @see System::$_memCache
*
* @return Void
* @return void
*/
public function setMemCache($memCache)
{
@@ -1034,7 +1124,7 @@ class System
*
* @see System::$_memFree
*
* @return Integer
* @return int
*/
public function getMemFree()
{
@@ -1044,11 +1134,11 @@ class System
/**
* Sets $_memFree.
*
* @param Integer $memFree free memory
* @param int $memFree free memory
*
* @see System::$_memFree
*
* @return Void
* @return void
*/
public function setMemFree($memFree)
{
@@ -1060,7 +1150,7 @@ class System
*
* @see System::$_memTotal
*
* @return Integer
* @return int
*/
public function getMemTotal()
{
@@ -1070,11 +1160,11 @@ class System
/**
* Sets $_memTotal.
*
* @param Integer $memTotal total memory
* @param int $memTotal total memory
*
* @see System::$_memTotal
*
* @return Void
* @return void
*/
public function setMemTotal($memTotal)
{
@@ -1086,7 +1176,7 @@ class System
*
* @see System::$_memUsed
*
* @return Integer
* @return int
*/
public function getMemUsed()
{
@@ -1096,11 +1186,11 @@ class System
/**
* Sets $_memUsed.
*
* @param Integer $memUsed used memory
* @param int $memUsed used memory
*
* @see System::$_memUsed
*
* @return Void
* @return void
*/
public function setMemUsed($memUsed)
{
@@ -1112,7 +1202,7 @@ class System
*
* @see System::$_swapDevices
*
* @return Array
* @return array
*/
public function getSwapDevices()
{
@@ -1127,7 +1217,7 @@ class System
* @see System::$_swapDevices
* @see DiskDevice
*
* @return Void
* @return void
*/
public function setSwapDevices($swapDevices)
{
@@ -1139,7 +1229,7 @@ class System
*
* @see System::$_processes
*
* @return Array
* @return array
*/
public function getProcesses()
{
@@ -1153,7 +1243,7 @@ class System
*
* @see System::$_processes
*
* @return Void
* @return void
*/
public function setProcesses($processes)
{
@@ -1164,4 +1254,64 @@ class System
}
*/
}
/**
* Returns $_virtualizer.
*
* @see System::$_virtualizer
*
* @return array
*/
public function getVirtualizer()
{
return $this->_virtualizer;
}
/**
* Sets $_virtualizer.
*
* @param String $virtualizer virtualizername
* @param Bool|String $value true, false or virtualizername to replace
*
* @see System::$_virtualizer
*
* @return void
*/
public function setVirtualizer($virtualizer, $value = true)
{
if (!isset($this->_virtualizer[$virtualizer])) {
if (is_bool($value)) {
$this->_virtualizer[$virtualizer] = $value;
} else { // replace the virtualizer with another
$this->_virtualizer[$virtualizer] = true;
$this->_virtualizer[$value] = false;
}
}
}
/**
* Returns $_OS.
*
* @see System::$_OS
*
* @return string
*/
public function getOS()
{
return $this->_OS;
}
/**
* Sets $_OS.
*
* @param $os operating system type
*
* @see System::$_OS
*
* @return void
*/
public function setOS($OS)
{
$this->_OS = $OS;
}
}

View File

@@ -8,7 +8,7 @@
* @package PSI_TO
* @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 SVN: $Id: class.UPSInfo.inc.php 329 2009-09-07 11:21:44Z bigmichi1 $
* @link http://phpsysinfo.sourceforge.net
*/
@@ -19,7 +19,7 @@
* @package PSI_TO
* @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
*/
@@ -30,7 +30,7 @@ class UPSInfo
*
* @see UPSDevice
*
* @var Array
* @var array
*/
private $_upsDevices = array();
@@ -39,7 +39,7 @@ class UPSInfo
*
* @see UPSInfo::$_upsDevices
*
* @return Array
* @return array
*/
public function getUpsDevices()
{
@@ -53,7 +53,7 @@ class UPSInfo
*
* @see UPSInfo::$_upsDevices
*
* @return Void
* @return void
*/
public function setUpsDevices($upsDevices)
{

View File

@@ -8,7 +8,7 @@
* @package PSI_TO
* @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 SVN: $Id: class.CpuDevice.inc.php 411 2010-12-28 22:32:52Z Jacky672 $
* @link http://phpsysinfo.sourceforge.net
*/
@@ -19,7 +19,7 @@
* @package PSI_TO
* @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
*/
@@ -28,123 +28,215 @@ class CpuDevice
/**
* model of the cpu
*
* @var String
* @var string
*/
private $_model = "";
/**
* cpu voltage
*
* @var Float
*/
private $_voltage = 0;
/**
* speed of the cpu in hertz
*
* @var Integer
* @var int
*/
private $_cpuSpeed = 0;
/**
* max speed of the cpu in hertz
*
* @var Integer
* @var int
*/
private $_cpuSpeedMax = 0;
/**
* min speed of the cpu in hertz
*
* @var Integer
* @var int
*/
private $_cpuSpeedMin = 0;
/**
* cache size in bytes, if available
*
* @var Integer
* @var int
*/
private $_cache = null;
/**
* virtualization, if available
*
* @var String
* @var string
*/
private $_virt = null;
/**
* busspeed in hertz, if available
*
* @var Integer
* @var int
*/
private $_busSpeed = null;
/**
* temperature of the cpu, if available
*
* @var Integer
*/
private $_temp = null;
/**
* bogomips of the cpu, if available
*
* @var Integer
* @var int
*/
private $_bogomips = null;
/**
* temperature of the cpu, if available
*
* @var int
*/
private $_temp = null;
/**
* vendorid, if available
*
* @var string
*/
private $_vendorid = null;
/**
* current load in percent of the cpu, if available
*
* @var Integer
* @var int
*/
private $_load = null;
/**
* Returns $_bogomips.
* Returns $_model.
*
* @see Cpu::$_bogomips
* @see Cpu::$_model
*
* @return Integer
* @return String
*/
public function getBogomips()
public function getModel()
{
return $this->_bogomips;
return $this->_model;
}
/**
* Sets $_bogomips.
* Sets $_model.
*
* @param Integer $bogomips bogompis
* @param String $model cpumodel
*
* @see Cpu::$_bogomips
* @see Cpu::$_model
*
* @return Void
* @return void
*/
public function setBogomips($bogomips)
public function setModel($model)
{
$this->_bogomips = $bogomips;
$this->_model = $model;
}
/**
* Returns $_busSpeed.
* Returns $_voltage.
*
* @see Cpu::$_busSpeed
* @see Cpu::$_voltage
*
* @return Integer
* @return Float
*/
public function getBusSpeed()
public function getVoltage()
{
return $this->_busSpeed;
return $this->_voltage;
}
/**
* Sets $_busSpeed.
* Sets $_voltage.
*
* @param Integer $busSpeed busspeed
* @param int $voltage voltage
*
* @see Cpu::$_busSpeed
* @see Cpu::$_voltage
*
* @return Void
* @return void
*/
public function setBusSpeed($busSpeed)
public function setVoltage($voltage)
{
$this->_busSpeed = $busSpeed;
$this->_voltage = $voltage;
}
/**
* Returns $_cpuSpeed.
*
* @see Cpu::$_cpuSpeed
*
* @return int
*/
public function getCpuSpeed()
{
return $this->_cpuSpeed;
}
/**
* Sets $_cpuSpeed.
*
* @param int $cpuSpeed cpuspeed
*
* @see Cpu::$_cpuSpeed
*
* @return void
*/
public function setCpuSpeed($cpuSpeed)
{
$this->_cpuSpeed = $cpuSpeed;
}
/**
* Returns $_cpuSpeedMax.
*
* @see Cpu::$_cpuSpeedMAx
*
* @return int
*/
public function getCpuSpeedMax()
{
return $this->_cpuSpeedMax;
}
/**
* Sets $_cpuSpeedMax.
*
* @param int $cpuSpeedMax cpuspeedmax
*
* @see Cpu::$_cpuSpeedMax
*
* @return void
*/
public function setCpuSpeedMax($cpuSpeedMax)
{
$this->_cpuSpeedMax = $cpuSpeedMax;
}
/**
* Returns $_cpuSpeedMin.
*
* @see Cpu::$_cpuSpeedMin
*
* @return int
*/
public function getCpuSpeedMin()
{
return $this->_cpuSpeedMin;
}
/**
* Sets $_cpuSpeedMin.
*
* @param int $cpuSpeedMin cpuspeedmin
*
* @see Cpu::$_cpuSpeedMin
*
* @return void
*/
public function setCpuSpeedMin($cpuSpeedMin)
{
$this->_cpuSpeedMin = $cpuSpeedMin;
}
/**
@@ -152,7 +244,7 @@ class CpuDevice
*
* @see Cpu::$_cache
*
* @return Integer
* @return int
*/
public function getCache()
{
@@ -162,11 +254,11 @@ class CpuDevice
/**
* Sets $_cache.
*
* @param Integer $cache cache size
* @param int $cache cache size
*
* @see Cpu::$_cache
*
* @return Void
* @return void
*/
public function setCache($cache)
{
@@ -188,11 +280,11 @@ class CpuDevice
/**
* Sets $_virt.
*
* @param String $_virt
* @param string $virt
*
* @see Cpu::$_virt
*
* @return Void
* @return void
*/
public function setVirt($virt)
{
@@ -200,107 +292,55 @@ class CpuDevice
}
/**
* Returns $_cpuSpeed.
* Returns $_busSpeed.
*
* @see Cpu::$_cpuSpeed
* @see Cpu::$_busSpeed
*
* @return Integer
* @return int
*/
public function getCpuSpeed()
public function getBusSpeed()
{
return $this->_cpuSpeed;
return $this->_busSpeed;
}
/**
* Returns $_cpuSpeedMax.
* Sets $_busSpeed.
*
* @see Cpu::$_cpuSpeedMAx
* @param int $busSpeed busspeed
*
* @return Integer
* @see Cpu::$_busSpeed
*
* @return void
*/
public function getCpuSpeedMax()
public function setBusSpeed($busSpeed)
{
return $this->_cpuSpeedMax;
$this->_busSpeed = $busSpeed;
}
/**
* Returns $_cpuSpeedMin.
* Returns $_bogomips.
*
* @see Cpu::$_cpuSpeedMin
* @see Cpu::$_bogomips
*
* @return Integer
* @return int
*/
public function getCpuSpeedMin()
public function getBogomips()
{
return $this->_cpuSpeedMin;
return $this->_bogomips;
}
/**
* Sets $_cpuSpeed.
* Sets $_bogomips.
*
* @param Integer $cpuSpeed cpuspeed
* @param int $bogomips bogompis
*
* @see Cpu::$_cpuSpeed
* @see Cpu::$_bogomips
*
* @return Void
* @return void
*/
public function setCpuSpeed($cpuSpeed)
public function setBogomips($bogomips)
{
$this->_cpuSpeed = $cpuSpeed;
}
/**
* Sets $_cpuSpeedMax.
*
* @param Integer $cpuSpeedMax cpuspeedmax
*
* @see Cpu::$_cpuSpeedMax
*
* @return Void
*/
public function setCpuSpeedMax($cpuSpeedMax)
{
$this->_cpuSpeedMax = $cpuSpeedMax;
}
/**
* Sets $_cpuSpeedMin.
*
* @param Integer $cpuSpeedMin cpuspeedmin
*
* @see Cpu::$_cpuSpeedMin
*
* @return Void
*/
public function setCpuSpeedMin($cpuSpeedMin)
{
$this->_cpuSpeedMin = $cpuSpeedMin;
}
/**
* Returns $_model.
*
* @see Cpu::$_model
*
* @return String
*/
public function getModel()
{
return $this->_model;
}
/**
* Sets $_model.
*
* @param String $model cpumodel
*
* @see Cpu::$_model
*
* @return Void
*/
public function setModel($model)
{
$this->_model = $model;
$this->_bogomips = $bogomips;
}
/**
@@ -308,33 +348,63 @@ class CpuDevice
*
* @see Cpu::$_temp
*
* @return Integer
* @return int
*/
/*
public function getTemp()
{
return $this->_temp;
}
*/
/**
* Sets $_temp.
*
* @param Integer $temp temperature
* @param int $temp temperature
*
* @see Cpu::$_temp
*
* @return Void
* @return void
*/
/*
public function setTemp($temp)
{
$this->_temp = $temp;
}
*/
/**
* Returns $_vendorid.
*
* @see Cpu::$_vendorid
*
* @return String
*/
public function getVendorId()
{
return $this->_vendorid;
}
/**
* Sets $_vendorid.
*
* @param string $vendorid
*
* @see Cpu::$_vendorid
*
* @return void
*/
public function setVendorId($vendorid)
{
$this->_vendorid = trim(preg_replace('/[\s!]/', '', $vendorid));
}
/**
* Returns $_load.
*
* @see CpuDevice::$_load
*
* @return Integer
* @return int
*/
public function getLoad()
{
@@ -344,11 +414,11 @@ class CpuDevice
/**
* Sets $_load.
*
* @param Integer $load load percent
* @param int $load load percent
*
* @see CpuDevice::$_load
*
* @return Void
* @return void
*/
public function setLoad($load)
{

View File

@@ -8,7 +8,7 @@
* @package PSI_TO
* @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 SVN: $Id: class.DiskDevice.inc.php 252 2009-06-17 13:06:44Z bigmichi1 $
* @link http://phpsysinfo.sourceforge.net
*/
@@ -19,7 +19,7 @@
* @package PSI_TO
* @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
*/
@@ -28,71 +28,78 @@ class DiskDevice
/**
* name of the disk device
*
* @var String
* @var string
*/
private $_name = "";
/**
* type of the filesystem on the disk device
*
* @var String
* @var string
*/
private $_fsType = "";
/**
* diskspace that is free in bytes
*
* @var Integer
* @var int
*/
private $_free = 0;
/**
* diskspace that is used in bytes
*
* @var Integer
* @var int
*/
private $_used = 0;
/**
* total diskspace
*
* @var Integer
* @var int
*/
private $_total = 0;
/**
* mount point of the disk device if available
*
* @var String
* @var string
*/
private $_mountPoint = null;
/**
* additional options of the device, like mount options
*
* @var String
* @var string
*/
private $_options = null;
/**
* inodes usage in percent if available
*
* @var
* @var int
*/
private $_percentInodesUsed = null;
/**
* ignore mode
*
* @var int
*/
private $_ignore = 0;
/**
* Returns PercentUsed calculated when function is called from internal values
*
* @see DiskDevice::$_total
* @see DiskDevice::$_used
*
* @return Integer
* @return int
*/
public function getPercentUsed()
{
if ($this->_total > 0) {
return round($this->_used / $this->_total * 100);
return 100 - min(floor($this->_free / $this->_total * 100), 100);
} else {
return 0;
}
@@ -103,7 +110,7 @@ class DiskDevice
*
* @see DiskDevice::$_PercentInodesUsed
*
* @return Integer
* @return int
*/
public function getPercentInodesUsed()
{
@@ -113,11 +120,11 @@ class DiskDevice
/**
* Sets $_PercentInodesUsed.
*
* @param Integer $percentInodesUsed inodes percent
* @param int $percentInodesUsed inodes percent
*
* @see DiskDevice::$_PercentInodesUsed
*
* @return Void
* @return void
*/
public function setPercentInodesUsed($percentInodesUsed)
{
@@ -129,7 +136,7 @@ class DiskDevice
*
* @see DiskDevice::$_free
*
* @return Integer
* @return int
*/
public function getFree()
{
@@ -139,11 +146,11 @@ class DiskDevice
/**
* Sets $_free.
*
* @param Integer $free free bytes
* @param int $free free bytes
*
* @see DiskDevice::$_free
*
* @return Void
* @return void
*/
public function setFree($free)
{
@@ -155,7 +162,7 @@ class DiskDevice
*
* @see DiskDevice::$_fsType
*
* @return String
* @return string
*/
public function getFsType()
{
@@ -169,7 +176,7 @@ class DiskDevice
*
* @see DiskDevice::$_fsType
*
* @return Void
* @return void
*/
public function setFsType($fsType)
{
@@ -181,7 +188,7 @@ class DiskDevice
*
* @see DiskDevice::$_mountPoint
*
* @return String
* @return string
*/
public function getMountPoint()
{
@@ -191,11 +198,11 @@ class DiskDevice
/**
* Sets $_mountPoint.
*
* @param String $mountPoint mountpoint
* @param string $mountPoint mountpoint
*
* @see DiskDevice::$_mountPoint
*
* @return Void
* @return void
*/
public function setMountPoint($mountPoint)
{
@@ -207,7 +214,7 @@ class DiskDevice
*
* @see DiskDevice::$_name
*
* @return String
* @return string
*/
public function getName()
{
@@ -217,11 +224,11 @@ class DiskDevice
/**
* Sets $_name.
*
* @param String $name device name
* @param string $name device name
*
* @see DiskDevice::$_name
*
* @return Void
* @return void
*/
public function setName($name)
{
@@ -233,7 +240,7 @@ class DiskDevice
*
* @see DiskDevice::$_options
*
* @return String
* @return string
*/
public function getOptions()
{
@@ -243,11 +250,11 @@ class DiskDevice
/**
* Sets $_options.
*
* @param String $options additional options
* @param string $options additional options
*
* @see DiskDevice::$_options
*
* @return Void
* @return void
*/
public function setOptions($options)
{
@@ -259,7 +266,7 @@ class DiskDevice
*
* @see DiskDevice::$_total
*
* @return Integer
* @return int
*/
public function getTotal()
{
@@ -269,11 +276,11 @@ class DiskDevice
/**
* Sets $_total.
*
* @param Integer $total total bytes
* @param int $total total bytes
*
* @see DiskDevice::$_total
*
* @return Void
* @return void
*/
public function setTotal($total)
{
@@ -285,7 +292,7 @@ class DiskDevice
*
* @see DiskDevice::$_used
*
* @return Integer
* @return int
*/
public function getUsed()
{
@@ -295,14 +302,38 @@ class DiskDevice
/**
* Sets $_used.
*
* @param Integer $used used bytes
* @param int $used used bytes
*
* @see DiskDevice::$_used
*
* @return Void
* @return void
*/
public function setUsed($used)
{
$this->_used = $used;
}
/**
* Returns $_ignore.
*
* @see DiskDevice::$_ignore
*
* @return int
*/
public function getIgnore()
{
return $this->_ignore;
}
/**
* Sets $_ignore.
*
* @see DiskDevice::$_ignore
*
* @return void
*/
public function setIgnore($ignore)
{
$this->_ignore = $ignore;
}
}

View File

@@ -8,7 +8,7 @@
* @package PSI_TO
* @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 SVN: $Id: class.HWDevice.inc.php 255 2009-06-17 13:39:41Z bigmichi1 $
* @link http://phpsysinfo.sourceforge.net
*/
@@ -19,7 +19,7 @@
* @package PSI_TO
* @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
*/
@@ -28,21 +28,56 @@ class HWDevice
/**
* name of the device
*
* @var String
* @var string
*/
private $_name = "";
/**
* capacity of the device, if not available it will be null
*
* @var Integer
* @var int
*/
private $_capacity = null;
/**
* manufacturer of the device, if not available it will be null
*
* @var int
*/
private $_manufacturer = null;
/**
* product of the device, if not available it will be null
*
* @var int
*/
private $_product = null;
/**
* serial number of the device, if not available it will be null
*
* @var string
*/
private $_serial = null;
/**
* speed of the device, if not available it will be null
*
* @var Float
*/
private $_speed = null;
/**
* voltage of the device, if not available it will be null
*
* @var Float
*/
private $_voltage = null;
/**
* count of the device
*
* @var Integer
* @var int
*/
private $_count = 1;
@@ -55,39 +90,18 @@ class HWDevice
*/
public function equals(HWDevice $dev)
{
if ($dev->getName() === $this->_name && $dev->getCapacity() === $this->_capacity) {
if ($dev->getName() === $this->_name
&& $dev->getCapacity() === $this->_capacity
&& $dev->getManufacturer() === $this->_manufacturer
&& $dev->getProduct() === $this->_product
&& $dev->getSerial() === $this->_serial
&& $dev->getSpeed() === $this->_speed) {
return true;
} else {
return false;
}
}
/**
* Returns $_capacity.
*
* @see HWDevice::$_capacity
*
* @return Integer
*/
public function getCapacity()
{
return $this->_capacity;
}
/**
* Sets $_capacity.
*
* @param Integer $capacity device capacity
*
* @see HWDevice::$_capacity
*
* @return Void
*/
public function setCapacity($capacity)
{
$this->_capacity = $capacity;
}
/**
* Returns $_name.
*
@@ -107,19 +121,175 @@ class HWDevice
*
* @see HWDevice::$_name
*
* @return Void
* @return void
*/
public function setName($name)
{
$this->_name = $name;
}
/**
* Returns $_manufacturer.
*
* @see HWDevice::$_manufacturer
*
* @return String
*/
public function getManufacturer()
{
return $this->_manufacturer;
}
/**
* Sets $_manufacturer.
*
* @param String $manufacturer manufacturer name
*
* @see HWDevice::$_manufacturer
*
* @return void
*/
public function setManufacturer($manufacturer)
{
$this->_manufacturer = $manufacturer;
}
/**
* Returns $_product.
*
* @see HWDevice::$_product
*
* @return String
*/
public function getProduct()
{
return $this->_product;
}
/**
* Sets $_product.
*
* @param String $product product name
*
* @see HWDevice::$_product
*
* @return void
*/
public function setProduct($product)
{
$this->_product = $product;
}
/**
* Returns $_serial.
*
* @see HWDevice::$_serial
*
* @return String
*/
public function getSerial()
{
return $this->_serial;
}
/**
* Sets $_serial.
*
* @param String $serial serial number
*
* @see HWDevice::$_serial
*
* @return void
*/
public function setSerial($serial)
{
$this->_serial = $serial;
}
/**
* Returns $_speed.
*
* @see HWDevice::$_speed
*
* @return Float
*/
public function getSpeed()
{
return $this->_speed;
}
/**
* Sets $_speed.
*
* @param Float $speed speed
*
* @see HWDevice::$_speed
*
* @return void
*/
public function setSpeed($speed)
{
$this->_speed = $speed;
}
/**
* Returns $_voltage.
*
* @see HWDevice::$_voltage
*
* @return Float
*/
public function getVoltage()
{
return $this->_voltage;
}
/**
* Sets $_voltage.
*
* @param Float $voltage voltage
*
* @see HWDevice::$_voltage
*
* @return void
*/
public function setVoltage($voltage)
{
$this->_voltage = $voltage;
}
/**
* Returns $_capacity.
*
* @see HWDevice::$_capacity
*
* @return int
*/
public function getCapacity()
{
return $this->_capacity;
}
/**
* Sets $_capacity.
*
* @param int $capacity device capacity
*
* @see HWDevice::$_capacity
*
* @return void
*/
public function setCapacity($capacity)
{
$this->_capacity = $capacity;
}
/**
* Returns $_count.
*
* @see HWDevice::$_count
*
* @return Integer
* @return int
*/
public function getCount()
{
@@ -129,11 +299,11 @@ class HWDevice
/**
* Sets $_count.
*
* @param Integer $count device count
* @param int $count device count
*
* @see HWDevice::$_count
*
* @return Void
* @return void
*/
public function setCount($count)
{

View File

@@ -8,7 +8,7 @@
* @package PSI_TO
* @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 SVN: $Id: class.NetDevice.inc.php 547 2012-03-22 09:44:38Z namiltd $
* @link http://phpsysinfo.sourceforge.net
*/
@@ -19,7 +19,7 @@
* @package PSI_TO
* @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
*/
@@ -28,51 +28,72 @@ class NetDevice
/**
* name of the device
*
* @var String
* @var string
*/
private $_name = "";
/**
* transmitted bytes
*
* @var Integer
* @var int
*/
private $_txBytes = 0;
/**
* received bytes
*
* @var Integer
* @var int
*/
private $_rxBytes = 0;
/**
* counted error packages
*
* @var Integer
* @var int
*/
private $_errors = 0;
/**
* counted droped packages
*
* @var Integer
* @var int
*/
private $_drops = 0;
/**
* string with info
*
* @var String
* @var string
*/
private $_info = null;
/**
* string with bridge
*
* @var string
*/
private $_bridge = null;
/**
* transmitted bytes rate
*
* @var int
*/
private $_txRate = null;
/**
* received bytes rate
*
* @var int
*/
private $_rxRate = null;
/**
* Returns $_drops.
*
* @see NetDevice::$_drops
*
* @return Integer
* @return int
*/
public function getDrops()
{
@@ -82,11 +103,11 @@ class NetDevice
/**
* Sets $_drops.
*
* @param Integer $drops dropped packages
* @param int $drops dropped packages
*
* @see NetDevice::$_drops
*
* @return Void
* @return void
*/
public function setDrops($drops)
{
@@ -98,7 +119,7 @@ class NetDevice
*
* @see NetDevice::$_errors
*
* @return Integer
* @return int
*/
public function getErrors()
{
@@ -108,11 +129,11 @@ class NetDevice
/**
* Sets $_errors.
*
* @param Integer $errors error packages
* @param int $errors error packages
*
* @see NetDevice::$_errors
*
* @return Void
* @return void
*/
public function setErrors($errors)
{
@@ -138,7 +159,7 @@ class NetDevice
*
* @see NetDevice::$_name
*
* @return Void
* @return void
*/
public function setName($name)
{
@@ -150,7 +171,7 @@ class NetDevice
*
* @see NetDevice::$_rxBytes
*
* @return Integer
* @return int
*/
public function getRxBytes()
{
@@ -160,11 +181,11 @@ class NetDevice
/**
* Sets $_rxBytes.
*
* @param Integer $rxBytes received bytes
* @param int $rxBytes received bytes
*
* @see NetDevice::$_rxBytes
*
* @return Void
* @return void
*/
public function setRxBytes($rxBytes)
{
@@ -176,7 +197,7 @@ class NetDevice
*
* @see NetDevice::$_txBytes
*
* @return Integer
* @return int
*/
public function getTxBytes()
{
@@ -186,11 +207,11 @@ class NetDevice
/**
* Sets $_txBytes.
*
* @param Integer $txBytes transmitted bytes
* @param int $txBytes transmitted bytes
*
* @see NetDevice::$_txBytes
*
* @return Void
* @return void
*/
public function setTxBytes($txBytes)
{
@@ -216,10 +237,88 @@ class NetDevice
*
* @see NetDevice::$_info
*
* @return Void
* @return void
*/
public function setInfo($info)
{
$this->_info = $info;
}
/**
* Returns $_bridge.
*
* @see NetDevice::$_bridge
*
* @return String
*/
public function getBridge()
{
return $this->_bridge;
}
/**
* Sets $_bridge.
*
* @param String $bridge bridge string
*
* @see NetDevice::$_bridge
*
* @return void
*/
public function setBridge($bridge)
{
$this->_bridge = $bridge;
}
/**
* Returns $_rxRate.
*
* @see NetDevice::$_rxRate
*
* @return int
*/
public function getRxRate()
{
return $this->_rxRate;
}
/**
* Sets $_rxRate.
*
* @param int $rxRate received bytes rate
*
* @see NetDevice::$_rxRate
*
* @return void
*/
public function setRxRate($rxRate)
{
$this->_rxRate = $rxRate;
}
/**
* Returns $_txRate.
*
* @see NetDevice::$_txRate
*
* @return int
*/
public function getTxRate()
{
return $this->_txRate;
}
/**
* Sets $_txRate.
*
* @param int $txRate transmitted bytes rate
*
* @see NetDevice::$_txRate
*
* @return void
*/
public function setTxRate($txRate)
{
$this->_txRate = $txRate;
}
}

View File

@@ -8,7 +8,7 @@
* @package PSI_TO
* @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 SVN: $Id: class.SensorDevice.inc.php 592 2012-07-03 10:55:51Z namiltd $
* @link http://phpsysinfo.sourceforge.net
*/
@@ -19,7 +19,7 @@
* @package PSI_TO
* @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
*/
@@ -28,44 +28,51 @@ class SensorDevice
/**
* name of the sensor
*
* @var String
* @var string
*/
private $_name = "";
/**
* current value of the sensor
*
* @var Integer
* @var int
*/
private $_value = 0;
/**
* maximum value of the sensor
*
* @var Integer
* @var int
*/
private $_max = null;
/**
* minimum value of the sensor
*
* @var Integer
* @var int
*/
private $_min = null;
/**
* event of the sensor
*
* @var String
* @var string
*/
private $_event = "";
/**
* unit of values of the sensor
*
* @var string
*/
private $_unit = "";
/**
* Returns $_max.
*
* @see Sensor::$_max
*
* @return Integer
* @return int
*/
public function getMax()
{
@@ -75,11 +82,11 @@ class SensorDevice
/**
* Sets $_max.
*
* @param Integer $max maximum value
* @param int $max maximum value
*
* @see Sensor::$_max
*
* @return Void
* @return void
*/
public function setMax($max)
{
@@ -91,7 +98,7 @@ class SensorDevice
*
* @see Sensor::$_min
*
* @return Integer
* @return int
*/
public function getMin()
{
@@ -101,11 +108,11 @@ class SensorDevice
/**
* Sets $_min.
*
* @param Integer $min minimum value
* @param int $min minimum value
*
* @see Sensor::$_min
*
* @return Void
* @return void
*/
public function setMin($min)
{
@@ -131,7 +138,7 @@ class SensorDevice
*
* @see Sensor::$_name
*
* @return Void
* @return void
*/
public function setName($name)
{
@@ -143,7 +150,7 @@ class SensorDevice
*
* @see Sensor::$_value
*
* @return Integer
* @return int
*/
public function getValue()
{
@@ -153,11 +160,11 @@ class SensorDevice
/**
* Sets $_value.
*
* @param Integer $value current value
* @param int $value current value
*
* @see Sensor::$_value
*
* @return Void
* @return void
*/
public function setValue($value)
{
@@ -183,10 +190,36 @@ class SensorDevice
*
* @see Sensor::$_event
*
* @return Void
* @return void
*/
public function setEvent($event)
{
$this->_event = $event;
}
/**
* Returns $_unit.
*
* @see Sensor::$_unit
*
* @return String
*/
public function getUnit()
{
return $this->_unit;
}
/**
* Sets $_unit.
*
* @param String $unit sensor unit
*
* @see Sensor::$_unit
*
* @return void
*/
public function setUnit($unit)
{
$this->_unit = $unit;
}
}

View File

@@ -8,7 +8,7 @@
* @package PSI_TO
* @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 SVN: $Id: class.UPSDevice.inc.php 262 2009-06-22 10:48:33Z bigmichi1 $
* @link http://phpsysinfo.sourceforge.net
*/
@@ -19,7 +19,7 @@
* @package PSI_TO
* @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
*/
@@ -28,121 +28,128 @@ class UPSDevice
/**
* name of the ups
*
* @var String
* @var string
*/
private $_name = "";
/**
* model of the ups
*
* @var String
* @var string
*/
private $_model = "";
/**
* mode of the ups
*
* @var String
* @var string
*/
private $_mode = "";
/**
* last start time
*
* @var String
* @var string
*/
private $_startTime = "";
/**
* status of the ups
*
* @var String
* @var string
*/
private $_status = "";
/**
* temperature of the ups
*
* @var Integer
* @var string
*/
private $_temperatur = null;
/**
* outages count
*
* @var Integer
* @var int
*/
private $_outages = null;
/**
* date of last outtage
*
* @var String
* @var string
*/
private $_lastOutage = null;
/**
* date of last outage finish
*
* @var String
* @var string
*/
private $_lastOutageFinish = null;
/**
* line volt
*
* @var Integer
* @var float
*/
private $_lineVoltage = null;
/**
* line freq
*
* @var Integer
* @var int
*/
private $_lineFrequency = null;
/**
* current load of the ups in percent
*
* @var Integer
* @var float
*/
private $_load = null;
/**
* battery installation date
*
* @var String
* @var string
*/
private $_batteryDate = null;
/**
* current battery volt
*
* @var Integer
* @var float
*/
private $_batteryVoltage = null;
/**
* current charge in percent of the battery
*
* @var Integer
* @var float
*/
private $_batterCharge = null;
/**
* time left
*
* @var String
* @var string
*/
private $_timeLeft = null;
/**
* beeper enabled or disabled
*
* @var string
*/
private $_beeperStatus = null;
/**
* Returns $_batterCharge.
*
* @see UPSDevice::$_batterCharge
*
* @return integer
* @return float
*/
public function getBatterCharge()
{
@@ -152,7 +159,7 @@ class UPSDevice
/**
* Sets $_batterCharge.
*
* @param Integer $batterCharge battery charge
* @param float $batterCharge battery charge
*
* @see UPSDevice::$_batterCharge
*
@@ -182,7 +189,7 @@ class UPSDevice
*
* @see UPSDevice::$_batteryDate
*
* @return Void
* @return void
*/
public function setBatteryDate($batteryDate)
{
@@ -194,7 +201,7 @@ class UPSDevice
*
* @see UPSDevice::$_batteryVoltage
*
* @return Integer
* @return float
*/
public function getBatteryVoltage()
{
@@ -204,11 +211,11 @@ class UPSDevice
/**
* Sets $_batteryVoltage.
*
* @param object $batteryVoltage battery volt
* @param float $batteryVoltage battery volt
*
* @see UPSDevice::$_batteryVoltage
*
* @return Void
* @return void
*/
public function setBatteryVoltage($batteryVoltage)
{
@@ -234,7 +241,7 @@ class UPSDevice
*
* @see UPSDevice::$lastOutage
*
* @return Void
* @return void
*/
public function setLastOutage($lastOutage)
{
@@ -260,7 +267,7 @@ class UPSDevice
*
* @see UPSDevice::$_lastOutageFinish
*
* @return Void
* @return void
*/
public function setLastOutageFinish($lastOutageFinish)
{
@@ -272,7 +279,7 @@ class UPSDevice
*
* @see UPSDevice::$_lineVoltage
*
* @return Integer
* @return float
*/
public function getLineVoltage()
{
@@ -282,11 +289,11 @@ class UPSDevice
/**
* Sets $_lineVoltage.
*
* @param Integer $lineVoltage line voltage
* @param float $lineVoltage line voltage
*
* @see UPSDevice::$_lineVoltage
*
* @return Void
* @return void
*/
public function setLineVoltage($lineVoltage)
{
@@ -298,7 +305,7 @@ class UPSDevice
*
* @see UPSDevice::$_lineFrequency
*
* @return Integer
* @return int
*/
public function getLineFrequency()
{
@@ -308,11 +315,11 @@ class UPSDevice
/**
* Sets $_lineFrequency.
*
* @param Integer $lineFrequency line frequency
* @param int $lineFrequency line frequency
*
* @see UPSDevice::$_lineFrequency
*
* @return Void
* @return void
*/
public function setLineFrequency($lineFrequency)
{
@@ -324,7 +331,7 @@ class UPSDevice
*
* @see UPSDevice::$_load
*
* @return Integer
* @return float
*/
public function getLoad()
{
@@ -334,11 +341,11 @@ class UPSDevice
/**
* Sets $_load.
*
* @param Integer $load current load
* @param float $load current load
*
* @see UPSDevice::$_load
*
* @return Void
* @return void
*/
public function setLoad($load)
{
@@ -364,7 +371,7 @@ class UPSDevice
*
* @see UPSDevice::$_mode
*
* @return Void
* @return void
*/
public function setMode($mode)
{
@@ -390,7 +397,7 @@ class UPSDevice
*
* @see UPSDevice::$_model
*
* @return Void
* @return void
*/
public function setModel($model)
{
@@ -416,7 +423,7 @@ class UPSDevice
*
* @see UPSDevice::$_name
*
* @return Void
* @return void
*/
public function setName($name)
{
@@ -428,7 +435,7 @@ class UPSDevice
*
* @see UPSDevice::$_outages
*
* @return Integer
* @return int
*/
public function getOutages()
{
@@ -438,11 +445,11 @@ class UPSDevice
/**
* Sets $_outages.
*
* @param Integer $outages outages count
* @param int $outages outages count
*
* @see UPSDevice::$_outages
*
* @return Void
* @return void
*/
public function setOutages($outages)
{
@@ -468,7 +475,7 @@ class UPSDevice
*
* @see UPSDevice::$_startTime
*
* @return Void
* @return void
*/
public function setStartTime($startTime)
{
@@ -494,7 +501,7 @@ class UPSDevice
*
* @see UPSDevice::$_status
*
* @return Void
* @return void
*/
public function setStatus($status)
{
@@ -506,7 +513,7 @@ class UPSDevice
*
* @see UPSDevice::$_temperatur
*
* @return Integer
* @return string
*/
public function getTemperatur()
{
@@ -516,11 +523,11 @@ class UPSDevice
/**
* Sets $_temperatur.
*
* @param Integer $temperatur temperature
* @param string $temperatur temperature
*
* @see UPSDevice::$_temperatur
*
* @return Void
* @return void
*/
public function setTemperatur($temperatur)
{
@@ -546,10 +553,36 @@ class UPSDevice
*
* @see UPSDevice::$_timeLeft
*
* @return Void
* @return void
*/
public function setTimeLeft($timeLeft)
{
$this->_timeLeft = $timeLeft;
}
/**
* Returns $_beeperStatus.
*
* @see UPSDevice::$_beeperStatus
*
* @return String
*/
public function getBeeperStatus()
{
return $this->_beeperStatus;
}
/**
* Sets $_beeperStatus.
*
* @param String $beeperStatus beeper status
*
* @see UPSDevice::$_beeperStatus
*
* @return void
*/
public function setBeeperStatus($beeperStatus)
{
$this->_beeperStatus = $beeperStatus;
}
}

View File

@@ -8,7 +8,7 @@
* @package PSI_UPS
* @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 SVN: $Id: class.apcupsd.inc.php 661 2012-08-27 11:26:39Z namiltd $
* @link http://phpsysinfo.sourceforge.net
*/
@@ -20,7 +20,7 @@
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @author Artem Volk <artvolk@mail.ru>
* @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
*/
@@ -29,7 +29,7 @@ class Apcupsd extends UPS
/**
* internal storage for all gathered data
*
* @var Array
* @var array
*/
private $_output = array();
@@ -39,22 +39,53 @@ class Apcupsd extends UPS
public function __construct()
{
parent::__construct();
if (defined('PSI_UPS_APCUPSD_LIST') && is_string(PSI_UPS_APCUPSD_LIST)) {
if (preg_match(ARRAY_EXP, PSI_UPS_APCUPSD_LIST)) {
$upses = eval(PSI_UPS_APCUPSD_LIST);
if (!defined('PSI_UPS_APCUPSD_ACCESS')) {
define('PSI_UPS_APCUPSD_ACCESS', false);
}
switch (strtolower(PSI_UPS_APCUPSD_ACCESS)) {
case 'data':
if (defined('PSI_UPS_APCUPSD_LIST') && is_string(PSI_UPS_APCUPSD_LIST)) {
if (preg_match(ARRAY_EXP, PSI_UPS_APCUPSD_LIST)) {
$upss = eval(PSI_UPS_APCUPSD_LIST);
} else {
$upss = array(PSI_UPS_APCUPSD_LIST);
}
} else {
$upses = array(PSI_UPS_APCUPSD_LIST);
$upss = array('UPS');
}
foreach ($upses as $ups) {
CommonFunctions::executeProgram('apcaccess', 'status '.trim($ups), $temp);
$un = 0;
foreach ($upss as $ups) {
$temp = "";
CommonFunctions::rftsdata("upsapcupsd{$un}.tmp", $temp);
if (! empty($temp)) {
$this->_output[] = $temp;
}
$un++;
}
} else { //use default if address and port not defined
CommonFunctions::executeProgram('apcaccess', 'status', $temp);
if (! empty($temp)) {
$this->_output[] = $temp;
break;
default:
if (defined('PSI_UPS_APCUPSD_LIST') && is_string(PSI_UPS_APCUPSD_LIST)) {
if (preg_match(ARRAY_EXP, PSI_UPS_APCUPSD_LIST)) {
$upses = eval(PSI_UPS_APCUPSD_LIST);
} else {
$upses = array(PSI_UPS_APCUPSD_LIST);
}
foreach ($upses as $ups) {
$temp = "";
CommonFunctions::executeProgram('apcaccess', 'status '.trim($ups), $temp);
if (! empty($temp)) {
$this->_output[] = $temp;
}
}
} else { //use default if address and port not defined
if (!defined('PSI_EMU_HOSTNAME') || defined('PSI_EMU_PORT')) {
CommonFunctions::executeProgram('apcaccess', 'status', $temp);
} else {
CommonFunctions::executeProgram('apcaccess', 'status '.PSI_EMU_HOSTNAME, $temp);
}
if (! empty($temp)) {
$this->_output[] = $temp;
}
}
}
}
@@ -62,7 +93,7 @@ class Apcupsd extends UPS
/**
* parse the input and store data in resultset for xml generation
*
* @return Void
* @return void
*/
private function _info()
{
@@ -75,7 +106,7 @@ class Apcupsd extends UPS
$dev->setName(trim($data[1]));
}
if (preg_match('/^MODEL\s*:\s*(.*)$/m', $ups, $data)) {
$model=trim($data[1]);
$model = trim($data[1]);
if (preg_match('/^APCMODEL\s*:\s*(.*)$/m', $ups, $data)) {
$dev->setModel($model.' ('.trim($data[1]).')');
} else {
@@ -92,7 +123,10 @@ class Apcupsd extends UPS
$dev->setStatus(trim($data[1]));
}
if (preg_match('/^ITEMP\s*:\s*(.*)$/m', $ups, $data)) {
$dev->setTemperatur(trim($data[1]));
$temperatur = trim($data[1]);
if (($temperatur !== "-273.1 C") && ($temperatur !== "-273.1 C Internal")) {
$dev->setTemperatur($temperatur);
}
}
// Outages
if (preg_match('/^NUMXFERS\s*:\s*(.*)$/m', $ups, $data)) {
@@ -136,7 +170,7 @@ class Apcupsd extends UPS
*
* @see PSI_Interface_UPS::build()
*
* @return Void
* @return void
*/
public function build()
{

View File

@@ -9,7 +9,7 @@
* @author Artem Volk <artvolk@mail.ru>
* @author Anders Häggström <hagge@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 SVN: $Id: class.nut.inc.php 661 2012-08-27 11:26:39Z namiltd $
* @link http://phpsysinfo.sourceforge.net
*/
@@ -21,7 +21,7 @@
* @author Artem Volk <artvolk@mail.ru>
* @author Anders Häggström <hagge@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
*/
@@ -40,29 +40,62 @@ class Nut extends UPS
public function __construct()
{
parent::__construct();
if (defined('PSI_UPS_NUT_LIST') && is_string(PSI_UPS_NUT_LIST)) {
if (preg_match(ARRAY_EXP, PSI_UPS_NUT_LIST)) {
$upses = eval(PSI_UPS_NUT_LIST);
if (!defined('PSI_UPS_NUT_ACCESS')) {
define('PSI_UPS_NUT_ACCESS', false);
}
switch (strtolower(PSI_UPS_NUT_ACCESS)) {
case 'data':
if (defined('PSI_UPS_NUT_LIST') && is_string(PSI_UPS_NUT_LIST)) {
if (preg_match(ARRAY_EXP, PSI_UPS_NUT_LIST)) {
$upss = eval(PSI_UPS_NUT_LIST);
} else {
$upss = array(PSI_UPS_NUT_LIST);
}
} else {
$upses = array(PSI_UPS_NUT_LIST);
$upss = array('UPS');
}
foreach ($upses as $ups) {
CommonFunctions::executeProgram('upsc', '-l '.trim($ups), $output);
$ups_names = preg_split("/\n/", $output, -1, PREG_SPLIT_NO_EMPTY);
foreach ($ups_names as $ups_name) {
CommonFunctions::executeProgram('upsc', trim($ups_name).'@'.trim($ups), $temp);
if (! empty($temp)) {
$this->_output[trim($ups_name).'@'.trim($ups)] = $temp;
$un = 0;
foreach ($upss as $ups) {
$temp = "";
CommonFunctions::rftsdata("upsnut{$un}.tmp", $temp);
if (! empty($temp)) {
$this->_output[$ups] = $temp;
}
$un++;
}
break;
default:
if (defined('PSI_UPS_NUT_LIST') && is_string(PSI_UPS_NUT_LIST)) {
if (preg_match(ARRAY_EXP, PSI_UPS_NUT_LIST)) {
$upses = eval(PSI_UPS_NUT_LIST);
} else {
$upses = array(PSI_UPS_NUT_LIST);
}
foreach ($upses as $ups) {
CommonFunctions::executeProgram('upsc', '-l '.trim($ups), $output, PSI_DEBUG);
$ups_names = preg_split("/\n/", $output, -1, PREG_SPLIT_NO_EMPTY);
foreach ($ups_names as $ups_name) {
$upsname = trim($ups_name).'@'.trim($ups);
$temp = "";
CommonFunctions::executeProgram('upsc', $upsname, $temp, PSI_DEBUG);
if (! empty($temp)) {
$this->_output[$upsname] = $temp;
}
}
}
}
} else { //use default if address and port not defined
CommonFunctions::executeProgram('upsc', '-l', $output);
$ups_names = preg_split("/\n/", $output, -1, PREG_SPLIT_NO_EMPTY);
foreach ($ups_names as $ups_name) {
CommonFunctions::executeProgram('upsc', trim($ups_name), $temp);
if (! empty($temp)) {
$this->_output[trim($ups_name)] = $temp;
} else { //use default if address and port not defined
if (!defined('PSI_EMU_HOSTNAME') || defined('PSI_EMU_PORT')) {
CommonFunctions::executeProgram('upsc', '-l', $output, PSI_DEBUG);
} else {
CommonFunctions::executeProgram('upsc', '-l '.PSI_EMU_HOSTNAME, $output, PSI_DEBUG);
}
$ups_names = preg_split("/\n/", $output, -1, PREG_SPLIT_NO_EMPTY);
foreach ($ups_names as $ups_name) {
$temp = "";
CommonFunctions::executeProgram('upsc', trim($ups_name), $temp, PSI_DEBUG);
if (! empty($temp)) {
$this->_output[trim($ups_name)] = $temp;
}
}
}
}
@@ -71,16 +104,16 @@ class Nut extends UPS
/**
* parse the input and store data in resultset for xml generation
*
* @return array
* @return void
*/
private function _info()
{
if (! empty($this->_output)) {
foreach ($this->_output as $name=>$value) {
foreach ($this->_output as $name => $value) {
$temp = preg_split("/\n/", $value, -1, PREG_SPLIT_NO_EMPTY);
$ups_data = array();
foreach ($temp as $value) {
$line = preg_split('/: /', $value, 2);
foreach ($temp as $valueTemp) {
$line = preg_split('/: /', $valueTemp, 2);
$ups_data[$line[0]] = isset($line[1]) ? trim($line[1]) : '';
}
$dev = new UPSDevice();
@@ -95,6 +128,9 @@ class Nut extends UPS
if (isset($ups_data['ups.status'])) {
$dev->setStatus($ups_data['ups.status']);
}
if (isset($ups_data['ups.beeper.status'])) {
$dev->setBeeperStatus($ups_data['ups.beeper.status']);
}
//Line
if (isset($ups_data['input.voltage'])) {
@@ -133,7 +169,7 @@ class Nut extends UPS
*
* @see PSI_Interface_UPS::build()
*
* @return Void
* @return void
*/
public function build()
{

View File

@@ -8,7 +8,7 @@
* @package PSI_UPS
* @author Robert Pelletier <drizzt@menzonet.org>
* @copyright 2014 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 SVN: $Id: class.nut.inc.php 661 2012-08-27 11:26:39Z namiltd $
* @link http://phpsysinfo.sourceforge.net
*/
@@ -19,7 +19,7 @@
* @package PSI_UPS
* @author Robert Pelletier <drizzt@menzonet.org>
* @copyright 2014 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
*/
@@ -38,41 +38,60 @@ class Pmset extends UPS
public function __construct()
{
parent::__construct();
CommonFunctions::executeProgram('pmset', '-g batt', $temp);
if (! empty($temp)) {
$this->_output[] = $temp;
if (defined('PSI_UPS_PMSET_ACCESS') && (strtolower(trim(PSI_UPS_PMSET_ACCESS))==='data')) {
if (CommonFunctions::rftsdata('upspmset.tmp', $temp)) {
$this->_output[] = $temp;
}
} elseif (PSI_OS == 'Darwin') {
if (CommonFunctions::executeProgram('pmset', '-g batt', $temp) && !empty($temp)) {
$this->_output[] = $temp;
}
}
}
/**
* parse the input and store data in resultset for xml generation
*
* @return array
* @return void
*/
private function _info()
{
if (empty($this->_output)) {
return;
}
$model = array();
$percCharge = array();
$lines = explode(PHP_EOL, implode($this->_output));
$dev = new UPSDevice();
$model = explode('FW:', $lines[1]);
if (strpos($model[0], 'InternalBattery') === false) {
$percCharge = explode(';', $lines[1]);
$dev->setName('UPS');
if ($model !== false) {
$dev->setModel(substr(trim($model[0]), 1));
}
if ($percCharge !== false) {
$dev->setBatterCharge(trim(substr($percCharge[0], -4, 3)));
$dev->setStatus(trim($percCharge[1]));
if (isset($percCharge[2])) {
$time = explode(':', $percCharge[2]);
$hours = $time[0];
$minutes = $hours*60+substr($time[1], 0, 2);
$dev->setTimeLeft($minutes);
if (count($lines)>1) {
if (strpos($lines[1], 'InternalBattery') === false) {
$dev = new UPSDevice();
$dev->setName('UPS');
$percCharge = explode(';', $lines[1]);
$model = explode('FW:', $lines[1]);
if ($model !== false) {
$dev->setModel(substr(trim($model[0]), 1));
}
if ($percCharge !== false) {
if (preg_match("/\s(\d+)\%$/", trim($percCharge[0]), $tmpbuf)) {
if ($tmpbuf[1]>100) {
$dev->setBatterCharge(100);
} else {
$dev->setBatterCharge($tmpbuf[1]);
}
}
$percCharge[1]=trim($percCharge[1]);
if (preg_match("/^(.+) present:/", $percCharge[1], $tmpbuf)) {
$dev->setStatus(trim($tmpbuf[1]));
} else {
$dev->setStatus($percCharge[1]);
}
if (isset($percCharge[2]) && preg_match("/\s(\d+):(\d+)\s/", $percCharge[2], $tmpbuf)) {
$dev->setTimeLeft($tmpbuf[1]*60+$tmpbuf[2]);
}
}
$dev->setMode("pmset");
$this->upsinfo->setUpsDevices($dev);
}
$this->upsinfo->setUpsDevices($dev);
}
}
@@ -81,7 +100,7 @@ class Pmset extends UPS
*
* @see PSI_Interface_UPS::build()
*
* @return Void
* @return void
*/
public function build()
{

View File

@@ -8,7 +8,7 @@
* @package PSI_UPS
* @author Mieczyslaw Nalewaj <namiltd@users.sourceforge.net>
* @copyright 2014 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 SVN: $Id: class.powersoftplus.inc.php 661 2014-06-13 11:26:39Z namiltd $
* @link http://phpsysinfo.sourceforge.net
*/
@@ -19,7 +19,7 @@
* @package PSI_UPS
* @author Mieczyslaw Nalewaj <namiltd@users.sourceforge.net>
* @copyright 2014 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
*/
@@ -28,7 +28,7 @@ class PowerSoftPlus extends UPS
/**
* internal storage for all gathered data
*
* @var Array
* @var array
*/
private $_output = array();
@@ -38,16 +38,23 @@ class PowerSoftPlus extends UPS
public function __construct()
{
parent::__construct();
CommonFunctions::executeProgram('powersoftplus', '-p', $temp);
if (! empty($temp)) {
$this->_output[] = $temp;
if (defined('PSI_UPS_POWERSOFTPLUS_ACCESS') && (strtolower(trim(PSI_UPS_POWERSOFTPLUS_ACCESS))==='data')) {
CommonFunctions::rftsdata('upspowersoftplus.tmp', $temp);
if (! empty($temp)) {
$this->_output[] = $temp;
}
} elseif (PSI_OS == 'Linux') {
CommonFunctions::executeProgram('powersoftplus', '-p', $temp);
if (! empty($temp)) {
$this->_output[] = $temp;
}
}
}
/**
* parse the input and store data in resultset for xml generation
*
* @return Void
* @return void
*/
private function _info()
{
@@ -69,18 +76,18 @@ class PowerSoftPlus extends UPS
if (preg_match('/^Current UPS state\s*:\s*(.*)$/m', $ups, $data)) {
$dev->setStatus(trim($data[1]));
}
if (preg_match('/^Output load\s*:\s*(.*)\s\[\%\]$/m', $ups, $data)) {
if (preg_match('/^Output load\s*:\s*(.*)\s\[\%\]\r?$/m', $ups, $data)) {
$load = trim($data[1]);
}
//wrong Output load issue
if (($load == 0) && ($maxpwr != 0) && preg_match('/^Effective power\s*:\s*(.*)\s\[W\]$/m', $ups, $data)) {
if (($load == 0) && ($maxpwr != 0) && preg_match('/^Effective power\s*:\s*(.*)\s\[W\]\r?$/m', $ups, $data)) {
$load = 100.0*trim($data[1])/$maxpwr;
}
if ($load != null) {
$dev->setLoad($load);
}
// Battery
if (preg_match('/^Battery voltage\s*:\s*(.*)\s\[Volt\]$/m', $ups, $data)) {
if (preg_match('/^Battery voltage\s*:\s*(.*)\s\[Volt\]\r?$/m', $ups, $data)) {
$dev->setBatteryVoltage(trim($data[1]));
}
if (preg_match('/^Battery state\s*:\s*(.*)$/m', $ups, $data)) {
@@ -91,10 +98,10 @@ class PowerSoftPlus extends UPS
}
}
// Line
if (preg_match('/^Input voltage\s*:\s*(.*)\s\[Volt\]$/m', $ups, $data)) {
if (preg_match('/^Input voltage\s*:\s*(.*)\s\[Volt\]\r?$/m', $ups, $data)) {
$dev->setLineVoltage(trim($data[1]));
}
if (preg_match('/^Input frequency\s*:\s*(.*)\s\[Hz\]$/m', $ups, $data)) {
if (preg_match('/^Input frequency\s*:\s*(.*)\s\[Hz\]\r?$/m', $ups, $data)) {
$dev->setLineFrequency(trim($data[1]));
}
$this->upsinfo->setUpsDevices($dev);
@@ -106,7 +113,7 @@ class PowerSoftPlus extends UPS
*
* @see PSI_Interface_UPS::build()
*
* @return Void
* @return void
*/
public function build()
{

View File

@@ -0,0 +1,292 @@
<?php
/**
* SNMPups class
*
* PHP version 5
*
* @category PHP
* @package PSI_UPS
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License version 2, or (at your option) any later version
* @version SVN: $Id: class.apcupsd.inc.php 661 2012-08-27 11:26:39Z namiltd $
* @link http://phpsysinfo.sourceforge.net
*/
/**
* getting ups information from SNMPups program
*
* @category PHP
* @package PSI_UPS
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @author Artem Volk <artvolk@mail.ru>
* @copyright 2009 phpSysInfo
* @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
*/
class SNMPups extends UPS
{
/**
* internal storage for all gathered data
*
* @var array
*/
private $_output = array();
/**
* get all information from all configured ups in phpsysinfo.ini and store output in internal array
*/
public function __construct()
{
parent::__construct();
if (!defined('PSI_UPS_SNMPUPS_ACCESS')) {
define('PSI_UPS_SNMPUPS_ACCESS', 'php-snmp');
}
switch (strtolower(PSI_UPS_SNMPUPS_ACCESS)) {
case 'data':
if (defined('PSI_UPS_SNMPUPS_LIST') && is_string(PSI_UPS_SNMPUPS_LIST)) {
if (preg_match(ARRAY_EXP, PSI_UPS_SNMPUPS_LIST)) {
$upss = eval(PSI_UPS_SNMPUPS_LIST);
} else {
$upss = array(PSI_UPS_SNMPUPS_LIST);
}
} else {
$upss = array('UPS');
}
$un = 0;
foreach ($upss as $ups) {
$temp = "";
CommonFunctions::rftsdata("upssnmpups{$un}.tmp", $temp);
if (! empty($temp)) {
$this->_output[] = $temp;
}
$un++;
}
break;
case 'command':
if (defined('PSI_UPS_SNMPUPS_LIST') && is_string(PSI_UPS_SNMPUPS_LIST)) {
if (preg_match(ARRAY_EXP, PSI_UPS_SNMPUPS_LIST)) {
$upss = eval(PSI_UPS_SNMPUPS_LIST);
} else {
$upss = array(PSI_UPS_SNMPUPS_LIST);
}
foreach ($upss as $ups) {
$buffer = "";
CommonFunctions::executeProgram("snmpwalk", "-Ona -c public -v 1 -t ".PSI_SNMP_TIMEOUT_INT." -r ".PSI_SNMP_RETRY_INT." ".$ups." .1.3.6.1.4.1.318.1.1.1.1", $buffer, PSI_DEBUG);
if (strlen($buffer) > 0) {
$this->_output[$ups] = $buffer;
$buffer = "";
CommonFunctions::executeProgram("snmpwalk", "-Ona -c public -v 1 -t ".PSI_SNMP_TIMEOUT_INT." -r ".PSI_SNMP_RETRY_INT." ".$ups." .1.3.6.1.4.1.318.1.1.1.2", $buffer, PSI_DEBUG);
if (strlen($buffer) > 0) {
$this->_output[$ups] .= "\n".$buffer;
}
$buffer = "";
CommonFunctions::executeProgram("snmpwalk", "-Ona -c public -v 1 -t ".PSI_SNMP_TIMEOUT_INT." -r ".PSI_SNMP_RETRY_INT." ".$ups." .1.3.6.1.4.1.318.1.1.1.3", $buffer, PSI_DEBUG);
if (strlen($buffer) > 0) {
$this->_output[$ups] .= "\n".$buffer;
}
$buffer = "";
CommonFunctions::executeProgram("snmpwalk", "-Ona -c public -v 1 -t ".PSI_SNMP_TIMEOUT_INT." -r ".PSI_SNMP_RETRY_INT." ".$ups." .1.3.6.1.4.1.318.1.1.1.4", $buffer, PSI_DEBUG);
if (strlen($buffer) > 0) {
$this->_output[$ups] .= "\n".$buffer;
}
}
}
}
break;
case 'php-snmp':
if (!extension_loaded("snmp")) {
$this->error->addError("Requirements error", "SNMPups plugin requires the snmp extension to php in order to work properly");
break;
}
snmp_set_valueretrieval(SNMP_VALUE_LIBRARY);
snmp_set_oid_output_format(SNMP_OID_OUTPUT_NUMERIC);
if (defined('PSI_UPS_SNMPUPS_LIST') && is_string(PSI_UPS_SNMPUPS_LIST)) {
if (preg_match(ARRAY_EXP, PSI_UPS_SNMPUPS_LIST)) {
$upss = eval(PSI_UPS_SNMPUPS_LIST);
} else {
$upss = array(PSI_UPS_SNMPUPS_LIST);
}
foreach ($upss as $ups) {
if (! PSI_DEBUG) {
restore_error_handler(); /* default error handler */
$old_err_rep = error_reporting();
error_reporting(E_ERROR); /* fatal errors only */
}
$bufferarr=snmprealwalk($ups, "public", ".1.3.6.1.4.1.318.1.1.1.1", 1000000 * PSI_SNMP_TIMEOUT_INT, PSI_SNMP_RETRY_INT);
if (! PSI_DEBUG) {
error_reporting($old_err_rep); /* restore error level */
set_error_handler('errorHandlerPsi'); /* restore error handler */
}
if (! empty($bufferarr)) {
$buffer="";
foreach ($bufferarr as $id=>$string) {
$buffer .= $id." = ".$string."\n";
}
if (! PSI_DEBUG) {
restore_error_handler(); /* default error handler */
$old_err_rep = error_reporting();
error_reporting(E_ERROR); /* fatal errors only */
}
$bufferarr2=snmprealwalk($ups, "public", ".1.3.6.1.4.1.318.1.1.1.2", 1000000 * PSI_SNMP_TIMEOUT_INT, PSI_SNMP_RETRY_INT);
$bufferarr3=snmprealwalk($ups, "public", ".1.3.6.1.4.1.318.1.1.1.3", 1000000 * PSI_SNMP_TIMEOUT_INT, PSI_SNMP_RETRY_INT);
$bufferarr4=snmprealwalk($ups, "public", ".1.3.6.1.4.1.318.1.1.1.4", 1000000 * PSI_SNMP_TIMEOUT_INT, PSI_SNMP_RETRY_INT);
if (! PSI_DEBUG) {
error_reporting($old_err_rep); /* restore error level */
set_error_handler('errorHandlerPsi'); /* restore error handler */
}
if (! empty($bufferarr2)) {
foreach ($bufferarr2 as $id=>$string) {
$buffer .= $id." = ".$string."\n";
}
}
if (! empty($bufferarr3)) {
foreach ($bufferarr3 as $id=>$string) {
$buffer .= $id." = ".$string."\n";
}
}
if (! empty($bufferarr4)) {
foreach ($bufferarr4 as $id=>$string) {
$buffer .= $id." = ".$string."\n";
}
}
if (strlen(trim($buffer)) > 0) {
$this->_output[$ups] = $buffer;
}
}
}
}
break;
default:
$this->error->addError("switch(PSI_UPS_SNMPUPS_ACCESS)", "Bad SNMPups configuration in phpsysinfo.ini");
}
}
/**
* parse the input and store data in resultset for xml generation
*
* @return void
*/
private function _info()
{
if (empty($this->_output)) {
return;
}
foreach ($this->_output as $result) {
$dev = new UPSDevice();
$status = "";
$status2 = "";
$status3 = "";
$dev->setMode("SNMP");
if (preg_match('/^\.1\.3\.6\.1\.4\.1\.318\.1\.1\.1\.1\.1\.2\.0 = STRING:\s(.*)/m', $result, $data)) {
$dev->setName(trim($data[1], "\" \r\t"));
}
if (preg_match('/^\.1\.3\.6\.1\.4\.1\.318\.1\.1\.1\.1\.1\.1\.0 = STRING:\s(.*)/m', $result, $data)) {
$dev->setModel(trim($data[1], "\" \r\t"));
}
if (preg_match('/^\.1\.3\.6\.1\.4\.1\.318\.1\.1\.1\.4\.1\.1\.0 = INTEGER:\s(.*)/m', $result, $data)) {
switch (trim($data[1])) {
case 1: $status = "Unknown"; break;
case 2: $status = "On Line"; break;
case 3: $status = "On Battery"; break;
case 4: $status = "On Smart Boost"; break;
case 5: $status = "Timed Sleeping"; break;
case 6: $status = "Software Bypass"; break;
case 7: $status = "Off"; break;
case 8: $status = "Rebooting"; break;
case 9: $status = "Switched Bypass"; break;
case 10:$status = "Hardware Failure Bypass"; break;
case 11:$status = "Sleeping Until Power Returns"; break;
case 12:$status = "On Smart Trim"; break;
default: $status = "Unknown state (".trim($data[1]).")";
}
}
if (preg_match('/^\.1\.3\.6\.1\.4\.1\.318\.1\.1\.1\.2\.1\.1\.0 = INTEGER:\s(.*)/m', $result, $data)) {
$batstat = "";
switch (trim($data[1])) {
case 1: $batstat = "Battery Unknown"; break;
case 2: break;
case 3: $batstat = "Battery Low"; break;
default: $batstat = "Battery Unknown (".trim($data[1]).")";
}
if ($batstat !== "") {
if ($status !== "") {
$status .= ", ".$batstat;
} else {
$status = $batstat;
}
}
}
if (preg_match('/^\.1\.3\.6\.1\.4\.1\.318\.1\.1\.1\.2\.2\.4\.0 = INTEGER:\s(.*)/m', $result, $data)) {
$batstat = "";
switch (trim($data[1])) {
case 1: break;
case 2: $batstat = "Replace Battery"; break;
default: $batstat = "Replace Battery (".trim($data[1]).")";
}
if ($batstat !== "") {
if ($status !== "") {
$status .= ", ".$batstat;
} else {
$status = $batstat;
}
}
}
if ($status !== "") {
$dev->setStatus(trim($status));
}
if (preg_match('/^\.1\.3\.6\.1\.4\.1\.318\.1\.1\.1\.3\.3\.1\.0 = Gauge32:\s(.*)/m', $result, $data)) {
$dev->setLineVoltage(trim($data[1])/10);
} elseif (preg_match('/^\.1\.3\.6\.1\.4\.1\.318\.1\.1\.1\.3\.2\.1\.0 = Gauge32:\s(.*)/m', $result, $data)) {
$dev->setLineVoltage(trim($data[1]));
}
if (preg_match('/^\.1\.3\.6\.1\.4\.1\.318\.1\.1\.1\.4\.3\.3\.0 = Gauge32:\s(.*)/m', $result, $data)) {
$dev->setLoad(trim($data[1])/10);
} elseif (preg_match('/^\.1\.3\.6\.1\.4\.1\.318\.1\.1\.1\.4\.2\.3\.0 = Gauge32:\s(.*)/m', $result, $data)) {
$dev->setLoad(trim($data[1]));
}
if (preg_match('/^\.1\.3\.6\.1\.4\.1\.318\.1\.1\.1\.2\.3\.4\.0 = INTEGER:\s(.*)/m', $result, $data)) {
$dev->setBatteryVoltage(trim($data[1])/10);
} elseif (preg_match('/^\.1\.3\.6\.1\.4\.1\.318\.1\.1\.1\.2\.2\.8\.0 = INTEGER:\s(.*)/m', $result, $data)) {
$dev->setBatteryVoltage(trim($data[1]));
}
if (preg_match('/^\.1\.3\.6\.1\.4\.1\.318\.1\.1\.1\.2\.3\.1\.0 = Gauge32:\s(.*)/m', $result, $data)) {
$dev->setBatterCharge(trim($data[1])/10);
} elseif (preg_match('/^\.1\.3\.6\.1\.4\.1\.318\.1\.1\.1\.2\.2\.1\.0 = Gauge32:\s(.*)/m', $result, $data)) {
$dev->setBatterCharge(trim($data[1]));
}
if (preg_match('/^\.1\.3\.6\.1\.4\.1\.318\.1\.1\.1\.2\.2\.3\.0 = Timeticks:\s\((\d*)\)/m', $result, $data)) {
$dev->setTimeLeft(trim($data[1])/6000);
}
if (preg_match('/^\.1\.3\.6\.1\.4\.1\.318\.1\.1\.1\.2\.3\.2\.0 = Gauge32:\s(.*)/m', $result, $data)) {
$dev->setTemperatur(trim($data[1])/10);
} elseif (preg_match('/^\.1\.3\.6\.1\.4\.1\.318\.1\.1\.1\.2\.2\.2\.0 = Gauge32:\s(.*)/m', $result, $data)) {
$dev->setTemperatur(trim($data[1]));
}
if (preg_match('/^\.1\.3\.6\.1\.4\.1\.318\.1\.1\.1\.2\.1\.3\.0 = STRING:\s(.*)/m', $result, $data)) {
$dev->setBatteryDate(trim($data[1], "\" \r\t"));
}
if (preg_match('/^\.1\.3\.6\.1\.4\.1\.318\.1\.1\.1\.3\.3\.4\.0 = Gauge32:\s(.*)/m', $result, $data)) {
$dev->setLineFrequency(trim($data[1])/10);
} elseif (preg_match('/^\.1\.3\.6\.1\.4\.1\.318\.1\.1\.1\.3\.2\.4\.0 = Gauge32:\s(.*)/m', $result, $data)) {
$dev->setLineFrequency(trim($data[1]));
}
$this->upsinfo->setUpsDevices($dev);
}
}
/**
* get the information
*
* @see PSI_Interface_UPS::build()
*
* @return void
*/
public function build()
{
$this->_info();
}
}

View File

@@ -8,7 +8,7 @@
* @package PSI_UPS
* @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 SVN: $Id: class.ups.inc.php 661 2012-08-27 11:26:39Z namiltd $
* @link http://phpsysinfo.sourceforge.net
*/
@@ -19,7 +19,7 @@
* @package PSI_UPS
* @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
*/
@@ -28,9 +28,9 @@ abstract class UPS implements PSI_Interface_UPS
/**
* object for error handling
*
* @var Error
* @var PSI_Error
*/
protected $error;
public $error;
/**
* main object for ups information
@@ -44,7 +44,7 @@ abstract class UPS implements PSI_Interface_UPS
*/
public function __construct()
{
$this->error = Error::singleton();
$this->error = PSI_Error::singleton();
$this->upsinfo = new UPSInfo();
}

View File

@@ -8,7 +8,7 @@
* @package PSI_XML
* @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 SVN: $Id: class.SimpleXMLExtended.inc.php 610 2012-07-11 19:12:12Z namiltd $
* @link http://phpsysinfo.sourceforge.net
*/
@@ -19,7 +19,7 @@
* @package PSI_XML
* @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
*/
@@ -28,7 +28,7 @@ class SimpleXMLExtended
/**
* store the encoding that is used for conversation to utf8
*
* @var String base encoding
* @var string base encoding
*/
private $_encoding = null;
@@ -42,7 +42,7 @@ class SimpleXMLExtended
/**
* _CP437toUTF8Table for code page conversion for CP437
*
* @var _CP437toUTF8Table array
* @var array _CP437toUTF8Table array
*/
private static $_CP437toUTF8Table = array(
"\xC3\x87","\xC3\xBC","\xC3\xA9","\xC3\xA2",
@@ -108,7 +108,7 @@ class SimpleXMLExtended
if ($value == null) {
return new SimpleXMLExtended($this->_SimpleXmlElement->addChild($nameUtf8), $this->_encoding);
} else {
$valueUtf8 = htmlspecialchars($this->_toUTF8($value));
$valueUtf8 = htmlspecialchars($this->_toUTF8($value), ENT_COMPAT, "UTF-8");
return new SimpleXMLExtended($this->_SimpleXmlElement->addChild($nameUtf8, $valueUtf8), $this->_encoding);
}
@@ -139,13 +139,17 @@ class SimpleXMLExtended
* @param String $name name of the attribute
* @param String $value value of the attribute
*
* @return Void
* @return void
*/
public function addAttribute($name, $value)
{
$nameUtf8 = $this->_toUTF8($name);
$valueUtf8 = htmlspecialchars($this->_toUTF8($value));
$this->_SimpleXmlElement->addAttribute($nameUtf8, $valueUtf8);
$valueUtf8 = htmlspecialchars($this->_toUTF8($value), ENT_COMPAT, "UTF-8");
if (($valueUtf8 === "") && (version_compare("5.2.2", PHP_VERSION, ">"))) {
$this->_SimpleXmlElement->addAttribute($nameUtf8, "\0"); // Fixing bug #41175 (addAttribute() fails to add an attribute with an empty value)
} else {
$this->_SimpleXmlElement->addAttribute($nameUtf8, $valueUtf8);
}
}
/**
@@ -153,7 +157,7 @@ class SimpleXMLExtended
*
* @param SimpleXMLElement $new_child child that should be appended
*
* @return Void
* @return void
*/
public function combinexml(SimpleXMLElement $new_child)
{
@@ -172,31 +176,46 @@ class SimpleXMLExtended
*/
private function _toUTF8($str)
{
$str = trim(preg_replace('/[\x00-\x09\x0b-\x1F]/', ' ', strval($str))); //remove nonprintable characters
if ($this->_encoding != null) {
if (strcasecmp($this->_encoding, "UTF-8") == 0) {
return trim($str);
return $str;
} elseif (strcasecmp($this->_encoding, "CP437") == 0) {
$str = trim($str);
$strr = "";
if (($strl = strlen($str)) > 0) for ($i = 0; $i < $strl; $i++) {
$strc = substr($str, $i, 1);
if ($strc < 128) $strr.=$strc;
else $strr.=$_CP437toUTF8Table[$strc-128];
else $strr.=self::$_CP437toUTF8Table[$strc-128];
}
return $strr;
} else {
$enclist = mb_list_encodings();
if (in_array($this->_encoding, $enclist)) {
return mb_convert_encoding(trim($str), 'UTF-8', $this->_encoding);
} elseif (function_exists("iconv")) {
return iconv($this->_encoding, 'UTF-8', trim($str));
if (preg_match("/^windows-\d+ \((.+)\)$/", $this->_encoding, $buf)) {
$encoding = $buf[1];
} else {
return mb_convert_encoding(trim($str), 'UTF-8');
$encoding = $this->_encoding;
}
}
$enclist = mb_list_encodings();
if (in_array($encoding, $enclist)) {
return mb_convert_encoding($str, 'UTF-8', $encoding);
} elseif (function_exists("iconv")) {
if (($iconvout=iconv($encoding, 'UTF-8', $str))!==false) {
return $iconvout;
} else {
return mb_convert_encoding($str, 'UTF-8');
}
} elseif (function_exists("libiconv") && (($iconvout=libiconv($encoding, 'UTF-8', $str))!==false)) {
return $iconvout;
} else {
return mb_convert_encoding($str, 'UTF-8');
}
}
} else {
return mb_convert_encoding(trim($str), 'UTF-8');
if (function_exists('mb_convert_encoding')) {
return mb_convert_encoding($str, 'UTF-8');
} else {
return $str;
}
}
}

View File

@@ -8,7 +8,7 @@
* @package PSI_XML
* @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 SVN: $Id: class.XML.inc.php 699 2012-09-15 11:57:13Z namiltd $
* @link http://phpsysinfo.sourceforge.net
*/
@@ -19,7 +19,7 @@
* @package PSI_XML
* @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
*/
@@ -47,7 +47,7 @@ class XML
/**
* object for error handling
*
* @var Error
* @var PSI_Error
*/
private $_errors;
@@ -65,13 +65,6 @@ class XML
*/
private $_plugin = '';
/**
* generate a xml for a plugin or for the main app
*
* @var boolean
*/
private $_plugin_request = false;
/**
* generate the entire xml with all plugins or only a part of the xml (main or plugin)
*
@@ -90,23 +83,23 @@ class XML
*
* @return void
*/
public function __construct($complete = false, $pluginname = "")
public function __construct($complete = false, $pluginname = "", $blockname = false)
{
$this->_errors = Error::singleton();
if ($pluginname == "") {
$this->_plugin_request = false;
$this->_plugin = '';
} else {
$this->_plugin_request = true;
$this->_plugin = $pluginname;
}
$this->_errors = PSI_Error::singleton();
$this->_plugin = $pluginname;
if ($complete) {
$this->_complete_request = true;
} else {
$this->_complete_request = false;
}
$os = PSI_OS;
$this->_sysinfo = new $os();
if (defined('PSI_EMU_PORT')) {
$os = 'SSH';
} elseif (defined('PSI_EMU_HOSTNAME')) {
$os = 'WINNT';
} else {
$os = PSI_OS;
}
$this->_sysinfo = new $os($blockname);
$this->_plugins = CommonFunctions::getPlugins();
$this->_xmlbody();
}
@@ -169,7 +162,14 @@ class XML
}
}
}
$vitals->addAttribute('OS', PSI_OS);
if (($os = $this->_sys->getOS()) == 'Android') {
$vitals->addAttribute('OS', 'Linux');
} elseif ($os == 'GNU') {
$vitals->addAttribute('OS', 'Hurd');
} else {
$vitals->addAttribute('OS', $os);
}
}
/**
@@ -193,15 +193,50 @@ class XML
}
}
foreach ($this->_sys->getNetDevices() as $dev) {
if (!in_array(trim($dev->getName()), $hideDevices)) {
if (defined('PSI_HIDE_NETWORK_INTERFACE_REGEX') && PSI_HIDE_NETWORK_INTERFACE_REGEX) {
$hide = false;
foreach ($hideDevices as $hidedev) {
if (preg_match('/^'.$hidedev.'$/', trim($dev->getName()))) {
$hide = true;
break;
}
}
} else {
$hide =in_array(trim($dev->getName()), $hideDevices);
}
if (!$hide) {
$device = $network->addChild('NetDevice');
$device->addAttribute('Name', $dev->getName());
$device->addAttribute('RxBytes', $dev->getRxBytes());
$device->addAttribute('TxBytes', $dev->getTxBytes());
$rxbytes = $dev->getRxBytes();
$txbytes = $dev->getTxBytes();
$device->addAttribute('RxBytes', $rxbytes);
$device->addAttribute('TxBytes', $txbytes);
if (defined('PSI_SHOW_NETWORK_ACTIVE_SPEED') && PSI_SHOW_NETWORK_ACTIVE_SPEED) {
if (($rxbytes == 0) && ($txbytes == 0)) {
$rxrate = $dev->getRxRate();
$txrate = $dev->getTxRate();
if (($rxrate !== null) || ($txrate !== null)) {
if ($rxrate !== null) {
$device->addAttribute('RxRate', $rxrate);
} else {
$device->addAttribute('RxRate', 0);
}
if ($txrate !== null) {
$device->addAttribute('TxRate', $txrate);
} else {
$device->addAttribute('TxRate', 0);
}
}
}
}
$device->addAttribute('Err', $dev->getErrors());
$device->addAttribute('Drops', $dev->getDrops());
if (defined('PSI_SHOW_NETWORK_INFOS') && PSI_SHOW_NETWORK_INFOS && $dev->getInfo())
if (defined('PSI_SHOW_NETWORK_BRIDGE') && PSI_SHOW_NETWORK_BRIDGE && $dev->getBridge()) {
$device->addAttribute('Bridge', $dev->getBridge());
}
if (defined('PSI_SHOW_NETWORK_INFOS') && PSI_SHOW_NETWORK_INFOS && $dev->getInfo()) {
$device->addAttribute('Info', $dev->getInfo());
}
}
}
}
@@ -213,77 +248,90 @@ class XML
*/
private function _buildHardware()
{
$dev = new HWDevice();
$hardware = $this->_xml->addChild('Hardware');
if ($this->_sys->getMachine() != "") {
$hardware->addAttribute('Name', $this->_sys->getMachine());
}
$pci = null;
foreach (System::removeDupsAndCount($this->_sys->getPciDevices()) as $dev) {
if ($pci === null) $pci = $hardware->addChild('PCI');
$tmp = $pci->addChild('Device');
$tmp->addAttribute('Name', $dev->getName());
$tmp->addAttribute('Count', $dev->getCount());
}
$usb = null;
foreach (System::removeDupsAndCount($this->_sys->getUsbDevices()) as $dev) {
if ($usb === null) $usb = $hardware->addChild('USB');
$tmp = $usb->addChild('Device');
$tmp->addAttribute('Name', $dev->getName());
$tmp->addAttribute('Count', $dev->getCount());
}
$ide = null;
foreach (System::removeDupsAndCount($this->_sys->getIdeDevices()) as $dev) {
if ($ide === null) $ide = $hardware->addChild('IDE');
$tmp = $ide->addChild('Device');
$tmp->addAttribute('Name', $dev->getName());
$tmp->addAttribute('Count', $dev->getCount());
if ($dev->getCapacity() !== null) {
$tmp->addAttribute('Capacity', $dev->getCapacity());
if (($machine = $this->_sys->getMachine()) != "") {
$machine = trim(preg_replace("/\s+/", " ", preg_replace("/^\s*[\/,]*/", "", preg_replace("/\/\s+,/", "/,", $machine)))); // remove leading slash or comma and unnecessary spaces
if (preg_match('/, BIOS .*$/', $machine, $mbuf, PREG_OFFSET_CAPTURE)) {
$comapos = $mbuf[0][1];
$endstr = $mbuf[0][0];
$offset = 0;
while (($offset < $comapos)
&& (($slashpos = strpos($machine, "/", $offset)) !== false)
&& ($slashpos < $comapos)) {
$len1 = $comapos - $slashpos - 1;
$str1 = substr($machine, $slashpos + 1, $len1);
$begstr = substr($machine, 0, $slashpos);
if ($len1 > 0) { // no empty
$str2 = substr($begstr, -$len1 - 1);
} else {
$str2 = " ";
}
if ((" ".$str1 === $str2) || ($str1 === $begstr)) { // duplicates
$machine = $begstr.$endstr;
break;
}
$offset = $slashpos + 1;
}
}
if ($machine != "") {
$hardware->addAttribute('Name', $machine);
}
}
$scsi = null;
foreach (System::removeDupsAndCount($this->_sys->getScsiDevices()) as $dev) {
if ($scsi === null) $scsi = $hardware->addChild('SCSI');
$tmp = $scsi->addChild('Device');
$tmp->addAttribute('Name', $dev->getName());
$tmp->addAttribute('Count', $dev->getCount());
if ($dev->getCapacity() !== null) {
$tmp->addAttribute('Capacity', $dev->getCapacity());
if (defined('PSI_SHOW_VIRTUALIZER_INFO') && PSI_SHOW_VIRTUALIZER_INFO) {
$virt = $this->_sys->getVirtualizer();
$virtstring = "";
foreach ($virt as $virtkey=>$virtvalue) if ($virtvalue) {
if ($virtstring !== "") {
$virtstring .= ", ";
}
if ($virtkey === 'microsoft') {
if (!isset($virt["wsl"]) || !$virt["wsl"]) {
$virtstring .= 'hyper-v';
}
} elseif ($virtkey === 'kvm') {
$virtstring .= 'qemu-kvm';
} elseif ($virtkey === 'oracle') {
$virtstring .= 'virtualbox';
} elseif ($virtkey === 'zvm') {
$virtstring .= 'z/vm';
} elseif ($virtkey === 'sre') {
$virtstring .= 'lmhs sre';
} else {
$virtstring .= $virtkey;
}
}
if ($virtstring !== "") {
$hardware->addAttribute('Virtualizer', $virtstring);
}
}
$tb = null;
foreach (System::removeDupsAndCount($this->_sys->getTbDevices()) as $dev) {
if ($tb === null) $tb = $hardware->addChild('TB');
$tmp = $tb->addChild('Device');
$tmp->addAttribute('Name', $dev->getName());
$tmp->addAttribute('Count', $dev->getCount());
}
$i2c = null;
foreach (System::removeDupsAndCount($this->_sys->getI2cDevices()) as $dev) {
if ($i2c === null) $i2c = $hardware->addChild('I2C');
$tmp = $i2c->addChild('Device');
$tmp->addAttribute('Name', $dev->getName());
$tmp->addAttribute('Count', $dev->getCount());
}
$cpu = null;
$vendortab = null;
foreach ($this->_sys->getCpus() as $oneCpu) {
if ($cpu === null) $cpu = $hardware->addChild('CPU');
$tmp = $cpu->addChild('CpuCore');
$tmp->addAttribute('Model', $oneCpu->getModel());
if ($oneCpu->getCpuSpeed() !== 0) {
$tmp->addAttribute('CpuSpeed', $oneCpu->getCpuSpeed());
if ($oneCpu->getVoltage() > 0) {
$tmp->addAttribute('Voltage', $oneCpu->getVoltage());
}
if ($oneCpu->getCpuSpeedMax() !== 0) {
if ($oneCpu->getCpuSpeed() > 0) {
$tmp->addAttribute('CpuSpeed', $oneCpu->getCpuSpeed());
} elseif ($oneCpu->getCpuSpeed() == -1) {
$tmp->addAttribute('CpuSpeed', 0); // core stopped
}
if ($oneCpu->getCpuSpeedMax() > 0) {
$tmp->addAttribute('CpuSpeedMax', $oneCpu->getCpuSpeedMax());
}
if ($oneCpu->getCpuSpeedMin() !== 0) {
if ($oneCpu->getCpuSpeedMin() > 0) {
$tmp->addAttribute('CpuSpeedMin', $oneCpu->getCpuSpeedMin());
}
/*
if ($oneCpu->getTemp() !== null) {
$tmp->addAttribute('CpuTemp', $oneCpu->getTemp());
}
*/
if ($oneCpu->getBusSpeed() !== null) {
$tmp->addAttribute('BusSpeed', $oneCpu->getBusSpeed());
}
@@ -293,6 +341,13 @@ class XML
if ($oneCpu->getVirt() !== null) {
$tmp->addAttribute('Virt', $oneCpu->getVirt());
}
if ($oneCpu->getVendorId() !== null) {
if ($vendortab === null) $vendortab = @parse_ini_file(PSI_APP_ROOT."/data/cpus.ini", true);
$shortvendorid = $oneCpu->getVendorId();
if ($vendortab && ($shortvendorid != "") && isset($vendortab['manufacturer'][$shortvendorid])) {
$tmp->addAttribute('Manufacturer', $vendortab['manufacturer'][$shortvendorid]);
}
}
if ($oneCpu->getBogomips() !== null) {
$tmp->addAttribute('Bogomips', $oneCpu->getBogomips());
}
@@ -300,6 +355,144 @@ class XML
$tmp->addAttribute('Load', $oneCpu->getLoad());
}
}
$mem = null;
foreach (System::removeDupsAndCount($this->_sys->getMemDevices()) as $dev) {
if ($mem === null) $mem = $hardware->addChild('MEM');
$tmp = $mem->addChild('Chip');
$tmp->addAttribute('Name', $dev->getName());
if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS) {
if ($dev->getCapacity() !== null) {
$tmp->addAttribute('Capacity', $dev->getCapacity());
}
if ($dev->getManufacturer() !== null) {
$tmp->addAttribute('Manufacturer', $dev->getManufacturer());
}
if ($dev->getProduct() !== null) {
$tmp->addAttribute('Product', $dev->getProduct());
}
if ($dev->getSpeed() !== null) {
$tmp->addAttribute('Speed', $dev->getSpeed());
}
if ($dev->getVoltage() !== null) {
$tmp->addAttribute('Voltage', $dev->getVoltage());
}
if (defined('PSI_SHOW_DEVICES_SERIAL') && PSI_SHOW_DEVICES_SERIAL && ($dev->getSerial() !== null)) {
$tmp->addAttribute('Serial', $dev->getSerial());
}
}
if ($dev->getCount() > 1) {
$tmp->addAttribute('Count', $dev->getCount());
}
}
$pci = null;
foreach (System::removeDupsAndCount($this->_sys->getPciDevices()) as $dev) {
if ($pci === null) $pci = $hardware->addChild('PCI');
$tmp = $pci->addChild('Device');
$tmp->addAttribute('Name', $dev->getName());
if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS) {
if ($dev->getManufacturer() !== null) {
$tmp->addAttribute('Manufacturer', $dev->getManufacturer());
}
if ($dev->getProduct() !== null) {
$tmp->addAttribute('Product', $dev->getProduct());
}
}
if ($dev->getCount() > 1) {
$tmp->addAttribute('Count', $dev->getCount());
}
}
$ide = null;
foreach (System::removeDupsAndCount($this->_sys->getIdeDevices()) as $dev) {
if ($ide === null) $ide = $hardware->addChild('IDE');
$tmp = $ide->addChild('Device');
$tmp->addAttribute('Name', $dev->getName());
if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS) {
if ($dev->getCapacity() !== null) {
$tmp->addAttribute('Capacity', $dev->getCapacity());
}
if (defined('PSI_SHOW_DEVICES_SERIAL') && PSI_SHOW_DEVICES_SERIAL && ($dev->getSerial() !== null)) {
$tmp->addAttribute('Serial', $dev->getSerial());
}
}
if ($dev->getCount() > 1) {
$tmp->addAttribute('Count', $dev->getCount());
}
}
$scsi = null;
foreach (System::removeDupsAndCount($this->_sys->getScsiDevices()) as $dev) {
if ($scsi === null) $scsi = $hardware->addChild('SCSI');
$tmp = $scsi->addChild('Device');
$tmp->addAttribute('Name', $dev->getName());
if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS) {
if ($dev->getCapacity() !== null) {
$tmp->addAttribute('Capacity', $dev->getCapacity());
}
if (defined('PSI_SHOW_DEVICES_SERIAL') && PSI_SHOW_DEVICES_SERIAL && ($dev->getSerial() !== null)) {
$tmp->addAttribute('Serial', $dev->getSerial());
}
}
if ($dev->getCount() > 1) {
$tmp->addAttribute('Count', $dev->getCount());
}
}
$nvme = null;
foreach (System::removeDupsAndCount($this->_sys->getNvmeDevices()) as $dev) {
if ($nvme === null) $nvme = $hardware->addChild('NVMe');
$tmp = $nvme->addChild('Device');
$tmp->addAttribute('Name', $dev->getName());
if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS) {
if ($dev->getCapacity() !== null) {
$tmp->addAttribute('Capacity', $dev->getCapacity());
}
if (defined('PSI_SHOW_DEVICES_SERIAL') && PSI_SHOW_DEVICES_SERIAL && ($dev->getSerial() !== null)) {
$tmp->addAttribute('Serial', $dev->getSerial());
}
}
if ($dev->getCount() > 1) {
$tmp->addAttribute('Count', $dev->getCount());
}
}
$usb = null;
foreach (System::removeDupsAndCount($this->_sys->getUsbDevices()) as $dev) {
if ($usb === null) $usb = $hardware->addChild('USB');
$tmp = $usb->addChild('Device');
$tmp->addAttribute('Name', $dev->getName());
if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS) {
if ($dev->getManufacturer() !== null) {
$tmp->addAttribute('Manufacturer', $dev->getManufacturer());
}
if ($dev->getProduct() !== null) {
$tmp->addAttribute('Product', $dev->getProduct());
}
if ($dev->getSpeed() !== null) {
$tmp->addAttribute('Speed', $dev->getSpeed());
}
if (defined('PSI_SHOW_DEVICES_SERIAL') && PSI_SHOW_DEVICES_SERIAL && ($dev->getSerial() !== null)) {
$tmp->addAttribute('Serial', $dev->getSerial());
}
}
if ($dev->getCount() > 1) {
$tmp->addAttribute('Count', $dev->getCount());
}
}
$tb = null;
foreach (System::removeDupsAndCount($this->_sys->getTbDevices()) as $dev) {
if ($tb === null) $tb = $hardware->addChild('TB');
$tmp = $tb->addChild('Device');
$tmp->addAttribute('Name', $dev->getName());
if ($dev->getCount() > 1) {
$tmp->addAttribute('Count', $dev->getCount());
}
}
$i2c = null;
foreach (System::removeDupsAndCount($this->_sys->getI2cDevices()) as $dev) {
if ($i2c === null) $i2c = $hardware->addChild('I2C');
$tmp = $i2c->addChild('Device');
$tmp->addAttribute('Name', $dev->getName());
if ($dev->getCount() > 1) {
$tmp->addAttribute('Count', $dev->getCount());
}
}
}
/**
@@ -348,28 +541,32 @@ class XML
*
* @param SimpleXmlExtended $mount Xml-Element
* @param DiskDevice $dev DiskDevice
* @param Integer $i counter
* @param int $i counter
*
* @return Void
* @return void
*/
private function _fillDevice(SimpleXMLExtended $mount, DiskDevice $dev, $i)
{
$mount->addAttribute('MountPointID', $i);
$mount->addAttribute('FSType', $dev->getFsType());
if ($dev->getFsType()!=="") {
$mount->addAttribute('FSType', $dev->getFsType());
}
$mount->addAttribute('Name', $dev->getName());
$mount->addAttribute('Free', sprintf("%.0f", $dev->getFree()));
$mount->addAttribute('Used', sprintf("%.0f", $dev->getUsed()));
$mount->addAttribute('Total', sprintf("%.0f", $dev->getTotal()));
$mount->addAttribute('Percent', $dev->getPercentUsed());
if (PSI_SHOW_MOUNT_OPTION === true) {
$percentUsed = $dev->getPercentUsed();
$mount->addAttribute('Percent', $percentUsed);
if ($dev->getPercentInodesUsed() !== null) {
$mount->addAttribute('Inodes', $dev->getPercentInodesUsed());
}
if ($dev->getIgnore() > 0) $mount->addAttribute('Ignore', $dev->getIgnore());
if (PSI_SHOW_MOUNT_OPTION) {
if ($dev->getOptions() !== null) {
$mount->addAttribute('MountOptions', preg_replace("/,/", ", ", $dev->getOptions()));
}
}
if ($dev->getPercentInodesUsed() !== null) {
$mount->addAttribute('Inodes', $dev->getPercentInodesUsed());
}
if (PSI_SHOW_MOUNT_POINT === true) {
if (PSI_SHOW_MOUNT_POINT && ($dev->getMountPoint() !== null)) {
$mount->addAttribute('MountPoint', $dev->getMountPoint());
}
}
@@ -381,8 +578,7 @@ class XML
*/
private function _buildFilesystems()
{
$hideMounts = $hideFstypes = $hideDisks = array();
$i = 1;
$hideMounts = $hideFstypes = $hideDisks = $ignoreFree = $ignoreTotal = $ignoreUsage = $ignoreThreshold = array();
if (defined('PSI_HIDE_MOUNTS') && is_string(PSI_HIDE_MOUNTS)) {
if (preg_match(ARRAY_EXP, PSI_HIDE_MOUNTS)) {
$hideMounts = eval(PSI_HIDE_MOUNTS);
@@ -408,10 +604,48 @@ class XML
return;
}
}
if (defined('PSI_IGNORE_FREE') && is_string(PSI_IGNORE_FREE)) {
if (preg_match(ARRAY_EXP, PSI_IGNORE_FREE)) {
$ignoreFree = eval(PSI_IGNORE_FREE);
} else {
$ignoreFree = array(PSI_IGNORE_FREE);
}
}
if (defined('PSI_IGNORE_TOTAL') && is_string(PSI_IGNORE_TOTAL)) {
if (preg_match(ARRAY_EXP, PSI_IGNORE_TOTAL)) {
$ignoreTotal = eval(PSI_IGNORE_TOTAL);
} else {
$ignoreTotal = array(PSI_IGNORE_TOTAL);
}
}
if (defined('PSI_IGNORE_USAGE') && is_string(PSI_IGNORE_USAGE)) {
if (preg_match(ARRAY_EXP, PSI_IGNORE_USAGE)) {
$ignoreUsage = eval(PSI_IGNORE_USAGE);
} else {
$ignoreUsage = array(PSI_IGNORE_USAGE);
}
}
if (defined('PSI_IGNORE_THRESHOLD_FS_TYPES') && is_string(PSI_IGNORE_THRESHOLD_FS_TYPES)) {
if (preg_match(ARRAY_EXP, PSI_IGNORE_THRESHOLD_FS_TYPES)) {
$ignoreThreshold = eval(PSI_IGNORE_THRESHOLD_FS_TYPES);
} else {
$ignoreThreshold = array(PSI_IGNORE_THRESHOLD_FS_TYPES);
}
}
$fs = $this->_xml->addChild('FileSystem');
$i = 1;
foreach ($this->_sys->getDiskDevices() as $disk) {
if (!in_array($disk->getMountPoint(), $hideMounts, true) && !in_array($disk->getFsType(), $hideFstypes, true) && !in_array($disk->getName(), $hideDisks, true)) {
$mount = $fs->addChild('Mount');
if (in_array($disk->getFsType(), $ignoreThreshold, true)) {
$disk->setIgnore(4);
} elseif (in_array($disk->getMountPoint(), $ignoreUsage, true)) {
$disk->setIgnore(3);
} elseif (in_array($disk->getMountPoint(), $ignoreTotal, true)) {
$disk->setIgnore(2);
} elseif (in_array($disk->getMountPoint(), $ignoreFree, true)) {
$disk->setIgnore(1);
}
$this->_fillDevice($mount, $disk, $i++);
}
}
@@ -425,105 +659,151 @@ class XML
private function _buildMbinfo()
{
$mbinfo = $this->_xml->addChild('MBInfo');
$temp = $fan = $volt = $power = $current = null;
$temp = $fan = $volt = $power = $current = $other = null;
$hideSensors = array();
if (sizeof(unserialize(PSI_MBINFO))>0) {
if (defined('PSI_HIDE_SENSORS') && is_string(PSI_HIDE_SENSORS)) {
if (preg_match(ARRAY_EXP, PSI_HIDE_SENSORS)) {
$hideSensors = eval(PSI_HIDE_SENSORS);
} else {
$hideSensors = array(PSI_HIDE_SENSORS);
}
}
foreach (unserialize(PSI_MBINFO) as $mbinfoclass) {
$mbinfo_data = new $mbinfoclass();
$mbinfo_detail = $mbinfo_data->getMBInfo();
foreach ($mbinfo_detail->getMbTemp() as $dev) {
if ($temp == null) {
$temp = $mbinfo->addChild('Temperature');
}
$item = $temp->addChild('Item');
$item->addAttribute('Label', $dev->getName());
$item->addAttribute('Value', $dev->getValue());
if ($dev->getMax() !== null) {
$item->addAttribute('Max', $dev->getMax());
}
if (defined('PSI_SENSOR_EVENTS') && PSI_SENSOR_EVENTS && $dev->getEvent() !== "") {
$item->addAttribute('Event', $dev->getEvent());
if (!$this->_sysinfo->getBlockName() || $this->_sysinfo->getBlockName()==='temperature' || $this->_sysinfo->getBlockName()==='mbinfo') foreach ($mbinfo_detail->getMbTemp() as $dev) {
$mbinfo_name = $dev->getName();
if (!in_array($mbinfo_name, $hideSensors, true)) {
if ($temp == null) {
$temp = $mbinfo->addChild('Temperature');
}
$item = $temp->addChild('Item');
$item->addAttribute('Label', $mbinfo_name);
$item->addAttribute('Value', $dev->getValue());
$alarm = false;
if ($dev->getMax() !== null) {
$item->addAttribute('Max', $dev->getMax());
$alarm = true;
}
if (defined('PSI_SENSOR_EVENTS') && PSI_SENSOR_EVENTS && ($dev->getEvent() !== "") && (((strtolower($dev->getEvent())) !== "alarm") || $alarm || ($dev->getValue() == 0))) {
$item->addAttribute('Event', ucfirst(strtolower($dev->getEvent())));
}
}
}
foreach ($mbinfo_detail->getMbFan() as $dev) {
if ($fan == null) {
$fan = $mbinfo->addChild('Fans');
}
$item = $fan->addChild('Item');
$item->addAttribute('Label', $dev->getName());
$item->addAttribute('Value', $dev->getValue());
if ($dev->getMin() !== null) {
$item->addAttribute('Min', $dev->getMin());
}
if (defined('PSI_SENSOR_EVENTS') && PSI_SENSOR_EVENTS && $dev->getEvent() !== "") {
$item->addAttribute('Event', $dev->getEvent());
if (!$this->_sysinfo->getBlockName() || $this->_sysinfo->getBlockName()==='fans' || $this->_sysinfo->getBlockName()==='mbinfo') foreach ($mbinfo_detail->getMbFan() as $dev) {
$mbinfo_name = $dev->getName();
if (!in_array($mbinfo_name, $hideSensors, true)) {
if ($fan == null) {
$fan = $mbinfo->addChild('Fans');
}
$item = $fan->addChild('Item');
$item->addAttribute('Label', $mbinfo_name);
$item->addAttribute('Value', $dev->getValue());
$alarm = false;
if ($dev->getMin() !== null) {
$item->addAttribute('Min', $dev->getMin());
$alarm = true;
}
if ($dev->getUnit() !== "") {
$item->addAttribute('Unit', $dev->getUnit());
}
if (defined('PSI_SENSOR_EVENTS') && PSI_SENSOR_EVENTS && ($dev->getEvent() !== "") && (((strtolower($dev->getEvent())) !== "alarm") || $alarm || ($dev->getValue() == 0))) {
$item->addAttribute('Event', ucfirst(strtolower($dev->getEvent())));
}
}
}
foreach ($mbinfo_detail->getMbVolt() as $dev) {
if ($volt == null) {
$volt = $mbinfo->addChild('Voltage');
}
$item = $volt->addChild('Item');
$item->addAttribute('Label', $dev->getName());
$item->addAttribute('Value', $dev->getValue());
if ($dev->getMin() !== null) {
$item->addAttribute('Min', $dev->getMin());
}
if ($dev->getMax() !== null) {
$item->addAttribute('Max', $dev->getMax());
}
if (defined('PSI_SENSOR_EVENTS') && PSI_SENSOR_EVENTS && $dev->getEvent() !== "") {
$item->addAttribute('Event', $dev->getEvent());
if (!$this->_sysinfo->getBlockName() || $this->_sysinfo->getBlockName()==='voltage' || $this->_sysinfo->getBlockName()==='mbinfo') foreach ($mbinfo_detail->getMbVolt() as $dev) {
$mbinfo_name = $dev->getName();
if (!in_array($mbinfo_name, $hideSensors, true)) {
if ($volt == null) {
$volt = $mbinfo->addChild('Voltage');
}
$item = $volt->addChild('Item');
$item->addAttribute('Label', $mbinfo_name);
$item->addAttribute('Value', $dev->getValue());
$alarm = false;
if (($dev->getMin() === null) || ($dev->getMin() != 0) || ($dev->getMax() === null) || ($dev->getMax() != 0)) {
if ($dev->getMin() !== null) {
$item->addAttribute('Min', $dev->getMin());
$alarm = true;
}
if ($dev->getMax() !== null) {
$item->addAttribute('Max', $dev->getMax());
$alarm = true;
}
}
if (defined('PSI_SENSOR_EVENTS') && PSI_SENSOR_EVENTS && ($dev->getEvent() !== "") && (((strtolower($dev->getEvent())) !== "alarm") || $alarm || ($dev->getValue() == 0))) {
$item->addAttribute('Event', ucfirst(strtolower($dev->getEvent())));
}
}
}
foreach ($mbinfo_detail->getMbPower() as $dev) {
if ($power == null) {
$power = $mbinfo->addChild('Power');
}
$item = $power->addChild('Item');
$item->addAttribute('Label', $dev->getName());
$item->addAttribute('Value', $dev->getValue());
if ($dev->getMax() !== null) {
$item->addAttribute('Max', $dev->getMax());
}
if (defined('PSI_SENSOR_EVENTS') && PSI_SENSOR_EVENTS && $dev->getEvent() !== "") {
$item->addAttribute('Event', $dev->getEvent());
if (!$this->_sysinfo->getBlockName() || $this->_sysinfo->getBlockName()==='power' || $this->_sysinfo->getBlockName()==='mbinfo') foreach ($mbinfo_detail->getMbPower() as $dev) {
$mbinfo_name = $dev->getName();
if (!in_array($mbinfo_name, $hideSensors, true)) {
if ($power == null) {
$power = $mbinfo->addChild('Power');
}
$item = $power->addChild('Item');
$item->addAttribute('Label', $mbinfo_name);
$item->addAttribute('Value', $dev->getValue());
$alarm = false;
if ($dev->getMax() !== null) {
$item->addAttribute('Max', $dev->getMax());
$alarm = true;
}
if (defined('PSI_SENSOR_EVENTS') && PSI_SENSOR_EVENTS && ($dev->getEvent() !== "") && (((strtolower($dev->getEvent())) !== "alarm") || $alarm || ($dev->getValue() == 0))) {
$item->addAttribute('Event', ucfirst(strtolower($dev->getEvent())));
}
}
}
foreach ($mbinfo_detail->getMbCurrent() as $dev) {
if ($current == null) {
$current = $mbinfo->addChild('Current');
}
$item = $current->addChild('Item');
$item->addAttribute('Label', $dev->getName());
$item->addAttribute('Value', $dev->getValue());
if ($dev->getMax() !== null) {
$item->addAttribute('Max', $dev->getMax());
}
if (defined('PSI_SENSOR_EVENTS') && PSI_SENSOR_EVENTS && $dev->getEvent() !== "") {
$item->addAttribute('Event', $dev->getEvent());
if (!$this->_sysinfo->getBlockName() || $this->_sysinfo->getBlockName()==='current' || $this->_sysinfo->getBlockName()==='mbinfo') foreach ($mbinfo_detail->getMbCurrent() as $dev) {
$mbinfo_name = $dev->getName();
if (!in_array($mbinfo_name, $hideSensors, true)) {
if ($current == null) {
$current = $mbinfo->addChild('Current');
}
$item = $current->addChild('Item');
$item->addAttribute('Label', $mbinfo_name);
$item->addAttribute('Value', $dev->getValue());
$alarm = false;
if (($dev->getMin() === null) || ($dev->getMin() != 0) || ($dev->getMax() === null) || ($dev->getMax() != 0)) {
if ($dev->getMin() !== null) {
$item->addAttribute('Min', $dev->getMin());
$alarm = true;
}
if ($dev->getMax() !== null) {
$item->addAttribute('Max', $dev->getMax());
$alarm = true;
}
}
if (defined('PSI_SENSOR_EVENTS') && PSI_SENSOR_EVENTS && ($dev->getEvent() !== "") && (((strtolower($dev->getEvent())) !== "alarm") || $alarm || ($dev->getValue() == 0))) {
$item->addAttribute('Event', ucfirst(strtolower($dev->getEvent())));
}
}
}
}
}
if (PSI_HDDTEMP) {
$hddtemp = new HDDTemp();
$hddtemp_data = $hddtemp->getMBInfo();
foreach ($hddtemp_data->getMbTemp() as $dev) {
if ($temp == null) {
$temp = $mbinfo->addChild('Temperature');
}
$item = $temp->addChild('Item');
$item->addAttribute('Label', $dev->getName());
$item->addAttribute('Value', $dev->getValue());
if ($dev->getMax() !== null) {
$item->addAttribute('Max', $dev->getMax());
if (!$this->_sysinfo->getBlockName() || $this->_sysinfo->getBlockName()==='other' || $this->_sysinfo->getBlockName()==='mbinfo') foreach ($mbinfo_detail->getMbOther() as $dev) {
$mbinfo_name = $dev->getName();
if (!in_array($mbinfo_name, $hideSensors, true)) {
if ($other == null) {
$other = $mbinfo->addChild('Other');
}
$item = $other->addChild('Item');
$item->addAttribute('Label', $mbinfo_name);
$item->addAttribute('Value', $dev->getValue());
if ($dev->getUnit() !== "") {
$item->addAttribute('Unit', $dev->getUnit());
}
if (defined('PSI_SENSOR_EVENTS') && PSI_SENSOR_EVENTS && $dev->getEvent() !== "") {
$item->addAttribute('Event', ucfirst(strtolower($dev->getEvent())));
}
}
}
}
}
@@ -537,7 +817,7 @@ class XML
private function _buildUpsinfo()
{
$upsinfo = $this->_xml->addChild('UPSInfo');
if (defined('PSI_UPS_APCUPSD_CGI_ENABLE') && PSI_UPS_APCUPSD_CGI_ENABLE) {
if (!defined('PSI_EMU_HOSTNAME') && defined('PSI_UPS_APCUPSD_CGI_ENABLE') && PSI_UPS_APCUPSD_CGI_ENABLE) {
$upsinfo->addAttribute('ApcupsdCgiLinks', true);
}
if (sizeof(unserialize(PSI_UPSINFO))>0) {
@@ -550,11 +830,16 @@ class XML
if ($ups->getModel() !== "") {
$item->addAttribute('Model', $ups->getModel());
}
$item->addAttribute('Mode', $ups->getMode());
if ($ups->getMode() !== "") {
$item->addAttribute('Mode', $ups->getMode());
}
if ($ups->getStartTime() !== "") {
$item->addAttribute('StartTime', $ups->getStartTime());
}
$item->addAttribute('Status', $ups->getStatus());
if ($ups->getBeeperStatus() !== null) {
$item->addAttribute('BeeperStatus', $ups->getBeeperStatus());
}
if ($ups->getTemperatur() !== null) {
$item->addAttribute('Temperature', $ups->getTemperatur());
}
@@ -600,9 +885,14 @@ class XML
*/
private function _buildXml()
{
if (!$this->_plugin_request || $this->_complete_request) {
if (($this->_plugin == '') || $this->_complete_request) {
if ($this->_sys === null) {
if (PSI_DEBUG === true) {
if (PSI_DEBUG) {
// unstable version check
if (!is_numeric(substr(PSI_VERSION, -1))) {
$this->_errors->addWarning("This is an unstable version of phpSysInfo, some things may not work correctly");
}
// Safe mode check
$safe_mode = @ini_get("safe_mode") ? true : false;
if ($safe_mode) {
@@ -620,28 +910,28 @@ class XML
$this->_errors->addError("WARN", "PhpSysInfo requires '.' inside the 'include_path' in php.ini");
}
// popen mode check
if (defined("PSI_MODE_POPEN") && PSI_MODE_POPEN === true) {
if (defined("PSI_MODE_POPEN") && PSI_MODE_POPEN) {
$this->_errors->addError("WARN", "Installed version of PHP does not support proc_open() function, popen() is used");
}
}
$this->_sys = $this->_sysinfo->getSys();
}
$this->_buildVitals();
$this->_buildNetwork();
$this->_buildHardware();
$this->_buildMemory();
$this->_buildFilesystems();
$this->_buildMbinfo();
$this->_buildUpsinfo();
if (!$this->_sysinfo->getBlockName() || $this->_sysinfo->getBlockName()==='vitals') $this->_buildVitals();
if (!$this->_sysinfo->getBlockName() || $this->_sysinfo->getBlockName()==='network') $this->_buildNetwork();
if (!$this->_sysinfo->getBlockName() || $this->_sysinfo->getBlockName()==='hardware') $this->_buildHardware();
if (!$this->_sysinfo->getBlockName() || $this->_sysinfo->getBlockName()==='memory') $this->_buildMemory();
if (!$this->_sysinfo->getBlockName() || $this->_sysinfo->getBlockName()==='filesystem') $this->_buildFilesystems();
if (!$this->_sysinfo->getBlockName() || in_array($this->_sysinfo->getBlockName(), array('mbinfo','voltage','current','temperature','fans','power','other'))) $this->_buildMbinfo();
if (!$this->_sysinfo->getBlockName() || $this->_sysinfo->getBlockName()==='ups') $this->_buildUpsinfo();
}
$this->_buildPlugins();
if (!$this->_sysinfo->getBlockName()) $this->_buildPlugins();
$this->_xml->combinexml($this->_errors->errorsAddToXML($this->_sysinfo->getEncoding()));
}
/**
* get the xml object
*
* @return string
* @return SimpleXmlElement
*/
public function getXml()
{
@@ -658,20 +948,25 @@ class XML
private function _buildPlugins()
{
$pluginroot = $this->_xml->addChild("Plugins");
if (($this->_plugin_request || $this->_complete_request) && count($this->_plugins) > 0) {
if ((($this->_plugin != '') || $this->_complete_request) && count($this->_plugins) > 0) {
$plugins = array();
if ($this->_complete_request) {
$plugins = $this->_plugins;
}
if ($this->_plugin_request) {
if (($this->_plugin != '')) {
$plugins = array($this->_plugin);
}
foreach ($plugins as $plugin) {
$object = new $plugin($this->_sysinfo->getEncoding());
$object->execute();
$oxml = $object->xml();
if (sizeof($oxml) > 0) {
$pluginroot->combinexml($oxml);
if (!$this->_complete_request ||
(!defined('PSI_PLUGIN_'.strtoupper($plugin).'_SSH_HOSTNAME') && !defined('PSI_PLUGIN_'.strtoupper($plugin).'_WMI_HOSTNAME')) ||
(defined('PSI_SSH_HOSTNAME') && (PSI_SSH_HOSTNAME == constant('PSI_PLUGIN_'.strtoupper($plugin).'_SSH_HOSTNAME'))) ||
(defined('PSI_WMI_HOSTNAME') && (PSI_WMI_HOSTNAME == constant('PSI_PLUGIN_'.strtoupper($plugin).'_WMI_HOSTNAME')))) {
$object = new $plugin($this->_sysinfo->getEncoding());
$object->execute();
$oxml = $object->xml();
if (sizeof($oxml) > 0) {
$pluginroot->combinexml($oxml);
}
}
}
}
@@ -698,32 +993,21 @@ class XML
$options = $this->_xml->addChild('Options');
$options->addAttribute('tempFormat', defined('PSI_TEMP_FORMAT') ? strtolower(PSI_TEMP_FORMAT) : 'c');
$options->addAttribute('byteFormat', defined('PSI_BYTE_FORMAT') ? strtolower(PSI_BYTE_FORMAT) : 'auto_binary');
$options->addAttribute('datetimeFormat', defined('PSI_DATETIME_FORMAT') ? strtolower(PSI_DATETIME_FORMAT) : 'utc');
if (defined('PSI_REFRESH')) {
if (PSI_REFRESH === false) {
$options->addAttribute('refresh', 0);
} elseif (PSI_REFRESH === true) {
$options->addAttribute('refresh', 1);
} else {
$options->addAttribute('refresh', PSI_REFRESH);
}
$options->addAttribute('refresh', max(intval(PSI_REFRESH), 0));
} else {
$options->addAttribute('refresh', 60000);
}
if (defined('PSI_FS_USAGE_THRESHOLD')) {
if (PSI_FS_USAGE_THRESHOLD === true) {
$options->addAttribute('threshold', 1);
} elseif ((PSI_FS_USAGE_THRESHOLD !== false) && (PSI_FS_USAGE_THRESHOLD >= 1) && (PSI_FS_USAGE_THRESHOLD <= 99)) {
$options->addAttribute('threshold', PSI_FS_USAGE_THRESHOLD);
if ((($fsut = intval(PSI_FS_USAGE_THRESHOLD)) >= 1) && ($fsut <= 99)) {
$options->addAttribute('threshold', $fsut);
}
} else {
$options->addAttribute('threshold', 90);
}
$options->addAttribute('showPickListTemplate', defined('PSI_SHOW_PICKLIST_TEMPLATE') ? (PSI_SHOW_PICKLIST_TEMPLATE ? 'true' : 'false') : 'false');
$options->addAttribute('showPickListLang', defined('PSI_SHOW_PICKLIST_LANG') ? (PSI_SHOW_PICKLIST_LANG ? 'true' : 'false') : 'false');
$options->addAttribute('showCPUListExpanded', defined('PSI_SHOW_CPULIST_EXPANDED') ? (PSI_SHOW_CPULIST_EXPANDED ? 'true' : 'false') : 'true');
$options->addAttribute('showCPUInfoExpanded', defined('PSI_SHOW_CPUINFO_EXPANDED') ? (PSI_SHOW_CPUINFO_EXPANDED ? 'true' : 'false') : 'false');
if (count($this->_plugins) > 0) {
if ($this->_plugin_request) {
if (($this->_plugin != '')) {
$plug = $this->_xml->addChild('UsedPlugins');
$plug->addChild('Plugin')->addAttribute('name', $this->_plugin);
} elseif ($this->_complete_request) {
@@ -731,11 +1015,13 @@ class XML
foreach ($this->_plugins as $plugin) {
$plug->addChild('Plugin')->addAttribute('name', $plugin);
}
/*
} else {
$plug = $this->_xml->addChild('UnusedPlugins');
foreach ($this->_plugins as $plugin) {
$plug->addChild('Plugin')->addAttribute('name', $plugin);
}
*/
}
}
}