Subversion Repositories ALCASAR

Compare Revisions

Ignore whitespace Rev 2769 → Rev 2770

/web/acc/phpsysinfo/includes/os/class.Linux.inc.php.default
File deleted
/web/acc/phpsysinfo/includes/os/class.HP-UX.inc.php
File deleted
/web/acc/phpsysinfo/includes/os/class.BSD.common.inc.php
File deleted
/web/acc/phpsysinfo/includes/os/class.parseProgs.inc.php
File deleted
/web/acc/phpsysinfo/includes/os/class.AIX.inc.php
0,0 → 1,362
<?php
/**
* IBM AIX System Class
*
* PHP version 5
*
* @category PHP
* @package PSI AIX OS class
* @author Krzysztof Paz (kpaz@gazeta.pl) based on HPUX of Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2011 Krzysztof Paz
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License version 2, or (at your option) any later version
* @version SVN: $Id: class.AIX.inc.php 287 2009-06-26 12:11:59Z Krzysztof Paz, IBM POLSKA
* @link http://phpsysinfo.sourceforge.net
*/
/**
* IBM AIX sysinfo class
* get all the required information from IBM AIX system
*
* @category PHP
* @package PSI AIX OS class
* @author Krzysztof Paz (kpaz@gazeta.pl) based on Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2011 Krzysztof Paz
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License version 2, or (at your option) any later version
* @version Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
class AIX extends OS
{
 
private $_aixdata = array();
 
/**
* Virtual Host Name
* @return void
*/
private function _hostname()
{
/* if (PSI_USE_VHOST === true) {
if (CommonFunctions::readenv('SERVER_NAME', $hnm)) $this->sys->setHostname($hnm);
} else {
if (CommonFunctions::executeProgram('hostname', '', $ret)) {
$this->sys->setHostname($ret);
}
} */
if (CommonFunctions::readenv('SERVER_NAME', $hnm)) $this->sys->setHostname($hnm);
 
}
 
/**
* IBM AIX Version
* @return void
*/
private function _kernel()
{
if (CommonFunctions::executeProgram('oslevel', '', $ret1) && CommonFunctions::executeProgram('oslevel', '-s', $ret2)) {
$this->sys->setKernel($ret1 . ' (' . $ret2 . ')');
}
}
 
/**
* UpTime
* time the system is running
* @return void
*/
private function _uptime()
{
if (CommonFunctions::executeProgram('uptime', '', $buf)) {
if (preg_match("/up (\d+) day[s]?,\s*(\d+):(\d+),/", $buf, $ar_buf)) {
$min = $ar_buf[3];
$hours = $ar_buf[2];
$days = $ar_buf[1];
$this->sys->setUptime($days * 86400 + $hours * 3600 + $min * 60);
}
}
}
 
/**
* Processor Load
* optionally create a loadbar
* @return void
*/
private function _loadavg()
{
if (CommonFunctions::executeProgram('uptime', '', $buf)) {
if (preg_match("/average: (.*), (.*), (.*)$/", $buf, $ar_buf)) {
$this->sys->setLoad($ar_buf[1].' '.$ar_buf[2].' '.$ar_buf[3]);
}
}
}
 
/**
* CPU information
* All of the tags here are highly architecture dependant
* @return void
*/
private function _cpuinfo()
{
$ncpu = 0;
$tcpu = "";
$vcpu = "";
$ccpu = "";
$scpu = "";
foreach ($this->readaixdata() as $line) {
if (preg_match("/^Number Of Processors:\s+(\d+)/", $line, $ar_buf)) {
$ncpu = $ar_buf[1];
}
if (preg_match("/^Processor Type:\s+(.+)/", $line, $ar_buf)) {
$tcpu = $ar_buf[1];
}
if (preg_match("/^Processor Version:\s+(.+)/", $line, $ar_buf)) {
$vcpu = $ar_buf[1];
}
if (preg_match("/^CPU Type:\s+(.+)/", $line, $ar_buf)) {
$ccpu = $ar_buf[1];
}
if (preg_match("/^Processor Clock Speed:\s+(\d+)\s/", $line, $ar_buf)) {
$scpu = $ar_buf[1];
}
}
for ($i = 0; $i < $ncpu; $i++) {
$dev = new CpuDevice();
if (trim($tcpu) != "") {
$cpu = trim($tcpu);
if (trim($vcpu) != "") $cpu .= " ".trim($vcpu);
if (trim($ccpu) != "") $cpu .= " ".trim($ccpu);
$dev->setModel($cpu);
}
if (trim($scpu) != "") {
$dev->setCpuSpeed(trim($scpu));
}
$this->sys->setCpus($dev);
}
}
 
/**
* PCI devices
* @return void
*/
private function _pci()
{
foreach ($this->readaixdata() as $line) {
if (preg_match("/^[\*\+]\s\S+\s+\S+\s+(.*PCI.*)/", $line, $ar_buf)) {
$dev = new HWDevice();
$dev->setName(trim($ar_buf[1]));
$this->sys->setPciDevices($dev);
}
}
}
 
/**
* IDE devices
* @return void
*/
private function _ide()
{
foreach ($this->readaixdata() as $line) {
if (preg_match("/^[\*\+]\s\S+\s+\S+\s+(.*IDE.*)/", $line, $ar_buf)) {
$dev = new HWDevice();
$dev->setName(trim($ar_buf[1]));
$this->sys->setIdeDevices($dev);
}
}
}
 
/**
* SCSI devices
* @return void
*/
private function _scsi()
{
foreach ($this->readaixdata() as $line) {
if (preg_match("/^[\*\+]\s\S+\s+\S+\s+(.*SCSI.*)/", $line, $ar_buf)) {
$dev = new HWDevice();
$dev->setName(trim($ar_buf[1]));
$this->sys->setScsiDevices($dev);
}
}
}
 
/**
* USB devices
* @return void
*/
private function _usb()
{
foreach ($this->readaixdata() as $line) {
if (preg_match("/^[\*\+]\s\S+\s+\S+\s+(.*USB.*)/", $line, $ar_buf)) {
$dev = new HWDevice();
$dev->setName(trim($ar_buf[1]));
$this->sys->setUsbDevices($dev);
}
}
}
 
/**
* Network devices
* includes also rx/tx bytes
* @return void
*/
private function _network()
{
if (CommonFunctions::executeProgram('netstat', '-ni | tail -n +2', $netstat)) {
$lines = preg_split("/\n/", $netstat, -1, PREG_SPLIT_NO_EMPTY);
foreach ($lines as $line) {
$ar_buf = preg_split("/\s+/", $line);
if (! empty($ar_buf[0]) && ! empty($ar_buf[3])) {
$dev = new NetDevice();
$dev->setName($ar_buf[0]);
$dev->setRxBytes($ar_buf[4]);
$dev->setTxBytes($ar_buf[6]);
$dev->setErrors($ar_buf[5] + $ar_buf[7]);
//$dev->setDrops($ar_buf[8]);
$this->sys->setNetDevices($dev);
}
}
}
}
 
/**
* Physical memory information and Swap Space information
* @return void
*/
private function _memory()
{
$mems = "";
$tswap = "";
$pswap = "";
foreach ($this->readaixdata() as $line) {
if (preg_match("/^Good Memory Size:\s+(\d+)\s+MB/", $line, $ar_buf)) {
$mems = $ar_buf[1];
}
if (preg_match("/^\s*Total Paging Space:\s+(\d+)MB/", $line, $ar_buf)) {
$tswap = $ar_buf[1];
}
if (preg_match("/^\s*Percent Used:\s+(\d+)%/", $line, $ar_buf)) {
$pswap = $ar_buf[1];
}
}
if (trim($mems) != "") {
$mems = $mems*1024*1024;
$this->sys->setMemTotal($mems);
$memu = 0;
$memf = 0;
if (CommonFunctions::executeProgram('svmon', '-G', $buf)) {
if (preg_match("/^memory\s+\d+\s+(\d+)\s+/", $buf, $ar_buf)) {
$memu = $ar_buf[1]*1024*4;
$memf = $mems - $memu;
}
}
$this->sys->setMemUsed($memu);
$this->sys->setMemFree($memf);
// $this->sys->setMemApplication($mems);
// $this->sys->setMemBuffer($mems);
// $this->sys->setMemCache($mems);
}
if (trim($tswap) != "") {
$dev = new DiskDevice();
$dev->setName("SWAP");
$dev->setFsType('swap');
$dev->setTotal($tswap * 1024 * 1024);
if (trim($pswap) != "") {
$dev->setUsed($dev->getTotal() * $pswap / 100);
}
$dev->setFree($dev->getTotal() - $dev->getUsed());
$this->sys->setSwapDevices($dev);
}
}
 
/**
* filesystem information
*
* @return void
*/
private function _filesystems()
{
if (CommonFunctions::executeProgram('df', '-kP', $df, PSI_DEBUG)) {
$mounts = preg_split("/\n/", $df, -1, PREG_SPLIT_NO_EMPTY);
if (CommonFunctions::executeProgram('mount', '-v', $s, PSI_DEBUG)) {
$lines = preg_split("/\n/", $s, -1, PREG_SPLIT_NO_EMPTY);
foreach ($lines as $line) {
$a = preg_split('/ /', $line, -1, PREG_SPLIT_NO_EMPTY);
$fsdev[$a[0]] = $a[4];
}
}
foreach ($mounts as $mount) {
$ar_buf = preg_split("/\s+/", $mount, 6);
$dev = new DiskDevice();
$dev->setName($ar_buf[0]);
$dev->setTotal($ar_buf[1] * 1024);
$dev->setUsed($ar_buf[2] * 1024);
$dev->setFree($ar_buf[3] * 1024);
$dev->setMountPoint($ar_buf[5]);
if (isset($fsdev[$ar_buf[0]])) {
$dev->setFsType($fsdev[$ar_buf[0]]);
}
$this->sys->setDiskDevices($dev);
}
}
}
 
/**
* Distribution
*
* @return void
*/
private function _distro()
{
$this->sys->setDistribution('IBM AIX');
$this->sys->setDistributionIcon('AIX.png');
}
 
/**
* IBM AIX informations by K.PAZ
* @return array
*/
private function readaixdata()
{
if (count($this->_aixdata) === 0) {
if (CommonFunctions::executeProgram('prtconf', '', $bufr)) {
$this->_aixdata = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
}
}
 
return $this->_aixdata;
}
 
/**
* get the information
*
* @see PSI_Interface_OS::build()
*
* @return Void
*/
public function build()
{
$this->error->addError("WARN", "The AIX version of phpSysInfo is a work in progress, some things currently don't work");
if (!$this->blockname || $this->blockname==='vitals') {
$this->_distro();
$this->_hostname();
$this->_kernel();
$this->_uptime();
$this->_users();
$this->_loadavg();
}
if (!$this->blockname || $this->blockname==='hardware') {
$this->_cpuinfo();
$this->_pci();
$this->_ide();
$this->_scsi();
$this->_usb();
}
if (!$this->blockname || $this->blockname==='network') {
$this->_network();
}
if (!$this->blockname || $this->blockname==='memory') {
$this->_memory();
}
if (!$this->blockname || $this->blockname==='filesystem') {
$this->_filesystems();
}
}
}
/web/acc/phpsysinfo/includes/os/class.Android.inc.php
0,0 → 1,274
<?php
/**
* Android System Class
*
* PHP version 5
*
* @category PHP
* @package PSI Android OS class
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License version 2, or (at your option) any later version
* @version SVN: $Id: class.Linux.inc.php 712 2012-12-05 14:09:18Z namiltd $
* @link http://phpsysinfo.sourceforge.net
*/
/**
* Android sysinfo class
* get all the required information from Android system
*
* @category PHP
* @package PSI Android OS class
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License version 2, or (at your option) any later version
* @version Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
class Android extends Linux
{
/**
* holds the data from /system/build.prop file
*
* @var string
*/
private $_buildprop = null;
 
/**
* reads the data from /system/build.prop file
*
* @return string
*/
private function _get_buildprop()
{
if ($this->_buildprop === null) {
if (!CommonFunctions::rfts('/system/build.prop', $this->_buildprop, 0, 4096, false)) {
CommonFunctions::rfts('/system//build.prop', $this->_buildprop, 0, 4096, false); //fix some access issues
}
}
 
return $this->_buildprop;
}
 
/**
* Kernel Version
*
* @return void
*/
private function _kernel()
{
if (CommonFunctions::executeProgram('uname', '-r', $strBuf, false)) {
$result = $strBuf;
if (CommonFunctions::executeProgram('uname', '-v', $strBuf, PSI_DEBUG)) {
if (preg_match('/SMP/', $strBuf)) {
$result .= ' (SMP)';
}
}
if (CommonFunctions::executeProgram('uname', '-m', $strBuf, PSI_DEBUG)) {
$result .= ' '.$strBuf;
}
$this->sys->setKernel($result);
} elseif (CommonFunctions::rfts('/proc/version', $strBuf, 1) && preg_match('/version\s+(\S+)/', $strBuf, $ar_buf)) {
$result = $ar_buf[1];
if (preg_match('/SMP/', $strBuf)) {
$result .= ' (SMP)';
}
$this->sys->setKernel($result);
}
}
 
/**
* Number of Users
*
* @return void
*/
protected function _users()
{
$this->sys->setUsers(1);
}
 
/**
* filesystem information
*
* @return void
*/
private function _filesystems()
{
$notwas = true;
if (CommonFunctions::executeProgram('df', '2>/dev/null ', $df, PSI_DEBUG) && preg_match("/\s+[0-9\.]+[KMGT]\s+/", $df)) {
$df = preg_split("/\n/", $df, -1, PREG_SPLIT_NO_EMPTY);
if (CommonFunctions::executeProgram('mount', '', $mount, PSI_DEBUG)) {
$mount = preg_split("/\n/", $mount, -1, PREG_SPLIT_NO_EMPTY);
foreach ($mount as $mount_line) {
$mount_buf = preg_split('/\s+/', $mount_line);
if (count($mount_buf) == 6) {
$mount_parm[$mount_buf[1]]['fstype'] = $mount_buf[2];
if (PSI_SHOW_MOUNT_OPTION) $mount_parm[$mount_buf[1]]['options'] = $mount_buf[3];
$mount_parm[$mount_buf[1]]['mountdev'] = $mount_buf[0];
}
}
foreach ($df as $df_line) {
if ((preg_match("/^(\/\S+)(\s+)(([0-9\.]+)([KMGT])(\s+)([0-9\.]+)([KMGT])(\s+)([0-9\.]+)([KMGT])(\s+))/", $df_line, $df_buf)
|| preg_match("/^(\/[^\s\:]+)\:(\s+)(([0-9\.]+)([KMGT])(\s+total\,\s+)([0-9\.]+)([KMGT])(\s+used\,\s+)([0-9\.]+)([KMGT])(\s+available))/", $df_line, $df_buf))
&& !preg_match('/^\/mnt\/asec\/com\./', $df_buf[1])) {
$dev = new DiskDevice();
if (PSI_SHOW_MOUNT_POINT) $dev->setMountPoint($df_buf[1]);
 
if ($df_buf[5] == 'K') $dev->setTotal($df_buf[4] * 1024);
elseif ($df_buf[5] == 'M') $dev->setTotal($df_buf[4] * 1024*1024);
elseif ($df_buf[5] == 'G') $dev->setTotal($df_buf[4] * 1024*1024*1024);
elseif ($df_buf[5] == 'T') $dev->setTotal($df_buf[4] * 1024*1024*1024*1024);
 
if ($df_buf[8] == 'K') $dev->setUsed($df_buf[7] * 1024);
elseif ($df_buf[8] == 'M') $dev->setUsed($df_buf[7] * 1024*1024);
elseif ($df_buf[8] == 'G') $dev->setUsed($df_buf[7] * 1024*1024*1024);
elseif ($df_buf[8] == 'T') $dev->setUsed($df_buf[7] * 1024*1024*1024*1024);
 
if ($df_buf[11] == 'K') $dev->setFree($df_buf[10] * 1024);
elseif ($df_buf[11] == 'M') $dev->setFree($df_buf[10] * 1024*1024);
elseif ($df_buf[11] == 'G') $dev->setFree($df_buf[10] * 1024*1024*1024);
elseif ($df_buf[11] == 'T') $dev->setFree($df_buf[10] * 1024*1024*1024*1024);
 
if (isset($mount_parm[$df_buf[1]])) {
$dev->setFsType($mount_parm[$df_buf[1]]['fstype']);
$dev->setName($mount_parm[$df_buf[1]]['mountdev']);
 
if (PSI_SHOW_MOUNT_OPTION) {
if (PSI_SHOW_MOUNT_CREDENTIALS) {
$dev->setOptions($mount_parm[$df_buf[1]]['options']);
} else {
$mpo=$mount_parm[$df_buf[1]]['options'];
 
$mpo=preg_replace('/(^guest,)|(^guest$)|(,guest$)/i', '', $mpo);
$mpo=preg_replace('/,guest,/i', ',', $mpo);
 
$mpo=preg_replace('/(^user=[^,]*,)|(^user=[^,]*$)|(,user=[^,]*$)/i', '', $mpo);
$mpo=preg_replace('/,user=[^,]*,/i', ',', $mpo);
 
$mpo=preg_replace('/(^username=[^,]*,)|(^username=[^,]*$)|(,username=[^,]*$)/i', '', $mpo);
$mpo=preg_replace('/,username=[^,]*,/i', ',', $mpo);
 
$mpo=preg_replace('/(^password=[^,]*,)|(^password=[^,]*$)|(,password=[^,]*$)/i', '', $mpo);
$mpo=preg_replace('/,password=[^,]*,/i', ',', $mpo);
 
$dev->setOptions($mpo);
}
}
}
$this->sys->setDiskDevices($dev);
$notwas = false;
}
}
}
}
if ($notwas) { // try Linux df style
$arrResult = Parser::df("-P 2>/dev/null", false);
foreach ($arrResult as $dev) {
$this->sys->setDiskDevices($dev);
}
}
}
 
/**
* Distribution
*
* @return void
*/
protected function _distro()
{
$buf = "";
if (($lines = $this->_get_buildprop()) && preg_match('/^ro\.build\.version\.release=([^\n]+)/m', $lines, $ar_buf)) {
$buf = trim($ar_buf[1]);
}
if (is_null($buf) || ($buf == "")) {
$this->sys->setDistribution('Android');
} else {
if (preg_match('/^(\d+\.\d+)/', $buf, $ver)
&& ($list = @parse_ini_file(PSI_APP_ROOT."/data/osnames.ini", true))
&& isset($list['Android'][$ver[1]])) {
$buf.=' '.$list['Android'][$ver[1]];
}
$this->sys->setDistribution('Android '.$buf);
}
$this->sys->setDistributionIcon('Android.png');
}
 
/**
* Machine
*
* @return void
*/
private function _machine()
{
if ($lines = $this->_get_buildprop()) {
$buf = "";
if (preg_match('/^ro\.product\.manufacturer=([^\n]+)/m', $lines, $ar_buf) && (trim($ar_buf[1]) !== "unknown")) {
$buf .= ' '.trim($ar_buf[1]);
}
if (preg_match('/^ro\.product\.model=([^\n]+)/m', $lines, $ar_buf) && (trim($ar_buf[1]) !== trim($buf))) {
$buf .= ' '.trim($ar_buf[1]);
}
if (preg_match('/^ro\.semc\.product\.name=([^\n]+)/m', $lines, $ar_buf)) {
$buf .= ' '.trim($ar_buf[1]);
}
if (trim($buf) != "") {
$this->sys->setMachine(trim($buf));
}
}
}
 
/**
* PCI devices
*
* @return void
*/
private function _pci()
{
if (CommonFunctions::executeProgram('lspci', '', $bufr, false)) {
$bufe = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
foreach ($bufe as $buf) {
$device = preg_split("/ /", $buf, 4);
if (isset($device[3]) && trim($device[3]) != "") {
$dev = new HWDevice();
$dev->setName('Class '.trim($device[2]).' Device '.trim($device[3]));
$this->sys->setPciDevices($dev);
}
}
}
}
 
/**
* get the information
*
* @see PSI_Interface_OS::build()
*
* @return Void
*/
public function build()
{
if (!$this->blockname || $this->blockname==='vitals') {
$this->_distro();
$this->_hostname();
$this->_kernel();
$this->_uptime();
$this->_users();
$this->_loadavg();
$this->_processes();
}
if (!$this->blockname || $this->blockname==='hardware') {
$this->_machine();
$this->_cpuinfo();
$this->_pci();
$this->_usb();
$this->_i2c();
}
if (!$this->blockname || $this->blockname==='network') {
$this->_network();
}
if (!$this->blockname || $this->blockname==='memory') {
$this->_memory();
}
if (!$this->blockname || $this->blockname==='filesystem') {
$this->_filesystems();
}
}
}
/web/acc/phpsysinfo/includes/os/class.BSDCommon.inc.php
0,0 → 1,661
<?php
/**
* BSDCommon Class
*
* PHP version 5
*
* @category PHP
* @package PSI BSDCommon OS class
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License version 2, or (at your option) any later version
* @version SVN: $Id: class.BSDCommon.inc.php 621 2012-07-29 18:49:04Z namiltd $
* @link http://phpsysinfo.sourceforge.net
*/
/**
* BSDCommon class
* get all the required information for BSD Like systems
* no need to implement in every class the same methods
*
* @category PHP
* @package PSI BSDCommon OS class
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License version 2, or (at your option) any later version
* @version Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
abstract class BSDCommon extends OS
{
/**
* content of the syslog
*
* @var array
*/
private $_dmesg = null;
 
/**
* regexp1 for cpu information out of the syslog
*
* @var string
*/
private $_CPURegExp1 = "//";
 
/**
* regexp2 for cpu information out of the syslog
*
* @var string
*/
private $_CPURegExp2 = "//";
 
/**
* regexp1 for scsi information out of the syslog
*
* @var string
*/
private $_SCSIRegExp1 = "//";
 
/**
* regexp2 for scsi information out of the syslog
*
* @var string
*/
private $_SCSIRegExp2 = "//";
 
/**
* regexp3 for scsi information out of the syslog
*
* @var string
*/
private $_SCSIRegExp3 = "//";
 
/**
* regexp1 for pci information out of the syslog
*
* @var string
*/
private $_PCIRegExp1 = "//";
 
/**
* regexp1 for pci information out of the syslog
*
* @var string
*/
private $_PCIRegExp2 = "//";
 
/**
* setter for cpuregexp1
*
* @param string $value value to set
*
* @return void
*/
protected function setCPURegExp1($value)
{
$this->_CPURegExp1 = $value;
}
 
/**
* setter for cpuregexp2
*
* @param string $value value to set
*
* @return void
*/
protected function setCPURegExp2($value)
{
$this->_CPURegExp2 = $value;
}
 
/**
* setter for scsiregexp1
*
* @param string $value value to set
*
* @return void
*/
protected function setSCSIRegExp1($value)
{
$this->_SCSIRegExp1 = $value;
}
 
/**
* setter for scsiregexp2
*
* @param string $value value to set
*
* @return void
*/
protected function setSCSIRegExp2($value)
{
$this->_SCSIRegExp2 = $value;
}
 
/**
* setter for scsiregexp3
*
* @param string $value value to set
*
* @return void
*/
protected function setSCSIRegExp3($value)
{
$this->_SCSIRegExp3 = $value;
}
 
/**
* setter for pciregexp1
*
* @param string $value value to set
*
* @return void
*/
protected function setPCIRegExp1($value)
{
$this->_PCIRegExp1 = $value;
}
 
/**
* setter for pciregexp2
*
* @param string $value value to set
*
* @return void
*/
protected function setPCIRegExp2($value)
{
$this->_PCIRegExp2 = $value;
}
 
/**
* read /var/run/dmesg.boot, but only if we haven't already
*
* @return array
*/
protected function readdmesg()
{
if ($this->_dmesg === null) {
if ((PSI_OS != "Darwin") && (CommonFunctions::rfts('/var/run/dmesg.boot', $buf, 0, 4096, false) || CommonFunctions::rfts('/var/log/dmesg.boot', $buf, 0, 4096, false) || CommonFunctions::rfts('/var/run/dmesg.boot', $buf))) { // Once again but with debug
$parts = preg_split("/rebooting|Uptime/", $buf, -1, PREG_SPLIT_NO_EMPTY);
$this->_dmesg = preg_split("/\n/", $parts[count($parts) - 1], -1, PREG_SPLIT_NO_EMPTY);
} else {
$this->_dmesg = array();
}
}
 
return $this->_dmesg;
}
 
/**
* get a value from sysctl command
*
* @param string $key key for the value to get
*
* @return string
*/
protected function grabkey($key)
{
$buf = "";
if (CommonFunctions::executeProgram('sysctl', "-n $key", $buf, PSI_DEBUG)) {
return $buf;
} else {
return '';
}
}
 
/**
* Virtual Host Name
*
* @return void
*/
protected function hostname()
{
if (PSI_USE_VHOST === true) {
if (CommonFunctions::readenv('SERVER_NAME', $hnm)) $this->sys->setHostname($hnm);
} else {
if (CommonFunctions::executeProgram('hostname', '', $buf, PSI_DEBUG)) {
$this->sys->setHostname($buf);
}
}
}
 
/**
* Kernel Version
*
* @return void
*/
protected function kernel()
{
$s = $this->grabkey('kern.version');
$a = preg_split('/:/', $s);
if (isset($a[2])) {
$this->sys->setKernel($a[0].$a[1].':'.$a[2]);
} else {
$this->sys->setKernel($s);
}
}
 
/**
* Processor Load
* optionally create a loadbar
*
* @return void
*/
protected function loadavg()
{
$s = $this->grabkey('vm.loadavg');
$s = preg_replace('/{ /', '', $s);
$s = preg_replace('/ }/', '', $s);
$this->sys->setLoad($s);
if (PSI_LOAD_BAR && (PSI_OS != "Darwin")) {
if ($fd = $this->grabkey('kern.cp_time')) {
// Find out the CPU load
// user + sys = load
// total = total
preg_match($this->_CPURegExp2, $fd, $res);
$load = $res[2] + $res[3] + $res[4]; // cpu.user + cpu.sys
$total = $res[2] + $res[3] + $res[4] + $res[5]; // cpu.total
// we need a second value, wait 1 second befor getting (< 1 second no good value will occour)
sleep(1);
$fd = $this->grabkey('kern.cp_time');
preg_match($this->_CPURegExp2, $fd, $res);
$load2 = $res[2] + $res[3] + $res[4];
$total2 = $res[2] + $res[3] + $res[4] + $res[5];
$this->sys->setLoadPercent((100 * ($load2 - $load)) / ($total2 - $total));
}
}
}
 
/**
* CPU information
*
* @return void
*/
protected function cpuinfo()
{
$dev = new CpuDevice();
 
if (PSI_OS == "NetBSD") {
if ($model = $this->grabkey('machdep.cpu_brand')) {
$dev->setModel($model);
}
if ($cpuspeed = $this->grabkey('machdep.tsc_freq')) {
$dev->setCpuSpeed(round($cpuspeed / 1000000));
}
}
 
if ($dev->getModel() === "") {
$dev->setModel($this->grabkey('hw.model'));
}
$notwas = true;
foreach ($this->readdmesg() as $line) {
if ($notwas) {
if (preg_match($this->_CPURegExp1, $line, $ar_buf)) {
if ($dev->getCpuSpeed() === 0) {
$dev->setCpuSpeed(round($ar_buf[2]));
}
$notwas = false;
}
} else {
if (preg_match("/ Origin| Features/", $line, $ar_buf)) {
if (preg_match("/ Features2[ ]*=.*<(.*)>/", $line, $ar_buf)) {
$feats = preg_split("/,/", strtolower(trim($ar_buf[1])), -1, PREG_SPLIT_NO_EMPTY);
foreach ($feats as $feat) {
if (($feat=="vmx") || ($feat=="svm")) {
$dev->setVirt($feat);
break 2;
}
}
break;
}
} else break;
}
}
 
$ncpu = $this->grabkey('hw.ncpu');
if (is_null($ncpu) || (trim($ncpu) == "") || (!($ncpu >= 1)))
$ncpu = 1;
for ($ncpu ; $ncpu > 0 ; $ncpu--) {
$this->sys->setCpus($dev);
}
}
 
/**
* SCSI devices
* get the scsi device information out of dmesg
*
* @return void
*/
protected function scsi()
{
foreach ($this->readdmesg() as $line) {
if (preg_match($this->_SCSIRegExp1, $line, $ar_buf)) {
$dev = new HWDevice();
$dev->setName($ar_buf[1].": ".trim($ar_buf[2]));
$this->sys->setScsiDevices($dev);
} elseif (preg_match($this->_SCSIRegExp2, $line, $ar_buf)) {
/* duplication security */
$notwas = true;
foreach ($this->sys->getScsiDevices() as $finddev) {
if ($notwas && (substr($finddev->getName(), 0, strpos($finddev->getName(), ': ')) == $ar_buf[1])) {
if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS) {
if (isset($ar_buf[3]) && ($ar_buf[3]==="G")) {
$finddev->setCapacity($ar_buf[2] * 1024 * 1024 * 1024);
} else {
$finddev->setCapacity($ar_buf[2] * 1024 * 1024);
}
}
$notwas = false;
break;
}
}
if ($notwas) {
$dev = new HWDevice();
$dev->setName($ar_buf[1]);
if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS) {
if (isset($ar_buf[3]) && ($ar_buf[3]==="G")) {
$dev->setCapacity($ar_buf[2] * 1024 * 1024 * 1024);
} else {
$dev->setCapacity($ar_buf[2] * 1024 * 1024);
}
}
$this->sys->setScsiDevices($dev);
}
} elseif (preg_match($this->_SCSIRegExp3, $line, $ar_buf)) {
/* duplication security */
$notwas = true;
foreach ($this->sys->getScsiDevices() as $finddev) {
if ($notwas && (substr($finddev->getName(), 0, strpos($finddev->getName(), ': ')) == $ar_buf[1])) {
if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS
&& defined('PSI_SHOW_DEVICES_SERIAL') && PSI_SHOW_DEVICES_SERIAL) {
$finddev->setSerial(trim($ar_buf[2]));
}
$notwas = false;
break;
}
}
if ($notwas) {
$dev = new HWDevice();
$dev->setName($ar_buf[1]);
if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS
&& defined('PSI_SHOW_DEVICES_SERIAL') && PSI_SHOW_DEVICES_SERIAL) {
$dev->setSerial(trim($ar_buf[2]));
}
$this->sys->setScsiDevices($dev);
}
}
}
/* cleaning */
foreach ($this->sys->getScsiDevices() as $finddev) {
if (strpos($finddev->getName(), ': ') !== false)
$finddev->setName(substr(strstr($finddev->getName(), ': '), 2));
}
}
 
/**
* parsing the output of pciconf command
*
* @return Array
*/
protected function pciconf()
{
$arrResults = array();
$intS = 0;
if (CommonFunctions::executeProgram("pciconf", "-lv", $strBuf, PSI_DEBUG)) {
$arrTemp = array();
$arrBlocks = preg_split("/\n\S/", $strBuf, -1, PREG_SPLIT_NO_EMPTY);
foreach ($arrBlocks as $strBlock) {
$arrLines = preg_split("/\n/", $strBlock, -1, PREG_SPLIT_NO_EMPTY);
$vend = null;
foreach ($arrLines as $strLine) {
if (preg_match("/\sclass=0x([a-fA-F0-9]{4})[a-fA-F0-9]{2}\s.*\schip=0x([a-fA-F0-9]{4})([a-fA-F0-9]{4})\s/", $strLine, $arrParts)) {
$arrTemp[$intS] = 'Class '.$arrParts[1].': Device '.$arrParts[3].':'.$arrParts[2];
$vend = '';
} elseif (preg_match("/(.*) = '(.*)'/", $strLine, $arrParts)) {
if (trim($arrParts[1]) == "vendor") {
$vend = trim($arrParts[2]);
} elseif (trim($arrParts[1]) == "device") {
if (($vend !== null) && ($vend !== '')) {
$arrTemp[$intS] = $vend." - ".trim($arrParts[2]);
} else {
$arrTemp[$intS] = trim($arrParts[2]);
$vend = '';
}
}
}
}
if ($vend !== null) {
$intS++;
}
}
foreach ($arrTemp as $name) {
$dev = new HWDevice();
$dev->setName($name);
$arrResults[] = $dev;
}
}
 
return $arrResults;
}
 
/**
* PCI devices
* get the pci device information out of dmesg
*
* @return void
*/
protected function pci()
{
if ((!$results = Parser::lspci(false)) && (!$results = $this->pciconf())) {
foreach ($this->readdmesg() as $line) {
if (preg_match($this->_PCIRegExp1, $line, $ar_buf)) {
$dev = new HWDevice();
$dev->setName($ar_buf[1].": ".$ar_buf[2]);
$results[] = $dev;
} elseif (preg_match($this->_PCIRegExp2, $line, $ar_buf)) {
$dev = new HWDevice();
$dev->setName($ar_buf[1].": ".$ar_buf[2]);
$results[] = $dev;
}
}
}
foreach ($results as $dev) {
$this->sys->setPciDevices($dev);
}
}
 
/**
* IDE devices
* get the ide device information out of dmesg
*
* @return void
*/
protected function ide()
{
foreach ($this->readdmesg() as $line) {
if (preg_match('/^(ad[0-9]+): (.*)MB <(.*)> (.*) (.*)/', $line, $ar_buf)) {
$dev = new HWDevice();
$dev->setName($ar_buf[1].": ".trim($ar_buf[3]));
if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS) {
$dev->setCapacity($ar_buf[2] * 1024 * 1024);
}
$this->sys->setIdeDevices($dev);
} elseif (preg_match('/^(acd[0-9]+): (.*) <(.*)> (.*)/', $line, $ar_buf)) {
$dev = new HWDevice();
$dev->setName($ar_buf[1].": ".trim($ar_buf[3]));
$this->sys->setIdeDevices($dev);
} elseif (preg_match('/^(ada[0-9]+): <(.*)> (.*)/', $line, $ar_buf)) {
$dev = new HWDevice();
$dev->setName($ar_buf[1].": ".trim($ar_buf[2]));
$this->sys->setIdeDevices($dev);
} elseif (preg_match('/^(ada[0-9]+): (.*)MB \((.*)\)/', $line, $ar_buf)) {
/* duplication security */
$notwas = true;
foreach ($this->sys->getIdeDevices() as $finddev) {
if ($notwas && (substr($finddev->getName(), 0, strpos($finddev->getName(), ': ')) == $ar_buf[1])) {
if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS) {
$finddev->setCapacity($ar_buf[2] * 1024 * 1024);
}
$notwas = false;
break;
}
}
if ($notwas) {
$dev = new HWDevice();
$dev->setName($ar_buf[1]);
if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS) {
$dev->setCapacity($ar_buf[2] * 1024 * 1024);
}
$this->sys->setIdeDevices($dev);
}
} elseif (preg_match('/^(ada[0-9]+): Serial Number (.*)/', $line, $ar_buf)) {
/* duplication security */
$notwas = true;
foreach ($this->sys->getIdeDevices() as $finddev) {
if ($notwas && (substr($finddev->getName(), 0, strpos($finddev->getName(), ': ')) == $ar_buf[1])) {
if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS
&& defined('PSI_SHOW_DEVICES_SERIAL') && PSI_SHOW_DEVICES_SERIAL) {
$finddev->setSerial(trim($ar_buf[2]));
}
$notwas = false;
break;
}
}
if ($notwas) {
$dev = new HWDevice();
$dev->setName($ar_buf[1]);
if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS
&& defined('PSI_SHOW_DEVICES_SERIAL') && PSI_SHOW_DEVICES_SERIAL) {
$finddev->setSerial(trim($ar_buf[2]));
}
$this->sys->setIdeDevices($dev);
}
}
}
/* cleaning */
foreach ($this->sys->getIdeDevices() as $finddev) {
if (strpos($finddev->getName(), ': ') !== false)
$finddev->setName(substr(strstr($finddev->getName(), ': '), 2));
}
}
 
/**
* Physical memory information and Swap Space information
*
* @return void
*/
protected function memory()
{
if (PSI_OS == 'FreeBSD' || PSI_OS == 'OpenBSD') {
// vmstat on fbsd 4.4 or greater outputs kbytes not hw.pagesize
// I should probably add some version checking here, but for now
// we only support fbsd 4.4
$pagesize = 1024;
} else {
$pagesize = $this->grabkey('hw.pagesize');
}
if (CommonFunctions::executeProgram('vmstat', '', $vmstat, PSI_DEBUG)) {
$lines = preg_split("/\n/", $vmstat, -1, PREG_SPLIT_NO_EMPTY);
$ar_buf = preg_split("/\s+/", trim($lines[2]), 19);
if (PSI_OS == 'NetBSD' || PSI_OS == 'DragonFly') {
$this->sys->setMemFree($ar_buf[4] * 1024);
} else {
$this->sys->setMemFree($ar_buf[4] * $pagesize);
}
$this->sys->setMemTotal($this->grabkey('hw.physmem'));
$this->sys->setMemUsed($this->sys->getMemTotal() - $this->sys->getMemFree());
 
if (((PSI_OS == 'OpenBSD' || PSI_OS == 'NetBSD') && CommonFunctions::executeProgram('swapctl', '-l -k', $swapstat, PSI_DEBUG)) || CommonFunctions::executeProgram('swapinfo', '-k', $swapstat, PSI_DEBUG)) {
$lines = preg_split("/\n/", $swapstat, -1, PREG_SPLIT_NO_EMPTY);
foreach ($lines as $line) {
$ar_buf = preg_split("/\s+/", $line, 6);
if (($ar_buf[0] != 'Total') && ($ar_buf[0] != 'Device')) {
$dev = new DiskDevice();
$dev->setMountPoint($ar_buf[0]);
$dev->setName("SWAP");
$dev->setFsType('swap');
$dev->setTotal($ar_buf[1] * 1024);
$dev->setUsed($ar_buf[2] * 1024);
$dev->setFree($dev->getTotal() - $dev->getUsed());
$this->sys->setSwapDevices($dev);
}
}
}
}
}
 
/**
* USB devices
* get the ide device information out of dmesg
*
* @return void
*/
protected function usb()
{
foreach ($this->readdmesg() as $line) {
// if (preg_match('/^(ugen[0-9\.]+): <(.*)> (.*) (.*)/', $line, $ar_buf)) {
// $dev->setName($ar_buf[1].": ".$ar_buf[2]);
if (preg_match('/^(u[a-z]+[0-9]+): <([^,]*)(.*)> on (usbus[0-9]+)/', $line, $ar_buf)) {
$dev = new HWDevice();
$dev->setName($ar_buf[2]);
$this->sys->setUSBDevices($dev);
}
}
}
 
/**
* filesystem information
*
* @return void
*/
protected function filesystems()
{
$arrResult = Parser::df();
foreach ($arrResult as $dev) {
$this->sys->setDiskDevices($dev);
}
}
 
/**
* Distribution
*
* @return void
*/
protected function distro()
{
if (CommonFunctions::executeProgram('uname', '-s', $result, PSI_DEBUG)) {
$this->sys->setDistribution($result);
}
}
 
/**
* get the information
*
* @see PSI_Interface_OS::build()
*
* @return Void
*/
public function build()
{
if (!$this->blockname || $this->blockname==='vitals') {
$this->distro();
$this->hostname();
$this->kernel();
$this->_users();
$this->loadavg();
}
if (!$this->blockname || $this->blockname==='hardware') {
$this->cpuinfo();
$this->pci();
$this->ide();
$this->scsi();
$this->usb();
}
if (!$this->blockname || $this->blockname==='memory') {
$this->memory();
}
if (!$this->blockname || $this->blockname==='filesystem') {
$this->filesystems();
}
}
}
/web/acc/phpsysinfo/includes/os/class.Darwin.inc.php
1,198 → 1,493
<?php
<?php
/**
* Darwin System Class
*
* PHP version 5
*
* @category PHP
* @package PSI Darwin OS class
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License version 2, or (at your option) any later version
* @version SVN: $Id: class.Darwin.inc.php 638 2012-08-24 09:40:48Z namiltd $
* @link http://phpsysinfo.sourceforge.net
*/
/**
* Darwin sysinfo class
* get all the required information from Darwin system
* information may be incomplete
*
* @category PHP
* @package PSI Darwin OS class
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License version 2, or (at your option) any later version
* @version Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
class Darwin extends BSDCommon
{
/**
* define the regexp for log parser
*/
/* public function __construct($blockname = false)
{
parent::__construct($blockname);
$this->error->addWarning("The Darwin version of phpSysInfo is a work in progress, some things currently don't work!");
$this->setCPURegExp1("/CPU: (.*) \((.*)-MHz (.*)\)/");
$this->setCPURegExp2("/(.*) ([0-9]+) ([0-9]+) ([0-9]+) ([0-9]+)/");
$this->setSCSIRegExp1("/^(.*): <(.*)> .*SCSI.*device/");
} */
 
// phpSysInfo - A PHP System Information Script
// http://phpsysinfo.sourceforge.net/
/**
* get a value from sysctl command
*
* @param string $key key of the value to get
*
* @return string
*/
protected function grabkey($key)
{
if (CommonFunctions::executeProgram('sysctl', $key, $s, PSI_DEBUG)) {
$s = preg_replace('/'.$key.': /', '', $s);
$s = preg_replace('/'.$key.' = /', '', $s);
 
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
return $s;
} else {
return '';
}
}
 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
/**
* get a value from ioreg command
*
* @param string $key key of the value to get
*
* @return string
*/
private function _grabioreg($key)
{
if (CommonFunctions::executeProgram('ioreg', '-c "'.$key.'"', $s, PSI_DEBUG)) {
/* delete newlines */
$s = preg_replace("/\s+/", " ", $s);
/* new newlines */
$s = preg_replace("/[\|\t ]*\+\-o/", "\n", $s);
/* combine duplicate whitespaces and some chars */
$s = preg_replace("/[\|\t ]+/", " ", $s);
 
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
$lines = preg_split("/\n/", $s, -1, PREG_SPLIT_NO_EMPTY);
$out = "";
foreach ($lines as $line) {
if (preg_match('/^([^<]*) <class '.$key.',/', $line)) {
$out .= $line."\n";
}
}
 
// $Id: class.Darwin.inc.php,v 1.33 2006/06/14 16:36:34 bigmichi1 Exp $
if (!defined('IN_PHPSYSINFO')) {
die("No Hacking");
}
return $out;
} else {
return '';
}
}
 
require_once(APP_ROOT . '/includes/os/class.BSD.common.inc.php');
/**
* UpTime
* time the system is running
*
* @return void
*/
private function _uptime()
{
if (CommonFunctions::executeProgram('sysctl', '-n kern.boottime', $a, PSI_DEBUG)) {
$tmp = explode(" ", $a);
if ($tmp[0]=="{") { /* kern.boottime= { sec = 1096732600, usec = 885425 } Sat Oct 2 10:56:40 2004 */
$data = trim($tmp[3], ",");
$this->sys->setUptime(time() - $data);
} else { /* kern.boottime= 1096732600 */
$this->sys->setUptime(time() - $a);
}
}
}
 
$error->addWarning("The Darwin version of phpSysInfo is work in progress, some things currently don't work");
/**
* get CPU information
*
* @return void
*/
protected function cpuinfo()
{
$dev = new CpuDevice();
if (CommonFunctions::executeProgram('hostinfo', '| grep "Processor type"', $buf, PSI_DEBUG)) {
$dev->setModel(preg_replace('/Processor type: /', '', $buf));
$buf=$this->grabkey('hw.model');
if (!is_null($buf) && (trim($buf) != "")) {
$this->sys->setMachine(trim($buf));
if (CommonFunctions::rfts(PSI_APP_ROOT.'/data/ModelTranslation.txt', $buffer)) {
$buffer = preg_split("/\n/", $buffer, -1, PREG_SPLIT_NO_EMPTY);
foreach ($buffer as $line) {
$ar_buf = preg_split("/:/", $line, 3);
if (trim($buf) === trim($ar_buf[0])) {
$dev->setModel(trim($ar_buf[2]));
$this->sys->setMachine($this->sys->getMachine().' - '.trim($ar_buf[1]));
break;
}
}
}
}
$buf=$this->grabkey('machdep.cpu.brand_string');
if (!is_null($buf) && (trim($buf) != "") &&
((trim($buf) != "i486 (Intel 80486)") || ($dev->getModel() == ""))) {
$dev->setModel(trim($buf));
}
$buf=$this->grabkey('machdep.cpu.features');
if (!is_null($buf) && (trim($buf) != "")) {
if (preg_match("/ VMX/", $buf)) {
$dev->setVirt("vmx");
} elseif (preg_match("/ SVM/", $buf)) {
$dev->setVirt("svm");
}
}
}
$dev->setCpuSpeed(round($this->grabkey('hw.cpufrequency') / 1000000));
$dev->setBusSpeed(round($this->grabkey('hw.busfrequency') / 1000000));
$bufn=$this->grabkey('hw.cpufrequency_min');
$bufx=$this->grabkey('hw.cpufrequency_max');
if (!is_null($bufn) && (trim($bufn) != "") && !is_null($bufx) && (trim($bufx) != "") && ($bufn != $bufx)) {
$dev->setCpuSpeedMin(round($bufn / 1000000));
$dev->setCpuSpeedMax(round($bufx / 1000000));
}
$buf=$this->grabkey('hw.l2cachesize');
if (!is_null($buf) && (trim($buf) != "")) {
$dev->setCache(round($buf));
}
$ncpu = $this->grabkey('hw.ncpu');
if (is_null($ncpu) || (trim($ncpu) == "") || (!($ncpu >= 1)))
$ncpu = 1;
for ($ncpu ; $ncpu > 0 ; $ncpu--) {
$this->sys->setCpus($dev);
}
}
 
class sysinfo extends bsd_common {
var $cpu_regexp;
var $scsi_regexp;
var $parser;
// Our contstructor
// this function is run on the initialization of this class
function sysinfo () {
// $this->cpu_regexp = "CPU: (.*) \((.*)-MHz (.*)\)";
// $this->scsi_regexp1 = "^(.*): <(.*)> .*SCSI.*device";
$this->cpu_regexp2 = "/(.*) ([0-9]+) ([0-9]+) ([0-9]+) ([0-9]+)/";
$this->parser = new Parser();
}
/**
* get the pci device information out of ioreg
*
* @return void
*/
protected function pci()
{
if (!$arrResults = Parser::lspci(false)) { //no lspci port
$s = $this->_grabioreg('IOPCIDevice');
$lines = preg_split("/\n/", $s, -1, PREG_SPLIT_NO_EMPTY);
foreach ($lines as $line) {
$dev = new HWDevice();
if (!preg_match('/"IOName" = "([^"]*)"/', $line, $ar_buf)) {
$ar_buf = preg_split("/[\s@]+/", $line, 19);
}
if (preg_match('/"model" = <?"([^"]*)"/', $line, $ar_buf2)) {
$dev->setName(trim($ar_buf[1]). ": ".trim($ar_buf2[1]));
} else {
$dev->setName(trim($ar_buf[1]));
}
$this->sys->setPciDevices($dev);
}
} else {
foreach ($arrResults as $dev) {
$this->sys->setPciDevices($dev);
}
}
}
 
function grab_key ($key) {
$s = execute_program('sysctl', $key);
$s = ereg_replace($key . ': ', '', $s);
$s = ereg_replace($key . ' = ', '', $s); // fix Apple set keys
return $s;
}
/**
* get the ide device information out of ioreg
*
* @return void
*/
protected function ide()
{
$s = $this->_grabioreg('IOATABlockStorageDevice');
$lines = preg_split("/\n/", $s, -1, PREG_SPLIT_NO_EMPTY);
foreach ($lines as $line) {
$dev = new HWDevice();
if (!preg_match('/"Product Name"="([^"]*)"/', $line, $ar_buf))
$ar_buf = preg_split("/[\s@]+/", $line, 19);
$dev->setName(trim($ar_buf[1]));
$this->sys->setIdeDevices($dev);
}
 
function grab_ioreg ($key) {
$s = execute_program('ioreg', '-cls "' . $key . '" | grep "' . $key . '"'); //ioreg -cls "$key" | grep "$key"
$s = ereg_replace('\|', '', $s);
$s = ereg_replace('\+\-\o', '', $s);
$s = ereg_replace('[ ]+', '', $s);
$s = ereg_replace('<[^>]+>', '', $s); // remove possible XML conflicts
$s = $this->_grabioreg('IOAHCIBlockStorageDevice');
$lines = preg_split("/\n/", $s, -1, PREG_SPLIT_NO_EMPTY);
foreach ($lines as $line) {
$dev = new HWDevice();
if (!preg_match('/"Product Name"="([^"]*)"/', $line, $ar_buf))
$ar_buf = preg_split("/[\s@]+/", $line, 19);
$dev->setName(trim($ar_buf[1]));
$this->sys->setIdeDevices($dev);
}
}
 
return $s;
}
/**
* get the usb device information out of ioreg
*
* @return void
*/
protected function usb()
{
$s = $this->_grabioreg('IOUSBDevice');
$lines = preg_split("/\n/", $s, -1, PREG_SPLIT_NO_EMPTY);
foreach ($lines as $line) {
$dev = new HWDevice();
if (!preg_match('/"USB Product Name" = "([^"]*)"/', $line, $ar_buf))
$ar_buf = preg_split("/[\s@]+/", $line, 19);
$dev->setName(trim($ar_buf[1]));
if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS) {
if (preg_match('/"USB Vendor Name" = "([^"]*)"/', $line, $ar_buf)) {
$dev->setManufacturer(trim($ar_buf[1]));
}
if (preg_match('/"USB Product Name" = "([^"]*)"/', $line, $ar_buf)) {
$dev->setProduct(trim($ar_buf[1]));
}
if (defined('PSI_SHOW_DEVICES_SERIAL') && PSI_SHOW_DEVICES_SERIAL
&& preg_match('/"USB Serial Number" = "([^"]*)"/', $line, $ar_buf)) {
$dev->setSerial(trim($ar_buf[1]));
}
}
$this->sys->setUsbDevices($dev);
}
}
 
function get_sys_ticks () {
$a = execute_program('sysctl', '-n kern.boottime'); // get boottime (value in seconds)
$sys_ticks = time() - $a;
/**
* get the scsi device information out of ioreg
*
* @return void
*/
protected function scsi()
{
$s = $this->_grabioreg('IOBlockStorageServices');
$lines = preg_split("/\n/", $s, -1, PREG_SPLIT_NO_EMPTY);
foreach ($lines as $line) {
$dev = new HWDevice();
if (!preg_match('/"Product Name"="([^"]*)"/', $line, $ar_buf))
$ar_buf = preg_split("/[\s@]+/", $line, 19);
$dev->setName(trim($ar_buf[1]));
$this->sys->setScsiDevices($dev);
}
}
 
return $sys_ticks;
}
/**
* get memory and swap information
*
* @return void
*/
protected function memory()
{
$s = $this->grabkey('hw.memsize');
if (CommonFunctions::executeProgram('vm_stat', '', $pstat, PSI_DEBUG)) {
// calculate free memory from page sizes (each page = 4096)
if (preg_match('/^Pages free:\s+(\S+)/m', $pstat, $free_buf)) {
if (preg_match('/^Anonymous pages:\s+(\S+)/m', $pstat, $anon_buf)
&& preg_match('/^Pages wired down:\s+(\S+)/m', $pstat, $wire_buf)
&& preg_match('/^File-backed pages:\s+(\S+)/m', $pstat, $fileb_buf)) {
// OS X 10.9 or never
$this->sys->setMemFree($free_buf[1] * 4 * 1024);
$this->sys->setMemApplication(($anon_buf[1]+$wire_buf[1]) * 4 * 1024);
$this->sys->setMemCache($fileb_buf[1] * 4 * 1024);
if (preg_match('/^Pages occupied by compressor:\s+(\S+)/m', $pstat, $compr_buf)) {
$this->sys->setMemBuffer($compr_buf[1] * 4 * 1024);
}
} else {
if (preg_match('/^Pages speculative:\s+(\S+)/m', $pstat, $spec_buf)) {
$this->sys->setMemFree(($free_buf[1]+$spec_buf[1]) * 4 * 1024);
} else {
$this->sys->setMemFree($free_buf[1] * 4 * 1024);
}
$appMemory = 0;
if (preg_match('/^Pages wired down:\s+(\S+)/m', $pstat, $wire_buf)) {
$appMemory += $wire_buf[1] * 4 * 1024;
}
if (preg_match('/^Pages active:\s+(\S+)/m', $pstat, $active_buf)) {
$appMemory += $active_buf[1] * 4 * 1024;
}
$this->sys->setMemApplication($appMemory);
 
function cpu_info () {
$results = array();
// $results['model'] = $this->grab_key('hw.model'); // need to expand this somehow...
// $results['model'] = $this->grab_key('hw.machine');
$results['model'] = ereg_replace('Processor type: ', '', execute_program('hostinfo', '| grep "Processor type"')); // get processor type
$results['cpus'] = $this->grab_key('hw.ncpu');
$results['cpuspeed'] = round($this->grab_key('hw.cpufrequency') / 1000000); // return cpu speed - Mhz
$results['busspeed'] = round($this->grab_key('hw.busfrequency') / 1000000); // return bus speed - Mhz
$results['cache'] = round($this->grab_key('hw.l2cachesize') / 1024); // return l2 cache
if (preg_match('/^Pages inactive:\s+(\S+)/m', $pstat, $inactive_buf)) {
$this->sys->setMemCache($inactive_buf[1] * 4 * 1024);
}
}
} else {
$lines = preg_split("/\n/", $pstat, -1, PREG_SPLIT_NO_EMPTY);
$ar_buf = preg_split("/\s+/", $lines[1], 19);
$this->sys->setMemFree($ar_buf[2] * 4 * 1024);
}
 
if (($this->grab_key('hw.model') == "PowerMac3,6") && ($results['cpus'] == "2")) { $results['model'] = 'Dual G4 - (PowerPC 7450)';} // is Dual G4
if (($this->grab_key('hw.model') == "PowerMac7,2") && ($results['cpus'] == "2")) { $results['model'] = 'Dual G5 - (PowerPC 970)';} // is Dual G5
if (($this->grab_key('hw.model') == "PowerMac1,1") && ($results['cpus'] == "1")) { $results['model'] = 'B&W G3 - (PowerPC 750)';} // is B&W G3
$this->sys->setMemTotal($s);
$this->sys->setMemUsed($this->sys->getMemTotal() - $this->sys->getMemFree());
 
return $results;
}
// get the pci device information out of ioreg
function pci () {
$results = array();
$s = $this->grab_ioreg('IOPCIDevice');
if (CommonFunctions::executeProgram('sysctl', 'vm.swapusage | colrm 1 22', $swapBuff, PSI_DEBUG)) {
$swap1 = preg_split('/M/', $swapBuff);
$swap2 = preg_split('/=/', $swap1[1]);
$swap3 = preg_split('/=/', $swap1[2]);
$dev = new DiskDevice();
$dev->setName('SWAP');
$dev->setMountPoint('SWAP');
$dev->setFsType('swap');
$dev->setTotal($swap1[0] * 1024 * 1024);
$dev->setUsed($swap2[1] * 1024 * 1024);
$dev->setFree($swap3[1] * 1024 * 1024);
$this->sys->setSwapDevices($dev);
}
}
}
 
$lines = explode("\n", $s);
for ($i = 0, $max = sizeof($lines); $i < $max; $i++) {
$ar_buf = preg_split("/\s+/", $lines[$i], 19);
$results[$i] = $ar_buf[0];
}
asort($results);
return array_values(array_unique($results));
}
// get the ide device information out of ioreg
function ide () {
$results = array();
// ioreg | grep "Media <class IOMedia>"
$s = $this->grab_ioreg('IOATABlockStorageDevice');
/**
* get the thunderbolt device information out of ioreg
*
* @return void
*/
protected function _tb()
{
$s = $this->_grabioreg('IOThunderboltPort');
$lines = preg_split("/\n/", $s, -1, PREG_SPLIT_NO_EMPTY);
foreach ($lines as $line) {
$dev = new HWDevice();
if (!preg_match('/"Description" = "([^"]*)"/', $line, $ar_buf))
$ar_buf = preg_split("/[\s@]+/", $line, 19);
$dev->setName(trim($ar_buf[1]));
$this->sys->setTbDevices($dev);
}
}
 
$lines = explode("\n", $s);
$j = 0;
for ($i = 0, $max = sizeof($lines); $i < $max; $i++) {
$ar_buf = preg_split("/\/\//", $lines[$i], 19);
/**
* get network information
*
* @return void
*/
private function _network()
{
if (CommonFunctions::executeProgram('netstat', '-nbdi | cut -c1-24,42- | grep Link', $netstat, PSI_DEBUG)) {
$lines = preg_split("/\n/", $netstat, -1, PREG_SPLIT_NO_EMPTY);
foreach ($lines as $line) {
$ar_buf = preg_split("/\s+/", $line, 10);
if (!empty($ar_buf[0])) {
$dev = new NetDevice();
$dev->setName($ar_buf[0]);
$dev->setTxBytes($ar_buf[8]);
$dev->setRxBytes($ar_buf[5]);
$dev->setErrors($ar_buf[4] + $ar_buf[7]);
if (isset($ar_buf[10])) {
$dev->setDrops($ar_buf[10]);
}
if (defined('PSI_SHOW_NETWORK_INFOS') && (PSI_SHOW_NETWORK_INFOS) && (CommonFunctions::executeProgram('ifconfig', $ar_buf[0].' 2>/dev/null', $bufr2, PSI_DEBUG))) {
$bufe2 = preg_split("/\n/", $bufr2, -1, PREG_SPLIT_NO_EMPTY);
foreach ($bufe2 as $buf2) {
if (preg_match('/^\s+ether\s+(\S+)/i', $buf2, $ar_buf2)) {
if (!defined('PSI_HIDE_NETWORK_MACADDR') || !PSI_HIDE_NETWORK_MACADDR) $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').preg_replace('/:/', '-', strtoupper($ar_buf2[1])));
} elseif (preg_match('/^\s+inet\s+(\S+)\s+netmask/i', $buf2, $ar_buf2)) {
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$ar_buf2[1]);
} elseif ((preg_match('/^\s+inet6\s+([^\s%]+)\s+prefixlen/i', $buf2, $ar_buf2)
|| preg_match('/^\s+inet6\s+([^\s%]+)%\S+\s+prefixlen/i', $buf2, $ar_buf2))
&& ($ar_buf2[1]!="::") && !preg_match('/^fe80::/i', $ar_buf2[1])) {
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').strtolower($ar_buf2[1]));
} elseif (preg_match('/^\s+media:\s+/i', $buf2) && preg_match('/[\(\s](\d+)(G*)base/i', $buf2, $ar_buf2)) {
if (isset($ar_buf2[2]) && strtoupper($ar_buf2[2])=="G") {
$unit = "G";
} else {
$unit = "M";
}
if (preg_match('/[<\s]([^\s<]+)-duplex/i', $buf2, $ar_buf3))
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$ar_buf2[1].$unit.'b/s '.strtolower($ar_buf3[1]));
else
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$ar_buf2[1].$unit.'b/s');
}
}
}
$this->sys->setNetDevices($dev);
}
}
}
}
 
if ( isset( $ar_buf[1] ) && $ar_buf[1] == 'class IOMedia' && preg_match('/Media/', $ar_buf[0])) {
$results[$j++]['model'] = $ar_buf[0];
}
}
asort($results);
return array_values(array_unique($results));
}
/**
* get icon name
*
* @return void
*/
protected function distro()
{
$this->sys->setDistributionIcon('Darwin.png');
if (!CommonFunctions::executeProgram('system_profiler', 'SPSoftwareDataType', $buffer, PSI_DEBUG)) {
parent::distro();
} else {
$arrBuff = preg_split("/\n/", $buffer, -1, PREG_SPLIT_NO_EMPTY);
foreach ($arrBuff as $line) {
$arrLine = preg_split("/:/", $line, -1, PREG_SPLIT_NO_EMPTY);
if (trim($arrLine[0]) === "System Version") {
$distro = trim($arrLine[1]);
 
function memory () {
$s = $this->grab_key('hw.memsize');
if (preg_match('/^Mac OS|^OS X|^macOS/', $distro)) {
$this->sys->setDistributionIcon('Apple.png');
if (preg_match('/(^Mac OS X Server|^Mac OS X|^OS X Server|^OS X|^macOS Server|^macOS) (\d+\.\d+)/', $distro, $ver)
&& ($list = @parse_ini_file(PSI_APP_ROOT."/data/osnames.ini", true))
&& isset($list['OS X'][$ver[2]])) {
$distro.=' '.$list['OS X'][$ver[2]];
}
}
 
$results['ram'] = array();
$results['swap'] = array();
$results['devswap'] = array();
$pstat = execute_program('vm_stat'); // use darwin's vm_stat
$lines = explode("\n", $pstat);
for ($i = 0, $max = sizeof($lines); $i < $max; $i++) {
$ar_buf = preg_split("/\s+/", $lines[$i], 19);
$this->sys->setDistribution($distro);
 
if ($i == 1) {
$results['ram']['free'] = $ar_buf[2] * 4; // calculate free memory from page sizes (each page = 4MB)
}
}
return;
}
}
}
}
 
$results['ram']['total'] = $s / 1024;
$results['ram']['shared'] = 0;
$results['ram']['buffers'] = 0;
$results['ram']['used'] = $results['ram']['total'] - $results['ram']['free'];
$results['ram']['cached'] = 0;
/**
* Processes
*
* @return void
*/
protected function _processes()
{
if (CommonFunctions::executeProgram('ps', 'aux', $bufr, PSI_DEBUG)) {
$lines = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
$processes['*'] = 0;
foreach ($lines as $line) {
if (preg_match("/^\S+\s+\d+\s+\S+\s+\S+\s+\d+\s+\d+\s+\S+\s+(\w)/", $line, $ar_buf)) {
$processes['*']++;
$state = $ar_buf[1];
if ($state == 'U') $state = 'D'; //linux format
elseif ($state == 'I') $state = 'S';
elseif ($state == 'D') $state = 'd'; //invalid
if (isset($processes[$state])) {
$processes[$state]++;
} else {
$processes[$state] = 1;
}
}
}
if ($processes['*'] > 0) {
$this->sys->setProcesses($processes);
}
}
}
 
$results['ram']['percent'] = round(($results['ram']['used'] * 100) / $results['ram']['total']);
// need to fix the swap info...
// meanwhile silence and / or disable the swap information
$pstat = execute_program('swapinfo', '-k', false);
if( $pstat != "ERROR" ) {
$lines = explode("\n", $pstat);
 
for ($i = 0, $max = sizeof($lines); $i < $max; $i++) {
$ar_buf = preg_split("/\s+/", $lines[$i], 6);
if ($i == 0) {
$results['swap']['total'] = 0;
$results['swap']['used'] = 0;
$results['swap']['free'] = 0;
} else {
$results['swap']['total'] = $results['swap']['total'] + $ar_buf[1];
$results['swap']['used'] = $results['swap']['used'] + $ar_buf[2];
$results['swap']['free'] = $results['swap']['free'] + $ar_buf[3];
}
}
$results['swap']['percent'] = round(($results['swap']['used'] * 100) / $results['swap']['total']);
/**
* get the information
*
* @see PSI_Interface_OS::build()
*
* @return Void
*/
public function build()
{
parent::build();
if (!$this->blockname || $this->blockname==='vitals') {
$this->_uptime();
$this->_processes();
}
if (!$this->blockname || $this->blockname==='hardware') {
$this->_tb();
}
if (!$this->blockname || $this->blockname==='network') {
$this->_network();
}
}
return $results;
}
 
function network () {
$netstat = execute_program('netstat', '-nbdi | cut -c1-24,42- | grep Link');
$lines = explode("\n", $netstat);
$results = array();
for ($i = 0, $max = sizeof($lines); $i < $max; $i++) {
$ar_buf = preg_split("/\s+/", $lines[$i], 10);
if (!empty($ar_buf[0])) {
$results[$ar_buf[0]] = array();
 
$results[$ar_buf[0]]['rx_bytes'] = $ar_buf[5];
$results[$ar_buf[0]]['rx_packets'] = $ar_buf[3];
$results[$ar_buf[0]]['rx_errs'] = $ar_buf[4];
$results[$ar_buf[0]]['rx_drop'] = isset( $ar_buf[10] ) ? $ar_buf[10] : 0;
 
$results[$ar_buf[0]]['tx_bytes'] = $ar_buf[8];
$results[$ar_buf[0]]['tx_packets'] = $ar_buf[6];
$results[$ar_buf[0]]['tx_errs'] = $ar_buf[7];
$results[$ar_buf[0]]['tx_drop'] = isset( $ar_buf[10] ) ? $ar_buf[10] : 0;
 
$results[$ar_buf[0]]['errs'] = $ar_buf[4] + $ar_buf[7];
$results[$ar_buf[0]]['drop'] = isset( $ar_buf[10] ) ? $ar_buf[10] : 0;
}
}
return $results;
}
 
function distroicon () {
$result = 'Darwin.png';
return($result);
}
 
}
 
?>
}
/web/acc/phpsysinfo/includes/os/class.DragonFly.inc.php
0,0 → 1,157
<?php
/**
* DragonFly System Class
*
* PHP version 5
*
* @category PHP
* @package PSI DragonFly OS class
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License version 2, or (at your option) any later version
* @version SVN: $Id: class.DragonFly.inc.php 287 2009-06-26 12:11:59Z bigmichi1 $
* @link http://phpsysinfo.sourceforge.net
*/
/**
* DragonFly sysinfo class
* get all the required information from DragonFly system
*
* @category PHP
* @package PSI DragonFly OS class
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License version 2, or (at your option) any later version
* @version Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
class DragonFly extends BSDCommon
{
/**
* define the regexp for log parser
*/
public function __construct($blockname = false)
{
parent::__construct($blockname);
$this->setCPURegExp1("/^cpu(.*)\, (.*) MHz/");
$this->setCPURegExp2("/^(.*) at scsibus.*: <(.*)> .*/");
$this->setSCSIRegExp2("/^(da[0-9]+): (.*)MB /");
$this->setPCIRegExp1("/(.*): <(.*)>(.*) (pci|legacypci)[0-9]+$/");
$this->setPCIRegExp2("/(.*): <(.*)>.* at [0-9\.]+$/");
}
 
/**
* UpTime
* time the system is running
*
* @return void
*/
private function _uptime()
{
$a = $this->grabkey('kern.boottime');
preg_match("/sec = ([0-9]+)/", $a, $buf);
$this->sys->setUptime(time() - $buf[1]);
}
 
/**
* get network information
*
* @return void
*/
private function _network()
{
CommonFunctions::executeProgram('netstat', '-nbdi | cut -c1-25,44- | grep "^[a-z]*[0-9][ \t].*Link"', $netstat_b);
CommonFunctions::executeProgram('netstat', '-ndi | cut -c1-25,44- | grep "^[a-z]*[0-9][ \t].*Link"', $netstat_n);
$lines_b = preg_split("/\n/", $netstat_b, -1, PREG_SPLIT_NO_EMPTY);
$lines_n = preg_split("/\n/", $netstat_n, -1, PREG_SPLIT_NO_EMPTY);
for ($i = 0, $max = sizeof($lines_b); $i < $max; $i++) {
$ar_buf_b = preg_split("/\s+/", $lines_b[$i]);
$ar_buf_n = preg_split("/\s+/", $lines_n[$i]);
if (!empty($ar_buf_b[0]) && (!empty($ar_buf_n[5]) || ($ar_buf_n[5] === "0"))) {
$dev = new NetDevice();
$dev->setName($ar_buf_b[0]);
$dev->setTxBytes($ar_buf_b[8]);
$dev->setRxBytes($ar_buf_b[5]);
$dev->setErrors($ar_buf_n[4] + $ar_buf_n[6]);
$dev->setDrops($ar_buf_n[8]);
$this->sys->setNetDevices($dev);
}
}
}
 
/**
* get the ide information
*
* @return void
*/
protected function ide()
{
foreach ($this->readdmesg() as $line) {
if (preg_match('/^(.*): (.*) <(.*)> at (ata[0-9]+\-(.*)) (.*)/', $line, $ar_buf)) {
$dev = new HWDevice();
$dev->setName($ar_buf[1]);
if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS && !preg_match("/^acd[0-9]+(.*)/", $ar_buf[1])) {
$dev->setCapacity($ar_buf[2] * 1024 * 1024);
}
$this->sys->setIdeDevices($dev);
}
}
}
 
/**
* get icon name
*
* @return void
*/
private function _distroicon()
{
$this->sys->setDistributionIcon('DragonFly.png');
}
 
/**
* Processes
*
* @return void
*/
protected function _processes()
{
if (CommonFunctions::executeProgram('ps', 'aux', $bufr, PSI_DEBUG)) {
$lines = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
$processes['*'] = 0;
foreach ($lines as $line) {
if (preg_match("/^\S+\s+\d+\s+\S+\s+\S+\s+\d+\s+\d+\s+\S+\s+(\w)/", $line, $ar_buf)) {
$processes['*']++;
$state = $ar_buf[1];
if ($state == 'I') $state = 'S'; //linux format
if (isset($processes[$state])) {
$processes[$state]++;
} else {
$processes[$state] = 1;
}
}
}
if ($processes['*'] > 0) {
$this->sys->setProcesses($processes);
}
}
}
 
/**
* get the information
*
* @see BSDCommon::build()
*
* @return Void
*/
public function build()
{
parent::build();
if (!$this->blockname || $this->blockname==='vitals') {
$this->_distroicon();
$this->_uptime();
$this->_processes();
}
if (!$this->blockname || $this->blockname==='network') {
$this->_network();
}
}
}
/web/acc/phpsysinfo/includes/os/class.FreeBSD.inc.php
1,108 → 1,208
<?php
<?php
/**
* FreeBSD System Class
*
* PHP version 5
*
* @category PHP
* @package PSI FreeBSD OS class
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License version 2, or (at your option) any later version
* @version SVN: $Id: class.FreeBSD.inc.php 696 2012-09-09 11:24:04Z namiltd $
* @link http://phpsysinfo.sourceforge.net
*/
/**
* FreeBSD sysinfo class
* get all the required information from FreeBSD system
*
* @category PHP
* @package PSI FreeBSD OS class
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License version 2, or (at your option) any later version
* @version Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
class FreeBSD extends BSDCommon
{
/**
* define the regexp for log parser
*/
public function __construct($blockname = false)
{
parent::__construct($blockname);
$this->setCPURegExp1("/CPU: (.*) \((.*)-MHz (.*)\)/");
$this->setCPURegExp2("/(.*) ([0-9]+) ([0-9]+) ([0-9]+) ([0-9]+)/");
$this->setSCSIRegExp1("/^(.*): <(.*)> .*SCSI.*device/");
$this->setSCSIRegExp2("/^(da[0-9]+): (.*)MB /");
$this->setSCSIRegExp3("/^(da[0-9]+|cd[0-9]+): Serial Number (.*)/");
$this->setPCIRegExp1("/(.*): <(.*)>(.*) pci[0-9]+$/");
$this->setPCIRegExp2("/(.*): <(.*)>.* at [.0-9]+ irq/");
}
 
// phpSysInfo - A PHP System Information Script
// http://phpsysinfo.sourceforge.net/
/**
* UpTime
* time the system is running
*
* @return void
*/
private function _uptime()
{
$s = preg_split('/ /', $this->grabkey('kern.boottime'));
$a = preg_replace('/,/', '', $s[3]);
$this->sys->setUptime(time() - $a);
}
 
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
/**
* get network information
*
* @return void
*/
private function _network()
{
$dev = null;
if (CommonFunctions::executeProgram('netstat', '-nibd', $netstat, PSI_DEBUG)) {
$lines = preg_split("/\n/", $netstat, -1, PREG_SPLIT_NO_EMPTY);
foreach ($lines as $line) {
$ar_buf = preg_split("/\s+/", $line);
if (!empty($ar_buf[0])) {
if (preg_match('/^<Link/i', $ar_buf[2])) {
$dev = new NetDevice();
$dev->setName($ar_buf[0]);
if ((strlen($ar_buf[3]) < 17) && ($ar_buf[0] != $ar_buf[3])) { /* no MAC or dev name*/
if (isset($ar_buf[11]) && (trim($ar_buf[11]) != '')) { /* Idrop column exist*/
$dev->setTxBytes($ar_buf[9]);
$dev->setRxBytes($ar_buf[6]);
$dev->setErrors($ar_buf[4] + $ar_buf[8]);
$dev->setDrops($ar_buf[11] + $ar_buf[5]);
} else {
$dev->setTxBytes($ar_buf[8]);
$dev->setRxBytes($ar_buf[5]);
$dev->setErrors($ar_buf[4] + $ar_buf[7]);
$dev->setDrops($ar_buf[10]);
}
} else {
if (isset($ar_buf[12]) && (trim($ar_buf[12]) != '')) { /* Idrop column exist*/
$dev->setTxBytes($ar_buf[10]);
$dev->setRxBytes($ar_buf[7]);
$dev->setErrors($ar_buf[5] + $ar_buf[9]);
$dev->setDrops($ar_buf[12] + $ar_buf[6]);
} else {
$dev->setTxBytes($ar_buf[9]);
$dev->setRxBytes($ar_buf[6]);
$dev->setErrors($ar_buf[5] + $ar_buf[8]);
$dev->setDrops($ar_buf[11]);
}
}
if (defined('PSI_SHOW_NETWORK_INFOS') && (PSI_SHOW_NETWORK_INFOS) && (CommonFunctions::executeProgram('ifconfig', $ar_buf[0].' 2>/dev/null', $bufr2, PSI_DEBUG))) {
$bufe2 = preg_split("/\n/", $bufr2, -1, PREG_SPLIT_NO_EMPTY);
foreach ($bufe2 as $buf2) {
if (preg_match('/^\s+ether\s+(\S+)/i', $buf2, $ar_buf2)) {
if (!defined('PSI_HIDE_NETWORK_MACADDR') || !PSI_HIDE_NETWORK_MACADDR) $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').preg_replace('/:/', '-', strtoupper($ar_buf2[1])));
} elseif (preg_match('/^\s+inet\s+(\S+)\s+netmask/i', $buf2, $ar_buf2)) {
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$ar_buf2[1]);
} elseif ((preg_match('/^\s+inet6\s+([^\s%]+)\s+prefixlen/i', $buf2, $ar_buf2)
|| preg_match('/^\s+inet6\s+([^\s%]+)%\S+\s+prefixlen/i', $buf2, $ar_buf2))
&& ($ar_buf2[1]!="::") && !preg_match('/^fe80::/i', $ar_buf2[1])) {
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').strtolower($ar_buf2[1]));
} elseif (preg_match('/^\s+media:\s+/i', $buf2) && preg_match('/[\(\s](\d+)(G*)base/i', $buf2, $ar_buf2)) {
if (isset($ar_buf2[2]) && strtoupper($ar_buf2[2])=="G") {
$unit = "G";
} else {
$unit = "M";
}
if (preg_match('/[<\s]([^\s<]+)-duplex/i', $buf2, $ar_buf3))
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$ar_buf2[1].$unit.'b/s '.strtolower($ar_buf3[1]));
else
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$ar_buf2[1].$unit.'b/s');
}
}
}
$this->sys->setNetDevices($dev);
}
}
}
}
}
 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
 
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
// $Id: class.FreeBSD.inc.php,v 1.17 2006/04/18 16:22:26 bigmichi1 Exp $
if (!defined('IN_PHPSYSINFO')) {
die("No Hacking");
}
 
require_once(APP_ROOT . '/includes/os/class.BSD.common.inc.php');
 
class sysinfo extends bsd_common {
var $cpu_regexp = "";
var $scsi_regexp1 = "";
var $scsi_regexp2 = "";
var $cpu_regexp2 = "";
// Our contstructor
// this function is run on the initialization of this class
function sysinfo () {
$this->bsd_common();
$this->cpu_regexp = "CPU: (.*) \((.*)-MHz (.*)\)";
$this->scsi_regexp1 = "^(.*): <(.*)> .*SCSI.*device";
$this->scsi_regexp2 = "^(da[0-9]): (.*)MB ";
$this->cpu_regexp2 = "/(.*) ([0-9]+) ([0-9]+) ([0-9]+) ([0-9]+)/";
}
 
function get_sys_ticks () {
$s = explode(' ', $this->grab_key('kern.boottime'));
$a = ereg_replace('{ ', '', $s[3]);
$sys_ticks = time() - $a;
return $sys_ticks;
}
 
function network () {
$netstat = execute_program('netstat', '-nibd | grep Link');
$lines = explode("\n", $netstat);
$results = array();
for ($i = 0, $max = sizeof($lines); $i < $max; $i++) {
$ar_buf = preg_split("/\s+/", $lines[$i]);
if (!empty($ar_buf[0])) {
$results[$ar_buf[0]] = array();
 
if (strlen($ar_buf[3]) < 15) {
$results[$ar_buf[0]]['rx_bytes'] = $ar_buf[5];
$results[$ar_buf[0]]['rx_packets'] = $ar_buf[3];
$results[$ar_buf[0]]['rx_errs'] = $ar_buf[4];
$results[$ar_buf[0]]['rx_drop'] = $ar_buf[10];
 
$results[$ar_buf[0]]['tx_bytes'] = $ar_buf[8];
$results[$ar_buf[0]]['tx_packets'] = $ar_buf[6];
$results[$ar_buf[0]]['tx_errs'] = $ar_buf[7];
$results[$ar_buf[0]]['tx_drop'] = $ar_buf[10];
 
$results[$ar_buf[0]]['errs'] = $ar_buf[4] + $ar_buf[7];
$results[$ar_buf[0]]['drop'] = $ar_buf[10];
/**
* get icon name and distro extended check
*
* @return void
*/
private function _distroicon()
{
if (extension_loaded('pfSense') && CommonFunctions::rfts('/etc/version', $version, 1, 4096, false) && (trim($version) != '')) { // pfSense detection
$this->sys->setDistribution('pfSense '. trim($version));
$this->sys->setDistributionIcon('pfSense.png');
} else {
$results[$ar_buf[0]]['rx_bytes'] = $ar_buf[6];
$results[$ar_buf[0]]['rx_packets'] = $ar_buf[4];
$results[$ar_buf[0]]['rx_errs'] = $ar_buf[5];
$results[$ar_buf[0]]['rx_drop'] = $ar_buf[11];
$this->sys->setDistributionIcon('FreeBSD.png');
}
}
 
$results[$ar_buf[0]]['tx_bytes'] = $ar_buf[9];
$results[$ar_buf[0]]['tx_packets'] = $ar_buf[7];
$results[$ar_buf[0]]['tx_errs'] = $ar_buf[8];
$results[$ar_buf[0]]['tx_drop'] = $ar_buf[11];
/**
* extend the memory information with additional values
*
* @return void
*/
private function _memoryadditional()
{
$pagesize = $this->grabkey("hw.pagesize");
$this->sys->setMemCache($this->grabkey("vm.stats.vm.v_cache_count") * $pagesize);
$this->sys->setMemApplication(($this->grabkey("vm.stats.vm.v_active_count") + $this->grabkey("vm.stats.vm.v_wire_count")) * $pagesize);
$this->sys->setMemBuffer($this->sys->getMemUsed() - $this->sys->getMemApplication() - $this->sys->getMemCache());
}
 
$results[$ar_buf[0]]['errs'] = $ar_buf[5] + $ar_buf[8];
$results[$ar_buf[0]]['drop'] = $ar_buf[11];
}
}
}
return $results;
}
/**
* Processes
*
* @return void
*/
protected function _processes()
{
if (CommonFunctions::executeProgram('ps', 'aux', $bufr, PSI_DEBUG)) {
$lines = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
$processes['*'] = 0;
foreach ($lines as $line) {
if (preg_match("/^\S+\s+\d+\s+\S+\s+\S+\s+\d+\s+\d+\s+\S+\s+(\w)/", $line, $ar_buf)) {
$processes['*']++;
$state = $ar_buf[1];
if ($state == 'L') $state = 'D'; //linux format
elseif ($state == 'I') $state = 'S';
if (isset($processes[$state])) {
$processes[$state]++;
} else {
$processes[$state] = 1;
}
}
}
if ($processes['*'] > 0) {
$this->sys->setProcesses($processes);
}
}
}
 
function distroicon () {
$result = 'FreeBSD.png';
return($result);
}
function memory_additional($results) {
$pagesize = $this->grab_key("hw.pagesize");
$results['ram']['cached'] = $this->grab_key("vm.stats.vm.v_cache_count") * $pagesize / 1024;
$results['ram']['cached_percent'] = round( $results['ram']['cached'] * 100 / $results['ram']['total']);
$results['ram']['app'] = $this->grab_key("vm.stats.vm.v_active_count") * $pagesize / 1024;
$results['ram']['app_percent'] = round( $results['ram']['app'] * 100 / $results['ram']['total']);
$results['ram']['buffers'] = $results['ram']['used'] - $results['ram']['app'] - $results['ram']['cached'];
$results['ram']['buffers_percent'] = round( $results['ram']['buffers'] * 100 / $results['ram']['total']);
return $results;
}
}
 
?>
/**
* get the information
*
* @see BSDCommon::build()
*
* @return Void
*/
public function build()
{
parent::build();
if (!$this->blockname || $this->blockname==='vitals') {
$this->_distroicon();
$this->_uptime();
$this->_processes();
}
if (!$this->blockname || $this->blockname==='network') {
$this->_network();
}
if (!$this->blockname || $this->blockname==='memory') {
$this->_memoryadditional();
}
}
}
/web/acc/phpsysinfo/includes/os/class.HPUX.inc.php
0,0 → 1,390
<?php
/**
* HP-UX System Class
*
* PHP version 5
*
* @category PHP
* @package PSI HPUX OS class
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License version 2, or (at your option) any later version
* @version SVN: $Id: class.HPUX.inc.php 596 2012-07-05 19:37:48Z namiltd $
* @link http://phpsysinfo.sourceforge.net
*/
/**
* HP-UX sysinfo class
* get all the required information from HP-UX system
*
* @category PHP
* @package PSI HPUX OS class
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License version 2, or (at your option) any later version
* @version Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
class HPUX extends OS
{
/**
* Virtual Host Name
*
* @return void
*/
private function _hostname()
{
if (PSI_USE_VHOST === true) {
if (CommonFunctions::readenv('SERVER_NAME', $hnm)) $this->sys->setHostname($hnm);
} else {
if (CommonFunctions::executeProgram('hostname', '', $ret)) {
$this->sys->setHostname($ret);
}
}
}
 
/**
* HP-UX Version
*
* @return void
*/
private function _kernel()
{
if (CommonFunctions::executeProgram('uname', '-srvm', $ret)) {
$this->sys->setKernel($ret);
}
}
 
/**
* UpTime
* time the system is running
*
* @return void
*/
private function _uptime()
{
if (CommonFunctions::executeProgram('uptime', '', $buf)) {
if (preg_match("/up (\d+) days,\s*(\d+):(\d+),/", $buf, $ar_buf)) {
$min = $ar_buf[3];
$hours = $ar_buf[2];
$days = $ar_buf[1];
$this->sys->setUptime($days * 86400 + $hours * 3600 + $min * 60);
}
}
}
 
/**
* Processor Load
* optionally create a loadbar
*
* @return void
*/
private function _loadavg()
{
if (CommonFunctions::executeProgram('uptime', '', $buf)) {
if (preg_match("/average: (.*), (.*), (.*)$/", $buf, $ar_buf)) {
$this->sys->setLoad($ar_buf[1].' '.$ar_buf[2].' '.$ar_buf[3]);
}
}
}
 
/**
* CPU information
* All of the tags here are highly architecture dependant
*
* @return void
*/
private function _cpuinfo()
{
if (CommonFunctions::rfts('/proc/cpuinfo', $bufr)) {
$processors = preg_split('/\s?\n\s?\n/', trim($bufr));
foreach ($processors as $processor) {
$dev = new CpuDevice();
$details = preg_split("/\n/", $processor, -1, PREG_SPLIT_NO_EMPTY);
foreach ($details as $detail) {
$arrBuff = preg_split('/\s+:\s+/', trim($detail));
if (count($arrBuff) == 2) {
switch (strtolower($arrBuff[0])) {
case 'model name':
case 'cpu':
$dev->setModel($arrBuff[1]);
break;
case 'cpu mhz':
case 'clock':
$dev->setCpuSpeed($arrBuff[1]);
break;
case 'cycle frequency [hz]':
$dev->setCpuSpeed($arrBuff[1] / 1000000);
break;
case 'cpu0clktck':
$dev->setCpuSpeed(hexdec($arrBuff[1]) / 1000000); // Linux sparc64
break;
case 'l2 cache':
case 'cache size':
$dev->setCache(preg_replace("/[a-zA-Z]/", "", $arrBuff[1]) * 1024);
break;
case 'bogomips':
case 'cpu0bogo':
$dev->setBogomips($arrBuff[1]);
break;
}
}
}
}
}
}
 
/**
* PCI devices
*
* @return void
*/
private function _pci()
{
if (CommonFunctions::rfts('/proc/pci', $bufr)) {
$device = false;
$bufe = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
foreach ($bufe as $buf) {
if (preg_match('/^\s*Bus\s/', $buf)) {
$device = true;
continue;
}
if ($device) {
$dev = new HWDevice();
$dev->setName(preg_replace('/\([^\)]+\)\.$/', '', trim($buf)));
$this->sys->setPciDevices($dev);
/*
list($key, $value) = preg_split('/: /', $buf, 2);
if (!preg_match('/bridge/i', $key) && !preg_match('/USB/i', $key)) {
$dev = new HWDevice();
$dev->setName(preg_replace('/\([^\)]+\)\.$/', '', trim($value)));
$this->sys->setPciDevices($dev);
}
*/
$device = false;
}
}
}
}
 
/**
* IDE devices
*
* @return void
*/
private function _ide()
{
$bufd = CommonFunctions::gdc('/proc/ide', false);
foreach ($bufd as $file) {
if (preg_match('/^hd/', $file)) {
$dev = new HWDevice();
$dev->setName(trim($file));
if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS && CommonFunctions::rfts("/proc/ide/".$file."/media", $buf, 1)) {
if (trim($buf) == 'disk') {
if (CommonFunctions::rfts("/proc/ide/".$file."/capacity", $buf, 1, 4096, false)) {
$dev->setCapacity(trim($buf) * 512);
}
}
}
$this->sys->setIdeDevices($dev);
}
}
}
 
/**
* SCSI devices
*
* @return void
*/
private function _scsi()
{
$get_type = false;
if (CommonFunctions::rfts('/proc/scsi/scsi', $bufr, 0, 4096, PSI_DEBUG)) {
$bufe = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
foreach ($bufe as $buf) {
if (preg_match('/Vendor: (.*) Model: (.*) Rev: (.*)/i', $buf, $dev)) {
$get_type = true;
continue;
}
if ($get_type) {
preg_match('/Type:\s+(\S+)/i', $buf, $dev_type);
$dev = new HWDevice();
$dev->setName($dev[1].' '.$dev[2].' ('.$dev_type[1].')');
$this->sys->setScsiDevices($dev);
$get_type = false;
}
}
}
}
 
/**
* USB devices
*
* @return void
*/
private function _usb()
{
if (CommonFunctions::rfts('/proc/bus/usb/devices', $bufr, 0, 4096, false)) {
$bufe = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
$devnum = -1;
$results = array();
foreach ($bufe as $buf) {
if (preg_match('/^T/', $buf)) {
$devnum++;
$results[$devnum] = "";
} elseif (preg_match('/^S:/', $buf)) {
list($key, $value) = preg_split('/: /', $buf, 2);
list($key, $value2) = preg_split('/=/', $value, 2);
if (trim($key) != "SerialNumber") {
$results[$devnum] .= " ".trim($value2);
}
}
}
foreach ($results as $var) {
$dev = new HWDevice();
$dev->setName($var);
$this->sys->setUsbDevices($dev);
}
}
}
 
/**
* Network devices
* includes also rx/tx bytes
*
* @return void
*/
private function _network()
{
if (CommonFunctions::executeProgram('netstat', '-ni | tail -n +2', $netstat)) {
$lines = preg_split("/\n/", $netstat, -1, PREG_SPLIT_NO_EMPTY);
foreach ($lines as $line) {
$ar_buf = preg_split("/\s+/", $line);
if (! empty($ar_buf[0]) && ! empty($ar_buf[3])) {
$dev = new NetDevice();
$dev->setName($ar_buf[0]);
$dev->setRxBytes($ar_buf[4]);
$dev->setTxBytes($ar_buf[6]);
$dev->setErrors($ar_buf[5] + $ar_buf[7]);
$dev->setDrops($ar_buf[8]);
$this->sys->setNetDevices($dev);
}
}
}
}
 
/**
* Physical memory information and Swap Space information
*
* @return void
*/
private function _memory()
{
if (CommonFunctions::rfts('/proc/meminfo', $bufr)) {
$bufe = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
foreach ($bufe as $buf) {
if (preg_match('/Mem:\s+(.*)$/', $buf, $ar_buf)) {
$ar_buf = preg_split('/\s+/', $ar_buf[1], 6);
$this->sys->setMemTotal($ar_buf[0]);
$this->sys->setMemUsed($ar_buf[1]);
$this->sys->setMemFree($ar_buf[2]);
$this->sys->setMemApplication($ar_buf[3]);
$this->sys->setMemBuffer($ar_buf[4]);
$this->sys->setMemCache($ar_buf[5]);
}
// Get info on individual swap files
if (CommonFunctions::rfts('/proc/swaps', $swaps)) {
$swapdevs = preg_split("/\n/", $swaps, -1, PREG_SPLIT_NO_EMPTY);
for ($i = 1, $max = (sizeof($swapdevs) - 1); $i < $max; $i++) {
$ar_buf = preg_split('/\s+/', $swapdevs[$i], 6);
$dev = new DiskDevice();
$dev->setMountPoint($ar_buf[0]);
$dev->setName("SWAP");
$dev->setFsType('swap');
$dev->setTotal($ar_buf[2] * 1024);
$dev->setUsed($ar_buf[3] * 1024);
$dev->setFree($dev->getTotal() - $dev->getUsed());
$this->sys->setSwapDevices($dev);
}
}
}
}
}
 
/**
* filesystem information
*
* @return void
*/
private function _filesystems()
{
if (CommonFunctions::executeProgram('df', '-kP', $df, PSI_DEBUG)) {
$mounts = preg_split("/\n/", $df, -1, PREG_SPLIT_NO_EMPTY);
if (CommonFunctions::executeProgram('mount', '-v', $s, PSI_DEBUG)) {
$lines = preg_split("/\n/", $s, -1, PREG_SPLIT_NO_EMPTY);
foreach ($lines as $line) {
$a = preg_split('/ /', $line, -1, PREG_SPLIT_NO_EMPTY);
$fsdev[$a[0]] = $a[4];
}
}
foreach ($mounts as $mount) {
$ar_buf = preg_split("/\s+/", $mount, 6);
$dev = new DiskDevice();
$dev->setName($ar_buf[0]);
$dev->setTotal($ar_buf[1] * 1024);
$dev->setUsed($ar_buf[2] * 1024);
$dev->setFree($ar_buf[3] * 1024);
$dev->setMountPoint($ar_buf[5]);
if (isset($fsdev[$ar_buf[0]])) {
$dev->setFsType($fsdev[$ar_buf[0]]);
}
$this->sys->setDiskDevices($dev);
}
}
}
 
/**
* Distribution
*
* @return void
*/
private function _distro()
{
$this->sys->setDistribution('HP-UX');
$this->sys->setDistributionIcon('HPUX.png');
}
 
/**
* get the information
*
* @see PSI_Interface_OS::build()
*
* @return Void
*/
public function build()
{
if (!$this->blockname || $this->blockname==='vitals') {
$this->_distro();
$this->_hostname();
$this->_kernel();
$this->_uptime();
$this->_users();
$this->_loadavg();
}
if (!$this->blockname || $this->blockname==='hardware') {
$this->_cpuinfo();
$this->_pci();
$this->_ide();
$this->_scsi();
$this->_usb();
}
if (!$this->blockname || $this->blockname==='network') {
$this->_network();
}
if (!$this->blockname || $this->blockname==='memory') {
$this->_memory();
}
if (!$this->blockname || $this->blockname==='filesystem') {
$this->_filesystems();
}
}
}
/web/acc/phpsysinfo/includes/os/class.Haiku.inc.php
0,0 → 1,391
<?php
/**
* Haiku System Class
*
* PHP version 5
*
* @category PHP
* @package PSI Haiku OS class
* @author Mieczyslaw Nalewaj <namiltd@users.sourceforge.net>
* @copyright 2012 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License version 2, or (at your option) any later version
* @version SVN: $Id: class.Haiku.inc.php 687 2012-09-06 20:54:49Z namiltd $
* @link http://phpsysinfo.sourceforge.net
*/
/**
* Haiku sysinfo class
* get all the required information from Haiku system
*
* @category PHP
* @package PSI Haiku OS class
* @author Mieczyslaw Nalewaj <namiltd@users.sourceforge.net>
* @copyright 2012 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License version 2, or (at your option) any later version
* @version Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
class Haiku extends OS
{
/**
* get the cpu information
*
* @return void
*/
protected function _cpuinfo()
{
 
if (CommonFunctions::executeProgram('sysinfo', '-cpu', $bufr, PSI_DEBUG)) {
$cpus = preg_split("/\nCPU #\d+/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
$cpuspeed = "";
foreach ($cpus as $cpu) {
if (preg_match("/^.*running at (\d+)MHz/", $cpu, $ar_buf)) {
$cpuspeed = $ar_buf[1];
} elseif (preg_match("/^: \"(.*)\"/", $cpu, $ar_buf)) {
$dev = new CpuDevice();
$dev->setModel($ar_buf[1]);
$arrLines = preg_split("/\n/", $cpu, -1, PREG_SPLIT_NO_EMPTY);
foreach ($arrLines as $Line) {
if (preg_match("/^\s+Data TLB:\s+(.*)K-byte/", $Line, $Line_buf)) {
$dev->setCache(max($Line_buf[1]*1024, $dev->getCache()));
} elseif (preg_match("/^\s+Data TLB:\s+(.*)M-byte/", $Line, $Line_buf)) {
$dev->setCache(max($Line_buf[1]*1024*1024, $dev->getCache()));
} elseif (preg_match("/^\s+Data TLB:\s+(.*)G-byte/", $Line, $Line_buf)) {
$dev->setCache(max($Line_buf[1]*1024*1024*1024, $dev->getCache()));
} elseif (preg_match("/\s+VMX/", $Line, $Line_buf)) {
$dev->setVirt("vmx");
} elseif (preg_match("/\s+SVM/", $Line, $Line_buf)) {
$dev->setVirt("svm");
}
}
if ($cpuspeed != "") {
$dev->setCpuSpeed($cpuspeed);
}
$this->sys->setCpus($dev);
}
}
}
}
 
/**
* PCI devices
* get the pci device information
*
* @return void
*/
protected function _pci()
{
if (CommonFunctions::executeProgram('listdev', '', $bufr, PSI_DEBUG)) {
// $devices = preg_split("/^device |\ndevice /", $bufr, -1, PREG_SPLIT_NO_EMPTY);
$devices = preg_split("/^device /m", $bufr, -1, PREG_SPLIT_NO_EMPTY);
foreach ($devices as $device) {
$ar_buf = preg_split("/\n/", $device);
if (count($ar_buf) >= 3) {
if (preg_match("/^([^\(\[\n]*)/", $device, $ar_buf2)) {
if (preg_match("/^[^\(]*\((.*)\)/", $device, $ar_buf3)) {
$ar_buf2[1] = $ar_buf3[1];
}
$name = trim($ar_buf2[1]).": ";
 
if (preg_match("/^\s+vendor\s+[0-9a-fA-F]{4}:\s+(.*)/", $ar_buf[1], $ar_buf3)) {
$name .=$ar_buf3[1]." ";
}
if (preg_match("/^\s+device\s+[0-9a-fA-F]{4}:\s+(.*)/", $ar_buf[2], $ar_buf3)) {
$name .=$ar_buf3[1]." ";
}
$dev = new HWDevice();
$dev->setName(trim($name));
$this->sys->setPciDevices($dev);
}
}
}
}
}
 
/**
* USB devices
* get the usb device information
*
* @return void
*/
protected function _usb()
{
if (CommonFunctions::executeProgram('listusb', '', $bufr, PSI_DEBUG)) {
$devices = preg_split("/\n/", $bufr);
foreach ($devices as $device) {
if (preg_match("/^\S+\s+\S+\s+\"(.*)\"\s+\"(.*)\"/", $device, $ar_buf)) {
$dev = new HWDevice();
$dev->setName(trim($ar_buf[1]." ".$ar_buf[2]));
$this->sys->setUSBDevices($dev);
}
}
}
}
 
/**
* Haiku Version
*
* @return void
*/
private function _kernel()
{
if (CommonFunctions::executeProgram('uname', '-rvm', $ret)) {
$this->sys->setKernel($ret);
}
}
 
/**
* Distribution
*
* @return void
*/
protected function _distro()
{
if (CommonFunctions::executeProgram('uname', '-sr', $ret))
$this->sys->setDistribution($ret);
else
$this->sys->setDistribution('Haiku');
 
$this->sys->setDistributionIcon('Haiku.png');
}
 
/**
* UpTime
* time the system is running
*
* @return void
*/
private function _uptime()
{
if (CommonFunctions::executeProgram('uptime', '-u', $buf)) {
if (preg_match("/^up (\d+) minute[s]?/", $buf, $ar_buf)) {
$min = $ar_buf[1];
$this->sys->setUptime($min * 60);
} elseif (preg_match("/^up (\d+) hour[s]?, (\d+) minute[s]?/", $buf, $ar_buf)) {
$min = $ar_buf[2];
$hours = $ar_buf[1];
$this->sys->setUptime($hours * 3600 + $min * 60);
} elseif (preg_match("/^up (\d+) day[s]?, (\d+) hour[s]?, (\d+) minute[s]?/", $buf, $ar_buf)) {
$min = $ar_buf[3];
$hours = $ar_buf[2];
$days = $ar_buf[1];
$this->sys->setUptime($days * 86400 + $hours * 3600 + $min * 60);
}
}
}
 
/**
* Processor Load
* optionally create a loadbar
*
* @return void
*/
private function _loadavg()
{
if (CommonFunctions::executeProgram('top', '-n 1 -i 1', $buf)) {
if (preg_match("/\s+(\S+)%\s+TOTAL\s+\(\S+%\s+idle time/", $buf, $ar_buf)) {
$this->sys->setLoad($ar_buf[1]);
if (PSI_LOAD_BAR) {
$this->sys->setLoadPercent(round($ar_buf[1]));
}
}
}
}
 
/**
* Number of Users
*
* @return void
*/
protected function _users()
{
$this->sys->setUsers(1);
}
 
/**
* Virtual Host Name
*
* @return void
*/
private function _hostname()
{
if (PSI_USE_VHOST === true) {
if (CommonFunctions::readenv('SERVER_NAME', $hnm)) $this->sys->setHostname($hnm);
} else {
if (CommonFunctions::executeProgram('uname', '-n', $result, PSI_DEBUG)) {
$ip = gethostbyname($result);
if ($ip != $result) {
$this->sys->setHostname(gethostbyaddr($ip));
}
}
}
}
 
/**
* Physical memory information and Swap Space information
*
* @return void
*/
private function _memory()
{
if (CommonFunctions::executeProgram('sysinfo', '-mem', $bufr, PSI_DEBUG)) {
if (preg_match("/(.*)bytes free\s+\(used\/max\s+(.*)\s+\/\s+(.*)\)\s*\n\s+\(cached\s+(.*)\)/", $bufr, $ar_buf)) {
$this->sys->setMemTotal($ar_buf[3]);
$this->sys->setMemFree($ar_buf[1]);
$this->sys->setMemCache($ar_buf[4]);
$this->sys->setMemUsed($ar_buf[2]);
}
}
if (CommonFunctions::executeProgram('vmstat', '', $bufr, PSI_DEBUG)) {
if (preg_match("/max swap space:\s+(.*)\nfree swap space:\s+(.*)\n/", $bufr, $ar_buf)) {
if ($ar_buf[1]>0) {
$dev = new DiskDevice();
$dev->setMountPoint("/boot/common/var/swap");
$dev->setName("SWAP");
$dev->setTotal($ar_buf[1]);
$dev->setFree($ar_buf[2]);
$dev->setUSed($ar_buf[1]-$ar_buf[2]);
$this->sys->setSwapDevices($dev);
}
}
}
}
 
/**
* filesystem information
*
* @return void
*/
private function _filesystems()
{
if (CommonFunctions::executeProgram('df', '-b', $df, PSI_DEBUG)) {
$df = preg_split("/\n/", $df, -1, PREG_SPLIT_NO_EMPTY);
foreach ($df as $df_line) {
$ar_buf = preg_split("/\s+/", $df_line);
if ((substr($df_line, 0, 1) == "/") && (count($ar_buf) == 6)) {
$dev = new DiskDevice();
$dev->setMountPoint($ar_buf[0]);
$dev->setName($ar_buf[5]);
$dev->setFsType($ar_buf[1]);
$dev->setOptions($ar_buf[4]);
$dev->setTotal($ar_buf[2] * 1024);
$dev->setFree($ar_buf[3] * 1024);
$dev->setUsed($dev->getTotal() - $dev->getFree());
$this->sys->setDiskDevices($dev);
}
}
}
}
 
/**
* network information
*
* @return void
*/
private function _network()
{
if (CommonFunctions::executeProgram('ifconfig', '', $bufr, PSI_DEBUG)) {
$lines = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
$was = false;
$errors = 0;
$drops = 0;
$dev = null;
foreach ($lines as $line) {
if (preg_match("/^(\S+)/", $line, $ar_buf)) {
if ($was) {
$dev->setErrors($errors);
$dev->setDrops($drops);
$this->sys->setNetDevices($dev);
}
$errors = 0;
$drops = 0;
$dev = new NetDevice();
$dev->setName($ar_buf[1]);
$was = true;
} else {
if ($was) {
if (preg_match('/\sReceive:\s\d+\spackets,\s(\d+)\serrors,\s(\d+)\sbytes,\s\d+\smcasts,\s(\d+)\sdropped/i', $line, $ar_buf2)) {
$errors +=$ar_buf2[1];
$drops +=$ar_buf2[3];
$dev->setRxBytes($ar_buf2[2]);
} elseif (preg_match('/\sTransmit:\s\d+\spackets,\s(\d+)\serrors,\s(\d+)\sbytes,\s\d+\smcasts,\s(\d+)\sdropped/i', $line, $ar_buf2)) {
$errors +=$ar_buf2[1];
$drops +=$ar_buf2[3];
$dev->setTxBytes($ar_buf2[2]);
}
 
if (defined('PSI_SHOW_NETWORK_INFOS') && (PSI_SHOW_NETWORK_INFOS)) {
if (preg_match('/\sEthernet,\s+Address:\s(\S*)/i', $line, $ar_buf2)) {
if (!defined('PSI_HIDE_NETWORK_MACADDR') || !PSI_HIDE_NETWORK_MACADDR) $dev->setInfo(preg_replace('/:/', '-', strtoupper($ar_buf2[1])));
} elseif (preg_match('/^\s+inet\saddr:\s(\S*),/i', $line, $ar_buf2)) {
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$ar_buf2[1]);
} elseif (preg_match('/^\s+inet6\saddr:\s(\S*),/i', $line, $ar_buf2)
&& ($ar_buf2[1]!="::") && !preg_match('/^fe80::/i', $ar_buf2[1])) {
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').strtolower($ar_buf2[1]));
}
}
}
}
}
if ($was) {
$dev->setErrors($errors);
$dev->setDrops($drops);
$this->sys->setNetDevices($dev);
}
}
}
 
/**
* Processes
*
* @return void
*/
protected function _processes()
{
if (CommonFunctions::executeProgram('ps', '', $bufr, PSI_DEBUG)) {
$lines = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
$processes['*'] = 0;
foreach ($lines as $line) {
if (preg_match("/^(kernel_team|\/)/", $line, $ar_buf)) {
$processes['*']++;
}
}
if ($processes['*'] > 0) {
$processes[' '] = $processes['*'];
$this->sys->setProcesses($processes);
}
}
}
 
/**
* get the information
*
* @return Void
*/
public function build()
{
$this->error->addError("WARN", "The Haiku version of phpSysInfo is a work in progress, some things currently don't work");
if (!$this->blockname || $this->blockname==='vitals') {
$this->_distro();
$this->_hostname();
$this->_kernel();
$this->_uptime();
$this->_users();
$this->_loadavg();
$this->_processes();
}
if (!$this->blockname || $this->blockname==='hardware') {
$this->_cpuinfo();
$this->_pci();
$this->_usb();
}
if (!$this->blockname || $this->blockname==='network') {
$this->_network();
}
if (!$this->blockname || $this->blockname==='memory') {
$this->_memory();
}
if (!$this->blockname || $this->blockname==='filesystem') {
$this->_filesystems();
}
}
}
/web/acc/phpsysinfo/includes/os/class.Linux.inc.php
1,553 → 1,1693
<?php
// phpSysInfo - A PHP System Information Script
// http://phpsysinfo.sourceforge.net/
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
// $Id: class.Linux.inc.php,v 1.88 2007/02/25 20:50:52 bigmichi1 Exp $
<?php
/**
* Linux System Class
*
* PHP version 5
*
* @category PHP
* @package PSI Linux OS class
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License version 2, or (at your option) any later version
* @version SVN: $Id: class.Linux.inc.php 712 2012-12-05 14:09:18Z namiltd $
* @link http://phpsysinfo.sourceforge.net
*/
/**
* Linux sysinfo class
* get all the required information from Linux system
*
* @category PHP
* @package PSI Linux OS class
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License version 2, or (at your option) any later version
* @version Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
class Linux extends OS
{
/**
* Assoc array of all CPUs loads.
*/
protected $_cpu_loads;
 
if (!defined('IN_PHPSYSINFO')) {
die("No Hacking");
}
/**
* Machine
*
* @return void
*/
private function _machine()
{
$machine = "";
if ((CommonFunctions::rfts('/var/log/dmesg', $result, 0, 4096, false)
&& preg_match('/^[\s\[\]\.\d]*DMI:\s*(.*)/m', $result, $ar_buf))
||(CommonFunctions::executeProgram('dmesg', '', $result, false)
&& preg_match('/^[\s\[\]\.\d]*DMI:\s*(.*)/m', $result, $ar_buf))) {
$machine = trim($ar_buf[1]);
} else { //data from /sys/devices/virtual/dmi/id/
$product = "";
$board = "";
$bios = "";
if (CommonFunctions::rfts('/sys/devices/virtual/dmi/id/board_vendor', $buf, 1, 4096, false) && (trim($buf)!="")) {
$machine = trim($buf);
}
if (CommonFunctions::rfts('/sys/devices/virtual/dmi/id/product_name', $buf, 1, 4096, false) && (trim($buf)!="")) {
$product = trim($buf);
}
if (CommonFunctions::rfts('/sys/devices/virtual/dmi/id/board_name', $buf, 1, 4096, false) && (trim($buf)!="")) {
$board = trim($buf);
}
if (CommonFunctions::rfts('/sys/devices/virtual/dmi/id/bios_version', $buf, 1, 4096, false) && (trim($buf)!="")) {
$bios = trim($buf);
}
if (CommonFunctions::rfts('/sys/devices/virtual/dmi/id/bios_date', $buf, 1, 4096, false) && (trim($buf)!="")) {
$bios = trim($bios." ".trim($buf));
}
if ($product != "") {
$machine .= " ".$product;
}
if ($board != "") {
$machine .= "/".$board;
}
if ($bios != "") {
$machine .= ", BIOS ".$bios;
}
}
 
require_once(APP_ROOT . '/includes/os/class.BSD.common.inc.php');
if ($machine != "") {
$machine = trim(preg_replace("/^\/,?/", "", preg_replace("/ ?(To be filled by O\.E\.M\.|System manufacturer|System Product Name|Not Specified) ?/i", "", $machine)));
}
 
class sysinfo {
var $inifile = "distros.ini";
var $icon = "unknown.png";
var $distro = "unknown";
var $parser;
// get the distro name and icon when create the sysinfo object
function sysinfo() {
$this->parser = new Parser();
$this->parser->df_param = 'P';
$list = @parse_ini_file(APP_ROOT . "/" . $this->inifile, true);
if (!$list) {
return;
}
$distro_info = execute_program('lsb_release','-a 2> /dev/null', false); // We have the '2> /dev/null' because Ubuntu gives an error on this command which causes the distro to be unknown
if ( $distro_info != 'ERROR') {
$distro_tmp = explode("\n",$distro_info);
foreach( $distro_tmp as $info ) {
$info_tmp = explode(':', $info, 2);
$distro[ $info_tmp[0] ] = trim($info_tmp[1]);
}
if( !isset( $list[$distro['Distributor ID']] ) ){
return;
}
$this->icon = isset($list[$distro['Distributor ID']]["Image"]) ? $list[$distro['Distributor ID']]["Image"] : $this->icon;
$this->distro = $distro['Description'];
} else { // Fall back in case 'lsb_release' does not exist ;)
foreach ($list as $section => $distribution) {
if (!isset($distribution["Files"])) {
continue;
} else {
foreach (explode(";", $distribution["Files"]) as $filename) {
if (file_exists($filename)) {
$buf = rfts( $filename );
$this->icon = isset($distribution["Image"]) ? $distribution["Image"] : $this->icon;
$this->distro = isset($distribution["Name"]) ? $distribution["Name"] . " " . trim($buf) : trim($buf);
break 2;
}
}
}
}
}
}
// get our apache SERVER_NAME or vhost
function vhostname () {
if (! ($result = getenv('SERVER_NAME'))) {
$result = 'N.A.';
}
return $result;
}
// get the IP address of our vhost name
function vip_addr () {
return gethostbyname($this->vhostname());
}
// get our canonical hostname
function chostname () {
$result = rfts( '/proc/sys/kernel/hostname', 1 );
if ( $result == "ERROR" ) {
$result = "N.A.";
if (CommonFunctions::fileexists($filename="/etc/config/uLinux.conf") // QNAP detection
&& CommonFunctions::rfts($filename, $buf, 0, 4096, false)
&& preg_match("/^Rsync\sModel\s*=\s*QNAP/m", $buf)
&& CommonFunctions::fileexists($filename="/etc/platform.conf") // Platform detection
&& CommonFunctions::rfts($filename, $buf, 0, 4096, false)
&& preg_match("/^DISPLAY_NAME\s*=\s*(\S+)/m", $buf, $mach_buf) && ($mach_buf[1]!=="")) {
if ($machine != "") {
$machine = "QNAP ".$mach_buf[1].' - '.$machine;
} else {
$machine = "QNAP ".$mach_buf[1];
}
}
 
if ($machine != "") {
$this->sys->setMachine($machine);
}
}
//else {
// $result = gethostbyaddr( gethostbyname( trim( $result ) ) );
//}
return $result;
}
// get the IP address of our canonical hostname
function ip_addr () {
if (!($result = getenv('SERVER_ADDR'))) {
$result = gethostbyname($this->chostname());
}
return $result;
}
 
function kernel () {
$buf = rfts( '/proc/version', 1 );
if ( $buf == "ERROR" ) {
$result = "N.A.";
} else {
if (preg_match('/version (.*?) /', $buf, $ar_buf)) {
$result = $ar_buf[1];
/**
* Hostname
*
* @return void
*/
protected function _hostname()
{
if (PSI_USE_VHOST === true) {
if (CommonFunctions::readenv('SERVER_NAME', $hnm)) $this->sys->setHostname($hnm);
} else {
if (CommonFunctions::rfts('/proc/sys/kernel/hostname', $result, 1, 4096, PSI_DEBUG && (PSI_OS != 'Android'))) {
$result = trim($result);
$ip = gethostbyname($result);
if ($ip != $result) {
$this->sys->setHostname(gethostbyaddr($ip));
}
} elseif (CommonFunctions::executeProgram('hostname', '', $ret)) {
$this->sys->setHostname($ret);
}
 
if (preg_match('/SMP/', $buf)) {
$result .= ' (SMP)';
}
}
}
return $result;
}
function uptime () {
$buf = rfts( '/proc/uptime', 1 );
$ar_buf = explode( ' ', $buf );
$result = trim( $ar_buf[0] );
}
}
 
return $result;
}
/**
* Kernel Version
*
* @return void
*/
private function _kernel()
{
$result = "";
if (CommonFunctions::executeProgram($uname="uptrack-uname", '-r', $strBuf, false) || // show effective kernel if ksplice uptrack is installed
CommonFunctions::executeProgram($uname="uname", '-r', $strBuf, PSI_DEBUG)) {
$result = $strBuf;
if (CommonFunctions::executeProgram($uname, '-v', $strBuf, PSI_DEBUG)) {
if (preg_match('/SMP/', $strBuf)) {
$result .= ' (SMP)';
}
}
if (CommonFunctions::executeProgram($uname, '-m', $strBuf, PSI_DEBUG)) {
$result .= ' '.$strBuf;
}
} elseif (CommonFunctions::rfts('/proc/version', $strBuf, 1) && preg_match('/version\s+(\S+)/', $strBuf, $ar_buf)) {
$result = $ar_buf[1];
if (preg_match('/SMP/', $strBuf)) {
$result .= ' (SMP)';
}
}
if ($result != "") {
if (CommonFunctions::rfts('/proc/self/cgroup', $strBuf2, 0, 4096, false)) {
if (preg_match('/:\/lxc\//m', $strBuf2)) {
$result .= ' [lxc]';
} elseif (preg_match('/:\/docker\//m', $strBuf2)) {
$result .= ' [docker]';
} elseif (preg_match('/:\/system\.slice\/docker\-/m', $strBuf2)) {
$result .= ' [docker]';
}
}
if (CommonFunctions::rfts('/proc/version', $strBuf2, 1, 4096, false)
&& preg_match('/^Linux version [\d\.-]+-Microsoft/', $strBuf2)) {
$result .= ' [lxss]';
}
$this->sys->setKernel($result);
}
}
 
function users () {
$strResult = 0;
$strBuf = execute_program('who', '-q');
if( $strBuf != "ERROR" ) {
$arrWho = explode( '=', $strBuf );
$strResult = $arrWho[1];
}
return $strResult;
}
function loadavg ($bar = false) {
$buf = rfts( '/proc/loadavg' );
if( $buf == "ERROR" ) {
$results['avg'] = array('N.A.', 'N.A.', 'N.A.');
} else {
$results['avg'] = preg_split("/\s/", $buf, 4);
unset($results['avg'][3]); // don't need the extra values, only first three
}
if ($bar) {
$buf = rfts( '/proc/stat', 1 );
if( $buf != "ERROR" ) {
sscanf($buf, "%*s %Ld %Ld %Ld %Ld", $ab, $ac, $ad, $ae);
// Find out the CPU load
// user + sys = load
// total = total
$load = $ab + $ac + $ad; // cpu.user + cpu.sys
$total = $ab + $ac + $ad + $ae; // cpu.total
/**
* UpTime
* time the system is running
*
* @return void
*/
protected function _uptime()
{
if (CommonFunctions::rfts('/proc/uptime', $buf, 1, 4096, PSI_OS != 'Android')) {
$ar_buf = preg_split('/ /', $buf);
$this->sys->setUptime(trim($ar_buf[0]));
} elseif (CommonFunctions::executeProgram('uptime', '', $buf)) {
if (preg_match("/up (\d+) day[s]?,[ ]+(\d+):(\d+),/", $buf, $ar_buf)) {
$min = $ar_buf[3];
$hours = $ar_buf[2];
$days = $ar_buf[1];
$this->sys->setUptime($days * 86400 + $hours * 3600 + $min * 60);
} elseif (preg_match("/up (\d+) day[s]?,[ ]+(\d+) min,/", $buf, $ar_buf)) {
$min = $ar_buf[2];
$days = $ar_buf[1];
$this->sys->setUptime($days * 86400 + $min * 60);
} elseif (preg_match("/up[ ]+(\d+):(\d+),/", $buf, $ar_buf)) {
$min = $ar_buf[2];
$hours = $ar_buf[1];
$this->sys->setUptime($hours * 3600 + $min * 60);
} elseif (preg_match("/up[ ]+(\d+) min,/", $buf, $ar_buf)) {
$min = $ar_buf[1];
$this->sys->setUptime($min * 60);
}
}
}
 
// we need a second value, wait 1 second befor getting (< 1 second no good value will occour)
sleep(1);
$buf = rfts( '/proc/stat', 1 );
sscanf($buf, "%*s %Ld %Ld %Ld %Ld", $ab, $ac, $ad, $ae);
$load2 = $ab + $ac + $ad;
$total2 = $ab + $ac + $ad + $ae;
$results['cpupercent'] = (100*($load2 - $load)) / ($total2 - $total);
}
/**
* Processor Load
* optionally create a loadbar
*
* @return void
*/
protected function _loadavg()
{
if (CommonFunctions::rfts('/proc/loadavg', $buf, 1, 4096, PSI_OS != 'Android')) {
$result = preg_split("/\s/", $buf, 4);
// don't need the extra values, only first three
unset($result[3]);
$this->sys->setLoad(implode(' ', $result));
} elseif (CommonFunctions::executeProgram('uptime', '', $buf) && preg_match("/load average: (.*), (.*), (.*)$/", $buf, $ar_buf)) {
$this->sys->setLoad($ar_buf[1].' '.$ar_buf[2].' '.$ar_buf[3]);
}
if (PSI_LOAD_BAR) {
$this->sys->setLoadPercent($this->_parseProcStat('cpu'));
}
}
return $results;
}
 
function cpu_info () {
$bufr = rfts( '/proc/cpuinfo' );
$results = array("cpus" => 0);
if ( $bufr != "ERROR" ) {
$bufe = explode("\n", $bufr);
$results = array('cpus' => 0, 'bogomips' => 0);
$ar_buf = array();
foreach( $bufe as $buf ) {
$arrBuff = preg_split('/\s+:\s+/', trim($buf));
if( count( $arrBuff ) == 2 ) {
$key = $arrBuff[0];
$value = $arrBuff[1];
// All of the tags here are highly architecture dependant.
// the only way I could reconstruct them for machines I don't
// have is to browse the kernel source. So if your arch isn't
// supported, tell me you want it written in.
switch ($key) {
case 'model name':
$results['model'] = $value;
break;
case 'cpu MHz':
$results['cpuspeed'] = sprintf('%.2f', $value);
break;
case 'cycle frequency [Hz]': // For Alpha arch - 2.2.x
$results['cpuspeed'] = sprintf('%.2f', $value / 1000000);
break;
case 'clock': // For PPC arch (damn borked POS)
$results['cpuspeed'] = sprintf('%.2f', $value);
break;
case 'cpu': // For PPC arch (damn borked POS)
$results['model'] = $value;
break;
case 'L2 cache': // More for PPC
$results['cache'] = $value;
break;
case 'revision': // For PPC arch (damn borked POS)
$results['model'] .= ' ( rev: ' . $value . ')';
break;
case 'cpu model': // For Alpha arch - 2.2.x
$results['model'] .= ' (' . $value . ')';
break;
case 'cache size':
$results['cache'] = $value;
break;
case 'bogomips':
$results['bogomips'] += $value;
break;
case 'BogoMIPS': // For alpha arch - 2.2.x
$results['bogomips'] += $value;
break;
case 'BogoMips': // For sparc arch
$results['bogomips'] += $value;
break;
case 'cpus detected': // For Alpha arch - 2.2.x
$results['cpus'] += $value;
break;
case 'system type': // Alpha arch - 2.2.x
$results['model'] .= ', ' . $value . ' ';
break;
case 'platform string': // Alpha arch - 2.2.x
$results['model'] .= ' (' . $value . ')';
break;
case 'processor':
$results['cpus'] += 1;
break;
case 'Cpu0ClkTck': // Linux sparc64
$results['cpuspeed'] = sprintf('%.2f', hexdec($value) / 1000000);
break;
case 'Cpu0Bogo': // Linux sparc64 & sparc32
$results['bogomips'] = $value;
break;
case 'ncpus probed': // Linux sparc64 & sparc32
$results['cpus'] = $value;
break;
}
}
}
// sparc64 specific code follows
// This adds the ability to display the cache that a CPU has
// Originally made by Sven Blumenstein <bazik@gentoo.org> in 2004
// Modified by Tom Weustink <freshy98@gmx.net> in 2004
$sparclist = array('SUNW,UltraSPARC@0,0', 'SUNW,UltraSPARC-II@0,0', 'SUNW,UltraSPARC@1c,0', 'SUNW,UltraSPARC-IIi@1c,0', 'SUNW,UltraSPARC-II@1c,0', 'SUNW,UltraSPARC-IIe@0,0');
foreach ($sparclist as $name) {
$buf = rfts( '/proc/openprom/' . $name . '/ecache-size',1 , 32, false );
if( $buf != "ERROR" ) {
$results['cache'] = base_convert($buf, 16, 10)/1024 . ' KB';
}
}
// sparc64 specific code ends
// XScale detection code
if ( $results['cpus'] == 0 ) {
foreach( $bufe as $buf ) {
$fields = preg_split('/\s*:\s*/', trim($buf), 2);
if (sizeof($fields) == 2) {
list($key, $value) = $fields;
switch($key) {
case 'Processor':
$results['cpus'] += 1;
$results['model'] = $value;
break;
case 'BogoMIPS': //BogoMIPS are not BogoMIPS on this CPU, it's the speed, no BogoMIPS available
$results['cpuspeed'] = $value;
break;
case 'I size':
$results['cache'] = $value;
break;
case 'D size':
$results['cache'] += $value;
break;
}
}
}
$results['cache'] = $results['cache'] / 1024 . " KB";
}
}
$keys = array_keys($results);
$keys2be = array('model', 'cpuspeed', 'cache', 'bogomips', 'cpus');
while ($ar_buf = each($keys2be)) {
if (! in_array($ar_buf[1], $keys)) {
$results[$ar_buf[1]] = 'N.A.';
}
}
$buf = rfts( '/proc/acpi/thermal_zone/THRM/temperature', 1, 4096, false );
if ( $buf != "ERROR" ) {
$results['temp'] = substr( $buf, 25, 2 );
}
return $results;
}
/**
* fill the load for a individual cpu, through parsing /proc/stat for the specified cpu
*
* @param String $cpuline cpu for which load should be meassured
*
* @return Integer
*/
protected function _parseProcStat($cpuline)
{
if (is_null($this->_cpu_loads)) {
$this->_cpu_loads = array();
 
function pci () {
$arrResults = array();
$booDevice = false;
if( ! $arrResults = $this->parser->parse_lspci() ) {
$strBuf = rfts( '/proc/pci', 0, 4096, false );
if( $strBuf != "ERROR" ) {
$arrBuf = explode( "\n", $strBuf );
foreach( $arrBuf as $strLine ) {
if( preg_match( '/Bus/', $strLine ) ) {
$booDevice = true;
continue;
}
if( $booDevice ) {
list( $strKey, $strValue ) = explode( ': ', $strLine, 2 );
if( ! preg_match( '/bridge/i', $strKey ) && ! preg_match( '/USB/i ', $strKey ) ) {
$arrResults[] = preg_replace( '/\([^\)]+\)\.$/', '', trim( $strValue ) );
}
$booDevice = false;
}
}
asort( $arrResults );
}
}
return $arrResults;
}
$cpu_tmp = array();
if (CommonFunctions::rfts('/proc/stat', $buf)) {
if (preg_match_all('/^(cpu[0-9]*) (.*)/m', $buf, $matches, PREG_SET_ORDER)) {
foreach ($matches as $line) {
$cpu = $line[1];
$buf2 = $line[2];
 
function ide () {
$results = array();
$bufd = gdc( '/proc/ide', false );
$cpu_tmp[$cpu] = array();
 
foreach( $bufd as $file ) {
if (preg_match('/^hd/', $file)) {
$results[$file] = array();
$buf = rfts("/proc/ide/" . $file . "/media", 1 );
if ( $buf != "ERROR" ) {
$results[$file]['media'] = trim($buf);
if ($results[$file]['media'] == 'disk') {
$results[$file]['media'] = 'Hard Disk';
$buf = rfts( "/proc/ide/" . $file . "/capacity", 1, 4096, false);
if( $buf == "ERROR" ) {
$buf = rfts( "/sys/block/" . $file . "/size", 1, 4096, false);
}
if ( $buf != "ERROR" ) {
$results[$file]['capacity'] = trim( $buf );
}
} elseif ($results[$file]['media'] == 'cdrom') {
$results[$file]['media'] = 'CD-ROM';
unset($results[$file]['capacity']);
}
$ab = 0;
$ac = 0;
$ad = 0;
$ae = 0;
sscanf($buf2, "%Ld %Ld %Ld %Ld", $ab, $ac, $ad, $ae);
$cpu_tmp[$cpu]['load'] = $ab + $ac + $ad; // cpu.user + cpu.sys
$cpu_tmp[$cpu]['total'] = $ab + $ac + $ad + $ae; // cpu.total
}
}
 
// we need a second value, wait 1 second befor getting (< 1 second no good value will occour)
sleep(1);
 
if (CommonFunctions::rfts('/proc/stat', $buf)) {
if (preg_match_all('/^(cpu[0-9]*) (.*)/m', $buf, $matches, PREG_SET_ORDER)) {
foreach ($matches as $line) {
$cpu = $line[1];
if (isset($cpu_tmp[$cpu])) {
$buf2 = $line[2];
 
$ab = 0;
$ac = 0;
$ad = 0;
$ae = 0;
sscanf($buf2, "%Ld %Ld %Ld %Ld", $ab, $ac, $ad, $ae);
$load2 = $ab + $ac + $ad; // cpu.user + cpu.sys
$total2 = $ab + $ac + $ad + $ae; // cpu.total
$total = $cpu_tmp[$cpu]['total'];
$load = $cpu_tmp[$cpu]['load'];
$this->_cpu_loads[$cpu] = 0;
if ($total > 0 && $total2 > 0 && $load > 0 && $load2 > 0 && $total2 != $total && $load2 != $load) {
$this->_cpu_loads[$cpu] = (100 * ($load2 - $load)) / ($total2 - $total);
}
}
}
}
}
}
}
 
if (isset($this->_cpu_loads[$cpuline])) {
return $this->_cpu_loads[$cpuline];
} else {
unset($results[$file]);
}
return 0;
}
}
 
$buf = rfts( "/proc/ide/" . $file . "/model", 1 );
if ( $buf != "ERROR" ) {
$results[$file]['model'] = trim( $buf );
if (preg_match('/WDC/', $results[$file]['model'])) {
$results[$file]['manufacture'] = 'Western Digital';
} elseif (preg_match('/IBM/', $results[$file]['model'])) {
$results[$file]['manufacture'] = 'IBM';
} elseif (preg_match('/FUJITSU/', $results[$file]['model'])) {
$results[$file]['manufacture'] = 'Fujitsu';
} else {
$results[$file]['manufacture'] = 'Unknown';
}
}
}
}
/**
* CPU information
* All of the tags here are highly architecture dependant.
*
* @return void
*/
protected function _cpuinfo()
{
if (CommonFunctions::rfts('/proc/cpuinfo', $bufr)) {
$cpulist = null;
$raslist = null;
 
asort($results);
return $results;
}
// sparc
if (preg_match('/\nCpu(\d+)Bogo\s*:/i', $bufr)) {
$bufr = preg_replace('/\nCpu(\d+)ClkTck\s*:/i', "\nCpu0ClkTck:", preg_replace('/\nCpu(\d+)Bogo\s*:/i', "\n\nprocessor: $1\nCpu0Bogo:", $bufr));
} else {
$bufr = preg_replace('/\nCpu(\d+)ClkTck\s*:/i', "\n\nprocessor: $1\nCpu0ClkTck:", $bufr);
}
 
function scsi () {
$results = array();
$dev_vendor = '';
$dev_model = '';
$dev_rev = '';
$dev_type = '';
$s = 1;
$get_type = 0;
if (preg_match('/\nprocessor\s*:\s*\d+\r?\nprocessor\s*:\s*\d+/', $bufr)) {
$bufr = preg_replace('/^(processor\s*:\s*\d+)\r?$/m', "$1\n", $bufr);
}
 
$bufr = execute_program('lsscsi', '-c', false);
if( $bufr == "ERROR" ) {
$bufr = rfts( '/proc/scsi/scsi', 0, 4096, false);
// IBM/S390
$bufr = preg_replace('/\ncpu number\s*:\s*(\d+)\r?\ncpu MHz dynamic\s*:\s*(\d+)/m', "\nprocessor:$1\nclock:$2", $bufr);
 
$processors = preg_split('/\s?\n\s?\n/', trim($bufr));
 
//first stage
$_arch = null;
$_impl = null;
$_part = null;
$_hard = null;
$_revi = null;
$_cpus = null;
$_buss = null;
$_bogo = null;
$_vend = null;
$procname = null;
foreach ($processors as $processor) if (!preg_match('/^\s*processor\s*:/mi', $processor)) {
$details = preg_split("/\n/", $processor, -1, PREG_SPLIT_NO_EMPTY);
foreach ($details as $detail) {
$arrBuff = preg_split('/\s*:\s*/', trim($detail));
if ((count($arrBuff) == 2) && (($arrBuff1 = trim($arrBuff[1])) !== '')) {
switch (strtolower($arrBuff[0])) {
case 'cpu architecture':
$_arch = $arrBuff1;
break;
case 'cpu implementer':
$_impl = $arrBuff1;
break;
case 'cpu part':
$_part = $arrBuff1;
break;
case 'hardware':
$_hard = $arrBuff1;
break;
case 'revision':
$_revi = $arrBuff1;
break;
case 'cpu frequency':
if (preg_match('/^(\d+)\s+Hz/i', $arrBuff1, $bufr2)) {
$_cpus = round($bufr2[1]/1000000);
}
break;
case 'system bus frequency':
if (preg_match('/^(\d+)\s+Hz/i', $arrBuff1, $bufr2)) {
$_buss = round($bufr2[1]/1000000);
}
break;
case 'bogomips per cpu':
$_bogo = round($arrBuff1);
break;
case 'vendor_id':
$_vend = $arrBuff1;
case 'cpu':
$procname = $arrBuff1;
break;
}
}
}
}
 
//second stage
$cpucount = 0;
$speedset = false;
foreach ($processors as $processor) if (preg_match('/^\s*processor\s*:/mi', $processor)) {
$proc = null;
$arch = null;
$impl = null;
$part = null;
$dev = new CpuDevice();
$details = preg_split("/\n/", $processor, -1, PREG_SPLIT_NO_EMPTY);
foreach ($details as $detail) {
$arrBuff = preg_split('/\s*:\s*/', trim($detail));
if ((count($arrBuff) == 2) && (($arrBuff1 = trim($arrBuff[1])) !== '')) {
switch (strtolower($arrBuff[0])) {
case 'processor':
$proc = $arrBuff1;
if (is_numeric($proc)) {
if (strlen($procname)>0) {
$dev->setModel($procname);
}
} else {
$procname = $proc;
$dev->setModel($procname);
}
break;
case 'model name':
case 'cpu model':
case 'cpu type':
case 'cpu':
$dev->setModel($arrBuff1);
break;
case 'cpu mhz':
case 'clock':
if ($arrBuff1 > 0) { //openSUSE fix
$dev->setCpuSpeed($arrBuff1);
$speedset = true;
}
break;
case 'cpu mhz static':
if ($arrBuff1 > 0) { //openSUSE fix
$dev->setCpuSpeedMax($arrBuff1);
}
break;
case 'cycle frequency [hz]':
$dev->setCpuSpeed($arrBuff1 / 1000000);
$speedset = true;
break;
case 'cpu0clktck':
$dev->setCpuSpeed(hexdec($arrBuff1) / 1000000); // Linux sparc64
$speedset = true;
break;
case 'l3 cache':
case 'cache size':
$dev->setCache(trim(preg_replace("/[a-zA-Z]/", "", $arrBuff1)) * 1024);
break;
case 'initial bogomips':
case 'bogomips':
case 'cpu0bogo':
$dev->setBogomips(round($arrBuff1));
break;
case 'flags':
if (preg_match("/ vmx/", $arrBuff1)) {
$dev->setVirt("vmx");
} elseif (preg_match("/ svm/", $arrBuff1)) {
$dev->setVirt("svm");
} elseif (preg_match("/ hypervisor/", $arrBuff1)) {
$dev->setVirt("hypervisor");
}
break;
case 'i size':
case 'd size':
if ($dev->getCache() === null) {
$dev->setCache($arrBuff1 * 1024);
} else {
$dev->setCache($dev->getCache() + ($arrBuff1 * 1024));
}
break;
case 'cpu architecture':
$arch = $arrBuff1;
break;
case 'cpu implementer':
$impl = $arrBuff1;
break;
case 'cpu part':
$part = $arrBuff1;
break;
case 'vendor_id':
$dev->setVendorId($arrBuff1);
break;
}
}
}
if ($arch === null) $arch = $_arch;
if ($impl === null) $impl = $_impl;
if ($part === null) $part = $_part;
 
// sparc64 specific code follows
// This adds the ability to display the cache that a CPU has
// Originally made by Sven Blumenstein <bazik@gentoo.org> in 2004
// Modified by Tom Weustink <freshy98@gmx.net> in 2004
$sparclist = array('SUNW,UltraSPARC@0,0', 'SUNW,UltraSPARC-II@0,0', 'SUNW,UltraSPARC@1c,0', 'SUNW,UltraSPARC-IIi@1c,0', 'SUNW,UltraSPARC-II@1c,0', 'SUNW,UltraSPARC-IIe@0,0');
foreach ($sparclist as $name) {
if (CommonFunctions::rfts('/proc/openprom/'.$name.'/ecache-size', $buf, 1, 32, false)) {
$dev->setCache(base_convert(trim($buf), 16, 10));
}
}
// sparc64 specific code ends
 
// XScale detection code
if (($arch === "5TE") && ($dev->getBogomips() != null)) {
$dev->setCpuSpeed($dev->getBogomips()); //BogoMIPS are not BogoMIPS on this CPU, it's the speed
$speedset = true;
$dev->setBogomips(null); // no BogoMIPS available, unset previously set BogoMIPS
}
 
if (($dev->getBusSpeed() == 0) && ($_buss !== null)) {
$dev->setBusSpeed($_buss);
}
if (($dev->getCpuSpeed() == 0) && ($_cpus !== null)) {
$dev->setCpuSpeed($_cpus);
$speedset = true;
}
if (($dev->getBogomips() == 0) && ($_bogo !== null)) {
$dev->setBogomips($_bogo);
}
if (($dev->getVendorId() === null) && ($_vend !== null)) {
$dev->setVendorId($_vend);
}
 
if ($proc != null) {
if (!is_numeric($proc)) {
$proc = 0;
}
// variable speed processors specific code follows
if (CommonFunctions::rfts('/sys/devices/system/cpu/cpu'.$proc.'/cpufreq/cpuinfo_cur_freq', $buf, 1, 4096, false)) {
$dev->setCpuSpeed(trim($buf) / 1000);
$speedset = true;
} elseif (CommonFunctions::rfts('/sys/devices/system/cpu/cpu'.$proc.'/cpufreq/scaling_cur_freq', $buf, 1, 4096, false)) {
$dev->setCpuSpeed(trim($buf) / 1000);
$speedset = true;
}
if (CommonFunctions::rfts('/sys/devices/system/cpu/cpu'.$proc.'/cpufreq/cpuinfo_max_freq', $buf, 1, 4096, false)) {
$dev->setCpuSpeedMax(trim($buf) / 1000);
}
if (CommonFunctions::rfts('/sys/devices/system/cpu/cpu'.$proc.'/cpufreq/cpuinfo_min_freq', $buf, 1, 4096, false)) {
$dev->setCpuSpeedMin(trim($buf) / 1000);
}
// variable speed processors specific code ends
if (PSI_LOAD_BAR) {
$dev->setLoad($this->_parseProcStat('cpu'.$proc));
}
/*
if (CommonFunctions::rfts('/proc/acpi/thermal_zone/THRM/temperature', $buf, 1, 4096, false)
&& preg_match("/(\S+)\sC$/", $buf, $value)) {
$dev->setTemp(value[1]);
}
*/
if (($arch !== null) && ($impl !== null) && ($part !== null)) {
if (($impl === '0x41')
&& (($_hard === 'BCM2708') || ($_hard === 'BCM2835') || ($_hard === 'BCM2709') || ($_hard === 'BCM2836') || ($_hard === 'BCM2710') || ($_hard === 'BCM2837') || ($_hard === 'BCM2711') || ($_hard === 'BCM2838'))
&& ($_revi !== null)) { // Raspberry Pi detection (instead of 'cat /proc/device-tree/model')
if ($raslist === null) $raslist = @parse_ini_file(PSI_APP_ROOT."/data/raspberry.ini", true);
if ($raslist && !preg_match('/[^0-9a-f]/', $_revi)) {
if (($revidec = hexdec($_revi)) & 0x800000) {
if ($this->sys->getMachine() === '') {
$manufacturer = ($revidec >> 16) & 15;
if (isset($raslist['manufacturer'][$manufacturer])) {
$manuf = ' '.$raslist['manufacturer'][$manufacturer];
} else {
$manuf = '';
}
$model = ($revidec >> 4) & 255;
if (isset($raslist['model'][$model])) {
$this->sys->setMachine('Raspberry Pi '.$raslist['model'][$model].' (PCB 1.'.($revidec & 15).$manuf.')');
} else {
$this->sys->setMachine('Raspberry Pi (PCB 1.'.($revidec & 15).$manuf.')');
}
}
} else {
if ($this->sys->getMachine() === '') {
if (isset($raslist['old'][$revidec & 0x7fffff])) {
$this->sys->setMachine('Raspberry Pi '.$raslist['old'][$revidec & 0x7fffff]);
} else {
$this->sys->setMachine('Raspberry Pi');
}
}
}
}
} elseif (($_hard !== null) && ($this->sys->getMachine() === '')) { // other ARM hardware
$this->sys->setMachine($_hard);
}
if ($cpulist === null) $cpulist = @parse_ini_file(PSI_APP_ROOT."/data/cpus.ini", true);
if ($cpulist && (isset($cpulist['cpu'][$cpuimplpart = strtolower($impl.','.$part)]))) {
if (($cpumodel = $dev->getModel()) !== '') {
$dev->setModel($cpumodel.' - '.$cpulist['cpu'][$cpuimplpart]);
} else {
$dev->setModel($cpulist['cpu'][$cpuimplpart]);
}
}
} elseif (($_hard !== null) && ($this->sys->getMachine() === '')) { // other hardware
$this->sys->setMachine($_hard);
}
 
if ($dev->getModel() === "") {
$dev->setModel("unknown");
}
$cpucount++;
$this->sys->setCpus($dev);
}
}
 
$cpudevices = glob('/sys/devices/system/cpu/cpu*/uevent', GLOB_NOSORT);
if (is_array($cpudevices) && (($cpustopped = count($cpudevices)-$cpucount) > 0)) {
for (; $cpustopped > 0; $cpustopped--) {
$dev = new CpuDevice();
$dev->setModel("stopped");
if ($speedset) {
$dev->setCpuSpeed(-1);
}
$this->sys->setCpus($dev);
}
}
}
}
if ( $bufr != "ERROR" ) {
$bufe = explode("\n", $bufr);
foreach( $bufe as $buf ) {
if (preg_match('/Vendor/', $buf)) {
preg_match('/Vendor: (.*) Model: (.*) Rev: (.*)/i', $buf, $dev);
list($key, $value) = explode(': ', $buf, 2);
$dev_str = $value;
$get_type = true;
continue;
}
 
if ($get_type) {
preg_match('/Type:\s+(\S+)/i', $buf, $dev_type);
$results[$s]['model'] = "$dev[1] $dev[2] ($dev_type[1])";
$results[$s]['media'] = "Hard Disk";
$s++;
$get_type = false;
}
}
}
asort($results);
return $results;
}
/**
* PCI devices
*
* @return void
*/
private function _pci()
{
if ($arrResults = Parser::lspci()) {
foreach ($arrResults as $dev) {
$this->sys->setPciDevices($dev);
}
} elseif (CommonFunctions::rfts('/proc/pci', $strBuf, 0, 4096, false)) {
$booDevice = false;
$arrBuf = preg_split("/\n/", $strBuf, -1, PREG_SPLIT_NO_EMPTY);
foreach ($arrBuf as $strLine) {
if (preg_match('/^\s*Bus\s/', $strLine)) {
$booDevice = true;
continue;
}
if ($booDevice) {
$dev = new HWDevice();
$dev->setName(preg_replace('/\([^\)]+\)\.$/', '', trim($strLine)));
$this->sys->setPciDevices($dev);
/*
list($strKey, $strValue) = preg_split('/: /', $strLine, 2);
if (!preg_match('/bridge/i', $strKey) && !preg_match('/USB/i ', $strKey)) {
$dev = new HWDevice();
$dev->setName(preg_replace('/\([^\)]+\)\.$/', '', trim($strValue)));
$this->sys->setPciDevices($dev);
}
*/
$booDevice = false;
}
}
} else {
$pcidevices = glob('/sys/bus/pci/devices/*/uevent', GLOB_NOSORT);
if (is_array($pcidevices) && (($total = count($pcidevices)) > 0)) {
$buf = "";
for ($i = 0; $i < $total; $i++) {
if (CommonFunctions::rfts($pcidevices[$i], $buf, 0, 4096, false) && (trim($buf) != "")) {
$pcibuf = "";
if (preg_match("/^PCI_CLASS=(\S+)/m", trim($buf), $subbuf)) {
$pcibuf = "Class ".$subbuf[1].":";
}
if (preg_match("/^PCI_ID=(\S+)/m", trim($buf), $subbuf)) {
$pcibuf .= " Device ".$subbuf[1];
}
if (preg_match("/^DRIVER=(\S+)/m", trim($buf), $subbuf)) {
$pcibuf .= " Driver ".$subbuf[1];
}
$dev = new HWDevice();
if (trim($pcibuf) != "") {
$dev->setName(trim($pcibuf));
} else {
$dev->setName("unknown");
}
$this->sys->setPciDevices($dev);
}
}
}
}
}
 
function usb () {
$results = array();
$devnum = -1;
/**
* IDE devices
*
* @return void
*/
private function _ide()
{
$bufd = CommonFunctions::gdc('/proc/ide', false);
foreach ($bufd as $file) {
if (preg_match('/^hd/', $file)) {
$dev = new HWDevice();
$dev->setName(trim($file));
if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS && CommonFunctions::rfts("/proc/ide/".$file."/media", $buf, 1)) {
if (trim($buf) == 'disk') {
if (CommonFunctions::rfts("/proc/ide/".$file."/capacity", $buf, 1, 4096, false) || CommonFunctions::rfts("/sys/block/".$file."/size", $buf, 1, 4096, false)) {
$dev->setCapacity(trim($buf) * 512);
}
}
}
if (CommonFunctions::rfts("/proc/ide/".$file."/model", $buf, 1)) {
$dev->setName($dev->getName().": ".trim($buf));
}
$this->sys->setIdeDevices($dev);
}
}
}
 
$bufr = execute_program('lsusb', '', false);
if( $bufr == "ERROR" ) {
$bufr = rfts( '/proc/bus/usb/devices', 0, 4096, false );
if ( $bufr != "ERROR" ) {
$bufe = explode("\n", $bufr);
foreach( $bufe as $buf ) {
if (preg_match('/^T/', $buf)) {
$devnum += 1;
$results[$devnum] = "";
} elseif (preg_match('/^S:/', $buf)) {
list($key, $value) = explode(': ', $buf, 2);
list($key, $value2) = explode('=', $value, 2);
if (trim($key) != "SerialNumber") {
$results[$devnum] .= " " . trim($value2);
$devstring = 0;
}
}
/**
* SCSI devices
*
* @return void
*/
private function _scsi()
{
$getline = 0;
$device = null;
$scsiid = null;
if (CommonFunctions::executeProgram('lsscsi', '-c', $bufr, PSI_DEBUG) || CommonFunctions::rfts('/proc/scsi/scsi', $bufr, 0, 4096, PSI_DEBUG)) {
$bufe = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
foreach ($bufe as $buf) {
if (preg_match('/Host: scsi(\d+) Channel: (\d+) Target: (\d+) Lun: (\d+)/i', $buf, $scsiids)
|| preg_match('/Host: scsi(\d+) Channel: (\d+) Id: (\d+) Lun: (\d+)/i', $buf, $scsiids)) {
$scsiid = $scsiids;
$getline = 1;
continue;
}
if ($getline == 1) {
preg_match('/Vendor: (.*) Model: (.*) Rev: (.*)/i', $buf, $devices);
$getline = 2;
$device = $devices;
continue;
}
if ($getline == 2) {
preg_match('/Type:\s+(\S+)/i', $buf, $dev_type);
 
$dev = new HWDevice();
$dev->setName($device[1].' '.$device[2].' ('.$dev_type[1].')');
 
if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS
&& ($dev_type[1]==='Direct-Access')) {
$sizelist = glob('/sys/bus/scsi/devices/'.intval($scsiid[1]).':'.intval($scsiid[2]).':'.intval($scsiid[3]).':'.intval($scsiid[4]).'/*/*/size', GLOB_NOSORT);
if (is_array($sizelist) && (($total = count($sizelist)) > 0)) {
$buf = "";
for ($i = 0; $i < $total; $i++) {
if (CommonFunctions::rfts($sizelist[$i], $buf, 1, 4096, false) && (($buf=trim($buf)) != "") && ($buf > 0)) {
$dev->setCapacity($buf * 512);
break;
}
}
}
}
$this->sys->setScsiDevices($dev);
$getline = 0;
}
}
}
} else {
$bufe = explode( "\n", $bufr );
foreach( $bufe as $buf ) {
$device = preg_split("/ /", $buf, 7);
if( isset( $device[6] ) && trim( $device[6] ) != "" ) {
$results[$devnum++] = trim( $device[6] );
}
}
}
}
return $results;
}
 
function sbus () {
$results = array();
$_results[0] = "";
// TODO. Nothing here yet. Move along.
$results = $_results;
return $results;
}
/**
* USB devices
*
* @return void
*/
protected function _usb()
{
$usbarray = array();
if (CommonFunctions::executeProgram('lsusb', (PSI_OS != 'Android')?'':'2>/dev/null', $bufr, PSI_DEBUG && (PSI_OS != 'Android'), 5) && ($bufr !== "")) {
$bufe = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
foreach ($bufe as $buf) {
$device = preg_split("/ /", $buf, 7);
if (((isset($device[6]) && trim($device[6]) != "")) ||
((isset($device[5]) && trim($device[5]) != ""))) {
$usbid = intval($device[1]).'-'.intval(trim($device[3],':')).' '.$device[5];
if ((isset($device[6]) && trim($device[6]) != "")) {
$usbarray[$usbid]['name'] = trim($device[6]);
} else {
$usbarray[$usbid]['name'] = 'unknown';
}
}
}
}
 
function network () {
$results = array();
$usbdevices = glob('/sys/bus/usb/devices/*/idProduct', GLOB_NOSORT);
if (is_array($usbdevices) && (($total = count($usbdevices)) > 0)) {
for ($i = 0; $i < $total; $i++) {
if (CommonFunctions::rfts($usbdevices[$i], $idproduct, 1, 4096, false) && (($idproduct=trim($idproduct)) != "")) { //is readable
$busnum = CommonFunctions::rolv($usbdevices[$i], '/\/idProduct$/', '/busnum');
$devnum = CommonFunctions::rolv($usbdevices[$i], '/\/idProduct$/', '/devnum');
$idvendor = CommonFunctions::rolv($usbdevices[$i], '/\/idProduct$/', '/idVendor');
if (($busnum!==null) && ($devnum!==null) && ($idvendor!==null)) {
$usbid = intval($busnum).'-'.intval($devnum).' '.$idvendor.':'.$idproduct;
$manufacturer = CommonFunctions::rolv($usbdevices[$i], '/\/idProduct$/', '/manufacturer');
if ($manufacturer!==null) {
$usbarray[$usbid]['manufacturer'] = $manufacturer;
}
$product = CommonFunctions::rolv($usbdevices[$i], '/\/idProduct$/', '/product');
if ($product!==null) {
$usbarray[$usbid]['product'] = $product;
}
if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS
&& defined('PSI_SHOW_DEVICES_SERIAL') && PSI_SHOW_DEVICES_SERIAL) {
$serial = CommonFunctions::rolv($usbdevices[$i], '/\/idProduct$/', '/serial');
if (($serial!==null) && !preg_match('/\W/', $serial)) {
$usbarray[$usbid]['serial'] = $serial;
}
}
}
}
}
}
 
$bufr = rfts( '/proc/net/dev' );
if ( $bufr != "ERROR" ) {
$bufe = explode("\n", $bufr);
foreach( $bufe as $buf ) {
if (preg_match('/:/', $buf)) {
list($dev_name, $stats_list) = preg_split('/:/', $buf, 2);
$stats = preg_split('/\s+/', trim($stats_list));
$results[$dev_name] = array();
if ((count($usbarray) == 0) && CommonFunctions::rfts('/proc/bus/usb/devices', $bufr, 0, 4096, false)) {
$devnum = -1;
$bufe = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
foreach ($bufe as $buf) {
if (preg_match('/^T/', $buf)) {
$devnum++;
} elseif (preg_match('/^S:/', $buf)) {
list($key, $value) = preg_split('/: /', $buf, 2);
list($key, $value2) = preg_split('/=/', $value, 2);
switch (trim($key)) {
case 'Manufacturer':
$usbarray[$devnum]['manufacturer'] = trim($value2);
break;
case 'Product':
$usbarray[$devnum]['product'] = trim($value2);
break;
case 'SerialNumber':
if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS
&& defined('PSI_SHOW_DEVICES_SERIAL') && PSI_SHOW_DEVICES_SERIAL
&& !preg_match('/\W/', trim($value2))) {
$usbarray[$devnum]['serial'] = trim($value2);
}
break;
}
}
}
}
 
$results[$dev_name]['rx_bytes'] = $stats[0];
$results[$dev_name]['rx_packets'] = $stats[1];
$results[$dev_name]['rx_errs'] = $stats[2];
$results[$dev_name]['rx_drop'] = $stats[3];
if ((count($usbarray) == 0) && CommonFunctions::rfts('/proc/bus/input/devices', $bufr, 0, 4096, false)) {
$devnam = "unknown";
$bufe = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
foreach ($bufe as $buf) {
if (preg_match('/^I:\s+(.+)/', $buf, $bufr)
&& isset($bufr[1]) && (trim($bufr[1])!=="")) {
$devnam = trim($bufr[1]);
$usbarray[$devnam]['phys'] = 'unknown';
} elseif (preg_match('/^N:\s+Name="([^"]+)"/', $buf, $bufr2)
&& isset($bufr2[1]) && (trim($bufr2[1])!=="")) {
$usbarray[$devnam]['name'] = trim($bufr2[1]);
} elseif (preg_match('/^P:\s+Phys=(.*)/', $buf, $bufr2)
&& isset($bufr2[1]) && (trim($bufr2[1])!=="")) {
$usbarray[$devnam]['phys'] = trim($bufr2[1]);
} elseif (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS
&& defined('PSI_SHOW_DEVICES_SERIAL') && PSI_SHOW_DEVICES_SERIAL
&& preg_match('/^U:\s+Uniq=(.+)/', $buf, $bufr2)
&& isset($bufr2[1]) && (trim($bufr2[1])!=="")) {
$usbarray[$devnam]['serial'] = trim($bufr2[1]);
}
}
}
 
$results[$dev_name]['tx_bytes'] = $stats[8];
$results[$dev_name]['tx_packets'] = $stats[9];
$results[$dev_name]['tx_errs'] = $stats[10];
$results[$dev_name]['tx_drop'] = $stats[11];
foreach ($usbarray as $usbdev) if (!isset($usbdev['phys']) || preg_match('/^usb-/', $usbdev['phys'])) {
$dev = new HWDevice();
 
$results[$dev_name]['errs'] = $stats[2] + $stats[10];
$results[$dev_name]['drop'] = $stats[3] + $stats[11];
}
}
if (isset($usbdev['manufacturer']) && (($manufacturer=$usbdev['manufacturer']) !== 'no manufacturer')) {
if (preg_match("/^linux\s/i", $manufacturer)) {
$manufacturer = 'Linux Foundation';
}
if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS) {
$dev->setManufacturer($manufacturer);
}
} else {
$manufacturer = '';
}
 
if (isset($usbdev['product'])) {
$product = $usbdev['product'];
if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS) {
$dev->setProduct($product);
}
} else {
$product = '';
}
 
if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS
&& defined('PSI_SHOW_DEVICES_SERIAL') && PSI_SHOW_DEVICES_SERIAL
&& isset($usbdev['serial'])) {
$dev->setSerial($usbdev['serial']);
}
 
if (isset($usbdev['name']) && (($name=$usbdev['name']) !== 'unknown')) {
$dev->setName($name);
} else {
if (($newname = trim($manufacturer.' '.$product)) !== '') {
$dev->setName($newname);
} else {
$dev->setName('unknown');
}
}
 
$this->sys->setUsbDevices($dev);
}
}
return $results;
}
 
function memory () {
$results['ram'] = array('total' => 0, 'free' => 0, 'used' => 0, 'percent' => 0);
$results['swap'] = array('total' => 0, 'free' => 0, 'used' => 0, 'percent' => 0);
$results['devswap'] = array();
/**
* I2C devices
*
* @return void
*/
protected function _i2c()
{
$i2cdevices = glob('/sys/bus/i2c/devices/*/name', GLOB_NOSORT);
if (is_array($i2cdevices) && (($total = count($i2cdevices)) > 0)) {
$buf = "";
for ($i = 0; $i < $total; $i++) {
if (CommonFunctions::rfts($i2cdevices[$i], $buf, 1, 4096, false) && (trim($buf) != "")) {
$dev = new HWDevice();
$dev->setName(trim($buf));
$this->sys->setI2cDevices($dev);
}
}
}
}
 
$bufr = rfts( '/proc/meminfo' );
if ( $bufr != "ERROR" ) {
$bufe = explode("\n", $bufr);
foreach( $bufe as $buf ) {
if (preg_match('/^MemTotal:\s+(.*)\s*kB/i', $buf, $ar_buf)) {
$results['ram']['total'] = $ar_buf[1];
} else if (preg_match('/^MemFree:\s+(.*)\s*kB/i', $buf, $ar_buf)) {
$results['ram']['free'] = $ar_buf[1];
} else if (preg_match('/^Cached:\s+(.*)\s*kB/i', $buf, $ar_buf)) {
$results['ram']['cached'] = $ar_buf[1];
} else if (preg_match('/^Buffers:\s+(.*)\s*kB/i', $buf, $ar_buf)) {
$results['ram']['buffers'] = $ar_buf[1];
}
}
/**
* NVMe devices
*
* @return void
*/
protected function _nvme()
{
if (CommonFunctions::executeProgram('nvme', 'list', $bufr, PSI_DEBUG) && ($bufr!="")) {
$bufe = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
$count = 0;
$nlocate = array();
$nsize = array();
foreach ($bufe as $buf) {
if ($count == 1) {
$locid = 0;
$nlocate[0] = 0;
$total = strlen($buf);
$begin = true;
for ($i = 0; $i < $total; $i++) {
if ($begin) {
if ($buf[$i] !== '-') {
$nsize[$locid] = $i - $nlocate[$locid];
$locid++;
$begin = false;
}
} else {
if ($buf[$i] === '-') {
$nlocate[$locid] = $i;
$begin = true;
}
}
}
if ($begin) {
$nsize[$locid] = $i - $nlocate[$locid];
}
} elseif ($count > 1) {
if (isset($nlocate[2]) && isset($nsize[2])) {
$dev = new HWDevice();
$dev->setName(trim(substr($buf, $nlocate[2], $nsize[2])));
if (defined('PSI_SHOW_DEVICES_INFOS') && (PSI_SHOW_DEVICES_INFOS)) {
if (isset($nlocate[4]) && isset($nsize[4])) {
if (preg_match('/\/\s*([0-9\.]+)\s*(B|KB|MB|GB|TB|PB)$/', str_replace(',', '.', trim(substr($buf, $nlocate[4], $nsize[4]))), $tmpbuf)) {
switch ($tmpbuf[2]) {
case 'B':
$dev->setCapacity($tmpbuf[1]);
break;
case 'KB':
$dev->setCapacity(1000*$tmpbuf[1]);
break;
case 'MB':
$dev->setCapacity(1000*1000*$tmpbuf[1]);
break;
case 'GB':
$dev->setCapacity(1000*1000*1000*$tmpbuf[1]);
break;
case 'TB':
$dev->setCapacity(1000*1000*1000*1000*$tmpbuf[1]);
break;
case 'PB':
$dev->setCapacity(1000*1000*1000*1000*1000*$tmpbuf[1]);
break;
}
}
}
if (defined('PSI_SHOW_DEVICES_SERIAL') && PSI_SHOW_DEVICES_SERIAL) {
if (isset($nlocate[1]) && isset($nsize[1])) {
$dev->setSerial(trim(substr($buf, $nlocate[1], $nsize[1])));
}
}
}
$this->sys->setNvmeDevices($dev);
}
}
$count++;
}
}
}
 
$results['ram']['used'] = $results['ram']['total'] - $results['ram']['free'];
$results['ram']['percent'] = round(($results['ram']['used'] * 100) / $results['ram']['total']);
// values for splitting memory usage
if (isset($results['ram']['cached']) && isset($results['ram']['buffers'])) {
$results['ram']['app'] = $results['ram']['used'] - $results['ram']['cached'] - $results['ram']['buffers'];
$results['ram']['app_percent'] = round(($results['ram']['app'] * 100) / $results['ram']['total']);
$results['ram']['buffers_percent'] = round(($results['ram']['buffers'] * 100) / $results['ram']['total']);
$results['ram']['cached_percent'] = round(($results['ram']['cached'] * 100) / $results['ram']['total']);
}
/**
* Network devices
* includes also rx/tx bytes
*
* @return void
*/
protected function _network()
{
if (CommonFunctions::rfts('/proc/net/dev', $bufr, 0, 4096, PSI_DEBUG)) {
$bufe = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
foreach ($bufe as $buf) {
if (preg_match('/:/', $buf)) {
list($dev_name, $stats_list) = preg_split('/:/', $buf, 2);
$stats = preg_split('/\s+/', trim($stats_list));
$dev = new NetDevice();
$dev->setName(trim($dev_name));
$dev->setRxBytes($stats[0]);
$dev->setTxBytes($stats[8]);
$dev->setErrors($stats[2] + $stats[10]);
$dev->setDrops($stats[3] + $stats[11]);
if (defined('PSI_SHOW_NETWORK_INFOS') && (PSI_SHOW_NETWORK_INFOS)) {
$macaddr = "";
if ((CommonFunctions::executeProgram('ip', 'addr show '.trim($dev_name), $bufr2, PSI_DEBUG) && ($bufr2!=""))
|| CommonFunctions::executeProgram('ifconfig', trim($dev_name).' 2>/dev/null', $bufr2, PSI_DEBUG)) {
$bufe2 = preg_split("/\n/", $bufr2, -1, PREG_SPLIT_NO_EMPTY);
foreach ($bufe2 as $buf2) {
// if (preg_match('/^'.trim($dev_name).'\s+Link\sencap:Ethernet\s+HWaddr\s(\S+)/i', $buf2, $ar_buf2)
if (preg_match('/\s+encap:Ethernet\s+HWaddr\s(\S+)/i', $buf2, $ar_buf2)
|| preg_match('/\s+encap:UNSPEC\s+HWaddr\s(\S+)-00-00-00-00-00-00-00-00-00-00\s*$/i', $buf2, $ar_buf2)
|| preg_match('/^\s+ether\s+(\S+)\s+txqueuelen/i', $buf2, $ar_buf2)
|| preg_match('/^\s+link\/ether\s+(\S+)\s+brd/i', $buf2, $ar_buf2)
|| preg_match('/^\s+link\/ether\s+(\S+)$/i', $buf2, $ar_buf2)
|| preg_match('/^\s+link\/ieee802.11\s+(\S+)$/i', $buf2, $ar_buf2)) {
if (!defined('PSI_HIDE_NETWORK_MACADDR') || !PSI_HIDE_NETWORK_MACADDR) {
$macaddr = preg_replace('/:/', '-', strtoupper($ar_buf2[1]));
if ($macaddr === '00-00-00-00-00-00') { // empty
$macaddr = "";
}
}
} elseif (preg_match('/^\s+inet\saddr:(\S+)\s+P-t-P:(\S+)/i', $buf2, $ar_buf2)
|| preg_match('/^\s+inet\s+(\S+)\s+netmask.+destination\s+(\S+)/i', $buf2, $ar_buf2)
|| preg_match('/^\s+inet\s+([^\/\s]+).*peer\s+([^\/\s]+).*\s+scope\s((global)|(host))/i', $buf2, $ar_buf2)) {
if ($ar_buf2[1] != $ar_buf2[2]) {
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$ar_buf2[1].";:".$ar_buf2[2]);
} else {
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$ar_buf2[1]);
}
} elseif ((preg_match('/^\s+inet\saddr:(\S+)/i', $buf2, $ar_buf2)
|| preg_match('/^\s+inet\s+(\S+)\s+netmask/i', $buf2, $ar_buf2)
|| preg_match('/^'.trim($dev_name).':\s+ip\s+(\S+)\s+mask/i', $buf2, $ar_buf2)
|| preg_match('/^\s+inet6\saddr:\s([^\/\s]+)(.+)\s+Scope:[GH]/i', $buf2, $ar_buf2)
|| preg_match('/^\s+inet6\s+(\S+)\s+prefixlen(.+)((<global>)|(<host>))/i', $buf2, $ar_buf2)
|| preg_match('/^\s+inet6?\s+([^\/\s]+).*\s+scope\s((global)|(host))/i', $buf2, $ar_buf2))
&& ($ar_buf2[1]!="::") && !preg_match('/^fe80::/i', $ar_buf2[1])) {
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').strtolower($ar_buf2[1]));
}
}
}
if ($macaddr != "") {
$dev->setInfo($macaddr.($dev->getInfo()?';'.$dev->getInfo():''));
}
if (CommonFunctions::rfts('/sys/class/net/'.trim($dev_name).'/speed', $buf, 1, 4096, false) && (($speed=trim($buf))!="") && ($buf > 0) && ($buf < 65535)) {
if ($speed > 1000) {
$speed = $speed/1000;
$unit = "G";
} else {
$unit = "M";
}
if (CommonFunctions::rfts('/sys/class/net/'.trim($dev_name).'/duplex', $buf, 1, 4096, false) && (($duplex=strtolower(trim($buf)))!="") && ($duplex!='unknown')) {
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$speed.$unit.'b/s '.$duplex);
} else {
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$speed.$unit.'b/s');
}
}
}
$this->sys->setNetDevices($dev);
}
}
} elseif (CommonFunctions::executeProgram('ip', 'addr show', $bufr, PSI_DEBUG) && ($bufr!="")) {
$lines = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
$was = false;
$macaddr = "";
$speedinfo = "";
$dev = null;
foreach ($lines as $line) {
if (preg_match("/^\d+:\s+([^\s:]+)/", $line, $ar_buf)) {
if ($was) {
if ($macaddr != "") {
$dev->setInfo($macaddr.($dev->getInfo()?';'.$dev->getInfo():''));
}
if ($speedinfo != "") {
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$speedinfo);
}
$this->sys->setNetDevices($dev);
}
$speedinfo = "";
$macaddr = "";
$dev = new NetDevice();
$dev->setName($ar_buf[1]);
if (CommonFunctions::executeProgram('ip', '-s link show '.$ar_buf[1], $bufr2, PSI_DEBUG) && ($bufr2!="")
&& preg_match("/\n\s+RX:\s[^\n]+\n\s+(\d+)\s+\d+\s+(\d+)\s+(\d+)[^\n]+\n\s+TX:\s[^\n]+\n\s+(\d+)\s+\d+\s+(\d+)\s+(\d+)/m", $bufr2, $ar_buf2)) {
$dev->setRxBytes($ar_buf2[1]);
$dev->setTxBytes($ar_buf2[4]);
$dev->setErrors($ar_buf2[2]+$ar_buf2[5]);
$dev->setDrops($ar_buf2[3]+$ar_buf2[6]);
}
$was = true;
if (defined('PSI_SHOW_NETWORK_INFOS') && (PSI_SHOW_NETWORK_INFOS)) {
if (CommonFunctions::rfts('/sys/class/net/'.$ar_buf[1].'/speed', $buf, 1, 4096, false) && (trim($buf)!="")) {
$speed = trim($buf);
if ($speed > 1000) {
$speed = $speed/1000;
$unit = "G";
} else {
$unit = "M";
}
if (CommonFunctions::rfts('/sys/class/net/'.$ar_buf[1].'/duplex', $buf, 1, 4096, false) && (trim($buf)!="")) {
$speedinfo = $speed.$unit.'b/s '.strtolower(trim($buf));
} else {
$speedinfo = $speed.$unit.'b/s';
}
}
}
} else {
if ($was) {
if (defined('PSI_SHOW_NETWORK_INFOS') && (PSI_SHOW_NETWORK_INFOS)) {
if (preg_match('/^\s+link\/ether\s+(\S+)\s+brd/i', $line, $ar_buf2)) {
if (!defined('PSI_HIDE_NETWORK_MACADDR') || !PSI_HIDE_NETWORK_MACADDR) $macaddr = preg_replace('/:/', '-', strtoupper($ar_buf2[1]));
} elseif (preg_match('/^\s+inet\s+([^\/\s]+).*peer\s+([^\/\s]+).*\s+scope\s((global)|(host))/i', $line, $ar_buf2)) {
if ($ar_buf2[1] != $ar_buf2[2]) {
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$ar_buf2[1].";:".$ar_buf2[2]);
} else {
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$ar_buf2[1]);
}
} elseif (preg_match('/^\s+inet6?\s+([^\/\s]+).*\s+scope\s((global)|(host))/i', $line, $ar_buf2)
&& ($ar_buf2[1]!="::") && !preg_match('/^fe80::/i', $ar_buf2[1])) {
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').strtolower($ar_buf2[1]));
}
}
}
}
}
if ($was) {
if ($macaddr != "") {
$dev->setInfo($macaddr.($dev->getInfo()?';'.$dev->getInfo():''));
}
if ($speedinfo != "") {
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$speedinfo);
}
$this->sys->setNetDevices($dev);
}
} elseif (CommonFunctions::executeProgram('ifconfig', '-a', $bufr, PSI_DEBUG)) {
$lines = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
$was = false;
$errors = 0;
$drops = 0;
$macaddr = "";
$speedinfo = "";
$dev = null;
foreach ($lines as $line) {
if (preg_match("/^([^\s:]+)/", $line, $ar_buf)) {
if ($was) {
$dev->setErrors($errors);
$dev->setDrops($drops);
if ($macaddr != "") {
$dev->setInfo($macaddr.($dev->getInfo()?';'.$dev->getInfo():''));
}
if ($speedinfo != "") {
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$speedinfo);
}
$this->sys->setNetDevices($dev);
}
$errors = 0;
$drops = 0;
$speedinfo = "";
$macaddr = "";
$dev = new NetDevice();
$dev->setName($ar_buf[1]);
$was = true;
if (defined('PSI_SHOW_NETWORK_INFOS') && (PSI_SHOW_NETWORK_INFOS)) {
if (CommonFunctions::rfts('/sys/class/net/'.$ar_buf[1].'/speed', $buf, 1, 4096, false) && (trim($buf)!="")) {
$speed = trim($buf);
if ($speed > 1000) {
$speed = $speed/1000;
$unit = "G";
} else {
$unit = "M";
}
if (CommonFunctions::rfts('/sys/class/net/'.$ar_buf[1].'/duplex', $buf, 1, 4096, false) && (trim($buf)!="")) {
$speedinfo = $speed.$unit.'b/s '.strtolower(trim($buf));
} else {
$speedinfo = $speed.$unit.'b/s';
}
}
if (preg_match('/^'.$ar_buf[1].'\s+Link\sencap:Ethernet\s+HWaddr\s(\S+)/i', $line, $ar_buf2))
if (!defined('PSI_HIDE_NETWORK_MACADDR') || !PSI_HIDE_NETWORK_MACADDR) $macaddr = preg_replace('/:/', '-', strtoupper($ar_buf2[1]));
elseif (preg_match('/^'.$ar_buf[1].':\s+ip\s+(\S+)\s+mask/i', $line, $ar_buf2))
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$ar_buf2[1]);
}
} else {
if ($was) {
if (preg_match('/\sRX bytes:(\d+)\s/i', $line, $ar_buf2)) {
$dev->setRxBytes($ar_buf2[1]);
}
if (preg_match('/\sTX bytes:(\d+)\s/i', $line, $ar_buf2)) {
$dev->setTxBytes($ar_buf2[1]);
}
 
$bufr = rfts( '/proc/swaps' );
if ( $bufr != "ERROR" ) {
$swaps = explode("\n", $bufr);
for ($i = 1; $i < (sizeof($swaps)); $i++) {
if( trim( $swaps[$i] ) != "" ) {
$ar_buf = preg_split('/\s+/', $swaps[$i], 6);
$results['devswap'][$i - 1] = array();
$results['devswap'][$i - 1]['dev'] = $ar_buf[0];
$results['devswap'][$i - 1]['total'] = $ar_buf[2];
$results['devswap'][$i - 1]['used'] = $ar_buf[3];
$results['devswap'][$i - 1]['free'] = ($results['devswap'][$i - 1]['total'] - $results['devswap'][$i - 1]['used']);
$results['devswap'][$i - 1]['percent'] = round(($ar_buf[3] * 100) / $ar_buf[2]);
$results['swap']['total'] += $ar_buf[2];
$results['swap']['used'] += $ar_buf[3];
$results['swap']['free'] = $results['swap']['total'] - $results['swap']['used'];
$results['swap']['percent'] = round(($results['swap']['used'] * 100) / $results['swap']['total']);
}
}
}
if (preg_match('/\sRX packets:\d+\serrors:(\d+)\sdropped:(\d+)/i', $line, $ar_buf2)) {
$errors +=$ar_buf2[1];
$drops +=$ar_buf2[2];
} elseif (preg_match('/\sTX packets:\d+\serrors:(\d+)\sdropped:(\d+)/i', $line, $ar_buf2)) {
$errors +=$ar_buf2[1];
$drops +=$ar_buf2[2];
}
 
if (defined('PSI_SHOW_NETWORK_INFOS') && (PSI_SHOW_NETWORK_INFOS)) {
if (preg_match('/\s+encap:Ethernet\s+HWaddr\s(\S+)/i', $line, $ar_buf2)
|| preg_match('/^\s+ether\s+(\S+)\s+txqueuelen/i', $line, $ar_buf2)) {
if (!defined('PSI_HIDE_NETWORK_MACADDR') || !PSI_HIDE_NETWORK_MACADDR) $macaddr = preg_replace('/:/', '-', strtoupper($ar_buf2[1]));
} elseif (preg_match('/^\s+inet\saddr:(\S+)\s+P-t-P:(\S+)/i', $line, $ar_buf2)
|| preg_match('/^\s+inet\s+(\S+)\s+netmask.+destination\s+(\S+)/i', $line, $ar_buf2)) {
if ($ar_buf2[1] != $ar_buf2[2]) {
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$ar_buf2[1].";:".$ar_buf2[2]);
} else {
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$ar_buf2[1]);
}
} elseif ((preg_match('/^\s+inet\saddr:(\S+)/i', $line, $ar_buf2)
|| preg_match('/^\s+inet\s+(\S+)\s+netmask/i', $line, $ar_buf2)
|| preg_match('/^\s+inet6\saddr:\s([^\/\s]+)(.+)\s+Scope:[GH]/i', $line, $ar_buf2)
|| preg_match('/^\s+inet6\s+(\S+)\s+prefixlen(.+)((<global>)|(<host>))/i', $line, $ar_buf2))
&& ($ar_buf2[1]!="::") && !preg_match('/^fe80::/i', $ar_buf2[1])) {
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').strtolower($ar_buf2[1]));
}
}
}
}
}
if ($was) {
$dev->setErrors($errors);
$dev->setDrops($drops);
if ($macaddr != "") {
$dev->setInfo($macaddr.($dev->getInfo()?';'.$dev->getInfo():''));
}
if ($speedinfo != "") {
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$speedinfo);
}
$this->sys->setNetDevices($dev);
}
}
}
return $results;
}
function filesystems () {
return $this->parser->parse_filesystems();
}
 
function distro () {
return $this->distro;
}
/**
* Physical memory information and Swap Space information
*
* @return void
*/
protected function _memory()
{
if (CommonFunctions::rfts('/proc/meminfo', $mbuf)) {
$bufe = preg_split("/\n/", $mbuf, -1, PREG_SPLIT_NO_EMPTY);
foreach ($bufe as $buf) {
if (preg_match('/^MemTotal:\s+(\d+)\s*kB/i', $buf, $ar_buf)) {
$this->sys->setMemTotal($ar_buf[1] * 1024);
} elseif (preg_match('/^MemFree:\s+(\d+)\s*kB/i', $buf, $ar_buf)) {
$this->sys->setMemFree($ar_buf[1] * 1024);
} elseif (preg_match('/^Cached:\s+(\d+)\s*kB/i', $buf, $ar_buf)) {
$this->sys->setMemCache($ar_buf[1] * 1024);
} elseif (preg_match('/^Buffers:\s+(\d+)\s*kB/i', $buf, $ar_buf)) {
$this->sys->setMemBuffer($ar_buf[1] * 1024);
}
}
$this->sys->setMemUsed($this->sys->getMemTotal() - $this->sys->getMemFree());
// values for splitting memory usage
if ($this->sys->getMemCache() !== null && $this->sys->getMemBuffer() !== null) {
$this->sys->setMemApplication($this->sys->getMemUsed() - $this->sys->getMemCache() - $this->sys->getMemBuffer());
}
if (CommonFunctions::rfts('/proc/swaps', $sbuf, 0, 4096, false)) {
$swaps = preg_split("/\n/", $sbuf, -1, PREG_SPLIT_NO_EMPTY);
unset($swaps[0]);
foreach ($swaps as $swap) {
$ar_buf = preg_split('/\s+/', $swap, 5);
$dev = new DiskDevice();
$dev->setMountPoint($ar_buf[0]);
$dev->setName("SWAP");
$dev->setTotal($ar_buf[2] * 1024);
$dev->setUsed($ar_buf[3] * 1024);
$dev->setFree($dev->getTotal() - $dev->getUsed());
$this->sys->setSwapDevices($dev);
}
}
}
}
 
function distroicon () {
return $this->icon;
}
/**
* filesystem information
*
* @return void
*/
private function _filesystems()
{
$df_args = "";
$hideFstypes = array();
if (defined('PSI_HIDE_FS_TYPES') && is_string(PSI_HIDE_FS_TYPES)) {
if (preg_match(ARRAY_EXP, PSI_HIDE_FS_TYPES)) {
$hideFstypes = eval(PSI_HIDE_FS_TYPES);
} else {
$hideFstypes = array(PSI_HIDE_FS_TYPES);
}
}
foreach ($hideFstypes as $Fstype) {
$df_args .= "-x $Fstype ";
}
if ($df_args !== "") {
$df_args = trim($df_args); //trim spaces
$arrResult = Parser::df("-P $df_args 2>/dev/null");
} else {
$arrResult = Parser::df("-P 2>/dev/null");
}
foreach ($arrResult as $dev) {
$this->sys->setDiskDevices($dev);
}
}
 
}
/**
* Distribution
*
* @return void
*/
protected function _distro()
{
$this->sys->setDistribution("Linux");
$list = @parse_ini_file(PSI_APP_ROOT."/data/distros.ini", true);
if (!$list) {
return;
}
// We have the '2>/dev/null' because Ubuntu gives an error on this command which causes the distro to be unknown
if (CommonFunctions::executeProgram('lsb_release', '-a 2>/dev/null', $distro_info, PSI_DEBUG) && (strlen($distro_info) > 0)) {
$distro_tmp = preg_split("/\n/", $distro_info, -1, PREG_SPLIT_NO_EMPTY);
foreach ($distro_tmp as $info) {
$info_tmp = preg_split('/:/', $info, 2);
if (isset($distro_tmp[0]) && !is_null($distro_tmp[0]) && (trim($distro_tmp[0]) != "") &&
isset($distro_tmp[1]) && !is_null($distro_tmp[1]) && (trim($distro_tmp[1]) != "")) {
$distro[trim($info_tmp[0])] = trim($info_tmp[1]);
}
}
if (!isset($distro['Distributor ID']) && !isset($distro['Description'])) { // Systems like StartOS
if (isset($distro_tmp[0]) && !is_null($distro_tmp[0]) && (trim($distro_tmp[0]) != "")) {
$this->sys->setDistribution(trim($distro_tmp[0]));
if (preg_match('/^(\S+)\s*/', $distro_tmp[0], $id_buf)
&& isset($list[trim($id_buf[1])]['Image'])) {
$this->sys->setDistributionIcon($list[trim($id_buf[1])]['Image']);
}
}
} else {
if (isset($distro['Description'])
&& preg_match('/^NAME=\s*"?([^"\n]+)"?\s*$/', $distro['Description'], $name_tmp)) {
$distro['Description'] = $name_tmp[1];
}
if (isset($distro['Description'])
&& ($distro['Description'] != "n/a")
&& (!isset($distro['Distributor ID'])
|| (($distro['Distributor ID'] != "n/a")
&& ($distro['Description'] != $distro['Distributor ID'])))) {
$this->sys->setDistribution($distro['Description']);
if (isset($distro['Release']) && ($distro['Release'] != "n/a")
&& ($distro['Release'] != $distro['Description']) && strstr($distro['Release'], ".")){
if (preg_match("/^(\d+)\.[0]+$/", $distro['Release'], $match_buf)) {
$tofind = $match_buf[1];
} else {
$tofind = $distro['Release'];
}
if (!preg_match("/^".$tofind."[\s\.]|[\(\[]".$tofind."[\.\)\]]|\s".$tofind."$|\s".$tofind."[\s\.]/", $distro['Description'])) {
$this->sys->setDistribution($this->sys->getDistribution()." ".$distro['Release']);
}
}
} elseif (isset($distro['Distributor ID']) && ($distro['Distributor ID'] != "n/a")) {
$this->sys->setDistribution($distro['Distributor ID']);
if (isset($distro['Release']) && ($distro['Release'] != "n/a")) {
$this->sys->setDistribution($this->sys->getDistribution()." ".$distro['Release']);
}
if (isset($distro['Codename']) && ($distro['Codename'] != "n/a")) {
$this->sys->setDistribution($this->sys->getDistribution()." (".$distro['Codename'].")");
}
}
if (isset($distro['Distributor ID']) && ($distro['Distributor ID'] != "n/a") && isset($list[$distro['Distributor ID']]['Image'])) {
$this->sys->setDistributionIcon($list[$distro['Distributor ID']]['Image']);
} elseif (isset($distro['Description']) && ($distro['Description'] != "n/a")) {
$this->sys->setDistribution($distro['Description']);
if (isset($list[$distro['Description']]['Image'])) {
$this->sys->setDistributionIcon($list[$distro['Description']]['Image']);
}
}
}
} else {
/* default error handler */
if (function_exists('errorHandlerPsi')) {
restore_error_handler();
}
/* fatal errors only */
$old_err_rep = error_reporting();
error_reporting(E_ERROR);
 
?>
// Fall back in case 'lsb_release' does not exist but exist /etc/lsb-release
if (CommonFunctions::fileexists($filename="/etc/lsb-release")
&& CommonFunctions::rfts($filename, $buf, 0, 4096, false)
&& preg_match('/^DISTRIB_ID="?([^"\n]+)"?/m', $buf, $id_buf)) {
if (preg_match('/^DISTRIB_DESCRIPTION="?([^"\n]+)"?/m', $buf, $desc_buf)
&& (trim($desc_buf[1])!=trim($id_buf[1]))) {
$this->sys->setDistribution(trim($desc_buf[1]));
if (preg_match('/^DISTRIB_RELEASE="?([^"\n]+)"?/m', $buf, $vers_buf)
&& (trim($vers_buf[1])!=trim($desc_buf[1])) && strstr($vers_buf[1], ".")){
if (preg_match("/^(\d+)\.[0]+$/", trim($vers_buf[1]), $match_buf)) {
$tofind = $match_buf[1];
} else {
$tofind = trim($vers_buf[1]);
}
if (!preg_match("/^".$tofind."[\s\.]|[\(\[]".$tofind."[\.\)\]]|\s".$tofind."$|\s".$tofind."[\s\.]/", trim($desc_buf[1]))) {
$this->sys->setDistribution($this->sys->getDistribution()." ".trim($vers_buf[1]));
}
}
} else {
if (isset($list[trim($id_buf[1])]['Name'])) {
$this->sys->setDistribution(trim($list[trim($id_buf[1])]['Name']));
} else {
$this->sys->setDistribution(trim($id_buf[1]));
}
if (preg_match('/^DISTRIB_RELEASE="?([^"\n]+)"?/m', $buf, $vers_buf)) {
$this->sys->setDistribution($this->sys->getDistribution()." ".trim($vers_buf[1]));
}
if (preg_match('/^DISTRIB_CODENAME="?([^"\n]+)"?/m', $buf, $vers_buf)) {
$this->sys->setDistribution($this->sys->getDistribution()." (".trim($vers_buf[1]).")");
}
}
if (isset($list[trim($id_buf[1])]['Image'])) {
$this->sys->setDistributionIcon($list[trim($id_buf[1])]['Image']);
}
} else { // otherwise find files specific for distribution
foreach ($list as $section=>$distribution) {
if (!isset($distribution['Files'])) {
continue;
} else {
foreach (preg_split("/;/", $distribution['Files'], -1, PREG_SPLIT_NO_EMPTY) as $filename) {
if (CommonFunctions::fileexists($filename)) {
$distro = $distribution;
if (isset($distribution['Mode'])&&(strtolower($distribution['Mode'])=="detection")) {
$buf = "";
} elseif (isset($distribution['Mode'])&&(strtolower($distribution['Mode'])=="execute")) {
if (!CommonFunctions::executeProgram($filename, '2>/dev/null', $buf, PSI_DEBUG)) {
$buf = "";
}
} else {
if (!CommonFunctions::rfts($filename, $buf, 1, 4096, false)) {
$buf = "";
} elseif (isset($distribution['Mode'])&&(strtolower($distribution['Mode'])=="analyse")) {
if (preg_match('/^(\S+)\s*/', preg_replace('/^Red\s+/', 'Red', $buf), $id_buf)
&& isset($list[trim($id_buf[1])]['Image'])) {
$distro = $list[trim($id_buf[1])];
}
}
}
if (isset($distro['Image'])) {
$this->sys->setDistributionIcon($distro['Image']);
}
if (isset($distribution['Name'])) {
if (is_null($buf) || (trim($buf) == "")) {
$this->sys->setDistribution($distribution['Name']);
} else {
$this->sys->setDistribution($distribution['Name']." ".trim($buf));
}
} else {
if (is_null($buf) || (trim($buf) == "")) {
$this->sys->setDistribution($section);
} else {
$this->sys->setDistribution(trim($buf));
}
}
if (isset($distribution['Files2'])) {
foreach (preg_split("/;/", $distribution['Files2'], -1, PREG_SPLIT_NO_EMPTY) as $filename2) {
if (CommonFunctions::fileexists($filename2) && CommonFunctions::rfts($filename2, $buf, 0, 4096, false)) {
if (preg_match('/^majorversion="?([^"\n]+)"?/m', $buf, $maj_buf)
&& preg_match('/^minorversion="?([^"\n]+)"?/m', $buf, $min_buf)) {
$distr2=$maj_buf[1].'.'.$min_buf[1];
if (preg_match('/^buildphase="?([^"\n]+)"?/m', $buf, $pha_buf) && ($pha_buf[1]!=="0")) {
$distr2.='.'.$pha_buf[1];
}
if (preg_match('/^buildnumber="?([^"\n]+)"?/m', $buf, $num_buf)) {
$distr2.='-'.$num_buf[1];
}
if (preg_match('/^builddate="?([^"\n]+)"?/m', $buf, $dat_buf)) {
$distr2.=' ('.$dat_buf[1].')';
}
$this->sys->setDistribution($this->sys->getDistribution()." ".$distr2);
} else {
$distr2=trim(substr($buf, 0, strpos($buf, "\n")));
if (!is_null($distr2) && ($distr2 != "")) {
$this->sys->setDistribution($this->sys->getDistribution()." ".$distr2);
}
}
break;
}
}
}
break 2;
}
}
}
}
}
// if the distribution is still unknown
if ($this->sys->getDistribution() == "Linux") {
if (CommonFunctions::fileexists($filename="/etc/DISTRO_SPECS")
&& CommonFunctions::rfts($filename, $buf, 0, 4096, false)
&& preg_match('/^DISTRO_NAME=\'(.+)\'/m', $buf, $id_buf)) {
if (isset($list[trim($id_buf[1])]['Name'])) {
$dist = trim($list[trim($id_buf[1])]['Name']);
} else {
$dist = trim($id_buf[1]);
}
if (preg_match('/^DISTRO_VERSION=([^#\n\r]+)/m', $buf, $vers_buf)) {
$this->sys->setDistribution(trim($dist." ".trim($vers_buf[1])));
} else {
$this->sys->setDistribution($dist);
}
if (isset($list[trim($id_buf[1])]['Image'])) {
$this->sys->setDistributionIcon($list[trim($id_buf[1])]['Image']);
} else {
if (isset($list['Puppy']['Image'])) {
$this->sys->setDistributionIcon($list['Puppy']['Image']);
}
}
} elseif ((CommonFunctions::fileexists($filename="/etc/distro-release")
&& CommonFunctions::rfts($filename, $buf, 1, 4096, false)
&& !is_null($buf) && (trim($buf) != ""))
|| (CommonFunctions::fileexists($filename="/etc/system-release")
&& CommonFunctions::rfts($filename, $buf, 1, 4096, false)
&& !is_null($buf) && (trim($buf) != ""))) {
$this->sys->setDistribution(trim($buf));
if (preg_match('/^(\S+)\s*/', preg_replace('/^Red\s+/', 'Red', $buf), $id_buf)
&& isset($list[trim($id_buf[1])]['Image'])) {
$this->sys->setDistributionIcon($list[trim($id_buf[1])]['Image']);
}
} elseif (CommonFunctions::fileexists($filename="/etc/solydxk/info")
&& CommonFunctions::rfts($filename, $buf, 0, 4096, false)
&& preg_match('/^DISTRIB_ID="?([^"\n]+)"?/m', $buf, $id_buf)) {
if (preg_match('/^DESCRIPTION="?([^"\n]+)"?/m', $buf, $desc_buf)
&& (trim($desc_buf[1])!=trim($id_buf[1]))) {
$this->sys->setDistribution(trim($desc_buf[1]));
} else {
if (isset($list[trim($id_buf[1])]['Name'])) {
$this->sys->setDistribution(trim($list[trim($id_buf[1])]['Name']));
} else {
$this->sys->setDistribution(trim($id_buf[1]));
}
if (preg_match('/^RELEASE="?([^"\n]+)"?/m', $buf, $vers_buf)) {
$this->sys->setDistribution($this->sys->getDistribution()." ".trim($vers_buf[1]));
}
if (preg_match('/^CODENAME="?([^"\n]+)"?/m', $buf, $vers_buf)) {
$this->sys->setDistribution($this->sys->getDistribution()." (".trim($vers_buf[1]).")");
}
}
if (isset($list[trim($id_buf[1])]['Image'])) {
$this->sys->setDistributionIcon($list[trim($id_buf[1])]['Image']);
} else {
$this->sys->setDistributionIcon($list['SolydXK']['Image']);
}
} elseif (CommonFunctions::fileexists($filename="/etc/os-release")
&& CommonFunctions::rfts($filename, $buf, 0, 4096, false)
&& (preg_match('/^TAILS_VERSION_ID="?([^"\n]+)"?/m', $buf, $tid_buf)
|| preg_match('/^NAME="?([^"\n]+)"?/m', $buf, $id_buf))) {
if (preg_match('/^TAILS_VERSION_ID="?([^"\n]+)"?/m', $buf, $tid_buf)) {
if (preg_match('/^TAILS_PRODUCT_NAME="?([^"\n]+)"?/m', $buf, $desc_buf)) {
$this->sys->setDistribution(trim($desc_buf[1])." ".trim($tid_buf[1]));
} else {
if (isset($list['Tails']['Name'])) {
$this->sys->setDistribution(trim($list['Tails']['Name'])." ".trim($tid_buf[1]));
} else {
$this->sys->setDistribution('Tails'." ".trim($tid_buf[1]));
}
}
$this->sys->setDistributionIcon($list['Tails']['Image']);
} else {
if (preg_match('/^PRETTY_NAME="?([^"\n]+)"?/m', $buf, $desc_buf)
&& !preg_match('/\$/', $desc_buf[1])) { //if is not defined by variable
$this->sys->setDistribution(trim($desc_buf[1]));
} else {
if (isset($list[trim($id_buf[1])]['Name'])) {
$this->sys->setDistribution(trim($list[trim($id_buf[1])]['Name']));
} else {
$this->sys->setDistribution(trim($id_buf[1]));
}
if (preg_match('/^VERSION="?([^"\n]+)"?/m', $buf, $vers_buf)) {
$this->sys->setDistribution($this->sys->getDistribution()." ".trim($vers_buf[1]));
} elseif (preg_match('/^VERSION_ID="?([^"\n]+)"?/m', $buf, $vers_buf)) {
$this->sys->setDistribution($this->sys->getDistribution()." ".trim($vers_buf[1]));
}
}
if (isset($list[trim($id_buf[1])]['Image'])) {
$this->sys->setDistributionIcon($list[trim($id_buf[1])]['Image']);
}
}
} elseif (CommonFunctions::fileexists($filename="/etc/debian_version")) {
if (!CommonFunctions::rfts($filename, $buf, 1, 4096, false)) {
$buf = "";
}
if (isset($list['Debian']['Image'])) {
$this->sys->setDistributionIcon($list['Debian']['Image']);
}
if (isset($list['Debian']['Name'])) {
if (is_null($buf) || (trim($buf) == "")) {
$this->sys->setDistribution($list['Debian']['Name']);
} else {
$this->sys->setDistribution($list['Debian']['Name']." ".trim($buf));
}
} else {
if (is_null($buf) || (trim($buf) == "")) {
$this->sys->setDistribution('Debian');
} else {
$this->sys->setDistribution(trim($buf));
}
}
} elseif (CommonFunctions::fileexists($filename="/etc/config/uLinux.conf")
&& CommonFunctions::rfts($filename, $buf, 0, 4096, false)
&& preg_match("/^Rsync\sModel\s*=\s*QNAP/m", $buf)
&& preg_match("/^Version\s*=\s*([\d\.]+)\r?\nBuild\sNumber\s*=\s*(\S+)/m", $buf, $ver_buf)) {
$buf = $ver_buf[1]."-".$ver_buf[2];
if (isset($list['QTS']['Image'])) {
$this->sys->setDistributionIcon($list['QTS']['Image']);
}
if (isset($list['QTS']['Name'])) {
$this->sys->setDistribution($list['QTS']['Name']." ".trim($buf));
} else {
$this->sys->setDistribution(trim($buf));
}
}
}
/* restore error level */
error_reporting($old_err_rep);
/* restore error handler */
if (function_exists('errorHandlerPsi')) {
set_error_handler('errorHandlerPsi');
}
}
}
 
/**
* Processes
*
* @return void
*/
protected function _processes()
{
$process = glob('/proc/*/status', GLOB_NOSORT);
if (is_array($process) && (($total = count($process)) > 0)) {
$processes['*'] = 0;
$buf = "";
for ($i = 0; $i < $total; $i++) {
if (CommonFunctions::rfts($process[$i], $buf, 0, 4096, false)) {
$processes['*']++; //current total
if (preg_match('/^State:\s+(\w)/m', $buf, $state)) {
if (isset($processes[$state[1]])) {
$processes[$state[1]]++;
} else {
$processes[$state[1]] = 1;
}
}
}
}
if (!($processes['*'] > 0)) {
$processes['*'] = $processes[' '] = $total; //all unknown
}
$this->sys->setProcesses($processes);
}
}
 
/**
* get the information
*
* @see PSI_Interface_OS::build()
*
* @return Void
*/
public function build()
{
if (!$this->blockname || $this->blockname==='vitals') {
$this->_distro();
$this->_hostname();
$this->_kernel();
$this->_uptime();
$this->_users();
$this->_loadavg();
$this->_processes();
}
if (!$this->blockname || $this->blockname==='hardware') {
$this->_machine();
$this->_cpuinfo();
$this->_pci();
$this->_ide();
$this->_scsi();
$this->_nvme();
$this->_usb();
$this->_i2c();
}
if (!$this->blockname || $this->blockname==='network') {
$this->_network();
}
if (!$this->blockname || $this->blockname==='memory') {
$this->_memory();
}
if (!$this->blockname || $this->blockname==='filesystem') {
$this->_filesystems();
}
}
}
/web/acc/phpsysinfo/includes/os/class.Minix.inc.php
0,0 → 1,359
<?php
/**
* Minix System Class
*
* PHP version 5
*
* @category PHP
* @package PSI Minix OS class
* @author Mieczyslaw Nalewaj <namiltd@users.sourceforge.net>
* @copyright 2012 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License version 2, or (at your option) any later version
* @version SVN: $Id: class.Minix.inc.php 687 2012-09-06 20:54:49Z namiltd $
* @link http://phpsysinfo.sourceforge.net
*/
/**
* Minix sysinfo class
* get all the required information from Minix system
*
* @category PHP
* @package PSI Minix OS class
* @author Mieczyslaw Nalewaj <namiltd@users.sourceforge.net>
* @copyright 2012 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License version 2, or (at your option) any later version
* @version Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
class Minix extends OS
{
/**
* content of the syslog
*
* @var array
*/
private $_dmesg = null;
 
/**
* read /var/log/messages, but only if we haven't already
*
* @return array
*/
protected function readdmesg()
{
if ($this->_dmesg === null) {
if (CommonFunctions::rfts('/var/log/messages', $buf)) {
$blocks = preg_replace("/\s(kernel: MINIX \d+\.\d+\.\d+\.)/", '<BLOCK>$1', $buf);
$parts = preg_split("/<BLOCK>/", $blocks, -1, PREG_SPLIT_NO_EMPTY);
$this->_dmesg = preg_split("/\n/", $parts[count($parts) - 1], -1, PREG_SPLIT_NO_EMPTY);
} else {
$this->_dmesg = array();
}
}
 
return $this->_dmesg;
}
 
/**
* get the cpu information
*
* @return void
*/
protected function _cpuinfo()
{
if (CommonFunctions::rfts('/proc/cpuinfo', $bufr, 0, 4096, false)) {
$processors = preg_split('/\s?\n\s?\n/', trim($bufr));
foreach ($processors as $processor) {
$_n = ""; $_f = ""; $_m = ""; $_s = "";
$dev = new CpuDevice();
$details = preg_split("/\n/", $processor, -1, PREG_SPLIT_NO_EMPTY);
foreach ($details as $detail) {
$arrBuff = preg_split('/\s+:\s+/', trim($detail));
if (count($arrBuff) == 2) {
switch (strtolower($arrBuff[0])) {
case 'model name':
$_n = $arrBuff[1];
break;
case 'cpu mhz':
$dev->setCpuSpeed($arrBuff[1]);
break;
case 'cpu family':
$_f = $arrBuff[1];
break;
case 'model':
$_m = $arrBuff[1];
break;
case 'stepping':
$_s = $arrBuff[1];
break;
case 'flags':
if (preg_match("/ vmx/", $arrBuff[1])) {
$dev->setVirt("vmx");
} elseif (preg_match("/ svm/", $arrBuff[1])) {
$dev->setVirt("svm");
}
break;
case 'vendor_id':
$dev->setVendorId($arrBuff[1]);
break;
}
}
}
if ($_n == "") $_n="CPU";
if ($_f != "") $_n.=" Family ".$_f;
if ($_m != "") $_n.=" Model ".$_m;
if ($_s != "") $_n.=" Stepping ".$_s;
$dev->SetModel($_n);
$this->sys->setCpus($dev);
}
} else
foreach ($this->readdmesg() as $line) {
if (preg_match('/kernel: (CPU .*) freq (.*) MHz/', $line, $ar_buf)) {
$dev = new CpuDevice();
$dev->setModel($ar_buf[1]);
$dev->setCpuSpeed($ar_buf[2]);
$this->sys->setCpus($dev);
}
}
}
 
/**
* PCI devices
* get the pci device information out of dmesg
*
* @return void
*/
protected function _pci()
{
if (CommonFunctions::rfts('/proc/pci', $strBuf, 0, 4096, false)) {
$arrLines = preg_split("/\n/", $strBuf, -1, PREG_SPLIT_NO_EMPTY);
$arrResults = array();
foreach ($arrLines as $strLine) {
$arrParams = preg_split('/\s+/', trim($strLine), 4);
if (count($arrParams) == 4)
$strName = $arrParams[3];
else
$strName = "unknown";
$strName = preg_replace('/\(.*\)/', '', $strName);
$dev = new HWDevice();
$dev->setName($strName);
$arrResults[] = $dev;
}
foreach ($arrResults as $dev) {
$this->sys->setPciDevices($dev);
}
}
if (!(isset($arrResults) && is_array($arrResults)) && ($results = Parser::lspci())) {
/* if access error: chmod 4755 /usr/bin/lspci */
foreach ($results as $dev) {
$this->sys->setPciDevices($dev);
}
}
}
 
/**
* Minix Version
*
* @return void
*/
private function _kernel()
{
if (CommonFunctions::executeProgram('uname', '-rvm', $ret)) {
foreach ($this->readdmesg() as $line) {
if (preg_match('/kernel: MINIX (\d+\.\d+\.\d+)\. \((.+)\)/', $line, $ar_buf)) {
$branch = $ar_buf[2];
break;
}
}
if (isset($branch))
$this->sys->setKernel($ret.' ('.$branch.')');
else
$this->sys->setKernel($ret);
}
}
 
/**
* Distribution
*
* @return void
*/
protected function _distro()
{
if (CommonFunctions::executeProgram('uname', '-sr', $ret))
$this->sys->setDistribution($ret);
else
$this->sys->setDistribution('Minix');
 
$this->sys->setDistributionIcon('Minix.png');
}
 
/**
* UpTime
* time the system is running
*
* @return void
*/
private function _uptime()
{
if (CommonFunctions::executeProgram('uptime', '', $buf)) {
if (preg_match("/up (\d+) day[s]?,\s*(\d+):(\d+),/", $buf, $ar_buf)) {
$min = $ar_buf[3];
$hours = $ar_buf[2];
$days = $ar_buf[1];
$this->sys->setUptime($days * 86400 + $hours * 3600 + $min * 60);
} elseif (preg_match("/up (\d+):(\d+),/", $buf, $ar_buf)) {
$min = $ar_buf[2];
$hours = $ar_buf[1];
$this->sys->setUptime($hours * 3600 + $min * 60);
}
}
}
 
/**
* Processor Load
* optionally create a loadbar
*
* @return void
*/
private function _loadavg()
{
if (CommonFunctions::executeProgram('uptime', '', $buf)) {
if (preg_match("/load averages: (.*), (.*), (.*)$/", $buf, $ar_buf)) {
$this->sys->setLoad($ar_buf[1].' '.$ar_buf[2].' '.$ar_buf[3]);
}
}
}
 
/**
* Virtual Host Name
*
* @return void
*/
private function _hostname()
{
if (PSI_USE_VHOST === true) {
if (CommonFunctions::readenv('SERVER_NAME', $hnm)) $this->sys->setHostname($hnm);
} else {
if (CommonFunctions::executeProgram('uname', '-n', $result, PSI_DEBUG)) {
$ip = gethostbyname($result);
if ($ip != $result) {
$this->sys->setHostname(gethostbyaddr($ip));
}
}
}
}
 
 
/**
* Physical memory information and Swap Space information
*
* @return void
*/
private function _memory()
{
if (CommonFunctions::rfts('/proc/meminfo', $bufr, 1, 4096, false)) {
$ar_buf = preg_split('/\s+/', trim($bufr));
if (count($ar_buf) >= 5) {
$this->sys->setMemTotal($ar_buf[0]*$ar_buf[1]);
$this->sys->setMemFree($ar_buf[0]*$ar_buf[2]);
$this->sys->setMemCache($ar_buf[0]*$ar_buf[4]);
$this->sys->setMemUsed($ar_buf[0]*($ar_buf[1]-$ar_buf[2]));
}
}
}
 
/**
* filesystem information
*
* @return void
*/
private function _filesystems()
{
$arrResult = Parser::df("-P 2>/dev/null");
foreach ($arrResult as $dev) {
$this->sys->setDiskDevices($dev);
}
}
 
/**
* network information
*
* @return void
*/
private function _network()
{
if (CommonFunctions::executeProgram('ifconfig', '-a', $bufr, PSI_DEBUG)) {
$lines = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
foreach ($lines as $line) {
if (preg_match("/^([^\s:]+):\saddress\s(\S+)\snetmask/", $line, $ar_buf)) {
$dev = new NetDevice();
$dev->setName($ar_buf[1]);
if (defined('PSI_SHOW_NETWORK_INFOS') && (PSI_SHOW_NETWORK_INFOS)) {
$dev->setInfo($ar_buf[2]);
}
$this->sys->setNetDevices($dev);
}
}
}
}
 
/**
* Processes
*
* @return void
*/
protected function _processes()
{
if (CommonFunctions::executeProgram('ps', 'alx', $bufr, PSI_DEBUG)) {
$lines = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
$processes['*'] = 0;
foreach ($lines as $line) {
if (preg_match("/^\s(\w)\s/", $line, $ar_buf)) {
$processes['*']++;
$state = $ar_buf[1];
if ($state == 'W') $state = 'D'; //linux format
elseif ($state == 'D') $state = 'd'; //invalid
if (isset($processes[$state])) {
$processes[$state]++;
} else {
$processes[$state] = 1;
}
}
}
if ($processes['*'] > 0) {
$this->sys->setProcesses($processes);
}
}
}
 
/**
* get the information
*
* @return Void
*/
public function build()
{
$this->error->addError("WARN", "The Minix version of phpSysInfo is a work in progress, some things currently don't work");
if (!$this->blockname || $this->blockname==='vitals') {
$this->_distro();
$this->_hostname();
$this->_kernel();
$this->_uptime();
$this->_users();
$this->_loadavg();
$this->_processes();
}
if (!$this->blockname || $this->blockname==='hardware') {
$this->_pci();
$this->_cpuinfo();
}
if (!$this->blockname || $this->blockname==='network') {
$this->_network();
}
if (!$this->blockname || $this->blockname==='memory') {
$this->_memory();
}
if (!$this->blockname || $this->blockname==='filesystem') {
$this->_filesystems();
}
}
}
/web/acc/phpsysinfo/includes/os/class.NetBSD.inc.php
1,111 → 1,208
<?php
<?php
/**
* NetBSD System Class
*
* PHP version 5
*
* @category PHP
* @package PSI NetBSD OS class
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License version 2, or (at your option) any later version
* @version SVN: $Id: class.NetBSD.inc.php 287 2009-06-26 12:11:59Z bigmichi1 $
* @link http://phpsysinfo.sourceforge.net
*/
/**
* NetBSD sysinfo class
* get all the required information from NetBSD systems
*
* @category PHP
* @package PSI NetBSD OS class
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License version 2, or (at your option) any later version
* @version Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
class NetBSD extends BSDCommon
{
/**
* define the regexp for log parser
*/
public function __construct($blockname = false)
{
parent::__construct($blockname);
$this->setCPURegExp1("/^cpu(.*)\, (.*) MHz/");
$this->setCPURegExp2("/user = (.*), nice = (.*), sys = (.*), intr = (.*), idle = (.*)/");
$this->setSCSIRegExp1("/^(.*) at scsibus.*: <(.*)> .*/");
$this->setSCSIRegExp2("/^(sd[0-9]+): (.*)([MG])B,/");
$this->setPCIRegExp1("/(.*) at pci[0-9]+ dev [0-9]* function [0-9]*: (.*)$/");
$this->setPCIRegExp2("/\"(.*)\" (.*).* at [.0-9]+ irq/");
}
 
// phpSysInfo - A PHP System Information Script
// http://phpsysinfo.sourceforge.net/
/**
* UpTime
* time the system is running
*
* @return void
*/
private function _uptime()
{
$a = $this->grabkey('kern.boottime');
$this->sys->setUptime(time() - $a);
}
 
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
/**
* get network information
*
* @return void
*/
private function _network()
{
CommonFunctions::executeProgram('netstat', '-nbdi | cut -c1-25,44- | grep "^[a-z]*[0-9][ \t].*Link"', $netstat_b);
CommonFunctions::executeProgram('netstat', '-ndi | cut -c1-25,44- | grep "^[a-z]*[0-9][ \t].*Link"', $netstat_n);
$lines_b = preg_split("/\n/", $netstat_b, -1, PREG_SPLIT_NO_EMPTY);
$lines_n = preg_split("/\n/", $netstat_n, -1, PREG_SPLIT_NO_EMPTY);
for ($i = 0, $max = sizeof($lines_b); $i < $max; $i++) {
$ar_buf_b = preg_split("/\s+/", $lines_b[$i]);
$ar_buf_n = preg_split("/\s+/", $lines_n[$i]);
if (!empty($ar_buf_b[0]) && (!empty($ar_buf_n[3]) || ($ar_buf_n[3] === "0"))) {
$dev = new NetDevice();
$dev->setName($ar_buf_b[0]);
$dev->setTxBytes($ar_buf_b[4]);
$dev->setRxBytes($ar_buf_b[3]);
$dev->setDrops($ar_buf_n[8]);
$dev->setErrors($ar_buf_n[4] + $ar_buf_n[6]);
if (defined('PSI_SHOW_NETWORK_INFOS') && (PSI_SHOW_NETWORK_INFOS) && (CommonFunctions::executeProgram('ifconfig', $ar_buf_b[0].' 2>/dev/null', $bufr2, PSI_DEBUG))) {
$speedinfo = "";
$bufe2 = preg_split("/\n/", $bufr2, -1, PREG_SPLIT_NO_EMPTY);
foreach ($bufe2 as $buf2) {
if (preg_match('/^\s+address:\s+(\S+)/i', $buf2, $ar_buf2)) {
if (!defined('PSI_HIDE_NETWORK_MACADDR') || !PSI_HIDE_NETWORK_MACADDR) $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').preg_replace('/:/', '-', strtoupper($ar_buf2[1])));
} elseif (preg_match('/^\s+inet\s+(\S+)\s+netmask/i', $buf2, $ar_buf2)) {
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$ar_buf2[1]);
} elseif ((preg_match('/^\s+inet6\s+([^\s%]+)\s+prefixlen/i', $buf2, $ar_buf2)
|| preg_match('/^\s+inet6\s+([^\s%]+)%\S+\s+prefixlen/i', $buf2, $ar_buf2))
&& ($ar_buf2[1]!="::") && !preg_match('/^fe80::/i', $ar_buf2[1])) {
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').strtolower($ar_buf2[1]));
} elseif (preg_match('/^\s+media:\s+/i', $buf2) && preg_match('/[\(\s](\d+)(G*)base/i', $buf2, $ar_buf2)) {
if (isset($ar_buf2[2]) && strtoupper($ar_buf2[2])=="G") {
$unit = "G";
} else {
$unit = "M";
}
if (preg_match('/\s(\S+)-duplex/i', $buf2, $ar_buf3))
$speedinfo = $ar_buf2[1].$unit.'b/s '.strtolower($ar_buf3[1]);
else
$speedinfo = $ar_buf2[1].$unit.'b/s';
}
}
if ($speedinfo != "") $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$speedinfo);
}
$this->sys->setNetDevices($dev);
}
}
}
 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
/**
* IDE information
*
* @return void
*/
protected function ide()
{
foreach ($this->readdmesg() as $line) {
if (preg_match('/^(.*) at (pciide|wdc|atabus|atapibus)[0-9]+ (.*): <(.*)>/', $line, $ar_buf)
|| preg_match('/^(.*) at (pciide|wdc|atabus|atapibus)[0-9]+ /', $line, $ar_buf)) {
$dev = new HWDevice();
if (isset($ar_buf[4])) {
$dev->setName($ar_buf[4]);
} else {
$dev->setName($ar_buf[1]);
// now loop again and find the name
foreach ($this->readdmesg() as $line2) {
if (preg_match("/^(".$ar_buf[1]."): <(.*)>$/", $line2, $ar_buf_n)) {
$dev->setName($ar_buf_n[2]);
break;
}
}
}
if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS) {
// now loop again and find the capacity
foreach ($this->readdmesg() as $line2) {
if (preg_match("/^(".$ar_buf[1]."): (.*), (.*), (.*)MB, .*$/", $line2, $ar_buf_n)) {
$dev->setCapacity($ar_buf_n[4] * 1024 * 1024);
break;
} elseif (preg_match("/^(".$ar_buf[1]."): (.*) MB, (.*), (.*), .*$/", $line2, $ar_buf_n)) {
$dev->setCapacity($ar_buf_n[2] * 1024 * 1024);
break;
} elseif (preg_match("/^(".$ar_buf[1]."): (.*) GB, (.*), (.*), .*$/", $line2, $ar_buf_n)) {
$dev->setCapacity($ar_buf_n[2] * 1024 * 1024 * 1024);
break;
}
}
}
$this->sys->setIdeDevices($dev);
}
}
}
 
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
/**
* get icon name
*
* @return void
*/
private function _distroicon()
{
$this->sys->setDistributionIcon('NetBSD.png');
}
 
// $Id: class.NetBSD.inc.php,v 1.18 2006/04/18 16:57:32 bigmichi1 Exp $
if (!defined('IN_PHPSYSINFO')) {
die("No Hacking");
/**
* Processes
*
* @return void
*/
protected function _processes()
{
if (CommonFunctions::executeProgram('ps', 'aux', $bufr, PSI_DEBUG)) {
$lines = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
$processes['*'] = 0;
foreach ($lines as $line) {
if (preg_match("/^\S+\s+\d+\s+\S+\s+\S+\s+\d+\s+\d+\s+\S+\s+(\w)/", $line, $ar_buf)) {
$processes['*']++;
$state = $ar_buf[1];
if ($state == 'O') $state = 'R'; //linux format
elseif ($state == 'I') $state = 'S';
if (isset($processes[$state])) {
$processes[$state]++;
} else {
$processes[$state] = 1;
}
}
}
if ($processes['*'] > 0) {
$this->sys->setProcesses($processes);
}
}
}
 
/**
* get the information
*
* @see BSDCommon::build()
*
* @return Void
*/
public function build()
{
parent::build();
if (!$this->blockname || $this->blockname==='vitals') {
$this->_distroicon();
$this->_uptime();
$this->_processes();
}
if (!$this->blockname || $this->blockname==='network') {
$this->_network();
}
}
}
 
require_once(APP_ROOT . '/includes/os/class.BSD.common.inc.php');
 
class sysinfo extends bsd_common {
var $cpu_regexp;
var $scsi_regexp;
// Our contstructor
// this function is run on the initialization of this class
function sysinfo () {
$this->bsd_common();
$this->cpu_regexp = "^cpu(.*)\, (.*) MHz";
$this->scsi_regexp1 = "^(.*) at scsibus.*: <(.*)> .*";
$this->scsi_regexp2 = "^(da[0-9]): (.*)MB ";
$this->cpu_regexp2 = "/user = (.*), nice = (.*), sys = (.*), intr = (.*), idle = (.*)/";
$this->pci_regexp1 = '/(.*) at pci[0-9] dev [0-9]* function [0-9]*: (.*)$/';
$this->pci_regexp2 = '/"(.*)" (.*).* at [.0-9]+ irq/';
}
 
function get_sys_ticks () {
$a = $this->grab_key('kern.boottime');
$sys_ticks = time() - $a;
return $sys_ticks;
}
 
function network () {
$netstat_b = execute_program('netstat', '-nbdi | cut -c1-25,44- | grep "^[a-z]*[0-9][ \t].*Link"');
$netstat_n = execute_program('netstat', '-ndi | cut -c1-25,44- | grep "^[a-z]*[0-9][ \t].*Link"');
$lines_b = explode("\n", $netstat_b);
$lines_n = explode("\n", $netstat_n);
$results = array();
for ($i = 0, $max = sizeof($lines_b); $i < $max; $i++) {
$ar_buf_b = preg_split("/\s+/", $lines_b[$i]);
$ar_buf_n = preg_split("/\s+/", $lines_n[$i]);
if (!empty($ar_buf_b[0]) && !empty($ar_buf_n[3])) {
$results[$ar_buf_b[0]] = array();
 
$results[$ar_buf_b[0]]['rx_bytes'] = $ar_buf_b[3];
$results[$ar_buf_b[0]]['rx_packets'] = $ar_buf_n[3];
$results[$ar_buf_b[0]]['rx_errs'] = $ar_buf_n[4];
$results[$ar_buf_b[0]]['rx_drop'] = $ar_buf_n[8];
 
$results[$ar_buf_b[0]]['tx_bytes'] = $ar_buf_b[4];
$results[$ar_buf_b[0]]['tx_packets'] = $ar_buf_n[5];
$results[$ar_buf_b[0]]['tx_errs'] = $ar_buf_n[6];
$results[$ar_buf_b[0]]['tx_drop'] = $ar_buf_n[8];
 
$results[$ar_buf_b[0]]['errs'] = $ar_buf_n[4] + $ar_buf_n[6];
$results[$ar_buf_b[0]]['drop'] = $ar_buf_n[8];
}
}
return $results;
}
 
// get the ide device information out of dmesg
function ide () {
$results = array();
 
$s = 0;
for ($i = 0, $max = count($this->read_dmesg()); $i < $max; $i++) {
$buf = $this->dmesg[$i];
if (preg_match('/^(.*) at (pciide|wdc|atabus|atapibus)[0-9] (.*): <(.*)>/', $buf, $ar_buf)) {
$s = $ar_buf[1];
$results[$s]['model'] = $ar_buf[4];
$results[$s]['media'] = 'Hard Disk';
// now loop again and find the capacity
for ($j = 0, $max1 = count($this->read_dmesg()); $j < $max1; $j++) {
$buf_n = $this->dmesg[$j];
if (preg_match("/^($s): (.*), (.*), (.*)MB, .*$/", $buf_n, $ar_buf_n)) {
$results[$s]['capacity'] = $ar_buf_n[4] * 2048 * 1.049;
} elseif (preg_match("/^($s): (.*) MB, (.*), (.*), .*$/", $buf_n, $ar_buf_n)) {
$results[$s]['capacity'] = $ar_buf_n[2] * 2048;
}
}
}
}
asort($results);
return $results;
}
 
function distroicon () {
$result = 'NetBSD.png';
return($result);
}
}
 
?>
/web/acc/phpsysinfo/includes/os/class.OS.inc.php
0,0 → 1,172
<?php
/**
* Basic OS Class
*
* PHP version 5
*
* @category PHP
* @package PSI OS class
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License version 2, or (at your option) any later version
* @version SVN: $Id: class.OS.inc.php 699 2012-09-15 11:57:13Z namiltd $
* @link http://phpsysinfo.sourceforge.net
*/
/**
* Basic OS functions for all OS classes
*
* @category PHP
* @package PSI OS class
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License version 2, or (at your option) any later version
* @version Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
abstract class OS implements PSI_Interface_OS
{
/**
* object for error handling
*
* @var PSI_Error
*/
protected $error;
 
/**
* block name
*
* @var string
*/
protected $blockname = false;
 
/**
* @var System
*/
protected $sys;
 
/**
* build the global Error object
*/
public function __construct($blockname = false)
{
$this->error = PSI_Error::singleton();
$this->sys = new System();
$this->blockname = $blockname;
}
 
/**
* get os specific encoding
*
* @see PSI_Interface_OS::getEncoding()
*
* @return string
*/
public function getEncoding()
{
return PSI_SYSTEM_CODEPAGE;
}
 
/**
* get os specific language
*
* @see PSI_Interface_OS::getLanguage()
*
* @return string
*/
public function getLanguage()
{
return PSI_SYSTEM_LANG;
}
 
/**
* get block name
*
* @see PSI_Interface_OS::getBlockName()
*
* @return string
*/
public function getBlockName()
{
return $this->blockname;
}
 
/**
* Number of Users
*
* @return void
*/
protected function _users()
{
if (CommonFunctions::executeProgram('who', '', $strBuf, PSI_DEBUG)) {
if (strlen($strBuf) > 0) {
$lines = preg_split('/\n/', $strBuf);
$this->sys->setUsers(count($lines));
}
} elseif (CommonFunctions::executeProgram('uptime', '', $buf, PSI_DEBUG) && preg_match("/,\s+(\d+)\s+user[s]?,/", $buf, $ar_buf)) {
//} elseif (CommonFunctions::executeProgram('uptime', '', $buf) && preg_match("/,\s+(\d+)\s+user[s]?,\s+load average[s]?:\s+(.*),\s+(.*),\s+(.*)$/", $buf, $ar_buf)) {
$this->sys->setUsers($ar_buf[1]);
} else {
$processlist = glob('/proc/*/cmdline', GLOB_NOSORT);
if (is_array($processlist) && (($total = count($processlist)) > 0)) {
$count = 0;
$buf = "";
for ($i = 0; $i < $total; $i++) {
if (CommonFunctions::rfts($processlist[$i], $buf, 0, 4096, false)) {
$name = str_replace(chr(0), ' ', trim($buf));
if (preg_match("/^-/", $name)) {
$count++;
}
}
}
if ($count > 0) {
$this->sys->setUsers($count);
}
}
}
}
 
/**
* IP of the Host
*
* @return void
*/
protected function _ip()
{
if (PSI_USE_VHOST === true) {
if ((CommonFunctions::readenv('SERVER_ADDR', $result) || CommonFunctions::readenv('LOCAL_ADDR', $result)) //is server address defined
&& !strstr($result, '.') && strstr($result, ':')) { //is IPv6, quick version of preg_match('/\(([[0-9A-Fa-f\:]+)\)/', $result)
$dnsrec = dns_get_record($this->sys->getHostname(), DNS_AAAA);
if (isset($dnsrec[0]['ipv6'])) { //is DNS IPv6 record
$this->sys->setIp($dnsrec[0]['ipv6']); //from DNS (avoid IPv6 NAT translation)
} else {
$this->sys->setIp(preg_replace('/^::ffff:/i', '', $result)); //from SERVER_ADDR or LOCAL_ADDR
}
} else {
$this->sys->setIp(gethostbyname($this->sys->getHostname())); //IPv4 only
}
} else {
if (CommonFunctions::readenv('SERVER_ADDR', $result) || CommonFunctions::readenv('LOCAL_ADDR', $result)) {
$this->sys->setIp(preg_replace('/^::ffff:/i', '', $result));
} else {
$this->sys->setIp(gethostbyname($this->sys->getHostname()));
}
}
}
 
/**
* get the filled or unfilled (with default values) System object
*
* @see PSI_Interface_OS::getSys()
*
* @return System
*/
final public function getSys()
{
$this->build();
if (!$this->blockname || $this->blockname==='vitals') {
$this->_ip();
}
 
return $this->sys;
}
}
/web/acc/phpsysinfo/includes/os/class.OpenBSD.inc.php
1,110 → 1,229
<?php
<?php
/**
* OpenBSD System Class
*
* PHP version 5
*
* @category PHP
* @package PSI OpenBSD OS class
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License version 2, or (at your option) any later version
* @version SVN: $Id: class.OpenBSD.inc.php 621 2012-07-29 18:49:04Z namiltd $
* @link http://phpsysinfo.sourceforge.net
*/
/**
* OpenBSD sysinfo class
* get all the required information from OpenBSD systems
*
* @category PHP
* @package PSI OpenBSD OS class
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License version 2, or (at your option) any later version
* @version Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
class OpenBSD extends BSDCommon
{
/**
* define the regexp for log parser
*/
public function __construct($blockname = false)
{
parent::__construct($blockname);
// $this->setCPURegExp1("/^cpu(.*) (.*) MHz/");
$this->setCPURegExp2("/(.*),(.*),(.*),(.*),(.*)/");
$this->setSCSIRegExp1("/^(.*) at scsibus.*: <(.*)> .*/");
$this->setSCSIRegExp2("/^(sd[0-9]+): (.*)MB,/");
$this->setPCIRegExp1("/(.*) at pci[0-9]+ .* \"(.*)\"/");
$this->setPCIRegExp2("/\"(.*)\" (.*).* at [.0-9]+ irq/");
}
 
// phpSysInfo - A PHP System Information Script
// http://phpsysinfo.sourceforge.net/
/**
* UpTime
* time the system is running
*
* @return void
*/
private function _uptime()
{
$a = $this->grabkey('kern.boottime');
$this->sys->setUptime(time() - $a);
}
 
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
/**
* get network information
*
* @return void
*/
private function _network()
{
CommonFunctions::executeProgram('netstat', '-nbdi | cut -c1-25,44- | grep Link | grep -v \'* \'', $netstat_b, PSI_DEBUG);
CommonFunctions::executeProgram('netstat', '-ndi | cut -c1-25,44- | grep Link | grep -v \'* \'', $netstat_n, PSI_DEBUG);
$lines_b = preg_split("/\n/", $netstat_b, -1, PREG_SPLIT_NO_EMPTY);
$lines_n = preg_split("/\n/", $netstat_n, -1, PREG_SPLIT_NO_EMPTY);
for ($i = 0, $max = sizeof($lines_b); $i < $max; $i++) {
$ar_buf_b = preg_split("/\s+/", $lines_b[$i]);
$ar_buf_n = preg_split("/\s+/", $lines_n[$i]);
if (!empty($ar_buf_b[0]) && (!empty($ar_buf_n[3]) || ($ar_buf_n[3] === "0"))) {
$dev = new NetDevice();
$dev->setName($ar_buf_b[0]);
$dev->setTxBytes($ar_buf_b[4]);
$dev->setRxBytes($ar_buf_b[3]);
$dev->setErrors($ar_buf_n[4] + $ar_buf_n[6]);
$dev->setDrops($ar_buf_n[8]);
if (defined('PSI_SHOW_NETWORK_INFOS') && (PSI_SHOW_NETWORK_INFOS) && (CommonFunctions::executeProgram('ifconfig', $ar_buf_b[0].' 2>/dev/null', $bufr2, PSI_DEBUG))) {
$speedinfo = "";
$bufe2 = preg_split("/\n/", $bufr2, -1, PREG_SPLIT_NO_EMPTY);
foreach ($bufe2 as $buf2) {
if (preg_match('/^\s+lladdr\s+(\S+)/i', $buf2, $ar_buf2)) {
if (!defined('PSI_HIDE_NETWORK_MACADDR') || !PSI_HIDE_NETWORK_MACADDR) $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').preg_replace('/:/', '-', strtoupper($ar_buf2[1])));
} elseif (preg_match('/^\s+inet\s+(\S+)\s+netmask/i', $buf2, $ar_buf2)) {
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$ar_buf2[1]);
} elseif ((preg_match('/^\s+inet6\s+([^\s%]+)\s+prefixlen/i', $buf2, $ar_buf2)
|| preg_match('/^\s+inet6\s+([^\s%]+)%\S+\s+prefixlen/i', $buf2, $ar_buf2))
&& ($ar_buf2[1]!="::") && !preg_match('/^fe80::/i', $ar_buf2[1])) {
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').strtolower($ar_buf2[1]));
} elseif (preg_match('/^\s+media:\s+/i', $buf2) && preg_match('/[\(\s](\d+)(G*)base/i', $buf2, $ar_buf2)) {
if (isset($ar_buf2[2]) && strtoupper($ar_buf2[2])=="G") {
$unit = "G";
} else {
$unit = "M";
}
if (preg_match('/\s(\S+)-duplex/i', $buf2, $ar_buf3))
$speedinfo = $ar_buf2[1].$unit.'b/s '.strtolower($ar_buf3[1]);
else
$speedinfo = $ar_buf2[1].$unit.'b/s';
}
}
if ($speedinfo != "") $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$speedinfo);
}
$this->sys->setNetDevices($dev);
}
}
}
 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
/**
* IDE information
*
* @return void
*/
protected function ide()
{
foreach ($this->readdmesg() as $line) {
if (preg_match('/^(.*) at pciide[0-9]+ (.*): <(.*)>/', $line, $ar_buf)) {
$dev = new HWDevice();
$dev->setName($ar_buf[3]);
if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS) {
// now loop again and find the capacity
foreach ($this->readdmesg() as $line2) {
if (preg_match("/^(".$ar_buf[1]."): (.*), (.*), (.*)MB, .*$/", $line2, $ar_buf_n)) {
$dev->setCapacity($ar_buf_n[4] * 1024 * 1024);
break;
}
}
}
$this->sys->setIdeDevices($dev);
}
}
}
 
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
/**
* get CPU information
*
* @return void
*/
protected function cpuinfo()
{
$dev = new CpuDevice();
$dev->setModel($this->grabkey('hw.model'));
$dev->setCpuSpeed($this->grabkey('hw.cpuspeed'));
$was = false;
foreach ($this->readdmesg() as $line) {
if (preg_match("/^cpu[0-9]+: (.*)/", $line, $ar_buf)) {
$was = true;
if (preg_match("/^cpu[0-9]+: (\d+)([KM])B (.*) L2 cache/", $line, $ar_buf2)) {
if ($ar_buf2[2]=="M") {
$dev->setCache($ar_buf2[1]*1024*1024);
} elseif ($ar_buf2[2]=="K") {
$dev->setCache($ar_buf2[1]*1024);
}
} else {
$feats = preg_split("/,/", strtolower(trim($ar_buf[1])), -1, PREG_SPLIT_NO_EMPTY);
foreach ($feats as $feat) {
if (($feat=="vmx") || ($feat=="svm")) {
$dev->setVirt($feat);
}
}
}
} elseif ($was) {
break;
}
}
$ncpu = $this->grabkey('hw.ncpu');
if (is_null($ncpu) || (trim($ncpu) == "") || (!($ncpu >= 1)))
$ncpu = 1;
for ($ncpu ; $ncpu > 0 ; $ncpu--) {
$this->sys->setCpus($dev);
}
}
 
// $Id: class.OpenBSD.inc.php,v 1.21 2006/04/18 17:46:15 bigmichi1 Exp $
if (!defined('IN_PHPSYSINFO')) {
die("No Hacking");
}
/**
* get icon name
*
* @return void
*/
private function _distroicon()
{
$this->sys->setDistributionIcon('OpenBSD.png');
}
 
require_once(APP_ROOT . '/includes/os/class.BSD.common.inc.php');
/**
* Processes
*
* @return void
*/
protected function _processes()
{
if (CommonFunctions::executeProgram('ps', 'aux', $bufr, PSI_DEBUG)) {
$lines = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
$processes['*'] = 0;
foreach ($lines as $line) {
if (preg_match("/^\S+\s+\d+\s+\S+\s+\S+\s+\d+\s+\d+\s+\S+\s+(\w)/", $line, $ar_buf)) {
$processes['*']++;
$state = $ar_buf[1];
if ($state == 'I') $state = 'S'; //linux format
if (isset($processes[$state])) {
$processes[$state]++;
} else {
$processes[$state] = 1;
}
}
}
if ($processes['*'] > 0) {
$this->sys->setProcesses($processes);
}
}
}
 
class sysinfo extends bsd_common {
var $cpu_regexp = "";
var $scsi_regexp1 = "";
var $scsi_regexp2 = "";
var $cpu_regexp2 = "";
// Our contstructor
// this function is run on the initialization of this class
function sysinfo () {
$this->bsd_common();
$this->cpu_regexp = "^cpu(.*) (.*) MHz";
$this->scsi_regexp1 = "^(.*) at scsibus.*: <(.*)> .*";
$this->scsi_regexp2 = "^(da[0-9]): (.*)MB ";
$this->cpu_regexp2 = "/(.*),(.*),(.*),(.*),(.*)/";
$this->pci_regexp1 = '/(.*) at pci[0-9] .* "(.*)"/';
$this->pci_regexp2 = '/"(.*)" (.*).* at [.0-9]+ irq/';
}
 
function get_sys_ticks () {
$a = $this->grab_key('kern.boottime');
$sys_ticks = time() - $a;
return $sys_ticks;
}
 
function network () {
$netstat_b = execute_program('netstat', '-nbdi | cut -c1-25,44- | grep Link | grep -v \'* \'');
$netstat_n = execute_program('netstat', '-ndi | cut -c1-25,44- | grep Link | grep -v \'* \'');
$lines_b = explode("\n", $netstat_b);
$lines_n = explode("\n", $netstat_n);
$results = array();
for ($i = 0, $max = sizeof($lines_b); $i < $max; $i++) {
$ar_buf_b = preg_split("/\s+/", $lines_b[$i]);
$ar_buf_n = preg_split("/\s+/", $lines_n[$i]);
if (!empty($ar_buf_b[0]) && !empty($ar_buf_n[3])) {
$results[$ar_buf_b[0]] = array();
 
$results[$ar_buf_b[0]]['rx_bytes'] = $ar_buf_b[3];
$results[$ar_buf_b[0]]['rx_packets'] = $ar_buf_n[3];
$results[$ar_buf_b[0]]['rx_errs'] = $ar_buf_n[4];
$results[$ar_buf_b[0]]['rx_drop'] = $ar_buf_n[8];
 
$results[$ar_buf_b[0]]['tx_bytes'] = $ar_buf_b[4];
$results[$ar_buf_b[0]]['tx_packets'] = $ar_buf_n[5];
$results[$ar_buf_b[0]]['tx_errs'] = $ar_buf_n[6];
$results[$ar_buf_b[0]]['tx_drop'] = $ar_buf_n[8];
 
$results[$ar_buf_b[0]]['errs'] = $ar_buf_n[4] + $ar_buf_n[6];
$results[$ar_buf_b[0]]['drop'] = $ar_buf_n[8];
}
}
return $results;
}
// get the ide device information out of dmesg
function ide () {
$results = array();
 
$s = 0;
for ($i = 0, $max = count($this->read_dmesg()); $i < $max; $i++) {
$buf = $this->dmesg[$i];
if (preg_match('/^(.*) at pciide[0-9] (.*): <(.*)>/', $buf, $ar_buf)) {
$s = $ar_buf[1];
$results[$s]['model'] = $ar_buf[3];
$results[$s]['media'] = 'Hard Disk';
// now loop again and find the capacity
for ($j = 0, $max1 = count($this->read_dmesg()); $j < $max1; $j++) {
$buf_n = $this->dmesg[$j];
if (preg_match("/^($s): (.*), (.*), (.*)MB, .*$/", $buf_n, $ar_buf_n)) {
$results[$s]['capacity'] = $ar_buf_n[4] * 2048 * 1.049;;
}
}
}
}
asort($results);
return $results;
}
 
function distroicon () {
$result = 'OpenBSD.png';
return($result);
}
}
 
?>
/**
* get the information
*
* @see BSDCommon::build()
*
* @return Void
*/
public function build()
{
parent::build();
if (!$this->blockname || $this->blockname==='vitals') {
$this->_distroicon();
$this->_uptime();
$this->_processes();
}
if (!$this->blockname || $this->blockname==='network') {
$this->_network();
}
}
}
/web/acc/phpsysinfo/includes/os/class.QNX.inc.php
0,0 → 1,233
<?php
/**
* QNX System Class
*
* PHP version 5
*
* @category PHP
* @package PSI QNX OS class
* @author Mieczyslaw Nalewaj <namiltd@users.sourceforge.net>
* @copyright 2012 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License version 2, or (at your option) any later version
* @version SVN: $Id: class.QNX.inc.php 687 2012-09-06 20:54:49Z namiltd $
* @link http://phpsysinfo.sourceforge.net
*/
/**
* QNX sysinfo class
* get all the required information from QNX system
*
* @category PHP
* @package PSI QNX OS class
* @author Mieczyslaw Nalewaj <namiltd@users.sourceforge.net>
* @copyright 2012 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License version 2, or (at your option) any later version
* @version Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
class QNX extends OS
{
/**
* get the cpu information
*
* @return void
*/
protected function _cpuinfo()
{
if (CommonFunctions::executeProgram('pidin', 'info', $buf)
&& preg_match('/^Processor\d+: (.*)/m', $buf)) {
$lines = preg_split("/\n/", $buf, -1, PREG_SPLIT_NO_EMPTY);
foreach ($lines as $line) {
if (preg_match('/^Processor\d+: (.+)/', $line, $proc)) {
$dev = new CpuDevice();
$dev->SetModel(trim($proc[1]));
if (preg_match('/(\d+)MHz/', $proc[1], $mhz)) {
$dev->setCpuSpeed($mhz[1]);
}
$this->sys->setCpus($dev);
}
}
}
}
 
/**
* QNX Version
*
* @return void
*/
private function _kernel()
{
if (CommonFunctions::executeProgram('uname', '-rvm', $ret)) {
$this->sys->setKernel($ret);
}
}
 
/**
* Distribution
*
* @return void
*/
protected function _distro()
{
if (CommonFunctions::executeProgram('uname', '-sr', $ret))
$this->sys->setDistribution($ret);
else
$this->sys->setDistribution('QNX');
 
$this->sys->setDistributionIcon('QNX.png');
}
 
/**
* UpTime
* time the system is running
*
* @return void
*/
private function _uptime()
{
 
if (CommonFunctions::executeProgram('pidin', 'info', $buf)
&& preg_match('/^.* BootTime:(.*)/', $buf, $bstart)
&& CommonFunctions::executeProgram('date', '', $bstop)) {
/* default error handler */
if (function_exists('errorHandlerPsi')) {
restore_error_handler();
}
/* fatal errors only */
$old_err_rep = error_reporting();
error_reporting(E_ERROR);
 
$uptime = strtotime($bstop)-strtotime($bstart[1]);
if ($uptime > 0) $this->sys->setUptime($uptime);
 
/* restore error level */
error_reporting($old_err_rep);
/* restore error handler */
if (function_exists('errorHandlerPsi')) {
set_error_handler('errorHandlerPsi');
}
}
}
 
/**
* Number of Users
*
* @return void
*/
protected function _users()
{
$this->sys->setUsers(1);
}
 
/**
* Virtual Host Name
*
* @return void
*/
private function _hostname()
{
if (PSI_USE_VHOST === true) {
if (CommonFunctions::readenv('SERVER_NAME', $hnm)) $this->sys->setHostname($hnm);
} else {
if (CommonFunctions::executeProgram('uname', '-n', $result, PSI_DEBUG)) {
$ip = gethostbyname($result);
if ($ip != $result) {
$this->sys->setHostname(gethostbyaddr($ip));
}
}
}
}
 
/**
* Physical memory information and Swap Space information
*
* @return void
*/
private function _memory()
{
if (CommonFunctions::executeProgram('pidin', 'info', $buf)
&& preg_match('/^.* FreeMem:(\S+)Mb\/(\S+)Mb/', $buf, $memm)) {
$this->sys->setMemTotal(1024*1024*$memm[2]);
$this->sys->setMemFree(1024*1024*$memm[1]);
$this->sys->setMemUsed(1024*1024*($memm[2]-$memm[1]));
}
}
 
/**
* filesystem information
*
* @return void
*/
private function _filesystems()
{
$arrResult = Parser::df("-P 2>/dev/null");
foreach ($arrResult as $dev) {
$this->sys->setDiskDevices($dev);
}
}
 
/**
* network information
*
* @return void
*/
private function _network()
{
if (CommonFunctions::executeProgram('ifconfig', '', $bufr, PSI_DEBUG)) {
$lines = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
$was = false;
$dev = null;
foreach ($lines as $line) {
if (preg_match("/^([^\s:]+)/", $line, $ar_buf)) {
if ($was) {
$this->sys->setNetDevices($dev);
}
$dev = new NetDevice();
$dev->setName($ar_buf[1]);
$was = true;
} else {
if ($was) {
if (defined('PSI_SHOW_NETWORK_INFOS') && (PSI_SHOW_NETWORK_INFOS)) {
if (preg_match('/^\s+address:\s*(\S+)/i', $line, $ar_buf2)) {
if (!defined('PSI_HIDE_NETWORK_MACADDR') || !PSI_HIDE_NETWORK_MACADDR) $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').preg_replace('/:/', '-', strtoupper($ar_buf2[1])));
} elseif (preg_match('/^\s+inet\s+(\S+)\s+netmask/i', $line, $ar_buf2))
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$ar_buf2[1]);
 
}
}
}
}
if ($was) {
$this->sys->setNetDevices($dev);
}
}
}
 
/**
* get the information
*
* @return Void
*/
public function build()
{
$this->error->addError("WARN", "The QNX version of phpSysInfo is a work in progress, some things currently don't work");
if (!$this->blockname || $this->blockname==='vitals') {
$this->_distro();
$this->_hostname();
$this->_kernel();
$this->_uptime();
$this->_users();
}
if (!$this->blockname || $this->blockname==='hardware') {
$this->_cpuinfo();
}
if (!$this->blockname || $this->blockname==='network') {
$this->_network();
}
if (!$this->blockname || $this->blockname==='memory') {
$this->_memory();
}
if (!$this->blockname || $this->blockname==='filesystem') {
$this->_filesystems();
}
}
}
/web/acc/phpsysinfo/includes/os/class.SunOS.inc.php
1,240 → 1,483
<?php
<?php
/**
* SunOS System Class
*
* PHP version 5
*
* @category PHP
* @package PSI SunOS OS class
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License version 2, or (at your option) any later version
* @version SVN: $Id: class.SunOS.inc.php 687 2012-09-06 20:54:49Z namiltd $
* @link http://phpsysinfo.sourceforge.net
*/
/**
* SunOS sysinfo class
* get all the required information from SunOS systems
*
* @category PHP
* @package PSI SunOS OS class
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License version 2, or (at your option) any later version
* @version Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
class SunOS extends OS
{
 
// phpSysInfo - A PHP System Information Script
// http://phpsysinfo.sourceforge.net/
/**
* content of prtconf -v
*
* @var array
*/
private $_prtconf = null;
 
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
/**
* Execute prtconf -v and save ass array
*
* @return array
*/
protected function prtconf()
{
if ($this->_prtconf === null) {
$this->_prtconf = array();
if (CommonFunctions::executeProgram('prtconf', '-v', $buf, PSI_DEBUG) && ($buf!="")) {
$blocks = preg_split( '/\n(?= \S)/', $buf, -1, PREG_SPLIT_NO_EMPTY);
if (!empty($blocks) && (count($blocks)>2)) {
array_shift($blocks);
foreach ($blocks as $block) {
if (preg_match('/^ (\S+) /',$block, $ar_buf)) {
$group = trim($ar_buf[1], ',');
$grouparr = array();
$blocks1 = preg_split( '/\n(?= \S)/', $block, -1, PREG_SPLIT_NO_EMPTY);
if (!empty($blocks1) && count($blocks1)) {
array_shift($blocks1);
foreach ($blocks1 as $block1) {
if (!preg_match('/^ name=\'([^\']+)\'/',$block1)
&& preg_match('/^ (\S+) /',$block1, $ar_buf)) {
$device = trim($ar_buf[1], ',');
$devicearr = array();
$blocks2 = preg_split( '/\n(?= \S)/', $block1, -1, PREG_SPLIT_NO_EMPTY);
if (!empty($blocks2) && count($blocks2)) {
array_shift($blocks2);
foreach ($blocks2 as $block2) {
if (!preg_match('/^ name=\'([^\']+)\'/',$block2)
&& preg_match('/^ (\S+) /',$block2, $ar_buf)) {
$subdev = trim($ar_buf[1], ',');
$subdevarr = array();
$blocks3 = preg_split( '/\n(?= \S)/', $block2, -1, PREG_SPLIT_NO_EMPTY);
if (!empty($blocks3) && count($blocks3)) {
array_shift($blocks3);
foreach ($blocks3 as $block3) {
if (preg_match('/^ name=\'([^\']+)\' [\s\S]+ value=\'?([^\']+)\'?/m',$block3, $ar_buf)) {
if ($subdev==='Hardware') {
$subdevarr[$ar_buf[1]] = $ar_buf[2];
$subdevarr['device'] = $device;
}
}
}
if (count($subdevarr)) {
$devicearr = $subdevarr;
}
}
}
}
}
if (count($devicearr)) {
$grouparr[$device][] = $devicearr;
}
}
}
}
if (count($grouparr)) {
$this->_prtconf[$group][] = $grouparr;
}
}
}
}
}
}
 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
return $this->_prtconf;
}
 
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
/**
* Extract kernel values via kstat() interface
*
* @param string $key key for kstat programm
*
* @return string
*/
private function _kstat($key)
{
if (CommonFunctions::executeProgram('kstat', '-p d '.$key, $m, PSI_DEBUG) && ($m!=="")) {
list($key, $value) = preg_split("/\t/", $m, 2);
 
// $Id: class.SunOS.inc.php,v 1.24 2007/02/18 18:59:54 bigmichi1 Exp $
return trim($value);
} else {
return '';
}
}
 
$error->addError("WARN", "The SunOS version of phpSysInfo is work in progress, some things currently don't work");
/**
* Virtual Host Name
*
* @return void
*/
private function _hostname()
{
if (PSI_USE_VHOST === true) {
if (CommonFunctions::readenv('SERVER_NAME', $hnm)) $this->sys->setHostname($hnm);
} else {
if (CommonFunctions::executeProgram('uname', '-n', $result, PSI_DEBUG)) {
$ip = gethostbyname($result);
if ($ip != $result) {
$this->sys->setHostname(gethostbyaddr($ip));
}
}
}
}
 
class sysinfo {
// Extract kernel values via kstat() interface
function kstat ($key) {
$m = execute_program('kstat', "-p d $key");
list($key, $value) = explode("\t", trim($m), 2);
return $value;
}
/**
* Kernel Version
*
* @return void
*/
private function _kernel()
{
if (CommonFunctions::executeProgram('uname', '-s', $os, PSI_DEBUG) && ($os!="")) {
if (CommonFunctions::executeProgram('uname', '-r', $version, PSI_DEBUG) && ($version!="")) {
$os.=' '.$version;
}
if (CommonFunctions::executeProgram('uname', '-v', $subversion, PSI_DEBUG) && ($subversion!="")) {
$os.=' ('.$subversion.')';
}
if (CommonFunctions::executeProgram('uname', '-i', $platform, PSI_DEBUG) && ($platform!="")) {
$os.=' '.$platform;
}
$this->sys->setKernel($os);
}
}
 
function vhostname () {
if (! ($result = getenv('SERVER_NAME'))) {
$result = 'N.A.';
}
return $result;
}
// get the IP address of our vhost name
function vip_addr () {
return gethostbyname($this->vhostname());
}
// get our canonical hostname
function chostname () {
if ($result = execute_program('uname', '-n')) {
$result = gethostbyaddr(gethostbyname($result));
} else {
$result = 'N.A.';
}
return $result;
}
// get the IP address of our canonical hostname
function ip_addr () {
if (!($result = getenv('SERVER_ADDR'))) {
$result = gethostbyname($this->chostname());
}
return $result;
}
/**
* UpTime
* time the system is running
*
* @return void
*/
private function _uptime()
{
$this->sys->setUptime(time() - $this->_kstat('unix:0:system_misc:boot_time'));
}
 
function kernel () {
$os = execute_program('uname', '-s');
$version = execute_program('uname', '-r');
return $os . ' ' . $version;
}
/**
* Processor Load
* optionally create a loadbar
*
* @return void
*/
private function _loadavg()
{
$load1 = $this->_kstat('unix:0:system_misc:avenrun_1min');
$load5 = $this->_kstat('unix:0:system_misc:avenrun_5min');
$load15 = $this->_kstat('unix:0:system_misc:avenrun_15min');
$this->sys->setLoad(round($load1 / 256, 2).' '.round($load5 / 256, 2).' '.round($load15 / 256, 2));
}
 
function uptime () {
$result = time() - $this->kstat('unix:0:system_misc:boot_time');
/**
* CPU information
*
* @return void
*/
private function _cpuinfo()
{
if (CommonFunctions::executeProgram('kstat', '-p d cpu_info:*:cpu_info*:core_id', $m, PSI_DEBUG) && ($m!=="")) {
$cpuc = count(preg_split('/\n/', $m, -1, PREG_SPLIT_NO_EMPTY));
for ($cpu=0; $cpu < $cpuc; $cpu++) {
$dev = new CpuDevice();
if (($buf = $this->_kstat('cpu_info:'.$cpu.':cpu_info'.$cpu.':current_clock_Hz')) !== "") {
$dev->setCpuSpeed($buf/1000000);
} elseif (($buf = $this->_kstat('cpu_info:'.$cpu.':cpu_info'.$cpu.':clock_MHz')) !== "") {
$dev->setCpuSpeed($buf);
}
if (($buf = $this->_kstat('cpu_info:'.$cpu.':cpu_info'.$cpu.':supported_frequencies_Hz')) !== "") {
$cpuarr = preg_split('/:/', $buf, -1, PREG_SPLIT_NO_EMPTY);
if (($cpuarrc=count($cpuarr))>1) {
$dev->setCpuSpeedMin($cpuarr[0]/1000000);
$dev->setCpuSpeedMax($cpuarr[$cpuarrc-1]/1000000);
}
}
if (($buf =$this->_kstat('cpu_info:'.$cpu.':cpu_info'.$cpu.':brand')) !== "") {
$dev->setModel($buf);
} elseif (($buf =$this->_kstat('cpu_info:'.$cpu.':cpu_info'.$cpu.':cpu_type')) !== "") {
$dev->setModel($buf);
} elseif (CommonFunctions::executeProgram('uname', '-p', $buf, PSI_DEBUG) && ($buf!="")) {
$dev->setModel($buf);
} elseif (CommonFunctions::executeProgram('uname', '-i', $buf, PSI_DEBUG) && ($buf!="")) {
$dev->setModel($buf);
}
$this->sys->setCpus($dev);
}
}
}
 
return $result;
}
/**
* PCI devices
*
* @return void
*/
protected function _pci()
{
$prtconf = $this->prtconf();
if ((count($prtconf)>1) && isset($prtconf['pci'])) {
foreach ($prtconf['pci'] as $prt) {
foreach ($prt as $pci) {
foreach ($pci as $pcidev) {
if (isset($pcidev['device'])) {
$dev = new HWDevice();
if (isset($pcidev['model'])) {
$name = $pcidev['model'];
} else {
$name = $pcidev['device'];
}
if (isset($pcidev['device-name'])) {
$name .= ': '.$pcidev['device-name'];
}
$dev->setName($name);
 
function users () {
$who = explode('=', execute_program('who', '-q'));
$result = $who[1];
return $result;
}
if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS) {
if (isset($pcidev['subsystem-name']) && ($pcidev['subsystem-name']!=='unknown subsystem')) {
$dev->setProduct($pcidev['subsystem-name']);
}
if (isset($pcidev['vendor-name'])) {
$dev->setManufacturer($pcidev['vendor-name']);
}
}
 
function loadavg ($bar = false) {
$load1 = $this->kstat('unix:0:system_misc:avenrun_1min');
$load5 = $this->kstat('unix:0:system_misc:avenrun_5min');
$load15 = $this->kstat('unix:0:system_misc:avenrun_15min');
$results['avg'] = array( round($load1/256, 2), round($load5/256, 2), round($load15/256, 2) );
return $results;
}
$this->sys->setPciDevices($dev);
}
}
}
}
}
}
 
function cpu_info () {
$results = array();
$ar_buf = array();
/**
* Network devices
*
* @return void
*/
private function _network()
{
if (CommonFunctions::executeProgram('netstat', '-ni | awk \'(NF ==10){print;}\'', $netstat, PSI_DEBUG)) {
$lines = preg_split("/\n/", $netstat, -1, PREG_SPLIT_NO_EMPTY);
foreach ($lines as $line) {
$ar_buf = preg_split("/\s+/", $line);
if (!empty($ar_buf[0]) && $ar_buf[0] !== 'Name') {
$dev = new NetDevice();
$dev->setName($ar_buf[0]);
$results[$ar_buf[0]]['errs'] = $ar_buf[5] + $ar_buf[7];
if (preg_match('/^(\D+)(\d+)$/', $ar_buf[0], $intf)) {
$prefix = $intf[1].':'.$intf[2].':'.$intf[1].$intf[2].':';
} elseif (preg_match('/^(\D.*)(\d+)$/', $ar_buf[0], $intf)) {
$prefix = $intf[1].':'.$intf[2].':mac:';
} else {
$prefix = "";
}
if ($prefix !== "") {
$cnt = $this->_kstat($prefix.'drop');
if ($cnt > 0) {
$dev->setDrops($cnt);
}
$cnt = $this->_kstat($prefix.'obytes64');
if ($cnt > 0) {
$dev->setTxBytes($cnt);
}
$cnt = $this->_kstat($prefix.'rbytes64');
if ($cnt > 0) {
$dev->setRxBytes($cnt);
}
}
if (defined('PSI_SHOW_NETWORK_INFOS') && (PSI_SHOW_NETWORK_INFOS)) {
if (CommonFunctions::executeProgram('ifconfig', $ar_buf[0], $bufr2, PSI_DEBUG) && ($bufr2!=="")) {
$bufe2 = preg_split("/\n/", $bufr2, -1, PREG_SPLIT_NO_EMPTY);
foreach ($bufe2 as $buf2) {
if (preg_match('/^\s+ether\s+(\S+)/i', $buf2, $ar_buf2)) {
if (!defined('PSI_HIDE_NETWORK_MACADDR') || !PSI_HIDE_NETWORK_MACADDR) $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').preg_replace('/:/', '-', strtoupper($ar_buf2[1])));
} elseif (preg_match('/^\s+inet\s+(\S+)\s+netmask/i', $buf2, $ar_buf2)) {
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$ar_buf2[1]);
}
}
}
if (CommonFunctions::executeProgram('ifconfig', $ar_buf[0].' inet6', $bufr2, PSI_DEBUG) && ($bufr2!=="")) {
$bufe2 = preg_split("/\n/", $bufr2, -1, PREG_SPLIT_NO_EMPTY);
foreach ($bufe2 as $buf2) {
if (preg_match('/^\s+inet6\s+([^\s\/]+)/i', $buf2, $ar_buf2)
&& ($ar_buf2[1]!="::") && !preg_match('/^fe80::/i', $ar_buf2[1]))
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').strtolower($ar_buf2[1]));
}
}
}
 
$results['model'] = execute_program('uname', '-i');
$results['cpuspeed'] = $this->kstat('cpu_info:0:cpu_info0:clock_MHz');
$results['cache'] = $this->kstat('cpu_info:0:cpu_info0:cpu_type');
$results['cpus'] = $this->kstat('unix:0:system_misc:ncpus');
$this->sys->setNetDevices($dev);
}
}
}
}
 
return $results;
}
/**
* Physical memory information and Swap Space information
*
* @return void
*/
private function _memory()
{
$pagesize = $this->_kstat('unix:0:seg_cache:slab_size');
$this->sys->setMemTotal($this->_kstat('unix:0:system_pages:pagestotal') * $pagesize);
$this->sys->setMemUsed($this->_kstat('unix:0:system_pages:pageslocked') * $pagesize);
$this->sys->setMemFree($this->_kstat('unix:0:system_pages:pagesfree') * $pagesize);
$dev = new DiskDevice();
$dev->setName('SWAP');
$dev->setFsType('swap');
$dev->setMountPoint('SWAP');
$dev->setTotal($this->_kstat('unix:0:vminfo:swap_avail') / 1024);
$dev->setUsed($this->_kstat('unix:0:vminfo:swap_alloc') / 1024);
$dev->setFree($this->_kstat('unix:0:vminfo:swap_free') / 1024);
$this->sys->setSwapDevices($dev);
}
 
function pci () {
// FIXME
$results = array();
return $results;
}
/**
* filesystem information
*
* @return void
*/
private function _filesystems()
{
if (CommonFunctions::executeProgram('df', '-k', $df, PSI_DEBUG)) {
$df = preg_replace('/\n\s/m', ' ', $df);
$mounts = preg_split("/\n/", $df, -1, PREG_SPLIT_NO_EMPTY);
foreach ($mounts as $mount) {
$ar_buf = preg_split('/\s+/', $mount, 6);
if (!empty($ar_buf[0]) && $ar_buf[0] !== 'Filesystem') {
$dev = new DiskDevice();
$dev->setName($ar_buf[0]);
$dev->setTotal($ar_buf[1] * 1024);
$dev->setUsed($ar_buf[2] * 1024);
$dev->setFree($ar_buf[3] * 1024);
$dev->setMountPoint($ar_buf[5]);
if (CommonFunctions::executeProgram('df', '-n', $dftypes, PSI_DEBUG)) {
$mounttypes = preg_split("/\n/", $dftypes, -1, PREG_SPLIT_NO_EMPTY);
foreach ($mounttypes as $type) {
$ty_buf = preg_split('/:/', $type, 2);
if (trim($ty_buf[0]) == $dev->getMountPoint()) {
$dev->setFsType($ty_buf[1]);
break;
}
}
} elseif (CommonFunctions::executeProgram('df', '-T', $dftypes, PSI_DEBUG)) {
$dftypes = preg_replace('/\n\s/m', ' ', $dftypes);
$mounttypes = preg_split("/\n/", $dftypes, -1, PREG_SPLIT_NO_EMPTY);
foreach ($mounttypes as $type) {
$ty_buf = preg_split("/\s+/", $type, 3);
if ($ty_buf[0] == $dev->getName()) {
$dev->setFsType($ty_buf[1]);
break;
}
}
}
$this->sys->setDiskDevices($dev);
}
}
}
}
 
function ide () {
// FIXME
$results = array();
return $results;
}
/**
* Distribution Icon
*
* @return void
*/
private function _distro()
{
if (CommonFunctions::rfts('/etc/release', $buf, 1, 4096, false) && (trim($buf)!="")) {
$this->sys->setDistribution(trim($buf));
$list = @parse_ini_file(PSI_APP_ROOT."/data/distros.ini", true);
if ($list && preg_match('/^(\S+)\s*/', preg_replace('/^Open\s+/', 'Open', preg_replace('/^Oracle\s+/', 'Oracle', trim($buf))), $id_buf) && isset($list[$distid=(trim($id_buf[1].' SunOS'))]['Image'])) {
$this->sys->setDistributionIcon($list[$distid]['Image']);
if (isset($list[trim($distid)]['Name'])) {
$this->sys->setDistribution(trim($list[$distid]['Name']).' '.$this->sys->getDistribution());
}
} else {
$this->sys->setDistributionIcon('SunOS.png');
}
} else {
$this->sys->setDistribution('SunOS');
$this->sys->setDistributionIcon('SunOS.png');
}
}
 
function scsi () {
// FIXME
$results = array();
return $results;
}
/**
* Processes
*
* @return void
*/
protected function _processes()
{
if (CommonFunctions::executeProgram('ps', 'aux', $bufr, PSI_DEBUG)) {
$lines = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
$processes['*'] = 0;
foreach ($lines as $line) {
if (preg_match("/^\S+\s+\d+\s+\S+\s+\S+\s+\d+\s+\d+\s+\S+\s+(\w)/", $line, $ar_buf)) {
$processes['*']++;
$state = $ar_buf[1];
if ($state == 'O') $state = 'R'; //linux format
elseif ($state == 'W') $state = 'D';
elseif ($state == 'D') $state = 'd'; //invalid
if (isset($processes[$state])) {
$processes[$state]++;
} else {
$processes[$state] = 1;
}
}
}
if ($processes['*'] > 0) {
$this->sys->setProcesses($processes);
}
}
}
 
function usb () {
// FIXME
$results = array();
return $results;
}
 
function sbus () {
$results = array();
$_results[0] = "";
// TODO. Nothing here yet. Move along.
$results = $_results;
return $results;
}
 
function network () {
$results = array();
 
$netstat = execute_program('netstat', '-ni | awk \'(NF ==10){print;}\'');
$lines = explode("\n", $netstat);
$results = array();
for ($i = 0, $max = sizeof($lines); $i < $max; $i++) {
$ar_buf = preg_split("/\s+/", $lines[$i]);
if ((!empty($ar_buf[0])) && ($ar_buf[0] != 'Name')) {
$results[$ar_buf[0]] = array();
 
$results[$ar_buf[0]]['rx_bytes'] = 0;
$results[$ar_buf[0]]['rx_packets'] = $ar_buf[4];
$results[$ar_buf[0]]['rx_errs'] = $ar_buf[5];
$results[$ar_buf[0]]['rx_drop'] = 0;
 
$results[$ar_buf[0]]['tx_bytes'] = 0;
$results[$ar_buf[0]]['tx_packets'] = $ar_buf[6];
$results[$ar_buf[0]]['tx_errs'] = $ar_buf[7];
$results[$ar_buf[0]]['tx_drop'] = 0;
 
$results[$ar_buf[0]]['errs'] = $ar_buf[5] + $ar_buf[
7];
$results[$ar_buf[0]]['drop'] = 0;
 
preg_match('/^(\D+)(\d+)$/', $ar_buf[0], $intf);
$prefix = $intf[1] . ':' . $intf[2] . ':' . $intf[1] . $intf[2] . ':';
$cnt = $this->kstat($prefix . 'drop');
 
if ($cnt > 0) {
$results[$ar_buf[0]]['rx_drop'] = $cnt;
}
$cnt = $this->kstat($prefix . 'obytes64');
 
if ($cnt > 0) {
$results[$ar_buf[0]]['tx_bytes'] = $cnt;
}
$cnt = $this->kstat($prefix . 'rbytes64');
 
if ($cnt > 0) {
$results[$ar_buf[0]]['rx_bytes'] = $cnt;
/**
* get the information
*
* @see PSI_Interface_OS::build()
*
* @return Void
*/
public function build()
{
$this->error->addError("WARN", "The SunOS version of phpSysInfo is a work in progress, some things currently don't work");
if (!$this->blockname || $this->blockname==='vitals') {
$this->_distro();
$this->_hostname();
$this->_kernel();
$this->_uptime();
$this->_users();
$this->_loadavg();
$this->_processes();
}
}
}
return $results;
}
 
function memory () {
$results['devswap'] = array();
 
$results['ram'] = array();
 
$pagesize = $this->kstat('unix:0:seg_cache:slab_size');
$results['ram']['total'] = $this->kstat('unix:0:system_pages:pagestotal') * $pagesize / 1024;
$results['ram']['used'] = $this->kstat('unix:0:system_pages:pageslocked') * $pagesize / 1024;
$results['ram']['free'] = $this->kstat('unix:0:system_pages:pagesfree') * $pagesize / 1024;
$results['ram']['shared'] = 0;
$results['ram']['buffers'] = 0;
$results['ram']['cached'] = 0;
 
$results['ram']['percent'] = round(($results['ram']['used'] * 100) / $results['ram']['total']);
 
$results['swap'] = array();
$results['swap']['total'] = $this->kstat('unix:0:vminfo:swap_avail') / 1024 / 1024;
$results['swap']['used'] = $this->kstat('unix:0:vminfo:swap_alloc') / 1024 / 1024;
$results['swap']['free'] = $this->kstat('unix:0:vminfo:swap_free') / 1024 / 1024;
$results['swap']['percent'] = round(($ar_buf[1] * 100) / $ar_buf[0]);
$results['swap']['percent'] = round(($results['swap']['used'] * 100) / $results['swap']['total']);
return $results;
}
 
function filesystems () {
$df = execute_program('df', '-k');
$mounts = explode("\n", $df);
 
$dftypes = execute_program('df', '-n');
$mounttypes = explode("\n", $dftypes);
 
for ($i = 1, $j = 0, $max = sizeof($mounts); $i < $max; $i++) {
$ar_buf = preg_split('/\s+/', $mounts[$i], 6);
$ty_buf = explode(':', $mounttypes[$i-1], 2);
 
if (hide_mount($ar_buf[5])) {
continue;
}
 
$results[$j] = array();
 
$results[$j]['disk'] = $ar_buf[0];
$results[$j]['size'] = $ar_buf[1];
$results[$j]['used'] = $ar_buf[2];
$results[$j]['free'] = $ar_buf[3];
$results[$j]['percent'] = round(($results[$j]['used'] * 100) / $results[$j]['size']);
$results[$j]['mount'] = $ar_buf[5];
$results[$j]['fstype'] = $ty_buf[1];
$j++;
}
return $results;
}
function distro () {
$result = 'SunOS';
return($result);
}
 
function distroicon () {
$result = 'SunOS.png';
return($result);
}
}
 
?>
if (!$this->blockname || $this->blockname==='hardware') {
$this->_cpuinfo();
$this->_pci();
}
if (!$this->blockname || $this->blockname==='network') {
$this->_network();
}
if (!$this->blockname || $this->blockname==='memory') {
$this->_memory();
}
if (!$this->blockname || $this->blockname==='filesystem') {
$this->_filesystems();
}
}
}
/web/acc/phpsysinfo/includes/os/class.WINNT.inc.php
1,344 → 1,1015
<?php
// phpSysInfo - A PHP System Information Script
// http://phpsysinfo.sourceforge.net/
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
// WINNT implementation written by Carl C. Longnecker, longneck@iname.com
// $Id: class.WINNT.inc.php,v 1.25 2007/03/07 20:21:27 bigmichi1 Exp $
<?php
/**
* WINNT System Class
*
* PHP version 5
*
* @category PHP
* @package PSI WINNT OS class
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License version 2, or (at your option) any later version
* @version SVN: $Id: class.WINNT.inc.php 699 2012-09-15 11:57:13Z namiltd $
* @link http://phpsysinfo.sourceforge.net
*/
/**
* WINNT sysinfo class
* get all the required information from WINNT systems
* information are retrieved through the WMI interface
*
* @category PHP
* @package PSI WINNT OS class
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License version 2, or (at your option) any later version
* @version Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
class WINNT extends OS
{
/**
* holds the data from WMI Win32_OperatingSystem
*
* @var array
*/
private $_Win32_OperatingSystem = null;
 
class sysinfo {
// $wmi holds the COM object that we pull all the WMI data from
var $wmi;
/**
* holds the data from WMI Win32_ComputerSystem
*
* @var array
*/
private $_Win32_ComputerSystem = null;
 
// $wmidevices holds all devices, which are in the system
var $wmidevices;
/**
* holds the data from WMI Win32_Processor
*
* @var array
*/
private $_Win32_Processor = null;
 
// this constructor initialis the $wmi object
function sysinfo ()
{
// don't set this params for local connection, it will not work
$strHostname = '';
$strUser = '';
$strPassword = '';
/**
* holds the data from WMI Win32_PerfFormattedData_PerfOS_Processor
*
* @var array
*/
private $_Win32_PerfFormattedData_PerfOS_Processor = null;
 
// initialize the wmi object
$objLocator = new COM("WbemScripting.SWbemLocator");
if($strHostname == "") {
$this->wmi = $objLocator->ConnectServer();
} else{
$this->wmi = $objLocator->ConnectServer($strHostname, "rootcimv2", "$strHostname\$strUser", $strPassword);
}
}
/**
* holds the data from systeminfo command
*
* @var string
*/
private $_systeminfo = null;
 
// private function for getting a list of values in the specified context, optionally filter this list, based on the list from second parameter
function _GetWMI($strClass, $strValue = array() ) {
$objWEBM = $this->wmi->Get($strClass);
/**
* holds the COM object that we pull all the WMI data from
*
* @var Object
*/
private $_wmi = null;
 
if( PHP_VERSION < 5 ) {
$objProp = $objWEBM->Properties_;
$arrProp = $objProp->Next($objProp->Count);
$objWEBMCol = $objWEBM->Instances_();
$arrWEBMCol = $objWEBMCol->Next($objWEBMCol->Count);
} else {
$arrProp = $objWEBM->Properties_;
$arrWEBMCol = $objWEBM->Instances_();
/**
* holds the COM object that we pull all the RegRead data from
*
* @var Object
*/
private $_reg = null;
 
/**
* holds the COM object that we pull all the EnumKey data from
*
* @var Object
*/
private $_key = null;
 
/**
* holds all devices, which are in the system
*
* @var array
*/
private $_wmidevices;
 
/**
* holds all disks, which are in the system
*
* @var array
*/
private $_wmidisks;
 
/**
* store language encoding of the system to convert some output to utf-8
*
* @var string
*/
private $_codepage = null;
 
/**
* store language of the system
*
* @var string
*/
private $_syslang = null;
 
/**
* reads the data from WMI Win32_OperatingSystem
*
* @return array
*/
private function _get_Win32_OperatingSystem()
{
if ($this->_Win32_OperatingSystem === null) $this->_Win32_OperatingSystem = CommonFunctions::getWMI($this->_wmi, 'Win32_OperatingSystem', array('CodeSet', 'Locale', 'LastBootUpTime', 'LocalDateTime', 'Version', 'ServicePackMajorVersion', 'Caption', 'OSArchitecture', 'TotalVisibleMemorySize', 'FreePhysicalMemory'));
return $this->_Win32_OperatingSystem;
}
 
foreach($arrWEBMCol as $objItem)
/**
* reads the data from WMI Win32_ComputerSystem
*
* @return array
*/
private function _get_Win32_ComputerSystem()
{
@reset($arrProp);
$arrInstance = array();
foreach($arrProp as $propItem)
{
eval("\$value = \$objItem->" .$propItem->Name .";");
if( empty( $strValue ) ) {
$arrInstance[$propItem->Name] = trim($value);
} else {
if( in_array( $propItem->Name, $strValue ) ) {
$arrInstance[$propItem->Name] = trim($value);
}
if ($this->_Win32_ComputerSystem === null) $this->_Win32_ComputerSystem = CommonFunctions::getWMI($this->_wmi, 'Win32_ComputerSystem', array('Name', 'Manufacturer', 'Model'));
return $this->_Win32_ComputerSystem;
}
 
/**
* reads the data from WMI Win32_Processor
*
* @return array
*/
private function _get_Win32_Processor()
{
if ($this->_Win32_Processor === null) $this->_Win32_Processor = CommonFunctions::getWMI($this->_wmi, 'Win32_Processor', array('LoadPercentage', 'AddressWidth', 'Name', 'L2CacheSize', 'L3CacheSize', 'CurrentClockSpeed', 'ExtClock', 'NumberOfCores', 'NumberOfLogicalProcessors', 'MaxClockSpeed', 'Manufacturer'));
return $this->_Win32_Processor;
}
 
/**
* reads the data from WMI Win32_PerfFormattedData_PerfOS_Processor
*
* @return array
*/
private function _get_Win32_PerfFormattedData_PerfOS_Processor()
{
if ($this->_Win32_PerfFormattedData_PerfOS_Processor === null) {
$this->_Win32_PerfFormattedData_PerfOS_Processor = array();
$buffer = $this->_get_Win32_OperatingSystem();
if ($buffer && isset($buffer[0]) && isset($buffer[0]['Version']) && version_compare($buffer[0]['Version'], "5.1", ">=")) { // minimal windows 2003 or windows XP
$cpubuffer = CommonFunctions::getWMI($this->_wmi, 'Win32_PerfFormattedData_PerfOS_Processor', array('Name', 'PercentProcessorTime'));
if ($cpubuffer) foreach ($cpubuffer as $cpu) {
if (isset($cpu['Name']) && isset($cpu['PercentProcessorTime'])) {
$this->_Win32_PerfFormattedData_PerfOS_Processor['cpu'.$cpu['Name']] = $cpu['PercentProcessorTime'];
}
}
}
}
$arrData[] = $arrInstance;
}
return $arrData;
}
 
// private function for getting different device types from the system
function _devicelist ( $strType ) {
if( empty( $this->wmidevices ) ) {
$this->wmidevices = $this->_GetWMI( "Win32_PnPEntity", array( "Name", "PNPDeviceID" ) );
return $this->_Win32_PerfFormattedData_PerfOS_Processor;
}
 
$list = array();
foreach ( $this->wmidevices as $device ) {
if ( substr( $device["PNPDeviceID"], 0, strpos( $device["PNPDeviceID"], "\\" ) + 1 ) == ( $strType . "\\" ) ) {
$list[] = $device["Name"];
}
/**
* reads the data from systeminfo
*
* @return string
*/
private function _get_systeminfo()
{
if ($this->_systeminfo === null) CommonFunctions::executeProgram('systeminfo', '', $this->_systeminfo, false);
return $this->_systeminfo;
}
 
return $list;
}
// get our apache SERVER_NAME or vhost
function vhostname () {
if (! ($result = getenv('SERVER_NAME'))) {
$result = 'N.A.';
}
return $result;
}
/**
* build the global Error object and create the WMI connection
*/
public function __construct($blockname = false)
{
parent::__construct($blockname);
try {
// initialize the wmi object
$objLocator = new COM('WbemScripting.SWbemLocator');
$this->_wmi = $objLocator->ConnectServer('', 'root\CIMv2');
} catch (Exception $e) {
$this->error->addError("WMI connect error", "PhpSysInfo can not connect to the WMI interface for security reasons.\nCheck an authentication mechanism for the directory where phpSysInfo is installed.");
}
try {
// initialize the RegRead object
$this->_reg = new COM("WScript.Shell");
} catch (Exception $e) {
//$this->error->addError("Windows Scripting Host error", "PhpSysInfo can not initialize Windows Scripting Host for security reasons.\nCheck an authentication mechanism for the directory where phpSysInfo is installed.");
$this->_reg = false;
}
try {
// initialize the EnumKey object
$this->_key = new COM("winmgmts:{impersonationLevel=impersonate}!\\\\.\\root\\default:StdRegProv");
} catch (Exception $e) {
//$this->error->addError("WWinmgmts Impersonationlevel Script Error", "PhpSysInfo can not initialize Winmgmts Impersonationlevel Script for security reasons.\nCheck an authentication mechanism for the directory where phpSysInfo is installed.");
$this->_key = false;
}
 
// get the IP address of our vhost name
function vip_addr () {
return gethostbyname($this->vhostname());
}
$this->_getCodeSet();
}
 
// get our canonical hostname
function chostname ()
{
$buffer = $this->_GetWMI( "Win32_ComputerSystem", array( "Name" ) );
$result = $buffer[0]["Name"];
return gethostbyaddr(gethostbyname($result));
}
/**
* store the codepage of the os for converting some strings to utf-8
*
* @return void
*/
private function _getCodeSet()
{
$buffer = $this->_get_Win32_OperatingSystem();
if (!$buffer) {
if (CommonFunctions::readReg($this->_reg, "HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Nls\\CodePage\\ACP", $strBuf, false)) {
$buffer[0]['CodeSet'] = $strBuf;
}
if (CommonFunctions::readReg($this->_reg, "HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Nls\\Language\\Default", $strBuf, false)) {
$buffer[0]['Locale'] = $strBuf;
}
}
if ($buffer && isset($buffer[0])) {
if (isset($buffer[0]['CodeSet'])) {
$codeset = $buffer[0]['CodeSet'];
if ($codeset == 932) {
$codename = ' (SJIS)';
} elseif ($codeset == 949) {
$codename = ' (EUC-KR)';
} elseif ($codeset == 950) {
$codename = ' (BIG-5)';
} else {
$codename = '';
}
CommonFunctions::setcp($codeset);
$this->_codepage = 'windows-'.$codeset.$codename;
}
if (isset($buffer[0]['Locale']) && (($locale = hexdec($buffer[0]['Locale']))>0)) {
$lang = "";
if (is_readable(PSI_APP_ROOT.'/data/languages.ini') && ($langdata = @parse_ini_file(PSI_APP_ROOT.'/data/languages.ini', true))) {
if (isset($langdata['WINNT'][$locale])) {
$lang = $langdata['WINNT'][$locale];
}
}
if ($lang == "") {
$lang = 'Unknown';
}
$this->_syslang = $lang.' ('.$locale.')';
}
}
}
 
// get the IP address of our canonical hostname
function ip_addr ()
{
$buffer = $this->_GetWMI( "Win32_ComputerSystem", array( "Name" ) );
$result = $buffer[0]["Name"];
return gethostbyname($result);
}
/**
* retrieve different device types from the system based on selector
*
* @param string $strType type of the devices that should be returned
*
* @return array list of devices of the specified type
*/
private function _devicelist($strType)
{
if (empty($this->_wmidevices)) {
if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS) {
$this->_wmidevices = CommonFunctions::getWMI($this->_wmi, 'Win32_PnPEntity', array('Name', 'PNPDeviceID', 'Manufacturer', 'PNPClass'));
if (defined('PSI_SHOW_DEVICES_SERIAL') && PSI_SHOW_DEVICES_SERIAL) {
$this->_wmidisks = CommonFunctions::getWMI($this->_wmi, 'Win32_DiskDrive', array('PNPDeviceID', 'Size', 'SerialNumber'));
} else {
$this->_wmidisks = CommonFunctions::getWMI($this->_wmi, 'Win32_DiskDrive', array('PNPDeviceID', 'Size'));
}
} else {
$this->_wmidevices = CommonFunctions::getWMI($this->_wmi, 'Win32_PnPEntity', array('Name', 'PNPDeviceID'));
$this->_wmidisks = array();
}
}
$list = array();
foreach ($this->_wmidevices as $device) {
if (substr($device['PNPDeviceID'], 0, strpos($device['PNPDeviceID'], "\\") + 1) == ($strType."\\")) {
if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS) {
if (!isset($device['PNPClass']) || ($device['PNPClass']===$strType) || ($device['PNPClass']==='System')) {
$device['PNPClass'] = null;
}
if (preg_match('/^\(.*\)$/', $device['Manufacturer'])) {
$device['Manufacturer'] = null;
}
$device['Capacity'] = null;
if (($strType==='IDE')||($strType==='SCSI')) {
foreach ($this->_wmidisks as $disk) {
if (($disk['PNPDeviceID'] === $device['PNPDeviceID']) && isset($disk['Size'])) {
$device['Capacity'] = $disk['Size'];
break;
}
}
}
$device['Serial'] = null;
if (defined('PSI_SHOW_DEVICES_SERIAL') && PSI_SHOW_DEVICES_SERIAL) {
if ($strType==='USB') {
if (preg_match('/\\\\(\w+)$/', $device['PNPDeviceID'], $buf)) {
$device['Serial'] = $buf[1];
}
} elseif (($strType==='IDE')||($strType==='SCSI')) {
foreach ($this->_wmidisks as $disk) {
if (($disk['PNPDeviceID'] === $device['PNPDeviceID']) && isset($disk['SerialNumber'])) {
$device['Serial'] = $disk['SerialNumber'];
break;
}
}
}
}
$list[] = array('Name'=>$device['Name'], 'Manufacturer'=>$device['Manufacturer'], 'Product'=>$device['PNPClass'], 'Capacity'=>$device['Capacity'], 'Serial'=>$device['Serial']);
} else {
$list[] = array('Name'=>$device['Name']);
}
}
}
 
function kernel ()
{
$buffer = $this->_GetWMI( "Win32_OperatingSystem", array( "Version", "ServicePackMajorVersion" ) );
$result = $buffer[0]["Version"];
if( $buffer[0]["ServicePackMajorVersion"] > 0 ) {
$result .= " SP" . $buffer[0]["ServicePackMajorVersion"];
return $list;
}
return $result;
}
 
// get the time the system is running
function uptime ()
{
$result = 0;
$buffer = $this->_GetWMI( "Win32_OperatingSystem", array( "LastBootUpTime", "LocalDateTime" ) );
/**
* Host Name
*
* @return void
*/
private function _hostname()
{
if (PSI_USE_VHOST === true) {
if (CommonFunctions::readenv('SERVER_NAME', $hnm)) $this->sys->setHostname($hnm);
} else {
$buffer = $this->_get_Win32_ComputerSystem();
if (!$buffer && CommonFunctions::readReg($this->_reg, "HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\ComputerName\\ActiveComputerName\\ComputerName", $strBuf, false) && (strlen($strBuf) > 0)) {
$buffer[0]['Name'] = $strBuf;
}
if ($buffer) {
$result = $buffer[0]['Name'];
$ip = gethostbyname($result);
if ($ip != $result) {
if ((version_compare("10.0.0.0", $ip, "<=") && version_compare($ip, "10.255.255.255", "<=")) ||
(version_compare("172.16.0.0", $ip, "<=") && version_compare($ip, "172.31.255.255", "<=")) ||
(version_compare("192.168.0.0", $ip, "<=") && version_compare($ip, "192.168.255.255", "<=")) ||
(version_compare("127.0.0.0", $ip, "<=") && version_compare($ip, "127.255.255.255", "<=")) ||
(version_compare("169.254.1.0", $ip, "<=") && version_compare($ip, "169.254.254.255", "<=")) ||
(version_compare("255.255.255.255", $ip, "=="))) {
$this->sys->setHostname($result); // internal ip
} else {
$this->sys->setHostname(gethostbyaddr($ip));
}
}
} else {
if (CommonFunctions::readenv('COMPUTERNAME', $hnm)) $this->sys->setHostname($hnm);
}
}
}
 
$byear = intval(substr($buffer[0]["LastBootUpTime"], 0, 4));
$bmonth = intval(substr($buffer[0]["LastBootUpTime"], 4, 2));
$bday = intval(substr($buffer[0]["LastBootUpTime"], 6, 2));
$bhour = intval(substr($buffer[0]["LastBootUpTime"], 8, 2));
$bminute = intval(substr($buffer[0]["LastBootUpTime"], 10, 2));
$bseconds = intval(substr($buffer[0]["LastBootUpTime"], 12, 2));
/**
* UpTime
* time the system is running
*
* @return void
*/
private function _uptime()
{
$result = 0;
date_default_timezone_set('UTC');
$buffer = $this->_get_Win32_OperatingSystem();
if ($buffer && ($buffer[0]['LastBootUpTime'] !== null)) {
$local = $buffer[0]['LocalDateTime'];
$boot = $buffer[0]['LastBootUpTime'];
 
$lyear = intval(substr($buffer[0]["LocalDateTime"], 0, 4));
$lmonth = intval(substr($buffer[0]["LocalDateTime"], 4, 2));
$lday = intval(substr($buffer[0]["LocalDateTime"], 6, 2));
$lhour = intval(substr($buffer[0]["LocalDateTime"], 8, 2));
$lminute = intval(substr($buffer[0]["LocalDateTime"], 10, 2));
$lseconds = intval(substr($buffer[0]["LocalDateTime"], 12, 2));
$lyear = intval(substr($local, 0, 4));
$lmonth = intval(substr($local, 4, 2));
$lday = intval(substr($local, 6, 2));
$lhour = intval(substr($local, 8, 2));
$lminute = intval(substr($local, 10, 2));
$lseconds = intval(substr($local, 12, 2));
$loffset = intval(substr($boot, 21, 4));
 
$boottime = mktime($bhour, $bminute, $bseconds, $bmonth, $bday, $byear);
$localtime = mktime($lhour, $lminute, $lseconds, $lmonth, $lday, $lyear);
$byear = intval(substr($boot, 0, 4));
$bmonth = intval(substr($boot, 4, 2));
$bday = intval(substr($boot, 6, 2));
$bhour = intval(substr($boot, 8, 2));
$bminute = intval(substr($boot, 10, 2));
$bseconds = intval(substr($boot, 12, 2));
$boffset = intval(substr($boot, 21, 4));
 
$result = $localtime - $boottime;
if (version_compare($buffer[0]['Version'], "5.1", "<")) { // fix LastBootUpTime on Windows 2000 and older
$boffset += $boffset;
}
 
return $result;
}
$localtime = mktime($lhour, $lminute, $lseconds, $lmonth, $lday, $lyear) - $loffset*60;
$boottime = mktime($bhour, $bminute, $bseconds, $bmonth, $bday, $byear) - $boffset*60;
 
// count the users, which are logged in
function users ()
{
if( stristr( $this->kernel(), "2000 P" ) ) return "N.A.";
$buffer = $this->_GetWMI( "Win32_PerfRawData_TermService_TerminalServices", array( "TotalSessions" ) );
return $buffer[0]["TotalSessions"];
}
$result = $localtime - $boottime;
 
// get the load of the processors
function loadavg ($bar = false)
{
$buffer = $this->_GetWMI( "Win32_Processor", array( "LoadPercentage" ) );
$cpuload = array();
for( $i = 0; $i < count( $buffer ); $i++ ) {
$cpuload['avg'][] = $buffer[$i]["LoadPercentage"];
$this->sys->setUptime($result);
} elseif (($this->sys->getDistribution()=="ReactOS") && CommonFunctions::executeProgram('uptime', '', $strBuf, false) && (strlen($strBuf) > 0) && preg_match("/^System Up Time:\s+(\d+) days, (\d+) Hours, (\d+) Minutes, (\d+) Seconds/", $strBuf, $ar_buf)) {
$sec = $ar_buf[4];
$min = $ar_buf[3];
$hours = $ar_buf[2];
$days = $ar_buf[1];
$this->sys->setUptime($days * 86400 + $hours * 3600 + $min * 60 + $sec);
}
}
if ($bar) {
$cpuload['cpupercent'] = array_sum( $cpuload['avg'] ) / count( $buffer );
 
/**
* Number of Users
*
* @return void
*/
protected function _users()
{
if (CommonFunctions::executeProgram('quser', '', $strBuf, false) && (strlen($strBuf) > 0)) {
$lines = preg_split('/\n/', $strBuf);
$users = count($lines)-1;
} else {
$users = 0;
$buffer = CommonFunctions::getWMI($this->_wmi, 'Win32_Process', array('Caption'));
foreach ($buffer as $process) {
if (strtoupper($process['Caption']) == strtoupper('explorer.exe')) {
$users++;
}
}
}
$this->sys->setUsers($users);
}
return $cpuload;
}
 
// get some informations about the cpu's
function cpu_info ()
{
$buffer = $this->_GetWMI( "Win32_Processor", array( "Name", "L2CacheSize", "CurrentClockSpeed", "ExtClock" ) );
$results["cpus"] = 0;
foreach ($buffer as $cpu) {
$results["cpus"]++;
$results["model"] = $cpu["Name"];
$results["cache"] = $cpu["L2CacheSize"];
$results["cpuspeed"] = $cpu["CurrentClockSpeed"];
$results["busspeed"] = $cpu["ExtClock"];
}
return $results;
}
/**
* Distribution
*
* @return void
*/
private function _distro()
{
$buffer = $this->_get_Win32_OperatingSystem();
if ($buffer) {
$ver = $buffer[0]['Version'];
$kernel = $ver;
if ($buffer[0]['ServicePackMajorVersion'] > 0) {
$kernel .= ' SP'.$buffer[0]['ServicePackMajorVersion'];
}
if (isset($buffer[0]['OSArchitecture']) && preg_match("/^(\d+)/", $buffer[0]['OSArchitecture'], $bits)) {
$this->sys->setKernel($kernel.' ('.$bits[1].'-bit)');
} elseif (($allCpus = $this->_get_Win32_Processor()) && isset($allCpus[0]['AddressWidth'])) {
$this->sys->setKernel($kernel.' ('.$allCpus[0]['AddressWidth'].'-bit)');
} else {
$this->sys->setKernel($kernel);
}
$this->sys->setDistribution($buffer[0]['Caption']);
 
// get the pci devices from the system
function pci ()
{
$pci = $this->_devicelist( "PCI" );
return $pci;
}
if (version_compare($ver, "5.1", "<"))
$icon = 'Win2000.png';
elseif (version_compare($ver, "5.1", ">=") && version_compare($ver, "6.0", "<"))
$icon = 'WinXP.png';
elseif (version_compare($ver, "6.0", ">=") && version_compare($ver, "6.2", "<"))
$icon = 'WinVista.png';
else
$icon = 'Win8.png';
$this->sys->setDistributionIcon($icon);
} elseif (CommonFunctions::executeProgram('cmd', '/c ver 2>nul', $ver_value, false)) {
if (preg_match("/ReactOS\r?\nVersion\s+(.+)/", $ver_value, $ar_temp)) {
$this->sys->setDistribution("ReactOS");
$this->sys->setKernel($ar_temp[1]);
$this->sys->setDistributionIcon('ReactOS.png');
$this->_wmi = false; // No WMI info on ReactOS yet
} elseif (preg_match("/^(Microsoft [^\[]*)\s*\[\D*\s*(.+)\]/", $ver_value, $ar_temp)) {
if (CommonFunctions::readReg($this->_reg, "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProductName", $strBuf, false) && (strlen($strBuf) > 0)) {
if (preg_match("/^Microsoft /", $strBuf)) {
$this->sys->setDistribution($strBuf);
} else {
$this->sys->setDistribution("Microsoft ".$strBuf);
}
} else {
$this->sys->setDistribution($ar_temp[1]);
}
$kernel = $ar_temp[2];
$this->sys->setKernel($kernel);
if ((($kernel[1] == '.') && ($kernel[0] <5)) || (substr($kernel, 0, 4) == '5.0.'))
$icon = 'Win2000.png';
elseif ((substr($kernel, 0, 4) == '6.0.') || (substr($kernel, 0, 4) == '6.1.'))
$icon = 'WinVista.png';
elseif ((substr($kernel, 0, 4) == '6.2.') || (substr($kernel, 0, 4) == '6.3.') || (substr($kernel, 0, 4) == '6.4.') || (substr($kernel, 0, 5) == '10.0.'))
$icon = 'Win8.png';
else
$icon = 'WinXP.png';
$this->sys->setDistributionIcon($icon);
} else {
$this->sys->setDistribution("WinNT");
$this->sys->setDistributionIcon('Win2000.png');
}
} else {
$this->sys->setDistribution("WinNT");
$this->sys->setDistributionIcon('Win2000.png');
}
}
 
// get the ide devices from the system
function ide ()
{
$buffer = $this->_devicelist( "IDE" );
$ide = array();
foreach ( $buffer as $device ) {
$ide[]['model'] = $device;
}
return $ide;
}
/**
* Processor Load
* optionally create a loadbar
*
* @return void
*/
private function _loadavg()
{
if (($cpubuffer = $this->_get_Win32_PerfFormattedData_PerfOS_Processor()) && isset($cpubuffer['cpu_Total'])) {
$this->sys->setLoad($cpubuffer['cpu_Total']);
if (PSI_LOAD_BAR) {
$this->sys->setLoadPercent($cpubuffer['cpu_Total']);
}
} elseif ($buffer = $this->_get_Win32_Processor()) {
$loadok = true;
$sum = 0;
foreach ($buffer as $load) {
$value = $load['LoadPercentage'];
if ($value !== null) {
$sum += $value;
} else {
$loadok = false;
break;
}
}
if ($loadok) {
$percent = $sum / count($buffer);
$this->sys->setLoad($percent);
if (PSI_LOAD_BAR) {
$this->sys->setLoadPercent($percent);
}
}
}
}
 
// get the scsi devices from the system
function scsi ()
{
$scsi = $this->_devicelist( "SCSI" );
return $scsi;
}
/**
* CPU information
*
* @return void
*/
private function _cpuinfo()
{
$allCpus = $this->_get_Win32_Processor();
if (!$allCpus) {
$hkey = "HKEY_LOCAL_MACHINE\\HARDWARE\\DESCRIPTION\\System\\CentralProcessor";
if (CommonFunctions::enumKey($this->_key, $hkey, $arrBuf, false)) {
foreach ($arrBuf as $coreCount) {
if (CommonFunctions::readReg($this->_reg, $hkey."\\".$coreCount."\\ProcessorNameString", $strBuf, false)) {
$allCpus[$coreCount]['Name'] = $strBuf;
}
if (CommonFunctions::readReg($this->_reg, $hkey."\\".$coreCount."\\~MHz", $strBuf, false)) {
if (preg_match("/^0x([0-9a-f]+)$/i", $strBuf, $hexvalue)) {
$allCpus[$coreCount]['CurrentClockSpeed'] = hexdec($hexvalue[1]);
}
}
if (CommonFunctions::readReg($this->_reg, $hkey."\\".$coreCount."\\VendorIdentifier", $strBuf, false)) {
$allCpus[$coreCount]['Manufacturer'] = $strBuf;
}
}
}
}
 
// get the usb devices from the system
function usb ()
{
$usb = $this->_devicelist( "USB" );
return $usb;
}
$globalcpus = 0;
foreach ($allCpus as $oneCpu) {
$cpuCount = 1;
if (isset($oneCpu['NumberOfLogicalProcessors'])) {
$cpuCount = $oneCpu['NumberOfLogicalProcessors'];
} elseif (isset($oneCpu['NumberOfCores'])) {
$cpuCount = $oneCpu['NumberOfCores'];
}
$globalcpus+=$cpuCount;
}
 
// get the sbus devices from the system - currently not called
function sbus ()
{
$sbus = $this->_devicelist( "SBUS" );
return $sbus;
}
foreach ($allCpus as $oneCpu) {
$cpuCount = 1;
if (isset($oneCpu['NumberOfLogicalProcessors'])) {
$cpuCount = $oneCpu['NumberOfLogicalProcessors'];
} elseif (isset($oneCpu['NumberOfCores'])) {
$cpuCount = $oneCpu['NumberOfCores'];
}
for ($i = 0; $i < $cpuCount; $i++) {
$cpu = new CpuDevice();
if (isset($oneCpu['Name'])) $cpu->setModel($oneCpu['Name']);
if (isset($oneCpu['L3CacheSize']) && ($oneCpu['L3CacheSize'] > 0)) {
$cpu->setCache($oneCpu['L3CacheSize'] * 1024);
} elseif (isset($oneCpu['L2CacheSize'])) {
$cpu->setCache($oneCpu['L2CacheSize'] * 1024);
}
if (isset($oneCpu['CurrentClockSpeed'])) {
$cpu->setCpuSpeed($oneCpu['CurrentClockSpeed']);
if (isset($oneCpu['MaxClockSpeed']) && ($oneCpu['CurrentClockSpeed'] < $oneCpu['MaxClockSpeed'])) $cpu->setCpuSpeedMax($oneCpu['MaxClockSpeed']);
}
if (isset($oneCpu['ExtClock'])) $cpu->setBusSpeed($oneCpu['ExtClock']);
if (isset($oneCpu['Manufacturer'])) $cpu->setVendorId($oneCpu['Manufacturer']);
if (PSI_LOAD_BAR) {
if (($cpubuffer = $this->_get_Win32_PerfFormattedData_PerfOS_Processor()) && (count($cpubuffer) == ($globalcpus+1)) && isset($cpubuffer['cpu'.$i])) {
$cpu->setLoad($cpubuffer['cpu'.$i]);
} elseif ((count($allCpus) == $globalcpus) && isset($oneCpu['LoadPercentage'])) {
$cpu->setLoad($oneCpu['LoadPercentage']);
}
}
$this->sys->setCpus($cpu);
}
}
}
 
// get the netowrk devices and rx/tx bytes
function network () {
$results = array();
$buffer = $this->_GetWMI( "Win32_PerfRawData_Tcpip_NetworkInterface" );
foreach( $buffer as $device ) {
$dev_name = $device["Name"];
// http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/win32_perfrawdata_tcpip_networkinterface.asp
// there is a possible bug in the wmi interfaceabout uint32 and uint64: http://www.ureader.com/message/1244948.aspx, so that
// magative numbers would occour, try to calculate the nagative value from total - positive number
if( $device["BytesSentPersec"] < 0) {
$results[$dev_name]['tx_bytes'] = $device["BytesTotalPersec"] - $device["BytesReceivedPersec"];
} else {
$results[$dev_name]['tx_bytes'] = $device["BytesSentPersec"];
}
if( $device["BytesReceivedPersec"] < 0 ) {
$results[$dev_name]['rx_bytes'] = $device["BytesTotalPersec"] - $device["BytesSentPersec"];
} else {
$results[$dev_name]['rx_bytes'] = $device["BytesReceivedPersec"];
}
$results[$dev_name]['rx_packets'] = $device["PacketsReceivedPersec"];
$results[$dev_name]['tx_packets'] = $device["PacketsSentPersec"];
$results[$dev_name]['rx_errs'] = $device["PacketsReceivedErrors"];
$results[$dev_name]['rx_drop'] = $device["PacketsReceivedDiscarded"];
$results[$dev_name]['errs'] = $device["PacketsReceivedErrors"];
$results[$dev_name]['drop'] = $device["PacketsReceivedDiscarded"];
}
return $results;
}
/**
* Machine information
*
* @return void
*/
private function _machine()
{
$buffer = $this->_get_Win32_ComputerSystem();
if ($buffer) {
$buf = "";
if (isset($buffer[0]['Manufacturer']) && !preg_match("/^To be filled by O\.E\.M\.$|^System manufacturer$|^Not Specified$/i", $buf2=$buffer[0]['Manufacturer'])) {
$buf .= ' '.$buf2;
}
 
function memory ()
{
$buffer = $this->_GetWMI( "Win32_LogicalMemoryConfiguration", array( "TotalPhysicalMemory" ) );
$results['ram']['total'] = $buffer[0]["TotalPhysicalMemory"];
if (isset($buffer[0]['Model']) && !preg_match("/^To be filled by O\.E\.M\.$|^System Product Name$|^Not Specified$/i", $buf2=$buffer[0]['Model'])) {
$buf .= ' '.$buf2;
}
if (trim($buf) != "") {
$this->sys->setMachine(trim($buf));
}
}
}
 
$buffer = $this->_GetWMI( "Win32_PerfRawData_PerfOS_Memory", array( "AvailableKBytes" ) );
$results['ram']['free'] = $buffer[0]["AvailableKBytes"];
/**
* Hardwaredevices
*
* @return void
*/
private function _hardware()
{
foreach ($this->_devicelist('PCI') as $pciDev) {
$dev = new HWDevice();
$dev->setName($pciDev['Name']);
if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS) {
$dev->setManufacturer($pciDev['Manufacturer']);
$dev->setProduct($pciDev['Product']);
}
$this->sys->setPciDevices($dev);
}
 
$results['ram']['used'] = $results['ram']['total'] - $results['ram']['free'];
$results['ram']['percent'] = ceil( ( $results['ram']['used'] * 100 ) / $results['ram']['total'] );
$results['swap']['total'] = 0;
$results['swap']['used'] = 0;
$results['swap']['free'] = 0;
foreach ($this->_devicelist('IDE') as $ideDev) {
$dev = new HWDevice();
$dev->setName($ideDev['Name']);
if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS) {
$dev->setCapacity($ideDev['Capacity']);
if (defined('PSI_SHOW_DEVICES_SERIAL') && PSI_SHOW_DEVICES_SERIAL) {
$dev->setSerial($ideDev['Serial']);
}
}
$this->sys->setIdeDevices($dev);
}
 
$buffer = $this->_GetWMI( "Win32_PageFileUsage" ); // no need to filter, using nearly everything from output
$k = 0;
foreach ($buffer as $swapdevice) {
$results['devswap'][$k]['dev'] = $swapdevice["Name"];
$results['devswap'][$k]['total'] = $swapdevice["AllocatedBaseSize"] * 1024;
$results['devswap'][$k]['used'] = $swapdevice["CurrentUsage"] * 1024;
$results['devswap'][$k]['free'] = ( $swapdevice["AllocatedBaseSize"] - $swapdevice["CurrentUsage"] ) * 1024;
$results['devswap'][$k]['percent'] = ceil( $swapdevice["CurrentUsage"] / $swapdevice["AllocatedBaseSize"] );
foreach ($this->_devicelist('SCSI') as $scsiDev) {
$dev = new HWDevice();
$dev->setName($scsiDev['Name']);
if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS) {
$dev->setCapacity($scsiDev['Capacity']);
if (defined('PSI_SHOW_DEVICES_SERIAL') && PSI_SHOW_DEVICES_SERIAL) {
$dev->setSerial($scsiDev['Serial']);
}
}
$this->sys->setScsiDevices($dev);
}
 
$results['swap']['total'] += $results['devswap'][$k]['total'];
$results['swap']['used'] += $results['devswap'][$k]['used'];
$results['swap']['free'] += $results['devswap'][$k]['free'];
$k += 1;
}
$results['swap']['percent'] = ceil( $results['swap']['used'] / $results['swap']['total'] * 100 );
return $results;
}
foreach ($this->_devicelist('USB') as $usbDev) {
$dev = new HWDevice();
$dev->setName($usbDev['Name']);
if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS) {
$dev->setManufacturer($usbDev['Manufacturer']);
$dev->setProduct($usbDev['Product']);
if (defined('PSI_SHOW_DEVICES_SERIAL') && PSI_SHOW_DEVICES_SERIAL) {
$dev->setSerial($usbDev['Serial']);
}
}
$this->sys->setUsbDevices($dev);
}
}
 
// get the filesystem informations
function filesystems ()
{
$typearray = array("Unknown", "No Root Directory", "Removeable Disk",
"Local Disk", "Network Drive", "Compact Disc", "RAM Disk");
$floppyarray = array("Unknown", "5 1/4 in.", "3 1/2 in.", "3 1/2 in.",
"3 1/2 in.", "3 1/2 in.", "5 1/4 in.", "5 1/4 in.", "5 1/4 in.",
"5 1/4 in.", "5 1/4 in.", "Other", "HD", "3 1/2 in.", "3 1/2 in.",
"5 1/4 in.", "5 1/4 in.", "3 1/2 in.", "3 1/2 in.", "5 1/4 in.",
"3 1/2 in.", "3 1/2 in.", "8 in.");
/**
* Network devices
*
* @return void
*/
private function _network()
{
if ($this->_wmi) {
$buffer = $this->_get_Win32_OperatingSystem();
if ($buffer && isset($buffer[0]) && isset($buffer[0]['Version']) && version_compare($buffer[0]['Version'], "6.2", ">=")) { // minimal windows 2012 or windows 8
$allDevices = CommonFunctions::getWMI($this->_wmi, 'Win32_PerfRawData_Tcpip_NetworkAdapter', array('Name', 'BytesSentPersec', 'BytesTotalPersec', 'BytesReceivedPersec', 'PacketsReceivedErrors', 'PacketsReceivedDiscarded', 'CurrentBandwidth'));
} else {
$allDevices = CommonFunctions::getWMI($this->_wmi, 'Win32_PerfRawData_Tcpip_NetworkInterface', array('Name', 'BytesSentPersec', 'BytesTotalPersec', 'BytesReceivedPersec', 'PacketsReceivedErrors', 'PacketsReceivedDiscarded', 'CurrentBandwidth'));
}
if ($allDevices) {
$aliases = array();
$hkey = "HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Network\\{4D36E972-E325-11CE-BFC1-08002BE10318}";
if (CommonFunctions::enumKey($this->_key, $hkey, $arrBuf, false)) {
foreach ($arrBuf as $netID) {
if (CommonFunctions::readReg($this->_reg, $hkey."\\".$netID."\\Connection\\PnPInstanceId", $strInstanceID, false)) { //a w Name jest net alias
if (CommonFunctions::readReg($this->_reg, "HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Enum\\".$strInstanceID."\\FriendlyName", $strName, false)) {
$cname = str_replace(array('(', ')', '#'), array('[', ']', '_'), $strName); //convert to canonical
if (!isset($aliases[$cname])) { // duplicate checking
$aliases[$cname]['id'] = $netID;
$aliases[$cname]['name'] = $strName;
if (CommonFunctions::readReg($this->_reg, $hkey."\\".$netID."\\Connection\\Name", $strCName, false)
&& (str_replace(array('(', ')', '#'), array('[', ']', '_'), $strCName) !== $cname)) {
$aliases[$cname]['netname'] = $strCName;
}
} else {
$aliases[$cname]['id'] = '';
}
}
}
}
}
 
$buffer = $this->_GetWMI( "Win32_LogicalDisk" , array( "Name", "Size", "FreeSpace", "FileSystem", "DriveType", "MediaType" ) );
$aliases2 = array();
$hkey = "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\NetworkCards";
if (CommonFunctions::enumKey($this->_key, $hkey, $arrBuf, false)) {
foreach ($arrBuf as $netCount) {
if (CommonFunctions::readReg($this->_reg, $hkey."\\".$netCount."\\Description", $strName, false)
&& CommonFunctions::readReg($this->_reg, $hkey."\\".$netCount."\\ServiceName", $strGUID, false)) {
$cname = str_replace(array('(', ')', '#'), array('[', ']', '_'), $strName); //convert to canonical
if (!isset($aliases2[$cname])) { // duplicate checking
$aliases2[$cname]['id'] = $strGUID;
$aliases2[$cname]['name'] = $strName;
} else {
$aliases2[$cname]['id'] = '';
}
}
}
}
 
$k = 0;
foreach ( $buffer as $filesystem ) {
if ( hide_mount( $filesystem["Name"] ) ) {
continue;
}
$results[$k]['mount'] = $filesystem["Name"];
$results[$k]['size'] = $filesystem["Size"] / 1024;
$results[$k]['used'] = ( $filesystem["Size"] - $filesystem["FreeSpace"] ) / 1024;
$results[$k]['free'] = $filesystem["FreeSpace"] / 1024;
@$results[$k]['percent'] = ceil( $results[$k]['used'] / $results[$k]['size'] * 100 ); // silence this line, nobody is having a floppy in the drive everytime
$results[$k]['fstype'] = $filesystem["FileSystem"];
$results[$k]['disk'] = $typearray[$filesystem["DriveType"]];
if ( $filesystem["MediaType"] != "" && $filesystem["DriveType"] == 2 ) $results[$k]['disk'] .= " (" . $floppyarray[$filesystem["MediaType"]] . ")";
$k += 1;
}
return $results;
}
$allNetworkAdapterConfigurations = CommonFunctions::getWMI($this->_wmi, 'Win32_NetworkAdapterConfiguration', array('SettingID', /*'Description',*/ 'MACAddress', 'IPAddress'));
foreach ($allDevices as $device) if (!preg_match('/^WAN Miniport \[/', $device['Name'])) {
$dev = new NetDevice();
$name = $device['Name'];
 
function distro ()
{
$buffer = $this->_GetWMI( "Win32_OperatingSystem", array( "Caption" ) );
return $buffer[0]["Caption"];
}
if (preg_match('/^isatap\.({[A-Fa-f0-9\-]*})/', $name)) {
$dev->setName("Microsoft ISATAP Adapter");
} else {
if (preg_match('/\s-\s([^-]*)$/', $name, $ar_name)) {
$name=substr($name, 0, strlen($name)-strlen($ar_name[0]));
}
$dev->setName($name);
}
 
function distroicon ()
{
return 'xp.gif';
}
}
$macexist = false;
if (((($ali=$aliases) && isset($ali[$name])) || (($ali=$aliases2) && isset($ali[$name]))) && isset($ali[$name]['id']) && ($ali[$name]['id'] !== "")) {
foreach ($allNetworkAdapterConfigurations as $NetworkAdapterConfiguration) {
if ($ali[$name]['id']==$NetworkAdapterConfiguration['SettingID']) {
$mininame = $ali[$name]['name'];
if (preg_match('/^isatap\.({[A-Fa-f0-9\-]*})/', $mininame))
$mininame="Microsoft ISATAP Adapter";
elseif (preg_match('/\s-\s([^-]*)$/', $mininame, $ar_name))
$name=substr($mininame, 0, strlen($mininame)-strlen($ar_name[0]));
$dev->setName($mininame);
if (trim($NetworkAdapterConfiguration['MACAddress']) !== "") $macexist = true;
if (defined('PSI_SHOW_NETWORK_INFOS') && PSI_SHOW_NETWORK_INFOS) {
if (isset($ali[$name]['netname'])) $dev->setInfo(str_replace(';', ':', $ali[$name]['netname']));
if ((!defined('PSI_HIDE_NETWORK_MACADDR') || !PSI_HIDE_NETWORK_MACADDR)
&& (trim($NetworkAdapterConfiguration['MACAddress']) !== "")) $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').str_replace(':', '-', strtoupper($NetworkAdapterConfiguration['MACAddress'])));
if (isset($NetworkAdapterConfiguration['IPAddress']))
foreach ($NetworkAdapterConfiguration['IPAddress'] as $ipaddres)
if (($ipaddres != "0.0.0.0") && ($ipaddres != "::") && !preg_match('/^fe80::/i', $ipaddres))
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').strtolower($ipaddres));
}
 
?>
break;
}
}
}
 
if ($macexist
// || ($device['CurrentBandwidth'] >= 1000000)
|| ($device['BytesTotalPersec'] != 0)
|| ($device['BytesSentPersec'] != 0)
|| ($device['BytesReceivedPersec'] != 0)
|| ($device['PacketsReceivedErrors'] != 0)
|| ($device['PacketsReceivedDiscarded'] != 0)) { // hide unused
if (defined('PSI_SHOW_NETWORK_INFOS') && PSI_SHOW_NETWORK_INFOS) {
if (($speedinfo = $device['CurrentBandwidth']) >= 1000000) {
if ($speedinfo > 1000000000) {
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').round($speedinfo/1000000000, 2)."Gb/s");
} else {
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').round($speedinfo/1000000, 2)."Mb/s");
}
}
}
 
// http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/win32_perfrawdata_tcpip_networkinterface.asp
// there is a possible bug in the wmi interfaceabout uint32 and uint64: http://www.ureader.com/message/1244948.aspx, so that
// magative numbers would occour, try to calculate the nagative value from total - positive number
$txbytes = $device['BytesSentPersec'];
$rxbytes = $device['BytesReceivedPersec'];
if (($txbytes < 0) && ($rxbytes < 0)) {
$txbytes += 4294967296;
$rxbytes += 4294967296;
} elseif ($txbytes < 0) {
if ($device['BytesTotalPersec'] > $rxbytes)
$txbytes = $device['BytesTotalPersec'] - $rxbytes;
else
$txbytes += 4294967296;
} elseif ($rxbytes < 0) {
if ($device['BytesTotalPersec'] > $txbytes)
$rxbytes = $device['BytesTotalPersec'] - $txbytes;
else
$rxbytes += 4294967296;
}
$dev->setTxBytes($txbytes);
$dev->setRxBytes($rxbytes);
$dev->setErrors($device['PacketsReceivedErrors']);
$dev->setDrops($device['PacketsReceivedDiscarded']);
 
$this->sys->setNetDevices($dev);
}
}
}
} elseif (($buffer = $this->_get_systeminfo()) && preg_match('/^(\s+)\[\d+\]:[^\r\n]+\r\n\s+[^\s\[]/m', $buffer, $matches, PREG_OFFSET_CAPTURE)) {
$netbuf = substr($buffer, $matches[0][1]);
if (preg_match('/^[^\s]/m', $netbuf, $matches2, PREG_OFFSET_CAPTURE)) {
$netbuf = substr($netbuf, 0, $matches2[0][1]);
}
$netstrs = preg_split('/^'.$matches[1][0].'\[\d+\]:/m', $netbuf, -1, PREG_SPLIT_NO_EMPTY);
$devnr = 0;
foreach ($netstrs as $netstr) {
$netstrls = preg_split('/\r\n/', $netstr, -1, PREG_SPLIT_NO_EMPTY);
if (sizeof($netstrls)>1) {
$dev = new NetDevice();
foreach ($netstrls as $nr=>$netstrl) {
if ($nr === 0) {
$name = trim($netstrl);
if ($name !== "") {
$dev->setName($name);
} else {
$dev->setName('dev'.$devnr);
$devnr++;
}
} elseif (preg_match('/\[\d+\]:\s+(.+)/', $netstrl, $netinfo)) {
$ipaddres = trim($netinfo[1]);
if (($ipaddres!="0.0.0.0") && !preg_match('/^fe80::/i', $ipaddres))
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').strtolower($ipaddres));
}
}
$this->sys->setNetDevices($dev);
}
}
}
}
 
/**
* Physical memory information and Swap Space information
*
* @link http://msdn2.microsoft.com/En-US/library/aa394239.aspx
* @link http://msdn2.microsoft.com/en-us/library/aa394246.aspx
* @return void
*/
private function _memory()
{
if ($this->_wmi) {
$buffer = $this->_get_Win32_OperatingSystem();
if ($buffer) {
$this->sys->setMemTotal($buffer[0]['TotalVisibleMemorySize'] * 1024);
$this->sys->setMemFree($buffer[0]['FreePhysicalMemory'] * 1024);
$this->sys->setMemUsed($this->sys->getMemTotal() - $this->sys->getMemFree());
}
$buffer = CommonFunctions::getWMI($this->_wmi, 'Win32_PageFileUsage');
foreach ($buffer as $swapdevice) {
$dev = new DiskDevice();
$dev->setName("SWAP");
$dev->setMountPoint($swapdevice['Name']);
$dev->setTotal($swapdevice['AllocatedBaseSize'] * 1024 * 1024);
$dev->setUsed($swapdevice['CurrentUsage'] * 1024 * 1024);
$dev->setFree($dev->getTotal() - $dev->getUsed());
$dev->setFsType('swap');
$this->sys->setSwapDevices($dev);
}
} elseif (($buffer = $this->_get_systeminfo()) && preg_match("/:\s([\d \xFF]+)\sMB\r\n.+:\s([\d \xFF]+)\sMB\r\n.+:\s([\d \xFF]+)\sMB\r\n.+:\s([\d \xFF]+)\sMB\r\n.+\s([\d \xFF]+)\sMB\r\n/m", $buffer, $buffer2)) {
// && (preg_match("/:\s([\d \xFF]+)\sMB\r\n.+:\s([\d \xFF]+)\sMB\r\n.+:\s([\d \xFF]+)\sMB\r\n.+:\s([\d \xFF]+)\sMB\r\n.+\s([\d \xFF]+)\sMB\r\n.*:\s+(\S+)\r\n/m", $buffer, $buffer2)) {
$this->sys->setMemTotal(preg_replace('/(\s)|(\xFF)/', '', $buffer2[1]) * 1024 * 1024);
$this->sys->setMemFree(preg_replace('/(\s)|(\xFF)/', '', $buffer2[2]) * 1024 * 1024);
$this->sys->setMemUsed($this->sys->getMemTotal() - $this->sys->getMemFree());
}
}
 
/**
* filesystem information
*
* @return void
*/
private function _filesystems()
{
$typearray = array('Unknown', 'No Root Directory', 'Removable Disk', 'Local Disk', 'Network Drive', 'Compact Disc', 'RAM Disk');
$floppyarray = array('Unknown', '5 1/4 in.', '3 1/2 in.', '3 1/2 in.', '3 1/2 in.', '3 1/2 in.', '5 1/4 in.', '5 1/4 in.', '5 1/4 in.', '5 1/4 in.', '5 1/4 in.', 'Other', 'HD', '3 1/2 in.', '3 1/2 in.', '5 1/4 in.', '5 1/4 in.', '3 1/2 in.', '3 1/2 in.', '5 1/4 in.', '3 1/2 in.', '3 1/2 in.', '8 in.');
$buffer = CommonFunctions::getWMI($this->_wmi, 'Win32_LogicalDisk', array('Name', 'Size', 'FreeSpace', 'FileSystem', 'DriveType', 'MediaType'));
foreach ($buffer as $filesystem) {
$dev = new DiskDevice();
$dev->setMountPoint($filesystem['Name']);
$dev->setFsType($filesystem['FileSystem']);
if ($filesystem['Size'] > 0) {
$dev->setTotal($filesystem['Size']);
$dev->setFree($filesystem['FreeSpace']);
$dev->setUsed($filesystem['Size'] - $filesystem['FreeSpace']);
}
if ($filesystem['MediaType'] != "" && $filesystem['DriveType'] == 2) {
$dev->setName($typearray[$filesystem['DriveType']]." (".$floppyarray[$filesystem['MediaType']].")");
} else {
$dev->setName($typearray[$filesystem['DriveType']]);
}
$this->sys->setDiskDevices($dev);
}
if (!$buffer && ($this->sys->getDistribution()=="ReactOS")) {
// test for command 'free' on current disk
if (CommonFunctions::executeProgram('cmd', '/c free 2>nul', $out_value, true)) {
for ($letter='A'; $letter!='AA'; $letter++) if (CommonFunctions::executeProgram('cmd', '/c free '.$letter.': 2>nul', $out_value, false)) {
$values = preg_replace('/[^\d\n]/', '', $out_value);
if (preg_match('/\n(\d+)\n(\d+)\n(\d+)$/', $values, $out_dig)) {
$size = $out_dig[1];
$used = $out_dig[2];
$free = $out_dig[3];
if ($used + $free == $size) {
$dev = new DiskDevice();
$dev->setMountPoint($letter.":");
$dev->setFsType('Unknown');
$dev->setName('Unknown');
$dev->setTotal($size);
$dev->setUsed($used);
$dev->setFree($free);
$this->sys->setDiskDevices($dev);
}
}
}
}
}
}
 
/**
* get os specific encoding
*
* @see OS::getEncoding()
*
* @return string
*/
public function getEncoding()
{
return $this->_codepage;
}
 
/**
* get os specific language
*
* @see OS::getLanguage()
*
* @return string
*/
public function getLanguage()
{
return $this->_syslang;
}
 
public function _processes()
{
$processes['*'] = 0;
if (CommonFunctions::executeProgram('qprocess', '*', $strBuf, false) && (strlen($strBuf) > 0)) {
$lines = preg_split('/\n/', $strBuf);
$processes['*'] = (count($lines)-1) - 3 ; //correction for process "qprocess *"
}
if ($processes['*'] <= 0) {
$buffer = CommonFunctions::getWMI($this->_wmi, 'Win32_Process', array('Caption'));
$processes['*'] = count($buffer);
}
$processes[' '] = $processes['*'];
$this->sys->setProcesses($processes);
}
 
/**
* get the information
*
* @see PSI_Interface_OS::build()
*
* @return Void
*/
public function build()
{
$this->_distro(); //share getDistribution()
if ($this->sys->getDistribution()=="ReactOS") {
$this->error->addError("WARN", "The ReactOS version of phpSysInfo is a work in progress, some things currently don't work");
}
if (!$this->blockname || $this->blockname==='vitals') {
$this->_hostname();
$this->_users();
$this->_uptime();
$this->_loadavg();
$this->_processes();
}
if (!$this->blockname || $this->blockname==='network') {
$this->_network();
}
if (!$this->blockname || $this->blockname==='hardware') {
$this->_machine();
$this->_cpuinfo();
$this->_hardware();
}
if (!$this->blockname || $this->blockname==='filesystem') {
$this->_filesystems();
}
if (!$this->blockname || $this->blockname==='memory') {
$this->_memory();
}
}
}