Subversion Repositories ALCASAR

Rev

Rev 3037 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log

Rev 3037 Rev 3100
1
<?php
1
<?php
2
/**
2
/**
3
 * BSDCommon Class
3
 * BSDCommon Class
4
 *
4
 *
5
 * PHP version 5
5
 * PHP version 5
6
 *
6
 *
7
 * @category  PHP
7
 * @category  PHP
8
 * @package   PSI BSDCommon OS class
8
 * @package   PSI BSDCommon OS class
9
 * @author    Michael Cramer <BigMichi1@users.sourceforge.net>
9
 * @author    Michael Cramer <BigMichi1@users.sourceforge.net>
10
 * @copyright 2009 phpSysInfo
10
 * @copyright 2009 phpSysInfo
11
 * @license   http://opensource.org/licenses/gpl-2.0.php GNU General Public License version 2, or (at your option) any later version
11
 * @license   http://opensource.org/licenses/gpl-2.0.php GNU General Public License version 2, or (at your option) any later version
12
 * @version   SVN: $Id: class.BSDCommon.inc.php 621 2012-07-29 18:49:04Z namiltd $
12
 * @version   SVN: $Id: class.BSDCommon.inc.php 621 2012-07-29 18:49:04Z namiltd $
13
 * @link      http://phpsysinfo.sourceforge.net
13
 * @link      http://phpsysinfo.sourceforge.net
14
 */
14
 */
15
 /**
15
 /**
16
 * BSDCommon class
16
 * BSDCommon class
17
 * get all the required information for BSD Like systems
17
 * get all the required information for BSD Like systems
18
 * no need to implement in every class the same methods
18
 * no need to implement in every class the same methods
19
 *
19
 *
20
 * @category  PHP
20
 * @category  PHP
21
 * @package   PSI BSDCommon OS class
21
 * @package   PSI BSDCommon OS class
22
 * @author    Michael Cramer <BigMichi1@users.sourceforge.net>
22
 * @author    Michael Cramer <BigMichi1@users.sourceforge.net>
23
 * @copyright 2009 phpSysInfo
23
 * @copyright 2009 phpSysInfo
24
 * @license   http://opensource.org/licenses/gpl-2.0.php GNU General Public License version 2, or (at your option) any later version
24
 * @license   http://opensource.org/licenses/gpl-2.0.php GNU General Public License version 2, or (at your option) any later version
25
 * @version   Release: 3.0
25
 * @version   Release: 3.0
26
 * @link      http://phpsysinfo.sourceforge.net
26
 * @link      http://phpsysinfo.sourceforge.net
27
 */
27
 */
28
abstract class BSDCommon extends OS
28
abstract class BSDCommon extends OS
29
{
29
{
30
    /**
30
    /**
31
     * Assoc array of all CPUs loads.
31
     * Assoc array of all CPUs loads.
32
     */
32
     */
33
    private $_cpu_loads = null;
33
    private $_cpu_loads = null;
34
 
34
 
35
    /**
35
    /**
36
     * content of the syslog
36
     * content of the syslog
37
     *
37
     *
38
     * @var array
38
     * @var array
39
     */
39
     */
40
    private $_dmesg = null;
40
    private $_dmesg = null;
41
 
41
 
42
    /**
42
    /**
43
     * regexp1 for cpu information out of the syslog
43
     * regexp1 for cpu information out of the syslog
44
     *
44
     *
45
     * @var string
45
     * @var string
46
     */
46
     */
47
    private $_CPURegExp1 = "//";
47
    private $_CPURegExp1 = "//";
48
 
48
 
49
    /**
49
    /**
50
     * regexp2 for cpu information out of the syslog
50
     * regexp2 for cpu information out of the syslog
51
     *
51
     *
52
     * @var string
52
     * @var string
53
     */
53
     */
54
    private $_CPURegExp2 = "//";
54
    private $_CPURegExp2 = "//";
55
 
55
 
56
    /**
56
    /**
57
     * regexp1 for scsi information out of the syslog
57
     * regexp1 for scsi information out of the syslog
58
     *
58
     *
59
     * @var string
59
     * @var string
60
     */
60
     */
61
    private $_SCSIRegExp1 = "//";
61
    private $_SCSIRegExp1 = "//";
62
 
62
 
63
    /**
63
    /**
64
     * regexp2 for scsi information out of the syslog
64
     * regexp2 for scsi information out of the syslog
65
     *
65
     *
66
     * @var string
66
     * @var string
67
     */
67
     */
68
    private $_SCSIRegExp2 = "//";
68
    private $_SCSIRegExp2 = "//";
69
 
69
 
70
    /**
70
    /**
71
     * regexp3 for scsi information out of the syslog
71
     * regexp3 for scsi information out of the syslog
72
     *
72
     *
73
     * @var string
73
     * @var string
74
     */
74
     */
75
    private $_SCSIRegExp3 = "//";
75
    private $_SCSIRegExp3 = "//";
76
 
76
 
77
    /**
77
    /**
78
     * regexp1 for pci information out of the syslog
78
     * regexp1 for pci information out of the syslog
79
     *
79
     *
80
     * @var string
80
     * @var string
81
     */
81
     */
82
    private $_PCIRegExp1 = "//";
82
    private $_PCIRegExp1 = "//";
83
 
83
 
84
    /**
84
    /**
85
     * regexp1 for pci information out of the syslog
85
     * regexp1 for pci information out of the syslog
86
     *
86
     *
87
     * @var string
87
     * @var string
88
     */
88
     */
89
    private $_PCIRegExp2 = "//";
89
    private $_PCIRegExp2 = "//";
90
 
90
 
91
    /**
91
    /**
92
     * setter for cpuregexp1
92
     * setter for cpuregexp1
93
     *
93
     *
94
     * @param string $value value to set
94
     * @param string $value value to set
95
     *
95
     *
96
     * @return void
96
     * @return void
97
     */
97
     */
98
    protected function setCPURegExp1($value)
98
    protected function setCPURegExp1($value)
99
    {
99
    {
100
        $this->_CPURegExp1 = $value;
100
        $this->_CPURegExp1 = $value;
101
    }
101
    }
102
 
102
 
103
    /**
103
    /**
104
     * setter for cpuregexp2
104
     * setter for cpuregexp2
105
     *
105
     *
106
     * @param string $value value to set
106
     * @param string $value value to set
107
     *
107
     *
108
     * @return void
108
     * @return void
109
     */
109
     */
110
    protected function setCPURegExp2($value)
110
    protected function setCPURegExp2($value)
111
    {
111
    {
112
        $this->_CPURegExp2 = $value;
112
        $this->_CPURegExp2 = $value;
113
    }
113
    }
114
 
114
 
115
    /**
115
    /**
116
     * setter for scsiregexp1
116
     * setter for scsiregexp1
117
     *
117
     *
118
     * @param string $value value to set
118
     * @param string $value value to set
119
     *
119
     *
120
     * @return void
120
     * @return void
121
     */
121
     */
122
    protected function setSCSIRegExp1($value)
122
    protected function setSCSIRegExp1($value)
123
    {
123
    {
124
        $this->_SCSIRegExp1 = $value;
124
        $this->_SCSIRegExp1 = $value;
125
    }
125
    }
126
 
126
 
127
    /**
127
    /**
128
     * setter for scsiregexp2
128
     * setter for scsiregexp2
129
     *
129
     *
130
     * @param string $value value to set
130
     * @param string $value value to set
131
     *
131
     *
132
     * @return void
132
     * @return void
133
     */
133
     */
134
    protected function setSCSIRegExp2($value)
134
    protected function setSCSIRegExp2($value)
135
    {
135
    {
136
        $this->_SCSIRegExp2 = $value;
136
        $this->_SCSIRegExp2 = $value;
137
    }
137
    }
138
 
138
 
139
    /**
139
    /**
140
     * setter for scsiregexp3
140
     * setter for scsiregexp3
141
     *
141
     *
142
     * @param string $value value to set
142
     * @param string $value value to set
143
     *
143
     *
144
     * @return void
144
     * @return void
145
     */
145
     */
146
    protected function setSCSIRegExp3($value)
146
    protected function setSCSIRegExp3($value)
147
    {
147
    {
148
        $this->_SCSIRegExp3 = $value;
148
        $this->_SCSIRegExp3 = $value;
149
    }
149
    }
150
 
150
 
151
    /**
151
    /**
152
     * setter for pciregexp1
152
     * setter for pciregexp1
153
     *
153
     *
154
     * @param string $value value to set
154
     * @param string $value value to set
155
     *
155
     *
156
     * @return void
156
     * @return void
157
     */
157
     */
158
    protected function setPCIRegExp1($value)
158
    protected function setPCIRegExp1($value)
159
    {
159
    {
160
        $this->_PCIRegExp1 = $value;
160
        $this->_PCIRegExp1 = $value;
161
    }
161
    }
162
 
162
 
163
    /**
163
    /**
164
     * setter for pciregexp2
164
     * setter for pciregexp2
165
     *
165
     *
166
     * @param string $value value to set
166
     * @param string $value value to set
167
     *
167
     *
168
     * @return void
168
     * @return void
169
     */
169
     */
170
    protected function setPCIRegExp2($value)
170
    protected function setPCIRegExp2($value)
171
    {
171
    {
172
        $this->_PCIRegExp2 = $value;
172
        $this->_PCIRegExp2 = $value;
173
    }
173
    }
174
 
174
 
175
    /**
175
    /**
176
     * read /var/run/dmesg.boot, but only if we haven't already
176
     * read /var/run/dmesg.boot, but only if we haven't already
177
     *
177
     *
178
     * @return array
178
     * @return array
179
     */
179
     */
180
    protected function readdmesg()
180
    protected function readdmesg()
181
    {
181
    {
182
        if ($this->_dmesg === null) {
182
        if ($this->_dmesg === null) {
183
            if ((PSI_OS != 'Darwin') && (CommonFunctions::rfts('/var/run/dmesg.boot', $buf, 0, 4096, false) || CommonFunctions::rfts('/var/log/dmesg.boot', $buf, 0, 4096, false) || CommonFunctions::rfts('/var/run/dmesg.boot', $buf))) {  // Once again but with debug
183
            if ((PSI_OS != 'Darwin') && (CommonFunctions::rfts('/var/run/dmesg.boot', $buf, 0, 4096, false) || CommonFunctions::rfts('/var/log/dmesg.boot', $buf, 0, 4096, false) || CommonFunctions::rfts('/var/run/dmesg.boot', $buf))) {  // Once again but with debug
184
                $parts = preg_split("/rebooting|Uptime/", $buf, -1, PREG_SPLIT_NO_EMPTY);
184
                $parts = preg_split("/rebooting|Uptime/", $buf, -1, PREG_SPLIT_NO_EMPTY);
185
                $this->_dmesg = preg_split("/\n/", $parts[count($parts) - 1], -1, PREG_SPLIT_NO_EMPTY);
185
                $this->_dmesg = preg_split("/\n/", $parts[count($parts) - 1], -1, PREG_SPLIT_NO_EMPTY);
186
            } else {
186
            } else {
187
                $this->_dmesg = array();
187
                $this->_dmesg = array();
188
            }
188
            }
189
        }
189
        }
190
 
190
 
191
        return $this->_dmesg;
191
        return $this->_dmesg;
192
    }
192
    }
193
 
193
 
194
    /**
194
    /**
195
     * get a value from sysctl command
195
     * get a value from sysctl command
196
     *
196
     *
197
     * @param string $key key for the value to get
197
     * @param string $key key for the value to get
198
     *
198
     *
199
     * @return string
199
     * @return string
200
     */
200
     */
201
    protected function grabkey($key)
201
    protected function grabkey($key)
202
    {
202
    {
203
        $buf = "";
203
        $buf = "";
204
        if (CommonFunctions::executeProgram('sysctl', "-n $key", $buf, PSI_DEBUG)) {
204
        if (CommonFunctions::executeProgram('sysctl', "-n $key", $buf, PSI_DEBUG)) {
205
            return $buf;
205
            return $buf;
206
        } else {
206
        } else {
207
            return '';
207
            return '';
208
        }
208
        }
209
    }
209
    }
210
 
210
 
211
    /**
211
    /**
212
     * Virtual Host Name
212
     * Virtual Host Name
213
     *
213
     *
214
     * @return void
214
     * @return void
215
     */
215
     */
216
    protected function hostname()
216
    protected function hostname()
217
    {
217
    {
218
        if (PSI_USE_VHOST) {
218
        if (PSI_USE_VHOST) {
219
            if (CommonFunctions::readenv('SERVER_NAME', $hnm)) $this->sys->setHostname($hnm);
219
            if (CommonFunctions::readenv('SERVER_NAME', $hnm)) $this->sys->setHostname($hnm);
220
        } else {
220
        } else {
221
            if (CommonFunctions::executeProgram('hostname', '', $buf, PSI_DEBUG)) {
221
            if (CommonFunctions::executeProgram('hostname', '', $buf, PSI_DEBUG)) {
222
                $this->sys->setHostname($buf);
222
                $this->sys->setHostname($buf);
223
            }
223
            }
224
        }
224
        }
225
    }
225
    }
226
 
226
 
227
    /**
227
    /**
228
     * Kernel Version
228
     * Kernel Version
229
     *
229
     *
230
     * @return void
230
     * @return void
231
     */
231
     */
232
    protected function kernel()
232
    protected function kernel()
233
    {
233
    {
234
        $s = $this->grabkey('kern.version');
234
        $s = $this->grabkey('kern.version');
235
        $a = preg_split('/:/', $s);
235
        $a = preg_split('/:/', $s, 4);
236
        if (isset($a[2])) {
236
        if (isset($a[3])) {
-
 
237
            if (preg_match('/^(\d{2} [A-Z]{3});/', $a[3], $abuf) // eg. 19:58 GMT;...
-
 
238
               || preg_match('/^(\d{2} [A-Z]{3} \d{4})/', $a[3], $abuf)) { // eg. 26:31 PDT 2019...
-
 
239
                $this->sys->setKernel($a[0].$a[1].':'.$a[2].':'.$abuf[1]);
-
 
240
            } else {
-
 
241
                $this->sys->setKernel($a[0].$a[1].':'.$a[2]);
-
 
242
            }
-
 
243
        } elseif (isset($a[2])) {
237
            $this->sys->setKernel($a[0].$a[1].':'.$a[2]);
244
            $this->sys->setKernel($a[0].$a[1].':'.$a[2]);
238
        } else {
245
        } else {
239
            $this->sys->setKernel($s);
246
            $this->sys->setKernel($s);
240
        }
247
        }
241
    }
248
    }
242
 
249
 
243
    /**
250
    /**
244
     * Virtualizer info
251
     * Virtualizer info
245
     *
252
     *
246
     * @return void
253
     * @return void
247
     */
254
     */
248
    private function virtualizer()
255
    private function virtualizer()
249
    {
256
    {
250
        if (defined('PSI_SHOW_VIRTUALIZER_INFO') && PSI_SHOW_VIRTUALIZER_INFO) {
257
        if (defined('PSI_SHOW_VIRTUALIZER_INFO') && PSI_SHOW_VIRTUALIZER_INFO) {
251
            $testvirt = $this->sys->getVirtualizer();
258
            $testvirt = $this->sys->getVirtualizer();
252
            $novm = true;
259
            $novm = true;
253
            foreach ($testvirt as $virtkey=>$virtvalue) if ($virtvalue) {
260
            foreach ($testvirt as $virtkey=>$virtvalue) if ($virtvalue) {
254
                $novm = false;
261
                $novm = false;
255
                break;
262
                break;
256
            }
263
            }
257
            // Detect QEMU cpu
264
            // Detect QEMU cpu
258
            if ($novm && isset($testvirt["cpuid:QEMU"])) {
265
            if ($novm && isset($testvirt["cpuid:QEMU"])) {
259
                $this->sys->setVirtualizer('qemu'); // QEMU
266
                $this->sys->setVirtualizer('qemu'); // QEMU
260
                $novm = false;
267
                $novm = false;
261
            }
268
            }
262
 
269
 
263
            if ($novm && isset($testvirt["hypervisor"])) {
270
            if ($novm && isset($testvirt["hypervisor"])) {
264
                $this->sys->setVirtualizer('unknown');
271
                $this->sys->setVirtualizer('unknown');
265
            }
272
            }
266
        }
273
        }
267
    }
274
    }
268
 
275
 
269
    /**
276
    /**
270
     * CPU usage
277
     * CPU usage
271
     *
278
     *
272
     * @return void
279
     * @return void
273
     */
280
     */
274
    protected function cpuusage()
281
    protected function cpuusage()
275
    {
282
    {
276
        if (($this->_cpu_loads === null)) {
283
        if (($this->_cpu_loads === null)) {
277
            $this->_cpu_loads = array();
284
            $this->_cpu_loads = array();
278
            if (PSI_OS != 'Darwin') {
285
            if (PSI_OS != 'Darwin') {
279
                if ($fd = $this->grabkey('kern.cp_time')) {
286
                if ($fd = $this->grabkey('kern.cp_time')) {
280
                    // Find out the CPU load
287
                    // Find out the CPU load
281
                    // user + sys = load
288
                    // user + sys = load
282
                    // total = total
289
                    // total = total
283
                    if (preg_match($this->_CPURegExp2, $fd, $res) && (sizeof($res) > 4)) {
290
                    if (preg_match($this->_CPURegExp2, $fd, $res) && (sizeof($res) > 4)) {
284
                        $load = $res[2] + $res[3] + $res[4]; // cpu.user + cpu.sys
291
                        $load = $res[2] + $res[3] + $res[4]; // cpu.user + cpu.sys
285
                        $total = $res[2] + $res[3] + $res[4] + $res[5]; // cpu.total
292
                        $total = $res[2] + $res[3] + $res[4] + $res[5]; // cpu.total
286
                        // we need a second value, wait 1 second befor getting (< 1 second no good value will occour)
293
                        // we need a second value, wait 1 second befor getting (< 1 second no good value will occour)
287
                        sleep(1);
294
                        sleep(1);
288
                        $fd = $this->grabkey('kern.cp_time');
295
                        $fd = $this->grabkey('kern.cp_time');
289
                        if (preg_match($this->_CPURegExp2, $fd, $res) && (sizeof($res) > 4)) {
296
                        if (preg_match($this->_CPURegExp2, $fd, $res) && (sizeof($res) > 4)) {
290
                            $load2 = $res[2] + $res[3] + $res[4];
297
                            $load2 = $res[2] + $res[3] + $res[4];
291
                            $total2 = $res[2] + $res[3] + $res[4] + $res[5];
298
                            $total2 = $res[2] + $res[3] + $res[4] + $res[5];
292
                            if ($total2 != $total) {
299
                            if ($total2 != $total) {
293
                                $this->_cpu_loads['cpu'] = (100 * ($load2 - $load)) / ($total2 - $total);
300
                                $this->_cpu_loads['cpu'] = (100 * ($load2 - $load)) / ($total2 - $total);
294
                            } else {
301
                            } else {
295
                                $this->_cpu_loads['cpu'] = 0;
302
                                $this->_cpu_loads['cpu'] = 0;
296
                            }
303
                            }
297
                        }
304
                        }
298
                    }
305
                    }
299
                }
306
                }
300
            } else {
307
            } else {
301
                $ncpu = $this->grabkey('hw.ncpu');
308
                $ncpu = $this->grabkey('hw.ncpu');
302
                if (($ncpu !== "") && ($ncpu >= 1) && CommonFunctions::executeProgram('ps', "-A -o %cpu", $pstable, false) && !empty($pstable)) {
309
                if (($ncpu !== "") && ($ncpu >= 1) && CommonFunctions::executeProgram('ps', "-A -o %cpu", $pstable, false) && !empty($pstable)) {
303
                    $pslines = preg_split("/\n/", $pstable, -1, PREG_SPLIT_NO_EMPTY);
310
                    $pslines = preg_split("/\n/", $pstable, -1, PREG_SPLIT_NO_EMPTY);
304
                    if (!empty($pslines) && (count($pslines)>1) && (trim($pslines[0])==="%CPU")) {
311
                    if (!empty($pslines) && (count($pslines)>1) && (trim($pslines[0])==="%CPU")) {
305
                        array_shift($pslines);
312
                        array_shift($pslines);
306
                        $sum = 0;
313
                        $sum = 0;
307
                        foreach ($pslines as $psline) {
314
                        foreach ($pslines as $psline) {
308
                            $sum+=trim($psline);
315
                            $sum+=str_replace(',', '.', trim($psline));
309
                        }
316
                        }
310
                        $this->_cpu_loads['cpu'] = min($sum/$ncpu, 100);
317
                        $this->_cpu_loads['cpu'] = min($sum/$ncpu, 100);
311
                    }
318
                    }
312
                }
319
                }
313
            }
320
            }
314
        }
321
        }
315
 
322
 
316
        if (isset($this->_cpu_loads['cpu'])) {
323
        if (isset($this->_cpu_loads['cpu'])) {
317
            return $this->_cpu_loads['cpu'];
324
            return $this->_cpu_loads['cpu'];
318
        } else {
325
        } else {
319
            return null;
326
            return null;
320
        }
327
        }
321
    }
328
    }
322
 
329
 
323
    /**
330
    /**
324
     * Processor Load
331
     * Processor Load
325
     * optionally create a loadbar
332
     * optionally create a loadbar
326
     *
333
     *
327
     * @return void
334
     * @return void
328
     */
335
     */
329
    protected function loadavg()
336
    protected function loadavg()
330
    {
337
    {
331
        $s = $this->grabkey('vm.loadavg');
338
        $s = $this->grabkey('vm.loadavg');
332
        $s = preg_replace('/{ /', '', $s);
339
        $s = preg_replace('/{ /', '', $s);
333
        $s = preg_replace('/ }/', '', $s);
340
        $s = preg_replace('/ }/', '', $s);
-
 
341
        $s = str_replace(',', '.', $s);
334
        $this->sys->setLoad($s);
342
        $this->sys->setLoad($s);
335
 
343
 
336
        if (PSI_LOAD_BAR) {
344
        if (PSI_LOAD_BAR) {
337
            $this->sys->setLoadPercent($this->cpuusage());
345
            $this->sys->setLoadPercent($this->cpuusage());
338
        }
346
        }
339
    }
347
    }
340
 
348
 
341
    /**
349
    /**
342
     * CPU information
350
     * CPU information
343
     *
351
     *
344
     * @return void
352
     * @return void
345
     */
353
     */
346
    protected function cpuinfo()
354
    protected function cpuinfo()
347
    {
355
    {
348
        $dev = new CpuDevice();
356
        $dev = new CpuDevice();
349
        $cpumodel = $this->grabkey('hw.model');
357
        $cpumodel = $this->grabkey('hw.model');
350
        $dev->setModel($cpumodel);
358
        $dev->setModel($cpumodel);
351
        if (defined('PSI_SHOW_VIRTUALIZER_INFO') && PSI_SHOW_VIRTUALIZER_INFO && preg_match('/^QEMU Virtual CPU version /', $cpumodel)) {
359
        if (defined('PSI_SHOW_VIRTUALIZER_INFO') && PSI_SHOW_VIRTUALIZER_INFO && preg_match('/^QEMU Virtual CPU version /', $cpumodel)) {
352
            $this->sys->setVirtualizer("cpuid:QEMU", false);
360
            $this->sys->setVirtualizer("cpuid:QEMU", false);
353
        }
361
        }
354
 
362
 
355
        $notwas = true;
363
        $notwas = true;
356
        foreach ($this->readdmesg() as $line) {
364
        foreach ($this->readdmesg() as $line) {
357
            if ($notwas) {
365
            if ($notwas) {
358
               $regexps = preg_split("/\n/", $this->_CPURegExp1, -1, PREG_SPLIT_NO_EMPTY); // multiple regexp separated by \n
366
               $regexps = preg_split("/\n/", $this->_CPURegExp1, -1, PREG_SPLIT_NO_EMPTY); // multiple regexp separated by \n
359
               foreach ($regexps as $regexp) {
367
               foreach ($regexps as $regexp) {
360
                   if (preg_match($regexp, $line, $ar_buf) && (sizeof($ar_buf) > 2)) {
368
                   if (preg_match($regexp, $line, $ar_buf) && (sizeof($ar_buf) > 2)) {
361
                        if ($dev->getCpuSpeed() === 0) {
369
                        if ($dev->getCpuSpeed() == 0) {
362
                            $dev->setCpuSpeed(round($ar_buf[2]));
370
                            $dev->setCpuSpeed(round($ar_buf[2]));
363
                        }
371
                        }
364
                        $notwas = false;
372
                        $notwas = false;
365
                        break;
373
                        break;
366
                    }
374
                    }
367
                }
375
                }
368
            } else {
376
            } else {
369
                if (preg_match("/^\s+Origin| Features/", $line, $ar_buf)) {
377
                if (preg_match("/^\s+Origin| Features/", $line, $ar_buf)) {
370
                    if (preg_match("/^\s+Origin[ ]*=[ ]*\"(.+)\"/", $line, $ar_buf)) {
378
                    if (preg_match("/^\s+Origin[ ]*=[ ]*\"(.+)\"/", $line, $ar_buf)) {
371
                        $dev->setVendorId($ar_buf[1]);
379
                        $dev->setVendorId($ar_buf[1]);
372
                    } elseif (preg_match("/ Features2[ ]*=.*<(.+)>/", $line, $ar_buf)) {
380
                    } elseif (preg_match("/ Features2[ ]*=.*<(.+)>/", $line, $ar_buf)) {
373
                        $feats = preg_split("/,/", strtolower(trim($ar_buf[1])), -1, PREG_SPLIT_NO_EMPTY);
381
                        $feats = preg_split("/,/", strtolower(trim($ar_buf[1])), -1, PREG_SPLIT_NO_EMPTY);
374
                        foreach ($feats as $feat) {
382
                        foreach ($feats as $feat) {
375
                            if (($feat=="vmx") || ($feat=="svm")) {
383
                            if (($feat=="vmx") || ($feat=="svm")) {
376
                                $dev->setVirt($feat);
384
                                $dev->setVirt($feat);
377
                            } elseif ($feat=="hv") {
385
                            } elseif ($feat=="hv") {
378
                                if ($dev->getVirt() === null) {
386
                                if ($dev->getVirt() === null) {
379
                                    $dev->setVirt('hypervisor');
387
                                    $dev->setVirt('hypervisor');
380
                                }
388
                                }
381
                                if (defined('PSI_SHOW_VIRTUALIZER_INFO') && PSI_SHOW_VIRTUALIZER_INFO) {
389
                                if (defined('PSI_SHOW_VIRTUALIZER_INFO') && PSI_SHOW_VIRTUALIZER_INFO) {
382
                                    $this->sys->setVirtualizer("hypervisor", false);
390
                                    $this->sys->setVirtualizer("hypervisor", false);
383
                                }
391
                                }
384
                            }
392
                            }
385
                        }
393
                        }
386
                    }
394
                    }
387
                } else break;
395
                } else break;
388
            }
396
            }
389
        }
397
        }
390
 
398
 
391
        $ncpu = $this->grabkey('hw.ncpu');
399
        $ncpu = $this->grabkey('hw.ncpu');
392
        if (($ncpu === "") || !($ncpu >= 1)) {
400
        if (($ncpu === "") || !($ncpu >= 1)) {
393
            $ncpu = 1;
401
            $ncpu = 1;
394
        }
402
        }
395
        if (($ncpu == 1) && PSI_LOAD_BAR) {
403
        if (($ncpu == 1) && PSI_LOAD_BAR) {
396
            $dev->setLoad($this->cpuusage());
404
            $dev->setLoad($this->cpuusage());
397
        }
405
        }
398
        for ($ncpu ; $ncpu > 0 ; $ncpu--) {
406
        for ($ncpu ; $ncpu > 0 ; $ncpu--) {
399
            $this->sys->setCpus($dev);
407
            $this->sys->setCpus($dev);
400
        }
408
        }
401
    }
409
    }
402
 
410
 
403
    /**
411
    /**
404
     * Machine information
412
     * Machine information
405
     *
413
     *
406
     * @return void
414
     * @return void
407
     */
415
     */
408
    private function machine()
416
    private function machine()
409
    {
417
    {
410
        if ((PSI_OS == 'NetBSD') || (PSI_OS == 'OpenBSD')) {
418
        if ((PSI_OS == 'NetBSD') || (PSI_OS == 'OpenBSD')) {
411
            $buffer = array();
419
            $buffer = array();
412
            if (PSI_OS == 'NetBSD') { // NetBSD
420
            if (PSI_OS == 'NetBSD') { // NetBSD
413
                $buffer['Manufacturer'] = $this->grabkey('machdep.dmi.system-vendor');
421
                $buffer['Manufacturer'] = $this->grabkey('machdep.dmi.system-vendor');
414
                $buffer['Model'] = $this->grabkey('machdep.dmi.system-product');
422
                $buffer['Model'] = $this->grabkey('machdep.dmi.system-product');
415
                $buffer['Product'] = $this->grabkey('machdep.dmi.board-product');
423
                $buffer['Product'] = $this->grabkey('machdep.dmi.board-product');
416
                $buffer['SMBIOSBIOSVersion'] = $this->grabkey('machdep.dmi.bios-version');
424
                $buffer['SMBIOSBIOSVersion'] = $this->grabkey('machdep.dmi.bios-version');
417
                $buffer['ReleaseDate'] = $this->grabkey('machdep.dmi.bios-date');
425
                $buffer['ReleaseDate'] = $this->grabkey('machdep.dmi.bios-date');
418
            } else { // OpenBSD
426
            } else { // OpenBSD
419
                $buffer['Manufacturer'] = $this->grabkey('hw.vendor');
427
                $buffer['Manufacturer'] = $this->grabkey('hw.vendor');
420
                $buffer['Model'] = $this->grabkey('hw.product');
428
                $buffer['Model'] = $this->grabkey('hw.product');
421
                $buffer['Product'] = "";
429
                $buffer['Product'] = "";
422
                $buffer['SMBIOSBIOSVersion'] = "";
430
                $buffer['SMBIOSBIOSVersion'] = "";
423
                $buffer['ReleaseDate'] = "";
431
                $buffer['ReleaseDate'] = "";
424
            }
432
            }
425
            if (defined('PSI_SHOW_VIRTUALIZER_INFO') && PSI_SHOW_VIRTUALIZER_INFO) {
433
            if (defined('PSI_SHOW_VIRTUALIZER_INFO') && PSI_SHOW_VIRTUALIZER_INFO) {
426
                $vendor_array = array();
434
                $vendor_array = array();
427
                $vendor_array[] = $buffer['Model'];
435
                $vendor_array[] = $buffer['Model'];
428
                $vendor_array[] = trim($buffer['Manufacturer']." ".$buffer['Model']);
436
                $vendor_array[] = trim($buffer['Manufacturer']." ".$buffer['Model']);
429
                if (PSI_OS == 'NetBSD') { // NetBSD
437
                if (PSI_OS == 'NetBSD') { // NetBSD
430
                    $vendor_array[] = $this->grabkey('machdep.dmi.board-vendor');
438
                    $vendor_array[] = $this->grabkey('machdep.dmi.board-vendor');
431
                    $vendor_array[] = $this->grabkey('machdep.dmi.bios-vendor');
439
                    $vendor_array[] = $this->grabkey('machdep.dmi.bios-vendor');
432
                }
440
                }
433
                $virt = CommonFunctions::decodevirtualizer($vendor_array);
441
                $virt = CommonFunctions::decodevirtualizer($vendor_array);
434
                if ($virt !== null) {
442
                if ($virt !== null) {
435
                    $this->sys->setVirtualizer($virt);
443
                    $this->sys->setVirtualizer($virt);
436
                }
444
                }
437
            }
445
            }
438
 
446
 
439
            $buf = "";
447
            $buf = "";
440
            if (($buffer['Manufacturer'] !== "") && !preg_match("/^To be filled by O\.E\.M\.$|^System manufacturer$|^Not Specified$/i", $buf2=trim($buffer['Manufacturer'])) && ($buf2 !== "")) {
448
            if (($buffer['Manufacturer'] !== "") && !preg_match("/^To be filled by O\.E\.M\.$|^System manufacturer$|^Not Specified$/i", $buf2=trim($buffer['Manufacturer'])) && ($buf2 !== "")) {
441
                $buf .= ' '.$buf2;
449
                $buf .= ' '.$buf2;
442
            }
450
            }
443
 
451
 
444
            if (($buffer['Model'] !== "") && !preg_match("/^To be filled by O\.E\.M\.$|^System Product Name$|^Not Specified$/i", $buf2=trim($buffer['Model'])) && ($buf2 !== "")) {
452
            if (($buffer['Model'] !== "") && !preg_match("/^To be filled by O\.E\.M\.$|^System Product Name$|^Not Specified$/i", $buf2=trim($buffer['Model'])) && ($buf2 !== "")) {
445
                $model = $buf2;
453
                $model = $buf2;
446
                $buf .= ' '.$buf2;
454
                $buf .= ' '.$buf2;
447
            }
455
            }
448
            if (($buffer['Product'] !== "") && !preg_match("/^To be filled by O\.E\.M\.$|^BaseBoard Product Name$|^Not Specified$|^Default string$/i", $buf2=trim($buffer['Product'])) && ($buf2 !== "")) {
456
            if (($buffer['Product'] !== "") && !preg_match("/^To be filled by O\.E\.M\.$|^BaseBoard Product Name$|^Not Specified$|^Default string$/i", $buf2=trim($buffer['Product'])) && ($buf2 !== "")) {
449
                if ($buf2 !== $model) {
457
                if ($buf2 !== $model) {
450
                    $buf .= '/'.$buf2;
458
                    $buf .= '/'.$buf2;
451
                } elseif (isset($buffer['SystemFamily']) && !preg_match("/^To be filled by O\.E\.M\.$|^System Family$|^Not Specified$/i", $buf2=trim($buffer['SystemFamily'])) && ($buf2 !== "")) {
459
                } elseif (isset($buffer['SystemFamily']) && !preg_match("/^To be filled by O\.E\.M\.$|^System Family$|^Not Specified$/i", $buf2=trim($buffer['SystemFamily'])) && ($buf2 !== "")) {
452
                    $buf .= '/'.$buf2;
460
                    $buf .= '/'.$buf2;
453
                }
461
                }
454
            }
462
            }
455
 
463
 
456
            $bver = "";
464
            $bver = "";
457
            $brel = "";
465
            $brel = "";
458
            if (($buf2=trim($buffer['SMBIOSBIOSVersion'])) !== "") {
466
            if (($buf2=trim($buffer['SMBIOSBIOSVersion'])) !== "") {
459
                $bver .= ' '.$buf2;
467
                $bver .= ' '.$buf2;
460
            }
468
            }
461
            if ($buffer['ReleaseDate'] !== "") {
469
            if ($buffer['ReleaseDate'] !== "") {
462
                if (preg_match("/^(\d{4})(\d{2})(\d{2})$/", $buffer['ReleaseDate'], $dateout)) {
470
                if (preg_match("/^(\d{4})(\d{2})(\d{2})$/", $buffer['ReleaseDate'], $dateout)) {
463
                    $brel .= ' '.$dateout[2].'/'.$dateout[3].'/'.$dateout[1];
471
                    $brel .= ' '.$dateout[2].'/'.$dateout[3].'/'.$dateout[1];
464
                } elseif (preg_match("/^\d{2}\/\d{2}\/\d{4}$/", $buffer['ReleaseDate'])) {
472
                } elseif (preg_match("/^\d{2}\/\d{2}\/\d{4}$/", $buffer['ReleaseDate'])) {
465
                    $brel .= ' '.$buffer['ReleaseDate'];
473
                    $brel .= ' '.$buffer['ReleaseDate'];
466
                }
474
                }
467
            }
475
            }
468
            if ((trim($bver) !== "") || (trim($brel) !== "")) {
476
            if ((trim($bver) !== "") || (trim($brel) !== "")) {
469
                $buf .= ', BIOS'.$bver.$brel;
477
                $buf .= ', BIOS'.$bver.$brel;
470
            }
478
            }
471
 
479
 
472
            if (trim($buf) !== "") {
480
            if (trim($buf) !== "") {
473
                $this->sys->setMachine(trim($buf));
481
                $this->sys->setMachine(trim($buf));
474
            }
482
            }
475
        } elseif ((PSI_OS == 'FreeBSD') && defined('PSI_SHOW_VIRTUALIZER_INFO') && PSI_SHOW_VIRTUALIZER_INFO) {
483
        } elseif ((PSI_OS == 'FreeBSD') && defined('PSI_SHOW_VIRTUALIZER_INFO') && PSI_SHOW_VIRTUALIZER_INFO) {
476
            $vendorid = $this->grabkey('hw.hv_vendor');
484
            $vendorid = $this->grabkey('hw.hv_vendor');
477
            if (trim($vendorid) === "") {
485
            if (trim($vendorid) === "") {
478
                foreach ($this->readdmesg() as $line) if (preg_match("/^Hypervisor: Origin = \"(.+)\"/", $line, $ar_buf)) {
486
                foreach ($this->readdmesg() as $line) if (preg_match("/^Hypervisor: Origin = \"(.+)\"/", $line, $ar_buf)) {
479
                    if (trim($ar_buf[1]) !== "") {
487
                    if (trim($ar_buf[1]) !== "") {
480
                        $vendorid = $ar_buf[1];
488
                        $vendorid = $ar_buf[1];
481
                    }
489
                    }
482
                    break;
490
                    break;
483
                }
491
                }
484
            }
492
            }
485
            if (trim($vendorid) !== "") {
493
            if (trim($vendorid) !== "") {
486
                $virt = CommonFunctions::decodevirtualizer($vendorid);
494
                $virt = CommonFunctions::decodevirtualizer($vendorid);
487
                if ($virt !== null) {
495
                if ($virt !== null) {
488
                    $this->sys->setVirtualizer($virt);
496
                    $this->sys->setVirtualizer($virt);
489
                } else {
497
                } else {
490
                    $this->sys->setVirtualizer('unknown');
498
                    $this->sys->setVirtualizer('unknown');
491
                }
499
                }
492
            }
500
            }
493
        }
501
        }
494
    }
502
    }
495
 
503
 
496
    /**
504
    /**
497
     * SCSI devices
505
     * SCSI devices
498
     * get the scsi device information out of dmesg
506
     * get the scsi device information out of dmesg
499
     *
507
     *
500
     * @return void
508
     * @return void
501
     */
509
     */
502
    protected function scsi()
510
    protected function scsi()
503
    {
511
    {
504
        foreach ($this->readdmesg() as $line) {
512
        foreach ($this->readdmesg() as $line) {
505
            if (preg_match($this->_SCSIRegExp1, $line, $ar_buf) && (sizeof($ar_buf) > 2)) {
513
            if (preg_match($this->_SCSIRegExp1, $line, $ar_buf) && (sizeof($ar_buf) > 2)) {
506
                $dev = new HWDevice();
514
                $dev = new HWDevice();
507
                $dev->setName($ar_buf[1].": ".trim($ar_buf[2]));
515
                $dev->setName($ar_buf[1].": ".trim($ar_buf[2]));
508
                $this->sys->setScsiDevices($dev);
516
                $this->sys->setScsiDevices($dev);
509
            } elseif (preg_match($this->_SCSIRegExp2, $line, $ar_buf) && (sizeof($ar_buf) > 1)) {
517
            } elseif (preg_match($this->_SCSIRegExp2, $line, $ar_buf) && (sizeof($ar_buf) > 1)) {
510
                /* duplication security */
518
                /* duplication security */
511
                $notwas = true;
519
                $notwas = true;
512
                foreach ($this->sys->getScsiDevices() as $finddev) {
520
                foreach ($this->sys->getScsiDevices() as $finddev) {
513
                    if ($notwas && (substr($finddev->getName(), 0, strpos($finddev->getName(), ': ')) == $ar_buf[1])) {
521
                    if ($notwas && (substr($finddev->getName(), 0, strpos($finddev->getName(), ': ')) == $ar_buf[1])) {
514
                        if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS) {
522
                        if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS) {
515
                            if (isset($ar_buf[3]) && ($ar_buf[3]==="G")) {
523
                            if (isset($ar_buf[3]) && ($ar_buf[3]==="G")) {
516
                                $finddev->setCapacity($ar_buf[2] * 1024 * 1024 * 1024);
524
                                $finddev->setCapacity($ar_buf[2] * 1024 * 1024 * 1024);
517
                            } elseif (isset($ar_buf[2])) {
525
                            } elseif (isset($ar_buf[2])) {
518
                                $finddev->setCapacity($ar_buf[2] * 1024 * 1024);
526
                                $finddev->setCapacity($ar_buf[2] * 1024 * 1024);
519
                            }
527
                            }
520
                        }
528
                        }
521
                        $notwas = false;
529
                        $notwas = false;
522
                        break;
530
                        break;
523
                    }
531
                    }
524
                }
532
                }
525
                if ($notwas) {
533
                if ($notwas) {
526
                    $dev = new HWDevice();
534
                    $dev = new HWDevice();
527
                    $dev->setName($ar_buf[1]);
535
                    $dev->setName($ar_buf[1]);
528
                    if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS) {
536
                    if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS) {
529
                        if (isset($ar_buf[3]) && ($ar_buf[3]==="G")) {
537
                        if (isset($ar_buf[3]) && ($ar_buf[3]==="G")) {
530
                                $dev->setCapacity($ar_buf[2] * 1024 * 1024 * 1024);
538
                                $dev->setCapacity($ar_buf[2] * 1024 * 1024 * 1024);
531
                            } elseif (isset($ar_buf[2])) {
539
                            } elseif (isset($ar_buf[2])) {
532
                                $dev->setCapacity($ar_buf[2] * 1024 * 1024);
540
                                $dev->setCapacity($ar_buf[2] * 1024 * 1024);
533
                            }
541
                            }
534
                    }
542
                    }
535
                    $this->sys->setScsiDevices($dev);
543
                    $this->sys->setScsiDevices($dev);
536
                }
544
                }
537
            } elseif (preg_match($this->_SCSIRegExp3, $line, $ar_buf) && (sizeof($ar_buf) > 1)) {
545
            } elseif (preg_match($this->_SCSIRegExp3, $line, $ar_buf) && (sizeof($ar_buf) > 1)) {
538
                /* duplication security */
546
                /* duplication security */
539
                $notwas = true;
547
                $notwas = true;
540
                foreach ($this->sys->getScsiDevices() as $finddev) {
548
                foreach ($this->sys->getScsiDevices() as $finddev) {
541
                    if ($notwas && (substr($finddev->getName(), 0, strpos($finddev->getName(), ': ')) == $ar_buf[1])) {
549
                    if ($notwas && (substr($finddev->getName(), 0, strpos($finddev->getName(), ': ')) == $ar_buf[1])) {
542
                        if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS
550
                        if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS
543
                           && defined('PSI_SHOW_DEVICES_SERIAL') && PSI_SHOW_DEVICES_SERIAL) {
551
                           && defined('PSI_SHOW_DEVICES_SERIAL') && PSI_SHOW_DEVICES_SERIAL) {
544
                            if (isset($ar_buf[2])) $finddev->setSerial(trim($ar_buf[2]));
552
                            if (isset($ar_buf[2])) $finddev->setSerial(trim($ar_buf[2]));
545
                        }
553
                        }
546
                        $notwas = false;
554
                        $notwas = false;
547
                        break;
555
                        break;
548
                    }
556
                    }
549
                }
557
                }
550
                if ($notwas) {
558
                if ($notwas) {
551
                    $dev = new HWDevice();
559
                    $dev = new HWDevice();
552
                    $dev->setName($ar_buf[1]);
560
                    $dev->setName($ar_buf[1]);
553
                    if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS
561
                    if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS
554
                       && defined('PSI_SHOW_DEVICES_SERIAL') && PSI_SHOW_DEVICES_SERIAL) {
562
                       && defined('PSI_SHOW_DEVICES_SERIAL') && PSI_SHOW_DEVICES_SERIAL) {
555
                        if (isset($ar_buf[2])) $dev->setSerial(trim($ar_buf[2]));
563
                        if (isset($ar_buf[2])) $dev->setSerial(trim($ar_buf[2]));
556
                    }
564
                    }
557
                    $this->sys->setScsiDevices($dev);
565
                    $this->sys->setScsiDevices($dev);
558
                }
566
                }
559
            }
567
            }
560
        }
568
        }
561
        /* cleaning */
569
        /* cleaning */
562
        foreach ($this->sys->getScsiDevices() as $finddev) {
570
        foreach ($this->sys->getScsiDevices() as $finddev) {
563
            if (strpos($finddev->getName(), ': ') !== false)
571
            if (strpos($finddev->getName(), ': ') !== false)
564
                $finddev->setName(substr(strstr($finddev->getName(), ': '), 2));
572
                $finddev->setName(substr(strstr($finddev->getName(), ': '), 2));
565
        }
573
        }
566
    }
574
    }
567
 
575
 
568
    /**
576
    /**
569
     * parsing the output of pciconf command
577
     * parsing the output of pciconf command
570
     *
578
     *
571
     * @return Array
579
     * @return Array
572
     */
580
     */
573
    protected function pciconf()
581
    protected function pciconf()
574
    {
582
    {
575
        $arrResults = array();
583
        $arrResults = array();
576
        $intS = 0;
584
        $intS = 0;
577
        if (CommonFunctions::executeProgram("pciconf", "-lv", $strBuf, PSI_DEBUG)) {
585
        if (CommonFunctions::executeProgram("pciconf", "-lv", $strBuf, PSI_DEBUG)) {
578
            $arrTemp = array();
586
            $arrTemp = array();
579
            $arrBlocks = preg_split("/\n\S/", $strBuf, -1, PREG_SPLIT_NO_EMPTY);
587
            $arrBlocks = preg_split("/\n\S/", $strBuf, -1, PREG_SPLIT_NO_EMPTY);
580
            foreach ($arrBlocks as $strBlock) {
588
            foreach ($arrBlocks as $strBlock) {
581
                $arrLines = preg_split("/\n/", $strBlock, -1, PREG_SPLIT_NO_EMPTY);
589
                $arrLines = preg_split("/\n/", $strBlock, -1, PREG_SPLIT_NO_EMPTY);
582
                $vend = null;
590
                $vend = null;
583
                foreach ($arrLines as $strLine) {
591
                foreach ($arrLines as $strLine) {
584
                    if (preg_match("/\sclass=0x([a-fA-F0-9]{4})[a-fA-F0-9]{2}\s.*\schip=0x([a-fA-F0-9]{4})([a-fA-F0-9]{4})\s/", $strLine, $arrParts)) {
592
                    if (preg_match("/\sclass=0x([a-fA-F0-9]{4})[a-fA-F0-9]{2}\s.*\schip=0x([a-fA-F0-9]{4})([a-fA-F0-9]{4})\s/", $strLine, $arrParts)) {
585
                        $arrTemp[$intS] = 'Class '.$arrParts[1].': Device '.$arrParts[3].':'.$arrParts[2];
593
                        $arrTemp[$intS] = 'Class '.$arrParts[1].': Device '.$arrParts[3].':'.$arrParts[2];
586
                        $vend = '';
594
                        $vend = '';
587
                    } elseif (preg_match("/(.*) = '(.*)'/", $strLine, $arrParts)) {
595
                    } elseif (preg_match("/(.*) = '(.*)'/", $strLine, $arrParts)) {
588
                        if (trim($arrParts[1]) == "vendor") {
596
                        if (trim($arrParts[1]) == "vendor") {
589
                            $vend = trim($arrParts[2]);
597
                            $vend = trim($arrParts[2]);
590
                        } elseif (trim($arrParts[1]) == "device") {
598
                        } elseif (trim($arrParts[1]) == "device") {
591
                            if (($vend !== null) && ($vend !== '')) {
599
                            if (($vend !== null) && ($vend !== '')) {
592
                                $arrTemp[$intS] = $vend." - ".trim($arrParts[2]);
600
                                $arrTemp[$intS] = $vend." - ".trim($arrParts[2]);
593
                            } else {
601
                            } else {
594
                                $arrTemp[$intS] = trim($arrParts[2]);
602
                                $arrTemp[$intS] = trim($arrParts[2]);
595
                                $vend = '';
603
                                $vend = '';
596
                            }
604
                            }
597
                        }
605
                        }
598
                    }
606
                    }
599
                }
607
                }
600
                if ($vend !== null) {
608
                if ($vend !== null) {
601
                    $intS++;
609
                    $intS++;
602
                }
610
                }
603
            }
611
            }
604
            foreach ($arrTemp as $name) {
612
            foreach ($arrTemp as $name) {
605
                $dev = new HWDevice();
613
                $dev = new HWDevice();
606
                $dev->setName($name);
614
                $dev->setName($name);
607
                $arrResults[] = $dev;
615
                $arrResults[] = $dev;
608
            }
616
            }
609
        }
617
        }
610
 
618
 
611
        return $arrResults;
619
        return $arrResults;
612
    }
620
    }
613
 
621
 
614
    /**
622
    /**
615
     * PCI devices
623
     * PCI devices
616
     * get the pci device information out of dmesg
624
     * get the pci device information out of dmesg
617
     *
625
     *
618
     * @return void
626
     * @return void
619
     */
627
     */
620
    protected function pci()
628
    protected function pci()
621
    {
629
    {
622
        if ((!$results = Parser::lspci(false)) && (!$results = $this->pciconf())) {
630
        if ((!$results = Parser::lspci(false)) && (!$results = $this->pciconf())) {
623
            foreach ($this->readdmesg() as $line) {
631
            foreach ($this->readdmesg() as $line) {
624
                if (preg_match($this->_PCIRegExp1, $line, $ar_buf) && (sizeof($ar_buf) > 2)) {
632
                if (preg_match($this->_PCIRegExp1, $line, $ar_buf) && (sizeof($ar_buf) > 2)) {
625
                    $dev = new HWDevice();
633
                    $dev = new HWDevice();
626
                    $dev->setName($ar_buf[1].": ".$ar_buf[2]);
634
                    $dev->setName($ar_buf[1].": ".$ar_buf[2]);
627
                    $results[] = $dev;
635
                    $results[] = $dev;
628
                } elseif (preg_match($this->_PCIRegExp2, $line, $ar_buf) && (sizeof($ar_buf) > 2)) {
636
                } elseif (preg_match($this->_PCIRegExp2, $line, $ar_buf) && (sizeof($ar_buf) > 2)) {
629
                    $dev = new HWDevice();
637
                    $dev = new HWDevice();
630
                    $dev->setName($ar_buf[1].": ".$ar_buf[2]);
638
                    $dev->setName($ar_buf[1].": ".$ar_buf[2]);
631
                    $results[] = $dev;
639
                    $results[] = $dev;
632
                }
640
                }
633
            }
641
            }
634
        }
642
        }
635
        foreach ($results as $dev) {
643
        foreach ($results as $dev) {
636
            $this->sys->setPciDevices($dev);
644
            $this->sys->setPciDevices($dev);
637
        }
645
        }
638
    }
646
    }
639
 
647
 
640
    /**
648
    /**
641
     * IDE devices
649
     * IDE devices
642
     * get the ide device information out of dmesg
650
     * get the ide device information out of dmesg
643
     *
651
     *
644
     * @return void
652
     * @return void
645
     */
653
     */
646
    protected function ide()
654
    protected function ide()
647
    {
655
    {
648
        foreach ($this->readdmesg() as $line) {
656
        foreach ($this->readdmesg() as $line) {
649
            if (preg_match('/^(ad[0-9]+): (.*)MB <(.*)> (.*) (.*)/', $line, $ar_buf)) {
657
            if (preg_match('/^(ad[0-9]+): (.*)MB <(.*)> (.*) (.*)/', $line, $ar_buf)) {
650
                $dev = new HWDevice();
658
                $dev = new HWDevice();
651
                $dev->setName($ar_buf[1].": ".trim($ar_buf[3]));
659
                $dev->setName($ar_buf[1].": ".trim($ar_buf[3]));
652
                if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS) {
660
                if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS) {
653
                    $dev->setCapacity($ar_buf[2] * 1024 * 1024);
661
                    $dev->setCapacity($ar_buf[2] * 1024 * 1024);
654
                }
662
                }
655
                $this->sys->setIdeDevices($dev);
663
                $this->sys->setIdeDevices($dev);
656
            } elseif (preg_match('/^(acd[0-9]+): (.*) <(.*)> (.*)/', $line, $ar_buf)) {
664
            } elseif (preg_match('/^(acd[0-9]+): (.*) <(.*)> (.*)/', $line, $ar_buf)) {
657
                $dev = new HWDevice();
665
                $dev = new HWDevice();
658
                $dev->setName($ar_buf[1].": ".trim($ar_buf[3]));
666
                $dev->setName($ar_buf[1].": ".trim($ar_buf[3]));
659
                $this->sys->setIdeDevices($dev);
667
                $this->sys->setIdeDevices($dev);
660
            } elseif (preg_match('/^(ada[0-9]+): <(.*)> (.*)/', $line, $ar_buf)) {
668
            } elseif (preg_match('/^(ada[0-9]+): <(.*)> (.*)/', $line, $ar_buf)) {
661
                $dev = new HWDevice();
669
                $dev = new HWDevice();
662
                $dev->setName($ar_buf[1].": ".trim($ar_buf[2]));
670
                $dev->setName($ar_buf[1].": ".trim($ar_buf[2]));
663
                $this->sys->setIdeDevices($dev);
671
                $this->sys->setIdeDevices($dev);
664
            } elseif (preg_match('/^(ada[0-9]+): (.*)MB \((.*)\)/', $line, $ar_buf)) {
672
            } elseif (preg_match('/^(ada[0-9]+): (.*)MB \((.*)\)/', $line, $ar_buf)) {
665
                /* duplication security */
673
                /* duplication security */
666
                $notwas = true;
674
                $notwas = true;
667
                foreach ($this->sys->getIdeDevices() as $finddev) {
675
                foreach ($this->sys->getIdeDevices() as $finddev) {
668
                    if ($notwas && (substr($finddev->getName(), 0, strpos($finddev->getName(), ': ')) == $ar_buf[1])) {
676
                    if ($notwas && (substr($finddev->getName(), 0, strpos($finddev->getName(), ': ')) == $ar_buf[1])) {
669
                        if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS) {
677
                        if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS) {
670
                            $finddev->setCapacity($ar_buf[2] * 1024 * 1024);
678
                            $finddev->setCapacity($ar_buf[2] * 1024 * 1024);
671
                        }
679
                        }
672
                        $notwas = false;
680
                        $notwas = false;
673
                        break;
681
                        break;
674
                    }
682
                    }
675
                }
683
                }
676
                if ($notwas) {
684
                if ($notwas) {
677
                    $dev = new HWDevice();
685
                    $dev = new HWDevice();
678
                    $dev->setName($ar_buf[1]);
686
                    $dev->setName($ar_buf[1]);
679
                    if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS) {
687
                    if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS) {
680
                        $dev->setCapacity($ar_buf[2] * 1024 * 1024);
688
                        $dev->setCapacity($ar_buf[2] * 1024 * 1024);
681
                    }
689
                    }
682
                    $this->sys->setIdeDevices($dev);
690
                    $this->sys->setIdeDevices($dev);
683
                }
691
                }
684
            } elseif (preg_match('/^(ada[0-9]+): Serial Number (.*)/', $line, $ar_buf)) {
692
            } elseif (preg_match('/^(ada[0-9]+): Serial Number (.*)/', $line, $ar_buf)) {
685
                /* duplication security */
693
                /* duplication security */
686
                $notwas = true;
694
                $notwas = true;
687
                foreach ($this->sys->getIdeDevices() as $finddev) {
695
                foreach ($this->sys->getIdeDevices() as $finddev) {
688
                    if ($notwas && (substr($finddev->getName(), 0, strpos($finddev->getName(), ': ')) == $ar_buf[1])) {
696
                    if ($notwas && (substr($finddev->getName(), 0, strpos($finddev->getName(), ': ')) == $ar_buf[1])) {
689
                        if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS
697
                        if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS
690
                           && defined('PSI_SHOW_DEVICES_SERIAL') && PSI_SHOW_DEVICES_SERIAL) {
698
                           && defined('PSI_SHOW_DEVICES_SERIAL') && PSI_SHOW_DEVICES_SERIAL) {
691
                            $finddev->setSerial(trim($ar_buf[2]));
699
                            $finddev->setSerial(trim($ar_buf[2]));
692
                        }
700
                        }
693
                        $notwas = false;
701
                        $notwas = false;
694
                        break;
702
                        break;
695
                    }
703
                    }
696
                }
704
                }
697
                if ($notwas) {
705
                if ($notwas) {
698
                    $dev = new HWDevice();
706
                    $dev = new HWDevice();
699
                    $dev->setName($ar_buf[1]);
707
                    $dev->setName($ar_buf[1]);
700
                    if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS
708
                    if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS
701
                       && defined('PSI_SHOW_DEVICES_SERIAL') && PSI_SHOW_DEVICES_SERIAL) {
709
                       && defined('PSI_SHOW_DEVICES_SERIAL') && PSI_SHOW_DEVICES_SERIAL) {
702
                        $finddev->setSerial(trim($ar_buf[2]));
710
                        $finddev->setSerial(trim($ar_buf[2]));
703
                    }
711
                    }
704
                    $this->sys->setIdeDevices($dev);
712
                    $this->sys->setIdeDevices($dev);
705
                }
713
                }
706
            }
714
            }
707
        }
715
        }
708
        /* cleaning */
716
        /* cleaning */
709
        foreach ($this->sys->getIdeDevices() as $finddev) {
717
        foreach ($this->sys->getIdeDevices() as $finddev) {
710
                    if (strpos($finddev->getName(), ': ') !== false)
718
                    if (strpos($finddev->getName(), ': ') !== false)
711
                        $finddev->setName(substr(strstr($finddev->getName(), ': '), 2));
719
                        $finddev->setName(substr(strstr($finddev->getName(), ': '), 2));
712
        }
720
        }
713
    }
721
    }
714
 
722
 
715
    /**
723
    /**
716
     * Physical memory information and Swap Space information
724
     * Physical memory information and Swap Space information
717
     *
725
     *
718
     * @return void
726
     * @return void
719
     */
727
     */
720
    protected function memory()
728
    protected function memory()
721
    {
729
    {
722
        if (PSI_OS == 'FreeBSD' || PSI_OS == 'OpenBSD') {
730
        if (PSI_OS == 'FreeBSD' || PSI_OS == 'OpenBSD') {
723
            // vmstat on fbsd 4.4 or greater outputs kbytes not hw.pagesize
731
            // vmstat on fbsd 4.4 or greater outputs kbytes not hw.pagesize
724
            // I should probably add some version checking here, but for now
732
            // I should probably add some version checking here, but for now
725
            // we only support fbsd 4.4
733
            // we only support fbsd 4.4
726
            $pagesize = 1024;
734
            $pagesize = 1024;
727
        } else {
735
        } else {
728
            $pagesize = $this->grabkey('hw.pagesize');
736
            $pagesize = $this->grabkey('hw.pagesize');
729
        }
737
        }
730
        if (CommonFunctions::executeProgram('vmstat', '', $vmstat, PSI_DEBUG)) {
738
        if (CommonFunctions::executeProgram('vmstat', '', $vmstat, PSI_DEBUG)) {
731
            $lines = preg_split("/\n/", $vmstat, -1, PREG_SPLIT_NO_EMPTY);
739
            $lines = preg_split("/\n/", $vmstat, -1, PREG_SPLIT_NO_EMPTY);
732
            $ar_buf = preg_split("/\s+/", trim($lines[2]), 19);
740
            $ar_buf = preg_split("/\s+/", trim($lines[2]), 19);
733
            if (PSI_OS == 'NetBSD' || PSI_OS == 'DragonFly') {
741
            if (PSI_OS == 'NetBSD' || PSI_OS == 'DragonFly') {
734
                $this->sys->setMemFree($ar_buf[4] * 1024);
742
                $this->sys->setMemFree($ar_buf[4] * 1024);
735
            } else {
743
            } else {
736
                $this->sys->setMemFree($ar_buf[4] * $pagesize);
744
                $this->sys->setMemFree($ar_buf[4] * $pagesize);
737
            }
745
            }
738
            $this->sys->setMemTotal($this->grabkey('hw.physmem'));
746
            $this->sys->setMemTotal($this->grabkey('hw.physmem'));
739
            $this->sys->setMemUsed($this->sys->getMemTotal() - $this->sys->getMemFree());
747
            $this->sys->setMemUsed($this->sys->getMemTotal() - $this->sys->getMemFree());
740
 
748
 
741
            if (((PSI_OS == 'OpenBSD' || PSI_OS == 'NetBSD') && CommonFunctions::executeProgram('swapctl', '-l -k', $swapstat, PSI_DEBUG)) || CommonFunctions::executeProgram('swapinfo', '-k', $swapstat, PSI_DEBUG)) {
749
            if (((PSI_OS == 'OpenBSD' || PSI_OS == 'NetBSD') && CommonFunctions::executeProgram('swapctl', '-l -k', $swapstat, PSI_DEBUG)) || CommonFunctions::executeProgram('swapinfo', '-k', $swapstat, PSI_DEBUG)) {
742
                $lines = preg_split("/\n/", $swapstat, -1, PREG_SPLIT_NO_EMPTY);
750
                $lines = preg_split("/\n/", $swapstat, -1, PREG_SPLIT_NO_EMPTY);
743
                foreach ($lines as $line) {
751
                foreach ($lines as $line) {
744
                    $ar_buf = preg_split("/\s+/", $line, 6);
752
                    $ar_buf = preg_split("/\s+/", $line, 6);
745
                    if (($ar_buf[0] != 'Total') && ($ar_buf[0] != 'Device')) {
753
                    if (($ar_buf[0] != 'Total') && ($ar_buf[0] != 'Device')) {
746
                        $dev = new DiskDevice();
754
                        $dev = new DiskDevice();
747
                        $dev->setMountPoint($ar_buf[0]);
755
                        $dev->setMountPoint($ar_buf[0]);
748
                        $dev->setName("SWAP");
756
                        $dev->setName("SWAP");
749
                        $dev->setFsType('swap');
757
                        $dev->setFsType('swap');
750
                        $dev->setTotal($ar_buf[1] * 1024);
758
                        $dev->setTotal($ar_buf[1] * 1024);
751
                        $dev->setUsed($ar_buf[2] * 1024);
759
                        $dev->setUsed($ar_buf[2] * 1024);
752
                        $dev->setFree($dev->getTotal() - $dev->getUsed());
760
                        $dev->setFree($dev->getTotal() - $dev->getUsed());
753
                        $this->sys->setSwapDevices($dev);
761
                        $this->sys->setSwapDevices($dev);
754
                    }
762
                    }
755
                }
763
                }
756
            }
764
            }
757
        }
765
        }
758
    }
766
    }
759
 
767
 
760
    /**
768
    /**
761
     * USB devices
769
     * USB devices
762
     * get the ide device information out of dmesg
770
     * get the ide device information out of dmesg
763
     *
771
     *
764
     * @return void
772
     * @return void
765
     */
773
     */
766
    protected function usb()
774
    protected function usb()
767
    {
775
    {
768
        $notwas = true;
776
        $notwas = true;
769
        if ((PSI_OS == 'FreeBSD') && CommonFunctions::executeProgram('usbconfig', '', $bufr, false)) {
777
        if ((PSI_OS == 'FreeBSD') && CommonFunctions::executeProgram('usbconfig', '', $bufr, false)) {
770
            $lines = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
778
            $lines = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
771
            foreach ($lines as $line) {
779
            foreach ($lines as $line) {
772
                if (preg_match('/^(ugen[0-9]+\.[0-9]+): <([^,]*)(.*)> at (usbus[0-9]+)/', $line, $ar_buf)) {
780
                if (preg_match('/^(ugen[0-9]+\.[0-9]+): <([^,]*)(.*)> at (usbus[0-9]+)/', $line, $ar_buf)) {
773
                    $notwas = false;
781
                    $notwas = false;
774
                    $dev = new HWDevice();
782
                    $dev = new HWDevice();
775
                    $dev->setName($ar_buf[2]);
783
                    $dev->setName($ar_buf[2]);
776
                    $this->sys->setUSBDevices($dev);
784
                    $this->sys->setUSBDevices($dev);
777
                }
785
                }
778
            }
786
            }
779
        }
787
        }
780
        if ($notwas) foreach ($this->readdmesg() as $line) {
788
        if ($notwas) foreach ($this->readdmesg() as $line) {
781
//            if (preg_match('/^(ugen[0-9\.]+): <(.*)> (.*) (.*)/', $line, $ar_buf)) {
789
//            if (preg_match('/^(ugen[0-9\.]+): <(.*)> (.*) (.*)/', $line, $ar_buf)) {
782
//                    $dev->setName($ar_buf[1].": ".$ar_buf[2]);
790
//                    $dev->setName($ar_buf[1].": ".$ar_buf[2]);
783
            if (preg_match('/^(u[a-z]+[0-9]+): <([^,]*)(.*)> on (usbus[0-9]+)/', $line, $ar_buf)) {
791
            if (preg_match('/^(u[a-z]+[0-9]+): <([^,]*)(.*)> on (usbus[0-9]+)/', $line, $ar_buf)) {
784
                    $dev = new HWDevice();
792
                    $dev = new HWDevice();
785
                    $dev->setName($ar_buf[2]);
793
                    $dev->setName($ar_buf[2]);
786
                    $this->sys->setUSBDevices($dev);
794
                    $this->sys->setUSBDevices($dev);
787
            }
795
            }
788
        }
796
        }
789
    }
797
    }
790
 
798
 
791
    /**
799
    /**
792
     * filesystem information
800
     * filesystem information
793
     *
801
     *
794
     * @return void
802
     * @return void
795
     */
803
     */
796
    protected function filesystems()
804
    protected function filesystems()
797
    {
805
    {
798
        $arrResult = Parser::df();
806
        $arrResult = Parser::df();
799
        foreach ($arrResult as $dev) {
807
        foreach ($arrResult as $dev) {
800
            $this->sys->setDiskDevices($dev);
808
            $this->sys->setDiskDevices($dev);
801
        }
809
        }
802
    }
810
    }
803
 
811
 
804
    /**
812
    /**
805
     * Distribution
813
     * Distribution
806
     *
814
     *
807
     * @return void
815
     * @return void
808
     */
816
     */
809
    protected function distro()
817
    protected function distro()
810
    {
818
    {
811
        if (CommonFunctions::executeProgram('uname', '-s', $result, PSI_DEBUG)) {
819
        if (CommonFunctions::executeProgram('uname', '-s', $result, PSI_DEBUG)) {
812
            $this->sys->setDistribution($result);
820
            $this->sys->setDistribution($result);
813
        }
821
        }
814
    }
822
    }
815
 
823
 
816
    /**
824
    /**
817
     * UpTime
825
     * UpTime
818
     * time the system is running
826
     * time the system is running
819
     *
827
     *
820
     * @return void
828
     * @return void
821
     */
829
     */
822
    private function uptime()
830
    private function uptime()
823
    {
831
    {
824
        if ($kb = $this->grabkey('kern.boottime')) {
832
        if ($kb = $this->grabkey('kern.boottime')) {
825
            if (preg_match("/sec = ([0-9]+)/", $kb, $buf)) { // format like: { sec = 1096732600, usec = 885425 } Sat Oct 2 10:56:40 2004
833
            if (preg_match("/sec = ([0-9]+)/", $kb, $buf)) { // format like: { sec = 1096732600, usec = 885425 } Sat Oct 2 10:56:40 2004
826
                $this->sys->setUptime(time() - $buf[1]);
834
                $this->sys->setUptime(time() - $buf[1]);
827
            } else {
835
            } else {
828
                date_default_timezone_set('UTC');
836
                date_default_timezone_set('UTC');
829
                $kbt = strtotime($kb);
837
                $kbt = strtotime($kb);
830
                if (($kbt !== false) && ($kbt != -1)) {
838
                if (($kbt !== false) && ($kbt != -1)) {
831
                    $this->sys->setUptime(time() - $kbt); // format like: Sat Oct 2 10:56:40 2004
839
                    $this->sys->setUptime(time() - $kbt); // format like: Sat Oct 2 10:56:40 2004
832
                } else {
840
                } else {
833
                    $this->sys->setUptime(time() - $kb); // format like: 1096732600
841
                    $this->sys->setUptime(time() - $kb); // format like: 1096732600
834
                }
842
                }
835
            }
843
            }
836
        }
844
        }
837
    }
845
    }
838
 
846
 
839
    /**
847
    /**
840
     * get the information
848
     * get the information
841
     *
849
     *
842
     * @see PSI_Interface_OS::build()
850
     * @see PSI_Interface_OS::build()
843
     *
851
     *
844
     * @return void
852
     * @return void
845
     */
853
     */
846
    public function build()
854
    public function build()
847
    {
855
    {
848
        if (!$this->blockname || $this->blockname==='vitals') {
856
        if (!$this->blockname || $this->blockname==='vitals') {
849
            $this->distro();
857
            $this->distro();
850
            $this->hostname();
858
            $this->hostname();
851
            $this->kernel();
859
            $this->kernel();
852
            $this->_users();
860
            $this->_users();
853
            $this->loadavg();
861
            $this->loadavg();
854
            $this->uptime();
862
            $this->uptime();
855
        }
863
        }
856
        if (!$this->blockname || $this->blockname==='hardware') {
864
        if (!$this->blockname || $this->blockname==='hardware') {
857
            $this->machine();
865
            $this->machine();
858
            $this->cpuinfo();
866
            $this->cpuinfo();
859
            $this->virtualizer();
867
            $this->virtualizer();
860
            $this->pci();
868
            $this->pci();
861
            $this->ide();
869
            $this->ide();
862
            $this->scsi();
870
            $this->scsi();
863
            $this->usb();
871
            $this->usb();
864
        }
872
        }
865
        if (!$this->blockname || $this->blockname==='memory') {
873
        if (!$this->blockname || $this->blockname==='memory') {
866
            $this->memory();
874
            $this->memory();
867
        }
875
        }
868
        if (!$this->blockname || $this->blockname==='filesystem') {
876
        if (!$this->blockname || $this->blockname==='filesystem') {
869
            $this->filesystems();
877
            $this->filesystems();
870
        }
878
        }
871
    }
879
    }
872
}
880
}
873
 
881