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

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

View File

@@ -0,0 +1,381 @@
<?php
/**
* IBM AIX System Class
*
* PHP version 5
*
* @category PHP
* @package PSI AIX OS class
* @author Krzysztof Paz (kpaz@gazeta.pl) based on HPUX of Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2011 Krzysztof Paz
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @version SVN: $Id: class.AIX.inc.php 287 2009-06-26 12:11:59Z Krzysztof Paz, IBM POLSKA
* @link http://phpsysinfo.sourceforge.net
*/
/**
* IBM AIX sysinfo class
* get all the required information from IBM AIX system
*
* @category PHP
* @package PSI AIX OS class
* @author Krzysztof Paz (kpaz@gazeta.pl) based on Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2011 Krzysztof Paz
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @version Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
class AIX extends OS
{
private $_aixdata = array();
/**
* Virtual Host Name
* @return void
*/
private function _hostname()
{
/* if (PSI_USE_VHOST === true) {
$this->sys->setHostname(getenv('SERVER_NAME'));
} else {
if (CommonFunctions::executeProgram('hostname', '', $ret)) {
$this->sys->setHostname($ret);
}
} */
$this->sys->setHostname(getenv('SERVER_NAME'));
}
/**
* IP of the Virtual Host Name
* @return void
*/
private function _ip()
{
if (PSI_USE_VHOST === true) {
$this->sys->setIp(gethostbyname($this->sys->getHostname()));
} else {
if (!($result = getenv('SERVER_ADDR'))) {
$this->sys->setIp(gethostbyname($this->sys->getHostname()));
} else {
$this->sys->setIp($result);
}
}
}
/**
* IBM AIX Version
* @return void
*/
private function _kernel()
{
if (CommonFunctions::executeProgram('oslevel', '', $ret1) && CommonFunctions::executeProgram('oslevel', '-s', $ret2)) {
$this->sys->setKernel($ret1 . ' (' . $ret2 . ')');
}
}
/**
* UpTime
* time the system is running
* @return void
*/
private function _uptime()
{
if (CommonFunctions::executeProgram('uptime', '', $buf)) {
if (preg_match("/up (\d+) days,\s*(\d+):(\d+),/", $buf, $ar_buf) || preg_match("/up (\d+) day,\s*(\d+):(\d+),/", $buf, $ar_buf)) {
$min = $ar_buf[3];
$hours = $ar_buf[2];
$days = $ar_buf[1];
$this->sys->setUptime($days * 86400 + $hours * 3600 + $min * 60);
}
}
}
/**
* Number of Users
* @return void
*/
private function _users()
{
if (CommonFunctions::executeProgram('who', '| wc -l', $buf, PSI_DEBUG)) {
$this->sys->setUsers($buf);
}
}
/**
* Processor Load
* optionally create a loadbar
* @return void
*/
private function _loadavg()
{
if (CommonFunctions::executeProgram('uptime', '', $buf)) {
if (preg_match("/average: (.*), (.*), (.*)$/", $buf, $ar_buf)) {
$this->sys->setLoad($ar_buf[1].' '.$ar_buf[2].' '.$ar_buf[3]);
}
}
}
/**
* CPU information
* All of the tags here are highly architecture dependant
* @return void
*/
private function _cpuinfo()
{
$ncpu = 0;
$tcpu = "";
$vcpu = "";
$ccpu = "";
$scpu = "";
foreach ($this->readaixdata() as $line) {
if (preg_match("/^Number Of Processors:\s+(\d+)/", $line, $ar_buf)) {
$ncpu = $ar_buf[1];
}
if (preg_match("/^Processor Type:\s+(.+)/", $line, $ar_buf)) {
$tcpu = $ar_buf[1];
}
if (preg_match("/^Processor Version:\s+(.+)/", $line, $ar_buf)) {
$vcpu = $ar_buf[1];
}
if (preg_match("/^CPU Type:\s+(.+)/", $line, $ar_buf)) {
$ccpu = $ar_buf[1];
}
if (preg_match("/^Processor Clock Speed:\s+(\d+)\s/", $line, $ar_buf)) {
$scpu = $ar_buf[1];
}
}
for ($i = 0; $i < $ncpu; $i++) {
$dev = new CpuDevice();
if (trim($tcpu) != "") {
$cpu = trim($tcpu);
if (trim($vcpu) != "") $cpu .= " ".trim($vcpu);
if (trim($ccpu) != "") $cpu .= " ".trim($ccpu);
$dev->setModel($cpu);
}
if (trim($scpu) != "") {
$dev->setCpuSpeed(trim($scpu));
}
$this->sys->setCpus($dev);
}
}
/**
* PCI devices
* @return void
*/
private function _pci()
{
foreach ($this->readaixdata() as $line) {
if (preg_match("/^[\*\+]\s\S+\s+\S+\s+(.*PCI.*)/", $line, $ar_buf)) {
$dev = new HWDevice();
$dev->setName(trim($ar_buf[1]));
$this->sys->setPciDevices($dev);
}
}
}
/**
* IDE devices
* @return void
*/
private function _ide()
{
foreach ($this->readaixdata() as $line) {
if (preg_match("/^[\*\+]\s\S+\s+\S+\s+(.*IDE.*)/", $line, $ar_buf)) {
$dev = new HWDevice();
$dev->setName(trim($ar_buf[1]));
$this->sys->setIdeDevices($dev);
}
}
}
/**
* SCSI devices
* @return void
*/
private function _scsi()
{
foreach ($this->readaixdata() as $line) {
if (preg_match("/^[\*\+]\s\S+\s+\S+\s+(.*SCSI.*)/", $line, $ar_buf)) {
$dev = new HWDevice();
$dev->setName(trim($ar_buf[1]));
$this->sys->setScsiDevices($dev);
}
}
}
/**
* USB devices
* @return void
*/
private function _usb()
{
foreach ($this->readaixdata() as $line) {
if (preg_match("/^[\*\+]\s\S+\s+\S+\s+(.*USB.*)/", $line, $ar_buf)) {
$dev = new HWDevice();
$dev->setName(trim($ar_buf[1]));
$this->sys->setUsbDevices($dev);
}
}
}
/**
* Network devices
* includes also rx/tx bytes
* @return void
*/
private function _network()
{
if (CommonFunctions::executeProgram('netstat', '-ni | tail -n +2', $netstat)) {
$lines = preg_split("/\n/", $netstat, -1, PREG_SPLIT_NO_EMPTY);
foreach ($lines as $line) {
$ar_buf = preg_split("/\s+/", $line);
if (! empty($ar_buf[0]) && ! empty($ar_buf[3])) {
$dev = new NetDevice();
$dev->setName($ar_buf[0]);
$dev->setRxBytes($ar_buf[4]);
$dev->setTxBytes($ar_buf[6]);
$dev->setErrors($ar_buf[5] + $ar_buf[7]);
//$dev->setDrops($ar_buf[8]);
$this->sys->setNetDevices($dev);
}
}
}
}
/**
* Physical memory information and Swap Space information
* @return void
*/
private function _memory()
{
$mems = "";
$tswap = "";
$pswap = "";
foreach ($this->readaixdata() as $line) {
if (preg_match("/^Good Memory Size:\s+(\d+)\s+MB/", $line, $ar_buf)) {
$mems = $ar_buf[1];
}
if (preg_match("/^\s*Total Paging Space:\s+(\d+)MB/", $line, $ar_buf)) {
$tswap = $ar_buf[1];
}
if (preg_match("/^\s*Percent Used:\s+(\d+)%/", $line, $ar_buf)) {
$pswap = $ar_buf[1];
}
}
if (trim($mems) != "") {
$mems = $mems*1024*1024;
$this->sys->setMemTotal($mems);
$memu = 0;
$memf = 0;
if (CommonFunctions::executeProgram('svmon', '-G', $buf)) {
if (preg_match("/^memory\s+\d+\s+(\d+)\s+/", $buf, $ar_buf)) {
$memu = $ar_buf[1]*1024*4;
$memf = $mems - $memu;
}
}
$this->sys->setMemUsed($memu);
$this->sys->setMemFree($memf);
// $this->sys->setMemApplication($mems);
// $this->sys->setMemBuffer($mems);
// $this->sys->setMemCache($mems);
}
if (trim($tswap) != "") {
$dev = new DiskDevice();
$dev->setName("SWAP");
$dev->setFsType('swap');
$dev->setTotal($tswap * 1024 * 1024);
if (trim($pswap) != "") {
$dev->setUsed($dev->getTotal() * $pswap / 100);
}
$dev->setFree($dev->getTotal() - $dev->getUsed());
$this->sys->setSwapDevices($dev);
}
}
/**
* filesystem information
*
* @return void
*/
private function _filesystems()
{
if (CommonFunctions::executeProgram('df', '-kP', $df, PSI_DEBUG)) {
$mounts = preg_split("/\n/", $df, -1, PREG_SPLIT_NO_EMPTY);
if (CommonFunctions::executeProgram('mount', '-v', $s, PSI_DEBUG)) {
$lines = preg_split("/\n/", $s, -1, PREG_SPLIT_NO_EMPTY);
while (list(, $line) = each($lines)) {
$a = preg_split('/ /', $line, -1, PREG_SPLIT_NO_EMPTY);
$fsdev[$a[0]] = $a[4];
}
}
foreach ($mounts as $mount) {
$ar_buf = preg_split("/\s+/", $mount, 6);
$dev = new DiskDevice();
$dev->setName($ar_buf[0]);
$dev->setTotal($ar_buf[1] * 1024);
$dev->setUsed($ar_buf[2] * 1024);
$dev->setFree($ar_buf[3] * 1024);
$dev->setMountPoint($ar_buf[5]);
if (isset($fsdev[$ar_buf[0]])) {
$dev->setFsType($fsdev[$ar_buf[0]]);
}
$this->sys->setDiskDevices($dev);
}
}
}
/**
* Distribution
*
* @return void
*/
private function _distro()
{
$this->sys->setDistribution('IBM AIX');
$this->sys->setDistributionIcon('AIX.png');
}
/**
* IBM AIX informations by K.PAZ
* @return void
*/
private function readaixdata()
{
if (count($this->_aixdata) === 0) {
if (CommonFunctions::executeProgram('prtconf', '', $bufr)) {
$this->_aixdata = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
}
}
return $this->_aixdata;
}
/**
* get the information
*
* @see PSI_Interface_OS::build()
*
* @return Void
*/
public function build()
{
$this->error->addError("WARN", "The AIX version of phpSysInfo is a work in progress, some things currently don't work");
$this->_distro();
$this->_hostname();
$this->_ip();
$this->_kernel();
$this->_uptime();
$this->_users();
$this->_loadavg();
$this->_cpuinfo();
$this->_pci();
$this->_ide();
$this->_scsi();
$this->_usb();
$this->_network();
$this->_memory();
$this->_filesystems();
}
}

View File

@@ -0,0 +1,254 @@
<?php
/**
* Android System Class
*
* PHP version 5
*
* @category PHP
* @package PSI Android OS class
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @version SVN: $Id: class.Linux.inc.php 712 2012-12-05 14:09:18Z namiltd $
* @link http://phpsysinfo.sourceforge.net
*/
/**
* Android sysinfo class
* get all the required information from Android system
*
* @category PHP
* @package PSI Android OS class
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @version Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
class Android extends Linux
{
/**
* call parent constructor
*/
public function __construct()
{
parent::__construct();
}
/**
* Kernel Version
*
* @return void
*/
private function _kernel()
{
if (CommonFunctions::rfts('/proc/version', $strBuf, 1)) {
if (preg_match('/version (.*?) /', $strBuf, $ar_buf)) {
$result = $ar_buf[1];
if (preg_match('/SMP/', $strBuf)) {
$result .= ' (SMP)';
}
$this->sys->setKernel($result);
}
}
}
/**
* Number of Users
*
* @return void
*/
private function _users()
{
$this->sys->setUsers(1);
}
/**
* filesystem information
*
* @return void
*/
private function _filesystems()
{
if (CommonFunctions::executeProgram('df', '2>/dev/null ', $df, PSI_DEBUG)) {
$df = preg_split("/\n/", $df, -1, PREG_SPLIT_NO_EMPTY);
if (CommonFunctions::executeProgram('mount', '', $mount, PSI_DEBUG)) {
$mount = preg_split("/\n/", $mount, -1, PREG_SPLIT_NO_EMPTY);
foreach ($mount as $mount_line) {
$mount_buf = preg_split('/\s+/', $mount_line);
if (count($mount_buf) == 6) {
$mount_parm[$mount_buf[1]]['fstype'] = $mount_buf[2];
if (PSI_SHOW_MOUNT_OPTION) $mount_parm[$mount_buf[1]]['options'] = $mount_buf[3];
$mount_parm[$mount_buf[1]]['mountdev'] = $mount_buf[0];
}
}
foreach ($df as $df_line) {
if ((preg_match("/^(\/\S+)(\s+)(([0-9\.]+)([KMGT])(\s+)([0-9\.]+)([KMGT])(\s+)([0-9\.]+)([KMGT])(\s+))/", $df_line, $df_buf)
|| preg_match("/^(\/[^\s\:]+)\:(\s+)(([0-9\.]+)([KMGT])(\s+total\,\s+)([0-9\.]+)([KMGT])(\s+used\,\s+)([0-9\.]+)([KMGT])(\s+available))/", $df_line, $df_buf))
&& !preg_match('/^\/mnt\/asec\/com\./', $df_buf[1])) {
$dev = new DiskDevice();
if (PSI_SHOW_MOUNT_POINT) $dev->setMountPoint($df_buf[1]);
if ($df_buf[5] == 'K') $dev->setTotal($df_buf[4] * 1024);
elseif ($df_buf[5] == 'M') $dev->setTotal($df_buf[4] * 1024*1024);
elseif ($df_buf[5] == 'G') $dev->setTotal($df_buf[4] * 1024*1024*1024);
elseif ($df_buf[5] == 'T') $dev->setTotal($df_buf[4] * 1024*1024*1024*1024);
if ($df_buf[8] == 'K') $dev->setUsed($df_buf[7] * 1024);
elseif ($df_buf[8] == 'M') $dev->setUsed($df_buf[7] * 1024*1024);
elseif ($df_buf[8] == 'G') $dev->setUsed($df_buf[7] * 1024*1024*1024);
elseif ($df_buf[8] == 'T') $dev->setUsed($df_buf[7] * 1024*1024*1024*1024);
if ($df_buf[11] == 'K') $dev->setFree($df_buf[10] * 1024);
elseif ($df_buf[11] == 'M') $dev->setFree($df_buf[10] * 1024*1024);
elseif ($df_buf[11] == 'G') $dev->setFree($df_buf[10] * 1024*1024*1024);
elseif ($df_buf[11] == 'T') $dev->setFree($df_buf[10] * 1024*1024*1024*1024);
if (isset($mount_parm[$df_buf[1]])) {
$dev->setFsType($mount_parm[$df_buf[1]]['fstype']);
$dev->setName($mount_parm[$df_buf[1]]['mountdev']);
if (PSI_SHOW_MOUNT_OPTION) {
if (PSI_SHOW_MOUNT_CREDENTIALS) {
$dev->setOptions($mount_parm[$df_buf[1]]['options']);
} else {
$mpo=$mount_parm[$df_buf[1]]['options'];
$mpo=preg_replace('/(^guest,)|(^guest$)|(,guest$)/i', '', $mpo);
$mpo=preg_replace('/,guest,/i', ',', $mpo);
$mpo=preg_replace('/(^user=[^,]*,)|(^user=[^,]*$)|(,user=[^,]*$)/i', '', $mpo);
$mpo=preg_replace('/,user=[^,]*,/i', ',', $mpo);
$mpo=preg_replace('/(^username=[^,]*,)|(^username=[^,]*$)|(,username=[^,]*$)/i', '', $mpo);
$mpo=preg_replace('/,username=[^,]*,/i', ',', $mpo);
$mpo=preg_replace('/(^password=[^,]*,)|(^password=[^,]*$)|(,password=[^,]*$)/i', '', $mpo);
$mpo=preg_replace('/,password=[^,]*,/i', ',', $mpo);
$dev->setOptions($mpo);
}
}
}
$this->sys->setDiskDevices($dev);
}
}
}
}
}
/**
* Distribution
*
* @return void
*/
private function _distro()
{
$buf = "";
if (CommonFunctions::rfts('/system/build.prop', $lines, 0, 4096, false)
&& preg_match('/^ro\.build\.version\.release=([^\n]+)/m', $lines, $ar_buf)) {
$buf = trim($ar_buf[1]);
}
if (is_null($buf) || ($buf == "")) {
$this->sys->setDistribution('Android');
} else {
if (preg_match('/^(\d+\.\d+)/', $buf, $ver)
&& ($list = @parse_ini_file(APP_ROOT."/data/osnames.ini", true))
&& isset($list['Android'][$ver[1]])) {
$buf.=' '.$list['Android'][$ver[1]];
}
$this->sys->setDistribution('Android '.$buf);
}
$this->sys->setDistributionIcon('Android.png');
}
/**
* Machine
*
* @return void
*/
private function _machine()
{
if (CommonFunctions::rfts('/system/build.prop', $lines, 0, 4096, false)) {
$buf = "";
if (preg_match('/^ro\.product\.manufacturer=([^\n]+)/m', $lines, $ar_buf)) {
$buf .= ' '.trim($ar_buf[1]);
}
if (preg_match('/^ro\.product\.model=([^\n]+)/m', $lines, $ar_buf) && (trim($buf) !== trim($ar_buf[1]))) {
$buf .= ' '.trim($ar_buf[1]);
}
if (preg_match('/^ro\.semc\.product\.name=([^\n]+)/m', $lines, $ar_buf)) {
$buf .= ' '.trim($ar_buf[1]);
}
if (trim($buf) != "") {
$this->sys->setMachine(trim($buf));
}
}
}
/**
* PCI devices
*
* @return array
*/
private function _pci()
{
if (CommonFunctions::executeProgram('lspci', '', $bufr, false)) {
$bufe = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
foreach ($bufe as $buf) {
$device = preg_split("/ /", $buf, 4);
if (isset($device[3]) && trim($device[3]) != "") {
$dev = new HWDevice();
$dev->setName('Class '.trim($device[2]).' Device '.trim($device[3]));
$this->sys->setPciDevices($dev);
}
}
}
}
/**
* USB devices
*
* @return array
*/
private function _usb()
{
if (file_exists('/dev/bus/usb') && CommonFunctions::executeProgram('lsusb', '', $bufr, false)) {
$bufe = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
foreach ($bufe as $buf) {
$device = preg_split("/ /", $buf, 6);
if (isset($device[5]) && trim($device[5]) != "") {
$dev = new HWDevice();
$dev->setName(trim($device[5]));
$this->sys->setUsbDevices($dev);
}
}
}
}
/**
* get the information
*
* @see PSI_Interface_OS::build()
*
* @return Void
*/
public function build()
{
$this->_distro();
$this->_hostname();
$this->_ip();
$this->_kernel();
$this->_machine();
$this->_uptime();
$this->_users();
$this->_cpuinfo();
$this->_pci();
$this->_usb();
$this->_i2c();
$this->_network();
$this->_memory();
$this->_filesystems();
$this->_loadavg();
$this->_processes();
}
}

View File

@@ -0,0 +1,592 @@
<?php
/**
* BSDCommon Class
*
* PHP version 5
*
* @category PHP
* @package PSI BSDCommon OS class
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @version SVN: $Id: class.BSDCommon.inc.php 621 2012-07-29 18:49:04Z namiltd $
* @link http://phpsysinfo.sourceforge.net
*/
/**
* BSDCommon class
* get all the required information for BSD Like systems
* no need to implement in every class the same methods
*
* @category PHP
* @package PSI BSDCommon OS class
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @version Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
abstract class BSDCommon extends OS
{
/**
* content of the syslog
*
* @var array
*/
private $_dmesg = array();
/**
* regexp1 for cpu information out of the syslog
*
* @var string
*/
private $_CPURegExp1 = "";
/**
* regexp2 for cpu information out of the syslog
*
* @var string
*/
private $_CPURegExp2 = "";
/**
* regexp1 for scsi information out of the syslog
*
* @var string
*/
private $_SCSIRegExp1 = "";
/**
* regexp2 for scsi information out of the syslog
*
* @var string
*/
private $_SCSIRegExp2 = "";
/**
* regexp1 for pci information out of the syslog
*
* @var string
*/
private $_PCIRegExp1 = "";
/**
* regexp1 for pci information out of the syslog
*
* @var string
*/
private $_PCIRegExp2 = "";
/**
* call parent constructor
*/
public function __construct()
{
parent::__construct();
}
/**
* setter for cpuregexp1
*
* @param string $value value to set
*
* @return void
*/
protected function setCPURegExp1($value)
{
$this->_CPURegExp1 = $value;
}
/**
* setter for cpuregexp2
*
* @param string $value value to set
*
* @return void
*/
protected function setCPURegExp2($value)
{
$this->_CPURegExp2 = $value;
}
/**
* setter for scsiregexp1
*
* @param string $value value to set
*
* @return void
*/
protected function setSCSIRegExp1($value)
{
$this->_SCSIRegExp1 = $value;
}
/**
* setter for scsiregexp2
*
* @param string $value value to set
*
* @return void
*/
protected function setSCSIRegExp2($value)
{
$this->_SCSIRegExp2 = $value;
}
/**
* setter for pciregexp1
*
* @param string $value value to set
*
* @return void
*/
protected function setPCIRegExp1($value)
{
$this->_PCIRegExp1 = $value;
}
/**
* setter for pciregexp2
*
* @param string $value value to set
*
* @return void
*/
protected function setPCIRegExp2($value)
{
$this->_PCIRegExp2 = $value;
}
/**
* read /var/run/dmesg.boot, but only if we haven't already
*
* @return array
*/
protected function readdmesg()
{
if (count($this->_dmesg) === 0) {
if (PSI_OS != "Darwin") {
if (CommonFunctions::rfts('/var/run/dmesg.boot', $buf, 0, 4096, false) || CommonFunctions::rfts('/var/log/dmesg.boot', $buf, 0, 4096, false) || CommonFunctions::rfts('/var/run/dmesg.boot', $buf)) { // Once again but with debug
$parts = preg_split("/rebooting|Uptime/", $buf, -1, PREG_SPLIT_NO_EMPTY);
$this->_dmesg = preg_split("/\n/", $parts[count($parts) - 1], -1, PREG_SPLIT_NO_EMPTY);
}
}
}
return $this->_dmesg;
}
/**
* get a value from sysctl command
*
* @param string $key key for the value to get
*
* @return string
*/
protected function grabkey($key)
{
$buf = "";
if (CommonFunctions::executeProgram('sysctl', "-n $key", $buf, PSI_DEBUG)) {
return $buf;
} else {
return '';
}
}
/**
* Virtual Host Name
*
* @return void
*/
protected function hostname()
{
if (PSI_USE_VHOST === true) {
$this->sys->setHostname(getenv('SERVER_NAME'));
} else {
if (CommonFunctions::executeProgram('hostname', '', $buf, PSI_DEBUG)) {
$this->sys->setHostname($buf);
}
}
}
/**
* IP of the Canonical Host Name
*
* @return void
*/
protected function ip()
{
if (PSI_USE_VHOST === true) {
$this->sys->setIp(gethostbyname($this->sys->getHostname()));
} else {
if (!($result = getenv('SERVER_ADDR'))) {
$this->sys->setIp(gethostbyname($this->sys->getHostname()));
} else {
$this->sys->setIp($result);
}
}
}
/**
* Kernel Version
*
* @return void
*/
protected function kernel()
{
$s = $this->grabkey('kern.version');
$a = preg_split('/:/', $s);
$this->sys->setKernel($a[0].$a[1].':'.$a[2]);
}
/**
* Number of Users
*
* @return void
*/
protected function users()
{
if (CommonFunctions::executeProgram('who', '| wc -l', $buf, PSI_DEBUG)) {
$this->sys->setUsers($buf);
}
}
/**
* Processor Load
* optionally create a loadbar
*
* @return void
*/
protected function loadavg()
{
$s = $this->grabkey('vm.loadavg');
$s = preg_replace('/{ /', '', $s);
$s = preg_replace('/ }/', '', $s);
$this->sys->setLoad($s);
if (PSI_LOAD_BAR && (PSI_OS != "Darwin")) {
if ($fd = $this->grabkey('kern.cp_time')) {
// Find out the CPU load
// user + sys = load
// total = total
preg_match($this->_CPURegExp2, $fd, $res);
$load = $res[2] + $res[3] + $res[4]; // cpu.user + cpu.sys
$total = $res[2] + $res[3] + $res[4] + $res[5]; // cpu.total
// we need a second value, wait 1 second befor getting (< 1 second no good value will occour)
sleep(1);
$fd = $this->grabkey('kern.cp_time');
preg_match($this->_CPURegExp2, $fd, $res);
$load2 = $res[2] + $res[3] + $res[4];
$total2 = $res[2] + $res[3] + $res[4] + $res[5];
$this->sys->setLoadPercent((100 * ($load2 - $load)) / ($total2 - $total));
}
}
}
/**
* CPU information
*
* @return void
*/
protected function cpuinfo()
{
$dev = new CpuDevice();
$dev->setModel($this->grabkey('hw.model'));
$notwas = true;
foreach ($this->readdmesg() as $line) {
if ($notwas) {
if (preg_match("/".$this->_CPURegExp1."/", $line, $ar_buf)) {
$dev->setCpuSpeed(round($ar_buf[2]));
$notwas = false;
}
} else {
if (preg_match("/ Origin| Features/", $line, $ar_buf)) {
if (preg_match("/ Features2[ ]*=.*<(.*)>/", $line, $ar_buf)) {
$feats = preg_split("/,/", strtolower(trim($ar_buf[1])), -1, PREG_SPLIT_NO_EMPTY);
foreach ($feats as $feat) {
if (($feat=="vmx") || ($feat=="svm")) {
$dev->setVirt($feat);
break 2;
}
}
break;
}
} else break;
}
}
$ncpu = $this->grabkey('hw.ncpu');
if (is_null($ncpu) || (trim($ncpu) == "") || (!($ncpu >= 1)))
$ncpu = 1;
for ($ncpu ; $ncpu > 0 ; $ncpu--) {
$this->sys->setCpus($dev);
}
}
/**
* SCSI devices
* get the scsi device information out of dmesg
*
* @return void
*/
protected function scsi()
{
foreach ($this->readdmesg() as $line) {
if (preg_match("/".$this->_SCSIRegExp1."/", $line, $ar_buf)) {
$dev = new HWDevice();
$dev->setName($ar_buf[1].": ".$ar_buf[2]);
$this->sys->setScsiDevices($dev);
} elseif (preg_match("/".$this->_SCSIRegExp2."/", $line, $ar_buf)) {
/* duplication security */
$notwas = true;
foreach ($this->sys->getScsiDevices() as $finddev) {
if ($notwas && (substr($finddev->getName(), 0, strpos($finddev->getName(), ': ')) == $ar_buf[1])) {
$finddev->setCapacity($ar_buf[2] * 2048 * 1.049);
$notwas = false;
break;
}
}
if ($notwas) {
$dev = new HWDevice();
$dev->setName($ar_buf[1]);
$dev->setCapacity($ar_buf[2] * 2048 * 1.049);
$this->sys->setScsiDevices($dev);
}
}
}
/* cleaning */
foreach ($this->sys->getScsiDevices() as $finddev) {
if (strpos($finddev->getName(), ': ') !== false)
$finddev->setName(substr(strstr($finddev->getName(), ': '), 2));
}
}
/**
* parsing the output of pciconf command
*
* @return Array
*/
protected function pciconf()
{
$arrResults = array();
$intS = 0;
if (CommonFunctions::executeProgram("pciconf", "-lv", $strBuf, PSI_DEBUG)) {
$arrTemp = array();
$arrBlocks = preg_split("/\n\S/", $strBuf, -1, PREG_SPLIT_NO_EMPTY);
foreach ($arrBlocks as $strBlock) {
$arrLines = preg_split("/\n/", $strBlock, -1, PREG_SPLIT_NO_EMPTY);
$vend = null;
foreach ($arrLines as $strLine) {
if (preg_match("/\sclass=0x([a-fA-F0-9]{4})[a-fA-F0-9]{2}\s.*\schip=0x([a-fA-F0-9]{4})([a-fA-F0-9]{4})\s/", $strLine, $arrParts)) {
$arrTemp[$intS] = 'Class '.$arrParts[1].': Device '.$arrParts[3].':'.$arrParts[2];
$vend = '';
} elseif (preg_match("/(.*) = '(.*)'/", $strLine, $arrParts)) {
if (trim($arrParts[1]) == "vendor") {
$vend = trim($arrParts[2]);
} elseif (trim($arrParts[1]) == "device") {
if (($vend !== null) && ($vend !== '')) {
$arrTemp[$intS] = $vend." - ".trim($arrParts[2]);
} else {
$arrTemp[$intS] = trim($arrParts[2]);
$vend = '';
}
}
}
}
if ($vend !== null) {
$intS++;
}
}
foreach ($arrTemp as $name) {
$dev = new HWDevice();
$dev->setName($name);
$arrResults[] = $dev;
}
}
return $arrResults;
}
/**
* PCI devices
* get the pci device information out of dmesg
*
* @return void
*/
protected function pci()
{
if (!is_array($results = Parser::lspci(false)) || !is_array($results = $this->pciconf())) {
foreach ($this->readdmesg() as $line) {
if (preg_match("/".$this->_PCIRegExp1."/", $line, $ar_buf)) {
$dev = new HWDevice();
$dev->setName($ar_buf[1].": ".$ar_buf[2]);
$results[] = $dev;
} elseif (preg_match("/".$this->_PCIRegExp2."/", $line, $ar_buf)) {
$dev = new HWDevice();
$dev->setName($ar_buf[1].": ".$ar_buf[2]);
$results[] = $dev;
}
}
}
foreach ($results as $dev) {
$this->sys->setPciDevices($dev);
}
}
/**
* IDE devices
* get the ide device information out of dmesg
*
* @return void
*/
protected function ide()
{
foreach ($this->readdmesg() as $line) {
if (preg_match('/^(ad[0-9]+): (.*)MB <(.*)> (.*) (.*)/', $line, $ar_buf)) {
$dev = new HWDevice();
$dev->setName($ar_buf[1].": ".$ar_buf[3]);
$dev->setCapacity($ar_buf[2] * 1024);
$this->sys->setIdeDevices($dev);
} elseif (preg_match('/^(acd[0-9]+): (.*) <(.*)> (.*)/', $line, $ar_buf)) {
$dev = new HWDevice();
$dev->setName($ar_buf[1].": ".$ar_buf[3]);
$this->sys->setIdeDevices($dev);
} elseif (preg_match('/^(ada[0-9]+): <(.*)> (.*)/', $line, $ar_buf)) {
$dev = new HWDevice();
$dev->setName($ar_buf[1].": ".$ar_buf[2]);
$this->sys->setIdeDevices($dev);
} elseif (preg_match('/^(ada[0-9]+): (.*)MB \((.*)\)/', $line, $ar_buf)) {
/* duplication security */
$notwas = true;
foreach ($this->sys->getIdeDevices() as $finddev) {
if ($notwas && (substr($finddev->getName(), 0, strpos($finddev->getName(), ': ')) == $ar_buf[1])) {
$finddev->setCapacity($ar_buf[2] * 1024);
$notwas = false;
break;
}
}
if ($notwas) {
$dev = new HWDevice();
$dev->setName($ar_buf[1]);
$dev->setCapacity($ar_buf[2] * 1024);
$this->sys->setIdeDevices($dev);
}
}
}
/* cleaning */
foreach ($this->sys->getIdeDevices() as $finddev) {
if (strpos($finddev->getName(), ': ') !== false)
$finddev->setName(substr(strstr($finddev->getName(), ': '), 2));
}
}
/**
* Physical memory information and Swap Space information
*
* @return void
*/
protected function memory()
{
if (PSI_OS == 'FreeBSD' || PSI_OS == 'OpenBSD') {
// vmstat on fbsd 4.4 or greater outputs kbytes not hw.pagesize
// I should probably add some version checking here, but for now
// we only support fbsd 4.4
$pagesize = 1024;
} else {
$pagesize = $this->grabkey('hw.pagesize');
}
if (CommonFunctions::executeProgram('vmstat', '', $vmstat, PSI_DEBUG)) {
$lines = preg_split("/\n/", $vmstat, -1, PREG_SPLIT_NO_EMPTY);
$ar_buf = preg_split("/\s+/", trim($lines[2]), 19);
if (PSI_OS == 'NetBSD' || PSI_OS == 'DragonFly') {
$this->sys->setMemFree($ar_buf[4] * 1024);
} else {
$this->sys->setMemFree($ar_buf[4] * $pagesize);
}
$this->sys->setMemTotal($this->grabkey('hw.physmem'));
$this->sys->setMemUsed($this->sys->getMemTotal() - $this->sys->getMemFree());
if (((PSI_OS == 'OpenBSD' || PSI_OS == 'NetBSD') && CommonFunctions::executeProgram('swapctl', '-l -k', $swapstat, PSI_DEBUG)) || CommonFunctions::executeProgram('swapinfo', '-k', $swapstat, PSI_DEBUG)) {
$lines = preg_split("/\n/", $swapstat, -1, PREG_SPLIT_NO_EMPTY);
foreach ($lines as $line) {
$ar_buf = preg_split("/\s+/", $line, 6);
if (($ar_buf[0] != 'Total') && ($ar_buf[0] != 'Device')) {
$dev = new DiskDevice();
$dev->setMountPoint($ar_buf[0]);
$dev->setName("SWAP");
$dev->setFsType('swap');
$dev->setTotal($ar_buf[1] * 1024);
$dev->setUsed($ar_buf[2] * 1024);
$dev->setFree($dev->getTotal() - $dev->getUsed());
$this->sys->setSwapDevices($dev);
}
}
}
}
}
/**
* USB devices
* get the ide device information out of dmesg
*
* @return void
*/
protected function usb()
{
foreach ($this->readdmesg() as $line) {
// if (preg_match('/^(ugen[0-9\.]+): <(.*)> (.*) (.*)/', $line, $ar_buf)) {
// $dev->setName($ar_buf[1].": ".$ar_buf[2]);
if (preg_match('/^(u[a-z]+[0-9]+): <([^,]*)(.*)> on (usbus[0-9]+)/', $line, $ar_buf)) {
$dev = new HWDevice();
$dev->setName($ar_buf[2]);
$this->sys->setUSBDevices($dev);
}
}
}
/**
* filesystem information
*
* @return void
*/
protected function filesystems()
{
$arrResult = Parser::df();
foreach ($arrResult as $dev) {
$this->sys->setDiskDevices($dev);
}
}
/**
* Distribution
*
* @return void
*/
protected function distro()
{
if (CommonFunctions::executeProgram('uname', '-s', $result, PSI_DEBUG)) {
$this->sys->setDistribution($result);
}
}
/**
* get the information
*
* @see PSI_Interface_OS::build()
*
* @return Void
*/
public function build()
{
$this->distro();
$this->memory();
$this->ide();
$this->pci();
$this->cpuinfo();
$this->filesystems();
$this->kernel();
$this->users();
$this->loadavg();
$this->hostname();
$this->ip();
$this->scsi();
$this->usb();
}
}

View File

@@ -0,0 +1,464 @@
<?php
/**
* Darwin System Class
*
* PHP version 5
*
* @category PHP
* @package PSI Darwin OS class
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @version SVN: $Id: class.Darwin.inc.php 638 2012-08-24 09:40:48Z namiltd $
* @link http://phpsysinfo.sourceforge.net
*/
/**
* Darwin sysinfo class
* get all the required information from Darwin system
* information may be incomplete
*
* @category PHP
* @package PSI Darwin OS class
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @version Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
class Darwin extends BSDCommon
{
/**
* define the regexp for log parser
*/
/* public function __construct()
{
parent::__construct();
$this->error->addWarning("The Darwin version of phpSysInfo is a work in progress, some things currently don't work!");
$this->setCPURegExp1("CPU: (.*) \((.*)-MHz (.*)\)");
$this->setCPURegExp2("/(.*) ([0-9]+) ([0-9]+) ([0-9]+) ([0-9]+)/");
$this->setSCSIRegExp1("^(.*): <(.*)> .*SCSI.*device");
} */
/**
* get a value from sysctl command
*
* @param string $key key of the value to get
*
* @return string
*/
protected function grabkey($key)
{
if (CommonFunctions::executeProgram('sysctl', $key, $s, PSI_DEBUG)) {
$s = preg_replace('/'.$key.': /', '', $s);
$s = preg_replace('/'.$key.' = /', '', $s);
return $s;
} else {
return '';
}
}
/**
* get a value from ioreg command
*
* @param string $key key of the value to get
*
* @return string
*/
private function _grabioreg($key)
{
if (CommonFunctions::executeProgram('ioreg', '-c "'.$key.'"', $s, PSI_DEBUG)) {
/* delete newlines */
$s = preg_replace("/\s+/", " ", $s);
/* new newlines */
$s = preg_replace("/[\|\t ]*\+\-o/", "\n", $s);
/* combine duplicate whitespaces and some chars */
$s = preg_replace("/[\|\t ]+/", " ", $s);
$lines = preg_split("/\n/", $s, -1, PREG_SPLIT_NO_EMPTY);
$out = "";
foreach ($lines as $line) {
if (preg_match('/^([^<]*) <class '.$key.',/', $line)) {
$out .= $line."\n";
}
}
return $out;
} else {
return '';
}
}
/**
* UpTime
* time the system is running
*
* @return void
*/
private function _uptime()
{
if (CommonFunctions::executeProgram('sysctl', '-n kern.boottime', $a, PSI_DEBUG)) {
$tmp = explode(" ", $a);
if ($tmp[0]=="{") { /* kern.boottime= { sec = 1096732600, usec = 885425 } Sat Oct 2 10:56:40 2004 */
$data = trim($tmp[3], ",");
$this->sys->setUptime(time() - $data);
} else { /* kern.boottime= 1096732600 */
$this->sys->setUptime(time() - $a);
}
}
}
/**
* get CPU information
*
* @return void
*/
protected function cpuinfo()
{
$dev = new CpuDevice();
if (CommonFunctions::executeProgram('hostinfo', '| grep "Processor type"', $buf, PSI_DEBUG)) {
$dev->setModel(preg_replace('/Processor type: /', '', $buf));
$buf=$this->grabkey('hw.model');
if (!is_null($buf) && (trim($buf) != "")) {
$this->sys->setMachine(trim($buf));
if (CommonFunctions::rfts(APP_ROOT.'/data/ModelTranslation.txt', $buffer)) {
$buffer = preg_split("/\n/", $buffer, -1, PREG_SPLIT_NO_EMPTY);
foreach ($buffer as $line) {
$ar_buf = preg_split("/:/", $line, 3);
if (trim($buf) === trim($ar_buf[0])) {
$dev->setModel(trim($ar_buf[2]));
$this->sys->setMachine($this->sys->getMachine().' - '.trim($ar_buf[1]));
break;
}
}
}
}
$buf=$this->grabkey('machdep.cpu.brand_string');
if (!is_null($buf) && (trim($buf) != "") &&
((trim($buf) != "i486 (Intel 80486)") || ($dev->getModel() == ""))) {
$dev->setModel(trim($buf));
}
$buf=$this->grabkey('machdep.cpu.features');
if (!is_null($buf) && (trim($buf) != "")) {
if (preg_match("/ VMX/", $buf)) {
$dev->setVirt("vmx");
} elseif (preg_match("/ SVM/", $buf)) {
$dev->setVirt("svm");
}
}
}
$dev->setCpuSpeed(round($this->grabkey('hw.cpufrequency') / 1000000));
$dev->setBusSpeed(round($this->grabkey('hw.busfrequency') / 1000000));
$bufn=$this->grabkey('hw.cpufrequency_min');
$bufx=$this->grabkey('hw.cpufrequency_max');
if (!is_null($bufn) && (trim($bufn) != "") && !is_null($bufx) && (trim($bufx) != "") && ($bufn != $bufx)) {
$dev->setCpuSpeedMin(round($bufn / 1000000));
$dev->setCpuSpeedMax(round($bufx / 1000000));
}
$buf=$this->grabkey('hw.l2cachesize');
if (!is_null($buf) && (trim($buf) != "")) {
$dev->setCache(round($buf));
}
$ncpu = $this->grabkey('hw.ncpu');
if (is_null($ncpu) || (trim($ncpu) == "") || (!($ncpu >= 1)))
$ncpu = 1;
for ($ncpu ; $ncpu > 0 ; $ncpu--) {
$this->sys->setCpus($dev);
}
}
/**
* get the pci device information out of ioreg
*
* @return void
*/
protected function pci()
{
if (!$arrResults = Parser::lspci(false)) { //no lspci port
$s = $this->_grabioreg('IOPCIDevice');
$lines = preg_split("/\n/", $s, -1, PREG_SPLIT_NO_EMPTY);
foreach ($lines as $line) {
$dev = new HWDevice();
if (!preg_match('/"IOName" = "([^"]*)"/', $line, $ar_buf)) {
$ar_buf = preg_split("/[\s@]+/", $line, 19);
}
if (preg_match('/"model" = <?"([^"]*)"/', $line, $ar_buf2)) {
$dev->setName(trim($ar_buf[1]). ": ".trim($ar_buf2[1]));
} else {
$dev->setName(trim($ar_buf[1]));
}
$this->sys->setPciDevices($dev);
}
} else {
foreach ($arrResults as $dev) {
$this->sys->setPciDevices($dev);
}
}
}
/**
* get the ide device information out of ioreg
*
* @return void
*/
protected function ide()
{
$s = $this->_grabioreg('IOATABlockStorageDevice');
$lines = preg_split("/\n/", $s, -1, PREG_SPLIT_NO_EMPTY);
foreach ($lines as $line) {
$dev = new HWDevice();
if (!preg_match('/"Product Name"="([^"]*)"/', $line, $ar_buf))
$ar_buf = preg_split("/[\s@]+/", $line, 19);
$dev->setName(trim($ar_buf[1]));
$this->sys->setIdeDevices($dev);
}
$s = $this->_grabioreg('IOAHCIBlockStorageDevice');
$lines = preg_split("/\n/", $s, -1, PREG_SPLIT_NO_EMPTY);
foreach ($lines as $line) {
$dev = new HWDevice();
if (!preg_match('/"Product Name"="([^"]*)"/', $line, $ar_buf))
$ar_buf = preg_split("/[\s@]+/", $line, 19);
$dev->setName(trim($ar_buf[1]));
$this->sys->setIdeDevices($dev);
}
}
/**
* get the usb device information out of ioreg
*
* @return void
*/
protected function usb()
{
$s = $this->_grabioreg('IOUSBDevice');
$lines = preg_split("/\n/", $s, -1, PREG_SPLIT_NO_EMPTY);
foreach ($lines as $line) {
$dev = new HWDevice();
if (!preg_match('/"USB Product Name" = "([^"]*)"/', $line, $ar_buf))
$ar_buf = preg_split("/[\s@]+/", $line, 19);
$dev->setName(trim($ar_buf[1]));
$this->sys->setUsbDevices($dev);
}
}
/**
* get the scsi device information out of ioreg
*
* @return void
*/
protected function scsi()
{
$s = $this->_grabioreg('IOBlockStorageServices');
$lines = preg_split("/\n/", $s, -1, PREG_SPLIT_NO_EMPTY);
foreach ($lines as $line) {
$dev = new HWDevice();
if (!preg_match('/"Product Name"="([^"]*)"/', $line, $ar_buf))
$ar_buf = preg_split("/[\s@]+/", $line, 19);
$dev->setName(trim($ar_buf[1]));
$this->sys->setScsiDevices($dev);
}
}
/**
* get memory and swap information
*
* @return void
*/
protected function memory()
{
$s = $this->grabkey('hw.memsize');
if (CommonFunctions::executeProgram('vm_stat', '', $pstat, PSI_DEBUG)) {
// calculate free memory from page sizes (each page = 4096)
if (preg_match('/^Pages free:\s+(\S+)/m', $pstat, $free_buf)) {
if (preg_match('/^Anonymous pages:\s+(\S+)/m', $pstat, $anon_buf)
&& preg_match('/^Pages wired down:\s+(\S+)/m', $pstat, $wire_buf)
&& preg_match('/^File-backed pages:\s+(\S+)/m', $pstat, $fileb_buf)) {
// OS X 10.9 or never
$this->sys->setMemFree($free_buf[1] * 4 * 1024);
$this->sys->setMemApplication(($anon_buf[1]+$wire_buf[1]) * 4 * 1024);
$this->sys->setMemCache($fileb_buf[1] * 4 * 1024);
if (preg_match('/^Pages occupied by compressor:\s+(\S+)/m', $pstat, $compr_buf)) {
$this->sys->setMemBuffer($compr_buf[1] * 4 * 1024);
}
} else {
if (preg_match('/^Pages speculative:\s+(\S+)/m', $pstat, $spec_buf)) {
$this->sys->setMemFree(($free_buf[1]+$spec_buf[1]) * 4 * 1024);
} else {
$this->sys->setMemFree($free_buf[1] * 4 * 1024);
}
$appMemory = 0;
if (preg_match('/^Pages wired down:\s+(\S+)/m', $pstat, $wire_buf)) {
$appMemory += $wire_buf[1] * 4 * 1024;
}
if (preg_match('/^Pages active:\s+(\S+)/m', $pstat, $active_buf)) {
$appMemory += $active_buf[1] * 4 * 1024;
}
$this->sys->setMemApplication($appMemory);
if (preg_match('/^Pages inactive:\s+(\S+)/m', $pstat, $inactive_buf)) {
$this->sys->setMemCache($inactive_buf[1] * 4 * 1024);
}
}
} else {
$lines = preg_split("/\n/", $pstat, -1, PREG_SPLIT_NO_EMPTY);
$ar_buf = preg_split("/\s+/", $lines[1], 19);
$this->sys->setMemFree($ar_buf[2] * 4 * 1024);
}
$this->sys->setMemTotal($s);
$this->sys->setMemUsed($this->sys->getMemTotal() - $this->sys->getMemFree());
if (CommonFunctions::executeProgram('sysctl', 'vm.swapusage | colrm 1 22', $swapBuff, PSI_DEBUG)) {
$swap1 = preg_split('/M/', $swapBuff);
$swap2 = preg_split('/=/', $swap1[1]);
$swap3 = preg_split('/=/', $swap1[2]);
$dev = new DiskDevice();
$dev->setName('SWAP');
$dev->setMountPoint('SWAP');
$dev->setFsType('swap');
$dev->setTotal($swap1[0] * 1024 * 1024);
$dev->setUsed($swap2[1] * 1024 * 1024);
$dev->setFree($swap3[1] * 1024 * 1024);
$this->sys->setSwapDevices($dev);
}
}
}
/**
* get the thunderbolt device information out of ioreg
*
* @return void
*/
protected function _tb()
{
$s = $this->_grabioreg('IOThunderboltPort');
$lines = preg_split("/\n/", $s, -1, PREG_SPLIT_NO_EMPTY);
foreach ($lines as $line) {
$dev = new HWDevice();
if (!preg_match('/"Description" = "([^"]*)"/', $line, $ar_buf))
$ar_buf = preg_split("/[\s@]+/", $line, 19);
$dev->setName(trim($ar_buf[1]));
$this->sys->setTbDevices($dev);
}
}
/**
* get network information
*
* @return void
*/
private function _network()
{
if (CommonFunctions::executeProgram('netstat', '-nbdi | cut -c1-24,42- | grep Link', $netstat, PSI_DEBUG)) {
$lines = preg_split("/\n/", $netstat, -1, PREG_SPLIT_NO_EMPTY);
foreach ($lines as $line) {
$ar_buf = preg_split("/\s+/", $line, 10);
if (! empty($ar_buf[0])) {
$dev = new NetDevice();
$dev->setName($ar_buf[0]);
$dev->setTxBytes($ar_buf[8]);
$dev->setRxBytes($ar_buf[5]);
$dev->setErrors($ar_buf[4] + $ar_buf[7]);
if (isset($ar_buf[10])) {
$dev->setDrops($ar_buf[10]);
}
if (defined('PSI_SHOW_NETWORK_INFOS') && (PSI_SHOW_NETWORK_INFOS) && (CommonFunctions::executeProgram('ifconfig', $ar_buf[0].' 2>/dev/null', $bufr2, PSI_DEBUG))) {
$bufe2 = preg_split("/\n/", $bufr2, -1, PREG_SPLIT_NO_EMPTY);
foreach ($bufe2 as $buf2) {
if (preg_match('/^\s+ether\s+(\S+)/i', $buf2, $ar_buf2))
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').preg_replace('/:/', '-', $ar_buf2[1]));
elseif (preg_match('/^\s+inet\s+(\S+)\s+netmask/i', $buf2, $ar_buf2))
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$ar_buf2[1]);
elseif ((preg_match('/^\s+inet6\s+([^\s%]+)\s+prefixlen/i', $buf2, $ar_buf2)
|| preg_match('/^\s+inet6\s+([^\s%]+)%\S+\s+prefixlen/i', $buf2, $ar_buf2))
&& !preg_match('/^fe80::/i', $ar_buf2[1]))
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$ar_buf2[1]);
}
}
$this->sys->setNetDevices($dev);
}
}
}
}
/**
* get icon name
*
* @return void
*/
protected function distro()
{
$this->sys->setDistributionIcon('Darwin.png');
if (!CommonFunctions::executeProgram('system_profiler', 'SPSoftwareDataType', $buffer, PSI_DEBUG)) {
parent::distro();
} else {
$arrBuff = preg_split("/\n/", $buffer, -1, PREG_SPLIT_NO_EMPTY);
foreach ($arrBuff as $line) {
$arrLine = preg_split("/:/", $line, -1, PREG_SPLIT_NO_EMPTY);
if (trim($arrLine[0]) === "System Version") {
$distro = trim($arrLine[1]);
if (preg_match('/(^Mac OS)|(^OS X)/', $distro)) {
$this->sys->setDistributionIcon('Apple.png');
if (preg_match('/((^Mac OS X Server)|(^Mac OS X)|(^OS X Server)|(^OS X)) (\d+\.\d+)/', $distro, $ver)
&& ($list = @parse_ini_file(APP_ROOT."/data/osnames.ini", true))
&& isset($list['OS X'][$ver[6]])) {
$distro.=' '.$list['OS X'][$ver[6]];
}
}
$this->sys->setDistribution($distro);
return;
}
}
}
}
/**
* Processes
*
* @return void
*/
protected function _processes()
{
if (CommonFunctions::executeProgram('ps', 'aux', $bufr, PSI_DEBUG)) {
$lines = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
$processes['*'] = 0;
foreach ($lines as $line) {
if (preg_match("/^\S+\s+\d+\s+\S+\s+\S+\s+\d+\s+\d+\s+\S+\s+(\w)/", $line, $ar_buf)) {
$processes['*']++;
$state = $ar_buf[1];
if ($state == 'U') $state = 'D'; //linux format
elseif ($state == 'I') $state = 'S';
elseif ($state == 'D') $state = 'd'; //invalid
if (isset($processes[$state])) {
$processes[$state]++;
} else {
$processes[$state] = 1;
}
}
}
if ($processes['*'] > 0) {
$this->sys->setProcesses($processes);
}
}
}
/**
* get the information
*
* @see PSI_Interface_OS::build()
*
* @return Void
*/
public function build()
{
parent::build();
$this->_uptime();
$this->_network();
$this->_processes();
$this->_tb();
}
}

View File

@@ -0,0 +1,153 @@
<?php
/**
* DragonFly System Class
*
* PHP version 5
*
* @category PHP
* @package PSI DragonFly OS class
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @version SVN: $Id: class.DragonFly.inc.php 287 2009-06-26 12:11:59Z bigmichi1 $
* @link http://phpsysinfo.sourceforge.net
*/
/**
* DragonFly sysinfo class
* get all the required information from DragonFly system
*
* @category PHP
* @package PSI DragonFly OS class
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @version Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
class DragonFly extends BSDCommon
{
/**
* define the regexp for log parser
*/
public function __construct()
{
parent::__construct();
$this->setCPURegExp1("^cpu(.*)\, (.*) MHz");
$this->setCPURegExp2("^(.*) at scsibus.*: <(.*)> .*");
$this->setSCSIRegExp2("^(da[0-9]): (.*)MB ");
$this->setPCIRegExp1("/(.*): <(.*)>(.*) (pci|legacypci)[0-9]$/");
$this->setPCIRegExp2("/(.*): <(.*)>.* at [0-9\.]+$/");
}
/**
* UpTime
* time the system is running
*
* @return void
*/
private function _uptime()
{
$a = $this->grab_key('kern.boottime');
preg_match("/sec = ([0-9]+)/", $a, $buf);
$this->sys->setUptime(time() - $buf[1]);
}
/**
* get network information
*
* @return array
*/
private function _network()
{
CommonFunctions::executeProgram('netstat', '-nbdi | cut -c1-25,44- | grep "^[a-z]*[0-9][ \t].*Link"', $netstat_b);
CommonFunctions::executeProgram('netstat', '-ndi | cut -c1-25,44- | grep "^[a-z]*[0-9][ \t].*Link"', $netstat_n);
$lines_b = preg_split("/\n/", $netstat_b, -1, PREG_SPLIT_NO_EMPTY);
$lines_n = preg_split("/\n/", $netstat_n, -1, PREG_SPLIT_NO_EMPTY);
for ($i = 0, $max = sizeof($lines_b); $i < $max; $i++) {
$ar_buf_b = preg_split("/\s+/", $lines_b[$i]);
$ar_buf_n = preg_split("/\s+/", $lines_n[$i]);
if (! empty($ar_buf_b[0]) && ! empty($ar_buf_n[3])) {
$dev = new NetDevice();
$dev->setName($ar_buf_b[0]);
$dev->setTxBytes($ar_buf_b[8]);
$dev->setRxBytes($ar_buf_b[5]);
$dev->setErrors($ar_buf_n[4] + $ar_buf_n[6]);
$dev->setDrops($ar_buf_n[8]);
$this->sys->setNetDevices($dev);
}
}
}
/**
* get the ide information
*
* @return array
*/
protected function ide()
{
foreach ($this->readdmesg() as $line) {
if (preg_match('/^(.*): (.*) <(.*)> at (ata[0-9]\-(.*)) (.*)/', $line, $ar_buf)) {
$dev = new HWDevice();
$dev->setName($ar_buf[1]);
if (!preg_match("/^acd[0-9](.*)/", $ar_buf[1])) {
$dev->setCapacity($ar_buf[2] * 1024);
}
$this->sys->setIdeDevices($dev);
}
}
}
/**
* get icon name
*
* @return void
*/
private function _distroicon()
{
$this->sys->setDistributionIcon('DragonFly.png');
}
/**
* Processes
*
* @return void
*/
protected function _processes()
{
if (CommonFunctions::executeProgram('ps', 'aux', $bufr, PSI_DEBUG)) {
$lines = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
$processes['*'] = 0;
foreach ($lines as $line) {
if (preg_match("/^\S+\s+\d+\s+\S+\s+\S+\s+\d+\s+\d+\s+\S+\s+(\w)/", $line, $ar_buf)) {
$processes['*']++;
$state = $ar_buf[1];
if ($state == 'I') $state = 'S'; //linux format
if (isset($processes[$state])) {
$processes[$state]++;
} else {
$processes[$state] = 1;
}
}
}
if ($processes['*'] > 0) {
$this->sys->setProcesses($processes);
}
}
}
/**
* get the information
*
* @see BSDCommon::build()
*
* @return Void
*/
public function build()
{
parent::build();
$this->_distroicon();
$this->_network();
$this->_uptime();
$this->_processes();
}
}

View File

@@ -0,0 +1,190 @@
<?php
/**
* FreeBSD System Class
*
* PHP version 5
*
* @category PHP
* @package PSI FreeBSD OS class
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @version SVN: $Id: class.FreeBSD.inc.php 696 2012-09-09 11:24:04Z namiltd $
* @link http://phpsysinfo.sourceforge.net
*/
/**
* FreeBSD sysinfo class
* get all the required information from FreeBSD system
*
* @category PHP
* @package PSI FreeBSD OS class
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @version Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
class FreeBSD extends BSDCommon
{
/**
* define the regexp for log parser
*/
public function __construct()
{
parent::__construct();
$this->setCPURegExp1("CPU: (.*) \((.*)-MHz (.*)\)");
$this->setCPURegExp2("/(.*) ([0-9]+) ([0-9]+) ([0-9]+) ([0-9]+)/");
$this->setSCSIRegExp1("^(.*): <(.*)> .*SCSI.*device");
$this->setSCSIRegExp2("^(da[0-9]): (.*)MB ");
$this->setPCIRegExp1("/(.*): <(.*)>(.*) pci[0-9]$/");
$this->setPCIRegExp2("/(.*): <(.*)>.* at [.0-9]+ irq/");
}
/**
* UpTime
* time the system is running
*
* @return void
*/
private function _uptime()
{
$s = preg_split('/ /', $this->grabkey('kern.boottime'));
$a = preg_replace('/,/', '', $s[3]);
$this->sys->setUptime(time() - $a);
}
/**
* get network information
*
* @return void
*/
private function _network()
{
$dev = null;
if (CommonFunctions::executeProgram('netstat', '-nibd', $netstat, PSI_DEBUG)) {
$lines = preg_split("/\n/", $netstat, -1, PREG_SPLIT_NO_EMPTY);
foreach ($lines as $line) {
$ar_buf = preg_split("/\s+/", $line);
if (! empty($ar_buf[0])) {
if (preg_match('/^<Link/i', $ar_buf[2])) {
$dev = new NetDevice();
$dev->setName($ar_buf[0]);
if (strlen($ar_buf[3]) < 17) { /* no Address */
if (isset($ar_buf[11]) && (trim($ar_buf[11]) != '')) { /* Idrop column exist*/
$dev->setTxBytes($ar_buf[9]);
$dev->setRxBytes($ar_buf[6]);
$dev->setErrors($ar_buf[4] + $ar_buf[8]);
$dev->setDrops($ar_buf[11] + $ar_buf[5]);
} else {
$dev->setTxBytes($ar_buf[8]);
$dev->setRxBytes($ar_buf[5]);
$dev->setErrors($ar_buf[4] + $ar_buf[7]);
$dev->setDrops($ar_buf[10]);
}
} else {
if (isset($ar_buf[12]) && (trim($ar_buf[12]) != '')) { /* Idrop column exist*/
$dev->setTxBytes($ar_buf[10]);
$dev->setRxBytes($ar_buf[7]);
$dev->setErrors($ar_buf[5] + $ar_buf[9]);
$dev->setDrops($ar_buf[12] + $ar_buf[6]);
} else {
$dev->setTxBytes($ar_buf[9]);
$dev->setRxBytes($ar_buf[6]);
$dev->setErrors($ar_buf[5] + $ar_buf[8]);
$dev->setDrops($ar_buf[11]);
}
}
if (defined('PSI_SHOW_NETWORK_INFOS') && (PSI_SHOW_NETWORK_INFOS) && (CommonFunctions::executeProgram('ifconfig', $ar_buf[0].' 2>/dev/null', $bufr2, PSI_DEBUG))) {
$bufe2 = preg_split("/\n/", $bufr2, -1, PREG_SPLIT_NO_EMPTY);
foreach ($bufe2 as $buf2) {
if (preg_match('/^\s+ether\s+(\S+)/i', $buf2, $ar_buf2))
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').preg_replace('/:/', '-', $ar_buf2[1]));
elseif (preg_match('/^\s+inet\s+(\S+)\s+netmask/i', $buf2, $ar_buf2))
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$ar_buf2[1]);
elseif ((preg_match('/^\s+inet6\s+([^\s%]+)\s+prefixlen/i', $buf2, $ar_buf2)
|| preg_match('/^\s+inet6\s+([^\s%]+)%\S+\s+prefixlen/i', $buf2, $ar_buf2))
&& !preg_match('/^fe80::/i', $ar_buf2[1]))
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$ar_buf2[1]);
}
}
$this->sys->setNetDevices($dev);
}
}
}
}
}
/**
* get icon name and distro extended check
*
* @return void
*/
private function _distroicon()
{
if (extension_loaded('pfSense') && CommonFunctions::rfts('/etc/version', $version, 1, 4096, false) && (trim($version) != '')) { // pfSense detection
$this->sys->setDistribution('pfSense '. trim($version));
$this->sys->setDistributionIcon('pfSense.png');
} else {
$this->sys->setDistributionIcon('FreeBSD.png');
}
}
/**
* extend the memory information with additional values
*
* @return void
*/
private function _memoryadditional()
{
$pagesize = $this->grabkey("hw.pagesize");
$this->sys->setMemCache($this->grabkey("vm.stats.vm.v_cache_count") * $pagesize);
$this->sys->setMemApplication(($this->grabkey("vm.stats.vm.v_active_count") + $this->grabkey("vm.stats.vm.v_wire_count")) * $pagesize);
$this->sys->setMemBuffer($this->sys->getMemUsed() - $this->sys->getMemApplication() - $this->sys->getMemCache());
}
/**
* Processes
*
* @return void
*/
protected function _processes()
{
if (CommonFunctions::executeProgram('ps', 'aux', $bufr, PSI_DEBUG)) {
$lines = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
$processes['*'] = 0;
foreach ($lines as $line) {
if (preg_match("/^\S+\s+\d+\s+\S+\s+\S+\s+\d+\s+\d+\s+\S+\s+(\w)/", $line, $ar_buf)) {
$processes['*']++;
$state = $ar_buf[1];
if ($state == 'L') $state = 'D'; //linux format
elseif ($state == 'I') $state = 'S';
if (isset($processes[$state])) {
$processes[$state]++;
} else {
$processes[$state] = 1;
}
}
}
if ($processes['*'] > 0) {
$this->sys->setProcesses($processes);
}
}
}
/**
* get the information
*
* @see BSDCommon::build()
*
* @return Void
*/
public function build()
{
parent::build();
$this->_memoryadditional();
$this->_distroicon();
$this->_network();
$this->_uptime();
$this->_processes();
}
}

View File

@@ -0,0 +1,404 @@
<?php
/**
* HP-UX System Class
*
* PHP version 5
*
* @category PHP
* @package PSI HPUX OS class
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @version SVN: $Id: class.HPUX.inc.php 596 2012-07-05 19:37:48Z namiltd $
* @link http://phpsysinfo.sourceforge.net
*/
/**
* HP-UX sysinfo class
* get all the required information from HP-UX system
*
* @category PHP
* @package PSI HPUX OS class
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @version Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
class HPUX extends OS
{
/**
* Virtual Host Name
*
* @return void
*/
private function _hostname()
{
if (PSI_USE_VHOST === true) {
$this->sys->setHostname(getenv('SERVER_NAME'));
} else {
if (CommonFunctions::executeProgram('hostname', '', $ret)) {
$this->sys->setHostname($ret);
}
}
}
/**
* IP of the Virtual Host Name
*
* @return void
*/
private function _ip()
{
if (PSI_USE_VHOST === true) {
$this->sys->setIp(gethostbyname($this->sys->getHostname()));
} else {
if (!($result = getenv('SERVER_ADDR'))) {
$this->sys->setIp(gethostbyname($this->sys->getHostname()));
} else {
$this->sys->setIp($result);
}
}
}
/**
* HP-UX Version
*
* @return void
*/
private function _kernel()
{
if (CommonFunctions::executeProgram('uname', '-srvm', $ret)) {
$this->sys->setKernel($ret);
}
}
/**
* UpTime
* time the system is running
*
* @return void
*/
private function _uptime()
{
if (CommonFunctions::executeProgram('uptime', '', $buf)) {
if (preg_match("/up (\d+) days,\s*(\d+):(\d+),/", $buf, $ar_buf)) {
$min = $ar_buf[3];
$hours = $ar_buf[2];
$days = $ar_buf[1];
$this->sys->setUptime($days * 86400 + $hours * 3600 + $min * 60);
}
}
}
/**
* Number of Users
*
* @return void
*/
private function _users()
{
if (CommonFunctions::executeProgram('who', '-q', $ret)) {
$who = preg_split('/=/', $ret, -1, PREG_SPLIT_NO_EMPTY);
$this->sys->setUsers($who[1]);
}
}
/**
* Processor Load
* optionally create a loadbar
*
* @return void
*/
private function _loadavg()
{
if (CommonFunctions::executeProgram('uptime', '', $buf)) {
if (preg_match("/average: (.*), (.*), (.*)$/", $buf, $ar_buf)) {
$this->sys->setLoad($ar_buf[1].' '.$ar_buf[2].' '.$ar_buf[3]);
}
}
}
/**
* CPU information
* All of the tags here are highly architecture dependant
*
* @return void
*/
private function _cpuinfo()
{
if (CommonFunctions::rfts('/proc/cpuinfo', $bufr)) {
$processors = preg_split('/\s?\n\s?\n/', trim($bufr));
foreach ($processors as $processor) {
$dev = new CpuDevice();
$details = preg_split("/\n/", $processor, -1, PREG_SPLIT_NO_EMPTY);
foreach ($details as $detail) {
$arrBuff = preg_split('/\s+:\s+/', trim($detail));
if (count($arrBuff) == 2) {
switch (strtolower($arrBuff[0])) {
case 'model name':
case 'cpu':
$dev->setModel($arrBuff[1]);
break;
case 'cpu mhz':
case 'clock':
$dev->setCpuSpeed($arrBuff[1]);
break;
case 'cycle frequency [hz]':
$dev->setCpuSpeed($arrBuff[1] / 1000000);
break;
case 'cpu0clktck':
$dev->setCpuSpeed(hexdec($arrBuff[1]) / 1000000); // Linux sparc64
break;
case 'l2 cache':
case 'cache size':
$dev->setCache(preg_replace("/[a-zA-Z]/", "", $arrBuff[1]) * 1024);
break;
case 'bogomips':
case 'cpu0bogo':
$dev->setBogomips($arrBuff[1]);
break;
}
}
}
}
}
}
/**
* PCI devices
*
* @return void
*/
private function _pci()
{
if (CommonFunctions::rfts('/proc/pci', $bufr)) {
$bufe = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
foreach ($bufe as $buf) {
if (preg_match('/Bus/', $buf)) {
$device = true;
continue;
}
if ($device) {
list($key, $value) = preg_split('/: /', $buf, 2);
if (!preg_match('/bridge/i', $key) && !preg_match('/USB/i', $key)) {
$dev = new HWDevice();
$dev->setName(preg_replace('/\([^\)]+\)\.$/', '', trim($value)));
$this->sys->setPciDevices($dev);
}
$device = false;
}
}
}
}
/**
* IDE devices
*
* @return void
*/
private function _ide()
{
$bufd = CommonFunctions::gdc('/proc/ide', false);
foreach ($bufd as $file) {
if (preg_match('/^hd/', $file)) {
$dev = new HWDevice();
$dev->setName(trim($file));
if (CommonFunctions::rfts("/proc/ide/".$file."/media", $buf, 1)) {
if (trim($buf) == 'disk') {
if (CommonFunctions::rfts("/proc/ide/".$file."/capacity", $buf, 1, 4096, false)) {
$dev->setCapacity(trim($buf) * 512 / 1024);
}
}
}
$this->sys->setIdeDevices($dev);
}
}
}
/**
* SCSI devices
*
* @return void
*/
private function _scsi()
{
$get_type = false;
if (CommonFunctions::rfts('/proc/scsi/scsi', $bufr, 0, 4096, PSI_DEBUG)) {
$bufe = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
foreach ($bufe as $buf) {
if (preg_match('/Vendor: (.*) Model: (.*) Rev: (.*)/i', $buf, $dev)) {
$get_type = true;
continue;
}
if ($get_type) {
preg_match('/Type:\s+(\S+)/i', $buf, $dev_type);
$dev = new HWDevice();
$dev->setName($dev[1].' '.$dev[2].' ('.$dev_type[1].')');
$this->sys->setScsiDevices($dev);
$get_type = false;
}
}
}
}
/**
* USB devices
*
* @return void
*/
private function _usb()
{
if (CommonFunctions::rfts('/proc/bus/usb/devices', $bufr, 0, 4096, false)) {
$bufe = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
foreach ($bufe as $buf) {
if (preg_match('/^T/', $buf)) {
$devnum += 1;
$results[$devnum] = "";
} elseif (preg_match('/^S:/', $buf)) {
list($key, $value) = preg_split('/: /', $buf, 2);
list($key, $value2) = preg_split('/=/', $value, 2);
if (trim($key) != "SerialNumber") {
$results[$devnum] .= " ".trim($value2);
}
}
}
foreach ($results as $var) {
$dev = new HWDevice();
$dev->setName($var);
$this->sys->setUsbDevices($dev);
}
}
}
/**
* Network devices
* includes also rx/tx bytes
*
* @return void
*/
private function _network()
{
if (CommonFunctions::executeProgram('netstat', '-ni | tail -n +2', $netstat)) {
$lines = preg_split("/\n/", $netstat, -1, PREG_SPLIT_NO_EMPTY);
foreach ($lines as $line) {
$ar_buf = preg_split("/\s+/", $line);
if (! empty($ar_buf[0]) && ! empty($ar_buf[3])) {
$dev = new NetDevice();
$dev->setName($ar_buf[0]);
$dev->setRxBytes($ar_buf[4]);
$dev->setTxBytes($ar_buf[6]);
$dev->setErrors($ar_buf[5] + $ar_buf[7]);
$dev->setDrops($ar_buf[8]);
$this->sys->setNetDevices($dev);
}
}
}
}
/**
* Physical memory information and Swap Space information
*
* @return void
*/
private function _memory()
{
if (CommonFunctions::rfts('/proc/meminfo', $bufr)) {
$bufe = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
foreach ($bufe as $buf) {
if (preg_match('/Mem:\s+(.*)$/', $buf, $ar_buf)) {
$ar_buf = preg_split('/\s+/', $ar_buf[1], 6);
$this->sys->setMemTotal($ar_buf[0]);
$this->sys->setMemUsed($ar_buf[1]);
$this->sys->setMemFree($ar_buf[2]);
$this->sys->setMemApplication($ar_buf[3]);
$this->sys->setMemBuffer($ar_buf[4]);
$this->sys->setMemCache($ar_buf[5]);
}
// Get info on individual swap files
if (CommonFunctions::rfts('/proc/swaps', $swaps)) {
$swapdevs = preg_split("/\n/", $swaps, -1, PREG_SPLIT_NO_EMPTY);
for ($i = 1, $max = (sizeof($swapdevs) - 1); $i < $max; $i++) {
$ar_buf = preg_split('/\s+/', $swapdevs[$i], 6);
$dev = new DiskDevice();
$dev->setMountPoint($ar_buf[0]);
$dev->setName("SWAP");
$dev->setFsType('swap');
$dev->setTotal($ar_buf[2] * 1024);
$dev->setUsed($ar_buf[3] * 1024);
$dev->setFree($dev->getTotal() - $dev->getUsed());
$this->sys->setSwapDevices($dev);
}
}
}
}
}
/**
* filesystem information
*
* @return void
*/
private function _filesystems()
{
if (CommonFunctions::executeProgram('df', '-kP', $df, PSI_DEBUG)) {
$mounts = preg_split("/\n/", $df, -1, PREG_SPLIT_NO_EMPTY);
if (CommonFunctions::executeProgram('mount', '-v', $s, PSI_DEBUG)) {
$lines = preg_split("/\n/", $s, -1, PREG_SPLIT_NO_EMPTY);
while (list(, $line) = each($lines)) {
$a = preg_split('/ /', $line, -1, PREG_SPLIT_NO_EMPTY);
$fsdev[$a[0]] = $a[4];
}
}
foreach ($mounts as $mount) {
$ar_buf = preg_split("/\s+/", $mount, 6);
$dev = new DiskDevice();
$dev->setName($ar_buf[0]);
$dev->setTotal($ar_buf[1] * 1024);
$dev->setUsed($ar_buf[2] * 1024);
$dev->setFree($ar_buf[3] * 1024);
$dev->setMountPoint($ar_buf[5]);
if (isset($fsdev[$ar_buf[0]])) {
$dev->setFsType($fsdev[$ar_buf[0]]);
}
$this->sys->setDiskDevices($dev);
}
}
}
/**
* Distribution
*
* @return void
*/
private function _distro()
{
$this->sys->setDistribution('HP-UX');
$this->sys->setDistributionIcon('HPUX.png');
}
/**
* get the information
*
* @see PSI_Interface_OS::build()
*
* @return Void
*/
public function build()
{
$this->_distro();
$this->_hostname();
$this->_ip();
$this->_kernel();
$this->_uptime();
$this->_users();
$this->_loadavg();
$this->_cpuinfo();
$this->_pci();
$this->_ide();
$this->_scsi();
$this->_usb();
$this->_network();
$this->_memory();
$this->_filesystems();
}
}

View File

@@ -0,0 +1,403 @@
<?php
/**
* Haiku System Class
*
* PHP version 5
*
* @category PHP
* @package PSI Haiku OS class
* @author Mieczyslaw Nalewaj <namiltd@users.sourceforge.net>
* @copyright 2012 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @version SVN: $Id: class.Haiku.inc.php 687 2012-09-06 20:54:49Z namiltd $
* @link http://phpsysinfo.sourceforge.net
*/
/**
* Haiku sysinfo class
* get all the required information from Haiku system
*
* @category PHP
* @package PSI Haiku OS class
* @author Mieczyslaw Nalewaj <namiltd@users.sourceforge.net>
* @copyright 2012 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @version Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
class Haiku extends OS
{
/**
* call parent constructor
*/
public function __construct()
{
parent::__construct();
}
/**
* get the cpu information
*
* @return array
*/
protected function _cpuinfo()
{
if (CommonFunctions::executeProgram('sysinfo', '-cpu', $bufr, PSI_DEBUG)) {
$cpus = preg_split("/\nCPU #\d+/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
$cpuspeed = "";
foreach ($cpus as $cpu) {
if (preg_match("/^.*running at (\d+)MHz/", $cpu, $ar_buf)) {
$cpuspeed = $ar_buf[1];
} elseif (preg_match("/^: \"(.*)\"/", $cpu, $ar_buf)) {
$dev = new CpuDevice();
$dev->setModel($ar_buf[1]);
$arrLines = preg_split("/\n/", $cpu, -1, PREG_SPLIT_NO_EMPTY);
foreach ($arrLines as $Line) {
if (preg_match("/^\s+Data TLB:\s+(.*)K-byte/", $Line, $Line_buf)) {
$dev->setCache(max($Line_buf[1]*1024, $dev->getCache()));
} elseif (preg_match("/^\s+Data TLB:\s+(.*)M-byte/", $Line, $Line_buf)) {
$dev->setCache(max($Line_buf[1]*1024*1024, $dev->getCache()));
} elseif (preg_match("/^\s+Data TLB:\s+(.*)G-byte/", $Line, $Line_buf)) {
$dev->setCache(max($Line_buf[1]*1024*1024*1024, $dev->getCache()));
} elseif (preg_match("/\s+VMX/", $Line, $Line_buf)) {
$dev->setVirt("vmx");
} elseif (preg_match("/\s+SVM/", $Line, $Line_buf)) {
$dev->setVirt("svm");
}
}
if ($cpuspeed != "")$dev->setCpuSpeed($cpuspeed);
$this->sys->setCpus($dev);
//echo ">>>>>".$cpu;
}
}
}
}
/**
* PCI devices
* get the pci device information
*
* @return void
*/
protected function _pci()
{
if (CommonFunctions::executeProgram('listdev', '', $bufr, PSI_DEBUG)) {
// $devices = preg_split("/^device |\ndevice /", $bufr, -1, PREG_SPLIT_NO_EMPTY);
$devices = preg_split("/^device /m", $bufr, -1, PREG_SPLIT_NO_EMPTY);
foreach ($devices as $device) {
$ar_buf = preg_split("/\n/", $device);
if (count($ar_buf) >= 3) {
if (preg_match("/^([^\(\[\n]*)/", $device, $ar_buf2)) {
if (preg_match("/^[^\(]*\((.*)\)/", $device, $ar_buf3)) {
$ar_buf2[1] = $ar_buf3[1];
}
$name = trim($ar_buf2[1]).": ";
if (preg_match("/^\s+vendor\s+[0-9a-fA-F]{4}:\s+(.*)/", $ar_buf[1], $ar_buf3)) {
$name .=$ar_buf3[1]." ";
}
if (preg_match("/^\s+device\s+[0-9a-fA-F]{4}:\s+(.*)/", $ar_buf[2], $ar_buf3)) {
$name .=$ar_buf3[1]." ";
}
$dev = new HWDevice();
$dev->setName(trim($name));
$this->sys->setPciDevices($dev);
}
}
}
}
}
/**
* USB devices
* get the usb device information
*
* @return void
*/
protected function _usb()
{
if (CommonFunctions::executeProgram('listusb', '', $bufr, PSI_DEBUG)) {
$devices = preg_split("/\n/", $bufr);
foreach ($devices as $device) {
if (preg_match("/^\S+\s+\S+\s+\"(.*)\"\s+\"(.*)\"/", $device, $ar_buf)) {
$dev = new HWDevice();
$dev->setName(trim($ar_buf[1]." ".$ar_buf[2]));
$this->sys->setUSBDevices($dev);
}
}
}
}
/**
* Haiku Version
*
* @return void
*/
private function _kernel()
{
if (CommonFunctions::executeProgram('uname', '-rvm', $ret)) {
$this->sys->setKernel($ret);
}
}
/**
* Distribution
*
* @return void
*/
protected function _distro()
{
if (CommonFunctions::executeProgram('uname', '-sr', $ret))
$this->sys->setDistribution($ret);
else
$this->sys->setDistribution('Haiku');
$this->sys->setDistributionIcon('Haiku.png');
}
/**
* UpTime
* time the system is running
*
* @return void
*/
private function _uptime()
{
if (CommonFunctions::executeProgram('uptime', '-u', $buf)) {
if (preg_match("/^up (\d+) minute[s]?/", $buf, $ar_buf)) {
$min = $ar_buf[1];
$this->sys->setUptime($min * 60);
} elseif (preg_match("/^up (\d+) hour[s]?, (\d+) minute[s]?/", $buf, $ar_buf)) {
$min = $ar_buf[2];
$hours = $ar_buf[1];
$this->sys->setUptime($hours * 3600 + $min * 60);
} elseif (preg_match("/^up (\d+) day[s]?, (\d+) hour[s]?, (\d+) minute[s]?/", $buf, $ar_buf)) {
$min = $ar_buf[3];
$hours = $ar_buf[2];
$days = $ar_buf[1];
$this->sys->setUptime($days * 86400 + $hours * 3600 + $min * 60);
}
}
}
/**
* Processor Load
* optionally create a loadbar
*
* @return void
*/
private function _loadavg()
{
if (CommonFunctions::executeProgram('top', '-n 1 -i 1', $buf)) {
if (preg_match("/\s+(\S+)%\s+TOTAL\s+\(\S+%\s+idle time/", $buf, $ar_buf)) {
$this->sys->setLoad($ar_buf[1]);
if (PSI_LOAD_BAR) {
$this->sys->setLoadPercent(round($ar_buf[1]));
}
}
}
}
/**
* Number of Users
*
* @return void
*/
private function _users()
{
$this->sys->setUsers(1);
}
/**
* Virtual Host Name
*
* @return void
*/
private function _hostname()
{
if (PSI_USE_VHOST === true) {
$this->sys->setHostname(getenv('SERVER_NAME'));
} else {
if (CommonFunctions::executeProgram('uname', '-n', $result, PSI_DEBUG)) {
$ip = gethostbyname($result);
if ($ip != $result) {
$this->sys->setHostname(gethostbyaddr($ip));
}
}
}
}
/**
* IP of the Virtual Host Name
*
* @return void
*/
private function _ip()
{
if (PSI_USE_VHOST === true) {
$this->sys->setIp(gethostbyname($this->sys->getHostname()));
} else {
if (!($result = getenv('SERVER_ADDR'))) {
$this->sys->setIp(gethostbyname($this->sys->getHostname()));
} else {
$this->sys->setIp($result);
}
}
}
/**
* Physical memory information and Swap Space information
*
* @return void
*/
private function _memory()
{
if (CommonFunctions::executeProgram('sysinfo', '-mem', $bufr, PSI_DEBUG)) {
if (preg_match("/(.*)bytes free\s+\(used\/max\s+(.*)\s+\/\s+(.*)\)\s*\n\s+\(cached\s+(.*)\)/", $bufr, $ar_buf)) {
$this->sys->setMemTotal($ar_buf[3]);
$this->sys->setMemFree($ar_buf[1]);
$this->sys->setMemCache($ar_buf[4]);
$this->sys->setMemUsed($ar_buf[2]);
}
}
if (CommonFunctions::executeProgram('vmstat', '', $bufr, PSI_DEBUG)) {
if (preg_match("/max swap space:\s+(.*)\nfree swap space:\s+(.*)\n/", $bufr, $ar_buf)) {
if ($ar_buf[1]>0) {
$dev = new DiskDevice();
$dev->setMountPoint("/boot/common/var/swap");
$dev->setName("SWAP");
$dev->setTotal($ar_buf[1]);
$dev->setFree($ar_buf[2]);
$dev->setUSed($ar_buf[1]-$ar_buf[2]);
$this->sys->setSwapDevices($dev);
}
}
}
}
/**
* filesystem information
*
* @return void
*/
private function _filesystems()
{
if (CommonFunctions::executeProgram('df', '-b', $df, PSI_DEBUG)) {
$df = preg_split("/\n/", $df, -1, PREG_SPLIT_NO_EMPTY);
foreach ($df as $df_line) {
$ar_buf = preg_split("/\s+/", $df_line);
if ((substr($df_line, 0, 1) == "/") && (count($ar_buf) == 6)) {
$dev = new DiskDevice();
$dev->setMountPoint($ar_buf[0]);
$dev->setName($ar_buf[5]);
$dev->setFsType($ar_buf[1]);
$dev->setOptions($ar_buf[4]);
$dev->setTotal($ar_buf[2] * 1024);
$dev->setFree($ar_buf[3] * 1024);
$dev->setUsed($dev->getTotal() - $dev->getFree());
$this->sys->setDiskDevices($dev);
}
}
}
}
/**
* network information
*
* @return void
*/
private function _network()
{
if (CommonFunctions::executeProgram('ifconfig', '', $bufr, PSI_DEBUG)) {
$lines = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
$notwas = true;
foreach ($lines as $line) {
if (preg_match("/^(\S+)/", $line, $ar_buf)) {
if (!$notwas) {
$dev->setErrors($errors);
$dev->setDrops($drops);
$this->sys->setNetDevices($dev);
}
$errors = 0;
$drops = 0;
$dev = new NetDevice();
$dev->setName($ar_buf[1]);
$notwas = false;
} else {
if (!$notwas) {
if (preg_match('/\sReceive:\s\d+\spackets,\s(\d+)\serrors,\s(\d+)\sbytes,\s\d+\smcasts,\s(\d+)\sdropped/i', $line, $ar_buf2)) {
$errors +=$ar_buf2[1];
$drops +=$ar_buf2[3];
$dev->setRxBytes($ar_buf2[2]);
} elseif (preg_match('/\sTransmit:\s\d+\spackets,\s(\d+)\serrors,\s(\d+)\sbytes,\s\d+\smcasts,\s(\d+)\sdropped/i', $line, $ar_buf2)) {
$errors +=$ar_buf2[1];
$drops +=$ar_buf2[3];
$dev->setTxBytes($ar_buf2[2]);
}
if (defined('PSI_SHOW_NETWORK_INFOS') && (PSI_SHOW_NETWORK_INFOS)) {
if (preg_match('/\sEthernet,\s+Address:\s(\S*)/i', $line, $ar_buf2))
$dev->setInfo(preg_replace('/:/', '-', $ar_buf2[1]));
elseif (preg_match('/^\s+inet\saddr:\s(\S*),/i', $line, $ar_buf2))
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$ar_buf2[1]);
elseif (preg_match('/^\s+inet6\saddr:\s(\S*),/i', $line, $ar_buf2))
if (!preg_match('/^fe80::/i', $ar_buf2[1]))
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$ar_buf2[1]);
}
}
}
}
if (!$notwas) {
$dev->setErrors($errors);
$dev->setDrops($drops);
$this->sys->setNetDevices($dev);
}
}
}
/**
* Processes
*
* @return void
*/
protected function _processes()
{
if (CommonFunctions::executeProgram('ps', '', $bufr, PSI_DEBUG)) {
$lines = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
$processes['*'] = 0;
foreach ($lines as $line) {
if (preg_match("/^(kernel_team|\/)/", $line, $ar_buf)) {
$processes['*']++;
}
}
if ($processes['*'] > 0) {
$processes[' '] = $processes['*'];
$this->sys->setProcesses($processes);
}
}
}
/**
* get the information
*
* @return Void
*/
public function build()
{
$this->error->addError("WARN", "The Haiku version of phpSysInfo is a work in progress, some things currently don't work");
$this->_distro();
$this->_hostname();
$this->_ip();
$this->_kernel();
$this->_uptime();
$this->_users();
$this->_loadavg();
$this->_pci();
$this->_usb();
$this->_cpuinfo();
$this->_memory();
$this->_filesystems();
$this->_network();
$this->_processes();
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,382 @@
<?php
/**
* Minix System Class
*
* PHP version 5
*
* @category PHP
* @package PSI Minix OS class
* @author Mieczyslaw Nalewaj <namiltd@users.sourceforge.net>
* @copyright 2012 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @version SVN: $Id: class.Minix.inc.php 687 2012-09-06 20:54:49Z namiltd $
* @link http://phpsysinfo.sourceforge.net
*/
/**
* Minix sysinfo class
* get all the required information from Minix system
*
* @category PHP
* @package PSI Minix OS class
* @author Mieczyslaw Nalewaj <namiltd@users.sourceforge.net>
* @copyright 2012 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @version Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
class Minix extends OS
{
/**
* content of the syslog
*
* @var array
*/
private $_dmesg = array();
/**
* call parent constructor
*/
public function __construct()
{
parent::__construct();
}
/**
* read /var/log/messages, but only if we haven't already
*
* @return array
*/
protected function readdmesg()
{
if (count($this->_dmesg) === 0) {
if (CommonFunctions::rfts('/var/log/messages', $buf)) {
$parts = preg_split("/kernel: APIC/", $buf, -1, PREG_SPLIT_NO_EMPTY);
// $parts = preg_split("/ syslogd: restart\n/", $buf, -1, PREG_SPLIT_NO_EMPTY);
$this->_dmesg = preg_split("/\n/", $parts[count($parts) - 1], -1, PREG_SPLIT_NO_EMPTY);
}
}
return $this->_dmesg;
}
/**
* get the cpu information
*
* @return array
*/
protected function _cpuinfo()
{
if (CommonFunctions::rfts('/proc/cpuinfo', $bufr, 0, 4096, false)) {
$processors = preg_split('/\s?\n\s?\n/', trim($bufr));
foreach ($processors as $processor) {
$_n = ""; $_f = ""; $_m = ""; $_s = "";
$dev = new CpuDevice();
$details = preg_split("/\n/", $processor, -1, PREG_SPLIT_NO_EMPTY);
foreach ($details as $detail) {
$arrBuff = preg_split('/\s+:\s+/', trim($detail));
if (count($arrBuff) == 2) {
switch (strtolower($arrBuff[0])) {
case 'model name':
$_n = $arrBuff[1];
break;
case 'cpu mhz':
$dev->setCpuSpeed($arrBuff[1]);
break;
case 'cpu family':
$_f = $arrBuff[1];
break;
case 'model':
$_m = $arrBuff[1];
break;
case 'stepping':
$_s = $arrBuff[1];
break;
case 'flags':
if (preg_match("/ vmx/", $arrBuff[1])) {
$dev->setVirt("vmx");
} elseif (preg_match("/ svm/", $arrBuff[1])) {
$dev->setVirt("svm");
}
break;
}
}
}
if ($_n == "") $_n="CPU";
if ($_f != "") $_n.=" Family ".$_f;
if ($_m != "") $_n.=" Model ".$_m;
if ($_s != "") $_n.=" Stepping ".$_s;
$dev->SetModel($_n);
$this->sys->setCpus($dev);
}
} else
foreach ($this->readdmesg() as $line) {
if (preg_match('/kernel: (CPU .*) freq (.*) MHz/', $line, $ar_buf)) {
$dev = new CpuDevice();
$dev->setModel($ar_buf[1]);
$dev->setCpuSpeed($ar_buf[2]);
$this->sys->setCpus($dev);
}
}
}
/**
* PCI devices
* get the pci device information out of dmesg
*
* @return void
*/
protected function _pci()
{
if (CommonFunctions::rfts('/proc/pci', $strBuf, 0, 4096, false)) {
$arrLines = preg_split("/\n/", $strBuf, -1, PREG_SPLIT_NO_EMPTY);
foreach ($arrLines as $strLine) {
$arrParams = preg_split('/\s+/', trim($strLine), 4);
if (count($arrParams) == 4)
$strName = $arrParams[3];
else
$strName = "unknown";
$strName = preg_replace('/\(.*\)/', '', $strName);
$dev = new HWDevice();
$dev->setName($strName);
$arrResults[] = $dev;
}
foreach ($arrResults as $dev) {
$this->sys->setPciDevices($dev);
}
}
if (!(isset($arrResults) && is_array($arrResults)) && is_array($results = Parser::lspci())) {
/* if access error: chmod 4755 /usr/bin/lspci */
foreach ($results as $dev) {
$this->sys->setPciDevices($dev);
}
}
}
/**
* Minix Version
*
* @return void
*/
private function _kernel()
{
foreach ($this->readdmesg() as $line) {
if (preg_match('/kernel: MINIX (.*) \((.*)\)/', $line, $ar_buf)) {
$branch = $ar_buf[2];
}
}
if (CommonFunctions::executeProgram('uname', '-rvm', $ret)) {
if (isset($branch))
$this->sys->setKernel($ret.' ('.$branch.')');
else
$this->sys->setKernel($ret);
}
}
/**
* Distribution
*
* @return void
*/
protected function _distro()
{
if (CommonFunctions::executeProgram('uname', '-sr', $ret))
$this->sys->setDistribution($ret);
else
$this->sys->setDistribution('Minix');
$this->sys->setDistributionIcon('Minix.png');
}
/**
* UpTime
* time the system is running
*
* @return void
*/
private function _uptime()
{
if (CommonFunctions::executeProgram('uptime', '', $buf)) {
if (preg_match("/up (\d+) days,\s*(\d+):(\d+),/", $buf, $ar_buf)) {
$min = $ar_buf[3];
$hours = $ar_buf[2];
$days = $ar_buf[1];
$this->sys->setUptime($days * 86400 + $hours * 3600 + $min * 60);
} elseif (preg_match("/up (\d+):(\d+),/", $buf, $ar_buf)) {
$min = $ar_buf[2];
$hours = $ar_buf[1];
$this->sys->setUptime($hours * 3600 + $min * 60);
}
}
}
/**
* Processor Load
* optionally create a loadbar
*
* @return void
*/
private function _loadavg()
{
if (CommonFunctions::executeProgram('uptime', '', $buf)) {
if (preg_match("/load averages: (.*), (.*), (.*)$/", $buf, $ar_buf)) {
$this->sys->setLoad($ar_buf[1].' '.$ar_buf[2].' '.$ar_buf[3]);
}
}
}
/**
* Number of Users
*
* @return void
*/
private function _users()
{
if (CommonFunctions::executeProgram('uptime', '', $buf)) {
if (preg_match("/, (.*) users, load averages: (.*), (.*), (.*)$/", $buf, $ar_buf)) {
$this->sys->setUsers($ar_buf[1]);
}
}
}
/**
* Virtual Host Name
*
* @return void
*/
private function _hostname()
{
if (PSI_USE_VHOST === true) {
$this->sys->setHostname(getenv('SERVER_NAME'));
} else {
if (CommonFunctions::executeProgram('uname', '-n', $result, PSI_DEBUG)) {
$ip = gethostbyname($result);
if ($ip != $result) {
$this->sys->setHostname(gethostbyaddr($ip));
}
}
}
}
/**
* IP of the Virtual Host Name
*
* @return void
*/
private function _ip()
{
if (PSI_USE_VHOST === true) {
$this->sys->setIp(gethostbyname($this->sys->getHostname()));
} else {
if (!($result = getenv('SERVER_ADDR'))) {
$this->sys->setIp(gethostbyname($this->sys->getHostname()));
} else {
$this->sys->setIp($result);
}
}
}
/**
* Physical memory information and Swap Space information
*
* @return void
*/
private function _memory()
{
if (CommonFunctions::rfts('/proc/meminfo', $bufr, 1, 4096, false)) {
$ar_buf = preg_split('/\s+/', trim($bufr));
if (count($ar_buf) >= 5) {
$this->sys->setMemTotal($ar_buf[0]*$ar_buf[1]);
$this->sys->setMemFree($ar_buf[0]*$ar_buf[2]);
$this->sys->setMemCache($ar_buf[0]*$ar_buf[4]);
$this->sys->setMemUsed($ar_buf[0]*($ar_buf[1]-$ar_buf[2]));
}
}
}
/**
* filesystem information
*
* @return void
*/
private function _filesystems()
{
$arrResult = Parser::df("-P 2>/dev/null");
foreach ($arrResult as $dev) {
$this->sys->setDiskDevices($dev);
}
}
/**
* network information
*
* @return void
*/
private function _network()
{
if (CommonFunctions::executeProgram('ifconfig', '-a', $bufr, PSI_DEBUG)) {
$lines = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
foreach ($lines as $line) {
if (preg_match("/^([^\s:]+):\saddress\s(\S+)\snetmask/", $line, $ar_buf)) {
$dev = new NetDevice();
$dev->setName($ar_buf[1]);
if (defined('PSI_SHOW_NETWORK_INFOS') && (PSI_SHOW_NETWORK_INFOS)) {
$dev->setInfo($ar_buf[2]);
}
$this->sys->setNetDevices($dev);
}
}
}
}
/**
* Processes
*
* @return void
*/
protected function _processes()
{
if (CommonFunctions::executeProgram('ps', 'alx', $bufr, PSI_DEBUG)) {
$lines = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
$processes['*'] = 0;
foreach ($lines as $line) {
if (preg_match("/^\s(\w)\s/", $line, $ar_buf)) {
$processes['*']++;
$state = $ar_buf[1];
if ($state == 'W') $state = 'D'; //linux format
elseif ($state == 'D') $state = 'd'; //invalid
if (isset($processes[$state])) {
$processes[$state]++;
} else {
$processes[$state] = 1;
}
}
}
if ($processes['*'] > 0) {
$this->sys->setProcesses($processes);
}
}
}
/**
* get the information
*
* @return Void
*/
public function build()
{
$this->error->addError("WARN", "The Minix version of phpSysInfo is a work in progress, some things currently don't work");
$this->_distro();
$this->_hostname();
$this->_ip();
$this->_kernel();
$this->_uptime();
$this->_users();
$this->_loadavg();
$this->_pci();
$this->_cpuinfo();
$this->_memory();
$this->_filesystems();
$this->_network();
$this->_processes();
}
}

View File

@@ -0,0 +1,159 @@
<?php
/**
* NetBSD System Class
*
* PHP version 5
*
* @category PHP
* @package PSI NetBSD OS class
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @version SVN: $Id: class.NetBSD.inc.php 287 2009-06-26 12:11:59Z bigmichi1 $
* @link http://phpsysinfo.sourceforge.net
*/
/**
* NetBSD sysinfo class
* get all the required information from NetBSD systems
*
* @category PHP
* @package PSI NetBSD OS class
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @version Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
class NetBSD extends BSDCommon
{
/**
* define the regexp for log parser
*/
public function __construct()
{
parent::__construct();
$this->setCPURegExp1("^cpu(.*)\, (.*) MHz");
$this->setCPURegExp2("/user = (.*), nice = (.*), sys = (.*), intr = (.*), idle = (.*)/");
$this->setSCSIRegExp1("^(.*) at scsibus.*: <(.*)> .*");
$this->setSCSIRegExp2("^(da[0-9]): (.*)MB ");
$this->setPCIRegExp1("/(.*) at pci[0-9] dev [0-9]* function [0-9]*: (.*)$/");
$this->setPCIRegExp2("/\"(.*)\" (.*).* at [.0-9]+ irq/");
}
/**
* UpTime
* time the system is running
*
* @return void
*/
private function _uptime()
{
$a = $this->grabkey('kern.boottime');
$this->sys->setUptime(time() - $a);
}
/**
* get network information
*
* @return void
*/
private function _network()
{
CommonFunctions::executeProgram('netstat', '-nbdi | cut -c1-25,44- | grep "^[a-z]*[0-9][ \t].*Link"', $netstat_b);
CommonFunctions::executeProgram('netstat', '-ndi | cut -c1-25,44- | grep "^[a-z]*[0-9][ \t].*Link"', $netstat_n);
$lines_b = preg_split("/\n/", $netstat_b, -1, PREG_SPLIT_NO_EMPTY);
$lines_n = preg_split("/\n/", $netstat_n, -1, PREG_SPLIT_NO_EMPTY);
for ($i = 0, $max = sizeof($lines_b); $i < $max; $i++) {
$ar_buf_b = preg_split("/\s+/", $lines_b[$i]);
$ar_buf_n = preg_split("/\s+/", $lines_n[$i]);
if (! empty($ar_buf_b[0]) && ! empty($ar_buf_n[3])) {
$dev = new NetDevice();
$dev->setName($ar_buf_b[0]);
$dev->setTxBytes($ar_buf_b[4]);
$dev->setRxBytes($ar_buf_b[3]);
$dev->setDrops($ar_buf_n[8]);
$dev->setErrors($ar_buf_n[4] + $ar_buf_n[6]);
$this->sys->setNetDevices($dev);
}
}
}
/**
* IDE information
*
* @return void
*/
protected function ide()
{
foreach ($this->readdmesg() as $line) {
if (preg_match('/^(.*) at (pciide|wdc|atabus|atapibus)[0-9] (.*): <(.*)>/', $line, $ar_buf)) {
$dev = new HWDevice();
$dev->setName($ar_buf[1]);
// now loop again and find the capacity
foreach ($this->readdmesg() as $line2) {
if (preg_match("/^(".$ar_buf[1]."): (.*), (.*), (.*)MB, .*$/", $line2, $ar_buf_n)) {
$dev->setCapacity($ar_buf_n[4] * 2048 * 1.049);
} elseif (preg_match("/^(".$ar_buf[1]."): (.*) MB, (.*), (.*), .*$/", $line2, $ar_buf_n)) {
$dev->setCapacity($ar_buf_n[2] * 2048);
}
}
$this->sys->setIdeDevices($dev);
}
}
}
/**
* get icon name
*
* @return void
*/
private function _distroicon()
{
$this->sys->setDistributionIcon('NetBSD.png');
}
/**
* Processes
*
* @return void
*/
protected function _processes()
{
if (CommonFunctions::executeProgram('ps', 'aux', $bufr, PSI_DEBUG)) {
$lines = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
$processes['*'] = 0;
foreach ($lines as $line) {
if (preg_match("/^\S+\s+\d+\s+\S+\s+\S+\s+\d+\s+\d+\s+\S+\s+(\w)/", $line, $ar_buf)) {
$processes['*']++;
$state = $ar_buf[1];
if ($state == 'O') $state = 'R'; //linux format
elseif ($state == 'I') $state = 'S';
if (isset($processes[$state])) {
$processes[$state]++;
} else {
$processes[$state] = 1;
}
}
}
if ($processes['*'] > 0) {
$this->sys->setProcesses($processes);
}
}
}
/**
* get the information
*
* @see BSDCommon::build()
*
* @return Void
*/
public function build()
{
parent::build();
$this->_distroicon();
$this->_network();
$this->_uptime();
$this->_processes();
}
}

View File

@@ -0,0 +1,85 @@
<?php
/**
* Basic OS Class
*
* PHP version 5
*
* @category PHP
* @package PSI OS class
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @version SVN: $Id: class.OS.inc.php 699 2012-09-15 11:57:13Z namiltd $
* @link http://phpsysinfo.sourceforge.net
*/
/**
* Basic OS functions for all OS classes
*
* @category PHP
* @package PSI OS class
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @version Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
abstract class OS implements PSI_Interface_OS
{
/**
* object for error handling
*
* @var Error
*/
protected $error;
/**
* @var System
*/
protected $sys;
/**
* build the global Error object
*/
public function __construct()
{
$this->error = Error::singleton();
$this->sys = new System();
}
/**
* get os specific encoding
*
* @see PSI_Interface_OS::getEncoding()
*
* @return string
*/
public function getEncoding()
{
return PSI_SYSTEM_CODEPAGE;
}
/**
* get os specific language
*
* @see PSI_Interface_OS::getLanguage()
*
* @return string
*/
public function getLanguage()
{
return PSI_SYSTEM_LANG;
}
/**
* get the filled or unfilled (with default values) System object
*
* @see PSI_Interface_OS::getSys()
*
* @return System
*/
final public function getSys()
{
$this->build();
return $this->sys;
}
}

View File

@@ -0,0 +1,174 @@
<?php
/**
* OpenBSD System Class
*
* PHP version 5
*
* @category PHP
* @package PSI OpenBSD OS class
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @version SVN: $Id: class.OpenBSD.inc.php 621 2012-07-29 18:49:04Z namiltd $
* @link http://phpsysinfo.sourceforge.net
*/
/**
* OpenBSD sysinfo class
* get all the required information from OpenBSD systems
*
* @category PHP
* @package PSI OpenBSD OS class
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @version Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
class OpenBSD extends BSDCommon
{
/**
* define the regexp for log parser
*/
public function __construct()
{
parent::__construct();
$this->setCPURegExp1("^cpu(.*) (.*) MHz");
$this->setCPURegExp2("/(.*),(.*),(.*),(.*),(.*)/");
$this->setSCSIRegExp1("^(.*) at scsibus.*: <(.*)> .*");
$this->setSCSIRegExp2("^(da[0-9]): (.*)MB ");
$this->setPCIRegExp1("/(.*) at pci[0-9] .* \"(.*)\"/");
$this->setPCIRegExp2("/\"(.*)\" (.*).* at [.0-9]+ irq/");
}
/**
* UpTime
* time the system is running
*
* @return void
*/
private function _uptime()
{
$a = $this->grabkey('kern.boottime');
$this->sys->setUptime(time() - $a);
}
/**
* get network information
*
* @return void
*/
private function _network()
{
CommonFunctions::executeProgram('netstat', '-nbdi | cut -c1-25,44- | grep Link | grep -v \'* \'', $netstat_b, PSI_DEBUG);
CommonFunctions::executeProgram('netstat', '-ndi | cut -c1-25,44- | grep Link | grep -v \'* \'', $netstat_n, PSI_DEBUG);
$lines_b = preg_split("/\n/", $netstat_b, -1, PREG_SPLIT_NO_EMPTY);
$lines_n = preg_split("/\n/", $netstat_n, -1, PREG_SPLIT_NO_EMPTY);
for ($i = 0, $max = sizeof($lines_b); $i < $max; $i++) {
$ar_buf_b = preg_split("/\s+/", $lines_b[$i]);
$ar_buf_n = preg_split("/\s+/", $lines_n[$i]);
if (! empty($ar_buf_b[0]) && ! empty($ar_buf_n[3])) {
$dev = new NetDevice();
$dev->setName($ar_buf_b[0]);
$dev->setTxBytes($ar_buf_b[4]);
$dev->setRxBytes($ar_buf_b[3]);
$dev->setErrors($ar_buf_n[4] + $ar_buf_n[6]);
$dev->setDrops($ar_buf_n[8]);
$this->sys->setNetDevices($dev);
}
}
}
/**
* IDE information
*
* @return void
*/
protected function ide()
{
foreach ($this->readdmesg() as $line) {
if (preg_match('/^(.*) at pciide[0-9] (.*): <(.*)>/', $line, $ar_buf)) {
$dev = new HWDevice();
$dev->setName($ar_buf[0]);
// now loop again and find the capacity
foreach ($this->readdmesg() as $line2) {
if (preg_match("/^(".$ar_buf[0]."): (.*), (.*), (.*)MB, .*$/", $line2, $ar_buf_n)) {
$dev->setCapacity($ar_buf_n[4] * 2048 * 1.049);
}
}
$this->sys->setIdeDevices($dev);
}
}
}
/**
* get CPU information
*
* @return void
*/
protected function cpuinfo()
{
$dev = new CpuDevice();
$dev->setModel($this->grabkey('hw.model'));
$dev->setCpuSpeed($this->grabkey('hw.cpuspeed'));
$ncpu = $this->grabkey('hw.ncpu');
if (is_null($ncpu) || (trim($ncpu) == "") || (!($ncpu >= 1)))
$ncpu = 1;
for ($ncpu ; $ncpu > 0 ; $ncpu--) {
$this->sys->setCpus($dev);
}
}
/**
* get icon name
*
* @return void
*/
private function _distroicon()
{
$this->sys->setDistributionIcon('OpenBSD.png');
}
/**
* Processes
*
* @return void
*/
protected function _processes()
{
if (CommonFunctions::executeProgram('ps', 'aux', $bufr, PSI_DEBUG)) {
$lines = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
$processes['*'] = 0;
foreach ($lines as $line) {
if (preg_match("/^\S+\s+\d+\s+\S+\s+\S+\s+\d+\s+\d+\s+\S+\s+(\w)/", $line, $ar_buf)) {
$processes['*']++;
$state = $ar_buf[1];
if ($state == 'I') $state = 'S'; //linux format
if (isset($processes[$state])) {
$processes[$state]++;
} else {
$processes[$state] = 1;
}
}
}
if ($processes['*'] > 0) {
$this->sys->setProcesses($processes);
}
}
}
/**
* get the information
*
* @see BSDCommon::build()
*
* @return Void
*/
public function build()
{
parent::build();
$this->_distroicon();
$this->_network();
$this->_uptime();
$this->_processes();
}
}

View File

@@ -0,0 +1,256 @@
<?php
/**
* QNX System Class
*
* PHP version 5
*
* @category PHP
* @package PSI QNX OS class
* @author Mieczyslaw Nalewaj <namiltd@users.sourceforge.net>
* @copyright 2012 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @version SVN: $Id: class.QNX.inc.php 687 2012-09-06 20:54:49Z namiltd $
* @link http://phpsysinfo.sourceforge.net
*/
/**
* QNX sysinfo class
* get all the required information from QNX system
*
* @category PHP
* @package PSI QNX OS class
* @author Mieczyslaw Nalewaj <namiltd@users.sourceforge.net>
* @copyright 2012 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @version Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
class QNX extends OS
{
/**
* content of the syslog
*
* @var array
*/
private $_dmesg = array();
/**
* call parent constructor
*/
public function __construct()
{
parent::__construct();
}
/**
* get the cpu information
*
* @return array
*/
protected function _cpuinfo()
{
if (CommonFunctions::executeProgram('pidin', 'info', $buf)
&& preg_match('/^Processor\d+: (.*)/m', $buf)) {
$lines = preg_split("/\n/", $buf, -1, PREG_SPLIT_NO_EMPTY);
foreach ($lines as $line) {
if (preg_match('/^Processor\d+: (.+)/', $line, $proc)) {
$dev = new CpuDevice();
$dev->SetModel(trim($proc[1]));
if (preg_match('/(\d+)MHz/', $proc[1], $mhz)) {
$dev->setCpuSpeed($mhz[1]);
}
$this->sys->setCpus($dev);
}
}
}
}
/**
* QNX Version
*
* @return void
*/
private function _kernel()
{
if (CommonFunctions::executeProgram('uname', '-rvm', $ret)) {
$this->sys->setKernel($ret);
}
}
/**
* Distribution
*
* @return void
*/
protected function _distro()
{
if (CommonFunctions::executeProgram('uname', '-sr', $ret))
$this->sys->setDistribution($ret);
else
$this->sys->setDistribution('QNX');
$this->sys->setDistributionIcon('QNX.png');
}
/**
* UpTime
* time the system is running
*
* @return void
*/
private function _uptime()
{
if (CommonFunctions::executeProgram('pidin', 'info', $buf)
&& preg_match('/^.* BootTime:(.*)/', $buf, $bstart)
&& CommonFunctions::executeProgram('date', '', $bstop)) {
/* default error handler */
if (function_exists('errorHandlerPsi')) {
restore_error_handler();
}
/* fatal errors only */
$old_err_rep = error_reporting();
error_reporting(E_ERROR);
$uptime = strtotime($bstop)-strtotime($bstart[1]);
if ($uptime > 0) $this->sys->setUptime($uptime);
/* restore error level */
error_reporting($old_err_rep);
/* restore error handler */
if (function_exists('errorHandlerPsi')) {
set_error_handler('errorHandlerPsi');
}
}
}
/**
* Number of Users
*
* @return void
*/
private function _users()
{
$this->sys->setUsers(1);
}
/**
* Virtual Host Name
*
* @return void
*/
private function _hostname()
{
if (PSI_USE_VHOST === true) {
$this->sys->setHostname(getenv('SERVER_NAME'));
} else {
if (CommonFunctions::executeProgram('uname', '-n', $result, PSI_DEBUG)) {
$ip = gethostbyname($result);
if ($ip != $result) {
$this->sys->setHostname(gethostbyaddr($ip));
}
}
}
}
/**
* IP of the Virtual Host Name
*
* @return void
*/
private function _ip()
{
if (PSI_USE_VHOST === true) {
$this->sys->setIp(gethostbyname($this->sys->getHostname()));
} else {
if (!($result = getenv('SERVER_ADDR'))) {
$this->sys->setIp(gethostbyname($this->sys->getHostname()));
} else {
$this->sys->setIp($result);
}
}
}
/**
* Physical memory information and Swap Space information
*
* @return void
*/
private function _memory()
{
if (CommonFunctions::executeProgram('pidin', 'info', $buf)
&& preg_match('/^.* FreeMem:(\S+)Mb\/(\S+)Mb/', $buf, $memm)) {
$this->sys->setMemTotal(1024*1024*$memm[2]);
$this->sys->setMemFree(1024*1024*$memm[1]);
$this->sys->setMemUsed(1024*1024*($memm[2]-$memm[1]));
}
}
/**
* filesystem information
*
* @return void
*/
private function _filesystems()
{
$arrResult = Parser::df("-P 2>/dev/null");
foreach ($arrResult as $dev) {
$this->sys->setDiskDevices($dev);
}
}
/**
* network information
*
* @return void
*/
private function _network()
{
if (CommonFunctions::executeProgram('ifconfig', '', $bufr, PSI_DEBUG)) {
$lines = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
$notwas = true;
foreach ($lines as $line) {
if (preg_match("/^([^\s:]+)/", $line, $ar_buf)) {
if (!$notwas) {
$this->sys->setNetDevices($dev);
}
$dev = new NetDevice();
$dev->setName($ar_buf[1]);
$notwas = false;
} else {
if (!$notwas) {
if (defined('PSI_SHOW_NETWORK_INFOS') && (PSI_SHOW_NETWORK_INFOS)) {
if (preg_match('/^\s+address:\s*(\S+)/i', $line, $ar_buf2)) {
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$ar_buf2[1]);
} elseif (preg_match('/^\s+inet\s+(\S+)\s+netmask/i', $line, $ar_buf2))
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$ar_buf2[1]);
}
}
}
}
if (!$notwas) {
$this->sys->setNetDevices($dev);
}
}
}
/**
* get the information
*
* @return Void
*/
public function build()
{
$this->error->addError("WARN", "The QNX version of phpSysInfo is a work in progress, some things currently don't work");
$this->_distro();
$this->_hostname();
$this->_ip();
$this->_kernel();
$this->_uptime();
$this->_users();
$this->_cpuinfo();
$this->_memory();
$this->_filesystems();
$this->_network();
}
}

View File

@@ -0,0 +1,349 @@
<?php
/**
* SunOS System Class
*
* PHP version 5
*
* @category PHP
* @package PSI SunOS OS class
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @version SVN: $Id: class.SunOS.inc.php 687 2012-09-06 20:54:49Z namiltd $
* @link http://phpsysinfo.sourceforge.net
*/
/**
* SunOS sysinfo class
* get all the required information from SunOS systems
*
* @category PHP
* @package PSI SunOS OS class
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @version Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
class SunOS extends OS
{
/**
* Extract kernel values via kstat() interface
*
* @param string $key key for kstat programm
*
* @return string
*/
private function _kstat($key)
{
if (CommonFunctions::executeProgram('kstat', '-p d '.$key, $m, PSI_DEBUG) &&
!is_null($m) && (trim($m)!=="")) {
list($key, $value) = preg_split("/\t/", trim($m), 2);
return $value;
} else {
return '';
}
}
/**
* Virtual Host Name
*
* @return void
*/
private function _hostname()
{
if (PSI_USE_VHOST === true) {
$this->sys->setHostname(getenv('SERVER_NAME'));
} else {
if (CommonFunctions::executeProgram('uname', '-n', $result, PSI_DEBUG)) {
$ip = gethostbyname($result);
if ($ip != $result) {
$this->sys->setHostname(gethostbyaddr($ip));
}
}
}
}
/**
* IP of the Virtual Host Name
*
* @return void
*/
private function _ip()
{
if (PSI_USE_VHOST === true) {
$this->sys->setIp(gethostbyname($this->sys->getHostname()));
} else {
if (!($result = getenv('SERVER_ADDR'))) {
$this->sys->setIp(gethostbyname($this->sys->getHostname()));
} else {
$this->sys->setIp($result);
}
}
}
/**
* Kernel Version
*
* @return void
*/
private function _kernel()
{
if (CommonFunctions::executeProgram('uname', '-s', $os, PSI_DEBUG)) {
if (CommonFunctions::executeProgram('uname', '-r', $version, PSI_DEBUG)) {
$this->sys->setKernel($os.' '.$version);
} else {
$this->sys->setKernel($os);
}
}
}
/**
* UpTime
* time the system is running
*
* @return void
*/
private function _uptime()
{
$this->sys->setUptime(time() - $this->_kstat('unix:0:system_misc:boot_time'));
}
/**
* Number of Users
*
* @return void
*/
private function _users()
{
if (CommonFunctions::executeProgram('who', '-q', $buf, PSI_DEBUG)) {
$who = preg_split('/=/', $buf);
$this->sys->setUsers($who[1]);
}
}
/**
* Processor Load
* optionally create a loadbar
*
* @return void
*/
private function _loadavg()
{
$load1 = $this->_kstat('unix:0:system_misc:avenrun_1min');
$load5 = $this->_kstat('unix:0:system_misc:avenrun_5min');
$load15 = $this->_kstat('unix:0:system_misc:avenrun_15min');
$this->sys->setLoad(round($load1 / 256, 2).' '.round($load5 / 256, 2).' '.round($load15 / 256, 2));
}
/**
* CPU information
*
* @return void
*/
private function _cpuinfo()
{
$dev = new CpuDevice();
if (CommonFunctions::executeProgram('uname', '-i', $buf, PSI_DEBUG)) {
$dev->setModel(trim($buf));
}
$dev->setCpuSpeed($this->_kstat('cpu_info:0:cpu_info0:clock_MHz'));
$dev->setCache($this->_kstat('cpu_info:0:cpu_info0:cpu_type') * 1024);
$this->sys->setCpus($dev);
}
/**
* Network devices
*
* @return void
*/
private function _network()
{
if (CommonFunctions::executeProgram('netstat', '-ni | awk \'(NF ==10){print;}\'', $netstat, PSI_DEBUG)) {
$lines = preg_split("/\n/", $netstat, -1, PREG_SPLIT_NO_EMPTY);
foreach ($lines as $line) {
$ar_buf = preg_split("/\s+/", $line);
if (!empty($ar_buf[0]) && $ar_buf[0] !== 'Name') {
$dev = new NetDevice();
$dev->setName($ar_buf[0]);
$results[$ar_buf[0]]['errs'] = $ar_buf[5] + $ar_buf[7];
if (preg_match('/^(\D+)(\d+)$/', $ar_buf[0], $intf)) {
$prefix = $intf[1].':'.$intf[2].':'.$intf[1].$intf[2].':';
} elseif (preg_match('/^(\D.*)(\d+)$/', $ar_buf[0], $intf)) {
$prefix = $intf[1].':'.$intf[2].':mac:';
} else {
$prefix = "";
}
if ($prefix !== "") {
$cnt = $this->_kstat($prefix.'drop');
if ($cnt > 0) {
$dev->setDrops($cnt);
}
$cnt = $this->_kstat($prefix.'obytes64');
if ($cnt > 0) {
$dev->setTxBytes($cnt);
}
$cnt = $this->_kstat($prefix.'rbytes64');
if ($cnt > 0) {
$dev->setRxBytes($cnt);
}
}
if (defined('PSI_SHOW_NETWORK_INFOS') && (PSI_SHOW_NETWORK_INFOS)) {
if (CommonFunctions::executeProgram('ifconfig', $ar_buf[0], $bufr2, PSI_DEBUG)
&& !is_null($bufr2) && (trim($bufr2) !== "")) {
$bufe2 = preg_split("/\n/", $bufr2, -1, PREG_SPLIT_NO_EMPTY);
foreach ($bufe2 as $buf2) {
if (preg_match('/^\s+ether\s+(\S+)/i', $buf2, $ar_buf2))
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').preg_replace('/:/', '-', $ar_buf2[1]));
elseif (preg_match('/^\s+inet\s+(\S+)\s+netmask/i', $buf2, $ar_buf2))
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$ar_buf2[1]);
}
}
if (CommonFunctions::executeProgram('ifconfig', $ar_buf[0].' inet6', $bufr2, PSI_DEBUG)
&& !is_null($bufr2) && (trim($bufr2) !== "")) {
$bufe2 = preg_split("/\n/", $bufr2, -1, PREG_SPLIT_NO_EMPTY);
foreach ($bufe2 as $buf2) {
if (preg_match('/^\s+inet6\s+([^\s\/]+)/i', $buf2, $ar_buf2)
&& !preg_match('/^fe80::/i', $ar_buf2[1]))
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$ar_buf2[1]);
}
}
}
$this->sys->setNetDevices($dev);
}
}
}
}
/**
* Physical memory information and Swap Space information
*
* @return void
*/
private function _memory()
{
$pagesize = $this->_kstat('unix:0:seg_cache:slab_size');
$this->sys->setMemTotal($this->_kstat('unix:0:system_pages:pagestotal') * $pagesize);
$this->sys->setMemUsed($this->_kstat('unix:0:system_pages:pageslocked') * $pagesize);
$this->sys->setMemFree($this->_kstat('unix:0:system_pages:pagesfree') * $pagesize);
$dev = new DiskDevice();
$dev->setName('SWAP');
$dev->setFsType('swap');
$dev->setMountPoint('SWAP');
$dev->setTotal($this->_kstat('unix:0:vminfo:swap_avail') / 1024);
$dev->setUsed($this->_kstat('unix:0:vminfo:swap_alloc') / 1024);
$dev->setFree($this->_kstat('unix:0:vminfo:swap_free') / 1024);
$this->sys->setSwapDevices($dev);
}
/**
* filesystem information
*
* @return void
*/
private function _filesystems()
{
if (CommonFunctions::executeProgram('df', '-k', $df, PSI_DEBUG)) {
$df = preg_replace('/\n\s/m', ' ', $df);
$mounts = preg_split("/\n/", $df, -1, PREG_SPLIT_NO_EMPTY);
foreach ($mounts as $mount) {
$ar_buf = preg_split('/\s+/', $mount, 6);
if (!empty($ar_buf[0]) && $ar_buf[0] !== 'Filesystem') {
$dev = new DiskDevice();
$dev->setName($ar_buf[0]);
$dev->setTotal($ar_buf[1] * 1024);
$dev->setUsed($ar_buf[2] * 1024);
$dev->setFree($ar_buf[3] * 1024);
$dev->setMountPoint($ar_buf[5]);
if (CommonFunctions::executeProgram('df', '-n', $dftypes, PSI_DEBUG)) {
$mounttypes = preg_split("/\n/", $dftypes, -1, PREG_SPLIT_NO_EMPTY);
foreach ($mounttypes as $type) {
$ty_buf = preg_split('/:/', $type, 2);
if (trim($ty_buf[0]) == $dev->getMountPoint()) {
$dev->setFsType($ty_buf[1]);
break;
}
}
} elseif (CommonFunctions::executeProgram('df', '-T', $dftypes, PSI_DEBUG)) {
$dftypes = preg_replace('/\n\s/m', ' ', $dftypes);
$mounttypes = preg_split("/\n/", $dftypes, -1, PREG_SPLIT_NO_EMPTY);
foreach ($mounttypes as $type) {
$ty_buf = preg_split("/\s+/", $type, 3);
if ($ty_buf[0] == $dev->getName()) {
$dev->setFsType($ty_buf[1]);
break;
}
}
}
$this->sys->setDiskDevices($dev);
}
}
}
}
/**
* Distribution Icon
*
* @return void
*/
private function _distro()
{
$this->sys->setDistribution('SunOS');
$this->sys->setDistributionIcon('SunOS.png');
}
/**
* Processes
*
* @return void
*/
protected function _processes()
{
if (CommonFunctions::executeProgram('ps', 'aux', $bufr, PSI_DEBUG)) {
$lines = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
$processes['*'] = 0;
foreach ($lines as $line) {
if (preg_match("/^\S+\s+\d+\s+\S+\s+\S+\s+\d+\s+\d+\s+\S+\s+(\w)/", $line, $ar_buf)) {
$processes['*']++;
$state = $ar_buf[1];
if ($state == 'O') $state = 'R'; //linux format
elseif ($state == 'W') $state = 'D';
elseif ($state == 'D') $state = 'd'; //invalid
if (isset($processes[$state])) {
$processes[$state]++;
} else {
$processes[$state] = 1;
}
}
}
if ($processes['*'] > 0) {
$this->sys->setProcesses($processes);
}
}
}
/**
* get the information
*
* @see PSI_Interface_OS::build()
*
* @return Void
*/
public function build()
{
$this->error->addError("WARN", "The SunOS version of phpSysInfo is a work in progress, some things currently don't work");
$this->_distro();
$this->_hostname();
$this->_ip();
$this->_kernel();
$this->_uptime();
$this->_users();
$this->_loadavg();
$this->_cpuinfo();
$this->_network();
$this->_memory();
$this->_filesystems();
$this->_processes();
}
}

View File

@@ -0,0 +1,609 @@
<?php
/**
* WINNT System Class
*
* PHP version 5
*
* @category PHP
* @package PSI WINNT OS class
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @version SVN: $Id: class.WINNT.inc.php 699 2012-09-15 11:57:13Z namiltd $
* @link http://phpsysinfo.sourceforge.net
*/
/**
* WINNT sysinfo class
* get all the required information from WINNT systems
* information are retrieved through the WMI interface
*
* @category PHP
* @package PSI WINNT OS class
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @version Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
class WINNT extends OS
{
/**
* holds the COM object that we pull all the WMI data from
*
* @var Object
*/
private $_wmi = null;
/**
* holds all devices, which are in the system
*
* @var array
*/
private $_wmidevices;
/**
* store language encoding of the system to convert some output to utf-8
*
* @var string
*/
private $_codepage = null;
/**
* store language of the system
*
* @var string
*/
private $_syslang = null;
/**
* build the global Error object and create the WMI connection
*/
public function __construct()
{
parent::__construct();
// don't set this params for local connection, it will not work
$strHostname = '';
$strUser = '';
$strPassword = '';
try {
// initialize the wmi object
$objLocator = new COM('WbemScripting.SWbemLocator');
if ($strHostname == "") {
$this->_wmi = $objLocator->ConnectServer();
} else {
$this->_wmi = $objLocator->ConnectServer($strHostname, 'root\CIMv2', $strHostname.'\\'.$strUser, $strPassword);
}
} catch (Exception $e) {
$this->error->addError("WMI connect error", "PhpSysInfo can not connect to the WMI interface for security reasons.\nCheck an authentication mechanism for the directory where phpSysInfo is installed.");
}
$this->_getCodeSet();
}
/**
* store the codepage of the os for converting some strings to utf-8
*
* @return void
*/
private function _getCodeSet()
{
$buffer = CommonFunctions::getWMI($this->_wmi, 'Win32_OperatingSystem', array('CodeSet', 'OSLanguage'));
if ($buffer) {
$this->_codepage = 'windows-'.$buffer[0]['CodeSet'];
$lang = "";
if (is_readable(APP_ROOT.'/data/languages.ini') && ($langdata = @parse_ini_file(APP_ROOT.'/data/languages.ini', true))) {
if (isset($langdata['WINNT'][$buffer[0]['OSLanguage']])) {
$lang = $langdata['WINNT'][$buffer[0]['OSLanguage']];
}
}
if ($lang == "") {
$lang = 'Unknown';
}
$this->_syslang = $lang.' ('.$buffer[0]['OSLanguage'].')';
}
}
/**
* retrieve different device types from the system based on selector
*
* @param string $strType type of the devices that should be returned
*
* @return array list of devices of the specified type
*/
private function _devicelist($strType)
{
if (empty($this->_wmidevices)) {
$this->_wmidevices = CommonFunctions::getWMI($this->_wmi, 'Win32_PnPEntity', array('Name', 'PNPDeviceID'));
}
$list = array();
foreach ($this->_wmidevices as $device) {
if (substr($device['PNPDeviceID'], 0, strpos($device['PNPDeviceID'], "\\") + 1) == ($strType."\\")) {
$list[] = $device['Name'];
}
}
return $list;
}
/**
* Host Name
*
* @return void
*/
private function _hostname()
{
if (PSI_USE_VHOST === true) {
if ($hnm = getenv('SERVER_NAME')) $this->sys->setHostname($hnm);
} else {
$buffer = CommonFunctions::getWMI($this->_wmi, 'Win32_ComputerSystem', array('Name'));
if ($buffer) {
$result = $buffer[0]['Name'];
$ip = gethostbyname($result);
if ($ip != $result) {
$long = ip2long($ip);
if (($long >= 167772160 && $long <= 184549375) ||
($long >= -1408237568 && $long <= -1407188993) ||
($long >= -1062731776 && $long <= -1062666241) ||
($long >= 2130706432 && $long <= 2147483647) || $long == -1) {
$this->sys->setHostname($result); //internal ip
} else {
$this->sys->setHostname(gethostbyaddr($ip));
}
}
} else {
if ($hnm = getenv('COMPUTERNAME')) $this->sys->setHostname($hnm);
}
}
}
/**
* IP of the Canonical Host Name
*
* @return void
*/
private function _ip()
{
if (PSI_USE_VHOST === true) {
if ((($hnm=$this->sys->getHostname()) != 'localhost') &&
(($hip=gethostbyname($hnm)) != $hnm)) $this->sys->setIp($hip);
} else {
$buffer = CommonFunctions::getWMI($this->_wmi, 'Win32_ComputerSystem', array('Name'));
if ($buffer) {
$result = $buffer[0]['Name'];
$this->sys->setIp(gethostbyname($result));
} else {
if ((($hnm=$this->sys->getHostname()) != 'localhost') &&
(($hip=gethostbyname($hnm)) != $hnm)) $this->sys->setIp($hip);
}
}
}
/**
* UpTime
* time the system is running
*
* @return void
*/
private function _uptime()
{
$result = 0;
date_default_timezone_set('UTC');
$buffer = CommonFunctions::getWMI($this->_wmi, 'Win32_OperatingSystem', array('LastBootUpTime', 'LocalDateTime'));
if ($buffer) {
$byear = intval(substr($buffer[0]['LastBootUpTime'], 0, 4));
$bmonth = intval(substr($buffer[0]['LastBootUpTime'], 4, 2));
$bday = intval(substr($buffer[0]['LastBootUpTime'], 6, 2));
$bhour = intval(substr($buffer[0]['LastBootUpTime'], 8, 2));
$bminute = intval(substr($buffer[0]['LastBootUpTime'], 10, 2));
$bseconds = intval(substr($buffer[0]['LastBootUpTime'], 12, 2));
$lyear = intval(substr($buffer[0]['LocalDateTime'], 0, 4));
$lmonth = intval(substr($buffer[0]['LocalDateTime'], 4, 2));
$lday = intval(substr($buffer[0]['LocalDateTime'], 6, 2));
$lhour = intval(substr($buffer[0]['LocalDateTime'], 8, 2));
$lminute = intval(substr($buffer[0]['LocalDateTime'], 10, 2));
$lseconds = intval(substr($buffer[0]['LocalDateTime'], 12, 2));
$boottime = mktime($bhour, $bminute, $bseconds, $bmonth, $bday, $byear);
$localtime = mktime($lhour, $lminute, $lseconds, $lmonth, $lday, $lyear);
$result = $localtime - $boottime;
$this->sys->setUptime($result);
}
}
/**
* Number of Users
*
* @return void
*/
private function _users()
{
if (CommonFunctions::executeProgram("quser", "", $strBuf, false) && (strlen(trim($strBuf)) > 0)) {
$lines = preg_split('/\n/', $strBuf);
$users = count($lines)-1;
} else {
$users = 0;
$buffer = CommonFunctions::getWMI($this->_wmi, 'Win32_Process', array('Caption'));
foreach ($buffer as $process) {
if (strtoupper($process['Caption']) == strtoupper('explorer.exe')) {
$users++;
}
}
}
$this->sys->setUsers($users);
}
/**
* Distribution
*
* @return void
*/
private function _distro()
{
$buffer = CommonFunctions::getWMI($this->_wmi, 'Win32_OperatingSystem', array('Version', 'ServicePackMajorVersion', 'Caption', 'OSArchitecture'));
if ($buffer) {
$kernel = $buffer[0]['Version'];
if ($buffer[0]['ServicePackMajorVersion'] > 0) {
$kernel .= ' SP'.$buffer[0]['ServicePackMajorVersion'];
}
if (isset($buffer[0]['OSArchitecture']) && preg_match("/^(\d+)/", $buffer[0]['OSArchitecture'], $bits)) {
$this->sys->setKernel($kernel.' ('.$bits[1].'-bit)');
} elseif (($allCpus = CommonFunctions::getWMI($this->_wmi, 'Win32_Processor', array('AddressWidth'))) && isset($allCpus[0]['AddressWidth'])) {
$this->sys->setKernel($kernel.' ('.$allCpus[0]['AddressWidth'].'-bit)');
} else {
$this->sys->setKernel($kernel);
}
$this->sys->setDistribution($buffer[0]['Caption']);
if ((($kernel[1] == ".") && ($kernel[0] <5)) || (substr($kernel, 0, 4) == "5.0."))
$icon = 'Win2000.png';
elseif ((substr($kernel, 0, 4) == "6.0.") || (substr($kernel, 0, 4) == "6.1."))
$icon = 'WinVista.png';
elseif ((substr($kernel, 0, 4) == "6.2.") || (substr($kernel, 0, 4) == "6.3.") || (substr($kernel, 0, 4) == "6.4.") || (substr($kernel, 0, 5) == "10.0."))
$icon = 'Win8.png';
else
$icon = 'WinXP.png';
$this->sys->setDistributionIcon($icon);
} elseif (CommonFunctions::executeProgram("cmd", "/c ver 2>nul", $ver_value, false)) {
if (preg_match("/ReactOS\r?\nVersion\s+(.+)/", $ver_value, $ar_temp)) {
$this->sys->setDistribution("ReactOS");
$this->sys->setKernel($ar_temp[1]);
$this->sys->setDistributionIcon('ReactOS.png');
} elseif (preg_match("/^(Microsoft [^\[]*)\s*\[\D*\s*(.+)\]/", $ver_value, $ar_temp)) {
$this->sys->setDistribution($ar_temp[1]);
$this->sys->setKernel($ar_temp[2]);
$this->sys->setDistributionIcon('Win2000.png');
} else {
$this->sys->setDistribution("WinNT");
$this->sys->setDistributionIcon('Win2000.png');
}
} else {
$this->sys->setDistribution("WinNT");
$this->sys->setDistributionIcon('Win2000.png');
}
}
/**
* Processor Load
* optionally create a loadbar
*
* @return void
*/
private function _loadavg()
{
$loadavg = "";
$sum = 0;
$buffer = CommonFunctions::getWMI($this->_wmi, 'Win32_Processor', array('LoadPercentage'));
if ($buffer) {
foreach ($buffer as $load) {
$value = $load['LoadPercentage'];
$loadavg .= $value.' ';
$sum += $value;
}
$this->sys->setLoad(trim($loadavg));
if (PSI_LOAD_BAR) {
$this->sys->setLoadPercent($sum / count($buffer));
}
}
}
/**
* CPU information
*
* @return void
*/
private function _cpuinfo()
{
$allCpus = CommonFunctions::getWMI($this->_wmi, 'Win32_Processor', array('Name', 'L2CacheSize', 'CurrentClockSpeed', 'ExtClock', 'NumberOfCores', 'MaxClockSpeed'));
foreach ($allCpus as $oneCpu) {
$coreCount = 1;
if (isset($oneCpu['NumberOfCores'])) {
$coreCount = $oneCpu['NumberOfCores'];
}
for ($i = 0; $i < $coreCount; $i++) {
$cpu = new CpuDevice();
$cpu->setModel($oneCpu['Name']);
$cpu->setCache($oneCpu['L2CacheSize'] * 1024);
$cpu->setCpuSpeed($oneCpu['CurrentClockSpeed']);
$cpu->setBusSpeed($oneCpu['ExtClock']);
if ($oneCpu['CurrentClockSpeed'] < $oneCpu['MaxClockSpeed']) $cpu->setCpuSpeedMax($oneCpu['MaxClockSpeed']);
$this->sys->setCpus($cpu);
}
}
}
/**
* Machine information
*
* @return void
*/
private function _machine()
{
$buffer = CommonFunctions::getWMI($this->_wmi, 'Win32_ComputerSystem', array('Manufacturer', 'Model'));
if ($buffer) {
$buf = "";
if (isset($buffer[0]['Manufacturer'])) {
$buf .= ' '.$buffer[0]['Manufacturer'];
}
if (isset($buffer[0]['Model'])) {
$buf .= ' '.$buffer[0]['Model'];
}
if (trim($buf) != "") {
$this->sys->setMachine(trim($buf));
}
}
}
/**
* Hardwaredevices
*
* @return void
*/
private function _hardware()
{
foreach ($this->_devicelist('PCI') as $pciDev) {
$dev = new HWDevice();
$dev->setName($pciDev);
$this->sys->setPciDevices($dev);
}
foreach ($this->_devicelist('IDE') as $ideDev) {
$dev = new HWDevice();
$dev->setName($ideDev);
$this->sys->setIdeDevices($dev);
}
foreach ($this->_devicelist('SCSI') as $scsiDev) {
$dev = new HWDevice();
$dev->setName($scsiDev);
$this->sys->setScsiDevices($dev);
}
foreach ($this->_devicelist('USB') as $usbDev) {
$dev = new HWDevice();
$dev->setName($usbDev);
$this->sys->setUsbDevices($dev);
}
}
/**
* Network devices
*
* @return void
*/
private function _network()
{
$allDevices = CommonFunctions::getWMI($this->_wmi, 'Win32_PerfRawData_Tcpip_NetworkInterface', array('Name', 'BytesSentPersec', 'BytesTotalPersec', 'BytesReceivedPersec', 'PacketsReceivedErrors', 'PacketsReceivedDiscarded'));
$allNetworkAdapterConfigurations = CommonFunctions::getWMI($this->_wmi, 'Win32_NetworkAdapterConfiguration', array('Description', 'MACAddress', 'IPAddress', 'SettingID'));
foreach ($allDevices as $device) {
$dev = new NetDevice();
$name=$device['Name'];
if (preg_match('/^isatap\.({[A-Fa-f0-9\-]*})/', $name, $ar_name)) { //isatap device
foreach ($allNetworkAdapterConfigurations as $NetworkAdapterConfiguration) {
if ($ar_name[1]==$NetworkAdapterConfiguration['SettingID']) {
$dev->setName($NetworkAdapterConfiguration['Description']);
if (defined('PSI_SHOW_NETWORK_INFOS') && PSI_SHOW_NETWORK_INFOS) {
$dev->setInfo(preg_replace('/:/', '-', $NetworkAdapterConfiguration['MACAddress']));
if (isset($NetworkAdapterConfiguration['IPAddress']))
foreach($NetworkAdapterConfiguration['IPAddress'] as $ipaddres)
if (($ipaddres!="0.0.0.0") && !preg_match('/^fe80::/i', $ipaddres))
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$ipaddres);
}
break;
}
}
}
if ($dev->getName() == "") { //no isatap or no isatap description
$cname=preg_replace('/[^A-Za-z0-9]/', '_', $name); //convert to canonical
if (preg_match('/\s-\s([^-]*)$/', $name, $ar_name))
$name=substr($name, 0, strlen($name)-strlen($ar_name[0]));
$dev->setName($name);
if (defined('PSI_SHOW_NETWORK_INFOS') && PSI_SHOW_NETWORK_INFOS) foreach ($allNetworkAdapterConfigurations as $NetworkAdapterConfiguration) {
if (preg_replace('/[^A-Za-z0-9]/', '_', $NetworkAdapterConfiguration['Description']) == $cname) {
if (!is_null($dev->getInfo())) {
$dev->setInfo(''); //multiple with the same name
} else {
$dev->setInfo(preg_replace('/:/', '-', $NetworkAdapterConfiguration['MACAddress']));
if (isset($NetworkAdapterConfiguration['IPAddress']))
foreach($NetworkAdapterConfiguration['IPAddress'] as $ipaddres)
if (($ipaddres!="0.0.0.0") && !preg_match('/^fe80::/i', $ipaddres))
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$ipaddres);
}
}
}
}
// http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/win32_perfrawdata_tcpip_networkinterface.asp
// there is a possible bug in the wmi interfaceabout uint32 and uint64: http://www.ureader.com/message/1244948.aspx, so that
// magative numbers would occour, try to calculate the nagative value from total - positive number
$txbytes = $device['BytesSentPersec'];
$rxbytes = $device['BytesReceivedPersec'];
if (($txbytes < 0) && ($rxbytes < 0)) {
$txbytes += 4294967296;
$rxbytes += 4294967296;
} elseif ($txbytes < 0) {
if ($device['BytesTotalPersec'] > $rxbytes)
$txbytes = $device['BytesTotalPersec'] - $rxbytes;
else
$txbytes += 4294967296;
} elseif ($rxbytes < 0) {
if ($device['BytesTotalPersec'] > $txbytes)
$rxbytes = $device['BytesTotalPersec'] - $txbytes;
else
$rxbytes += 4294967296;
}
$dev->setTxBytes($txbytes);
$dev->setRxBytes($rxbytes);
$dev->setErrors($device['PacketsReceivedErrors']);
$dev->setDrops($device['PacketsReceivedDiscarded']);
$this->sys->setNetDevices($dev);
}
}
/**
* Physical memory information and Swap Space information
*
* @link http://msdn2.microsoft.com/En-US/library/aa394239.aspx
* @link http://msdn2.microsoft.com/en-us/library/aa394246.aspx
* @return void
*/
private function _memory()
{
$buffer = CommonFunctions::getWMI($this->_wmi, "Win32_OperatingSystem", array('TotalVisibleMemorySize', 'FreePhysicalMemory'));
if ($buffer) {
$this->sys->setMemTotal($buffer[0]['TotalVisibleMemorySize'] * 1024);
$this->sys->setMemFree($buffer[0]['FreePhysicalMemory'] * 1024);
$this->sys->setMemUsed($this->sys->getMemTotal() - $this->sys->getMemFree());
}
$buffer = CommonFunctions::getWMI($this->_wmi, 'Win32_PageFileUsage');
foreach ($buffer as $swapdevice) {
$dev = new DiskDevice();
$dev->setName("SWAP");
$dev->setMountPoint($swapdevice['Name']);
$dev->setTotal($swapdevice['AllocatedBaseSize'] * 1024 * 1024);
$dev->setUsed($swapdevice['CurrentUsage'] * 1024 * 1024);
$dev->setFree($dev->getTotal() - $dev->getUsed());
$dev->setFsType('swap');
$this->sys->setSwapDevices($dev);
}
}
/**
* filesystem information
*
* @return void
*/
private function _filesystems()
{
$typearray = array('Unknown', 'No Root Directory', 'Removable Disk', 'Local Disk', 'Network Drive', 'Compact Disc', 'RAM Disk');
$floppyarray = array('Unknown', '5 1/4 in.', '3 1/2 in.', '3 1/2 in.', '3 1/2 in.', '3 1/2 in.', '5 1/4 in.', '5 1/4 in.', '5 1/4 in.', '5 1/4 in.', '5 1/4 in.', 'Other', 'HD', '3 1/2 in.', '3 1/2 in.', '5 1/4 in.', '5 1/4 in.', '3 1/2 in.', '3 1/2 in.', '5 1/4 in.', '3 1/2 in.', '3 1/2 in.', '8 in.');
$buffer = CommonFunctions::getWMI($this->_wmi, 'Win32_LogicalDisk', array('Name', 'Size', 'FreeSpace', 'FileSystem', 'DriveType', 'MediaType'));
foreach ($buffer as $filesystem) {
$dev = new DiskDevice();
$dev->setMountPoint($filesystem['Name']);
$dev->setFsType($filesystem['FileSystem']);
if ($filesystem['Size'] > 0) {
$dev->setTotal($filesystem['Size']);
$dev->setFree($filesystem['FreeSpace']);
$dev->setUsed($filesystem['Size'] - $filesystem['FreeSpace']);
}
if ($filesystem['MediaType'] != "" && $filesystem['DriveType'] == 2) {
$dev->setName($typearray[$filesystem['DriveType']]." (".$floppyarray[$filesystem['MediaType']].")");
} else {
$dev->setName($typearray[$filesystem['DriveType']]);
}
$this->sys->setDiskDevices($dev);
}
if (!$buffer && ($this->sys->getDistribution()=="ReactOS")) {
// test for command 'free' on current disk
if (CommonFunctions::executeProgram("cmd", "/c free 2>nul", $out_value, true)) {
for ($letter='A'; $letter!='AA'; $letter++) if (CommonFunctions::executeProgram("cmd", "/c free ".$letter.": 2>nul", $out_value, false)) {
if (preg_match('/\n\s*([\d\.\,]+).*\n\s*([\d\.\,]+).*\n\s*([\d\.\,]+).*$/', $out_value, $out_dig)) {
$size = preg_replace('/(\.)|(\,)/', '', $out_dig[1]);
$used = preg_replace('/(\.)|(\,)/', '', $out_dig[2]);
$free = preg_replace('/(\.)|(\,)/', '', $out_dig[3]);
if ($used + $free == $size) {
$dev = new DiskDevice();
$dev->setMountPoint($letter.":");
$dev->setFsType('Unknown');
$dev->setTotal($size);
$dev->setFree($free);
$dev->setUsed($used);
$this->sys->setDiskDevices($dev);
}
}
}
}
}
}
/**
* get os specific encoding
*
* @see OS::getEncoding()
*
* @return string
*/
public function getEncoding()
{
return $this->_codepage;
}
/**
* get os specific language
*
* @see OS::getLanguage()
*
* @return string
*/
public function getLanguage()
{
return $this->_syslang;
}
public function _processes()
{
$processes['*'] = 0;
if (CommonFunctions::executeProgram("qprocess", "*", $strBuf, false) && (strlen(trim($strBuf)) > 0)) {
$lines = preg_split('/\n/', $strBuf);
$processes['*'] = (count($lines)-1) - 3 ; //correction for process "qprocess *"
}
if ($processes['*'] <= 0) {
$buffer = CommonFunctions::getWMI($this->_wmi, 'Win32_Process', array('Caption'));
$processes['*'] = count($buffer);
}
$processes[' '] = $processes['*'];
$this->sys->setProcesses($processes);
}
/**
* get the information
*
* @see PSI_Interface_OS::build()
*
* @return Void
*/
public function build()
{
$this->_distro();
if ($this->sys->getDistribution()=="ReactOS") {
$this->error->addError("WARN", "The ReactOS version of phpSysInfo is a work in progress, some things currently don't work");
}
$this->_hostname();
$this->_ip();
$this->_users();
$this->_machine();
$this->_uptime();
$this->_cpuinfo();
$this->_network();
$this->_hardware();
$this->_filesystems();
$this->_memory();
$this->_loadavg();
$this->_processes();
}
}