Subversion Repositories ALCASAR

Rev

Rev 2976 | Rev 3100 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log

Rev 2976 Rev 3037
Line 25... Line 25...
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
    /**
Line 101... Line 277...
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);
Line 113... Line 289...
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
Line 174... Line 523...
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
    }
Line 208... Line 557...
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
        }
Line 221... Line 570...
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)) {
Line 293... Line 642...
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)) {
Line 316... Line 666...
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;
Line 338... Line 689...
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;
Line 359... Line 713...
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
 
Line 375... Line 729...
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);
Line 400... Line 755...
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);
Line 432... Line 787...
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) {
Line 453... Line 814...
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
Line 476... Line 843...
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)) {
Line 494... Line 861...
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)) {
Line 559... Line 929...
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) {
Line 627... Line 1006...
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 = "";
Line 715... Line 1094...
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);
Line 747... Line 1126...
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;
Line 790... Line 1169...
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++;
Line 815... Line 1194...
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
 
Line 899... Line 1277...
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();
Line 955... Line 1333...
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])) {
Line 1024... Line 1401...
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)
Line 1118... Line 1495...
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]);
Line 1263... Line 1645...
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]);
Line 1293... Line 1681...
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
    /**
Line 1317... Line 1712...
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) {
Line 1340... Line 1735...
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")
Line 1379... Line 1778...
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 */
Line 1409... Line 1822...
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]);
Line 1430... Line 1843...
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']);
Line 1468... Line 1881...
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
                                        }
Line 1536... Line 1949...
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']);
Line 1612... Line 2025...
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
                    }
Line 1655... Line 2068...
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();
Line 1699... Line 2112...
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
}