Subversion Repositories ALCASAR

Rev

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

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