initial commit of file from CVS for smeserver-phpsysinfo on Sat Sep 7 20:53:46 AEST 2024

This commit is contained in:
Trevor Batley
2024-09-07 20:53:46 +10:00
parent 8f9c36d1f5
commit 9552652292
693 changed files with 86806 additions and 2 deletions

View File

@@ -0,0 +1,73 @@
<?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 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 __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(APP_ROOT.$dir.'class.'.strtolower($class_name).'.inc.php')) {
include_once 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(APP_ROOT.$dir.'class.'.$class_name.'.inc.php')) {
include_once APP_ROOT.$dir.'class.'.$class_name.'.inc.php';
return;
}
}
$error = Error::singleton();
$error->addError("_autoload(\"".$class_name."\")", "autoloading of class file (class.".$class_name.".inc.php) failed!");
$error->errorsAsXML();
}
/**
* 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 = Error::singleton();
$error->addPhpError("errorHandlerPsi : ", "Level : ".$level." Message : ".$message." File : ".$file." Line : ".$line);
}
set_error_handler('errorHandlerPsi');

View File

@@ -0,0 +1,563 @@
<?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 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 Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
class CommonFunctions
{
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 complete path and name of the program
*/
private static function _findProgram($strProgram)
{
$path_parts = pathinfo($strProgram);
if (empty($path_parts['basename'])) {
return;
}
$arrPath = array();
if ((PSI_OS == 'WINNT') && empty($path_parts['extension'])) {
$strProgram .= '.exe';
$path_parts = pathinfo($strProgram);
}
if (empty($path_parts['dirname']) || ($path_parts['dirname'] == '.')) {
if (PSI_OS == 'WINNT') {
$arrPath = preg_split('/;/', getenv("Path"), -1, PREG_SPLIT_NO_EMPTY);
} else {
$arrPath = preg_split('/:/', getenv("PATH"), -1, PREG_SPLIT_NO_EMPTY);
}
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 {
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') && (($windir = getenv("WinDir")) !== false)) {
$windir = strtolower($windir);
foreach ($arrPath as $strPath) {
if ((strtolower($strPath) == $windir."\\system32") && is_dir($windir."\\SysWOW64")) {
$exceptPath = $windir."\\sysnative";
array_push($arrPath, $exceptPath);
break;
}
}
} else if (PSI_OS == 'Android') {
$exceptPath = '/system/bin';
}
// If open_basedir defined, fill the $open_basedir array with authorized paths,. (Not tested when no open_basedir restriction)
if ((bool) ini_get('open_basedir')) {
if (PSI_OS == 'WINNT') {
$open_basedir = preg_split('/;/', ini_get('open_basedir'), -1, PREG_SPLIT_NO_EMPTY);
} else {
$open_basedir = preg_split('/:/', ini_get('open_basedir'), -1, PREG_SPLIT_NO_EMPTY);
}
}
foreach ($arrPath as $strPath) {
// Path with trailing slash
if (PSI_OS == 'WINNT') {
$strPathS = rtrim($strPath, "\\")."\\";
} else {
$strPathS = rtrim($strPath, "/")."/";
}
// To avoid "open_basedir restriction in effect" error when testing paths if restriction is enabled
if (isset($open_basedir)) {
$inBaseDir = false;
if (PSI_OS == 'WINNT') {
foreach ($open_basedir as $openbasedir) {
if (substr($openbasedir, -1)=="\\") {
$str_Path = $strPathS;
} else {
$str_Path = $strPath;
}
if (stripos($str_Path, $openbasedir) === 0) {
$inBaseDir = true;
break;
}
}
} else {
foreach ($open_basedir as $openbasedir) {
if (substr($openbasedir, -1)=="/") {
$str_Path = $strPathS;
} else {
$str_Path = $strPath;
}
if (strpos($str_Path, $openbasedir) === 0) {
$inBaseDir = true;
break;
}
}
}
if ($inBaseDir == false) {
continue;
}
}
if (($strPath !== $exceptPath) && !is_dir($strPath)) {
continue;
}
if (PSI_OS == 'WINNT') {
$strProgrammpath = rtrim($strPath, "\\")."\\".$strProgram;
} else {
$strProgrammpath = rtrim($strPath, "/")."/".$strProgram;
}
if (is_executable($strProgrammpath)) {
return $strProgrammpath;
}
}
}
/**
* 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
*
* @return boolean command successfull or not
*/
public static function executeProgram($strProgramname, $strArgs, &$strBuffer, $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("Executing: ".trim($strProgramname.' '.$strArgs));
if ($out == false) {
if (substr(PSI_LOG, 0, 1)=="-") {
$strBuffer = '';
return false;
}
} else {
$strBuffer = $out;
return true;
}
}
$strBuffer = '';
$strError = '';
$pipes = array();
$strProgram = self::_findProgram($strProgramname);
$error = Error::singleton();
if (!$strProgram) {
if ($booErrorRep) {
$error->addError('find_program('.$strProgramname.')', 'program not found on the machine');
}
return false;
}
// 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);
}
}
}
$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('"'.$strProgram.'" '.$strArgs." 2>nul", "r");
} else {
$process = $pipes[1] = popen('"'.$strProgram.'" '.$strArgs." 2>/dev/null", "r");
}
} else {
$process = proc_open('"'.$strProgram.'" '.$strArgs, $descriptorspec, $pipes);
}
if (is_resource($process)) {
self::_timeoutfgets($pipes, $strBuffer, $strError);
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
$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 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 = 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;
}
}
}
return file_exists($strFileName);
}
/**
* 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 = 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', 'mbstring', 'dom', 'com_dotnet');
else
$arrReq = array('simplexml', 'pcre', 'xml', 'mbstring', 'dom');
$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 (default value is 30)
*
* @return void
*/
private static function _timeoutfgets($pipes, &$out, &$err, $timeout = 30)
{
$w = null;
$e = null;
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 !');
break;
}
foreach ($read as $r) {
if ($r == $pipes[1]) {
$out .= fread($r, 4096);
} else if (feof($pipes[1]) && $pipe2 && ($r == $pipes[2])) {//read STDERR after STDOUT
$err .= fread($r, 4096);
}
}
}
}
/**
* function for getting a list of values in the specified context
* optionally filter this list, based on the list from third parameter
*
* @param $wmi holds the COM object that we pull the WMI data from
* @param string $strClass name of the class where the values are stored
* @param array $strValue filter out only needed values, if not set all values of the class are returned
*
* @return array content of the class stored in an array
*/
public static function getWMI($wmi, $strClass, $strValue = array())
{
$arrData = array();
if ($wmi) {
$value = "";
try {
$objWEBM = $wmi->Get($strClass);
$arrProp = $objWEBM->Properties_;
$arrWEBMCol = $objWEBM->Instances_();
foreach ($arrWEBMCol as $objItem) {
if (is_array($arrProp)) {
reset($arrProp);
}
$arrInstance = array();
foreach ($arrProp as $propItem) {
$value = $objItem->{$propItem->Name}; //instead exploitable eval("\$value = \$objItem->".$propItem->Name.";");
if (empty($strValue)) {
if (is_string($value)) $arrInstance[$propItem->Name] = trim($value);
else $arrInstance[$propItem->Name] = $value;
} else {
if (in_array($propItem->Name, $strValue)) {
if (is_string($value)) $arrInstance[$propItem->Name] = trim($value);
else $arrInstance[$propItem->Name] = $value;
}
}
}
$arrData[] = $arrInstance;
}
} catch (Exception $e) {
if (PSI_DEBUG) {
$error = Error::singleton();
$error->addError($e->getCode(), $e->getMessage());
}
}
}
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();
}
}
}

View File

@@ -0,0 +1,216 @@
<?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 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 Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
class Parser
{
/**
* parsing the output of lspci command
*
* @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
*
* @return array
*/
public static function df($df_param = "")
{
$arrResult = array();
if (CommonFunctions::executeProgram('mount', '', $mount, PSI_DEBUG)) {
$mount = preg_split("/\n/", $mount, -1, PREG_SPLIT_NO_EMPTY);
foreach ($mount as $mount_line) {
if (preg_match("/(\S+) on ([\S ]+) type (.*) \((.*)\)/", $mount_line, $mount_buf)) {
$mount_parm[$mount_buf[2]]['fstype'] = $mount_buf[3];
$mount_parm[$mount_buf[2]]['name'] = $mount_buf[1];
if (PSI_SHOW_MOUNT_OPTION) $mount_parm[$mount_buf[2]]['options'] = $mount_buf[4];
} elseif (preg_match("/(\S+) is (.*) mounted on (\S+) \(type (.*)\)/", $mount_line, $mount_buf)) {
$mount_parm[$mount_buf[3]]['fstype'] = $mount_buf[4];
$mount_parm[$mount_buf[3]]['name'] = $mount_buf[1];
if (PSI_SHOW_MOUNT_OPTION) $mount_parm[$mount_buf[3]]['options'] = $mount_buf[2];
} elseif (preg_match("/(\S+) (.*) on (\S+) \((.*)\)/", $mount_line, $mount_buf)) {
$mount_parm[$mount_buf[3]]['fstype'] = $mount_buf[2];
$mount_parm[$mount_buf[3]]['name'] = $mount_buf[1];
if (PSI_SHOW_MOUNT_OPTION) $mount_parm[$mount_buf[3]]['options'] = $mount_buf[4];
} elseif (preg_match("/(\S+) on ([\S ]+) \((\S+)(,\s(.*))?\)/", $mount_line, $mount_buf)) {
$mount_parm[$mount_buf[2]]['fstype'] = $mount_buf[3];
$mount_parm[$mount_buf[2]]['name'] = $mount_buf[1];
if (PSI_SHOW_MOUNT_OPTION) $mount_parm[$mount_buf[2]]['options'] = isset($mount_buf[5]) ? $mount_buf[5] : '';
}
}
} 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)) {
$mount_point = preg_replace("/\\\\040/i", ' ', $mount_buf[2]); //space as \040
$mount_parm[$mount_point]['fstype'] = $mount_buf[3];
$mount_parm[$mount_point]['name'] = $mount_buf[1];
if (PSI_SHOW_MOUNT_OPTION) $mount_parm[$mount_point]['options'] = $mount_buf[4];
}
}
}
if (CommonFunctions::executeProgram('df', '-k '.$df_param, $df, PSI_DEBUG)) {
$df = preg_split("/\n/", $df, -1, PREG_SPLIT_NO_EMPTY);
if (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]);
if (isset($mount_parm[$df_buf[5]])) {
$dev->setFsType($mount_parm[$df_buf[5]]['fstype']);
if (PSI_SHOW_MOUNT_OPTION) {
if (PSI_SHOW_MOUNT_CREDENTIALS) {
$dev->setOptions($mount_parm[$df_buf[5]]['options']);
} else {
$mpo=$mount_parm[$df_buf[5]]['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);
}
}
}
if (PSI_SHOW_INODES && isset($df_inodes[trim($df_buf[0])])) {
$dev->setPercentInodesUsed($df_inodes[trim($df_buf[0])]);
}
$arrResult[] = $dev;
}
}
}
} else {
if (isset($mount_parm)) {
foreach ($mount_parm as $mount_point=>$mount_param) {
$total = disk_total_space($mount_point);
if (($mount_param['fstype'] != 'none') && ($total > 0)) {
$dev = new DiskDevice();
$dev->setName($mount_param['name']);
$dev->setFsType($mount_param['fstype']);
if (PSI_SHOW_MOUNT_POINT) $dev->setMountPoint($mount_point);
$dev->setTotal($total);
$free = disk_free_space($mount_point);
if ($free > 0) {
$dev->setFree($free);
} else {
$free = 0;
}
if ($total > $free) $dev->setUsed($total - $free);
if (PSI_SHOW_MOUNT_OPTION) {
if (PSI_SHOW_MOUNT_CREDENTIALS) {
$dev->setOptions($mount_param['options']);
} else {
$mpo=$mount_param['options'];
$mpo=preg_replace('/(^guest,)|(^guest$)|(,guest$)/i', '', $mpo);
$mpo=preg_replace('/,guest,/i', ',', $mpo);
$mpo=preg_replace('/(^user=[^,]*,)|(^user=[^,]*$)|(,user=[^,]*$)/i', '', $mpo);
$mpo=preg_replace('/,user=[^,]*,/i', ',', $mpo);
$mpo=preg_replace('/(^username=[^,]*,)|(^username=[^,]*$)|(,username=[^,]*$)/i', '', $mpo);
$mpo=preg_replace('/,username=[^,]*,/i', ',', $mpo);
$mpo=preg_replace('/(^password=[^,]*,)|(^password=[^,]*$)|(,password=[^,]*$)/i', '', $mpo);
$mpo=preg_replace('/,password=[^,]*,/i', ',', $mpo);
$dev->setOptions($mpo);
}
}
$arrResult[] = $dev;
}
}
}
}
return $arrResult;
}
}

View File

@@ -0,0 +1,290 @@
<?php
/**
* Error class
*
* PHP version 5
*
* @category PHP
* @package PSI_Error
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @version SVN: $Id: class.Error.inc.php 569 2012-04-16 06:08:18Z namiltd $
* @link http://phpsysinfo.sourceforge.net
*/
/**
* class for the error handling in phpsysinfo
*
* @category PHP
* @package PSI_Error
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @version Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
class Error
{
/**
* holds the instance of this class
*
* @static
* @var object
*/
private static $_instance;
/**
* holds the error messages
*
* @var array
*/
private $_arrErrorList = array();
/**
* current number ob errors
*
* @var integer
*/
private $_errors = 0;
/**
* initalize some used vars
*/
private function __construct()
{
$this->_errors = 0;
$this->_arrErrorList = array();
}
/**
* Singleton function
*
* @return Error instance of the class
*/
public static function singleton()
{
if (!isset(self::$_instance)) {
$c = __CLASS__;
self::$_instance = new $c;
}
return self::$_instance;
}
/**
* triggers an error when somebody tries to clone the object
*
* @return void
*/
public function __clone()
{
trigger_error("Can't be cloned", E_USER_ERROR);
}
/**
* adds an phpsysinfo error to the internal list
*
* @param string $strCommand Command, which cause the Error
* @param string $strMessage additional Message, to describe the Error
*
* @return void
*/
public function addError($strCommand, $strMessage)
{
$this->_addError($strCommand, $this->_trace($strMessage));
}
/**
* adds an error to the internal list
*
* @param string $strCommand Command, which cause the Error
* @param string $strMessage message, that describe the Error
*
* @return void
*/
private function _addError($strCommand, $strMessage)
{
$index = count($this->_arrErrorList) + 1;
$this->_arrErrorList[$index]['command'] = $strCommand;
$this->_arrErrorList[$index]['message'] = $strMessage;
$this->_errors++;
}
/**
* add a config error to the internal list
*
* @param object $strCommand Command, which cause the Error
* @param object $strMessage additional Message, to describe the Error
*
* @return void
*/
public function addConfigError($strCommand, $strMessage)
{
$this->_addError($strCommand, "Wrong Value in phpsysinfo.ini for ".$strMessage);
}
/**
* add a php error to the internal list
*
* @param object $strCommand Command, which cause the Error
* @param object $strMessage additional Message, to describe the Error
*
* @return void
*/
public function addPhpError($strCommand, $strMessage)
{
$this->_addError($strCommand, "PHP throws a error\n".$strMessage);
}
/**
* adds a waraning to the internal list
*
* @param string $strMessage Warning message to display
*
* @return void
*/
public function addWarning($strMessage)
{
$index = count($this->_arrErrorList) + 1;
$this->_arrErrorList[$index]['command'] = "WARN";
$this->_arrErrorList[$index]['message'] = $strMessage;
}
/**
* converts the internal error and warning list to a XML file
*
* @return void
*/
public function errorsAsXML()
{
$dom = new DOMDocument('1.0', 'UTF-8');
$root = $dom->createElement("phpsysinfo");
$dom->appendChild($root);
$xml = new SimpleXMLExtended(simplexml_import_dom($dom), 'UTF-8');
$generation = $xml->addChild('Generation');
$generation->addAttribute('version', PSI_VERSION_STRING);
$generation->addAttribute('timestamp', time());
$xmlerr = $xml->addChild("Errors");
foreach ($this->_arrErrorList as $arrLine) {
// $error = $xmlerr->addCData('Error', $arrLine['message']);
$error = $xmlerr->addChild('Error');
$error->addAttribute('Message', $arrLine['message']);
$error->addAttribute('Function', $arrLine['command']);
}
header("Cache-Control: no-cache, must-revalidate\n");
header("Content-Type: text/xml\n\n");
echo $xml->getSimpleXmlElement()->asXML();
exit();
}
/**
* add the errors to an existing xml document
*
* @param String $encoding encoding
*
* @return SimpleXmlElement
*/
public function errorsAddToXML($encoding)
{
$dom = new DOMDocument('1.0', 'UTF-8');
$root = $dom->createElement("Errors");
$dom->appendChild($root);
$xml = simplexml_import_dom($dom);
$xmlerr = new SimpleXMLExtended($xml, $encoding);
foreach ($this->_arrErrorList as $arrLine) {
// $error = $xmlerr->addCData('Error', $arrLine['message']);
$error = $xmlerr->addChild('Error');
$error->addAttribute('Message', $arrLine['message']);
$error->addAttribute('Function', $arrLine['command']);
}
return $xmlerr->getSimpleXmlElement();
}
/**
* check if errors exists
*
* @return boolean true if are errors logged, false if not
*/
public function errorsExist()
{
if ($this->_errors > 0) {
return true;
} else {
return false;
}
}
/**
* generate a function backtrace for error diagnostic, function is genearally based on code submitted in the php reference page
*
* @param string $strMessage additional message to display
*
* @return string formatted string of the backtrace
*/
private function _trace($strMessage)
{
$arrTrace = array_reverse(debug_backtrace());
$strFunc = '';
$strBacktrace = htmlspecialchars($strMessage)."\n\n";
foreach ($arrTrace as $val) {
// avoid the last line, which says the error is from the error class
if ($val == $arrTrace[count($arrTrace) - 1]) {
break;
}
$strBacktrace .= str_replace(APP_ROOT, ".", $val['file']).' on line '.$val['line'];
if ($strFunc) {
$strBacktrace .= ' in function '.$strFunc;
}
if ($val['function'] == 'include' || $val['function'] == 'require' || $val['function'] == 'include_once' || $val['function'] == 'require_once') {
$strFunc = '';
} else {
$strFunc = $val['function'].'(';
if (isset($val['args'][0])) {
$strFunc .= ' ';
$strComma = '';
foreach ($val['args'] as $val) {
$strFunc .= $strComma.$this->_printVar($val);
$strComma = ', ';
}
$strFunc .= ' ';
}
$strFunc .= ')';
}
$strBacktrace .= "\n";
}
return $strBacktrace;
}
/**
* convert some special vars into better readable output
*
* @param mixed $var value, which should be formatted
*
* @return string formatted string
*/
private function _printVar($var)
{
if (is_string($var)) {
$search = array("\x00", "\x0a", "\x0d", "\x1a", "\x09");
$replace = array('\0', '\n', '\r', '\Z', '\t');
return ('"'.str_replace($search, $replace, $var).'"');
} elseif (is_bool($var)) {
if ($var) {
return ('true');
} else {
return ('false');
}
} elseif (is_array($var)) {
$strResult = 'array( ';
$strComma = '';
foreach ($var as $key=>$val) {
$strResult .= $strComma.$this->_printVar($key).' => '.$this->_printVar($val);
$strComma = ', ';
}
$strResult .= ' )';
return ($strResult);
}
// anything else, just let php try to print it
return (var_export($var, true));
}
}

View File

@@ -0,0 +1,50 @@
<?php
/**
* Basic OS Functions
*
* PHP version 5
*
* @category PHP
* @package PSI_Interfaces
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @version SVN: $Id: class.PSI_Interface_OS.inc.php 263 2009-06-22 13:01:52Z bigmichi1 $
* @link http://phpsysinfo.sourceforge.net
*/
/**
* define which methods a os class for phpsysinfo must implement
* to be recognized and fully work without errors, these are the methods which
* are called from outside to include the information in the main application
*
* @category PHP
* @package PSI_Interfaces
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @version Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
interface PSI_Interface_OS
{
/**
* get a special encoding from os where phpsysinfo is running
*
* @return string
*/
public function getEncoding();
/**
* build the os information
*
* @return void
*/
public function build();
/**
* get the filled or unfilled (with default values) system object
*
* @return System
*/
public function getSys();
}

View File

@@ -0,0 +1,35 @@
<?php
/**
* Basic Output Functions
*
* PHP version 5
*
* @category PHP
* @package PSI_Interfaces
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @version SVN: $Id: class.PSI_Interface_Output.inc.php 214 2009-05-25 08:32:40Z bigmichi1 $
* @link http://phpsysinfo.sourceforge.net
*/
/**
* define which methods a output class for phpsysinfo must implement
* to be recognized and fully work without errors
*
* @category PHP
* @package PSI_Interfaces
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @version Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
interface PSI_Interface_Output
{
/**
* generate the output
*
* @return void
*/
public function run();
}

View File

@@ -0,0 +1,43 @@
<?php
/**
* Basic Plugin Functions
*
* PHP version 5
*
* @category PHP
* @package PSI_Interfaces
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @version SVN: $Id: class.PSI_Interface_Plugin.inc.php 273 2009-06-24 11:40:09Z bigmichi1 $
* @link http://phpsysinfo.sourceforge.net
*/
/**
* define which methods a plugin class for phpsysinfo must implement
* to be recognized and fully work without errors, these are the methods which
* are called from outside to include the information in the main application
*
* @category PHP
* @package PSI_Interfaces
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @version Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
interface PSI_Interface_Plugin
{
/**
* doing all tasks before the xml can be build
*
* @return void
*/
public function execute();
/**
* build the xml
*
* @return SimpleXMLObject entire XML content for the plugin which than can be appended to the main XML
*/
public function xml();
}

View File

@@ -0,0 +1,43 @@
<?php
/**
* Basic Sensor Functions
*
* PHP version 5
*
* @category PHP
* @package PSI_Interfaces
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @version SVN: $Id: class.PSI_Interface_Sensor.inc.php 263 2009-06-22 13:01:52Z bigmichi1 $
* @link http://phpsysinfo.sourceforge.net
*/
/**
* define which methods every sensor class for phpsysinfo must implement
* to be recognized and fully work without errors, these are the methods which
* are called from outside to include the information in the main application
*
* @category PHP
* @package PSI_Interfaces
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @version Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
interface PSI_Interface_Sensor
{
/**
* build the mbinfo information
*
* @return void
*/
public function build();
/**
* get the filled or unfilled (with default values) MBInfo object
*
* @return MBInfo
*/
public function getMBInfo();
}

View File

@@ -0,0 +1,42 @@
<?php
/**
* Basic UPS Functions
*
* PHP version 5
*
* @category PHP
* @package PSI_Interfaces
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @version SVN: $Id: class.PSI_Interface_UPS.inc.php 263 2009-06-22 13:01:52Z bigmichi1 $
* @link http://phpsysinfo.sourceforge.net
*/
/**
* define which methods a ups class for phpsysinfo must implement
* to be recognized and fully work without errors
*
* @category PHP
* @package PSI_Interfaces
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @version Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
interface PSI_Interface_UPS
{
/**
* build the ups information
*
* @return void
*/
public function build();
/**
* get the filled or unfilled (with default values) UPSInfo object
*
* @return UPSInfo
*/
public function getUPSInfo();
}

View File

@@ -0,0 +1,10 @@
versions, links and simple description of used files
===========================================================
class.JavaScriptPacker.inc.php
---------
VERSION : 1.1+FF4
URL : http://dean.edwards.name
DESC : Downloaded from http://dean.edwards.name/download/ http://joliclic.free.fr/php/javascript-packer/en/ + Firefox 4 fix
LICENSE : LGPL 2.1 (http://creativecommons.org/licenses/LGPL/2.1/)
USED : define('PSI_JS_COMPRESSION', 'None'); or define('PSI_JS_COMPRESSION', 'Normal');

View File

@@ -0,0 +1,788 @@
<?php
/* 25 October 2011. version 1.1-FF4
*
* This is the php version of the Dean Edwards JavaScript's Packer,
* Based on :
*
* ParseMaster, version 1.0.2 (2005-08-19) Copyright 2005, Dean Edwards
* a multi-pattern parser.
* KNOWN BUG: erroneous behavior when using escapeChar with a replacement
* value that is a function
*
* packer, version 2.0.2 (2005-08-19) Copyright 2004-2005, Dean Edwards
*
* License: http://creativecommons.org/licenses/LGPL/2.1/
*
* Ported to PHP by Nicolas Martin.
*
* ----------------------------------------------------------------------
* changelog:
* 1.1 : correct a bug, '\0' packed then unpacked becomes '\'.
* 1.1-FF4 : Firefox 4 fix, Copyright 2011, Mieczyslaw Nalewaj
* ----------------------------------------------------------------------
*
* examples of usage :
* $myPacker = new JavaScriptPacker($script, 62, true, false);
* $packed = $myPacker->pack();
*
* or
*
* $myPacker = new JavaScriptPacker($script, 'Normal', true, false);
* $packed = $myPacker->pack();
*
* or (default values)
*
* $myPacker = new JavaScriptPacker($script);
* $packed = $myPacker->pack();
*
*
* params of the constructor :
* $script: the JavaScript to pack, string.
* $encoding: level of encoding, int or string :
* 0,10,62,95 or 'None', 'Numeric', 'Normal', 'High ASCII'.
* default: 62.
* $fastDecode: include the fast decoder in the packed result, boolean.
* default : true.
* $specialChars: if you are flagged your private and local variables
* in the script, boolean.
* default: false.
*
* The pack() method return the compressed JavasScript, as a string.
*
* see http://dean.edwards.name/packer/usage/ for more information.
*
* Notes :
* # need PHP 5 . Tested with PHP 5.1.2, 5.1.3, 5.1.4, 5.2.3
*
* # The packed result may be different than with the Dean Edwards
* version, but with the same length. The reason is that the PHP
* function usort to sort array don't necessarily preserve the
* original order of two equal member. The Javascript sort function
* in fact preserve this order (but that's not require by the
* ECMAScript standard). So the encoded keywords order can be
* different in the two results.
*
* # Be careful with the 'High ASCII' Level encoding if you use
* UTF-8 in your files...
*/
class JavaScriptPacker
{
// constants
const IGNORE = '$1';
// validate parameters
private $_script = '';
private $_encoding = 62;
private $_fastDecode = true;
private $_specialChars = false;
private $LITERAL_ENCODING = array(
'None' => 0,
'Numeric' => 10,
'Normal' => 62,
'High ASCII' => 95
);
public function __construct($_script, $_encoding = 62, $_fastDecode = true, $_specialChars = false)
{
$this->_script = $_script . "\n";
if (array_key_exists($_encoding, $this->LITERAL_ENCODING))
$_encoding = $this->LITERAL_ENCODING[$_encoding];
$this->_encoding = min((int) $_encoding, 95);
$this->_fastDecode = $_fastDecode;
$this->_specialChars = $_specialChars;
}
public function pack()
{
$this->_addParser('_basicCompression');
if ($this->_specialChars)
$this->_addParser('_encodeSpecialChars');
if ($this->_encoding)
$this->_addParser('_encodeKeywords');
// go!
return $this->_pack($this->_script);
}
// apply all parsing routines
private function _pack($script)
{
for ($i = 0; isset($this->_parsers[$i]); $i++) {
$script = call_user_func(array(&$this, $this->_parsers[$i]), $script);
}
return $script;
}
// keep a list of parsing functions, they'll be executed all at once
private $_parsers = array();
private function _addParser($parser)
{
$this->_parsers[] = $parser;
}
// zero encoding - just removal of white space and comments
private function _basicCompression($script)
{
$parser = new ParseMaster();
// make safe
$parser->escapeChar = '\\';
// protect strings
$parser->add('/\'[^\'\\n\\r]*\'/', self::IGNORE);
$parser->add('/"[^"\\n\\r]*"/', self::IGNORE);
// remove comments
$parser->add('/\\/\\/[^\\n\\r]*[\\n\\r]/', ' ');
$parser->add('/\\/\\*[^*]*\\*+([^\\/][^*]*\\*+)*\\//', ' ');
// protect regular expressions
$parser->add('/\\s+(\\/[^\\/\\n\\r\\*][^\\/\\n\\r]*\\/g?i?)/', '$2'); // IGNORE
$parser->add('/[^\\w\\x24\\/\'"*)\\?:]\\/[^\\/\\n\\r\\*][^\\/\\n\\r]*\\/g?i?/', self::IGNORE);
// remove: ;;; doSomething();
if ($this->_specialChars) $parser->add('/;;;[^\\n\\r]+[\\n\\r]/');
// remove redundant semi-colons
$parser->add('/\\(;;\\)/', self::IGNORE); // protect for (;;) loops
$parser->add('/;+\\s*([};])/', '$2');
// apply the above
$script = $parser->exec($script);
// remove white-space
$parser->add('/(\\b|\\x24)\\s+(\\b|\\x24)/', '$2 $3');
$parser->add('/([+\\-])\\s+([+\\-])/', '$2 $3');
$parser->add('/\\s+/', '');
// done
return $parser->exec($script);
}
private function _encodeSpecialChars($script)
{
$parser = new ParseMaster();
// replace: $name -> n, $$name -> na
$parser->add('/((\\x24+)([a-zA-Z$_]+))(\\d*)/',
array('fn' => '_replace_name')
);
// replace: _name -> _0, double-underscore (__name) is ignored
$regexp = '/\\b_[A-Za-z\\d]\\w*/';
// build the word list
$keywords = $this->_analyze($script, $regexp, '_encodePrivate');
// quick ref
$encoded = $keywords['encoded'];
$parser->add($regexp,
array(
'fn' => '_replace_encoded',
'data' => $encoded
)
);
return $parser->exec($script);
}
private function _encodeKeywords($script)
{
// escape high-ascii values already in the script (i.e. in strings)
if ($this->_encoding > 62)
$script = $this->_escape95($script);
// create the parser
$parser = new ParseMaster();
$encode = $this->_getEncoder($this->_encoding);
// for high-ascii, don't encode single character low-ascii
$regexp = ($this->_encoding > 62) ? '/\\w\\w+/' : '/\\w+/';
// build the word list
$keywords = $this->_analyze($script, $regexp, $encode);
$encoded = $keywords['encoded'];
// encode
$parser->add($regexp,
array(
'fn' => '_replace_encoded',
'data' => $encoded
)
);
if (empty($script)) return $script;
else {
//$res = $parser->exec($script);
//$res = $this->_bootStrap($res, $keywords);
//return $res;
return $this->_bootStrap($parser->exec($script), $keywords);
}
}
private function _analyze($script, $regexp, $encode)
{
// analyse
// retreive all words in the script
$all = array();
preg_match_all($regexp, $script, $all);
$_sorted = array(); // list of words sorted by frequency
$_encoded = array(); // dictionary of word->encoding
$_protected = array(); // instances of "protected" words
$all = $all[0]; // simulate the javascript comportement of global match
if (!empty($all)) {
$unsorted = array(); // same list, not sorted
$protected = array(); // "protected" words (dictionary of word->"word")
$value = array(); // dictionary of charCode->encoding (eg. 256->ff)
$this->_count = array(); // word->count
$i = count($all); $j = 0; //$word = null;
// count the occurrences - used for sorting later
do {
--$i;
$word = '$' . $all[$i];
if (!isset($this->_count[$word])) {
$this->_count[$word] = 0;
$unsorted[$j] = $word;
// make a dictionary of all of the protected words in this script
// these are words that might be mistaken for encoding
//if (is_string($encode) && method_exists($this, $encode))
$values[$j] = call_user_func(array(&$this, $encode), $j);
$protected['$' . $values[$j]] = $j++;
}
// increment the word counter
$this->_count[$word]++;
} while ($i > 0);
// prepare to sort the word list, first we must protect
// words that are also used as codes. we assign them a code
// equivalent to the word itself.
// e.g. if "do" falls within our encoding range
// then we store keywords["do"] = "do";
// this avoids problems when decoding
$i = count($unsorted);
do {
$word = $unsorted[--$i];
if (isset($protected[$word]) /*!= null*/) {
$_sorted[$protected[$word]] = substr($word, 1);
$_protected[$protected[$word]] = true;
$this->_count[$word] = 0;
}
} while ($i);
// sort the words by frequency
// Note: the javascript and php version of sort can be different :
// in php manual, usort :
// " If two members compare as equal,
// their order in the sorted array is undefined."
// so the final packed script is different of the Dean's javascript version
// but equivalent.
// the ECMAscript standard does not guarantee this behaviour,
// and thus not all browsers (e.g. Mozilla versions dating back to at
// least 2003) respect this.
usort($unsorted, array(&$this, '_sortWords'));
$j = 0;
// because there are "protected" words in the list
// we must add the sorted words around them
do {
if (!isset($_sorted[$i]))
$_sorted[$i] = substr($unsorted[$j++], 1);
$_encoded[$_sorted[$i]] = $values[$i];
} while (++$i < count($unsorted));
}
return array(
'sorted' => $_sorted,
'encoded' => $_encoded,
'protected' => $_protected);
}
private $_count = array();
private function _sortWords($match1, $match2)
{
return $this->_count[$match2] - $this->_count[$match1];
}
// build the boot function used for loading and decoding
private function _bootStrap($packed, $keywords)
{
$ENCODE = $this->_safeRegExp('$encode\\($count\\)');
// $packed: the packed script
$packed = "'" . $this->_escape($packed) . "'";
// $ascii: base for encoding
$ascii = min(count($keywords['sorted']), $this->_encoding);
if ($ascii == 0) $ascii = 1;
// $count: number of words contained in the script
$count = count($keywords['sorted']);
// $keywords: list of words contained in the script
foreach ($keywords['protected'] as $i=>$value) {
$keywords['sorted'][$i] = '';
}
// convert from a string to an array
ksort($keywords['sorted']);
$keywords = "'" . implode('|', $keywords['sorted']) . "'.split('|')";
$encode = ($this->_encoding > 62) ? '_encode95' : $this->_getEncoder($ascii);
$encode = $this->_getJSFunction($encode);
$encode = preg_replace('/_encoding/', '$ascii', $encode);
$encode = preg_replace('/arguments\\.callee/', '$encode', $encode);
$inline = '\\$count' . ($ascii > 10 ? '.toString(\\$ascii)' : '');
// $decode: code snippet to speed up decoding
if ($this->_fastDecode) {
// create the decoder
$decode = $this->_getJSFunction('_decodeBody');
if ($this->_encoding > 62)
$decode = preg_replace('/\\\\w/', '[\\xa1-\\xff]', $decode);
// perform the encoding inline for lower ascii values
elseif ($ascii < 36)
$decode = preg_replace($ENCODE, $inline, $decode);
// special case: when $count==0 there are no keywords. I want to keep
// the basic shape of the unpacking funcion so i'll frig the code...
if ($count == 0)
$decode = preg_replace($this->_safeRegExp('($count)\\s*=\\s*1'), '$1=0', $decode, 1);
}
// boot function
$unpack = $this->_getJSFunction('_unpack');
if ($this->_fastDecode) {
// insert the decoder
$this->buffer = $decode;
$unpack = preg_replace_callback('/\\{/', array(&$this, '_insertFastDecode'), $unpack, 1);
}
$unpack = preg_replace('/"/', "'", $unpack);
if ($this->_encoding > 62) { // high-ascii
// get rid of the word-boundaries for regexp matches
$unpack = preg_replace('/\'\\\\\\\\b\'\s*\\+|\\+\s*\'\\\\\\\\b\'/', '', $unpack);
}
if ($ascii > 36 || $this->_encoding > 62 || $this->_fastDecode) {
// insert the encode function
$this->buffer = $encode;
$unpack = preg_replace_callback('/\\{/', array(&$this, '_insertFastEncode'), $unpack, 1);
} else {
// perform the encoding inline
$unpack = preg_replace($ENCODE, $inline, $unpack);
}
// pack the boot function too
$unpackPacker = new JavaScriptPacker($unpack, 0, false, true);
$unpack = $unpackPacker->pack();
// arguments
$params = array($packed, $ascii, $count, $keywords);
if ($this->_fastDecode) {
$params[] = 0;
$params[] = '{}';
}
$params = implode(',', $params);
// the whole thing
//Firefox 4 fix, old: return 'eval(' . $unpack . '(' . $params . "))\n";
return "(typeof setTimeout=='function'?setTimeout:eval)(" . $unpack . "(" . $params . "));\n";
}
private $buffer;
private function _insertFastDecode($match)
{
return '{' . $this->buffer . ';';
}
private function _insertFastEncode($match)
{
return '{$encode=' . $this->buffer . ';';
}
// mmm.. ..which one do i need ??
private function _getEncoder($ascii)
{
return $ascii > 10 ? $ascii > 36 ? $ascii > 62 ?
'_encode95' : '_encode62' : '_encode36' : '_encode10';
}
// zero encoding
// characters: 0123456789
private function _encode10($charCode)
{
return $charCode;
}
// inherent base36 support
// characters: 0123456789abcdefghijklmnopqrstuvwxyz
private function _encode36($charCode)
{
return base_convert($charCode, 10, 36);
}
// hitch a ride on base36 and add the upper case alpha characters
// characters: 0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ
private function _encode62($charCode)
{
$res = '';
if ($charCode >= $this->_encoding) {
$res = $this->_encode62((int) ($charCode / $this->_encoding));
}
$charCode = $charCode % $this->_encoding;
if ($charCode > 35)
return $res . chr($charCode + 29);
else
return $res . base_convert($charCode, 10, 36);
}
// use high-ascii values
// characters: ¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþ
private function _encode95($charCode)
{
$res = '';
if ($charCode >= $this->_encoding)
$res = $this->_encode95($charCode / $this->_encoding);
return $res . chr(($charCode % $this->_encoding) + 161);
}
private function _safeRegExp($string)
{
return '/'.preg_replace('/\$/', '\\\$', $string).'/';
}
private function _encodePrivate($charCode)
{
return "_" . $charCode;
}
// protect characters used by the parser
private function _escape($script)
{
return preg_replace('/([\\\\\'])/', '\\\$1', $script);
}
// protect high-ascii characters already in the script
private function _escape95($script)
{
return preg_replace_callback(
'/[\\xa1-\\xff]/',
array(&$this, '_escape95Bis'),
$script
);
}
private function _escape95Bis($match)
{
return '\x'.((string) dechex(ord($match)));
}
private function _getJSFunction($aName)
{
if (defined('self::JSFUNCTION'.$aName))
return constant('self::JSFUNCTION'.$aName);
else
return '';
}
// JavaScript Functions used.
// Note : In Dean's version, these functions are converted
// with 'String(aFunctionName);'.
// This internal conversion complete the original code, ex :
// 'while (aBool) anAction();' is converted to
// 'while (aBool) { anAction(); }'.
// The JavaScript functions below are corrected.
// unpacking function - this is the boot strap function
// data extracted from this packing routine is passed to
// this function when decoded in the target
// NOTE ! : without the ';' final.
const JSFUNCTION_unpack =
'function ($packed, $ascii, $count, $keywords, $encode, $decode) {
while ($count--) {
if ($keywords[$count]) {
$packed = $packed.replace(new RegExp(\'\\\\b\' + $encode($count) + \'\\\\b\', \'g\'), $keywords[$count]);
}
}
return $packed;
}';
/*
'function ($packed, $ascii, $count, $keywords, $encode, $decode) {
while ($count--)
if ($keywords[$count])
$packed = $packed.replace(new RegExp(\'\\\\b\' + $encode($count) + \'\\\\b\', \'g\'), $keywords[$count]);
return $packed;
}';
*/
// code-snippet inserted into the unpacker to speed up decoding
const JSFUNCTION_decodeBody =
//_decode = function () {
// does the browser support String.replace where the
// replacement value is a function?
' if (!\'\'.replace(/^/, String)) {
// decode all the values we need
while ($count--) {
$decode[$encode($count)] = $keywords[$count] || $encode($count);
}
// global replacement function
$keywords = [function ($encoded) {return $decode[$encoded]}];
// generic match
$encode = function () {return \'\\\\w+\'};
// reset the loop counter - we are now doing a global replace
$count = 1;
}
';
//};
/*
' if (!\'\'.replace(/^/, String)) {
// decode all the values we need
while ($count--) $decode[$encode($count)] = $keywords[$count] || $encode($count);
// global replacement function
$keywords = [function ($encoded) {return $decode[$encoded]}];
// generic match
$encode = function () {return\'\\\\w+\'};
// reset the loop counter - we are now doing a global replace
$count = 1;
}';
*/
// zero encoding
// characters: 0123456789
const JSFUNCTION_encode10 =
'function ($charCode) {
return $charCode;
}';//;';
// inherent base36 support
// characters: 0123456789abcdefghijklmnopqrstuvwxyz
const JSFUNCTION_encode36 =
'function ($charCode) {
return $charCode.toString(36);
}';//;';
// hitch a ride on base36 and add the upper case alpha characters
// characters: 0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ
const JSFUNCTION_encode62 =
'function ($charCode) {
return ($charCode < _encoding ? \'\' : arguments.callee(parseInt($charCode / _encoding))) +
(($charCode = $charCode % _encoding) > 35 ? String.fromCharCode($charCode + 29) : $charCode.toString(36));
}';
// use high-ascii values
// characters: ¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþ
const JSFUNCTION_encode95 =
'function ($charCode) {
return ($charCode < _encoding ? \'\' : arguments.callee($charCode / _encoding)) +
String.fromCharCode($charCode % _encoding + 161);
}';
}
class ParseMaster
{
public $ignoreCase = false;
public $escapeChar = '';
// constants
const EXPRESSION = 0;
const REPLACEMENT = 1;
const LENGTH = 2;
// used to determine nesting levels
private $GROUPS = '/\\(/';//g
private $SUB_REPLACE = '/\\$\\d/';
private $INDEXED = '/^\\$\\d+$/';
private $TRIM = '/([\'"])\\1\\.(.*)\\.\\1\\1$/';
private $ESCAPE = '/\\\./';//g
private $QUOTE = '/\'/';
private $DELETED = '/\\x01[^\\x01]*\\x01/';//g
public function add($expression, $replacement = '')
{
// count the number of sub-expressions
// - add one because each pattern is itself a sub-expression
$length = 1 + preg_match_all($this->GROUPS, $this->_internalEscape((string) $expression), $out);
// treat only strings $replacement
if (is_string($replacement)) {
// does the pattern deal with sub-expressions?
if (preg_match($this->SUB_REPLACE, $replacement)) {
// a simple lookup? (e.g. "$2")
if (preg_match($this->INDEXED, $replacement)) {
// store the index (used for fast retrieval of matched strings)
$replacement = (int) (substr($replacement, 1)) - 1;
} else { // a complicated lookup (e.g. "Hello $2 $1")
// build a function to do the lookup
$quote = preg_match($this->QUOTE, $this->_internalEscape($replacement))
? '"' : "'";
$replacement = array(
'fn' => '_backReferences',
'data' => array(
'replacement' => $replacement,
'length' => $length,
'quote' => $quote
)
);
}
}
}
// pass the modified arguments
if (!empty($expression)) $this->_add($expression, $replacement, $length);
else $this->_add('/^$/', $replacement, $length);
}
public function exec($string)
{
// execute the global replacement
$this->_escaped = array();
// simulate the _patterns.toSTring of Dean
$regexp = '/';
foreach ($this->_patterns as $reg) {
$regexp .= '(' . substr($reg[self::EXPRESSION], 1, -1) . ')|';
}
$regexp = substr($regexp, 0, -1) . '/';
$regexp .= ($this->ignoreCase) ? 'i' : '';
$string = $this->_escape($string, $this->escapeChar);
$string = preg_replace_callback(
$regexp,
array(
&$this,
'_replacement'
),
$string
);
$string = $this->_unescape($string, $this->escapeChar);
return preg_replace($this->DELETED, '', $string);
}
public function reset()
{
// clear the patterns collection so that this object may be re-used
$this->_patterns = array();
}
// private
private $_escaped = array(); // escaped characters
private $_patterns = array(); // patterns stored by index
// create and add a new pattern to the patterns collection
private function _add()
{
$arguments = func_get_args();
$this->_patterns[] = $arguments;
}
// this is the global replace function (it's quite complicated)
private function _replacement($arguments)
{
if (empty($arguments)) return '';
$i = 1; $j = 0;
// loop through the patterns
while (isset($this->_patterns[$j])) {
$pattern = $this->_patterns[$j++];
// do we have a result?
if (isset($arguments[$i]) && ($arguments[$i] != '')) {
$replacement = $pattern[self::REPLACEMENT];
if (is_array($replacement) && isset($replacement['fn'])) {
if (isset($replacement['data'])) $this->buffer = $replacement['data'];
return call_user_func(array(&$this, $replacement['fn']), $arguments, $i);
} elseif (is_int($replacement)) {
return $arguments[$replacement + $i];
}
$delete = ($this->escapeChar == '' ||
strpos($arguments[$i], $this->escapeChar) === false)
? '' : "\x01" . $arguments[$i] . "\x01";
return $delete . $replacement;
// skip over references to sub-expressions
} else {
$i += $pattern[self::LENGTH];
}
}
}
private function _backReferences($match, $offset)
{
$replacement = $this->buffer['replacement'];
$quote = $this->buffer['quote'];
$i = $this->buffer['length'];
while ($i) {
$replacement = str_replace('$'.$i--, $match[$offset + $i], $replacement);
}
return $replacement;
}
private function _replace_name($match, $offset)
{
$length = strlen($match[$offset + 2]);
$start = $length - max($length - strlen($match[$offset + 3]), 0);
return substr($match[$offset + 1], $start, $length) . $match[$offset + 4];
}
private function _replace_encoded($match, $offset)
{
return $this->buffer[$match[$offset]];
}
// php : we cannot pass additional data to preg_replace_callback,
// and we cannot use &$this in create_function, so let's go to lower level
private $buffer;
// encode escaped characters
private function _escape($string, $escapeChar)
{
if ($escapeChar) {
$this->buffer = $escapeChar;
return preg_replace_callback(
'/\\' . $escapeChar . '(.)' .'/',
array(&$this, '_escapeBis'),
$string
);
} else {
return $string;
}
}
private function _escapeBis($match)
{
$this->_escaped[] = $match[1];
return $this->buffer;
}
// decode escaped characters
private function _unescape($string, $escapeChar)
{
if ($escapeChar) {
$regexp = '/'.'\\'.$escapeChar.'/';
$this->buffer = array('escapeChar'=> $escapeChar, 'i' => 0);
return preg_replace_callback(
$regexp,
array(&$this, '_unescapeBis'),
$string
);
} else {
return $string;
}
}
private function _unescapeBis()
{
if (isset($this->_escaped[$this->buffer['i']])
&& $this->_escaped[$this->buffer['i']] != '')
{
$temp = $this->_escaped[$this->buffer['i']];
} else {
$temp = '';
}
$this->buffer['i']++;
return $this->buffer['escapeChar'] . $temp;
}
private function _internalEscape($string)
{
return preg_replace($this->ESCAPE, '', $string);
}
}

View File

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

View File

@@ -0,0 +1,177 @@
<?php
/**
* freeipmi sensor class
*
* PHP version 5
*
* @category PHP
* @package PSI_Sensor
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @version SVN: $Id: class.freeipmi.inc.php 661 2012-08-27 11:26:39Z namiltd $
* @link http://phpsysinfo.sourceforge.net
*/
/**
* getting information from ipmi-sensors
*
* @category PHP
* @package PSI_Sensor
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @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 tcp or file access
*/
public function __construct()
{
parent::__construct();
switch (strtolower(PSI_SENSOR_ACCESS)) {
case 'command':
CommonFunctions::executeProgram('ipmi-sensors', '--output-sensor-thresholds', $lines);
$this->_lines = preg_split("/\n/", $lines, -1, PREG_SPLIT_NO_EMPTY);
break;
case 'file':
if (CommonFunctions::rfts(APP_ROOT.'/data/freeipmi.txt', $lines)) {
$this->_lines = preg_split("/\n/", $lines, -1, PREG_SPLIT_NO_EMPTY);
}
break;
default:
$this->error->addConfigError('__construct()', 'PSI_SENSOR_ACCESS');
break;
}
}
/**
* get temperature information
*
* @return void
*/
private function _temperature()
{
foreach ($this->_lines as $line) {
$buffer = preg_split("/\s*\|\s*/", $line);
if ($buffer[2] == "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[9] != "N/A") $dev->setMax($buffer[9]);
if ($buffer[11] != "'OK'") $dev->setEvent(trim($buffer[11], "'"));
$this->mbinfo->setMbCurrent($dev);
}
}
}
/**
* get the information
*
* @see PSI_Interface_Sensor::build()
*
* @return Void
*/
public function build()
{
$this->_temperature();
$this->_voltage();
$this->_fans();
$this->_power();
$this->_current();
}
}

View File

@@ -0,0 +1,135 @@
<?php
/**
* hddtemp sensor class
*
* PHP version 5
*
* @category PHP
* @package PSI_Sensor
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @version SVN: $Id: class.hddtemp.inc.php 661 2012-08-27 11:26:39Z namiltd $
* @link http://phpsysinfo.sourceforge.net
*/
/**
* getting information from hddtemp
*
* @category PHP
* @package PSI_Sensor
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @author T.A. van Roermund <timo@van-roermund.nl>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @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 array temperatures in array
*/
private function _temperature()
{
$ar_buf = array();
switch (strtolower(PSI_HDD_TEMP)) {
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()", "PSI_HDD_TEMP");
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);
}
}
}
}
/**
* get the information
*
* @see PSI_Interface_Sensor::build()
*
* @return Void
*/
public function build()
{
$this->_temperature();
}
}

View File

@@ -0,0 +1,159 @@
<?php
/**
* healthd sensor class
*
* PHP version 5
*
* @category PHP
* @package PSI_Sensor
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @version SVN: $Id: class.healthd.inc.php 661 2012-08-27 11:26:39Z namiltd $
* @link http://phpsysinfo.sourceforge.net
*/
/**
* getting information from healthd
*
* @category PHP
* @package PSI_Sensor
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @version Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
class Healthd extends Sensors
{
/**
* content to parse
*
* @var array
*/
private $_lines = array();
/**
* fill the private content var through tcp or file access
*/
public function __construct()
{
parent::__construct();
switch (strtolower(PSI_SENSOR_ACCESS)) {
case 'command':
$lines = "";
CommonFunctions::executeProgram('healthdc', '-t', $lines);
$this->_lines = preg_split("/\n/", $lines, -1, PREG_SPLIT_NO_EMPTY);
break;
case 'file':
if (CommonFunctions::rfts(APP_ROOT.'/data/healthd.txt', $lines)) {
$this->_lines = preg_split("/\n/", $lines, -1, PREG_SPLIT_NO_EMPTY);
}
break;
default:
$this->error->addConfigError('__construct()', 'PSI_SENSOR_ACCESS');
break;
}
}
/**
* get temperature information
*
* @return void
*/
private function _temperature()
{
$ar_buf = preg_split("/\t+/", $this->_lines);
$dev1 = new SensorDevice();
$dev1->setName('temp1');
$dev1->setValue($ar_buf[1]);
$dev1->setMax(70);
$this->mbinfo->setMbTemp($dev1);
$dev2 = new SensorDevice();
$dev2->setName('temp1');
$dev2->setValue($ar_buf[2]);
$dev2->setMax(70);
$this->mbinfo->setMbTemp($dev2);
$dev3 = new SensorDevice();
$dev3->setName('temp1');
$dev3->setValue($ar_buf[3]);
$dev3->setMax(70);
$this->mbinfo->setMbTemp($dev3);
}
/**
* get fan information
*
* @return void
*/
private function _fans()
{
$ar_buf = preg_split("/\t+/", $this->_lines);
$dev1 = new SensorDevice();
$dev1->setName('fan1');
$dev1->setValue($ar_buf[4]);
$dev1->setMin(3000);
$this->mbinfo->setMbFan($dev1);
$dev2 = new SensorDevice();
$dev2->setName('fan2');
$dev2->setValue($ar_buf[5]);
$dev2->setMin(3000);
$this->mbinfo->setMbFan($dev2);
$dev3 = new SensorDevice();
$dev3->setName('fan3');
$dev3->setValue($ar_buf[6]);
$dev3->setMin(3000);
$this->mbinfo->setMbFan($dev3);
}
/**
* get voltage information
*
* @return array voltage in array with lable
*/
private function _voltage()
{
$ar_buf = preg_split("/\t+/", $this->_lines);
$dev1 = new SensorDevice();
$dev1->setName('Vcore1');
$dev1->setValue($ar_buf[7]);
$this->mbinfo->setMbVolt($dev1);
$dev2 = new SensorDevice();
$dev2->setName('Vcore2');
$dev2->setValue($ar_buf[8]);
$this->mbinfo->setMbVolt($dev2);
$dev3 = new SensorDevice();
$dev3->setName('3volt');
$dev3->setValue($ar_buf[9]);
$this->mbinfo->setMbVolt($dev3);
$dev4 = new SensorDevice();
$dev4->setName('+5Volt');
$dev4->setValue($ar_buf[10]);
$this->mbinfo->setMbVolt($dev4);
$dev5 = new SensorDevice();
$dev5->setName('+12Volt');
$dev5->setValue($ar_buf[11]);
$this->mbinfo->setMbVolt($dev5);
$dev6 = new SensorDevice();
$dev6->setName('-12Volt');
$dev6->setValue($ar_buf[12]);
$this->mbinfo->setMbVolt($dev6);
$dev7 = new SensorDevice();
$dev7->setName('-5Volt');
$dev7->setValue($ar_buf[13]);
$this->mbinfo->setMbVolt($dev7);
}
/**
* get the information
*
* @see PSI_Interface_Sensor::build()
*
* @return Void
*/
public function build()
{
$this->_temperature();
$this->_fans();
$this->_voltage();
}
}

View File

@@ -0,0 +1,156 @@
<?php
/**
* hwsensors sensor class
*
* PHP version 5
*
* @category PHP
* @package PSI_Sensor
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @version SVN: $Id: class.hwsensors.inc.php 661 2012-08-27 11:26:39Z namiltd $
* @link http://phpsysinfo.sourceforge.net
*/
/**
* getting information from hwsensors
*
* @category PHP
* @package PSI_Sensor
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @version Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
class HWSensors extends Sensors
{
/**
* content to parse
*
* @var array
*/
private $_lines = array();
/**
* fill the private content var through tcp or file access
*/
public function __construct()
{
parent::__construct();
$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);
}
/**
* 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);
}
}
}
/**
* 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);
}
}
}
/**
* 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);
}
}
}
/**
* get the information
*
* @see PSI_Interface_Sensor::build()
*
* @return Void
*/
public function build()
{
$this->_temperature();
$this->_voltage();
$this->_fans();
}
}

View File

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

View File

@@ -0,0 +1,220 @@
<?php
/**
* ipmiutil sensor class
*
* PHP version 5
*
* @category PHP
* @package PSI_Sensor
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @version SVN: $Id: class.ipmiutil.inc.php 661 2012-08-27 11:26:39Z namiltd $
* @link http://phpsysinfo.sourceforge.net
*/
/**
* getting information from ipmi-sensors
*
* @category PHP
* @package PSI_Sensor
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @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 tcp or file access
*/
public function __construct()
{
parent::__construct();
switch (strtolower(PSI_SENSOR_ACCESS)) {
case 'command':
CommonFunctions::executeProgram('ipmiutil', 'sensor -stw', $lines);
$this->_lines = preg_split("/\r?\n/", $lines, -1, PREG_SPLIT_NO_EMPTY);
break;
case 'file':
if (CommonFunctions::rfts(APP_ROOT.'/data/ipmiutil.txt', $lines)) {
$this->_lines = preg_split("/\r?\n/", $lines, -1, PREG_SPLIT_NO_EMPTY);
}
break;
default:
$this->error->addConfigError('__construct()', 'PSI_SENSOR_ACCESS');
break;
}
}
/**
* get temperature information
*
* @return void
*/
private function _temperature()
{
foreach ($this->_lines as $line) {
$buffer = preg_split("/\s*\|\s*/", $line);
if (isset($buffer[2]) && $buffer[2] == "Temperature" && $buffer[1] == "Full" && isset($buffer[6]) && preg_match("/^(\S+)\sC$/", $buffer[6], $value)) {
$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)) {
$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)) {
$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)) {
$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)) {
$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->setMbCurrent($dev);
}
}
}
/**
* get the information
*
* @see PSI_Interface_Sensor::build()
*
* @return Void
*/
public function build()
{
$this->_temperature();
$this->_voltage();
$this->_fans();
$this->_power();
$this->_current();
}
}

View File

@@ -0,0 +1,91 @@
<?php
/**
* K8Temp sensor class
*
* PHP version 5
*
* @category PHP
* @package PSI_Sensor
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @version SVN: $Id: class.k8temp.inc.php 661 2012-08-27 11:26:39Z namiltd $
* @link http://phpsysinfo.sourceforge.net
*/
/**
* getting information from k8temp
*
* @category PHP
* @package PSI_Sensor
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @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 (strtolower(PSI_SENSOR_ACCESS)) {
case 'command':
$lines = "";
CommonFunctions::executeProgram('k8temp', '', $lines);
$this->_lines = preg_split("/\n/", $lines, -1, PREG_SPLIT_NO_EMPTY);
break;
case 'file':
if (CommonFunctions::rfts(APP_ROOT.'/data/k8temp.txt', $lines)) {
$this->_lines = preg_split("/\n/", $lines, -1, PREG_SPLIT_NO_EMPTY);
}
break;
default:
$this->error->addConfigError('__construct()', 'PSI_SENSOR_ACCESS');
break;
}
}
/**
* get temperature information
*
* @return void
*/
private function _temperature()
{
foreach ($this->_lines as $line) {
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();
}
}

View File

@@ -0,0 +1,411 @@
<?php
/**
* lmsensor sensor class
*
* PHP version 5
*
* @category PHP
* @package PSI_Sensor
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @version SVN: $Id: class.lmsensors.inc.php 661 2012-08-27 11:26:39Z namiltd $
* @link http://phpsysinfo.sourceforge.net
*/
/**
* getting information from lmsensor
*
* @category PHP
* @package PSI_Sensor
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @version Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
class LMSensors extends Sensors
{
/**
* content to parse
*
* @var array
*/
private $_lines = array();
/**
* fill the private content var through tcp or file access
*/
public function __construct()
{
parent::__construct();
switch (strtolower(PSI_SENSOR_ACCESS)) {
case 'command':
if (CommonFunctions::executeProgram("sensors", "", $lines)) {
// Martijn Stolk: Dirty fix for misinterpreted output of sensors,
// where info could come on next line when the label is too long.
$lines = str_replace(":\n", ":", $lines);
$lines = str_replace("\n\n", "\n", $lines);
$this->_lines = preg_split("/\n/", $lines, -1, PREG_SPLIT_NO_EMPTY);
}
break;
case 'file':
if (CommonFunctions::rfts(APP_ROOT.'/data/lmsensors.txt', $lines)) {
$lines = str_replace(":\n", ":", $lines);
$lines = str_replace("\n\n", "\n", $lines);
$this->_lines = preg_split("/\n/", $lines, -1, PREG_SPLIT_NO_EMPTY);
}
break;
default:
$this->error->addConfigError('__construct()', 'PSI_SENSOR_ACCESS');
break;
}
}
/**
* get temperature information
*
* @return void
*/
private function _temperature()
{
$ar_buf = array();
foreach ($this->_lines as $line) {
$data = array();
if (preg_match("/(.*):(.*)\((.*)=(.*),(.*)=(.*)\)(.*)/", $line, $data)) {
;
} elseif (preg_match("/(.*):(.*)\((.*)=(.*)\)(.*)/", $line, $data)) {
;
} else {
preg_match("/(.*):(.*)/", $line, $data);
}
if (count($data) > 1) {
$temp = substr(trim($data[2]), -1);
switch ($temp) {
case "C":
// case "F":
array_push($ar_buf, $line);
}
}
}
foreach ($ar_buf as $line) {
$data = array();
if (preg_match("/(.*):(.*).C[ ]*\((.*)=(.*).C,(.*)=(.*).C\)(.*)\)/", $line, $data)) {
;
} elseif (preg_match("/(.*):(.*).C[ ]*\((.*)=(.*).C,(.*)=(.*).C\)(.*)/", $line, $data)) {
;
} elseif (preg_match("/(.*):(.*).C[ ]*\((.*)=(.*).C\)(.*)/", $line, $data)) {
;
} elseif (preg_match("/(.*):(.*).C[ \t]+/", $line, $data)) {
;
} else {
preg_match("/(.*):(.*).C$/", $line, $data);
}
foreach ($data as $key=>$value) {
if (preg_match("/^\+?(-?[0-9\.]+).?$/", trim($value), $newvalue)) {
$data[$key] = 0+trim($newvalue[1]);
} else {
$data[$key] = trim($value);
}
}
$dev = new SensorDevice();
if (strlen($data[1]) == 4) {
if ($data[1][0] == "T") {
if ($data[1][1] == "A") {
$data[1] = $data[1] . " Ambient";
} elseif ($data[1][1] == "C") {
$data[1] = $data[1] . " CPU";
} elseif ($data[1][1] == "G") {
$data[1] = $data[1] . " GPU";
} elseif ($data[1][1] == "H") {
$data[1] = $data[1] . " Harddisk";
} elseif ($data[1][1] == "L") {
$data[1] = $data[1] . " LCD";
} elseif ($data[1][1] == "O") {
$data[1] = $data[1] . " ODD";
} elseif ($data[1][1] == "B") {
$data[1] = $data[1] . " Battery";
}
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";
}
}
}
$dev->setName($data[1]);
$dev->setValue($data[2]);
if (isset($data[6]) && $data[2] <= $data[6]) {
$dev->setMax(max($data[4], $data[6]));
} elseif (isset($data[4]) && $data[2] <= $data[4]) {
$dev->setMax($data[4]);
}
if (preg_match("/\sALARM(\s*)$/", $line)) {
$dev->setEvent("Alarm");
}
$this->mbinfo->setMbTemp($dev);
}
}
/**
* get fan information
*
* @return void
*/
private function _fans()
{
$ar_buf = array();
foreach ($this->_lines as $line) {
$data = array();
if (preg_match("/(.*):(.*)\((.*)=(.*),(.*)=(.*)\)(.*)/", $line, $data)) {
;
} elseif (preg_match("/(.*):(.*)\((.*)=(.*)\)(.*)/", $line, $data)) {
;
} else {
preg_match("/(.*):(.*)/", $line, $data);
}
if (count($data) > 1) {
$temp = substr(trim($data[2]), -4);
switch ($temp) {
case " RPM":
array_push($ar_buf, $line);
}
}
}
foreach ($ar_buf as $line) {
$data = array();
if (preg_match("/(.*):(.*) RPM[ ]*\((.*)=(.*) RPM,(.*)=(.*)\)(.*)\)/", $line, $data)) {
;
} elseif (preg_match("/(.*):(.*) RPM[ ]*\((.*)=(.*) RPM,(.*)=(.*)\)(.*)/", $line, $data)) {
;
} elseif (preg_match("/(.*):(.*) RPM[ ]*\((.*)=(.*) RPM\)(.*)/", $line, $data)) {
;
} elseif (preg_match("/(.*):(.*) RPM[ \t]+/", $line, $data)) {
;
} else {
preg_match("/(.*):(.*) RPM$/", $line, $data);
}
$dev = new SensorDevice();
$dev->setName(trim($data[1]));
$dev->setValue(trim($data[2]));
if (isset($data[4])) {
$dev->setMin(trim($data[4]));
}
if (preg_match("/\sALARM(\s*)$/", $line)) {
$dev->setEvent("Alarm");
}
$this->mbinfo->setMbFan($dev);
}
}
/**
* get voltage information
*
* @return void
*/
private function _voltage()
{
$ar_buf = array();
foreach ($this->_lines as $line) {
$data = array();
if (preg_match("/(.*):(.*)\((.*)=(.*),(.*)=(.*)\)(.*)/", $line, $data)) {
;
} elseif (preg_match("/(.*):(.*)\(/", $line, $data)) {
;
} else {
preg_match("/(.*):(.*)/", $line, $data);
}
if (count($data) > 1) {
$temp = substr(trim($data[2]), -2);
switch ($temp) {
case " V":
array_push($ar_buf, $line);
}
}
}
foreach ($ar_buf as $line) {
$data = array();
if (preg_match("/(.*):(.*) V[ ]*\((.*)=(.*) V,(.*)=(.*) V\)(.*)\)/", $line, $data)) {
;
} elseif (preg_match("/(.*):(.*) V[ ]*\((.*)=(.*) V,(.*)=(.*) V\)(.*)/", $line, $data)) {
;
} elseif (preg_match("/(.*):(.*) V[ \t]+/", $line, $data)) {
;
} else {
preg_match("/(.*):(.*) V$/", $line, $data);
}
foreach ($data as $key=>$value) {
if (preg_match("/^\+?(-?[0-9\.]+)$/", trim($value), $newvalue)) {
$data[$key] = 0+trim($newvalue[1]);
} else {
$data[$key] = trim($value);
}
}
if (isset($data[1])) {
$dev = new SensorDevice();
$dev->setName($data[1]);
$dev->setValue($data[2]);
if (isset($data[4])) {
$dev->setMin($data[4]);
}
if (isset($data[6])) {
$dev->setMax($data[6]);
}
if (preg_match("/\sALARM(\s*)$/", $line)) {
$dev->setEvent("Alarm");
}
$this->mbinfo->setMbVolt($dev);
}
}
}
/**
* get power information
*
* @return void
*/
private function _power()
{
$ar_buf = array();
foreach ($this->_lines as $line) {
$data = array();
if (preg_match("/(.*):(.*)\((.*)=(.*),(.*)=(.*)\)(.*)/", $line, $data)) {
;
} elseif (preg_match("/(.*):(.*)\((.*)=(.*)\)(.*)/", $line, $data)) {
;
} else {
preg_match("/(.*):(.*)/", $line, $data);
}
if (count($data) > 1) {
$temp = substr(trim($data[2]), -2);
switch ($temp) {
case " W":
array_push($ar_buf, $line);
}
}
}
foreach ($ar_buf as $line) {
$data = array();
/* not tested yet
if (preg_match("/(.*):(.*) W[ ]*\((.*)=(.*) W,(.*)=(.*) W\)(.*)\)/", $line, $data)) {
;
} elseif (preg_match("/(.*):(.*) W[ ]*\((.*)=(.*) W,(.*)=(.*) W\)(.*)/", $line, $data)) {
;
} else
*/
if (preg_match("/(.*):(.*) W[ ]*\((.*)=(.*) W\)(.*)/", $line, $data)) {
;
} elseif (preg_match("/(.*):(.*) W[ \t]+/", $line, $data)) {
;
} else {
preg_match("/(.*):(.*) W$/", $line, $data);
}
foreach ($data as $key=>$value) {
if (preg_match("/^\+?([0-9\.]+).?$/", trim($value), $newvalue)) {
$data[$key] = trim($newvalue[1]);
} else {
$data[$key] = trim($value);
}
}
$dev = new SensorDevice();
$dev->setName($data[1]);
$dev->setValue($data[2]);
if (isset($data[6]) && $data[2] <= $data[6]) {
$dev->setMax(max($data[4], $data[6]));
} elseif (isset($data[4]) && $data[2] <= $data[4]) {
$dev->setMax($data[4]);
}
if (preg_match("/\sALARM(\s*)$/", $line)) {
$dev->setEvent("Alarm");
}
$this->mbinfo->setMbPower($dev);
}
}
/**
* get current information
*
* @return void
*/
private function _current()
{
$ar_buf = array();
foreach ($this->_lines as $line) {
$data = array();
if (preg_match("/(.*):(.*)\((.*)=(.*),(.*)=(.*)\)(.*)/", $line, $data)) {
;
} elseif (preg_match("/(.*):(.*)\((.*)=(.*)\)(.*)/", $line, $data)) {
;
} else {
preg_match("/(.*):(.*)/", $line, $data);
}
if (count($data) > 1) {
$temp = substr(trim($data[2]), -2);
switch ($temp) {
case " A":
array_push($ar_buf, $line);
}
}
}
foreach ($ar_buf as $line) {
$data = array();
/* not tested yet
if (preg_match("/(.*):(.*) A[ ]*\((.*)=(.*) A,(.*)=(.*) A\)(.*)\)/", $line, $data)) {
;
} elseif (preg_match("/(.*):(.*) A[ ]*\((.*)=(.*) A,(.*)=(.*) A\)(.*)/", $line, $data)) {
;
} else
*/
if (preg_match("/(.*):(.*) A[ ]*\((.*)=(.*) A\)(.*)/", $line, $data)) {
;
} elseif (preg_match("/(.*):(.*) A[ \t]+/", $line, $data)) {
;
} else {
preg_match("/(.*):(.*) A$/", $line, $data);
}
foreach ($data as $key=>$value) {
if (preg_match("/^\+?([0-9\.]+).?$/", trim($value), $newvalue)) {
$data[$key] = trim($newvalue[1]);
} else {
$data[$key] = trim($value);
}
}
$dev = new SensorDevice();
$dev->setName($data[1]);
$dev->setValue($data[2]);
if (isset($data[6]) && $data[2] <= $data[6]) {
$dev->setMax(max($data[4], $data[6]));
} elseif (isset($data[4]) && $data[2] <= $data[4]) {
$dev->setMax($data[4]);
}
if (preg_match("/\sALARM(\s*)$/", $line)) {
$dev->setEvent("Alarm");
}
$this->mbinfo->setMbCurrent($dev);
}
}
/**
* get the information
*
* @see PSI_Interface_Sensor::build()
*
* @return Void
*/
public function build()
{
$this->_temperature();
$this->_voltage();
$this->_fans();
$this->_power();
$this->_current();
}
}

View File

@@ -0,0 +1,138 @@
<?php
/**
* MBM5 sensor class
*
* PHP version 5
*
* @category PHP
* @package PSI_Sensor
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @version SVN: $Id: class.mbm5.inc.php 661 2012-08-27 11:26:39Z namiltd $
* @link http://phpsysinfo.sourceforge.net
*/
/**
* getting information from Motherboard Monitor 5
* information retrival through csv file
*
* @category PHP
* @package PSI_Sensor
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @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();
/**
* array withe the values
*
* @var array
*/
private $_buf_value = array();
/**
* read the MBM5.csv file and fill the private arrays
*/
public function __construct()
{
parent::__construct();
switch (strtolower(PSI_SENSOR_ACCESS)) {
case 'file':
$delim = "/;/";
CommonFunctions::rfts(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);
break;
default:
$this->error->addConfigError('__construct()', 'PSI_SENSOR_ACCESS');
break;
}
}
/**
* 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();
}
}

View File

@@ -0,0 +1,143 @@
<?php
/**
* mbmon sensor class
*
* PHP version 5
*
* @category PHP
* @package PSI_Sensor
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @version SVN: $Id: class.mbmon.inc.php 661 2012-08-27 11:26:39Z namiltd $
* @link http://phpsysinfo.sourceforge.net
*/
/**
* getting information from mbmon
*
* @category PHP
* @package PSI_Sensor
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @version Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
class MBMon extends Sensors
{
/**
* content to parse
*
* @var array
*/
private $_lines = array();
/**
* fill the private content var through tcp or file access
*/
public function __construct()
{
parent::__construct();
switch (strtolower(PSI_SENSOR_ACCESS)) {
case '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 'file':
if (CommonFunctions::rfts(APP_ROOT.'/data/mbmon.txt', $lines)) {
$this->_lines = preg_split("/\n/", $lines, -1, PREG_SPLIT_NO_EMPTY);
}
break;
default:
$this->error->addConfigError('__construct()', 'PSI_SENSOR_ACCESS');
break;
}
}
/**
* get temperature information
*
* @return void
*/
private function _temperature()
{
foreach ($this->_lines as $line) {
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);
}
}
}
}
/**
* 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);
}
}
}
}
/**
* 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);
}
}
}
}
/**
* get the information
*
* @see PSI_Interface_Sensor::build()
*
* @return void
*/
public function build()
{
$this->_temperature();
$this->_voltage();
$this->_fans();
}
}

View File

@@ -0,0 +1,145 @@
<?php
/**
* Open Hardware Monitor sensor class
*
* PHP version 5
*
* @category PHP
* @package PSI_Sensor
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @version SVN: $Id: class.ohm.inc.php 661 2012-08-27 11:26:39Z namiltd $
* @link http://phpsysinfo.sourceforge.net
*/
/**
* getting information from Open Hardware Monitor
*
* @category PHP
* @package PSI_Sensor
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @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;
// don't set this params for local connection, it will not work
$strHostname = '';
$strUser = '';
$strPassword = '';
try {
// initialize the wmi object
$objLocator = new COM('WbemScripting.SWbemLocator');
if ($strHostname == "") {
$_wmi = $objLocator->ConnectServer($strHostname, 'root\OpenHardwareMonitor');
} else {
$_wmi = $objLocator->ConnectServer($strHostname, 'root\OpenHardwareMonitor', $strHostname.'\\'.$strUser, $strPassword);
}
} catch (Exception $e) {
$this->error->addError("WMI connect error", "PhpSysInfo can not connect to the WMI interface for OpenHardwareMonitor data.");
}
if ($_wmi) {
$this->_buf = CommonFunctions::getWMI($_wmi, 'Sensor', array('Parent', 'Name', 'SensorType', 'Value'));
}
}
/**
* get temperature information
*
* @return void
*/
private function _temperature()
{
if ($this->_buf) foreach ($this->_buf as $buffer) {
if ($buffer['SensorType'] == "Temperature") {
$dev = new SensorDevice();
$dev->setName($buffer['Parent'].' '.$buffer['Name']);
$dev->setValue($buffer['Value']);
$this->mbinfo->setMbTemp($dev);
}
}
}
/**
* get voltage information
*
* @return void
*/
private function _voltage()
{
if ($this->_buf) foreach ($this->_buf as $buffer) {
if ($buffer['SensorType'] == "Voltage") {
$dev = new SensorDevice();
$dev->setName($buffer['Parent'].' '.$buffer['Name']);
$dev->setValue($buffer['Value']);
$this->mbinfo->setMbVolt($dev);
}
}
}
/**
* get fan information
*
* @return void
*/
private function _fans()
{
if ($this->_buf) foreach ($this->_buf as $buffer) {
if ($buffer['SensorType'] == "Fan") {
$dev = new SensorDevice();
$dev->setName($buffer['Parent'].' '.$buffer['Name']);
$dev->setValue($buffer['Value']);
$this->mbinfo->setMbFan($dev);
}
}
}
/**
* get power information
*
* @return void
*/
private function _power()
{
if ($this->_buf) foreach ($this->_buf as $buffer) {
if ($buffer['SensorType'] == "Power") {
$dev = new SensorDevice();
$dev->setName($buffer['Parent'].' '.$buffer['Name']);
$dev->setValue($buffer['Value']);
$this->mbinfo->setMbPower($dev);
}
}
}
/**
* get the information
*
* @see PSI_Interface_Sensor::build()
*
* @return Void
*/
public function build()
{
$this->_temperature();
$this->_voltage();
$this->_fans();
$this->_power();
}
}

View File

@@ -0,0 +1,62 @@
<?php
/**
* pitemp sensor class
*
* PHP version 5
*
* @category PHP
* @package PSI_Sensor
* @author Marc Hillesheim <hawkeyexp@gmail.com>
* @copyright 2012 Marc Hillesheim
* @link http://pi.no-ip.biz
*/
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, 0, 4096, false)) { // Not Banana Pi
CommonFunctions::rfts('/sys/class/thermal/thermal_zone0/temp', $temp);
CommonFunctions::rfts('/sys/class/thermal/thermal_zone0/trip_point_0_temp', $temp_max, 0, 4096, PSI_DEBUG);
}
if (!is_null($temp) && (trim($temp) != "")) {
$dev = new SensorDevice();
$dev->setName("CPU 1");
$dev->setValue($temp / 1000);
if (!is_null($temp_max) && (trim($temp_max) != "") && ($temp_max > 0)) {
$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, 0, 4096, false) && !is_null($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, 0, 4096, false) && !is_null($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();
}
}

View File

@@ -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 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 Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
abstract class Sensors implements PSI_Interface_Sensor
{
/**
* object for error handling
*
* @var Error
*/
protected $error;
/**
* object for the information
*
* @var MBInfo
*/
protected $mbinfo;
/**
* build the global Error object
*/
public function __construct()
{
$this->error = 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;
}
}

View File

@@ -0,0 +1,132 @@
<?php
/**
* Thermal Zone sensor class
*
* PHP version 5
*
* @category PHP
* @package PSI_Sensor
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @version SVN: $Id: class.ohm.inc.php 661 2012-08-27 11:26:39Z namiltd $
* @link http://phpsysinfo.sourceforge.net
*/
/**
* getting information from Thermal Zone WMI class
*
* @category PHP
* @package PSI_Sensor
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @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;
// don't set this params for local connection, it will not work
$strHostname = '';
$strUser = '';
$strPassword = '';
try {
// initialize the wmi object
$objLocator = new COM('WbemScripting.SWbemLocator');
if ($strHostname == "") {
$_wmi = $objLocator->ConnectServer($strHostname, 'root\WMI');
} else {
$_wmi = $objLocator->ConnectServer($strHostname, 'root\WMI', $strHostname.'\\'.$strUser, $strPassword);
}
} catch (Exception $e) {
$this->error->addError("WMI connect error", "PhpSysInfo can not connect to the WMI interface for ThermalZone data.");
}
if ($_wmi) {
$this->_buf = CommonFunctions::getWMI($_wmi, 'MSAcpi_ThermalZoneTemperature', array('InstanceName', 'CriticalTripPoint', 'CurrentTemperature'));
}
}
}
/**
* 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 {
foreach (glob('/sys/class/thermal/thermal_zone*/') as $thermalzone) {
$thermalzonetemp = $thermalzone.'temp';
$temp = null;
if (CommonFunctions::rfts($thermalzonetemp, $temp, 0, 4096, false) && !is_null($temp) && (trim($temp) != "")) {
if ($temp >= 1000) {
$temp = $temp / 1000;
}
if ($temp > -40) {
$dev = new SensorDevice();
$dev->setValue($temp);
$temp_type = null;
if (CommonFunctions::rfts($thermalzone.'type', $temp_type, 0, 4096, false) && !is_null($temp_type) && (trim($temp_type) != "")) {
$dev->setName($temp_type);
}
$temp_max = null;
if (CommonFunctions::rfts($thermalzone.'trip_point_0_temp', $temp_max, 0, 4096, false) && !is_null($temp_max) && (trim($temp_max) != "") && ($temp_max > 0)) {
if ($temp_max >= 1000) {
$temp_max = $temp_max / 1000;
}
$dev->setMax($temp_max);
}
$this->mbinfo->setMbTemp($dev);
}
}
}
}
}
/**
* get the information
*
* @see PSI_Interface_Sensor::build()
*
* @return Void
*/
public function build()
{
$this->_temperature();
}
}

View File

@@ -0,0 +1,381 @@
<?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 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 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) {
$this->sys->setHostname(getenv('SERVER_NAME'));
} else {
if (CommonFunctions::executeProgram('hostname', '', $ret)) {
$this->sys->setHostname($ret);
}
} */
$this->sys->setHostname(getenv('SERVER_NAME'));
}
/**
* IP of the Virtual Host Name
* @return void
*/
private function _ip()
{
if (PSI_USE_VHOST === true) {
$this->sys->setIp(gethostbyname($this->sys->getHostname()));
} else {
if (!($result = getenv('SERVER_ADDR'))) {
$this->sys->setIp(gethostbyname($this->sys->getHostname()));
} else {
$this->sys->setIp($result);
}
}
}
/**
* IBM AIX Version
* @return void
*/
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+) days,\s*(\d+):(\d+),/", $buf, $ar_buf) || 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);
}
}
}
/**
* Number of Users
* @return void
*/
private function _users()
{
if (CommonFunctions::executeProgram('who', '| wc -l', $buf, PSI_DEBUG)) {
$this->sys->setUsers($buf);
}
}
/**
* Processor Load
* optionally create a loadbar
* @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);
while (list(, $line) = each($lines)) {
$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 void
*/
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");
$this->_distro();
$this->_hostname();
$this->_ip();
$this->_kernel();
$this->_uptime();
$this->_users();
$this->_loadavg();
$this->_cpuinfo();
$this->_pci();
$this->_ide();
$this->_scsi();
$this->_usb();
$this->_network();
$this->_memory();
$this->_filesystems();
}
}

View File

@@ -0,0 +1,254 @@
<?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 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 Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
class Android extends Linux
{
/**
* call parent constructor
*/
public function __construct()
{
parent::__construct();
}
/**
* Kernel Version
*
* @return void
*/
private function _kernel()
{
if (CommonFunctions::rfts('/proc/version', $strBuf, 1)) {
if (preg_match('/version (.*?) /', $strBuf, $ar_buf)) {
$result = $ar_buf[1];
if (preg_match('/SMP/', $strBuf)) {
$result .= ' (SMP)';
}
$this->sys->setKernel($result);
}
}
}
/**
* Number of Users
*
* @return void
*/
private function _users()
{
$this->sys->setUsers(1);
}
/**
* filesystem information
*
* @return void
*/
private function _filesystems()
{
if (CommonFunctions::executeProgram('df', '2>/dev/null ', $df, PSI_DEBUG)) {
$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);
}
}
}
}
}
/**
* Distribution
*
* @return void
*/
private function _distro()
{
$buf = "";
if (CommonFunctions::rfts('/system/build.prop', $lines, 0, 4096, false)
&& 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(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 (CommonFunctions::rfts('/system/build.prop', $lines, 0, 4096, false)) {
$buf = "";
if (preg_match('/^ro\.product\.manufacturer=([^\n]+)/m', $lines, $ar_buf)) {
$buf .= ' '.trim($ar_buf[1]);
}
if (preg_match('/^ro\.product\.model=([^\n]+)/m', $lines, $ar_buf) && (trim($buf) !== trim($ar_buf[1]))) {
$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 array
*/
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);
}
}
}
}
/**
* USB devices
*
* @return array
*/
private function _usb()
{
if (file_exists('/dev/bus/usb') && CommonFunctions::executeProgram('lsusb', '', $bufr, false)) {
$bufe = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
foreach ($bufe as $buf) {
$device = preg_split("/ /", $buf, 6);
if (isset($device[5]) && trim($device[5]) != "") {
$dev = new HWDevice();
$dev->setName(trim($device[5]));
$this->sys->setUsbDevices($dev);
}
}
}
}
/**
* get the information
*
* @see PSI_Interface_OS::build()
*
* @return Void
*/
public function build()
{
$this->_distro();
$this->_hostname();
$this->_ip();
$this->_kernel();
$this->_machine();
$this->_uptime();
$this->_users();
$this->_cpuinfo();
$this->_pci();
$this->_usb();
$this->_i2c();
$this->_network();
$this->_memory();
$this->_filesystems();
$this->_loadavg();
$this->_processes();
}
}

View File

@@ -0,0 +1,592 @@
<?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 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 Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
abstract class BSDCommon extends OS
{
/**
* content of the syslog
*
* @var array
*/
private $_dmesg = array();
/**
* 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 = "";
/**
* regexp1 for pci information out of the syslog
*
* @var string
*/
private $_PCIRegExp1 = "";
/**
* regexp1 for pci information out of the syslog
*
* @var string
*/
private $_PCIRegExp2 = "";
/**
* call parent constructor
*/
public function __construct()
{
parent::__construct();
}
/**
* 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 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 (count($this->_dmesg) === 0) {
if (PSI_OS != "Darwin") {
if (CommonFunctions::rfts('/var/run/dmesg.boot', $buf, 0, 4096, false) || CommonFunctions::rfts('/var/log/dmesg.boot', $buf, 0, 4096, false) || CommonFunctions::rfts('/var/run/dmesg.boot', $buf)) { // Once again but with debug
$parts = preg_split("/rebooting|Uptime/", $buf, -1, PREG_SPLIT_NO_EMPTY);
$this->_dmesg = preg_split("/\n/", $parts[count($parts) - 1], -1, PREG_SPLIT_NO_EMPTY);
}
}
}
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) {
$this->sys->setHostname(getenv('SERVER_NAME'));
} else {
if (CommonFunctions::executeProgram('hostname', '', $buf, PSI_DEBUG)) {
$this->sys->setHostname($buf);
}
}
}
/**
* IP of the Canonical Host Name
*
* @return void
*/
protected function ip()
{
if (PSI_USE_VHOST === true) {
$this->sys->setIp(gethostbyname($this->sys->getHostname()));
} else {
if (!($result = getenv('SERVER_ADDR'))) {
$this->sys->setIp(gethostbyname($this->sys->getHostname()));
} else {
$this->sys->setIp($result);
}
}
}
/**
* Kernel Version
*
* @return void
*/
protected function kernel()
{
$s = $this->grabkey('kern.version');
$a = preg_split('/:/', $s);
$this->sys->setKernel($a[0].$a[1].':'.$a[2]);
}
/**
* Number of Users
*
* @return void
*/
protected function users()
{
if (CommonFunctions::executeProgram('who', '| wc -l', $buf, PSI_DEBUG)) {
$this->sys->setUsers($buf);
}
}
/**
* 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();
$dev->setModel($this->grabkey('hw.model'));
$notwas = true;
foreach ($this->readdmesg() as $line) {
if ($notwas) {
if (preg_match("/".$this->_CPURegExp1."/", $line, $ar_buf)) {
$dev->setCpuSpeed(round($ar_buf[2]));
$notwas = false;
}
} 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].": ".$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])) {
$finddev->setCapacity($ar_buf[2] * 2048 * 1.049);
$notwas = false;
break;
}
}
if ($notwas) {
$dev = new HWDevice();
$dev->setName($ar_buf[1]);
$dev->setCapacity($ar_buf[2] * 2048 * 1.049);
$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 (!is_array($results = Parser::lspci(false)) || !is_array($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].": ".$ar_buf[3]);
$dev->setCapacity($ar_buf[2] * 1024);
$this->sys->setIdeDevices($dev);
} elseif (preg_match('/^(acd[0-9]+): (.*) <(.*)> (.*)/', $line, $ar_buf)) {
$dev = new HWDevice();
$dev->setName($ar_buf[1].": ".$ar_buf[3]);
$this->sys->setIdeDevices($dev);
} elseif (preg_match('/^(ada[0-9]+): <(.*)> (.*)/', $line, $ar_buf)) {
$dev = new HWDevice();
$dev->setName($ar_buf[1].": ".$ar_buf[2]);
$this->sys->setIdeDevices($dev);
} elseif (preg_match('/^(ada[0-9]+): (.*)MB \((.*)\)/', $line, $ar_buf)) {
/* duplication security */
$notwas = true;
foreach ($this->sys->getIdeDevices() as $finddev) {
if ($notwas && (substr($finddev->getName(), 0, strpos($finddev->getName(), ': ')) == $ar_buf[1])) {
$finddev->setCapacity($ar_buf[2] * 1024);
$notwas = false;
break;
}
}
if ($notwas) {
$dev = new HWDevice();
$dev->setName($ar_buf[1]);
$dev->setCapacity($ar_buf[2] * 1024);
$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()
{
$this->distro();
$this->memory();
$this->ide();
$this->pci();
$this->cpuinfo();
$this->filesystems();
$this->kernel();
$this->users();
$this->loadavg();
$this->hostname();
$this->ip();
$this->scsi();
$this->usb();
}
}

View File

@@ -0,0 +1,464 @@
<?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 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 Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
class Darwin extends BSDCommon
{
/**
* define the regexp for log parser
*/
/* public function __construct()
{
parent::__construct();
$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");
} */
/**
* 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);
return $s;
} else {
return '';
}
}
/**
* 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);
$lines = preg_split("/\n/", $s, -1, PREG_SPLIT_NO_EMPTY);
$out = "";
foreach ($lines as $line) {
if (preg_match('/^([^<]*) <class '.$key.',/', $line)) {
$out .= $line."\n";
}
}
return $out;
} else {
return '';
}
}
/**
* UpTime
* time the system is running
*
* @return void
*/
private function _uptime()
{
if (CommonFunctions::executeProgram('sysctl', '-n kern.boottime', $a, PSI_DEBUG)) {
$tmp = explode(" ", $a);
if ($tmp[0]=="{") { /* kern.boottime= { sec = 1096732600, usec = 885425 } Sat Oct 2 10:56:40 2004 */
$data = trim($tmp[3], ",");
$this->sys->setUptime(time() - $data);
} else { /* kern.boottime= 1096732600 */
$this->sys->setUptime(time() - $a);
}
}
}
/**
* get CPU information
*
* @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(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);
}
}
/**
* 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);
}
}
}
/**
* 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);
}
$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);
}
}
/**
* 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]));
$this->sys->setUsbDevices($dev);
}
}
/**
* 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);
}
}
/**
* 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);
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);
}
$this->sys->setMemTotal($s);
$this->sys->setMemUsed($this->sys->getMemTotal() - $this->sys->getMemFree());
if (CommonFunctions::executeProgram('sysctl', 'vm.swapusage | colrm 1 22', $swapBuff, PSI_DEBUG)) {
$swap1 = preg_split('/M/', $swapBuff);
$swap2 = preg_split('/=/', $swap1[1]);
$swap3 = preg_split('/=/', $swap1[2]);
$dev = new DiskDevice();
$dev->setName('SWAP');
$dev->setMountPoint('SWAP');
$dev->setFsType('swap');
$dev->setTotal($swap1[0] * 1024 * 1024);
$dev->setUsed($swap2[1] * 1024 * 1024);
$dev->setFree($swap3[1] * 1024 * 1024);
$this->sys->setSwapDevices($dev);
}
}
}
/**
* 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);
}
}
/**
* 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))
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').preg_replace('/:/', '-', $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))
&& !preg_match('/^fe80::/i', $ar_buf2[1]))
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$ar_buf2[1]);
}
}
$this->sys->setNetDevices($dev);
}
}
}
}
/**
* 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]);
if (preg_match('/(^Mac OS)|(^OS X)/', $distro)) {
$this->sys->setDistributionIcon('Apple.png');
if (preg_match('/((^Mac OS X Server)|(^Mac OS X)|(^OS X Server)|(^OS X)) (\d+\.\d+)/', $distro, $ver)
&& ($list = @parse_ini_file(APP_ROOT."/data/osnames.ini", true))
&& isset($list['OS X'][$ver[6]])) {
$distro.=' '.$list['OS X'][$ver[6]];
}
}
$this->sys->setDistribution($distro);
return;
}
}
}
}
/**
* 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);
}
}
}
/**
* get the information
*
* @see PSI_Interface_OS::build()
*
* @return Void
*/
public function build()
{
parent::build();
$this->_uptime();
$this->_network();
$this->_processes();
$this->_tb();
}
}

View File

@@ -0,0 +1,153 @@
<?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 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 Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
class DragonFly extends BSDCommon
{
/**
* define the regexp for log parser
*/
public function __construct()
{
parent::__construct();
$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->grab_key('kern.boottime');
preg_match("/sec = ([0-9]+)/", $a, $buf);
$this->sys->setUptime(time() - $buf[1]);
}
/**
* get network information
*
* @return array
*/
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])) {
$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 array
*/
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 (!preg_match("/^acd[0-9](.*)/", $ar_buf[1])) {
$dev->setCapacity($ar_buf[2] * 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();
$this->_distroicon();
$this->_network();
$this->_uptime();
$this->_processes();
}
}

View File

@@ -0,0 +1,190 @@
<?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 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 Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
class FreeBSD extends BSDCommon
{
/**
* define the regexp for log parser
*/
public function __construct()
{
parent::__construct();
$this->setCPURegExp1("CPU: (.*) \((.*)-MHz (.*)\)");
$this->setCPURegExp2("/(.*) ([0-9]+) ([0-9]+) ([0-9]+) ([0-9]+)/");
$this->setSCSIRegExp1("^(.*): <(.*)> .*SCSI.*device");
$this->setSCSIRegExp2("^(da[0-9]): (.*)MB ");
$this->setPCIRegExp1("/(.*): <(.*)>(.*) pci[0-9]$/");
$this->setPCIRegExp2("/(.*): <(.*)>.* at [.0-9]+ irq/");
}
/**
* UpTime
* time the system is running
*
* @return void
*/
private function _uptime()
{
$s = preg_split('/ /', $this->grabkey('kern.boottime'));
$a = preg_replace('/,/', '', $s[3]);
$this->sys->setUptime(time() - $a);
}
/**
* get network information
*
* @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) { /* no Address */
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))
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').preg_replace('/:/', '-', $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))
&& !preg_match('/^fe80::/i', $ar_buf2[1]))
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$ar_buf2[1]);
}
}
$this->sys->setNetDevices($dev);
}
}
}
}
}
/**
* 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 {
$this->sys->setDistributionIcon('FreeBSD.png');
}
}
/**
* 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());
}
/**
* 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);
}
}
}
/**
* get the information
*
* @see BSDCommon::build()
*
* @return Void
*/
public function build()
{
parent::build();
$this->_memoryadditional();
$this->_distroicon();
$this->_network();
$this->_uptime();
$this->_processes();
}
}

View File

@@ -0,0 +1,404 @@
<?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 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 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) {
$this->sys->setHostname(getenv('SERVER_NAME'));
} else {
if (CommonFunctions::executeProgram('hostname', '', $ret)) {
$this->sys->setHostname($ret);
}
}
}
/**
* IP of the Virtual Host Name
*
* @return void
*/
private function _ip()
{
if (PSI_USE_VHOST === true) {
$this->sys->setIp(gethostbyname($this->sys->getHostname()));
} else {
if (!($result = getenv('SERVER_ADDR'))) {
$this->sys->setIp(gethostbyname($this->sys->getHostname()));
} else {
$this->sys->setIp($result);
}
}
}
/**
* HP-UX Version
*
* @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);
}
}
}
/**
* Number of Users
*
* @return void
*/
private function _users()
{
if (CommonFunctions::executeProgram('who', '-q', $ret)) {
$who = preg_split('/=/', $ret, -1, PREG_SPLIT_NO_EMPTY);
$this->sys->setUsers($who[1]);
}
}
/**
* Processor Load
* optionally create a loadbar
*
* @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)) {
$bufe = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
foreach ($bufe as $buf) {
if (preg_match('/Bus/', $buf)) {
$device = true;
continue;
}
if ($device) {
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 (CommonFunctions::rfts("/proc/ide/".$file."/media", $buf, 1)) {
if (trim($buf) == 'disk') {
if (CommonFunctions::rfts("/proc/ide/".$file."/capacity", $buf, 1, 4096, false)) {
$dev->setCapacity(trim($buf) * 512 / 1024);
}
}
}
$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);
foreach ($bufe as $buf) {
if (preg_match('/^T/', $buf)) {
$devnum += 1;
$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);
while (list(, $line) = each($lines)) {
$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()
{
$this->_distro();
$this->_hostname();
$this->_ip();
$this->_kernel();
$this->_uptime();
$this->_users();
$this->_loadavg();
$this->_cpuinfo();
$this->_pci();
$this->_ide();
$this->_scsi();
$this->_usb();
$this->_network();
$this->_memory();
$this->_filesystems();
}
}

View File

@@ -0,0 +1,403 @@
<?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 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 Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
class Haiku extends OS
{
/**
* call parent constructor
*/
public function __construct()
{
parent::__construct();
}
/**
* get the cpu information
*
* @return array
*/
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);
//echo ">>>>>".$cpu;
}
}
}
}
/**
* 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
*/
private function _users()
{
$this->sys->setUsers(1);
}
/**
* Virtual Host Name
*
* @return void
*/
private function _hostname()
{
if (PSI_USE_VHOST === true) {
$this->sys->setHostname(getenv('SERVER_NAME'));
} else {
if (CommonFunctions::executeProgram('uname', '-n', $result, PSI_DEBUG)) {
$ip = gethostbyname($result);
if ($ip != $result) {
$this->sys->setHostname(gethostbyaddr($ip));
}
}
}
}
/**
* IP of the Virtual Host Name
*
* @return void
*/
private function _ip()
{
if (PSI_USE_VHOST === true) {
$this->sys->setIp(gethostbyname($this->sys->getHostname()));
} else {
if (!($result = getenv('SERVER_ADDR'))) {
$this->sys->setIp(gethostbyname($this->sys->getHostname()));
} else {
$this->sys->setIp($result);
}
}
}
/**
* Physical memory information and Swap Space information
*
* @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);
$notwas = true;
foreach ($lines as $line) {
if (preg_match("/^(\S+)/", $line, $ar_buf)) {
if (!$notwas) {
$dev->setErrors($errors);
$dev->setDrops($drops);
$this->sys->setNetDevices($dev);
}
$errors = 0;
$drops = 0;
$dev = new NetDevice();
$dev->setName($ar_buf[1]);
$notwas = false;
} else {
if (!$notwas) {
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))
$dev->setInfo(preg_replace('/:/', '-', $ar_buf2[1]));
elseif (preg_match('/^\s+inet\saddr:\s(\S*),/i', $line, $ar_buf2))
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$ar_buf2[1]);
elseif (preg_match('/^\s+inet6\saddr:\s(\S*),/i', $line, $ar_buf2))
if (!preg_match('/^fe80::/i', $ar_buf2[1]))
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$ar_buf2[1]);
}
}
}
}
if (!$notwas) {
$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");
$this->_distro();
$this->_hostname();
$this->_ip();
$this->_kernel();
$this->_uptime();
$this->_users();
$this->_loadavg();
$this->_pci();
$this->_usb();
$this->_cpuinfo();
$this->_memory();
$this->_filesystems();
$this->_network();
$this->_processes();
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,382 @@
<?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 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 Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
class Minix extends OS
{
/**
* content of the syslog
*
* @var array
*/
private $_dmesg = array();
/**
* call parent constructor
*/
public function __construct()
{
parent::__construct();
}
/**
* read /var/log/messages, but only if we haven't already
*
* @return array
*/
protected function readdmesg()
{
if (count($this->_dmesg) === 0) {
if (CommonFunctions::rfts('/var/log/messages', $buf)) {
$parts = preg_split("/kernel: APIC/", $buf, -1, PREG_SPLIT_NO_EMPTY);
// $parts = preg_split("/ syslogd: restart\n/", $buf, -1, PREG_SPLIT_NO_EMPTY);
$this->_dmesg = preg_split("/\n/", $parts[count($parts) - 1], -1, PREG_SPLIT_NO_EMPTY);
}
}
return $this->_dmesg;
}
/**
* get the cpu information
*
* @return array
*/
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;
}
}
}
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);
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)) && is_array($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()
{
foreach ($this->readdmesg() as $line) {
if (preg_match('/kernel: MINIX (.*) \((.*)\)/', $line, $ar_buf)) {
$branch = $ar_buf[2];
}
}
if (CommonFunctions::executeProgram('uname', '-rvm', $ret)) {
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+) 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);
} 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]);
}
}
}
/**
* Number of Users
*
* @return void
*/
private function _users()
{
if (CommonFunctions::executeProgram('uptime', '', $buf)) {
if (preg_match("/, (.*) users, load averages: (.*), (.*), (.*)$/", $buf, $ar_buf)) {
$this->sys->setUsers($ar_buf[1]);
}
}
}
/**
* Virtual Host Name
*
* @return void
*/
private function _hostname()
{
if (PSI_USE_VHOST === true) {
$this->sys->setHostname(getenv('SERVER_NAME'));
} else {
if (CommonFunctions::executeProgram('uname', '-n', $result, PSI_DEBUG)) {
$ip = gethostbyname($result);
if ($ip != $result) {
$this->sys->setHostname(gethostbyaddr($ip));
}
}
}
}
/**
* IP of the Virtual Host Name
*
* @return void
*/
private function _ip()
{
if (PSI_USE_VHOST === true) {
$this->sys->setIp(gethostbyname($this->sys->getHostname()));
} else {
if (!($result = getenv('SERVER_ADDR'))) {
$this->sys->setIp(gethostbyname($this->sys->getHostname()));
} else {
$this->sys->setIp($result);
}
}
}
/**
* Physical memory information and Swap Space information
*
* @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");
$this->_distro();
$this->_hostname();
$this->_ip();
$this->_kernel();
$this->_uptime();
$this->_users();
$this->_loadavg();
$this->_pci();
$this->_cpuinfo();
$this->_memory();
$this->_filesystems();
$this->_network();
$this->_processes();
}
}

View File

@@ -0,0 +1,159 @@
<?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 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 Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
class NetBSD extends BSDCommon
{
/**
* define the regexp for log parser
*/
public function __construct()
{
parent::__construct();
$this->setCPURegExp1("^cpu(.*)\, (.*) MHz");
$this->setCPURegExp2("/user = (.*), nice = (.*), sys = (.*), intr = (.*), idle = (.*)/");
$this->setSCSIRegExp1("^(.*) at scsibus.*: <(.*)> .*");
$this->setSCSIRegExp2("^(da[0-9]): (.*)MB ");
$this->setPCIRegExp1("/(.*) at pci[0-9] dev [0-9]* function [0-9]*: (.*)$/");
$this->setPCIRegExp2("/\"(.*)\" (.*).* at [.0-9]+ irq/");
}
/**
* UpTime
* time the system is running
*
* @return void
*/
private function _uptime()
{
$a = $this->grabkey('kern.boottime');
$this->sys->setUptime(time() - $a);
}
/**
* get network information
*
* @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])) {
$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]);
$this->sys->setNetDevices($dev);
}
}
}
/**
* 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)) {
$dev = new HWDevice();
$dev->setName($ar_buf[1]);
// now loop again and find the capacity
foreach ($this->readdmesg() as $line2) {
if (preg_match("/^(".$ar_buf[1]."): (.*), (.*), (.*)MB, .*$/", $line2, $ar_buf_n)) {
$dev->setCapacity($ar_buf_n[4] * 2048 * 1.049);
} elseif (preg_match("/^(".$ar_buf[1]."): (.*) MB, (.*), (.*), .*$/", $line2, $ar_buf_n)) {
$dev->setCapacity($ar_buf_n[2] * 2048);
}
}
$this->sys->setIdeDevices($dev);
}
}
}
/**
* get icon name
*
* @return void
*/
private function _distroicon()
{
$this->sys->setDistributionIcon('NetBSD.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 == '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();
$this->_distroicon();
$this->_network();
$this->_uptime();
$this->_processes();
}
}

View File

@@ -0,0 +1,85 @@
<?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 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 Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
abstract class OS implements PSI_Interface_OS
{
/**
* object for error handling
*
* @var Error
*/
protected $error;
/**
* @var System
*/
protected $sys;
/**
* build the global Error object
*/
public function __construct()
{
$this->error = Error::singleton();
$this->sys = new System();
}
/**
* 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 the filled or unfilled (with default values) System object
*
* @see PSI_Interface_OS::getSys()
*
* @return System
*/
final public function getSys()
{
$this->build();
return $this->sys;
}
}

View File

@@ -0,0 +1,174 @@
<?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 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 Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
class OpenBSD extends BSDCommon
{
/**
* define the regexp for log parser
*/
public function __construct()
{
parent::__construct();
$this->setCPURegExp1("^cpu(.*) (.*) MHz");
$this->setCPURegExp2("/(.*),(.*),(.*),(.*),(.*)/");
$this->setSCSIRegExp1("^(.*) at scsibus.*: <(.*)> .*");
$this->setSCSIRegExp2("^(da[0-9]): (.*)MB ");
$this->setPCIRegExp1("/(.*) at pci[0-9] .* \"(.*)\"/");
$this->setPCIRegExp2("/\"(.*)\" (.*).* at [.0-9]+ irq/");
}
/**
* UpTime
* time the system is running
*
* @return void
*/
private function _uptime()
{
$a = $this->grabkey('kern.boottime');
$this->sys->setUptime(time() - $a);
}
/**
* get network information
*
* @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])) {
$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]);
$this->sys->setNetDevices($dev);
}
}
}
/**
* 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[0]);
// now loop again and find the capacity
foreach ($this->readdmesg() as $line2) {
if (preg_match("/^(".$ar_buf[0]."): (.*), (.*), (.*)MB, .*$/", $line2, $ar_buf_n)) {
$dev->setCapacity($ar_buf_n[4] * 2048 * 1.049);
}
}
$this->sys->setIdeDevices($dev);
}
}
}
/**
* get CPU information
*
* @return void
*/
protected function cpuinfo()
{
$dev = new CpuDevice();
$dev->setModel($this->grabkey('hw.model'));
$dev->setCpuSpeed($this->grabkey('hw.cpuspeed'));
$ncpu = $this->grabkey('hw.ncpu');
if (is_null($ncpu) || (trim($ncpu) == "") || (!($ncpu >= 1)))
$ncpu = 1;
for ($ncpu ; $ncpu > 0 ; $ncpu--) {
$this->sys->setCpus($dev);
}
}
/**
* get icon name
*
* @return void
*/
private function _distroicon()
{
$this->sys->setDistributionIcon('OpenBSD.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();
$this->_distroicon();
$this->_network();
$this->_uptime();
$this->_processes();
}
}

View File

@@ -0,0 +1,256 @@
<?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 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 Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
class QNX extends OS
{
/**
* content of the syslog
*
* @var array
*/
private $_dmesg = array();
/**
* call parent constructor
*/
public function __construct()
{
parent::__construct();
}
/**
* get the cpu information
*
* @return array
*/
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
*/
private function _users()
{
$this->sys->setUsers(1);
}
/**
* Virtual Host Name
*
* @return void
*/
private function _hostname()
{
if (PSI_USE_VHOST === true) {
$this->sys->setHostname(getenv('SERVER_NAME'));
} else {
if (CommonFunctions::executeProgram('uname', '-n', $result, PSI_DEBUG)) {
$ip = gethostbyname($result);
if ($ip != $result) {
$this->sys->setHostname(gethostbyaddr($ip));
}
}
}
}
/**
* IP of the Virtual Host Name
*
* @return void
*/
private function _ip()
{
if (PSI_USE_VHOST === true) {
$this->sys->setIp(gethostbyname($this->sys->getHostname()));
} else {
if (!($result = getenv('SERVER_ADDR'))) {
$this->sys->setIp(gethostbyname($this->sys->getHostname()));
} else {
$this->sys->setIp($result);
}
}
}
/**
* Physical memory information and Swap Space information
*
* @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);
$notwas = true;
foreach ($lines as $line) {
if (preg_match("/^([^\s:]+)/", $line, $ar_buf)) {
if (!$notwas) {
$this->sys->setNetDevices($dev);
}
$dev = new NetDevice();
$dev->setName($ar_buf[1]);
$notwas = false;
} else {
if (!$notwas) {
if (defined('PSI_SHOW_NETWORK_INFOS') && (PSI_SHOW_NETWORK_INFOS)) {
if (preg_match('/^\s+address:\s*(\S+)/i', $line, $ar_buf2)) {
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$ar_buf2[1]);
} elseif (preg_match('/^\s+inet\s+(\S+)\s+netmask/i', $line, $ar_buf2))
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$ar_buf2[1]);
}
}
}
}
if (!$notwas) {
$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");
$this->_distro();
$this->_hostname();
$this->_ip();
$this->_kernel();
$this->_uptime();
$this->_users();
$this->_cpuinfo();
$this->_memory();
$this->_filesystems();
$this->_network();
}
}

View File

@@ -0,0 +1,349 @@
<?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 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 Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
class SunOS extends OS
{
/**
* 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) &&
!is_null($m) && (trim($m)!=="")) {
list($key, $value) = preg_split("/\t/", trim($m), 2);
return $value;
} else {
return '';
}
}
/**
* Virtual Host Name
*
* @return void
*/
private function _hostname()
{
if (PSI_USE_VHOST === true) {
$this->sys->setHostname(getenv('SERVER_NAME'));
} else {
if (CommonFunctions::executeProgram('uname', '-n', $result, PSI_DEBUG)) {
$ip = gethostbyname($result);
if ($ip != $result) {
$this->sys->setHostname(gethostbyaddr($ip));
}
}
}
}
/**
* IP of the Virtual Host Name
*
* @return void
*/
private function _ip()
{
if (PSI_USE_VHOST === true) {
$this->sys->setIp(gethostbyname($this->sys->getHostname()));
} else {
if (!($result = getenv('SERVER_ADDR'))) {
$this->sys->setIp(gethostbyname($this->sys->getHostname()));
} else {
$this->sys->setIp($result);
}
}
}
/**
* Kernel Version
*
* @return void
*/
private function _kernel()
{
if (CommonFunctions::executeProgram('uname', '-s', $os, PSI_DEBUG)) {
if (CommonFunctions::executeProgram('uname', '-r', $version, PSI_DEBUG)) {
$this->sys->setKernel($os.' '.$version);
} else {
$this->sys->setKernel($os);
}
}
}
/**
* UpTime
* time the system is running
*
* @return void
*/
private function _uptime()
{
$this->sys->setUptime(time() - $this->_kstat('unix:0:system_misc:boot_time'));
}
/**
* Number of Users
*
* @return void
*/
private function _users()
{
if (CommonFunctions::executeProgram('who', '-q', $buf, PSI_DEBUG)) {
$who = preg_split('/=/', $buf);
$this->sys->setUsers($who[1]);
}
}
/**
* Processor Load
* optionally create a loadbar
*
* @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));
}
/**
* CPU information
*
* @return void
*/
private function _cpuinfo()
{
$dev = new CpuDevice();
if (CommonFunctions::executeProgram('uname', '-i', $buf, PSI_DEBUG)) {
$dev->setModel(trim($buf));
}
$dev->setCpuSpeed($this->_kstat('cpu_info:0:cpu_info0:clock_MHz'));
$dev->setCache($this->_kstat('cpu_info:0:cpu_info0:cpu_type') * 1024);
$this->sys->setCpus($dev);
}
/**
* 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)
&& !is_null($bufr2) && (trim($bufr2) !== "")) {
$bufe2 = preg_split("/\n/", $bufr2, -1, PREG_SPLIT_NO_EMPTY);
foreach ($bufe2 as $buf2) {
if (preg_match('/^\s+ether\s+(\S+)/i', $buf2, $ar_buf2))
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').preg_replace('/:/', '-', $ar_buf2[1]));
elseif (preg_match('/^\s+inet\s+(\S+)\s+netmask/i', $buf2, $ar_buf2))
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$ar_buf2[1]);
}
}
if (CommonFunctions::executeProgram('ifconfig', $ar_buf[0].' inet6', $bufr2, PSI_DEBUG)
&& !is_null($bufr2) && (trim($bufr2) !== "")) {
$bufe2 = preg_split("/\n/", $bufr2, -1, PREG_SPLIT_NO_EMPTY);
foreach ($bufe2 as $buf2) {
if (preg_match('/^\s+inet6\s+([^\s\/]+)/i', $buf2, $ar_buf2)
&& !preg_match('/^fe80::/i', $ar_buf2[1]))
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$ar_buf2[1]);
}
}
}
$this->sys->setNetDevices($dev);
}
}
}
}
/**
* 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);
}
/**
* 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);
}
}
}
}
/**
* Distribution Icon
*
* @return void
*/
private function _distro()
{
$this->sys->setDistribution('SunOS');
$this->sys->setDistributionIcon('SunOS.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 == '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);
}
}
}
/**
* 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");
$this->_distro();
$this->_hostname();
$this->_ip();
$this->_kernel();
$this->_uptime();
$this->_users();
$this->_loadavg();
$this->_cpuinfo();
$this->_network();
$this->_memory();
$this->_filesystems();
$this->_processes();
}
}

View File

@@ -0,0 +1,609 @@
<?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 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 Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
class WINNT extends OS
{
/**
* holds the COM object that we pull all the WMI data from
*
* @var Object
*/
private $_wmi = null;
/**
* holds all devices, which are in the system
*
* @var array
*/
private $_wmidevices;
/**
* 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;
/**
* build the global Error object and create the WMI connection
*/
public function __construct()
{
parent::__construct();
// don't set this params for local connection, it will not work
$strHostname = '';
$strUser = '';
$strPassword = '';
try {
// initialize the wmi object
$objLocator = new COM('WbemScripting.SWbemLocator');
if ($strHostname == "") {
$this->_wmi = $objLocator->ConnectServer();
} else {
$this->_wmi = $objLocator->ConnectServer($strHostname, 'root\CIMv2', $strHostname.'\\'.$strUser, $strPassword);
}
} catch (Exception $e) {
$this->error->addError("WMI connect error", "PhpSysInfo can not connect to the WMI interface for security reasons.\nCheck an authentication mechanism for the directory where phpSysInfo is installed.");
}
$this->_getCodeSet();
}
/**
* store the codepage of the os for converting some strings to utf-8
*
* @return void
*/
private function _getCodeSet()
{
$buffer = CommonFunctions::getWMI($this->_wmi, 'Win32_OperatingSystem', array('CodeSet', 'OSLanguage'));
if ($buffer) {
$this->_codepage = 'windows-'.$buffer[0]['CodeSet'];
$lang = "";
if (is_readable(APP_ROOT.'/data/languages.ini') && ($langdata = @parse_ini_file(APP_ROOT.'/data/languages.ini', true))) {
if (isset($langdata['WINNT'][$buffer[0]['OSLanguage']])) {
$lang = $langdata['WINNT'][$buffer[0]['OSLanguage']];
}
}
if ($lang == "") {
$lang = 'Unknown';
}
$this->_syslang = $lang.' ('.$buffer[0]['OSLanguage'].')';
}
}
/**
* 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)) {
$this->_wmidevices = CommonFunctions::getWMI($this->_wmi, 'Win32_PnPEntity', array('Name', 'PNPDeviceID'));
}
$list = array();
foreach ($this->_wmidevices as $device) {
if (substr($device['PNPDeviceID'], 0, strpos($device['PNPDeviceID'], "\\") + 1) == ($strType."\\")) {
$list[] = $device['Name'];
}
}
return $list;
}
/**
* Host Name
*
* @return void
*/
private function _hostname()
{
if (PSI_USE_VHOST === true) {
if ($hnm = getenv('SERVER_NAME')) $this->sys->setHostname($hnm);
} else {
$buffer = CommonFunctions::getWMI($this->_wmi, 'Win32_ComputerSystem', array('Name'));
if ($buffer) {
$result = $buffer[0]['Name'];
$ip = gethostbyname($result);
if ($ip != $result) {
$long = ip2long($ip);
if (($long >= 167772160 && $long <= 184549375) ||
($long >= -1408237568 && $long <= -1407188993) ||
($long >= -1062731776 && $long <= -1062666241) ||
($long >= 2130706432 && $long <= 2147483647) || $long == -1) {
$this->sys->setHostname($result); //internal ip
} else {
$this->sys->setHostname(gethostbyaddr($ip));
}
}
} else {
if ($hnm = getenv('COMPUTERNAME')) $this->sys->setHostname($hnm);
}
}
}
/**
* IP of the Canonical Host Name
*
* @return void
*/
private function _ip()
{
if (PSI_USE_VHOST === true) {
if ((($hnm=$this->sys->getHostname()) != 'localhost') &&
(($hip=gethostbyname($hnm)) != $hnm)) $this->sys->setIp($hip);
} else {
$buffer = CommonFunctions::getWMI($this->_wmi, 'Win32_ComputerSystem', array('Name'));
if ($buffer) {
$result = $buffer[0]['Name'];
$this->sys->setIp(gethostbyname($result));
} else {
if ((($hnm=$this->sys->getHostname()) != 'localhost') &&
(($hip=gethostbyname($hnm)) != $hnm)) $this->sys->setIp($hip);
}
}
}
/**
* UpTime
* time the system is running
*
* @return void
*/
private function _uptime()
{
$result = 0;
date_default_timezone_set('UTC');
$buffer = CommonFunctions::getWMI($this->_wmi, 'Win32_OperatingSystem', array('LastBootUpTime', 'LocalDateTime'));
if ($buffer) {
$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));
$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));
$boottime = mktime($bhour, $bminute, $bseconds, $bmonth, $bday, $byear);
$localtime = mktime($lhour, $lminute, $lseconds, $lmonth, $lday, $lyear);
$result = $localtime - $boottime;
$this->sys->setUptime($result);
}
}
/**
* Number of Users
*
* @return void
*/
private function _users()
{
if (CommonFunctions::executeProgram("quser", "", $strBuf, false) && (strlen(trim($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);
}
/**
* Distribution
*
* @return void
*/
private function _distro()
{
$buffer = CommonFunctions::getWMI($this->_wmi, 'Win32_OperatingSystem', array('Version', 'ServicePackMajorVersion', 'Caption', 'OSArchitecture'));
if ($buffer) {
$kernel = $buffer[0]['Version'];
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 = CommonFunctions::getWMI($this->_wmi, 'Win32_Processor', array('AddressWidth'))) && isset($allCpus[0]['AddressWidth'])) {
$this->sys->setKernel($kernel.' ('.$allCpus[0]['AddressWidth'].'-bit)');
} else {
$this->sys->setKernel($kernel);
}
$this->sys->setDistribution($buffer[0]['Caption']);
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);
} 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');
} elseif (preg_match("/^(Microsoft [^\[]*)\s*\[\D*\s*(.+)\]/", $ver_value, $ar_temp)) {
$this->sys->setDistribution($ar_temp[1]);
$this->sys->setKernel($ar_temp[2]);
$this->sys->setDistributionIcon('Win2000.png');
} else {
$this->sys->setDistribution("WinNT");
$this->sys->setDistributionIcon('Win2000.png');
}
} else {
$this->sys->setDistribution("WinNT");
$this->sys->setDistributionIcon('Win2000.png');
}
}
/**
* Processor Load
* optionally create a loadbar
*
* @return void
*/
private function _loadavg()
{
$loadavg = "";
$sum = 0;
$buffer = CommonFunctions::getWMI($this->_wmi, 'Win32_Processor', array('LoadPercentage'));
if ($buffer) {
foreach ($buffer as $load) {
$value = $load['LoadPercentage'];
$loadavg .= $value.' ';
$sum += $value;
}
$this->sys->setLoad(trim($loadavg));
if (PSI_LOAD_BAR) {
$this->sys->setLoadPercent($sum / count($buffer));
}
}
}
/**
* CPU information
*
* @return void
*/
private function _cpuinfo()
{
$allCpus = CommonFunctions::getWMI($this->_wmi, 'Win32_Processor', array('Name', 'L2CacheSize', 'CurrentClockSpeed', 'ExtClock', 'NumberOfCores', 'MaxClockSpeed'));
foreach ($allCpus as $oneCpu) {
$coreCount = 1;
if (isset($oneCpu['NumberOfCores'])) {
$coreCount = $oneCpu['NumberOfCores'];
}
for ($i = 0; $i < $coreCount; $i++) {
$cpu = new CpuDevice();
$cpu->setModel($oneCpu['Name']);
$cpu->setCache($oneCpu['L2CacheSize'] * 1024);
$cpu->setCpuSpeed($oneCpu['CurrentClockSpeed']);
$cpu->setBusSpeed($oneCpu['ExtClock']);
if ($oneCpu['CurrentClockSpeed'] < $oneCpu['MaxClockSpeed']) $cpu->setCpuSpeedMax($oneCpu['MaxClockSpeed']);
$this->sys->setCpus($cpu);
}
}
}
/**
* Machine information
*
* @return void
*/
private function _machine()
{
$buffer = CommonFunctions::getWMI($this->_wmi, 'Win32_ComputerSystem', array('Manufacturer', 'Model'));
if ($buffer) {
$buf = "";
if (isset($buffer[0]['Manufacturer'])) {
$buf .= ' '.$buffer[0]['Manufacturer'];
}
if (isset($buffer[0]['Model'])) {
$buf .= ' '.$buffer[0]['Model'];
}
if (trim($buf) != "") {
$this->sys->setMachine(trim($buf));
}
}
}
/**
* Hardwaredevices
*
* @return void
*/
private function _hardware()
{
foreach ($this->_devicelist('PCI') as $pciDev) {
$dev = new HWDevice();
$dev->setName($pciDev);
$this->sys->setPciDevices($dev);
}
foreach ($this->_devicelist('IDE') as $ideDev) {
$dev = new HWDevice();
$dev->setName($ideDev);
$this->sys->setIdeDevices($dev);
}
foreach ($this->_devicelist('SCSI') as $scsiDev) {
$dev = new HWDevice();
$dev->setName($scsiDev);
$this->sys->setScsiDevices($dev);
}
foreach ($this->_devicelist('USB') as $usbDev) {
$dev = new HWDevice();
$dev->setName($usbDev);
$this->sys->setUsbDevices($dev);
}
}
/**
* Network devices
*
* @return void
*/
private function _network()
{
$allDevices = CommonFunctions::getWMI($this->_wmi, 'Win32_PerfRawData_Tcpip_NetworkInterface', array('Name', 'BytesSentPersec', 'BytesTotalPersec', 'BytesReceivedPersec', 'PacketsReceivedErrors', 'PacketsReceivedDiscarded'));
$allNetworkAdapterConfigurations = CommonFunctions::getWMI($this->_wmi, 'Win32_NetworkAdapterConfiguration', array('Description', 'MACAddress', 'IPAddress', 'SettingID'));
foreach ($allDevices as $device) {
$dev = new NetDevice();
$name=$device['Name'];
if (preg_match('/^isatap\.({[A-Fa-f0-9\-]*})/', $name, $ar_name)) { //isatap device
foreach ($allNetworkAdapterConfigurations as $NetworkAdapterConfiguration) {
if ($ar_name[1]==$NetworkAdapterConfiguration['SettingID']) {
$dev->setName($NetworkAdapterConfiguration['Description']);
if (defined('PSI_SHOW_NETWORK_INFOS') && PSI_SHOW_NETWORK_INFOS) {
$dev->setInfo(preg_replace('/:/', '-', $NetworkAdapterConfiguration['MACAddress']));
if (isset($NetworkAdapterConfiguration['IPAddress']))
foreach($NetworkAdapterConfiguration['IPAddress'] as $ipaddres)
if (($ipaddres!="0.0.0.0") && !preg_match('/^fe80::/i', $ipaddres))
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$ipaddres);
}
break;
}
}
}
if ($dev->getName() == "") { //no isatap or no isatap description
$cname=preg_replace('/[^A-Za-z0-9]/', '_', $name); //convert to canonical
if (preg_match('/\s-\s([^-]*)$/', $name, $ar_name))
$name=substr($name, 0, strlen($name)-strlen($ar_name[0]));
$dev->setName($name);
if (defined('PSI_SHOW_NETWORK_INFOS') && PSI_SHOW_NETWORK_INFOS) foreach ($allNetworkAdapterConfigurations as $NetworkAdapterConfiguration) {
if (preg_replace('/[^A-Za-z0-9]/', '_', $NetworkAdapterConfiguration['Description']) == $cname) {
if (!is_null($dev->getInfo())) {
$dev->setInfo(''); //multiple with the same name
} else {
$dev->setInfo(preg_replace('/:/', '-', $NetworkAdapterConfiguration['MACAddress']));
if (isset($NetworkAdapterConfiguration['IPAddress']))
foreach($NetworkAdapterConfiguration['IPAddress'] as $ipaddres)
if (($ipaddres!="0.0.0.0") && !preg_match('/^fe80::/i', $ipaddres))
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$ipaddres);
}
}
}
}
// 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);
}
}
/**
* 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()
{
$buffer = CommonFunctions::getWMI($this->_wmi, "Win32_OperatingSystem", array('TotalVisibleMemorySize', 'FreePhysicalMemory'));
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);
}
}
/**
* filesystem information
*
* @return void
*/
private function _filesystems()
{
$typearray = array('Unknown', 'No Root Directory', 'Removable Disk', 'Local Disk', 'Network Drive', 'Compact Disc', 'RAM Disk');
$floppyarray = array('Unknown', '5 1/4 in.', '3 1/2 in.', '3 1/2 in.', '3 1/2 in.', '3 1/2 in.', '5 1/4 in.', '5 1/4 in.', '5 1/4 in.', '5 1/4 in.', '5 1/4 in.', 'Other', 'HD', '3 1/2 in.', '3 1/2 in.', '5 1/4 in.', '5 1/4 in.', '3 1/2 in.', '3 1/2 in.', '5 1/4 in.', '3 1/2 in.', '3 1/2 in.', '8 in.');
$buffer = CommonFunctions::getWMI($this->_wmi, 'Win32_LogicalDisk', array('Name', 'Size', 'FreeSpace', 'FileSystem', 'DriveType', 'MediaType'));
foreach ($buffer as $filesystem) {
$dev = new DiskDevice();
$dev->setMountPoint($filesystem['Name']);
$dev->setFsType($filesystem['FileSystem']);
if ($filesystem['Size'] > 0) {
$dev->setTotal($filesystem['Size']);
$dev->setFree($filesystem['FreeSpace']);
$dev->setUsed($filesystem['Size'] - $filesystem['FreeSpace']);
}
if ($filesystem['MediaType'] != "" && $filesystem['DriveType'] == 2) {
$dev->setName($typearray[$filesystem['DriveType']]." (".$floppyarray[$filesystem['MediaType']].")");
} else {
$dev->setName($typearray[$filesystem['DriveType']]);
}
$this->sys->setDiskDevices($dev);
}
if (!$buffer && ($this->sys->getDistribution()=="ReactOS")) {
// test for command 'free' on current disk
if (CommonFunctions::executeProgram("cmd", "/c free 2>nul", $out_value, true)) {
for ($letter='A'; $letter!='AA'; $letter++) if (CommonFunctions::executeProgram("cmd", "/c free ".$letter.": 2>nul", $out_value, false)) {
if (preg_match('/\n\s*([\d\.\,]+).*\n\s*([\d\.\,]+).*\n\s*([\d\.\,]+).*$/', $out_value, $out_dig)) {
$size = preg_replace('/(\.)|(\,)/', '', $out_dig[1]);
$used = preg_replace('/(\.)|(\,)/', '', $out_dig[2]);
$free = preg_replace('/(\.)|(\,)/', '', $out_dig[3]);
if ($used + $free == $size) {
$dev = new DiskDevice();
$dev->setMountPoint($letter.":");
$dev->setFsType('Unknown');
$dev->setTotal($size);
$dev->setFree($free);
$dev->setUsed($used);
$this->sys->setDiskDevices($dev);
}
}
}
}
}
}
/**
* 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(trim($strBuf)) > 0)) {
$lines = preg_split('/\n/', $strBuf);
$processes['*'] = (count($lines)-1) - 3 ; //correction for process "qprocess *"
}
if ($processes['*'] <= 0) {
$buffer = CommonFunctions::getWMI($this->_wmi, 'Win32_Process', array('Caption'));
$processes['*'] = count($buffer);
}
$processes[' '] = $processes['*'];
$this->sys->setProcesses($processes);
}
/**
* get the information
*
* @see PSI_Interface_OS::build()
*
* @return Void
*/
public function build()
{
$this->_distro();
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");
}
$this->_hostname();
$this->_ip();
$this->_users();
$this->_machine();
$this->_uptime();
$this->_cpuinfo();
$this->_network();
$this->_hardware();
$this->_filesystems();
$this->_memory();
$this->_loadavg();
$this->_processes();
}
}

View File

@@ -0,0 +1,60 @@
<?php
/**
* basic output functions
*
* PHP version 5
*
* @category PHP
* @package PSI_Output
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @version SVN: $Id: class.Output.inc.php 569 2012-04-16 06:08:18Z namiltd $
* @link http://phpsysinfo.sourceforge.net
*/
/**
* basic output functions for all output formats
*
* @category PHP
* @package PSI_Output
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @version Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
abstract class Output
{
/**
* error object for logging errors
*
* @var Error
*/
protected $error;
/**
* call the parent constructor and check for needed extensions
*/
public function __construct()
{
$this->error = Error::singleton();
$this->_checkConfig();
CommonFunctions::checkForExtensions();
// $this->error = Error::singleton();
// $this->_checkConfig();
}
/**
* read the config file and check for existence
*
* @return void
*/
private function _checkConfig()
{
include_once APP_ROOT.'/read_config.php';
if ($this->error->errorsExist()) {
$this->error->errorsAsXML();
}
}
}

View File

@@ -0,0 +1,93 @@
<?php
/**
* basic output functions
*
* PHP version 5
*
* @category PHP
* @package PSI_Output
* @author Damien Roth <iysaak@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @version SVN: $Id: class.Output.inc.php 315 2009-09-02 15:48:31Z bigmichi1 $
* @link http://phpsysinfo.sourceforge.net
*/
/**
* basic output functions for all output formats
*
* @category PHP
* @package PSI_Output
* @author Damien Roth <iysaak@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @version Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
class Template
{
/**
* Vars used in the template
*
* @Array
*/
private $_vars;
/**
* Template file
*
* @String
*/
private $_file;
/**
* Constructor
*
* @param String $file the template file name
*/
public function __construct($file=null)
{
$this->_file = $file;
$this->_vars = array();
}
/**
* Set a template variable.
*
* @param string variable name
* @param string variable value
*/
public function set($name, $value)
{
$this->_vars[$name] = is_object($value) ? $value->fetch() : $value;
}
/**
* Open, parse, and return the template file.
*
* @param string $file
*
* @return string
*/
public function fetch($file=null)
{
if (!$file) {
$file = $this->_file;
}
// Extract the vars to local namespace
extract($this->_vars);
// Start output buffering
ob_start();
include(APP_ROOT.$file);
// Get the contents of the buffer
$contents = ob_get_contents();
// End buffering and discard
ob_end_clean();
return $contents;
}
}

View File

@@ -0,0 +1,139 @@
<?php
/**
* start page for webaccess
*
* PHP version 5
*
* @category PHP
* @package PSI_Web
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @version SVN: $Id: class.Webpage.inc.php 661 2012-08-27 11:26:39Z namiltd $
* @link http://phpsysinfo.sourceforge.net
*/
/**
* generate the dynamic webpage
*
* @category PHP
* @package PSI_Web
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @version Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
class Webpage extends Output implements PSI_Interface_Output
{
/**
* configured language
*
* @var String
*/
private $_language;
/**
* configured template
*
* @var String
*/
private $_template;
/**
* all available templates
*
* @var Array
*/
private $_templates = array();
/**
* all available languages
*
* @var Array
*/
private $_languages = array();
/**
* check for all extensions that are needed, initialize needed vars and read phpsysinfo.ini
*/
public function __construct()
{
parent::__construct();
$this->_getTemplateList();
$this->_getLanguageList();
}
/**
* checking phpsysinfo.ini setting for template, if not supportet set phpsysinfo.css as default
* checking phpsysinfo.ini setting for language, if not supported set en as default
*
* @return void
*/
private function _checkTemplateLanguage()
{
$this->_template = trim(strtolower(PSI_DEFAULT_TEMPLATE));
if (!file_exists(APP_ROOT.'/templates/'.$this->_template.".css")) {
$this->_template = 'phpsysinfo';
}
$this->_language = trim(strtolower(PSI_DEFAULT_LANG));
if (!file_exists(APP_ROOT.'/language/'.$this->_language.".xml")) {
$this->_language = 'en';
}
}
/**
* get all available tamplates and store them in internal array
*
* @return void
*/
private function _getTemplateList()
{
$dirlist = CommonFunctions::gdc(APP_ROOT.'/templates/');
sort($dirlist);
foreach ($dirlist as $file) {
$tpl_ext = substr($file, strlen($file) - 4);
$tpl_name = substr($file, 0, strlen($file) - 4);
if (($tpl_ext === ".css") && ($tpl_name !== "phpsysinfo_bootstrap")) {
array_push($this->_templates, $tpl_name);
}
}
}
/**
* get all available translations and store them in internal array
*
* @return void
*/
private function _getLanguageList()
{
$dirlist = CommonFunctions::gdc(APP_ROOT.'/language/');
sort($dirlist);
foreach ($dirlist as $file) {
$lang_ext = substr($file, strlen($file) - 4);
$lang_name = substr($file, 0, strlen($file) - 4);
if ($lang_ext == ".xml") {
array_push($this->_languages, $lang_name);
}
}
}
/**
* render the page
*
* @return void
*/
public function run()
{
$this->_checkTemplateLanguage();
$tpl = new Template("/templates/html/index_dynamic.html");
$tpl->set("template", $this->_template);
$tpl->set("templates", $this->_templates);
$tpl->set("language", $this->_language);
$tpl->set("languages", $this->_languages);
echo $tpl->fetch();
}
}

View File

@@ -0,0 +1,189 @@
<?php
/**
* XML Generator 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 SVN: $Id: class.WebpageXML.inc.php 661 2012-08-27 11:26:39Z namiltd $
* @link http://phpsysinfo.sourceforge.net
*/
/**
* class for xml output
*
* @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 Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
class WebpageXML extends Output implements PSI_Interface_Output
{
/**
* xml object that holds the generated xml
*
* @var XML
*/
private $_xml;
/**
* only plugin xml
*
* @var boolean
*/
private $_pluginRequest = false;
/**
* complete xml
*
* @var boolean
*/
private $_completeXML = false;
/**
* name of the plugin
*
* @var string
*/
private $_pluginName = null;
/**
* generate the output
*
* @return void
*/
private function _prepare()
{
if (!$this->_pluginRequest) {
// Figure out which OS we are running on, and detect support
if (!file_exists(APP_ROOT.'/includes/os/class.'.PSI_OS.'.inc.php')) {
$this->error->addError("file_exists(class.".PSI_OS.".inc.php)", PSI_OS." is not currently supported");
}
// check if there is a valid sensor configuration in phpsysinfo.ini
$foundsp = array();
if (defined('PSI_SENSOR_PROGRAM') && is_string(PSI_SENSOR_PROGRAM)) {
if (preg_match(ARRAY_EXP, PSI_SENSOR_PROGRAM)) {
$sensorprograms = eval(strtolower(PSI_SENSOR_PROGRAM));
} else {
$sensorprograms = array(strtolower(PSI_SENSOR_PROGRAM));
}
foreach ($sensorprograms as $sensorprogram) {
if (!file_exists(APP_ROOT.'/includes/mb/class.'.$sensorprogram.'.inc.php')) {
$this->error->addError("file_exists(class.".htmlspecialchars($sensorprogram).".inc.php)", "specified sensor program is not supported");
} else {
$foundsp[] = $sensorprogram;
}
}
}
/**
* motherboard information
*
* @var serialized array
*/
define('PSI_MBINFO', serialize($foundsp));
// check if there is a valid hddtemp configuration in phpsysinfo.ini
$found = false;
if (PSI_HDD_TEMP !== false) {
$found = true;
}
/**
* hddtemp information available or not
*
* @var boolean
*/
define('PSI_HDDTEMP', $found);
// check if there is a valid ups configuration in phpsysinfo.ini
$foundup = array();
if (defined('PSI_UPS_PROGRAM') && is_string(PSI_UPS_PROGRAM)) {
if (preg_match(ARRAY_EXP, PSI_UPS_PROGRAM)) {
$upsprograms = eval(strtolower(PSI_UPS_PROGRAM));
} else {
$upsprograms = array(strtolower(PSI_UPS_PROGRAM));
}
foreach ($upsprograms as $upsprogram) {
if (!file_exists(APP_ROOT.'/includes/ups/class.'.$upsprogram.'.inc.php')) {
$this->error->addError("file_exists(class.".htmlspecialchars($upsprogram).".inc.php)", "specified UPS program is not supported");
} else {
$foundup[] = $upsprogram;
}
}
}
/**
* ups information
*
* @var serialized array
*/
define('PSI_UPSINFO', serialize($foundup));
// if there are errors stop executing the script until they are fixed
if ($this->error->errorsExist()) {
$this->error->errorsAsXML();
}
}
// Create the XML
if ($this->_pluginRequest) {
$this->_xml = new XML(false, $this->_pluginName);
} else {
$this->_xml = new XML($this->_completeXML);
}
}
/**
* render the output
*
* @return void
*/
public function run()
{
header("Cache-Control: no-cache, must-revalidate\n");
header("Content-Type: text/xml\n\n");
$xml = $this->_xml->getXml();
echo $xml->asXML();
}
/**
* get XML as pure string
*
* @return string
*/
public function getXMLString()
{
$xml = $this->_xml->getXml();
return $xml->asXML();
}
/**
* set parameters for the XML generation process
*
* @param boolean $completeXML switch for complete xml with all plugins
* @param string $plugin name of the plugin
*
* @return void
*/
public function __construct($completeXML, $plugin = null)
{
parent::__construct();
if ($completeXML) {
$this->_completeXML = true;
}
if ($plugin) {
if (in_array(strtolower($plugin), CommonFunctions::getPlugins())) {
$this->_pluginName = $plugin;
$this->_pluginRequest = true;
}
}
$this->_prepare();
}
}

View File

@@ -0,0 +1,54 @@
<?php
/**
* start page for webaccess
*
* PHP version 5
*
* @category PHP
* @package PSI_Web
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @version SVN: $Id: class.WebpageXSLT.inc.php 569 2012-04-16 06:08:18Z namiltd $
* @link http://phpsysinfo.sourceforge.net
*/
/**
* generate a static webpage with xslt trasformation of the xml
*
* @category PHP
* @package PSI_Web
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @version Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
class WebpageXSLT extends WebpageXML implements PSI_Interface_Output
{
/**
* call the parent constructor
*/
public function __construct()
{
parent::__construct(false, null);
}
/**
* generate the static page
*
* @return void
*/
public function run()
{
CommonFunctions::checkForExtensions(array('xsl'));
$xmlfile = $this->getXMLString();
$xslfile = "phpsysinfo.xslt";
$domxml = new DOMDocument();
$domxml->loadXML($xmlfile);
$domxsl = new DOMDocument();
$domxsl->load($xslfile);
$xsltproc = new XSLTProcessor;
$xsltproc->importStyleSheet($domxsl);
echo $xsltproc->transformToXML($domxml);
}
}

View File

@@ -0,0 +1,134 @@
<?php
/**
* Basic Plugin Functions
*
* PHP version 5
*
* @category PHP
* @package PSI_Plugin
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @version SVN: $Id: class.PSI_Plugin.inc.php 661 2012-08-27 11:26:39Z namiltd $
* @link http://phpsysinfo.sourceforge.net
*/
/**
* basic functions to get a plugin working in phpSysinfo
* every plugin must implement this abstract class to be a valid plugin, main tasks
* of this class are reading the configuration file and check for the required files
* (*.js, lang/en.xml) to get everything working, if we have errors here we log them
* to our global error object
*
* @category PHP
* @package PSI_Plugin
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @version Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
abstract class PSI_Plugin implements PSI_Interface_Plugin
{
/**
* name of the plugin (classname)
*
* @var string
*/
private $_plugin_name = "";
/**
* full directory path of the plugin
*
* @var string
*/
private $_plugin_base = "";
/**
* global object for error handling
*
* @var Error
*/
protected $global_error = "";
/**
* xml tamplate with header
*
* @var SimpleXMLExtended
*/
protected $xml;
/**
* build the global Error object, read the configuration and check if all files are available
* for a minimalistic function of the plugin
*
* @param String $plugin_name name of the plugin
* @param String $enc target encoding
*
* @return void
*/
public function __construct($plugin_name, $enc)
{
$this->global_error = Error::Singleton();
if (trim($plugin_name) != "") {
$this->_plugin_name = $plugin_name;
$this->_plugin_base = APP_ROOT."/plugins/".strtolower($this->_plugin_name)."/";
$this->_checkfiles();
$this->_getconfig();
} else {
$this->global_error->addError("__construct()", "Parent constructor called without Plugin-Name!");
}
$this->_createXml($enc);
}
/**
* read the plugin configuration file, if we have one in the plugin directory
*
* @return void
*/
private function _getconfig()
{
if ((!defined('PSI_PLUGIN_'.strtoupper($this->_plugin_name).'_ACCESS')) &&
(!defined('PSI_PLUGIN_'.strtoupper($this->_plugin_name).'_FILE'))) {
$this->global_error->addError("config.ini", "Config for plugin ".$this->_plugin_name." not exist!");
}
}
/**
* check if there is a default translation file availabe and also the required js file for
* appending the content of the plugin to the main webpage
*
* @return void
*/
private function _checkfiles()
{
if (!file_exists($this->_plugin_base."js/".strtolower($this->_plugin_name).".js")) {
$this->global_error->addError("file_exists(".$this->_plugin_base."js/".strtolower($this->_plugin_name).".js)", "JS-File for Plugin '".$this->_plugin_name."' is missing!");
} else {
if (!is_readable($this->_plugin_base."js/".strtolower($this->_plugin_name).".js")) {
$this->global_error->addError("is_readable(".$this->_plugin_base."js/".strtolower($this->_plugin_name).".js)", "JS-File for Plugin '".$this->_plugin_name."' is not readable but present!");
}
}
if (!file_exists($this->_plugin_base."lang/en.xml")) {
$this->global_error->addError("file_exists(".$this->_plugin_base."lang/en.xml)", "At least an english translation must exist for the plugin!");
} else {
if (!is_readable($this->_plugin_base."lang/en.xml")) {
$this->global_error->addError("is_readable(".$this->_plugin_base."js/".$this->_plugin_name.".js)", "The english translation can't be read but is present!");
}
}
}
/**
* create the xml template where plugin information are added to
*
* @param String $enc target encoding
*
* @return Void
*/
private function _createXml($enc)
{
$dom = new DOMDocument('1.0', 'UTF-8');
$root = $dom->createElement("Plugin_".$this->_plugin_name);
$dom->appendChild($root);
$this->xml = new SimpleXMLExtended(simplexml_import_dom($dom), $enc);
}
}

View File

@@ -0,0 +1,201 @@
<?php
/**
* MBInfo TO class
*
* PHP version 5
*
* @category PHP
* @package PSI_TO
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @version SVN: $Id: class.MBInfo.inc.php 253 2009-06-17 13:07:50Z bigmichi1 $
* @link http://phpsysinfo.sourceforge.net
*/
/**
* MBInfo TO class
*
* @category PHP
* @package PSI_TO
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @version Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
class MBInfo
{
/**
* array with SensorDevices for temperatures
*
* @see SensorDevice
*
* @var Array
*/
private $_mbTemp = array();
/**
* array with SensorDevices for fans
*
* @see SensorDevice
*
* @var Array
*/
private $_mbFan = array();
/**
* array with SensorDevices for voltages
*
* @see SensorDevice
*
* @var Array
*/
private $_mbVolt = array();
/**
* array with SensorDevices for power
*
* @see SensorDevice
*
* @var Array
*/
private $_mbPower = array();
/**
* array with SensorDevices for apmers
*
* @see SensorDevice
*
* @var Array
*/
private $_mbCurrent = array();
/**
* Returns $_mbFan.
*
* @see System::$_mbFan
*
* @return Array
*/
public function getMbFan()
{
return $this->_mbFan;
}
/**
* Sets $_mbFan.
*
* @param SensorDevice $mbFan fan device
*
* @see System::$_mbFan
*
* @return Void
*/
public function setMbFan($mbFan)
{
array_push($this->_mbFan, $mbFan);
}
/**
* Returns $_mbTemp.
*
* @see System::$_mbTemp
*
* @return Array
*/
public function getMbTemp()
{
return $this->_mbTemp;
}
/**
* Sets $_mbTemp.
*
* @param Sensor $mbTemp temp device
*
* @see System::$_mbTemp
*
* @return Void
*/
public function setMbTemp($mbTemp)
{
array_push($this->_mbTemp, $mbTemp);
}
/**
* Returns $_mbVolt.
*
* @see System::$_mbVolt
*
* @return Array
*/
public function getMbVolt()
{
return $this->_mbVolt;
}
/**
* Sets $_mbVolt.
*
* @param Sensor $mbVolt voltage device
*
* @see System::$_mbVolt
*
* @return Void
*/
public function setMbVolt($mbVolt)
{
array_push($this->_mbVolt, $mbVolt);
}
/**
* Returns $_mbPower.
*
* @see System::$_mbPower
*
* @return Array
*/
public function getMbPower()
{
return $this->_mbPower;
}
/**
* Sets $_mbPower.
*
* @param Sensor $mbPower power device
*
* @see System::$_mbPower
*
* @return Void
*/
public function setMbPower($mbPower)
{
array_push($this->_mbPower, $mbPower);
}
/**
* Returns $_mbCurrent.
*
* @see System::$_mbCurrent
*
* @return Array
*/
public function getMbCurrent()
{
return $this->_mbCurrent;
}
/**
* Sets $_mbCurrent.
*
* @param Sensor $mbCurrent current device
*
* @see System::$_mbCurrent
*
* @return Void
*/
public function setMbCurrent($mbCurrent)
{
array_push($this->_mbCurrent, $mbCurrent);
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,62 @@
<?php
/**
* MBInfo TO class
*
* PHP version 5
*
* @category PHP
* @package PSI_TO
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @version SVN: $Id: class.UPSInfo.inc.php 329 2009-09-07 11:21:44Z bigmichi1 $
* @link http://phpsysinfo.sourceforge.net
*/
/**
* MBInfo TO class
*
* @category PHP
* @package PSI_TO
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @version Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
class UPSInfo
{
/**
* array with upsdivices
*
* @see UPSDevice
*
* @var Array
*/
private $_upsDevices = array();
/**
* Returns $_upsDevices.
*
* @see UPSInfo::$_upsDevices
*
* @return Array
*/
public function getUpsDevices()
{
return $this->_upsDevices;
}
/**
* Sets $_upsDevices.
*
* @param UPSDevice $upsDevices upsdevice
*
* @see UPSInfo::$_upsDevices
*
* @return Void
*/
public function setUpsDevices($upsDevices)
{
array_push($this->_upsDevices, $upsDevices);
}
}

View File

@@ -0,0 +1,357 @@
<?php
/**
* CpuDevice TO class
*
* PHP version 5
*
* @category PHP
* @package PSI_TO
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @version SVN: $Id: class.CpuDevice.inc.php 411 2010-12-28 22:32:52Z Jacky672 $
* @link http://phpsysinfo.sourceforge.net
*/
/**
* CpuDevice TO class
*
* @category PHP
* @package PSI_TO
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @version Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
class CpuDevice
{
/**
* model of the cpu
*
* @var String
*/
private $_model = "";
/**
* speed of the cpu in hertz
*
* @var Integer
*/
private $_cpuSpeed = 0;
/**
* max speed of the cpu in hertz
*
* @var Integer
*/
private $_cpuSpeedMax = 0;
/**
* min speed of the cpu in hertz
*
* @var Integer
*/
private $_cpuSpeedMin = 0;
/**
* cache size in bytes, if available
*
* @var Integer
*/
private $_cache = null;
/**
* virtualization, if available
*
* @var String
*/
private $_virt = null;
/**
* busspeed in hertz, if available
*
* @var Integer
*/
private $_busSpeed = null;
/**
* temperature of the cpu, if available
*
* @var Integer
*/
private $_temp = null;
/**
* bogomips of the cpu, if available
*
* @var Integer
*/
private $_bogomips = null;
/**
* current load in percent of the cpu, if available
*
* @var Integer
*/
private $_load = null;
/**
* Returns $_bogomips.
*
* @see Cpu::$_bogomips
*
* @return Integer
*/
public function getBogomips()
{
return $this->_bogomips;
}
/**
* Sets $_bogomips.
*
* @param Integer $bogomips bogompis
*
* @see Cpu::$_bogomips
*
* @return Void
*/
public function setBogomips($bogomips)
{
$this->_bogomips = $bogomips;
}
/**
* Returns $_busSpeed.
*
* @see Cpu::$_busSpeed
*
* @return Integer
*/
public function getBusSpeed()
{
return $this->_busSpeed;
}
/**
* Sets $_busSpeed.
*
* @param Integer $busSpeed busspeed
*
* @see Cpu::$_busSpeed
*
* @return Void
*/
public function setBusSpeed($busSpeed)
{
$this->_busSpeed = $busSpeed;
}
/**
* Returns $_cache.
*
* @see Cpu::$_cache
*
* @return Integer
*/
public function getCache()
{
return $this->_cache;
}
/**
* Sets $_cache.
*
* @param Integer $cache cache size
*
* @see Cpu::$_cache
*
* @return Void
*/
public function setCache($cache)
{
$this->_cache = $cache;
}
/**
* Returns $_virt.
*
* @see Cpu::$_virt
*
* @return String
*/
public function getVirt()
{
return $this->_virt;
}
/**
* Sets $_virt.
*
* @param String $_virt
*
* @see Cpu::$_virt
*
* @return Void
*/
public function setVirt($virt)
{
$this->_virt = $virt;
}
/**
* Returns $_cpuSpeed.
*
* @see Cpu::$_cpuSpeed
*
* @return Integer
*/
public function getCpuSpeed()
{
return $this->_cpuSpeed;
}
/**
* Returns $_cpuSpeedMax.
*
* @see Cpu::$_cpuSpeedMAx
*
* @return Integer
*/
public function getCpuSpeedMax()
{
return $this->_cpuSpeedMax;
}
/**
* Returns $_cpuSpeedMin.
*
* @see Cpu::$_cpuSpeedMin
*
* @return Integer
*/
public function getCpuSpeedMin()
{
return $this->_cpuSpeedMin;
}
/**
* Sets $_cpuSpeed.
*
* @param Integer $cpuSpeed cpuspeed
*
* @see Cpu::$_cpuSpeed
*
* @return Void
*/
public function setCpuSpeed($cpuSpeed)
{
$this->_cpuSpeed = $cpuSpeed;
}
/**
* Sets $_cpuSpeedMax.
*
* @param Integer $cpuSpeedMax cpuspeedmax
*
* @see Cpu::$_cpuSpeedMax
*
* @return Void
*/
public function setCpuSpeedMax($cpuSpeedMax)
{
$this->_cpuSpeedMax = $cpuSpeedMax;
}
/**
* Sets $_cpuSpeedMin.
*
* @param Integer $cpuSpeedMin cpuspeedmin
*
* @see Cpu::$_cpuSpeedMin
*
* @return Void
*/
public function setCpuSpeedMin($cpuSpeedMin)
{
$this->_cpuSpeedMin = $cpuSpeedMin;
}
/**
* Returns $_model.
*
* @see Cpu::$_model
*
* @return String
*/
public function getModel()
{
return $this->_model;
}
/**
* Sets $_model.
*
* @param String $model cpumodel
*
* @see Cpu::$_model
*
* @return Void
*/
public function setModel($model)
{
$this->_model = $model;
}
/**
* Returns $_temp.
*
* @see Cpu::$_temp
*
* @return Integer
*/
public function getTemp()
{
return $this->_temp;
}
/**
* Sets $_temp.
*
* @param Integer $temp temperature
*
* @see Cpu::$_temp
*
* @return Void
*/
public function setTemp($temp)
{
$this->_temp = $temp;
}
/**
* Returns $_load.
*
* @see CpuDevice::$_load
*
* @return Integer
*/
public function getLoad()
{
return $this->_load;
}
/**
* Sets $_load.
*
* @param Integer $load load percent
*
* @see CpuDevice::$_load
*
* @return Void
*/
public function setLoad($load)
{
$this->_load = $load;
}
}

View File

@@ -0,0 +1,308 @@
<?php
/**
* DiskDevice TO class
*
* PHP version 5
*
* @category PHP
* @package PSI_TO
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @version SVN: $Id: class.DiskDevice.inc.php 252 2009-06-17 13:06:44Z bigmichi1 $
* @link http://phpsysinfo.sourceforge.net
*/
/**
* DiskDevice TO class
*
* @category PHP
* @package PSI_TO
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @version Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
class DiskDevice
{
/**
* name of the disk device
*
* @var String
*/
private $_name = "";
/**
* type of the filesystem on the disk device
*
* @var String
*/
private $_fsType = "";
/**
* diskspace that is free in bytes
*
* @var Integer
*/
private $_free = 0;
/**
* diskspace that is used in bytes
*
* @var Integer
*/
private $_used = 0;
/**
* total diskspace
*
* @var Integer
*/
private $_total = 0;
/**
* mount point of the disk device if available
*
* @var String
*/
private $_mountPoint = null;
/**
* additional options of the device, like mount options
*
* @var String
*/
private $_options = null;
/**
* inodes usage in percent if available
*
* @var
*/
private $_percentInodesUsed = null;
/**
* Returns PercentUsed calculated when function is called from internal values
*
* @see DiskDevice::$_total
* @see DiskDevice::$_used
*
* @return Integer
*/
public function getPercentUsed()
{
if ($this->_total > 0) {
return round($this->_used / $this->_total * 100);
} else {
return 0;
}
}
/**
* Returns $_PercentInodesUsed.
*
* @see DiskDevice::$_PercentInodesUsed
*
* @return Integer
*/
public function getPercentInodesUsed()
{
return $this->_percentInodesUsed;
}
/**
* Sets $_PercentInodesUsed.
*
* @param Integer $percentInodesUsed inodes percent
*
* @see DiskDevice::$_PercentInodesUsed
*
* @return Void
*/
public function setPercentInodesUsed($percentInodesUsed)
{
$this->_percentInodesUsed = $percentInodesUsed;
}
/**
* Returns $_free.
*
* @see DiskDevice::$_free
*
* @return Integer
*/
public function getFree()
{
return $this->_free;
}
/**
* Sets $_free.
*
* @param Integer $free free bytes
*
* @see DiskDevice::$_free
*
* @return Void
*/
public function setFree($free)
{
$this->_free = $free;
}
/**
* Returns $_fsType.
*
* @see DiskDevice::$_fsType
*
* @return String
*/
public function getFsType()
{
return $this->_fsType;
}
/**
* Sets $_fsType.
*
* @param String $fsType filesystemtype
*
* @see DiskDevice::$_fsType
*
* @return Void
*/
public function setFsType($fsType)
{
$this->_fsType = $fsType;
}
/**
* Returns $_mountPoint.
*
* @see DiskDevice::$_mountPoint
*
* @return String
*/
public function getMountPoint()
{
return $this->_mountPoint;
}
/**
* Sets $_mountPoint.
*
* @param String $mountPoint mountpoint
*
* @see DiskDevice::$_mountPoint
*
* @return Void
*/
public function setMountPoint($mountPoint)
{
$this->_mountPoint = $mountPoint;
}
/**
* Returns $_name.
*
* @see DiskDevice::$_name
*
* @return String
*/
public function getName()
{
return $this->_name;
}
/**
* Sets $_name.
*
* @param String $name device name
*
* @see DiskDevice::$_name
*
* @return Void
*/
public function setName($name)
{
$this->_name = $name;
}
/**
* Returns $_options.
*
* @see DiskDevice::$_options
*
* @return String
*/
public function getOptions()
{
return $this->_options;
}
/**
* Sets $_options.
*
* @param String $options additional options
*
* @see DiskDevice::$_options
*
* @return Void
*/
public function setOptions($options)
{
$this->_options = $options;
}
/**
* Returns $_total.
*
* @see DiskDevice::$_total
*
* @return Integer
*/
public function getTotal()
{
return $this->_total;
}
/**
* Sets $_total.
*
* @param Integer $total total bytes
*
* @see DiskDevice::$_total
*
* @return Void
*/
public function setTotal($total)
{
$this->_total = $total;
}
/**
* Returns $_used.
*
* @see DiskDevice::$_used
*
* @return Integer
*/
public function getUsed()
{
return $this->_used;
}
/**
* Sets $_used.
*
* @param Integer $used used bytes
*
* @see DiskDevice::$_used
*
* @return Void
*/
public function setUsed($used)
{
$this->_used = $used;
}
}

View File

@@ -0,0 +1,142 @@
<?php
/**
* HWDevice TO class
*
* PHP version 5
*
* @category PHP
* @package PSI_TO
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @version SVN: $Id: class.HWDevice.inc.php 255 2009-06-17 13:39:41Z bigmichi1 $
* @link http://phpsysinfo.sourceforge.net
*/
/**
* HWDevice TO class
*
* @category PHP
* @package PSI_TO
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @version Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
class HWDevice
{
/**
* name of the device
*
* @var String
*/
private $_name = "";
/**
* capacity of the device, if not available it will be null
*
* @var Integer
*/
private $_capacity = null;
/**
* count of the device
*
* @var Integer
*/
private $_count = 1;
/**
* compare a given device with the internal one
*
* @param HWDevice $dev device that should be compared
*
* @return boolean
*/
public function equals(HWDevice $dev)
{
if ($dev->getName() === $this->_name && $dev->getCapacity() === $this->_capacity) {
return true;
} else {
return false;
}
}
/**
* Returns $_capacity.
*
* @see HWDevice::$_capacity
*
* @return Integer
*/
public function getCapacity()
{
return $this->_capacity;
}
/**
* Sets $_capacity.
*
* @param Integer $capacity device capacity
*
* @see HWDevice::$_capacity
*
* @return Void
*/
public function setCapacity($capacity)
{
$this->_capacity = $capacity;
}
/**
* Returns $_name.
*
* @see HWDevice::$_name
*
* @return String
*/
public function getName()
{
return $this->_name;
}
/**
* Sets $_name.
*
* @param String $name device name
*
* @see HWDevice::$_name
*
* @return Void
*/
public function setName($name)
{
$this->_name = $name;
}
/**
* Returns $_count.
*
* @see HWDevice::$_count
*
* @return Integer
*/
public function getCount()
{
return $this->_count;
}
/**
* Sets $_count.
*
* @param Integer $count device count
*
* @see HWDevice::$_count
*
* @return Void
*/
public function setCount($count)
{
$this->_count = $count;
}
}

View File

@@ -0,0 +1,225 @@
<?php
/**
* NetDevice TO class
*
* PHP version 5
*
* @category PHP
* @package PSI_TO
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @version SVN: $Id: class.NetDevice.inc.php 547 2012-03-22 09:44:38Z namiltd $
* @link http://phpsysinfo.sourceforge.net
*/
/**
* NetDevice TO class
*
* @category PHP
* @package PSI_TO
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @version Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
class NetDevice
{
/**
* name of the device
*
* @var String
*/
private $_name = "";
/**
* transmitted bytes
*
* @var Integer
*/
private $_txBytes = 0;
/**
* received bytes
*
* @var Integer
*/
private $_rxBytes = 0;
/**
* counted error packages
*
* @var Integer
*/
private $_errors = 0;
/**
* counted droped packages
*
* @var Integer
*/
private $_drops = 0;
/**
* string with info
*
* @var String
*/
private $_info = null;
/**
* Returns $_drops.
*
* @see NetDevice::$_drops
*
* @return Integer
*/
public function getDrops()
{
return $this->_drops;
}
/**
* Sets $_drops.
*
* @param Integer $drops dropped packages
*
* @see NetDevice::$_drops
*
* @return Void
*/
public function setDrops($drops)
{
$this->_drops = $drops;
}
/**
* Returns $_errors.
*
* @see NetDevice::$_errors
*
* @return Integer
*/
public function getErrors()
{
return $this->_errors;
}
/**
* Sets $_errors.
*
* @param Integer $errors error packages
*
* @see NetDevice::$_errors
*
* @return Void
*/
public function setErrors($errors)
{
$this->_errors = $errors;
}
/**
* Returns $_name.
*
* @see NetDevice::$_name
*
* @return String
*/
public function getName()
{
return $this->_name;
}
/**
* Sets $_name.
*
* @param String $name device name
*
* @see NetDevice::$_name
*
* @return Void
*/
public function setName($name)
{
$this->_name = $name;
}
/**
* Returns $_rxBytes.
*
* @see NetDevice::$_rxBytes
*
* @return Integer
*/
public function getRxBytes()
{
return $this->_rxBytes;
}
/**
* Sets $_rxBytes.
*
* @param Integer $rxBytes received bytes
*
* @see NetDevice::$_rxBytes
*
* @return Void
*/
public function setRxBytes($rxBytes)
{
$this->_rxBytes = $rxBytes;
}
/**
* Returns $_txBytes.
*
* @see NetDevice::$_txBytes
*
* @return Integer
*/
public function getTxBytes()
{
return $this->_txBytes;
}
/**
* Sets $_txBytes.
*
* @param Integer $txBytes transmitted bytes
*
* @see NetDevice::$_txBytes
*
* @return Void
*/
public function setTxBytes($txBytes)
{
$this->_txBytes = $txBytes;
}
/**
* Returns $_info.
*
* @see NetDevice::$_info
*
* @return String
*/
public function getInfo()
{
return $this->_info;
}
/**
* Sets $_info.
*
* @param String $info info string
*
* @see NetDevice::$_info
*
* @return Void
*/
public function setInfo($info)
{
$this->_info = $info;
}
}

View File

@@ -0,0 +1,192 @@
<?php
/**
* SensorDevice TO class
*
* PHP version 5
*
* @category PHP
* @package PSI_TO
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @version SVN: $Id: class.SensorDevice.inc.php 592 2012-07-03 10:55:51Z namiltd $
* @link http://phpsysinfo.sourceforge.net
*/
/**
* SensorDevice TO class
*
* @category PHP
* @package PSI_TO
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @version Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
class SensorDevice
{
/**
* name of the sensor
*
* @var String
*/
private $_name = "";
/**
* current value of the sensor
*
* @var Integer
*/
private $_value = 0;
/**
* maximum value of the sensor
*
* @var Integer
*/
private $_max = null;
/**
* minimum value of the sensor
*
* @var Integer
*/
private $_min = null;
/**
* event of the sensor
*
* @var String
*/
private $_event = "";
/**
* Returns $_max.
*
* @see Sensor::$_max
*
* @return Integer
*/
public function getMax()
{
return $this->_max;
}
/**
* Sets $_max.
*
* @param Integer $max maximum value
*
* @see Sensor::$_max
*
* @return Void
*/
public function setMax($max)
{
$this->_max = $max;
}
/**
* Returns $_min.
*
* @see Sensor::$_min
*
* @return Integer
*/
public function getMin()
{
return $this->_min;
}
/**
* Sets $_min.
*
* @param Integer $min minimum value
*
* @see Sensor::$_min
*
* @return Void
*/
public function setMin($min)
{
$this->_min = $min;
}
/**
* Returns $_name.
*
* @see Sensor::$_name
*
* @return String
*/
public function getName()
{
return $this->_name;
}
/**
* Sets $_name.
*
* @param String $name sensor name
*
* @see Sensor::$_name
*
* @return Void
*/
public function setName($name)
{
$this->_name = $name;
}
/**
* Returns $_value.
*
* @see Sensor::$_value
*
* @return Integer
*/
public function getValue()
{
return $this->_value;
}
/**
* Sets $_value.
*
* @param Integer $value current value
*
* @see Sensor::$_value
*
* @return Void
*/
public function setValue($value)
{
$this->_value = $value;
}
/**
* Returns $_event.
*
* @see Sensor::$_event
*
* @return String
*/
public function getEvent()
{
return $this->_event;
}
/**
* Sets $_event.
*
* @param String $event sensor event
*
* @see Sensor::$_event
*
* @return Void
*/
public function setEvent($event)
{
$this->_event = $event;
}
}

View File

@@ -0,0 +1,555 @@
<?php
/**
* UPSDevice TO class
*
* PHP version 5
*
* @category PHP
* @package PSI_TO
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @version SVN: $Id: class.UPSDevice.inc.php 262 2009-06-22 10:48:33Z bigmichi1 $
* @link http://phpsysinfo.sourceforge.net
*/
/**
* UPSDevice TO class
*
* @category PHP
* @package PSI_TO
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @version Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
class UPSDevice
{
/**
* name of the ups
*
* @var String
*/
private $_name = "";
/**
* model of the ups
*
* @var String
*/
private $_model = "";
/**
* mode of the ups
*
* @var String
*/
private $_mode = "";
/**
* last start time
*
* @var String
*/
private $_startTime = "";
/**
* status of the ups
*
* @var String
*/
private $_status = "";
/**
* temperature of the ups
*
* @var Integer
*/
private $_temperatur = null;
/**
* outages count
*
* @var Integer
*/
private $_outages = null;
/**
* date of last outtage
*
* @var String
*/
private $_lastOutage = null;
/**
* date of last outage finish
*
* @var String
*/
private $_lastOutageFinish = null;
/**
* line volt
*
* @var Integer
*/
private $_lineVoltage = null;
/**
* line freq
*
* @var Integer
*/
private $_lineFrequency = null;
/**
* current load of the ups in percent
*
* @var Integer
*/
private $_load = null;
/**
* battery installation date
*
* @var String
*/
private $_batteryDate = null;
/**
* current battery volt
*
* @var Integer
*/
private $_batteryVoltage = null;
/**
* current charge in percent of the battery
*
* @var Integer
*/
private $_batterCharge = null;
/**
* time left
*
* @var String
*/
private $_timeLeft = null;
/**
* Returns $_batterCharge.
*
* @see UPSDevice::$_batterCharge
*
* @return integer
*/
public function getBatterCharge()
{
return $this->_batterCharge;
}
/**
* Sets $_batterCharge.
*
* @param Integer $batterCharge battery charge
*
* @see UPSDevice::$_batterCharge
*
* @return void
*/
public function setBatterCharge($batterCharge)
{
$this->_batterCharge = $batterCharge;
}
/**
* Returns $_batteryDate.
*
* @see UPSDevice::$_batteryDate
*
* @return String
*/
public function getBatteryDate()
{
return $this->_batteryDate;
}
/**
* Sets $_batteryDate.
*
* @param object $batteryDate battery date
*
* @see UPSDevice::$_batteryDate
*
* @return Void
*/
public function setBatteryDate($batteryDate)
{
$this->_batteryDate = $batteryDate;
}
/**
* Returns $_batteryVoltage.
*
* @see UPSDevice::$_batteryVoltage
*
* @return Integer
*/
public function getBatteryVoltage()
{
return $this->_batteryVoltage;
}
/**
* Sets $_batteryVoltage.
*
* @param object $batteryVoltage battery volt
*
* @see UPSDevice::$_batteryVoltage
*
* @return Void
*/
public function setBatteryVoltage($batteryVoltage)
{
$this->_batteryVoltage = $batteryVoltage;
}
/**
* Returns $_lastOutage.
*
* @see UPSDevice::$_lastOutage
*
* @return String
*/
public function getLastOutage()
{
return $this->_lastOutage;
}
/**
* Sets $_lastOutage.
*
* @param String $lastOutage last Outage
*
* @see UPSDevice::$lastOutage
*
* @return Void
*/
public function setLastOutage($lastOutage)
{
$this->_lastOutage = $lastOutage;
}
/**
* Returns $_lastOutageFinish.
*
* @see UPSDevice::$_lastOutageFinish
*
* @return String
*/
public function getLastOutageFinish()
{
return $this->_lastOutageFinish;
}
/**
* Sets $_lastOutageFinish.
*
* @param String $lastOutageFinish last outage finish
*
* @see UPSDevice::$_lastOutageFinish
*
* @return Void
*/
public function setLastOutageFinish($lastOutageFinish)
{
$this->_lastOutageFinish = $lastOutageFinish;
}
/**
* Returns $_lineVoltage.
*
* @see UPSDevice::$_lineVoltage
*
* @return Integer
*/
public function getLineVoltage()
{
return $this->_lineVoltage;
}
/**
* Sets $_lineVoltage.
*
* @param Integer $lineVoltage line voltage
*
* @see UPSDevice::$_lineVoltage
*
* @return Void
*/
public function setLineVoltage($lineVoltage)
{
$this->_lineVoltage = $lineVoltage;
}
/**
* Returns $_lineFrequency.
*
* @see UPSDevice::$_lineFrequency
*
* @return Integer
*/
public function getLineFrequency()
{
return $this->_lineFrequency;
}
/**
* Sets $_lineFrequency.
*
* @param Integer $lineFrequency line frequency
*
* @see UPSDevice::$_lineFrequency
*
* @return Void
*/
public function setLineFrequency($lineFrequency)
{
$this->_lineFrequency = $lineFrequency;
}
/**
* Returns $_load.
*
* @see UPSDevice::$_load
*
* @return Integer
*/
public function getLoad()
{
return $this->_load;
}
/**
* Sets $_load.
*
* @param Integer $load current load
*
* @see UPSDevice::$_load
*
* @return Void
*/
public function setLoad($load)
{
$this->_load = $load;
}
/**
* Returns $_mode.
*
* @see UPSDevice::$_mode
*
* @return String
*/
public function getMode()
{
return $this->_mode;
}
/**
* Sets $_mode.
*
* @param String $mode mode
*
* @see UPSDevice::$_mode
*
* @return Void
*/
public function setMode($mode)
{
$this->_mode = $mode;
}
/**
* Returns $_model.
*
* @see UPSDevice::$_model
*
* @return String
*/
public function getModel()
{
return $this->_model;
}
/**
* Sets $_model.
*
* @param String $model model
*
* @see UPSDevice::$_model
*
* @return Void
*/
public function setModel($model)
{
$this->_model = $model;
}
/**
* Returns $_name.
*
* @see UPSDevice::$_name
*
* @return String
*/
public function getName()
{
return $this->_name;
}
/**
* Sets $_name.
*
* @param String $name name
*
* @see UPSDevice::$_name
*
* @return Void
*/
public function setName($name)
{
$this->_name = $name;
}
/**
* Returns $_outages.
*
* @see UPSDevice::$_outages
*
* @return Integer
*/
public function getOutages()
{
return $this->_outages;
}
/**
* Sets $_outages.
*
* @param Integer $outages outages count
*
* @see UPSDevice::$_outages
*
* @return Void
*/
public function setOutages($outages)
{
$this->_outages = $outages;
}
/**
* Returns $_startTime.
*
* @see UPSDevice::$_startTime
*
* @return String
*/
public function getStartTime()
{
return $this->_startTime;
}
/**
* Sets $_startTime.
*
* @param String $startTime startTime
*
* @see UPSDevice::$_startTime
*
* @return Void
*/
public function setStartTime($startTime)
{
$this->_startTime = $startTime;
}
/**
* Returns $_status.
*
* @see UPSDevice::$_status
*
* @return String
*/
public function getStatus()
{
return $this->_status;
}
/**
* Sets $_status.
*
* @param String $status status
*
* @see UPSDevice::$_status
*
* @return Void
*/
public function setStatus($status)
{
$this->_status = $status;
}
/**
* Returns $_temperatur.
*
* @see UPSDevice::$_temperatur
*
* @return Integer
*/
public function getTemperatur()
{
return $this->_temperatur;
}
/**
* Sets $_temperatur.
*
* @param Integer $temperatur temperature
*
* @see UPSDevice::$_temperatur
*
* @return Void
*/
public function setTemperatur($temperatur)
{
$this->_temperatur = $temperatur;
}
/**
* Returns $_timeLeft.
*
* @see UPSDevice::$_timeLeft
*
* @return String
*/
public function getTimeLeft()
{
return $this->_timeLeft;
}
/**
* Sets $_timeLeft.
*
* @param String $timeLeft time left
*
* @see UPSDevice::$_timeLeft
*
* @return Void
*/
public function setTimeLeft($timeLeft)
{
$this->_timeLeft = $timeLeft;
}
}

View File

@@ -0,0 +1,145 @@
<?php
/**
* Apcupsd class
*
* PHP version 5
*
* @category PHP
* @package PSI_UPS
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @version SVN: $Id: class.apcupsd.inc.php 661 2012-08-27 11:26:39Z namiltd $
* @link http://phpsysinfo.sourceforge.net
*/
/**
* getting ups information from apcupsd program
*
* @category PHP
* @package PSI_UPS
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @author Artem Volk <artvolk@mail.ru>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @version Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
class Apcupsd extends UPS
{
/**
* internal storage for all gathered data
*
* @var Array
*/
private $_output = array();
/**
* get all information from all configured ups in phpsysinfo.ini and store output in internal array
*/
public function __construct()
{
parent::__construct();
if (defined('PSI_UPS_APCUPSD_LIST') && is_string(PSI_UPS_APCUPSD_LIST)) {
if (preg_match(ARRAY_EXP, PSI_UPS_APCUPSD_LIST)) {
$upses = eval(PSI_UPS_APCUPSD_LIST);
} else {
$upses = array(PSI_UPS_APCUPSD_LIST);
}
foreach ($upses as $ups) {
CommonFunctions::executeProgram('apcaccess', 'status '.trim($ups), $temp);
if (! empty($temp)) {
$this->_output[] = $temp;
}
}
} else { //use default if address and port not defined
CommonFunctions::executeProgram('apcaccess', 'status', $temp);
if (! empty($temp)) {
$this->_output[] = $temp;
}
}
}
/**
* parse the input and store data in resultset for xml generation
*
* @return Void
*/
private function _info()
{
foreach ($this->_output as $ups) {
$dev = new UPSDevice();
// General info
if (preg_match('/^UPSNAME\s*:\s*(.*)$/m', $ups, $data)) {
$dev->setName(trim($data[1]));
}
if (preg_match('/^MODEL\s*:\s*(.*)$/m', $ups, $data)) {
$model=trim($data[1]);
if (preg_match('/^APCMODEL\s*:\s*(.*)$/m', $ups, $data)) {
$dev->setModel($model.' ('.trim($data[1]).')');
} else {
$dev->setModel($model);
}
}
if (preg_match('/^UPSMODE\s*:\s*(.*)$/m', $ups, $data)) {
$dev->setMode(trim($data[1]));
}
if (preg_match('/^STARTTIME\s*:\s*(.*)$/m', $ups, $data)) {
$dev->setStartTime(trim($data[1]));
}
if (preg_match('/^STATUS\s*:\s*(.*)$/m', $ups, $data)) {
$dev->setStatus(trim($data[1]));
}
if (preg_match('/^ITEMP\s*:\s*(.*)$/m', $ups, $data)) {
$dev->setTemperatur(trim($data[1]));
}
// Outages
if (preg_match('/^NUMXFERS\s*:\s*(.*)$/m', $ups, $data)) {
$dev->setOutages(trim($data[1]));
}
if (preg_match('/^LASTXFER\s*:\s*(.*)$/m', $ups, $data)) {
$dev->setLastOutage(trim($data[1]));
}
if (preg_match('/^XOFFBATT\s*:\s*(.*)$/m', $ups, $data)) {
$dev->setLastOutageFinish(trim($data[1]));
}
// Line
if (preg_match('/^LINEV\s*:\s*(\d*\.\d*)(.*)$/m', $ups, $data)) {
$dev->setLineVoltage(trim($data[1]));
}
if (preg_match('/^LINEFREQ\s*:\s*(\d*\.\d*)(.*)$/m', $ups, $data)) {
$dev->setLineFrequency(trim($data[1]));
}
if (preg_match('/^LOADPCT\s*:\s*(\d*\.\d*)(.*)$/m', $ups, $data)) {
$dev->setLoad(trim($data[1]));
}
// Battery
if (preg_match('/^BATTDATE\s*:\s*(.*)$/m', $ups, $data)) {
$dev->setBatteryDate(trim($data[1]));
}
if (preg_match('/^BATTV\s*:\s*(\d*\.\d*)(.*)$/m', $ups, $data)) {
$dev->setBatteryVoltage(trim($data[1]));
}
if (preg_match('/^BCHARGE\s*:\s*(\d*\.\d*)(.*)$/m', $ups, $data)) {
$dev->setBatterCharge(trim($data[1]));
}
if (preg_match('/^TIMELEFT\s*:\s*(\d*\.\d*)(.*)$/m', $ups, $data)) {
$dev->setTimeLeft(trim($data[1]));
}
$this->upsinfo->setUpsDevices($dev);
}
}
/**
* get the information
*
* @see PSI_Interface_UPS::build()
*
* @return Void
*/
public function build()
{
$this->_info();
}
}

View File

@@ -0,0 +1,142 @@
<?php
/**
* Nut class
*
* PHP version 5
*
* @category PHP
* @package PSI_UPS
* @author Artem Volk <artvolk@mail.ru>
* @author Anders Häggström <hagge@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @version SVN: $Id: class.nut.inc.php 661 2012-08-27 11:26:39Z namiltd $
* @link http://phpsysinfo.sourceforge.net
*/
/**
* getting ups information from upsc program
*
* @category PHP
* @package PSI_UPS
* @author Artem Volk <artvolk@mail.ru>
* @author Anders Häggström <hagge@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @version Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
class Nut extends UPS
{
/**
* internal storage for all gathered data
*
* @var array
*/
private $_output = array();
/**
* get all information from all configured ups and store output in internal array
*/
public function __construct()
{
parent::__construct();
if (defined('PSI_UPS_NUT_LIST') && is_string(PSI_UPS_NUT_LIST)) {
if (preg_match(ARRAY_EXP, PSI_UPS_NUT_LIST)) {
$upses = eval(PSI_UPS_NUT_LIST);
} else {
$upses = array(PSI_UPS_NUT_LIST);
}
foreach ($upses as $ups) {
CommonFunctions::executeProgram('upsc', '-l '.trim($ups), $output);
$ups_names = preg_split("/\n/", $output, -1, PREG_SPLIT_NO_EMPTY);
foreach ($ups_names as $ups_name) {
CommonFunctions::executeProgram('upsc', trim($ups_name).'@'.trim($ups), $temp);
if (! empty($temp)) {
$this->_output[trim($ups_name).'@'.trim($ups)] = $temp;
}
}
}
} else { //use default if address and port not defined
CommonFunctions::executeProgram('upsc', '-l', $output);
$ups_names = preg_split("/\n/", $output, -1, PREG_SPLIT_NO_EMPTY);
foreach ($ups_names as $ups_name) {
CommonFunctions::executeProgram('upsc', trim($ups_name), $temp);
if (! empty($temp)) {
$this->_output[trim($ups_name)] = $temp;
}
}
}
}
/**
* parse the input and store data in resultset for xml generation
*
* @return array
*/
private function _info()
{
if (! empty($this->_output)) {
foreach ($this->_output as $name=>$value) {
$temp = preg_split("/\n/", $value, -1, PREG_SPLIT_NO_EMPTY);
$ups_data = array();
foreach ($temp as $value) {
$line = preg_split('/: /', $value, 2);
$ups_data[$line[0]] = isset($line[1]) ? trim($line[1]) : '';
}
$dev = new UPSDevice();
//General
$dev->setName($name);
if (isset($ups_data['ups.model'])) {
$dev->setModel($ups_data['ups.model']);
}
if (isset($ups_data['driver.name'])) {
$dev->setMode($ups_data['driver.name']);
}
if (isset($ups_data['ups.status'])) {
$dev->setStatus($ups_data['ups.status']);
}
//Line
if (isset($ups_data['input.voltage'])) {
$dev->setLineVoltage($ups_data['input.voltage']);
}
if (isset($ups_data['input.frequency'])) {
$dev->setLineFrequency($ups_data['input.frequency']);
}
if (isset($ups_data['ups.load'])) {
$dev->setLoad($ups_data['ups.load']);
}
//Battery
if (isset($ups_data['battery.voltage'])) {
$dev->setBatteryVoltage($ups_data['battery.voltage']);
}
if (isset($ups_data['battery.charge'])) {
$dev->setBatterCharge($ups_data['battery.charge']);
}
if (isset($ups_data['battery.runtime'])) {
$dev->setTimeLeft(round($ups_data['battery.runtime']/60, 2));
}
//Temperature
if (isset($ups_data['ups.temperature'])) {
$dev->setTemperatur($ups_data['ups.temperature']);
}
$this->upsinfo->setUpsDevices($dev);
}
}
}
/**
* get the information
*
* @see PSI_Interface_UPS::build()
*
* @return Void
*/
public function build()
{
$this->_info();
}
}

View File

@@ -0,0 +1,90 @@
<?php
/**
* Pmset class
*
* PHP version 5
*
* @category PHP
* @package PSI_UPS
* @author Robert Pelletier <drizzt@menzonet.org>
* @copyright 2014 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @version SVN: $Id: class.nut.inc.php 661 2012-08-27 11:26:39Z namiltd $
* @link http://phpsysinfo.sourceforge.net
*/
/**
* getting ups information from pmset program
*
* @category PHP
* @package PSI_UPS
* @author Robert Pelletier <drizzt@menzonet.org>
* @copyright 2014 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @version Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
class Pmset extends UPS
{
/**
* internal storage for all gathered data
*
* @var array
*/
private $_output = array();
/**
* get all information from all configured ups and store output in internal array
*/
public function __construct()
{
parent::__construct();
CommonFunctions::executeProgram('pmset', '-g batt', $temp);
if (! empty($temp)) {
$this->_output[] = $temp;
}
}
/**
* parse the input and store data in resultset for xml generation
*
* @return array
*/
private function _info()
{
$model = array();
$percCharge = array();
$lines = explode(PHP_EOL, implode($this->_output));
$dev = new UPSDevice();
$model = explode('FW:', $lines[1]);
if (strpos($model[0], 'InternalBattery') === false) {
$percCharge = explode(';', $lines[1]);
$dev->setName('UPS');
if ($model !== false) {
$dev->setModel(substr(trim($model[0]), 1));
}
if ($percCharge !== false) {
$dev->setBatterCharge(trim(substr($percCharge[0], -4, 3)));
$dev->setStatus(trim($percCharge[1]));
if (isset($percCharge[2])) {
$time = explode(':', $percCharge[2]);
$hours = $time[0];
$minutes = $hours*60+substr($time[1], 0, 2);
$dev->setTimeLeft($minutes);
}
}
$this->upsinfo->setUpsDevices($dev);
}
}
/**
* get the information
*
* @see PSI_Interface_UPS::build()
*
* @return Void
*/
public function build()
{
$this->_info();
}
}

View File

@@ -0,0 +1,115 @@
<?php
/**
* PowerSoftPlus class
*
* PHP version 5
*
* @category PHP
* @package PSI_UPS
* @author Mieczyslaw Nalewaj <namiltd@users.sourceforge.net>
* @copyright 2014 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @version SVN: $Id: class.powersoftplus.inc.php 661 2014-06-13 11:26:39Z namiltd $
* @link http://phpsysinfo.sourceforge.net
*/
/**
* getting ups information from powersoftplus program
*
* @category PHP
* @package PSI_UPS
* @author Mieczyslaw Nalewaj <namiltd@users.sourceforge.net>
* @copyright 2014 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @version Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
class PowerSoftPlus extends UPS
{
/**
* internal storage for all gathered data
*
* @var Array
*/
private $_output = array();
/**
* get all information from all configured ups in phpsysinfo.ini and store output in internal array
*/
public function __construct()
{
parent::__construct();
CommonFunctions::executeProgram('powersoftplus', '-p', $temp);
if (! empty($temp)) {
$this->_output[] = $temp;
}
}
/**
* parse the input and store data in resultset for xml generation
*
* @return Void
*/
private function _info()
{
foreach ($this->_output as $ups) {
$dev = new UPSDevice();
// General info
$dev->setName("EVER");
$dev->setMode("PowerSoftPlus");
$maxpwr = 0;
$load = null;
if (preg_match('/^Identifier: UPS Model\s*:\s*(.*)$/m', $ups, $data)) {
$dev->setModel(trim($data[1]));
if (preg_match('/\s(\d*)[^\d]*$/', trim($data[1]), $number)) {
$maxpwr=$number[1]*0.65;
}
}
if (preg_match('/^Current UPS state\s*:\s*(.*)$/m', $ups, $data)) {
$dev->setStatus(trim($data[1]));
}
if (preg_match('/^Output load\s*:\s*(.*)\s\[\%\]$/m', $ups, $data)) {
$load = trim($data[1]);
}
//wrong Output load issue
if (($load == 0) && ($maxpwr != 0) && preg_match('/^Effective power\s*:\s*(.*)\s\[W\]$/m', $ups, $data)) {
$load = 100.0*trim($data[1])/$maxpwr;
}
if ($load != null) {
$dev->setLoad($load);
}
// Battery
if (preg_match('/^Battery voltage\s*:\s*(.*)\s\[Volt\]$/m', $ups, $data)) {
$dev->setBatteryVoltage(trim($data[1]));
}
if (preg_match('/^Battery state\s*:\s*(.*)$/m', $ups, $data)) {
if (preg_match('/^At full capacity$/', trim($data[1]))) {
$dev->setBatterCharge(100);
} elseif (preg_match('/^(Discharged)|(Depleted)$/', trim($data[1]))) {
$dev->setBatterCharge(0);
}
}
// Line
if (preg_match('/^Input voltage\s*:\s*(.*)\s\[Volt\]$/m', $ups, $data)) {
$dev->setLineVoltage(trim($data[1]));
}
if (preg_match('/^Input frequency\s*:\s*(.*)\s\[Hz\]$/m', $ups, $data)) {
$dev->setLineFrequency(trim($data[1]));
}
$this->upsinfo->setUpsDevices($dev);
}
}
/**
* get the information
*
* @see PSI_Interface_UPS::build()
*
* @return Void
*/
public function build()
{
$this->_info();
}
}

View File

@@ -0,0 +1,64 @@
<?php
/**
* Basic UPS Class
*
* PHP version 5
*
* @category PHP
* @package PSI_UPS
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @version SVN: $Id: class.ups.inc.php 661 2012-08-27 11:26:39Z namiltd $
* @link http://phpsysinfo.sourceforge.net
*/
/**
* Basic UPS functions for all UPS classes
*
* @category PHP
* @package PSI_UPS
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @version Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
abstract class UPS implements PSI_Interface_UPS
{
/**
* object for error handling
*
* @var Error
*/
protected $error;
/**
* main object for ups information
*
* @var UPSInfo
*/
protected $upsinfo;
/**
* build the global Error object
*/
public function __construct()
{
$this->error = Error::singleton();
$this->upsinfo = new UPSInfo();
}
/**
* build and return the ups information
*
* @see PSI_Interface_UPS::getUPSInfo()
*
* @return UPSInfo
*/
final public function getUPSInfo()
{
$this->build();
return $this->upsinfo;
}
}

View File

@@ -0,0 +1,212 @@
<?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 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 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 _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));
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));
$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)
{
if ($this->_encoding != null) {
if (strcasecmp($this->_encoding, "UTF-8") == 0) {
return trim($str);
} elseif (strcasecmp($this->_encoding, "CP437") == 0) {
$str = trim($str);
$strr = "";
if (($strl = strlen($str)) > 0) for ($i = 0; $i < $strl; $i++) {
$strc = substr($str, $i, 1);
if ($strc < 128) $strr.=$strc;
else $strr.=$_CP437toUTF8Table[$strc-128];
}
return $strr;
} else {
$enclist = mb_list_encodings();
if (in_array($this->_encoding, $enclist)) {
return mb_convert_encoding(trim($str), 'UTF-8', $this->_encoding);
} elseif (function_exists("iconv")) {
return iconv($this->_encoding, 'UTF-8', trim($str));
} else {
return mb_convert_encoding(trim($str), 'UTF-8');
}
}
} else {
return mb_convert_encoding(trim($str), 'UTF-8');
}
}
/**
* Returns the SimpleXmlElement
*
* @return SimpleXmlElement entire xml as SimpleXmlElement
*/
public function getSimpleXmlElement()
{
return $this->_SimpleXmlElement;
}
}

View File

@@ -0,0 +1,742 @@
<?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 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 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 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 = "")
{
$this->_errors = 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();
$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);
}
/**
* 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()
{
$dev = new HWDevice();
$hardware = $this->_xml->addChild('Hardware');
if ($this->_sys->getMachine() != "") {
$hardware->addAttribute('Name', $this->_sys->getMachine());
}
$pci = null;
foreach (System::removeDupsAndCount($this->_sys->getPciDevices()) as $dev) {
if ($pci === null) $pci = $hardware->addChild('PCI');
$tmp = $pci->addChild('Device');
$tmp->addAttribute('Name', $dev->getName());
$tmp->addAttribute('Count', $dev->getCount());
}
$usb = null;
foreach (System::removeDupsAndCount($this->_sys->getUsbDevices()) as $dev) {
if ($usb === null) $usb = $hardware->addChild('USB');
$tmp = $usb->addChild('Device');
$tmp->addAttribute('Name', $dev->getName());
$tmp->addAttribute('Count', $dev->getCount());
}
$ide = null;
foreach (System::removeDupsAndCount($this->_sys->getIdeDevices()) as $dev) {
if ($ide === null) $ide = $hardware->addChild('IDE');
$tmp = $ide->addChild('Device');
$tmp->addAttribute('Name', $dev->getName());
$tmp->addAttribute('Count', $dev->getCount());
if ($dev->getCapacity() !== null) {
$tmp->addAttribute('Capacity', $dev->getCapacity());
}
}
$scsi = null;
foreach (System::removeDupsAndCount($this->_sys->getScsiDevices()) as $dev) {
if ($scsi === null) $scsi = $hardware->addChild('SCSI');
$tmp = $scsi->addChild('Device');
$tmp->addAttribute('Name', $dev->getName());
$tmp->addAttribute('Count', $dev->getCount());
if ($dev->getCapacity() !== null) {
$tmp->addAttribute('Capacity', $dev->getCapacity());
}
}
$tb = null;
foreach (System::removeDupsAndCount($this->_sys->getTbDevices()) as $dev) {
if ($tb === null) $tb = $hardware->addChild('TB');
$tmp = $tb->addChild('Device');
$tmp->addAttribute('Name', $dev->getName());
$tmp->addAttribute('Count', $dev->getCount());
}
$i2c = null;
foreach (System::removeDupsAndCount($this->_sys->getI2cDevices()) as $dev) {
if ($i2c === null) $i2c = $hardware->addChild('I2C');
$tmp = $i2c->addChild('Device');
$tmp->addAttribute('Name', $dev->getName());
$tmp->addAttribute('Count', $dev->getCount());
}
$cpu = null;
foreach ($this->_sys->getCpus() as $oneCpu) {
if ($cpu === null) $cpu = $hardware->addChild('CPU');
$tmp = $cpu->addChild('CpuCore');
$tmp->addAttribute('Model', $oneCpu->getModel());
if ($oneCpu->getCpuSpeed() !== 0) {
$tmp->addAttribute('CpuSpeed', $oneCpu->getCpuSpeed());
}
if ($oneCpu->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->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);
$mount->addAttribute('FSType', $dev->getFsType());
$mount->addAttribute('Name', $dev->getName());
$mount->addAttribute('Free', sprintf("%.0f", $dev->getFree()));
$mount->addAttribute('Used', sprintf("%.0f", $dev->getUsed()));
$mount->addAttribute('Total', sprintf("%.0f", $dev->getTotal()));
$mount->addAttribute('Percent', $dev->getPercentUsed());
if (PSI_SHOW_MOUNT_OPTION === true) {
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 = 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;
}
}
$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');
$this->_fillDevice($mount, $disk, $i++);
}
}
}
/**
* generate the motherboard information
*
* @return void
*/
private function _buildMbinfo()
{
$mbinfo = $this->_xml->addChild('MBInfo');
$temp = $fan = $volt = $power = $current = null;
if (sizeof(unserialize(PSI_MBINFO))>0) {
foreach (unserialize(PSI_MBINFO) as $mbinfoclass) {
$mbinfo_data = new $mbinfoclass();
$mbinfo_detail = $mbinfo_data->getMBInfo();
foreach ($mbinfo_detail->getMbTemp() as $dev) {
if ($temp == null) {
$temp = $mbinfo->addChild('Temperature');
}
$item = $temp->addChild('Item');
$item->addAttribute('Label', $dev->getName());
$item->addAttribute('Value', $dev->getValue());
if ($dev->getMax() !== null) {
$item->addAttribute('Max', $dev->getMax());
}
if (defined('PSI_SENSOR_EVENTS') && PSI_SENSOR_EVENTS && $dev->getEvent() !== "") {
$item->addAttribute('Event', $dev->getEvent());
}
}
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());
}
}
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());
}
}
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());
}
}
foreach ($mbinfo_detail->getMbCurrent() as $dev) {
if ($current == null) {
$current = $mbinfo->addChild('Current');
}
$item = $current->addChild('Item');
$item->addAttribute('Label', $dev->getName());
$item->addAttribute('Value', $dev->getValue());
if ($dev->getMax() !== null) {
$item->addAttribute('Max', $dev->getMax());
}
if (defined('PSI_SENSOR_EVENTS') && PSI_SENSOR_EVENTS && $dev->getEvent() !== "") {
$item->addAttribute('Event', $dev->getEvent());
}
}
}
}
if (PSI_HDDTEMP) {
$hddtemp = new HDDTemp();
$hddtemp_data = $hddtemp->getMBInfo();
foreach ($hddtemp_data->getMbTemp() as $dev) {
if ($temp == null) {
$temp = $mbinfo->addChild('Temperature');
}
$item = $temp->addChild('Item');
$item->addAttribute('Label', $dev->getName());
$item->addAttribute('Value', $dev->getValue());
if ($dev->getMax() !== null) {
$item->addAttribute('Max', $dev->getMax());
}
}
}
}
/**
* 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());
}
$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) {
// 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();
}
$this->_buildVitals();
$this->_buildNetwork();
$this->_buildHardware();
$this->_buildMemory();
$this->_buildFilesystems();
$this->_buildMbinfo();
$this->_buildUpsinfo();
}
$this->_buildPlugins();
$this->_xml->combinexml($this->_errors->errorsAddToXML($this->_sysinfo->getEncoding()));
}
/**
* get the xml object
*
* @return string
*/
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');
if (defined('PSI_REFRESH')) {
if (PSI_REFRESH === false) {
$options->addAttribute('refresh', 0);
} elseif (PSI_REFRESH === true) {
$options->addAttribute('refresh', 1);
} else {
$options->addAttribute('refresh', PSI_REFRESH);
}
} else {
$options->addAttribute('refresh', 60000);
}
if (defined('PSI_FS_USAGE_THRESHOLD')) {
if (PSI_FS_USAGE_THRESHOLD === true) {
$options->addAttribute('threshold', 1);
} elseif ((PSI_FS_USAGE_THRESHOLD !== false) && (PSI_FS_USAGE_THRESHOLD >= 1) && (PSI_FS_USAGE_THRESHOLD <= 99)) {
$options->addAttribute('threshold', PSI_FS_USAGE_THRESHOLD);
}
} else {
$options->addAttribute('threshold', 90);
}
$options->addAttribute('showPickListTemplate', defined('PSI_SHOW_PICKLIST_TEMPLATE') ? (PSI_SHOW_PICKLIST_TEMPLATE ? 'true' : 'false') : 'false');
$options->addAttribute('showPickListLang', defined('PSI_SHOW_PICKLIST_LANG') ? (PSI_SHOW_PICKLIST_LANG ? 'true' : 'false') : 'false');
$options->addAttribute('showCPUListExpanded', defined('PSI_SHOW_CPULIST_EXPANDED') ? (PSI_SHOW_CPULIST_EXPANDED ? 'true' : 'false') : 'true');
$options->addAttribute('showCPUInfoExpanded', defined('PSI_SHOW_CPUINFO_EXPANDED') ? (PSI_SHOW_CPUINFO_EXPANDED ? 'true' : 'false') : 'false');
if (count($this->_plugins) > 0) {
if ($this->_plugin_request) {
$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);
}
}
}
}
}