Subversion Repositories ALCASAR

Compare Revisions

Ignore whitespace Rev 2769 → Rev 2770

/web/acc/phpsysinfo/includes/system_header.php
File deleted
/web/acc/phpsysinfo/includes/indicator.php
File deleted
/web/acc/phpsysinfo/includes/XPath.class.php
File deleted
\ No newline at end of file
/web/acc/phpsysinfo/includes/lang/tw.php
File deleted
/web/acc/phpsysinfo/includes/lang/id.php
File deleted
/web/acc/phpsysinfo/includes/lang/cn.php
File deleted
/web/acc/phpsysinfo/includes/lang/en.php
File deleted
/web/acc/phpsysinfo/includes/lang/cs.php
File deleted
/web/acc/phpsysinfo/includes/lang/pa_utf8.php
File deleted
/web/acc/phpsysinfo/includes/lang/ct.php
File deleted
/web/acc/phpsysinfo/includes/lang/es.php
File deleted
/web/acc/phpsysinfo/includes/lang/et.php
File deleted
/web/acc/phpsysinfo/includes/lang/gr.php
File deleted
/web/acc/phpsysinfo/includes/lang/ko.php
File deleted
/web/acc/phpsysinfo/includes/lang/eu.php
File deleted
/web/acc/phpsysinfo/includes/lang/is.php
File deleted
/web/acc/phpsysinfo/includes/lang/it.php
File deleted
/web/acc/phpsysinfo/includes/lang/sk.php
File deleted
/web/acc/phpsysinfo/includes/lang/da.php
File deleted
/web/acc/phpsysinfo/includes/lang/sr.php
File deleted
/web/acc/phpsysinfo/includes/lang/big5.php
File deleted
/web/acc/phpsysinfo/includes/lang/bg.php
File deleted
/web/acc/phpsysinfo/includes/lang/de.php
File deleted
/web/acc/phpsysinfo/includes/lang/sv.php
File deleted
/web/acc/phpsysinfo/includes/lang/ja.php
File deleted
/web/acc/phpsysinfo/includes/lang/he.php
File deleted
/web/acc/phpsysinfo/includes/lang/fi.php
File deleted
/web/acc/phpsysinfo/includes/lang/br.php
File deleted
/web/acc/phpsysinfo/includes/lang/fr.php
File deleted
/web/acc/phpsysinfo/includes/lang/ar_utf8.php
File deleted
/web/acc/phpsysinfo/includes/lang/nl.php
File deleted
/web/acc/phpsysinfo/includes/lang/jp.php
File deleted
/web/acc/phpsysinfo/includes/lang/pl.php
File deleted
/web/acc/phpsysinfo/includes/lang/no.php
File deleted
/web/acc/phpsysinfo/includes/lang/hu.php
File deleted
/web/acc/phpsysinfo/includes/lang/lt.php
File deleted
/web/acc/phpsysinfo/includes/lang/ro.php
File deleted
/web/acc/phpsysinfo/includes/lang/lv.php
File deleted
/web/acc/phpsysinfo/includes/lang/pt.php
File deleted
/web/acc/phpsysinfo/includes/lang/ca.php
File deleted
/web/acc/phpsysinfo/includes/lang/pt-br.php
File deleted
/web/acc/phpsysinfo/includes/lang/tr.php
File deleted
/web/acc/phpsysinfo/includes/lang/ru.php
File deleted
/web/acc/phpsysinfo/includes/system_footer.php
File deleted
/web/acc/phpsysinfo/includes/class.error.inc.php
File deleted
/web/acc/phpsysinfo/includes/class.Template.inc.php
File deleted
/web/acc/phpsysinfo/includes/common_functions.php
File deleted
/web/acc/phpsysinfo/includes/autoloader.inc.php
0,0 → 1,77
<?php
/**
* class autoloader
*
* PHP version 5
*
* @category PHP
* @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 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
*/
 
error_reporting(E_ALL | E_STRICT);
 
/**
* automatic loading classes when using them
*
* @param string $class_name name of the class which must be loaded
*
* @return void
*/
function psi_autoload($class_name)
{
//$class_name = str_replace('-', '', $class_name);
 
/* case-insensitive folders */
$dirs = array('/plugins/'.strtolower($class_name).'/', '/includes/mb/', '/includes/ups/');
 
foreach ($dirs as $dir) {
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;
}
}
 
/* case-sensitive folders */
$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(PSI_APP_ROOT.$dir.'class.'.$class_name.'.inc.php')) {
include_once PSI_APP_ROOT.$dir.'class.'.$class_name.'.inc.php';
 
return;
}
}
 
$error = PSI_Error::singleton();
 
$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
*
* @param integer $level contains the level of the error raised, as an integer.
* @param string $message contains the error message, as a string.
* @param string $file which contains the filename that the error was raised in, as a string.
* @param integer $line which contains the line number the error was raised at, as an integer.
*
* @return void
*/
function errorHandlerPsi($level, $message, $file, $line)
{
$error = PSI_Error::singleton();
if (PSI_DEBUG || (($level !== 2) && ($level !== 8)) || !(preg_match("/^[^:]*: open_basedir /", $message) || preg_match("/^fopen\(/", $message) || preg_match("/^is_readable\(/", $message) || preg_match("/^file_exists\(/", $message) || preg_match("/^fgets\(/", $message))) { // disable open_basedir, fopen, is_readable, file_exists and fgets warnings and notices
$error->addPhpError("errorHandlerPsi : ", "Level : ".$level." Message : ".$message." File : ".$file." Line : ".$line);
}
}
 
set_error_handler('errorHandlerPsi');
/web/acc/phpsysinfo/includes/class.CommonFunctions.inc.php
0,0 → 1,756
<?php
/**
* common Functions class
*
* PHP version 5
*
* @category PHP
* @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 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
*/
/**
* class with common functions used in all places
*
* @category PHP
* @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 version 2, or (at your option) any later version
* @version Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
class CommonFunctions
{
/**
* holds codepage for chcp
*
* @var integer
*/
private static $_cp = null;
 
public static function setcp($cp)
{
CommonFunctions::$_cp = $cp;
}
 
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)=="+"))) {
$log_file = substr(PSI_LOG, 1);
if (file_exists($log_file)) {
$contents = @file_get_contents($log_file);
if ($contents && preg_match("/^\-\-\-[^-\r\n]+\-\-\- ".preg_quote($string, '/')."\r?\n/m", $contents, $matches, PREG_OFFSET_CAPTURE)) {
$findIndex = $matches[0][1];
if (preg_match("/\r?\n/m", $contents, $matches, PREG_OFFSET_CAPTURE, $findIndex)) {
$startIndex = $matches[0][1]+1;
if (preg_match("/^\-\-\-[^-\r\n]+\-\-\- /m", $contents, $matches, PREG_OFFSET_CAPTURE, $startIndex)) {
$stopIndex = $matches[0][1];
 
return substr($contents, $startIndex, $stopIndex-$startIndex);
} else {
return substr($contents, $startIndex);
}
}
}
}
}
 
return false;
}
 
/**
* Find a system program, do also path checking when not running on WINNT
* on WINNT we simply return the name with the exe extension to the program name
*
* @param string $strProgram name of the program
*
* @return string|null complete path and name of the program
*/
private static function _findProgram($strProgram)
{
$path_parts = pathinfo($strProgram);
if (empty($path_parts['basename'])) {
return null;
}
$arrPath = array();
 
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') {
if (CommonFunctions::readenv('Path', $serverpath)) {
$arrPath = preg_split('/;/', $serverpath, -1, PREG_SPLIT_NO_EMPTY);
}
} else {
if (CommonFunctions::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)) {
$arrPath = array_merge(eval(PSI_ADD_PATHS), $arrPath); // In this order so $addpaths is before $arrPath when looking for a program
} else {
$arrPath = array_merge(array(PSI_ADD_PATHS), $arrPath); // In this order so $addpaths is before $arrPath when looking for a program
}
}
} 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 (PSI_OS == 'Android') {
array_push($arrPath, '/system/bin');
} else {
array_push($arrPath, '/bin', '/sbin', '/usr/bin', '/usr/sbin', '/usr/local/bin', '/usr/local/sbin');
}
}
 
$exceptPath = "";
if ((PSI_OS == 'WINNT') && CommonFunctions::readenv('WinDir', $windir)) {
foreach ($arrPath as $strPath) {
if ((strtolower($strPath) == $windir."\\system32") && is_dir($windir."\\SysWOW64")) {
if (is_dir($windir."\\sysnative")) {
$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;
}
}
} elseif (PSI_OS == 'Android') {
$exceptPath = '/system/bin';
}
 
foreach ($arrPath as $strPath) {
// Path with and without trailing slash
if (PSI_OS == 'WINNT') {
$strPath = rtrim($strPath, "\\");
$strPathS = $strPath."\\";
} else {
$strPath = rtrim($strPath, "/");
$strPathS = $strPath."/";
}
if (($strPath !== $exceptPath) && !is_dir($strPath)) {
continue;
}
if (PSI_OS == 'WINNT') {
$strProgrammpath = $strPathS.$strProgram;
} else {
$strProgrammpath = $strPathS.$strProgram;
}
if (is_executable($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
* 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 &$strBuffer output of the command
* @param boolean $booErrorRep en- or disables the reporting of errors which should be logged
* @param integer $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, $timeout = PSI_EXEC_TIMEOUT_INT)
{
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));
if ($out == false) {
if (substr(PSI_LOG, 0, 1)=="-") {
$strBuffer = '';
 
return false;
}
} else {
$strBuffer = $out;
 
return true;
}
}
 
if ((PSI_OS !== 'WINNT') && preg_match('/^([^=]+=[^ \t]+)[ \t]+(.*)$/', $strProgramname, $strmatch)) {
$strSet = $strmatch[1].' ';
$strProgramname = $strmatch[2];
} else {
$strSet = '';
}
$strProgram = self::_findProgram($strProgramname);
$error = PSI_Error::singleton();
if (!$strProgram) {
if ($booErrorRep) {
$error->addError('find_program("'.$strProgramname.'")', 'program not found on the machine');
}
 
return false;
} else {
if (preg_match('/\s/', $strProgram)) {
$strProgram = '"'.$strProgram.'"';
}
}
 
if ((PSI_OS !== 'WINNT') && 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) {
if ($booErrorRep) {
$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;
}
}
}
}
 
// 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);
}
}
$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 (PSI_OS == 'WINNT') {
$process = $pipes[1] = popen($strSet.$strProgram.$strArgs." 2>nul", "r");
} else {
$process = $pipes[1] = popen($strSet.$strProgram.$strArgs." 2>/dev/null", "r");
}
} else {
$process = proc_open($strSet.$strProgram.$strArgs, $descriptorspec, $pipes);
}
if (is_resource($process)) {
$te = self::_timeoutfgets($pipes, $strBuffer, $strError, $timeout);
if (defined("PSI_MODE_POPEN") && PSI_MODE_POPEN === true) {
$return_value = pclose($pipes[1]);
} else {
fclose($pipes[0]);
fclose($pipes[1]);
fclose($pipes[2]);
// It is important that you close any pipes before calling
// proc_close in order to avoid a deadlock
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) {
$error->addError($strProgram, "\nOpen process error");
}
 
return false;
}
$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);
}
if (! empty($strError)) {
if ($booErrorRep) {
$error->addError($strProgram, $strError."\nReturn value: ".$return_value);
}
 
return $return_value == 0;
}
 
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 = "")
{
$filename = preg_replace($match, $replace, $similarFileName);
if (CommonFunctions::fileexists($filename) && CommonFunctions::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 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_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) {
if (substr(PSI_LOG, 0, 1)=="-") {
$strRet = '';
 
return false;
}
} else {
$strRet = $out;
 
return true;
}
}
 
$strFile = "";
$intCurLine = 1;
$error = PSI_Error::singleton();
if (file_exists($strFileName)) {
if (is_readable($strFileName)) {
if ($fd = fopen($strFileName, 'r')) {
while (!feof($fd)) {
$strFile .= fgets($fd, $intBytes);
if ($intLines <= $intCurLine && $intLines != 0) {
break;
} else {
$intCurLine++;
}
}
fclose($fd);
$strRet = $strFile;
if (defined('PSI_LOG') && is_string(PSI_LOG) && (strlen(PSI_LOG)>0) && (substr(PSI_LOG, 0, 1)!="-") && (substr(PSI_LOG, 0, 1)!="+")) {
if ((strlen($strRet)>0)&&(substr($strRet, -1)!="\n")) {
error_log("---".gmdate('r T')."--- Reading: ".$strFileName."\n".$strRet."\n", 3, PSI_LOG);
} else {
error_log("---".gmdate('r T')."--- Reading: ".$strFileName."\n".$strRet, 3, PSI_LOG);
}
}
} else {
if ($booErrorRep) {
$error->addError('fopen('.$strFileName.')', 'file can not read by phpsysinfo');
}
 
return false;
}
} else {
if ($booErrorRep) {
$error->addError('fopen('.$strFileName.')', 'file permission error');
}
 
return false;
}
} else {
if ($booErrorRep) {
$error->addError('file_exists('.$strFileName.')', 'the file does not exist on your machine');
}
 
return false;
}
 
return true;
}
 
/**
* file exists
*
* @param string $strFileName name of the file which should be check
*
* @return boolean command successfull or not
*/
public static function fileexists($strFileName)
{
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)
&& ($contents = @file_get_contents($log_file))
&& preg_match("/^\-\-\-[^-\n]+\-\-\- ".preg_quote("Reading: ".$strFileName, '/')."\n/m", $contents)) {
return true;
} else {
if (substr(PSI_LOG, 0, 1)=="-") {
return false;
}
}
}
 
$exists = file_exists($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;
}
 
/**
* reads a directory and return the name of the files and directorys in it
*
* @param string $strPath path of the directory which should be read
* @param boolean $booErrorRep en- or disables the reporting of errors which should be logged
*
* @return array content of the directory excluding . and ..
*/
public static function gdc($strPath, $booErrorRep = true)
{
$arrDirectoryContent = array();
$error = PSI_Error::singleton();
if (is_dir($strPath)) {
if ($handle = opendir($strPath)) {
while (($strFile = readdir($handle)) !== false) {
if ($strFile != "." && $strFile != "..") {
$arrDirectoryContent[] = $strFile;
}
}
closedir($handle);
} else {
if ($booErrorRep) {
$error->addError('opendir('.$strPath.')', 'directory can not be read by phpsysinfo');
}
}
} else {
if ($booErrorRep) {
$error->addError('is_dir('.$strPath.')', 'directory does not exist on your machine');
}
}
 
return $arrDirectoryContent;
}
 
/**
* Check for needed php extensions
*
* We need that extensions for almost everything
* This function will return a hard coded
* XML string (with headers) if the SimpleXML extension isn't loaded.
* Then it will terminate the script.
* See bug #1787137
*
* @param array $arrExt additional extensions for which a check should run
*
* @return void
*/
public static function checkForExtensions($arrExt = array())
{
if ((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', 'dom', 'mbstring', 'com_dotnet');
else
$arrReq = array('simplexml', 'pcre', 'xml', 'dom', 'mbstring');
$extensions = array_merge($arrExt, $arrReq);
$text = "";
$error = false;
$text .= "<?xml version='1.0'?>\n";
$text .= "<phpsysinfo>\n";
$text .= " <Error>\n";
foreach ($extensions as $extension) {
if (!extension_loaded($extension)) {
$text .= " <Function>checkForExtensions</Function>\n";
$text .= " <Message>phpSysInfo requires the ".$extension." extension to php in order to work properly.</Message>\n";
$error = true;
}
}
$text .= " </Error>\n";
$text .= "</phpsysinfo>";
if ($error) {
header("Content-Type: text/xml\n\n");
echo $text;
die();
}
}
 
/**
* 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
*
* @return boolean timeout expired or not
*/
private static function _timeoutfgets($pipes, &$out, &$err, $timeout)
{
$w = null;
$e = null;
$te = false;
 
if (defined("PSI_MODE_POPEN") && PSI_MODE_POPEN === true) {
$pipe2 = false;
} else {
$pipe2 = true;
}
while (!(feof($pipes[1]) && (!$pipe2 || feof($pipes[2])))) {
if ($pipe2) {
$read = array($pipes[1], $pipes[2]);
} else {
$read = array($pipes[1]);
}
 
$n = stream_select($read, $w, $e, $timeout);
 
if ($n === false) {
error_log('stream_select: failed !');
break;
} elseif ($n === 0) {
error_log('stream_select: timeout expired !');
$te = true;
break;
}
 
foreach ($read as $r) {
if ($r == $pipes[1]) {
$out .= fread($r, 4096);
} elseif (feof($pipes[1]) && $pipe2 && ($r == $pipes[2])) {//read STDERR after STDOUT
$err .= fread($r, 4096);
}
}
}
 
return $te;
}
 
/**
* function for getting a list of values in the specified context
* optionally filter this list, based on the list from third parameter
*
* @param $wmi object 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 (gettype($wmi) === "object") {
$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 = PSI_Error::singleton();
$error->addError("getWMI()", preg_replace('/<br\/>/', "\n", preg_replace('/<b>|<\/b>/', '', $e->getMessage())));
}
}
}
 
return $arrData;
}
 
/**
* get all configured plugins from phpsysinfo.ini (file must be included and processed before calling this function)
*
* @return array
*/
public static function getPlugins()
{
if (defined('PSI_PLUGINS') && is_string(PSI_PLUGINS)) {
if (preg_match(ARRAY_EXP, PSI_PLUGINS)) {
return eval(strtolower(PSI_PLUGINS));
} else {
return array(strtolower(PSI_PLUGINS));
}
} else {
return array();
}
}
 
/**
* name natural compare function
*
* @return comprasion result
*/
public static function name_natural_compare($a, $b)
{
return strnatcmp($a->getName(), $b->getName());
}
 
/**
* readReg function
*
* @return boolean command successfull or not
*/
public static function readReg($reg, $strName, &$strBuffer, $booErrorRep = true)
{
$strBuffer = '';
if ($reg === false) {
$last = strrpos($strName, "\\");
$keyname = substr($strName, $last + 1);
if (CommonFunctions::$_cp) {
if (CommonFunctions::executeProgram('cmd', '/c chcp '.CommonFunctions::$_cp.' && reg query "'.substr($strName, 0, $last).'" /v '.$keyname.' 2>&1', $strBuf, $booErrorRep) && (strlen($strBuf) > 0) && preg_match("/^\s*".$keyname."\s+REG_\S+\s+(.+)\s*$/mi", $strBuf, $buffer2)) {
$strBuffer = $buffer2[1];
} else {
return false;
}
} else {
if (CommonFunctions::executeProgram('reg', 'query "'.substr($strName, 0, $last).'" /v '.$keyname.' 2>&1', $strBuf, $booErrorRep) && (strlen($strBuf) > 0) && preg_match("/^\s*".$keyname."\s+REG_\S+\s+(.+)\s*$/mi", $strBuf, $buffer2)) {
$strBuffer = $buffer2[1];
} else {
return false;
}
}
} elseif (gettype($reg) === "object") {
try {
$strBuffer = $reg->RegRead($strName);
} catch (Exception $e) {
if ($booErrorRep) {
$error = PSI_Error::singleton();
$error->addError("readReg()", preg_replace('/<br\/>/', "\n", preg_replace('/<b>|<\/b>/', '', $e->getMessage())));
}
 
return false;
}
}
 
return true;
}
 
 
/**
* enumKey function
*
* @return boolean command successfull or not
*/
public static function enumKey($key, $strName, &$arrBuffer, $booErrorRep = true)
{
$_hkey = array('HKEY_CLASSES_ROOT'=>0x80000000, 'HKEY_CURRENT_USER'=>0x80000001, 'HKEY_LOCAL_MACHINE'=>0x80000002, 'HKEY_USERS'=>0x80000003, 'HKEY_PERFORMANCE_DATA'=>0x80000004, 'HKEY_PERFORMANCE_TEXT'=>0x80000050, 'HKEY_PERFORMANCE_NLSTEXT'=>0x80000060, 'HKEY_CURRENT_CONFIG'=>0x80000005, 'HKEY_DYN_DATA'=>0x80000006);
 
$arrBuffer = array();
if ($key === false) {
if (CommonFunctions::$_cp) {
if (CommonFunctions::executeProgram('cmd', '/c chcp '.CommonFunctions::$_cp.' && reg query "'.$strName.'" 2>&1', $strBuf, $booErrorRep) && (strlen($strBuf) > 0) && preg_match_all("/^".preg_replace("/\\\\/", "\\\\\\\\", $strName)."\\\\(.*)/mi", $strBuf, $buffer2)) {
foreach ($buffer2[1] as $sub_key) {
$arrBuffer[] = trim($sub_key);
}
} else {
return false;
}
} else {
if (CommonFunctions::executeProgram('reg', 'query "'.$strName.'" 2>&1', $strBuf, $booErrorRep) && (strlen($strBuf) > 0) && preg_match_all("/^".preg_replace("/\\\\/", "\\\\\\\\", $strName)."\\\\(.*)/mi", $strBuf, $buffer2)) {
foreach ($buffer2[1] as $sub_key) {
$arrBuffer[] = trim($sub_key);
}
} else {
return false;
}
}
} elseif (gettype($key) === "object") {
$first = strpos($strName, "\\");
$hkey = substr($strName, 0, $first);
if (isset($_hkey[$hkey])) {
$sub_keys = new VARIANT();
try {
$key->EnumKey(strval($_hkey[$hkey]), substr($strName, $first+1), $sub_keys);
} catch (Exception $e) {
if ($booErrorRep) {
$error = PSI_Error::singleton();
$error->addError("enumKey()", preg_replace('/<br\/>/', "\n", preg_replace('/<b>|<\/b>/', '', $e->getMessage())));;
}
 
return false;
}
foreach ($sub_keys as $sub_key) {
$arrBuffer[] = $sub_key;
}
} else {
return false;
}
}
 
return true;
}
}
/web/acc/phpsysinfo/includes/class.Parser.inc.php
0,0 → 1,275
<?php
/**
* parser Class
*
* PHP version 5
*
* @category PHP
* @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 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
*/
/**
* parser class with common used parsing metods
*
* @category PHP
* @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 version 2, or (at your option) any later version
* @version Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
class Parser
{
/**
* parsing the output of lspci command
*
* @param bool $debug
* @return array
*/
public static function lspci($debug = PSI_DEBUG)
{
$arrResults = array();
if (CommonFunctions::executeProgram("lspci", "", $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);
$arrResults[] = $dev;
}
}
 
return $arrResults;
}
 
/**
* parsing the output of df command
*
* @param string $df_param additional parameter for df command
* @param bool $get_inodes
*
* @return array
*/
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)) {
$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)) {
$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)) {
$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)) {
$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)) {
$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
$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!=="")) {
$df = preg_split("/\n/", $df, -1, PREG_SPLIT_NO_EMPTY);
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
foreach ($df2 as $df2_line) {
if (preg_match("/^(\S+).*\s([0-9]+)%/", $df2_line, $inode_buf)) {
$df_inodes[$inode_buf[1]] = $inode_buf[2];
}
}
}
}
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)) {
if (count($df_buf1) == 3) {
$df_buf = array($df_buf2[1], $df_buf2[4], $df_buf2[6], $df_buf2[8], $df_buf2[10], $df_buf1[2]);
} else {
$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]);
 
$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_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;
}
}
}
}
}
 
return $arrResult;
}
}
/web/acc/phpsysinfo/includes/mb/class.coretemp.inc.php
0,0 → 1,54
<?php
/**
* coretemp sensor class, getting hardware temperature information through sysctl on FreeBSD
* or from /sys/devices/platform/coretemp. on Linux
*
* 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 Coretemp extends Hwmon
{
/**
* get the information
*
* @see PSI_Interface_Sensor::build()
*
* @return Void
*/
public function build()
{
if (PSI_OS == 'Linux') {
$hwpaths = glob("/sys/devices/platform/coretemp.*/", GLOB_NOSORT);
if (is_array($hwpaths) && (count($hwpaths) > 0)) {
$hwpaths = array_merge($hwpaths, glob("/sys/devices/platform/coretemp.*/hwmon/hwmon*/", GLOB_NOSORT));
}
if (is_array($hwpaths) && (($totalh = count($hwpaths)) > 0)) {
for ($h = 0; $h < $totalh; $h++) {
$this->_temperature($hwpaths[$h]);
}
}
} else {
$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);
}
}
}
}
}
/web/acc/phpsysinfo/includes/mb/class.freeipmi.inc.php
0,0 → 1,187
<?php
/**
* freeipmi sensor class, getting information from ipmi-sensors
*
* PHP version 5
*
* @category PHP
* @package PSI_Sensor
* @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 FreeIPMI 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();
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);
break;
case 'data':
if (CommonFunctions::rfts(PSI_APP_ROOT.'/data/freeipmi.txt', $lines)) {
$this->_lines = preg_split("/\n/", $lines, -1, PREG_SPLIT_NO_EMPTY);
}
break;
default:
$this->error->addConfigError('__construct()', '[sensor_freeipmi] ACCESS');
break;
}
}
 
/**
* get temperature information
*
* @return void
*/
private function _temperature()
{
foreach ($this->_lines as $line) {
$buffer = preg_split("/\s*\|\s*/", $line);
if ($buffer[2] == "Temperature" && $buffer[11] != "N/A" && $buffer[4] == "C") {
$dev = new SensorDevice();
$dev->setName($buffer[1]);
$dev->setValue($buffer[3]);
if ($buffer[9] != "N/A") $dev->setMax($buffer[9]);
if ($buffer[11] != "'OK'") $dev->setEvent(trim($buffer[11], "'"));
$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] == "Voltage" && $buffer[11] != "N/A" && $buffer[4] == "V") {
$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->setMbVolt($dev);
}
}
}
 
/**
* get fan information
*
* @return void
*/
private function _fans()
{
foreach ($this->_lines as $line) {
$buffer = preg_split("/\s*\|\s*/", $line);
if ($buffer[2] == "Fan" && $buffer[11] != "N/A" && $buffer[4] == "RPM") {
$dev = new SensorDevice();
$dev->setName($buffer[1]);
$dev->setValue($buffer[3]);
if ($buffer[6] != "N/A") {
$dev->setMin($buffer[6]);
} elseif (($buffer[9] != "N/A") && ($buffer[9]<$buffer[3])) { //max instead min issue
$dev->setMin($buffer[9]);
}
if ($buffer[11] != "'OK'") $dev->setEvent(trim($buffer[11], "'"));
$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] == "Current" && $buffer[11] != "N/A" && $buffer[4] == "W") {
$dev = new SensorDevice();
$dev->setName($buffer[1]);
$dev->setValue($buffer[3]);
if ($buffer[9] != "N/A") $dev->setMax($buffer[9]);
if ($buffer[11] != "'OK'") $dev->setEvent(trim($buffer[11], "'"));
$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] == "Current" && $buffer[11] != "N/A" && $buffer[4] == "A") {
$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);
}
}
}
 
/**
* 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
*/
public function build()
{
$this->_temperature();
$this->_voltage();
$this->_fans();
$this->_power();
$this->_current();
$this->_other();
}
}
/web/acc/phpsysinfo/includes/mb/class.hddtemp.inc.php
1,114 → 1,124
<?php
/**
* hddtemp sensor class, getting information from hddtemp
*
* PHP version 5
*
* @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 version 2, or (at your option) any later version
* @version Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
class HDDTemp extends Sensors
{
/**
* get the temperature information from hddtemp
* access is available through tcp or command
*
* @return void
*/
private function _temperature()
{
$ar_buf = array();
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);
// if connected, read the output of the hddtemp daemon
if ($fp) {
while (!feof($fp)) {
$lines .= fread($fp, 1024);
}
fclose($fp);
} else {
$this->error->addError("HDDTemp error", $errno.", ".$errstr);
}
$lines = str_replace("||", "|\n|", $lines);
$ar_buf = preg_split("/\n/", $lines, -1, PREG_SPLIT_NO_EMPTY);
break;
case 'command':
$strDrives = "";
$strContent = "";
$hddtemp_value = "";
if (CommonFunctions::rfts("/proc/diskstats", $strContent, 0, 4096, false)) {
$arrContent = preg_split("/\n/", $strContent, -1, PREG_SPLIT_NO_EMPTY);
foreach ($arrContent as $strLine) {
preg_match("/^\s(.*)\s([a-z]*)\s(.*)/", $strLine, $arrSplit);
if (! empty($arrSplit[2])) {
$strDrive = '/dev/'.$arrSplit[2];
if (file_exists($strDrive)) {
$strDrives = $strDrives.$strDrive.' ';
}
}
}
} else {
if (CommonFunctions::rfts("/proc/partitions", $strContent, 0, 4096, false)) {
$arrContent = preg_split("/\n/", $strContent, -1, PREG_SPLIT_NO_EMPTY);
foreach ($arrContent as $strLine) {
if (!preg_match("/^\s(.*)\s([\/a-z0-9]*(\/disc))\s(.*)/", $strLine, $arrSplit)) {
preg_match("/^\s(.*)\s([a-z]*)\s(.*)/", $strLine, $arrSplit);
}
if (! empty($arrSplit[2])) {
$strDrive = '/dev/'.$arrSplit[2];
if (file_exists($strDrive)) {
$strDrives = $strDrives.$strDrive.' ';
}
}
}
}
}
if (trim($strDrives) == "") {
break;
}
if (CommonFunctions::executeProgram("hddtemp", $strDrives, $hddtemp_value, PSI_DEBUG)) {
$hddtemp_value = preg_split("/\n/", $hddtemp_value, -1, PREG_SPLIT_NO_EMPTY);
foreach ($hddtemp_value as $line) {
$temp = preg_split("/:\s/", $line, 3);
if (count($temp) == 3 && preg_match("/^[0-9]/", $temp[2])) {
preg_match("/^([0-9]*)(.*)/", $temp[2], $ar_temp);
$temp[2] = trim($ar_temp[1]);
$temp[3] = trim($ar_temp[2]);
array_push($ar_buf, "|".implode("|", $temp)."|");
}
}
}
break;
default:
$this->error->addConfigError("temperature()", "[sensor_hddtemp] ACCESS");
break;
}
// Timo van Roermund: parse the info from the hddtemp daemon.
foreach ($ar_buf as $line) {
$data = array();
if (preg_match("/\|(.*)\|(.*)\|(.*)\|(.*)\|/", $line, $data)) {
if (trim($data[3]) != "ERR") {
// get the info we need
$dev = new SensorDevice();
$dev->setName($data[1] . ' (' . (strpos($data[2], " ")?substr($data[2], 0, strpos($data[2], " ")):$data[2]) . ')');
if (is_numeric($data[3])) {
$dev->setValue($data[3]);
}
// $dev->setMax(60);
$this->mbinfo->setMbTemp($dev);
}
}
}
}
 
// phpSysInfo - A PHP System Information Script
// http://phpsysinfo.sourceforge.net/
 
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
 
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
// $Id: class.hddtemp.inc.php,v 1.7 2007/01/21 13:17:20 bigmichi1 Exp $
 
class hddtemp {
function temperature($hddtemp_avail) {
$ar_buf = array();
$results = array();
switch ($hddtemp_avail) {
case "tcp":
// Timo van Roermund: connect to the hddtemp daemon, use a 5 second timeout.
$fp = fsockopen('localhost', 7634, $errno, $errstr, 5);
// if connected, read the output of the hddtemp daemon
if ($fp) {
// read output of the daemon
$lines = '';
while (!feof($fp)) {
$lines .= fread($fp, 1024);
}
// close the connection
fclose($fp);
} else {
die("HDDTemp error: " . $errno . ", " . $errstr);
}
$lines = str_replace("||", "|\n|", $lines);
$ar_buf = explode("\n", $lines);
break;
case "suid":
$strDrives = "";
$strContent = rfts( "/proc/diskstats", 0, 4096, false );
if( $strContent != "ERROR" ) {
$arrContent = explode( "\n", $strContent );
foreach( $arrContent as $strLine ) {
preg_match( "/^\s(.*)\s([a-z]*)\s(.*)/", $strLine, $arrSplit );
if( !empty( $arrSplit[2] ) ) {
$strDrive = '/dev/' . $arrSplit[2];
if( file_exists( $strDrive ) ) {
$strDrives = $strDrives . $strDrive . ' ';
}
}
}
} else {
$strContent = rfts( "/proc/partitions", 0, 4096, false );
if( $strContent != "ERROR" ) {
$arrContent = explode( "\n", $strContent );
foreach( $arrContent as $strLine ) {
if( !preg_match( "/^\s(.*)\s([\/a-z0-9]*(\/disc))\s(.*)/", $strLine, $arrSplit ) ) {
preg_match( "/^\s(.*)\s([a-z]*)\s(.*)/", $strLine, $arrSplit );
}
if( !empty( $arrSplit[2] ) ) {
$strDrive = '/dev/' . $arrSplit[2];
if( file_exists( $strDrive ) ) {
$strDrives = $strDrives . $strDrive . ' ';
}
}
}
}
}
if( trim( $strDrives ) == "" ) {
return array();
}
 
$hddtemp_value = execute_program("hddtemp", $strDrives);
$hddtemp_value = explode("\n", $hddtemp_value);
foreach($hddtemp_value as $line) {
$temp = preg_split("/:\s/", $line, 3);
if(count($temp) == 3 && preg_match("/^[0-9]/", $temp[2])) {
list($temp[2], $temp[3]) = (preg_split("/\s/", $temp[2]));
array_push( $ar_buf, "|" . implode("|", $temp) . "|");
}
}
break;
default:
die("Bad hddtemp configuration in config.php");
}
// Timo van Roermund: parse the info from the hddtemp daemon.
$i = 0;
foreach($ar_buf as $line) {
$data = array();
if (ereg("\|(.*)\|(.*)\|(.*)\|(.*)\|", $line, $data)) {
if( trim($data[3]) != "ERR" ) {
// get the info we need
$results[$i]['label'] = $data[1];
$results[$i]['value'] = $data[3];
$results[$i]['model'] = $data[2];
$i++;
}
}
}
return $results;
}
/**
* get the information
*
* @see PSI_Interface_Sensor::build()
*
* @return Void
*/
public function build()
{
$this->_temperature();
}
}
?>
/web/acc/phpsysinfo/includes/mb/class.healthd.inc.php
1,116 → 1,157
<?php
<?php
/**
* healthd sensor class, getting information from healthd
*
* 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 Healthd extends Sensors
{
/**
* content to parse
*
* @var array
*/
private $_values = array();
 
// phpSysInfo - A PHP System Information Script
// http://phpsysinfo.sourceforge.net/
/**
* fill the private content var through command or data access
*/
public function __construct()
{
parent::__construct();
switch (defined('PSI_SENSOR_HEALTHD_ACCESS')?strtolower(PSI_SENSOR_HEALTHD_ACCESS):'command') {
case 'command':
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 'data':
if (CommonFunctions::rfts(PSI_APP_ROOT.'/data/healthd.txt', $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()', '[sensor_healthd] ACCESS');
break;
}
}
 
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
/**
* get temperature information
*
* @return void
*/
private function _temperature()
{
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);
}
}
 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
 
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
// $Id: class.healthd.inc.php,v 1.6 2007/02/18 19:11:31 bigmichi1 Exp $
 
class mbinfo {
var $lines;
 
function temperature() {
$ar_buf = array();
$results = array();
 
if (!isset($this->lines)) {
$this->lines = execute_program('healthdc', '-t');
/**
* get fan information
*
* @return void
*/
private function _fans()
{
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);
}
}
 
$ar_buf = preg_split("/\t+/", $this->lines);
 
$results[0]['label'] = 'temp1';
$results[0]['value'] = $ar_buf[1];
$results[0]['limit'] = '70.0';
$results[0]['percent'] = $results[0]['value'] * 100 / $results[0]['limit'];
$results[1]['label'] = 'temp2';
$results[1]['value'] = $ar_buf[2];
$results[1]['limit'] = '70.0';
$results[1]['percent'] = $results[1]['value'] * 100 / $results[1]['limit'];
$results[2]['label'] = 'temp3';
$results[2]['value'] = $ar_buf[3];
$results[2]['limit'] = '70.0';
$results[2]['percent'] = $results[2]['value'] * 100 / $results[2]['limit'];
return $results;
}
 
function fans() {
$ar_buf = array();
$results = array();
 
if (!isset($this->lines)) {
$this->lines = execute_program('healthdc', '-t');
/**
* get voltage information
*
* @return void
*/
private function _voltage()
{
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);
}
}
 
$ar_buf = preg_split("/\t+/", $this->lines);
 
$results[0]['label'] = 'fan1';
$results[0]['value'] = $ar_buf[4];
$results[0]['min'] = '3000';
$results[1]['label'] = 'fan2';
$results[1]['value'] = $ar_buf[5];
$results[1]['min'] = '3000';
$results[2]['label'] = 'fan3';
$results[2]['value'] = $ar_buf[6];
$results[2]['min'] = '3000';
 
return $results;
}
 
function voltage() {
$ar_buf = array();
$results = array();
 
if (!isset($this->lines)) {
$this->lines = execute_program('healthdc', '-t');
/**
* get the information
*
* @see PSI_Interface_Sensor::build()
*
* @return Void
*/
public function build()
{
$this->_temperature();
$this->_fans();
$this->_voltage();
}
 
$ar_buf = preg_split("/\t+/", $this->lines);
 
$results[0]['label'] = 'Vcore1';
$results[0]['value'] = $ar_buf[7];
$results[0]['min'] = '0.00';
$results[0]['max'] = '0.00';
$results[1]['label'] = 'Vcore2';
$results[1]['value'] = $ar_buf[8];
$results[1]['min'] = '0.00';
$results[1]['max'] = '0.00';
$results[2]['label'] = '3volt';
$results[2]['value'] = $ar_buf[9];
$results[2]['min'] = '0.00';
$results[2]['max'] = '0.00';
$results[3]['label'] = '+5Volt';
$results[3]['value'] = $ar_buf[10];
$results[3]['min'] = '0.00';
$results[3]['max'] = '0.00';
$results[4]['label'] = '+12Volt';
$results[4]['value'] = $ar_buf[11];
$results[4]['min'] = '0.00';
$results[4]['max'] = '0.00';
$results[5]['label'] = '-12Volt';
$results[5]['value'] = $ar_buf[12];
$results[5]['min'] = '0.00';
$results[5]['max'] = '0.00';
$results[6]['label'] = '-5Volt';
$results[6]['value'] = $ar_buf[13];
$results[6]['min'] = '0.00';
$results[6]['max'] = '0.00';
 
return $results;
}
}
 
?>
}
/web/acc/phpsysinfo/includes/mb/class.hwmon.inc.php
0,0 → 1,256
<?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 = glob($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 ($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 = glob($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 = glob($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 = glob($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 = glob($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()
{
$hwpaths = glob("/sys/class/hwmon/hwmon*/", GLOB_NOSORT);
if (is_array($hwpaths) && (count($hwpaths) > 0)) {
$hwpaths = array_merge($hwpaths, glob("/sys/class/hwmon/hwmon*/device/", GLOB_NOSORT));
}
if (is_array($hwpaths) && (($totalh = count($hwpaths)) > 0)) {
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]);
}
}
}
}
/web/acc/phpsysinfo/includes/mb/class.hwsensors.inc.php
1,80 → 1,145
<?php
<?php
/**
* hwsensors sensor class, getting information from hwsensors
*
* 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 HWSensors extends Sensors
{
/**
* content to parse
*
* @var array
*/
private $_lines = array();
 
// phpSysInfo - A PHP System Information Script
// http://phpsysinfo.sourceforge.net/
/**
* 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);
}
 
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
 
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
// $Id: class.hwsensors.inc.php,v 1.4 2006/05/20 17:01:07 bigmichi1 Exp $
 
class mbinfo {
var $lines;
 
function mbinfo() {
$this->lines = execute_program('sysctl', '-w hw.sensors');
$this->lines = explode("\n", $this->lines);
/**
* get temperature information
*
* @return void
*/
private function _temperature()
{
foreach ($this->_lines as $line) {
if (preg_match('/^hw\.sensors\.[0-9]+=[^\s,]+,\s+([^,]+),\s+temp,\s+([0-9\.]+)\s+degC.*$/', $line, $ar_buf)) {
$dev = new SensorDevice();
$dev->setName($ar_buf[1]);
$dev->setValue($ar_buf[2]);
$this->mbinfo->setMbTemp($dev);
} elseif (preg_match('/^hw\.sensors\.[0-9]+=[^\s,]+,\s+([^,]+),\s+([0-9\.]+)\s+degC$/', $line, $ar_buf)) {
$dev = new SensorDevice();
$dev->setName($ar_buf[1]);
$dev->setValue($ar_buf[2]);
$this->mbinfo->setMbTemp($dev);
} elseif (preg_match('/^hw\.sensors\.[^\.]+\.(.*)=([0-9\.]+)\s+degC\s+\((.*)\)$/', $line, $ar_buf)) {
$dev = new SensorDevice();
$dev->setName($ar_buf[3]);
$dev->setValue($ar_buf[2]);
$this->mbinfo->setMbTemp($dev);
} elseif (preg_match('/^hw\.sensors\.[^\.]+\.(.*)=([0-9\.]+)\s+degC$/', $line, $ar_buf)) {
$dev = new SensorDevice();
$dev->setName($ar_buf[1]);
$dev->setValue($ar_buf[2]);
$this->mbinfo->setMbTemp($dev);
}
}
}
 
function temperature() {
$ar_buf = array();
$results = array();
 
foreach( $this->lines as $line ) {
$ar_buf = preg_split("/[\s,]+/", $line);
if( isset( $ar_buf[3] ) && $ar_buf[2] == 'temp') {
$results[$j]['label'] = $ar_buf[1];
$results[$j]['value'] = $ar_buf[3];
$results[$j]['limit'] = '70.0';
$results[$j]['percent'] = $results[$j]['value'] * 100 / $results[$j]['limit'];
$j++;
}
}
return $results;
/**
* get fan information
*
* @return void
*/
private function _fans()
{
foreach ($this->_lines as $line) {
if (preg_match('/^hw\.sensors\.[0-9]+=[^\s,]+,\s+([^,]+),\s+fanrpm,\s+([0-9\.]+)\s+RPM.*$/', $line, $ar_buf)) {
$dev = new SensorDevice();
$dev->setName($ar_buf[1]);
$dev->setValue($ar_buf[2]);
$this->mbinfo->setMbFan($dev);
} elseif (preg_match('/^hw\.sensors\.[0-9]+=[^\s,]+,\s+([^,]+),\s+([0-9\.]+)\s+RPM$/', $line, $ar_buf)) {
$dev = new SensorDevice();
$dev->setName($ar_buf[1]);
$dev->setValue($ar_buf[2]);
$this->mbinfo->setMbFan($dev);
} elseif (preg_match('/^hw\.sensors\.[^\.]+\.(.*)=([0-9\.]+)\s+RPM\s+\((.*)\)$/', $line, $ar_buf)) {
$dev = new SensorDevice();
$dev->setName($ar_buf[3]);
$dev->setValue($ar_buf[2]);
$this->mbinfo->setMbFan($dev);
} elseif (preg_match('/^hw\.sensors\.[^\.]+\.(.*)=([0-9\.]+)\s+RPM$/', $line, $ar_buf)) {
$dev = new SensorDevice();
$dev->setName($ar_buf[1]);
$dev->setValue($ar_buf[2]);
$this->mbinfo->setMbFan($dev);
}
}
}
 
function fans() {
$ar_buf = array();
$results = array();
 
foreach( $this->lines as $line ) {
$ar_buf = preg_split("/[\s,]+/", $line );
if( isset( $ar_buf[3] ) && $ar_buf[2] == 'fanrpm') {
$results[$j]['label'] = $ar_buf[1];
$results[$j]['value'] = $ar_buf[3];
$j++;
}
}
return $results;
/**
* get voltage information
*
* @return void
*/
private function _voltage()
{
foreach ($this->_lines as $line) {
if (preg_match('/^hw\.sensors\.[0-9]+=[^\s,]+,\s+([^,]+),\s+volts_dc,\s+([0-9\.]+)\s+V.*$/', $line, $ar_buf)) {
$dev = new SensorDevice();
$dev->setName($ar_buf[1]);
$dev->setValue($ar_buf[2]);
$this->mbinfo->setMbVolt($dev);
} elseif (preg_match('/^hw\.sensors\.[0-9]+=[^\s,]+,\s+([^,]+),\s+([0-9\.]+)\s+V\sDC$/', $line, $ar_buf)) {
$dev = new SensorDevice();
$dev->setName($ar_buf[1]);
$dev->setValue($ar_buf[2]);
$this->mbinfo->setMbVolt($dev);
} elseif (preg_match('/^hw\.sensors\.[^\.]+\.(.*)=([0-9\.]+)\s+VDC\s+\((.*)\)$/', $line, $ar_buf)) {
$dev = new SensorDevice();
$dev->setName($ar_buf[3]);
$dev->setValue($ar_buf[2]);
$this->mbinfo->setMbVolt($dev);
} elseif (preg_match('/^hw\.sensors\.[^\.]+\.(.*)=([0-9\.]+)\s+VDC$/', $line, $ar_buf)) {
$dev = new SensorDevice();
$dev->setName($ar_buf[1]);
$dev->setValue($ar_buf[2]);
$this->mbinfo->setMbVolt($dev);
}
}
}
 
function voltage() {
$ar_buf = array();
$results = array();
 
foreach( $this->lines as $line ) {
$ar_buf = preg_split("/[\s,]+/", $line );
if ( isset( $ar_buf[3] ) && $ar_buf[2] == 'volts_dc') {
$results[$j]['label'] = $ar_buf[1];
$results[$j]['value'] = $ar_buf[3];
$results[$j]['min'] = '0.00';
$results[$j]['max'] = '0.00';
$j++;
}
}
return $results;
/**
* get the information
*
* @see PSI_Interface_Sensor::build()
*
* @return Void
*/
public function build()
{
$this->_temperature();
$this->_voltage();
$this->_fans();
}
}
 
?>
/web/acc/phpsysinfo/includes/mb/class.ipmitool.inc.php
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 = "";
switch (defined('PSI_SENSOR_IPMITOOL_ACCESS')?strtolower(PSI_SENSOR_IPMITOOL_ACCESS):'command') {
case 'command':
CommonFunctions::executeProgram('ipmitool', 'sensor -v', $lines);
break;
case 'data':
CommonFunctions::rfts(PSI_APP_ROOT.'/data/ipmitool.txt', $lines);
break;
default:
$this->error->addConfigError('__construct()', '[sensor_ipmitool] ACCESS');
break;
}
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];
}
break;
}
$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();
}
}
/web/acc/phpsysinfo/includes/mb/class.ipmiutil.inc.php
0,0 → 1,265
<?php
/**
* ipmiutil sensor class, getting information from ipmi-sensors
*
* PHP version 5
*
* @category PHP
* @package PSI_Sensor
* @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 IPMIutil 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();
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 'data':
if (CommonFunctions::rfts(PSI_APP_ROOT.'/data/ipmiutil.txt', $lines)) {
$this->_lines = preg_split("/\r?\n/", $lines, -1, PREG_SPLIT_NO_EMPTY);
}
break;
default:
$this->error->addConfigError('__construct()', '[sensor_ipmiutil] ACCESS');
break;
}
}
 
/**
* get temperature information
*
* @return void
*/
private function _temperature()
{
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)
&& $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("/^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))
||(isset($buffer[11]) && preg_match("/^hi-crit\s(\S+)\s*$/", $buffer[11], $limits))) {
$dev->setMax($limits[1]);
}
}
if ($buffer[5] != "OK") $dev->setEvent($buffer[5]);
$this->mbinfo->setMbTemp($dev);
}
}
}
 
/**
* get voltage information
*
* @return void
*/
private function _voltage()
{
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)
&& $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))
||(isset($buffer[11]) && preg_match("/^hi-crit\s(\S+)\s*$/", $buffer[11], $limits))) {
$dev->setMax($limits[1]);
}
}
if ($buffer[5] != "OK") $dev->setEvent($buffer[5]);
$this->mbinfo->setMbVolt($dev);
}
}
}
 
/**
* get fan information
*
* @return void
*/
private function _fans()
{
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)
&& $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]);
} elseif ((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))
||(isset($buffer[11]) && preg_match("/^hi-crit\s(\S+)\s*$/", $buffer[11], $limits))) {
if ($limits[1]<$value[1]) {//max instead min issue
$dev->setMin($limits[1]);
}
}
}
if ($buffer[5] != "OK") $dev->setEvent($buffer[5]);
$this->mbinfo->setMbFan($dev);
}
}
}
 
/**
* get power information
*
* @return void
*/
private function _power()
{
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)
&& $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("/^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))
||(isset($buffer[11]) && preg_match("/^hi-crit\s(\S+)\s*$/", $buffer[11], $limits))) {
$dev->setMax($limits[1]);
}
}
if ($buffer[5] != "OK") $dev->setEvent($buffer[5]);
$this->mbinfo->setMbPower($dev);
}
}
}
 
/**
* get current information
*
* @return void
*/
private function _current()
{
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)
&& $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))
||(isset($buffer[11]) && preg_match("/^hi-crit\s(\S+)\s*$/", $buffer[11], $limits))) {
$dev->setMax($limits[1]);
}
}
if ($buffer[5] != "OK") $dev->setEvent($buffer[5]);
$this->mbinfo->setMbCurrent($dev);
}
}
}
 
/**
* 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])) {
$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);
}
$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();
}
}
/web/acc/phpsysinfo/includes/mb/class.k8temp.inc.php
0,0 → 1,80
<?php
/**
* K8Temp sensor class, getting information from k8temp
*
* 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 K8Temp extends Sensors
{
/**
* content to parse
*
* @var array
*/
private $_lines = array();
 
/**
* fill the private array
*/
public function __construct()
{
parent::__construct();
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 'data':
if (CommonFunctions::rfts(PSI_APP_ROOT.'/data/k8temp.txt', $lines)) {
$this->_lines = preg_split("/\n/", $lines, -1, PREG_SPLIT_NO_EMPTY);
}
break;
default:
$this->error->addConfigError('__construct()', '[sensor_k8temp] ACCESS');
break;
}
}
 
/**
* get temperature information
*
* @return void
*/
private function _temperature()
{
foreach ($this->_lines as $line) {
if (preg_match('/(.*):\s*(\d*)/', $line, $data)) {
if ($data[2] > 0) {
$dev = new SensorDevice();
$dev->setName($data[1]);
// $dev->setMax('70.0');
if ($data[2] < 250) {
$dev->setValue($data[2]);
}
$this->mbinfo->setMbTemp($dev);
}
}
}
}
 
/**
* get the information
*
* @see PSI_Interface_Sensor::build()
*
* @return Void
*/
public function build()
{
$this->_temperature();
}
}
/web/acc/phpsysinfo/includes/mb/class.lmsensors.inc.php
1,175 → 1,419
<?php
<?php
/**
* lmsensor sensor class, getting information from lmsensor
*
* 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 LMSensors extends Sensors
{
/**
* content to parse
*
* @var array
*/
private $_lines = array();
 
// phpSysInfo - A PHP System Information Script
// http://phpsysinfo.sourceforge.net/
/**
* fill the private content var through command or data access
*/
public function __construct()
{
parent::__construct();
$lines = "";
switch (defined('PSI_SENSOR_LMSENSORS_ACCESS')?strtolower(PSI_SENSOR_LMSENSORS_ACCESS):'command') {
case 'command':
CommonFunctions::executeProgram("sensors", "", $lines);
break;
case 'data':
CommonFunctions::rfts(PSI_APP_ROOT.'/data/lmsensors.txt', $lines);
break;
default:
$this->error->addConfigError('__construct()', '[sensor_lmsensors] ACCESS');
break;
}
 
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
if (trim($lines) !== "") {
$lines = str_replace(":\n", ":", $lines);
$lines = str_replace("\n\n", "\n", $lines);
$this->_lines = preg_split("/\n/", $lines, -1, PREG_SPLIT_NO_EMPTY);
}
}
 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
/**
* get temperature information
*
* @return void
*/
private function _temperature()
{
$applesmc = false;
$sname = '';
foreach ($this->_lines as $line) {
if ((trim($line) !== "") && (strpos($line, ':') === false)) {
//$applesmc = preg_match("/^applesmc-/", $line);
$sname = trim($line);
$applesmc = ($sname === "applesmc-isa-0300");
if (preg_match('/^([^-]+)-/', $sname, $snamebuf)) {
$sname = ' ('.$snamebuf[1].')';
} else {
$sname = '';
}
}
$data = array();
if (preg_match("/^(.+):(.+).C\s*\((.+)=(.+).C,(.+)=(.+).C\)(.*)\)/", $line, $data)) {
;
} elseif (preg_match("/^(.+):(.+).C\s*\((.+)=(.+).C,(.+)=(.+).C\)(.*)/", $line, $data)) {
;
} elseif (preg_match("/^(.+):(.+).C\s*\((.+)=(.+).C\)(.*)/", $line, $data)) {
;
} elseif (preg_match("/^(.+):(.+).C\s*\(/", $line, $data)) {
;
} else {
preg_match("/^(.+):(.+).C$/", $line, $data);
}
if (count($data)>2) {
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 ($applesmc && (strlen($data[1]) == 4)) {
if ($data[1][0] == "T") {
if ($data[1][1] == "A") {
$data[1] = $data[1] . " Ambient";
} elseif ($data[1][1] == "B") {
$data[1] = $data[1] . " Battery";
} 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 Bay";
} elseif ($data[1][1] == "h") {
$data[1] = $data[1] . " Heatpipe";
} elseif ($data[1][1] == "L") {
$data[1] = $data[1] . " LCD";
} elseif ($data[1][1] == "M") {
$data[1] = $data[1] . " Memory";
} elseif ($data[1][1] == "m") {
$data[1] = $data[1] . " Memory Contr.";
} elseif ($data[1][1] == "N") {
$data[1] = $data[1] . " Northbridge";
} elseif ($data[1][1] == "O") {
$data[1] = $data[1] . " Optical Drive";
} elseif ($data[1][1] == "p") {
$data[1] = $data[1] . " Power supply";
} elseif ($data[1][1] == "S") {
$data[1] = $data[1] . " Slot";
} elseif ($data[1][1] == "s") {
$data[1] = $data[1] . " Slot";
} elseif ($data[1][1] == "W") {
$data[1] = $data[1] . " Airport";
}
 
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
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";
}
}
}
 
// $Id: class.lmsensors.inc.php,v 1.19 2007/02/18 19:11:31 bigmichi1 Exp $
if (!defined('IN_PHPSYSINFO')) {
die("No Hacking");
}
$dev = new SensorDevice();
$dev->setName($data[1].$sname);
$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) || preg_match("/\sALARM\s+sensor\s+=/", $line)) {
$dev->setEvent("Alarm");
}
$this->mbinfo->setMbTemp($dev);
}
}
}
 
require_once(APP_ROOT . "/includes/common_functions.php");
 
class mbinfo {
var $lines;
 
function mbinfo() {
$lines = execute_program("sensors", "");
// 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 = explode("\n", $lines);
}
function temperature() {
$ar_buf = array();
$results = array();
 
$sensors_value = $this->lines;
 
foreach($sensors_value as $line) {
$data = array();
if (ereg("(.*):(.*)\((.*)=(.*),(.*)=(.*)\)(.*)", $line, $data)) ;
elseif (ereg("(.*):(.*)\((.*)=(.*)\)(.*)", $line, $data)) ;
else (ereg("(.*):(.*)", $line, $data));
if (count($data) > 1) {
$temp = substr(trim($data[2]), -1);
switch ($temp) {
case "C";
case "F":
array_push($ar_buf, $line);
break;
/**
* get fan information
*
* @return void
*/
private function _fans()
{
$sname = '';
foreach ($this->_lines as $line) {
if ((trim($line) !== "") && (strpos($line, ':') === false)) {
$sname = trim($line);
if (preg_match('/^([^-]+)-/', $sname, $snamebuf)) {
$sname = ' ('.$snamebuf[1].')';
} else {
$sname = '';
}
}
$data = array();
if (preg_match("/^(.+):(.+) RPM\s*\((.+)=(.+) RPM,(.+)=(.+)\)(.*)\)/", $line, $data)) {
;
} elseif (preg_match("/^(.+):(.+) RPM\s*\((.+)=(.+) RPM,(.+)=(.+)\)(.*)/", $line, $data)) {
;
} elseif (preg_match("/^(.+):(.+) RPM\s*\((.+)=(.+) RPM\)(.*)/", $line, $data)) {
;
} elseif (preg_match("/^(.+):(.+) RPM\s*\(/", $line, $data)) {
;
} else {
preg_match("/^(.+):(.+) RPM$/", $line, $data);
}
if (count($data)>2) {
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();
$dev->setName($data[1].$sname);
$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);
}
}
}
}
 
$i = 0;
foreach($ar_buf as $line) {
unset($data);
if (ereg("(.*):(.*).C[ ]*\((.*)=(.*).C,(.*)=(.*).C\)(.*)\)", $line, $data)) ;
elseif (ereg("(.*):(.*).C[ ]*\((.*)=(.*).C,(.*)=(.*).C\)(.*)", $line, $data)) ;
elseif (ereg("(.*):(.*).C[ ]*\((.*)=(.*).C\)(.*)", $line, $data)) ;
else (ereg("(.*):(.*).C", $line, $data));
/**
* get voltage information
*
* @return void
*/
private function _voltage()
{
$sname = '';
foreach ($this->_lines as $line) {
if ((trim($line) !== "") && (strpos($line, ':') === false)) {
$sname = trim($line);
if (preg_match('/^([^-]+)-/', $sname, $snamebuf)) {
$sname = ' ('.$snamebuf[1].')';
} else {
$sname = '';
}
}
$data = array();
if (preg_match("/^(.+):(.+) V\s*\((.+)=(.+) V,(.+)=(.+) V\)(.*)\)/", $line, $data)) {
;
} elseif (preg_match("/^(.+):(.+) V\s*\((.+)=(.+) V,(.+)=(.+) V\)(.*)/", $line, $data)) {
;
} elseif (preg_match("/^(.+):(.+) V\s*\(/", $line, $data)) {
;
} else {
preg_match("/^(.+):(.+) V$/", $line, $data);
}
 
$results[$i]['label'] = $data[1];
$results[$i]['value'] = trim($data[2]);
if ( isset( $data[6] ) && trim( $data[2] ) > trim( $data[6] ) ) {
$results[$i]['limit'] = "+75";
$results[$i]['perce'] = "+75";
} else {
$results[$i]['limit'] = isset($data[4]) ? trim($data[4]) : "+75";
$results[$i]['perce'] = isset($data[6]) ? trim($data[6]) : "+75";
}
if ($results[$i]['limit'] < $results[$i]['perce']) {
$results[$i]['limit'] = $results[$i]['perce'];
}
$i++;
if (count($data)>2) {
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();
$dev->setName($data[1].$sname);
$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);
}
}
}
 
asort($results);
return array_values($results);
}
/**
* get power information
*
* @return void
*/
private function _power()
{
$sname = '';
foreach ($this->_lines as $line) {
if ((trim($line) !== "") && (strpos($line, ':') === false)) {
$sname = trim($line);
if (preg_match('/^([^-]+)-/', $sname, $snamebuf)) {
$sname = ' ('.$snamebuf[1].')';
} else {
$sname = '';
}
}
$data = array();
/* not tested yet
if (preg_match("/^(.+):(.+) W\s*\((.+)=(.+) W,(.+)=(.+) W\)(.*)\)/", $line, $data)) {
;
} elseif (preg_match("/^(.+):(.+) W\s*\((.+)=(.+) W,(.+)=(.+) W\)(.*)/", $line, $data)) {
;
} else
*/
if (preg_match("/^(.+):(.+) W\s*\((.+)=(.+) W\)(.*)/", $line, $data)) {
;
} elseif (preg_match("/^(.+):(.+) W\s*\(/", $line, $data)) {
;
} else {
preg_match("/^(.+):(.+) W$/", $line, $data);
}
if (count($data)>2) {
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();
$dev->setName($data[1].$sname);
$dev->setValue($data[2]);
 
function fans() {
$ar_buf = array();
$results = array();
 
$sensors_value = $this->lines;
 
foreach($sensors_value as $line) {
$data = array();
if (ereg("(.*):(.*)\((.*)=(.*),(.*)=(.*)\)(.*)", $line, $data));
elseif (ereg("(.*):(.*)\((.*)=(.*)\)(.*)", $line, $data));
else ereg("(.*):(.*)", $line, $data);
 
if (count($data) > 1) {
$temp = explode(" ", trim($data[2]));
if (count($temp) == 1)
$temp = explode("\xb0", trim($data[2]));
if(isset($temp[1])) {
switch ($temp[1]) {
case "RPM":
array_push($ar_buf, $line);
break;
}
}
}
/* not tested yet
if (isset($data[6]) && $data[2] <= $data[6]) {
$dev->setMax(max($data[4], $data[6]));
} else
*/
if (isset($data[4]) && $data[2] <= $data[4]) {
$dev->setMax($data[4]);
}
if (preg_match("/\sALARM\s*$/", $line)) {
$dev->setEvent("Alarm");
}
$this->mbinfo->setMbPower($dev);
}
}
}
 
$i = 0;
foreach($ar_buf as $line) {
unset($data);
if (ereg("(.*):(.*) RPM \((.*)=(.*) RPM,(.*)=(.*)\)(.*)\)", $line, $data));
elseif (ereg("(.*):(.*) RPM \((.*)=(.*) RPM,(.*)=(.*)\)(.*)", $line, $data));
elseif (ereg("(.*):(.*) RPM \((.*)=(.*) RPM\)(.*)", $line, $data));
else ereg("(.*):(.*) RPM", $line, $data);
 
$results[$i]['label'] = trim($data[1]);
$results[$i]['value'] = trim($data[2]);
$results[$i]['min'] = isset($data[4]) ? trim($data[4]) : 0;
$i++;
/**
* get current information
*
* @return void
*/
private function _current()
{
$sname = '';
foreach ($this->_lines as $line) {
if ((trim($line) !== "") && (strpos($line, ':') === false)) {
$sname = trim($line);
if (preg_match('/^([^-]+)-/', $sname, $snamebuf)) {
$sname = ' ('.$snamebuf[1].')';
} else {
$sname = '';
}
}
$data = array();
if (preg_match("/^(.+):(.+) A\s*\((.+)=(.+) A,(.+)=(.+) A\)(.*)\)/", $line, $data)) {
;
} elseif (preg_match("/^(.+):(.+) A\s*\((.+)=(.+) A,(.+)=(.+) A\)(.*)/", $line, $data)) {
;
} elseif (preg_match("/^(.+):(.+) A\s*\(/", $line, $data)) {
;
} else {
preg_match("/^(.+):(.+) A$/", $line, $data);
}
if (count($data)>2) {
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].$sname);
$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->setMbCurrent($dev);
}
}
}
 
asort($results);
return array_values($results);
}
 
function voltage() {
$ar_buf = array();
$results = array();
 
$sensors_value = $this->lines;
 
foreach($sensors_value as $line) {
$data = array();
if (ereg("(.*):(.*)\((.*)=(.*),(.*)=(.*)\)(.*)", $line, $data));
else ereg("(.*):(.*)", $line, $data);
if (count($data) > 1) {
$temp = explode(" ", trim($data[2]));
if (count($temp) == 1)
$temp = explode("\xb0", trim($data[2]));
if (isset($temp[1])) {
switch ($temp[1]) {
case "V":
array_push($ar_buf, $line);
break;
}
/**
* get other information
*
* @return void
*/
private function _other()
{
$sname = '';
foreach ($this->_lines as $line) {
if ((trim($line) !== "") && (strpos($line, ':') === false)) {
$sname = trim($line);
if (preg_match('/^([^-]+)-/', $sname, $snamebuf)) {
$sname = ' ('.$snamebuf[1].')';
} else {
$sname = '';
}
}
$data = array();
preg_match("/^(.+):\s*([^\-\+\d\s].+)$/", $line, $data);
if ((count($data)>2) && ($data[1]!=="Adapter")) {
$dev = new SensorDevice();
$dev->setName($data[1].$sname);
if (preg_match("/(.*\s*)ALARM\s*$/", $data[2], $aldata)) {
$dev->setEvent("Alarm");
if ((count($aldata)>1) && trim($aldata[1]!=="")) {
$dev->setValue(trim($aldata[1]));
} else {
$dev->setValue($data[2]);
}
} else {
$dev->setValue($data[2]);
}
$this->mbinfo->setMbOther($dev);
}
}
}
}
 
$i = 0;
foreach($ar_buf as $line) {
unset($data);
if (ereg("(.*):(.*) V \((.*)=(.*) V,(.*)=(.*) V\)(.*)\)", $line, $data));
elseif (ereg("(.*):(.*) V \((.*)=(.*) V,(.*)=(.*) V\)(.*)", $line, $data));
else ereg("(.*):(.*) V$", $line, $data);
if(isset($data[1])) {
$results[$i]['label'] = trim($data[1]);
$results[$i]['value'] = trim($data[2]);
$results[$i]['min'] = isset($data[4]) ? trim($data[4]) : 0;
$results[$i]['max'] = isset($data[6]) ? trim($data[6]) : 0;
$i++;
}
/**
* 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();
}
return $results;
}
}
 
?>
/web/acc/phpsysinfo/includes/mb/class.mbm5.inc.php
1,79 → 1,119
<?php
//
// phpSysInfo - A PHP System Information Script
// http://phpsysinfo.sourceforge.net/
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//
// $Id: class.mbm5.inc.php,v 1.7 2007/02/18 19:11:31 bigmichi1 Exp $
<?php
/**
* MBM5 sensor class, getting information from Motherboard Monitor 5 information retrival through csv file
*
* 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 MBM5 extends Sensors
{
/**
* array with the names of the labels
*
* @var array
*/
private $_buf_label = array();
 
class mbinfo {
var $buf_label;
var $buf_value;
/**
* array withe the values
*
* @var array
*/
private $_buf_value = array();
 
function mbinfo() {
$buffer = rfts( APP_ROOT . "/data/MBM5.csv" );
if( strpos( $buffer, ";") === false ) {
$delim = ",";
} else {
$delim = ";";
}
$buffer = explode( "\n", $buffer );
$this->buf_label = explode( $delim, $buffer[0] );
$this->buf_value = explode( $delim, $buffer[1] );
}
function temperature() {
$results = array();
$intCount = 0;
for( $intPosi = 3; $intPosi < 6; $intPosi++ ) {
$results[$intCount]['label'] = $this->buf_label[$intPosi];
$results[$intCount]['value'] = $this->buf_value[$intPosi];
$results[$intCount]['limit'] = '70.0';
$intCount++;
}
return $results;
}
function fans() {
$results = array();
$intCount = 0;
for( $intPosi = 13; $intPosi < 16; $intPosi++ ) {
$results[$intCount]['label'] = $this->buf_label[$intPosi];
$results[$intCount]['value'] = $this->buf_value[$intPosi];
$results[$intCount]['min'] = '3000';
$intCount++;
}
return $results;
}
function voltage() {
$results = array();
$intCount = 0;
for( $intPosi = 6; $intPosi < 13; $intPosi++ ) {
$results[$intCount]['label'] = $this->buf_label[$intPosi];
$results[$intCount]['value'] = $this->buf_value[$intPosi];
$results[$intCount]['min'] = '0.00';
$results[$intCount]['max'] = '0.00';
$intCount++;
}
return $results;
}
}
/**
* read the MBM5.csv file and fill the private arrays
*/
public function __construct()
{
parent::__construct();
$delim = "/;/";
CommonFunctions::rfts(PSI_APP_ROOT."/data/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);
}
 
?>
/**
* get temperature information
*
* @return void
*/
private function _temperature()
{
for ($intPosi = 3; $intPosi < 6; $intPosi++) {
if ($this->_buf_value[$intPosi] == 0) {
continue;
}
preg_match("/([0-9\.])*/", str_replace(",", ".", $this->_buf_value[$intPosi]), $hits);
$dev = new SensorDevice();
$dev->setName($this->_buf_label[$intPosi]);
$dev->setValue($hits[0]);
// $dev->setMax(70);
$this->mbinfo->setMbTemp($dev);
}
}
 
/**
* get fan information
*
* @return void
*/
private function _fans()
{
for ($intPosi = 13; $intPosi < 16; $intPosi++) {
if (!isset($this->_buf_value[$intPosi])) {
continue;
}
preg_match("/([0-9\.])*/", str_replace(",", ".", $this->_buf_value[$intPosi]), $hits);
$dev = new SensorDevice();
$dev->setName($this->_buf_label[$intPosi]);
$dev->setValue($hits[0]);
// $dev->setMin(3000);
$this->mbinfo->setMbFan($dev);
}
}
 
/**
* get voltage information
*
* @return void
*/
private function _voltage()
{
for ($intPosi = 6; $intPosi < 13; $intPosi++) {
if ($this->_buf_value[$intPosi] == 0) {
continue;
}
preg_match("/([0-9\.])*/", str_replace(",", ".", $this->_buf_value[$intPosi]), $hits);
$dev = new SensorDevice();
$dev->setName($this->_buf_label[$intPosi]);
$dev->setValue($hits[0]);
$this->mbinfo->setMbVolt($dev);
}
}
 
/**
* get the information
*
* @see PSI_Interface_Sensor::build()
*
* @return Void
*/
public function build()
{
$this->_fans();
$this->_temperature();
$this->_voltage();
}
}
/web/acc/phpsysinfo/includes/mb/class.mbmon.inc.php
1,99 → 1,132
<?php
/**
* mbmon sensor class, getting information from mbmon
*
* 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 MBMon extends Sensors
{
/**
* content to parse
*
* @var array
*/
private $_lines = array();
 
// phpSysInfo - A PHP System Information Script
// http://phpsysinfo.sourceforge.net/
/**
* fill the private content var through tcp, command or data access
*/
public function __construct()
{
parent::__construct();
switch (defined('PSI_SENSOR_MBMON_ACCESS')?strtolower(PSI_SENSOR_MBMON_ACCESS):'command') {
case 'tcp':
$fp = fsockopen("localhost", 411, $errno, $errstr, 5);
if ($fp) {
$lines = "";
while (!feof($fp)) {
$lines .= fread($fp, 1024);
}
$this->_lines = preg_split("/\n/", $lines, -1, PREG_SPLIT_NO_EMPTY);
} else {
$this->error->addError("fsockopen()", $errno." ".$errstr);
}
break;
case 'command':
CommonFunctions::executeProgram('mbmon', '-c 1 -r', $lines, PSI_DEBUG);
$this->_lines = preg_split("/\n/", $lines, -1, PREG_SPLIT_NO_EMPTY);
break;
case 'data':
if (CommonFunctions::rfts(PSI_APP_ROOT.'/data/mbmon.txt', $lines)) {
$this->_lines = preg_split("/\n/", $lines, -1, PREG_SPLIT_NO_EMPTY);
}
break;
default:
$this->error->addConfigError('__construct()', '[sensor_mbmon] ACCESS');
break;
}
}
 
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
 
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
// This class was created by Z. Frombach ( zoltan at frombach dot com )
 
// $Id: class.mbmon.inc.php,v 1.5 2007/02/18 19:11:31 bigmichi1 Exp $
 
class mbinfo {
var $lines;
 
function temperature() {
$results = array();
 
if (!isset($this->lines) ) {
$this->lines = explode("\n", execute_program('mbmon', '-c 1 -r'));
}
 
$i = 0;
foreach($this->lines as $line) {
if (preg_match('/^(TEMP\d*)\s*:\s*(.*)$/D', $line, $data)) {
if ($data[2]<>'0') {
$results[$i]['label'] = $data[1];
$results[$i]['limit'] = '70.0';
if($data[2] > 250) {
$results[$i]['value'] = 0;
$results[$i]['percent'] = 0;
} else {
$results[$i]['value'] = $data[2];
$results[$i]['percent'] = $results[$i]['value'] * 100 / $results[$i]['limit'];
}
$i++;
/**
* get temperature information
*
* @return void
*/
private function _temperature()
{
foreach ($this->_lines as $line) {
if (preg_match('/^(TEMP\d*)\s*:\s*(.*)$/D', $line, $data)) {
if ($data[2] <> '0') {
$dev = new SensorDevice();
$dev->setName($data[1]);
// $dev->setMax(70);
if ($data[2] < 250) {
$dev->setValue($data[2]);
}
$this->mbinfo->setMbTemp($dev);
}
}
}
}
}
return $results;
}
 
function fans() {
$results = array();
 
if (!isset($this->lines) ) {
$this->lines = explode("\n", execute_program('mbmon', '-c 1 -r'));
}
 
$i = 0;
foreach($this->lines as $line) {
if (preg_match('/^(FAN\d*)\s*:\s*(.*)$/D', $line, $data)) {
if ($data[2]<>'0') {
$results[$i]['label'] = $data[1];
$results[$i]['value'] = $data[2];
$results[$i]['min'] = '3000';
$i++;
/**
* get fan information
*
* @return void
*/
private function _fans()
{
foreach ($this->_lines as $line) {
if (preg_match('/^(FAN\d*)\s*:\s*(.*)$/D', $line, $data)) {
if ($data[2] <> '0') {
$dev = new SensorDevice();
$dev->setName($data[1]);
$dev->setValue($data[2]);
// $dev->setMax(3000);
$this->mbinfo->setMbFan($dev);
}
}
}
}
}
return $results;
}
 
function voltage() {
$results = array();
 
if (!isset($this->lines) ) {
$this->lines = explode("\n", execute_program('mbmon', '-c 1 -r'));
}
 
$i = 0;
foreach($this->lines as $line) {
if (preg_match('/^(V.*)\s*:\s*(.*)$/D', $line, $data)) {
if ($data[2]<>'+0.00') {
$results[$i]['label'] = $data[1];
$results[$i]['value'] = $data[2];
$results[$i]['min'] = '0.00';
$results[$i]['max'] = '0.00';
$i++;
/**
* get voltage information
*
* @return void
*/
private function _voltage()
{
foreach ($this->_lines as $line) {
if (preg_match('/^(V.*)\s*:\s*(.*)$/D', $line, $data)) {
if ($data[2] <> '+0.00') {
$dev = new SensorDevice();
$dev->setName($data[1]);
$dev->setValue($data[2]);
$this->mbinfo->setMbVolt($dev);
}
}
}
}
}
 
return $results;
}
/**
* get the information
*
* @see PSI_Interface_Sensor::build()
*
* @return void
*/
public function build()
{
$this->_temperature();
$this->_voltage();
$this->_fans();
}
}
 
?>
/web/acc/phpsysinfo/includes/mb/class.ohm.inc.php
0,0 → 1,122
<?php
/**
* Open Hardware Monitor sensor class, getting information from Open Hardware Monitor
*
* PHP version 5
*
* @category PHP
* @package PSI_Sensor
* @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 OHM extends Sensors
{
/**
* holds the COM object that we pull all the WMI data from
*
* @var Object
*/
private $_buf = array();
 
/**
* fill the private content var
*/
public function __construct()
{
parent::__construct();
$_wmi = null;
try {
// initialize the wmi object
$objLocator = new COM('WbemScripting.SWbemLocator');
$_wmi = $objLocator->ConnectServer('', 'root\OpenHardwareMonitor');
} catch (Exception $e) {
$this->error->addError("WMI connect error", "PhpSysInfo can not connect to the WMI interface for OpenHardwareMonitor data.");
}
if ($_wmi) {
$tmpbuf = CommonFunctions::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'];
}
}
}
}
 
/**
* get temperature information
*
* @return void
*/
private function _temperature()
{
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);
}
}
 
/**
* get voltage information
*
* @return void
*/
private function _voltage()
{
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);
}
}
 
/**
* get fan information
*
* @return void
*/
private function _fans()
{
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);
}
}
 
/**
* get power information
*
* @return void
*/
private function _power()
{
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);
}
}
 
/**
* get the information
*
* @see PSI_Interface_Sensor::build()
*
* @return Void
*/
public function build()
{
$this->_temperature();
$this->_voltage();
$this->_fans();
$this->_power();
}
}
/web/acc/phpsysinfo/includes/mb/class.pitemp.inc.php
0,0 → 1,64
<?php
/**
* pitemp sensor class
*
* PHP version 5
*
* @category PHP
* @package PSI_Sensor
* @author Marc Hillesheim <hawkeyexp@gmail.com>
* @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
{
private function _temperature()
{
$temp = null;
$temp_max = null;
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) && (($temp = trim($temp)) != "")) {
$dev = new SensorDevice();
$dev->setName("CPU 1");
$dev->setValue($temp / 1000);
if (!is_null($temp_max) && (($temp_max = trim($temp_max)) != "") && ($temp_max > 0)) {
$dev->setMax($temp_max / 1000);
}
$this->mbinfo->setMbTemp($dev);
}
}
 
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, 1, 4096, false) && !is_null($volt) && (($volt = trim($volt)) != "")) { // Banana Pi
$dev = new SensorDevice();
$dev->setName("Voltage 1");
$dev->setValue($volt / 1000000);
$this->mbinfo->setMbVolt($dev);
}
}
 
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, 1, 4096, false) && !is_null($current) && (($current = trim($current)) != "")) { // Banana Pi
$dev = new SensorDevice();
$dev->setName("Current 1");
$dev->setValue($current / 1000000);
$this->mbinfo->setMbCurrent($dev);
}
}
 
public function build()
{
$this->_temperature();
$this->_voltage();
$this->_current();
}
}
/web/acc/phpsysinfo/includes/mb/class.qtssnmp.inc.php
0,0 → 1,81
<?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 (CommonFunctions::executeProgram("snmpwalk", "-Ona -c public -v 1 -t ".PSI_SNMP_TIMEOUT_INT." -r ".PSI_SNMP_RETRY_INT." 127.0.0.1 .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." 127.0.0.1 .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." 127.0.0.1 .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 (CommonFunctions::executeProgram("snmpwalk", "-Ona -c public -v 1 -t ".PSI_SNMP_TIMEOUT_INT." -r ".PSI_SNMP_RETRY_INT." 127.0.0.1 .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()
{
$this->_temperature();
$this->_fans();
}
}
/web/acc/phpsysinfo/includes/mb/class.sensors.inc.php
0,0 → 1,64
<?php
/**
* Basic OS Class
*
* PHP version 5
*
* @category PHP
* @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 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
*/
/**
* Basic OS functions for all OS classes
*
* @category PHP
* @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 version 2, or (at your option) any later version
* @version Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
abstract class Sensors implements PSI_Interface_Sensor
{
/**
* object for error handling
*
* @var PSI_Error
*/
protected $error;
 
/**
* object for the information
*
* @var MBInfo
*/
protected $mbinfo;
 
/**
* build the global Error object
*/
public function __construct()
{
$this->error = PSI_Error::singleton();
$this->mbinfo = new MBInfo();
}
 
/**
* get the filled or unfilled (with default values) MBInfo object
*
* @see PSI_Interface_Sensor::getMBInfo()
*
* @return MBInfo
*/
final public function getMBInfo()
{
$this->build();
 
return $this->mbinfo;
}
}
/web/acc/phpsysinfo/includes/mb/class.speedfan.inc.php
0,0 → 1,126
<?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();
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::rfts(PSI_APP_ROOT.'/data/speedfan.txt', $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');
break;
}
}
 
/**
* 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();
}
}
/web/acc/phpsysinfo/includes/mb/class.thermalzone.inc.php
0,0 → 1,139
<?php
/**
* Thermal Zone sensor class, getting information from Thermal Zone WMI class
*
* PHP version 5
*
* @category PHP
* @package PSI_Sensor
* @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
*/
private $_buf = array();
 
/**
* fill the private content var
*/
public function __construct()
{
parent::__construct();
if (PSI_OS == 'WINNT') {
$_wmi = null;
try {
// initialize the wmi object
$objLocator = new COM('WbemScripting.SWbemLocator');
$_wmi = $objLocator->ConnectServer('', 'root\WMI');
} catch (Exception $e) {
$this->error->addError("WMI connect error", "PhpSysInfo can not connect to the WMI interface for ThermalZone data.");
}
if ($_wmi) {
$this->_buf = CommonFunctions::getWMI($_wmi, 'MSAcpi_ThermalZoneTemperature', array('InstanceName', 'CriticalTripPoint', 'CurrentTemperature'));
}
}
}
 
/**
* get temperature information
*
* @return void
*/
private function _temperature()
{
if (PSI_OS == 'WINNT') {
if ($this->_buf) foreach ($this->_buf as $buffer) {
if (isset($buffer['CurrentTemperature']) && (($value = ($buffer['CurrentTemperature'] - 2732)/10) > -100)) {
$dev = new SensorDevice();
if (isset($buffer['InstanceName']) && preg_match("/([^\\\\ ]+)$/", $buffer['InstanceName'], $outbuf)) {
$dev->setName('ThermalZone '.$outbuf[1]);
} else {
$dev->setName('ThermalZone THM0_0');
}
$dev->setValue($value);
if (isset($buffer['CriticalTripPoint']) && (($maxvalue = ($buffer['CriticalTripPoint'] - 2732)/10) > 0)) {
$dev->setMax($maxvalue);
}
$this->mbinfo->setMbTemp($dev);
}
}
} else {
$notwas = true;
$thermalzones = glob('/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, 1, 4096, false) && !is_null($temp) && (($temp = trim($temp)) != "")) {
if ($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, 1, 4096, false) && !is_null($temp_type) && (($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, 1, 4096, false) && !is_null($temp_max) && (($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);
}
} else {
$this->mbinfo->setMbTemp($dev);
}
$notwas = false;
}
}
}
if ($notwas) {
$thermalzones = glob('/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) && !is_null($temp) && (($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);
}
}
}
}
}
 
/**
* get the information
*
* @see PSI_Interface_Sensor::build()
*
* @return Void
*/
public function build()
{
$this->_temperature();
}
}
/web/acc/phpsysinfo/includes/mb/class.thinkpad.inc.php
0,0 → 1,34
<?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') {
$hwpaths = glob("/sys/devices/platform/thinkpad_hwmon/", GLOB_NOSORT);
if (is_array($hwpaths) && (count($hwpaths) == 1)) {
$this->_temperature($hwpaths[0]);
$this->_fans($hwpaths[0]);
}
}
}
}
/web/acc/phpsysinfo/includes/os/class.Linux.inc.php.default
File deleted
/web/acc/phpsysinfo/includes/os/class.HP-UX.inc.php
File deleted
/web/acc/phpsysinfo/includes/os/class.BSD.common.inc.php
File deleted
/web/acc/phpsysinfo/includes/os/class.parseProgs.inc.php
File deleted
/web/acc/phpsysinfo/includes/os/class.AIX.inc.php
0,0 → 1,362
<?php
/**
* IBM AIX System Class
*
* PHP version 5
*
* @category PHP
* @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 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
*/
/**
* IBM AIX sysinfo class
* get all the required information from IBM AIX system
*
* @category PHP
* @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 version 2, or (at your option) any later version
* @version Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
class AIX extends OS
{
 
private $_aixdata = array();
 
/**
* Virtual Host Name
* @return void
*/
private function _hostname()
{
/* if (PSI_USE_VHOST === true) {
if (CommonFunctions::readenv('SERVER_NAME', $hnm)) $this->sys->setHostname($hnm);
} else {
if (CommonFunctions::executeProgram('hostname', '', $ret)) {
$this->sys->setHostname($ret);
}
} */
if (CommonFunctions::readenv('SERVER_NAME', $hnm)) $this->sys->setHostname($hnm);
 
}
 
/**
* IBM AIX Version
* @return void
*/
private function _kernel()
{
if (CommonFunctions::executeProgram('oslevel', '', $ret1) && CommonFunctions::executeProgram('oslevel', '-s', $ret2)) {
$this->sys->setKernel($ret1 . ' (' . $ret2 . ')');
}
}
 
/**
* UpTime
* time the system is running
* @return void
*/
private function _uptime()
{
if (CommonFunctions::executeProgram('uptime', '', $buf)) {
if (preg_match("/up (\d+) day[s]?,\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);
}
}
}
 
/**
* Processor Load
* optionally create a loadbar
* @return void
*/
private function _loadavg()
{
if (CommonFunctions::executeProgram('uptime', '', $buf)) {
if (preg_match("/average: (.*), (.*), (.*)$/", $buf, $ar_buf)) {
$this->sys->setLoad($ar_buf[1].' '.$ar_buf[2].' '.$ar_buf[3]);
}
}
}
 
/**
* CPU information
* All of the tags here are highly architecture dependant
* @return void
*/
private function _cpuinfo()
{
$ncpu = 0;
$tcpu = "";
$vcpu = "";
$ccpu = "";
$scpu = "";
foreach ($this->readaixdata() as $line) {
if (preg_match("/^Number Of Processors:\s+(\d+)/", $line, $ar_buf)) {
$ncpu = $ar_buf[1];
}
if (preg_match("/^Processor Type:\s+(.+)/", $line, $ar_buf)) {
$tcpu = $ar_buf[1];
}
if (preg_match("/^Processor Version:\s+(.+)/", $line, $ar_buf)) {
$vcpu = $ar_buf[1];
}
if (preg_match("/^CPU Type:\s+(.+)/", $line, $ar_buf)) {
$ccpu = $ar_buf[1];
}
if (preg_match("/^Processor Clock Speed:\s+(\d+)\s/", $line, $ar_buf)) {
$scpu = $ar_buf[1];
}
}
for ($i = 0; $i < $ncpu; $i++) {
$dev = new CpuDevice();
if (trim($tcpu) != "") {
$cpu = trim($tcpu);
if (trim($vcpu) != "") $cpu .= " ".trim($vcpu);
if (trim($ccpu) != "") $cpu .= " ".trim($ccpu);
$dev->setModel($cpu);
}
if (trim($scpu) != "") {
$dev->setCpuSpeed(trim($scpu));
}
$this->sys->setCpus($dev);
}
}
 
/**
* PCI devices
* @return void
*/
private function _pci()
{
foreach ($this->readaixdata() as $line) {
if (preg_match("/^[\*\+]\s\S+\s+\S+\s+(.*PCI.*)/", $line, $ar_buf)) {
$dev = new HWDevice();
$dev->setName(trim($ar_buf[1]));
$this->sys->setPciDevices($dev);
}
}
}
 
/**
* IDE devices
* @return void
*/
private function _ide()
{
foreach ($this->readaixdata() as $line) {
if (preg_match("/^[\*\+]\s\S+\s+\S+\s+(.*IDE.*)/", $line, $ar_buf)) {
$dev = new HWDevice();
$dev->setName(trim($ar_buf[1]));
$this->sys->setIdeDevices($dev);
}
}
}
 
/**
* SCSI devices
* @return void
*/
private function _scsi()
{
foreach ($this->readaixdata() as $line) {
if (preg_match("/^[\*\+]\s\S+\s+\S+\s+(.*SCSI.*)/", $line, $ar_buf)) {
$dev = new HWDevice();
$dev->setName(trim($ar_buf[1]));
$this->sys->setScsiDevices($dev);
}
}
}
 
/**
* USB devices
* @return void
*/
private function _usb()
{
foreach ($this->readaixdata() as $line) {
if (preg_match("/^[\*\+]\s\S+\s+\S+\s+(.*USB.*)/", $line, $ar_buf)) {
$dev = new HWDevice();
$dev->setName(trim($ar_buf[1]));
$this->sys->setUsbDevices($dev);
}
}
}
 
/**
* Network devices
* includes also rx/tx bytes
* @return void
*/
private function _network()
{
if (CommonFunctions::executeProgram('netstat', '-ni | tail -n +2', $netstat)) {
$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]) && ! empty($ar_buf[3])) {
$dev = new NetDevice();
$dev->setName($ar_buf[0]);
$dev->setRxBytes($ar_buf[4]);
$dev->setTxBytes($ar_buf[6]);
$dev->setErrors($ar_buf[5] + $ar_buf[7]);
//$dev->setDrops($ar_buf[8]);
$this->sys->setNetDevices($dev);
}
}
}
}
 
/**
* Physical memory information and Swap Space information
* @return void
*/
private function _memory()
{
$mems = "";
$tswap = "";
$pswap = "";
foreach ($this->readaixdata() as $line) {
if (preg_match("/^Good Memory Size:\s+(\d+)\s+MB/", $line, $ar_buf)) {
$mems = $ar_buf[1];
}
if (preg_match("/^\s*Total Paging Space:\s+(\d+)MB/", $line, $ar_buf)) {
$tswap = $ar_buf[1];
}
if (preg_match("/^\s*Percent Used:\s+(\d+)%/", $line, $ar_buf)) {
$pswap = $ar_buf[1];
}
}
if (trim($mems) != "") {
$mems = $mems*1024*1024;
$this->sys->setMemTotal($mems);
$memu = 0;
$memf = 0;
if (CommonFunctions::executeProgram('svmon', '-G', $buf)) {
if (preg_match("/^memory\s+\d+\s+(\d+)\s+/", $buf, $ar_buf)) {
$memu = $ar_buf[1]*1024*4;
$memf = $mems - $memu;
}
}
$this->sys->setMemUsed($memu);
$this->sys->setMemFree($memf);
// $this->sys->setMemApplication($mems);
// $this->sys->setMemBuffer($mems);
// $this->sys->setMemCache($mems);
}
if (trim($tswap) != "") {
$dev = new DiskDevice();
$dev->setName("SWAP");
$dev->setFsType('swap');
$dev->setTotal($tswap * 1024 * 1024);
if (trim($pswap) != "") {
$dev->setUsed($dev->getTotal() * $pswap / 100);
}
$dev->setFree($dev->getTotal() - $dev->getUsed());
$this->sys->setSwapDevices($dev);
}
}
 
/**
* filesystem information
*
* @return void
*/
private function _filesystems()
{
if (CommonFunctions::executeProgram('df', '-kP', $df, PSI_DEBUG)) {
$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);
foreach ($lines as $line) {
$a = preg_split('/ /', $line, -1, PREG_SPLIT_NO_EMPTY);
$fsdev[$a[0]] = $a[4];
}
}
foreach ($mounts as $mount) {
$ar_buf = preg_split("/\s+/", $mount, 6);
$dev = new DiskDevice();
$dev->setName($ar_buf[0]);
$dev->setTotal($ar_buf[1] * 1024);
$dev->setUsed($ar_buf[2] * 1024);
$dev->setFree($ar_buf[3] * 1024);
$dev->setMountPoint($ar_buf[5]);
if (isset($fsdev[$ar_buf[0]])) {
$dev->setFsType($fsdev[$ar_buf[0]]);
}
$this->sys->setDiskDevices($dev);
}
}
}
 
/**
* Distribution
*
* @return void
*/
private function _distro()
{
$this->sys->setDistribution('IBM AIX');
$this->sys->setDistributionIcon('AIX.png');
}
 
/**
* IBM AIX informations by K.PAZ
* @return array
*/
private function readaixdata()
{
if (count($this->_aixdata) === 0) {
if (CommonFunctions::executeProgram('prtconf', '', $bufr)) {
$this->_aixdata = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
}
}
 
return $this->_aixdata;
}
 
/**
* get the information
*
* @see PSI_Interface_OS::build()
*
* @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");
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==='network') {
$this->_network();
}
if (!$this->blockname || $this->blockname==='memory') {
$this->_memory();
}
if (!$this->blockname || $this->blockname==='filesystem') {
$this->_filesystems();
}
}
}
/web/acc/phpsysinfo/includes/os/class.Android.inc.php
0,0 → 1,274
<?php
/**
* Android System Class
*
* PHP version 5
*
* @category PHP
* @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 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
*/
/**
* Android sysinfo class
* get all the required information from Android system
*
* @category PHP
* @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 version 2, or (at your option) any later version
* @version Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
class Android extends Linux
{
/**
* holds the data from /system/build.prop file
*
* @var string
*/
private $_buildprop = null;
 
/**
* reads the data from /system/build.prop file
*
* @return string
*/
private function _get_buildprop()
{
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;
}
 
/**
* Kernel Version
*
* @return void
*/
private function _kernel()
{
if (CommonFunctions::executeProgram('uname', '-r', $strBuf, false)) {
$result = $strBuf;
if (CommonFunctions::executeProgram('uname', '-v', $strBuf, PSI_DEBUG)) {
if (preg_match('/SMP/', $strBuf)) {
$result .= ' (SMP)';
}
}
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);
}
}
 
/**
* Number of Users
*
* @return void
*/
protected function _users()
{
$this->sys->setUsers(1);
}
 
/**
* filesystem information
*
* @return void
*/
private function _filesystems()
{
$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);
foreach ($mount as $mount_line) {
$mount_buf = preg_split('/\s+/', $mount_line);
if (count($mount_buf) == 6) {
$mount_parm[$mount_buf[1]]['fstype'] = $mount_buf[2];
if (PSI_SHOW_MOUNT_OPTION) $mount_parm[$mount_buf[1]]['options'] = $mount_buf[3];
$mount_parm[$mount_buf[1]]['mountdev'] = $mount_buf[0];
}
}
foreach ($df as $df_line) {
if ((preg_match("/^(\/\S+)(\s+)(([0-9\.]+)([KMGT])(\s+)([0-9\.]+)([KMGT])(\s+)([0-9\.]+)([KMGT])(\s+))/", $df_line, $df_buf)
|| preg_match("/^(\/[^\s\:]+)\:(\s+)(([0-9\.]+)([KMGT])(\s+total\,\s+)([0-9\.]+)([KMGT])(\s+used\,\s+)([0-9\.]+)([KMGT])(\s+available))/", $df_line, $df_buf))
&& !preg_match('/^\/mnt\/asec\/com\./', $df_buf[1])) {
$dev = new DiskDevice();
if (PSI_SHOW_MOUNT_POINT) $dev->setMountPoint($df_buf[1]);
 
if ($df_buf[5] == 'K') $dev->setTotal($df_buf[4] * 1024);
elseif ($df_buf[5] == 'M') $dev->setTotal($df_buf[4] * 1024*1024);
elseif ($df_buf[5] == 'G') $dev->setTotal($df_buf[4] * 1024*1024*1024);
elseif ($df_buf[5] == 'T') $dev->setTotal($df_buf[4] * 1024*1024*1024*1024);
 
if ($df_buf[8] == 'K') $dev->setUsed($df_buf[7] * 1024);
elseif ($df_buf[8] == 'M') $dev->setUsed($df_buf[7] * 1024*1024);
elseif ($df_buf[8] == 'G') $dev->setUsed($df_buf[7] * 1024*1024*1024);
elseif ($df_buf[8] == 'T') $dev->setUsed($df_buf[7] * 1024*1024*1024*1024);
 
if ($df_buf[11] == 'K') $dev->setFree($df_buf[10] * 1024);
elseif ($df_buf[11] == 'M') $dev->setFree($df_buf[10] * 1024*1024);
elseif ($df_buf[11] == 'G') $dev->setFree($df_buf[10] * 1024*1024*1024);
elseif ($df_buf[11] == 'T') $dev->setFree($df_buf[10] * 1024*1024*1024*1024);
 
if (isset($mount_parm[$df_buf[1]])) {
$dev->setFsType($mount_parm[$df_buf[1]]['fstype']);
$dev->setName($mount_parm[$df_buf[1]]['mountdev']);
 
if (PSI_SHOW_MOUNT_OPTION) {
if (PSI_SHOW_MOUNT_CREDENTIALS) {
$dev->setOptions($mount_parm[$df_buf[1]]['options']);
} else {
$mpo=$mount_parm[$df_buf[1]]['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);
}
}
}
$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);
}
}
}
 
/**
* Distribution
*
* @return void
*/
protected function _distro()
{
$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 == "")) {
$this->sys->setDistribution('Android');
} else {
if (preg_match('/^(\d+\.\d+)/', $buf, $ver)
&& ($list = @parse_ini_file(PSI_APP_ROOT."/data/osnames.ini", true))
&& isset($list['Android'][$ver[1]])) {
$buf.=' '.$list['Android'][$ver[1]];
}
$this->sys->setDistribution('Android '.$buf);
}
$this->sys->setDistributionIcon('Android.png');
}
 
/**
* Machine
*
* @return void
*/
private function _machine()
{
if ($lines = $this->_get_buildprop()) {
$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($ar_buf[1]) !== trim($buf))) {
$buf .= ' '.trim($ar_buf[1]);
}
if (preg_match('/^ro\.semc\.product\.name=([^\n]+)/m', $lines, $ar_buf)) {
$buf .= ' '.trim($ar_buf[1]);
}
if (trim($buf) != "") {
$this->sys->setMachine(trim($buf));
}
}
}
 
/**
* PCI devices
*
* @return void
*/
private function _pci()
{
if (CommonFunctions::executeProgram('lspci', '', $bufr, false)) {
$bufe = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
foreach ($bufe as $buf) {
$device = preg_split("/ /", $buf, 4);
if (isset($device[3]) && trim($device[3]) != "") {
$dev = new HWDevice();
$dev->setName('Class '.trim($device[2]).' Device '.trim($device[3]));
$this->sys->setPciDevices($dev);
}
}
}
}
 
/**
* get the information
*
* @see PSI_Interface_OS::build()
*
* @return Void
*/
public function build()
{
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->_pci();
$this->_usb();
$this->_i2c();
}
if (!$this->blockname || $this->blockname==='network') {
$this->_network();
}
if (!$this->blockname || $this->blockname==='memory') {
$this->_memory();
}
if (!$this->blockname || $this->blockname==='filesystem') {
$this->_filesystems();
}
}
}
/web/acc/phpsysinfo/includes/os/class.BSDCommon.inc.php
0,0 → 1,661
<?php
/**
* BSDCommon Class
*
* PHP version 5
*
* @category PHP
* @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 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
*/
/**
* BSDCommon class
* get all the required information for BSD Like systems
* no need to implement in every class the same methods
*
* @category PHP
* @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 version 2, or (at your option) any later version
* @version Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
abstract class BSDCommon extends OS
{
/**
* content of the syslog
*
* @var array
*/
private $_dmesg = null;
 
/**
* regexp1 for cpu information out of the syslog
*
* @var string
*/
private $_CPURegExp1 = "//";
 
/**
* regexp2 for cpu information out of the syslog
*
* @var string
*/
private $_CPURegExp2 = "//";
 
/**
* regexp1 for scsi information out of the syslog
*
* @var string
*/
private $_SCSIRegExp1 = "//";
 
/**
* regexp2 for scsi information out of the syslog
*
* @var string
*/
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 = "//";
 
/**
* regexp1 for pci information out of the syslog
*
* @var string
*/
private $_PCIRegExp2 = "//";
 
/**
* setter for cpuregexp1
*
* @param string $value value to set
*
* @return void
*/
protected function setCPURegExp1($value)
{
$this->_CPURegExp1 = $value;
}
 
/**
* setter for cpuregexp2
*
* @param string $value value to set
*
* @return void
*/
protected function setCPURegExp2($value)
{
$this->_CPURegExp2 = $value;
}
 
/**
* setter for scsiregexp1
*
* @param string $value value to set
*
* @return void
*/
protected function setSCSIRegExp1($value)
{
$this->_SCSIRegExp1 = $value;
}
 
/**
* setter for scsiregexp2
*
* @param string $value value to set
*
* @return void
*/
protected function setSCSIRegExp2($value)
{
$this->_SCSIRegExp2 = $value;
}
 
/**
* setter for scsiregexp3
*
* @param string $value value to set
*
* @return void
*/
protected function setSCSIRegExp3($value)
{
$this->_SCSIRegExp3 = $value;
}
 
/**
* setter for pciregexp1
*
* @param string $value value to set
*
* @return void
*/
protected function setPCIRegExp1($value)
{
$this->_PCIRegExp1 = $value;
}
 
/**
* setter for pciregexp2
*
* @param string $value value to set
*
* @return void
*/
protected function setPCIRegExp2($value)
{
$this->_PCIRegExp2 = $value;
}
 
/**
* read /var/run/dmesg.boot, but only if we haven't already
*
* @return array
*/
protected function readdmesg()
{
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();
}
}
 
return $this->_dmesg;
}
 
/**
* get a value from sysctl command
*
* @param string $key key for the value to get
*
* @return string
*/
protected function grabkey($key)
{
$buf = "";
if (CommonFunctions::executeProgram('sysctl', "-n $key", $buf, PSI_DEBUG)) {
return $buf;
} else {
return '';
}
}
 
/**
* Virtual Host Name
*
* @return void
*/
protected function hostname()
{
if (PSI_USE_VHOST === true) {
if (CommonFunctions::readenv('SERVER_NAME', $hnm)) $this->sys->setHostname($hnm);
} else {
if (CommonFunctions::executeProgram('hostname', '', $buf, PSI_DEBUG)) {
$this->sys->setHostname($buf);
}
}
}
 
/**
* Kernel Version
*
* @return void
*/
protected function kernel()
{
$s = $this->grabkey('kern.version');
$a = preg_split('/:/', $s);
if (isset($a[2])) {
$this->sys->setKernel($a[0].$a[1].':'.$a[2]);
} else {
$this->sys->setKernel($s);
}
}
 
/**
* Processor Load
* optionally create a loadbar
*
* @return void
*/
protected function loadavg()
{
$s = $this->grabkey('vm.loadavg');
$s = preg_replace('/{ /', '', $s);
$s = preg_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));
}
}
}
 
/**
* CPU information
*
* @return void
*/
protected function cpuinfo()
{
$dev = new CpuDevice();
 
if (PSI_OS == "NetBSD") {
if ($model = $this->grabkey('machdep.cpu_brand')) {
$dev->setModel($model);
}
if ($cpuspeed = $this->grabkey('machdep.tsc_freq')) {
$dev->setCpuSpeed(round($cpuspeed / 1000000));
}
}
 
if ($dev->getModel() === "") {
$dev->setModel($this->grabkey('hw.model'));
}
$notwas = true;
foreach ($this->readdmesg() as $line) {
if ($notwas) {
if (preg_match($this->_CPURegExp1, $line, $ar_buf)) {
if ($dev->getCpuSpeed() === 0) {
$dev->setCpuSpeed(round($ar_buf[2]));
}
$notwas = false;
}
} else {
if (preg_match("/ Origin| Features/", $line, $ar_buf)) {
if (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;
}
}
break;
}
} else break;
}
}
 
$ncpu = $this->grabkey('hw.ncpu');
if (is_null($ncpu) || (trim($ncpu) == "") || (!($ncpu >= 1)))
$ncpu = 1;
for ($ncpu ; $ncpu > 0 ; $ncpu--) {
$this->sys->setCpus($dev);
}
}
 
/**
* SCSI devices
* get the scsi device information out of dmesg
*
* @return void
*/
protected function scsi()
{
foreach ($this->readdmesg() as $line) {
if (preg_match($this->_SCSIRegExp1, $line, $ar_buf)) {
$dev = new HWDevice();
$dev->setName($ar_buf[1].": ".trim($ar_buf[2]));
$this->sys->setScsiDevices($dev);
} elseif (preg_match($this->_SCSIRegExp2, $line, $ar_buf)) {
/* 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) {
if (isset($ar_buf[3]) && ($ar_buf[3]==="G")) {
$finddev->setCapacity($ar_buf[2] * 1024 * 1024 * 1024);
} else {
$finddev->setCapacity($ar_buf[2] * 1024 * 1024);
}
}
$notwas = false;
break;
}
}
if ($notwas) {
$dev = new HWDevice();
$dev->setName($ar_buf[1]);
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);
} else {
$dev->setCapacity($ar_buf[2] * 1024 * 1024);
}
}
$this->sys->setScsiDevices($dev);
}
} elseif (preg_match($this->_SCSIRegExp3, $line, $ar_buf)) {
/* 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) {
$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) {
$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));
}
}
 
/**
* parsing the output of pciconf command
*
* @return Array
*/
protected function pciconf()
{
$arrResults = array();
$intS = 0;
if (CommonFunctions::executeProgram("pciconf", "-lv", $strBuf, PSI_DEBUG)) {
$arrTemp = array();
$arrBlocks = preg_split("/\n\S/", $strBuf, -1, PREG_SPLIT_NO_EMPTY);
foreach ($arrBlocks as $strBlock) {
$arrLines = preg_split("/\n/", $strBlock, -1, PREG_SPLIT_NO_EMPTY);
$vend = null;
foreach ($arrLines as $strLine) {
if (preg_match("/\sclass=0x([a-fA-F0-9]{4})[a-fA-F0-9]{2}\s.*\schip=0x([a-fA-F0-9]{4})([a-fA-F0-9]{4})\s/", $strLine, $arrParts)) {
$arrTemp[$intS] = 'Class '.$arrParts[1].': Device '.$arrParts[3].':'.$arrParts[2];
$vend = '';
} elseif (preg_match("/(.*) = '(.*)'/", $strLine, $arrParts)) {
if (trim($arrParts[1]) == "vendor") {
$vend = trim($arrParts[2]);
} elseif (trim($arrParts[1]) == "device") {
if (($vend !== null) && ($vend !== '')) {
$arrTemp[$intS] = $vend." - ".trim($arrParts[2]);
} else {
$arrTemp[$intS] = trim($arrParts[2]);
$vend = '';
}
}
}
}
if ($vend !== null) {
$intS++;
}
}
foreach ($arrTemp as $name) {
$dev = new HWDevice();
$dev->setName($name);
$arrResults[] = $dev;
}
}
 
return $arrResults;
}
 
/**
* PCI devices
* get the pci device information out of dmesg
*
* @return void
*/
protected function pci()
{
if ((!$results = Parser::lspci(false)) && (!$results = $this->pciconf())) {
foreach ($this->readdmesg() as $line) {
if (preg_match($this->_PCIRegExp1, $line, $ar_buf)) {
$dev = new HWDevice();
$dev->setName($ar_buf[1].": ".$ar_buf[2]);
$results[] = $dev;
} elseif (preg_match($this->_PCIRegExp2, $line, $ar_buf)) {
$dev = new HWDevice();
$dev->setName($ar_buf[1].": ".$ar_buf[2]);
$results[] = $dev;
}
}
}
foreach ($results as $dev) {
$this->sys->setPciDevices($dev);
}
}
 
/**
* IDE devices
* get the ide device information out of dmesg
*
* @return void
*/
protected function ide()
{
foreach ($this->readdmesg() as $line) {
if (preg_match('/^(ad[0-9]+): (.*)MB <(.*)> (.*) (.*)/', $line, $ar_buf)) {
$dev = new HWDevice();
$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].": ".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].": ".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])) {
if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS) {
$finddev->setCapacity($ar_buf[2] * 1024 * 1024);
}
$notwas = false;
break;
}
}
if ($notwas) {
$dev = new HWDevice();
$dev->setName($ar_buf[1]);
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);
}
}
}
/* cleaning */
foreach ($this->sys->getIdeDevices() as $finddev) {
if (strpos($finddev->getName(), ': ') !== false)
$finddev->setName(substr(strstr($finddev->getName(), ': '), 2));
}
}
 
/**
* Physical memory information and Swap Space information
*
* @return void
*/
protected function memory()
{
if (PSI_OS == 'FreeBSD' || PSI_OS == 'OpenBSD') {
// vmstat on fbsd 4.4 or greater outputs kbytes not hw.pagesize
// I should probably add some version checking here, but for now
// we only support fbsd 4.4
$pagesize = 1024;
} else {
$pagesize = $this->grabkey('hw.pagesize');
}
if (CommonFunctions::executeProgram('vmstat', '', $vmstat, PSI_DEBUG)) {
$lines = preg_split("/\n/", $vmstat, -1, PREG_SPLIT_NO_EMPTY);
$ar_buf = preg_split("/\s+/", trim($lines[2]), 19);
if (PSI_OS == 'NetBSD' || PSI_OS == 'DragonFly') {
$this->sys->setMemFree($ar_buf[4] * 1024);
} else {
$this->sys->setMemFree($ar_buf[4] * $pagesize);
}
$this->sys->setMemTotal($this->grabkey('hw.physmem'));
$this->sys->setMemUsed($this->sys->getMemTotal() - $this->sys->getMemFree());
 
if (((PSI_OS == 'OpenBSD' || PSI_OS == 'NetBSD') && CommonFunctions::executeProgram('swapctl', '-l -k', $swapstat, PSI_DEBUG)) || CommonFunctions::executeProgram('swapinfo', '-k', $swapstat, PSI_DEBUG)) {
$lines = preg_split("/\n/", $swapstat, -1, PREG_SPLIT_NO_EMPTY);
foreach ($lines as $line) {
$ar_buf = preg_split("/\s+/", $line, 6);
if (($ar_buf[0] != 'Total') && ($ar_buf[0] != 'Device')) {
$dev = new DiskDevice();
$dev->setMountPoint($ar_buf[0]);
$dev->setName("SWAP");
$dev->setFsType('swap');
$dev->setTotal($ar_buf[1] * 1024);
$dev->setUsed($ar_buf[2] * 1024);
$dev->setFree($dev->getTotal() - $dev->getUsed());
$this->sys->setSwapDevices($dev);
}
}
}
}
}
 
/**
* USB devices
* get the ide device information out of dmesg
*
* @return void
*/
protected function usb()
{
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)) {
$dev = new HWDevice();
$dev->setName($ar_buf[2]);
$this->sys->setUSBDevices($dev);
}
}
}
 
/**
* filesystem information
*
* @return void
*/
protected function filesystems()
{
$arrResult = Parser::df();
foreach ($arrResult as $dev) {
$this->sys->setDiskDevices($dev);
}
}
 
/**
* Distribution
*
* @return void
*/
protected function distro()
{
if (CommonFunctions::executeProgram('uname', '-s', $result, PSI_DEBUG)) {
$this->sys->setDistribution($result);
}
}
 
/**
* get the information
*
* @see PSI_Interface_OS::build()
*
* @return Void
*/
public function build()
{
if (!$this->blockname || $this->blockname==='vitals') {
$this->distro();
$this->hostname();
$this->kernel();
$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();
}
}
}
/web/acc/phpsysinfo/includes/os/class.Darwin.inc.php
1,198 → 1,493
<?php
<?php
/**
* Darwin System Class
*
* PHP version 5
*
* @category PHP
* @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 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
*/
/**
* Darwin sysinfo class
* get all the required information from Darwin system
* information may be incomplete
*
* @category PHP
* @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 version 2, or (at your option) any later version
* @version Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
class Darwin extends BSDCommon
{
/**
* define the regexp for log parser
*/
/* public function __construct($blockname = false)
{
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->setCPURegExp2("/(.*) ([0-9]+) ([0-9]+) ([0-9]+) ([0-9]+)/");
$this->setSCSIRegExp1("/^(.*): <(.*)> .*SCSI.*device/");
} */
 
// phpSysInfo - A PHP System Information Script
// http://phpsysinfo.sourceforge.net/
/**
* get a value from sysctl command
*
* @param string $key key of the value to get
*
* @return string
*/
protected function grabkey($key)
{
if (CommonFunctions::executeProgram('sysctl', $key, $s, PSI_DEBUG)) {
$s = preg_replace('/'.$key.': /', '', $s);
$s = preg_replace('/'.$key.' = /', '', $s);
 
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
return $s;
} else {
return '';
}
}
 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
/**
* get a value from ioreg command
*
* @param string $key key of the value to get
*
* @return string
*/
private function _grabioreg($key)
{
if (CommonFunctions::executeProgram('ioreg', '-c "'.$key.'"', $s, PSI_DEBUG)) {
/* delete newlines */
$s = preg_replace("/\s+/", " ", $s);
/* new newlines */
$s = preg_replace("/[\|\t ]*\+\-o/", "\n", $s);
/* combine duplicate whitespaces and some chars */
$s = preg_replace("/[\|\t ]+/", " ", $s);
 
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
$lines = preg_split("/\n/", $s, -1, PREG_SPLIT_NO_EMPTY);
$out = "";
foreach ($lines as $line) {
if (preg_match('/^([^<]*) <class '.$key.',/', $line)) {
$out .= $line."\n";
}
}
 
// $Id: class.Darwin.inc.php,v 1.33 2006/06/14 16:36:34 bigmichi1 Exp $
if (!defined('IN_PHPSYSINFO')) {
die("No Hacking");
}
return $out;
} else {
return '';
}
}
 
require_once(APP_ROOT . '/includes/os/class.BSD.common.inc.php');
/**
* 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);
}
}
}
 
$error->addWarning("The Darwin version of phpSysInfo is work in progress, some things currently don't work");
/**
* get CPU information
*
* @return void
*/
protected function cpuinfo()
{
$dev = new CpuDevice();
if (CommonFunctions::executeProgram('hostinfo', '| grep "Processor type"', $buf, PSI_DEBUG)) {
$dev->setModel(preg_replace('/Processor type: /', '', $buf));
$buf=$this->grabkey('hw.model');
if (!is_null($buf) && (trim($buf) != "")) {
$this->sys->setMachine(trim($buf));
if (CommonFunctions::rfts(PSI_APP_ROOT.'/data/ModelTranslation.txt', $buffer)) {
$buffer = preg_split("/\n/", $buffer, -1, PREG_SPLIT_NO_EMPTY);
foreach ($buffer as $line) {
$ar_buf = preg_split("/:/", $line, 3);
if (trim($buf) === trim($ar_buf[0])) {
$dev->setModel(trim($ar_buf[2]));
$this->sys->setMachine($this->sys->getMachine().' - '.trim($ar_buf[1]));
break;
}
}
}
}
$buf=$this->grabkey('machdep.cpu.brand_string');
if (!is_null($buf) && (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 (preg_match("/ VMX/", $buf)) {
$dev->setVirt("vmx");
} elseif (preg_match("/ SVM/", $buf)) {
$dev->setVirt("svm");
}
}
}
$dev->setCpuSpeed(round($this->grabkey('hw.cpufrequency') / 1000000));
$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)) {
$dev->setCpuSpeedMin(round($bufn / 1000000));
$dev->setCpuSpeedMax(round($bufx / 1000000));
}
$buf=$this->grabkey('hw.l2cachesize');
if (!is_null($buf) && (trim($buf) != "")) {
$dev->setCache(round($buf));
}
$ncpu = $this->grabkey('hw.ncpu');
if (is_null($ncpu) || (trim($ncpu) == "") || (!($ncpu >= 1)))
$ncpu = 1;
for ($ncpu ; $ncpu > 0 ; $ncpu--) {
$this->sys->setCpus($dev);
}
}
 
class sysinfo extends bsd_common {
var $cpu_regexp;
var $scsi_regexp;
var $parser;
// Our contstructor
// this function is run on the initialization of this class
function sysinfo () {
// $this->cpu_regexp = "CPU: (.*) \((.*)-MHz (.*)\)";
// $this->scsi_regexp1 = "^(.*): <(.*)> .*SCSI.*device";
$this->cpu_regexp2 = "/(.*) ([0-9]+) ([0-9]+) ([0-9]+) ([0-9]+)/";
$this->parser = new Parser();
}
/**
* get the pci device information out of ioreg
*
* @return void
*/
protected function pci()
{
if (!$arrResults = Parser::lspci(false)) { //no lspci port
$s = $this->_grabioreg('IOPCIDevice');
$lines = preg_split("/\n/", $s, -1, PREG_SPLIT_NO_EMPTY);
foreach ($lines as $line) {
$dev = new HWDevice();
if (!preg_match('/"IOName" = "([^"]*)"/', $line, $ar_buf)) {
$ar_buf = preg_split("/[\s@]+/", $line, 19);
}
if (preg_match('/"model" = <?"([^"]*)"/', $line, $ar_buf2)) {
$dev->setName(trim($ar_buf[1]). ": ".trim($ar_buf2[1]));
} else {
$dev->setName(trim($ar_buf[1]));
}
$this->sys->setPciDevices($dev);
}
} else {
foreach ($arrResults as $dev) {
$this->sys->setPciDevices($dev);
}
}
}
 
function grab_key ($key) {
$s = execute_program('sysctl', $key);
$s = ereg_replace($key . ': ', '', $s);
$s = ereg_replace($key . ' = ', '', $s); // fix Apple set keys
return $s;
}
/**
* get the ide device information out of ioreg
*
* @return void
*/
protected function ide()
{
$s = $this->_grabioreg('IOATABlockStorageDevice');
$lines = preg_split("/\n/", $s, -1, PREG_SPLIT_NO_EMPTY);
foreach ($lines as $line) {
$dev = new HWDevice();
if (!preg_match('/"Product Name"="([^"]*)"/', $line, $ar_buf))
$ar_buf = preg_split("/[\s@]+/", $line, 19);
$dev->setName(trim($ar_buf[1]));
$this->sys->setIdeDevices($dev);
}
 
function grab_ioreg ($key) {
$s = execute_program('ioreg', '-cls "' . $key . '" | grep "' . $key . '"'); //ioreg -cls "$key" | grep "$key"
$s = ereg_replace('\|', '', $s);
$s = ereg_replace('\+\-\o', '', $s);
$s = ereg_replace('[ ]+', '', $s);
$s = ereg_replace('<[^>]+>', '', $s); // remove possible XML conflicts
$s = $this->_grabioreg('IOAHCIBlockStorageDevice');
$lines = preg_split("/\n/", $s, -1, PREG_SPLIT_NO_EMPTY);
foreach ($lines as $line) {
$dev = new HWDevice();
if (!preg_match('/"Product Name"="([^"]*)"/', $line, $ar_buf))
$ar_buf = preg_split("/[\s@]+/", $line, 19);
$dev->setName(trim($ar_buf[1]));
$this->sys->setIdeDevices($dev);
}
}
 
return $s;
}
/**
* get the usb device information out of ioreg
*
* @return void
*/
protected function usb()
{
$s = $this->_grabioreg('IOUSBDevice');
$lines = preg_split("/\n/", $s, -1, PREG_SPLIT_NO_EMPTY);
foreach ($lines as $line) {
$dev = new HWDevice();
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);
}
}
 
function get_sys_ticks () {
$a = execute_program('sysctl', '-n kern.boottime'); // get boottime (value in seconds)
$sys_ticks = time() - $a;
/**
* get the scsi device information out of ioreg
*
* @return void
*/
protected function scsi()
{
$s = $this->_grabioreg('IOBlockStorageServices');
$lines = preg_split("/\n/", $s, -1, PREG_SPLIT_NO_EMPTY);
foreach ($lines as $line) {
$dev = new HWDevice();
if (!preg_match('/"Product Name"="([^"]*)"/', $line, $ar_buf))
$ar_buf = preg_split("/[\s@]+/", $line, 19);
$dev->setName(trim($ar_buf[1]));
$this->sys->setScsiDevices($dev);
}
}
 
return $sys_ticks;
}
/**
* get memory and swap information
*
* @return void
*/
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);
} 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);
 
function cpu_info () {
$results = array();
// $results['model'] = $this->grab_key('hw.model'); // need to expand this somehow...
// $results['model'] = $this->grab_key('hw.machine');
$results['model'] = ereg_replace('Processor type: ', '', execute_program('hostinfo', '| grep "Processor type"')); // get processor type
$results['cpus'] = $this->grab_key('hw.ncpu');
$results['cpuspeed'] = round($this->grab_key('hw.cpufrequency') / 1000000); // return cpu speed - Mhz
$results['busspeed'] = round($this->grab_key('hw.busfrequency') / 1000000); // return bus speed - Mhz
$results['cache'] = round($this->grab_key('hw.l2cachesize') / 1024); // return l2 cache
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);
}
 
if (($this->grab_key('hw.model') == "PowerMac3,6") && ($results['cpus'] == "2")) { $results['model'] = 'Dual G4 - (PowerPC 7450)';} // is Dual G4
if (($this->grab_key('hw.model') == "PowerMac7,2") && ($results['cpus'] == "2")) { $results['model'] = 'Dual G5 - (PowerPC 970)';} // is Dual G5
if (($this->grab_key('hw.model') == "PowerMac1,1") && ($results['cpus'] == "1")) { $results['model'] = 'B&W G3 - (PowerPC 750)';} // is B&W G3
$this->sys->setMemTotal($s);
$this->sys->setMemUsed($this->sys->getMemTotal() - $this->sys->getMemFree());
 
return $results;
}
// get the pci device information out of ioreg
function pci () {
$results = array();
$s = $this->grab_ioreg('IOPCIDevice');
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);
}
}
}
 
$lines = explode("\n", $s);
for ($i = 0, $max = sizeof($lines); $i < $max; $i++) {
$ar_buf = preg_split("/\s+/", $lines[$i], 19);
$results[$i] = $ar_buf[0];
}
asort($results);
return array_values(array_unique($results));
}
// get the ide device information out of ioreg
function ide () {
$results = array();
// ioreg | grep "Media <class IOMedia>"
$s = $this->grab_ioreg('IOATABlockStorageDevice');
/**
* get the thunderbolt device information out of ioreg
*
* @return void
*/
protected function _tb()
{
$s = $this->_grabioreg('IOThunderboltPort');
$lines = preg_split("/\n/", $s, -1, PREG_SPLIT_NO_EMPTY);
foreach ($lines as $line) {
$dev = new HWDevice();
if (!preg_match('/"Description" = "([^"]*)"/', $line, $ar_buf))
$ar_buf = preg_split("/[\s@]+/", $line, 19);
$dev->setName(trim($ar_buf[1]));
$this->sys->setTbDevices($dev);
}
}
 
$lines = explode("\n", $s);
$j = 0;
for ($i = 0, $max = sizeof($lines); $i < $max; $i++) {
$ar_buf = preg_split("/\/\//", $lines[$i], 19);
/**
* get network information
*
* @return void
*/
private function _network()
{
if (CommonFunctions::executeProgram('netstat', '-nbdi | cut -c1-24,42- | grep Link', $netstat, PSI_DEBUG)) {
$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])) {
$dev = new NetDevice();
$dev->setName($ar_buf[0]);
$dev->setTxBytes($ar_buf[8]);
$dev->setRxBytes($ar_buf[5]);
$dev->setErrors($ar_buf[4] + $ar_buf[7]);
if (isset($ar_buf[10])) {
$dev->setDrops($ar_buf[10]);
}
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)) {
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))
$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);
}
}
}
}
 
if ( isset( $ar_buf[1] ) && $ar_buf[1] == 'class IOMedia' && preg_match('/Media/', $ar_buf[0])) {
$results[$j++]['model'] = $ar_buf[0];
}
}
asort($results);
return array_values(array_unique($results));
}
/**
* get icon name
*
* @return void
*/
protected function distro()
{
$this->sys->setDistributionIcon('Darwin.png');
if (!CommonFunctions::executeProgram('system_profiler', 'SPSoftwareDataType', $buffer, PSI_DEBUG)) {
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]);
 
function memory () {
$s = $this->grab_key('hw.memsize');
if (preg_match('/^Mac OS|^OS X|^macOS/', $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))
&& isset($list['OS X'][$ver[2]])) {
$distro.=' '.$list['OS X'][$ver[2]];
}
}
 
$results['ram'] = array();
$results['swap'] = array();
$results['devswap'] = array();
$pstat = execute_program('vm_stat'); // use darwin's vm_stat
$lines = explode("\n", $pstat);
for ($i = 0, $max = sizeof($lines); $i < $max; $i++) {
$ar_buf = preg_split("/\s+/", $lines[$i], 19);
$this->sys->setDistribution($distro);
 
if ($i == 1) {
$results['ram']['free'] = $ar_buf[2] * 4; // calculate free memory from page sizes (each page = 4MB)
}
}
return;
}
}
}
}
 
$results['ram']['total'] = $s / 1024;
$results['ram']['shared'] = 0;
$results['ram']['buffers'] = 0;
$results['ram']['used'] = $results['ram']['total'] - $results['ram']['free'];
$results['ram']['cached'] = 0;
/**
* Processes
*
* @return void
*/
protected function _processes()
{
if (CommonFunctions::executeProgram('ps', 'aux', $bufr, PSI_DEBUG)) {
$lines = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
$processes['*'] = 0;
foreach ($lines as $line) {
if (preg_match("/^\S+\s+\d+\s+\S+\s+\S+\s+\d+\s+\d+\s+\S+\s+(\w)/", $line, $ar_buf)) {
$processes['*']++;
$state = $ar_buf[1];
if ($state == 'U') $state = 'D'; //linux format
elseif ($state == 'I') $state = 'S';
elseif ($state == 'D') $state = 'd'; //invalid
if (isset($processes[$state])) {
$processes[$state]++;
} else {
$processes[$state] = 1;
}
}
}
if ($processes['*'] > 0) {
$this->sys->setProcesses($processes);
}
}
}
 
$results['ram']['percent'] = round(($results['ram']['used'] * 100) / $results['ram']['total']);
// need to fix the swap info...
// meanwhile silence and / or disable the swap information
$pstat = execute_program('swapinfo', '-k', false);
if( $pstat != "ERROR" ) {
$lines = explode("\n", $pstat);
 
for ($i = 0, $max = sizeof($lines); $i < $max; $i++) {
$ar_buf = preg_split("/\s+/", $lines[$i], 6);
if ($i == 0) {
$results['swap']['total'] = 0;
$results['swap']['used'] = 0;
$results['swap']['free'] = 0;
} else {
$results['swap']['total'] = $results['swap']['total'] + $ar_buf[1];
$results['swap']['used'] = $results['swap']['used'] + $ar_buf[2];
$results['swap']['free'] = $results['swap']['free'] + $ar_buf[3];
}
}
$results['swap']['percent'] = round(($results['swap']['used'] * 100) / $results['swap']['total']);
/**
* get the information
*
* @see PSI_Interface_OS::build()
*
* @return Void
*/
public function build()
{
parent::build();
if (!$this->blockname || $this->blockname==='vitals') {
$this->_uptime();
$this->_processes();
}
if (!$this->blockname || $this->blockname==='hardware') {
$this->_tb();
}
if (!$this->blockname || $this->blockname==='network') {
$this->_network();
}
}
return $results;
}
 
function network () {
$netstat = execute_program('netstat', '-nbdi | cut -c1-24,42- | grep Link');
$lines = explode("\n", $netstat);
$results = array();
for ($i = 0, $max = sizeof($lines); $i < $max; $i++) {
$ar_buf = preg_split("/\s+/", $lines[$i], 10);
if (!empty($ar_buf[0])) {
$results[$ar_buf[0]] = array();
 
$results[$ar_buf[0]]['rx_bytes'] = $ar_buf[5];
$results[$ar_buf[0]]['rx_packets'] = $ar_buf[3];
$results[$ar_buf[0]]['rx_errs'] = $ar_buf[4];
$results[$ar_buf[0]]['rx_drop'] = isset( $ar_buf[10] ) ? $ar_buf[10] : 0;
 
$results[$ar_buf[0]]['tx_bytes'] = $ar_buf[8];
$results[$ar_buf[0]]['tx_packets'] = $ar_buf[6];
$results[$ar_buf[0]]['tx_errs'] = $ar_buf[7];
$results[$ar_buf[0]]['tx_drop'] = isset( $ar_buf[10] ) ? $ar_buf[10] : 0;
 
$results[$ar_buf[0]]['errs'] = $ar_buf[4] + $ar_buf[7];
$results[$ar_buf[0]]['drop'] = isset( $ar_buf[10] ) ? $ar_buf[10] : 0;
}
}
return $results;
}
 
function distroicon () {
$result = 'Darwin.png';
return($result);
}
 
}
 
?>
}
/web/acc/phpsysinfo/includes/os/class.DragonFly.inc.php
0,0 → 1,157
<?php
/**
* DragonFly System Class
*
* PHP version 5
*
* @category PHP
* @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 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
*/
/**
* DragonFly sysinfo class
* get all the required information from DragonFly system
*
* @category PHP
* @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 version 2, or (at your option) any later version
* @version Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
class DragonFly extends BSDCommon
{
/**
* define the regexp for log parser
*/
public function __construct($blockname = false)
{
parent::__construct($blockname);
$this->setCPURegExp1("/^cpu(.*)\, (.*) MHz/");
$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->grabkey('kern.boottime');
preg_match("/sec = ([0-9]+)/", $a, $buf);
$this->sys->setUptime(time() - $buf[1]);
}
 
/**
* get network information
*
* @return void
*/
private function _network()
{
CommonFunctions::executeProgram('netstat', '-nbdi | cut -c1-25,44- | grep "^[a-z]*[0-9][ \t].*Link"', $netstat_b);
CommonFunctions::executeProgram('netstat', '-ndi | cut -c1-25,44- | grep "^[a-z]*[0-9][ \t].*Link"', $netstat_n);
$lines_b = preg_split("/\n/", $netstat_b, -1, PREG_SPLIT_NO_EMPTY);
$lines_n = preg_split("/\n/", $netstat_n, -1, PREG_SPLIT_NO_EMPTY);
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[5]) || ($ar_buf_n[5] === "0"))) {
$dev = new NetDevice();
$dev->setName($ar_buf_b[0]);
$dev->setTxBytes($ar_buf_b[8]);
$dev->setRxBytes($ar_buf_b[5]);
$dev->setErrors($ar_buf_n[4] + $ar_buf_n[6]);
$dev->setDrops($ar_buf_n[8]);
$this->sys->setNetDevices($dev);
}
}
}
 
/**
* get the ide information
*
* @return void
*/
protected function ide()
{
foreach ($this->readdmesg() as $line) {
if (preg_match('/^(.*): (.*) <(.*)> at (ata[0-9]+\-(.*)) (.*)/', $line, $ar_buf)) {
$dev = new HWDevice();
$dev->setName($ar_buf[1]);
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);
}
}
}
 
/**
* get icon name
*
* @return void
*/
private function _distroicon()
{
$this->sys->setDistributionIcon('DragonFly.png');
}
 
/**
* Processes
*
* @return void
*/
protected function _processes()
{
if (CommonFunctions::executeProgram('ps', 'aux', $bufr, PSI_DEBUG)) {
$lines = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
$processes['*'] = 0;
foreach ($lines as $line) {
if (preg_match("/^\S+\s+\d+\s+\S+\s+\S+\s+\d+\s+\d+\s+\S+\s+(\w)/", $line, $ar_buf)) {
$processes['*']++;
$state = $ar_buf[1];
if ($state == 'I') $state = 'S'; //linux format
if (isset($processes[$state])) {
$processes[$state]++;
} else {
$processes[$state] = 1;
}
}
}
if ($processes['*'] > 0) {
$this->sys->setProcesses($processes);
}
}
}
 
/**
* get the information
*
* @see BSDCommon::build()
*
* @return Void
*/
public function build()
{
parent::build();
if (!$this->blockname || $this->blockname==='vitals') {
$this->_distroicon();
$this->_uptime();
$this->_processes();
}
if (!$this->blockname || $this->blockname==='network') {
$this->_network();
}
}
}
/web/acc/phpsysinfo/includes/os/class.FreeBSD.inc.php
1,108 → 1,208
<?php
<?php
/**
* FreeBSD System Class
*
* PHP version 5
*
* @category PHP
* @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 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
*/
/**
* FreeBSD sysinfo class
* get all the required information from FreeBSD system
*
* @category PHP
* @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 version 2, or (at your option) any later version
* @version Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
class FreeBSD extends BSDCommon
{
/**
* define the regexp for log parser
*/
public function __construct($blockname = false)
{
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->setSCSIRegExp3("/^(da[0-9]+|cd[0-9]+): Serial Number (.*)/");
$this->setPCIRegExp1("/(.*): <(.*)>(.*) pci[0-9]+$/");
$this->setPCIRegExp2("/(.*): <(.*)>.* at [.0-9]+ irq/");
}
 
// phpSysInfo - A PHP System Information Script
// http://phpsysinfo.sourceforge.net/
/**
* 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);
}
 
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
/**
* get network information
*
* @return void
*/
private function _network()
{
$dev = null;
if (CommonFunctions::executeProgram('netstat', '-nibd', $netstat, PSI_DEBUG)) {
$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 (preg_match('/^<Link/i', $ar_buf[2])) {
$dev = new NetDevice();
$dev->setName($ar_buf[0]);
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]);
$dev->setErrors($ar_buf[4] + $ar_buf[8]);
$dev->setDrops($ar_buf[11] + $ar_buf[5]);
} else {
$dev->setTxBytes($ar_buf[8]);
$dev->setRxBytes($ar_buf[5]);
$dev->setErrors($ar_buf[4] + $ar_buf[7]);
$dev->setDrops($ar_buf[10]);
}
} else {
if (isset($ar_buf[12]) && (trim($ar_buf[12]) != '')) { /* Idrop column exist*/
$dev->setTxBytes($ar_buf[10]);
$dev->setRxBytes($ar_buf[7]);
$dev->setErrors($ar_buf[5] + $ar_buf[9]);
$dev->setDrops($ar_buf[12] + $ar_buf[6]);
} else {
$dev->setTxBytes($ar_buf[9]);
$dev->setRxBytes($ar_buf[6]);
$dev->setErrors($ar_buf[5] + $ar_buf[8]);
$dev->setDrops($ar_buf[11]);
}
}
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)) {
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))
$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);
}
}
}
}
}
 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
 
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
// $Id: class.FreeBSD.inc.php,v 1.17 2006/04/18 16:22:26 bigmichi1 Exp $
if (!defined('IN_PHPSYSINFO')) {
die("No Hacking");
}
 
require_once(APP_ROOT . '/includes/os/class.BSD.common.inc.php');
 
class sysinfo extends bsd_common {
var $cpu_regexp = "";
var $scsi_regexp1 = "";
var $scsi_regexp2 = "";
var $cpu_regexp2 = "";
// Our contstructor
// this function is run on the initialization of this class
function sysinfo () {
$this->bsd_common();
$this->cpu_regexp = "CPU: (.*) \((.*)-MHz (.*)\)";
$this->scsi_regexp1 = "^(.*): <(.*)> .*SCSI.*device";
$this->scsi_regexp2 = "^(da[0-9]): (.*)MB ";
$this->cpu_regexp2 = "/(.*) ([0-9]+) ([0-9]+) ([0-9]+) ([0-9]+)/";
}
 
function get_sys_ticks () {
$s = explode(' ', $this->grab_key('kern.boottime'));
$a = ereg_replace('{ ', '', $s[3]);
$sys_ticks = time() - $a;
return $sys_ticks;
}
 
function network () {
$netstat = execute_program('netstat', '-nibd | grep Link');
$lines = explode("\n", $netstat);
$results = array();
for ($i = 0, $max = sizeof($lines); $i < $max; $i++) {
$ar_buf = preg_split("/\s+/", $lines[$i]);
if (!empty($ar_buf[0])) {
$results[$ar_buf[0]] = array();
 
if (strlen($ar_buf[3]) < 15) {
$results[$ar_buf[0]]['rx_bytes'] = $ar_buf[5];
$results[$ar_buf[0]]['rx_packets'] = $ar_buf[3];
$results[$ar_buf[0]]['rx_errs'] = $ar_buf[4];
$results[$ar_buf[0]]['rx_drop'] = $ar_buf[10];
 
$results[$ar_buf[0]]['tx_bytes'] = $ar_buf[8];
$results[$ar_buf[0]]['tx_packets'] = $ar_buf[6];
$results[$ar_buf[0]]['tx_errs'] = $ar_buf[7];
$results[$ar_buf[0]]['tx_drop'] = $ar_buf[10];
 
$results[$ar_buf[0]]['errs'] = $ar_buf[4] + $ar_buf[7];
$results[$ar_buf[0]]['drop'] = $ar_buf[10];
/**
* get icon name and distro extended check
*
* @return void
*/
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');
} else {
$results[$ar_buf[0]]['rx_bytes'] = $ar_buf[6];
$results[$ar_buf[0]]['rx_packets'] = $ar_buf[4];
$results[$ar_buf[0]]['rx_errs'] = $ar_buf[5];
$results[$ar_buf[0]]['rx_drop'] = $ar_buf[11];
$this->sys->setDistributionIcon('FreeBSD.png');
}
}
 
$results[$ar_buf[0]]['tx_bytes'] = $ar_buf[9];
$results[$ar_buf[0]]['tx_packets'] = $ar_buf[7];
$results[$ar_buf[0]]['tx_errs'] = $ar_buf[8];
$results[$ar_buf[0]]['tx_drop'] = $ar_buf[11];
/**
* extend the memory information with additional values
*
* @return void
*/
private function _memoryadditional()
{
$pagesize = $this->grabkey("hw.pagesize");
$this->sys->setMemCache($this->grabkey("vm.stats.vm.v_cache_count") * $pagesize);
$this->sys->setMemApplication(($this->grabkey("vm.stats.vm.v_active_count") + $this->grabkey("vm.stats.vm.v_wire_count")) * $pagesize);
$this->sys->setMemBuffer($this->sys->getMemUsed() - $this->sys->getMemApplication() - $this->sys->getMemCache());
}
 
$results[$ar_buf[0]]['errs'] = $ar_buf[5] + $ar_buf[8];
$results[$ar_buf[0]]['drop'] = $ar_buf[11];
}
}
}
return $results;
}
/**
* Processes
*
* @return void
*/
protected function _processes()
{
if (CommonFunctions::executeProgram('ps', 'aux', $bufr, PSI_DEBUG)) {
$lines = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
$processes['*'] = 0;
foreach ($lines as $line) {
if (preg_match("/^\S+\s+\d+\s+\S+\s+\S+\s+\d+\s+\d+\s+\S+\s+(\w)/", $line, $ar_buf)) {
$processes['*']++;
$state = $ar_buf[1];
if ($state == 'L') $state = 'D'; //linux format
elseif ($state == 'I') $state = 'S';
if (isset($processes[$state])) {
$processes[$state]++;
} else {
$processes[$state] = 1;
}
}
}
if ($processes['*'] > 0) {
$this->sys->setProcesses($processes);
}
}
}
 
function distroicon () {
$result = 'FreeBSD.png';
return($result);
}
function memory_additional($results) {
$pagesize = $this->grab_key("hw.pagesize");
$results['ram']['cached'] = $this->grab_key("vm.stats.vm.v_cache_count") * $pagesize / 1024;
$results['ram']['cached_percent'] = round( $results['ram']['cached'] * 100 / $results['ram']['total']);
$results['ram']['app'] = $this->grab_key("vm.stats.vm.v_active_count") * $pagesize / 1024;
$results['ram']['app_percent'] = round( $results['ram']['app'] * 100 / $results['ram']['total']);
$results['ram']['buffers'] = $results['ram']['used'] - $results['ram']['app'] - $results['ram']['cached'];
$results['ram']['buffers_percent'] = round( $results['ram']['buffers'] * 100 / $results['ram']['total']);
return $results;
}
}
 
?>
/**
* get the information
*
* @see BSDCommon::build()
*
* @return Void
*/
public function build()
{
parent::build();
if (!$this->blockname || $this->blockname==='vitals') {
$this->_distroicon();
$this->_uptime();
$this->_processes();
}
if (!$this->blockname || $this->blockname==='network') {
$this->_network();
}
if (!$this->blockname || $this->blockname==='memory') {
$this->_memoryadditional();
}
}
}
/web/acc/phpsysinfo/includes/os/class.HPUX.inc.php
0,0 → 1,390
<?php
/**
* HP-UX System Class
*
* PHP version 5
*
* @category PHP
* @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 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
*/
/**
* HP-UX sysinfo class
* get all the required information from HP-UX system
*
* @category PHP
* @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 version 2, or (at your option) any later version
* @version Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
class HPUX extends OS
{
/**
* Virtual Host Name
*
* @return void
*/
private function _hostname()
{
if (PSI_USE_VHOST === true) {
if (CommonFunctions::readenv('SERVER_NAME', $hnm)) $this->sys->setHostname($hnm);
} else {
if (CommonFunctions::executeProgram('hostname', '', $ret)) {
$this->sys->setHostname($ret);
}
}
}
 
/**
* HP-UX Version
*
* @return void
*/
private function _kernel()
{
if (CommonFunctions::executeProgram('uname', '-srvm', $ret)) {
$this->sys->setKernel($ret);
}
}
 
/**
* UpTime
* time the system is running
*
* @return void
*/
private function _uptime()
{
if (CommonFunctions::executeProgram('uptime', '', $buf)) {
if (preg_match("/up (\d+) days,\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);
}
}
}
 
/**
* Processor Load
* optionally create a loadbar
*
* @return void
*/
private function _loadavg()
{
if (CommonFunctions::executeProgram('uptime', '', $buf)) {
if (preg_match("/average: (.*), (.*), (.*)$/", $buf, $ar_buf)) {
$this->sys->setLoad($ar_buf[1].' '.$ar_buf[2].' '.$ar_buf[3]);
}
}
}
 
/**
* CPU information
* All of the tags here are highly architecture dependant
*
* @return void
*/
private function _cpuinfo()
{
if (CommonFunctions::rfts('/proc/cpuinfo', $bufr)) {
$processors = preg_split('/\s?\n\s?\n/', trim($bufr));
foreach ($processors as $processor) {
$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])) {
case 'model name':
case 'cpu':
$dev->setModel($arrBuff[1]);
break;
case 'cpu mhz':
case 'clock':
$dev->setCpuSpeed($arrBuff[1]);
break;
case 'cycle frequency [hz]':
$dev->setCpuSpeed($arrBuff[1] / 1000000);
break;
case 'cpu0clktck':
$dev->setCpuSpeed(hexdec($arrBuff[1]) / 1000000); // Linux sparc64
break;
case 'l2 cache':
case 'cache size':
$dev->setCache(preg_replace("/[a-zA-Z]/", "", $arrBuff[1]) * 1024);
break;
case 'bogomips':
case 'cpu0bogo':
$dev->setBogomips($arrBuff[1]);
break;
}
}
}
}
}
}
 
/**
* PCI devices
*
* @return void
*/
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('/^\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;
}
}
}
}
 
/**
* IDE devices
*
* @return void
*/
private function _ide()
{
$bufd = CommonFunctions::gdc('/proc/ide', false);
foreach ($bufd as $file) {
if (preg_match('/^hd/', $file)) {
$dev = new HWDevice();
$dev->setName(trim($file));
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);
}
}
}
$this->sys->setIdeDevices($dev);
}
}
}
 
/**
* SCSI devices
*
* @return void
*/
private function _scsi()
{
$get_type = false;
if (CommonFunctions::rfts('/proc/scsi/scsi', $bufr, 0, 4096, PSI_DEBUG)) {
$bufe = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
foreach ($bufe as $buf) {
if (preg_match('/Vendor: (.*) Model: (.*) Rev: (.*)/i', $buf, $dev)) {
$get_type = true;
continue;
}
if ($get_type) {
preg_match('/Type:\s+(\S+)/i', $buf, $dev_type);
$dev = new HWDevice();
$dev->setName($dev[1].' '.$dev[2].' ('.$dev_type[1].')');
$this->sys->setScsiDevices($dev);
$get_type = false;
}
}
}
}
 
/**
* USB devices
*
* @return void
*/
private function _usb()
{
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++;
$results[$devnum] = "";
} elseif (preg_match('/^S:/', $buf)) {
list($key, $value) = preg_split('/: /', $buf, 2);
list($key, $value2) = preg_split('/=/', $value, 2);
if (trim($key) != "SerialNumber") {
$results[$devnum] .= " ".trim($value2);
}
}
}
foreach ($results as $var) {
$dev = new HWDevice();
$dev->setName($var);
$this->sys->setUsbDevices($dev);
}
}
}
 
/**
* Network devices
* includes also rx/tx bytes
*
* @return void
*/
private function _network()
{
if (CommonFunctions::executeProgram('netstat', '-ni | tail -n +2', $netstat)) {
$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]) && ! empty($ar_buf[3])) {
$dev = new NetDevice();
$dev->setName($ar_buf[0]);
$dev->setRxBytes($ar_buf[4]);
$dev->setTxBytes($ar_buf[6]);
$dev->setErrors($ar_buf[5] + $ar_buf[7]);
$dev->setDrops($ar_buf[8]);
$this->sys->setNetDevices($dev);
}
}
}
}
 
/**
* Physical memory information and Swap Space information
*
* @return void
*/
private function _memory()
{
if (CommonFunctions::rfts('/proc/meminfo', $bufr)) {
$bufe = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
foreach ($bufe as $buf) {
if (preg_match('/Mem:\s+(.*)$/', $buf, $ar_buf)) {
$ar_buf = preg_split('/\s+/', $ar_buf[1], 6);
$this->sys->setMemTotal($ar_buf[0]);
$this->sys->setMemUsed($ar_buf[1]);
$this->sys->setMemFree($ar_buf[2]);
$this->sys->setMemApplication($ar_buf[3]);
$this->sys->setMemBuffer($ar_buf[4]);
$this->sys->setMemCache($ar_buf[5]);
}
// Get info on individual swap files
if (CommonFunctions::rfts('/proc/swaps', $swaps)) {
$swapdevs = preg_split("/\n/", $swaps, -1, PREG_SPLIT_NO_EMPTY);
for ($i = 1, $max = (sizeof($swapdevs) - 1); $i < $max; $i++) {
$ar_buf = preg_split('/\s+/', $swapdevs[$i], 6);
$dev = new DiskDevice();
$dev->setMountPoint($ar_buf[0]);
$dev->setName("SWAP");
$dev->setFsType('swap');
$dev->setTotal($ar_buf[2] * 1024);
$dev->setUsed($ar_buf[3] * 1024);
$dev->setFree($dev->getTotal() - $dev->getUsed());
$this->sys->setSwapDevices($dev);
}
}
}
}
}
 
/**
* filesystem information
*
* @return void
*/
private function _filesystems()
{
if (CommonFunctions::executeProgram('df', '-kP', $df, PSI_DEBUG)) {
$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);
foreach ($lines as $line) {
$a = preg_split('/ /', $line, -1, PREG_SPLIT_NO_EMPTY);
$fsdev[$a[0]] = $a[4];
}
}
foreach ($mounts as $mount) {
$ar_buf = preg_split("/\s+/", $mount, 6);
$dev = new DiskDevice();
$dev->setName($ar_buf[0]);
$dev->setTotal($ar_buf[1] * 1024);
$dev->setUsed($ar_buf[2] * 1024);
$dev->setFree($ar_buf[3] * 1024);
$dev->setMountPoint($ar_buf[5]);
if (isset($fsdev[$ar_buf[0]])) {
$dev->setFsType($fsdev[$ar_buf[0]]);
}
$this->sys->setDiskDevices($dev);
}
}
}
 
/**
* Distribution
*
* @return void
*/
private function _distro()
{
$this->sys->setDistribution('HP-UX');
$this->sys->setDistributionIcon('HPUX.png');
}
 
/**
* get the information
*
* @see PSI_Interface_OS::build()
*
* @return Void
*/
public function build()
{
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==='network') {
$this->_network();
}
if (!$this->blockname || $this->blockname==='memory') {
$this->_memory();
}
if (!$this->blockname || $this->blockname==='filesystem') {
$this->_filesystems();
}
}
}
/web/acc/phpsysinfo/includes/os/class.Haiku.inc.php
0,0 → 1,391
<?php
/**
* Haiku System Class
*
* PHP version 5
*
* @category PHP
* @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 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
*/
/**
* Haiku sysinfo class
* get all the required information from Haiku system
*
* @category PHP
* @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 version 2, or (at your option) any later version
* @version Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
class Haiku extends OS
{
/**
* get the cpu information
*
* @return void
*/
protected function _cpuinfo()
{
 
if (CommonFunctions::executeProgram('sysinfo', '-cpu', $bufr, PSI_DEBUG)) {
$cpus = preg_split("/\nCPU #\d+/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
$cpuspeed = "";
foreach ($cpus as $cpu) {
if (preg_match("/^.*running at (\d+)MHz/", $cpu, $ar_buf)) {
$cpuspeed = $ar_buf[1];
} elseif (preg_match("/^: \"(.*)\"/", $cpu, $ar_buf)) {
$dev = new CpuDevice();
$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()));
} 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);
}
$this->sys->setCpus($dev);
}
}
}
}
 
/**
* PCI devices
* get the pci device information
*
* @return void
*/
protected function _pci()
{
if (CommonFunctions::executeProgram('listdev', '', $bufr, PSI_DEBUG)) {
// $devices = preg_split("/^device |\ndevice /", $bufr, -1, PREG_SPLIT_NO_EMPTY);
$devices = preg_split("/^device /m", $bufr, -1, PREG_SPLIT_NO_EMPTY);
foreach ($devices as $device) {
$ar_buf = preg_split("/\n/", $device);
if (count($ar_buf) >= 3) {
if (preg_match("/^([^\(\[\n]*)/", $device, $ar_buf2)) {
if (preg_match("/^[^\(]*\((.*)\)/", $device, $ar_buf3)) {
$ar_buf2[1] = $ar_buf3[1];
}
$name = trim($ar_buf2[1]).": ";
 
if (preg_match("/^\s+vendor\s+[0-9a-fA-F]{4}:\s+(.*)/", $ar_buf[1], $ar_buf3)) {
$name .=$ar_buf3[1]." ";
}
if (preg_match("/^\s+device\s+[0-9a-fA-F]{4}:\s+(.*)/", $ar_buf[2], $ar_buf3)) {
$name .=$ar_buf3[1]." ";
}
$dev = new HWDevice();
$dev->setName(trim($name));
$this->sys->setPciDevices($dev);
}
}
}
}
}
 
/**
* USB devices
* get the usb device information
*
* @return void
*/
protected function _usb()
{
if (CommonFunctions::executeProgram('listusb', '', $bufr, PSI_DEBUG)) {
$devices = preg_split("/\n/", $bufr);
foreach ($devices as $device) {
if (preg_match("/^\S+\s+\S+\s+\"(.*)\"\s+\"(.*)\"/", $device, $ar_buf)) {
$dev = new HWDevice();
$dev->setName(trim($ar_buf[1]." ".$ar_buf[2]));
$this->sys->setUSBDevices($dev);
}
}
}
}
 
/**
* Haiku Version
*
* @return void
*/
private function _kernel()
{
if (CommonFunctions::executeProgram('uname', '-rvm', $ret)) {
$this->sys->setKernel($ret);
}
}
 
/**
* Distribution
*
* @return void
*/
protected function _distro()
{
if (CommonFunctions::executeProgram('uname', '-sr', $ret))
$this->sys->setDistribution($ret);
else
$this->sys->setDistribution('Haiku');
 
$this->sys->setDistributionIcon('Haiku.png');
}
 
/**
* UpTime
* time the system is running
*
* @return void
*/
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)) {
$min = $ar_buf[3];
$hours = $ar_buf[2];
$days = $ar_buf[1];
$this->sys->setUptime($days * 86400 + $hours * 3600 + $min * 60);
}
}
}
 
/**
* Processor Load
* optionally create a loadbar
*
* @return void
*/
private function _loadavg()
{
if (CommonFunctions::executeProgram('top', '-n 1 -i 1', $buf)) {
if (preg_match("/\s+(\S+)%\s+TOTAL\s+\(\S+%\s+idle time/", $buf, $ar_buf)) {
$this->sys->setLoad($ar_buf[1]);
if (PSI_LOAD_BAR) {
$this->sys->setLoadPercent(round($ar_buf[1]));
}
}
}
}
 
/**
* Number of Users
*
* @return void
*/
protected function _users()
{
$this->sys->setUsers(1);
}
 
/**
* Virtual Host Name
*
* @return void
*/
private function _hostname()
{
if (PSI_USE_VHOST === true) {
if (CommonFunctions::readenv('SERVER_NAME', $hnm)) $this->sys->setHostname($hnm);
} else {
if (CommonFunctions::executeProgram('uname', '-n', $result, PSI_DEBUG)) {
$ip = gethostbyname($result);
if ($ip != $result) {
$this->sys->setHostname(gethostbyaddr($ip));
}
}
}
}
 
/**
* Physical memory information and Swap Space information
*
* @return void
*/
private function _memory()
{
if (CommonFunctions::executeProgram('sysinfo', '-mem', $bufr, PSI_DEBUG)) {
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->setMemUsed($ar_buf[2]);
}
}
if (CommonFunctions::executeProgram('vmstat', '', $bufr, PSI_DEBUG)) {
if (preg_match("/max swap space:\s+(.*)\nfree swap space:\s+(.*)\n/", $bufr, $ar_buf)) {
if ($ar_buf[1]>0) {
$dev = new DiskDevice();
$dev->setMountPoint("/boot/common/var/swap");
$dev->setName("SWAP");
$dev->setTotal($ar_buf[1]);
$dev->setFree($ar_buf[2]);
$dev->setUSed($ar_buf[1]-$ar_buf[2]);
$this->sys->setSwapDevices($dev);
}
}
}
}
 
/**
* filesystem information
*
* @return void
*/
private function _filesystems()
{
if (CommonFunctions::executeProgram('df', '-b', $df, PSI_DEBUG)) {
$df = preg_split("/\n/", $df, -1, PREG_SPLIT_NO_EMPTY);
foreach ($df as $df_line) {
$ar_buf = preg_split("/\s+/", $df_line);
if ((substr($df_line, 0, 1) == "/") && (count($ar_buf) == 6)) {
$dev = new DiskDevice();
$dev->setMountPoint($ar_buf[0]);
$dev->setName($ar_buf[5]);
$dev->setFsType($ar_buf[1]);
$dev->setOptions($ar_buf[4]);
$dev->setTotal($ar_buf[2] * 1024);
$dev->setFree($ar_buf[3] * 1024);
$dev->setUsed($dev->getTotal() - $dev->getFree());
$this->sys->setDiskDevices($dev);
}
}
}
}
 
/**
* network information
*
* @return void
*/
private function _network()
{
if (CommonFunctions::executeProgram('ifconfig', '', $bufr, PSI_DEBUG)) {
$lines = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
$was = false;
$errors = 0;
$drops = 0;
$dev = null;
foreach ($lines as $line) {
if (preg_match("/^(\S+)/", $line, $ar_buf)) {
if ($was) {
$dev->setErrors($errors);
$dev->setDrops($drops);
$this->sys->setNetDevices($dev);
}
$errors = 0;
$drops = 0;
$dev = new NetDevice();
$dev->setName($ar_buf[1]);
$was = true;
} else {
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];
$dev->setRxBytes($ar_buf2[2]);
} elseif (preg_match('/\sTransmit:\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];
$dev->setTxBytes($ar_buf2[2]);
}
 
if (defined('PSI_SHOW_NETWORK_INFOS') && (PSI_SHOW_NETWORK_INFOS)) {
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 ($was) {
$dev->setErrors($errors);
$dev->setDrops($drops);
$this->sys->setNetDevices($dev);
}
}
}
 
/**
* Processes
*
* @return void
*/
protected function _processes()
{
if (CommonFunctions::executeProgram('ps', '', $bufr, PSI_DEBUG)) {
$lines = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
$processes['*'] = 0;
foreach ($lines as $line) {
if (preg_match("/^(kernel_team|\/)/", $line, $ar_buf)) {
$processes['*']++;
}
}
if ($processes['*'] > 0) {
$processes[' '] = $processes['*'];
$this->sys->setProcesses($processes);
}
}
}
 
/**
* get the information
*
* @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");
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==='network') {
$this->_network();
}
if (!$this->blockname || $this->blockname==='memory') {
$this->_memory();
}
if (!$this->blockname || $this->blockname==='filesystem') {
$this->_filesystems();
}
}
}
/web/acc/phpsysinfo/includes/os/class.Linux.inc.php
1,553 → 1,1693
<?php
// phpSysInfo - A PHP System Information Script
// http://phpsysinfo.sourceforge.net/
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
// $Id: class.Linux.inc.php,v 1.88 2007/02/25 20:50:52 bigmichi1 Exp $
<?php
/**
* Linux System Class
*
* PHP version 5
*
* @category PHP
* @package PSI Linux 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 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
*/
/**
* Linux sysinfo class
* get all the required information from Linux system
*
* @category PHP
* @package PSI Linux 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 version 2, or (at your option) any later version
* @version Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
class Linux extends OS
{
/**
* Assoc array of all CPUs loads.
*/
protected $_cpu_loads;
 
if (!defined('IN_PHPSYSINFO')) {
die("No Hacking");
}
/**
* Machine
*
* @return void
*/
private function _machine()
{
$machine = "";
if ((CommonFunctions::rfts('/var/log/dmesg', $result, 0, 4096, false)
&& preg_match('/^[\s\[\]\.\d]*DMI:\s*(.*)/m', $result, $ar_buf))
||(CommonFunctions::executeProgram('dmesg', '', $result, false)
&& preg_match('/^[\s\[\]\.\d]*DMI:\s*(.*)/m', $result, $ar_buf))) {
$machine = trim($ar_buf[1]);
} else { //data from /sys/devices/virtual/dmi/id/
$product = "";
$board = "";
$bios = "";
if (CommonFunctions::rfts('/sys/devices/virtual/dmi/id/board_vendor', $buf, 1, 4096, false) && (trim($buf)!="")) {
$machine = trim($buf);
}
if (CommonFunctions::rfts('/sys/devices/virtual/dmi/id/product_name', $buf, 1, 4096, false) && (trim($buf)!="")) {
$product = trim($buf);
}
if (CommonFunctions::rfts('/sys/devices/virtual/dmi/id/board_name', $buf, 1, 4096, false) && (trim($buf)!="")) {
$board = trim($buf);
}
if (CommonFunctions::rfts('/sys/devices/virtual/dmi/id/bios_version', $buf, 1, 4096, false) && (trim($buf)!="")) {
$bios = trim($buf);
}
if (CommonFunctions::rfts('/sys/devices/virtual/dmi/id/bios_date', $buf, 1, 4096, false) && (trim($buf)!="")) {
$bios = trim($bios." ".trim($buf));
}
if ($product != "") {
$machine .= " ".$product;
}
if ($board != "") {
$machine .= "/".$board;
}
if ($bios != "") {
$machine .= ", BIOS ".$bios;
}
}
 
require_once(APP_ROOT . '/includes/os/class.BSD.common.inc.php');
if ($machine != "") {
$machine = trim(preg_replace("/^\/,?/", "", preg_replace("/ ?(To be filled by O\.E\.M\.|System manufacturer|System Product Name|Not Specified) ?/i", "", $machine)));
}
 
class sysinfo {
var $inifile = "distros.ini";
var $icon = "unknown.png";
var $distro = "unknown";
var $parser;
// get the distro name and icon when create the sysinfo object
function sysinfo() {
$this->parser = new Parser();
$this->parser->df_param = 'P';
$list = @parse_ini_file(APP_ROOT . "/" . $this->inifile, true);
if (!$list) {
return;
}
$distro_info = execute_program('lsb_release','-a 2> /dev/null', false); // We have the '2> /dev/null' because Ubuntu gives an error on this command which causes the distro to be unknown
if ( $distro_info != 'ERROR') {
$distro_tmp = explode("\n",$distro_info);
foreach( $distro_tmp as $info ) {
$info_tmp = explode(':', $info, 2);
$distro[ $info_tmp[0] ] = trim($info_tmp[1]);
}
if( !isset( $list[$distro['Distributor ID']] ) ){
return;
}
$this->icon = isset($list[$distro['Distributor ID']]["Image"]) ? $list[$distro['Distributor ID']]["Image"] : $this->icon;
$this->distro = $distro['Description'];
} else { // Fall back in case 'lsb_release' does not exist ;)
foreach ($list as $section => $distribution) {
if (!isset($distribution["Files"])) {
continue;
} else {
foreach (explode(";", $distribution["Files"]) as $filename) {
if (file_exists($filename)) {
$buf = rfts( $filename );
$this->icon = isset($distribution["Image"]) ? $distribution["Image"] : $this->icon;
$this->distro = isset($distribution["Name"]) ? $distribution["Name"] . " " . trim($buf) : trim($buf);
break 2;
}
}
}
}
}
}
// get our apache SERVER_NAME or vhost
function vhostname () {
if (! ($result = getenv('SERVER_NAME'))) {
$result = 'N.A.';
}
return $result;
}
// get the IP address of our vhost name
function vip_addr () {
return gethostbyname($this->vhostname());
}
// get our canonical hostname
function chostname () {
$result = rfts( '/proc/sys/kernel/hostname', 1 );
if ( $result == "ERROR" ) {
$result = "N.A.";
if (CommonFunctions::fileexists($filename="/etc/config/uLinux.conf") // QNAP detection
&& CommonFunctions::rfts($filename, $buf, 0, 4096, false)
&& preg_match("/^Rsync\sModel\s*=\s*QNAP/m", $buf)
&& CommonFunctions::fileexists($filename="/etc/platform.conf") // Platform detection
&& CommonFunctions::rfts($filename, $buf, 0, 4096, false)
&& preg_match("/^DISPLAY_NAME\s*=\s*(\S+)/m", $buf, $mach_buf) && ($mach_buf[1]!=="")) {
if ($machine != "") {
$machine = "QNAP ".$mach_buf[1].' - '.$machine;
} else {
$machine = "QNAP ".$mach_buf[1];
}
}
 
if ($machine != "") {
$this->sys->setMachine($machine);
}
}
//else {
// $result = gethostbyaddr( gethostbyname( trim( $result ) ) );
//}
return $result;
}
// get the IP address of our canonical hostname
function ip_addr () {
if (!($result = getenv('SERVER_ADDR'))) {
$result = gethostbyname($this->chostname());
}
return $result;
}
 
function kernel () {
$buf = rfts( '/proc/version', 1 );
if ( $buf == "ERROR" ) {
$result = "N.A.";
} else {
if (preg_match('/version (.*?) /', $buf, $ar_buf)) {
$result = $ar_buf[1];
/**
* Hostname
*
* @return void
*/
protected function _hostname()
{
if (PSI_USE_VHOST === true) {
if (CommonFunctions::readenv('SERVER_NAME', $hnm)) $this->sys->setHostname($hnm);
} else {
if (CommonFunctions::rfts('/proc/sys/kernel/hostname', $result, 1, 4096, PSI_DEBUG && (PSI_OS != 'Android'))) {
$result = trim($result);
$ip = gethostbyname($result);
if ($ip != $result) {
$this->sys->setHostname(gethostbyaddr($ip));
}
} elseif (CommonFunctions::executeProgram('hostname', '', $ret)) {
$this->sys->setHostname($ret);
}
 
if (preg_match('/SMP/', $buf)) {
$result .= ' (SMP)';
}
}
}
return $result;
}
function uptime () {
$buf = rfts( '/proc/uptime', 1 );
$ar_buf = explode( ' ', $buf );
$result = trim( $ar_buf[0] );
}
}
 
return $result;
}
/**
* Kernel Version
*
* @return void
*/
private function _kernel()
{
$result = "";
if (CommonFunctions::executeProgram($uname="uptrack-uname", '-r', $strBuf, false) || // show effective kernel if ksplice uptrack is installed
CommonFunctions::executeProgram($uname="uname", '-r', $strBuf, PSI_DEBUG)) {
$result = $strBuf;
if (CommonFunctions::executeProgram($uname, '-v', $strBuf, PSI_DEBUG)) {
if (preg_match('/SMP/', $strBuf)) {
$result .= ' (SMP)';
}
}
if (CommonFunctions::executeProgram($uname, '-m', $strBuf, PSI_DEBUG)) {
$result .= ' '.$strBuf;
}
} 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)';
}
}
if ($result != "") {
if (CommonFunctions::rfts('/proc/self/cgroup', $strBuf2, 0, 4096, false)) {
if (preg_match('/:\/lxc\//m', $strBuf2)) {
$result .= ' [lxc]';
} elseif (preg_match('/:\/docker\//m', $strBuf2)) {
$result .= ' [docker]';
} elseif (preg_match('/:\/system\.slice\/docker\-/m', $strBuf2)) {
$result .= ' [docker]';
}
}
if (CommonFunctions::rfts('/proc/version', $strBuf2, 1, 4096, false)
&& preg_match('/^Linux version [\d\.-]+-Microsoft/', $strBuf2)) {
$result .= ' [lxss]';
}
$this->sys->setKernel($result);
}
}
 
function users () {
$strResult = 0;
$strBuf = execute_program('who', '-q');
if( $strBuf != "ERROR" ) {
$arrWho = explode( '=', $strBuf );
$strResult = $arrWho[1];
}
return $strResult;
}
function loadavg ($bar = false) {
$buf = rfts( '/proc/loadavg' );
if( $buf == "ERROR" ) {
$results['avg'] = array('N.A.', 'N.A.', 'N.A.');
} else {
$results['avg'] = preg_split("/\s/", $buf, 4);
unset($results['avg'][3]); // don't need the extra values, only first three
}
if ($bar) {
$buf = rfts( '/proc/stat', 1 );
if( $buf != "ERROR" ) {
sscanf($buf, "%*s %Ld %Ld %Ld %Ld", $ab, $ac, $ad, $ae);
// Find out the CPU load
// user + sys = load
// total = total
$load = $ab + $ac + $ad; // cpu.user + cpu.sys
$total = $ab + $ac + $ad + $ae; // cpu.total
/**
* UpTime
* time the system is running
*
* @return void
*/
protected function _uptime()
{
if (CommonFunctions::rfts('/proc/uptime', $buf, 1, 4096, PSI_OS != 'Android')) {
$ar_buf = preg_split('/ /', $buf);
$this->sys->setUptime(trim($ar_buf[0]));
} elseif (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+) day[s]?,[ ]+(\d+) min,/", $buf, $ar_buf)) {
$min = $ar_buf[2];
$days = $ar_buf[1];
$this->sys->setUptime($days * 86400 + $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+) min,/", $buf, $ar_buf)) {
$min = $ar_buf[1];
$this->sys->setUptime($min * 60);
}
}
}
 
// we need a second value, wait 1 second befor getting (< 1 second no good value will occour)
sleep(1);
$buf = rfts( '/proc/stat', 1 );
sscanf($buf, "%*s %Ld %Ld %Ld %Ld", $ab, $ac, $ad, $ae);
$load2 = $ab + $ac + $ad;
$total2 = $ab + $ac + $ad + $ae;
$results['cpupercent'] = (100*($load2 - $load)) / ($total2 - $total);
}
/**
* Processor Load
* optionally create a loadbar
*
* @return void
*/
protected function _loadavg()
{
if (CommonFunctions::rfts('/proc/loadavg', $buf, 1, 4096, PSI_OS != 'Android')) {
$result = preg_split("/\s/", $buf, 4);
// don't need the extra values, only first three
unset($result[3]);
$this->sys->setLoad(implode(' ', $result));
} elseif (CommonFunctions::executeProgram('uptime', '', $buf) && preg_match("/load average: (.*), (.*), (.*)$/", $buf, $ar_buf)) {
$this->sys->setLoad($ar_buf[1].' '.$ar_buf[2].' '.$ar_buf[3]);
}
if (PSI_LOAD_BAR) {
$this->sys->setLoadPercent($this->_parseProcStat('cpu'));
}
}
return $results;
}
 
function cpu_info () {
$bufr = rfts( '/proc/cpuinfo' );
$results = array("cpus" => 0);
if ( $bufr != "ERROR" ) {
$bufe = explode("\n", $bufr);
$results = array('cpus' => 0, 'bogomips' => 0);
$ar_buf = array();
foreach( $bufe as $buf ) {
$arrBuff = preg_split('/\s+:\s+/', trim($buf));
if( count( $arrBuff ) == 2 ) {
$key = $arrBuff[0];
$value = $arrBuff[1];
// All of the tags here are highly architecture dependant.
// the only way I could reconstruct them for machines I don't
// have is to browse the kernel source. So if your arch isn't
// supported, tell me you want it written in.
switch ($key) {
case 'model name':
$results['model'] = $value;
break;
case 'cpu MHz':
$results['cpuspeed'] = sprintf('%.2f', $value);
break;
case 'cycle frequency [Hz]': // For Alpha arch - 2.2.x
$results['cpuspeed'] = sprintf('%.2f', $value / 1000000);
break;
case 'clock': // For PPC arch (damn borked POS)
$results['cpuspeed'] = sprintf('%.2f', $value);
break;
case 'cpu': // For PPC arch (damn borked POS)
$results['model'] = $value;
break;
case 'L2 cache': // More for PPC
$results['cache'] = $value;
break;
case 'revision': // For PPC arch (damn borked POS)
$results['model'] .= ' ( rev: ' . $value . ')';
break;
case 'cpu model': // For Alpha arch - 2.2.x
$results['model'] .= ' (' . $value . ')';
break;
case 'cache size':
$results['cache'] = $value;
break;
case 'bogomips':
$results['bogomips'] += $value;
break;
case 'BogoMIPS': // For alpha arch - 2.2.x
$results['bogomips'] += $value;
break;
case 'BogoMips': // For sparc arch
$results['bogomips'] += $value;
break;
case 'cpus detected': // For Alpha arch - 2.2.x
$results['cpus'] += $value;
break;
case 'system type': // Alpha arch - 2.2.x
$results['model'] .= ', ' . $value . ' ';
break;
case 'platform string': // Alpha arch - 2.2.x
$results['model'] .= ' (' . $value . ')';
break;
case 'processor':
$results['cpus'] += 1;
break;
case 'Cpu0ClkTck': // Linux sparc64
$results['cpuspeed'] = sprintf('%.2f', hexdec($value) / 1000000);
break;
case 'Cpu0Bogo': // Linux sparc64 & sparc32
$results['bogomips'] = $value;
break;
case 'ncpus probed': // Linux sparc64 & sparc32
$results['cpus'] = $value;
break;
}
}
}
// sparc64 specific code follows
// This adds the ability to display the cache that a CPU has
// Originally made by Sven Blumenstein <bazik@gentoo.org> in 2004
// Modified by Tom Weustink <freshy98@gmx.net> in 2004
$sparclist = array('SUNW,UltraSPARC@0,0', 'SUNW,UltraSPARC-II@0,0', 'SUNW,UltraSPARC@1c,0', 'SUNW,UltraSPARC-IIi@1c,0', 'SUNW,UltraSPARC-II@1c,0', 'SUNW,UltraSPARC-IIe@0,0');
foreach ($sparclist as $name) {
$buf = rfts( '/proc/openprom/' . $name . '/ecache-size',1 , 32, false );
if( $buf != "ERROR" ) {
$results['cache'] = base_convert($buf, 16, 10)/1024 . ' KB';
}
}
// sparc64 specific code ends
// XScale detection code
if ( $results['cpus'] == 0 ) {
foreach( $bufe as $buf ) {
$fields = preg_split('/\s*:\s*/', trim($buf), 2);
if (sizeof($fields) == 2) {
list($key, $value) = $fields;
switch($key) {
case 'Processor':
$results['cpus'] += 1;
$results['model'] = $value;
break;
case 'BogoMIPS': //BogoMIPS are not BogoMIPS on this CPU, it's the speed, no BogoMIPS available
$results['cpuspeed'] = $value;
break;
case 'I size':
$results['cache'] = $value;
break;
case 'D size':
$results['cache'] += $value;
break;
}
}
}
$results['cache'] = $results['cache'] / 1024 . " KB";
}
}
$keys = array_keys($results);
$keys2be = array('model', 'cpuspeed', 'cache', 'bogomips', 'cpus');
while ($ar_buf = each($keys2be)) {
if (! in_array($ar_buf[1], $keys)) {
$results[$ar_buf[1]] = 'N.A.';
}
}
$buf = rfts( '/proc/acpi/thermal_zone/THRM/temperature', 1, 4096, false );
if ( $buf != "ERROR" ) {
$results['temp'] = substr( $buf, 25, 2 );
}
return $results;
}
/**
* 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 Integer
*/
protected function _parseProcStat($cpuline)
{
if (is_null($this->_cpu_loads)) {
$this->_cpu_loads = array();
 
function pci () {
$arrResults = array();
$booDevice = false;
if( ! $arrResults = $this->parser->parse_lspci() ) {
$strBuf = rfts( '/proc/pci', 0, 4096, false );
if( $strBuf != "ERROR" ) {
$arrBuf = explode( "\n", $strBuf );
foreach( $arrBuf as $strLine ) {
if( preg_match( '/Bus/', $strLine ) ) {
$booDevice = true;
continue;
}
if( $booDevice ) {
list( $strKey, $strValue ) = explode( ': ', $strLine, 2 );
if( ! preg_match( '/bridge/i', $strKey ) && ! preg_match( '/USB/i ', $strKey ) ) {
$arrResults[] = preg_replace( '/\([^\)]+\)\.$/', '', trim( $strValue ) );
}
$booDevice = false;
}
}
asort( $arrResults );
}
}
return $arrResults;
}
$cpu_tmp = array();
if (CommonFunctions::rfts('/proc/stat', $buf)) {
if (preg_match_all('/^(cpu[0-9]*) (.*)/m', $buf, $matches, PREG_SET_ORDER)) {
foreach ($matches as $line) {
$cpu = $line[1];
$buf2 = $line[2];
 
function ide () {
$results = array();
$bufd = gdc( '/proc/ide', false );
$cpu_tmp[$cpu] = array();
 
foreach( $bufd as $file ) {
if (preg_match('/^hd/', $file)) {
$results[$file] = array();
$buf = rfts("/proc/ide/" . $file . "/media", 1 );
if ( $buf != "ERROR" ) {
$results[$file]['media'] = trim($buf);
if ($results[$file]['media'] == 'disk') {
$results[$file]['media'] = 'Hard Disk';
$buf = rfts( "/proc/ide/" . $file . "/capacity", 1, 4096, false);
if( $buf == "ERROR" ) {
$buf = rfts( "/sys/block/" . $file . "/size", 1, 4096, false);
}
if ( $buf != "ERROR" ) {
$results[$file]['capacity'] = trim( $buf );
}
} elseif ($results[$file]['media'] == 'cdrom') {
$results[$file]['media'] = 'CD-ROM';
unset($results[$file]['capacity']);
}
$ab = 0;
$ac = 0;
$ad = 0;
$ae = 0;
sscanf($buf2, "%Ld %Ld %Ld %Ld", $ab, $ac, $ad, $ae);
$cpu_tmp[$cpu]['load'] = $ab + $ac + $ad; // cpu.user + cpu.sys
$cpu_tmp[$cpu]['total'] = $ab + $ac + $ad + $ae; // cpu.total
}
}
 
// we need a second value, wait 1 second befor getting (< 1 second no good value will occour)
sleep(1);
 
if (CommonFunctions::rfts('/proc/stat', $buf)) {
if (preg_match_all('/^(cpu[0-9]*) (.*)/m', $buf, $matches, PREG_SET_ORDER)) {
foreach ($matches as $line) {
$cpu = $line[1];
if (isset($cpu_tmp[$cpu])) {
$buf2 = $line[2];
 
$ab = 0;
$ac = 0;
$ad = 0;
$ae = 0;
sscanf($buf2, "%Ld %Ld %Ld %Ld", $ab, $ac, $ad, $ae);
$load2 = $ab + $ac + $ad; // cpu.user + cpu.sys
$total2 = $ab + $ac + $ad + $ae; // cpu.total
$total = $cpu_tmp[$cpu]['total'];
$load = $cpu_tmp[$cpu]['load'];
$this->_cpu_loads[$cpu] = 0;
if ($total > 0 && $total2 > 0 && $load > 0 && $load2 > 0 && $total2 != $total && $load2 != $load) {
$this->_cpu_loads[$cpu] = (100 * ($load2 - $load)) / ($total2 - $total);
}
}
}
}
}
}
}
 
if (isset($this->_cpu_loads[$cpuline])) {
return $this->_cpu_loads[$cpuline];
} else {
unset($results[$file]);
}
return 0;
}
}
 
$buf = rfts( "/proc/ide/" . $file . "/model", 1 );
if ( $buf != "ERROR" ) {
$results[$file]['model'] = trim( $buf );
if (preg_match('/WDC/', $results[$file]['model'])) {
$results[$file]['manufacture'] = 'Western Digital';
} elseif (preg_match('/IBM/', $results[$file]['model'])) {
$results[$file]['manufacture'] = 'IBM';
} elseif (preg_match('/FUJITSU/', $results[$file]['model'])) {
$results[$file]['manufacture'] = 'Fujitsu';
} else {
$results[$file]['manufacture'] = 'Unknown';
}
}
}
}
/**
* CPU information
* All of the tags here are highly architecture dependant.
*
* @return void
*/
protected function _cpuinfo()
{
if (CommonFunctions::rfts('/proc/cpuinfo', $bufr)) {
$cpulist = null;
$raslist = null;
 
asort($results);
return $results;
}
// sparc
if (preg_match('/\nCpu(\d+)Bogo\s*:/i', $bufr)) {
$bufr = preg_replace('/\nCpu(\d+)ClkTck\s*:/i', "\nCpu0ClkTck:", preg_replace('/\nCpu(\d+)Bogo\s*:/i', "\n\nprocessor: $1\nCpu0Bogo:", $bufr));
} else {
$bufr = preg_replace('/\nCpu(\d+)ClkTck\s*:/i', "\n\nprocessor: $1\nCpu0ClkTck:", $bufr);
}
 
function scsi () {
$results = array();
$dev_vendor = '';
$dev_model = '';
$dev_rev = '';
$dev_type = '';
$s = 1;
$get_type = 0;
if (preg_match('/\nprocessor\s*:\s*\d+\r?\nprocessor\s*:\s*\d+/', $bufr)) {
$bufr = preg_replace('/^(processor\s*:\s*\d+)\r?$/m', "$1\n", $bufr);
}
 
$bufr = execute_program('lsscsi', '-c', false);
if( $bufr == "ERROR" ) {
$bufr = rfts( '/proc/scsi/scsi', 0, 4096, false);
// IBM/S390
$bufr = preg_replace('/\ncpu number\s*:\s*(\d+)\r?\ncpu MHz dynamic\s*:\s*(\d+)/m', "\nprocessor:$1\nclock:$2", $bufr);
 
$processors = preg_split('/\s?\n\s?\n/', trim($bufr));
 
//first stage
$_arch = null;
$_impl = null;
$_part = null;
$_hard = null;
$_revi = null;
$_cpus = null;
$_buss = null;
$_bogo = null;
$_vend = null;
$procname = null;
foreach ($processors as $processor) if (!preg_match('/^\s*processor\s*:/mi', $processor)) {
$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) && (($arrBuff1 = trim($arrBuff[1])) !== '')) {
switch (strtolower($arrBuff[0])) {
case 'cpu architecture':
$_arch = $arrBuff1;
break;
case 'cpu implementer':
$_impl = $arrBuff1;
break;
case 'cpu part':
$_part = $arrBuff1;
break;
case 'hardware':
$_hard = $arrBuff1;
break;
case 'revision':
$_revi = $arrBuff1;
break;
case 'cpu frequency':
if (preg_match('/^(\d+)\s+Hz/i', $arrBuff1, $bufr2)) {
$_cpus = round($bufr2[1]/1000000);
}
break;
case 'system bus frequency':
if (preg_match('/^(\d+)\s+Hz/i', $arrBuff1, $bufr2)) {
$_buss = round($bufr2[1]/1000000);
}
break;
case 'bogomips per cpu':
$_bogo = round($arrBuff1);
break;
case 'vendor_id':
$_vend = $arrBuff1;
case 'cpu':
$procname = $arrBuff1;
break;
}
}
}
}
 
//second stage
$cpucount = 0;
$speedset = false;
foreach ($processors as $processor) if (preg_match('/^\s*processor\s*:/mi', $processor)) {
$proc = null;
$arch = null;
$impl = null;
$part = null;
$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) && (($arrBuff1 = trim($arrBuff[1])) !== '')) {
switch (strtolower($arrBuff[0])) {
case 'processor':
$proc = $arrBuff1;
if (is_numeric($proc)) {
if (strlen($procname)>0) {
$dev->setModel($procname);
}
} else {
$procname = $proc;
$dev->setModel($procname);
}
break;
case 'model name':
case 'cpu model':
case 'cpu type':
case 'cpu':
$dev->setModel($arrBuff1);
break;
case 'cpu mhz':
case 'clock':
if ($arrBuff1 > 0) { //openSUSE fix
$dev->setCpuSpeed($arrBuff1);
$speedset = true;
}
break;
case 'cpu mhz static':
if ($arrBuff1 > 0) { //openSUSE fix
$dev->setCpuSpeedMax($arrBuff1);
}
break;
case 'cycle frequency [hz]':
$dev->setCpuSpeed($arrBuff1 / 1000000);
$speedset = true;
break;
case 'cpu0clktck':
$dev->setCpuSpeed(hexdec($arrBuff1) / 1000000); // Linux sparc64
$speedset = true;
break;
case 'l3 cache':
case 'cache size':
$dev->setCache(trim(preg_replace("/[a-zA-Z]/", "", $arrBuff1)) * 1024);
break;
case 'initial bogomips':
case 'bogomips':
case 'cpu0bogo':
$dev->setBogomips(round($arrBuff1));
break;
case 'flags':
if (preg_match("/ vmx/", $arrBuff1)) {
$dev->setVirt("vmx");
} elseif (preg_match("/ svm/", $arrBuff1)) {
$dev->setVirt("svm");
} elseif (preg_match("/ hypervisor/", $arrBuff1)) {
$dev->setVirt("hypervisor");
}
break;
case 'i size':
case 'd size':
if ($dev->getCache() === null) {
$dev->setCache($arrBuff1 * 1024);
} else {
$dev->setCache($dev->getCache() + ($arrBuff1 * 1024));
}
break;
case 'cpu architecture':
$arch = $arrBuff1;
break;
case 'cpu implementer':
$impl = $arrBuff1;
break;
case 'cpu part':
$part = $arrBuff1;
break;
case 'vendor_id':
$dev->setVendorId($arrBuff1);
break;
}
}
}
if ($arch === null) $arch = $_arch;
if ($impl === null) $impl = $_impl;
if ($part === null) $part = $_part;
 
// sparc64 specific code follows
// This adds the ability to display the cache that a CPU has
// Originally made by Sven Blumenstein <bazik@gentoo.org> in 2004
// Modified by Tom Weustink <freshy98@gmx.net> in 2004
$sparclist = array('SUNW,UltraSPARC@0,0', 'SUNW,UltraSPARC-II@0,0', 'SUNW,UltraSPARC@1c,0', 'SUNW,UltraSPARC-IIi@1c,0', 'SUNW,UltraSPARC-II@1c,0', 'SUNW,UltraSPARC-IIe@0,0');
foreach ($sparclist as $name) {
if (CommonFunctions::rfts('/proc/openprom/'.$name.'/ecache-size', $buf, 1, 32, false)) {
$dev->setCache(base_convert(trim($buf), 16, 10));
}
}
// sparc64 specific code ends
 
// XScale detection code
if (($arch === "5TE") && ($dev->getBogomips() != null)) {
$dev->setCpuSpeed($dev->getBogomips()); //BogoMIPS are not BogoMIPS on this CPU, it's the speed
$speedset = true;
$dev->setBogomips(null); // no BogoMIPS available, unset previously set BogoMIPS
}
 
if (($dev->getBusSpeed() == 0) && ($_buss !== null)) {
$dev->setBusSpeed($_buss);
}
if (($dev->getCpuSpeed() == 0) && ($_cpus !== null)) {
$dev->setCpuSpeed($_cpus);
$speedset = true;
}
if (($dev->getBogomips() == 0) && ($_bogo !== null)) {
$dev->setBogomips($_bogo);
}
if (($dev->getVendorId() === null) && ($_vend !== null)) {
$dev->setVendorId($_vend);
}
 
if ($proc != null) {
if (!is_numeric($proc)) {
$proc = 0;
}
// variable speed processors specific code follows
if (CommonFunctions::rfts('/sys/devices/system/cpu/cpu'.$proc.'/cpufreq/cpuinfo_cur_freq', $buf, 1, 4096, false)) {
$dev->setCpuSpeed(trim($buf) / 1000);
$speedset = true;
} elseif (CommonFunctions::rfts('/sys/devices/system/cpu/cpu'.$proc.'/cpufreq/scaling_cur_freq', $buf, 1, 4096, false)) {
$dev->setCpuSpeed(trim($buf) / 1000);
$speedset = true;
}
if (CommonFunctions::rfts('/sys/devices/system/cpu/cpu'.$proc.'/cpufreq/cpuinfo_max_freq', $buf, 1, 4096, false)) {
$dev->setCpuSpeedMax(trim($buf) / 1000);
}
if (CommonFunctions::rfts('/sys/devices/system/cpu/cpu'.$proc.'/cpufreq/cpuinfo_min_freq', $buf, 1, 4096, false)) {
$dev->setCpuSpeedMin(trim($buf) / 1000);
}
// variable speed processors specific code ends
if (PSI_LOAD_BAR) {
$dev->setLoad($this->_parseProcStat('cpu'.$proc));
}
/*
if (CommonFunctions::rfts('/proc/acpi/thermal_zone/THRM/temperature', $buf, 1, 4096, false)
&& preg_match("/(\S+)\sC$/", $buf, $value)) {
$dev->setTemp(value[1]);
}
*/
if (($arch !== null) && ($impl !== null) && ($part !== null)) {
if (($impl === '0x41')
&& (($_hard === 'BCM2708') || ($_hard === 'BCM2835') || ($_hard === 'BCM2709') || ($_hard === 'BCM2836') || ($_hard === 'BCM2710') || ($_hard === 'BCM2837') || ($_hard === 'BCM2711') || ($_hard === 'BCM2838'))
&& ($_revi !== null)) { // Raspberry Pi detection (instead of 'cat /proc/device-tree/model')
if ($raslist === null) $raslist = @parse_ini_file(PSI_APP_ROOT."/data/raspberry.ini", true);
if ($raslist && !preg_match('/[^0-9a-f]/', $_revi)) {
if (($revidec = hexdec($_revi)) & 0x800000) {
if ($this->sys->getMachine() === '') {
$manufacturer = ($revidec >> 16) & 15;
if (isset($raslist['manufacturer'][$manufacturer])) {
$manuf = ' '.$raslist['manufacturer'][$manufacturer];
} else {
$manuf = '';
}
$model = ($revidec >> 4) & 255;
if (isset($raslist['model'][$model])) {
$this->sys->setMachine('Raspberry Pi '.$raslist['model'][$model].' (PCB 1.'.($revidec & 15).$manuf.')');
} else {
$this->sys->setMachine('Raspberry Pi (PCB 1.'.($revidec & 15).$manuf.')');
}
}
} else {
if ($this->sys->getMachine() === '') {
if (isset($raslist['old'][$revidec & 0x7fffff])) {
$this->sys->setMachine('Raspberry Pi '.$raslist['old'][$revidec & 0x7fffff]);
} else {
$this->sys->setMachine('Raspberry Pi');
}
}
}
}
} elseif (($_hard !== null) && ($this->sys->getMachine() === '')) { // other ARM hardware
$this->sys->setMachine($_hard);
}
if ($cpulist === null) $cpulist = @parse_ini_file(PSI_APP_ROOT."/data/cpus.ini", true);
if ($cpulist && (isset($cpulist['cpu'][$cpuimplpart = strtolower($impl.','.$part)]))) {
if (($cpumodel = $dev->getModel()) !== '') {
$dev->setModel($cpumodel.' - '.$cpulist['cpu'][$cpuimplpart]);
} else {
$dev->setModel($cpulist['cpu'][$cpuimplpart]);
}
}
} elseif (($_hard !== null) && ($this->sys->getMachine() === '')) { // other hardware
$this->sys->setMachine($_hard);
}
 
if ($dev->getModel() === "") {
$dev->setModel("unknown");
}
$cpucount++;
$this->sys->setCpus($dev);
}
}
 
$cpudevices = glob('/sys/devices/system/cpu/cpu*/uevent', GLOB_NOSORT);
if (is_array($cpudevices) && (($cpustopped = count($cpudevices)-$cpucount) > 0)) {
for (; $cpustopped > 0; $cpustopped--) {
$dev = new CpuDevice();
$dev->setModel("stopped");
if ($speedset) {
$dev->setCpuSpeed(-1);
}
$this->sys->setCpus($dev);
}
}
}
}
if ( $bufr != "ERROR" ) {
$bufe = explode("\n", $bufr);
foreach( $bufe as $buf ) {
if (preg_match('/Vendor/', $buf)) {
preg_match('/Vendor: (.*) Model: (.*) Rev: (.*)/i', $buf, $dev);
list($key, $value) = explode(': ', $buf, 2);
$dev_str = $value;
$get_type = true;
continue;
}
 
if ($get_type) {
preg_match('/Type:\s+(\S+)/i', $buf, $dev_type);
$results[$s]['model'] = "$dev[1] $dev[2] ($dev_type[1])";
$results[$s]['media'] = "Hard Disk";
$s++;
$get_type = false;
}
}
}
asort($results);
return $results;
}
/**
* PCI devices
*
* @return void
*/
private function _pci()
{
if ($arrResults = Parser::lspci()) {
foreach ($arrResults as $dev) {
$this->sys->setPciDevices($dev);
}
} elseif (CommonFunctions::rfts('/proc/pci', $strBuf, 0, 4096, false)) {
$booDevice = false;
$arrBuf = preg_split("/\n/", $strBuf, -1, PREG_SPLIT_NO_EMPTY);
foreach ($arrBuf as $strLine) {
if (preg_match('/^\s*Bus\s/', $strLine)) {
$booDevice = true;
continue;
}
if ($booDevice) {
$dev = new HWDevice();
$dev->setName(preg_replace('/\([^\)]+\)\.$/', '', trim($strLine)));
$this->sys->setPciDevices($dev);
/*
list($strKey, $strValue) = preg_split('/: /', $strLine, 2);
if (!preg_match('/bridge/i', $strKey) && !preg_match('/USB/i ', $strKey)) {
$dev = new HWDevice();
$dev->setName(preg_replace('/\([^\)]+\)\.$/', '', trim($strValue)));
$this->sys->setPciDevices($dev);
}
*/
$booDevice = false;
}
}
} else {
$pcidevices = glob('/sys/bus/pci/devices/*/uevent', GLOB_NOSORT);
if (is_array($pcidevices) && (($total = count($pcidevices)) > 0)) {
$buf = "";
for ($i = 0; $i < $total; $i++) {
if (CommonFunctions::rfts($pcidevices[$i], $buf, 0, 4096, false) && (trim($buf) != "")) {
$pcibuf = "";
if (preg_match("/^PCI_CLASS=(\S+)/m", trim($buf), $subbuf)) {
$pcibuf = "Class ".$subbuf[1].":";
}
if (preg_match("/^PCI_ID=(\S+)/m", trim($buf), $subbuf)) {
$pcibuf .= " Device ".$subbuf[1];
}
if (preg_match("/^DRIVER=(\S+)/m", trim($buf), $subbuf)) {
$pcibuf .= " Driver ".$subbuf[1];
}
$dev = new HWDevice();
if (trim($pcibuf) != "") {
$dev->setName(trim($pcibuf));
} else {
$dev->setName("unknown");
}
$this->sys->setPciDevices($dev);
}
}
}
}
}
 
function usb () {
$results = array();
$devnum = -1;
/**
* IDE devices
*
* @return void
*/
private function _ide()
{
$bufd = CommonFunctions::gdc('/proc/ide', false);
foreach ($bufd as $file) {
if (preg_match('/^hd/', $file)) {
$dev = new HWDevice();
$dev->setName(trim($file));
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) || CommonFunctions::rfts("/sys/block/".$file."/size", $buf, 1, 4096, false)) {
$dev->setCapacity(trim($buf) * 512);
}
}
}
if (CommonFunctions::rfts("/proc/ide/".$file."/model", $buf, 1)) {
$dev->setName($dev->getName().": ".trim($buf));
}
$this->sys->setIdeDevices($dev);
}
}
}
 
$bufr = execute_program('lsusb', '', false);
if( $bufr == "ERROR" ) {
$bufr = rfts( '/proc/bus/usb/devices', 0, 4096, false );
if ( $bufr != "ERROR" ) {
$bufe = explode("\n", $bufr);
foreach( $bufe as $buf ) {
if (preg_match('/^T/', $buf)) {
$devnum += 1;
$results[$devnum] = "";
} elseif (preg_match('/^S:/', $buf)) {
list($key, $value) = explode(': ', $buf, 2);
list($key, $value2) = explode('=', $value, 2);
if (trim($key) != "SerialNumber") {
$results[$devnum] .= " " . trim($value2);
$devstring = 0;
}
}
/**
* SCSI devices
*
* @return void
*/
private function _scsi()
{
$getline = 0;
$device = null;
$scsiid = null;
if (CommonFunctions::executeProgram('lsscsi', '-c', $bufr, PSI_DEBUG) || CommonFunctions::rfts('/proc/scsi/scsi', $bufr, 0, 4096, PSI_DEBUG)) {
$bufe = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
foreach ($bufe as $buf) {
if (preg_match('/Host: scsi(\d+) Channel: (\d+) Target: (\d+) Lun: (\d+)/i', $buf, $scsiids)
|| preg_match('/Host: scsi(\d+) Channel: (\d+) Id: (\d+) Lun: (\d+)/i', $buf, $scsiids)) {
$scsiid = $scsiids;
$getline = 1;
continue;
}
if ($getline == 1) {
preg_match('/Vendor: (.*) Model: (.*) Rev: (.*)/i', $buf, $devices);
$getline = 2;
$device = $devices;
continue;
}
if ($getline == 2) {
preg_match('/Type:\s+(\S+)/i', $buf, $dev_type);
 
$dev = new HWDevice();
$dev->setName($device[1].' '.$device[2].' ('.$dev_type[1].')');
 
if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS
&& ($dev_type[1]==='Direct-Access')) {
$sizelist = glob('/sys/bus/scsi/devices/'.intval($scsiid[1]).':'.intval($scsiid[2]).':'.intval($scsiid[3]).':'.intval($scsiid[4]).'/*/*/size', GLOB_NOSORT);
if (is_array($sizelist) && (($total = count($sizelist)) > 0)) {
$buf = "";
for ($i = 0; $i < $total; $i++) {
if (CommonFunctions::rfts($sizelist[$i], $buf, 1, 4096, false) && (($buf=trim($buf)) != "") && ($buf > 0)) {
$dev->setCapacity($buf * 512);
break;
}
}
}
}
$this->sys->setScsiDevices($dev);
$getline = 0;
}
}
}
} else {
$bufe = explode( "\n", $bufr );
foreach( $bufe as $buf ) {
$device = preg_split("/ /", $buf, 7);
if( isset( $device[6] ) && trim( $device[6] ) != "" ) {
$results[$devnum++] = trim( $device[6] );
}
}
}
}
return $results;
}
 
function sbus () {
$results = array();
$_results[0] = "";
// TODO. Nothing here yet. Move along.
$results = $_results;
return $results;
}
/**
* USB devices
*
* @return void
*/
protected function _usb()
{
$usbarray = array();
if (CommonFunctions::executeProgram('lsusb', (PSI_OS != 'Android')?'':'2>/dev/null', $bufr, PSI_DEBUG && (PSI_OS != 'Android'), 5) && ($bufr !== "")) {
$bufe = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
foreach ($bufe as $buf) {
$device = preg_split("/ /", $buf, 7);
if (((isset($device[6]) && trim($device[6]) != "")) ||
((isset($device[5]) && trim($device[5]) != ""))) {
$usbid = intval($device[1]).'-'.intval(trim($device[3],':')).' '.$device[5];
if ((isset($device[6]) && trim($device[6]) != "")) {
$usbarray[$usbid]['name'] = trim($device[6]);
} else {
$usbarray[$usbid]['name'] = 'unknown';
}
}
}
}
 
function network () {
$results = array();
$usbdevices = glob('/sys/bus/usb/devices/*/idProduct', GLOB_NOSORT);
if (is_array($usbdevices) && (($total = count($usbdevices)) > 0)) {
for ($i = 0; $i < $total; $i++) {
if (CommonFunctions::rfts($usbdevices[$i], $idproduct, 1, 4096, false) && (($idproduct=trim($idproduct)) != "")) { //is readable
$busnum = CommonFunctions::rolv($usbdevices[$i], '/\/idProduct$/', '/busnum');
$devnum = CommonFunctions::rolv($usbdevices[$i], '/\/idProduct$/', '/devnum');
$idvendor = CommonFunctions::rolv($usbdevices[$i], '/\/idProduct$/', '/idVendor');
if (($busnum!==null) && ($devnum!==null) && ($idvendor!==null)) {
$usbid = intval($busnum).'-'.intval($devnum).' '.$idvendor.':'.$idproduct;
$manufacturer = CommonFunctions::rolv($usbdevices[$i], '/\/idProduct$/', '/manufacturer');
if ($manufacturer!==null) {
$usbarray[$usbid]['manufacturer'] = $manufacturer;
}
$product = CommonFunctions::rolv($usbdevices[$i], '/\/idProduct$/', '/product');
if ($product!==null) {
$usbarray[$usbid]['product'] = $product;
}
if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS
&& defined('PSI_SHOW_DEVICES_SERIAL') && PSI_SHOW_DEVICES_SERIAL) {
$serial = CommonFunctions::rolv($usbdevices[$i], '/\/idProduct$/', '/serial');
if (($serial!==null) && !preg_match('/\W/', $serial)) {
$usbarray[$usbid]['serial'] = $serial;
}
}
}
}
}
}
 
$bufr = rfts( '/proc/net/dev' );
if ( $bufr != "ERROR" ) {
$bufe = explode("\n", $bufr);
foreach( $bufe as $buf ) {
if (preg_match('/:/', $buf)) {
list($dev_name, $stats_list) = preg_split('/:/', $buf, 2);
$stats = preg_split('/\s+/', trim($stats_list));
$results[$dev_name] = array();
if ((count($usbarray) == 0) && CommonFunctions::rfts('/proc/bus/usb/devices', $bufr, 0, 4096, false)) {
$devnum = -1;
$bufe = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
foreach ($bufe as $buf) {
if (preg_match('/^T/', $buf)) {
$devnum++;
} elseif (preg_match('/^S:/', $buf)) {
list($key, $value) = preg_split('/: /', $buf, 2);
list($key, $value2) = preg_split('/=/', $value, 2);
switch (trim($key)) {
case 'Manufacturer':
$usbarray[$devnum]['manufacturer'] = trim($value2);
break;
case 'Product':
$usbarray[$devnum]['product'] = trim($value2);
break;
case 'SerialNumber':
if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS
&& defined('PSI_SHOW_DEVICES_SERIAL') && PSI_SHOW_DEVICES_SERIAL
&& !preg_match('/\W/', trim($value2))) {
$usbarray[$devnum]['serial'] = trim($value2);
}
break;
}
}
}
}
 
$results[$dev_name]['rx_bytes'] = $stats[0];
$results[$dev_name]['rx_packets'] = $stats[1];
$results[$dev_name]['rx_errs'] = $stats[2];
$results[$dev_name]['rx_drop'] = $stats[3];
if ((count($usbarray) == 0) && CommonFunctions::rfts('/proc/bus/input/devices', $bufr, 0, 4096, false)) {
$devnam = "unknown";
$bufe = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
foreach ($bufe as $buf) {
if (preg_match('/^I:\s+(.+)/', $buf, $bufr)
&& isset($bufr[1]) && (trim($bufr[1])!=="")) {
$devnam = trim($bufr[1]);
$usbarray[$devnam]['phys'] = 'unknown';
} elseif (preg_match('/^N:\s+Name="([^"]+)"/', $buf, $bufr2)
&& isset($bufr2[1]) && (trim($bufr2[1])!=="")) {
$usbarray[$devnam]['name'] = trim($bufr2[1]);
} elseif (preg_match('/^P:\s+Phys=(.*)/', $buf, $bufr2)
&& isset($bufr2[1]) && (trim($bufr2[1])!=="")) {
$usbarray[$devnam]['phys'] = trim($bufr2[1]);
} elseif (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS
&& defined('PSI_SHOW_DEVICES_SERIAL') && PSI_SHOW_DEVICES_SERIAL
&& preg_match('/^U:\s+Uniq=(.+)/', $buf, $bufr2)
&& isset($bufr2[1]) && (trim($bufr2[1])!=="")) {
$usbarray[$devnam]['serial'] = trim($bufr2[1]);
}
}
}
 
$results[$dev_name]['tx_bytes'] = $stats[8];
$results[$dev_name]['tx_packets'] = $stats[9];
$results[$dev_name]['tx_errs'] = $stats[10];
$results[$dev_name]['tx_drop'] = $stats[11];
foreach ($usbarray as $usbdev) if (!isset($usbdev['phys']) || preg_match('/^usb-/', $usbdev['phys'])) {
$dev = new HWDevice();
 
$results[$dev_name]['errs'] = $stats[2] + $stats[10];
$results[$dev_name]['drop'] = $stats[3] + $stats[11];
}
}
if (isset($usbdev['manufacturer']) && (($manufacturer=$usbdev['manufacturer']) !== 'no manufacturer')) {
if (preg_match("/^linux\s/i", $manufacturer)) {
$manufacturer = 'Linux Foundation';
}
if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS) {
$dev->setManufacturer($manufacturer);
}
} else {
$manufacturer = '';
}
 
if (isset($usbdev['product'])) {
$product = $usbdev['product'];
if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS) {
$dev->setProduct($product);
}
} else {
$product = '';
}
 
if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS
&& defined('PSI_SHOW_DEVICES_SERIAL') && PSI_SHOW_DEVICES_SERIAL
&& isset($usbdev['serial'])) {
$dev->setSerial($usbdev['serial']);
}
 
if (isset($usbdev['name']) && (($name=$usbdev['name']) !== 'unknown')) {
$dev->setName($name);
} else {
if (($newname = trim($manufacturer.' '.$product)) !== '') {
$dev->setName($newname);
} else {
$dev->setName('unknown');
}
}
 
$this->sys->setUsbDevices($dev);
}
}
return $results;
}
 
function memory () {
$results['ram'] = array('total' => 0, 'free' => 0, 'used' => 0, 'percent' => 0);
$results['swap'] = array('total' => 0, 'free' => 0, 'used' => 0, 'percent' => 0);
$results['devswap'] = array();
/**
* I2C devices
*
* @return void
*/
protected function _i2c()
{
$i2cdevices = glob('/sys/bus/i2c/devices/*/name', GLOB_NOSORT);
if (is_array($i2cdevices) && (($total = count($i2cdevices)) > 0)) {
$buf = "";
for ($i = 0; $i < $total; $i++) {
if (CommonFunctions::rfts($i2cdevices[$i], $buf, 1, 4096, false) && (trim($buf) != "")) {
$dev = new HWDevice();
$dev->setName(trim($buf));
$this->sys->setI2cDevices($dev);
}
}
}
}
 
$bufr = rfts( '/proc/meminfo' );
if ( $bufr != "ERROR" ) {
$bufe = explode("\n", $bufr);
foreach( $bufe as $buf ) {
if (preg_match('/^MemTotal:\s+(.*)\s*kB/i', $buf, $ar_buf)) {
$results['ram']['total'] = $ar_buf[1];
} else if (preg_match('/^MemFree:\s+(.*)\s*kB/i', $buf, $ar_buf)) {
$results['ram']['free'] = $ar_buf[1];
} else if (preg_match('/^Cached:\s+(.*)\s*kB/i', $buf, $ar_buf)) {
$results['ram']['cached'] = $ar_buf[1];
} else if (preg_match('/^Buffers:\s+(.*)\s*kB/i', $buf, $ar_buf)) {
$results['ram']['buffers'] = $ar_buf[1];
}
}
/**
* NVMe devices
*
* @return void
*/
protected function _nvme()
{
if (CommonFunctions::executeProgram('nvme', 'list', $bufr, PSI_DEBUG) && ($bufr!="")) {
$bufe = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
$count = 0;
$nlocate = array();
$nsize = array();
foreach ($bufe as $buf) {
if ($count == 1) {
$locid = 0;
$nlocate[0] = 0;
$total = strlen($buf);
$begin = true;
for ($i = 0; $i < $total; $i++) {
if ($begin) {
if ($buf[$i] !== '-') {
$nsize[$locid] = $i - $nlocate[$locid];
$locid++;
$begin = false;
}
} else {
if ($buf[$i] === '-') {
$nlocate[$locid] = $i;
$begin = true;
}
}
}
if ($begin) {
$nsize[$locid] = $i - $nlocate[$locid];
}
} elseif ($count > 1) {
if (isset($nlocate[2]) && isset($nsize[2])) {
$dev = new HWDevice();
$dev->setName(trim(substr($buf, $nlocate[2], $nsize[2])));
if (defined('PSI_SHOW_DEVICES_INFOS') && (PSI_SHOW_DEVICES_INFOS)) {
if (isset($nlocate[4]) && isset($nsize[4])) {
if (preg_match('/\/\s*([0-9\.]+)\s*(B|KB|MB|GB|TB|PB)$/', str_replace(',', '.', trim(substr($buf, $nlocate[4], $nsize[4]))), $tmpbuf)) {
switch ($tmpbuf[2]) {
case 'B':
$dev->setCapacity($tmpbuf[1]);
break;
case 'KB':
$dev->setCapacity(1000*$tmpbuf[1]);
break;
case 'MB':
$dev->setCapacity(1000*1000*$tmpbuf[1]);
break;
case 'GB':
$dev->setCapacity(1000*1000*1000*$tmpbuf[1]);
break;
case 'TB':
$dev->setCapacity(1000*1000*1000*1000*$tmpbuf[1]);
break;
case 'PB':
$dev->setCapacity(1000*1000*1000*1000*1000*$tmpbuf[1]);
break;
}
}
}
if (defined('PSI_SHOW_DEVICES_SERIAL') && PSI_SHOW_DEVICES_SERIAL) {
if (isset($nlocate[1]) && isset($nsize[1])) {
$dev->setSerial(trim(substr($buf, $nlocate[1], $nsize[1])));
}
}
}
$this->sys->setNvmeDevices($dev);
}
}
$count++;
}
}
}
 
$results['ram']['used'] = $results['ram']['total'] - $results['ram']['free'];
$results['ram']['percent'] = round(($results['ram']['used'] * 100) / $results['ram']['total']);
// values for splitting memory usage
if (isset($results['ram']['cached']) && isset($results['ram']['buffers'])) {
$results['ram']['app'] = $results['ram']['used'] - $results['ram']['cached'] - $results['ram']['buffers'];
$results['ram']['app_percent'] = round(($results['ram']['app'] * 100) / $results['ram']['total']);
$results['ram']['buffers_percent'] = round(($results['ram']['buffers'] * 100) / $results['ram']['total']);
$results['ram']['cached_percent'] = round(($results['ram']['cached'] * 100) / $results['ram']['total']);
}
/**
* Network devices
* includes also rx/tx bytes
*
* @return void
*/
protected function _network()
{
if (CommonFunctions::rfts('/proc/net/dev', $bufr, 0, 4096, PSI_DEBUG)) {
$bufe = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
foreach ($bufe as $buf) {
if (preg_match('/:/', $buf)) {
list($dev_name, $stats_list) = preg_split('/:/', $buf, 2);
$stats = preg_split('/\s+/', trim($stats_list));
$dev = new NetDevice();
$dev->setName(trim($dev_name));
$dev->setRxBytes($stats[0]);
$dev->setTxBytes($stats[8]);
$dev->setErrors($stats[2] + $stats[10]);
$dev->setDrops($stats[3] + $stats[11]);
if (defined('PSI_SHOW_NETWORK_INFOS') && (PSI_SHOW_NETWORK_INFOS)) {
$macaddr = "";
if ((CommonFunctions::executeProgram('ip', 'addr show '.trim($dev_name), $bufr2, PSI_DEBUG) && ($bufr2!=""))
|| CommonFunctions::executeProgram('ifconfig', trim($dev_name).' 2>/dev/null', $bufr2, PSI_DEBUG)) {
$bufe2 = preg_split("/\n/", $bufr2, -1, PREG_SPLIT_NO_EMPTY);
foreach ($bufe2 as $buf2) {
// if (preg_match('/^'.trim($dev_name).'\s+Link\sencap:Ethernet\s+HWaddr\s(\S+)/i', $buf2, $ar_buf2)
if (preg_match('/\s+encap:Ethernet\s+HWaddr\s(\S+)/i', $buf2, $ar_buf2)
|| preg_match('/\s+encap:UNSPEC\s+HWaddr\s(\S+)-00-00-00-00-00-00-00-00-00-00\s*$/i', $buf2, $ar_buf2)
|| preg_match('/^\s+ether\s+(\S+)\s+txqueuelen/i', $buf2, $ar_buf2)
|| preg_match('/^\s+link\/ether\s+(\S+)\s+brd/i', $buf2, $ar_buf2)
|| preg_match('/^\s+link\/ether\s+(\S+)$/i', $buf2, $ar_buf2)
|| preg_match('/^\s+link\/ieee802.11\s+(\S+)$/i', $buf2, $ar_buf2)) {
if (!defined('PSI_HIDE_NETWORK_MACADDR') || !PSI_HIDE_NETWORK_MACADDR) {
$macaddr = preg_replace('/:/', '-', strtoupper($ar_buf2[1]));
if ($macaddr === '00-00-00-00-00-00') { // empty
$macaddr = "";
}
}
} elseif (preg_match('/^\s+inet\saddr:(\S+)\s+P-t-P:(\S+)/i', $buf2, $ar_buf2)
|| preg_match('/^\s+inet\s+(\S+)\s+netmask.+destination\s+(\S+)/i', $buf2, $ar_buf2)
|| preg_match('/^\s+inet\s+([^\/\s]+).*peer\s+([^\/\s]+).*\s+scope\s((global)|(host))/i', $buf2, $ar_buf2)) {
if ($ar_buf2[1] != $ar_buf2[2]) {
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$ar_buf2[1].";:".$ar_buf2[2]);
} else {
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$ar_buf2[1]);
}
} elseif ((preg_match('/^\s+inet\saddr:(\S+)/i', $buf2, $ar_buf2)
|| preg_match('/^\s+inet\s+(\S+)\s+netmask/i', $buf2, $ar_buf2)
|| preg_match('/^'.trim($dev_name).':\s+ip\s+(\S+)\s+mask/i', $buf2, $ar_buf2)
|| preg_match('/^\s+inet6\saddr:\s([^\/\s]+)(.+)\s+Scope:[GH]/i', $buf2, $ar_buf2)
|| preg_match('/^\s+inet6\s+(\S+)\s+prefixlen(.+)((<global>)|(<host>))/i', $buf2, $ar_buf2)
|| preg_match('/^\s+inet6?\s+([^\/\s]+).*\s+scope\s((global)|(host))/i', $buf2, $ar_buf2))
&& ($ar_buf2[1]!="::") && !preg_match('/^fe80::/i', $ar_buf2[1])) {
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').strtolower($ar_buf2[1]));
}
}
}
if ($macaddr != "") {
$dev->setInfo($macaddr.($dev->getInfo()?';'.$dev->getInfo():''));
}
if (CommonFunctions::rfts('/sys/class/net/'.trim($dev_name).'/speed', $buf, 1, 4096, false) && (($speed=trim($buf))!="") && ($buf > 0) && ($buf < 65535)) {
if ($speed > 1000) {
$speed = $speed/1000;
$unit = "G";
} else {
$unit = "M";
}
if (CommonFunctions::rfts('/sys/class/net/'.trim($dev_name).'/duplex', $buf, 1, 4096, false) && (($duplex=strtolower(trim($buf)))!="") && ($duplex!='unknown')) {
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$speed.$unit.'b/s '.$duplex);
} else {
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$speed.$unit.'b/s');
}
}
}
$this->sys->setNetDevices($dev);
}
}
} elseif (CommonFunctions::executeProgram('ip', 'addr show', $bufr, PSI_DEBUG) && ($bufr!="")) {
$lines = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
$was = false;
$macaddr = "";
$speedinfo = "";
$dev = null;
foreach ($lines as $line) {
if (preg_match("/^\d+:\s+([^\s:]+)/", $line, $ar_buf)) {
if ($was) {
if ($macaddr != "") {
$dev->setInfo($macaddr.($dev->getInfo()?';'.$dev->getInfo():''));
}
if ($speedinfo != "") {
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$speedinfo);
}
$this->sys->setNetDevices($dev);
}
$speedinfo = "";
$macaddr = "";
$dev = new NetDevice();
$dev->setName($ar_buf[1]);
if (CommonFunctions::executeProgram('ip', '-s link show '.$ar_buf[1], $bufr2, PSI_DEBUG) && ($bufr2!="")
&& preg_match("/\n\s+RX:\s[^\n]+\n\s+(\d+)\s+\d+\s+(\d+)\s+(\d+)[^\n]+\n\s+TX:\s[^\n]+\n\s+(\d+)\s+\d+\s+(\d+)\s+(\d+)/m", $bufr2, $ar_buf2)) {
$dev->setRxBytes($ar_buf2[1]);
$dev->setTxBytes($ar_buf2[4]);
$dev->setErrors($ar_buf2[2]+$ar_buf2[5]);
$dev->setDrops($ar_buf2[3]+$ar_buf2[6]);
}
$was = true;
if (defined('PSI_SHOW_NETWORK_INFOS') && (PSI_SHOW_NETWORK_INFOS)) {
if (CommonFunctions::rfts('/sys/class/net/'.$ar_buf[1].'/speed', $buf, 1, 4096, false) && (trim($buf)!="")) {
$speed = trim($buf);
if ($speed > 1000) {
$speed = $speed/1000;
$unit = "G";
} else {
$unit = "M";
}
if (CommonFunctions::rfts('/sys/class/net/'.$ar_buf[1].'/duplex', $buf, 1, 4096, false) && (trim($buf)!="")) {
$speedinfo = $speed.$unit.'b/s '.strtolower(trim($buf));
} else {
$speedinfo = $speed.$unit.'b/s';
}
}
}
} else {
if ($was) {
if (defined('PSI_SHOW_NETWORK_INFOS') && (PSI_SHOW_NETWORK_INFOS)) {
if (preg_match('/^\s+link\/ether\s+(\S+)\s+brd/i', $line, $ar_buf2)) {
if (!defined('PSI_HIDE_NETWORK_MACADDR') || !PSI_HIDE_NETWORK_MACADDR) $macaddr = preg_replace('/:/', '-', strtoupper($ar_buf2[1]));
} elseif (preg_match('/^\s+inet\s+([^\/\s]+).*peer\s+([^\/\s]+).*\s+scope\s((global)|(host))/i', $line, $ar_buf2)) {
if ($ar_buf2[1] != $ar_buf2[2]) {
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$ar_buf2[1].";:".$ar_buf2[2]);
} else {
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$ar_buf2[1]);
}
} elseif (preg_match('/^\s+inet6?\s+([^\/\s]+).*\s+scope\s((global)|(host))/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 ($was) {
if ($macaddr != "") {
$dev->setInfo($macaddr.($dev->getInfo()?';'.$dev->getInfo():''));
}
if ($speedinfo != "") {
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$speedinfo);
}
$this->sys->setNetDevices($dev);
}
} elseif (CommonFunctions::executeProgram('ifconfig', '-a', $bufr, PSI_DEBUG)) {
$lines = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
$was = false;
$errors = 0;
$drops = 0;
$macaddr = "";
$speedinfo = "";
$dev = null;
foreach ($lines as $line) {
if (preg_match("/^([^\s:]+)/", $line, $ar_buf)) {
if ($was) {
$dev->setErrors($errors);
$dev->setDrops($drops);
if ($macaddr != "") {
$dev->setInfo($macaddr.($dev->getInfo()?';'.$dev->getInfo():''));
}
if ($speedinfo != "") {
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$speedinfo);
}
$this->sys->setNetDevices($dev);
}
$errors = 0;
$drops = 0;
$speedinfo = "";
$macaddr = "";
$dev = new NetDevice();
$dev->setName($ar_buf[1]);
$was = true;
if (defined('PSI_SHOW_NETWORK_INFOS') && (PSI_SHOW_NETWORK_INFOS)) {
if (CommonFunctions::rfts('/sys/class/net/'.$ar_buf[1].'/speed', $buf, 1, 4096, false) && (trim($buf)!="")) {
$speed = trim($buf);
if ($speed > 1000) {
$speed = $speed/1000;
$unit = "G";
} else {
$unit = "M";
}
if (CommonFunctions::rfts('/sys/class/net/'.$ar_buf[1].'/duplex', $buf, 1, 4096, false) && (trim($buf)!="")) {
$speedinfo = $speed.$unit.'b/s '.strtolower(trim($buf));
} else {
$speedinfo = $speed.$unit.'b/s';
}
}
if (preg_match('/^'.$ar_buf[1].'\s+Link\sencap:Ethernet\s+HWaddr\s(\S+)/i', $line, $ar_buf2))
if (!defined('PSI_HIDE_NETWORK_MACADDR') || !PSI_HIDE_NETWORK_MACADDR) $macaddr = preg_replace('/:/', '-', strtoupper($ar_buf2[1]));
elseif (preg_match('/^'.$ar_buf[1].':\s+ip\s+(\S+)\s+mask/i', $line, $ar_buf2))
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$ar_buf2[1]);
}
} else {
if ($was) {
if (preg_match('/\sRX bytes:(\d+)\s/i', $line, $ar_buf2)) {
$dev->setRxBytes($ar_buf2[1]);
}
if (preg_match('/\sTX bytes:(\d+)\s/i', $line, $ar_buf2)) {
$dev->setTxBytes($ar_buf2[1]);
}
 
$bufr = rfts( '/proc/swaps' );
if ( $bufr != "ERROR" ) {
$swaps = explode("\n", $bufr);
for ($i = 1; $i < (sizeof($swaps)); $i++) {
if( trim( $swaps[$i] ) != "" ) {
$ar_buf = preg_split('/\s+/', $swaps[$i], 6);
$results['devswap'][$i - 1] = array();
$results['devswap'][$i - 1]['dev'] = $ar_buf[0];
$results['devswap'][$i - 1]['total'] = $ar_buf[2];
$results['devswap'][$i - 1]['used'] = $ar_buf[3];
$results['devswap'][$i - 1]['free'] = ($results['devswap'][$i - 1]['total'] - $results['devswap'][$i - 1]['used']);
$results['devswap'][$i - 1]['percent'] = round(($ar_buf[3] * 100) / $ar_buf[2]);
$results['swap']['total'] += $ar_buf[2];
$results['swap']['used'] += $ar_buf[3];
$results['swap']['free'] = $results['swap']['total'] - $results['swap']['used'];
$results['swap']['percent'] = round(($results['swap']['used'] * 100) / $results['swap']['total']);
}
}
}
if (preg_match('/\sRX packets:\d+\serrors:(\d+)\sdropped:(\d+)/i', $line, $ar_buf2)) {
$errors +=$ar_buf2[1];
$drops +=$ar_buf2[2];
} elseif (preg_match('/\sTX packets:\d+\serrors:(\d+)\sdropped:(\d+)/i', $line, $ar_buf2)) {
$errors +=$ar_buf2[1];
$drops +=$ar_buf2[2];
}
 
if (defined('PSI_SHOW_NETWORK_INFOS') && (PSI_SHOW_NETWORK_INFOS)) {
if (preg_match('/\s+encap:Ethernet\s+HWaddr\s(\S+)/i', $line, $ar_buf2)
|| preg_match('/^\s+ether\s+(\S+)\s+txqueuelen/i', $line, $ar_buf2)) {
if (!defined('PSI_HIDE_NETWORK_MACADDR') || !PSI_HIDE_NETWORK_MACADDR) $macaddr = preg_replace('/:/', '-', strtoupper($ar_buf2[1]));
} elseif (preg_match('/^\s+inet\saddr:(\S+)\s+P-t-P:(\S+)/i', $line, $ar_buf2)
|| preg_match('/^\s+inet\s+(\S+)\s+netmask.+destination\s+(\S+)/i', $line, $ar_buf2)) {
if ($ar_buf2[1] != $ar_buf2[2]) {
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$ar_buf2[1].";:".$ar_buf2[2]);
} else {
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$ar_buf2[1]);
}
} elseif ((preg_match('/^\s+inet\saddr:(\S+)/i', $line, $ar_buf2)
|| preg_match('/^\s+inet\s+(\S+)\s+netmask/i', $line, $ar_buf2)
|| preg_match('/^\s+inet6\saddr:\s([^\/\s]+)(.+)\s+Scope:[GH]/i', $line, $ar_buf2)
|| preg_match('/^\s+inet6\s+(\S+)\s+prefixlen(.+)((<global>)|(<host>))/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 ($was) {
$dev->setErrors($errors);
$dev->setDrops($drops);
if ($macaddr != "") {
$dev->setInfo($macaddr.($dev->getInfo()?';'.$dev->getInfo():''));
}
if ($speedinfo != "") {
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$speedinfo);
}
$this->sys->setNetDevices($dev);
}
}
}
return $results;
}
function filesystems () {
return $this->parser->parse_filesystems();
}
 
function distro () {
return $this->distro;
}
/**
* Physical memory information and Swap Space information
*
* @return void
*/
protected function _memory()
{
if (CommonFunctions::rfts('/proc/meminfo', $mbuf)) {
$bufe = preg_split("/\n/", $mbuf, -1, PREG_SPLIT_NO_EMPTY);
foreach ($bufe as $buf) {
if (preg_match('/^MemTotal:\s+(\d+)\s*kB/i', $buf, $ar_buf)) {
$this->sys->setMemTotal($ar_buf[1] * 1024);
} elseif (preg_match('/^MemFree:\s+(\d+)\s*kB/i', $buf, $ar_buf)) {
$this->sys->setMemFree($ar_buf[1] * 1024);
} elseif (preg_match('/^Cached:\s+(\d+)\s*kB/i', $buf, $ar_buf)) {
$this->sys->setMemCache($ar_buf[1] * 1024);
} elseif (preg_match('/^Buffers:\s+(\d+)\s*kB/i', $buf, $ar_buf)) {
$this->sys->setMemBuffer($ar_buf[1] * 1024);
}
}
$this->sys->setMemUsed($this->sys->getMemTotal() - $this->sys->getMemFree());
// values for splitting memory usage
if ($this->sys->getMemCache() !== null && $this->sys->getMemBuffer() !== null) {
$this->sys->setMemApplication($this->sys->getMemUsed() - $this->sys->getMemCache() - $this->sys->getMemBuffer());
}
if (CommonFunctions::rfts('/proc/swaps', $sbuf, 0, 4096, false)) {
$swaps = preg_split("/\n/", $sbuf, -1, PREG_SPLIT_NO_EMPTY);
unset($swaps[0]);
foreach ($swaps as $swap) {
$ar_buf = preg_split('/\s+/', $swap, 5);
$dev = new DiskDevice();
$dev->setMountPoint($ar_buf[0]);
$dev->setName("SWAP");
$dev->setTotal($ar_buf[2] * 1024);
$dev->setUsed($ar_buf[3] * 1024);
$dev->setFree($dev->getTotal() - $dev->getUsed());
$this->sys->setSwapDevices($dev);
}
}
}
}
 
function distroicon () {
return $this->icon;
}
/**
* filesystem information
*
* @return void
*/
private function _filesystems()
{
$df_args = "";
$hideFstypes = array();
if (defined('PSI_HIDE_FS_TYPES') && is_string(PSI_HIDE_FS_TYPES)) {
if (preg_match(ARRAY_EXP, PSI_HIDE_FS_TYPES)) {
$hideFstypes = eval(PSI_HIDE_FS_TYPES);
} else {
$hideFstypes = array(PSI_HIDE_FS_TYPES);
}
}
foreach ($hideFstypes as $Fstype) {
$df_args .= "-x $Fstype ";
}
if ($df_args !== "") {
$df_args = trim($df_args); //trim spaces
$arrResult = Parser::df("-P $df_args 2>/dev/null");
} else {
$arrResult = Parser::df("-P 2>/dev/null");
}
foreach ($arrResult as $dev) {
$this->sys->setDiskDevices($dev);
}
}
 
}
/**
* Distribution
*
* @return void
*/
protected function _distro()
{
$this->sys->setDistribution("Linux");
$list = @parse_ini_file(PSI_APP_ROOT."/data/distros.ini", true);
if (!$list) {
return;
}
// We have the '2>/dev/null' because Ubuntu gives an error on this command which causes the distro to be unknown
if (CommonFunctions::executeProgram('lsb_release', '-a 2>/dev/null', $distro_info, PSI_DEBUG) && (strlen($distro_info) > 0)) {
$distro_tmp = preg_split("/\n/", $distro_info, -1, PREG_SPLIT_NO_EMPTY);
foreach ($distro_tmp as $info) {
$info_tmp = preg_split('/:/', $info, 2);
if (isset($distro_tmp[0]) && !is_null($distro_tmp[0]) && (trim($distro_tmp[0]) != "") &&
isset($distro_tmp[1]) && !is_null($distro_tmp[1]) && (trim($distro_tmp[1]) != "")) {
$distro[trim($info_tmp[0])] = trim($info_tmp[1]);
}
}
if (!isset($distro['Distributor ID']) && !isset($distro['Description'])) { // Systems like StartOS
if (isset($distro_tmp[0]) && !is_null($distro_tmp[0]) && (trim($distro_tmp[0]) != "")) {
$this->sys->setDistribution(trim($distro_tmp[0]));
if (preg_match('/^(\S+)\s*/', $distro_tmp[0], $id_buf)
&& isset($list[trim($id_buf[1])]['Image'])) {
$this->sys->setDistributionIcon($list[trim($id_buf[1])]['Image']);
}
}
} else {
if (isset($distro['Description'])
&& preg_match('/^NAME=\s*"?([^"\n]+)"?\s*$/', $distro['Description'], $name_tmp)) {
$distro['Description'] = $name_tmp[1];
}
if (isset($distro['Description'])
&& ($distro['Description'] != "n/a")
&& (!isset($distro['Distributor ID'])
|| (($distro['Distributor ID'] != "n/a")
&& ($distro['Description'] != $distro['Distributor ID'])))) {
$this->sys->setDistribution($distro['Description']);
if (isset($distro['Release']) && ($distro['Release'] != "n/a")
&& ($distro['Release'] != $distro['Description']) && strstr($distro['Release'], ".")){
if (preg_match("/^(\d+)\.[0]+$/", $distro['Release'], $match_buf)) {
$tofind = $match_buf[1];
} else {
$tofind = $distro['Release'];
}
if (!preg_match("/^".$tofind."[\s\.]|[\(\[]".$tofind."[\.\)\]]|\s".$tofind."$|\s".$tofind."[\s\.]/", $distro['Description'])) {
$this->sys->setDistribution($this->sys->getDistribution()." ".$distro['Release']);
}
}
} elseif (isset($distro['Distributor ID']) && ($distro['Distributor ID'] != "n/a")) {
$this->sys->setDistribution($distro['Distributor ID']);
if (isset($distro['Release']) && ($distro['Release'] != "n/a")) {
$this->sys->setDistribution($this->sys->getDistribution()." ".$distro['Release']);
}
if (isset($distro['Codename']) && ($distro['Codename'] != "n/a")) {
$this->sys->setDistribution($this->sys->getDistribution()." (".$distro['Codename'].")");
}
}
if (isset($distro['Distributor ID']) && ($distro['Distributor ID'] != "n/a") && isset($list[$distro['Distributor ID']]['Image'])) {
$this->sys->setDistributionIcon($list[$distro['Distributor ID']]['Image']);
} elseif (isset($distro['Description']) && ($distro['Description'] != "n/a")) {
$this->sys->setDistribution($distro['Description']);
if (isset($list[$distro['Description']]['Image'])) {
$this->sys->setDistributionIcon($list[$distro['Description']]['Image']);
}
}
}
} else {
/* default error handler */
if (function_exists('errorHandlerPsi')) {
restore_error_handler();
}
/* fatal errors only */
$old_err_rep = error_reporting();
error_reporting(E_ERROR);
 
?>
// Fall back in case 'lsb_release' does not exist but exist /etc/lsb-release
if (CommonFunctions::fileexists($filename="/etc/lsb-release")
&& CommonFunctions::rfts($filename, $buf, 0, 4096, false)
&& preg_match('/^DISTRIB_ID="?([^"\n]+)"?/m', $buf, $id_buf)) {
if (preg_match('/^DISTRIB_DESCRIPTION="?([^"\n]+)"?/m', $buf, $desc_buf)
&& (trim($desc_buf[1])!=trim($id_buf[1]))) {
$this->sys->setDistribution(trim($desc_buf[1]));
if (preg_match('/^DISTRIB_RELEASE="?([^"\n]+)"?/m', $buf, $vers_buf)
&& (trim($vers_buf[1])!=trim($desc_buf[1])) && strstr($vers_buf[1], ".")){
if (preg_match("/^(\d+)\.[0]+$/", trim($vers_buf[1]), $match_buf)) {
$tofind = $match_buf[1];
} else {
$tofind = trim($vers_buf[1]);
}
if (!preg_match("/^".$tofind."[\s\.]|[\(\[]".$tofind."[\.\)\]]|\s".$tofind."$|\s".$tofind."[\s\.]/", trim($desc_buf[1]))) {
$this->sys->setDistribution($this->sys->getDistribution()." ".trim($vers_buf[1]));
}
}
} else {
if (isset($list[trim($id_buf[1])]['Name'])) {
$this->sys->setDistribution(trim($list[trim($id_buf[1])]['Name']));
} else {
$this->sys->setDistribution(trim($id_buf[1]));
}
if (preg_match('/^DISTRIB_RELEASE="?([^"\n]+)"?/m', $buf, $vers_buf)) {
$this->sys->setDistribution($this->sys->getDistribution()." ".trim($vers_buf[1]));
}
if (preg_match('/^DISTRIB_CODENAME="?([^"\n]+)"?/m', $buf, $vers_buf)) {
$this->sys->setDistribution($this->sys->getDistribution()." (".trim($vers_buf[1]).")");
}
}
if (isset($list[trim($id_buf[1])]['Image'])) {
$this->sys->setDistributionIcon($list[trim($id_buf[1])]['Image']);
}
} else { // otherwise find files specific for distribution
foreach ($list as $section=>$distribution) {
if (!isset($distribution['Files'])) {
continue;
} else {
foreach (preg_split("/;/", $distribution['Files'], -1, PREG_SPLIT_NO_EMPTY) as $filename) {
if (CommonFunctions::fileexists($filename)) {
$distro = $distribution;
if (isset($distribution['Mode'])&&(strtolower($distribution['Mode'])=="detection")) {
$buf = "";
} elseif (isset($distribution['Mode'])&&(strtolower($distribution['Mode'])=="execute")) {
if (!CommonFunctions::executeProgram($filename, '2>/dev/null', $buf, PSI_DEBUG)) {
$buf = "";
}
} else {
if (!CommonFunctions::rfts($filename, $buf, 1, 4096, false)) {
$buf = "";
} elseif (isset($distribution['Mode'])&&(strtolower($distribution['Mode'])=="analyse")) {
if (preg_match('/^(\S+)\s*/', preg_replace('/^Red\s+/', 'Red', $buf), $id_buf)
&& isset($list[trim($id_buf[1])]['Image'])) {
$distro = $list[trim($id_buf[1])];
}
}
}
if (isset($distro['Image'])) {
$this->sys->setDistributionIcon($distro['Image']);
}
if (isset($distribution['Name'])) {
if (is_null($buf) || (trim($buf) == "")) {
$this->sys->setDistribution($distribution['Name']);
} else {
$this->sys->setDistribution($distribution['Name']." ".trim($buf));
}
} else {
if (is_null($buf) || (trim($buf) == "")) {
$this->sys->setDistribution($section);
} else {
$this->sys->setDistribution(trim($buf));
}
}
if (isset($distribution['Files2'])) {
foreach (preg_split("/;/", $distribution['Files2'], -1, PREG_SPLIT_NO_EMPTY) as $filename2) {
if (CommonFunctions::fileexists($filename2) && CommonFunctions::rfts($filename2, $buf, 0, 4096, false)) {
if (preg_match('/^majorversion="?([^"\n]+)"?/m', $buf, $maj_buf)
&& preg_match('/^minorversion="?([^"\n]+)"?/m', $buf, $min_buf)) {
$distr2=$maj_buf[1].'.'.$min_buf[1];
if (preg_match('/^buildphase="?([^"\n]+)"?/m', $buf, $pha_buf) && ($pha_buf[1]!=="0")) {
$distr2.='.'.$pha_buf[1];
}
if (preg_match('/^buildnumber="?([^"\n]+)"?/m', $buf, $num_buf)) {
$distr2.='-'.$num_buf[1];
}
if (preg_match('/^builddate="?([^"\n]+)"?/m', $buf, $dat_buf)) {
$distr2.=' ('.$dat_buf[1].')';
}
$this->sys->setDistribution($this->sys->getDistribution()." ".$distr2);
} else {
$distr2=trim(substr($buf, 0, strpos($buf, "\n")));
if (!is_null($distr2) && ($distr2 != "")) {
$this->sys->setDistribution($this->sys->getDistribution()." ".$distr2);
}
}
break;
}
}
}
break 2;
}
}
}
}
}
// if the distribution is still unknown
if ($this->sys->getDistribution() == "Linux") {
if (CommonFunctions::fileexists($filename="/etc/DISTRO_SPECS")
&& CommonFunctions::rfts($filename, $buf, 0, 4096, false)
&& preg_match('/^DISTRO_NAME=\'(.+)\'/m', $buf, $id_buf)) {
if (isset($list[trim($id_buf[1])]['Name'])) {
$dist = trim($list[trim($id_buf[1])]['Name']);
} else {
$dist = trim($id_buf[1]);
}
if (preg_match('/^DISTRO_VERSION=([^#\n\r]+)/m', $buf, $vers_buf)) {
$this->sys->setDistribution(trim($dist." ".trim($vers_buf[1])));
} else {
$this->sys->setDistribution($dist);
}
if (isset($list[trim($id_buf[1])]['Image'])) {
$this->sys->setDistributionIcon($list[trim($id_buf[1])]['Image']);
} else {
if (isset($list['Puppy']['Image'])) {
$this->sys->setDistributionIcon($list['Puppy']['Image']);
}
}
} elseif ((CommonFunctions::fileexists($filename="/etc/distro-release")
&& CommonFunctions::rfts($filename, $buf, 1, 4096, false)
&& !is_null($buf) && (trim($buf) != ""))
|| (CommonFunctions::fileexists($filename="/etc/system-release")
&& CommonFunctions::rfts($filename, $buf, 1, 4096, false)
&& !is_null($buf) && (trim($buf) != ""))) {
$this->sys->setDistribution(trim($buf));
if (preg_match('/^(\S+)\s*/', preg_replace('/^Red\s+/', 'Red', $buf), $id_buf)
&& isset($list[trim($id_buf[1])]['Image'])) {
$this->sys->setDistributionIcon($list[trim($id_buf[1])]['Image']);
}
} elseif (CommonFunctions::fileexists($filename="/etc/solydxk/info")
&& CommonFunctions::rfts($filename, $buf, 0, 4096, false)
&& preg_match('/^DISTRIB_ID="?([^"\n]+)"?/m', $buf, $id_buf)) {
if (preg_match('/^DESCRIPTION="?([^"\n]+)"?/m', $buf, $desc_buf)
&& (trim($desc_buf[1])!=trim($id_buf[1]))) {
$this->sys->setDistribution(trim($desc_buf[1]));
} else {
if (isset($list[trim($id_buf[1])]['Name'])) {
$this->sys->setDistribution(trim($list[trim($id_buf[1])]['Name']));
} else {
$this->sys->setDistribution(trim($id_buf[1]));
}
if (preg_match('/^RELEASE="?([^"\n]+)"?/m', $buf, $vers_buf)) {
$this->sys->setDistribution($this->sys->getDistribution()." ".trim($vers_buf[1]));
}
if (preg_match('/^CODENAME="?([^"\n]+)"?/m', $buf, $vers_buf)) {
$this->sys->setDistribution($this->sys->getDistribution()." (".trim($vers_buf[1]).")");
}
}
if (isset($list[trim($id_buf[1])]['Image'])) {
$this->sys->setDistributionIcon($list[trim($id_buf[1])]['Image']);
} else {
$this->sys->setDistributionIcon($list['SolydXK']['Image']);
}
} elseif (CommonFunctions::fileexists($filename="/etc/os-release")
&& CommonFunctions::rfts($filename, $buf, 0, 4096, false)
&& (preg_match('/^TAILS_VERSION_ID="?([^"\n]+)"?/m', $buf, $tid_buf)
|| preg_match('/^NAME="?([^"\n]+)"?/m', $buf, $id_buf))) {
if (preg_match('/^TAILS_VERSION_ID="?([^"\n]+)"?/m', $buf, $tid_buf)) {
if (preg_match('/^TAILS_PRODUCT_NAME="?([^"\n]+)"?/m', $buf, $desc_buf)) {
$this->sys->setDistribution(trim($desc_buf[1])." ".trim($tid_buf[1]));
} else {
if (isset($list['Tails']['Name'])) {
$this->sys->setDistribution(trim($list['Tails']['Name'])." ".trim($tid_buf[1]));
} else {
$this->sys->setDistribution('Tails'." ".trim($tid_buf[1]));
}
}
$this->sys->setDistributionIcon($list['Tails']['Image']);
} else {
if (preg_match('/^PRETTY_NAME="?([^"\n]+)"?/m', $buf, $desc_buf)
&& !preg_match('/\$/', $desc_buf[1])) { //if is not defined by variable
$this->sys->setDistribution(trim($desc_buf[1]));
} else {
if (isset($list[trim($id_buf[1])]['Name'])) {
$this->sys->setDistribution(trim($list[trim($id_buf[1])]['Name']));
} else {
$this->sys->setDistribution(trim($id_buf[1]));
}
if (preg_match('/^VERSION="?([^"\n]+)"?/m', $buf, $vers_buf)) {
$this->sys->setDistribution($this->sys->getDistribution()." ".trim($vers_buf[1]));
} elseif (preg_match('/^VERSION_ID="?([^"\n]+)"?/m', $buf, $vers_buf)) {
$this->sys->setDistribution($this->sys->getDistribution()." ".trim($vers_buf[1]));
}
}
if (isset($list[trim($id_buf[1])]['Image'])) {
$this->sys->setDistributionIcon($list[trim($id_buf[1])]['Image']);
}
}
} elseif (CommonFunctions::fileexists($filename="/etc/debian_version")) {
if (!CommonFunctions::rfts($filename, $buf, 1, 4096, false)) {
$buf = "";
}
if (isset($list['Debian']['Image'])) {
$this->sys->setDistributionIcon($list['Debian']['Image']);
}
if (isset($list['Debian']['Name'])) {
if (is_null($buf) || (trim($buf) == "")) {
$this->sys->setDistribution($list['Debian']['Name']);
} else {
$this->sys->setDistribution($list['Debian']['Name']." ".trim($buf));
}
} else {
if (is_null($buf) || (trim($buf) == "")) {
$this->sys->setDistribution('Debian');
} else {
$this->sys->setDistribution(trim($buf));
}
}
} elseif (CommonFunctions::fileexists($filename="/etc/config/uLinux.conf")
&& CommonFunctions::rfts($filename, $buf, 0, 4096, false)
&& preg_match("/^Rsync\sModel\s*=\s*QNAP/m", $buf)
&& preg_match("/^Version\s*=\s*([\d\.]+)\r?\nBuild\sNumber\s*=\s*(\S+)/m", $buf, $ver_buf)) {
$buf = $ver_buf[1]."-".$ver_buf[2];
if (isset($list['QTS']['Image'])) {
$this->sys->setDistributionIcon($list['QTS']['Image']);
}
if (isset($list['QTS']['Name'])) {
$this->sys->setDistribution($list['QTS']['Name']." ".trim($buf));
} else {
$this->sys->setDistribution(trim($buf));
}
}
}
/* restore error level */
error_reporting($old_err_rep);
/* restore error handler */
if (function_exists('errorHandlerPsi')) {
set_error_handler('errorHandlerPsi');
}
}
}
 
/**
* Processes
*
* @return void
*/
protected function _processes()
{
$process = glob('/proc/*/status', GLOB_NOSORT);
if (is_array($process) && (($total = count($process)) > 0)) {
$processes['*'] = 0;
$buf = "";
for ($i = 0; $i < $total; $i++) {
if (CommonFunctions::rfts($process[$i], $buf, 0, 4096, false)) {
$processes['*']++; //current total
if (preg_match('/^State:\s+(\w)/m', $buf, $state)) {
if (isset($processes[$state[1]])) {
$processes[$state[1]]++;
} else {
$processes[$state[1]] = 1;
}
}
}
}
if (!($processes['*'] > 0)) {
$processes['*'] = $processes[' '] = $total; //all unknown
}
$this->sys->setProcesses($processes);
}
}
 
/**
* get the information
*
* @see PSI_Interface_OS::build()
*
* @return Void
*/
public function build()
{
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->_pci();
$this->_ide();
$this->_scsi();
$this->_nvme();
$this->_usb();
$this->_i2c();
}
if (!$this->blockname || $this->blockname==='network') {
$this->_network();
}
if (!$this->blockname || $this->blockname==='memory') {
$this->_memory();
}
if (!$this->blockname || $this->blockname==='filesystem') {
$this->_filesystems();
}
}
}
/web/acc/phpsysinfo/includes/os/class.Minix.inc.php
0,0 → 1,359
<?php
/**
* Minix System Class
*
* PHP version 5
*
* @category PHP
* @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 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
*/
/**
* Minix sysinfo class
* get all the required information from Minix system
*
* @category PHP
* @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 version 2, or (at your option) any later version
* @version Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
class Minix extends OS
{
/**
* content of the syslog
*
* @var array
*/
private $_dmesg = null;
 
/**
* read /var/log/messages, but only if we haven't already
*
* @return array
*/
protected function readdmesg()
{
if ($this->_dmesg === null) {
if (CommonFunctions::rfts('/var/log/messages', $buf)) {
$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();
}
}
 
return $this->_dmesg;
}
 
/**
* get the cpu information
*
* @return void
*/
protected function _cpuinfo()
{
if (CommonFunctions::rfts('/proc/cpuinfo', $bufr, 0, 4096, false)) {
$processors = preg_split('/\s?\n\s?\n/', trim($bufr));
foreach ($processors as $processor) {
$_n = ""; $_f = ""; $_m = ""; $_s = "";
$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])) {
case 'model name':
$_n = $arrBuff[1];
break;
case 'cpu mhz':
$dev->setCpuSpeed($arrBuff[1]);
break;
case 'cpu family':
$_f = $arrBuff[1];
break;
case 'model':
$_m = $arrBuff[1];
break;
case 'stepping':
$_s = $arrBuff[1];
break;
case 'flags':
if (preg_match("/ vmx/", $arrBuff[1])) {
$dev->setVirt("vmx");
} elseif (preg_match("/ svm/", $arrBuff[1])) {
$dev->setVirt("svm");
}
break;
case 'vendor_id':
$dev->setVendorId($arrBuff[1]);
break;
}
}
}
if ($_n == "") $_n="CPU";
if ($_f != "") $_n.=" Family ".$_f;
if ($_m != "") $_n.=" Model ".$_m;
if ($_s != "") $_n.=" Stepping ".$_s;
$dev->SetModel($_n);
$this->sys->setCpus($dev);
}
} else
foreach ($this->readdmesg() as $line) {
if (preg_match('/kernel: (CPU .*) freq (.*) MHz/', $line, $ar_buf)) {
$dev = new CpuDevice();
$dev->setModel($ar_buf[1]);
$dev->setCpuSpeed($ar_buf[2]);
$this->sys->setCpus($dev);
}
}
}
 
/**
* PCI devices
* get the pci device information out of dmesg
*
* @return void
*/
protected function _pci()
{
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)
$strName = $arrParams[3];
else
$strName = "unknown";
$strName = preg_replace('/\(.*\)/', '', $strName);
$dev = new HWDevice();
$dev->setName($strName);
$arrResults[] = $dev;
}
foreach ($arrResults as $dev) {
$this->sys->setPciDevices($dev);
}
}
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);
}
}
}
 
/**
* Minix Version
*
* @return void
*/
private function _kernel()
{
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
$this->sys->setKernel($ret);
}
}
 
/**
* Distribution
*
* @return void
*/
protected function _distro()
{
if (CommonFunctions::executeProgram('uname', '-sr', $ret))
$this->sys->setDistribution($ret);
else
$this->sys->setDistribution('Minix');
 
$this->sys->setDistributionIcon('Minix.png');
}
 
/**
* UpTime
* time the system is running
*
* @return void
*/
private function _uptime()
{
if (CommonFunctions::executeProgram('uptime', '', $buf)) {
if (preg_match("/up (\d+) day[s]?,\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);
}
}
}
 
/**
* Processor Load
* optionally create a loadbar
*
* @return void
*/
private function _loadavg()
{
if (CommonFunctions::executeProgram('uptime', '', $buf)) {
if (preg_match("/load averages: (.*), (.*), (.*)$/", $buf, $ar_buf)) {
$this->sys->setLoad($ar_buf[1].' '.$ar_buf[2].' '.$ar_buf[3]);
}
}
}
 
/**
* Virtual Host Name
*
* @return void
*/
private function _hostname()
{
if (PSI_USE_VHOST === true) {
if (CommonFunctions::readenv('SERVER_NAME', $hnm)) $this->sys->setHostname($hnm);
} else {
if (CommonFunctions::executeProgram('uname', '-n', $result, PSI_DEBUG)) {
$ip = gethostbyname($result);
if ($ip != $result) {
$this->sys->setHostname(gethostbyaddr($ip));
}
}
}
}
 
 
/**
* Physical memory information and Swap Space information
*
* @return void
*/
private function _memory()
{
if (CommonFunctions::rfts('/proc/meminfo', $bufr, 1, 4096, false)) {
$ar_buf = preg_split('/\s+/', trim($bufr));
if (count($ar_buf) >= 5) {
$this->sys->setMemTotal($ar_buf[0]*$ar_buf[1]);
$this->sys->setMemFree($ar_buf[0]*$ar_buf[2]);
$this->sys->setMemCache($ar_buf[0]*$ar_buf[4]);
$this->sys->setMemUsed($ar_buf[0]*($ar_buf[1]-$ar_buf[2]));
}
}
}
 
/**
* filesystem information
*
* @return void
*/
private function _filesystems()
{
$arrResult = Parser::df("-P 2>/dev/null");
foreach ($arrResult as $dev) {
$this->sys->setDiskDevices($dev);
}
}
 
/**
* network information
*
* @return void
*/
private function _network()
{
if (CommonFunctions::executeProgram('ifconfig', '-a', $bufr, PSI_DEBUG)) {
$lines = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
foreach ($lines as $line) {
if (preg_match("/^([^\s:]+):\saddress\s(\S+)\snetmask/", $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]);
}
$this->sys->setNetDevices($dev);
}
}
}
}
 
/**
* Processes
*
* @return void
*/
protected function _processes()
{
if (CommonFunctions::executeProgram('ps', 'alx', $bufr, PSI_DEBUG)) {
$lines = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
$processes['*'] = 0;
foreach ($lines as $line) {
if (preg_match("/^\s(\w)\s/", $line, $ar_buf)) {
$processes['*']++;
$state = $ar_buf[1];
if ($state == 'W') $state = 'D'; //linux format
elseif ($state == 'D') $state = 'd'; //invalid
if (isset($processes[$state])) {
$processes[$state]++;
} else {
$processes[$state] = 1;
}
}
}
if ($processes['*'] > 0) {
$this->sys->setProcesses($processes);
}
}
}
 
/**
* get the information
*
* @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");
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==='network') {
$this->_network();
}
if (!$this->blockname || $this->blockname==='memory') {
$this->_memory();
}
if (!$this->blockname || $this->blockname==='filesystem') {
$this->_filesystems();
}
}
}
/web/acc/phpsysinfo/includes/os/class.NetBSD.inc.php
1,111 → 1,208
<?php
<?php
/**
* NetBSD System Class
*
* PHP version 5
*
* @category PHP
* @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 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
*/
/**
* NetBSD sysinfo class
* get all the required information from NetBSD systems
*
* @category PHP
* @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 version 2, or (at your option) any later version
* @version Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
class NetBSD extends BSDCommon
{
/**
* define the regexp for log parser
*/
public function __construct($blockname = false)
{
parent::__construct($blockname);
$this->setCPURegExp1("/^cpu(.*)\, (.*) MHz/");
$this->setCPURegExp2("/user = (.*), nice = (.*), sys = (.*), intr = (.*), idle = (.*)/");
$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/");
}
 
// phpSysInfo - A PHP System Information Script
// http://phpsysinfo.sourceforge.net/
/**
* UpTime
* time the system is running
*
* @return void
*/
private function _uptime()
{
$a = $this->grabkey('kern.boottime');
$this->sys->setUptime(time() - $a);
}
 
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
/**
* get network information
*
* @return void
*/
private function _network()
{
CommonFunctions::executeProgram('netstat', '-nbdi | cut -c1-25,44- | grep "^[a-z]*[0-9][ \t].*Link"', $netstat_b);
CommonFunctions::executeProgram('netstat', '-ndi | cut -c1-25,44- | grep "^[a-z]*[0-9][ \t].*Link"', $netstat_n);
$lines_b = preg_split("/\n/", $netstat_b, -1, PREG_SPLIT_NO_EMPTY);
$lines_n = preg_split("/\n/", $netstat_n, -1, PREG_SPLIT_NO_EMPTY);
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]) || ($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);
}
}
}
 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
/**
* IDE information
*
* @return void
*/
protected function ide()
{
foreach ($this->readdmesg() as $line) {
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();
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);
}
}
}
 
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
/**
* get icon name
*
* @return void
*/
private function _distroicon()
{
$this->sys->setDistributionIcon('NetBSD.png');
}
 
// $Id: class.NetBSD.inc.php,v 1.18 2006/04/18 16:57:32 bigmichi1 Exp $
if (!defined('IN_PHPSYSINFO')) {
die("No Hacking");
/**
* Processes
*
* @return void
*/
protected function _processes()
{
if (CommonFunctions::executeProgram('ps', 'aux', $bufr, PSI_DEBUG)) {
$lines = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
$processes['*'] = 0;
foreach ($lines as $line) {
if (preg_match("/^\S+\s+\d+\s+\S+\s+\S+\s+\d+\s+\d+\s+\S+\s+(\w)/", $line, $ar_buf)) {
$processes['*']++;
$state = $ar_buf[1];
if ($state == 'O') $state = 'R'; //linux format
elseif ($state == 'I') $state = 'S';
if (isset($processes[$state])) {
$processes[$state]++;
} else {
$processes[$state] = 1;
}
}
}
if ($processes['*'] > 0) {
$this->sys->setProcesses($processes);
}
}
}
 
/**
* get the information
*
* @see BSDCommon::build()
*
* @return Void
*/
public function build()
{
parent::build();
if (!$this->blockname || $this->blockname==='vitals') {
$this->_distroicon();
$this->_uptime();
$this->_processes();
}
if (!$this->blockname || $this->blockname==='network') {
$this->_network();
}
}
}
 
require_once(APP_ROOT . '/includes/os/class.BSD.common.inc.php');
 
class sysinfo extends bsd_common {
var $cpu_regexp;
var $scsi_regexp;
// Our contstructor
// this function is run on the initialization of this class
function sysinfo () {
$this->bsd_common();
$this->cpu_regexp = "^cpu(.*)\, (.*) MHz";
$this->scsi_regexp1 = "^(.*) at scsibus.*: <(.*)> .*";
$this->scsi_regexp2 = "^(da[0-9]): (.*)MB ";
$this->cpu_regexp2 = "/user = (.*), nice = (.*), sys = (.*), intr = (.*), idle = (.*)/";
$this->pci_regexp1 = '/(.*) at pci[0-9] dev [0-9]* function [0-9]*: (.*)$/';
$this->pci_regexp2 = '/"(.*)" (.*).* at [.0-9]+ irq/';
}
 
function get_sys_ticks () {
$a = $this->grab_key('kern.boottime');
$sys_ticks = time() - $a;
return $sys_ticks;
}
 
function network () {
$netstat_b = execute_program('netstat', '-nbdi | cut -c1-25,44- | grep "^[a-z]*[0-9][ \t].*Link"');
$netstat_n = execute_program('netstat', '-ndi | cut -c1-25,44- | grep "^[a-z]*[0-9][ \t].*Link"');
$lines_b = explode("\n", $netstat_b);
$lines_n = explode("\n", $netstat_n);
$results = array();
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])) {
$results[$ar_buf_b[0]] = array();
 
$results[$ar_buf_b[0]]['rx_bytes'] = $ar_buf_b[3];
$results[$ar_buf_b[0]]['rx_packets'] = $ar_buf_n[3];
$results[$ar_buf_b[0]]['rx_errs'] = $ar_buf_n[4];
$results[$ar_buf_b[0]]['rx_drop'] = $ar_buf_n[8];
 
$results[$ar_buf_b[0]]['tx_bytes'] = $ar_buf_b[4];
$results[$ar_buf_b[0]]['tx_packets'] = $ar_buf_n[5];
$results[$ar_buf_b[0]]['tx_errs'] = $ar_buf_n[6];
$results[$ar_buf_b[0]]['tx_drop'] = $ar_buf_n[8];
 
$results[$ar_buf_b[0]]['errs'] = $ar_buf_n[4] + $ar_buf_n[6];
$results[$ar_buf_b[0]]['drop'] = $ar_buf_n[8];
}
}
return $results;
}
 
// get the ide device information out of dmesg
function ide () {
$results = array();
 
$s = 0;
for ($i = 0, $max = count($this->read_dmesg()); $i < $max; $i++) {
$buf = $this->dmesg[$i];
if (preg_match('/^(.*) at (pciide|wdc|atabus|atapibus)[0-9] (.*): <(.*)>/', $buf, $ar_buf)) {
$s = $ar_buf[1];
$results[$s]['model'] = $ar_buf[4];
$results[$s]['media'] = 'Hard Disk';
// now loop again and find the capacity
for ($j = 0, $max1 = count($this->read_dmesg()); $j < $max1; $j++) {
$buf_n = $this->dmesg[$j];
if (preg_match("/^($s): (.*), (.*), (.*)MB, .*$/", $buf_n, $ar_buf_n)) {
$results[$s]['capacity'] = $ar_buf_n[4] * 2048 * 1.049;
} elseif (preg_match("/^($s): (.*) MB, (.*), (.*), .*$/", $buf_n, $ar_buf_n)) {
$results[$s]['capacity'] = $ar_buf_n[2] * 2048;
}
}
}
}
asort($results);
return $results;
}
 
function distroicon () {
$result = 'NetBSD.png';
return($result);
}
}
 
?>
/web/acc/phpsysinfo/includes/os/class.OS.inc.php
0,0 → 1,172
<?php
/**
* Basic OS Class
*
* PHP version 5
*
* @category PHP
* @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 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
*/
/**
* Basic OS functions for all OS classes
*
* @category PHP
* @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 version 2, or (at your option) any later version
* @version Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
abstract class OS implements PSI_Interface_OS
{
/**
* object for error handling
*
* @var PSI_Error
*/
protected $error;
 
/**
* block name
*
* @var string
*/
protected $blockname = false;
 
/**
* @var System
*/
protected $sys;
 
/**
* build the global Error object
*/
public function __construct($blockname = false)
{
$this->error = PSI_Error::singleton();
$this->sys = new System();
$this->blockname = $blockname;
}
 
/**
* get os specific encoding
*
* @see PSI_Interface_OS::getEncoding()
*
* @return string
*/
public function getEncoding()
{
return PSI_SYSTEM_CODEPAGE;
}
 
/**
* get os specific language
*
* @see PSI_Interface_OS::getLanguage()
*
* @return string
*/
public function getLanguage()
{
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 = glob('/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 === true) {
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
}
} else {
if (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()));
}
}
}
 
/**
* get the filled or unfilled (with default values) System object
*
* @see PSI_Interface_OS::getSys()
*
* @return System
*/
final public function getSys()
{
$this->build();
if (!$this->blockname || $this->blockname==='vitals') {
$this->_ip();
}
 
return $this->sys;
}
}
/web/acc/phpsysinfo/includes/os/class.OpenBSD.inc.php
1,110 → 1,229
<?php
<?php
/**
* OpenBSD System Class
*
* PHP version 5
*
* @category PHP
* @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 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
*/
/**
* OpenBSD sysinfo class
* get all the required information from OpenBSD systems
*
* @category PHP
* @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 version 2, or (at your option) any later version
* @version Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
class OpenBSD extends BSDCommon
{
/**
* define the regexp for log parser
*/
public function __construct($blockname = false)
{
parent::__construct($blockname);
// $this->setCPURegExp1("/^cpu(.*) (.*) MHz/");
$this->setCPURegExp2("/(.*),(.*),(.*),(.*),(.*)/");
$this->setSCSIRegExp1("/^(.*) at scsibus.*: <(.*)> .*/");
$this->setSCSIRegExp2("/^(sd[0-9]+): (.*)MB,/");
$this->setPCIRegExp1("/(.*) at pci[0-9]+ .* \"(.*)\"/");
$this->setPCIRegExp2("/\"(.*)\" (.*).* at [.0-9]+ irq/");
}
 
// phpSysInfo - A PHP System Information Script
// http://phpsysinfo.sourceforge.net/
/**
* UpTime
* time the system is running
*
* @return void
*/
private function _uptime()
{
$a = $this->grabkey('kern.boottime');
$this->sys->setUptime(time() - $a);
}
 
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
/**
* get network information
*
* @return void
*/
private function _network()
{
CommonFunctions::executeProgram('netstat', '-nbdi | cut -c1-25,44- | grep Link | grep -v \'* \'', $netstat_b, PSI_DEBUG);
CommonFunctions::executeProgram('netstat', '-ndi | cut -c1-25,44- | grep Link | grep -v \'* \'', $netstat_n, PSI_DEBUG);
$lines_b = preg_split("/\n/", $netstat_b, -1, PREG_SPLIT_NO_EMPTY);
$lines_n = preg_split("/\n/", $netstat_n, -1, PREG_SPLIT_NO_EMPTY);
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]) || ($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 (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);
}
}
}
 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
/**
* IDE information
*
* @return void
*/
protected function ide()
{
foreach ($this->readdmesg() as $line) {
if (preg_match('/^(.*) at pciide[0-9]+ (.*): <(.*)>/', $line, $ar_buf)) {
$dev = new HWDevice();
$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);
}
}
}
 
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
/**
* get CPU information
*
* @return void
*/
protected function cpuinfo()
{
$dev = new CpuDevice();
$dev->setModel($this->grabkey('hw.model'));
$dev->setCpuSpeed($this->grabkey('hw.cpuspeed'));
$was = false;
foreach ($this->readdmesg() as $line) {
if (preg_match("/^cpu[0-9]+: (.*)/", $line, $ar_buf)) {
$was = true;
if (preg_match("/^cpu[0-9]+: (\d+)([KM])B (.*) L2 cache/", $line, $ar_buf2)) {
if ($ar_buf2[2]=="M") {
$dev->setCache($ar_buf2[1]*1024*1024);
} elseif ($ar_buf2[2]=="K") {
$dev->setCache($ar_buf2[1]*1024);
}
} else {
$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);
}
}
}
} elseif ($was) {
break;
}
}
$ncpu = $this->grabkey('hw.ncpu');
if (is_null($ncpu) || (trim($ncpu) == "") || (!($ncpu >= 1)))
$ncpu = 1;
for ($ncpu ; $ncpu > 0 ; $ncpu--) {
$this->sys->setCpus($dev);
}
}
 
// $Id: class.OpenBSD.inc.php,v 1.21 2006/04/18 17:46:15 bigmichi1 Exp $
if (!defined('IN_PHPSYSINFO')) {
die("No Hacking");
}
/**
* get icon name
*
* @return void
*/
private function _distroicon()
{
$this->sys->setDistributionIcon('OpenBSD.png');
}
 
require_once(APP_ROOT . '/includes/os/class.BSD.common.inc.php');
/**
* Processes
*
* @return void
*/
protected function _processes()
{
if (CommonFunctions::executeProgram('ps', 'aux', $bufr, PSI_DEBUG)) {
$lines = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
$processes['*'] = 0;
foreach ($lines as $line) {
if (preg_match("/^\S+\s+\d+\s+\S+\s+\S+\s+\d+\s+\d+\s+\S+\s+(\w)/", $line, $ar_buf)) {
$processes['*']++;
$state = $ar_buf[1];
if ($state == 'I') $state = 'S'; //linux format
if (isset($processes[$state])) {
$processes[$state]++;
} else {
$processes[$state] = 1;
}
}
}
if ($processes['*'] > 0) {
$this->sys->setProcesses($processes);
}
}
}
 
class sysinfo extends bsd_common {
var $cpu_regexp = "";
var $scsi_regexp1 = "";
var $scsi_regexp2 = "";
var $cpu_regexp2 = "";
// Our contstructor
// this function is run on the initialization of this class
function sysinfo () {
$this->bsd_common();
$this->cpu_regexp = "^cpu(.*) (.*) MHz";
$this->scsi_regexp1 = "^(.*) at scsibus.*: <(.*)> .*";
$this->scsi_regexp2 = "^(da[0-9]): (.*)MB ";
$this->cpu_regexp2 = "/(.*),(.*),(.*),(.*),(.*)/";
$this->pci_regexp1 = '/(.*) at pci[0-9] .* "(.*)"/';
$this->pci_regexp2 = '/"(.*)" (.*).* at [.0-9]+ irq/';
}
 
function get_sys_ticks () {
$a = $this->grab_key('kern.boottime');
$sys_ticks = time() - $a;
return $sys_ticks;
}
 
function network () {
$netstat_b = execute_program('netstat', '-nbdi | cut -c1-25,44- | grep Link | grep -v \'* \'');
$netstat_n = execute_program('netstat', '-ndi | cut -c1-25,44- | grep Link | grep -v \'* \'');
$lines_b = explode("\n", $netstat_b);
$lines_n = explode("\n", $netstat_n);
$results = array();
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])) {
$results[$ar_buf_b[0]] = array();
 
$results[$ar_buf_b[0]]['rx_bytes'] = $ar_buf_b[3];
$results[$ar_buf_b[0]]['rx_packets'] = $ar_buf_n[3];
$results[$ar_buf_b[0]]['rx_errs'] = $ar_buf_n[4];
$results[$ar_buf_b[0]]['rx_drop'] = $ar_buf_n[8];
 
$results[$ar_buf_b[0]]['tx_bytes'] = $ar_buf_b[4];
$results[$ar_buf_b[0]]['tx_packets'] = $ar_buf_n[5];
$results[$ar_buf_b[0]]['tx_errs'] = $ar_buf_n[6];
$results[$ar_buf_b[0]]['tx_drop'] = $ar_buf_n[8];
 
$results[$ar_buf_b[0]]['errs'] = $ar_buf_n[4] + $ar_buf_n[6];
$results[$ar_buf_b[0]]['drop'] = $ar_buf_n[8];
}
}
return $results;
}
// get the ide device information out of dmesg
function ide () {
$results = array();
 
$s = 0;
for ($i = 0, $max = count($this->read_dmesg()); $i < $max; $i++) {
$buf = $this->dmesg[$i];
if (preg_match('/^(.*) at pciide[0-9] (.*): <(.*)>/', $buf, $ar_buf)) {
$s = $ar_buf[1];
$results[$s]['model'] = $ar_buf[3];
$results[$s]['media'] = 'Hard Disk';
// now loop again and find the capacity
for ($j = 0, $max1 = count($this->read_dmesg()); $j < $max1; $j++) {
$buf_n = $this->dmesg[$j];
if (preg_match("/^($s): (.*), (.*), (.*)MB, .*$/", $buf_n, $ar_buf_n)) {
$results[$s]['capacity'] = $ar_buf_n[4] * 2048 * 1.049;;
}
}
}
}
asort($results);
return $results;
}
 
function distroicon () {
$result = 'OpenBSD.png';
return($result);
}
}
 
?>
/**
* get the information
*
* @see BSDCommon::build()
*
* @return Void
*/
public function build()
{
parent::build();
if (!$this->blockname || $this->blockname==='vitals') {
$this->_distroicon();
$this->_uptime();
$this->_processes();
}
if (!$this->blockname || $this->blockname==='network') {
$this->_network();
}
}
}
/web/acc/phpsysinfo/includes/os/class.QNX.inc.php
0,0 → 1,233
<?php
/**
* QNX System Class
*
* PHP version 5
*
* @category PHP
* @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 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
*/
/**
* QNX sysinfo class
* get all the required information from QNX system
*
* @category PHP
* @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 version 2, or (at your option) any later version
* @version Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
class QNX extends OS
{
/**
* get the cpu information
*
* @return void
*/
protected function _cpuinfo()
{
if (CommonFunctions::executeProgram('pidin', 'info', $buf)
&& preg_match('/^Processor\d+: (.*)/m', $buf)) {
$lines = preg_split("/\n/", $buf, -1, PREG_SPLIT_NO_EMPTY);
foreach ($lines as $line) {
if (preg_match('/^Processor\d+: (.+)/', $line, $proc)) {
$dev = new CpuDevice();
$dev->SetModel(trim($proc[1]));
if (preg_match('/(\d+)MHz/', $proc[1], $mhz)) {
$dev->setCpuSpeed($mhz[1]);
}
$this->sys->setCpus($dev);
}
}
}
}
 
/**
* QNX Version
*
* @return void
*/
private function _kernel()
{
if (CommonFunctions::executeProgram('uname', '-rvm', $ret)) {
$this->sys->setKernel($ret);
}
}
 
/**
* Distribution
*
* @return void
*/
protected function _distro()
{
if (CommonFunctions::executeProgram('uname', '-sr', $ret))
$this->sys->setDistribution($ret);
else
$this->sys->setDistribution('QNX');
 
$this->sys->setDistributionIcon('QNX.png');
}
 
/**
* UpTime
* time the system is running
*
* @return void
*/
private function _uptime()
{
 
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);
 
$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');
}
}
}
 
/**
* Number of Users
*
* @return void
*/
protected function _users()
{
$this->sys->setUsers(1);
}
 
/**
* Virtual Host Name
*
* @return void
*/
private function _hostname()
{
if (PSI_USE_VHOST === true) {
if (CommonFunctions::readenv('SERVER_NAME', $hnm)) $this->sys->setHostname($hnm);
} else {
if (CommonFunctions::executeProgram('uname', '-n', $result, PSI_DEBUG)) {
$ip = gethostbyname($result);
if ($ip != $result) {
$this->sys->setHostname(gethostbyaddr($ip));
}
}
}
}
 
/**
* Physical memory information and Swap Space information
*
* @return void
*/
private function _memory()
{
if (CommonFunctions::executeProgram('pidin', 'info', $buf)
&& preg_match('/^.* FreeMem:(\S+)Mb\/(\S+)Mb/', $buf, $memm)) {
$this->sys->setMemTotal(1024*1024*$memm[2]);
$this->sys->setMemFree(1024*1024*$memm[1]);
$this->sys->setMemUsed(1024*1024*($memm[2]-$memm[1]));
}
}
 
/**
* filesystem information
*
* @return void
*/
private function _filesystems()
{
$arrResult = Parser::df("-P 2>/dev/null");
foreach ($arrResult as $dev) {
$this->sys->setDiskDevices($dev);
}
}
 
/**
* network information
*
* @return void
*/
private function _network()
{
if (CommonFunctions::executeProgram('ifconfig', '', $bufr, PSI_DEBUG)) {
$lines = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
$was = false;
$dev = null;
foreach ($lines as $line) {
if (preg_match("/^([^\s:]+)/", $line, $ar_buf)) {
if ($was) {
$this->sys->setNetDevices($dev);
}
$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+address:\s*(\S+)/i', $line, $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', $line, $ar_buf2))
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$ar_buf2[1]);
 
}
}
}
}
if ($was) {
$this->sys->setNetDevices($dev);
}
}
}
 
/**
* get the information
*
* @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");
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==='network') {
$this->_network();
}
if (!$this->blockname || $this->blockname==='memory') {
$this->_memory();
}
if (!$this->blockname || $this->blockname==='filesystem') {
$this->_filesystems();
}
}
}
/web/acc/phpsysinfo/includes/os/class.SunOS.inc.php
1,240 → 1,483
<?php
<?php
/**
* SunOS System Class
*
* PHP version 5
*
* @category PHP
* @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 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
*/
/**
* SunOS sysinfo class
* get all the required information from SunOS systems
*
* @category PHP
* @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 version 2, or (at your option) any later version
* @version Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
class SunOS extends OS
{
 
// phpSysInfo - A PHP System Information Script
// http://phpsysinfo.sourceforge.net/
/**
* content of prtconf -v
*
* @var array
*/
private $_prtconf = null;
 
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
/**
* 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;
}
}
}
}
}
}
 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
return $this->_prtconf;
}
 
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
/**
* Extract kernel values via kstat() interface
*
* @param string $key key for kstat programm
*
* @return string
*/
private function _kstat($key)
{
if (CommonFunctions::executeProgram('kstat', '-p d '.$key, $m, PSI_DEBUG) && ($m!=="")) {
list($key, $value) = preg_split("/\t/", $m, 2);
 
// $Id: class.SunOS.inc.php,v 1.24 2007/02/18 18:59:54 bigmichi1 Exp $
return trim($value);
} else {
return '';
}
}
 
$error->addError("WARN", "The SunOS version of phpSysInfo is work in progress, some things currently don't work");
/**
* Virtual Host Name
*
* @return void
*/
private function _hostname()
{
if (PSI_USE_VHOST === true) {
if (CommonFunctions::readenv('SERVER_NAME', $hnm)) $this->sys->setHostname($hnm);
} else {
if (CommonFunctions::executeProgram('uname', '-n', $result, PSI_DEBUG)) {
$ip = gethostbyname($result);
if ($ip != $result) {
$this->sys->setHostname(gethostbyaddr($ip));
}
}
}
}
 
class sysinfo {
// Extract kernel values via kstat() interface
function kstat ($key) {
$m = execute_program('kstat', "-p d $key");
list($key, $value) = explode("\t", trim($m), 2);
return $value;
}
/**
* Kernel Version
*
* @return void
*/
private function _kernel()
{
if (CommonFunctions::executeProgram('uname', '-s', $os, PSI_DEBUG) && ($os!="")) {
if (CommonFunctions::executeProgram('uname', '-r', $version, PSI_DEBUG) && ($version!="")) {
$os.=' '.$version;
}
if (CommonFunctions::executeProgram('uname', '-v', $subversion, PSI_DEBUG) && ($subversion!="")) {
$os.=' ('.$subversion.')';
}
if (CommonFunctions::executeProgram('uname', '-i', $platform, PSI_DEBUG) && ($platform!="")) {
$os.=' '.$platform;
}
$this->sys->setKernel($os);
}
}
 
function vhostname () {
if (! ($result = getenv('SERVER_NAME'))) {
$result = 'N.A.';
}
return $result;
}
// get the IP address of our vhost name
function vip_addr () {
return gethostbyname($this->vhostname());
}
// get our canonical hostname
function chostname () {
if ($result = execute_program('uname', '-n')) {
$result = gethostbyaddr(gethostbyname($result));
} else {
$result = 'N.A.';
}
return $result;
}
// get the IP address of our canonical hostname
function ip_addr () {
if (!($result = getenv('SERVER_ADDR'))) {
$result = gethostbyname($this->chostname());
}
return $result;
}
/**
* UpTime
* time the system is running
*
* @return void
*/
private function _uptime()
{
$this->sys->setUptime(time() - $this->_kstat('unix:0:system_misc:boot_time'));
}
 
function kernel () {
$os = execute_program('uname', '-s');
$version = execute_program('uname', '-r');
return $os . ' ' . $version;
}
/**
* Processor Load
* optionally create a loadbar
*
* @return void
*/
private function _loadavg()
{
$load1 = $this->_kstat('unix:0:system_misc:avenrun_1min');
$load5 = $this->_kstat('unix:0:system_misc:avenrun_5min');
$load15 = $this->_kstat('unix:0:system_misc:avenrun_15min');
$this->sys->setLoad(round($load1 / 256, 2).' '.round($load5 / 256, 2).' '.round($load15 / 256, 2));
}
 
function uptime () {
$result = time() - $this->kstat('unix:0:system_misc:boot_time');
/**
* CPU information
*
* @return void
*/
private function _cpuinfo()
{
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);
}
}
}
 
return $result;
}
/**
* 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);
 
function users () {
$who = explode('=', execute_program('who', '-q'));
$result = $who[1];
return $result;
}
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']);
}
}
 
function loadavg ($bar = false) {
$load1 = $this->kstat('unix:0:system_misc:avenrun_1min');
$load5 = $this->kstat('unix:0:system_misc:avenrun_5min');
$load15 = $this->kstat('unix:0:system_misc:avenrun_15min');
$results['avg'] = array( round($load1/256, 2), round($load5/256, 2), round($load15/256, 2) );
return $results;
}
$this->sys->setPciDevices($dev);
}
}
}
}
}
}
 
function cpu_info () {
$results = array();
$ar_buf = array();
/**
* Network devices
*
* @return void
*/
private function _network()
{
if (CommonFunctions::executeProgram('netstat', '-ni | awk \'(NF ==10){print;}\'', $netstat, PSI_DEBUG)) {
$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]) && $ar_buf[0] !== 'Name') {
$dev = new NetDevice();
$dev->setName($ar_buf[0]);
$results[$ar_buf[0]]['errs'] = $ar_buf[5] + $ar_buf[7];
if (preg_match('/^(\D+)(\d+)$/', $ar_buf[0], $intf)) {
$prefix = $intf[1].':'.$intf[2].':'.$intf[1].$intf[2].':';
} elseif (preg_match('/^(\D.*)(\d+)$/', $ar_buf[0], $intf)) {
$prefix = $intf[1].':'.$intf[2].':mac:';
} else {
$prefix = "";
}
if ($prefix !== "") {
$cnt = $this->_kstat($prefix.'drop');
if ($cnt > 0) {
$dev->setDrops($cnt);
}
$cnt = $this->_kstat($prefix.'obytes64');
if ($cnt > 0) {
$dev->setTxBytes($cnt);
}
$cnt = $this->_kstat($prefix.'rbytes64');
if ($cnt > 0) {
$dev->setRxBytes($cnt);
}
}
if (defined('PSI_SHOW_NETWORK_INFOS') && (PSI_SHOW_NETWORK_INFOS)) {
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)) {
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) && ($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)
&& ($ar_buf2[1]!="::") && !preg_match('/^fe80::/i', $ar_buf2[1]))
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').strtolower($ar_buf2[1]));
}
}
}
 
$results['model'] = execute_program('uname', '-i');
$results['cpuspeed'] = $this->kstat('cpu_info:0:cpu_info0:clock_MHz');
$results['cache'] = $this->kstat('cpu_info:0:cpu_info0:cpu_type');
$results['cpus'] = $this->kstat('unix:0:system_misc:ncpus');
$this->sys->setNetDevices($dev);
}
}
}
}
 
return $results;
}
/**
* Physical memory information and Swap Space information
*
* @return void
*/
private function _memory()
{
$pagesize = $this->_kstat('unix:0:seg_cache:slab_size');
$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);
}
 
function pci () {
// FIXME
$results = array();
return $results;
}
/**
* filesystem information
*
* @return void
*/
private function _filesystems()
{
if (CommonFunctions::executeProgram('df', '-k', $df, PSI_DEBUG)) {
$df = preg_replace('/\n\s/m', ' ', $df);
$mounts = preg_split("/\n/", $df, -1, PREG_SPLIT_NO_EMPTY);
foreach ($mounts as $mount) {
$ar_buf = preg_split('/\s+/', $mount, 6);
if (!empty($ar_buf[0]) && $ar_buf[0] !== 'Filesystem') {
$dev = new DiskDevice();
$dev->setName($ar_buf[0]);
$dev->setTotal($ar_buf[1] * 1024);
$dev->setUsed($ar_buf[2] * 1024);
$dev->setFree($ar_buf[3] * 1024);
$dev->setMountPoint($ar_buf[5]);
if (CommonFunctions::executeProgram('df', '-n', $dftypes, PSI_DEBUG)) {
$mounttypes = preg_split("/\n/", $dftypes, -1, PREG_SPLIT_NO_EMPTY);
foreach ($mounttypes as $type) {
$ty_buf = preg_split('/:/', $type, 2);
if (trim($ty_buf[0]) == $dev->getMountPoint()) {
$dev->setFsType($ty_buf[1]);
break;
}
}
} elseif (CommonFunctions::executeProgram('df', '-T', $dftypes, PSI_DEBUG)) {
$dftypes = preg_replace('/\n\s/m', ' ', $dftypes);
$mounttypes = preg_split("/\n/", $dftypes, -1, PREG_SPLIT_NO_EMPTY);
foreach ($mounttypes as $type) {
$ty_buf = preg_split("/\s+/", $type, 3);
if ($ty_buf[0] == $dev->getName()) {
$dev->setFsType($ty_buf[1]);
break;
}
}
}
$this->sys->setDiskDevices($dev);
}
}
}
}
 
function ide () {
// FIXME
$results = array();
return $results;
}
/**
* Distribution Icon
*
* @return void
*/
private function _distro()
{
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', 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');
}
}
 
function scsi () {
// FIXME
$results = array();
return $results;
}
/**
* Processes
*
* @return void
*/
protected function _processes()
{
if (CommonFunctions::executeProgram('ps', 'aux', $bufr, PSI_DEBUG)) {
$lines = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
$processes['*'] = 0;
foreach ($lines as $line) {
if (preg_match("/^\S+\s+\d+\s+\S+\s+\S+\s+\d+\s+\d+\s+\S+\s+(\w)/", $line, $ar_buf)) {
$processes['*']++;
$state = $ar_buf[1];
if ($state == 'O') $state = 'R'; //linux format
elseif ($state == 'W') $state = 'D';
elseif ($state == 'D') $state = 'd'; //invalid
if (isset($processes[$state])) {
$processes[$state]++;
} else {
$processes[$state] = 1;
}
}
}
if ($processes['*'] > 0) {
$this->sys->setProcesses($processes);
}
}
}
 
function usb () {
// FIXME
$results = array();
return $results;
}
 
function sbus () {
$results = array();
$_results[0] = "";
// TODO. Nothing here yet. Move along.
$results = $_results;
return $results;
}
 
function network () {
$results = array();
 
$netstat = execute_program('netstat', '-ni | awk \'(NF ==10){print;}\'');
$lines = explode("\n", $netstat);
$results = array();
for ($i = 0, $max = sizeof($lines); $i < $max; $i++) {
$ar_buf = preg_split("/\s+/", $lines[$i]);
if ((!empty($ar_buf[0])) && ($ar_buf[0] != 'Name')) {
$results[$ar_buf[0]] = array();
 
$results[$ar_buf[0]]['rx_bytes'] = 0;
$results[$ar_buf[0]]['rx_packets'] = $ar_buf[4];
$results[$ar_buf[0]]['rx_errs'] = $ar_buf[5];
$results[$ar_buf[0]]['rx_drop'] = 0;
 
$results[$ar_buf[0]]['tx_bytes'] = 0;
$results[$ar_buf[0]]['tx_packets'] = $ar_buf[6];
$results[$ar_buf[0]]['tx_errs'] = $ar_buf[7];
$results[$ar_buf[0]]['tx_drop'] = 0;
 
$results[$ar_buf[0]]['errs'] = $ar_buf[5] + $ar_buf[
7];
$results[$ar_buf[0]]['drop'] = 0;
 
preg_match('/^(\D+)(\d+)$/', $ar_buf[0], $intf);
$prefix = $intf[1] . ':' . $intf[2] . ':' . $intf[1] . $intf[2] . ':';
$cnt = $this->kstat($prefix . 'drop');
 
if ($cnt > 0) {
$results[$ar_buf[0]]['rx_drop'] = $cnt;
}
$cnt = $this->kstat($prefix . 'obytes64');
 
if ($cnt > 0) {
$results[$ar_buf[0]]['tx_bytes'] = $cnt;
}
$cnt = $this->kstat($prefix . 'rbytes64');
 
if ($cnt > 0) {
$results[$ar_buf[0]]['rx_bytes'] = $cnt;
/**
* get the information
*
* @see PSI_Interface_OS::build()
*
* @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");
if (!$this->blockname || $this->blockname==='vitals') {
$this->_distro();
$this->_hostname();
$this->_kernel();
$this->_uptime();
$this->_users();
$this->_loadavg();
$this->_processes();
}
}
}
return $results;
}
 
function memory () {
$results['devswap'] = array();
 
$results['ram'] = array();
 
$pagesize = $this->kstat('unix:0:seg_cache:slab_size');
$results['ram']['total'] = $this->kstat('unix:0:system_pages:pagestotal') * $pagesize / 1024;
$results['ram']['used'] = $this->kstat('unix:0:system_pages:pageslocked') * $pagesize / 1024;
$results['ram']['free'] = $this->kstat('unix:0:system_pages:pagesfree') * $pagesize / 1024;
$results['ram']['shared'] = 0;
$results['ram']['buffers'] = 0;
$results['ram']['cached'] = 0;
 
$results['ram']['percent'] = round(($results['ram']['used'] * 100) / $results['ram']['total']);
 
$results['swap'] = array();
$results['swap']['total'] = $this->kstat('unix:0:vminfo:swap_avail') / 1024 / 1024;
$results['swap']['used'] = $this->kstat('unix:0:vminfo:swap_alloc') / 1024 / 1024;
$results['swap']['free'] = $this->kstat('unix:0:vminfo:swap_free') / 1024 / 1024;
$results['swap']['percent'] = round(($ar_buf[1] * 100) / $ar_buf[0]);
$results['swap']['percent'] = round(($results['swap']['used'] * 100) / $results['swap']['total']);
return $results;
}
 
function filesystems () {
$df = execute_program('df', '-k');
$mounts = explode("\n", $df);
 
$dftypes = execute_program('df', '-n');
$mounttypes = explode("\n", $dftypes);
 
for ($i = 1, $j = 0, $max = sizeof($mounts); $i < $max; $i++) {
$ar_buf = preg_split('/\s+/', $mounts[$i], 6);
$ty_buf = explode(':', $mounttypes[$i-1], 2);
 
if (hide_mount($ar_buf[5])) {
continue;
}
 
$results[$j] = array();
 
$results[$j]['disk'] = $ar_buf[0];
$results[$j]['size'] = $ar_buf[1];
$results[$j]['used'] = $ar_buf[2];
$results[$j]['free'] = $ar_buf[3];
$results[$j]['percent'] = round(($results[$j]['used'] * 100) / $results[$j]['size']);
$results[$j]['mount'] = $ar_buf[5];
$results[$j]['fstype'] = $ty_buf[1];
$j++;
}
return $results;
}
function distro () {
$result = 'SunOS';
return($result);
}
 
function distroicon () {
$result = 'SunOS.png';
return($result);
}
}
 
?>
if (!$this->blockname || $this->blockname==='hardware') {
$this->_cpuinfo();
$this->_pci();
}
if (!$this->blockname || $this->blockname==='network') {
$this->_network();
}
if (!$this->blockname || $this->blockname==='memory') {
$this->_memory();
}
if (!$this->blockname || $this->blockname==='filesystem') {
$this->_filesystems();
}
}
}
/web/acc/phpsysinfo/includes/os/class.WINNT.inc.php
1,344 → 1,1015
<?php
// phpSysInfo - A PHP System Information Script
// http://phpsysinfo.sourceforge.net/
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
// WINNT implementation written by Carl C. Longnecker, longneck@iname.com
// $Id: class.WINNT.inc.php,v 1.25 2007/03/07 20:21:27 bigmichi1 Exp $
<?php
/**
* WINNT System Class
*
* PHP version 5
*
* @category PHP
* @package PSI WINNT 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 version 2, or (at your option) any later version
* @version SVN: $Id: class.WINNT.inc.php 699 2012-09-15 11:57:13Z namiltd $
* @link http://phpsysinfo.sourceforge.net
*/
/**
* WINNT sysinfo class
* get all the required information from WINNT systems
* information are retrieved through the WMI interface
*
* @category PHP
* @package PSI WINNT 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 version 2, or (at your option) any later version
* @version Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
class WINNT extends OS
{
/**
* holds the data from WMI Win32_OperatingSystem
*
* @var array
*/
private $_Win32_OperatingSystem = null;
 
class sysinfo {
// $wmi holds the COM object that we pull all the WMI data from
var $wmi;
/**
* holds the data from WMI Win32_ComputerSystem
*
* @var array
*/
private $_Win32_ComputerSystem = null;
 
// $wmidevices holds all devices, which are in the system
var $wmidevices;
/**
* holds the data from WMI Win32_Processor
*
* @var array
*/
private $_Win32_Processor = null;
 
// this constructor initialis the $wmi object
function sysinfo ()
{
// don't set this params for local connection, it will not work
$strHostname = '';
$strUser = '';
$strPassword = '';
/**
* holds the data from WMI Win32_PerfFormattedData_PerfOS_Processor
*
* @var array
*/
private $_Win32_PerfFormattedData_PerfOS_Processor = null;
 
// initialize the wmi object
$objLocator = new COM("WbemScripting.SWbemLocator");
if($strHostname == "") {
$this->wmi = $objLocator->ConnectServer();
} else{
$this->wmi = $objLocator->ConnectServer($strHostname, "rootcimv2", "$strHostname\$strUser", $strPassword);
}
}
/**
* holds the data from systeminfo command
*
* @var string
*/
private $_systeminfo = null;
 
// private function for getting a list of values in the specified context, optionally filter this list, based on the list from second parameter
function _GetWMI($strClass, $strValue = array() ) {
$objWEBM = $this->wmi->Get($strClass);
/**
* holds the COM object that we pull all the WMI data from
*
* @var Object
*/
private $_wmi = null;
 
if( PHP_VERSION < 5 ) {
$objProp = $objWEBM->Properties_;
$arrProp = $objProp->Next($objProp->Count);
$objWEBMCol = $objWEBM->Instances_();
$arrWEBMCol = $objWEBMCol->Next($objWEBMCol->Count);
} else {
$arrProp = $objWEBM->Properties_;
$arrWEBMCol = $objWEBM->Instances_();
/**
* holds the COM object that we pull all the RegRead data from
*
* @var Object
*/
private $_reg = null;
 
/**
* holds the COM object that we pull all the EnumKey data from
*
* @var Object
*/
private $_key = null;
 
/**
* holds all devices, which are in the system
*
* @var array
*/
private $_wmidevices;
 
/**
* holds all disks, which are in the system
*
* @var array
*/
private $_wmidisks;
 
/**
* store language encoding of the system to convert some output to utf-8
*
* @var string
*/
private $_codepage = null;
 
/**
* store language of the system
*
* @var string
*/
private $_syslang = null;
 
/**
* reads the data from WMI Win32_OperatingSystem
*
* @return array
*/
private function _get_Win32_OperatingSystem()
{
if ($this->_Win32_OperatingSystem === null) $this->_Win32_OperatingSystem = CommonFunctions::getWMI($this->_wmi, 'Win32_OperatingSystem', array('CodeSet', 'Locale', 'LastBootUpTime', 'LocalDateTime', 'Version', 'ServicePackMajorVersion', 'Caption', 'OSArchitecture', 'TotalVisibleMemorySize', 'FreePhysicalMemory'));
return $this->_Win32_OperatingSystem;
}
 
foreach($arrWEBMCol as $objItem)
/**
* reads the data from WMI Win32_ComputerSystem
*
* @return array
*/
private function _get_Win32_ComputerSystem()
{
@reset($arrProp);
$arrInstance = array();
foreach($arrProp as $propItem)
{
eval("\$value = \$objItem->" .$propItem->Name .";");
if( empty( $strValue ) ) {
$arrInstance[$propItem->Name] = trim($value);
} else {
if( in_array( $propItem->Name, $strValue ) ) {
$arrInstance[$propItem->Name] = trim($value);
}
if ($this->_Win32_ComputerSystem === null) $this->_Win32_ComputerSystem = CommonFunctions::getWMI($this->_wmi, 'Win32_ComputerSystem', array('Name', 'Manufacturer', 'Model'));
return $this->_Win32_ComputerSystem;
}
 
/**
* reads the data from WMI Win32_Processor
*
* @return array
*/
private function _get_Win32_Processor()
{
if ($this->_Win32_Processor === null) $this->_Win32_Processor = CommonFunctions::getWMI($this->_wmi, 'Win32_Processor', array('LoadPercentage', 'AddressWidth', 'Name', 'L2CacheSize', 'L3CacheSize', 'CurrentClockSpeed', 'ExtClock', 'NumberOfCores', 'NumberOfLogicalProcessors', 'MaxClockSpeed', 'Manufacturer'));
return $this->_Win32_Processor;
}
 
/**
* reads the data from WMI Win32_PerfFormattedData_PerfOS_Processor
*
* @return array
*/
private function _get_Win32_PerfFormattedData_PerfOS_Processor()
{
if ($this->_Win32_PerfFormattedData_PerfOS_Processor === null) {
$this->_Win32_PerfFormattedData_PerfOS_Processor = array();
$buffer = $this->_get_Win32_OperatingSystem();
if ($buffer && isset($buffer[0]) && isset($buffer[0]['Version']) && version_compare($buffer[0]['Version'], "5.1", ">=")) { // minimal windows 2003 or windows XP
$cpubuffer = CommonFunctions::getWMI($this->_wmi, 'Win32_PerfFormattedData_PerfOS_Processor', array('Name', 'PercentProcessorTime'));
if ($cpubuffer) foreach ($cpubuffer as $cpu) {
if (isset($cpu['Name']) && isset($cpu['PercentProcessorTime'])) {
$this->_Win32_PerfFormattedData_PerfOS_Processor['cpu'.$cpu['Name']] = $cpu['PercentProcessorTime'];
}
}
}
}
$arrData[] = $arrInstance;
}
return $arrData;
}
 
// private function for getting different device types from the system
function _devicelist ( $strType ) {
if( empty( $this->wmidevices ) ) {
$this->wmidevices = $this->_GetWMI( "Win32_PnPEntity", array( "Name", "PNPDeviceID" ) );
return $this->_Win32_PerfFormattedData_PerfOS_Processor;
}
 
$list = array();
foreach ( $this->wmidevices as $device ) {
if ( substr( $device["PNPDeviceID"], 0, strpos( $device["PNPDeviceID"], "\\" ) + 1 ) == ( $strType . "\\" ) ) {
$list[] = $device["Name"];
}
/**
* reads the data from systeminfo
*
* @return string
*/
private function _get_systeminfo()
{
if ($this->_systeminfo === null) CommonFunctions::executeProgram('systeminfo', '', $this->_systeminfo, false);
return $this->_systeminfo;
}
 
return $list;
}
// get our apache SERVER_NAME or vhost
function vhostname () {
if (! ($result = getenv('SERVER_NAME'))) {
$result = 'N.A.';
}
return $result;
}
/**
* build the global Error object and create the WMI connection
*/
public function __construct($blockname = false)
{
parent::__construct($blockname);
try {
// initialize the wmi object
$objLocator = new COM('WbemScripting.SWbemLocator');
$this->_wmi = $objLocator->ConnectServer('', 'root\CIMv2');
} catch (Exception $e) {
$this->error->addError("WMI connect error", "PhpSysInfo can not connect to the WMI interface for security reasons.\nCheck an authentication mechanism for the directory where phpSysInfo is installed.");
}
try {
// initialize the RegRead object
$this->_reg = new COM("WScript.Shell");
} catch (Exception $e) {
//$this->error->addError("Windows Scripting Host error", "PhpSysInfo can not initialize Windows Scripting Host for security reasons.\nCheck an authentication mechanism for the directory where phpSysInfo is installed.");
$this->_reg = false;
}
try {
// initialize the EnumKey object
$this->_key = new COM("winmgmts:{impersonationLevel=impersonate}!\\\\.\\root\\default:StdRegProv");
} catch (Exception $e) {
//$this->error->addError("WWinmgmts Impersonationlevel Script Error", "PhpSysInfo can not initialize Winmgmts Impersonationlevel Script for security reasons.\nCheck an authentication mechanism for the directory where phpSysInfo is installed.");
$this->_key = false;
}
 
// get the IP address of our vhost name
function vip_addr () {
return gethostbyname($this->vhostname());
}
$this->_getCodeSet();
}
 
// get our canonical hostname
function chostname ()
{
$buffer = $this->_GetWMI( "Win32_ComputerSystem", array( "Name" ) );
$result = $buffer[0]["Name"];
return gethostbyaddr(gethostbyname($result));
}
/**
* store the codepage of the os for converting some strings to utf-8
*
* @return void
*/
private function _getCodeSet()
{
$buffer = $this->_get_Win32_OperatingSystem();
if (!$buffer) {
if (CommonFunctions::readReg($this->_reg, "HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Nls\\CodePage\\ACP", $strBuf, false)) {
$buffer[0]['CodeSet'] = $strBuf;
}
if (CommonFunctions::readReg($this->_reg, "HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Nls\\Language\\Default", $strBuf, false)) {
$buffer[0]['Locale'] = $strBuf;
}
}
if ($buffer && isset($buffer[0])) {
if (isset($buffer[0]['CodeSet'])) {
$codeset = $buffer[0]['CodeSet'];
if ($codeset == 932) {
$codename = ' (SJIS)';
} elseif ($codeset == 949) {
$codename = ' (EUC-KR)';
} elseif ($codeset == 950) {
$codename = ' (BIG-5)';
} else {
$codename = '';
}
CommonFunctions::setcp($codeset);
$this->_codepage = 'windows-'.$codeset.$codename;
}
if (isset($buffer[0]['Locale']) && (($locale = hexdec($buffer[0]['Locale']))>0)) {
$lang = "";
if (is_readable(PSI_APP_ROOT.'/data/languages.ini') && ($langdata = @parse_ini_file(PSI_APP_ROOT.'/data/languages.ini', true))) {
if (isset($langdata['WINNT'][$locale])) {
$lang = $langdata['WINNT'][$locale];
}
}
if ($lang == "") {
$lang = 'Unknown';
}
$this->_syslang = $lang.' ('.$locale.')';
}
}
}
 
// get the IP address of our canonical hostname
function ip_addr ()
{
$buffer = $this->_GetWMI( "Win32_ComputerSystem", array( "Name" ) );
$result = $buffer[0]["Name"];
return gethostbyname($result);
}
/**
* retrieve different device types from the system based on selector
*
* @param string $strType type of the devices that should be returned
*
* @return array list of devices of the specified type
*/
private function _devicelist($strType)
{
if (empty($this->_wmidevices)) {
if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS) {
$this->_wmidevices = CommonFunctions::getWMI($this->_wmi, 'Win32_PnPEntity', array('Name', 'PNPDeviceID', 'Manufacturer', 'PNPClass'));
if (defined('PSI_SHOW_DEVICES_SERIAL') && PSI_SHOW_DEVICES_SERIAL) {
$this->_wmidisks = CommonFunctions::getWMI($this->_wmi, 'Win32_DiskDrive', array('PNPDeviceID', 'Size', 'SerialNumber'));
} else {
$this->_wmidisks = CommonFunctions::getWMI($this->_wmi, 'Win32_DiskDrive', array('PNPDeviceID', 'Size'));
}
} else {
$this->_wmidevices = CommonFunctions::getWMI($this->_wmi, 'Win32_PnPEntity', array('Name', 'PNPDeviceID'));
$this->_wmidisks = array();
}
}
$list = array();
foreach ($this->_wmidevices as $device) {
if (substr($device['PNPDeviceID'], 0, strpos($device['PNPDeviceID'], "\\") + 1) == ($strType."\\")) {
if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS) {
if (!isset($device['PNPClass']) || ($device['PNPClass']===$strType) || ($device['PNPClass']==='System')) {
$device['PNPClass'] = null;
}
if (preg_match('/^\(.*\)$/', $device['Manufacturer'])) {
$device['Manufacturer'] = null;
}
$device['Capacity'] = null;
if (($strType==='IDE')||($strType==='SCSI')) {
foreach ($this->_wmidisks as $disk) {
if (($disk['PNPDeviceID'] === $device['PNPDeviceID']) && isset($disk['Size'])) {
$device['Capacity'] = $disk['Size'];
break;
}
}
}
$device['Serial'] = null;
if (defined('PSI_SHOW_DEVICES_SERIAL') && PSI_SHOW_DEVICES_SERIAL) {
if ($strType==='USB') {
if (preg_match('/\\\\(\w+)$/', $device['PNPDeviceID'], $buf)) {
$device['Serial'] = $buf[1];
}
} elseif (($strType==='IDE')||($strType==='SCSI')) {
foreach ($this->_wmidisks as $disk) {
if (($disk['PNPDeviceID'] === $device['PNPDeviceID']) && isset($disk['SerialNumber'])) {
$device['Serial'] = $disk['SerialNumber'];
break;
}
}
}
}
$list[] = array('Name'=>$device['Name'], 'Manufacturer'=>$device['Manufacturer'], 'Product'=>$device['PNPClass'], 'Capacity'=>$device['Capacity'], 'Serial'=>$device['Serial']);
} else {
$list[] = array('Name'=>$device['Name']);
}
}
}
 
function kernel ()
{
$buffer = $this->_GetWMI( "Win32_OperatingSystem", array( "Version", "ServicePackMajorVersion" ) );
$result = $buffer[0]["Version"];
if( $buffer[0]["ServicePackMajorVersion"] > 0 ) {
$result .= " SP" . $buffer[0]["ServicePackMajorVersion"];
return $list;
}
return $result;
}
 
// get the time the system is running
function uptime ()
{
$result = 0;
$buffer = $this->_GetWMI( "Win32_OperatingSystem", array( "LastBootUpTime", "LocalDateTime" ) );
/**
* Host Name
*
* @return void
*/
private function _hostname()
{
if (PSI_USE_VHOST === true) {
if (CommonFunctions::readenv('SERVER_NAME', $hnm)) $this->sys->setHostname($hnm);
} else {
$buffer = $this->_get_Win32_ComputerSystem();
if (!$buffer && CommonFunctions::readReg($this->_reg, "HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\ComputerName\\ActiveComputerName\\ComputerName", $strBuf, false) && (strlen($strBuf) > 0)) {
$buffer[0]['Name'] = $strBuf;
}
if ($buffer) {
$result = $buffer[0]['Name'];
$ip = gethostbyname($result);
if ($ip != $result) {
if ((version_compare("10.0.0.0", $ip, "<=") && version_compare($ip, "10.255.255.255", "<=")) ||
(version_compare("172.16.0.0", $ip, "<=") && version_compare($ip, "172.31.255.255", "<=")) ||
(version_compare("192.168.0.0", $ip, "<=") && version_compare($ip, "192.168.255.255", "<=")) ||
(version_compare("127.0.0.0", $ip, "<=") && version_compare($ip, "127.255.255.255", "<=")) ||
(version_compare("169.254.1.0", $ip, "<=") && version_compare($ip, "169.254.254.255", "<=")) ||
(version_compare("255.255.255.255", $ip, "=="))) {
$this->sys->setHostname($result); // internal ip
} else {
$this->sys->setHostname(gethostbyaddr($ip));
}
}
} else {
if (CommonFunctions::readenv('COMPUTERNAME', $hnm)) $this->sys->setHostname($hnm);
}
}
}
 
$byear = intval(substr($buffer[0]["LastBootUpTime"], 0, 4));
$bmonth = intval(substr($buffer[0]["LastBootUpTime"], 4, 2));
$bday = intval(substr($buffer[0]["LastBootUpTime"], 6, 2));
$bhour = intval(substr($buffer[0]["LastBootUpTime"], 8, 2));
$bminute = intval(substr($buffer[0]["LastBootUpTime"], 10, 2));
$bseconds = intval(substr($buffer[0]["LastBootUpTime"], 12, 2));
/**
* UpTime
* time the system is running
*
* @return void
*/
private function _uptime()
{
$result = 0;
date_default_timezone_set('UTC');
$buffer = $this->_get_Win32_OperatingSystem();
if ($buffer && ($buffer[0]['LastBootUpTime'] !== null)) {
$local = $buffer[0]['LocalDateTime'];
$boot = $buffer[0]['LastBootUpTime'];
 
$lyear = intval(substr($buffer[0]["LocalDateTime"], 0, 4));
$lmonth = intval(substr($buffer[0]["LocalDateTime"], 4, 2));
$lday = intval(substr($buffer[0]["LocalDateTime"], 6, 2));
$lhour = intval(substr($buffer[0]["LocalDateTime"], 8, 2));
$lminute = intval(substr($buffer[0]["LocalDateTime"], 10, 2));
$lseconds = intval(substr($buffer[0]["LocalDateTime"], 12, 2));
$lyear = intval(substr($local, 0, 4));
$lmonth = intval(substr($local, 4, 2));
$lday = intval(substr($local, 6, 2));
$lhour = intval(substr($local, 8, 2));
$lminute = intval(substr($local, 10, 2));
$lseconds = intval(substr($local, 12, 2));
$loffset = intval(substr($boot, 21, 4));
 
$boottime = mktime($bhour, $bminute, $bseconds, $bmonth, $bday, $byear);
$localtime = mktime($lhour, $lminute, $lseconds, $lmonth, $lday, $lyear);
$byear = intval(substr($boot, 0, 4));
$bmonth = intval(substr($boot, 4, 2));
$bday = intval(substr($boot, 6, 2));
$bhour = intval(substr($boot, 8, 2));
$bminute = intval(substr($boot, 10, 2));
$bseconds = intval(substr($boot, 12, 2));
$boffset = intval(substr($boot, 21, 4));
 
$result = $localtime - $boottime;
if (version_compare($buffer[0]['Version'], "5.1", "<")) { // fix LastBootUpTime on Windows 2000 and older
$boffset += $boffset;
}
 
return $result;
}
$localtime = mktime($lhour, $lminute, $lseconds, $lmonth, $lday, $lyear) - $loffset*60;
$boottime = mktime($bhour, $bminute, $bseconds, $bmonth, $bday, $byear) - $boffset*60;
 
// count the users, which are logged in
function users ()
{
if( stristr( $this->kernel(), "2000 P" ) ) return "N.A.";
$buffer = $this->_GetWMI( "Win32_PerfRawData_TermService_TerminalServices", array( "TotalSessions" ) );
return $buffer[0]["TotalSessions"];
}
$result = $localtime - $boottime;
 
// get the load of the processors
function loadavg ($bar = false)
{
$buffer = $this->_GetWMI( "Win32_Processor", array( "LoadPercentage" ) );
$cpuload = array();
for( $i = 0; $i < count( $buffer ); $i++ ) {
$cpuload['avg'][] = $buffer[$i]["LoadPercentage"];
$this->sys->setUptime($result);
} elseif (($this->sys->getDistribution()=="ReactOS") && CommonFunctions::executeProgram('uptime', '', $strBuf, false) && (strlen($strBuf) > 0) && preg_match("/^System Up Time:\s+(\d+) days, (\d+) Hours, (\d+) Minutes, (\d+) Seconds/", $strBuf, $ar_buf)) {
$sec = $ar_buf[4];
$min = $ar_buf[3];
$hours = $ar_buf[2];
$days = $ar_buf[1];
$this->sys->setUptime($days * 86400 + $hours * 3600 + $min * 60 + $sec);
}
}
if ($bar) {
$cpuload['cpupercent'] = array_sum( $cpuload['avg'] ) / count( $buffer );
 
/**
* Number of Users
*
* @return void
*/
protected function _users()
{
if (CommonFunctions::executeProgram('quser', '', $strBuf, false) && (strlen($strBuf) > 0)) {
$lines = preg_split('/\n/', $strBuf);
$users = count($lines)-1;
} else {
$users = 0;
$buffer = CommonFunctions::getWMI($this->_wmi, 'Win32_Process', array('Caption'));
foreach ($buffer as $process) {
if (strtoupper($process['Caption']) == strtoupper('explorer.exe')) {
$users++;
}
}
}
$this->sys->setUsers($users);
}
return $cpuload;
}
 
// get some informations about the cpu's
function cpu_info ()
{
$buffer = $this->_GetWMI( "Win32_Processor", array( "Name", "L2CacheSize", "CurrentClockSpeed", "ExtClock" ) );
$results["cpus"] = 0;
foreach ($buffer as $cpu) {
$results["cpus"]++;
$results["model"] = $cpu["Name"];
$results["cache"] = $cpu["L2CacheSize"];
$results["cpuspeed"] = $cpu["CurrentClockSpeed"];
$results["busspeed"] = $cpu["ExtClock"];
}
return $results;
}
/**
* Distribution
*
* @return void
*/
private function _distro()
{
$buffer = $this->_get_Win32_OperatingSystem();
if ($buffer) {
$ver = $buffer[0]['Version'];
$kernel = $ver;
if ($buffer[0]['ServicePackMajorVersion'] > 0) {
$kernel .= ' SP'.$buffer[0]['ServicePackMajorVersion'];
}
if (isset($buffer[0]['OSArchitecture']) && preg_match("/^(\d+)/", $buffer[0]['OSArchitecture'], $bits)) {
$this->sys->setKernel($kernel.' ('.$bits[1].'-bit)');
} elseif (($allCpus = $this->_get_Win32_Processor()) && isset($allCpus[0]['AddressWidth'])) {
$this->sys->setKernel($kernel.' ('.$allCpus[0]['AddressWidth'].'-bit)');
} else {
$this->sys->setKernel($kernel);
}
$this->sys->setDistribution($buffer[0]['Caption']);
 
// get the pci devices from the system
function pci ()
{
$pci = $this->_devicelist( "PCI" );
return $pci;
}
if (version_compare($ver, "5.1", "<"))
$icon = 'Win2000.png';
elseif (version_compare($ver, "5.1", ">=") && version_compare($ver, "6.0", "<"))
$icon = 'WinXP.png';
elseif (version_compare($ver, "6.0", ">=") && version_compare($ver, "6.2", "<"))
$icon = 'WinVista.png';
else
$icon = 'Win8.png';
$this->sys->setDistributionIcon($icon);
} elseif (CommonFunctions::executeProgram('cmd', '/c ver 2>nul', $ver_value, false)) {
if (preg_match("/ReactOS\r?\nVersion\s+(.+)/", $ver_value, $ar_temp)) {
$this->sys->setDistribution("ReactOS");
$this->sys->setKernel($ar_temp[1]);
$this->sys->setDistributionIcon('ReactOS.png');
$this->_wmi = false; // No WMI info on ReactOS yet
} elseif (preg_match("/^(Microsoft [^\[]*)\s*\[\D*\s*(.+)\]/", $ver_value, $ar_temp)) {
if (CommonFunctions::readReg($this->_reg, "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProductName", $strBuf, false) && (strlen($strBuf) > 0)) {
if (preg_match("/^Microsoft /", $strBuf)) {
$this->sys->setDistribution($strBuf);
} else {
$this->sys->setDistribution("Microsoft ".$strBuf);
}
} else {
$this->sys->setDistribution($ar_temp[1]);
}
$kernel = $ar_temp[2];
$this->sys->setKernel($kernel);
if ((($kernel[1] == '.') && ($kernel[0] <5)) || (substr($kernel, 0, 4) == '5.0.'))
$icon = 'Win2000.png';
elseif ((substr($kernel, 0, 4) == '6.0.') || (substr($kernel, 0, 4) == '6.1.'))
$icon = 'WinVista.png';
elseif ((substr($kernel, 0, 4) == '6.2.') || (substr($kernel, 0, 4) == '6.3.') || (substr($kernel, 0, 4) == '6.4.') || (substr($kernel, 0, 5) == '10.0.'))
$icon = 'Win8.png';
else
$icon = 'WinXP.png';
$this->sys->setDistributionIcon($icon);
} else {
$this->sys->setDistribution("WinNT");
$this->sys->setDistributionIcon('Win2000.png');
}
} else {
$this->sys->setDistribution("WinNT");
$this->sys->setDistributionIcon('Win2000.png');
}
}
 
// get the ide devices from the system
function ide ()
{
$buffer = $this->_devicelist( "IDE" );
$ide = array();
foreach ( $buffer as $device ) {
$ide[]['model'] = $device;
}
return $ide;
}
/**
* Processor Load
* optionally create a loadbar
*
* @return void
*/
private function _loadavg()
{
if (($cpubuffer = $this->_get_Win32_PerfFormattedData_PerfOS_Processor()) && isset($cpubuffer['cpu_Total'])) {
$this->sys->setLoad($cpubuffer['cpu_Total']);
if (PSI_LOAD_BAR) {
$this->sys->setLoadPercent($cpubuffer['cpu_Total']);
}
} elseif ($buffer = $this->_get_Win32_Processor()) {
$loadok = true;
$sum = 0;
foreach ($buffer as $load) {
$value = $load['LoadPercentage'];
if ($value !== null) {
$sum += $value;
} else {
$loadok = false;
break;
}
}
if ($loadok) {
$percent = $sum / count($buffer);
$this->sys->setLoad($percent);
if (PSI_LOAD_BAR) {
$this->sys->setLoadPercent($percent);
}
}
}
}
 
// get the scsi devices from the system
function scsi ()
{
$scsi = $this->_devicelist( "SCSI" );
return $scsi;
}
/**
* CPU information
*
* @return void
*/
private function _cpuinfo()
{
$allCpus = $this->_get_Win32_Processor();
if (!$allCpus) {
$hkey = "HKEY_LOCAL_MACHINE\\HARDWARE\\DESCRIPTION\\System\\CentralProcessor";
if (CommonFunctions::enumKey($this->_key, $hkey, $arrBuf, false)) {
foreach ($arrBuf as $coreCount) {
if (CommonFunctions::readReg($this->_reg, $hkey."\\".$coreCount."\\ProcessorNameString", $strBuf, false)) {
$allCpus[$coreCount]['Name'] = $strBuf;
}
if (CommonFunctions::readReg($this->_reg, $hkey."\\".$coreCount."\\~MHz", $strBuf, false)) {
if (preg_match("/^0x([0-9a-f]+)$/i", $strBuf, $hexvalue)) {
$allCpus[$coreCount]['CurrentClockSpeed'] = hexdec($hexvalue[1]);
}
}
if (CommonFunctions::readReg($this->_reg, $hkey."\\".$coreCount."\\VendorIdentifier", $strBuf, false)) {
$allCpus[$coreCount]['Manufacturer'] = $strBuf;
}
}
}
}
 
// get the usb devices from the system
function usb ()
{
$usb = $this->_devicelist( "USB" );
return $usb;
}
$globalcpus = 0;
foreach ($allCpus as $oneCpu) {
$cpuCount = 1;
if (isset($oneCpu['NumberOfLogicalProcessors'])) {
$cpuCount = $oneCpu['NumberOfLogicalProcessors'];
} elseif (isset($oneCpu['NumberOfCores'])) {
$cpuCount = $oneCpu['NumberOfCores'];
}
$globalcpus+=$cpuCount;
}
 
// get the sbus devices from the system - currently not called
function sbus ()
{
$sbus = $this->_devicelist( "SBUS" );
return $sbus;
}
foreach ($allCpus as $oneCpu) {
$cpuCount = 1;
if (isset($oneCpu['NumberOfLogicalProcessors'])) {
$cpuCount = $oneCpu['NumberOfLogicalProcessors'];
} elseif (isset($oneCpu['NumberOfCores'])) {
$cpuCount = $oneCpu['NumberOfCores'];
}
for ($i = 0; $i < $cpuCount; $i++) {
$cpu = new CpuDevice();
if (isset($oneCpu['Name'])) $cpu->setModel($oneCpu['Name']);
if (isset($oneCpu['L3CacheSize']) && ($oneCpu['L3CacheSize'] > 0)) {
$cpu->setCache($oneCpu['L3CacheSize'] * 1024);
} elseif (isset($oneCpu['L2CacheSize'])) {
$cpu->setCache($oneCpu['L2CacheSize'] * 1024);
}
if (isset($oneCpu['CurrentClockSpeed'])) {
$cpu->setCpuSpeed($oneCpu['CurrentClockSpeed']);
if (isset($oneCpu['MaxClockSpeed']) && ($oneCpu['CurrentClockSpeed'] < $oneCpu['MaxClockSpeed'])) $cpu->setCpuSpeedMax($oneCpu['MaxClockSpeed']);
}
if (isset($oneCpu['ExtClock'])) $cpu->setBusSpeed($oneCpu['ExtClock']);
if (isset($oneCpu['Manufacturer'])) $cpu->setVendorId($oneCpu['Manufacturer']);
if (PSI_LOAD_BAR) {
if (($cpubuffer = $this->_get_Win32_PerfFormattedData_PerfOS_Processor()) && (count($cpubuffer) == ($globalcpus+1)) && isset($cpubuffer['cpu'.$i])) {
$cpu->setLoad($cpubuffer['cpu'.$i]);
} elseif ((count($allCpus) == $globalcpus) && isset($oneCpu['LoadPercentage'])) {
$cpu->setLoad($oneCpu['LoadPercentage']);
}
}
$this->sys->setCpus($cpu);
}
}
}
 
// get the netowrk devices and rx/tx bytes
function network () {
$results = array();
$buffer = $this->_GetWMI( "Win32_PerfRawData_Tcpip_NetworkInterface" );
foreach( $buffer as $device ) {
$dev_name = $device["Name"];
// http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/win32_perfrawdata_tcpip_networkinterface.asp
// there is a possible bug in the wmi interfaceabout uint32 and uint64: http://www.ureader.com/message/1244948.aspx, so that
// magative numbers would occour, try to calculate the nagative value from total - positive number
if( $device["BytesSentPersec"] < 0) {
$results[$dev_name]['tx_bytes'] = $device["BytesTotalPersec"] - $device["BytesReceivedPersec"];
} else {
$results[$dev_name]['tx_bytes'] = $device["BytesSentPersec"];
}
if( $device["BytesReceivedPersec"] < 0 ) {
$results[$dev_name]['rx_bytes'] = $device["BytesTotalPersec"] - $device["BytesSentPersec"];
} else {
$results[$dev_name]['rx_bytes'] = $device["BytesReceivedPersec"];
}
$results[$dev_name]['rx_packets'] = $device["PacketsReceivedPersec"];
$results[$dev_name]['tx_packets'] = $device["PacketsSentPersec"];
$results[$dev_name]['rx_errs'] = $device["PacketsReceivedErrors"];
$results[$dev_name]['rx_drop'] = $device["PacketsReceivedDiscarded"];
$results[$dev_name]['errs'] = $device["PacketsReceivedErrors"];
$results[$dev_name]['drop'] = $device["PacketsReceivedDiscarded"];
}
return $results;
}
/**
* Machine information
*
* @return void
*/
private function _machine()
{
$buffer = $this->_get_Win32_ComputerSystem();
if ($buffer) {
$buf = "";
if (isset($buffer[0]['Manufacturer']) && !preg_match("/^To be filled by O\.E\.M\.$|^System manufacturer$|^Not Specified$/i", $buf2=$buffer[0]['Manufacturer'])) {
$buf .= ' '.$buf2;
}
 
function memory ()
{
$buffer = $this->_GetWMI( "Win32_LogicalMemoryConfiguration", array( "TotalPhysicalMemory" ) );
$results['ram']['total'] = $buffer[0]["TotalPhysicalMemory"];
if (isset($buffer[0]['Model']) && !preg_match("/^To be filled by O\.E\.M\.$|^System Product Name$|^Not Specified$/i", $buf2=$buffer[0]['Model'])) {
$buf .= ' '.$buf2;
}
if (trim($buf) != "") {
$this->sys->setMachine(trim($buf));
}
}
}
 
$buffer = $this->_GetWMI( "Win32_PerfRawData_PerfOS_Memory", array( "AvailableKBytes" ) );
$results['ram']['free'] = $buffer[0]["AvailableKBytes"];
/**
* Hardwaredevices
*
* @return void
*/
private function _hardware()
{
foreach ($this->_devicelist('PCI') as $pciDev) {
$dev = new HWDevice();
$dev->setName($pciDev['Name']);
if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS) {
$dev->setManufacturer($pciDev['Manufacturer']);
$dev->setProduct($pciDev['Product']);
}
$this->sys->setPciDevices($dev);
}
 
$results['ram']['used'] = $results['ram']['total'] - $results['ram']['free'];
$results['ram']['percent'] = ceil( ( $results['ram']['used'] * 100 ) / $results['ram']['total'] );
$results['swap']['total'] = 0;
$results['swap']['used'] = 0;
$results['swap']['free'] = 0;
foreach ($this->_devicelist('IDE') as $ideDev) {
$dev = new HWDevice();
$dev->setName($ideDev['Name']);
if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS) {
$dev->setCapacity($ideDev['Capacity']);
if (defined('PSI_SHOW_DEVICES_SERIAL') && PSI_SHOW_DEVICES_SERIAL) {
$dev->setSerial($ideDev['Serial']);
}
}
$this->sys->setIdeDevices($dev);
}
 
$buffer = $this->_GetWMI( "Win32_PageFileUsage" ); // no need to filter, using nearly everything from output
$k = 0;
foreach ($buffer as $swapdevice) {
$results['devswap'][$k]['dev'] = $swapdevice["Name"];
$results['devswap'][$k]['total'] = $swapdevice["AllocatedBaseSize"] * 1024;
$results['devswap'][$k]['used'] = $swapdevice["CurrentUsage"] * 1024;
$results['devswap'][$k]['free'] = ( $swapdevice["AllocatedBaseSize"] - $swapdevice["CurrentUsage"] ) * 1024;
$results['devswap'][$k]['percent'] = ceil( $swapdevice["CurrentUsage"] / $swapdevice["AllocatedBaseSize"] );
foreach ($this->_devicelist('SCSI') as $scsiDev) {
$dev = new HWDevice();
$dev->setName($scsiDev['Name']);
if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS) {
$dev->setCapacity($scsiDev['Capacity']);
if (defined('PSI_SHOW_DEVICES_SERIAL') && PSI_SHOW_DEVICES_SERIAL) {
$dev->setSerial($scsiDev['Serial']);
}
}
$this->sys->setScsiDevices($dev);
}
 
$results['swap']['total'] += $results['devswap'][$k]['total'];
$results['swap']['used'] += $results['devswap'][$k]['used'];
$results['swap']['free'] += $results['devswap'][$k]['free'];
$k += 1;
}
$results['swap']['percent'] = ceil( $results['swap']['used'] / $results['swap']['total'] * 100 );
return $results;
}
foreach ($this->_devicelist('USB') as $usbDev) {
$dev = new HWDevice();
$dev->setName($usbDev['Name']);
if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS) {
$dev->setManufacturer($usbDev['Manufacturer']);
$dev->setProduct($usbDev['Product']);
if (defined('PSI_SHOW_DEVICES_SERIAL') && PSI_SHOW_DEVICES_SERIAL) {
$dev->setSerial($usbDev['Serial']);
}
}
$this->sys->setUsbDevices($dev);
}
}
 
// get the filesystem informations
function filesystems ()
{
$typearray = array("Unknown", "No Root Directory", "Removeable Disk",
"Local Disk", "Network Drive", "Compact Disc", "RAM Disk");
$floppyarray = array("Unknown", "5 1/4 in.", "3 1/2 in.", "3 1/2 in.",
"3 1/2 in.", "3 1/2 in.", "5 1/4 in.", "5 1/4 in.", "5 1/4 in.",
"5 1/4 in.", "5 1/4 in.", "Other", "HD", "3 1/2 in.", "3 1/2 in.",
"5 1/4 in.", "5 1/4 in.", "3 1/2 in.", "3 1/2 in.", "5 1/4 in.",
"3 1/2 in.", "3 1/2 in.", "8 in.");
/**
* Network devices
*
* @return void
*/
private function _network()
{
if ($this->_wmi) {
$buffer = $this->_get_Win32_OperatingSystem();
if ($buffer && isset($buffer[0]) && isset($buffer[0]['Version']) && version_compare($buffer[0]['Version'], "6.2", ">=")) { // minimal windows 2012 or windows 8
$allDevices = CommonFunctions::getWMI($this->_wmi, 'Win32_PerfRawData_Tcpip_NetworkAdapter', array('Name', 'BytesSentPersec', 'BytesTotalPersec', 'BytesReceivedPersec', 'PacketsReceivedErrors', 'PacketsReceivedDiscarded', 'CurrentBandwidth'));
} else {
$allDevices = CommonFunctions::getWMI($this->_wmi, 'Win32_PerfRawData_Tcpip_NetworkInterface', array('Name', 'BytesSentPersec', 'BytesTotalPersec', 'BytesReceivedPersec', 'PacketsReceivedErrors', 'PacketsReceivedDiscarded', 'CurrentBandwidth'));
}
if ($allDevices) {
$aliases = array();
$hkey = "HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Network\\{4D36E972-E325-11CE-BFC1-08002BE10318}";
if (CommonFunctions::enumKey($this->_key, $hkey, $arrBuf, false)) {
foreach ($arrBuf as $netID) {
if (CommonFunctions::readReg($this->_reg, $hkey."\\".$netID."\\Connection\\PnPInstanceId", $strInstanceID, false)) { //a w Name jest net alias
if (CommonFunctions::readReg($this->_reg, "HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Enum\\".$strInstanceID."\\FriendlyName", $strName, false)) {
$cname = str_replace(array('(', ')', '#'), array('[', ']', '_'), $strName); //convert to canonical
if (!isset($aliases[$cname])) { // duplicate checking
$aliases[$cname]['id'] = $netID;
$aliases[$cname]['name'] = $strName;
if (CommonFunctions::readReg($this->_reg, $hkey."\\".$netID."\\Connection\\Name", $strCName, false)
&& (str_replace(array('(', ')', '#'), array('[', ']', '_'), $strCName) !== $cname)) {
$aliases[$cname]['netname'] = $strCName;
}
} else {
$aliases[$cname]['id'] = '';
}
}
}
}
}
 
$buffer = $this->_GetWMI( "Win32_LogicalDisk" , array( "Name", "Size", "FreeSpace", "FileSystem", "DriveType", "MediaType" ) );
$aliases2 = array();
$hkey = "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\NetworkCards";
if (CommonFunctions::enumKey($this->_key, $hkey, $arrBuf, false)) {
foreach ($arrBuf as $netCount) {
if (CommonFunctions::readReg($this->_reg, $hkey."\\".$netCount."\\Description", $strName, false)
&& CommonFunctions::readReg($this->_reg, $hkey."\\".$netCount."\\ServiceName", $strGUID, false)) {
$cname = str_replace(array('(', ')', '#'), array('[', ']', '_'), $strName); //convert to canonical
if (!isset($aliases2[$cname])) { // duplicate checking
$aliases2[$cname]['id'] = $strGUID;
$aliases2[$cname]['name'] = $strName;
} else {
$aliases2[$cname]['id'] = '';
}
}
}
}
 
$k = 0;
foreach ( $buffer as $filesystem ) {
if ( hide_mount( $filesystem["Name"] ) ) {
continue;
}
$results[$k]['mount'] = $filesystem["Name"];
$results[$k]['size'] = $filesystem["Size"] / 1024;
$results[$k]['used'] = ( $filesystem["Size"] - $filesystem["FreeSpace"] ) / 1024;
$results[$k]['free'] = $filesystem["FreeSpace"] / 1024;
@$results[$k]['percent'] = ceil( $results[$k]['used'] / $results[$k]['size'] * 100 ); // silence this line, nobody is having a floppy in the drive everytime
$results[$k]['fstype'] = $filesystem["FileSystem"];
$results[$k]['disk'] = $typearray[$filesystem["DriveType"]];
if ( $filesystem["MediaType"] != "" && $filesystem["DriveType"] == 2 ) $results[$k]['disk'] .= " (" . $floppyarray[$filesystem["MediaType"]] . ")";
$k += 1;
}
return $results;
}
$allNetworkAdapterConfigurations = CommonFunctions::getWMI($this->_wmi, 'Win32_NetworkAdapterConfiguration', array('SettingID', /*'Description',*/ 'MACAddress', 'IPAddress'));
foreach ($allDevices as $device) if (!preg_match('/^WAN Miniport \[/', $device['Name'])) {
$dev = new NetDevice();
$name = $device['Name'];
 
function distro ()
{
$buffer = $this->_GetWMI( "Win32_OperatingSystem", array( "Caption" ) );
return $buffer[0]["Caption"];
}
if (preg_match('/^isatap\.({[A-Fa-f0-9\-]*})/', $name)) {
$dev->setName("Microsoft ISATAP Adapter");
} else {
if (preg_match('/\s-\s([^-]*)$/', $name, $ar_name)) {
$name=substr($name, 0, strlen($name)-strlen($ar_name[0]));
}
$dev->setName($name);
}
 
function distroicon ()
{
return 'xp.gif';
}
}
$macexist = false;
if (((($ali=$aliases) && isset($ali[$name])) || (($ali=$aliases2) && isset($ali[$name]))) && isset($ali[$name]['id']) && ($ali[$name]['id'] !== "")) {
foreach ($allNetworkAdapterConfigurations as $NetworkAdapterConfiguration) {
if ($ali[$name]['id']==$NetworkAdapterConfiguration['SettingID']) {
$mininame = $ali[$name]['name'];
if (preg_match('/^isatap\.({[A-Fa-f0-9\-]*})/', $mininame))
$mininame="Microsoft ISATAP Adapter";
elseif (preg_match('/\s-\s([^-]*)$/', $mininame, $ar_name))
$name=substr($mininame, 0, strlen($mininame)-strlen($ar_name[0]));
$dev->setName($mininame);
if (trim($NetworkAdapterConfiguration['MACAddress']) !== "") $macexist = true;
if (defined('PSI_SHOW_NETWORK_INFOS') && PSI_SHOW_NETWORK_INFOS) {
if (isset($ali[$name]['netname'])) $dev->setInfo(str_replace(';', ':', $ali[$name]['netname']));
if ((!defined('PSI_HIDE_NETWORK_MACADDR') || !PSI_HIDE_NETWORK_MACADDR)
&& (trim($NetworkAdapterConfiguration['MACAddress']) !== "")) $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').str_replace(':', '-', strtoupper($NetworkAdapterConfiguration['MACAddress'])));
if (isset($NetworkAdapterConfiguration['IPAddress']))
foreach ($NetworkAdapterConfiguration['IPAddress'] as $ipaddres)
if (($ipaddres != "0.0.0.0") && ($ipaddres != "::") && !preg_match('/^fe80::/i', $ipaddres))
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').strtolower($ipaddres));
}
 
?>
break;
}
}
}
 
if ($macexist
// || ($device['CurrentBandwidth'] >= 1000000)
|| ($device['BytesTotalPersec'] != 0)
|| ($device['BytesSentPersec'] != 0)
|| ($device['BytesReceivedPersec'] != 0)
|| ($device['PacketsReceivedErrors'] != 0)
|| ($device['PacketsReceivedDiscarded'] != 0)) { // hide unused
if (defined('PSI_SHOW_NETWORK_INFOS') && PSI_SHOW_NETWORK_INFOS) {
if (($speedinfo = $device['CurrentBandwidth']) >= 1000000) {
if ($speedinfo > 1000000000) {
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').round($speedinfo/1000000000, 2)."Gb/s");
} else {
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').round($speedinfo/1000000, 2)."Mb/s");
}
}
}
 
// http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/win32_perfrawdata_tcpip_networkinterface.asp
// there is a possible bug in the wmi interfaceabout uint32 and uint64: http://www.ureader.com/message/1244948.aspx, so that
// magative numbers would occour, try to calculate the nagative value from total - positive number
$txbytes = $device['BytesSentPersec'];
$rxbytes = $device['BytesReceivedPersec'];
if (($txbytes < 0) && ($rxbytes < 0)) {
$txbytes += 4294967296;
$rxbytes += 4294967296;
} elseif ($txbytes < 0) {
if ($device['BytesTotalPersec'] > $rxbytes)
$txbytes = $device['BytesTotalPersec'] - $rxbytes;
else
$txbytes += 4294967296;
} elseif ($rxbytes < 0) {
if ($device['BytesTotalPersec'] > $txbytes)
$rxbytes = $device['BytesTotalPersec'] - $txbytes;
else
$rxbytes += 4294967296;
}
$dev->setTxBytes($txbytes);
$dev->setRxBytes($rxbytes);
$dev->setErrors($device['PacketsReceivedErrors']);
$dev->setDrops($device['PacketsReceivedDiscarded']);
 
$this->sys->setNetDevices($dev);
}
}
}
} elseif (($buffer = $this->_get_systeminfo()) && preg_match('/^(\s+)\[\d+\]:[^\r\n]+\r\n\s+[^\s\[]/m', $buffer, $matches, PREG_OFFSET_CAPTURE)) {
$netbuf = substr($buffer, $matches[0][1]);
if (preg_match('/^[^\s]/m', $netbuf, $matches2, PREG_OFFSET_CAPTURE)) {
$netbuf = substr($netbuf, 0, $matches2[0][1]);
}
$netstrs = preg_split('/^'.$matches[1][0].'\[\d+\]:/m', $netbuf, -1, PREG_SPLIT_NO_EMPTY);
$devnr = 0;
foreach ($netstrs as $netstr) {
$netstrls = preg_split('/\r\n/', $netstr, -1, PREG_SPLIT_NO_EMPTY);
if (sizeof($netstrls)>1) {
$dev = new NetDevice();
foreach ($netstrls as $nr=>$netstrl) {
if ($nr === 0) {
$name = trim($netstrl);
if ($name !== "") {
$dev->setName($name);
} else {
$dev->setName('dev'.$devnr);
$devnr++;
}
} elseif (preg_match('/\[\d+\]:\s+(.+)/', $netstrl, $netinfo)) {
$ipaddres = trim($netinfo[1]);
if (($ipaddres!="0.0.0.0") && !preg_match('/^fe80::/i', $ipaddres))
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').strtolower($ipaddres));
}
}
$this->sys->setNetDevices($dev);
}
}
}
}
 
/**
* Physical memory information and Swap Space information
*
* @link http://msdn2.microsoft.com/En-US/library/aa394239.aspx
* @link http://msdn2.microsoft.com/en-us/library/aa394246.aspx
* @return void
*/
private function _memory()
{
if ($this->_wmi) {
$buffer = $this->_get_Win32_OperatingSystem();
if ($buffer) {
$this->sys->setMemTotal($buffer[0]['TotalVisibleMemorySize'] * 1024);
$this->sys->setMemFree($buffer[0]['FreePhysicalMemory'] * 1024);
$this->sys->setMemUsed($this->sys->getMemTotal() - $this->sys->getMemFree());
}
$buffer = CommonFunctions::getWMI($this->_wmi, 'Win32_PageFileUsage');
foreach ($buffer as $swapdevice) {
$dev = new DiskDevice();
$dev->setName("SWAP");
$dev->setMountPoint($swapdevice['Name']);
$dev->setTotal($swapdevice['AllocatedBaseSize'] * 1024 * 1024);
$dev->setUsed($swapdevice['CurrentUsage'] * 1024 * 1024);
$dev->setFree($dev->getTotal() - $dev->getUsed());
$dev->setFsType('swap');
$this->sys->setSwapDevices($dev);
}
} elseif (($buffer = $this->_get_systeminfo()) && preg_match("/:\s([\d \xFF]+)\sMB\r\n.+:\s([\d \xFF]+)\sMB\r\n.+:\s([\d \xFF]+)\sMB\r\n.+:\s([\d \xFF]+)\sMB\r\n.+\s([\d \xFF]+)\sMB\r\n/m", $buffer, $buffer2)) {
// && (preg_match("/:\s([\d \xFF]+)\sMB\r\n.+:\s([\d \xFF]+)\sMB\r\n.+:\s([\d \xFF]+)\sMB\r\n.+:\s([\d \xFF]+)\sMB\r\n.+\s([\d \xFF]+)\sMB\r\n.*:\s+(\S+)\r\n/m", $buffer, $buffer2)) {
$this->sys->setMemTotal(preg_replace('/(\s)|(\xFF)/', '', $buffer2[1]) * 1024 * 1024);
$this->sys->setMemFree(preg_replace('/(\s)|(\xFF)/', '', $buffer2[2]) * 1024 * 1024);
$this->sys->setMemUsed($this->sys->getMemTotal() - $this->sys->getMemFree());
}
}
 
/**
* filesystem information
*
* @return void
*/
private function _filesystems()
{
$typearray = array('Unknown', 'No Root Directory', 'Removable Disk', 'Local Disk', 'Network Drive', 'Compact Disc', 'RAM Disk');
$floppyarray = array('Unknown', '5 1/4 in.', '3 1/2 in.', '3 1/2 in.', '3 1/2 in.', '3 1/2 in.', '5 1/4 in.', '5 1/4 in.', '5 1/4 in.', '5 1/4 in.', '5 1/4 in.', 'Other', 'HD', '3 1/2 in.', '3 1/2 in.', '5 1/4 in.', '5 1/4 in.', '3 1/2 in.', '3 1/2 in.', '5 1/4 in.', '3 1/2 in.', '3 1/2 in.', '8 in.');
$buffer = CommonFunctions::getWMI($this->_wmi, 'Win32_LogicalDisk', array('Name', 'Size', 'FreeSpace', 'FileSystem', 'DriveType', 'MediaType'));
foreach ($buffer as $filesystem) {
$dev = new DiskDevice();
$dev->setMountPoint($filesystem['Name']);
$dev->setFsType($filesystem['FileSystem']);
if ($filesystem['Size'] > 0) {
$dev->setTotal($filesystem['Size']);
$dev->setFree($filesystem['FreeSpace']);
$dev->setUsed($filesystem['Size'] - $filesystem['FreeSpace']);
}
if ($filesystem['MediaType'] != "" && $filesystem['DriveType'] == 2) {
$dev->setName($typearray[$filesystem['DriveType']]." (".$floppyarray[$filesystem['MediaType']].")");
} else {
$dev->setName($typearray[$filesystem['DriveType']]);
}
$this->sys->setDiskDevices($dev);
}
if (!$buffer && ($this->sys->getDistribution()=="ReactOS")) {
// test for command 'free' on current disk
if (CommonFunctions::executeProgram('cmd', '/c free 2>nul', $out_value, true)) {
for ($letter='A'; $letter!='AA'; $letter++) if (CommonFunctions::executeProgram('cmd', '/c free '.$letter.': 2>nul', $out_value, false)) {
$values = preg_replace('/[^\d\n]/', '', $out_value);
if (preg_match('/\n(\d+)\n(\d+)\n(\d+)$/', $values, $out_dig)) {
$size = $out_dig[1];
$used = $out_dig[2];
$free = $out_dig[3];
if ($used + $free == $size) {
$dev = new DiskDevice();
$dev->setMountPoint($letter.":");
$dev->setFsType('Unknown');
$dev->setName('Unknown');
$dev->setTotal($size);
$dev->setUsed($used);
$dev->setFree($free);
$this->sys->setDiskDevices($dev);
}
}
}
}
}
}
 
/**
* get os specific encoding
*
* @see OS::getEncoding()
*
* @return string
*/
public function getEncoding()
{
return $this->_codepage;
}
 
/**
* get os specific language
*
* @see OS::getLanguage()
*
* @return string
*/
public function getLanguage()
{
return $this->_syslang;
}
 
public function _processes()
{
$processes['*'] = 0;
if (CommonFunctions::executeProgram('qprocess', '*', $strBuf, false) && (strlen($strBuf) > 0)) {
$lines = preg_split('/\n/', $strBuf);
$processes['*'] = (count($lines)-1) - 3 ; //correction for process "qprocess *"
}
if ($processes['*'] <= 0) {
$buffer = CommonFunctions::getWMI($this->_wmi, 'Win32_Process', array('Caption'));
$processes['*'] = count($buffer);
}
$processes[' '] = $processes['*'];
$this->sys->setProcesses($processes);
}
 
/**
* get the information
*
* @see PSI_Interface_OS::build()
*
* @return Void
*/
public function build()
{
$this->_distro(); //share getDistribution()
if ($this->sys->getDistribution()=="ReactOS") {
$this->error->addError("WARN", "The ReactOS version of phpSysInfo is a work in progress, some things currently don't work");
}
if (!$this->blockname || $this->blockname==='vitals') {
$this->_hostname();
$this->_users();
$this->_uptime();
$this->_loadavg();
$this->_processes();
}
if (!$this->blockname || $this->blockname==='network') {
$this->_network();
}
if (!$this->blockname || $this->blockname==='hardware') {
$this->_machine();
$this->_cpuinfo();
$this->_hardware();
}
if (!$this->blockname || $this->blockname==='filesystem') {
$this->_filesystems();
}
if (!$this->blockname || $this->blockname==='memory') {
$this->_memory();
}
}
}
/web/acc/phpsysinfo/includes/xml/hardware.php
File deleted
/web/acc/phpsysinfo/includes/xml/memory.php
File deleted
/web/acc/phpsysinfo/includes/xml/network.php
File deleted
/web/acc/phpsysinfo/includes/xml/mbinfo.php
File deleted
/web/acc/phpsysinfo/includes/xml/portail.php
File deleted
Property changes:
Deleted: svn:keywords
-Id Date Author
\ No newline at end of property
/web/acc/phpsysinfo/includes/xml/utilisateur.php.2
File deleted
/web/acc/phpsysinfo/includes/xml/vitals.php
File deleted
/web/acc/phpsysinfo/includes/xml/filesystems.php
File deleted
/web/acc/phpsysinfo/includes/xml/hddtemp.php
File deleted
/web/acc/phpsysinfo/includes/xml/class.SimpleXMLExtended.inc.php
0,0 → 1,227
<?php
/**
* modified XML Element
*
* PHP version 5
*
* @category PHP
* @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 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
*/
/**
* class extends the SimpleXML element for including some special functions, like encoding stuff and cdata support
*
* @category PHP
* @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 version 2, or (at your option) any later version
* @version Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
class SimpleXMLExtended
{
/**
* store the encoding that is used for conversation to utf8
*
* @var String base encoding
*/
private $_encoding = null;
 
/**
* SimpleXMLElement to which every call is delegated
*
* @var SimpleXMLElement delegated SimpleXMLElement
*/
private $_SimpleXmlElement = null;
 
/**
* _CP437toUTF8Table for code page conversion for CP437
*
* @var array _CP437toUTF8Table array
*/
private static $_CP437toUTF8Table = array(
"\xC3\x87","\xC3\xBC","\xC3\xA9","\xC3\xA2",
"\xC3\xA4","\xC3\xA0","\xC3\xA5","\xC3\xA7",
"\xC3\xAA","\xC3\xAB","\xC3\xA8","\xC3\xAF",
"\xC3\xAE","\xC3\xAC","\xC3\x84","\xC3\x85",
"\xC3\x89","\xC3\xA6","\xC3\x86","\xC3\xB4",
"\xC3\xB6","\xC3\xB2","\xC3\xBB","\xC3\xB9",
"\xC3\xBF","\xC3\x96","\xC3\x9C","\xC3\xA2",
"\xC2\xA3","\xC3\xA5","\xE2\x82\xA7","\xC6\x92",
"\xC3\xA1","\xC3\xAD","\xC3\xB3","\xC3\xBA",
"\xC3\xB1","\xC3\x91","\xC2\xAA","\xC2\xBA",
"\xC2\xBF","\xE2\x8C\x90","\xC2\xAC","\xC2\xBD",
"\xC2\xBC","\xC2\xA1","\xC2\xAB","\xC2\xBB",
"\xE2\x96\x91","\xE2\x96\x92","\xE2\x96\x93","\xE2\x94\x82",
"\xE2\x94\xA4","\xE2\x95\xA1","\xE2\x95\xA2","\xE2\x95\x96",
"\xE2\x95\x95","\xE2\x95\xA3","\xE2\x95\x91","\xE2\x95\x97",
"\xE2\x95\x9D","\xE2\x95\x9C","\xE2\x95\x9B","\xE2\x94\x90",
"\xE2\x94\x94","\xE2\x94\xB4","\xE2\x94\xAC","\xE2\x94\x9C",
"\xE2\x94\x80","\xE2\x94\xBC","\xE2\x95\x9E","\xE2\x95\x9F",
"\xE2\x95\x9A","\xE2\x95\x94","\xE2\x95\xA9","\xE2\x95\xA6",
"\xE2\x95\xA0","\xE2\x95\x90","\xE2\x95\xAC","\xE2\x95\xA7",
"\xE2\x95\xA8","\xE2\x95\xA4","\xE2\x95\xA5","\xE2\x95\x99",
"\xE2\x95\x98","\xE2\x95\x92","\xE2\x95\x93","\xE2\x95\xAB",
"\xE2\x95\xAA","\xE2\x94\x98","\xE2\x94\x8C","\xE2\x96\x88",
"\xE2\x96\x84","\xE2\x96\x8C","\xE2\x96\x90","\xE2\x96\x80",
"\xCE\xB1","\xC3\x9F","\xCE\x93","\xCF\x80",
"\xCE\xA3","\xCF\x83","\xC2\xB5","\xCF\x84",
"\xCE\xA6","\xCE\x98","\xCE\xA9","\xCE\xB4",
"\xE2\x88\x9E","\xCF\x86","\xCE\xB5","\xE2\x88\xA9",
"\xE2\x89\xA1","\xC2\xB1","\xE2\x89\xA5","\xE2\x89\xA4",
"\xE2\x8C\xA0","\xE2\x8C\xA1","\xC3\xB7","\xE2\x89\x88",
"\xC2\xB0","\xE2\x88\x99","\xC2\xB7","\xE2\x88\x9A",
"\xE2\x81\xBF","\xC2\xB2","\xE2\x96\xA0","\xC2\xA0");
 
/**
* create a new extended SimpleXMLElement and set encoding if specified
*
* @param SimpleXMLElement $xml base xml element
* @param String $encoding base encoding that should be used for conversation to utf8
*
* @return void
*/
public function __construct($xml, $encoding = null)
{
if ($encoding != null) {
$this->_encoding = $encoding;
}
$this->_SimpleXmlElement = $xml;
}
 
/**
* insert a child element with or without a value, also doing conversation of name and if value is set to utf8
*
* @param String $name name of the child element
* @param String $value a value that should be insert to the child
*
* @return SimpleXMLExtended extended child SimpleXMLElement
*/
public function addChild($name, $value = null)
{
$nameUtf8 = $this->_toUTF8($name);
if ($value == null) {
return new SimpleXMLExtended($this->_SimpleXmlElement->addChild($nameUtf8), $this->_encoding);
} else {
$valueUtf8 = htmlspecialchars($this->_toUTF8($value), ENT_COMPAT, "UTF-8");
 
return new SimpleXMLExtended($this->_SimpleXmlElement->addChild($nameUtf8, $valueUtf8), $this->_encoding);
}
}
 
/**
* insert a child with cdata section
*
* @param String $name name of the child element
* @param String $cdata data for CDATA section
*
* @return SimpleXMLExtended extended child SimpleXMLElement
*/
public function addCData($name, $cdata)
{
$nameUtf8 = $this->_toUTF8($name);
$node = $this->_SimpleXmlElement->addChild($nameUtf8);
$domnode = dom_import_simplexml($node);
$no = $domnode->ownerDocument;
$domnode->appendChild($no->createCDATASection($cdata));
 
return new SimpleXMLExtended($node, $this->_encoding);
}
 
/**
* add a attribute to a child and convert name and value to utf8
*
* @param String $name name of the attribute
* @param String $value value of the attribute
*
* @return Void
*/
public function addAttribute($name, $value)
{
$nameUtf8 = $this->_toUTF8($name);
$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);
}
}
 
/**
* append a xml-tree to another xml-tree
*
* @param SimpleXMLElement $new_child child that should be appended
*
* @return Void
*/
public function combinexml(SimpleXMLElement $new_child)
{
$node1 = dom_import_simplexml($this->_SimpleXmlElement);
$dom_sxe = dom_import_simplexml($new_child);
$node2 = $node1->ownerDocument->importNode($dom_sxe, true);
$node1->appendChild($node2);
}
 
/**
* convert a string into an UTF-8 string
*
* @param String $str string to convert
*
* @return String UTF-8 string
*/
private function _toUTF8($str)
{
$str = trim(preg_replace('/[\x00-\x09\x0b-\x1F]/', ' ', $str)); //remove nonprintable characters
if ($this->_encoding != null) {
if (strcasecmp($this->_encoding, "UTF-8") == 0) {
return $str;
} elseif (strcasecmp($this->_encoding, "CP437") == 0) {
$strr = "";
if (($strl = strlen($str)) > 0) for ($i = 0; $i < $strl; $i++) {
$strc = substr($str, $i, 1);
if ($strc < 128) $strr.=$strc;
else $strr.=self::$_CP437toUTF8Table[$strc-128];
}
 
return $strr;
} else {
if (preg_match("/^windows-\d+ \((.+)\)$/", $this->_encoding, $buf)) {
$encoding = $buf[1];
} else {
$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($str, 'UTF-8');
}
}
 
/**
* Returns the SimpleXmlElement
*
* @return SimpleXmlElement entire xml as SimpleXmlElement
*/
public function getSimpleXmlElement()
{
return $this->_SimpleXmlElement;
}
}
/web/acc/phpsysinfo/includes/xml/class.XML.inc.php
0,0 → 1,836
<?php
/**
* XML Generation class
*
* PHP version 5
*
* @category PHP
* @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 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
*/
/**
* class for generation of the xml
*
* @category PHP
* @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 version 2, or (at your option) any later version
* @version Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
class XML
{
/**
* Sysinfo object where the information retrieval methods are included
*
* @var PSI_Interface_OS
*/
private $_sysinfo;
 
/**
* @var System
*/
private $_sys = null;
 
/**
* xml object with the xml content
*
* @var SimpleXMLExtended
*/
private $_xml;
 
/**
* object for error handling
*
* @var PSI_Error
*/
private $_errors;
 
/**
* array with all enabled plugins (name)
*
* @var array
*/
private $_plugins;
 
/**
* plugin name if pluginrequest
*
* @var string
*/
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)
*
* @var boolean
*/
private $_complete_request = false;
 
/**
* doing some initial tasks
* - generate the xml structure with the right header elements
* - get the error object for error output
* - get a instance of the sysinfo object
*
* @param boolean $complete generate xml with all plugins or not
* @param string $pluginname name of the plugin
*
* @return void
*/
public function __construct($complete = false, $pluginname = "", $blockname = false)
{
$this->_errors = PSI_Error::singleton();
if ($pluginname == "") {
$this->_plugin_request = false;
$this->_plugin = '';
} else {
$this->_plugin_request = true;
$this->_plugin = $pluginname;
}
if ($complete) {
$this->_complete_request = true;
} else {
$this->_complete_request = false;
}
$os = PSI_OS;
$this->_sysinfo = new $os($blockname);
$this->_plugins = CommonFunctions::getPlugins();
$this->_xmlbody();
}
 
/**
* generate common information
*
* @return void
*/
private function _buildVitals()
{
$vitals = $this->_xml->addChild('Vitals');
$vitals->addAttribute('Hostname', $this->_sys->getHostname());
$vitals->addAttribute('IPAddr', $this->_sys->getIp());
$vitals->addAttribute('Kernel', $this->_sys->getKernel());
$vitals->addAttribute('Distro', $this->_sys->getDistribution());
$vitals->addAttribute('Distroicon', $this->_sys->getDistributionIcon());
$vitals->addAttribute('Uptime', $this->_sys->getUptime());
$vitals->addAttribute('Users', $this->_sys->getUsers());
$vitals->addAttribute('LoadAvg', $this->_sys->getLoad());
if ($this->_sys->getLoadPercent() !== null) {
$vitals->addAttribute('CPULoad', $this->_sys->getLoadPercent());
}
if ($this->_sysinfo->getLanguage() !== null) {
$vitals->addAttribute('SysLang', $this->_sysinfo->getLanguage());
}
if ($this->_sysinfo->getEncoding() !== null) {
$vitals->addAttribute('CodePage', $this->_sysinfo->getEncoding());
}
 
//processes
if (($procss = $this->_sys->getProcesses()) !== null) {
if (isset($procss['*']) && (($procall = $procss['*']) > 0)) {
$vitals->addAttribute('Processes', $procall);
if (!isset($procss[' ']) || !($procss[' '] > 0)) { // not unknown
$procsum = 0;
if (isset($procss['R']) && (($proctmp = $procss['R']) > 0)) {
$vitals->addAttribute('ProcessesRunning', $proctmp);
$procsum += $proctmp;
}
if (isset($procss['S']) && (($proctmp = $procss['S']) > 0)) {
$vitals->addAttribute('ProcessesSleeping', $proctmp);
$procsum += $proctmp;
}
if (isset($procss['T']) && (($proctmp = $procss['T']) > 0)) {
$vitals->addAttribute('ProcessesStopped', $proctmp);
$procsum += $proctmp;
}
if (isset($procss['Z']) && (($proctmp = $procss['Z']) > 0)) {
$vitals->addAttribute('ProcessesZombie', $proctmp);
$procsum += $proctmp;
}
if (isset($procss['D']) && (($proctmp = $procss['D']) > 0)) {
$vitals->addAttribute('ProcessesWaiting', $proctmp);
$procsum += $proctmp;
}
if (($proctmp = $procall - $procsum) > 0) {
$vitals->addAttribute('ProcessesOther', $proctmp);
}
}
}
}
// $vitals->addAttribute('OS', PSI_OS);
$vitals->addAttribute('OS', (PSI_OS=='Android')?'Linux':PSI_OS);
}
 
/**
* generate the network information
*
* @return void
*/
private function _buildNetwork()
{
$hideDevices = array();
$network = $this->_xml->addChild('Network');
if (defined('PSI_HIDE_NETWORK_INTERFACE')) {
if (is_string(PSI_HIDE_NETWORK_INTERFACE)) {
if (preg_match(ARRAY_EXP, PSI_HIDE_NETWORK_INTERFACE)) {
$hideDevices = eval(PSI_HIDE_NETWORK_INTERFACE);
} else {
$hideDevices = array(PSI_HIDE_NETWORK_INTERFACE);
}
} elseif (PSI_HIDE_NETWORK_INTERFACE === true) {
return;
}
}
foreach ($this->_sys->getNetDevices() as $dev) {
if (!in_array(trim($dev->getName()), $hideDevices)) {
$device = $network->addChild('NetDevice');
$device->addAttribute('Name', $dev->getName());
$device->addAttribute('RxBytes', $dev->getRxBytes());
$device->addAttribute('TxBytes', $dev->getTxBytes());
$device->addAttribute('Err', $dev->getErrors());
$device->addAttribute('Drops', $dev->getDrops());
if (defined('PSI_SHOW_NETWORK_INFOS') && PSI_SHOW_NETWORK_INFOS && $dev->getInfo())
$device->addAttribute('Info', $dev->getInfo());
}
}
}
 
/**
* generate the hardware information
*
* @return void
*/
private function _buildHardware()
{
$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());
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());
}
}
$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 (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());
}
}
$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());
}
}
$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());
}
}
 
$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', max($oneCpu->getCpuSpeed(), 0));
}
if ($oneCpu->getCpuSpeedMax() !== 0) {
$tmp->addAttribute('CpuSpeedMax', $oneCpu->getCpuSpeedMax());
}
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());
}
if ($oneCpu->getCache() !== null) {
$tmp->addAttribute('Cache', $oneCpu->getCache());
}
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 = preg_replace('/[\s!]/', '', $oneCpu->getVendorId());
if ($vendortab && ($shortvendorid != "") && isset($vendortab['manufacturer'][$shortvendorid])) {
$tmp->addAttribute('Manufacturer', $vendortab['manufacturer'][$shortvendorid]);
}
}
if ($oneCpu->getBogomips() !== null) {
$tmp->addAttribute('Bogomips', $oneCpu->getBogomips());
}
if ($oneCpu->getLoad() !== null) {
$tmp->addAttribute('Load', $oneCpu->getLoad());
}
}
}
 
/**
* generate the memory information
*
* @return void
*/
private function _buildMemory()
{
$memory = $this->_xml->addChild('Memory');
$memory->addAttribute('Free', $this->_sys->getMemFree());
$memory->addAttribute('Used', $this->_sys->getMemUsed());
$memory->addAttribute('Total', $this->_sys->getMemTotal());
$memory->addAttribute('Percent', $this->_sys->getMemPercentUsed());
if (($this->_sys->getMemApplication() !== null) || ($this->_sys->getMemBuffer() !== null) || ($this->_sys->getMemCache() !== null)) {
$details = $memory->addChild('Details');
if ($this->_sys->getMemApplication() !== null) {
$details->addAttribute('App', $this->_sys->getMemApplication());
$details->addAttribute('AppPercent', $this->_sys->getMemPercentApplication());
}
if ($this->_sys->getMemBuffer() !== null) {
$details->addAttribute('Buffers', $this->_sys->getMemBuffer());
$details->addAttribute('BuffersPercent', $this->_sys->getMemPercentBuffer());
}
if ($this->_sys->getMemCache() !== null) {
$details->addAttribute('Cached', $this->_sys->getMemCache());
$details->addAttribute('CachedPercent', $this->_sys->getMemPercentCache());
}
}
if (count($this->_sys->getSwapDevices()) > 0) {
$swap = $memory->addChild('Swap');
$swap->addAttribute('Free', $this->_sys->getSwapFree());
$swap->addAttribute('Used', $this->_sys->getSwapUsed());
$swap->addAttribute('Total', $this->_sys->getSwapTotal());
$swap->addAttribute('Percent', $this->_sys->getSwapPercentUsed());
$i = 1;
foreach ($this->_sys->getSwapDevices() as $dev) {
$swapMount = $swap->addChild('Mount');
$this->_fillDevice($swapMount, $dev, $i++);
}
}
}
 
/**
* fill a xml element with atrributes from a disk device
*
* @param SimpleXmlExtended $mount Xml-Element
* @param DiskDevice $dev DiskDevice
* @param Integer $i counter
*
* @return Void
*/
private function _fillDevice(SimpleXMLExtended $mount, DiskDevice $dev, $i)
{
$mount->addAttribute('MountPointID', $i);
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 ($dev->getIgnore() > 0) $mount->addAttribute('Ignore', $dev->getIgnore());
if (PSI_SHOW_MOUNT_OPTION === true) {
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) {
$mount->addAttribute('MountPoint', $dev->getMountPoint());
}
}
 
/**
* generate the filesysteminformation
*
* @return void
*/
private function _buildFilesystems()
{
$hideMounts = $hideFstypes = $hideDisks = $ignoreFree = $ignoreUsage = $ignoreThreshold = array();
$i = 1;
if (defined('PSI_HIDE_MOUNTS') && is_string(PSI_HIDE_MOUNTS)) {
if (preg_match(ARRAY_EXP, PSI_HIDE_MOUNTS)) {
$hideMounts = eval(PSI_HIDE_MOUNTS);
} else {
$hideMounts = array(PSI_HIDE_MOUNTS);
}
}
if (defined('PSI_HIDE_FS_TYPES') && is_string(PSI_HIDE_FS_TYPES)) {
if (preg_match(ARRAY_EXP, PSI_HIDE_FS_TYPES)) {
$hideFstypes = eval(PSI_HIDE_FS_TYPES);
} else {
$hideFstypes = array(PSI_HIDE_FS_TYPES);
}
}
if (defined('PSI_HIDE_DISKS')) {
if (is_string(PSI_HIDE_DISKS)) {
if (preg_match(ARRAY_EXP, PSI_HIDE_DISKS)) {
$hideDisks = eval(PSI_HIDE_DISKS);
} else {
$hideDisks = array(PSI_HIDE_DISKS);
}
} elseif (PSI_HIDE_DISKS === true) {
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_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');
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(3);
} elseif (in_array($disk->getMountPoint(), $ignoreUsage, true)) {
$disk->setIgnore(2);
} elseif (in_array($disk->getMountPoint(), $ignoreFree, true)) {
$disk->setIgnore(1);
}
$this->_fillDevice($mount, $disk, $i++);
}
}
}
 
/**
* generate the motherboard information
*
* @return void
*/
private function _buildMbinfo()
{
$mbinfo = $this->_xml->addChild('MBInfo');
$temp = $fan = $volt = $power = $current = $other = null;
 
if (sizeof(unserialize(PSI_MBINFO))>0) {
foreach (unserialize(PSI_MBINFO) as $mbinfoclass) {
$mbinfo_data = new $mbinfoclass();
$mbinfo_detail = $mbinfo_data->getMBInfo();
 
if (!$this->_sysinfo->getBlockName() || $this->_sysinfo->getBlockName()==='temperature') 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()==='fans') 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()==='voltage') 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()==='power') 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()==='current') 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->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()==='other') foreach ($mbinfo_detail->getMbOther() as $dev) {
if ($other == null) {
$other = $mbinfo->addChild('Other');
}
$item = $other->addChild('Item');
$item->addAttribute('Label', $dev->getName());
$item->addAttribute('Value', $dev->getValue());
if (defined('PSI_SENSOR_EVENTS') && PSI_SENSOR_EVENTS && $dev->getEvent() !== "") {
$item->addAttribute('Event', $dev->getEvent());
}
}
}
}
}
 
/**
* generate the ups information
*
* @return void
*/
private function _buildUpsinfo()
{
$upsinfo = $this->_xml->addChild('UPSInfo');
if (defined('PSI_UPS_APCUPSD_CGI_ENABLE') && PSI_UPS_APCUPSD_CGI_ENABLE) {
$upsinfo->addAttribute('ApcupsdCgiLinks', true);
}
if (sizeof(unserialize(PSI_UPSINFO))>0) {
foreach (unserialize(PSI_UPSINFO) as $upsinfoclass) {
$upsinfo_data = new $upsinfoclass();
$upsinfo_detail = $upsinfo_data->getUPSInfo();
foreach ($upsinfo_detail->getUpsDevices() as $ups) {
$item = $upsinfo->addChild('UPS');
$item->addAttribute('Name', $ups->getName());
if ($ups->getModel() !== "") {
$item->addAttribute('Model', $ups->getModel());
}
if ($ups->getMode() !== "") {
$item->addAttribute('Mode', $ups->getMode());
}
if ($ups->getStartTime() !== "") {
$item->addAttribute('StartTime', $ups->getStartTime());
}
$item->addAttribute('Status', $ups->getStatus());
if ($ups->getTemperatur() !== null) {
$item->addAttribute('Temperature', $ups->getTemperatur());
}
if ($ups->getOutages() !== null) {
$item->addAttribute('OutagesCount', $ups->getOutages());
}
if ($ups->getLastOutage() !== null) {
$item->addAttribute('LastOutage', $ups->getLastOutage());
}
if ($ups->getLastOutageFinish() !== null) {
$item->addAttribute('LastOutageFinish', $ups->getLastOutageFinish());
}
if ($ups->getLineVoltage() !== null) {
$item->addAttribute('LineVoltage', $ups->getLineVoltage());
}
if ($ups->getLineFrequency() !== null) {
$item->addAttribute('LineFrequency', $ups->getLineFrequency());
}
if ($ups->getLoad() !== null) {
$item->addAttribute('LoadPercent', $ups->getLoad());
}
if ($ups->getBatteryDate() !== null) {
$item->addAttribute('BatteryDate', $ups->getBatteryDate());
}
if ($ups->getBatteryVoltage() !== null) {
$item->addAttribute('BatteryVoltage', $ups->getBatteryVoltage());
}
if ($ups->getBatterCharge() !== null) {
$item->addAttribute('BatteryChargePercent', $ups->getBatterCharge());
}
if ($ups->getTimeLeft() !== null) {
$item->addAttribute('TimeLeftMinutes', $ups->getTimeLeft());
}
}
}
}
}
 
/**
* generate the xml document
*
* @return void
*/
private function _buildXml()
{
if (!$this->_plugin_request || $this->_complete_request) {
if ($this->_sys === null) {
if (PSI_DEBUG === true) {
// unstable version check
if (!is_numeric(substr(PSI_VERSION, -1))) {
$this->_errors->addError("WARN", "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) {
$this->_errors->addError("WARN", "PhpSysInfo requires to set off 'safe_mode' in 'php.ini'");
}
// Include path check
$include_path = @ini_get("include_path");
if ($include_path && ($include_path!="")) {
$include_path = preg_replace("/(:)|(;)/", "\n", $include_path);
if (preg_match("/^\.$/m", $include_path)) {
$include_path = ".";
}
}
if ($include_path != ".") {
$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) {
$this->_errors->addError("WARN", "Installed version of PHP does not support proc_open() function, popen() is used");
}
}
$this->_sys = $this->_sysinfo->getSys();
}
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('voltage','current','temperature','fans','power','other'))) $this->_buildMbinfo();
if (!$this->_sysinfo->getBlockName() || $this->_sysinfo->getBlockName()==='ups') $this->_buildUpsinfo();
}
if (!$this->_sysinfo->getBlockName()) $this->_buildPlugins();
$this->_xml->combinexml($this->_errors->errorsAddToXML($this->_sysinfo->getEncoding()));
}
 
/**
* get the xml object
*
* @return SimpleXmlElement
*/
public function getXml()
{
$this->_buildXml();
 
return $this->_xml->getSimpleXmlElement();
}
 
/**
* include xml-trees of the plugins to the main xml
*
* @return void
*/
private function _buildPlugins()
{
$pluginroot = $this->_xml->addChild("Plugins");
if (($this->_plugin_request || $this->_complete_request) && count($this->_plugins) > 0) {
$plugins = array();
if ($this->_complete_request) {
$plugins = $this->_plugins;
}
if ($this->_plugin_request) {
$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);
}
}
}
}
 
/**
* build the xml structure where the content can be inserted
*
* @return void
*/
private function _xmlbody()
{
$dom = new DOMDocument('1.0', 'UTF-8');
$root = $dom->createElement("tns:phpsysinfo");
$root->setAttribute('xmlns:tns', 'http://phpsysinfo.sourceforge.net/');
$root->setAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
$root->setAttribute('xsi:schemaLocation', 'http://phpsysinfo.sourceforge.net/ phpsysinfo3.xsd');
$dom->appendChild($root);
$this->_xml = new SimpleXMLExtended(simplexml_import_dom($dom), $this->_sysinfo->getEncoding());
 
$generation = $this->_xml->addChild('Generation');
$generation->addAttribute('version', PSI_VERSION_STRING);
$generation->addAttribute('timestamp', time());
$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')) {
$options->addAttribute('refresh', max(intval(PSI_REFRESH), 0));
} else {
$options->addAttribute('refresh', 60000);
}
if (defined('PSI_FS_USAGE_THRESHOLD')) {
if ((($fsut = intval(PSI_FS_USAGE_THRESHOLD)) >= 1) && ($fsut <= 99)) {
$options->addAttribute('threshold', $fsut);
}
} else {
$options->addAttribute('threshold', 90);
}
if (count($this->_plugins) > 0) {
if ($this->_plugin_request) {
$plug = $this->_xml->addChild('UsedPlugins');
$plug->addChild('Plugin')->addAttribute('name', $this->_plugin);
} elseif ($this->_complete_request) {
$plug = $this->_xml->addChild('UsedPlugins');
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);
}
*/
}
}
}
}