Subversion Repositories ALCASAR

Rev

Rev 3037 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log

Rev 3037 Rev 3100
1
<?php
1
<?php
2
/**
2
/**
3
 * Linux System Class
3
 * Linux System Class
4
 *
4
 *
5
 * PHP version 5
5
 * PHP version 5
6
 *
6
 *
7
 * @category  PHP
7
 * @category  PHP
8
 * @package   PSI Linux OS class
8
 * @package   PSI Linux OS class
9
 * @author    Michael Cramer <BigMichi1@users.sourceforge.net>
9
 * @author    Michael Cramer <BigMichi1@users.sourceforge.net>
10
 * @copyright 2009 phpSysInfo
10
 * @copyright 2009 phpSysInfo
11
 * @license   http://opensource.org/licenses/gpl-2.0.php GNU General Public License version 2, or (at your option) any later version
11
 * @license   http://opensource.org/licenses/gpl-2.0.php GNU General Public License version 2, or (at your option) any later version
12
 * @version   SVN: $Id: class.Linux.inc.php 712 2012-12-05 14:09:18Z namiltd $
12
 * @version   SVN: $Id: class.Linux.inc.php 712 2012-12-05 14:09:18Z namiltd $
13
 * @link      http://phpsysinfo.sourceforge.net
13
 * @link      http://phpsysinfo.sourceforge.net
14
 */
14
 */
15
 /**
15
 /**
16
 * Linux sysinfo class
16
 * Linux sysinfo class
17
 * get all the required information from Linux system
17
 * get all the required information from Linux system
18
 *
18
 *
19
 * @category  PHP
19
 * @category  PHP
20
 * @package   PSI Linux OS class
20
 * @package   PSI Linux OS class
21
 * @author    Michael Cramer <BigMichi1@users.sourceforge.net>
21
 * @author    Michael Cramer <BigMichi1@users.sourceforge.net>
22
 * @copyright 2009 phpSysInfo
22
 * @copyright 2009 phpSysInfo
23
 * @license   http://opensource.org/licenses/gpl-2.0.php GNU General Public License version 2, or (at your option) any later version
23
 * @license   http://opensource.org/licenses/gpl-2.0.php GNU General Public License version 2, or (at your option) any later version
24
 * @version   Release: 3.0
24
 * @version   Release: 3.0
25
 * @link      http://phpsysinfo.sourceforge.net
25
 * @link      http://phpsysinfo.sourceforge.net
26
 */
26
 */
27
class Linux extends OS
27
class Linux extends OS
28
{
28
{
29
    /**
29
    /**
30
     * Uptime command result.
30
     * Uptime command result.
31
     */
31
     */
32
    private $_uptime = null;
32
    private $_uptime = null;
33
 
33
 
34
    /**
34
    /**
35
     * Assoc array of all CPUs loads.
35
     * Assoc array of all CPUs loads.
36
     */
36
     */
37
    private $_cpu_loads = null;
37
    protected $_cpu_loads = null;
38
 
38
 
39
    /**
39
    /**
40
     * Version string.
40
     * Version string.
41
     */
41
     */
42
    private $_kernel_string = null;
42
    private $_kernel_string = null;
43
 
43
 
44
    /**
44
    /**
45
     * Array of info from Bios.
45
     * Array of info from Bios.
46
     */
46
     */
47
    private $_machine_info = null;
47
    private $_machine_info = null;
48
 
48
 
49
    /**
49
    /**
50
     * Array of info from dmesg.
50
     * Array of info from dmesg.
51
     */
51
     */
52
    private $_dmesg_info = null;
52
    private $_dmesg_info = null;
53
 
53
 
54
    /**
54
    /**
55
     * Result of systemd-detect-virt.
55
     * Result of systemd-detect-virt.
56
     */
56
     */
57
    private $system_detect_virt = null;
57
    private $system_detect_virt = null;
58
 
58
 
59
     /**
59
     /**
60
      * Get info from dmesg
60
      * Get info from dmesg
61
      *
61
      *
62
      * @return array
62
      * @return array
63
      */
63
      */
64
    private function _get_dmesg_info()
64
    private function _get_dmesg_info()
65
    {
65
    {
66
        if ($this->_dmesg_info === null) {
66
        if ($this->_dmesg_info === null) {
67
            $this->_dmesg_info = array();
67
            $this->_dmesg_info = array();
68
            if (CommonFunctions::rfts('/var/log/dmesg', $result, 0, 4096, false)) {
68
            if (CommonFunctions::rfts('/var/log/dmesg', $result, 0, 4096, false)) {
69
                if (preg_match('/^[\s\[\]\.\d]*DMI:\s*(.+)/m', $result, $ar_buf)) {
69
                if (preg_match('/^[\s\[\]\.\d]*DMI:\s*(.+)/m', $result, $ar_buf)) {
70
                    $this->_dmesg_info['dmi'] = trim($ar_buf[1]);
70
                    $this->_dmesg_info['dmi'] = trim($ar_buf[1]);
71
                }
71
                }
72
                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)) {
72
                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)) {
73
                    $this->_dmesg_info['hypervisor'] = trim($ar_buf[1]);
73
                    $this->_dmesg_info['hypervisor'] = trim($ar_buf[1]);
74
                }
74
                }
75
            }
75
            }
76
            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)) {
76
            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)) {
77
                if (!isset($this->_dmesg_info['dmi']) && preg_match('/^[\s\[\]\.\d]*DMI:\s*(.+)/m', $result, $ar_buf)) {
77
                if (!isset($this->_dmesg_info['dmi']) && preg_match('/^[\s\[\]\.\d]*DMI:\s*(.+)/m', $result, $ar_buf)) {
78
                    $this->_dmesg_info['dmi'] = trim($ar_buf[1]);
78
                    $this->_dmesg_info['dmi'] = trim($ar_buf[1]);
79
                }
79
                }
80
                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)) {
80
                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)) {
81
                    $this->_dmesg_info['hypervisor'] = trim($ar_buf[1]);
81
                    $this->_dmesg_info['hypervisor'] = trim($ar_buf[1]);
82
                }
82
                }
83
            }
83
            }
84
        }
84
        }
85
 
85
 
86
        return $this->_dmesg_info;
86
        return $this->_dmesg_info;
87
    }
87
    }
88
 
88
 
89
    /**
89
    /**
90
     * Get machine info
90
     * Get machine info
91
     *
91
     *
92
     * @return string
92
     * @return string
93
     */
93
     */
94
    private function _get_machine_info()
94
    private function _get_machine_info()
95
    {
95
    {
96
        if ($this->_machine_info === null) {
96
        if ($this->_machine_info === null) {
97
            $this->_machine_info = array();
97
            $this->_machine_info = array();
98
            if (defined('PSI_SHOW_VIRTUALIZER_INFO') && PSI_SHOW_VIRTUALIZER_INFO) {
98
            if (defined('PSI_SHOW_VIRTUALIZER_INFO') && PSI_SHOW_VIRTUALIZER_INFO) {
99
                if (CommonFunctions::executeProgram('systemd-detect-virt', '-v', $resultv, false)) {
99
                if (CommonFunctions::executeProgram('systemd-detect-virt', '-v', $resultv, false)) {
100
                    $this->system_detect_virt = $resultv;
100
                    $this->system_detect_virt = $resultv;
101
                }
101
                }
102
            }
102
            }
103
            $vendor_array = array();
103
            $vendor_array = array();
104
            if ((($dmesg = $this->_get_dmesg_info()) !== null) && isset($dmesg['dmi'])) {
104
            if ((($dmesg = $this->_get_dmesg_info()) !== null) && isset($dmesg['dmi'])) {
105
                $this->_machine_info['machine'] = $dmesg['dmi'];
105
                $this->_machine_info['machine'] = $dmesg['dmi'];
106
                if (defined('PSI_SHOW_VIRTUALIZER_INFO') && PSI_SHOW_VIRTUALIZER_INFO && ($this->system_detect_virt === null)) {
106
                if (defined('PSI_SHOW_VIRTUALIZER_INFO') && PSI_SHOW_VIRTUALIZER_INFO && ($this->system_detect_virt === null)) {
107
                    /* Test this before sys_vendor to detect KVM over QEMU */
107
                    /* Test this before sys_vendor to detect KVM over QEMU */
108
                    if (CommonFunctions::rfts('/sys/devices/virtual/dmi/id/product_name', $buf, 1, 4096, false) && (trim($buf)!="")) {
108
                    if (CommonFunctions::rfts('/sys/devices/virtual/dmi/id/product_name', $buf, 1, 4096, false) && (trim($buf)!="")) {
109
                        $vendor_array[] = $product_name = trim($buf);
109
                        $vendor_array[] = $product_name = trim($buf);
110
                    } else {
110
                    } else {
111
                        $product_name = '';
111
                        $product_name = '';
112
                    }
112
                    }
113
                    if (CommonFunctions::rfts('/sys/devices/virtual/dmi/id/sys_vendor', $buf, 1, 4096, false) && (trim($buf)!="")) {
113
                    if (CommonFunctions::rfts('/sys/devices/virtual/dmi/id/sys_vendor', $buf, 1, 4096, false) && (trim($buf)!="")) {
114
                        $vendor_array[] = trim($buf);
114
                        $vendor_array[] = trim($buf);
115
                    }
115
                    }
116
                    if (CommonFunctions::rfts('/sys/devices/virtual/dmi/id/board_vendor', $buf, 1, 4096, false) && (trim($buf)!="")) {
116
                    if (CommonFunctions::rfts('/sys/devices/virtual/dmi/id/board_vendor', $buf, 1, 4096, false) && (trim($buf)!="")) {
117
                        if ($product_name != "") {
117
                        if ($product_name != "") {
118
                            $vendor_array[] = trim($buf)." ".$product_name;
118
                            $vendor_array[] = trim($buf)." ".$product_name;
119
                        } else {
119
                        } else {
120
                            $vendor_array[] = trim($buf);
120
                            $vendor_array[] = trim($buf);
121
                        }
121
                        }
122
                    } else {
122
                    } else {
123
                        $vendor_array[] = $dmesg['dmi'];
123
                        $vendor_array[] = $dmesg['dmi'];
124
                    }
124
                    }
125
                    if (CommonFunctions::rfts('/sys/devices/virtual/dmi/id/bios_vendor', $buf, 1, 4096, false) && (trim($buf)!="")) {
125
                    if (CommonFunctions::rfts('/sys/devices/virtual/dmi/id/bios_vendor', $buf, 1, 4096, false) && (trim($buf)!="")) {
126
                        $vendor_array[] = trim($buf);
126
                        $vendor_array[] = trim($buf);
127
                    }
127
                    }
128
                    if (CommonFunctions::rfts('/sys/devices/virtual/dmi/id/product_version', $buf, 1, 4096, false) && (trim($buf)!="")) {
128
                    if (CommonFunctions::rfts('/sys/devices/virtual/dmi/id/product_version', $buf, 1, 4096, false) && (trim($buf)!="")) {
129
                        $vendor_array[] = trim($buf);
129
                        $vendor_array[] = trim($buf);
130
                    }
130
                    }
131
                }
131
                }
132
            } else { // 'machine' data from /sys/devices/virtual/dmi/id/
132
            } else { // 'machine' data from /sys/devices/virtual/dmi/id/
133
                $bios = "";
133
                $bios = "";
134
                if (defined('PSI_SHOW_VIRTUALIZER_INFO') && PSI_SHOW_VIRTUALIZER_INFO && ($this->system_detect_virt === null)) {
134
                if (defined('PSI_SHOW_VIRTUALIZER_INFO') && PSI_SHOW_VIRTUALIZER_INFO && ($this->system_detect_virt === null)) {
135
                    // Test this before sys_vendor to detect KVM over QEMU
135
                    // Test this before sys_vendor to detect KVM over QEMU
136
                    if (CommonFunctions::rfts('/sys/devices/virtual/dmi/id/product_name', $buf, 1, 4096, false) && (trim($buf)!="")) {
136
                    if (CommonFunctions::rfts('/sys/devices/virtual/dmi/id/product_name', $buf, 1, 4096, false) && (trim($buf)!="")) {
137
                        $vendor_array[] = $product_name = trim($buf);
137
                        $vendor_array[] = $product_name = trim($buf);
138
                    } else {
138
                    } else {
139
                        $product_name = '';
139
                        $product_name = '';
140
                    }
140
                    }
141
 
141
 
142
                    if (CommonFunctions::rfts('/sys/devices/virtual/dmi/id/sys_vendor', $buf, 1, 4096, false) && (trim($buf)!="")) {
142
                    if (CommonFunctions::rfts('/sys/devices/virtual/dmi/id/sys_vendor', $buf, 1, 4096, false) && (trim($buf)!="")) {
143
                        $vendor_array[] = trim($buf);
143
                        $vendor_array[] = trim($buf);
144
                    }
144
                    }
145
                    if (CommonFunctions::rfts('/sys/devices/virtual/dmi/id/board_vendor', $buf, 1, 4096, false) && (trim($buf)!="")) {
145
                    if (CommonFunctions::rfts('/sys/devices/virtual/dmi/id/board_vendor', $buf, 1, 4096, false) && (trim($buf)!="")) {
146
                        if ($product_name != "") {
146
                        if ($product_name != "") {
147
                            $this->_machine_info['machine'] = trim($buf)." ".$product_name;
147
                            $this->_machine_info['machine'] = trim($buf)." ".$product_name;
148
                        } else {
148
                        } else {
149
                            $this->_machine_info['machine'] = trim($buf);
149
                            $this->_machine_info['machine'] = trim($buf);
150
                        }
150
                        }
151
                        $vendor_array[] = $this->_machine_info["machine"];
151
                        $vendor_array[] = $this->_machine_info["machine"];
152
                    } elseif ($product_name != "") {
152
                    } elseif ($product_name != "") {
153
                        $this->_machine_info['machine'] = $product_name;
153
                        $this->_machine_info['machine'] = $product_name;
154
                    }
154
                    }
155
 
155
 
156
                    if (CommonFunctions::rfts('/sys/devices/virtual/dmi/id/bios_vendor', $buf, 1, 4096, false) && (trim($buf)!="")) {
156
                    if (CommonFunctions::rfts('/sys/devices/virtual/dmi/id/bios_vendor', $buf, 1, 4096, false) && (trim($buf)!="")) {
157
                        $vendor_array[] = trim($buf);
157
                        $vendor_array[] = trim($buf);
158
                    }
158
                    }
159
                    if (CommonFunctions::rfts('/sys/devices/virtual/dmi/id/product_version', $buf, 1, 4096, false) && (trim($buf)!="")) {
159
                    if (CommonFunctions::rfts('/sys/devices/virtual/dmi/id/product_version', $buf, 1, 4096, false) && (trim($buf)!="")) {
160
                        $vendor_array[] = trim($buf);
160
                        $vendor_array[] = trim($buf);
161
                    }
161
                    }
162
                } else {
162
                } else {
163
                    if (CommonFunctions::rfts('/sys/devices/virtual/dmi/id/board_vendor', $buf, 1, 4096, false) && (trim($buf)!="")) {
163
                    if (CommonFunctions::rfts('/sys/devices/virtual/dmi/id/board_vendor', $buf, 1, 4096, false) && (trim($buf)!="")) {
164
                        $this->_machine_info['machine'] = trim($buf);
164
                        $this->_machine_info['machine'] = trim($buf);
165
                    }
165
                    }
166
                    if (CommonFunctions::rfts('/sys/devices/virtual/dmi/id/product_name', $buf, 1, 4096, false) && (trim($buf)!="")) {
166
                    if (CommonFunctions::rfts('/sys/devices/virtual/dmi/id/product_name', $buf, 1, 4096, false) && (trim($buf)!="")) {
167
                        if (isset($this->_machine_info['machine'])) {
167
                        if (isset($this->_machine_info['machine'])) {
168
                            $this->_machine_info['machine'] .= " ".trim($buf);
168
                            $this->_machine_info['machine'] .= " ".trim($buf);
169
                        } else {
169
                        } else {
170
                            $this->_machine_info['machine'] = trim($buf);
170
                            $this->_machine_info['machine'] = trim($buf);
171
                        }
171
                        }
172
                    }
172
                    }
173
                }
173
                }
174
                if (CommonFunctions::rfts('/sys/devices/virtual/dmi/id/board_name', $buf, 1, 4096, false) && (trim($buf)!="")) {
174
                if (CommonFunctions::rfts('/sys/devices/virtual/dmi/id/board_name', $buf, 1, 4096, false) && (trim($buf)!="")) {
175
                    if (isset($this->_machine_info['machine'])) {
175
                    if (isset($this->_machine_info['machine'])) {
176
                        $this->_machine_info['machine'] .= "/".trim($buf);
176
                        $this->_machine_info['machine'] .= "/".trim($buf);
177
                    } else {
177
                    } else {
178
                        $this->_machine_info['machine'] = trim($buf);
178
                        $this->_machine_info['machine'] = trim($buf);
179
                    }
179
                    }
180
                }
180
                }
181
                if (CommonFunctions::rfts('/sys/devices/virtual/dmi/id/bios_version', $buf, 1, 4096, false) && (trim($buf)!="")) {
181
                if (CommonFunctions::rfts('/sys/devices/virtual/dmi/id/bios_version', $buf, 1, 4096, false) && (trim($buf)!="")) {
182
                    $bios = trim($buf);
182
                    $bios = trim($buf);
183
                }
183
                }
184
                if (CommonFunctions::rfts('/sys/devices/virtual/dmi/id/bios_date', $buf, 1, 4096, false) && (trim($buf)!="")) {
184
                if (CommonFunctions::rfts('/sys/devices/virtual/dmi/id/bios_date', $buf, 1, 4096, false) && (trim($buf)!="")) {
185
                    $bios = trim($bios." ".trim($buf));
185
                    $bios = trim($bios." ".trim($buf));
186
                }
186
                }
187
                if ($bios != "") {
187
                if ($bios != "") {
188
                    if (isset($this->_machine_info['machine'])) {
188
                    if (isset($this->_machine_info['machine'])) {
189
                        $this->_machine_info['machine'] .= ", BIOS ".$bios;
189
                        $this->_machine_info['machine'] .= ", BIOS ".$bios;
190
                    } else {
190
                    } else {
191
                        $this->_machine_info['machine'] = "BIOS ".$bios;
191
                        $this->_machine_info['machine'] = "BIOS ".$bios;
192
                    }
192
                    }
193
                }
193
                }
194
            }
194
            }
195
            if (isset($this->_machine_info['machine'])) {
195
            if (isset($this->_machine_info['machine'])) {
196
                $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'])));
196
                $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'])));
197
            }
197
            }
198
 
198
 
199
            if (defined('PSI_SHOW_VIRTUALIZER_INFO') && PSI_SHOW_VIRTUALIZER_INFO && ($this->system_detect_virt === null) && count($vendor_array)>0) {
199
            if (defined('PSI_SHOW_VIRTUALIZER_INFO') && PSI_SHOW_VIRTUALIZER_INFO && ($this->system_detect_virt === null) && count($vendor_array) > 0) {
200
                $virt = CommonFunctions::decodevirtualizer($vendor_array);
200
                $virt = CommonFunctions::decodevirtualizer($vendor_array);
201
                if ($virt !== null) {
201
                if ($virt !== null) {
202
                    $this->_machine_info['hypervisor'] = $virt;
202
                    $this->_machine_info['hypervisor'] = $virt;
203
                }
203
                }
204
            }
204
            }
205
        }
205
        }
206
 
206
 
207
        return $this->_machine_info;
207
        return $this->_machine_info;
208
    }
208
    }
209
 
209
 
210
    /**
210
    /**
211
     * Get kernel string
211
     * Get kernel string
212
     *
212
     *
213
     * @return string
213
     * @return string
214
     */
214
     */
215
    private function _get_kernel_string()
215
    private function _get_kernel_string()
216
    {
216
    {
217
        if ($this->_kernel_string === null) {
217
        if ($this->_kernel_string === null) {
218
            $this->_kernel_string = "";
218
            $this->_kernel_string = "";
-
 
219
            if ($this->sys->getOS() == 'SSH') {
-
 
220
                if (CommonFunctions::executeProgram('uname', '-s', $strBuf, false) && ($strBuf !== '')) {
-
 
221
                    $this->sys->setOS($strBuf);
-
 
222
                } else {
-
 
223
                    return $this->_kernel_string;
-
 
224
                }
-
 
225
            }
219
            if (CommonFunctions::executeProgram($uname="uptrack-uname", '-r', $strBuf, false) || // show effective kernel if ksplice uptrack is installed
226
            if ((CommonFunctions::executeProgram($uname="uptrack-uname", '-r', $strBuf, false) && ($strBuf !== '')) || // show effective kernel if ksplice uptrack is installed
220
                CommonFunctions::executeProgram($uname="uname", '-r', $strBuf, PSI_DEBUG)) {
227
                (CommonFunctions::executeProgram($uname="uname", '-r', $strBuf, PSI_DEBUG) && ($strBuf !== ''))) {
221
                $this->_kernel_string = $strBuf;
228
                $this->_kernel_string = $strBuf;
222
                if (CommonFunctions::executeProgram($uname, '-v', $strBuf, PSI_DEBUG)) {
229
                if (CommonFunctions::executeProgram($uname, '-v', $strBuf, PSI_DEBUG) && ($strBuf !== '')) {
223
                    if (preg_match('/ SMP /', $strBuf)) {
230
                    if (preg_match('/ SMP /', $strBuf)) {
224
                        $this->_kernel_string .= ' (SMP)';
231
                        $this->_kernel_string .= ' (SMP)';
225
                    }
232
                    }
226
                }
233
                }
227
                if (CommonFunctions::executeProgram($uname, '-m', $strBuf, PSI_DEBUG)) {
234
                if (CommonFunctions::executeProgram($uname, '-m', $strBuf, PSI_DEBUG) && ($strBuf !== '')) {
228
                    $this->_kernel_string .= ' '.$strBuf;
235
                    $this->_kernel_string .= ' '.$strBuf;
229
                }
236
                }
230
            } elseif (CommonFunctions::rfts('/proc/version', $strBuf, 1)) {
237
            } elseif (CommonFunctions::rfts('/proc/version', $strBuf, 1)) {
-
 
238
                if (preg_match('/\/Hurd-([^\)]+)/', $strBuf, $ar_buf)) {
-
 
239
                    $this->_kernel_string = $ar_buf[1];
231
                if (preg_match('/version\s+(\S+)/', $strBuf, $ar_buf)) {
240
                } elseif (preg_match('/version\s+(\S+)/', $strBuf, $ar_buf)) {
232
                    $this->_kernel_string = $ar_buf[1];
241
                    $this->_kernel_string = $ar_buf[1];
233
                    if (preg_match('/ SMP /', $strBuf)) {
242
                    if (preg_match('/ SMP /', $strBuf)) {
234
                        $this->_kernel_string .= ' (SMP)';
243
                        $this->_kernel_string .= ' (SMP)';
235
                    }
244
                    }
236
                }
245
                }
237
            }
246
            }
238
        }
247
        }
239
 
248
 
240
        return $this->_kernel_string;
249
        return $this->_kernel_string;
241
    }
250
    }
242
 
251
 
243
    /**
252
    /**
-
 
253
     * check OS type
-
 
254
     */
-
 
255
    public function __construct($blockname = false)
-
 
256
    {
-
 
257
        parent::__construct($blockname);
-
 
258
        $this->_get_kernel_string();
-
 
259
    }
-
 
260
 
-
 
261
    /**
244
     * Machine
262
     * Machine
245
     *
263
     *
246
     * @return void
264
     * @return void
247
     */
265
     */
248
    private function _machine()
266
    protected function _machine()
249
    {
267
    {
250
        $machine_info = $this->_get_machine_info();
268
        $machine_info = $this->_get_machine_info();
251
        if (isset($machine_info['machine'])) {
269
        if (isset($machine_info['machine'])) {
252
            $machine = $machine_info['machine'];
270
            $machine = $machine_info['machine'];
253
        } else {
271
        } else {
254
            $machine = "";
272
            $machine = "";
255
        }
273
        }
256
 
274
 
257
        if (CommonFunctions::fileexists($filename="/etc/config/uLinux.conf") // QNAP detection
275
        if (CommonFunctions::fileexists($filename="/etc/config/uLinux.conf") // QNAP detection
258
           && CommonFunctions::rfts($filename, $buf, 0, 4096, false)
276
           && CommonFunctions::rfts($filename, $buf, 0, 4096, false)
259
           && preg_match("/^Rsync\sModel\s*=\s*QNAP/m", $buf)
277
           && preg_match("/^Rsync\sModel\s*=\s*QNAP/m", $buf)
260
           && CommonFunctions::fileexists($filename="/etc/platform.conf") // Platform detection
278
           && CommonFunctions::fileexists($filename="/etc/platform.conf") // Platform detection
261
           && CommonFunctions::rfts($filename, $buf, 0, 4096, false)
279
           && CommonFunctions::rfts($filename, $buf, 0, 4096, false)
262
           && preg_match("/^DISPLAY_NAME\s*=\s*(\S+)/m", $buf, $mach_buf) && ($mach_buf[1]!=="")) {
280
           && preg_match("/^DISPLAY_NAME\s*=\s*(\S+)/m", $buf, $mach_buf) && ($mach_buf[1]!=="")) {
263
            if ($machine !== "") {
281
            if ($machine !== "") {
264
                $machine = "QNAP ".$mach_buf[1].' - '.$machine;
282
                $machine = "QNAP ".$mach_buf[1].' - '.$machine;
265
            } else {
283
            } else {
266
                $machine = "QNAP ".$mach_buf[1];
284
                $machine = "QNAP ".$mach_buf[1];
267
            }
285
            }
268
        }
286
        }
269
 
287
 
270
        if ($machine !== "") {
288
        if ($machine !== "") {
271
            $this->sys->setMachine($machine);
289
            $this->sys->setMachine($machine);
272
        }
290
        }
273
    }
291
    }
274
 
292
 
275
    /**
293
    /**
276
     * Hostname
294
     * Hostname
277
     *
295
     *
278
     * @return void
296
     * @return void
279
     */
297
     */
280
    protected function _hostname()
298
    protected function _hostname()
281
    {
299
    {
282
        if (PSI_USE_VHOST) {
300
        if (PSI_USE_VHOST && !defined('PSI_EMU_PORT')) {
283
            if (CommonFunctions::readenv('SERVER_NAME', $hnm)) $this->sys->setHostname($hnm);
301
            if (CommonFunctions::readenv('SERVER_NAME', $hnm)) $this->sys->setHostname($hnm);
284
        } else {
302
        } else {
285
            if (CommonFunctions::rfts('/proc/sys/kernel/hostname', $result, 1, 4096, PSI_DEBUG && (PSI_OS != 'Android'))) {
303
            if (CommonFunctions::rfts('/proc/sys/kernel/hostname', $result, 1, 4096, PSI_DEBUG && (PSI_OS != 'Android'))) {
286
                $result = trim($result);
304
                $result = trim($result);
287
                $ip = gethostbyname($result);
305
                $ip = gethostbyname($result);
288
                if ($ip != $result) {
306
                if ($ip != $result) {
289
                    $this->sys->setHostname(gethostbyaddr($ip));
307
                    $this->sys->setHostname(gethostbyaddr($ip));
290
                }
308
                }
291
            } elseif (CommonFunctions::executeProgram('hostname', '', $ret)) {
309
            } elseif (CommonFunctions::executeProgram('hostname', '', $ret)) {
292
                $this->sys->setHostname($ret);
310
                $this->sys->setHostname($ret);
293
            }
311
            }
294
        }
312
        }
295
    }
313
    }
296
 
314
 
297
    /**
315
    /**
298
     * Kernel Version
316
     * Kernel Version
299
     *
317
     *
300
     * @return void
318
     * @return void
301
     */
319
     */
302
    private function _kernel()
320
    protected function _kernel()
303
    {
321
    {
304
        if (($verBuf = $this->_get_kernel_string()) != "") {
322
        if (($verBuf = $this->_get_kernel_string()) != "") {
305
            $this->sys->setKernel($verBuf);
323
            $this->sys->setKernel($verBuf);
306
        }
324
        }
307
    }
325
    }
308
 
326
 
309
    /**
327
    /**
310
     * Virtualizer info
328
     * Virtualizer info
311
     *
329
     *
312
     * @return void
330
     * @return void
313
     */
331
     */
314
    protected function _virtualizer()
332
    protected function _virtualizer()
315
    {
333
    {
316
        if (!defined('PSI_SHOW_VIRTUALIZER_INFO') || !PSI_SHOW_VIRTUALIZER_INFO) {
334
        if (!defined('PSI_SHOW_VIRTUALIZER_INFO') || !PSI_SHOW_VIRTUALIZER_INFO) {
317
            return;
335
            return;
318
        }
336
        }
319
        if ($this->system_detect_virt !== null) {
337
        if ($this->system_detect_virt !== null) {
320
            if (($this->system_detect_virt !== "") && ($this->system_detect_virt !== "none")) {
338
            if (($this->system_detect_virt !== "") && ($this->system_detect_virt !== "none")) {
321
                $this->sys->setVirtualizer($this->system_detect_virt);
339
                $this->sys->setVirtualizer($this->system_detect_virt);
322
            }
340
            }
323
            if (($verBuf = $this->_get_kernel_string()) !== "") {
341
            if (($verBuf = $this->_get_kernel_string()) !== "") {
324
                if (preg_match('/^[\d\.-]+-microsoft-standard/', $verBuf)) {
342
                if (preg_match('/^[\d\.-]+-microsoft-standard/', $verBuf)) {
325
                    $this->sys->setVirtualizer('wsl2', 'wsl'); // Windows Subsystem for Linux 2
343
                    $this->sys->setVirtualizer('wsl2', 'wsl'); // Windows Subsystem for Linux 2
326
                }
344
                }
327
            }
345
            }
328
            if (CommonFunctions::executeProgram('systemd-detect-virt', '-c', $resultc, false) && ($resultc !== "") && ($resultc !== "none")) {
346
            if (CommonFunctions::executeProgram('systemd-detect-virt', '-c', $resultc, false) && ($resultc !== "") && ($resultc !== "none")) {
329
                $this->sys->setVirtualizer($resultc);
347
                $this->sys->setVirtualizer($resultc);
330
            }
348
            }
331
        } else {
349
        } else {
332
            $cpuvirt = $this->sys->getVirtualizer(); // previous info from _cpuinfo()
350
            $cpuvirt = $this->sys->getVirtualizer(); // previous info from _cpuinfo()
333
 
351
 
334
            $novm = true;
352
            $novm = true;
335
            // code based on src/basic/virt.c from systemd-detect-virt source code (https://github.com/systemd/systemd)
353
            // code based on src/basic/virt.c from systemd-detect-virt source code (https://github.com/systemd/systemd)
336
 
354
 
337
            // First, try to detect Oracle Virtualbox and Amazon EC2 Nitro, even if they use KVM, as well as Xen even if
355
            // First, try to detect Oracle Virtualbox, Amazon EC2 Nitro and Parallels, even if they use KVM,
338
            // it cloaks as Microsoft Hyper-V. Attempt to detect uml at this stage also since it runs as a user-process
356
            // as well as Xen even if it cloaks as Microsoft Hyper-V. Attempt to detect uml at this stage also
339
            // nested inside other VMs. Also check for Xen now, because Xen PV mode does not override CPUID when nested
357
            // since it runs as a user-process nested inside other VMs. Also check for Xen now, because Xen PV
340
            // inside another hypervisor.
358
            // mode does not override CPUID when nested inside another hypervisor.
341
            $machine_info = $this->_get_machine_info();
359
            $machine_info = $this->_get_machine_info();
342
            if (isset($machine_info['hypervisor'])) {
360
            if (isset($machine_info['hypervisor'])) {
343
                $hypervisor = $machine_info['hypervisor'];
361
                $hypervisor = $machine_info['hypervisor'];
344
                if (($hypervisor === 'oracle') || ($hypervisor === 'amazon') || ($hypervisor === 'xen')) {
362
                if (($hypervisor === 'oracle') || ($hypervisor === 'amazon') || ($hypervisor === 'xen') || ($hypervisor === 'parallels')) {
345
                    $this->sys->setVirtualizer($hypervisor);
363
                    $this->sys->setVirtualizer($hypervisor);
346
                    $novm = false;
364
                    $novm = false;
347
                }
365
                }
348
            }
366
            }
349
 
367
 
350
            // Detect UML
368
            // Detect UML
351
            if ($novm) {
369
            if ($novm) {
352
                if (isset($cpuvirt["cpuid:UserModeLinux"])) {
370
                if (isset($cpuvirt["cpuid:UserModeLinux"])) {
353
                    $this->sys->setVirtualizer('uml'); // User-mode Linux
371
                    $this->sys->setVirtualizer('uml'); // User-mode Linux
354
                    $novm = false;
372
                    $novm = false;
355
                }
373
                }
356
            }
374
            }
357
 
375
 
358
            // Detect Xen
376
            // Detect Xen
359
            if ($novm && is_dir('/proc/xen')) {
377
            if ($novm && is_dir('/proc/xen')) {
360
                // xen Dom0 is detected as XEN in hypervisor and maybe others.
378
                // xen Dom0 is detected as XEN in hypervisor and maybe others.
361
                // In order to detect the Dom0 as not virtualization we need to
379
                // In order to detect the Dom0 as not virtualization we need to
362
                // double-check it
380
                // double-check it
363
                if (CommonFunctions::rfts('/sys/hypervisor/properties/features', $features, 1, 4096, false)) {
381
                if (CommonFunctions::rfts('/sys/hypervisor/properties/features', $features, 1, 4096, false)) {
364
                    if ((hexdec($features) & 2048) == 0) { // XENFEAT_dom0 is not set
382
                    if ((hexdec($features) & 2048) == 0) { // XENFEAT_dom0 is not set
365
                        $this->sys->setVirtualizer('xen'); // Xen hypervisor (only domU, not dom0)
383
                        $this->sys->setVirtualizer('xen'); // Xen hypervisor (only domU, not dom0)
366
                        $novm = false;
384
                        $novm = false;
367
                    }
385
                    }
368
                } elseif (CommonFunctions::rfts('/proc/xen/capabilities', $capabilities, 1, 4096, false) && !preg_match('/control_d/', $capabilities)) { // control_d not in capabilities
386
                } elseif (CommonFunctions::rfts('/proc/xen/capabilities', $capabilities, 1, 4096, false) && !preg_match('/control_d/', $capabilities)) { // control_d not in capabilities
369
                    $this->sys->setVirtualizer('xen'); // Xen hypervisor (only domU, not dom0)
387
                    $this->sys->setVirtualizer('xen'); // Xen hypervisor (only domU, not dom0)
370
                    $novm = false;
388
                    $novm = false;
371
                }
389
                }
372
            }
390
            }
373
 
391
 
374
            // Second, try to detect from CPUID, this will report KVM for whatever software is used even if info in DMI is overwritten.
392
            // Second, try to detect from CPUID, this will report KVM for whatever software is used even if info in DMI is overwritten.
375
            // Since the vendor_id in /proc/cpuinfo is overwritten on virtualization we use values from msr-cpuid.
393
            // Since the vendor_id in /proc/cpuinfo is overwritten on virtualization we use values from msr-cpuid.
376
            if ($novm && CommonFunctions::executeProgram('msr-cpuid', '', $bufr, false)
394
            if ($novm && CommonFunctions::executeProgram('msr-cpuid', '', $bufr, false)
377
               && (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))) {
395
               && (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))) {
378
                $virt = CommonFunctions::decodevirtualizer($cpuid[1].$cpuid[2].$cpuid[3]);
396
                $virt = CommonFunctions::decodevirtualizer($cpuid[1].$cpuid[2].$cpuid[3]);
379
                if ($virt !== null) {
397
                if ($virt !== null) {
380
                    $this->sys->setVirtualizer($virt);
398
                    $this->sys->setVirtualizer($virt);
381
                }
399
                }
382
            }
400
            }
383
 
401
 
384
            // Third, try to detect from DMI.
402
            // Third, try to detect from DMI.
385
            if ($novm && isset($hypervisor)) {
403
            if ($novm && isset($hypervisor)) {
386
                $this->sys->setVirtualizer($hypervisor);
404
                $this->sys->setVirtualizer($hypervisor);
387
                $novm = false;
405
                $novm = false;
388
            }
406
            }
389
 
407
 
390
            // Check high-level hypervisor sysfs file
408
            // Check high-level hypervisor sysfs file
391
            if ($novm && CommonFunctions::rfts('/sys/hypervisor/type', $type, 1, 4096, false) && ($type === "xen")) {
409
            if ($novm && CommonFunctions::rfts('/sys/hypervisor/type', $type, 1, 4096, false) && ($type === "xen")) {
392
                $this->sys->setVirtualizer('xen'); // Xen hypervisor
410
                $this->sys->setVirtualizer('xen'); // Xen hypervisor
393
                $novm = false;
411
                $novm = false;
394
            }
412
            }
395
 
413
 
396
            if ($novm) {
414
            if ($novm) {
397
                if (CommonFunctions::rfts('/proc/device-tree/hypervisor/compatible', $compatible, 1, 4096, false)) {
415
                if (CommonFunctions::rfts('/proc/device-tree/hypervisor/compatible', $compatible, 1, 4096, false)) {
398
                    switch ($compatible) {
416
                    switch ($compatible) {
399
                    case 'linux,kvm':
417
                    case 'linux,kvm':
400
                        $this->sys->setVirtualizer('kvm'); // KVM
418
                        $this->sys->setVirtualizer('kvm'); // KVM
401
                        $novm = false;
419
                        $novm = false;
402
                        break;
420
                        break;
403
                    case 'vmware':
421
                    case 'vmware':
404
                        $this->sys->setVirtualizer('vmware'); // VMware
422
                        $this->sys->setVirtualizer('vmware'); // VMware
405
                        $novm = false;
423
                        $novm = false;
406
                        break;
424
                        break;
407
                    case 'xen':
425
                    case 'xen':
408
                        $this->sys->setVirtualizer('xen'); // Xen hypervisor
426
                        $this->sys->setVirtualizer('xen'); // Xen hypervisor
409
                        $novm = false;
427
                        $novm = false;
410
                    }
428
                    }
411
                } else {
429
                } else {
412
                    if (CommonFunctions::fileexists('/proc/device-tree/ibm,partition-name')
430
                    if (CommonFunctions::fileexists('/proc/device-tree/ibm,partition-name')
413
                       && CommonFunctions::fileexists('/proc/device-tree/hmc-managed?')
431
                       && CommonFunctions::fileexists('/proc/device-tree/hmc-managed?')
414
                       && CommonFunctions::fileexists('/proc/device-tree/chosen/qemu,graphic-width')) {
432
                       && CommonFunctions::fileexists('/proc/device-tree/chosen/qemu,graphic-width')) {
415
                        $this->sys->setVirtualizer('powervm'); // IBM PowerVM hypervisor
433
                        $this->sys->setVirtualizer('powervm'); // IBM PowerVM hypervisor
416
                        $novm = false;
434
                        $novm = false;
417
                    } else {
435
                    } else {
418
                        $names = CommonFunctions::findglob('/proc/device-tree', GLOB_NOSORT);
436
                        $names = CommonFunctions::findglob('/proc/device-tree', GLOB_NOSORT);
419
                        if (is_array($names) && (($total = count($names)) > 0)) {
437
                        if (is_array($names) && (($total = count($names)) > 0)) {
420
                            for ($i = 0; $i < $total; $i++) {
438
                            for ($i = 0; $i < $total; $i++) {
421
                                if (preg_match('/fw-cfg/', $names[$i])) {
439
                                if (preg_match('/fw-cfg/', $names[$i])) {
422
                                    $this->sys->setVirtualizer('qemu'); // QEMU
440
                                    $this->sys->setVirtualizer('qemu'); // QEMU
423
                                    $novm = false;
441
                                    $novm = false;
424
                                    break;
442
                                    break;
425
                                }
443
                                }
426
                            }
444
                            }
427
                        }
445
                        }
428
                    }
446
                    }
429
                }
447
                }
430
            }
448
            }
431
 
449
 
432
            if ($novm && CommonFunctions::rfts('/proc/sysinfo', $sysinfo, 0, 4096, false) && preg_match('//VM00 Control Program:\s*(\S+)/m', $sysinfo, $vcp)) {
450
            if ($novm && CommonFunctions::rfts('/proc/sysinfo', $sysinfo, 0, 4096, false) && preg_match('//VM00 Control Program:\s*(\S+)/m', $sysinfo, $vcp)) {
433
                if ($vcp[1] === 'z/VM') {
451
                if ($vcp[1] === 'z/VM') {
434
                    $this->sys->setVirtualizer('zvm'); // s390 z/VM
452
                    $this->sys->setVirtualizer('zvm'); // s390 z/VM
435
                } else {
453
                } else {
436
                    $this->sys->setVirtualizer('kvm'); // KVM
454
                    $this->sys->setVirtualizer('kvm'); // KVM
437
                }
455
                }
438
                $novm = false;
456
                $novm = false;
439
            }
457
            }
440
 
458
 
441
            // Additional tests outside of the systemd-detect-virt source code
459
            // Additional tests outside of the systemd-detect-virt source code
442
            if ($novm && (($dmesg = $this->_get_dmesg_info()) !== null) && isset($dmesg['hypervisor'])) {
460
            if ($novm && (($dmesg = $this->_get_dmesg_info()) !== null) && isset($dmesg['hypervisor'])) {
443
                switch ($dmesg['hypervisor']) {
461
                switch ($dmesg['hypervisor']) {
444
                case 'VMware':
462
                case 'VMware':
445
                    $this->sys->setVirtualizer('vmware'); // VMware
463
                    $this->sys->setVirtualizer('vmware'); // VMware
446
                    $novm = false;
464
                    $novm = false;
447
                    break;
465
                    break;
448
                case 'KVM':
466
                case 'KVM':
449
                    $this->sys->setVirtualizer('kvm'); // KVM
467
                    $this->sys->setVirtualizer('kvm'); // KVM
450
                    $novm = false;
468
                    $novm = false;
451
                    break;
469
                    break;
452
                case 'Microsoft HyperV':
470
                case 'Microsoft HyperV':
453
                case 'Microsoft Hyper-V':
471
                case 'Microsoft Hyper-V':
454
                    $this->sys->setVirtualizer('microsoft'); // Hyper-V
472
                    $this->sys->setVirtualizer('microsoft'); // Hyper-V
455
                    $novm = false;
473
                    $novm = false;
456
                    break;
474
                    break;
457
                case 'ACRN':
475
                case 'ACRN':
458
                    $this->sys->setVirtualizer('acrn'); // ACRN hypervisor
476
                    $this->sys->setVirtualizer('acrn'); // ACRN hypervisor
459
                    $novm = false;
477
                    $novm = false;
460
                    break;
478
                    break;
461
                case 'Jailhouse':
479
                case 'Jailhouse':
462
                    $this->sys->setVirtualizer('jailhouse'); // Jailhouse
480
                    $this->sys->setVirtualizer('jailhouse'); // Jailhouse
463
                    $novm = false;
481
                    $novm = false;
464
                    break;
482
                    break;
465
                case 'Xen':
483
                case 'Xen':
466
                case 'Xen PV':
484
                case 'Xen PV':
467
                case 'Xen HVM':
485
                case 'Xen HVM':
468
                    // xen Dom0 is detected as XEN in hypervisor and maybe others.
486
                    // xen Dom0 is detected as XEN in hypervisor and maybe others.
469
                    // In order to detect the Dom0 as not virtualization we need to
487
                    // In order to detect the Dom0 as not virtualization we need to
470
                    // double-check it
488
                    // double-check it
471
                    if (CommonFunctions::rfts('/sys/hypervisor/properties/features', $features, 1, 4096, false)) {
489
                    if (CommonFunctions::rfts('/sys/hypervisor/properties/features', $features, 1, 4096, false)) {
472
                        if ((hexdec($features) & 2048) == 0) { // XENFEAT_dom0 is not set
490
                        if ((hexdec($features) & 2048) == 0) { // XENFEAT_dom0 is not set
473
                            $this->sys->setVirtualizer('xen'); // Xen hypervisor (only domU, not dom0)
491
                            $this->sys->setVirtualizer('xen'); // Xen hypervisor (only domU, not dom0)
474
                            $novm = false;
492
                            $novm = false;
475
                        }
493
                        }
476
                    } elseif (CommonFunctions::rfts('/proc/xen/capabilities', $capabilities, 1, 4096, false) && !preg_match('/control_d/', $capabilities)) { // control_d not in capabilities
494
                    } elseif (CommonFunctions::rfts('/proc/xen/capabilities', $capabilities, 1, 4096, false) && !preg_match('/control_d/', $capabilities)) { // control_d not in capabilities
477
                        $this->sys->setVirtualizer('xen'); // Xen hypervisor (only domU, not dom0)
495
                        $this->sys->setVirtualizer('xen'); // Xen hypervisor (only domU, not dom0)
478
                        $novm = false;
496
                        $novm = false;
479
                    }
497
                    }
480
                }
498
                }
481
            }
499
            }
482
 
500
 
483
            // Detect QEMU cpu
501
            // Detect QEMU cpu
484
            if ($novm && isset($cpuvirt["cpuid:QEMU"])) {
502
            if ($novm && isset($cpuvirt["cpuid:QEMU"])) {
485
                $this->sys->setVirtualizer('qemu'); // QEMU
503
                $this->sys->setVirtualizer('qemu'); // QEMU
486
                $novm = false;
504
                $novm = false;
487
            }
505
            }
488
 
506
 
489
            if ($novm && isset($cpuvirt["hypervisor"])) {
507
            if ($novm && isset($cpuvirt["hypervisor"])) {
490
                $this->sys->setVirtualizer('unknown');
508
                $this->sys->setVirtualizer('unknown');
491
            }
509
            }
492
 
510
 
493
            if ((count(CommonFunctions::gdc('/proc/vz', false)) == 0) && (count(CommonFunctions::gdc('/proc/bc', false)) > 0)) {
511
            if ((count(CommonFunctions::gdc('/proc/vz', false)) == 0) && (count(CommonFunctions::gdc('/proc/bc', false)) > 0)) {
494
                $this->sys->setVirtualizer('openvz'); // OpenVZ/Virtuozzo
512
                $this->sys->setVirtualizer('openvz'); // OpenVZ/Virtuozzo
495
            }
513
            }
496
 
514
 
497
            if (($verBuf = $this->_get_kernel_string()) !== "") {
515
            if (($verBuf = $this->_get_kernel_string()) !== "") {
498
                if (preg_match('/^[\d\.-]+-Microsoft/', $verBuf)) {
516
                if (preg_match('/^[\d\.-]+-Microsoft/', $verBuf)) {
499
                    $this->sys->setVirtualizer('wsl'); // Windows Subsystem for Linux
517
                    $this->sys->setVirtualizer('wsl'); // Windows Subsystem for Linux
500
                } elseif (preg_match('/^[\d\.-]+-microsoft-standard/', $verBuf)) {
518
                } elseif (preg_match('/^[\d\.-]+-microsoft-standard/', $verBuf)) {
501
                    $this->sys->setVirtualizer('wsl2'); // Windows Subsystem for Linux 2
519
                    $this->sys->setVirtualizer('wsl2'); // Windows Subsystem for Linux 2
502
                }
520
                }
503
            }
521
            }
504
 
522
 
505
            if (CommonFunctions::rfts('/proc/self/cgroup', $strBuf2, 0, 4096, false)) {
523
            if (CommonFunctions::rfts('/proc/self/cgroup', $strBuf2, 0, 4096, false)) {
506
               if (preg_match('/:\/lxc\//m', $strBuf2)) {
524
               if (preg_match('/:\/lxc\//m', $strBuf2)) {
507
                    $this->sys->setVirtualizer('lxc'); // Linux container
525
                    $this->sys->setVirtualizer('lxc'); // Linux container
508
                } elseif (preg_match('/:\/docker\//m', $strBuf2)) {
526
                } elseif (preg_match('/:\/docker\//m', $strBuf2)) {
509
                    $this->sys->setVirtualizer('docker'); // Docker
527
                    $this->sys->setVirtualizer('docker'); // Docker
510
                } elseif (preg_match('/:\/system\.slice\/docker\-/m', $strBuf2)) {
528
                } elseif (preg_match('/:\/system\.slice\/docker\-/m', $strBuf2)) {
511
                    $this->sys->setVirtualizer('docker'); // Docker
529
                    $this->sys->setVirtualizer('docker'); // Docker
512
                }
530
                }
513
            }
531
            }
514
        }
532
        }
515
    }
533
    }
516
 
534
 
517
    /**
535
    /**
518
     * UpTime
536
     * UpTime
519
     * time the system is running
537
     * time the system is running
520
     *
538
     *
521
     * @return void
539
     * @return void
522
     */
540
     */
523
    protected function _uptime()
541
    protected function _uptime($bufu = null)
524
    {
542
    {
525
        if (CommonFunctions::rfts('/proc/uptime', $buf, 1, 4096, PSI_OS != 'Android')) {
543
        if (CommonFunctions::rfts('/proc/uptime', $buf, 1, 4096, PSI_OS != 'Android')) {
526
            $ar_buf = preg_split('/ /', $buf);
544
            $ar_buf = preg_split('/ /', $buf);
527
            $this->sys->setUptime(trim($ar_buf[0]));
545
            $this->sys->setUptime(trim($ar_buf[0]));
528
        } elseif (($this->_uptime !== null) || CommonFunctions::executeProgram('uptime', '', $this->_uptime)) {
546
        } elseif (($this->_uptime !== null) || ($bufu !== null) || CommonFunctions::executeProgram('uptime', '', $bufu)) {
-
 
547
            if (($this->_uptime === null) && ($bufu !== null)) {
-
 
548
                $this->_uptime = $bufu;
-
 
549
            }
529
            if (preg_match("/up (\d+) day[s]?,[ ]+(\d+):(\d+),/", $this->_uptime, $ar_buf)) {
550
            if (preg_match("/up (\d+) day[s]?,[ ]+(\d+):(\d+),/", $this->_uptime, $ar_buf)) {
530
                $min = $ar_buf[3];
551
                $min = $ar_buf[3];
531
                $hours = $ar_buf[2];
552
                $hours = $ar_buf[2];
532
                $days = $ar_buf[1];
553
                $days = $ar_buf[1];
533
                $this->sys->setUptime($days * 86400 + $hours * 3600 + $min * 60);
554
                $this->sys->setUptime($days * 86400 + $hours * 3600 + $min * 60);
534
            } elseif (preg_match("/up (\d+) day[s]?,[ ]+(\d+) min,/", $this->_uptime, $ar_buf)) {
555
            } elseif (preg_match("/up (\d+) day[s]?,[ ]+(\d+) min,/", $this->_uptime, $ar_buf)) {
535
                $min = $ar_buf[2];
556
                $min = $ar_buf[2];
536
                $days = $ar_buf[1];
557
                $days = $ar_buf[1];
537
                $this->sys->setUptime($days * 86400 + $min * 60);
558
                $this->sys->setUptime($days * 86400 + $min * 60);
538
            } elseif (preg_match("/up[ ]+(\d+):(\d+),/", $this->_uptime, $ar_buf)) {
559
            } elseif (preg_match("/up[ ]+(\d+):(\d+),/", $this->_uptime, $ar_buf)) {
539
                $min = $ar_buf[2];
560
                $min = $ar_buf[2];
540
                $hours = $ar_buf[1];
561
                $hours = $ar_buf[1];
541
                $this->sys->setUptime($hours * 3600 + $min * 60);
562
                $this->sys->setUptime($hours * 3600 + $min * 60);
-
 
563
            } elseif (preg_match("/up[ ]+(\d+):(\d+):(\d+)/", $this->_uptime, $ar_buf)) {
-
 
564
                $sec = $ar_buf[3];
-
 
565
                $min = $ar_buf[2];
-
 
566
                $hours = $ar_buf[1];
-
 
567
                $this->sys->setUptime($hours * 3600 + $min * 60 + $sec);
542
            } elseif (preg_match("/up[ ]+(\d+) min,/", $this->_uptime, $ar_buf)) {
568
            } elseif (preg_match("/up[ ]+(\d+) min,/", $this->_uptime, $ar_buf)) {
543
                $min = $ar_buf[1];
569
                $min = $ar_buf[1];
544
                $this->sys->setUptime($min * 60);
570
                $this->sys->setUptime($min * 60);
-
 
571
            } elseif (preg_match("/up[ ]+(\d+) day[s]?,[ ]+(\d+) hour[s]?,[ ]+(\d+) minute[s]?/", $this->_uptime, $ar_buf)) {
-
 
572
                $min = $ar_buf[3];
-
 
573
                $hours = $ar_buf[2];
-
 
574
                $days = $ar_buf[1];
-
 
575
                $this->sys->setUptime($days * 86400 + $hours * 3600 + $min * 60);
545
            }
576
            }
546
        }
577
        }
547
    }
578
    }
548
 
579
 
549
    /**
580
    /**
550
     * Processor Load
581
     * Processor Load
551
     * optionally create a loadbar
582
     * optionally create a loadbar
552
     *
583
     *
553
     * @return void
584
     * @return void
554
     */
585
     */
555
    protected function _loadavg()
586
    protected function _loadavg($buf = null)
556
    {
587
    {
557
        if (CommonFunctions::rfts('/proc/loadavg', $buf, 1, 4096, PSI_OS != 'Android')) {
588
        if ((($buf !== null) || CommonFunctions::rfts('/proc/loadavg', $buf, 1, 4096, PSI_OS != 'Android')) && preg_match("/^\d/", trim($buf))) {
558
            $result = preg_split("/\s/", $buf, 4);
589
            $result = preg_split("/\s/", $buf, 4);
559
            // don't need the extra values, only first three
590
            // don't need the extra values, only first three
560
            unset($result[3]);
591
            unset($result[3]);
561
            $this->sys->setLoad(implode(' ', $result));
592
            $this->sys->setLoad(implode(' ', $result));
562
        } elseif ((($this->_uptime !== null) || CommonFunctions::executeProgram('uptime', '', $this->_uptime)) && preg_match("/load average: (.*), (.*), (.*)$/", $this->_uptime, $ar_buf)) {
593
        } elseif (($buf === null) && ((($this->_uptime !== null) || CommonFunctions::executeProgram('uptime', '', $this->_uptime)) && preg_match("/load average: (.*), (.*), (.*)$/", $this->_uptime, $ar_buf))) {
563
            $this->sys->setLoad($ar_buf[1].' '.$ar_buf[2].' '.$ar_buf[3]);
594
              $this->sys->setLoad($ar_buf[1].' '.$ar_buf[2].' '.$ar_buf[3]);
564
        }
595
        }
565
        if (PSI_LOAD_BAR) {
596
        if (PSI_LOAD_BAR) {
566
            $this->sys->setLoadPercent($this->_parseProcStat('cpu'));
597
            $this->sys->setLoadPercent($this->_parseProcStat('cpu'));
567
        }
598
        }
568
    }
599
    }
569
 
600
 
570
    /**
601
    /**
571
     * fill the load for a individual cpu, through parsing /proc/stat for the specified cpu
602
     * fill the load for a individual cpu, through parsing /proc/stat for the specified cpu
572
     *
603
     *
573
     * @param String $cpuline cpu for which load should be meassured
604
     * @param String $cpuline cpu for which load should be meassured
574
     *
605
     *
575
     * @return int
606
     * @return int
576
     */
607
     */
577
    protected function _parseProcStat($cpuline)
608
    protected function _parseProcStat($cpuline)
578
    {
609
    {
579
        if ($this->_cpu_loads === null) {
610
        if ($this->_cpu_loads === null) {
580
            $this->_cpu_loads = array();
611
            $this->_cpu_loads = array();
581
 
612
 
582
            $cpu_tmp = array();
613
            $cpu_tmp = array();
583
            if (CommonFunctions::rfts('/proc/stat', $buf, 0, 4096, PSI_DEBUG && (PSI_OS != 'Android'))) {
614
            if (CommonFunctions::rfts('/proc/stat', $buf, 0, 4096, PSI_DEBUG && (PSI_OS != 'Android'))) {
584
                if (preg_match_all('/^(cpu[0-9]*) (.*)/m', $buf, $matches, PREG_SET_ORDER)) {
615
                if (preg_match_all('/^(cpu[0-9]*) (.*)/m', $buf, $matches, PREG_SET_ORDER)) {
585
                    foreach ($matches as $line) {
616
                    foreach ($matches as $line) {
586
                        $cpu = $line[1];
617
                        $cpu = $line[1];
587
                        $buf2 = $line[2];
618
                        $buf2 = $line[2];
588
 
619
 
589
                        $cpu_tmp[$cpu] = array();
620
                        $cpu_tmp[$cpu] = array();
590
 
621
 
591
                        $ab = 0;
622
                        $ab = 0;
592
                        $ac = 0;
623
                        $ac = 0;
593
                        $ad = 0;
624
                        $ad = 0;
594
                        $ae = 0;
625
                        $ae = 0;
595
                        sscanf($buf2, "%Ld %Ld %Ld %Ld", $ab, $ac, $ad, $ae);
626
                        sscanf($buf2, "%Ld %Ld %Ld %Ld", $ab, $ac, $ad, $ae);
596
                        $cpu_tmp[$cpu]['load'] = $ab + $ac + $ad; // cpu.user + cpu.sys
627
                        $cpu_tmp[$cpu]['load'] = $ab + $ac + $ad; // cpu.user + cpu.sys
597
                        $cpu_tmp[$cpu]['total'] = $ab + $ac + $ad + $ae; // cpu.total
628
                        $cpu_tmp[$cpu]['total'] = $ab + $ac + $ad + $ae; // cpu.total
598
                    }
629
                    }
599
                }
630
                }
600
 
631
 
601
                // we need a second value, wait 1 second befor getting (< 1 second no good value will occour)
632
                // we need a second value, wait 1 second befor getting (< 1 second no good value will occour)
602
                sleep(1);
633
                sleep(1);
603
 
634
 
604
                if (CommonFunctions::rfts('/proc/stat', $buf, 0, 4096, PSI_DEBUG)) {
635
                if (CommonFunctions::rfts('/proc/stat', $buf, 0, 4096, PSI_DEBUG)) {
605
                    if (preg_match_all('/^(cpu[0-9]*) (.*)/m', $buf, $matches, PREG_SET_ORDER)) {
636
                    if (preg_match_all('/^(cpu[0-9]*) (.*)/m', $buf, $matches, PREG_SET_ORDER)) {
606
                        foreach ($matches as $line) {
637
                        foreach ($matches as $line) {
607
                            $cpu = $line[1];
638
                            $cpu = $line[1];
608
                            if (isset($cpu_tmp[$cpu])) {
639
                            if (isset($cpu_tmp[$cpu])) {
609
                                $buf2 = $line[2];
640
                                $buf2 = $line[2];
610
 
641
 
611
                                $ab = 0;
642
                                $ab = 0;
612
                                $ac = 0;
643
                                $ac = 0;
613
                                $ad = 0;
644
                                $ad = 0;
614
                                $ae = 0;
645
                                $ae = 0;
615
                                sscanf($buf2, "%Ld %Ld %Ld %Ld", $ab, $ac, $ad, $ae);
646
                                sscanf($buf2, "%Ld %Ld %Ld %Ld", $ab, $ac, $ad, $ae);
616
                                $load2 = $ab + $ac + $ad; // cpu.user + cpu.sys
647
                                $load2 = $ab + $ac + $ad; // cpu.user + cpu.sys
617
                                $total2 = $ab + $ac + $ad + $ae; // cpu.total
648
                                $total2 = $ab + $ac + $ad + $ae; // cpu.total
618
                                $total = $cpu_tmp[$cpu]['total'];
649
                                $total = $cpu_tmp[$cpu]['total'];
619
                                $load = $cpu_tmp[$cpu]['load'];
650
                                $load = $cpu_tmp[$cpu]['load'];
620
                                $this->_cpu_loads[$cpu] = 0;
651
                                $this->_cpu_loads[$cpu] = 0;
621
                                if ($total > 0 && $total2 > 0 && $load > 0 && $load2 > 0 && $total2 != $total && $load2 != $load) {
652
                                if ($total > 0 && $total2 > 0 && $load > 0 && $load2 > 0 && $total2 != $total && $load2 != $load) {
622
                                    $this->_cpu_loads[$cpu] = (100 * ($load2 - $load)) / ($total2 - $total);
653
                                    $this->_cpu_loads[$cpu] = (100 * ($load2 - $load)) / ($total2 - $total);
623
                                }
654
                                }
624
                            }
655
                            }
625
                        }
656
                        }
626
                    }
657
                    }
627
                }
658
                }
628
            }
659
            }
629
        }
660
        }
630
 
661
 
631
        if (isset($this->_cpu_loads[$cpuline])) {
662
        if (isset($this->_cpu_loads[$cpuline])) {
632
            return $this->_cpu_loads[$cpuline];
663
            return $this->_cpu_loads[$cpuline];
633
        } else {
664
        } else {
634
            return null;
665
            return null;
635
        }
666
        }
636
    }
667
    }
637
 
668
 
638
    /**
669
    /**
639
     * CPU information
670
     * CPU information
640
     * All of the tags here are highly architecture dependant.
671
     * All of the tags here are highly architecture dependant.
641
     *
672
     *
642
     * @return void
673
     * @return void
643
     */
674
     */
644
    protected function _cpuinfo()
675
    protected function _cpuinfo($bufr = null)
645
    {
676
    {
646
        if (CommonFunctions::rfts('/proc/cpuinfo', $bufr)) {
677
        if (($bufr !== null) || CommonFunctions::rfts('/proc/cpuinfo', $bufr)) {
647
 
-
 
648
            $cpulist = null;
678
            $cpulist = null;
649
            $raslist = null;
679
            $raslist = null;
650
 
680
 
651
            // sparc
681
            // sparc
652
            if (preg_match('/\nCpu(\d+)Bogo\s*:/i', $bufr)) {
682
            if (preg_match('/\nCpu(\d+)Bogo\s*:/i', $bufr)) {
653
                $bufr = preg_replace('/\nCpu(\d+)ClkTck\s*:/i', "\nCpu0ClkTck:", preg_replace('/\nCpu(\d+)Bogo\s*:/i', "\n\nprocessor: $1\nCpu0Bogo:", $bufr));
683
                $bufr = preg_replace('/\nCpu(\d+)ClkTck\s*:/i', "\nCpu0ClkTck:", preg_replace('/\nCpu(\d+)Bogo\s*:/i', "\n\nprocessor: $1\nCpu0Bogo:", $bufr));
654
            } else {
684
            } else {
655
                $bufr = preg_replace('/\nCpu(\d+)ClkTck\s*:/i', "\n\nprocessor: $1\nCpu0ClkTck:", $bufr);
685
                $bufr = preg_replace('/\nCpu(\d+)ClkTck\s*:/i', "\n\nprocessor: $1\nCpu0ClkTck:", $bufr);
656
            }
686
            }
657
 
687
 
658
            if (preg_match('/\nprocessor\s*:\s*\d+\r?\nprocessor\s*:\s*\d+/', $bufr)) {
688
            if (preg_match('/\nprocessor\s*:\s*\d+\r?\nprocessor\s*:\s*\d+/', $bufr)) {
659
                $bufr = preg_replace('/^(processor\s*:\s*\d+)\r?$/m', "$1\n", $bufr);
689
                $bufr = preg_replace('/^(processor\s*:\s*\d+)\r?$/m', "$1\n", $bufr);
660
            }
690
            }
661
 
691
 
662
            // IBM/S390
692
            // IBM/S390
663
            $bufr = preg_replace('/\ncpu number\s*:\s*(\d+)\r?\ncpu MHz dynamic\s*:\s*(\d+)/m', "\nprocessor:$1\nclock:$2", $bufr);
693
            $bufr = preg_replace('/\ncpu number\s*:\s*(\d+)\r?\ncpu MHz dynamic\s*:\s*(\d+)/m', "\nprocessor:$1\nclock:$2", $bufr);
664
 
694
 
665
            $processors = preg_split('/\s?\n\s?\n/', trim($bufr));
695
            $processors = preg_split('/\s?\n\s?\n/', trim($bufr));
666
 
696
 
667
            //first stage
697
            //first stage
668
            $_arch = null;
698
            $_arch = null;
669
            $_impl = null;
699
            $_impl = null;
670
            $_part = null;
700
            $_part = null;
671
            $_vari = null;
701
            $_vari = null;
672
            $_hard = null;
702
            $_hard = null;
673
            $_revi = null;
703
            $_revi = null;
674
            $_cpus = null;
704
            $_cpus = null;
675
            $_buss = null;
705
            $_buss = null;
676
            $_bogo = null;
706
            $_bogo = null;
677
            $_vend = null;
707
            $_vend = null;
678
            $procname = null;
708
            $procname = null;
679
            foreach ($processors as $processor) if (!preg_match('/^\s*processor\s*:/mi', $processor)) {
709
            foreach ($processors as $processor) if (!preg_match('/^\s*processor\s*:/mi', $processor)) {
680
                $details = preg_split("/\n/", $processor, -1, PREG_SPLIT_NO_EMPTY);
710
                $details = preg_split("/\n/", $processor, -1, PREG_SPLIT_NO_EMPTY);
681
                foreach ($details as $detail) {
711
                foreach ($details as $detail) {
682
                    $arrBuff = preg_split('/\s*:\s*/', trim($detail));
712
                    $arrBuff = preg_split('/\s*:\s*/', trim($detail));
683
                    if ((count($arrBuff) == 2) && (($arrBuff1 = trim($arrBuff[1])) !== '')) {
713
                    if ((count($arrBuff) == 2) && (($arrBuff1 = trim($arrBuff[1])) !== '')) {
684
                        switch (strtolower($arrBuff[0])) {
714
                        switch (strtolower($arrBuff[0])) {
685
                        case 'cpu architecture':
715
                        case 'cpu architecture':
686
                            $_arch = $arrBuff1;
716
                            $_arch = $arrBuff1;
687
                            break;
717
                            break;
688
                        case 'cpu implementer':
718
                        case 'cpu implementer':
689
                            $_impl = $arrBuff1;
719
                            $_impl = $arrBuff1;
690
                            break;
720
                            break;
691
                        case 'cpu part':
721
                        case 'cpu part':
692
                            $_part = $arrBuff1;
722
                            $_part = $arrBuff1;
693
                            break;
723
                            break;
694
                        case 'cpu variant':
724
                        case 'cpu variant':
695
                            $_vari = $arrBuff1;
725
                            $_vari = $arrBuff1;
696
                            break;
726
                            break;
697
                        case 'hardware':
727
                        case 'hardware':
698
                            $_hard = $arrBuff1;
728
                            $_hard = $arrBuff1;
699
                            break;
729
                            break;
700
                        case 'revision':
730
                        case 'revision':
701
                            $_revi = $arrBuff1;
731
                            $_revi = $arrBuff1;
702
                            break;
732
                            break;
703
                        case 'cpu frequency':
733
                        case 'cpu frequency':
704
                            if (preg_match('/^(\d+)\s+Hz/i', $arrBuff1, $bufr2)) {
734
                            if (preg_match('/^(\d+)\s+Hz/i', $arrBuff1, $bufr2)) {
705
                                $_cpus = round($bufr2[1]/1000000);
735
                                $_cpus = round($bufr2[1]/1000000);
-
 
736
                            } elseif (preg_match('/^(\d+)\s+MHz/i', $arrBuff1, $bufr2)) {
-
 
737
                                $_cpus = $bufr2[1];
706
                            }
738
                            }
707
                            break;
739
                            break;
708
                        case 'system bus frequency':
740
                        case 'system bus frequency':
709
                            if (preg_match('/^(\d+)\s+Hz/i', $arrBuff1, $bufr2)) {
741
                            if (preg_match('/^(\d+)\s+Hz/i', $arrBuff1, $bufr2)) {
710
                                $_buss = round($bufr2[1]/1000000);
742
                                $_buss = round($bufr2[1]/1000000);
-
 
743
                            } elseif (preg_match('/^(\d+)\s+MHz/i', $arrBuff1, $bufr2)) {
-
 
744
                                $_buss = $bufr2[1];
711
                            }
745
                            }
712
                            break;
746
                            break;
713
                        case 'bogomips per cpu':
747
                        case 'bogomips per cpu':
714
                            $_bogo = round($arrBuff1);
748
                            $_bogo = round($arrBuff1);
715
                            break;
749
                            break;
716
                        case 'vendor_id':
750
                        case 'vendor_id':
717
                            $_vend = $arrBuff1;
751
                            $_vend = $arrBuff1;
718
                            break;
752
                            break;
719
                        case 'cpu':
753
                        case 'cpu':
720
                            $procname = $arrBuff1;
754
                            $procname = $arrBuff1;
721
                        }
755
                        }
722
                    }
756
                    }
723
                }
757
                }
724
            }
758
            }
725
 
759
 
726
            //second stage
760
            //second stage
727
            $cpucount = 0;
761
            $cpucount = 0;
728
            $speedset = false;
762
            $speedset = false;
729
            foreach ($processors as $processor) if (preg_match('/^\s*processor\s*:/mi', $processor)) {
763
            foreach ($processors as $processor) if (preg_match('/^\s*processor\s*:/mi', $processor)) {
730
                $proc = null;
764
                $proc = null;
731
                $arch = null;
765
                $arch = null;
732
                $impl = null;
766
                $impl = null;
733
                $part = null;
767
                $part = null;
734
                $vari = null;
768
                $vari = null;
735
                $dev = new CpuDevice();
769
                $dev = new CpuDevice();
736
                $details = preg_split("/\n/", $processor, -1, PREG_SPLIT_NO_EMPTY);
770
                $details = preg_split("/\n/", $processor, -1, PREG_SPLIT_NO_EMPTY);
737
                foreach ($details as $detail) {
771
                foreach ($details as $detail) {
738
                    $arrBuff = preg_split('/\s*:\s*/', trim($detail));
772
                    $arrBuff = preg_split('/\s*:\s*/', trim($detail));
739
                    if ((count($arrBuff) == 2) && (($arrBuff1 = trim($arrBuff[1])) !== '')) {
773
                    if ((count($arrBuff) == 2) && (($arrBuff1 = trim($arrBuff[1])) !== '')) {
740
                        switch (strtolower($arrBuff[0])) {
774
                        switch (strtolower($arrBuff[0])) {
741
                        case 'processor':
775
                        case 'processor':
742
                            $proc = $arrBuff1;
776
                            $proc = $arrBuff1;
743
                            if (is_numeric($proc)) {
777
                            if (is_numeric($proc)) {
744
                                if (($procname !== null) && (strlen($procname)>0)) {
778
                                if (($procname !== null) && (strlen($procname) > 0)) {
745
                                    $dev->setModel($procname);
779
                                    $dev->setModel($procname);
746
                                }
780
                                }
747
                            } else {
781
                            } else {
748
                                $procname = $proc;
782
                                $procname = $proc;
749
                                $dev->setModel($procname);
783
                                $dev->setModel($procname);
750
                            }
784
                            }
751
                            break;
785
                            break;
752
                        case 'model name':
786
                        case 'model name':
753
                        case 'cpu model':
787
                        case 'cpu model':
754
                        case 'cpu type':
788
                        case 'cpu type':
755
                        case 'cpu':
789
                        case 'cpu':
756
                            $dev->setModel($arrBuff1);
790
                            $dev->setModel($arrBuff1);
757
                            break;
791
                            break;
-
 
792
                        case 'cpu frequency':
-
 
793
                            if (preg_match('/^(\d+)\s+Hz/i', $arrBuff1, $bufr2)) {
-
 
794
                                if (($tmpsp = round($bufr2[1]/1000000)) > 0) {
-
 
795
                                    $dev->setCpuSpeed($tmpsp);
-
 
796
                                    $speedset = true;
-
 
797
                                }
-
 
798
                            } elseif (preg_match('/^(\d+)\s+MHz/i', $arrBuff1, $bufr2)) {
-
 
799
                                if ($bufr2[1] > 0) {
-
 
800
                                    $dev->setCpuSpeed($bufr2[1]);
-
 
801
                                    $speedset = true;
-
 
802
                                }
-
 
803
                            }
-
 
804
                            break;
758
                        case 'cpu mhz':
805
                        case 'cpu mhz':
759
                        case 'clock':
806
                        case 'clock':
760
                            if ($arrBuff1 > 0) { // openSUSE fix
807
                            if ($arrBuff1 > 0) {
761
                                $dev->setCpuSpeed($arrBuff1);
808
                                $dev->setCpuSpeed($arrBuff1);
762
                                $speedset = true;
809
                                $speedset = true;
763
                            }
810
                            }
764
                            break;
811
                            break;
765
                        case 'cpu mhz static':
812
                        case 'cpu mhz static':
766
                            if ($arrBuff1 > 0) { // openSUSE fix
-
 
767
                                $dev->setCpuSpeedMax($arrBuff1);
813
                            $dev->setCpuSpeedMax($arrBuff1);
768
                            }
-
 
769
                            break;
814
                            break;
770
                        case 'cycle frequency [hz]':
815
                        case 'cycle frequency [hz]':
-
 
816
                            if (($tmpsp = round($arrBuff1/1000000)) > 0) {
771
                            $dev->setCpuSpeed($arrBuff1 / 1000000);
817
                                $dev->setCpuSpeed($tmpsp);
772
                            $speedset = true;
818
                                $speedset = true;
-
 
819
                            }
773
                            break;
820
                            break;
774
                        case 'cpu0clktck':
821
                        case 'cpu0clktck': // Linux sparc64
775
                            $dev->setCpuSpeed(hexdec($arrBuff1) / 1000000); // Linux sparc64
822
                            if (($tmpsp = round(hexdec($arrBuff1)/1000000)) > 0) {
-
 
823
                                $dev->setCpuSpeed($tmpsp);
776
                            $speedset = true;
824
                                $speedset = true;
-
 
825
                            }
777
                            break;
826
                            break;
778
                        case 'l3 cache':
827
                        case 'l3 cache':
779
                        case 'cache size':
828
                        case 'cache size':
780
                            $dev->setCache(trim(preg_replace("/[a-zA-Z]/", "", $arrBuff1)) * 1024);
829
                            $dev->setCache(trim(preg_replace("/[a-zA-Z]/", "", $arrBuff1)) * 1024);
781
                            break;
830
                            break;
782
                        case 'initial bogomips':
831
                        case 'initial bogomips':
783
                        case 'bogomips':
832
                        case 'bogomips':
784
                        case 'cpu0bogo':
833
                        case 'cpu0bogo':
785
                            $dev->setBogomips(round($arrBuff1));
834
                            $dev->setBogomips(round($arrBuff1));
786
                            break;
835
                            break;
787
                        case 'flags':
836
                        case 'flags':
788
                            if (preg_match("/ vmx/", $arrBuff1)) {
837
                            if (preg_match("/ vmx/", $arrBuff1)) {
789
                                $dev->setVirt("vmx");
838
                                $dev->setVirt("vmx");
790
                            } elseif (preg_match("/ svm/", $arrBuff1)) {
839
                            } elseif (preg_match("/ svm/", $arrBuff1)) {
791
                                $dev->setVirt("svm");
840
                                $dev->setVirt("svm");
792
                            }
841
                            }
793
                            if (preg_match("/ hypervisor/", $arrBuff1)) {
842
                            if (preg_match("/ hypervisor/", $arrBuff1)) {
794
                                if ($dev->getVirt() === null) {
843
                                if ($dev->getVirt() === null) {
795
                                    $dev->setVirt("hypervisor");
844
                                    $dev->setVirt("hypervisor");
796
                                }
845
                                }
797
                                if (defined('PSI_SHOW_VIRTUALIZER_INFO') && PSI_SHOW_VIRTUALIZER_INFO && ($this->system_detect_virt === null)) {
846
                                if (defined('PSI_SHOW_VIRTUALIZER_INFO') && PSI_SHOW_VIRTUALIZER_INFO && ($this->system_detect_virt === null)) {
798
                                    $this->sys->setVirtualizer("hypervisor", false);
847
                                    $this->sys->setVirtualizer("hypervisor", false);
799
                                }
848
                                }
800
                            }
849
                            }
801
                            break;
850
                            break;
802
                        case 'i size':
851
                        case 'i size':
803
                        case 'd size':
852
                        case 'd size':
804
                            if ($dev->getCache() === null) {
853
                            if ($dev->getCache() === null) {
805
                                $dev->setCache($arrBuff1 * 1024);
854
                                $dev->setCache($arrBuff1 * 1024);
806
                            } else {
855
                            } else {
807
                                $dev->setCache($dev->getCache() + ($arrBuff1 * 1024));
856
                                $dev->setCache($dev->getCache() + ($arrBuff1 * 1024));
808
                            }
857
                            }
809
                            break;
858
                            break;
810
                        case 'cpu architecture':
859
                        case 'cpu architecture':
811
                            $arch = $arrBuff1;
860
                            $arch = $arrBuff1;
812
                            break;
861
                            break;
813
                        case 'cpu implementer':
862
                        case 'cpu implementer':
814
                            $impl = $arrBuff1;
863
                            $impl = $arrBuff1;
815
                            break;
864
                            break;
816
                        case 'cpu part':
865
                        case 'cpu part':
817
                            $part = $arrBuff1;
866
                            $part = $arrBuff1;
818
                            break;
867
                            break;
819
                        case 'cpu variant':
868
                        case 'cpu variant':
820
                            $vari = $arrBuff1;
869
                            $vari = $arrBuff1;
821
                            break;
870
                            break;
822
                        case 'vendor_id':
871
                        case 'vendor_id':
823
                            $dev->setVendorId($arrBuff1);
872
                            $dev->setVendorId($arrBuff1);
824
                            if (defined('PSI_SHOW_VIRTUALIZER_INFO') && PSI_SHOW_VIRTUALIZER_INFO && preg_match('/^User Mode Linux/', $arrBuff1)) {
873
                            if (defined('PSI_SHOW_VIRTUALIZER_INFO') && PSI_SHOW_VIRTUALIZER_INFO && preg_match('/^User Mode Linux/', $arrBuff1)) {
825
                                $this->sys->setVirtualizer("cpuid:UserModeLinux", false);
874
                                $this->sys->setVirtualizer("cpuid:UserModeLinux", false);
826
                            }
875
                            }
827
                        }
876
                        }
828
                    }
877
                    }
829
                }
878
                }
830
                if ($arch === null) $arch = $_arch;
879
                if ($arch === null) $arch = $_arch;
831
                if ($impl === null) $impl = $_impl;
880
                if ($impl === null) $impl = $_impl;
832
                if ($part === null) $part = $_part;
881
                if ($part === null) $part = $_part;
833
                if ($vari === null) $vari = $_vari;
882
                if ($vari === null) $vari = $_vari;
834
 
883
 
835
                // sparc64 specific code follows
884
                // sparc64 specific code follows
836
                // This adds the ability to display the cache that a CPU has
885
                // This adds the ability to display the cache that a CPU has
837
                // Originally made by Sven Blumenstein <bazik@gentoo.org> in 2004
886
                // Originally made by Sven Blumenstein <bazik@gentoo.org> in 2004
838
                // Modified by Tom Weustink <freshy98@gmx.net> in 2004
887
                // Modified by Tom Weustink <freshy98@gmx.net> in 2004
839
                $sparclist = array('SUNW,UltraSPARC@0,0', 'SUNW,UltraSPARC-II@0,0', 'SUNW,UltraSPARC@1c,0', 'SUNW,UltraSPARC-IIi@1c,0', 'SUNW,UltraSPARC-II@1c,0', 'SUNW,UltraSPARC-IIe@0,0');
888
                $sparclist = array('SUNW,UltraSPARC@0,0', 'SUNW,UltraSPARC-II@0,0', 'SUNW,UltraSPARC@1c,0', 'SUNW,UltraSPARC-IIi@1c,0', 'SUNW,UltraSPARC-II@1c,0', 'SUNW,UltraSPARC-IIe@0,0');
840
                foreach ($sparclist as $name) {
889
                foreach ($sparclist as $name) {
841
                    if (CommonFunctions::rfts('/proc/openprom/'.$name.'/ecache-size', $buf, 1, 32, false)) {
890
                    if (CommonFunctions::rfts('/proc/openprom/'.$name.'/ecache-size', $buf, 1, 32, false)) {
842
                        $dev->setCache(base_convert(trim($buf), 16, 10));
891
                        $dev->setCache(base_convert(trim($buf), 16, 10));
843
                    }
892
                    }
844
                }
893
                }
845
                // sparc64 specific code ends
894
                // sparc64 specific code ends
846
 
895
 
847
                // XScale detection code
896
                // XScale detection code
848
                if (($arch === "5TE") && ($dev->getBogomips() !== null)) {
897
                if (($arch === "5TE") && (($bogo = $dev->getBogomips()) !== null) && ($bogo > 0)) {
849
                    $dev->setCpuSpeed($dev->getBogomips()); // BogoMIPS are not BogoMIPS on this CPU, it's the speed
898
                    $dev->setCpuSpeed($bogo); // BogoMIPS are not BogoMIPS on this CPU, it's the speed
850
                    $speedset = true;
899
                    $speedset = true;
851
                    $dev->setBogomips(null); // no BogoMIPS available, unset previously set BogoMIPS
900
                    $dev->setBogomips(null); // no BogoMIPS available, unset previously set BogoMIPS
852
                }
901
                }
853
 
902
 
854
                if (($dev->getBusSpeed() == 0) && ($_buss !== null)) {
903
                if (($dev->getBusSpeed() == 0) && ($_buss !== null)) {
855
                    $dev->setBusSpeed($_buss);
904
                    $dev->setBusSpeed($_buss);
856
                }
905
                }
857
                if (($dev->getCpuSpeed() == 0) && ($_cpus !== null)) {
906
                if (($dev->getCpuSpeed() == 0) && ($_cpus !== null) && ($_cpus > 0)) {
858
                    $dev->setCpuSpeed($_cpus);
907
                    $dev->setCpuSpeed($_cpus);
859
                    $speedset = true;
908
                    $speedset = true;
860
                }
909
                }
861
                if (($dev->getBogomips() == 0) && ($_bogo !== null)) {
910
                if (($dev->getBogomips() == 0) && ($_bogo !== null)) {
862
                    $dev->setBogomips($_bogo);
911
                    $dev->setBogomips($_bogo);
863
                }
912
                }
864
                if (($dev->getVendorId() === null) && ($_vend !== null)) {
913
                if (($dev->getVendorId() === null) && ($_vend !== null)) {
865
                    $dev->setVendorId($_vend);
914
                    $dev->setVendorId($_vend);
866
                     if (defined('PSI_SHOW_VIRTUALIZER_INFO') && PSI_SHOW_VIRTUALIZER_INFO && preg_match('/^User Mode Linux/', $_vend)) {
915
                     if (defined('PSI_SHOW_VIRTUALIZER_INFO') && PSI_SHOW_VIRTUALIZER_INFO && preg_match('/^User Mode Linux/', $_vend)) {
867
                        $this->sys->setVirtualizer("cpuid:UserModeLinux", false);
916
                        $this->sys->setVirtualizer("cpuid:UserModeLinux", false);
868
                    }
917
                    }
869
                }
918
                }
870
 
919
 
871
                if ($proc !== null) {
920
                if ($proc !== null) {
872
                    if (!is_numeric($proc)) {
921
                    if (!is_numeric($proc)) {
873
                        $proc = 0;
922
                        $proc = 0;
874
                    }
923
                    }
875
                    // variable speed processors specific code follows
924
                    // variable speed processors specific code follows
876
                    if (CommonFunctions::rfts('/sys/devices/system/cpu/cpu'.$proc.'/cpufreq/cpuinfo_cur_freq', $buf, 1, 4096, false)) {
925
                    if (CommonFunctions::rfts('/sys/devices/system/cpu/cpu'.$proc.'/cpufreq/cpuinfo_cur_freq', $buf, 1, 4096, false)
877
                        $dev->setCpuSpeed(trim($buf) / 1000);
926
                       || CommonFunctions::rfts('/sys/devices/system/cpu/cpu'.$proc.'/cpufreq/scaling_cur_freq', $buf, 1, 4096, false)) {
878
                        $speedset = true;
927
                        if (round(trim($buf)/1000) > 0) {
879
                    } elseif (CommonFunctions::rfts('/sys/devices/system/cpu/cpu'.$proc.'/cpufreq/scaling_cur_freq', $buf, 1, 4096, false)) {
-
 
880
                        $dev->setCpuSpeed(trim($buf) / 1000);
928
                            $dev->setCpuSpeed(round(trim($buf)/1000));
881
                        $speedset = true;
929
                            $speedset = true;
882
                    }
930
                        }
883
                    if (CommonFunctions::rfts('/sys/devices/system/cpu/cpu'.$proc.'/cpufreq/cpuinfo_max_freq', $buf, 1, 4096, false)) {
-
 
884
                        $dev->setCpuSpeedMax(trim($buf) / 1000);
-
 
885
                    }
931
                    }
-
 
932
                    if (CommonFunctions::rfts('/sys/devices/system/cpu/cpu'.$proc.'/cpufreq/cpuinfo_max_freq', $buf, 1, 4096, false)
-
 
933
                       || CommonFunctions::rfts('/sys/devices/system/cpu/cpu'.$proc.'/cpufreq/scaling_max_freq', $buf, 1, 4096, false)) {
-
 
934
                        $dev->setCpuSpeedMax(round(trim($buf)/1000));
-
 
935
                    }
886
                    if (CommonFunctions::rfts('/sys/devices/system/cpu/cpu'.$proc.'/cpufreq/cpuinfo_min_freq', $buf, 1, 4096, false)) {
936
                    if (CommonFunctions::rfts('/sys/devices/system/cpu/cpu'.$proc.'/cpufreq/cpuinfo_min_freq', $buf, 1, 4096, false)
-
 
937
                       || CommonFunctions::rfts('/sys/devices/system/cpu/cpu'.$proc.'/cpufreq/scaling_min_freq', $buf, 1, 4096, false)) {
887
                        $dev->setCpuSpeedMin(trim($buf) / 1000);
938
                        $dev->setCpuSpeedMin(round(trim($buf)/1000));
888
                    }
939
                    }
889
                    // variable speed processors specific code ends
940
                    // variable speed processors specific code ends
890
                    if (PSI_LOAD_BAR) {
941
                    if (PSI_LOAD_BAR) {
891
                            $dev->setLoad($this->_parseProcStat('cpu'.$proc));
942
                            $dev->setLoad($this->_parseProcStat('cpu'.$proc));
892
                    }
943
                    }
893
/*
944
/*
894
                    if (CommonFunctions::rfts('/proc/acpi/thermal_zone/THRM/temperature', $buf, 1, 4096, false)
945
                    if (CommonFunctions::rfts('/proc/acpi/thermal_zone/THRM/temperature', $buf, 1, 4096, false)
895
                       &&  preg_match("/(\S+)\sC$/", $buf, $value)) {
946
                       &&  preg_match("/(\S+)\sC$/", $buf, $value)) {
896
                        $dev->setTemp(value[1]);
947
                        $dev->setTemp(value[1]);
897
                    }
948
                    }
898
*/
949
*/
899
                    if (($arch !== null) && ($impl !== null) && ($part !== null)) {
950
                    if (($arch !== null) && ($impl !== null) && ($part !== null)) {
900
                        if (($impl === '0x41')
951
                        if (($impl === '0x41')
901
                           && (($_hard === 'BCM2708') || ($_hard === 'BCM2835') || ($_hard === 'BCM2709') || ($_hard === 'BCM2836') || ($_hard === 'BCM2710') || ($_hard === 'BCM2837') || ($_hard === 'BCM2711') || ($_hard === 'BCM2838'))
952
                           && (($_hard === 'BCM2708') || ($_hard === 'BCM2835') || ($_hard === 'BCM2709') || ($_hard === 'BCM2836') || ($_hard === 'BCM2710') || ($_hard === 'BCM2837') || ($_hard === 'BCM2711') || ($_hard === 'BCM2838'))
902
                           && ($_revi !== null)) { // Raspberry Pi detection (instead of 'cat /proc/device-tree/model')
953
                           && ($_revi !== null)) { // Raspberry Pi detection (instead of 'cat /proc/device-tree/model')
903
                            if ($raslist === null) $raslist = @parse_ini_file(PSI_APP_ROOT."/data/raspberry.ini", true);
954
                            if ($raslist === null) $raslist = @parse_ini_file(PSI_APP_ROOT."/data/raspberry.ini", true);
-
 
955
                            $oldmach = $this->sys->getMachine();
-
 
956
                            if (($oldmach !== '') && preg_match("/^raspberrypi rpi(,.+)/", $oldmach, $machbuf)) {
-
 
957
                                $oldmachend = $machbuf[1];
-
 
958
                            } else {
-
 
959
                                 $oldmachend = '';
-
 
960
                            }
904
                            if ($raslist && !preg_match('/[^0-9a-f]/', $_revi)) {
961
                            if ($raslist && !preg_match('/[^0-9a-f]/', $_revi)) {
905
                                if (($revidec = hexdec($_revi)) & 0x800000) {
962
                                if (($revidec = hexdec($_revi)) & 0x800000) {
906
                                    if ($this->sys->getMachine() === '') {
963
                                    if (($oldmach === '') || ($oldmachend !== '')) {
907
                                        $manufacturer = ($revidec >> 16) & 15;
964
                                        $manufacturer = ($revidec >> 16) & 15;
908
                                        if (isset($raslist['manufacturer'][$manufacturer])) {
965
                                        if (isset($raslist['manufacturer'][$manufacturer])) {
909
                                            $manuf = ' '.$raslist['manufacturer'][$manufacturer];
966
                                            $manuf = ' '.$raslist['manufacturer'][$manufacturer];
910
                                        } else {
967
                                        } else {
911
                                            $manuf = '';
968
                                            $manuf = '';
912
                                        }
969
                                        }
913
                                        $model = ($revidec >> 4) & 255;
970
                                        $model = ($revidec >> 4) & 255;
914
                                        if (isset($raslist['model'][$model])) {
971
                                        if (isset($raslist['model'][$model])) {
915
                                            $this->sys->setMachine('Raspberry Pi '.$raslist['model'][$model].' (PCB 1.'.($revidec & 15).$manuf.')');
972
                                            $this->sys->setMachine('Raspberry Pi '.$raslist['model'][$model].' (PCB 1.'.($revidec & 15).$manuf.')'.$oldmachend);
916
                                        } else {
973
                                        } else {
917
                                            $this->sys->setMachine('Raspberry Pi (PCB 1.'.($revidec & 15).$manuf.')');
974
                                            $this->sys->setMachine('Raspberry Pi (PCB 1.'.($revidec & 15).$manuf.')'.$oldmachend);
918
                                        }
975
                                        }
919
                                    }
976
                                    }
920
                                } else {
977
                                } else {
921
                                    if ($this->sys->getMachine() === '') {
978
                                    if (($oldmach === '') || ($oldmachend !== '')) {
922
                                        if (isset($raslist['old'][$revidec & 0x7fffff])) {
979
                                        if (isset($raslist['old'][$revidec & 0x7fffff])) {
923
                                            $this->sys->setMachine('Raspberry Pi '.$raslist['old'][$revidec & 0x7fffff]);
980
                                            $this->sys->setMachine('Raspberry Pi '.$raslist['old'][$revidec & 0x7fffff].$oldmachend);
924
                                        } else {
981
                                        } else {
925
                                            $this->sys->setMachine('Raspberry Pi');
982
                                            $this->sys->setMachine('Raspberry Pi'.$oldmachend);
926
                                        }
983
                                        }
927
                                    }
984
                                    }
928
                                }
985
                                }
929
                            }
986
                            }
930
                        } elseif (($_hard !== null) && ($this->sys->getMachine() === '')) { // other ARM hardware
987
                        } elseif (($_hard !== null) && ($this->sys->getMachine() === '')) { // other ARM hardware
931
                            $this->sys->setMachine($_hard);
988
                            $this->sys->setMachine($_hard);
932
                        }
989
                        }
933
                        if ($cpulist === null) $cpulist = @parse_ini_file(PSI_APP_ROOT."/data/cpus.ini", true);
990
                        if ($cpulist === null) $cpulist = @parse_ini_file(PSI_APP_ROOT."/data/cpus.ini", true);
934
                        if ($cpulist && (((($vari !== null) && isset($cpulist['cpu'][$cpufromlist = strtolower($impl.','.$part.','.$vari)]))
991
                        if ($cpulist && (((($vari !== null) && isset($cpulist['cpu'][$cpufromlist = strtolower($impl.','.$part.','.$vari)]))
935
                           || isset($cpulist['cpu'][$cpufromlist = strtolower($impl.','.$part)])))) {
992
                           || isset($cpulist['cpu'][$cpufromlist = strtolower($impl.','.$part)])))) {
936
                            if (($cpumodel = $dev->getModel()) !== '') {
993
                            if (($cpumodel = $dev->getModel()) !== '') {
937
                                $dev->setModel($cpumodel.' - '.$cpulist['cpu'][$cpufromlist]);
994
                                $dev->setModel($cpumodel.' - '.$cpulist['cpu'][$cpufromlist]);
938
                            } else {
995
                            } else {
939
                                $dev->setModel($cpulist['cpu'][$cpufromlist]);
996
                                $dev->setModel($cpulist['cpu'][$cpufromlist]);
940
                            }
997
                            }
941
                        }
998
                        }
942
                    } elseif (($_hard !== null) && ($this->sys->getMachine() === '')) { // other hardware
999
                    } elseif (($_hard !== null) && ($this->sys->getMachine() === '')) { // other hardware
943
                        $this->sys->setMachine($_hard);
1000
                        $this->sys->setMachine($_hard);
944
                    }
1001
                    }
945
 
1002
 
946
                    $cpumodel = $dev->getModel();
1003
                    $cpumodel = $dev->getModel();
947
                    if (defined('PSI_SHOW_VIRTUALIZER_INFO') && PSI_SHOW_VIRTUALIZER_INFO && ($this->system_detect_virt === null) && preg_match('/^QEMU Virtual CPU version /', $cpumodel)) {
1004
                    if (defined('PSI_SHOW_VIRTUALIZER_INFO') && PSI_SHOW_VIRTUALIZER_INFO && ($this->system_detect_virt === null) && preg_match('/^QEMU Virtual CPU version /', $cpumodel)) {
948
                        $this->sys->setVirtualizer("cpuid:QEMU", false);
1005
                        $this->sys->setVirtualizer("cpuid:QEMU", false);
949
                    }
1006
                    }
950
                    if ($cpumodel === "") {
1007
                    if ($cpumodel === "") {
951
                        if (($vendid = $dev->getVendorId()) !== "") {
1008
                        if (($vendid = $dev->getVendorId()) !== "") {
952
                            $dev->setModel($vendid);
1009
                            $dev->setModel($vendid);
953
                        } else {
1010
                        } else {
954
                            $dev->setModel("unknown");
1011
                            $dev->setModel("unknown");
955
                        }
1012
                        }
956
                    }
1013
                    }
957
                    $cpucount++;
1014
                    $cpucount++;
958
                    $this->sys->setCpus($dev);
1015
                    $this->sys->setCpus($dev);
959
                }
1016
                }
960
            }
1017
            }
961
 
1018
 
962
            $cpudevices = CommonFunctions::findglob('/sys/devices/system/cpu/cpu*/uevent', GLOB_NOSORT);
1019
            $cpudevices = CommonFunctions::findglob('/sys/devices/system/cpu/cpu*/uevent', GLOB_NOSORT);
963
            if (is_array($cpudevices) && (($cpustopped = count($cpudevices)-$cpucount) > 0)) {
1020
            if (is_array($cpudevices) && (($cpustopped = count($cpudevices)-$cpucount) > 0)) {
964
                for (; $cpustopped > 0; $cpustopped--) {
1021
                for (; $cpustopped > 0; $cpustopped--) {
965
                    $dev = new CpuDevice();
1022
                    $dev = new CpuDevice();
966
                    $dev->setModel("stopped");
1023
                    $dev->setModel("stopped");
967
                    if ($speedset) {
1024
                    if ($speedset) {
968
                        $dev->setCpuSpeed(-1);
1025
                        $dev->setCpuSpeed(-1);
969
                    }
1026
                    }
970
                    $this->sys->setCpus($dev);
1027
                    $this->sys->setCpus($dev);
971
                }
1028
                }
972
            }
1029
            }
973
        }
1030
        }
974
    }
1031
    }
975
 
1032
 
976
    /**
1033
    /**
977
     * PCI devices
1034
     * PCI devices
978
     *
1035
     *
979
     * @return void
1036
     * @return void
980
     */
1037
     */
981
    private function _pci()
1038
    private function _pci()
982
    {
1039
    {
983
        if ($arrResults = Parser::lspci()) {
1040
        if ($arrResults = Parser::lspci()) {
984
            foreach ($arrResults as $dev) {
1041
            foreach ($arrResults as $dev) {
985
                $this->sys->setPciDevices($dev);
1042
                $this->sys->setPciDevices($dev);
986
            }
1043
            }
987
        } elseif (CommonFunctions::rfts('/proc/pci', $strBuf, 0, 4096, false)) {
1044
        } elseif (CommonFunctions::rfts('/proc/pci', $strBuf, 0, 4096, false)) {
988
            $booDevice = false;
1045
            $booDevice = false;
989
            $arrBuf = preg_split("/\n/", $strBuf, -1, PREG_SPLIT_NO_EMPTY);
1046
            $arrBuf = preg_split("/\n/", $strBuf, -1, PREG_SPLIT_NO_EMPTY);
990
            foreach ($arrBuf as $strLine) {
1047
            foreach ($arrBuf as $strLine) {
991
                if (preg_match('/^\s*Bus\s/', $strLine)) {
1048
                if (preg_match('/^\s*Bus\s/', $strLine)) {
992
                    $booDevice = true;
1049
                    $booDevice = true;
993
                    continue;
1050
                    continue;
994
                }
1051
                }
995
                if ($booDevice) {
1052
                if ($booDevice) {
996
                    $dev = new HWDevice();
1053
                    $dev = new HWDevice();
997
                    $dev->setName(preg_replace('/\(rev\s[^\)]+\)\.$/', '', trim($strLine)));
1054
                    $dev->setName(preg_replace('/\(rev\s[^\)]+\)\.$/', '', trim($strLine)));
998
                    $this->sys->setPciDevices($dev);
1055
                    $this->sys->setPciDevices($dev);
999
/*
1056
/*
1000
                    list($strKey, $strValue) = preg_split('/: /', $strLine, 2);
1057
                    list($strKey, $strValue) = preg_split('/: /', $strLine, 2);
1001
                    if (!preg_match('/bridge/i', $strKey) && !preg_match('/USB/i ', $strKey)) {
1058
                    if (!preg_match('/bridge/i', $strKey) && !preg_match('/USB/i ', $strKey)) {
1002
                        $dev = new HWDevice();
1059
                        $dev = new HWDevice();
1003
                        $dev->setName(preg_replace('/\(rev\s[^\)]+\)\.$/', '', trim($strValue)));
1060
                        $dev->setName(preg_replace('/\(rev\s[^\)]+\)\.$/', '', trim($strValue)));
1004
                        $this->sys->setPciDevices($dev);
1061
                        $this->sys->setPciDevices($dev);
1005
                    }
1062
                    }
1006
*/
1063
*/
1007
                    $booDevice = false;
1064
                    $booDevice = false;
1008
                }
1065
                }
1009
            }
1066
            }
1010
        } else {
1067
        } else {
1011
            $pcidevices = CommonFunctions::findglob('/sys/bus/pci/devices/*/uevent', GLOB_NOSORT);
1068
            $pcidevices = CommonFunctions::findglob('/sys/bus/pci/devices/*/uevent', GLOB_NOSORT);
1012
            if (is_array($pcidevices) && (($total = count($pcidevices)) > 0)) {
1069
            if (is_array($pcidevices) && (($total = count($pcidevices)) > 0)) {
1013
                $buf = "";
1070
                $buf = "";
1014
                for ($i = 0; $i < $total; $i++) {
1071
                for ($i = 0; $i < $total; $i++) {
1015
                    if (CommonFunctions::rfts($pcidevices[$i], $buf, 0, 4096, false) && (trim($buf) != "")) {
1072
                    if (CommonFunctions::rfts($pcidevices[$i], $buf, 0, 4096, false) && (trim($buf) != "")) {
1016
                        $pcibuf = "";
1073
                        $pcibuf = "";
1017
                        if (preg_match("/^PCI_CLASS=(\S+)/m", trim($buf), $subbuf)) {
1074
                        if (preg_match("/^PCI_CLASS=(\S+)/m", trim($buf), $subbuf)) {
1018
                            $pcibuf = "Class ".$subbuf[1].":";
1075
                            $pcibuf = "Class ".$subbuf[1].":";
1019
                        }
1076
                        }
1020
                        if (preg_match("/^PCI_ID=(\S+)/m", trim($buf), $subbuf)) {
1077
                        if (preg_match("/^PCI_ID=(\S+)/m", trim($buf), $subbuf)) {
1021
                            $pcibuf .= " Device ".$subbuf[1];
1078
                            $pcibuf .= " Device ".$subbuf[1];
1022
                        }
1079
                        }
1023
                        if (preg_match("/^DRIVER=(\S+)/m", trim($buf), $subbuf)) {
1080
                        if (preg_match("/^DRIVER=(\S+)/m", trim($buf), $subbuf)) {
1024
                            $pcibuf .= " Driver ".$subbuf[1];
1081
                            $pcibuf .= " Driver ".$subbuf[1];
1025
                        }
1082
                        }
1026
                        $dev = new HWDevice();
1083
                        $dev = new HWDevice();
1027
                        if (trim($pcibuf) != "") {
1084
                        if (trim($pcibuf) != "") {
1028
                            $dev->setName(trim($pcibuf));
1085
                            $dev->setName(trim($pcibuf));
1029
                        } else {
1086
                        } else {
1030
                            $dev->setName("unknown");
1087
                            $dev->setName("unknown");
1031
                        }
1088
                        }
1032
                        $this->sys->setPciDevices($dev);
1089
                        $this->sys->setPciDevices($dev);
1033
                    }
1090
                    }
1034
                }
1091
                }
1035
            }
1092
            }
1036
        }
1093
        }
1037
    }
1094
    }
1038
 
1095
 
1039
    /**
1096
    /**
1040
     * IDE devices
1097
     * IDE devices
1041
     *
1098
     *
1042
     * @return void
1099
     * @return void
1043
     */
1100
     */
1044
    private function _ide()
1101
    private function _ide()
1045
    {
1102
    {
1046
        $bufd = CommonFunctions::gdc('/proc/ide', false);
1103
        $bufd = CommonFunctions::gdc('/proc/ide', false);
1047
        foreach ($bufd as $file) {
1104
        foreach ($bufd as $file) {
1048
            if (preg_match('/^hd/', $file)) {
1105
            if (preg_match('/^hd/', $file)) {
1049
                $dev = new HWDevice();
1106
                $dev = new HWDevice();
1050
                $dev->setName(trim($file));
1107
                $dev->setName(trim($file));
1051
                if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS && CommonFunctions::rfts("/proc/ide/".$file."/media", $buf, 1)) {
1108
                if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS && CommonFunctions::rfts("/proc/ide/".$file."/media", $buf, 1)) {
1052
                    if (trim($buf) == 'disk') {
1109
                    if (trim($buf) == 'disk') {
1053
                        if (CommonFunctions::rfts("/proc/ide/".$file."/capacity", $buf, 1, 4096, false) || CommonFunctions::rfts("/sys/block/".$file."/size", $buf, 1, 4096, false)) {
1110
                        if (CommonFunctions::rfts("/proc/ide/".$file."/capacity", $buf, 1, 4096, false) || CommonFunctions::rfts("/sys/block/".$file."/size", $buf, 1, 4096, false)) {
1054
                            $dev->setCapacity(trim($buf) * 512);
1111
                            $dev->setCapacity(trim($buf) * 512);
1055
                        }
1112
                        }
1056
                    }
1113
                    }
1057
                }
1114
                }
1058
                if (CommonFunctions::rfts("/proc/ide/".$file."/model", $buf, 1)) {
1115
                if (CommonFunctions::rfts("/proc/ide/".$file."/model", $buf, 1)) {
1059
                    $dev->setName($dev->getName().": ".trim($buf));
1116
                    $dev->setName($dev->getName().": ".trim($buf));
1060
                }
1117
                }
1061
                $this->sys->setIdeDevices($dev);
1118
                $this->sys->setIdeDevices($dev);
1062
            }
1119
            }
1063
        }
1120
        }
1064
    }
1121
    }
1065
 
1122
 
1066
    /**
1123
    /**
1067
     * SCSI devices
1124
     * SCSI devices
1068
     *
1125
     *
1069
     * @return void
1126
     * @return void
1070
     */
1127
     */
1071
    private function _scsi()
1128
    private function _scsi()
1072
    {
1129
    {
1073
        $getline = 0;
1130
        $getline = 0;
1074
        $device = null;
1131
        $device = null;
1075
        $scsiid = null;
1132
        $scsiid = null;
1076
        if (CommonFunctions::executeProgram('lsscsi', '-c', $bufr, PSI_DEBUG) || CommonFunctions::rfts('/proc/scsi/scsi', $bufr, 0, 4096, PSI_DEBUG)) {
1133
        if (CommonFunctions::executeProgram('lsscsi', '-c', $bufr, PSI_DEBUG) || CommonFunctions::rfts('/proc/scsi/scsi', $bufr, 0, 4096, PSI_DEBUG)) {
1077
            $bufe = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
1134
            $bufe = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
1078
            foreach ($bufe as $buf) {
1135
            foreach ($bufe as $buf) {
1079
                if (preg_match('/Host: scsi(\d+) Channel: (\d+) Target: (\d+) Lun: (\d+)/i', $buf, $scsiids)
1136
                if (preg_match('/Host: scsi(\d+) Channel: (\d+) Target: (\d+) Lun: (\d+)/i', $buf, $scsiids)
1080
                   || preg_match('/Host: scsi(\d+) Channel: (\d+) Id: (\d+) Lun: (\d+)/i', $buf, $scsiids)) {
1137
                   || preg_match('/Host: scsi(\d+) Channel: (\d+) Id: (\d+) Lun: (\d+)/i', $buf, $scsiids)) {
1081
                    $scsiid = $scsiids;
1138
                    $scsiid = $scsiids;
1082
                    $getline = 1;
1139
                    $getline = 1;
1083
                    continue;
1140
                    continue;
1084
                }
1141
                }
1085
                if ($getline == 1) {
1142
                if ($getline == 1) {
1086
                    preg_match('/Vendor: (.*) Model: (.*) Rev: (.*)/i', $buf, $devices);
1143
                    preg_match('/Vendor: (.*) Model: (.*) Rev: (.*)/i', $buf, $devices);
1087
                    $getline = 2;
1144
                    $getline = 2;
1088
                    $device = $devices;
1145
                    $device = $devices;
1089
                    continue;
1146
                    continue;
1090
                }
1147
                }
1091
                if ($getline == 2) {
1148
                if ($getline == 2) {
1092
                    preg_match('/Type:\s+(\S+)/i', $buf, $dev_type);
1149
                    preg_match('/Type:\s+(\S+)/i', $buf, $dev_type);
1093
 
1150
 
1094
                    $dev = new HWDevice();
1151
                    $dev = new HWDevice();
1095
                    $dev->setName($device[1].' '.$device[2].' ('.$dev_type[1].')');
1152
                    $dev->setName($device[1].' '.$device[2].' ('.$dev_type[1].')');
1096
 
1153
 
1097
                    if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS
1154
                    if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS
1098
                       && ($dev_type[1]==='Direct-Access')) {
1155
                       && ($dev_type[1]==='Direct-Access')) {
1099
                       $sizelist = CommonFunctions::findglob('/sys/bus/scsi/devices/'.intval($scsiid[1]).':'.intval($scsiid[2]).':'.intval($scsiid[3]).':'.intval($scsiid[4]).'/*/*/size', GLOB_NOSORT);
1156
                       $sizelist = CommonFunctions::findglob('/sys/bus/scsi/devices/'.intval($scsiid[1]).':'.intval($scsiid[2]).':'.intval($scsiid[3]).':'.intval($scsiid[4]).'/*/*/size', GLOB_NOSORT);
1100
                       if (is_array($sizelist) && (($total = count($sizelist)) > 0)) {
1157
                       if (is_array($sizelist) && (($total = count($sizelist)) > 0)) {
1101
                           $buf = "";
1158
                           $buf = "";
1102
                           for ($i = 0; $i < $total; $i++) {
1159
                           for ($i = 0; $i < $total; $i++) {
1103
                               if (CommonFunctions::rfts($sizelist[$i], $buf, 1, 4096, false) && (($buf=trim($buf)) != "") && ($buf > 0)) {
1160
                               if (CommonFunctions::rfts($sizelist[$i], $buf, 1, 4096, false) && (($buf=trim($buf)) != "") && ($buf > 0)) {
1104
                                   $dev->setCapacity($buf * 512);
1161
                                   $dev->setCapacity($buf * 512);
1105
                                   break;
1162
                                   break;
1106
                               }
1163
                               }
1107
                           }
1164
                           }
1108
                       }
1165
                       }
1109
                    }
1166
                    }
1110
                    $this->sys->setScsiDevices($dev);
1167
                    $this->sys->setScsiDevices($dev);
1111
                    $getline = 0;
1168
                    $getline = 0;
1112
                }
1169
                }
1113
            }
1170
            }
1114
        }
1171
        }
1115
    }
1172
    }
1116
 
1173
 
1117
    /**
1174
    /**
1118
     * USB devices
1175
     * USB devices
1119
     *
1176
     *
1120
     * @return void
1177
     * @return void
1121
     */
1178
     */
1122
    protected function _usb()
1179
    protected function _usb($bufu = null)
1123
    {
1180
    {
1124
        $usbarray = array();
1181
        $usbarray = array();
-
 
1182
        if ($nobufu = ($bufu === null)) {
1125
        if (CommonFunctions::executeProgram('lsusb', (PSI_OS != 'Android')?'':'2>/dev/null', $bufr, PSI_DEBUG && (PSI_OS != 'Android'), 5) && ($bufr !== "")) {
1183
            if (CommonFunctions::executeProgram('lsusb', (PSI_OS != 'Android')?'':'2>/dev/null', $bufr, PSI_DEBUG && (PSI_OS != 'Android'), 5) && ($bufr !== "")) {
1126
            $bufe = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
1184
                $bufe = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
1127
            foreach ($bufe as $buf) {
1185
                foreach ($bufe as $buf) {
1128
                $device = preg_split("/ /", $buf, 7);
1186
                    $device = preg_split("/ /", $buf, 7);
1129
                if (((isset($device[6]) && trim($device[6]) != "")) ||
1187
                    if (((isset($device[6]) && trim($device[6]) != "")) ||
1130
                    ((isset($device[5]) && trim($device[5]) != ""))) {
1188
                        ((isset($device[5]) && trim($device[5]) != ""))) {
1131
                    $usbid = intval($device[1]).'-'.intval(trim($device[3], ':')).' '.$device[5];
1189
                        $usbid = intval($device[1]).'-'.intval(trim($device[3], ':')).' '.$device[5];
1132
                    if ((isset($device[6]) && trim($device[6]) != "")) {
1190
                        if ((isset($device[6]) && trim($device[6]) != "")) {
1133
                        $usbarray[$usbid]['name'] = trim($device[6]);
1191
                            $usbarray[$usbid]['name'] = trim($device[6]);
1134
                    } else {
1192
                        } else {
1135
                        $usbarray[$usbid]['name'] = 'unknown';
1193
                            $usbarray[$usbid]['name'] = 'unknown';
-
 
1194
                        }
1136
                    }
1195
                    }
1137
                }
1196
                }
1138
            }
1197
            }
1139
        }
-
 
1140
 
1198
 
1141
        $usbdevices = CommonFunctions::findglob('/sys/bus/usb/devices/*/idProduct', GLOB_NOSORT);
1199
            $usbdevices = CommonFunctions::findglob('/sys/bus/usb/devices/*/idProduct', GLOB_NOSORT);
1142
        if (is_array($usbdevices) && (($total = count($usbdevices)) > 0)) {
1200
            if (is_array($usbdevices) && (($total = count($usbdevices)) > 0)) {
1143
            for ($i = 0; $i < $total; $i++) {
1201
                for ($i = 0; $i < $total; $i++) {
1144
                if (CommonFunctions::rfts($usbdevices[$i], $idproduct, 1, 4096, false) && (($idproduct=trim($idproduct)) != "")) { // is readable
1202
                    if (CommonFunctions::rfts($usbdevices[$i], $idproduct, 1, 4096, false) && (($idproduct=trim($idproduct)) != "")) { // is readable
1145
                    $busnum = CommonFunctions::rolv($usbdevices[$i], '/\/idProduct$/', '/busnum');
1203
                        $busnum = CommonFunctions::rolv($usbdevices[$i], '/\/idProduct$/', '/busnum');
1146
                    $devnum = CommonFunctions::rolv($usbdevices[$i], '/\/idProduct$/', '/devnum');
1204
                        $devnum = CommonFunctions::rolv($usbdevices[$i], '/\/idProduct$/', '/devnum');
1147
                    $idvendor = CommonFunctions::rolv($usbdevices[$i], '/\/idProduct$/', '/idVendor');
1205
                        $idvendor = CommonFunctions::rolv($usbdevices[$i], '/\/idProduct$/', '/idVendor');
1148
                    if (($busnum!==null) && ($devnum!==null) && ($idvendor!==null)) {
1206
                        if (($busnum!==null) && ($devnum!==null) && ($idvendor!==null)) {
1149
                        $usbid = intval($busnum).'-'.intval($devnum).' '.$idvendor.':'.$idproduct;
1207
                            $usbid = intval($busnum).'-'.intval($devnum).' '.$idvendor.':'.$idproduct;
1150
                        $manufacturer = CommonFunctions::rolv($usbdevices[$i], '/\/idProduct$/', '/manufacturer');
1208
                            $manufacturer = CommonFunctions::rolv($usbdevices[$i], '/\/idProduct$/', '/manufacturer');
1151
                        if ($manufacturer!==null) {
1209
                            if ($manufacturer!==null) {
1152
                            $usbarray[$usbid]['manufacturer'] = $manufacturer;
1210
                                $usbarray[$usbid]['manufacturer'] = $manufacturer;
1153
                        }
1211
                            }
1154
                        $product = CommonFunctions::rolv($usbdevices[$i], '/\/idProduct$/', '/product');
1212
                            $product = CommonFunctions::rolv($usbdevices[$i], '/\/idProduct$/', '/product');
1155
                        if ($product!==null) {
1213
                            if ($product!==null) {
1156
                            $usbarray[$usbid]['product'] = $product;
1214
                                $usbarray[$usbid]['product'] = $product;
1157
                        }
1215
                            }
1158
                        $speed = CommonFunctions::rolv($usbdevices[$i], '/\/idProduct$/', '/speed');
1216
                            $speed = CommonFunctions::rolv($usbdevices[$i], '/\/idProduct$/', '/speed');
1159
                        if ($product!==null) {
1217
                            if ($product!==null) {
1160
                            $usbarray[$usbid]['speed'] = $speed;
1218
                                $usbarray[$usbid]['speed'] = $speed;
1161
                        }
1219
                            }
1162
                        if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS
1220
                            if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS
1163
                           && defined('PSI_SHOW_DEVICES_SERIAL') && PSI_SHOW_DEVICES_SERIAL) {
1221
                               && defined('PSI_SHOW_DEVICES_SERIAL') && PSI_SHOW_DEVICES_SERIAL) {
1164
                            $serial = CommonFunctions::rolv($usbdevices[$i], '/\/idProduct$/', '/serial');
1222
                                $serial = CommonFunctions::rolv($usbdevices[$i], '/\/idProduct$/', '/serial');
1165
                            if (($serial!==null) && !preg_match('/\W/', $serial)) {
1223
                                if (($serial!==null) && !preg_match('/\W/', $serial)) {
1166
                                $usbarray[$usbid]['serial'] = $serial;
1224
                                    $usbarray[$usbid]['serial'] = $serial;
-
 
1225
                                }
1167
                            }
1226
                            }
1168
                        }
1227
                        }
1169
                    }
1228
                    }
1170
                }
1229
                }
1171
            }
1230
            }
1172
        }
1231
        }
1173
 
1232
 
1174
        if ((count($usbarray) == 0) && CommonFunctions::rfts('/proc/bus/usb/devices', $bufr, 0, 4096, false)) { // usb-devices
1233
        if (!$nobufu || ((count($usbarray) == 0) && CommonFunctions::rfts('/proc/bus/usb/devices', $bufu, 0, 4096, false))) { // usb-devices
1175
            $devnum = -1;
1234
            $devnum = -1;
1176
            $bufe = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
1235
            $bufe = preg_split("/\n/", $bufu, -1, PREG_SPLIT_NO_EMPTY);
1177
            foreach ($bufe as $buf) {
1236
            foreach ($bufe as $buf) {
1178
                if (preg_match('/^T/', $buf)) {
1237
                if (preg_match('/^T/', $buf)) {
1179
                    $devnum++;
1238
                    $devnum++;
1180
                    if (preg_match('/\sSpd=([\d\.]+)/', $buf, $bufr)
1239
                    if (preg_match('/\sSpd=([\d\.]+)/', $buf, $bufr)
1181
                       && isset($bufr[1]) && ($bufr[1]!=="")) {
1240
                       && isset($bufr[1]) && ($bufr[1]!=="")) {
1182
                        $usbarray[$devnum]['speed'] = $bufr[1];
1241
                        $usbarray[$devnum]['speed'] = $bufr[1];
1183
                    }
1242
                    }
1184
                } elseif (preg_match('/^S:/', $buf)) {
1243
                } elseif (preg_match('/^S:/', $buf)) {
1185
                    list($key, $value) = preg_split('/: /', $buf, 2);
1244
                    list($key, $value) = preg_split('/: /', $buf, 2);
1186
                    list($key, $value2) = preg_split('/=/', $value, 2);
1245
                    list($key, $value2) = preg_split('/=/', $value, 2);
1187
                    switch (trim($key)) {
1246
                    switch (trim($key)) {
1188
                    case 'Manufacturer':
1247
                    case 'Manufacturer':
1189
                        $usbarray[$devnum]['manufacturer'] = trim($value2);
1248
                        $usbarray[$devnum]['manufacturer'] = trim($value2);
1190
                        break;
1249
                        break;
1191
                    case 'Product':
1250
                    case 'Product':
1192
                        $usbarray[$devnum]['product'] = trim($value2);
1251
                        $usbarray[$devnum]['product'] = trim($value2);
1193
                        break;
1252
                        break;
1194
                    case 'SerialNumber':
1253
                    case 'SerialNumber':
1195
                        if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS
1254
                        if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS
1196
                           && defined('PSI_SHOW_DEVICES_SERIAL') && PSI_SHOW_DEVICES_SERIAL
1255
                           && defined('PSI_SHOW_DEVICES_SERIAL') && PSI_SHOW_DEVICES_SERIAL
1197
                           && !preg_match('/\W/', trim($value2))) {
1256
                           && !preg_match('/\W/', trim($value2))) {
1198
                            $usbarray[$devnum]['serial'] = trim($value2);
1257
                            $usbarray[$devnum]['serial'] = trim($value2);
1199
                        }
1258
                        }
1200
                    }
1259
                    }
1201
                }
1260
                }
1202
            }
1261
            }
1203
        }
1262
        }
1204
 
1263
 
1205
        if ((count($usbarray) == 0) && CommonFunctions::rfts('/proc/bus/input/devices', $bufr, 0, 4096, false)) {
1264
        if ($nobufu && (count($usbarray) == 0) && CommonFunctions::rfts('/proc/bus/input/devices', $bufr, 0, 4096, false)) {
1206
            $devnam = "unknown";
1265
            $devnam = "unknown";
1207
            $bufe = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
1266
            $bufe = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
1208
            foreach ($bufe as $buf) {
1267
            foreach ($bufe as $buf) {
1209
                if (preg_match('/^I:\s+(.+)/', $buf, $bufr)
1268
                if (preg_match('/^I:\s+(.+)/', $buf, $bufr)
1210
                   && isset($bufr[1]) && (trim($bufr[1])!=="")) {
1269
                   && isset($bufr[1]) && (trim($bufr[1])!=="")) {
1211
                    $devnam = trim($bufr[1]);
1270
                    $devnam = trim($bufr[1]);
1212
                    $usbarray[$devnam]['phys'] = 'unknown';
1271
                    $usbarray[$devnam]['phys'] = 'unknown';
1213
                } elseif (preg_match('/^N:\s+Name="([^"]+)"/', $buf, $bufr2)
1272
                } elseif (preg_match('/^N:\s+Name="([^"]+)"/', $buf, $bufr2)
1214
                   && isset($bufr2[1]) && (trim($bufr2[1])!=="")) {
1273
                   && isset($bufr2[1]) && (trim($bufr2[1])!=="")) {
1215
                    $usbarray[$devnam]['name'] = trim($bufr2[1]);
1274
                    $usbarray[$devnam]['name'] = trim($bufr2[1]);
1216
                } elseif (preg_match('/^P:\s+Phys=(.*)/', $buf, $bufr2)
1275
                } elseif (preg_match('/^P:\s+Phys=(.*)/', $buf, $bufr2)
1217
                   && isset($bufr2[1]) && (trim($bufr2[1])!=="")) {
1276
                   && isset($bufr2[1]) && (trim($bufr2[1])!=="")) {
1218
                    $usbarray[$devnam]['phys'] = trim($bufr2[1]);
1277
                    $usbarray[$devnam]['phys'] = trim($bufr2[1]);
1219
                } elseif (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS
1278
                } elseif (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS
1220
                   && defined('PSI_SHOW_DEVICES_SERIAL') && PSI_SHOW_DEVICES_SERIAL
1279
                   && defined('PSI_SHOW_DEVICES_SERIAL') && PSI_SHOW_DEVICES_SERIAL
1221
                   && preg_match('/^U:\s+Uniq=(.+)/', $buf, $bufr2)
1280
                   && preg_match('/^U:\s+Uniq=(.+)/', $buf, $bufr2)
1222
                   && isset($bufr2[1]) && (trim($bufr2[1])!=="")) {
1281
                   && isset($bufr2[1]) && (trim($bufr2[1])!=="")) {
1223
                    $usbarray[$devnam]['serial'] = trim($bufr2[1]);
1282
                    $usbarray[$devnam]['serial'] = trim($bufr2[1]);
1224
                }
1283
                }
1225
            }
1284
            }
1226
        }
1285
        }
1227
 
1286
 
1228
        foreach ($usbarray as $usbdev) if (!isset($usbdev['phys']) || preg_match('/^usb-/', $usbdev['phys'])) {
1287
        foreach ($usbarray as $usbdev) if (!isset($usbdev['phys']) || preg_match('/^usb-/', $usbdev['phys'])) {
1229
            $dev = new HWDevice();
1288
            $dev = new HWDevice();
1230
 
1289
 
1231
            if (isset($usbdev['manufacturer']) && (($manufacturer=$usbdev['manufacturer']) !== 'no manufacturer')) {
1290
            if (isset($usbdev['manufacturer']) && (($manufacturer=$usbdev['manufacturer']) !== 'no manufacturer')) {
1232
                if (preg_match("/^linux\s/i", $manufacturer)) {
1291
                if (preg_match("/^linux\s/i", $manufacturer)) {
1233
                    $manufacturer = 'Linux Foundation';
1292
                    $manufacturer = 'Linux Foundation';
1234
                }
1293
                }
1235
                if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS) {
1294
                if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS) {
1236
                    $dev->setManufacturer($manufacturer);
1295
                    $dev->setManufacturer($manufacturer);
1237
                }
1296
                }
1238
            } else {
1297
            } else {
1239
                $manufacturer = '';
1298
                $manufacturer = '';
1240
            }
1299
            }
1241
 
1300
 
1242
            if (isset($usbdev['product'])) {
1301
            if (isset($usbdev['product'])) {
1243
                $product = $usbdev['product'];
1302
                $product = $usbdev['product'];
1244
                if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS) {
1303
                if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS) {
1245
                    $dev->setProduct($product);
1304
                    $dev->setProduct($product);
1246
                }
1305
                }
1247
            } else {
1306
            } else {
1248
                $product = '';
1307
                $product = '';
1249
            }
1308
            }
1250
 
1309
 
1251
            if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS) {
1310
            if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS) {
1252
                if (isset($usbdev['speed'])) {
1311
                if (isset($usbdev['speed'])) {
1253
                    $dev->setSpeed($usbdev['speed']);
1312
                    $dev->setSpeed($usbdev['speed']);
1254
                }
1313
                }
1255
                if (defined('PSI_SHOW_DEVICES_SERIAL') && PSI_SHOW_DEVICES_SERIAL
1314
                if (defined('PSI_SHOW_DEVICES_SERIAL') && PSI_SHOW_DEVICES_SERIAL
1256
                   && isset($usbdev['serial'])) {
1315
                   && isset($usbdev['serial'])) {
1257
                    $dev->setSerial($usbdev['serial']);
1316
                    $dev->setSerial($usbdev['serial']);
1258
                }
1317
                }
1259
            }
1318
            }
1260
 
1319
 
1261
            if (isset($usbdev['name']) && (($name=$usbdev['name']) !== 'unknown')) {
1320
            if (isset($usbdev['name']) && (($name=$usbdev['name']) !== 'unknown')) {
1262
                $dev->setName($name);
1321
                $dev->setName($name);
1263
            } else {
1322
            } else {
1264
                if (($newname = trim($manufacturer.' '.$product)) !== '') {
1323
                if (($newname = trim($manufacturer.' '.$product)) !== '') {
1265
                    $dev->setName($newname);
1324
                    $dev->setName($newname);
1266
                } else {
1325
                } else {
1267
                    $dev->setName('unknown');
1326
                    $dev->setName('unknown');
1268
                }
1327
                }
1269
            }
1328
            }
1270
 
1329
 
1271
            $this->sys->setUsbDevices($dev);
1330
            $this->sys->setUsbDevices($dev);
1272
        }
1331
        }
1273
    }
1332
    }
1274
 
1333
 
1275
    /**
1334
    /**
1276
     * I2C devices
1335
     * I2C devices
1277
     *
1336
     *
1278
     * @return void
1337
     * @return void
1279
     */
1338
     */
1280
    protected function _i2c()
1339
    protected function _i2c()
1281
    {
1340
    {
1282
        $i2cdevices = CommonFunctions::findglob('/sys/bus/i2c/devices/*/name', GLOB_NOSORT);
1341
        $i2cdevices = CommonFunctions::findglob('/sys/bus/i2c/devices/*/name', GLOB_NOSORT);
1283
        if (is_array($i2cdevices) && (($total = count($i2cdevices)) > 0)) {
1342
        if (is_array($i2cdevices) && (($total = count($i2cdevices)) > 0)) {
1284
            $buf = "";
1343
            $buf = "";
1285
            for ($i = 0; $i < $total; $i++) {
1344
            for ($i = 0; $i < $total; $i++) {
1286
                if (CommonFunctions::rfts($i2cdevices[$i], $buf, 1, 4096, false) && (trim($buf) != "")) {
1345
                if (CommonFunctions::rfts($i2cdevices[$i], $buf, 1, 4096, false) && (trim($buf) != "")) {
1287
                    $dev = new HWDevice();
1346
                    $dev = new HWDevice();
1288
                    $dev->setName(trim($buf));
1347
                    $dev->setName(trim($buf));
1289
                    $this->sys->setI2cDevices($dev);
1348
                    $this->sys->setI2cDevices($dev);
1290
                }
1349
                }
1291
            }
1350
            }
1292
        }
1351
        }
1293
    }
1352
    }
1294
 
1353
 
1295
    /**
1354
    /**
1296
     * NVMe devices
1355
     * NVMe devices
1297
     *
1356
     *
1298
     * @return void
1357
     * @return void
1299
     */
1358
     */
1300
    protected function _nvme()
1359
    protected function _nvme()
1301
    {
1360
    {
1302
        if (CommonFunctions::executeProgram('nvme', 'list', $bufr, PSI_DEBUG) && ($bufr!="")) {
1361
        if (CommonFunctions::executeProgram('nvme', 'list', $bufr, PSI_DEBUG) && ($bufr!="")) {
1303
            $bufe = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
1362
            $bufe = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
1304
            $count = 0;
1363
            $count = 0;
1305
            $nlocate = array();
1364
            $nlocate = array();
1306
            $nsize = array();
1365
            $nsize = array();
1307
            foreach ($bufe as $buf) {
1366
            foreach ($bufe as $buf) {
1308
                if ($count == 1) {
1367
                if ($count == 1) {
1309
                    $locid = 0;
1368
                    $locid = 0;
1310
                    $nlocate[0] = 0;
1369
                    $nlocate[0] = 0;
1311
                    $total = strlen($buf);
1370
                    $total = strlen($buf);
1312
                    $begin = true;
1371
                    $begin = true;
1313
                    for ($i = 0; $i < $total; $i++) {
1372
                    for ($i = 0; $i < $total; $i++) {
1314
                        if ($begin) {
1373
                        if ($begin) {
1315
                            if ($buf[$i] !== '-') {
1374
                            if ($buf[$i] !== '-') {
1316
                                $nsize[$locid] = $i - $nlocate[$locid];
1375
                                $nsize[$locid] = $i - $nlocate[$locid];
1317
                                $locid++;
1376
                                $locid++;
1318
                                $begin = false;
1377
                                $begin = false;
1319
                            }
1378
                            }
1320
                        } else {
1379
                        } else {
1321
                            if ($buf[$i] === '-') {
1380
                            if ($buf[$i] === '-') {
1322
                                $nlocate[$locid] = $i;
1381
                                $nlocate[$locid] = $i;
1323
                                $begin = true;
1382
                                $begin = true;
1324
                            }
1383
                            }
1325
                        }
1384
                        }
1326
                    }
1385
                    }
1327
                    if ($begin) {
1386
                    if ($begin) {
1328
                        $nsize[$locid] = $i - $nlocate[$locid];
1387
                        $nsize[$locid] = $i - $nlocate[$locid];
1329
                    }
1388
                    }
1330
                } elseif ($count > 1) {
1389
                } elseif ($count > 1) {
1331
                    if (isset($nlocate[2]) && isset($nsize[2])) {
1390
                    if (isset($nlocate[2]) && isset($nsize[2])) {
1332
                        $dev = new HWDevice();
1391
                        $dev = new HWDevice();
1333
                        $dev->setName(trim(substr($buf, $nlocate[2], $nsize[2])));
1392
                        $dev->setName(trim(substr($buf, $nlocate[2], $nsize[2])));
1334
                        if (defined('PSI_SHOW_DEVICES_INFOS') && (PSI_SHOW_DEVICES_INFOS)) {
1393
                        if (defined('PSI_SHOW_DEVICES_INFOS') && (PSI_SHOW_DEVICES_INFOS)) {
1335
                            if (isset($nlocate[4]) && isset($nsize[4])) {
1394
                            if (isset($nlocate[4]) && isset($nsize[4])) {
1336
                                if (preg_match('/\/\s*([0-9\.]+)\s*(B|KB|MB|GB|TB|PB)$/', str_replace(',', '.', trim(substr($buf, $nlocate[4], $nsize[4]))), $tmpbuf)) {
1395
                                if (preg_match('/\/\s*([0-9\.]+)\s*(B|KB|MB|GB|TB|PB)$/', str_replace(',', '.', trim(substr($buf, $nlocate[4], $nsize[4]))), $tmpbuf)) {
1337
                                    switch ($tmpbuf[2]) {
1396
                                    switch ($tmpbuf[2]) {
1338
                                    case 'B':
1397
                                    case 'B':
1339
                                        $dev->setCapacity($tmpbuf[1]);
1398
                                        $dev->setCapacity($tmpbuf[1]);
1340
                                        break;
1399
                                        break;
1341
                                    case 'KB':
1400
                                    case 'KB':
1342
                                        $dev->setCapacity(1000*$tmpbuf[1]);
1401
                                        $dev->setCapacity(1000*$tmpbuf[1]);
1343
                                        break;
1402
                                        break;
1344
                                    case 'MB':
1403
                                    case 'MB':
1345
                                        $dev->setCapacity(1000*1000*$tmpbuf[1]);
1404
                                        $dev->setCapacity(1000*1000*$tmpbuf[1]);
1346
                                        break;
1405
                                        break;
1347
                                    case 'GB':
1406
                                    case 'GB':
1348
                                        $dev->setCapacity(1000*1000*1000*$tmpbuf[1]);
1407
                                        $dev->setCapacity(1000*1000*1000*$tmpbuf[1]);
1349
                                        break;
1408
                                        break;
1350
                                    case 'TB':
1409
                                    case 'TB':
1351
                                        $dev->setCapacity(1000*1000*1000*1000*$tmpbuf[1]);
1410
                                        $dev->setCapacity(1000*1000*1000*1000*$tmpbuf[1]);
1352
                                        break;
1411
                                        break;
1353
                                    case 'PB':
1412
                                    case 'PB':
1354
                                        $dev->setCapacity(1000*1000*1000*1000*1000*$tmpbuf[1]);
1413
                                        $dev->setCapacity(1000*1000*1000*1000*1000*$tmpbuf[1]);
1355
                                    }
1414
                                    }
1356
                                }
1415
                                }
1357
                            }
1416
                            }
1358
                            if (defined('PSI_SHOW_DEVICES_SERIAL') && PSI_SHOW_DEVICES_SERIAL) {
1417
                            if (defined('PSI_SHOW_DEVICES_SERIAL') && PSI_SHOW_DEVICES_SERIAL) {
1359
                                if (isset($nlocate[1]) && isset($nsize[1])) {
1418
                                if (isset($nlocate[1]) && isset($nsize[1])) {
1360
                                    $dev->setSerial(trim(substr($buf, $nlocate[1], $nsize[1])));
1419
                                    $dev->setSerial(trim(substr($buf, $nlocate[1], $nsize[1])));
1361
                                }
1420
                                }
1362
                            }
1421
                            }
1363
                        }
1422
                        }
1364
                        $this->sys->setNvmeDevices($dev);
1423
                        $this->sys->setNvmeDevices($dev);
1365
                    }
1424
                    }
1366
                }
1425
                }
1367
                $count++;
1426
                $count++;
1368
            }
1427
            }
1369
        }
1428
        }
1370
    }
1429
    }
1371
 
1430
 
1372
    /**
1431
    /**
1373
     * Network devices
1432
     * Network devices
1374
     * includes also rx/tx bytes
1433
     * includes also rx/tx bytes
1375
     *
1434
     *
1376
     * @return void
1435
     * @return void
1377
     */
1436
     */
1378
    protected function _network()
1437
    protected function _network($bufr = null)
1379
    {
1438
    {
1380
        if (CommonFunctions::rfts('/proc/net/dev', $bufr, 0, 4096, PSI_DEBUG)) {
1439
        if (($bufr === null) && CommonFunctions::rfts('/proc/net/dev', $bufr, 0, 4096, PSI_DEBUG)) {
1381
            $bufe = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
1440
            $bufe = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
1382
            foreach ($bufe as $buf) {
1441
            foreach ($bufe as $buf) {
1383
                if (preg_match('/:/', $buf)) {
1442
                if (preg_match('/:/', $buf)) {
1384
                    list($dev_name, $stats_list) = preg_split('/:/', $buf, 2);
1443
                    list($dev_name, $stats_list) = preg_split('/:/', $buf, 2);
1385
                    $stats = preg_split('/\s+/', trim($stats_list));
1444
                    $stats = preg_split('/\s+/', trim($stats_list));
1386
                    $dev = new NetDevice();
1445
                    $dev = new NetDevice();
1387
                    $dev->setName(trim($dev_name));
1446
                    $dev->setName(trim($dev_name));
1388
                    $dev->setRxBytes($stats[0]);
1447
                    $dev->setRxBytes($stats[0]);
1389
                    $dev->setTxBytes($stats[8]);
1448
                    $dev->setTxBytes($stats[8]);
1390
                    $dev->setErrors($stats[2] + $stats[10]);
1449
                    $dev->setErrors($stats[2] + $stats[10]);
1391
                    $dev->setDrops($stats[3] + $stats[11]);
1450
                    $dev->setDrops($stats[3] + $stats[11]);
1392
                    if (defined('PSI_SHOW_NETWORK_INFOS') && (PSI_SHOW_NETWORK_INFOS)) {
1451
                    if (defined('PSI_SHOW_NETWORK_INFOS') && (PSI_SHOW_NETWORK_INFOS)) {
1393
                        $macaddr = "";
1452
                        $macaddr = "";
1394
                        if ((CommonFunctions::executeProgram('ip', 'addr show '.trim($dev_name), $bufr2, PSI_DEBUG) && ($bufr2!=""))
1453
                        if ((CommonFunctions::executeProgram('ip', 'addr show '.trim($dev_name), $bufr2, PSI_DEBUG) && ($bufr2!=""))
1395
                           || CommonFunctions::executeProgram('ifconfig', trim($dev_name).' 2>/dev/null', $bufr2, PSI_DEBUG)) {
1454
                           || CommonFunctions::executeProgram('ifconfig', trim($dev_name).' 2>/dev/null', $bufr2, PSI_DEBUG)) {
1396
                            $bufe2 = preg_split("/\n/", $bufr2, -1, PREG_SPLIT_NO_EMPTY);
1455
                            $bufe2 = preg_split("/\n/", $bufr2, -1, PREG_SPLIT_NO_EMPTY);
1397
                            foreach ($bufe2 as $buf2) {
1456
                            foreach ($bufe2 as $buf2) {
1398
//                                if (preg_match('/^'.trim($dev_name).'\s+Link\sencap:Ethernet\s+HWaddr\s(\S+)/i', $buf2, $ar_buf2)
1457
//                                if (preg_match('/^'.trim($dev_name).'\s+Link\sencap:Ethernet\s+HWaddr\s(\S+)/i', $buf2, $ar_buf2)
1399
                                if (preg_match('/\s+encap:Ethernet\s+HWaddr\s(\S+)/i', $buf2, $ar_buf2)
1458
                                if (preg_match('/\s+encap:Ethernet\s+HWaddr\s(\S+)/i', $buf2, $ar_buf2)
1400
                                   || preg_match('/\s+encap:UNSPEC\s+HWaddr\s(\S+)-00-00-00-00-00-00-00-00-00-00\s*$/i', $buf2, $ar_buf2)
1459
                                   || preg_match('/\s+encap:UNSPEC\s+HWaddr\s(\S+)-00-00-00-00-00-00-00-00-00-00\s*$/i', $buf2, $ar_buf2)
1401
                                   || preg_match('/^\s+ether\s+(\S+)\s+txqueuelen/i', $buf2, $ar_buf2)
1460
                                   || preg_match('/^\s+ether\s+(\S+)\s+txqueuelen/i', $buf2, $ar_buf2)
1402
                                   || preg_match('/^\s+link\/\S+\s+(\S+)\s+brd/i', $buf2, $ar_buf2)
1461
                                   || preg_match('/^\s+link\/\S+\s+(\S+)\s+brd/i', $buf2, $ar_buf2)
1403
                                   || preg_match('/^\s+link\/\S+\s+(\S+)$/i', $buf2, $ar_buf2)) {
1462
                                   || preg_match('/^\s+link\/\S+\s+(\S+)$/i', $buf2, $ar_buf2)) {
1404
                                    if (!defined('PSI_HIDE_NETWORK_MACADDR') || !PSI_HIDE_NETWORK_MACADDR) {
1463
                                    if (!defined('PSI_HIDE_NETWORK_MACADDR') || !PSI_HIDE_NETWORK_MACADDR) {
1405
                                        $macaddr = preg_replace('/:/', '-', strtoupper($ar_buf2[1]));
1464
                                        $macaddr = preg_replace('/:/', '-', strtoupper($ar_buf2[1]));
1406
                                        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
1465
                                        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
1407
                                            $macaddr = "";
1466
                                            $macaddr = "";
1408
                                        }
1467
                                        }
1409
                                    }
1468
                                    }
1410
                                } elseif (preg_match('/^\s+inet\saddr:(\S+)\s+P-t-P:(\S+)/i', $buf2, $ar_buf2)
1469
                                } elseif (preg_match('/^\s+inet\saddr:(\S+)\s+P-t-P:(\S+)/i', $buf2, $ar_buf2)
1411
                                       || preg_match('/^\s+inet\s+(\S+)\s+netmask.+destination\s+(\S+)/i', $buf2, $ar_buf2)
1470
                                       || preg_match('/^\s+inet\s+(\S+)\s+netmask.+destination\s+(\S+)/i', $buf2, $ar_buf2)
1412
                                       || preg_match('/^\s+inet\s+([^\/\s]+).*peer\s+([^\/\s]+).*\s+scope\s((global)|(host))/i', $buf2, $ar_buf2)) {
1471
                                       || preg_match('/^\s+inet\s+([^\/\s]+).*peer\s+([^\/\s]+).*\s+scope\s((global)|(host))/i', $buf2, $ar_buf2)) {
1413
                                    if ($ar_buf2[1] != $ar_buf2[2]) {
1472
                                    if ($ar_buf2[1] != $ar_buf2[2]) {
1414
                                        $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$ar_buf2[1].";:".$ar_buf2[2]);
1473
                                        $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$ar_buf2[1].";:".$ar_buf2[2]);
1415
                                    } else {
1474
                                    } else {
1416
                                        $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$ar_buf2[1]);
1475
                                        $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$ar_buf2[1]);
1417
                                    }
1476
                                    }
1418
                                } elseif ((preg_match('/^\s+inet\saddr:(\S+)/i', $buf2, $ar_buf2)
1477
                                } elseif ((preg_match('/^\s+inet\saddr:(\S+)/i', $buf2, $ar_buf2)
1419
                                   || preg_match('/^\s+inet\s+(\S+)\s+netmask/i', $buf2, $ar_buf2)
1478
                                   || preg_match('/^\s+inet\s+(\S+)\s+netmask/i', $buf2, $ar_buf2)
1420
                                   || preg_match('/^'.trim($dev_name).':\s+ip\s+(\S+)\s+mask/i', $buf2, $ar_buf2)
1479
                                   || preg_match('/^'.trim($dev_name).':\s+ip\s+(\S+)\s+mask/i', $buf2, $ar_buf2)
1421
                                   || preg_match('/^\s+inet6\saddr:\s([^\/\s]+)(.+)\s+Scope:[GH]/i', $buf2, $ar_buf2)
1480
                                   || preg_match('/^\s+inet6\saddr:\s([^\/\s]+)(.+)\s+Scope:[GH]/i', $buf2, $ar_buf2)
1422
                                   || preg_match('/^\s+inet6\s+(\S+)\s+prefixlen(.+)((<global>)|(<host>))/i', $buf2, $ar_buf2)
1481
                                   || preg_match('/^\s+inet6\s+(\S+)\s+prefixlen(.+)((<global>)|(<host>))/i', $buf2, $ar_buf2)
1423
                                   || preg_match('/^\s+inet6?\s+([^\/\s]+).*\s+scope\s((global)|(host))/i', $buf2, $ar_buf2))
1482
                                   || preg_match('/^\s+inet6?\s+([^\/\s]+).*\s+scope\s((global)|(host))/i', $buf2, $ar_buf2)
-
 
1483
                                   || preg_match('/^\s+inet\saddr6:\s+(\S+)\s+prefixlen(.+)/i', $buf2, $ar_buf2))
1424
                                   && ($ar_buf2[1]!="::") && !preg_match('/^fe80::/i', $ar_buf2[1])) {
1484
                                   && ($ar_buf2[1]!="::") && !preg_match('/^fe80::/i', $ar_buf2[1])) {
1425
                                    $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').strtolower($ar_buf2[1]));
1485
                                    $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').strtolower($ar_buf2[1]));
1426
                                }
1486
                                }
1427
                            }
1487
                            }
1428
                        }
1488
                        }
1429
                        if ($macaddr != "") {
1489
                        if ($macaddr != "") {
1430
                            $dev->setInfo($macaddr.($dev->getInfo()?';'.$dev->getInfo():''));
1490
                            $dev->setInfo($macaddr.($dev->getInfo()?';'.$dev->getInfo():''));
1431
                        }
1491
                        }
1432
                        if ((!CommonFunctions::rfts('/sys/class/net/'.trim($dev_name).'/operstate', $buf, 1, 4096, false) || (($down=strtolower(trim($buf)))=="") || ($down!=="down")) &&
1492
                        if ((!CommonFunctions::rfts('/sys/class/net/'.trim($dev_name).'/operstate', $buf, 1, 4096, false) || (($down=strtolower(trim($buf)))=="") || ($down!=="down")) &&
1433
                           (CommonFunctions::rfts('/sys/class/net/'.trim($dev_name).'/speed', $buf, 1, 4096, false) && (($speed=trim($buf))!="") && ($buf > 0) && ($buf < 65535))) {
1493
                           (CommonFunctions::rfts('/sys/class/net/'.trim($dev_name).'/speed', $buf, 1, 4096, false) && (($speed=trim($buf))!="") && ($buf > 0) && ($buf < 65535))) {
1434
                            if ($speed > 1000) {
1494
                            if ($speed > 1000) {
1435
                                $speed = $speed/1000;
1495
                                $speed = $speed/1000;
1436
                                $unit = "G";
1496
                                $unit = "G";
1437
                            } else {
1497
                            } else {
1438
                                $unit = "M";
1498
                                $unit = "M";
1439
                            }
1499
                            }
1440
                            if (CommonFunctions::rfts('/sys/class/net/'.trim($dev_name).'/duplex', $buf, 1, 4096, false) && (($duplex=strtolower(trim($buf)))!="") && ($duplex!='unknown')) {
1500
                            if (CommonFunctions::rfts('/sys/class/net/'.trim($dev_name).'/duplex', $buf, 1, 4096, false) && (($duplex=strtolower(trim($buf)))!="") && ($duplex!='unknown')) {
1441
                                $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$speed.$unit.'b/s '.$duplex);
1501
                                $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$speed.$unit.'b/s '.$duplex);
1442
                            } else {
1502
                            } else {
1443
                                $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$speed.$unit.'b/s');
1503
                                $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$speed.$unit.'b/s');
1444
                            }
1504
                            }
1445
                        }
1505
                        }
1446
                    }
1506
                    }
1447
                    $this->sys->setNetDevices($dev);
1507
                    $this->sys->setNetDevices($dev);
1448
                }
1508
                }
1449
            }
1509
            }
1450
        } elseif (CommonFunctions::executeProgram('ip', 'addr show', $bufr, PSI_DEBUG) && ($bufr!="")) {
1510
        } elseif (($bufr === null) && CommonFunctions::executeProgram('ip', 'addr show', $bufr, PSI_DEBUG) && ($bufr!="")) {
1451
            $lines = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
1511
            $lines = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
1452
            $was = false;
1512
            $was = false;
1453
            $macaddr = "";
1513
            $macaddr = "";
1454
            $speedinfo = "";
1514
            $speedinfo = "";
1455
            $dev = null;
1515
            $dev = null;
1456
            foreach ($lines as $line) {
1516
            foreach ($lines as $line) {
1457
                if (preg_match("/^\d+:\s+([^\s:]+)/", $line, $ar_buf)) {
1517
                if (preg_match("/^\d+:\s+([^\s:]+)/", $line, $ar_buf)) {
1458
                    if ($was) {
1518
                    if ($was) {
1459
                        if ($macaddr != "") {
1519
                        if ($macaddr != "") {
1460
                            $dev->setInfo($macaddr.($dev->getInfo()?';'.$dev->getInfo():''));
1520
                            $dev->setInfo($macaddr.($dev->getInfo()?';'.$dev->getInfo():''));
1461
                        }
1521
                        }
1462
                        if ($speedinfo != "") {
1522
                        if ($speedinfo != "") {
1463
                            $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$speedinfo);
1523
                            $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$speedinfo);
1464
                        }
1524
                        }
1465
                        $this->sys->setNetDevices($dev);
1525
                        $this->sys->setNetDevices($dev);
1466
                    }
1526
                    }
1467
                    $speedinfo = "";
1527
                    $speedinfo = "";
1468
                    $macaddr = "";
1528
                    $macaddr = "";
1469
                    $dev = new NetDevice();
1529
                    $dev = new NetDevice();
1470
                    $dev->setName($ar_buf[1]);
1530
                    $dev->setName($ar_buf[1]);
1471
                    if (CommonFunctions::executeProgram('ip', '-s link show '.$ar_buf[1], $bufr2, PSI_DEBUG) && ($bufr2!="")
1531
                    if (CommonFunctions::executeProgram('ip', '-s link show '.$ar_buf[1], $bufr2, PSI_DEBUG) && ($bufr2!="")
1472
                       && preg_match("/\n\s+RX:\s[^\n]+\n\s+(\d+)\s+\d+\s+(\d+)\s+(\d+)[^\n]+\n\s+TX:\s[^\n]+\n\s+(\d+)\s+\d+\s+(\d+)\s+(\d+)/m", $bufr2, $ar_buf2)) {
1532
                       && preg_match("/\n\s+RX:\s[^\n]+\n\s+(\d+)\s+\d+\s+(\d+)\s+(\d+)[^\n]+\n\s+TX:\s[^\n]+\n\s+(\d+)\s+\d+\s+(\d+)\s+(\d+)/m", $bufr2, $ar_buf2)) {
1473
                        $dev->setRxBytes($ar_buf2[1]);
1533
                        $dev->setRxBytes($ar_buf2[1]);
1474
                        $dev->setTxBytes($ar_buf2[4]);
1534
                        $dev->setTxBytes($ar_buf2[4]);
1475
                        $dev->setErrors($ar_buf2[2]+$ar_buf2[5]);
1535
                        $dev->setErrors($ar_buf2[2]+$ar_buf2[5]);
1476
                        $dev->setDrops($ar_buf2[3]+$ar_buf2[6]);
1536
                        $dev->setDrops($ar_buf2[3]+$ar_buf2[6]);
1477
                    }
1537
                    }
1478
                    $was = true;
1538
                    $was = true;
1479
                    if (defined('PSI_SHOW_NETWORK_INFOS') && (PSI_SHOW_NETWORK_INFOS)) {
1539
                    if (defined('PSI_SHOW_NETWORK_INFOS') && (PSI_SHOW_NETWORK_INFOS)) {
1480
                        if ((!CommonFunctions::rfts('/sys/class/net/'.$ar_buf[1].'/operstate', $buf, 1, 4096, false) || (($down=strtolower(trim($buf)))=="") || ($down!=="down")) &&
1540
                        if ((!CommonFunctions::rfts('/sys/class/net/'.$ar_buf[1].'/operstate', $buf, 1, 4096, false) || (($down=strtolower(trim($buf)))=="") || ($down!=="down")) &&
1481
                           (CommonFunctions::rfts('/sys/class/net/'.$ar_buf[1].'/speed', $buf, 1, 4096, false) && (($speed=trim($buf))!="") && ($buf > 0) && ($buf < 65535))) {
1541
                           (CommonFunctions::rfts('/sys/class/net/'.$ar_buf[1].'/speed', $buf, 1, 4096, false) && (($speed=trim($buf))!="") && ($buf > 0) && ($buf < 65535))) {
1482
                            if ($speed > 1000) {
1542
                            if ($speed > 1000) {
1483
                                $speed = $speed/1000;
1543
                                $speed = $speed/1000;
1484
                                $unit = "G";
1544
                                $unit = "G";
1485
                            } else {
1545
                            } else {
1486
                                $unit = "M";
1546
                                $unit = "M";
1487
                            }
1547
                            }
1488
                            if (CommonFunctions::rfts('/sys/class/net/'.$ar_buf[1].'/duplex', $buf, 1, 4096, false) && (($duplex=strtolower(trim($buf)))!="") && ($duplex!='unknown')) {
1548
                            if (CommonFunctions::rfts('/sys/class/net/'.$ar_buf[1].'/duplex', $buf, 1, 4096, false) && (($duplex=strtolower(trim($buf)))!="") && ($duplex!='unknown')) {
1489
                                $speedinfo = $speed.$unit.'b/s '.$duplex;
1549
                                $speedinfo = $speed.$unit.'b/s '.$duplex;
1490
                            } else {
1550
                            } else {
1491
                                $speedinfo = $speed.$unit.'b/s';
1551
                                $speedinfo = $speed.$unit.'b/s';
1492
                            }
1552
                            }
1493
                        }
1553
                        }
1494
                    }
1554
                    }
1495
                } else {
1555
                } else {
1496
                    if ($was) {
1556
                    if ($was) {
1497
                        if (defined('PSI_SHOW_NETWORK_INFOS') && (PSI_SHOW_NETWORK_INFOS)) {
1557
                        if (defined('PSI_SHOW_NETWORK_INFOS') && (PSI_SHOW_NETWORK_INFOS)) {
1498
                            if (preg_match('/^\s+link\/\S+\s+(\S+)\s+brd/i', $line, $ar_buf2)
1558
                            if (preg_match('/^\s+link\/\S+\s+(\S+)\s+brd/i', $line, $ar_buf2)
1499
                               || preg_match('/^\s+link\/\S+\s+(\S+)$/i', $line, $ar_buf2)) {
1559
                               || preg_match('/^\s+link\/\S+\s+(\S+)$/i', $line, $ar_buf2)) {
1500
                                if (!defined('PSI_HIDE_NETWORK_MACADDR') || !PSI_HIDE_NETWORK_MACADDR) {
1560
                                if (!defined('PSI_HIDE_NETWORK_MACADDR') || !PSI_HIDE_NETWORK_MACADDR) {
1501
                                    $macaddr = preg_replace('/:/', '-', strtoupper($ar_buf2[1]));
1561
                                    $macaddr = preg_replace('/:/', '-', strtoupper($ar_buf2[1]));
1502
                                    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
1562
                                    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
1503
                                        $macaddr = "";
1563
                                        $macaddr = "";
1504
                                    }
1564
                                    }
1505
                                }
1565
                                }
1506
                            } elseif (preg_match('/^\s+inet\s+([^\/\s]+).*peer\s+([^\/\s]+).*\s+scope\s((global)|(host))/i', $line, $ar_buf2)) {
1566
                            } elseif (preg_match('/^\s+inet\s+([^\/\s]+).*peer\s+([^\/\s]+).*\s+scope\s((global)|(host))/i', $line, $ar_buf2)) {
1507
                                if ($ar_buf2[1] != $ar_buf2[2]) {
1567
                                if ($ar_buf2[1] != $ar_buf2[2]) {
1508
                                     $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$ar_buf2[1].";:".$ar_buf2[2]);
1568
                                     $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$ar_buf2[1].";:".$ar_buf2[2]);
1509
                                } else {
1569
                                } else {
1510
                                     $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$ar_buf2[1]);
1570
                                     $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$ar_buf2[1]);
1511
                                }
1571
                                }
1512
                            } elseif (preg_match('/^\s+inet6?\s+([^\/\s]+).*\s+scope\s((global)|(host))/i', $line, $ar_buf2)
1572
                            } elseif (preg_match('/^\s+inet6?\s+([^\/\s]+).*\s+scope\s((global)|(host))/i', $line, $ar_buf2)
1513
                                     && ($ar_buf2[1]!="::") && !preg_match('/^fe80::/i', $ar_buf2[1])) {
1573
                                     && ($ar_buf2[1]!="::") && !preg_match('/^fe80::/i', $ar_buf2[1])) {
1514
                                $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').strtolower($ar_buf2[1]));
1574
                                $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').strtolower($ar_buf2[1]));
1515
                            }
1575
                            }
1516
                        }
1576
                        }
1517
                    }
1577
                    }
1518
                }
1578
                }
1519
            }
1579
            }
1520
            if ($was) {
1580
            if ($was) {
1521
                if ($macaddr != "") {
1581
                if ($macaddr != "") {
1522
                    $dev->setInfo($macaddr.($dev->getInfo()?';'.$dev->getInfo():''));
1582
                    $dev->setInfo($macaddr.($dev->getInfo()?';'.$dev->getInfo():''));
1523
                }
1583
                }
1524
                if ($speedinfo != "") {
1584
                if ($speedinfo != "") {
1525
                    $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$speedinfo);
1585
                    $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$speedinfo);
1526
                }
1586
                }
1527
                $this->sys->setNetDevices($dev);
1587
                $this->sys->setNetDevices($dev);
1528
            }
1588
            }
1529
        } elseif (CommonFunctions::executeProgram('ifconfig', '-a', $bufr, PSI_DEBUG)) {
1589
        } elseif (($bufr !== null) || CommonFunctions::executeProgram('ifconfig', '-a', $bufr, PSI_DEBUG)) {
1530
            $lines = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
1590
            $lines = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
1531
            $was = false;
1591
            $was = false;
1532
            $errors = 0;
1592
            $errors = 0;
1533
            $drops = 0;
1593
            $drops = 0;
1534
            $macaddr = "";
1594
            $macaddr = "";
1535
            $speedinfo = "";
1595
            $speedinfo = "";
1536
            $dev = null;
1596
            $dev = null;
1537
            foreach ($lines as $line) {
1597
            foreach ($lines as $line) {
1538
                if (preg_match("/^([^\s:]+)/", $line, $ar_buf)) {
1598
                if (preg_match("/^([^\s:]+)/", $line, $ar_buf)) {
1539
                    if ($was) {
1599
                    if ($was) {
1540
                        $dev->setErrors($errors);
1600
                        $dev->setErrors($errors);
1541
                        $dev->setDrops($drops);
1601
                        $dev->setDrops($drops);
1542
                        if ($macaddr != "") {
1602
                        if ($macaddr != "") {
1543
                            $dev->setInfo($macaddr.($dev->getInfo()?';'.$dev->getInfo():''));
1603
                            $dev->setInfo($macaddr.($dev->getInfo()?';'.$dev->getInfo():''));
1544
                        }
1604
                        }
1545
                        if ($speedinfo != "") {
1605
                        if ($speedinfo != "") {
1546
                            $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$speedinfo);
1606
                            $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$speedinfo);
1547
                        }
1607
                        }
1548
                        $this->sys->setNetDevices($dev);
1608
                        $this->sys->setNetDevices($dev);
1549
                    }
1609
                    }
1550
                    $errors = 0;
1610
                    $errors = 0;
1551
                    $drops = 0;
1611
                    $drops = 0;
1552
                    $speedinfo = "";
1612
                    $speedinfo = "";
1553
                    $macaddr = "";
1613
                    $macaddr = "";
1554
                    $dev = new NetDevice();
1614
                    $dev = new NetDevice();
1555
                    $dev->setName($ar_buf[1]);
1615
                    $dev->setName($ar_buf[1]);
1556
                    $was = true;
1616
                    $was = true;
1557
                    if (defined('PSI_SHOW_NETWORK_INFOS') && (PSI_SHOW_NETWORK_INFOS)) {
1617
                    if (defined('PSI_SHOW_NETWORK_INFOS') && (PSI_SHOW_NETWORK_INFOS)) {
1558
                        if ((!CommonFunctions::rfts('/sys/class/net/'.$ar_buf[1].'/operstate', $buf, 1, 4096, false) || (($down=strtolower(trim($buf)))=="") || ($down!=="down")) &&
1618
                        if ((!CommonFunctions::rfts('/sys/class/net/'.$ar_buf[1].'/operstate', $buf, 1, 4096, false) || (($down=strtolower(trim($buf)))=="") || ($down!=="down")) &&
1559
                           (CommonFunctions::rfts('/sys/class/net/'.$ar_buf[1].'/speed', $buf, 1, 4096, false) && (($speed=trim($buf))!="") && ($buf > 0) && ($buf < 65535))) {
1619
                           (CommonFunctions::rfts('/sys/class/net/'.$ar_buf[1].'/speed', $buf, 1, 4096, false) && (($speed=trim($buf))!="") && ($buf > 0) && ($buf < 65535))) {
1560
                            if ($speed > 1000) {
1620
                            if ($speed > 1000) {
1561
                                $speed = $speed/1000;
1621
                                $speed = $speed/1000;
1562
                                $unit = "G";
1622
                                $unit = "G";
1563
                            } else {
1623
                            } else {
1564
                                $unit = "M";
1624
                                $unit = "M";
1565
                            }
1625
                            }
1566
                            if (CommonFunctions::rfts('/sys/class/net/'.$ar_buf[1].'/duplex', $buf, 1, 4096, false) && (($duplex=strtolower(trim($buf)))!="") && ($duplex!='unknown')) {
1626
                            if (CommonFunctions::rfts('/sys/class/net/'.$ar_buf[1].'/duplex', $buf, 1, 4096, false) && (($duplex=strtolower(trim($buf)))!="") && ($duplex!='unknown')) {
1567
                                $speedinfo = $speed.$unit.'b/s '.$duplex;
1627
                                $speedinfo = $speed.$unit.'b/s '.$duplex;
1568
                            } else {
1628
                            } else {
1569
                                $speedinfo = $speed.$unit.'b/s';
1629
                                $speedinfo = $speed.$unit.'b/s';
1570
                            }
1630
                            }
1571
                        }
1631
                        }
1572
                        if (preg_match('/^'.$ar_buf[1].'\s+Link\sencap:Ethernet\s+HWaddr\s(\S+)/i', $line, $ar_buf2)
1632
                        if (preg_match('/^'.$ar_buf[1].'\s+Link\sencap:Ethernet\s+HWaddr\s(\S+)/i', $line, $ar_buf2)
1573
                           || preg_match('/^'.$ar_buf[1].'\s+Link\s+encap:UNSPEC\s+HWaddr\s(\S+)-00-00-00-00-00-00-00-00-00-00\s*$/i', $line, $ar_buf2)) {
1633
                           || preg_match('/^'.$ar_buf[1].'\s+Link\s+encap:UNSPEC\s+HWaddr\s(\S+)-00-00-00-00-00-00-00-00-00-00\s*$/i', $line, $ar_buf2)) {
1574
                            if (!defined('PSI_HIDE_NETWORK_MACADDR') || !PSI_HIDE_NETWORK_MACADDR) {
1634
                            if (!defined('PSI_HIDE_NETWORK_MACADDR') || !PSI_HIDE_NETWORK_MACADDR) {
1575
                                $macaddr = preg_replace('/:/', '-', strtoupper($ar_buf2[1]));
1635
                                $macaddr = preg_replace('/:/', '-', strtoupper($ar_buf2[1]));
1576
                                if ($macaddr === '00-00-00-00-00-00') { // empty
1636
                                if ($macaddr === '00-00-00-00-00-00') { // empty
1577
                                    $macaddr = "";
1637
                                    $macaddr = "";
1578
                                }
1638
                                }
1579
                            }
1639
                            }
1580
                        } elseif (preg_match('/^'.$ar_buf[1].':\s+ip\s+(\S+)\s+mask/i', $line, $ar_buf2))
1640
                        } elseif (preg_match('/^'.$ar_buf[1].':\s+ip\s+(\S+)\s+mask/i', $line, $ar_buf2))
1581
                            $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$ar_buf2[1]);
1641
                            $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$ar_buf2[1]);
1582
                    }
1642
                    }
1583
                } else {
1643
                } else {
1584
                    if ($was) {
1644
                    if ($was) {
1585
                        if (preg_match('/\sRX bytes:(\d+)\s/i', $line, $ar_buf2)) {
1645
                        if (preg_match('/\sRX bytes:(\d+)\s/i', $line, $ar_buf2)) {
1586
                            $dev->setRxBytes($ar_buf2[1]);
1646
                            $dev->setRxBytes($ar_buf2[1]);
1587
                        }
1647
                        }
1588
                        if (preg_match('/\sTX bytes:(\d+)\s/i', $line, $ar_buf2)) {
1648
                        if (preg_match('/\sTX bytes:(\d+)\s/i', $line, $ar_buf2)) {
1589
                            $dev->setTxBytes($ar_buf2[1]);
1649
                            $dev->setTxBytes($ar_buf2[1]);
1590
                        }
1650
                        }
1591
 
1651
 
1592
                        if (preg_match('/\sRX packets:\d+\serrors:(\d+)\sdropped:(\d+)/i', $line, $ar_buf2)) {
1652
                        if (preg_match('/\sRX packets:\d+\serrors:(\d+)\sdropped:(\d+)/i', $line, $ar_buf2)) {
1593
                            $errors +=$ar_buf2[1];
1653
                            $errors +=$ar_buf2[1];
1594
                            $drops +=$ar_buf2[2];
1654
                            $drops +=$ar_buf2[2];
1595
                        } elseif (preg_match('/\sTX packets:\d+\serrors:(\d+)\sdropped:(\d+)/i', $line, $ar_buf2)) {
1655
                        } elseif (preg_match('/\sTX packets:\d+\serrors:(\d+)\sdropped:(\d+)/i', $line, $ar_buf2)) {
1596
                            $errors +=$ar_buf2[1];
1656
                            $errors +=$ar_buf2[1];
1597
                            $drops +=$ar_buf2[2];
1657
                            $drops +=$ar_buf2[2];
1598
                        }
1658
                        }
1599
 
1659
 
1600
                        if (defined('PSI_SHOW_NETWORK_INFOS') && (PSI_SHOW_NETWORK_INFOS)) {
1660
                        if (defined('PSI_SHOW_NETWORK_INFOS') && (PSI_SHOW_NETWORK_INFOS)) {
1601
                            if (preg_match('/\s+encap:Ethernet\s+HWaddr\s(\S+)/i', $line, $ar_buf2)
1661
                            if (preg_match('/\s+encap:Ethernet\s+HWaddr\s(\S+)/i', $line, $ar_buf2)
1602
                             || preg_match('/\s+encap:UNSPEC\s+HWaddr\s(\S+)-00-00-00-00-00-00-00-00-00-00\s*$/i', $line, $ar_buf2)
1662
                             || preg_match('/\s+encap:UNSPEC\s+HWaddr\s(\S+)-00-00-00-00-00-00-00-00-00-00\s*$/i', $line, $ar_buf2)
1603
                             || preg_match('/^\s+ether\s+(\S+)\s+txqueuelen/i', $line, $ar_buf2)) {
1663
                             || preg_match('/^\s+ether\s+(\S+)\s+txqueuelen/i', $line, $ar_buf2)) {
1604
                                if (!defined('PSI_HIDE_NETWORK_MACADDR') || !PSI_HIDE_NETWORK_MACADDR) {
1664
                                if (!defined('PSI_HIDE_NETWORK_MACADDR') || !PSI_HIDE_NETWORK_MACADDR) {
1605
                                    $macaddr = preg_replace('/:/', '-', strtoupper($ar_buf2[1]));
1665
                                    $macaddr = preg_replace('/:/', '-', strtoupper($ar_buf2[1]));
1606
                                    if ($macaddr === '00-00-00-00-00-00') { // empty
1666
                                    if ($macaddr === '00-00-00-00-00-00') { // empty
1607
                                        $macaddr = "";
1667
                                        $macaddr = "";
1608
                                    }
1668
                                    }
1609
                                }
1669
                                }
1610
                            } elseif (preg_match('/^\s+inet\saddr:(\S+)\s+P-t-P:(\S+)/i', $line, $ar_buf2)
1670
                            } elseif (preg_match('/^\s+inet\saddr:(\S+)\s+P-t-P:(\S+)/i', $line, $ar_buf2)
1611
                                  || preg_match('/^\s+inet\s+(\S+)\s+netmask.+destination\s+(\S+)/i', $line, $ar_buf2)) {
1671
                                  || preg_match('/^\s+inet\s+(\S+)\s+netmask.+destination\s+(\S+)/i', $line, $ar_buf2)) {
1612
                                if ($ar_buf2[1] != $ar_buf2[2]) {
1672
                                if ($ar_buf2[1] != $ar_buf2[2]) {
1613
                                     $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$ar_buf2[1].";:".$ar_buf2[2]);
1673
                                     $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$ar_buf2[1].";:".$ar_buf2[2]);
1614
                                } else {
1674
                                } else {
1615
                                     $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$ar_buf2[1]);
1675
                                     $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$ar_buf2[1]);
1616
                                }
1676
                                }
1617
                            } elseif ((preg_match('/^\s+inet\saddr:(\S+)/i', $line, $ar_buf2)
1677
                            } elseif ((preg_match('/^\s+inet\saddr:(\S+)/i', $line, $ar_buf2)
1618
                                  || preg_match('/^\s+inet\s+(\S+)\s+netmask/i', $line, $ar_buf2)
1678
                                  || preg_match('/^\s+inet\s+(\S+)\s+netmask/i', $line, $ar_buf2)
1619
                                  || preg_match('/^\s+inet6\saddr:\s([^\/\s]+)(.+)\s+Scope:[GH]/i', $line, $ar_buf2)
1679
                                  || preg_match('/^\s+inet6\saddr:\s([^\/\s]+)(.+)\s+Scope:[GH]/i', $line, $ar_buf2)
1620
                                  || preg_match('/^\s+inet6\s+(\S+)\s+prefixlen(.+)((<global>)|(<host>))/i', $line, $ar_buf2))
1680
                                  || preg_match('/^\s+inet6\s+(\S+)\s+prefixlen(.+)((<global>)|(<host>))/i', $line, $ar_buf2)
-
 
1681
                                  || preg_match('/^\s+inet\saddr6:\s+(\S+)\s+prefixlen(.+)/i', $line, $ar_buf2))
1621
                                  && ($ar_buf2[1]!="::") && !preg_match('/^fe80::/i', $ar_buf2[1])) {
1682
                                  && ($ar_buf2[1]!="::") && !preg_match('/^fe80::/i', $ar_buf2[1])) {
1622
                                $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').strtolower($ar_buf2[1]));
1683
                                $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').strtolower($ar_buf2[1]));
1623
                            }
1684
                            }
1624
                        }
1685
                        }
1625
                    }
1686
                    }
1626
                }
1687
                }
1627
            }
1688
            }
1628
            if ($was) {
1689
            if ($was) {
1629
                $dev->setErrors($errors);
1690
                $dev->setErrors($errors);
1630
                $dev->setDrops($drops);
1691
                $dev->setDrops($drops);
1631
                if ($macaddr != "") {
1692
                if ($macaddr != "") {
1632
                    $dev->setInfo($macaddr.($dev->getInfo()?';'.$dev->getInfo():''));
1693
                    $dev->setInfo($macaddr.($dev->getInfo()?';'.$dev->getInfo():''));
1633
                }
1694
                }
1634
                if ($speedinfo != "") {
1695
                if ($speedinfo != "") {
1635
                    $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$speedinfo);
1696
                    $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$speedinfo);
1636
                }
1697
                }
1637
                $this->sys->setNetDevices($dev);
1698
                $this->sys->setNetDevices($dev);
1638
            }
1699
            }
1639
        }
1700
        }
1640
    }
1701
    }
1641
 
1702
 
1642
    /**
1703
    /**
1643
     * Physical memory information and Swap Space information
1704
     * Physical memory information and Swap Space information
1644
     *
1705
     *
1645
     * @return void
1706
     * @return void
1646
     */
1707
     */
1647
    protected function _memory()
1708
    protected function _memory($mbuf = null, $sbuf = null)
1648
    {
1709
    {
1649
        if (CommonFunctions::rfts('/proc/meminfo', $mbuf)) {
1710
        if (($mbuf !== null) || CommonFunctions::rfts('/proc/meminfo', $mbuf)) {
1650
            $swaptotal = null;
1711
            $swaptotal = null;
1651
            $swapfree = null;
1712
            $swapfree = null;
1652
            $bufe = preg_split("/\n/", $mbuf, -1, PREG_SPLIT_NO_EMPTY);
1713
            $bufe = preg_split("/\n/", $mbuf, -1, PREG_SPLIT_NO_EMPTY);
1653
            foreach ($bufe as $buf) {
1714
            foreach ($bufe as $buf) {
1654
                if (preg_match('/^MemTotal:\s+(\d+)\s*kB/i', $buf, $ar_buf)) {
1715
                if (preg_match('/^MemTotal:\s+(\d+)\s*kB/i', $buf, $ar_buf)) {
1655
                    $this->sys->setMemTotal($ar_buf[1] * 1024);
1716
                    $this->sys->setMemTotal($ar_buf[1] * 1024);
1656
                } elseif (preg_match('/^MemFree:\s+(\d+)\s*kB/i', $buf, $ar_buf)) {
1717
                } elseif (preg_match('/^MemFree:\s+(\d+)\s*kB/i', $buf, $ar_buf)) {
1657
                    $this->sys->setMemFree($ar_buf[1] * 1024);
1718
                    $this->sys->setMemFree($ar_buf[1] * 1024);
1658
                } elseif (preg_match('/^Cached:\s+(\d+)\s*kB/i', $buf, $ar_buf)) {
1719
                } elseif (preg_match('/^Cached:\s+(\d+)\s*kB/i', $buf, $ar_buf)) {
1659
                    $this->sys->setMemCache($ar_buf[1] * 1024);
1720
                    $this->sys->setMemCache($ar_buf[1] * 1024);
1660
                } elseif (preg_match('/^Buffers:\s+(\d+)\s*kB/i', $buf, $ar_buf)) {
1721
                } elseif (preg_match('/^Buffers:\s+(\d+)\s*kB/i', $buf, $ar_buf)) {
1661
                    $this->sys->setMemBuffer($ar_buf[1] * 1024);
1722
                    $this->sys->setMemBuffer($ar_buf[1] * 1024);
1662
                } elseif (preg_match('/^SwapTotal:\s+(\d+)\s*kB/i', $buf, $ar_buf)) {
1723
                } elseif (preg_match('/^SwapTotal:\s+(\d+)\s*kB/i', $buf, $ar_buf)) {
1663
                    $swaptotal = $ar_buf[1] * 1024;
1724
                    $swaptotal = $ar_buf[1] * 1024;
1664
                } elseif (preg_match('/^SwapFree:\s+(\d+)\s*kB/i', $buf, $ar_buf)) {
1725
                } elseif (preg_match('/^SwapFree:\s+(\d+)\s*kB/i', $buf, $ar_buf)) {
1665
                    $swapfree = $ar_buf[1] * 1024;
1726
                    $swapfree = $ar_buf[1] * 1024;
1666
                }
1727
                }
1667
            }
1728
            }
1668
            $this->sys->setMemUsed($this->sys->getMemTotal() - $this->sys->getMemFree());
1729
            $this->sys->setMemUsed($this->sys->getMemTotal() - $this->sys->getMemFree());
1669
            // values for splitting memory usage
1730
            // values for splitting memory usage
1670
            if (($this->sys->getMemCache() !== null) && ($this->sys->getMemBuffer() !== null)) {
1731
            if (($this->sys->getMemCache() !== null) && ($this->sys->getMemBuffer() !== null)) {
1671
                $this->sys->setMemApplication($this->sys->getMemUsed() - $this->sys->getMemCache() - $this->sys->getMemBuffer());
1732
                $this->sys->setMemApplication($this->sys->getMemUsed() - $this->sys->getMemCache() - $this->sys->getMemBuffer());
1672
            }
1733
            }
1673
            if (CommonFunctions::rfts('/proc/swaps', $sbuf, 0, 4096, false)) {
1734
            if (($sbuf !== null) || CommonFunctions::rfts('/proc/swaps', $sbuf, 0, 4096, false)) {
1674
                $swaps = preg_split("/\n/", $sbuf, -1, PREG_SPLIT_NO_EMPTY);
1735
                $swaps = preg_split("/\n/", $sbuf, -1, PREG_SPLIT_NO_EMPTY);
1675
                unset($swaps[0]);
1736
                unset($swaps[0]);
1676
                foreach ($swaps as $swap) {
1737
                foreach ($swaps as $swap) {
1677
                    $ar_buf = preg_split('/\s+/', $swap, 5);
1738
                    $ar_buf = preg_split('/\s+/', $swap, 5);
1678
                    $dev = new DiskDevice();
1739
                    $dev = new DiskDevice();
1679
                    $dev->setMountPoint($ar_buf[0]);
1740
                    $dev->setMountPoint($ar_buf[0]);
1680
                    $dev->setName("SWAP");
1741
                    $dev->setName("SWAP");
1681
                    $dev->setTotal($ar_buf[2] * 1024);
1742
                    $dev->setTotal($ar_buf[2] * 1024);
1682
                    $dev->setUsed($ar_buf[3] * 1024);
1743
                    $dev->setUsed($ar_buf[3] * 1024);
1683
                    $dev->setFree($dev->getTotal() - $dev->getUsed());
1744
                    $dev->setFree($dev->getTotal() - $dev->getUsed());
1684
                    $this->sys->setSwapDevices($dev);
1745
                    $this->sys->setSwapDevices($dev);
1685
                }
1746
                }
1686
            } elseif (($swaptotal !== null) && ($swapfree !== null) && ($swaptotal > 0)) {
1747
            } elseif (($swaptotal !== null) && ($swapfree !== null) && ($swaptotal > 0)) {
1687
                    $dev = new DiskDevice();
1748
                    $dev = new DiskDevice();
1688
                    $dev->setName("SWAP");
1749
                    $dev->setName("SWAP");
1689
                    $dev->setTotal($swaptotal);
1750
                    $dev->setTotal($swaptotal);
1690
                    $dev->setFree($swapfree);
1751
                    $dev->setFree($swapfree);
1691
                    $dev->setUsed($dev->getTotal() - $dev->getFree());
1752
                    $dev->setUsed($dev->getTotal() - $dev->getFree());
1692
                    $this->sys->setSwapDevices($dev);
1753
                    $this->sys->setSwapDevices($dev);
1693
            }
1754
            }
1694
        }
1755
        }
1695
    }
1756
    }
1696
 
1757
 
1697
    /**
1758
    /**
1698
     * filesystem information
1759
     * filesystem information
1699
     *
1760
     *
1700
     * @return void
1761
     * @return void
1701
     */
1762
     */
1702
    private function _filesystems()
1763
    protected function _filesystems()
1703
    {
1764
    {
1704
        $df_args = "";
1765
        $df_args = "";
1705
        $hideFstypes = array();
1766
        $hideFstypes = array();
1706
        if (defined('PSI_HIDE_FS_TYPES') && is_string(PSI_HIDE_FS_TYPES)) {
1767
        if (defined('PSI_HIDE_FS_TYPES') && is_string(PSI_HIDE_FS_TYPES)) {
1707
            if (preg_match(ARRAY_EXP, PSI_HIDE_FS_TYPES)) {
1768
            if (preg_match(ARRAY_EXP, PSI_HIDE_FS_TYPES)) {
1708
                $hideFstypes = eval(PSI_HIDE_FS_TYPES);
1769
                $hideFstypes = eval(PSI_HIDE_FS_TYPES);
1709
            } else {
1770
            } else {
1710
                $hideFstypes = array(PSI_HIDE_FS_TYPES);
1771
                $hideFstypes = array(PSI_HIDE_FS_TYPES);
1711
            }
1772
            }
1712
        }
1773
        }
1713
        foreach ($hideFstypes as $Fstype) {
1774
        foreach ($hideFstypes as $Fstype) {
1714
            $df_args .= "-x $Fstype ";
1775
            $df_args .= "-x $Fstype ";
1715
        }
1776
        }
1716
        if ($df_args !== "") {
1777
        if ($df_args !== "") {
1717
            $df_args = trim($df_args); // trim spaces
1778
            $df_args = trim($df_args); // trim spaces
1718
            $arrResult = Parser::df("-P $df_args 2>/dev/null");
1779
            $arrResult = Parser::df("-P $df_args 2>/dev/null");
1719
        } else {
1780
        } else {
1720
            $arrResult = Parser::df("-P 2>/dev/null");
1781
            $arrResult = Parser::df("-P 2>/dev/null");
1721
        }
1782
        }
1722
        foreach ($arrResult as $dev) {
1783
        foreach ($arrResult as $dev) {
1723
            $this->sys->setDiskDevices($dev);
1784
            $this->sys->setDiskDevices($dev);
1724
        }
1785
        }
1725
    }
1786
    }
1726
 
1787
 
1727
    /**
1788
    /**
1728
     * Distribution
1789
     * Distribution
1729
     *
1790
     *
1730
     * @return void
1791
     * @return void
1731
     */
1792
     */
1732
    protected function _distro()
1793
    protected function _distro()
1733
    {
1794
    {
1734
        $this->sys->setDistribution("Linux");
1795
        $this->sys->setDistribution("Linux");
1735
        $list = @parse_ini_file(PSI_APP_ROOT."/data/distros.ini", true);
1796
        $list = @parse_ini_file(PSI_APP_ROOT."/data/distros.ini", true);
1736
        if (!$list) {
1797
        if (!$list) {
1737
            return;
1798
            return;
1738
        }
1799
        }
1739
        // We have the '2>/dev/null' because Ubuntu gives an error on this command which causes the distro to be unknown
1800
        // We have the '2>/dev/null' because Ubuntu gives an error on this command which causes the distro to be unknown
1740
        if (CommonFunctions::executeProgram('lsb_release', '-a 2>/dev/null', $distro_info, PSI_DEBUG) && strlen($distro_info) > 0) {
1801
        if (CommonFunctions::executeProgram('lsb_release', '-a 2>/dev/null', $distro_info, PSI_DEBUG) && strlen($distro_info) > 0) {
1741
            $distro_tmp = preg_split("/\r?\n/", $distro_info, -1, PREG_SPLIT_NO_EMPTY);
1802
            $distro_tmp = preg_split("/\r?\n/", $distro_info, -1, PREG_SPLIT_NO_EMPTY);
1742
            foreach ($distro_tmp as $info) {
1803
            foreach ($distro_tmp as $info) {
1743
                $info_tmp = preg_split('/:/', $info, 2);
1804
                $info_tmp = preg_split('/:/', $info, 2);
1744
                if (isset($distro_tmp[0]) && ($distro_tmp[0] !== null) && (trim($distro_tmp[0]) != "") &&
1805
                if (isset($distro_tmp[0]) && ($distro_tmp[0] !== null) && (trim($distro_tmp[0]) != "") &&
1745
                     isset($distro_tmp[1]) && ($distro_tmp[1] !== null) && (trim($distro_tmp[1]) != "")) {
1806
                     isset($distro_tmp[1]) && ($distro_tmp[1] !== null) && (trim($distro_tmp[1]) != "")) {
1746
                    $distro[trim($info_tmp[0])] = trim($info_tmp[1]);
1807
                    $distro[trim($info_tmp[0])] = trim($info_tmp[1]);
1747
                }
1808
                }
1748
            }
1809
            }
1749
            if (!isset($distro['Distributor ID']) && !isset($distro['Description'])) { // Systems like StartOS
1810
            if (!isset($distro['Distributor ID']) && !isset($distro['Description'])) { // Systems like StartOS
1750
                if (isset($distro_tmp[0]) && ($distro_tmp[0] !== null) && (trim($distro_tmp[0]) != "")) {
1811
                if (isset($distro_tmp[0]) && ($distro_tmp[0] !== null) && (trim($distro_tmp[0]) != "")) {
1751
                    $this->sys->setDistribution(trim($distro_tmp[0]));
1812
                    $this->sys->setDistribution(trim($distro_tmp[0]));
1752
                    if (preg_match('/^(\S+)\s*/', $distro_tmp[0], $id_buf)
1813
                    if (preg_match('/^(\S+)\s*/', $distro_tmp[0], $id_buf)
1753
                        && isset($list[trim($id_buf[1])]['Image'])) {
1814
                        && isset($list[trim($id_buf[1])]['Image'])) {
1754
                            $this->sys->setDistributionIcon($list[trim($id_buf[1])]['Image']);
1815
                            $this->sys->setDistributionIcon($list[trim($id_buf[1])]['Image']);
1755
                    }
1816
                    }
1756
                }
1817
                }
1757
            } else {
1818
            } else {
1758
                if (isset($distro['Description']) && ($distro['Description'] != "n/a") && isset($distro['Distributor ID']) && $distro['Distributor ID']=="Neon") { // Neon systems
1819
                if (isset($distro['Description']) && ($distro['Description'] != "n/a") && isset($distro['Distributor ID']) && $distro['Distributor ID']=="Neon") { // Neon systems
1759
                    $distro_tmp = preg_split("/\s/", $distro['Description'], -1, PREG_SPLIT_NO_EMPTY);
1820
                    $distro_tmp = preg_split("/\s/", $distro['Description'], -1, PREG_SPLIT_NO_EMPTY);
1760
                    $distro['Distributor ID'] = $distro_tmp[0];
1821
                    $distro['Distributor ID'] = $distro_tmp[0];
1761
                }
1822
                }
1762
                if (isset($distro['Description'])
1823
                if (isset($distro['Description'])
1763
                   && preg_match('/^NAME=\s*"?([^"\r\n]+)"?\s*$/', $distro['Description'], $name_tmp)) {
1824
                   && preg_match('/^NAME=\s*"?([^"\r\n]+)"?\s*$/', $distro['Description'], $name_tmp)) {
1764
                   $distro['Description'] = trim($name_tmp[1]);
1825
                   $distro['Description'] = trim($name_tmp[1]);
1765
                }
1826
                }
1766
                if (isset($distro['Description'])
1827
                if (isset($distro['Description'])
1767
                   && ($distro['Description'] != "n/a")
1828
                   && ($distro['Description'] != "n/a")
1768
                   && (!isset($distro['Distributor ID'])
1829
                   && (!isset($distro['Distributor ID'])
1769
                   || (($distro['Distributor ID'] != "n/a")
1830
                   || (($distro['Distributor ID'] != "n/a")
1770
                   && ($distro['Description'] != $distro['Distributor ID'])))) {
1831
                   && ($distro['Description'] != $distro['Distributor ID'])))) {
1771
                    $this->sys->setDistribution($distro['Description']);
1832
                    $this->sys->setDistribution($distro['Description']);
1772
                    if (isset($distro['Release']) && ($distro['Release'] != "n/a")
1833
                    if (isset($distro['Release']) && ($distro['Release'] != "n/a")
1773
                       && ($distro['Release'] != $distro['Description']) && strstr($distro['Release'], ".")){
1834
                       && ($distro['Release'] != $distro['Description']) && strstr($distro['Release'], ".")){
1774
                        if (preg_match("/^(\d+)\.[0]+$/", $distro['Release'], $match_buf)) {
1835
                        if (preg_match("/^(\d+)\.[0]+$/", $distro['Release'], $match_buf)) {
1775
                            $tofind = $match_buf[1];
1836
                            $tofind = $match_buf[1];
1776
                        } else {
1837
                        } else {
1777
                            $tofind = $distro['Release'];
1838
                            $tofind = $distro['Release'];
1778
                        }
1839
                        }
1779
                        if (!preg_match("/^".$tofind."[\s\.]|[\(\[]".$tofind."[\.\)\]]|\s".$tofind."$|\s".$tofind."[\s\.]/", $distro['Description'])) {
1840
                        if (!preg_match("/^".$tofind."[\s\.]|[\(\[]".$tofind."[\.\)\]]|\s".$tofind."$|\s".$tofind."[\s\.]/", $distro['Description'])) {
1780
                            $this->sys->setDistribution($this->sys->getDistribution()." ".$distro['Release']);
1841
                            $this->sys->setDistribution($this->sys->getDistribution()." ".$distro['Release']);
1781
                        }
1842
                        }
1782
                    }
1843
                    }
1783
                } elseif (isset($distro['Distributor ID'])) {
1844
                } elseif (isset($distro['Distributor ID'])) {
1784
                    if ($distro['Distributor ID'] != "n/a") {
1845
                    if ($distro['Distributor ID'] != "n/a") {
1785
                        $this->sys->setDistribution($distro['Distributor ID']);
1846
                        $this->sys->setDistribution($distro['Distributor ID']);
1786
                        if (isset($distro['Release']) && ($distro['Release'] != "n/a")) {
1847
                        if (isset($distro['Release']) && ($distro['Release'] != "n/a")) {
1787
                            $this->sys->setDistribution($this->sys->getDistribution()." ".$distro['Release']);
1848
                            $this->sys->setDistribution($this->sys->getDistribution()." ".$distro['Release']);
1788
                        }
1849
                        }
1789
                        if (isset($distro['Codename']) && ($distro['Codename'] != "n/a")) {
1850
                        if (isset($distro['Codename']) && ($distro['Codename'] != "n/a")) {
1790
                            $this->sys->setDistribution($this->sys->getDistribution()." (".$distro['Codename'].")");
1851
                            $this->sys->setDistribution($this->sys->getDistribution()." (".$distro['Codename'].")");
1791
                        }
1852
                        }
1792
                    } elseif (isset($distro['Description']) && ($distro['Description'] != "n/a")) {
1853
                    } elseif (isset($distro['Description']) && ($distro['Description'] != "n/a")) {
1793
                        $this->sys->setDistribution($distro['Description']);
1854
                        $this->sys->setDistribution($distro['Description']);
1794
                    }
1855
                    }
1795
                }
1856
                }
1796
                if (isset($distro['Distributor ID'])) {
1857
                if (isset($distro['Distributor ID'])) {
1797
                    $distrib = $distro['Distributor ID'];
1858
                    $distrib = $distro['Distributor ID'];
1798
                    if (isset($distro['Description'])) {
1859
                    if (isset($distro['Description'])) {
1799
                        $distarr = preg_split("/\s/", $distro['Description'], -1, PREG_SPLIT_NO_EMPTY);
1860
                        $distarr = preg_split("/\s/", $distro['Description'], -1, PREG_SPLIT_NO_EMPTY);
1800
                        if (isset($distarr[0])) {
1861
                        if (isset($distarr[0])) {
1801
                            if ($distrib != "n/a") {
1862
                            if ($distrib != "n/a") {
1802
                                $distrib .= ' '.$distarr[0];
1863
                                $distrib .= ' '.$distarr[0];
1803
                            } else {
1864
                            } else {
1804
                                $distrib = $distarr[0];
1865
                                $distrib = $distarr[0];
1805
                            }
1866
                            }
1806
                        }
1867
                        }
1807
                    }
1868
                    }
1808
                    if (isset($list[$distrib]['Image'])) {
1869
                    if (isset($list[$distrib]['Image'])) {
1809
                        $this->sys->setDistributionIcon($list[$distrib]['Image']);
1870
                        $this->sys->setDistributionIcon($list[$distrib]['Image']);
1810
                    } elseif (($distro['Distributor ID'] != "n/a") && isset($list[$distro['Distributor ID']]['Image'])) {
1871
                    } elseif (($distro['Distributor ID'] != "n/a") && isset($list[$distro['Distributor ID']]['Image'])) {
1811
                        $this->sys->setDistributionIcon($list[$distro['Distributor ID']]['Image']);
1872
                        $this->sys->setDistributionIcon($list[$distro['Distributor ID']]['Image']);
1812
                    }
1873
                    }
1813
                }
1874
                }
1814
            }
1875
            }
1815
        } else {
1876
        } else {
1816
            /* default error handler */
1877
            /* default error handler */
1817
            if (function_exists('errorHandlerPsi')) {
1878
            if (function_exists('errorHandlerPsi')) {
1818
                restore_error_handler();
1879
                restore_error_handler();
1819
            }
1880
            }
1820
            /* fatal errors only */
1881
            /* fatal errors only */
1821
            $old_err_rep = error_reporting();
1882
            $old_err_rep = error_reporting();
1822
            error_reporting(E_ERROR);
1883
            error_reporting(E_ERROR);
1823
 
1884
 
1824
            // Fall back in case 'lsb_release' does not exist but exist /etc/lsb-release
1885
            // Fall back in case 'lsb_release' does not exist but exist /etc/lsb-release
1825
            if (CommonFunctions::fileexists($filename="/etc/lsb-release")
1886
            if (CommonFunctions::fileexists($filename="/etc/lsb-release")
1826
               && CommonFunctions::rfts($filename, $buf, 0, 4096, false)
1887
               && CommonFunctions::rfts($filename, $buf, 0, 4096, false)
1827
               && preg_match('/^DISTRIB_ID="?([^"\r\n]+)/m', $buf, $id_buf)) {
1888
               && preg_match('/^DISTRIB_ID="?([^"\r\n]+)/m', $buf, $id_buf)) {
1828
                if (preg_match('/^DISTRIB_DESCRIPTION="?([^"\r\n]+)/m', $buf, $desc_buf)
1889
                if (preg_match('/^DISTRIB_DESCRIPTION="?([^"\r\n]+)/m', $buf, $desc_buf)
1829
                   && (trim($desc_buf[1])!=trim($id_buf[1]))) {
1890
                   && (trim($desc_buf[1])!=trim($id_buf[1]))) {
1830
                    $this->sys->setDistribution(trim($desc_buf[1]));
1891
                    $this->sys->setDistribution(trim($desc_buf[1]));
1831
                    if (preg_match('/^DISTRIB_RELEASE="?([^"\r\n]+)/m', $buf, $vers_buf)
1892
                    if (preg_match('/^DISTRIB_RELEASE="?([^"\r\n]+)/m', $buf, $vers_buf)
1832
                       && (trim($vers_buf[1])!=trim($desc_buf[1])) && strstr($vers_buf[1], ".")){
1893
                       && (trim($vers_buf[1])!=trim($desc_buf[1])) && strstr($vers_buf[1], ".")){
1833
                        if (preg_match("/^(\d+)\.[0]+$/", trim($vers_buf[1]), $match_buf)) {
1894
                        if (preg_match("/^(\d+)\.[0]+$/", trim($vers_buf[1]), $match_buf)) {
1834
                            $tofind = $match_buf[1];
1895
                            $tofind = $match_buf[1];
1835
                        } else {
1896
                        } else {
1836
                            $tofind = trim($vers_buf[1]);
1897
                            $tofind = trim($vers_buf[1]);
1837
                        }
1898
                        }
1838
                        if (!preg_match("/^".$tofind."[\s\.]|[\(\[]".$tofind."[\.\)\]]|\s".$tofind."$|\s".$tofind."[\s\.]/", trim($desc_buf[1]))) {
1899
                        if (!preg_match("/^".$tofind."[\s\.]|[\(\[]".$tofind."[\.\)\]]|\s".$tofind."$|\s".$tofind."[\s\.]/", trim($desc_buf[1]))) {
1839
                            $this->sys->setDistribution($this->sys->getDistribution()." ".trim($vers_buf[1]));
1900
                            $this->sys->setDistribution($this->sys->getDistribution()." ".trim($vers_buf[1]));
1840
                        }
1901
                        }
1841
                    }
1902
                    }
1842
                } else {
1903
                } else {
1843
                    if (isset($list[trim($id_buf[1])]['Name'])) {
1904
                    if (isset($list[trim($id_buf[1])]['Name'])) {
1844
                        $this->sys->setDistribution(trim($list[trim($id_buf[1])]['Name']));
1905
                        $this->sys->setDistribution(trim($list[trim($id_buf[1])]['Name']));
1845
                    } else {
1906
                    } else {
1846
                        $this->sys->setDistribution(trim($id_buf[1]));
1907
                        $this->sys->setDistribution(trim($id_buf[1]));
1847
                    }
1908
                    }
1848
                    if (preg_match('/^DISTRIB_RELEASE="?([^"\r\n]+)/m', $buf, $vers_buf)) {
1909
                    if (preg_match('/^DISTRIB_RELEASE="?([^"\r\n]+)/m', $buf, $vers_buf)) {
1849
                        $this->sys->setDistribution($this->sys->getDistribution()." ".trim($vers_buf[1]));
1910
                        $this->sys->setDistribution($this->sys->getDistribution()." ".trim($vers_buf[1]));
1850
                    }
1911
                    }
1851
                    if (preg_match('/^DISTRIB_CODENAME="?([^"\r\n]+)/m', $buf, $vers_buf)) {
1912
                    if (preg_match('/^DISTRIB_CODENAME="?([^"\r\n]+)/m', $buf, $vers_buf)) {
1852
                        $this->sys->setDistribution($this->sys->getDistribution()." (".trim($vers_buf[1]).")");
1913
                        $this->sys->setDistribution($this->sys->getDistribution()." (".trim($vers_buf[1]).")");
1853
                    }
1914
                    }
1854
                }
1915
                }
1855
                if (isset($list[trim($id_buf[1])]['Image'])) {
1916
                if (isset($list[trim($id_buf[1])]['Image'])) {
1856
                    $this->sys->setDistributionIcon($list[trim($id_buf[1])]['Image']);
1917
                    $this->sys->setDistributionIcon($list[trim($id_buf[1])]['Image']);
1857
                }
1918
                }
1858
            } else { // otherwise find files specific for distribution
1919
            } else { // otherwise find files specific for distribution
1859
                foreach ($list as $section=>$distribution) {
1920
                foreach ($list as $section=>$distribution) {
1860
                    if (!isset($distribution['Files'])) {
1921
                    if (!isset($distribution['Files'])) {
1861
                        continue;
1922
                        continue;
1862
                    } else {
1923
                    } else {
1863
                        foreach (preg_split("/;/", $distribution['Files'], -1, PREG_SPLIT_NO_EMPTY) as $filename) {
1924
                        foreach (preg_split("/;/", $distribution['Files'], -1, PREG_SPLIT_NO_EMPTY) as $filename) {
1864
                            if (CommonFunctions::fileexists($filename)) {
1925
                            if (CommonFunctions::fileexists($filename)) {
1865
                                $distro = $distribution;
1926
                                $distro = $distribution;
1866
                                if (isset($distribution['Mode'])&&(strtolower($distribution['Mode'])=="detection")) {
1927
                                if (isset($distribution['Mode'])&&(strtolower($distribution['Mode'])=="detection")) {
1867
                                    $buf = "";
1928
                                    $buf = "";
1868
                                } elseif (isset($distribution['Mode'])&&(strtolower($distribution['Mode'])=="execute")) {
1929
                                } elseif (isset($distribution['Mode'])&&(strtolower($distribution['Mode'])=="execute")) {
1869
                                    if (!CommonFunctions::executeProgram($filename, '2>/dev/null', $buf, PSI_DEBUG)) {
1930
                                    if (!CommonFunctions::executeProgram($filename, '2>/dev/null', $buf, PSI_DEBUG)) {
1870
                                        $buf = "";
1931
                                        $buf = "";
1871
                                    }
1932
                                    }
1872
                                } else {
1933
                                } else {
1873
                                    if (!CommonFunctions::rfts($filename, $buf, 1, 4096, false)) {
1934
                                    if (!CommonFunctions::rfts($filename, $buf, 1, 4096, false)) {
1874
                                        $buf = "";
1935
                                        $buf = "";
1875
                                    } elseif (isset($distribution['Mode'])&&(strtolower($distribution['Mode'])=="analyse")) {
1936
                                    } elseif (isset($distribution['Mode'])&&(strtolower($distribution['Mode'])=="analyse")) {
1876
                                        if (preg_match('/^(\S+)\s*/', preg_replace('/^Red\s+/', 'Red', $buf), $id_buf)
1937
                                        if (preg_match('/^(\S+)\s*/', preg_replace('/^Red\s+/', 'Red', $buf), $id_buf)
1877
                                           && isset($list[trim($id_buf[1])]['Image'])) {
1938
                                           && isset($list[trim($id_buf[1])]['Image'])) {
1878
                                            $distro = $list[trim($id_buf[1])];
1939
                                            $distro = $list[trim($id_buf[1])];
1879
                                        }
1940
                                        }
1880
                                    }
1941
                                    }
1881
                                }
1942
                                }
1882
                                if (isset($distro['Image'])) {
1943
                                if (isset($distro['Image'])) {
1883
                                    $this->sys->setDistributionIcon($distro['Image']);
1944
                                    $this->sys->setDistributionIcon($distro['Image']);
1884
                                }
1945
                                }
1885
                                if (isset($distribution['Name'])) {
1946
                                if (isset($distribution['Name'])) {
1886
                                    if (($buf === null) || (trim($buf) == "")) {
1947
                                    if (($buf === null) || (trim($buf) == "")) {
1887
                                        $this->sys->setDistribution($distribution['Name']);
1948
                                        $this->sys->setDistribution($distribution['Name']);
1888
                                    } else {
1949
                                    } else {
1889
                                        $this->sys->setDistribution($distribution['Name']." ".trim($buf));
1950
                                        $this->sys->setDistribution($distribution['Name']." ".trim($buf));
1890
                                    }
1951
                                    }
1891
                                } else {
1952
                                } else {
1892
                                    if (($buf === null) || (trim($buf) == "")) {
1953
                                    if (($buf === null) || (trim($buf) == "")) {
1893
                                        $this->sys->setDistribution($section);
1954
                                        $this->sys->setDistribution($section);
1894
                                    } else {
1955
                                    } else {
1895
                                        $this->sys->setDistribution(trim($buf));
1956
                                        $this->sys->setDistribution(trim($buf));
1896
                                    }
1957
                                    }
1897
                                }
1958
                                }
1898
                                if (isset($distribution['Files2'])) {
1959
                                if (isset($distribution['Files2'])) {
1899
                                    foreach (preg_split("/;/", $distribution['Files2'], -1, PREG_SPLIT_NO_EMPTY) as $filename2) {
1960
                                    foreach (preg_split("/;/", $distribution['Files2'], -1, PREG_SPLIT_NO_EMPTY) as $filename2) {
1900
                                        if (CommonFunctions::fileexists($filename2) && CommonFunctions::rfts($filename2, $buf, 0, 4096, false)) {
1961
                                        if (CommonFunctions::fileexists($filename2) && CommonFunctions::rfts($filename2, $buf, 0, 4096, false)) {
1901
                                            if (preg_match('/^majorversion="?([^"\r\n]+)/m', $buf, $maj_buf)
1962
                                            if (preg_match('/^majorversion="?([^"\r\n]+)/m', $buf, $maj_buf)
1902
                                               && preg_match('/^minorversion="?([^"\r\n]+)/m', $buf, $min_buf)) {
1963
                                               && preg_match('/^minorversion="?([^"\r\n]+)/m', $buf, $min_buf)) {
1903
                                                $distr2=$maj_buf[1].'.'.$min_buf[1];
1964
                                                $distr2=$maj_buf[1].'.'.$min_buf[1];
1904
                                                if (preg_match('/^buildphase="?([^"\r\n]+)/m', $buf, $pha_buf) && ($pha_buf[1]!=="0")) {
1965
                                                if (preg_match('/^buildphase="?([^"\r\n]+)/m', $buf, $pha_buf) && ($pha_buf[1]!=="0")) {
1905
                                                    $distr2.='.'.$pha_buf[1];
1966
                                                    $distr2.='.'.$pha_buf[1];
1906
                                                }
1967
                                                }
1907
                                                if (preg_match('/^buildnumber="?([^"\r\n]+)/m', $buf, $num_buf)) {
1968
                                                if (preg_match('/^buildnumber="?([^"\r\n]+)/m', $buf, $num_buf)) {
1908
                                                    $distr2.='-'.$num_buf[1];
1969
                                                    $distr2.='-'.$num_buf[1];
1909
                                                }
1970
                                                }
1910
                                                if (preg_match('/^builddate="?([^"\r\n]+)/m', $buf, $dat_buf)) {
1971
                                                if (preg_match('/^builddate="?([^"\r\n]+)/m', $buf, $dat_buf)) {
1911
                                                    $distr2.=' ('.$dat_buf[1].')';
1972
                                                    $distr2.=' ('.$dat_buf[1].')';
1912
                                                }
1973
                                                }
1913
                                                $this->sys->setDistribution($this->sys->getDistribution()." ".$distr2);
1974
                                                $this->sys->setDistribution($this->sys->getDistribution()." ".$distr2);
1914
                                            } else {
1975
                                            } else {
1915
                                                $distr2=trim(substr($buf, 0, strpos($buf, "\n")));
1976
                                                $distr2=trim(substr($buf, 0, strpos($buf, "\n")));
1916
                                                if (($distr2 !== null) && ($distr2 != "")) {
1977
                                                if (($distr2 !== null) && ($distr2 != "")) {
1917
                                                    $this->sys->setDistribution($this->sys->getDistribution()." ".$distr2);
1978
                                                    $this->sys->setDistribution($this->sys->getDistribution()." ".$distr2);
1918
                                                }
1979
                                                }
1919
                                            }
1980
                                            }
1920
                                            break;
1981
                                            break;
1921
                                        }
1982
                                        }
1922
                                    }
1983
                                    }
1923
                                }
1984
                                }
1924
                                break 2;
1985
                                break 2;
1925
                            }
1986
                            }
1926
                        }
1987
                        }
1927
                    }
1988
                    }
1928
                }
1989
                }
1929
            }
1990
            }
1930
            // if the distribution is still unknown
1991
            // if the distribution is still unknown
1931
            if ($this->sys->getDistribution() == "Linux") {
1992
            if ($this->sys->getDistribution() == "Linux") {
1932
                if (CommonFunctions::fileexists($filename="/etc/DISTRO_SPECS")
1993
                if (CommonFunctions::fileexists($filename="/etc/DISTRO_SPECS")
1933
                   && CommonFunctions::rfts($filename, $buf, 0, 4096, false)
1994
                   && CommonFunctions::rfts($filename, $buf, 0, 4096, false)
1934
                   && preg_match('/^DISTRO_NAME=\'(.+)\'/m', $buf, $id_buf)) {
1995
                   && preg_match('/^DISTRO_NAME=\'(.+)\'/m', $buf, $id_buf)) {
1935
                    if (isset($list[trim($id_buf[1])]['Name'])) {
1996
                    if (isset($list[trim($id_buf[1])]['Name'])) {
1936
                        $dist = trim($list[trim($id_buf[1])]['Name']);
1997
                        $dist = trim($list[trim($id_buf[1])]['Name']);
1937
                    } else {
1998
                    } else {
1938
                        $dist = trim($id_buf[1]);
1999
                        $dist = trim($id_buf[1]);
1939
                    }
2000
                    }
1940
                    if (preg_match('/^DISTRO_VERSION=([^#\n\r]+)/m', $buf, $vers_buf)) {
2001
                    if (preg_match('/^DISTRO_VERSION=([^#\n\r]+)/m', $buf, $vers_buf)) {
1941
                        $this->sys->setDistribution(trim($dist." ".trim($vers_buf[1])));
2002
                        $this->sys->setDistribution(trim($dist." ".trim($vers_buf[1])));
1942
                    } else {
2003
                    } else {
1943
                        $this->sys->setDistribution($dist);
2004
                        $this->sys->setDistribution($dist);
1944
                    }
2005
                    }
1945
                    if (isset($list[trim($id_buf[1])]['Image'])) {
2006
                    if (isset($list[trim($id_buf[1])]['Image'])) {
1946
                        $this->sys->setDistributionIcon($list[trim($id_buf[1])]['Image']);
2007
                        $this->sys->setDistributionIcon($list[trim($id_buf[1])]['Image']);
1947
                    } else {
2008
                    } else {
1948
                        if (isset($list['Puppy']['Image'])) {
2009
                        if (isset($list['Puppy']['Image'])) {
1949
                            $this->sys->setDistributionIcon($list['Puppy']['Image']);
2010
                            $this->sys->setDistributionIcon($list['Puppy']['Image']);
1950
                        }
2011
                        }
1951
                    }
2012
                    }
1952
                } elseif ((CommonFunctions::fileexists($filename="/etc/distro-release")
2013
                } elseif ((CommonFunctions::fileexists($filename="/etc/distro-release")
1953
                        && CommonFunctions::rfts($filename, $buf, 1, 4096, false)
2014
                        && CommonFunctions::rfts($filename, $buf, 1, 4096, false)
1954
                        && ($buf !== null) && (trim($buf) != ""))
2015
                        && ($buf !== null) && (trim($buf) != ""))
1955
                    || (CommonFunctions::fileexists($filename="/etc/system-release")
2016
                    || (CommonFunctions::fileexists($filename="/etc/system-release")
1956
                        && CommonFunctions::rfts($filename, $buf, 1, 4096, false)
2017
                        && CommonFunctions::rfts($filename, $buf, 1, 4096, false)
1957
                        && ($buf !== null) && (trim($buf) != ""))) {
2018
                        && ($buf !== null) && (trim($buf) != ""))) {
1958
                    $this->sys->setDistribution(trim($buf));
2019
                    $this->sys->setDistribution(trim($buf));
1959
                    if (preg_match('/^(\S+)\s*/', preg_replace('/^Red\s+/', 'Red', $buf), $id_buf)
2020
                    if (preg_match('/^(\S+)\s*/', preg_replace('/^Red\s+/', 'Red', $buf), $id_buf)
1960
                        && isset($list[trim($id_buf[1])]['Image'])) {
2021
                        && isset($list[trim($id_buf[1])]['Image'])) {
1961
                            $this->sys->setDistributionIcon($list[trim($id_buf[1])]['Image']);
2022
                            $this->sys->setDistributionIcon($list[trim($id_buf[1])]['Image']);
1962
                    }
2023
                    }
1963
                } elseif (CommonFunctions::fileexists($filename="/etc/solydxk/info")
2024
                } elseif (CommonFunctions::fileexists($filename="/etc/solydxk/info")
1964
                   && CommonFunctions::rfts($filename, $buf, 0, 4096, false)
2025
                   && CommonFunctions::rfts($filename, $buf, 0, 4096, false)
1965
                   && preg_match('/^DISTRIB_ID="?([^"\r\n]+)/m', $buf, $id_buf)) {
2026
                   && preg_match('/^DISTRIB_ID="?([^"\r\n]+)/m', $buf, $id_buf)) {
1966
                    if (preg_match('/^DESCRIPTION="?([^"\r\n]+)/m', $buf, $desc_buf)
2027
                    if (preg_match('/^DESCRIPTION="?([^"\r\n]+)/m', $buf, $desc_buf)
1967
                       && (trim($desc_buf[1])!=trim($id_buf[1]))) {
2028
                       && (trim($desc_buf[1])!=trim($id_buf[1]))) {
1968
                        $this->sys->setDistribution(trim($desc_buf[1]));
2029
                        $this->sys->setDistribution(trim($desc_buf[1]));
1969
                    } else {
2030
                    } else {
1970
                        if (isset($list[trim($id_buf[1])]['Name'])) {
2031
                        if (isset($list[trim($id_buf[1])]['Name'])) {
1971
                            $this->sys->setDistribution(trim($list[trim($id_buf[1])]['Name']));
2032
                            $this->sys->setDistribution(trim($list[trim($id_buf[1])]['Name']));
1972
                        } else {
2033
                        } else {
1973
                            $this->sys->setDistribution(trim($id_buf[1]));
2034
                            $this->sys->setDistribution(trim($id_buf[1]));
1974
                        }
2035
                        }
1975
                        if (preg_match('/^RELEASE="?([^"\r\n]+)/m', $buf, $vers_buf)) {
2036
                        if (preg_match('/^RELEASE="?([^"\r\n]+)/m', $buf, $vers_buf)) {
1976
                            $this->sys->setDistribution($this->sys->getDistribution()." ".trim($vers_buf[1]));
2037
                            $this->sys->setDistribution($this->sys->getDistribution()." ".trim($vers_buf[1]));
1977
                        }
2038
                        }
1978
                        if (preg_match('/^CODENAME="?([^"\r\n]+)/m', $buf, $vers_buf)) {
2039
                        if (preg_match('/^CODENAME="?([^"\r\n]+)/m', $buf, $vers_buf)) {
1979
                            $this->sys->setDistribution($this->sys->getDistribution()." (".trim($vers_buf[1]).")");
2040
                            $this->sys->setDistribution($this->sys->getDistribution()." (".trim($vers_buf[1]).")");
1980
                        }
2041
                        }
1981
                    }
2042
                    }
1982
                    if (isset($list[trim($id_buf[1])]['Image'])) {
2043
                    if (isset($list[trim($id_buf[1])]['Image'])) {
1983
                        $this->sys->setDistributionIcon($list[trim($id_buf[1])]['Image']);
2044
                        $this->sys->setDistributionIcon($list[trim($id_buf[1])]['Image']);
1984
                    } else {
2045
                    } else {
1985
                        $this->sys->setDistributionIcon($list['SolydXK']['Image']);
2046
                        $this->sys->setDistributionIcon($list['SolydXK']['Image']);
1986
                    }
2047
                    }
1987
                } elseif (CommonFunctions::fileexists($filename="/etc/os-release")
2048
                } elseif (CommonFunctions::fileexists($filename="/etc/os-release")
1988
                   && CommonFunctions::rfts($filename, $buf, 0, 4096, false)
2049
                   && CommonFunctions::rfts($filename, $buf, 0, 4096, false)
1989
                   && (preg_match('/^TAILS_VERSION_ID="?([^"\r\n]+)/m', $buf, $tid_buf)
2050
                   && (preg_match('/^TAILS_VERSION_ID="?([^"\r\n]+)/m', $buf, $tid_buf)
1990
                   || preg_match('/^NAME=["\']?([^"\'\r\n]+)/m', $buf, $id_buf))) {
2051
                   || preg_match('/^NAME=["\']?([^"\'\r\n]+)/m', $buf, $id_buf))) {
1991
                    if (preg_match('/^TAILS_VERSION_ID="?([^"\r\n]+)/m', $buf, $tid_buf)) {
2052
                    if (preg_match('/^TAILS_VERSION_ID="?([^"\r\n]+)/m', $buf, $tid_buf)) {
1992
                        if (preg_match('/^TAILS_PRODUCT_NAME="?([^"\r\n]+)/m', $buf, $desc_buf)) {
2053
                        if (preg_match('/^TAILS_PRODUCT_NAME="?([^"\r\n]+)/m', $buf, $desc_buf)) {
1993
                            $this->sys->setDistribution(trim($desc_buf[1])." ".trim($tid_buf[1]));
2054
                            $this->sys->setDistribution(trim($desc_buf[1])." ".trim($tid_buf[1]));
1994
                        } else {
2055
                        } else {
1995
                            if (isset($list['Tails']['Name'])) {
2056
                            if (isset($list['Tails']['Name'])) {
1996
                                $this->sys->setDistribution(trim($list['Tails']['Name'])." ".trim($tid_buf[1]));
2057
                                $this->sys->setDistribution(trim($list['Tails']['Name'])." ".trim($tid_buf[1]));
1997
                            } else {
2058
                            } else {
1998
                                $this->sys->setDistribution('Tails'." ".trim($tid_buf[1]));
2059
                                $this->sys->setDistribution('Tails'." ".trim($tid_buf[1]));
1999
                            }
2060
                            }
2000
                        }
2061
                        }
2001
                        $this->sys->setDistributionIcon($list['Tails']['Image']);
2062
                        $this->sys->setDistributionIcon($list['Tails']['Image']);
2002
                    } else {
2063
                    } else {
2003
                        if (preg_match('/^PRETTY_NAME=["\']?([^"\'\r\n]+)/m', $buf, $desc_buf)
2064
                        if (preg_match('/^PRETTY_NAME=["\']?([^"\'\r\n]+)/m', $buf, $desc_buf)
2004
                           && !preg_match('/\$/', $desc_buf[1])) { // if is not defined by variable
2065
                           && !preg_match('/\$/', $desc_buf[1])) { // if is not defined by variable
2005
                            $this->sys->setDistribution(trim($desc_buf[1]));
2066
                            $this->sys->setDistribution(trim($desc_buf[1]));
2006
                        } else {
2067
                        } else {
2007
                            if (isset($list[trim($id_buf[1])]['Name'])) {
2068
                            if (isset($list[trim($id_buf[1])]['Name'])) {
2008
                                $this->sys->setDistribution(trim($list[trim($id_buf[1])]['Name']));
2069
                                $this->sys->setDistribution(trim($list[trim($id_buf[1])]['Name']));
2009
                            } else {
2070
                            } else {
2010
                                $this->sys->setDistribution(trim($id_buf[1]));
2071
                                $this->sys->setDistribution(trim($id_buf[1]));
2011
                            }
2072
                            }
2012
                            if (preg_match('/^VERSION=["\']?([^"\'\r\n]+)/m', $buf, $vers_buf)) {
2073
                            if (preg_match('/^VERSION=["\']?([^"\'\r\n]+)/m', $buf, $vers_buf)) {
2013
                                $this->sys->setDistribution($this->sys->getDistribution()." ".trim($vers_buf[1]));
2074
                                $this->sys->setDistribution($this->sys->getDistribution()." ".trim($vers_buf[1]));
2014
                            } elseif (preg_match('/^VERSION_ID=["\']?([^"\'\r\n]+)/m', $buf, $vers_buf)) {
2075
                            } elseif (preg_match('/^VERSION_ID=["\']?([^"\'\r\n]+)/m', $buf, $vers_buf)) {
2015
                                $this->sys->setDistribution($this->sys->getDistribution()." ".trim($vers_buf[1]));
2076
                                $this->sys->setDistribution($this->sys->getDistribution()." ".trim($vers_buf[1]));
2016
                            }
2077
                            }
2017
                        }
2078
                        }
2018
                        if (isset($list[trim($id_buf[1])]['Image'])) {
2079
                        if (isset($list[trim($id_buf[1])]['Image'])) {
2019
                            $this->sys->setDistributionIcon($list[trim($id_buf[1])]['Image']);
2080
                            $this->sys->setDistributionIcon($list[trim($id_buf[1])]['Image']);
2020
                        }
2081
                        }
2021
                    }
2082
                    }
2022
                } elseif (CommonFunctions::fileexists($filename="/etc/debian_version")) {
2083
                } elseif (CommonFunctions::fileexists($filename="/etc/debian_version")) {
2023
                    if (!CommonFunctions::rfts($filename, $buf, 1, 4096, false)) {
2084
                    if (!CommonFunctions::rfts($filename, $buf, 1, 4096, false)) {
2024
                        $buf = "";
2085
                        $buf = "";
2025
                    }
2086
                    }
2026
                    if (isset($list['Debian']['Image'])) {
2087
                    if (isset($list['Debian']['Image'])) {
2027
                        $this->sys->setDistributionIcon($list['Debian']['Image']);
2088
                        $this->sys->setDistributionIcon($list['Debian']['Image']);
2028
                    }
2089
                    }
2029
                    if (isset($list['Debian']['Name'])) {
2090
                    if (isset($list['Debian']['Name'])) {
2030
                        if (($buf === null) || (trim($buf) == "")) {
2091
                        if (($buf === null) || (trim($buf) == "")) {
2031
                            $this->sys->setDistribution($list['Debian']['Name']);
2092
                            $this->sys->setDistribution($list['Debian']['Name']);
2032
                        } else {
2093
                        } else {
2033
                            $this->sys->setDistribution($list['Debian']['Name']." ".trim($buf));
2094
                            $this->sys->setDistribution($list['Debian']['Name']." ".trim($buf));
2034
                        }
2095
                        }
2035
                    } else {
2096
                    } else {
2036
                        if (($buf === null) || (trim($buf) == "")) {
2097
                        if (($buf === null) || (trim($buf) == "")) {
2037
                            $this->sys->setDistribution('Debian');
2098
                            $this->sys->setDistribution('Debian');
2038
                        } else {
2099
                        } else {
-
 
2100
                            $this->sys->setDistribution(trim($buf));
-
 
2101
                        }
-
 
2102
                    }
-
 
2103
                } elseif (CommonFunctions::fileexists($filename="/etc/slackware-version")) {
-
 
2104
                    if (!CommonFunctions::rfts($filename, $buf, 1, 4096, false)) {
-
 
2105
                        $buf = "";
-
 
2106
                    }
-
 
2107
                    if (isset($list['Slackware']['Image'])) {
-
 
2108
                        $this->sys->setDistributionIcon($list['Slackware']['Image']);
-
 
2109
                    }
-
 
2110
                    if (isset($list['Slackware']['Name'])) {
-
 
2111
                        if (($buf === null) || (trim($buf) == "")) {
-
 
2112
                            $this->sys->setDistribution($list['Slackware']['Name']);
-
 
2113
                        } else {
-
 
2114
                            $this->sys->setDistribution($list['Slackware']['Name']." ".trim($buf));
-
 
2115
                        }
-
 
2116
                    } else {
-
 
2117
                        if (($buf === null) || (trim($buf) == "")) {
-
 
2118
                            $this->sys->setDistribution('Slackware');
-
 
2119
                        } else {
2039
                            $this->sys->setDistribution(trim($buf));
2120
                            $this->sys->setDistribution(trim($buf));
2040
                        }
2121
                        }
2041
                    }
2122
                    }
2042
                } elseif (CommonFunctions::fileexists($filename="/etc/config/uLinux.conf")
2123
                } elseif (CommonFunctions::fileexists($filename="/etc/config/uLinux.conf")
2043
                   && CommonFunctions::rfts($filename, $buf, 0, 4096, false)
2124
                   && CommonFunctions::rfts($filename, $buf, 0, 4096, false)
2044
                   && preg_match("/^Rsync\sModel\s*=\s*QNAP/m", $buf)
2125
                   && preg_match("/^Rsync\sModel\s*=\s*QNAP/m", $buf)
2045
                   && preg_match("/^Version\s*=\s*([\d\.]+)\r?\nBuild\sNumber\s*=\s*(\S+)/m", $buf, $ver_buf)) {
2126
                   && preg_match("/^Version\s*=\s*([\d\.]+)\r?\nBuild\sNumber\s*=\s*(\S+)/m", $buf, $ver_buf)) {
2046
                    $buf = $ver_buf[1]."-".$ver_buf[2];
2127
                    $buf = $ver_buf[1]."-".$ver_buf[2];
2047
                    if (isset($list['QTS']['Image'])) {
2128
                    if (isset($list['QTS']['Image'])) {
2048
                        $this->sys->setDistributionIcon($list['QTS']['Image']);
2129
                        $this->sys->setDistributionIcon($list['QTS']['Image']);
2049
                    }
2130
                    }
2050
                    if (isset($list['QTS']['Name'])) {
2131
                    if (isset($list['QTS']['Name'])) {
2051
                        $this->sys->setDistribution($list['QTS']['Name']." ".trim($buf));
2132
                        $this->sys->setDistribution($list['QTS']['Name']." ".trim($buf));
2052
                    } else {
2133
                    } else {
2053
                        $this->sys->setDistribution(trim($buf));
2134
                        $this->sys->setDistribution(trim($buf));
2054
                    }
2135
                    }
2055
                }
2136
                }
2056
            }
2137
            }
2057
            /* restore error level */
2138
            /* restore error level */
2058
            error_reporting($old_err_rep);
2139
            error_reporting($old_err_rep);
2059
            /* restore error handler */
2140
            /* restore error handler */
2060
            if (function_exists('errorHandlerPsi')) {
2141
            if (function_exists('errorHandlerPsi')) {
2061
                set_error_handler('errorHandlerPsi');
2142
                set_error_handler('errorHandlerPsi');
2062
            }
2143
            }
2063
        }
2144
        }
2064
    }
2145
    }
2065
 
2146
 
2066
    /**
2147
    /**
2067
     * Processes
2148
     * Processes
2068
     *
2149
     *
2069
     * @return void
2150
     * @return void
2070
     */
2151
     */
2071
    protected function _processes()
2152
    protected function _processes()
2072
    {
2153
    {
2073
        $process = CommonFunctions::findglob('/proc/*/status', GLOB_NOSORT);
2154
        $process = CommonFunctions::findglob('/proc/*/status', GLOB_NOSORT);
2074
        if (is_array($process) && (($total = count($process)) > 0)) {
2155
        if (is_array($process) && (($total = count($process)) > 0)) {
2075
            $processes['*'] = 0;
2156
            $processes['*'] = 0;
2076
            $buf = "";
2157
            $buf = "";
2077
            for ($i = 0; $i < $total; $i++) {
2158
            for ($i = 0; $i < $total; $i++) {
2078
                if (CommonFunctions::rfts($process[$i], $buf, 0, 4096, false)) {
2159
                if (CommonFunctions::rfts($process[$i], $buf, 0, 4096, false)) {
2079
                    $processes['*']++; // current total
2160
                    $processes['*']++; // current total
2080
                    if (preg_match('/^State:\s+(\w)/m', $buf, $state)) {
2161
                    if (preg_match('/^State:\s+(\w)/m', $buf, $state)) {
2081
                        if (isset($processes[$state[1]])) {
2162
                        if (isset($processes[$state[1]])) {
2082
                            $processes[$state[1]]++;
2163
                            $processes[$state[1]]++;
2083
                        } else {
2164
                        } else {
2084
                            $processes[$state[1]] = 1;
2165
                            $processes[$state[1]] = 1;
2085
                        }
2166
                        }
2086
                    }
2167
                    }
2087
                }
2168
                }
2088
            }
2169
            }
2089
            if (!($processes['*'] > 0)) {
2170
            if (!($processes['*'] > 0)) {
2090
                $processes['*'] = $processes[' '] = $total; // all unknown
2171
                $processes['*'] = $processes[' '] = $total; // all unknown
2091
            }
2172
            }
2092
            $this->sys->setProcesses($processes);
2173
            $this->sys->setProcesses($processes);
2093
        }
2174
        }
2094
    }
2175
    }
2095
 
2176
 
2096
    /**
2177
    /**
2097
     * get the information
2178
     * get the information
2098
     *
2179
     *
2099
     * @see PSI_Interface_OS::build()
2180
     * @see PSI_Interface_OS::build()
2100
     *
2181
     *
2101
     * @return void
2182
     * @return void
2102
     */
2183
     */
2103
    public function build()
2184
    public function build()
2104
    {
2185
    {
2105
        if (!$this->blockname || $this->blockname==='vitals') {
2186
        if (!$this->blockname || $this->blockname==='vitals') {
2106
            $this->_distro();
2187
            $this->_distro();
2107
            $this->_hostname();
2188
            $this->_hostname();
2108
            $this->_kernel();
2189
            $this->_kernel();
2109
            $this->_uptime();
2190
            $this->_uptime();
2110
            $this->_users();
2191
            $this->_users();
2111
            $this->_loadavg();
2192
            $this->_loadavg();
2112
            $this->_processes();
2193
            $this->_processes();
2113
        }
2194
        }
2114
        if (!$this->blockname || $this->blockname==='hardware') {
2195
        if (!$this->blockname || $this->blockname==='hardware') {
2115
            $this->_machine();
2196
            $this->_machine();
2116
            $this->_cpuinfo();
2197
            $this->_cpuinfo();
2117
            $this->_virtualizer();
2198
            $this->_virtualizer();
2118
            $this->_pci();
2199
            $this->_pci();
2119
            $this->_ide();
2200
            $this->_ide();
2120
            $this->_scsi();
2201
            $this->_scsi();
2121
            $this->_nvme();
2202
            $this->_nvme();
2122
            $this->_usb();
2203
            $this->_usb();
2123
            $this->_i2c();
2204
            $this->_i2c();
2124
        }
2205
        }
2125
        if (!$this->blockname || $this->blockname==='memory') {
2206
        if (!$this->blockname || $this->blockname==='memory') {
2126
            $this->_memory();
2207
            $this->_memory();
2127
        }
2208
        }
2128
        if (!$this->blockname || $this->blockname==='filesystem') {
2209
        if (!$this->blockname || $this->blockname==='filesystem') {
2129
            $this->_filesystems();
2210
            $this->_filesystems();
2130
        }
2211
        }
2131
        if (!$this->blockname || $this->blockname==='network') {
2212
        if (!$this->blockname || $this->blockname==='network') {
2132
            $this->_network();
2213
            $this->_network();
2133
        }
2214
        }
2134
    }
2215
    }
2135
}
2216
}
2136
 
2217