Subversion Repositories ALCASAR

Compare Revisions

Ignore whitespace Rev 3099 → Rev 3100

/web/acc/phpsysinfo/includes/os/class.Android.inc.php
54,7 → 54,7
*
* @return void
*/
private function _kernel()
protected function _kernel()
{
if (CommonFunctions::executeProgram('uname', '-r', $strBuf, false)) {
$result = $strBuf;
91,7 → 91,7
*
* @return void
*/
private function _filesystems()
protected function _filesystems()
{
$notwas = true;
if (CommonFunctions::executeProgram('df', '2>/dev/null ', $df, PSI_DEBUG) && preg_match("/\s+[0-9\.]+[KMGT]\s+/", $df)) {
197,7 → 197,7
*
* @return void
*/
private function _machine()
protected function _machine()
{
if ($lines = $this->_get_buildprop()) {
$buf = "";
/web/acc/phpsysinfo/includes/os/class.BSDCommon.inc.php
232,8 → 232,15
protected function kernel()
{
$s = $this->grabkey('kern.version');
$a = preg_split('/:/', $s);
if (isset($a[2])) {
$a = preg_split('/:/', $s, 4);
if (isset($a[3])) {
if (preg_match('/^(\d{2} [A-Z]{3});/', $a[3], $abuf) // eg. 19:58 GMT;...
|| preg_match('/^(\d{2} [A-Z]{3} \d{4})/', $a[3], $abuf)) { // eg. 26:31 PDT 2019...
$this->sys->setKernel($a[0].$a[1].':'.$a[2].':'.$abuf[1]);
} else {
$this->sys->setKernel($a[0].$a[1].':'.$a[2]);
}
} elseif (isset($a[2])) {
$this->sys->setKernel($a[0].$a[1].':'.$a[2]);
} else {
$this->sys->setKernel($s);
305,7 → 312,7
array_shift($pslines);
$sum = 0;
foreach ($pslines as $psline) {
$sum+=trim($psline);
$sum+=str_replace(',', '.', trim($psline));
}
$this->_cpu_loads['cpu'] = min($sum/$ncpu, 100);
}
331,6 → 338,7
$s = $this->grabkey('vm.loadavg');
$s = preg_replace('/{ /', '', $s);
$s = preg_replace('/ }/', '', $s);
$s = str_replace(',', '.', $s);
$this->sys->setLoad($s);
 
if (PSI_LOAD_BAR) {
358,7 → 366,7
$regexps = preg_split("/\n/", $this->_CPURegExp1, -1, PREG_SPLIT_NO_EMPTY); // multiple regexp separated by \n
foreach ($regexps as $regexp) {
if (preg_match($regexp, $line, $ar_buf) && (sizeof($ar_buf) > 2)) {
if ($dev->getCpuSpeed() === 0) {
if ($dev->getCpuSpeed() == 0) {
$dev->setCpuSpeed(round($ar_buf[2]));
}
$notwas = false;
/web/acc/phpsysinfo/includes/os/class.Darwin.inc.php
97,8 → 97,8
protected function cpuinfo()
{
$dev = new CpuDevice();
if (CommonFunctions::executeProgram('hostinfo', '| grep "Processor type"', $buf, PSI_DEBUG)) {
$dev->setModel(preg_replace('/Processor type: /', '', $buf));
if (CommonFunctions::executeProgram('hostinfo', '', $buf, PSI_DEBUG) && ($buf !== '') && preg_match('/^Processor type:[ ]+(.+)$/m', $buf, $proc) && (($proc[1] = trim($proc[1])) !== '')) {
$dev->setModel($proc[1]);
$buf=$this->grabkey('hw.model');
if (($buf !== null) && (trim($buf) != "")) {
$this->sys->setMachine(trim($buf));
264,60 → 264,61
*/
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);
if (($s = $this->grabkey('hw.memsize')) > 0) {
$this->sys->setMemTotal($s);
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);
}
} 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);
$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);
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);
}
} 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->setMemUsed($this->sys->getMemTotal() - $this->sys->getMemFree());
}
 
$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]);
if (($swap=trim($swap1[0])) > 0) {
if (($swap = $this->grabkey("vm.swapusage")) > 0) {
$swap0 = preg_split('/M/', $swapBuff);
$swap1 = preg_split('/=/', $swap0[0]);
$swap2 = preg_split('/=/', $swap0[1]);
$swap3 = preg_split('/=/', $swap0[2]);
if (($swap=str_replace(',', '.', trim($swap1[1]))) > 0) {
$dev = new DiskDevice();
$dev->setName('SWAP');
$dev->setMountPoint('SWAP');
$dev->setFsType('swap');
$dev->setTotal($swap * 1024 * 1024);
$dev->setUsed(trim($swap2[1]) * 1024 * 1024);
$dev->setFree(trim($swap3[1]) * 1024 * 1024);
$dev->setUsed(str_replace(',', '.', trim($swap2[1])) * 1024 * 1024);
$dev->setFree(str_replace(',', '.', trim($swap3[1])) * 1024 * 1024);
$this->sys->setSwapDevices($dev);
}
}
417,7 → 418,7
}
if (isset($distro_arr['System Version'])) {
$distro = $distro_arr['System Version'];
if (preg_match('/^Mac OS|^OS X|^macOS/', $distro)) {
if (preg_match('/^Mac OS |^OS X |^macOS |^iPhone OS |^Mac OS$|^OS X$|^macOS$|^iPhone OS$/', $distro)) {
$this->sys->setDistributionIcon('Apple.png');
if (preg_match('/(^Mac OS X Server|^Mac OS X|^OS X Server|^OS X|^macOS Server|^macOS) ((\d+)\.\d+)/', $distro, $ver)
&& ($list = @parse_ini_file(PSI_APP_ROOT."/data/osnames.ini", true))) {
/web/acc/phpsysinfo/includes/os/class.FreeBSD.inc.php
127,6 → 127,9
} elseif (preg_match('/^FreeNAS/i', $version)) { // FreeNAS detection
$this->sys->setDistribution($version);
$this->sys->setDistributionIcon('FreeNAS.png');
} elseif (preg_match('/^TrueNAS/i', $version)) { // TrueNAS detection
$this->sys->setDistribution($version);
$this->sys->setDistributionIcon('TrueNAS.png');
} else {
$this->sys->setDistributionIcon('FreeBSD.png');
}
/web/acc/phpsysinfo/includes/os/class.GNU.inc.php
0,0 → 1,118
<?php
/**
* GNU Class
*
* PHP version 5
*
* @category PHP
* @package PSI GNU class
* @author Mieczyslaw Nalewaj <namiltd@users.sourceforge.net>
* @copyright 2012 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License version 2, or (at your option) any later version
* @version SVN: $Id: class.GNU.inc.php 687 2012-09-06 20:54:49Z namiltd $
* @link http://phpsysinfo.sourceforge.net
*/
/**
* GNU sysinfo class
* get all the required information from GNU
*
* @category PHP
* @package PSI GNU class
* @author Mieczyslaw Nalewaj <namiltd@users.sourceforge.net>
* @copyright 2022 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License version 2, or (at your option) any later version
* @version Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
class GNU extends Linux
{
/**
* Network devices
* includes also rx/tx bytes
*
* @return void
*/
protected function _network($bufr = null)
{
if ($this->sys->getOS() == 'GNU') {
if (CommonFunctions::executeProgram('ifconfig', '-a', $bufr, PSI_DEBUG)) {
$lines = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
$was = false;
$macaddr = "";
$dev = null;
foreach ($lines as $line) {
if (preg_match("/^\/dev\/([^\s:]+)/", $line, $ar_buf) || preg_match("/^([^\s:]+)/", $line, $ar_buf)) {
if ($was) {
if ($macaddr != "") {
$dev->setInfo($macaddr.($dev->getInfo()?';'.$dev->getInfo():''));
}
$this->sys->setNetDevices($dev);
}
$macaddr = "";
$dev = new NetDevice();
$dev->setName($ar_buf[1]);
$was = true;
} else {
if ($was) {
if (defined('PSI_SHOW_NETWORK_INFOS') && (PSI_SHOW_NETWORK_INFOS)) {
if (preg_match('/^\s+inet address\s+(\S+)$/', $line, $ar_buf)) {
$dev->setInfo($ar_buf[1]);
} elseif (preg_match('/^\s+hardware addr\s+(\S+)$/', $line, $ar_buf)) {
if (!defined('PSI_HIDE_NETWORK_MACADDR') || !PSI_HIDE_NETWORK_MACADDR) {
$macaddr = preg_replace('/:/', '-', strtoupper($ar_buf[1]));
if ($macaddr === '00-00-00-00-00-00') { // empty
$macaddr = "";
}
}
}
}
}
}
}
if ($was) {
if ($macaddr != "") {
$dev->setInfo($macaddr.($dev->getInfo()?';'.$dev->getInfo():''));
}
$this->sys->setNetDevices($dev);
}
}
} else {
parent::_network($bufr);
}
}
 
/**
* Number of Users
*
* @return void
*/
protected function _users()
{
if ($this->sys->getOS() == 'GNU') {
if (CommonFunctions::executeProgram('who', '', $strBuf, PSI_DEBUG)) {
if (strlen($strBuf) > 0) {
$lines = preg_split('/\n/', $strBuf);
preg_match_all('/^login\s+/m', $strBuf, $ttybuf);
if (($who = count($lines)-count($ttybuf[0])) > 0) {
$this->sys->setUsers($who);
}
}
}
} else {
parent::_users();
}
}
 
/**
* get the information
*
* @return void
*/
public function build()
{
if ($this->sys->getOS() == 'GNU') {
$this->error->addWarning("The GNU Hurd version of phpSysInfo is a work in progress, some things currently don't work");
}
parent::build();
}
}
/web/acc/phpsysinfo/includes/os/class.Linux.inc.php
34,7 → 34,7
/**
* Assoc array of all CPUs loads.
*/
private $_cpu_loads = null;
protected $_cpu_loads = null;
 
/**
* Version string.
196,7 → 196,7
$this->_machine_info['machine'] = trim(preg_replace("/^\/,?/", "", preg_replace("/ ?(To be filled by O\.E\.M\.|System manufacturer|System Product Name|Not Specified|Default string) ?/i", "", $this->_machine_info['machine'])));
}
 
if (defined('PSI_SHOW_VIRTUALIZER_INFO') && PSI_SHOW_VIRTUALIZER_INFO && ($this->system_detect_virt === null) && count($vendor_array)>0) {
if (defined('PSI_SHOW_VIRTUALIZER_INFO') && PSI_SHOW_VIRTUALIZER_INFO && ($this->system_detect_virt === null) && count($vendor_array) > 0) {
$virt = CommonFunctions::decodevirtualizer($vendor_array);
if ($virt !== null) {
$this->_machine_info['hypervisor'] = $virt;
216,20 → 216,29
{
if ($this->_kernel_string === null) {
$this->_kernel_string = "";
if (CommonFunctions::executeProgram($uname="uptrack-uname", '-r', $strBuf, false) || // show effective kernel if ksplice uptrack is installed
CommonFunctions::executeProgram($uname="uname", '-r', $strBuf, PSI_DEBUG)) {
if ($this->sys->getOS() == 'SSH') {
if (CommonFunctions::executeProgram('uname', '-s', $strBuf, false) && ($strBuf !== '')) {
$this->sys->setOS($strBuf);
} else {
return $this->_kernel_string;
}
}
if ((CommonFunctions::executeProgram($uname="uptrack-uname", '-r', $strBuf, false) && ($strBuf !== '')) || // show effective kernel if ksplice uptrack is installed
(CommonFunctions::executeProgram($uname="uname", '-r', $strBuf, PSI_DEBUG) && ($strBuf !== ''))) {
$this->_kernel_string = $strBuf;
if (CommonFunctions::executeProgram($uname, '-v', $strBuf, PSI_DEBUG)) {
if (CommonFunctions::executeProgram($uname, '-v', $strBuf, PSI_DEBUG) && ($strBuf !== '')) {
if (preg_match('/ SMP /', $strBuf)) {
$this->_kernel_string .= ' (SMP)';
}
}
if (CommonFunctions::executeProgram($uname, '-m', $strBuf, PSI_DEBUG)) {
if (CommonFunctions::executeProgram($uname, '-m', $strBuf, PSI_DEBUG) && ($strBuf !== '')) {
$this->_kernel_string .= ' '.$strBuf;
}
} elseif (CommonFunctions::rfts('/proc/version', $strBuf, 1)) {
if (preg_match('/version\s+(\S+)/', $strBuf, $ar_buf)) {
if (preg_match('/\/Hurd-([^\)]+)/', $strBuf, $ar_buf)) {
$this->_kernel_string = $ar_buf[1];
} elseif (preg_match('/version\s+(\S+)/', $strBuf, $ar_buf)) {
$this->_kernel_string = $ar_buf[1];
if (preg_match('/ SMP /', $strBuf)) {
$this->_kernel_string .= ' (SMP)';
}
241,11 → 250,20
}
 
/**
* check OS type
*/
public function __construct($blockname = false)
{
parent::__construct($blockname);
$this->_get_kernel_string();
}
 
/**
* Machine
*
* @return void
*/
private function _machine()
protected function _machine()
{
$machine_info = $this->_get_machine_info();
if (isset($machine_info['machine'])) {
279,7 → 297,7
*/
protected function _hostname()
{
if (PSI_USE_VHOST) {
if (PSI_USE_VHOST && !defined('PSI_EMU_PORT')) {
if (CommonFunctions::readenv('SERVER_NAME', $hnm)) $this->sys->setHostname($hnm);
} else {
if (CommonFunctions::rfts('/proc/sys/kernel/hostname', $result, 1, 4096, PSI_DEBUG && (PSI_OS != 'Android'))) {
299,7 → 317,7
*
* @return void
*/
private function _kernel()
protected function _kernel()
{
if (($verBuf = $this->_get_kernel_string()) != "") {
$this->sys->setKernel($verBuf);
334,14 → 352,14
$novm = true;
// code based on src/basic/virt.c from systemd-detect-virt source code (https://github.com/systemd/systemd)
 
// First, try to detect Oracle Virtualbox and Amazon EC2 Nitro, even if they use KVM, as well as Xen even if
// it cloaks as Microsoft Hyper-V. Attempt to detect uml at this stage also since it runs as a user-process
// nested inside other VMs. Also check for Xen now, because Xen PV mode does not override CPUID when nested
// inside another hypervisor.
// First, try to detect Oracle Virtualbox, Amazon EC2 Nitro and Parallels, even if they use KVM,
// as well as Xen even if it cloaks as Microsoft Hyper-V. Attempt to detect uml at this stage also
// since it runs as a user-process nested inside other VMs. Also check for Xen now, because Xen PV
// mode does not override CPUID when nested inside another hypervisor.
$machine_info = $this->_get_machine_info();
if (isset($machine_info['hypervisor'])) {
$hypervisor = $machine_info['hypervisor'];
if (($hypervisor === 'oracle') || ($hypervisor === 'amazon') || ($hypervisor === 'xen')) {
if (($hypervisor === 'oracle') || ($hypervisor === 'amazon') || ($hypervisor === 'xen') || ($hypervisor === 'parallels')) {
$this->sys->setVirtualizer($hypervisor);
$novm = false;
}
520,12 → 538,15
*
* @return void
*/
protected function _uptime()
protected function _uptime($bufu = null)
{
if (CommonFunctions::rfts('/proc/uptime', $buf, 1, 4096, PSI_OS != 'Android')) {
$ar_buf = preg_split('/ /', $buf);
$this->sys->setUptime(trim($ar_buf[0]));
} elseif (($this->_uptime !== null) || CommonFunctions::executeProgram('uptime', '', $this->_uptime)) {
} elseif (($this->_uptime !== null) || ($bufu !== null) || CommonFunctions::executeProgram('uptime', '', $bufu)) {
if (($this->_uptime === null) && ($bufu !== null)) {
$this->_uptime = $bufu;
}
if (preg_match("/up (\d+) day[s]?,[ ]+(\d+):(\d+),/", $this->_uptime, $ar_buf)) {
$min = $ar_buf[3];
$hours = $ar_buf[2];
539,9 → 560,19
$min = $ar_buf[2];
$hours = $ar_buf[1];
$this->sys->setUptime($hours * 3600 + $min * 60);
} elseif (preg_match("/up[ ]+(\d+):(\d+):(\d+)/", $this->_uptime, $ar_buf)) {
$sec = $ar_buf[3];
$min = $ar_buf[2];
$hours = $ar_buf[1];
$this->sys->setUptime($hours * 3600 + $min * 60 + $sec);
} elseif (preg_match("/up[ ]+(\d+) min,/", $this->_uptime, $ar_buf)) {
$min = $ar_buf[1];
$this->sys->setUptime($min * 60);
} elseif (preg_match("/up[ ]+(\d+) day[s]?,[ ]+(\d+) hour[s]?,[ ]+(\d+) minute[s]?/", $this->_uptime, $ar_buf)) {
$min = $ar_buf[3];
$hours = $ar_buf[2];
$days = $ar_buf[1];
$this->sys->setUptime($days * 86400 + $hours * 3600 + $min * 60);
}
}
}
552,15 → 583,15
*
* @return void
*/
protected function _loadavg()
protected function _loadavg($buf = null)
{
if (CommonFunctions::rfts('/proc/loadavg', $buf, 1, 4096, PSI_OS != 'Android')) {
if ((($buf !== null) || CommonFunctions::rfts('/proc/loadavg', $buf, 1, 4096, PSI_OS != 'Android')) && preg_match("/^\d/", trim($buf))) {
$result = preg_split("/\s/", $buf, 4);
// don't need the extra values, only first three
unset($result[3]);
$this->sys->setLoad(implode(' ', $result));
} elseif ((($this->_uptime !== null) || CommonFunctions::executeProgram('uptime', '', $this->_uptime)) && preg_match("/load average: (.*), (.*), (.*)$/", $this->_uptime, $ar_buf)) {
$this->sys->setLoad($ar_buf[1].' '.$ar_buf[2].' '.$ar_buf[3]);
} elseif (($buf === null) && ((($this->_uptime !== null) || CommonFunctions::executeProgram('uptime', '', $this->_uptime)) && preg_match("/load average: (.*), (.*), (.*)$/", $this->_uptime, $ar_buf))) {
$this->sys->setLoad($ar_buf[1].' '.$ar_buf[2].' '.$ar_buf[3]);
}
if (PSI_LOAD_BAR) {
$this->sys->setLoadPercent($this->_parseProcStat('cpu'));
641,10 → 672,9
*
* @return void
*/
protected function _cpuinfo()
protected function _cpuinfo($bufr = null)
{
if (CommonFunctions::rfts('/proc/cpuinfo', $bufr)) {
 
if (($bufr !== null) || CommonFunctions::rfts('/proc/cpuinfo', $bufr)) {
$cpulist = null;
$raslist = null;
 
703,11 → 733,15
case 'cpu frequency':
if (preg_match('/^(\d+)\s+Hz/i', $arrBuff1, $bufr2)) {
$_cpus = round($bufr2[1]/1000000);
} elseif (preg_match('/^(\d+)\s+MHz/i', $arrBuff1, $bufr2)) {
$_cpus = $bufr2[1];
}
break;
case 'system bus frequency':
if (preg_match('/^(\d+)\s+Hz/i', $arrBuff1, $bufr2)) {
$_buss = round($bufr2[1]/1000000);
} elseif (preg_match('/^(\d+)\s+MHz/i', $arrBuff1, $bufr2)) {
$_buss = $bufr2[1];
}
break;
case 'bogomips per cpu':
741,7 → 775,7
case 'processor':
$proc = $arrBuff1;
if (is_numeric($proc)) {
if (($procname !== null) && (strlen($procname)>0)) {
if (($procname !== null) && (strlen($procname) > 0)) {
$dev->setModel($procname);
}
} else {
755,25 → 789,40
case 'cpu':
$dev->setModel($arrBuff1);
break;
case 'cpu frequency':
if (preg_match('/^(\d+)\s+Hz/i', $arrBuff1, $bufr2)) {
if (($tmpsp = round($bufr2[1]/1000000)) > 0) {
$dev->setCpuSpeed($tmpsp);
$speedset = true;
}
} elseif (preg_match('/^(\d+)\s+MHz/i', $arrBuff1, $bufr2)) {
if ($bufr2[1] > 0) {
$dev->setCpuSpeed($bufr2[1]);
$speedset = true;
}
}
break;
case 'cpu mhz':
case 'clock':
if ($arrBuff1 > 0) { // openSUSE fix
if ($arrBuff1 > 0) {
$dev->setCpuSpeed($arrBuff1);
$speedset = true;
}
break;
case 'cpu mhz static':
if ($arrBuff1 > 0) { // openSUSE fix
$dev->setCpuSpeedMax($arrBuff1);
}
$dev->setCpuSpeedMax($arrBuff1);
break;
case 'cycle frequency [hz]':
$dev->setCpuSpeed($arrBuff1 / 1000000);
$speedset = true;
if (($tmpsp = round($arrBuff1/1000000)) > 0) {
$dev->setCpuSpeed($tmpsp);
$speedset = true;
}
break;
case 'cpu0clktck':
$dev->setCpuSpeed(hexdec($arrBuff1) / 1000000); // Linux sparc64
$speedset = true;
case 'cpu0clktck': // Linux sparc64
if (($tmpsp = round(hexdec($arrBuff1)/1000000)) > 0) {
$dev->setCpuSpeed($tmpsp);
$speedset = true;
}
break;
case 'l3 cache':
case 'cache size':
845,8 → 894,8
// sparc64 specific code ends
 
// XScale detection code
if (($arch === "5TE") && ($dev->getBogomips() !== null)) {
$dev->setCpuSpeed($dev->getBogomips()); // BogoMIPS are not BogoMIPS on this CPU, it's the speed
if (($arch === "5TE") && (($bogo = $dev->getBogomips()) !== null) && ($bogo > 0)) {
$dev->setCpuSpeed($bogo); // BogoMIPS are not BogoMIPS on this CPU, it's the speed
$speedset = true;
$dev->setBogomips(null); // no BogoMIPS available, unset previously set BogoMIPS
}
854,7 → 903,7
if (($dev->getBusSpeed() == 0) && ($_buss !== null)) {
$dev->setBusSpeed($_buss);
}
if (($dev->getCpuSpeed() == 0) && ($_cpus !== null)) {
if (($dev->getCpuSpeed() == 0) && ($_cpus !== null) && ($_cpus > 0)) {
$dev->setCpuSpeed($_cpus);
$speedset = true;
}
873,18 → 922,20
$proc = 0;
}
// variable speed processors specific code follows
if (CommonFunctions::rfts('/sys/devices/system/cpu/cpu'.$proc.'/cpufreq/cpuinfo_cur_freq', $buf, 1, 4096, false)) {
$dev->setCpuSpeed(trim($buf) / 1000);
$speedset = true;
} elseif (CommonFunctions::rfts('/sys/devices/system/cpu/cpu'.$proc.'/cpufreq/scaling_cur_freq', $buf, 1, 4096, false)) {
$dev->setCpuSpeed(trim($buf) / 1000);
$speedset = true;
if (CommonFunctions::rfts('/sys/devices/system/cpu/cpu'.$proc.'/cpufreq/cpuinfo_cur_freq', $buf, 1, 4096, false)
|| CommonFunctions::rfts('/sys/devices/system/cpu/cpu'.$proc.'/cpufreq/scaling_cur_freq', $buf, 1, 4096, false)) {
if (round(trim($buf)/1000) > 0) {
$dev->setCpuSpeed(round(trim($buf)/1000));
$speedset = true;
}
}
if (CommonFunctions::rfts('/sys/devices/system/cpu/cpu'.$proc.'/cpufreq/cpuinfo_max_freq', $buf, 1, 4096, false)) {
$dev->setCpuSpeedMax(trim($buf) / 1000);
if (CommonFunctions::rfts('/sys/devices/system/cpu/cpu'.$proc.'/cpufreq/cpuinfo_max_freq', $buf, 1, 4096, false)
|| CommonFunctions::rfts('/sys/devices/system/cpu/cpu'.$proc.'/cpufreq/scaling_max_freq', $buf, 1, 4096, false)) {
$dev->setCpuSpeedMax(round(trim($buf)/1000));
}
if (CommonFunctions::rfts('/sys/devices/system/cpu/cpu'.$proc.'/cpufreq/cpuinfo_min_freq', $buf, 1, 4096, false)) {
$dev->setCpuSpeedMin(trim($buf) / 1000);
if (CommonFunctions::rfts('/sys/devices/system/cpu/cpu'.$proc.'/cpufreq/cpuinfo_min_freq', $buf, 1, 4096, false)
|| CommonFunctions::rfts('/sys/devices/system/cpu/cpu'.$proc.'/cpufreq/scaling_min_freq', $buf, 1, 4096, false)) {
$dev->setCpuSpeedMin(round(trim($buf)/1000));
}
// variable speed processors specific code ends
if (PSI_LOAD_BAR) {
901,9 → 952,15
&& (($_hard === 'BCM2708') || ($_hard === 'BCM2835') || ($_hard === 'BCM2709') || ($_hard === 'BCM2836') || ($_hard === 'BCM2710') || ($_hard === 'BCM2837') || ($_hard === 'BCM2711') || ($_hard === 'BCM2838'))
&& ($_revi !== null)) { // Raspberry Pi detection (instead of 'cat /proc/device-tree/model')
if ($raslist === null) $raslist = @parse_ini_file(PSI_APP_ROOT."/data/raspberry.ini", true);
$oldmach = $this->sys->getMachine();
if (($oldmach !== '') && preg_match("/^raspberrypi rpi(,.+)/", $oldmach, $machbuf)) {
$oldmachend = $machbuf[1];
} else {
$oldmachend = '';
}
if ($raslist && !preg_match('/[^0-9a-f]/', $_revi)) {
if (($revidec = hexdec($_revi)) & 0x800000) {
if ($this->sys->getMachine() === '') {
if (($oldmach === '') || ($oldmachend !== '')) {
$manufacturer = ($revidec >> 16) & 15;
if (isset($raslist['manufacturer'][$manufacturer])) {
$manuf = ' '.$raslist['manufacturer'][$manufacturer];
912,17 → 969,17
}
$model = ($revidec >> 4) & 255;
if (isset($raslist['model'][$model])) {
$this->sys->setMachine('Raspberry Pi '.$raslist['model'][$model].' (PCB 1.'.($revidec & 15).$manuf.')');
$this->sys->setMachine('Raspberry Pi '.$raslist['model'][$model].' (PCB 1.'.($revidec & 15).$manuf.')'.$oldmachend);
} else {
$this->sys->setMachine('Raspberry Pi (PCB 1.'.($revidec & 15).$manuf.')');
$this->sys->setMachine('Raspberry Pi (PCB 1.'.($revidec & 15).$manuf.')'.$oldmachend);
}
}
} else {
if ($this->sys->getMachine() === '') {
if (($oldmach === '') || ($oldmachend !== '')) {
if (isset($raslist['old'][$revidec & 0x7fffff])) {
$this->sys->setMachine('Raspberry Pi '.$raslist['old'][$revidec & 0x7fffff]);
$this->sys->setMachine('Raspberry Pi '.$raslist['old'][$revidec & 0x7fffff].$oldmachend);
} else {
$this->sys->setMachine('Raspberry Pi');
$this->sys->setMachine('Raspberry Pi'.$oldmachend);
}
}
}
1119,52 → 1176,54
*
* @return void
*/
protected function _usb()
protected function _usb($bufu = null)
{
$usbarray = array();
if (CommonFunctions::executeProgram('lsusb', (PSI_OS != 'Android')?'':'2>/dev/null', $bufr, PSI_DEBUG && (PSI_OS != 'Android'), 5) && ($bufr !== "")) {
$bufe = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
foreach ($bufe as $buf) {
$device = preg_split("/ /", $buf, 7);
if (((isset($device[6]) && trim($device[6]) != "")) ||
((isset($device[5]) && trim($device[5]) != ""))) {
$usbid = intval($device[1]).'-'.intval(trim($device[3], ':')).' '.$device[5];
if ((isset($device[6]) && trim($device[6]) != "")) {
$usbarray[$usbid]['name'] = trim($device[6]);
} else {
$usbarray[$usbid]['name'] = 'unknown';
if ($nobufu = ($bufu === null)) {
if (CommonFunctions::executeProgram('lsusb', (PSI_OS != 'Android')?'':'2>/dev/null', $bufr, PSI_DEBUG && (PSI_OS != 'Android'), 5) && ($bufr !== "")) {
$bufe = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
foreach ($bufe as $buf) {
$device = preg_split("/ /", $buf, 7);
if (((isset($device[6]) && trim($device[6]) != "")) ||
((isset($device[5]) && trim($device[5]) != ""))) {
$usbid = intval($device[1]).'-'.intval(trim($device[3], ':')).' '.$device[5];
if ((isset($device[6]) && trim($device[6]) != "")) {
$usbarray[$usbid]['name'] = trim($device[6]);
} else {
$usbarray[$usbid]['name'] = 'unknown';
}
}
}
}
}
 
$usbdevices = CommonFunctions::findglob('/sys/bus/usb/devices/*/idProduct', GLOB_NOSORT);
if (is_array($usbdevices) && (($total = count($usbdevices)) > 0)) {
for ($i = 0; $i < $total; $i++) {
if (CommonFunctions::rfts($usbdevices[$i], $idproduct, 1, 4096, false) && (($idproduct=trim($idproduct)) != "")) { // is readable
$busnum = CommonFunctions::rolv($usbdevices[$i], '/\/idProduct$/', '/busnum');
$devnum = CommonFunctions::rolv($usbdevices[$i], '/\/idProduct$/', '/devnum');
$idvendor = CommonFunctions::rolv($usbdevices[$i], '/\/idProduct$/', '/idVendor');
if (($busnum!==null) && ($devnum!==null) && ($idvendor!==null)) {
$usbid = intval($busnum).'-'.intval($devnum).' '.$idvendor.':'.$idproduct;
$manufacturer = CommonFunctions::rolv($usbdevices[$i], '/\/idProduct$/', '/manufacturer');
if ($manufacturer!==null) {
$usbarray[$usbid]['manufacturer'] = $manufacturer;
}
$product = CommonFunctions::rolv($usbdevices[$i], '/\/idProduct$/', '/product');
if ($product!==null) {
$usbarray[$usbid]['product'] = $product;
}
$speed = CommonFunctions::rolv($usbdevices[$i], '/\/idProduct$/', '/speed');
if ($product!==null) {
$usbarray[$usbid]['speed'] = $speed;
}
if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS
&& defined('PSI_SHOW_DEVICES_SERIAL') && PSI_SHOW_DEVICES_SERIAL) {
$serial = CommonFunctions::rolv($usbdevices[$i], '/\/idProduct$/', '/serial');
if (($serial!==null) && !preg_match('/\W/', $serial)) {
$usbarray[$usbid]['serial'] = $serial;
$usbdevices = CommonFunctions::findglob('/sys/bus/usb/devices/*/idProduct', GLOB_NOSORT);
if (is_array($usbdevices) && (($total = count($usbdevices)) > 0)) {
for ($i = 0; $i < $total; $i++) {
if (CommonFunctions::rfts($usbdevices[$i], $idproduct, 1, 4096, false) && (($idproduct=trim($idproduct)) != "")) { // is readable
$busnum = CommonFunctions::rolv($usbdevices[$i], '/\/idProduct$/', '/busnum');
$devnum = CommonFunctions::rolv($usbdevices[$i], '/\/idProduct$/', '/devnum');
$idvendor = CommonFunctions::rolv($usbdevices[$i], '/\/idProduct$/', '/idVendor');
if (($busnum!==null) && ($devnum!==null) && ($idvendor!==null)) {
$usbid = intval($busnum).'-'.intval($devnum).' '.$idvendor.':'.$idproduct;
$manufacturer = CommonFunctions::rolv($usbdevices[$i], '/\/idProduct$/', '/manufacturer');
if ($manufacturer!==null) {
$usbarray[$usbid]['manufacturer'] = $manufacturer;
}
$product = CommonFunctions::rolv($usbdevices[$i], '/\/idProduct$/', '/product');
if ($product!==null) {
$usbarray[$usbid]['product'] = $product;
}
$speed = CommonFunctions::rolv($usbdevices[$i], '/\/idProduct$/', '/speed');
if ($product!==null) {
$usbarray[$usbid]['speed'] = $speed;
}
if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS
&& defined('PSI_SHOW_DEVICES_SERIAL') && PSI_SHOW_DEVICES_SERIAL) {
$serial = CommonFunctions::rolv($usbdevices[$i], '/\/idProduct$/', '/serial');
if (($serial!==null) && !preg_match('/\W/', $serial)) {
$usbarray[$usbid]['serial'] = $serial;
}
}
}
}
}
1171,9 → 1230,9
}
}
 
if ((count($usbarray) == 0) && CommonFunctions::rfts('/proc/bus/usb/devices', $bufr, 0, 4096, false)) { // usb-devices
if (!$nobufu || ((count($usbarray) == 0) && CommonFunctions::rfts('/proc/bus/usb/devices', $bufu, 0, 4096, false))) { // usb-devices
$devnum = -1;
$bufe = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
$bufe = preg_split("/\n/", $bufu, -1, PREG_SPLIT_NO_EMPTY);
foreach ($bufe as $buf) {
if (preg_match('/^T/', $buf)) {
$devnum++;
1202,7 → 1261,7
}
}
 
if ((count($usbarray) == 0) && CommonFunctions::rfts('/proc/bus/input/devices', $bufr, 0, 4096, false)) {
if ($nobufu && (count($usbarray) == 0) && CommonFunctions::rfts('/proc/bus/input/devices', $bufr, 0, 4096, false)) {
$devnam = "unknown";
$bufe = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
foreach ($bufe as $buf) {
1375,9 → 1434,9
*
* @return void
*/
protected function _network()
protected function _network($bufr = null)
{
if (CommonFunctions::rfts('/proc/net/dev', $bufr, 0, 4096, PSI_DEBUG)) {
if (($bufr === null) && CommonFunctions::rfts('/proc/net/dev', $bufr, 0, 4096, PSI_DEBUG)) {
$bufe = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
foreach ($bufe as $buf) {
if (preg_match('/:/', $buf)) {
1420,7 → 1479,8
|| preg_match('/^'.trim($dev_name).':\s+ip\s+(\S+)\s+mask/i', $buf2, $ar_buf2)
|| preg_match('/^\s+inet6\saddr:\s([^\/\s]+)(.+)\s+Scope:[GH]/i', $buf2, $ar_buf2)
|| preg_match('/^\s+inet6\s+(\S+)\s+prefixlen(.+)((<global>)|(<host>))/i', $buf2, $ar_buf2)
|| preg_match('/^\s+inet6?\s+([^\/\s]+).*\s+scope\s((global)|(host))/i', $buf2, $ar_buf2))
|| preg_match('/^\s+inet6?\s+([^\/\s]+).*\s+scope\s((global)|(host))/i', $buf2, $ar_buf2)
|| preg_match('/^\s+inet\saddr6:\s+(\S+)\s+prefixlen(.+)/i', $buf2, $ar_buf2))
&& ($ar_buf2[1]!="::") && !preg_match('/^fe80::/i', $ar_buf2[1])) {
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').strtolower($ar_buf2[1]));
}
1447,7 → 1507,7
$this->sys->setNetDevices($dev);
}
}
} elseif (CommonFunctions::executeProgram('ip', 'addr show', $bufr, PSI_DEBUG) && ($bufr!="")) {
} elseif (($bufr === null) && CommonFunctions::executeProgram('ip', 'addr show', $bufr, PSI_DEBUG) && ($bufr!="")) {
$lines = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
$was = false;
$macaddr = "";
1526,7 → 1586,7
}
$this->sys->setNetDevices($dev);
}
} elseif (CommonFunctions::executeProgram('ifconfig', '-a', $bufr, PSI_DEBUG)) {
} elseif (($bufr !== null) || CommonFunctions::executeProgram('ifconfig', '-a', $bufr, PSI_DEBUG)) {
$lines = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
$was = false;
$errors = 0;
1617,7 → 1677,8
} elseif ((preg_match('/^\s+inet\saddr:(\S+)/i', $line, $ar_buf2)
|| preg_match('/^\s+inet\s+(\S+)\s+netmask/i', $line, $ar_buf2)
|| preg_match('/^\s+inet6\saddr:\s([^\/\s]+)(.+)\s+Scope:[GH]/i', $line, $ar_buf2)
|| preg_match('/^\s+inet6\s+(\S+)\s+prefixlen(.+)((<global>)|(<host>))/i', $line, $ar_buf2))
|| preg_match('/^\s+inet6\s+(\S+)\s+prefixlen(.+)((<global>)|(<host>))/i', $line, $ar_buf2)
|| preg_match('/^\s+inet\saddr6:\s+(\S+)\s+prefixlen(.+)/i', $line, $ar_buf2))
&& ($ar_buf2[1]!="::") && !preg_match('/^fe80::/i', $ar_buf2[1])) {
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').strtolower($ar_buf2[1]));
}
1644,9 → 1705,9
*
* @return void
*/
protected function _memory()
protected function _memory($mbuf = null, $sbuf = null)
{
if (CommonFunctions::rfts('/proc/meminfo', $mbuf)) {
if (($mbuf !== null) || CommonFunctions::rfts('/proc/meminfo', $mbuf)) {
$swaptotal = null;
$swapfree = null;
$bufe = preg_split("/\n/", $mbuf, -1, PREG_SPLIT_NO_EMPTY);
1670,7 → 1731,7
if (($this->sys->getMemCache() !== null) && ($this->sys->getMemBuffer() !== null)) {
$this->sys->setMemApplication($this->sys->getMemUsed() - $this->sys->getMemCache() - $this->sys->getMemBuffer());
}
if (CommonFunctions::rfts('/proc/swaps', $sbuf, 0, 4096, false)) {
if (($sbuf !== null) || CommonFunctions::rfts('/proc/swaps', $sbuf, 0, 4096, false)) {
$swaps = preg_split("/\n/", $sbuf, -1, PREG_SPLIT_NO_EMPTY);
unset($swaps[0]);
foreach ($swaps as $swap) {
1699,7 → 1760,7
*
* @return void
*/
private function _filesystems()
protected function _filesystems()
{
$df_args = "";
$hideFstypes = array();
2039,6 → 2100,26
$this->sys->setDistribution(trim($buf));
}
}
} elseif (CommonFunctions::fileexists($filename="/etc/slackware-version")) {
if (!CommonFunctions::rfts($filename, $buf, 1, 4096, false)) {
$buf = "";
}
if (isset($list['Slackware']['Image'])) {
$this->sys->setDistributionIcon($list['Slackware']['Image']);
}
if (isset($list['Slackware']['Name'])) {
if (($buf === null) || (trim($buf) == "")) {
$this->sys->setDistribution($list['Slackware']['Name']);
} else {
$this->sys->setDistribution($list['Slackware']['Name']." ".trim($buf));
}
} else {
if (($buf === null) || (trim($buf) == "")) {
$this->sys->setDistribution('Slackware');
} else {
$this->sys->setDistribution(trim($buf));
}
}
} elseif (CommonFunctions::fileexists($filename="/etc/config/uLinux.conf")
&& CommonFunctions::rfts($filename, $buf, 0, 4096, false)
&& preg_match("/^Rsync\sModel\s*=\s*QNAP/m", $buf)
/web/acc/phpsysinfo/includes/os/class.OS.inc.php
52,6 → 52,7
$this->error = PSI_Error::singleton();
$this->sys = new System();
$this->blockname = $blockname;
$this->sys->setOS(get_class($this));
}
 
/**
/web/acc/phpsysinfo/includes/os/class.SSH.inc.php
0,0 → 1,848
<?php
/**
* SSH Class
*
* PHP version 5
*
* @category PHP
* @package PSI SSH class
* @author Mieczyslaw Nalewaj <namiltd@users.sourceforge.net>
* @copyright 2012 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License version 2, or (at your option) any later version
* @version SVN: $Id: class.SSH.inc.php 687 2012-09-06 20:54:49Z namiltd $
* @link http://phpsysinfo.sourceforge.net
*/
/**
* SSH sysinfo class
* get all the required information from SSH
*
* @category PHP
* @package PSI SSH class
* @author Mieczyslaw Nalewaj <namiltd@users.sourceforge.net>
* @copyright 2022 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License version 2, or (at your option) any later version
* @version Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
class SSH extends GNU
{
/**
* content of the system status
*
* @var string
*/
private $_sysstatus = null;
 
/**
* content of the system performance status
*
* @var string
*/
private $_sysperformance = null;
 
/**
* content of the sys ver systeminfo
*
* @var string
*/
private $_sysversysteminfo = null;
 
/**
* content of the show status
*
* @var string
*/
private $_showstatus = null;
 
/**
* OS type
*
* @var string
*/
private $_ostype = null;
 
/**
* check system type
*/
public function __construct($blockname = false)
{
parent::__construct($blockname);
$this->_ostype = $this->sys->getOS();
switch ($this->_ostype) {
case '4.2BSD':
case 'AIX':
case 'Darwin':
case 'DragonFly':
case 'FreeBSD':
case 'HI-UX/MPP':
case 'Haiku':
case 'Minix':
case 'NetBSD':
case 'OpenBSD':
case 'QNX':
case 'SunOS':
$this->error->addError("__construct()", "OS ".$this->_ostype. " is not supported via SSH");
break;
case 'GNU':
case 'Linux':
break;
default:
if ($this->getSystemStatus() !== '') {
$this->_ostype = 'FortiOS';
$this->sys->setOS('Linux');
} elseif ($this->getSysVerSysteminfo() !== '') {
$this->_ostype = 'DrayOS';
$this->sys->setOS('DrayOS');
}
}
}
 
/**
* get os specific encoding
*
* @see PSI_Interface_OS::getEncoding()
*
* @return string
*/
public function getEncoding()
{
// if (($this->_ostype === 'FortiOS') || ($this->_ostype === 'DrayOS') || ($this->_ostype === 'SSH')) {
// return 'UTF-8';
// }
//return null;
}
 
/**
* get os specific language
*
* @see PSI_Interface_OS::getLanguage()
*
* @return string
*/
public function getLanguage()
{
//return null;
}
 
private function getSystemStatus()
{
if ($this->_sysstatus === null) {
if (CommonFunctions::executeProgram('get', 'system status', $resulte, false) && ($resulte !== "")
&& preg_match('/^(.*[\$#]\s*)/', $resulte, $resulto, PREG_OFFSET_CAPTURE)) {
$this->_sysstatus = substr($resulte, strlen($resulto[1][0]));
} else {
$this->_sysstatus = '';
}
}
 
return $this->_sysstatus;
}
 
private function getSystemPerformance()
{
if ($this->_sysperformance === null) {
if (CommonFunctions::executeProgram('get', 'system performance status', $resulte, false) && ($resulte !== "")
&& preg_match('/^(.*[\$#]\s*)/', $resulte, $resulto, PREG_OFFSET_CAPTURE)) {
$this->_sysperformance = substr($resulte, strlen($resulto[1][0]));
} else {
$this->_sysperformance = '';
}
}
 
return $this->_sysperformance;
}
 
private function getSysVerSysteminfo()
{
if ($this->_sysversysteminfo === null) {
if (CommonFunctions::executeProgram('sys', 'ver systeminfo', $resulte, false, PSI_EXEC_TIMEOUT_INT, '>') && ($resulte !== "")
&& preg_match('/([\s\S]+> sys ver systeminfo)/', $resulte, $resulto, PREG_OFFSET_CAPTURE)) {
$this->_sysversysteminfo = substr($resulte, strlen($resulto[1][0]));
} else {
$this->_sysversysteminfo = '';
}
}
 
return $this->_sysversysteminfo;
}
 
private function getShowStatus()
{
if ($this->_showstatus === null) {
if (CommonFunctions::executeProgram('show', 'status', $resulte, false, PSI_EXEC_TIMEOUT_INT, '>') && ($resulte !== "")
&& preg_match('/([\s\S]+> show status)/', $resulte, $resulto, PREG_OFFSET_CAPTURE)) {
$this->_showstatus = substr($resulte, strlen($resulto[1][0]));
} else {
$this->_showstatus = '';
}
}
 
return $this->_showstatus;
}
/**
* Physical memory information and Swap Space information
*
* @return void
*/
protected function _memory($mbuf = null, $sbuf = null)
{
switch ($this->_ostype) {
case 'FortiOS':
if (CommonFunctions::executeProgram('get', 'hardware memory', $resulte, false) && ($resulte !== "")
&& preg_match('/^(.*[\$#]\s*)/', $resulte, $resulto, PREG_OFFSET_CAPTURE)) {
parent::_memory(substr($resulte, strlen($resulto[1][0])));
}
break;
case 'DrayOS':
if (($sysstat = $this->getSysVerSysteminfo()) !== '') {
$machine= '';
if (preg_match("/ Total memory usage : \d+ % \((\d+)K\/(\d+)K\)/", $sysstat, $buf)) {
$this->sys->setMemTotal($buf[2]*1024);
$this->sys->setMemUsed($buf[1]*1024);
$this->sys->setMemFree(($buf[2]-$buf[1])*1024);
}
}
break;
case 'GNU':
case 'Linux':
if (!CommonFunctions::executeProgram('cat', '/proc/meminfo', $mbuf, false) || ($mbuf === "")) {
$mbuf = null;
}
if (!CommonFunctions::executeProgram('cat', '/proc/swaps', $sbuf, false) || ($sbuf === "")) {
$sbuf = null;
}
if (($mbuf !== null) || ($sbuf !== null)) {
parent::_memory($mbuf, $sbuf);
}
}
 
}
 
/**
* USB devices
*
* @return void
*/
protected function _usb($bufu = null)
{
switch ($this->_ostype) {
case 'FortiOS':
$bufr = '';
if (CommonFunctions::executeProgram('fnsysctl', 'cat /proc/bus/usb/devices', $resulte, false) && ($resulte !== "")
&& preg_match('/^(.*[\$#]\s*)/', $resulte, $resulto, PREG_OFFSET_CAPTURE)) {
$resulti = substr($resulte, strlen($resulto[1][0]));
if (preg_match('/(\n.*[\$#])$/', $resulti, $resulto, PREG_OFFSET_CAPTURE)) {
$bufr = substr($resulti, 0, $resulto[1][1]);
if (count(preg_split('/\n/', $bufr, -1, PREG_SPLIT_NO_EMPTY)) >= 2) {
parent::_usb($bufr);
}
}
}
break;
case 'GNU':
case 'Linux':
parent::_usb();
}
}
 
/**
* Network devices
* includes also rx/tx bytes
*
* @return void
*/
protected function _network($bufr = null)
{
switch ($this->_ostype) {
case 'FortiOS':
$bufr = '';
if (CommonFunctions::executeProgram('fnsysctl', 'ifconfig', $resulte, false) && ($resulte !== "")
&& preg_match('/^(.*[\$#]\s*)/', $resulte, $resulto, PREG_OFFSET_CAPTURE)) {
$resulti = substr($resulte, strlen($resulto[1][0]));
if (preg_match('/(\n.*[\$#])$/', $resulti, $resulto, PREG_OFFSET_CAPTURE)) {
$bufr = substr($resulti, 0, $resulto[1][1]);
if (count(preg_split('/\n/', $bufr, -1, PREG_SPLIT_NO_EMPTY)) < 2) {
$bufr = '';
}
}
}
 
if ($bufr !== '') {
parent::_network($bufr);
} else {
$netdevs = array();
if (CommonFunctions::executeProgram('diagnose', 'ip address list', $resulte, false) && ($resulte !== "")
&& preg_match('/^(.*[\$#]\s*)/', $resulte, $resulto, PREG_OFFSET_CAPTURE)) {
$strBuf = substr($resulte, strlen($resulto[1][0]));
$lines = preg_split('/\n/', $strBuf, -1, PREG_SPLIT_NO_EMPTY);
foreach ($lines as $line) if (preg_match('/^IP=(\S+)->.+ devname=(\S+)$/', $line, $buf)) {
if (!isset($netdevs[$buf[2]])) {
$netdevs[$buf[2]] = $buf[1];
} else {
$netdevs[$buf[2]] .= ';'.$buf[1];
}
}
}
if (CommonFunctions::executeProgram('diagnose', 'ipv6 address list', $resulte, false) && ($resulte !== "")
&& preg_match('/^(.*[\$#]\s*)/', $resulte, $resulto, PREG_OFFSET_CAPTURE)) {
$strBuf = substr($resulte, strlen($resulto[1][0]));
$lines = preg_split('/\n/', $strBuf, -1, PREG_SPLIT_NO_EMPTY);
foreach ($lines as $line) if (preg_match('/ devname=(\S+) .+ addr=(\S+)/', $line, $buf)) {
if (!preg_match('/^fe80::/i', $buf[2])) {
if (!isset($netdevs[$buf[1]])) {
$netdevs[$buf[1]] = $buf[2];
} else {
$netdevs[$buf[1]] .= ';'.$buf[2];
}
}
}
}
 
foreach ($netdevs as $netname=>$netinfo) {
if (!preg_match('/^vsys_/i', $netname)) {
$dev = new NetDevice();
// if ($netname === 'root') {
// $dev->setName('lo');
// } else {
$dev->setName($netname);
// }
$this->sys->setNetDevices($dev);
$dev->setInfo($netinfo);
}
}
}
break;
case 'DrayOS':
$macarray = array();
if (defined('PSI_SHOW_NETWORK_INFOS') && (PSI_SHOW_NETWORK_INFOS) && (!defined('PSI_HIDE_NETWORK_MACADDR') || !PSI_HIDE_NETWORK_MACADDR)) {
if (CommonFunctions::executeProgram('sys', 'iface', $resulte, false, PSI_EXEC_TIMEOUT_INT, '>') && ($resulte !== "")
&& preg_match('/([\s\S]+> sys iface)/', $resulte, $resulto, PREG_OFFSET_CAPTURE)) {
$lines = preg_split("/\n/", substr($resulte, strlen($resulto[1][0])), -1, PREG_SPLIT_NO_EMPTY);
$ipaddr = 'LAN';
foreach ($lines as $line) {
if (preg_match("/^IP Address:\s+([\d\.]+)\s/", trim($line), $ar_buf)) {
if ($ipaddr === false) {
$ipaddr = $ar_buf[1];
}
} elseif (preg_match("/^MAC:\s+([\d\-A-F]+)/", trim($line), $ar_buf)) {
if ($ipaddr !== '0.0.0.0') {
$macarray[$ipaddr] = $ar_buf[1];
}
$ipaddr = false;
}
}
}
}
 
$lantxrate = false;
$lanrxrate = false;
if (defined('PSI_SHOW_NETWORK_ACTIVE_SPEED') && PSI_SHOW_NETWORK_ACTIVE_SPEED) {
if ((($bufr = $this->getShowStatus()) !== '') && preg_match('/IP Address:[\d\.]+[ ]+Tx Rate:(\d+)[ ]+Rx Rate:(\d+)/m', $bufr, $ar_buf)) {
$lantxrate = $ar_buf[1];
$lanrxrate = $ar_buf[2];
}
}
 
$notwaslan = true;
if (CommonFunctions::executeProgram('show', 'lan', $resulte, false, PSI_EXEC_TIMEOUT_INT, '>') && ($resulte !== "")
&& preg_match('/([\s\S]+> show lan)/', $resulte, $resulto, PREG_OFFSET_CAPTURE)) {
$lines = preg_split("/\n/", substr($resulte, strlen($resulto[1][0])), -1, PREG_SPLIT_NO_EMPTY);
foreach ($lines as $line) {
if (preg_match("/^\[V\](\S+)\s+([\d\.]+)\s/", trim($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]);
if (isset($macarray['LAN'])) {
$dev->setInfo($macarray['LAN'].';'.$ar_buf[2]);
} else {
$dev->setInfo($ar_buf[2]);
}
}
if ($lantxrate !== false) {
$dev->setTxRate($lantxrate);
}
if ($lanrxrate !== false) {
$dev->setRxRate($lanrxrate);
}
$this->sys->setNetDevices($dev);
if (preg_match('/^LAN/', $ar_buf[1])) {
$notwaslan = false;
}
}
}
}
if (($bufr = $this->getShowStatus()) !== '') {
$lines = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
$last = false;
$dev = null;
foreach ($lines as $line) {
if (preg_match("/^(.+) Status/", trim($line), $ar_buf)) {
if (($last !== false) && (($last !== 'LAN') || $notwaslan)) {
$this->sys->setNetDevices($dev);
}
$dev = new NetDevice();
$last = preg_replace('/\s+/', '', $ar_buf[1]);
$dev->setName($last);
} else {
if ($last !== false) {
if (preg_match('/ IP:([\d\.]+)[ ]+GW/', $line, $ar_buf) || preg_match('/IP Address:([\d\.]+)[ ]+Tx/', $line, $ar_buf)) {
if (defined('PSI_SHOW_NETWORK_INFOS') && (PSI_SHOW_NETWORK_INFOS)) {
if ($last === 'LAN') {
if (isset($macarray['LAN'])) {
$dev->setInfo($macarray['LAN'].';'.$ar_buf[1]);
}
if ($lantxrate !== false) {
$dev->setTxRate($lantxrate);
}
if ($lanrxrate !== false) {
$dev->setRxRate($lanrxrate);
}
} elseif (isset($macarray[$ar_buf[1]])) {
$dev->setInfo($macarray[$ar_buf[1]].';'.$ar_buf[1]);
} else {
$dev->setInfo($ar_buf[1]);
}
}
} elseif (preg_match('/TX Packets:\d+[ ]+TX Rate\(bps\):(\d+)[ ]+RX Packets:\d+[ ]+RX Rate\(bps\):(\d+)/', $line, $ar_buf)) {
if (defined('PSI_SHOW_NETWORK_ACTIVE_SPEED') && PSI_SHOW_NETWORK_ACTIVE_SPEED) {
$dev->setTxRate($ar_buf[1]);
$dev->setRxRate($ar_buf[2]);
}
}
}
}
}
if (($last !== false) && (($last !== 'LAN') || $notwaslan)) {
$this->sys->setNetDevices($dev);
}
}
break;
case 'GNU':
case 'Linux':
parent::_network();
}
}
 
/**
* CPU information
* All of the tags here are highly architecture dependant.
*
* @return void
*/
protected function _cpuinfo($bufr = null)
{
switch ($this->_ostype) {
case 'FortiOS':
if (CommonFunctions::executeProgram('get', 'hardware cpu', $resulte, false) && ($resulte !== "")
&& preg_match('/^(.*[\$#]\s*)/', $resulte, $resulto, PREG_OFFSET_CAPTURE)) {
parent::_cpuinfo(substr($resulte, strlen($resulto[1][0])));
}
break;
case 'DrayOS':
if (preg_match_all("/CPU(\d+) speed:[ ]*(\d+) MHz/m", $sysinfo = $this->getSysVerSysteminfo(), $bufarr)) {
foreach ($bufarr[1] as $index=>$nr) {
$dev = new CpuDevice();
$dev->setModel('CPU'.$nr);
$dev->setCpuSpeed($bufarr[2][$index]);
if (PSI_LOAD_BAR) {
$dev->setLoad($this->_parseProcStat('cpu'.$nr));
}
$this->sys->setCpus($dev);
}
// $this->_cpu_loads['cpu'] = $buf[1];
// if (preg_match("/CPU1 speed/", $sysinfo)) {
// $this->_cpu_loads['cpu0'] = $buf[1];
// }
}
break;
case 'GNU':
case 'Linux':
if (CommonFunctions::executeProgram('cat', '/proc/cpuinfo', $resulte, false) && ($resulte !== "")) {
parent::_cpuinfo($resulte);
}
}
}
 
/**
* Machine
*
* @return void
*/
protected function _machine()
{
switch ($this->_ostype) {
case 'FortiOS':
if (($sysstat = $this->getSystemStatus()) !== '') {
$machine= '';
if (preg_match("/^Version: (\S+) v/", $sysstat, $buf)) {
$machine = $buf[1];
}
if (preg_match("/\nSystem Part-Number: (\S+)\n/", $sysstat, $buf)) {
$machine .= ' '.$buf[1];
}
if (preg_match("/\nBIOS version: (\S+)\n/", $sysstat, $buf)) {
if (trim($machine) !== '') {
$machine .= ', BIOS '.$buf[1];
} else {
$machine = 'BIOS '.$buf[1];
}
}
$machine = trim($machine);
 
if ($machine !== '') {
$this->sys->setMachine($machine);
}
}
break;
case 'DrayOS':
if (($sysstat = $this->getSysVerSysteminfo()) !== '') {
$machine= '';
if (preg_match("/[\r\n]Router Model: (\S+) /", $sysstat, $buf)) {
$machine = $buf[1];
}
if (preg_match("/[\r\n]Revision: (.+)[\r\n]/", $sysstat, $buf)) {
$machine .= ' '.$buf[1];
}
$machine = trim($machine);
 
if ($machine !== '') {
$this->sys->setMachine($machine);
}
}
break;
 
case 'GNU':
case 'Linux':
parent::_machine();
}
}
 
/**
* Hostname
*
* @return void
*/
protected function _hostname()
{
switch ($this->_ostype) {
case 'FortiOS':
// $hostname = PSI_EMU_HOSTNAME;
if (preg_match("/\nHostname: ([^\n]+)\n/", $this->getSystemStatus(), $buf)) {
$this->sys->setHostname(trim($buf[1]));
// $hostname = trim($buf[1]);
}
 
// $ip = gethostbyname($hostname);
// if ($ip != $hostname) {
// $this->sys->setHostname(gethostbyaddr($ip));
// } else {
// $this->sys->setHostname($hostname);
// }
break;
case 'DrayOS':
if (preg_match("/[\r\n]Router Name: ([^\n\r]+)[\r\n]/", $this->getSysVerSysteminfo(), $buf)) {
$this->sys->setHostname(trim($buf[1]));
}
break;
case 'GNU':
case 'Linux':
parent::_hostname();
}
 
}
 
/**
* filesystem information
*
* @return void
*/
protected function _filesystems()
{
switch ($this->_ostype) {
case 'FortiOS':
if (CommonFunctions::executeProgram('fnsysctl', 'df -k', $resulte, false) && ($resulte !== "")
&& preg_match('/^(.*[\$#]\s*)/', $resulte, $resulto, PREG_OFFSET_CAPTURE)) {
$resulti = substr($resulte, $resulto[1][1]);
$df = preg_split("/\n/", $resulti, -1, PREG_SPLIT_NO_EMPTY);
foreach ($df as $df_line) {
$df_buf1 = preg_split("/(\%\s)/", $df_line, 3);
if (count($df_buf1) != 2) {
continue;
}
if (preg_match("/(.*)(\s+)(([0-9]+)(\s+)([0-9]+)(\s+)([\-0-9]+)(\s+)([0-9]+)$)/", $df_buf1[0], $df_buf2)) {
$df_buf = array($df_buf2[1], $df_buf2[4], $df_buf2[6], $df_buf2[8], $df_buf2[10], $df_buf1[1]);
if (count($df_buf) == 6) {
$df_buf[5] = trim($df_buf[5]);
$dev = new DiskDevice();
$dev->setName(trim($df_buf[0]));
if ($df_buf[2] < 0) {
$dev->setTotal($df_buf[3] * 1024);
$dev->setUsed($df_buf[3] * 1024);
} else {
$dev->setTotal($df_buf[1] * 1024);
$dev->setUsed($df_buf[2] * 1024);
if ($df_buf[3]>0) {
$dev->setFree($df_buf[3] * 1024);
}
}
if (PSI_SHOW_MOUNT_POINT) $dev->setMountPoint($df_buf[5]);
$dev->setFsType('unknown');
$this->sys->setDiskDevices($dev);
}
}
}
}
break;
case 'DrayOS':
if (CommonFunctions::executeProgram('nand', 'usage', $resulte, false, PSI_EXEC_TIMEOUT_INT, '>') && ($resulte !== "")
&& preg_match('/([\s\S]+> nand usage)/', $resulte, $resulto, PREG_OFFSET_CAPTURE)) {
$df = substr($resulte, strlen($resulto[1][0]));
 
if (preg_match('/Usecfg/', $df)) { // fix for Vigor2135ac v4.4.2
$df = preg_replace("/(cfg|bin)/", "\n$1", substr($resulte, strlen($resulto[1][0])));
$percent = '';
} else {
$percent = '%';
}
 
$df = preg_split("/\n/", $df, -1, PREG_SPLIT_NO_EMPTY);
foreach ($df as $df_line) {
if (preg_match("/^(\S+)[ ]+(\d+)[ ]+(\d+)[ ]+(\d+)[ ]+(\d+)".$percent."/", trim($df_line), $df_buf)) {
$dev = new DiskDevice();
$dev->setName($df_buf[1]);
$dev->setTotal($df_buf[2]);
$dev->setUsed($df_buf[3]);
$dev->setFree($df_buf[4]);
$dev->setFsType('NAND');
$this->sys->setDiskDevices($dev);
}
}
}
break;
case 'GNU':
case 'Linux':
parent::_filesystems();
}
}
 
/**
* Distribution
*
* @return void
*/
protected function _distro()
{
switch ($this->_ostype) {
case 'FortiOS':
if (preg_match("/^Version: \S+ (v[^\n]+)\n/", $this->getSystemStatus(), $buf)) {
$this->sys->setDistribution('FortiOS '.trim($buf[1]));
}
$this->sys->setDistributionIcon('FortiOS.png');
break;
case 'DrayOS':
if (preg_match("/ Version: ([^\n]+)\n/", $this->getSysVerSysteminfo(), $buf)) {
$this->sys->setDistribution('DrayOS '.trim($buf[1]));
}
$this->sys->setDistributionIcon('DrayOS.png');
break;
case 'GNU':
case 'Linux':
parent::_distro();
}
// if ($this->_ostype !== null) {
// $this->sys->setDistributionIcon($this->_ostype);
// }
}
 
/**
* fill the load for a individual cpu, through parsing /proc/stat for the specified cpu
*
* @param String $cpuline cpu for which load should be meassured
*
* @return int
*/
protected function _parseProcStat($cpuline)
{
if ($this->_cpu_loads === null) {
$this->_cpu_loads = array();
switch ($this->_ostype) {
case 'FortiOS':
if (($strBuf = $this->getSystemPerformance()) !== '') {
$lines = preg_split('/\n/', $strBuf, -1, PREG_SPLIT_NO_EMPTY);
foreach ($lines as $line) if (preg_match('/^CPU(\d*) states: \d+% user \d+% system \d+% nice (\d+)% idle /', $line, $buf)) {
$this->_cpu_loads['cpu'.$buf[1]] = 100-$buf[2];
}
}
break;
case 'DrayOS':
if (preg_match("/CPU usage :[ ]*(\d+) %/", $sysinfo = $this->getSysVerSysteminfo(), $buf)) {
$this->_cpu_loads['cpu'] = $buf[1];
if (preg_match("/CPU1 speed/", $sysinfo) && !preg_match("/CPU2 speed/", $sysinfo)) { //only one cpu
$this->_cpu_loads['cpu1'] = $buf[1];
}
}
}
}
if (isset($this->_cpu_loads[$cpuline])) {
return $this->_cpu_loads[$cpuline];
} else {
return null;
}
}
 
/**
* Processor Load
* optionally create a loadbar
*
* @return void
*/
protected function _loadavg($bufr = null)
{
switch ($this->_ostype) {
case 'FortiOS':
if (CommonFunctions::executeProgram('fnsysctl', 'cat /proc/loadavg', $resulte, false) && ($resulte !== "")
&& preg_match('/^(.*[\$#]\s*)/', $resulte, $resulto, PREG_OFFSET_CAPTURE)) {
parent::_loadavg(substr($resulte, strlen($resulto[1][0])));
}
break;
case 'DrayOS':
if (PSI_LOAD_BAR) {
$this->sys->setLoadPercent($this->_parseProcStat('cpu'));
}
break;
case 'GNU':
case 'Linux':
parent::_loadavg();
}
}
 
/**
* UpTime
* time the system is running
*
* @return void
*/
protected function _uptime($bufu = null)
{
switch ($this->_ostype) {
case 'FortiOS':
if (preg_match("/\nUptime: ([^\n]+)\n/", $this->getSystemPerformance(), $buf)) {
parent::_uptime('up '.trim($buf[1]));
}
break;
case 'DrayOS':
if (preg_match("/System Uptime:([\d:]+)/", $this->getShowStatus(), $buf)) {
parent::_uptime('up '.trim($buf[1]));
}
break;
case 'GNU':
case 'Linux':
if (CommonFunctions::executeProgram('cat', '/proc/uptime', $resulte, false) && ($resulte !== "")) {
$ar_buf = preg_split('/ /', $resulte);
$this->sys->setUptime(trim($ar_buf[0]));
} else {
parent::_uptime();
}
}
}
 
/**
* Kernel Version
*
* @return void
*/
protected function _kernel()
{
switch ($this->_ostype) {
case 'FortiOS':
if (CommonFunctions::executeProgram('fnsysctl', 'cat /proc/version', $resulte, false) && ($resulte !== "")
&& preg_match('/^(.*[\$#]\s*)/', $resulte, $resulto, PREG_OFFSET_CAPTURE)) {
$strBuf = substr($resulte, $resulto[1][1]);
if (preg_match('/version\s+(\S+)/', $strBuf, $ar_buf)) {
$verBuf = $ar_buf[1];
if (preg_match('/ SMP /', $strBuf)) {
$verBuf .= ' (SMP)';
}
$this->sys->setKernel($verBuf);
}
}
break;
case 'GNU':
case 'Linux':
parent::_kernel();
}
}
 
/**
* get the information
*
* @return void
*/
public function build()
{
$this->error->addWarning("The SSH version of phpSysInfo is a work in progress, some things currently don't work");
switch ($this->_ostype) {
case 'FortiOS':
if (!$this->blockname || $this->blockname==='vitals') {
$this->_distro();
$this->_hostname();
$this->_kernel();
$this->_uptime();
// $this->_users();
$this->_loadavg();
// $this->_processes();
}
if (!$this->blockname || $this->blockname==='hardware') {
$this->_machine();
$this->_cpuinfo();
//$this->_virtualizer();
// $this->_pci();
$this->_usb();
// $this->_i2c();
}
if (!$this->blockname || $this->blockname==='memory') {
$this->_memory();
}
if (!$this->blockname || $this->blockname==='filesystem') {
$this->_filesystems();
}
if (!$this->blockname || $this->blockname==='network') {
$this->_network();
}
break;
case 'DrayOS':
if (!$this->blockname || $this->blockname==='vitals') {
$this->_distro();
$this->_hostname();
// $this->_kernel();
$this->_uptime();
//// $this->_users();
$this->_loadavg();
//// $this->_processes();
}
if (!$this->blockname || $this->blockname==='hardware') {
$this->_machine();
$this->_cpuinfo();
// //$this->_virtualizer();
//// $this->_pci();
// $this->_usb();
//// $this->_i2c();
}
if (!$this->blockname || $this->blockname==='memory') {
$this->_memory();
}
if (!$this->blockname || $this->blockname==='filesystem') {
$this->_filesystems();
}
if (!$this->blockname || $this->blockname==='network') {
$this->_network();
}
break;
 
case 'GNU':
case 'Linux':
parent::build();
}
}
}