Subversion Repositories ALCASAR

Rev

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

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