Subversion Repositories ALCASAR

Compare Revisions

Ignore whitespace Rev 3036 → Rev 3037

/web/acc/phpsysinfo/includes/os/class.Linux.inc.php
27,55 → 27,231
class Linux extends OS
{
/**
* Uptime command result.
*/
private $_uptime = null;
 
/**
* Assoc array of all CPUs loads.
*/
private $_cpu_loads = null;
 
/**
* Machine
*
* @return void
* Version string.
*/
private function _machine()
private $_kernel_string = null;
 
/**
* Array of info from Bios.
*/
private $_machine_info = null;
 
/**
* Array of info from dmesg.
*/
private $_dmesg_info = null;
 
/**
* Result of systemd-detect-virt.
*/
private $system_detect_virt = null;
 
/**
* Get info from dmesg
*
* @return array
*/
private function _get_dmesg_info()
{
$machine = "";
if ((CommonFunctions::rfts('/var/log/dmesg', $result, 0, 4096, false)
&& preg_match('/^[\s\[\]\.\d]*DMI:\s*(.*)/m', $result, $ar_buf))
||(CommonFunctions::executeProgram('dmesg', '', $result, false)
&& preg_match('/^[\s\[\]\.\d]*DMI:\s*(.*)/m', $result, $ar_buf))) {
$machine = trim($ar_buf[1]);
} else { //data from /sys/devices/virtual/dmi/id/
$product = "";
$board = "";
$bios = "";
if (CommonFunctions::rfts('/sys/devices/virtual/dmi/id/board_vendor', $buf, 1, 4096, false) && (trim($buf)!="")) {
$machine = trim($buf);
if ($this->_dmesg_info === null) {
$this->_dmesg_info = array();
if (CommonFunctions::rfts('/var/log/dmesg', $result, 0, 4096, false)) {
if (preg_match('/^[\s\[\]\.\d]*DMI:\s*(.+)/m', $result, $ar_buf)) {
$this->_dmesg_info['dmi'] = trim($ar_buf[1]);
}
if (defined('PSI_SHOW_VIRTUALIZER_INFO') && PSI_SHOW_VIRTUALIZER_INFO && ($this->system_detect_virt === null) && preg_match('/^[\s\[\]\.\d]*Hypervisor detected:\s*(.+)/m', $result, $ar_buf)) {
$this->_dmesg_info['hypervisor'] = trim($ar_buf[1]);
}
}
if (CommonFunctions::rfts('/sys/devices/virtual/dmi/id/product_name', $buf, 1, 4096, false) && (trim($buf)!="")) {
$product = trim($buf);
if ((count($this->_dmesg_info) < ((defined('PSI_SHOW_VIRTUALIZER_INFO') && PSI_SHOW_VIRTUALIZER_INFO && ($this->system_detect_virt === null))?2:1)) && CommonFunctions::executeProgram('dmesg', '', $result, false)) {
if (!isset($this->_dmesg_info['dmi']) && preg_match('/^[\s\[\]\.\d]*DMI:\s*(.+)/m', $result, $ar_buf)) {
$this->_dmesg_info['dmi'] = trim($ar_buf[1]);
}
if (defined('PSI_SHOW_VIRTUALIZER_INFO') && PSI_SHOW_VIRTUALIZER_INFO && ($this->system_detect_virt === null) && !isset($this->_dmesg_info['hypervisor']) && preg_match('/^[\s\[\]\.\d]*Hypervisor detected:\s*(.+)/m', $result, $ar_buf)) {
$this->_dmesg_info['hypervisor'] = trim($ar_buf[1]);
}
}
if (CommonFunctions::rfts('/sys/devices/virtual/dmi/id/board_name', $buf, 1, 4096, false) && (trim($buf)!="")) {
$board = trim($buf);
}
 
return $this->_dmesg_info;
}
 
/**
* Get machine info
*
* @return string
*/
private function _get_machine_info()
{
if ($this->_machine_info === null) {
$this->_machine_info = array();
if (defined('PSI_SHOW_VIRTUALIZER_INFO') && PSI_SHOW_VIRTUALIZER_INFO) {
if (CommonFunctions::executeProgram('systemd-detect-virt', '-v', $resultv, false)) {
$this->system_detect_virt = $resultv;
}
}
if (CommonFunctions::rfts('/sys/devices/virtual/dmi/id/bios_version', $buf, 1, 4096, false) && (trim($buf)!="")) {
$bios = trim($buf);
$vendor_array = array();
if ((($dmesg = $this->_get_dmesg_info()) !== null) && isset($dmesg['dmi'])) {
$this->_machine_info['machine'] = $dmesg['dmi'];
if (defined('PSI_SHOW_VIRTUALIZER_INFO') && PSI_SHOW_VIRTUALIZER_INFO && ($this->system_detect_virt === null)) {
/* Test this before sys_vendor to detect KVM over QEMU */
if (CommonFunctions::rfts('/sys/devices/virtual/dmi/id/product_name', $buf, 1, 4096, false) && (trim($buf)!="")) {
$vendor_array[] = $product_name = trim($buf);
} else {
$product_name = '';
}
if (CommonFunctions::rfts('/sys/devices/virtual/dmi/id/sys_vendor', $buf, 1, 4096, false) && (trim($buf)!="")) {
$vendor_array[] = trim($buf);
}
if (CommonFunctions::rfts('/sys/devices/virtual/dmi/id/board_vendor', $buf, 1, 4096, false) && (trim($buf)!="")) {
if ($product_name != "") {
$vendor_array[] = trim($buf)." ".$product_name;
} else {
$vendor_array[] = trim($buf);
}
} else {
$vendor_array[] = $dmesg['dmi'];
}
if (CommonFunctions::rfts('/sys/devices/virtual/dmi/id/bios_vendor', $buf, 1, 4096, false) && (trim($buf)!="")) {
$vendor_array[] = trim($buf);
}
if (CommonFunctions::rfts('/sys/devices/virtual/dmi/id/product_version', $buf, 1, 4096, false) && (trim($buf)!="")) {
$vendor_array[] = trim($buf);
}
}
} else { // 'machine' data from /sys/devices/virtual/dmi/id/
$bios = "";
if (defined('PSI_SHOW_VIRTUALIZER_INFO') && PSI_SHOW_VIRTUALIZER_INFO && ($this->system_detect_virt === null)) {
// Test this before sys_vendor to detect KVM over QEMU
if (CommonFunctions::rfts('/sys/devices/virtual/dmi/id/product_name', $buf, 1, 4096, false) && (trim($buf)!="")) {
$vendor_array[] = $product_name = trim($buf);
} else {
$product_name = '';
}
 
if (CommonFunctions::rfts('/sys/devices/virtual/dmi/id/sys_vendor', $buf, 1, 4096, false) && (trim($buf)!="")) {
$vendor_array[] = trim($buf);
}
if (CommonFunctions::rfts('/sys/devices/virtual/dmi/id/board_vendor', $buf, 1, 4096, false) && (trim($buf)!="")) {
if ($product_name != "") {
$this->_machine_info['machine'] = trim($buf)." ".$product_name;
} else {
$this->_machine_info['machine'] = trim($buf);
}
$vendor_array[] = $this->_machine_info["machine"];
} elseif ($product_name != "") {
$this->_machine_info['machine'] = $product_name;
}
 
if (CommonFunctions::rfts('/sys/devices/virtual/dmi/id/bios_vendor', $buf, 1, 4096, false) && (trim($buf)!="")) {
$vendor_array[] = trim($buf);
}
if (CommonFunctions::rfts('/sys/devices/virtual/dmi/id/product_version', $buf, 1, 4096, false) && (trim($buf)!="")) {
$vendor_array[] = trim($buf);
}
} else {
if (CommonFunctions::rfts('/sys/devices/virtual/dmi/id/board_vendor', $buf, 1, 4096, false) && (trim($buf)!="")) {
$this->_machine_info['machine'] = trim($buf);
}
if (CommonFunctions::rfts('/sys/devices/virtual/dmi/id/product_name', $buf, 1, 4096, false) && (trim($buf)!="")) {
if (isset($this->_machine_info['machine'])) {
$this->_machine_info['machine'] .= " ".trim($buf);
} else {
$this->_machine_info['machine'] = trim($buf);
}
}
}
if (CommonFunctions::rfts('/sys/devices/virtual/dmi/id/board_name', $buf, 1, 4096, false) && (trim($buf)!="")) {
if (isset($this->_machine_info['machine'])) {
$this->_machine_info['machine'] .= "/".trim($buf);
} else {
$this->_machine_info['machine'] = trim($buf);
}
}
if (CommonFunctions::rfts('/sys/devices/virtual/dmi/id/bios_version', $buf, 1, 4096, false) && (trim($buf)!="")) {
$bios = trim($buf);
}
if (CommonFunctions::rfts('/sys/devices/virtual/dmi/id/bios_date', $buf, 1, 4096, false) && (trim($buf)!="")) {
$bios = trim($bios." ".trim($buf));
}
if ($bios != "") {
if (isset($this->_machine_info['machine'])) {
$this->_machine_info['machine'] .= ", BIOS ".$bios;
} else {
$this->_machine_info['machine'] = "BIOS ".$bios;
}
}
}
if (CommonFunctions::rfts('/sys/devices/virtual/dmi/id/bios_date', $buf, 1, 4096, false) && (trim($buf)!="")) {
$bios = trim($bios." ".trim($buf));
if (isset($this->_machine_info['machine'])) {
$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 ($product != "") {
$machine .= " ".$product;
 
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;
}
}
if ($board != "") {
$machine .= "/".$board;
}
 
return $this->_machine_info;
}
 
/**
* Get kernel string
*
* @return string
*/
private function _get_kernel_string()
{
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)) {
$this->_kernel_string = $strBuf;
if (CommonFunctions::executeProgram($uname, '-v', $strBuf, PSI_DEBUG)) {
if (preg_match('/ SMP /', $strBuf)) {
$this->_kernel_string .= ' (SMP)';
}
}
if (CommonFunctions::executeProgram($uname, '-m', $strBuf, PSI_DEBUG)) {
$this->_kernel_string .= ' '.$strBuf;
}
} elseif (CommonFunctions::rfts('/proc/version', $strBuf, 1)) {
if (preg_match('/version\s+(\S+)/', $strBuf, $ar_buf)) {
$this->_kernel_string = $ar_buf[1];
if (preg_match('/ SMP /', $strBuf)) {
$this->_kernel_string .= ' (SMP)';
}
}
}
if ($bios != "") {
$machine .= ", BIOS ".$bios;
}
}
 
if ($machine != "") {
$machine = trim(preg_replace("/^\/,?/", "", preg_replace("/ ?(To be filled by O\.E\.M\.|System manufacturer|System Product Name|Not Specified|Default string) ?/i", "", $machine)));
return $this->_kernel_string;
}
 
/**
* Machine
*
* @return void
*/
private function _machine()
{
$machine_info = $this->_get_machine_info();
if (isset($machine_info['machine'])) {
$machine = $machine_info['machine'];
} else {
$machine = "";
}
 
if (CommonFunctions::fileexists($filename="/etc/config/uLinux.conf") // QNAP detection
84,7 → 260,7
&& CommonFunctions::fileexists($filename="/etc/platform.conf") // Platform detection
&& CommonFunctions::rfts($filename, $buf, 0, 4096, false)
&& preg_match("/^DISPLAY_NAME\s*=\s*(\S+)/m", $buf, $mach_buf) && ($mach_buf[1]!=="")) {
if ($machine != "") {
if ($machine !== "") {
$machine = "QNAP ".$mach_buf[1].' - '.$machine;
} else {
$machine = "QNAP ".$mach_buf[1];
91,7 → 267,7
}
}
 
if ($machine != "") {
if ($machine !== "") {
$this->sys->setMachine($machine);
}
}
103,7 → 279,7
*/
protected function _hostname()
{
if (PSI_USE_VHOST === true) {
if (PSI_USE_VHOST) {
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'))) {
115,7 → 291,6
} elseif (CommonFunctions::executeProgram('hostname', '', $ret)) {
$this->sys->setHostname($ret);
}
 
}
}
 
126,42 → 301,216
*/
private function _kernel()
{
$result = "";
if (CommonFunctions::executeProgram($uname="uptrack-uname", '-r', $strBuf, false) || // show effective kernel if ksplice uptrack is installed
CommonFunctions::executeProgram($uname="uname", '-r', $strBuf, PSI_DEBUG)) {
$result = $strBuf;
if (CommonFunctions::executeProgram($uname, '-v', $strBuf, PSI_DEBUG)) {
if (preg_match('/SMP/', $strBuf)) {
$result .= ' (SMP)';
if (($verBuf = $this->_get_kernel_string()) != "") {
$this->sys->setKernel($verBuf);
}
}
 
/**
* Virtualizer info
*
* @return void
*/
protected function _virtualizer()
{
if (!defined('PSI_SHOW_VIRTUALIZER_INFO') || !PSI_SHOW_VIRTUALIZER_INFO) {
return;
}
if ($this->system_detect_virt !== null) {
if (($this->system_detect_virt !== "") && ($this->system_detect_virt !== "none")) {
$this->sys->setVirtualizer($this->system_detect_virt);
}
if (($verBuf = $this->_get_kernel_string()) !== "") {
if (preg_match('/^[\d\.-]+-microsoft-standard/', $verBuf)) {
$this->sys->setVirtualizer('wsl2', 'wsl'); // Windows Subsystem for Linux 2
}
}
if (CommonFunctions::executeProgram($uname, '-m', $strBuf, PSI_DEBUG)) {
$result .= ' '.$strBuf;
if (CommonFunctions::executeProgram('systemd-detect-virt', '-c', $resultc, false) && ($resultc !== "") && ($resultc !== "none")) {
$this->sys->setVirtualizer($resultc);
}
} elseif (CommonFunctions::rfts('/proc/version', $strBuf, 1) && preg_match('/version\s+(\S+)/', $strBuf, $ar_buf)) {
$result = $ar_buf[1];
if (preg_match('/SMP/', $strBuf)) {
$result .= ' (SMP)';
} else {
$cpuvirt = $this->sys->getVirtualizer(); // previous info from _cpuinfo()
 
$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.
$machine_info = $this->_get_machine_info();
if (isset($machine_info['hypervisor'])) {
$hypervisor = $machine_info['hypervisor'];
if (($hypervisor === 'oracle') || ($hypervisor === 'amazon') || ($hypervisor === 'xen')) {
$this->sys->setVirtualizer($hypervisor);
$novm = false;
}
}
}
if ($result != "") {
 
// Detect UML
if ($novm) {
if (isset($cpuvirt["cpuid:UserModeLinux"])) {
$this->sys->setVirtualizer('uml'); // User-mode Linux
$novm = false;
}
}
 
// Detect Xen
if ($novm && is_dir('/proc/xen')) {
// xen Dom0 is detected as XEN in hypervisor and maybe others.
// In order to detect the Dom0 as not virtualization we need to
// double-check it
if (CommonFunctions::rfts('/sys/hypervisor/properties/features', $features, 1, 4096, false)) {
if ((hexdec($features) & 2048) == 0) { // XENFEAT_dom0 is not set
$this->sys->setVirtualizer('xen'); // Xen hypervisor (only domU, not dom0)
$novm = false;
}
} elseif (CommonFunctions::rfts('/proc/xen/capabilities', $capabilities, 1, 4096, false) && !preg_match('/control_d/', $capabilities)) { // control_d not in capabilities
$this->sys->setVirtualizer('xen'); // Xen hypervisor (only domU, not dom0)
$novm = false;
}
}
 
// Second, try to detect from CPUID, this will report KVM for whatever software is used even if info in DMI is overwritten.
// Since the vendor_id in /proc/cpuinfo is overwritten on virtualization we use values from msr-cpuid.
if ($novm && CommonFunctions::executeProgram('msr-cpuid', '', $bufr, false)
&& (preg_match('/^40000000 00000000: [0-9a-f]{8} \S{4} [0-9a-f]{8} ([A-Za-z0-9\.]{4}) [0-9a-f]{8} ([A-Za-z0-9\.]{4}) [0-9a-f]{8} ([A-Za-z0-9\.]{4})/m', $bufr, $cpuid))) {
$virt = CommonFunctions::decodevirtualizer($cpuid[1].$cpuid[2].$cpuid[3]);
if ($virt !== null) {
$this->sys->setVirtualizer($virt);
}
}
 
// Third, try to detect from DMI.
if ($novm && isset($hypervisor)) {
$this->sys->setVirtualizer($hypervisor);
$novm = false;
}
 
// Check high-level hypervisor sysfs file
if ($novm && CommonFunctions::rfts('/sys/hypervisor/type', $type, 1, 4096, false) && ($type === "xen")) {
$this->sys->setVirtualizer('xen'); // Xen hypervisor
$novm = false;
}
 
if ($novm) {
if (CommonFunctions::rfts('/proc/device-tree/hypervisor/compatible', $compatible, 1, 4096, false)) {
switch ($compatible) {
case 'linux,kvm':
$this->sys->setVirtualizer('kvm'); // KVM
$novm = false;
break;
case 'vmware':
$this->sys->setVirtualizer('vmware'); // VMware
$novm = false;
break;
case 'xen':
$this->sys->setVirtualizer('xen'); // Xen hypervisor
$novm = false;
}
} else {
if (CommonFunctions::fileexists('/proc/device-tree/ibm,partition-name')
&& CommonFunctions::fileexists('/proc/device-tree/hmc-managed?')
&& CommonFunctions::fileexists('/proc/device-tree/chosen/qemu,graphic-width')) {
$this->sys->setVirtualizer('powervm'); // IBM PowerVM hypervisor
$novm = false;
} else {
$names = CommonFunctions::findglob('/proc/device-tree', GLOB_NOSORT);
if (is_array($names) && (($total = count($names)) > 0)) {
for ($i = 0; $i < $total; $i++) {
if (preg_match('/fw-cfg/', $names[$i])) {
$this->sys->setVirtualizer('qemu'); // QEMU
$novm = false;
break;
}
}
}
}
}
}
 
if ($novm && CommonFunctions::rfts('/proc/sysinfo', $sysinfo, 0, 4096, false) && preg_match('//VM00 Control Program:\s*(\S+)/m', $sysinfo, $vcp)) {
if ($vcp[1] === 'z/VM') {
$this->sys->setVirtualizer('zvm'); // s390 z/VM
} else {
$this->sys->setVirtualizer('kvm'); // KVM
}
$novm = false;
}
 
// Additional tests outside of the systemd-detect-virt source code
if ($novm && (($dmesg = $this->_get_dmesg_info()) !== null) && isset($dmesg['hypervisor'])) {
switch ($dmesg['hypervisor']) {
case 'VMware':
$this->sys->setVirtualizer('vmware'); // VMware
$novm = false;
break;
case 'KVM':
$this->sys->setVirtualizer('kvm'); // KVM
$novm = false;
break;
case 'Microsoft HyperV':
case 'Microsoft Hyper-V':
$this->sys->setVirtualizer('microsoft'); // Hyper-V
$novm = false;
break;
case 'ACRN':
$this->sys->setVirtualizer('acrn'); // ACRN hypervisor
$novm = false;
break;
case 'Jailhouse':
$this->sys->setVirtualizer('jailhouse'); // Jailhouse
$novm = false;
break;
case 'Xen':
case 'Xen PV':
case 'Xen HVM':
// xen Dom0 is detected as XEN in hypervisor and maybe others.
// In order to detect the Dom0 as not virtualization we need to
// double-check it
if (CommonFunctions::rfts('/sys/hypervisor/properties/features', $features, 1, 4096, false)) {
if ((hexdec($features) & 2048) == 0) { // XENFEAT_dom0 is not set
$this->sys->setVirtualizer('xen'); // Xen hypervisor (only domU, not dom0)
$novm = false;
}
} elseif (CommonFunctions::rfts('/proc/xen/capabilities', $capabilities, 1, 4096, false) && !preg_match('/control_d/', $capabilities)) { // control_d not in capabilities
$this->sys->setVirtualizer('xen'); // Xen hypervisor (only domU, not dom0)
$novm = false;
}
}
}
 
// Detect QEMU cpu
if ($novm && isset($cpuvirt["cpuid:QEMU"])) {
$this->sys->setVirtualizer('qemu'); // QEMU
$novm = false;
}
 
if ($novm && isset($cpuvirt["hypervisor"])) {
$this->sys->setVirtualizer('unknown');
}
 
if ((count(CommonFunctions::gdc('/proc/vz', false)) == 0) && (count(CommonFunctions::gdc('/proc/bc', false)) > 0)) {
$this->sys->setVirtualizer('openvz'); // OpenVZ/Virtuozzo
}
 
if (($verBuf = $this->_get_kernel_string()) !== "") {
if (preg_match('/^[\d\.-]+-Microsoft/', $verBuf)) {
$this->sys->setVirtualizer('wsl'); // Windows Subsystem for Linux
} elseif (preg_match('/^[\d\.-]+-microsoft-standard/', $verBuf)) {
$this->sys->setVirtualizer('wsl2'); // Windows Subsystem for Linux 2
}
}
 
if (CommonFunctions::rfts('/proc/self/cgroup', $strBuf2, 0, 4096, false)) {
if (preg_match('/:\/lxc\//m', $strBuf2)) {
$result .= ' [lxc]';
if (preg_match('/:\/lxc\//m', $strBuf2)) {
$this->sys->setVirtualizer('lxc'); // Linux container
} elseif (preg_match('/:\/docker\//m', $strBuf2)) {
$result .= ' [docker]';
$this->sys->setVirtualizer('docker'); // Docker
} elseif (preg_match('/:\/system\.slice\/docker\-/m', $strBuf2)) {
$result .= ' [docker]';
$this->sys->setVirtualizer('docker'); // Docker
}
}
if (CommonFunctions::rfts('/proc/version', $strBuf2, 1, 4096, false)) {
if (preg_match('/^Linux version [\d\.-]+-Microsoft/', $strBuf2)) {
$result .= ' [wsl]';
} elseif (preg_match('/^Linux version [\d\.-]+-microsoft-standard/', $strBuf2)) {
$result .= ' [wsl2]';
}
}
$this->sys->setKernel($result);
}
}
 
176,21 → 525,21
if (CommonFunctions::rfts('/proc/uptime', $buf, 1, 4096, PSI_OS != 'Android')) {
$ar_buf = preg_split('/ /', $buf);
$this->sys->setUptime(trim($ar_buf[0]));
} elseif (CommonFunctions::executeProgram('uptime', '', $buf)) {
if (preg_match("/up (\d+) day[s]?,[ ]+(\d+):(\d+),/", $buf, $ar_buf)) {
} elseif (($this->_uptime !== null) || CommonFunctions::executeProgram('uptime', '', $this->_uptime)) {
if (preg_match("/up (\d+) day[s]?,[ ]+(\d+):(\d+),/", $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);
} elseif (preg_match("/up (\d+) day[s]?,[ ]+(\d+) min,/", $buf, $ar_buf)) {
} elseif (preg_match("/up (\d+) day[s]?,[ ]+(\d+) min,/", $this->_uptime, $ar_buf)) {
$min = $ar_buf[2];
$days = $ar_buf[1];
$this->sys->setUptime($days * 86400 + $min * 60);
} elseif (preg_match("/up[ ]+(\d+):(\d+),/", $buf, $ar_buf)) {
} elseif (preg_match("/up[ ]+(\d+):(\d+),/", $this->_uptime, $ar_buf)) {
$min = $ar_buf[2];
$hours = $ar_buf[1];
$this->sys->setUptime($hours * 3600 + $min * 60);
} elseif (preg_match("/up[ ]+(\d+) min,/", $buf, $ar_buf)) {
} elseif (preg_match("/up[ ]+(\d+) min,/", $this->_uptime, $ar_buf)) {
$min = $ar_buf[1];
$this->sys->setUptime($min * 60);
}
210,7 → 559,7
// don't need the extra values, only first three
unset($result[3]);
$this->sys->setLoad(implode(' ', $result));
} elseif (CommonFunctions::executeProgram('uptime', '', $buf) && preg_match("/load average: (.*), (.*), (.*)$/", $buf, $ar_buf)) {
} 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]);
}
if (PSI_LOAD_BAR) {
223,11 → 572,11
*
* @param String $cpuline cpu for which load should be meassured
*
* @return Integer
* @return int
*/
protected function _parseProcStat($cpuline)
{
if (is_null($this->_cpu_loads)) {
if ($this->_cpu_loads === null) {
$this->_cpu_loads = array();
 
$cpu_tmp = array();
295,6 → 644,7
protected function _cpuinfo()
{
if (CommonFunctions::rfts('/proc/cpuinfo', $bufr)) {
 
$cpulist = null;
$raslist = null;
 
318,6 → 668,7
$_arch = null;
$_impl = null;
$_part = null;
$_vari = null;
$_hard = null;
$_revi = null;
$_cpus = null;
340,6 → 691,9
case 'cpu part':
$_part = $arrBuff1;
break;
case 'cpu variant':
$_vari = $arrBuff1;
break;
case 'hardware':
$_hard = $arrBuff1;
break;
361,9 → 715,9
break;
case 'vendor_id':
$_vend = $arrBuff1;
break;
case 'cpu':
$procname = $arrBuff1;
break;
}
}
}
377,6 → 731,7
$arch = null;
$impl = null;
$part = null;
$vari = null;
$dev = new CpuDevice();
$details = preg_split("/\n/", $processor, -1, PREG_SPLIT_NO_EMPTY);
foreach ($details as $detail) {
386,7 → 741,7
case 'processor':
$proc = $arrBuff1;
if (is_numeric($proc)) {
if (strlen($procname)>0) {
if (($procname !== null) && (strlen($procname)>0)) {
$dev->setModel($procname);
}
} else {
402,13 → 757,13
break;
case 'cpu mhz':
case 'clock':
if ($arrBuff1 > 0) { //openSUSE fix
if ($arrBuff1 > 0) { // openSUSE fix
$dev->setCpuSpeed($arrBuff1);
$speedset = true;
}
break;
case 'cpu mhz static':
if ($arrBuff1 > 0) { //openSUSE fix
if ($arrBuff1 > 0) { // openSUSE fix
$dev->setCpuSpeedMax($arrBuff1);
}
break;
434,9 → 789,15
$dev->setVirt("vmx");
} elseif (preg_match("/ svm/", $arrBuff1)) {
$dev->setVirt("svm");
} elseif (preg_match("/ hypervisor/", $arrBuff1)) {
$dev->setVirt("hypervisor");
}
if (preg_match("/ hypervisor/", $arrBuff1)) {
if ($dev->getVirt() === null) {
$dev->setVirt("hypervisor");
}
if (defined('PSI_SHOW_VIRTUALIZER_INFO') && PSI_SHOW_VIRTUALIZER_INFO && ($this->system_detect_virt === null)) {
$this->sys->setVirtualizer("hypervisor", false);
}
}
break;
case 'i size':
case 'd size':
455,9 → 816,14
case 'cpu part':
$part = $arrBuff1;
break;
case 'cpu variant':
$vari = $arrBuff1;
break;
case 'vendor_id':
$dev->setVendorId($arrBuff1);
break;
if (defined('PSI_SHOW_VIRTUALIZER_INFO') && PSI_SHOW_VIRTUALIZER_INFO && preg_match('/^User Mode Linux/', $arrBuff1)) {
$this->sys->setVirtualizer("cpuid:UserModeLinux", false);
}
}
}
}
464,6 → 830,7
if ($arch === null) $arch = $_arch;
if ($impl === null) $impl = $_impl;
if ($part === null) $part = $_part;
if ($vari === null) $vari = $_vari;
 
// sparc64 specific code follows
// This adds the ability to display the cache that a CPU has
478,8 → 845,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") && ($dev->getBogomips() !== null)) {
$dev->setCpuSpeed($dev->getBogomips()); // BogoMIPS are not BogoMIPS on this CPU, it's the speed
$speedset = true;
$dev->setBogomips(null); // no BogoMIPS available, unset previously set BogoMIPS
}
496,9 → 863,12
}
if (($dev->getVendorId() === null) && ($_vend !== null)) {
$dev->setVendorId($_vend);
if (defined('PSI_SHOW_VIRTUALIZER_INFO') && PSI_SHOW_VIRTUALIZER_INFO && preg_match('/^User Mode Linux/', $_vend)) {
$this->sys->setVirtualizer("cpuid:UserModeLinux", false);
}
}
 
if ($proc != null) {
if ($proc !== null) {
if (!is_numeric($proc)) {
$proc = 0;
}
561,11 → 931,12
$this->sys->setMachine($_hard);
}
if ($cpulist === null) $cpulist = @parse_ini_file(PSI_APP_ROOT."/data/cpus.ini", true);
if ($cpulist && (isset($cpulist['cpu'][$cpuimplpart = strtolower($impl.','.$part)]))) {
if ($cpulist && (((($vari !== null) && isset($cpulist['cpu'][$cpufromlist = strtolower($impl.','.$part.','.$vari)]))
|| isset($cpulist['cpu'][$cpufromlist = strtolower($impl.','.$part)])))) {
if (($cpumodel = $dev->getModel()) !== '') {
$dev->setModel($cpumodel.' - '.$cpulist['cpu'][$cpuimplpart]);
$dev->setModel($cpumodel.' - '.$cpulist['cpu'][$cpufromlist]);
} else {
$dev->setModel($cpulist['cpu'][$cpuimplpart]);
$dev->setModel($cpulist['cpu'][$cpufromlist]);
}
}
} elseif (($_hard !== null) && ($this->sys->getMachine() === '')) { // other hardware
572,15 → 943,23
$this->sys->setMachine($_hard);
}
 
if ($dev->getModel() === "") {
$dev->setModel("unknown");
$cpumodel = $dev->getModel();
if (defined('PSI_SHOW_VIRTUALIZER_INFO') && PSI_SHOW_VIRTUALIZER_INFO && ($this->system_detect_virt === null) && preg_match('/^QEMU Virtual CPU version /', $cpumodel)) {
$this->sys->setVirtualizer("cpuid:QEMU", false);
}
if ($cpumodel === "") {
if (($vendid = $dev->getVendorId()) !== "") {
$dev->setModel($vendid);
} else {
$dev->setModel("unknown");
}
}
$cpucount++;
$this->sys->setCpus($dev);
}
}
 
$cpudevices = glob('/sys/devices/system/cpu/cpu*/uevent', GLOB_NOSORT);
$cpudevices = CommonFunctions::findglob('/sys/devices/system/cpu/cpu*/uevent', GLOB_NOSORT);
if (is_array($cpudevices) && (($cpustopped = count($cpudevices)-$cpucount) > 0)) {
for (; $cpustopped > 0; $cpustopped--) {
$dev = new CpuDevice();
629,7 → 1008,7
}
}
} else {
$pcidevices = glob('/sys/bus/pci/devices/*/uevent', GLOB_NOSORT);
$pcidevices = CommonFunctions::findglob('/sys/bus/pci/devices/*/uevent', GLOB_NOSORT);
if (is_array($pcidevices) && (($total = count($pcidevices)) > 0)) {
$buf = "";
for ($i = 0; $i < $total; $i++) {
717,7 → 1096,7
 
if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS
&& ($dev_type[1]==='Direct-Access')) {
$sizelist = glob('/sys/bus/scsi/devices/'.intval($scsiid[1]).':'.intval($scsiid[2]).':'.intval($scsiid[3]).':'.intval($scsiid[4]).'/*/*/size', GLOB_NOSORT);
$sizelist = CommonFunctions::findglob('/sys/bus/scsi/devices/'.intval($scsiid[1]).':'.intval($scsiid[2]).':'.intval($scsiid[3]).':'.intval($scsiid[4]).'/*/*/size', GLOB_NOSORT);
if (is_array($sizelist) && (($total = count($sizelist)) > 0)) {
$buf = "";
for ($i = 0; $i < $total; $i++) {
749,7 → 1128,7
$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];
$usbid = intval($device[1]).'-'.intval(trim($device[3], ':')).' '.$device[5];
if ((isset($device[6]) && trim($device[6]) != "")) {
$usbarray[$usbid]['name'] = trim($device[6]);
} else {
759,10 → 1138,10
}
}
 
$usbdevices = glob('/sys/bus/usb/devices/*/idProduct', GLOB_NOSORT);
$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
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');
792,7 → 1171,7
}
}
 
if ((count($usbarray) == 0) && CommonFunctions::rfts('/proc/bus/usb/devices', $bufr, 0, 4096, false)) { //usb-devices
if ((count($usbarray) == 0) && CommonFunctions::rfts('/proc/bus/usb/devices', $bufr, 0, 4096, false)) { // usb-devices
$devnum = -1;
$bufe = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
foreach ($bufe as $buf) {
817,8 → 1196,7
&& defined('PSI_SHOW_DEVICES_SERIAL') && PSI_SHOW_DEVICES_SERIAL
&& !preg_match('/\W/', trim($value2))) {
$usbarray[$devnum]['serial'] = trim($value2);
}
break;
}
}
}
}
901,7 → 1279,7
*/
protected function _i2c()
{
$i2cdevices = glob('/sys/bus/i2c/devices/*/name', GLOB_NOSORT);
$i2cdevices = CommonFunctions::findglob('/sys/bus/i2c/devices/*/name', GLOB_NOSORT);
if (is_array($i2cdevices) && (($total = count($i2cdevices)) > 0)) {
$buf = "";
for ($i = 0; $i < $total; $i++) {
957,24 → 1335,23
if (isset($nlocate[4]) && isset($nsize[4])) {
if (preg_match('/\/\s*([0-9\.]+)\s*(B|KB|MB|GB|TB|PB)$/', str_replace(',', '.', trim(substr($buf, $nlocate[4], $nsize[4]))), $tmpbuf)) {
switch ($tmpbuf[2]) {
case 'B':
$dev->setCapacity($tmpbuf[1]);
break;
case 'KB':
$dev->setCapacity(1000*$tmpbuf[1]);
break;
case 'MB':
$dev->setCapacity(1000*1000*$tmpbuf[1]);
break;
case 'GB':
$dev->setCapacity(1000*1000*1000*$tmpbuf[1]);
break;
case 'TB':
$dev->setCapacity(1000*1000*1000*1000*$tmpbuf[1]);
break;
case 'PB':
$dev->setCapacity(1000*1000*1000*1000*1000*$tmpbuf[1]);
break;
case 'B':
$dev->setCapacity($tmpbuf[1]);
break;
case 'KB':
$dev->setCapacity(1000*$tmpbuf[1]);
break;
case 'MB':
$dev->setCapacity(1000*1000*$tmpbuf[1]);
break;
case 'GB':
$dev->setCapacity(1000*1000*1000*$tmpbuf[1]);
break;
case 'TB':
$dev->setCapacity(1000*1000*1000*1000*$tmpbuf[1]);
break;
case 'PB':
$dev->setCapacity(1000*1000*1000*1000*1000*$tmpbuf[1]);
}
}
}
1026,7 → 1403,7
|| preg_match('/^\s+link\/\S+\s+(\S+)$/i', $buf2, $ar_buf2)) {
if (!defined('PSI_HIDE_NETWORK_MACADDR') || !PSI_HIDE_NETWORK_MACADDR) {
$macaddr = preg_replace('/:/', '-', strtoupper($ar_buf2[1]));
if ($macaddr === '00-00-00-00-00-00') { // empty
if (($macaddr === '00-00-00-00-00-00') || ($macaddr === '00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00') || ($macaddr === '--') || ($macaddr === '0.0.0.0')) { // empty
$macaddr = "";
}
}
1120,7 → 1497,12
if (defined('PSI_SHOW_NETWORK_INFOS') && (PSI_SHOW_NETWORK_INFOS)) {
if (preg_match('/^\s+link\/\S+\s+(\S+)\s+brd/i', $line, $ar_buf2)
|| preg_match('/^\s+link\/\S+\s+(\S+)$/i', $line, $ar_buf2)) {
if (!defined('PSI_HIDE_NETWORK_MACADDR') || !PSI_HIDE_NETWORK_MACADDR) $macaddr = preg_replace('/:/', '-', strtoupper($ar_buf2[1]));
if (!defined('PSI_HIDE_NETWORK_MACADDR') || !PSI_HIDE_NETWORK_MACADDR) {
$macaddr = preg_replace('/:/', '-', strtoupper($ar_buf2[1]));
if (($macaddr === '00-00-00-00-00-00') || ($macaddr === '00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00') || ($macaddr === '--') || ($macaddr === '0.0.0.0')) { // empty
$macaddr = "";
}
}
} elseif (preg_match('/^\s+inet\s+([^\/\s]+).*peer\s+([^\/\s]+).*\s+scope\s((global)|(host))/i', $line, $ar_buf2)) {
if ($ar_buf2[1] != $ar_buf2[2]) {
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$ar_buf2[1].";:".$ar_buf2[2]);
1265,6 → 1647,8
protected function _memory()
{
if (CommonFunctions::rfts('/proc/meminfo', $mbuf)) {
$swaptotal = null;
$swapfree = null;
$bufe = preg_split("/\n/", $mbuf, -1, PREG_SPLIT_NO_EMPTY);
foreach ($bufe as $buf) {
if (preg_match('/^MemTotal:\s+(\d+)\s*kB/i', $buf, $ar_buf)) {
1275,11 → 1659,15
$this->sys->setMemCache($ar_buf[1] * 1024);
} elseif (preg_match('/^Buffers:\s+(\d+)\s*kB/i', $buf, $ar_buf)) {
$this->sys->setMemBuffer($ar_buf[1] * 1024);
} elseif (preg_match('/^SwapTotal:\s+(\d+)\s*kB/i', $buf, $ar_buf)) {
$swaptotal = $ar_buf[1] * 1024;
} elseif (preg_match('/^SwapFree:\s+(\d+)\s*kB/i', $buf, $ar_buf)) {
$swapfree = $ar_buf[1] * 1024;
}
}
$this->sys->setMemUsed($this->sys->getMemTotal() - $this->sys->getMemFree());
// values for splitting memory usage
if ($this->sys->getMemCache() !== null && $this->sys->getMemBuffer() !== null) {
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)) {
1295,6 → 1683,13
$dev->setFree($dev->getTotal() - $dev->getUsed());
$this->sys->setSwapDevices($dev);
}
} elseif (($swaptotal !== null) && ($swapfree !== null) && ($swaptotal > 0)) {
$dev = new DiskDevice();
$dev->setName("SWAP");
$dev->setTotal($swaptotal);
$dev->setFree($swapfree);
$dev->setUsed($dev->getTotal() - $dev->getFree());
$this->sys->setSwapDevices($dev);
}
}
}
1319,7 → 1714,7
$df_args .= "-x $Fstype ";
}
if ($df_args !== "") {
$df_args = trim($df_args); //trim spaces
$df_args = trim($df_args); // trim spaces
$arrResult = Parser::df("-P $df_args 2>/dev/null");
} else {
$arrResult = Parser::df("-P 2>/dev/null");
1342,17 → 1737,17
return;
}
// We have the '2>/dev/null' because Ubuntu gives an error on this command which causes the distro to be unknown
if (CommonFunctions::executeProgram('lsb_release', '-a 2>/dev/null', $distro_info, PSI_DEBUG) && (strlen($distro_info) > 0)) {
$distro_tmp = preg_split("/\n/", $distro_info, -1, PREG_SPLIT_NO_EMPTY);
if (CommonFunctions::executeProgram('lsb_release', '-a 2>/dev/null', $distro_info, PSI_DEBUG) && strlen($distro_info) > 0) {
$distro_tmp = preg_split("/\r?\n/", $distro_info, -1, PREG_SPLIT_NO_EMPTY);
foreach ($distro_tmp as $info) {
$info_tmp = preg_split('/:/', $info, 2);
if (isset($distro_tmp[0]) && !is_null($distro_tmp[0]) && (trim($distro_tmp[0]) != "") &&
isset($distro_tmp[1]) && !is_null($distro_tmp[1]) && (trim($distro_tmp[1]) != "")) {
if (isset($distro_tmp[0]) && ($distro_tmp[0] !== null) && (trim($distro_tmp[0]) != "") &&
isset($distro_tmp[1]) && ($distro_tmp[1] !== null) && (trim($distro_tmp[1]) != "")) {
$distro[trim($info_tmp[0])] = trim($info_tmp[1]);
}
}
if (!isset($distro['Distributor ID']) && !isset($distro['Description'])) { // Systems like StartOS
if (isset($distro_tmp[0]) && !is_null($distro_tmp[0]) && (trim($distro_tmp[0]) != "")) {
if (isset($distro_tmp[0]) && ($distro_tmp[0] !== null) && (trim($distro_tmp[0]) != "")) {
$this->sys->setDistribution(trim($distro_tmp[0]));
if (preg_match('/^(\S+)\s*/', $distro_tmp[0], $id_buf)
&& isset($list[trim($id_buf[1])]['Image'])) {
1360,9 → 1755,13
}
}
} else {
if (isset($distro['Description']) && ($distro['Description'] != "n/a") && isset($distro['Distributor ID']) && $distro['Distributor ID']=="Neon") { // Neon systems
$distro_tmp = preg_split("/\s/", $distro['Description'], -1, PREG_SPLIT_NO_EMPTY);
$distro['Distributor ID'] = $distro_tmp[0];
}
if (isset($distro['Description'])
&& preg_match('/^NAME=\s*"?([^"\n]+)"?\s*$/', $distro['Description'], $name_tmp)) {
$distro['Description'] = $name_tmp[1];
&& preg_match('/^NAME=\s*"?([^"\r\n]+)"?\s*$/', $distro['Description'], $name_tmp)) {
$distro['Description'] = trim($name_tmp[1]);
}
if (isset($distro['Description'])
&& ($distro['Description'] != "n/a")
1381,22 → 1780,36
$this->sys->setDistribution($this->sys->getDistribution()." ".$distro['Release']);
}
}
} elseif (isset($distro['Distributor ID']) && ($distro['Distributor ID'] != "n/a")) {
$this->sys->setDistribution($distro['Distributor ID']);
if (isset($distro['Release']) && ($distro['Release'] != "n/a")) {
$this->sys->setDistribution($this->sys->getDistribution()." ".$distro['Release']);
} elseif (isset($distro['Distributor ID'])) {
if ($distro['Distributor ID'] != "n/a") {
$this->sys->setDistribution($distro['Distributor ID']);
if (isset($distro['Release']) && ($distro['Release'] != "n/a")) {
$this->sys->setDistribution($this->sys->getDistribution()." ".$distro['Release']);
}
if (isset($distro['Codename']) && ($distro['Codename'] != "n/a")) {
$this->sys->setDistribution($this->sys->getDistribution()." (".$distro['Codename'].")");
}
} elseif (isset($distro['Description']) && ($distro['Description'] != "n/a")) {
$this->sys->setDistribution($distro['Description']);
}
if (isset($distro['Codename']) && ($distro['Codename'] != "n/a")) {
$this->sys->setDistribution($this->sys->getDistribution()." (".$distro['Codename'].")");
}
}
if (isset($distro['Distributor ID']) && ($distro['Distributor ID'] != "n/a") && isset($list[$distro['Distributor ID']]['Image'])) {
$this->sys->setDistributionIcon($list[$distro['Distributor ID']]['Image']);
} elseif (isset($distro['Description']) && ($distro['Description'] != "n/a")) {
$this->sys->setDistribution($distro['Description']);
if (isset($list[$distro['Description']]['Image'])) {
$this->sys->setDistributionIcon($list[$distro['Description']]['Image']);
if (isset($distro['Distributor ID'])) {
$distrib = $distro['Distributor ID'];
if (isset($distro['Description'])) {
$distarr = preg_split("/\s/", $distro['Description'], -1, PREG_SPLIT_NO_EMPTY);
if (isset($distarr[0])) {
if ($distrib != "n/a") {
$distrib .= ' '.$distarr[0];
} else {
$distrib = $distarr[0];
}
}
}
if (isset($list[$distrib]['Image'])) {
$this->sys->setDistributionIcon($list[$distrib]['Image']);
} elseif (($distro['Distributor ID'] != "n/a") && isset($list[$distro['Distributor ID']]['Image'])) {
$this->sys->setDistributionIcon($list[$distro['Distributor ID']]['Image']);
}
}
}
} else {
1411,11 → 1824,11
// Fall back in case 'lsb_release' does not exist but exist /etc/lsb-release
if (CommonFunctions::fileexists($filename="/etc/lsb-release")
&& CommonFunctions::rfts($filename, $buf, 0, 4096, false)
&& preg_match('/^DISTRIB_ID="?([^"\n]+)"?/m', $buf, $id_buf)) {
if (preg_match('/^DISTRIB_DESCRIPTION="?([^"\n]+)"?/m', $buf, $desc_buf)
&& preg_match('/^DISTRIB_ID="?([^"\r\n]+)/m', $buf, $id_buf)) {
if (preg_match('/^DISTRIB_DESCRIPTION="?([^"\r\n]+)/m', $buf, $desc_buf)
&& (trim($desc_buf[1])!=trim($id_buf[1]))) {
$this->sys->setDistribution(trim($desc_buf[1]));
if (preg_match('/^DISTRIB_RELEASE="?([^"\n]+)"?/m', $buf, $vers_buf)
if (preg_match('/^DISTRIB_RELEASE="?([^"\r\n]+)/m', $buf, $vers_buf)
&& (trim($vers_buf[1])!=trim($desc_buf[1])) && strstr($vers_buf[1], ".")){
if (preg_match("/^(\d+)\.[0]+$/", trim($vers_buf[1]), $match_buf)) {
$tofind = $match_buf[1];
1432,10 → 1845,10
} else {
$this->sys->setDistribution(trim($id_buf[1]));
}
if (preg_match('/^DISTRIB_RELEASE="?([^"\n]+)"?/m', $buf, $vers_buf)) {
if (preg_match('/^DISTRIB_RELEASE="?([^"\r\n]+)/m', $buf, $vers_buf)) {
$this->sys->setDistribution($this->sys->getDistribution()." ".trim($vers_buf[1]));
}
if (preg_match('/^DISTRIB_CODENAME="?([^"\n]+)"?/m', $buf, $vers_buf)) {
if (preg_match('/^DISTRIB_CODENAME="?([^"\r\n]+)/m', $buf, $vers_buf)) {
$this->sys->setDistribution($this->sys->getDistribution()." (".trim($vers_buf[1]).")");
}
}
1470,13 → 1883,13
$this->sys->setDistributionIcon($distro['Image']);
}
if (isset($distribution['Name'])) {
if (is_null($buf) || (trim($buf) == "")) {
if (($buf === null) || (trim($buf) == "")) {
$this->sys->setDistribution($distribution['Name']);
} else {
$this->sys->setDistribution($distribution['Name']." ".trim($buf));
}
} else {
if (is_null($buf) || (trim($buf) == "")) {
if (($buf === null) || (trim($buf) == "")) {
$this->sys->setDistribution($section);
} else {
$this->sys->setDistribution(trim($buf));
1485,22 → 1898,22
if (isset($distribution['Files2'])) {
foreach (preg_split("/;/", $distribution['Files2'], -1, PREG_SPLIT_NO_EMPTY) as $filename2) {
if (CommonFunctions::fileexists($filename2) && CommonFunctions::rfts($filename2, $buf, 0, 4096, false)) {
if (preg_match('/^majorversion="?([^"\n]+)"?/m', $buf, $maj_buf)
&& preg_match('/^minorversion="?([^"\n]+)"?/m', $buf, $min_buf)) {
if (preg_match('/^majorversion="?([^"\r\n]+)/m', $buf, $maj_buf)
&& preg_match('/^minorversion="?([^"\r\n]+)/m', $buf, $min_buf)) {
$distr2=$maj_buf[1].'.'.$min_buf[1];
if (preg_match('/^buildphase="?([^"\n]+)"?/m', $buf, $pha_buf) && ($pha_buf[1]!=="0")) {
if (preg_match('/^buildphase="?([^"\r\n]+)/m', $buf, $pha_buf) && ($pha_buf[1]!=="0")) {
$distr2.='.'.$pha_buf[1];
}
if (preg_match('/^buildnumber="?([^"\n]+)"?/m', $buf, $num_buf)) {
if (preg_match('/^buildnumber="?([^"\r\n]+)/m', $buf, $num_buf)) {
$distr2.='-'.$num_buf[1];
}
if (preg_match('/^builddate="?([^"\n]+)"?/m', $buf, $dat_buf)) {
if (preg_match('/^builddate="?([^"\r\n]+)/m', $buf, $dat_buf)) {
$distr2.=' ('.$dat_buf[1].')';
}
$this->sys->setDistribution($this->sys->getDistribution()." ".$distr2);
} else {
$distr2=trim(substr($buf, 0, strpos($buf, "\n")));
if (!is_null($distr2) && ($distr2 != "")) {
if (($distr2 !== null) && ($distr2 != "")) {
$this->sys->setDistribution($this->sys->getDistribution()." ".$distr2);
}
}
1538,10 → 1951,10
}
} elseif ((CommonFunctions::fileexists($filename="/etc/distro-release")
&& CommonFunctions::rfts($filename, $buf, 1, 4096, false)
&& !is_null($buf) && (trim($buf) != ""))
&& ($buf !== null) && (trim($buf) != ""))
|| (CommonFunctions::fileexists($filename="/etc/system-release")
&& CommonFunctions::rfts($filename, $buf, 1, 4096, false)
&& !is_null($buf) && (trim($buf) != ""))) {
&& ($buf !== null) && (trim($buf) != ""))) {
$this->sys->setDistribution(trim($buf));
if (preg_match('/^(\S+)\s*/', preg_replace('/^Red\s+/', 'Red', $buf), $id_buf)
&& isset($list[trim($id_buf[1])]['Image'])) {
1549,8 → 1962,8
}
} elseif (CommonFunctions::fileexists($filename="/etc/solydxk/info")
&& CommonFunctions::rfts($filename, $buf, 0, 4096, false)
&& preg_match('/^DISTRIB_ID="?([^"\n]+)"?/m', $buf, $id_buf)) {
if (preg_match('/^DESCRIPTION="?([^"\n]+)"?/m', $buf, $desc_buf)
&& preg_match('/^DISTRIB_ID="?([^"\r\n]+)/m', $buf, $id_buf)) {
if (preg_match('/^DESCRIPTION="?([^"\r\n]+)/m', $buf, $desc_buf)
&& (trim($desc_buf[1])!=trim($id_buf[1]))) {
$this->sys->setDistribution(trim($desc_buf[1]));
} else {
1559,10 → 1972,10
} else {
$this->sys->setDistribution(trim($id_buf[1]));
}
if (preg_match('/^RELEASE="?([^"\n]+)"?/m', $buf, $vers_buf)) {
if (preg_match('/^RELEASE="?([^"\r\n]+)/m', $buf, $vers_buf)) {
$this->sys->setDistribution($this->sys->getDistribution()." ".trim($vers_buf[1]));
}
if (preg_match('/^CODENAME="?([^"\n]+)"?/m', $buf, $vers_buf)) {
if (preg_match('/^CODENAME="?([^"\r\n]+)/m', $buf, $vers_buf)) {
$this->sys->setDistribution($this->sys->getDistribution()." (".trim($vers_buf[1]).")");
}
}
1573,10 → 1986,10
}
} elseif (CommonFunctions::fileexists($filename="/etc/os-release")
&& CommonFunctions::rfts($filename, $buf, 0, 4096, false)
&& (preg_match('/^TAILS_VERSION_ID="?([^"\n]+)"?/m', $buf, $tid_buf)
|| preg_match('/^NAME="?([^"\n]+)"?/m', $buf, $id_buf))) {
if (preg_match('/^TAILS_VERSION_ID="?([^"\n]+)"?/m', $buf, $tid_buf)) {
if (preg_match('/^TAILS_PRODUCT_NAME="?([^"\n]+)"?/m', $buf, $desc_buf)) {
&& (preg_match('/^TAILS_VERSION_ID="?([^"\r\n]+)/m', $buf, $tid_buf)
|| preg_match('/^NAME=["\']?([^"\'\r\n]+)/m', $buf, $id_buf))) {
if (preg_match('/^TAILS_VERSION_ID="?([^"\r\n]+)/m', $buf, $tid_buf)) {
if (preg_match('/^TAILS_PRODUCT_NAME="?([^"\r\n]+)/m', $buf, $desc_buf)) {
$this->sys->setDistribution(trim($desc_buf[1])." ".trim($tid_buf[1]));
} else {
if (isset($list['Tails']['Name'])) {
1587,8 → 2000,8
}
$this->sys->setDistributionIcon($list['Tails']['Image']);
} else {
if (preg_match('/^PRETTY_NAME="?([^"\n]+)"?/m', $buf, $desc_buf)
&& !preg_match('/\$/', $desc_buf[1])) { //if is not defined by variable
if (preg_match('/^PRETTY_NAME=["\']?([^"\'\r\n]+)/m', $buf, $desc_buf)
&& !preg_match('/\$/', $desc_buf[1])) { // if is not defined by variable
$this->sys->setDistribution(trim($desc_buf[1]));
} else {
if (isset($list[trim($id_buf[1])]['Name'])) {
1596,9 → 2009,9
} else {
$this->sys->setDistribution(trim($id_buf[1]));
}
if (preg_match('/^VERSION="?([^"\n]+)"?/m', $buf, $vers_buf)) {
if (preg_match('/^VERSION=["\']?([^"\'\r\n]+)/m', $buf, $vers_buf)) {
$this->sys->setDistribution($this->sys->getDistribution()." ".trim($vers_buf[1]));
} elseif (preg_match('/^VERSION_ID="?([^"\n]+)"?/m', $buf, $vers_buf)) {
} elseif (preg_match('/^VERSION_ID=["\']?([^"\'\r\n]+)/m', $buf, $vers_buf)) {
$this->sys->setDistribution($this->sys->getDistribution()." ".trim($vers_buf[1]));
}
}
1614,13 → 2027,13
$this->sys->setDistributionIcon($list['Debian']['Image']);
}
if (isset($list['Debian']['Name'])) {
if (is_null($buf) || (trim($buf) == "")) {
if (($buf === null) || (trim($buf) == "")) {
$this->sys->setDistribution($list['Debian']['Name']);
} else {
$this->sys->setDistribution($list['Debian']['Name']." ".trim($buf));
}
} else {
if (is_null($buf) || (trim($buf) == "")) {
if (($buf === null) || (trim($buf) == "")) {
$this->sys->setDistribution('Debian');
} else {
$this->sys->setDistribution(trim($buf));
1657,13 → 2070,13
*/
protected function _processes()
{
$process = glob('/proc/*/status', GLOB_NOSORT);
$process = CommonFunctions::findglob('/proc/*/status', GLOB_NOSORT);
if (is_array($process) && (($total = count($process)) > 0)) {
$processes['*'] = 0;
$buf = "";
for ($i = 0; $i < $total; $i++) {
if (CommonFunctions::rfts($process[$i], $buf, 0, 4096, false)) {
$processes['*']++; //current total
$processes['*']++; // current total
if (preg_match('/^State:\s+(\w)/m', $buf, $state)) {
if (isset($processes[$state[1]])) {
$processes[$state[1]]++;
1674,7 → 2087,7
}
}
if (!($processes['*'] > 0)) {
$processes['*'] = $processes[' '] = $total; //all unknown
$processes['*'] = $processes[' '] = $total; // all unknown
}
$this->sys->setProcesses($processes);
}
1685,7 → 2098,7
*
* @see PSI_Interface_OS::build()
*
* @return Void
* @return void
*/
public function build()
{
1701,6 → 2114,7
if (!$this->blockname || $this->blockname==='hardware') {
$this->_machine();
$this->_cpuinfo();
$this->_virtualizer();
$this->_pci();
$this->_ide();
$this->_scsi();
1708,9 → 2122,6
$this->_usb();
$this->_i2c();
}
if (!$this->blockname || $this->blockname==='network') {
$this->_network();
}
if (!$this->blockname || $this->blockname==='memory') {
$this->_memory();
}
1717,5 → 2128,8
if (!$this->blockname || $this->blockname==='filesystem') {
$this->_filesystems();
}
if (!$this->blockname || $this->blockname==='network') {
$this->_network();
}
}
}