2024-09-07 20:53:46 +10:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Minix System Class
|
|
|
|
*
|
|
|
|
* PHP version 5
|
|
|
|
*
|
|
|
|
* @category PHP
|
|
|
|
* @package PSI Minix OS class
|
|
|
|
* @author Mieczyslaw Nalewaj <namiltd@users.sourceforge.net>
|
|
|
|
* @copyright 2012 phpSysInfo
|
2025-05-14 16:14:01 +01:00
|
|
|
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License version 2, or (at your option) any later version
|
2024-09-07 20:53:46 +10:00
|
|
|
* @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
|
2025-05-14 16:14:01 +01:00
|
|
|
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License version 2, or (at your option) any later version
|
2024-09-07 20:53:46 +10:00
|
|
|
* @version Release: 3.0
|
|
|
|
* @link http://phpsysinfo.sourceforge.net
|
|
|
|
*/
|
|
|
|
class Minix extends OS
|
|
|
|
{
|
2025-05-14 16:14:01 +01:00
|
|
|
/**
|
|
|
|
* uptime command result.
|
|
|
|
*/
|
|
|
|
private $_uptime = null;
|
|
|
|
|
2024-09-07 20:53:46 +10:00
|
|
|
/**
|
|
|
|
* content of the syslog
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
2025-05-14 16:14:01 +01:00
|
|
|
private $_dmesg = null;
|
2024-09-07 20:53:46 +10:00
|
|
|
|
|
|
|
/**
|
|
|
|
* read /var/log/messages, but only if we haven't already
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
protected function readdmesg()
|
|
|
|
{
|
2025-05-14 16:14:01 +01:00
|
|
|
if ($this->_dmesg === null) {
|
2024-09-07 20:53:46 +10:00
|
|
|
if (CommonFunctions::rfts('/var/log/messages', $buf)) {
|
2025-05-14 16:14:01 +01:00
|
|
|
$blocks = preg_replace("/\s(kernel: MINIX \d+\.\d+\.\d+\.)/", '<BLOCK>$1', $buf);
|
|
|
|
$parts = preg_split("/<BLOCK>/", $blocks, -1, PREG_SPLIT_NO_EMPTY);
|
2024-09-07 20:53:46 +10:00
|
|
|
$this->_dmesg = preg_split("/\n/", $parts[count($parts) - 1], -1, PREG_SPLIT_NO_EMPTY);
|
2025-05-14 16:14:01 +01:00
|
|
|
} else {
|
|
|
|
$this->_dmesg = array();
|
2024-09-07 20:53:46 +10:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->_dmesg;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* get the cpu information
|
|
|
|
*
|
2025-05-14 16:14:01 +01:00
|
|
|
* @return void
|
2024-09-07 20:53:46 +10:00
|
|
|
*/
|
|
|
|
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) {
|
2025-05-14 16:14:01 +01:00
|
|
|
if (preg_match('/^([^:]+):(.+)$/', trim($detail) , $arrBuff) && (($arrBuff2 = trim($arrBuff[2])) !== '')) {
|
|
|
|
switch (strtolower(trim($arrBuff[1]))) {
|
2024-09-07 20:53:46 +10:00
|
|
|
case 'model name':
|
2025-05-14 16:14:01 +01:00
|
|
|
$_n = $arrBuff2;
|
2024-09-07 20:53:46 +10:00
|
|
|
break;
|
|
|
|
case 'cpu mhz':
|
2025-05-14 16:14:01 +01:00
|
|
|
$dev->setCpuSpeed($arrBuff2);
|
2024-09-07 20:53:46 +10:00
|
|
|
break;
|
|
|
|
case 'cpu family':
|
2025-05-14 16:14:01 +01:00
|
|
|
$_f = $arrBuff2;
|
2024-09-07 20:53:46 +10:00
|
|
|
break;
|
|
|
|
case 'model':
|
2025-05-14 16:14:01 +01:00
|
|
|
$_m = $arrBuff2;
|
2024-09-07 20:53:46 +10:00
|
|
|
break;
|
|
|
|
case 'stepping':
|
2025-05-14 16:14:01 +01:00
|
|
|
$_s = $arrBuff2;
|
2024-09-07 20:53:46 +10:00
|
|
|
break;
|
|
|
|
case 'flags':
|
2025-05-14 16:14:01 +01:00
|
|
|
if (preg_match("/ vmx/", $arrBuff2)) {
|
2024-09-07 20:53:46 +10:00
|
|
|
$dev->setVirt("vmx");
|
2025-05-14 16:14:01 +01:00
|
|
|
} elseif (preg_match("/ svm/", $arrBuff2)) {
|
2024-09-07 20:53:46 +10:00
|
|
|
$dev->setVirt("svm");
|
|
|
|
}
|
2025-05-14 16:14:01 +01:00
|
|
|
break;
|
|
|
|
case 'vendor_id':
|
|
|
|
$dev->setVendorId($arrBuff2);
|
2024-09-07 20:53:46 +10:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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);
|
2025-05-14 16:14:01 +01:00
|
|
|
$arrResults = array();
|
2024-09-07 20:53:46 +10:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
2025-05-14 16:14:01 +01:00
|
|
|
if (!(isset($arrResults) && is_array($arrResults)) && ($results = Parser::lspci())) {
|
2024-09-07 20:53:46 +10:00
|
|
|
/* if access error: chmod 4755 /usr/bin/lspci */
|
|
|
|
foreach ($results as $dev) {
|
|
|
|
$this->sys->setPciDevices($dev);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Minix Version
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
private function _kernel()
|
|
|
|
{
|
|
|
|
if (CommonFunctions::executeProgram('uname', '-rvm', $ret)) {
|
2025-05-14 16:14:01 +01:00
|
|
|
foreach ($this->readdmesg() as $line) {
|
|
|
|
if (preg_match('/kernel: MINIX (\d+\.\d+\.\d+)\. \((.+)\)/', $line, $ar_buf)) {
|
|
|
|
$branch = $ar_buf[2];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2024-09-07 20:53:46 +10:00
|
|
|
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()
|
|
|
|
{
|
2025-05-14 16:14:01 +01:00
|
|
|
if (($this->_uptime !== null) || CommonFunctions::executeProgram('uptime', '', $this->_uptime)) {
|
|
|
|
if (preg_match("/up (\d+) day[s]?,\s*(\d+):(\d+),/", $this->_uptime, $ar_buf)) {
|
2024-09-07 20:53:46 +10:00
|
|
|
$min = $ar_buf[3];
|
|
|
|
$hours = $ar_buf[2];
|
|
|
|
$days = $ar_buf[1];
|
|
|
|
$this->sys->setUptime($days * 86400 + $hours * 3600 + $min * 60);
|
2025-05-14 16:14:01 +01:00
|
|
|
} elseif (preg_match("/up (\d+):(\d+),/", $this->_uptime, $ar_buf)) {
|
2024-09-07 20:53:46 +10:00
|
|
|
$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()
|
|
|
|
{
|
2025-05-14 16:14:01 +01:00
|
|
|
if (($this->_uptime !== null) || CommonFunctions::executeProgram('uptime', '', $this->_uptime)) {
|
|
|
|
if (preg_match("/load averages: (.*), (.*), (.*)$/", $this->_uptime, $ar_buf)) {
|
2024-09-07 20:53:46 +10:00
|
|
|
$this->sys->setLoad($ar_buf[1].' '.$ar_buf[2].' '.$ar_buf[3]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Virtual Host Name
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
private function _hostname()
|
|
|
|
{
|
2025-05-14 16:14:01 +01:00
|
|
|
if (PSI_USE_VHOST) {
|
|
|
|
if (CommonFunctions::readenv('SERVER_NAME', $hnm)) $this->sys->setHostname($hnm);
|
2024-09-07 20:53:46 +10:00
|
|
|
} else {
|
|
|
|
if (CommonFunctions::executeProgram('uname', '-n', $result, PSI_DEBUG)) {
|
|
|
|
$ip = gethostbyname($result);
|
|
|
|
if ($ip != $result) {
|
|
|
|
$this->sys->setHostname(gethostbyaddr($ip));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Physical memory information and Swap Space information
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
private function _memory()
|
|
|
|
{
|
|
|
|
if (CommonFunctions::rfts('/proc/meminfo', $bufr, 1, 4096, false)) {
|
|
|
|
$ar_buf = preg_split('/\s+/', trim($bufr));
|
|
|
|
if (count($ar_buf) >= 5) {
|
|
|
|
$this->sys->setMemTotal($ar_buf[0]*$ar_buf[1]);
|
|
|
|
$this->sys->setMemFree($ar_buf[0]*$ar_buf[2]);
|
|
|
|
$this->sys->setMemCache($ar_buf[0]*$ar_buf[4]);
|
|
|
|
$this->sys->setMemUsed($ar_buf[0]*($ar_buf[1]-$ar_buf[2]));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* filesystem information
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
private function _filesystems()
|
|
|
|
{
|
|
|
|
$arrResult = Parser::df("-P 2>/dev/null");
|
|
|
|
foreach ($arrResult as $dev) {
|
|
|
|
$this->sys->setDiskDevices($dev);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* network information
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
private function _network()
|
|
|
|
{
|
|
|
|
if (CommonFunctions::executeProgram('ifconfig', '-a', $bufr, PSI_DEBUG)) {
|
|
|
|
$lines = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
|
|
|
|
foreach ($lines as $line) {
|
|
|
|
if (preg_match("/^([^\s:]+):\saddress\s(\S+)\snetmask/", $line, $ar_buf)) {
|
|
|
|
$dev = new NetDevice();
|
|
|
|
$dev->setName($ar_buf[1]);
|
|
|
|
if (defined('PSI_SHOW_NETWORK_INFOS') && (PSI_SHOW_NETWORK_INFOS)) {
|
|
|
|
$dev->setInfo($ar_buf[2]);
|
|
|
|
}
|
|
|
|
$this->sys->setNetDevices($dev);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Processes
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
protected function _processes()
|
|
|
|
{
|
|
|
|
if (CommonFunctions::executeProgram('ps', 'alx', $bufr, PSI_DEBUG)) {
|
|
|
|
$lines = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
|
|
|
|
$processes['*'] = 0;
|
|
|
|
foreach ($lines as $line) {
|
|
|
|
if (preg_match("/^\s(\w)\s/", $line, $ar_buf)) {
|
|
|
|
$processes['*']++;
|
|
|
|
$state = $ar_buf[1];
|
|
|
|
if ($state == 'W') $state = 'D'; //linux format
|
|
|
|
elseif ($state == 'D') $state = 'd'; //invalid
|
|
|
|
if (isset($processes[$state])) {
|
|
|
|
$processes[$state]++;
|
|
|
|
} else {
|
|
|
|
$processes[$state] = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($processes['*'] > 0) {
|
|
|
|
$this->sys->setProcesses($processes);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* get the information
|
|
|
|
*
|
2025-05-14 16:14:01 +01:00
|
|
|
* @return void
|
2024-09-07 20:53:46 +10:00
|
|
|
*/
|
|
|
|
public function build()
|
|
|
|
{
|
2025-05-14 16:14:01 +01:00
|
|
|
$this->error->addWarning("The Minix version of phpSysInfo is a work in progress, some things currently don't work");
|
|
|
|
if (!$this->blockname || $this->blockname==='vitals') {
|
|
|
|
$this->_distro();
|
|
|
|
$this->_hostname();
|
|
|
|
$this->_kernel();
|
|
|
|
$this->_uptime();
|
|
|
|
$this->_users();
|
|
|
|
$this->_loadavg();
|
|
|
|
$this->_processes();
|
|
|
|
}
|
|
|
|
if (!$this->blockname || $this->blockname==='hardware') {
|
|
|
|
$this->_pci();
|
|
|
|
$this->_cpuinfo();
|
|
|
|
}
|
|
|
|
if (!$this->blockname || $this->blockname==='memory') {
|
|
|
|
$this->_memory();
|
|
|
|
}
|
|
|
|
if (!$this->blockname || $this->blockname==='filesystem') {
|
|
|
|
$this->_filesystems();
|
|
|
|
}
|
|
|
|
if (!$this->blockname || $this->blockname==='network') {
|
|
|
|
$this->_network();
|
|
|
|
}
|
2024-09-07 20:53:46 +10:00
|
|
|
}
|
|
|
|
}
|