Subversion Repositories ALCASAR

Rev

Rev 2770 | Rev 3037 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log

Rev Author Line No. Line
2770 rexy 1
<?php
2
/**
3
 * BSDCommon Class
4
 *
5
 * PHP version 5
6
 *
7
 * @category  PHP
8
 * @package   PSI BSDCommon OS class
9
 * @author    Michael Cramer <BigMichi1@users.sourceforge.net>
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
12
 * @version   SVN: $Id: class.BSDCommon.inc.php 621 2012-07-29 18:49:04Z namiltd $
13
 * @link      http://phpsysinfo.sourceforge.net
14
 */
15
 /**
16
 * BSDCommon class
17
 * get all the required information for BSD Like systems
18
 * no need to implement in every class the same methods
19
 *
20
 * @category  PHP
21
 * @package   PSI BSDCommon OS class
22
 * @author    Michael Cramer <BigMichi1@users.sourceforge.net>
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
25
 * @version   Release: 3.0
26
 * @link      http://phpsysinfo.sourceforge.net
27
 */
28
abstract class BSDCommon extends OS
29
{
30
    /**
31
     * content of the syslog
32
     *
33
     * @var array
34
     */
35
    private $_dmesg = null;
36
 
37
    /**
38
     * regexp1 for cpu information out of the syslog
39
     *
40
     * @var string
41
     */
42
    private $_CPURegExp1 = "//";
43
 
44
    /**
45
     * regexp2 for cpu information out of the syslog
46
     *
47
     * @var string
48
     */
49
    private $_CPURegExp2 = "//";
50
 
51
    /**
52
     * regexp1 for scsi information out of the syslog
53
     *
54
     * @var string
55
     */
56
    private $_SCSIRegExp1 = "//";
57
 
58
    /**
59
     * regexp2 for scsi information out of the syslog
60
     *
61
     * @var string
62
     */
63
    private $_SCSIRegExp2 = "//";
64
 
65
    /**
66
     * regexp3 for scsi information out of the syslog
67
     *
68
     * @var string
69
     */
70
    private $_SCSIRegExp3 = "//";
71
 
72
    /**
73
     * regexp1 for pci information out of the syslog
74
     *
75
     * @var string
76
     */
77
    private $_PCIRegExp1 = "//";
78
 
79
    /**
80
     * regexp1 for pci information out of the syslog
81
     *
82
     * @var string
83
     */
84
    private $_PCIRegExp2 = "//";
85
 
86
    /**
87
     * setter for cpuregexp1
88
     *
89
     * @param string $value value to set
90
     *
91
     * @return void
92
     */
93
    protected function setCPURegExp1($value)
94
    {
95
        $this->_CPURegExp1 = $value;
96
    }
97
 
98
    /**
99
     * setter for cpuregexp2
100
     *
101
     * @param string $value value to set
102
     *
103
     * @return void
104
     */
105
    protected function setCPURegExp2($value)
106
    {
107
        $this->_CPURegExp2 = $value;
108
    }
109
 
110
    /**
111
     * setter for scsiregexp1
112
     *
113
     * @param string $value value to set
114
     *
115
     * @return void
116
     */
117
    protected function setSCSIRegExp1($value)
118
    {
119
        $this->_SCSIRegExp1 = $value;
120
    }
121
 
122
    /**
123
     * setter for scsiregexp2
124
     *
125
     * @param string $value value to set
126
     *
127
     * @return void
128
     */
129
    protected function setSCSIRegExp2($value)
130
    {
131
        $this->_SCSIRegExp2 = $value;
132
    }
133
 
134
    /**
135
     * setter for scsiregexp3
136
     *
137
     * @param string $value value to set
138
     *
139
     * @return void
140
     */
141
    protected function setSCSIRegExp3($value)
142
    {
143
        $this->_SCSIRegExp3 = $value;
144
    }
145
 
146
    /**
147
     * setter for pciregexp1
148
     *
149
     * @param string $value value to set
150
     *
151
     * @return void
152
     */
153
    protected function setPCIRegExp1($value)
154
    {
155
        $this->_PCIRegExp1 = $value;
156
    }
157
 
158
    /**
159
     * setter for pciregexp2
160
     *
161
     * @param string $value value to set
162
     *
163
     * @return void
164
     */
165
    protected function setPCIRegExp2($value)
166
    {
167
        $this->_PCIRegExp2 = $value;
168
    }
169
 
170
    /**
171
     * read /var/run/dmesg.boot, but only if we haven't already
172
     *
173
     * @return array
174
     */
175
    protected function readdmesg()
176
    {
177
        if ($this->_dmesg === null) {
2976 rexy 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
2770 rexy 179
                $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);
181
            } else {
182
                $this->_dmesg = array();
183
            }
184
        }
185
 
186
        return $this->_dmesg;
187
    }
188
 
189
    /**
190
     * get a value from sysctl command
191
     *
192
     * @param string $key key for the value to get
193
     *
194
     * @return string
195
     */
196
    protected function grabkey($key)
197
    {
198
        $buf = "";
199
        if (CommonFunctions::executeProgram('sysctl', "-n $key", $buf, PSI_DEBUG)) {
200
            return $buf;
201
        } else {
202
            return '';
203
        }
204
    }
205
 
206
    /**
207
     * Virtual Host Name
208
     *
209
     * @return void
210
     */
211
    protected function hostname()
212
    {
213
        if (PSI_USE_VHOST === true) {
214
            if (CommonFunctions::readenv('SERVER_NAME', $hnm)) $this->sys->setHostname($hnm);
215
        } else {
216
            if (CommonFunctions::executeProgram('hostname', '', $buf, PSI_DEBUG)) {
217
                $this->sys->setHostname($buf);
218
            }
219
        }
220
    }
221
 
222
    /**
223
     * Kernel Version
224
     *
225
     * @return void
226
     */
227
    protected function kernel()
228
    {
229
        $s = $this->grabkey('kern.version');
230
        $a = preg_split('/:/', $s);
231
        if (isset($a[2])) {
232
            $this->sys->setKernel($a[0].$a[1].':'.$a[2]);
233
        } else {
234
            $this->sys->setKernel($s);
235
        }
236
    }
237
 
238
    /**
239
     * Processor Load
240
     * optionally create a loadbar
241
     *
242
     * @return void
243
     */
244
    protected function loadavg()
245
    {
246
        $s = $this->grabkey('vm.loadavg');
247
        $s = preg_replace('/{ /', '', $s);
248
        $s = preg_replace('/ }/', '', $s);
249
        $this->sys->setLoad($s);
2976 rexy 250
        if (PSI_LOAD_BAR) {
251
            if (PSI_OS != 'Darwin') {
252
                if ($fd = $this->grabkey('kern.cp_time')) {
253
                    // Find out the CPU load
254
                    // user + sys = load
255
                    // total = total
256
                    if (preg_match($this->_CPURegExp2, $fd, $res) && (sizeof($res) > 4)) {
257
                        $load = $res[2] + $res[3] + $res[4]; // cpu.user + cpu.sys
258
                        $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)
260
                        sleep(1);
261
                        $fd = $this->grabkey('kern.cp_time');
262
                        if (preg_match($this->_CPURegExp2, $fd, $res) && (sizeof($res) > 4)) {
263
                            $load2 = $res[2] + $res[3] + $res[4];
264
                            $total2 = $res[2] + $res[3] + $res[4] + $res[5];
265
                            $this->sys->setLoadPercent((100 * ($load2 - $load)) / ($total2 - $total));
266
                        }
267
                    }
268
                }
269
            } else {
270
                $ncpu = $this->grabkey('hw.ncpu');
271
                if (!is_null($ncpu) && (trim($ncpu) != "") && ($ncpu >= 1) && CommonFunctions::executeProgram('ps', "-A -o %cpu", $pstable, false) && !empty($pstable)) {
272
                    $pslines = preg_split("/\n/", $pstable, -1, PREG_SPLIT_NO_EMPTY);
273
                    if (!empty($pslines) && (count($pslines)>1) && (trim($pslines[0])==="%CPU")) {
274
                        array_shift($pslines);
275
                        $sum = 0;
276
                        foreach ($pslines as $psline) {
277
                            $sum+=trim($psline);
278
                        }
279
                        $this->sys->setLoadPercent(min($sum/$ncpu, 100));
280
                    }
281
                }
2770 rexy 282
            }
283
        }
284
    }
285
 
286
    /**
287
     * CPU information
288
     *
289
     * @return void
290
     */
291
    protected function cpuinfo()
292
    {
293
        $dev = new CpuDevice();
294
 
2976 rexy 295
        if (PSI_OS == 'NetBSD') {
2770 rexy 296
            if ($model = $this->grabkey('machdep.cpu_brand')) {
297
               $dev->setModel($model);
298
            }
299
            if ($cpuspeed = $this->grabkey('machdep.tsc_freq')) {
300
               $dev->setCpuSpeed(round($cpuspeed / 1000000));
301
            }
302
        }
303
 
304
        if ($dev->getModel() === "") {
305
            $dev->setModel($this->grabkey('hw.model'));
306
        }
307
        $notwas = true;
308
        foreach ($this->readdmesg() as $line) {
309
            if ($notwas) {
2976 rexy 310
               if (preg_match($this->_CPURegExp1, $line, $ar_buf) && (sizeof($ar_buf) > 2)) {
2770 rexy 311
                    if ($dev->getCpuSpeed() === 0) {
312
                        $dev->setCpuSpeed(round($ar_buf[2]));
313
                    }
314
                    $notwas = false;
315
                }
316
            } else {
317
                if (preg_match("/ Origin| Features/", $line, $ar_buf)) {
318
                    if (preg_match("/ Features2[ ]*=.*<(.*)>/", $line, $ar_buf)) {
319
                        $feats = preg_split("/,/", strtolower(trim($ar_buf[1])), -1, PREG_SPLIT_NO_EMPTY);
320
                        foreach ($feats as $feat) {
321
                            if (($feat=="vmx") || ($feat=="svm")) {
322
                                $dev->setVirt($feat);
323
                                break 2;
324
                            }
325
                        }
326
                        break;
327
                    }
328
                } else break;
329
            }
330
        }
331
 
332
        $ncpu = $this->grabkey('hw.ncpu');
333
        if (is_null($ncpu) || (trim($ncpu) == "") || (!($ncpu >= 1)))
334
            $ncpu = 1;
335
        for ($ncpu ; $ncpu > 0 ; $ncpu--) {
336
            $this->sys->setCpus($dev);
337
        }
338
    }
339
 
340
    /**
341
     * SCSI devices
342
     * get the scsi device information out of dmesg
343
     *
344
     * @return void
345
     */
346
    protected function scsi()
347
    {
348
        foreach ($this->readdmesg() as $line) {
2976 rexy 349
            if (preg_match($this->_SCSIRegExp1, $line, $ar_buf) && (sizeof($ar_buf) > 2)) {
2770 rexy 350
                $dev = new HWDevice();
351
                $dev->setName($ar_buf[1].": ".trim($ar_buf[2]));
352
                $this->sys->setScsiDevices($dev);
2976 rexy 353
            } elseif (preg_match($this->_SCSIRegExp2, $line, $ar_buf) && (sizeof($ar_buf) > 1)) {
2770 rexy 354
                /* duplication security */
355
                $notwas = true;
356
                foreach ($this->sys->getScsiDevices() as $finddev) {
357
                    if ($notwas && (substr($finddev->getName(), 0, strpos($finddev->getName(), ': ')) == $ar_buf[1])) {
358
                        if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS) {
359
                            if (isset($ar_buf[3]) && ($ar_buf[3]==="G")) {
360
                                $finddev->setCapacity($ar_buf[2] * 1024 * 1024 * 1024);
2976 rexy 361
                            } elseif (isset($ar_buf[2])) {
2770 rexy 362
                                $finddev->setCapacity($ar_buf[2] * 1024 * 1024);
363
                            }
364
                        }
365
                        $notwas = false;
366
                        break;
367
                    }
368
                }
369
                if ($notwas) {
370
                    $dev = new HWDevice();
371
                    $dev->setName($ar_buf[1]);
372
                    if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS) {
373
                        if (isset($ar_buf[3]) && ($ar_buf[3]==="G")) {
374
                                $dev->setCapacity($ar_buf[2] * 1024 * 1024 * 1024);
2976 rexy 375
                            } elseif (isset($ar_buf[2])) {
2770 rexy 376
                                $dev->setCapacity($ar_buf[2] * 1024 * 1024);
377
                            }
378
                    }
379
                    $this->sys->setScsiDevices($dev);
380
                }
2976 rexy 381
            } elseif (preg_match($this->_SCSIRegExp3, $line, $ar_buf) && (sizeof($ar_buf) > 1)) {
2770 rexy 382
                /* duplication security */
383
                $notwas = true;
384
                foreach ($this->sys->getScsiDevices() as $finddev) {
385
                    if ($notwas && (substr($finddev->getName(), 0, strpos($finddev->getName(), ': ')) == $ar_buf[1])) {
386
                        if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS
387
                           && defined('PSI_SHOW_DEVICES_SERIAL') && PSI_SHOW_DEVICES_SERIAL) {
2976 rexy 388
                            if (isset($ar_buf[2])) $finddev->setSerial(trim($ar_buf[2]));
2770 rexy 389
                        }
390
                        $notwas = false;
391
                        break;
392
                    }
393
                }
394
                if ($notwas) {
395
                    $dev = new HWDevice();
396
                    $dev->setName($ar_buf[1]);
397
                    if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS
398
                       && defined('PSI_SHOW_DEVICES_SERIAL') && PSI_SHOW_DEVICES_SERIAL) {
2976 rexy 399
                        if (isset($ar_buf[2])) $dev->setSerial(trim($ar_buf[2]));
2770 rexy 400
                    }
401
                    $this->sys->setScsiDevices($dev);
402
                }
403
            }
404
        }
405
        /* cleaning */
406
        foreach ($this->sys->getScsiDevices() as $finddev) {
407
                    if (strpos($finddev->getName(), ': ') !== false)
408
                        $finddev->setName(substr(strstr($finddev->getName(), ': '), 2));
409
        }
410
    }
411
 
412
    /**
413
     * parsing the output of pciconf command
414
     *
415
     * @return Array
416
     */
417
    protected function pciconf()
418
    {
419
        $arrResults = array();
420
        $intS = 0;
421
        if (CommonFunctions::executeProgram("pciconf", "-lv", $strBuf, PSI_DEBUG)) {
422
            $arrTemp = array();
423
            $arrBlocks = preg_split("/\n\S/", $strBuf, -1, PREG_SPLIT_NO_EMPTY);
424
            foreach ($arrBlocks as $strBlock) {
425
                $arrLines = preg_split("/\n/", $strBlock, -1, PREG_SPLIT_NO_EMPTY);
426
                $vend = null;
427
                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)) {
429
                        $arrTemp[$intS] = 'Class '.$arrParts[1].': Device '.$arrParts[3].':'.$arrParts[2];
430
                        $vend = '';
431
                    } elseif (preg_match("/(.*) = '(.*)'/", $strLine, $arrParts)) {
432
                        if (trim($arrParts[1]) == "vendor") {
433
                            $vend = trim($arrParts[2]);
434
                        } elseif (trim($arrParts[1]) == "device") {
435
                            if (($vend !== null) && ($vend !== '')) {
436
                                $arrTemp[$intS] = $vend." - ".trim($arrParts[2]);
437
                            } else {
438
                                $arrTemp[$intS] = trim($arrParts[2]);
439
                                $vend = '';
440
                            }
441
                        }
442
                    }
443
                }
444
                if ($vend !== null) {
445
                    $intS++;
446
                }
447
            }
448
            foreach ($arrTemp as $name) {
449
                $dev = new HWDevice();
450
                $dev->setName($name);
451
                $arrResults[] = $dev;
452
            }
453
        }
454
 
455
        return $arrResults;
456
    }
457
 
458
    /**
459
     * PCI devices
460
     * get the pci device information out of dmesg
461
     *
462
     * @return void
463
     */
464
    protected function pci()
465
    {
466
        if ((!$results = Parser::lspci(false)) && (!$results = $this->pciconf())) {
467
            foreach ($this->readdmesg() as $line) {
2976 rexy 468
                if (preg_match($this->_PCIRegExp1, $line, $ar_buf) && (sizeof($ar_buf) > 2)) {
2770 rexy 469
                    $dev = new HWDevice();
470
                    $dev->setName($ar_buf[1].": ".$ar_buf[2]);
471
                    $results[] = $dev;
2976 rexy 472
                } elseif (preg_match($this->_PCIRegExp2, $line, $ar_buf) && (sizeof($ar_buf) > 2)) {
2770 rexy 473
                    $dev = new HWDevice();
474
                    $dev->setName($ar_buf[1].": ".$ar_buf[2]);
475
                    $results[] = $dev;
476
                }
477
            }
478
        }
479
        foreach ($results as $dev) {
480
            $this->sys->setPciDevices($dev);
481
        }
482
    }
483
 
484
    /**
485
     * IDE devices
486
     * get the ide device information out of dmesg
487
     *
488
     * @return void
489
     */
490
    protected function ide()
491
    {
492
        foreach ($this->readdmesg() as $line) {
493
            if (preg_match('/^(ad[0-9]+): (.*)MB <(.*)> (.*) (.*)/', $line, $ar_buf)) {
494
                $dev = new HWDevice();
495
                $dev->setName($ar_buf[1].": ".trim($ar_buf[3]));
496
                if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS) {
497
                    $dev->setCapacity($ar_buf[2] * 1024 * 1024);
498
                }
499
                $this->sys->setIdeDevices($dev);
500
            } elseif (preg_match('/^(acd[0-9]+): (.*) <(.*)> (.*)/', $line, $ar_buf)) {
501
                $dev = new HWDevice();
502
                $dev->setName($ar_buf[1].": ".trim($ar_buf[3]));
503
                $this->sys->setIdeDevices($dev);
504
            } elseif (preg_match('/^(ada[0-9]+): <(.*)> (.*)/', $line, $ar_buf)) {
505
                $dev = new HWDevice();
506
                $dev->setName($ar_buf[1].": ".trim($ar_buf[2]));
507
                $this->sys->setIdeDevices($dev);
508
            } elseif (preg_match('/^(ada[0-9]+): (.*)MB \((.*)\)/', $line, $ar_buf)) {
509
                /* duplication security */
510
                $notwas = true;
511
                foreach ($this->sys->getIdeDevices() as $finddev) {
512
                    if ($notwas && (substr($finddev->getName(), 0, strpos($finddev->getName(), ': ')) == $ar_buf[1])) {
513
                        if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS) {
514
                            $finddev->setCapacity($ar_buf[2] * 1024 * 1024);
515
                        }
516
                        $notwas = false;
517
                        break;
518
                    }
519
                }
520
                if ($notwas) {
521
                    $dev = new HWDevice();
522
                    $dev->setName($ar_buf[1]);
523
                    if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS) {
524
                        $dev->setCapacity($ar_buf[2] * 1024 * 1024);
525
                    }
526
                    $this->sys->setIdeDevices($dev);
527
                }
528
            } elseif (preg_match('/^(ada[0-9]+): Serial Number (.*)/', $line, $ar_buf)) {
529
                /* duplication security */
530
                $notwas = true;
531
                foreach ($this->sys->getIdeDevices() as $finddev) {
532
                    if ($notwas && (substr($finddev->getName(), 0, strpos($finddev->getName(), ': ')) == $ar_buf[1])) {
533
                        if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS
534
                           && defined('PSI_SHOW_DEVICES_SERIAL') && PSI_SHOW_DEVICES_SERIAL) {
535
                            $finddev->setSerial(trim($ar_buf[2]));
536
                        }
537
                        $notwas = false;
538
                        break;
539
                    }
540
                }
541
                if ($notwas) {
542
                    $dev = new HWDevice();
543
                    $dev->setName($ar_buf[1]);
544
                    if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS
545
                       && defined('PSI_SHOW_DEVICES_SERIAL') && PSI_SHOW_DEVICES_SERIAL) {
546
                        $finddev->setSerial(trim($ar_buf[2]));
547
                    }
548
                    $this->sys->setIdeDevices($dev);
549
                }
550
            }
551
        }
552
        /* cleaning */
553
        foreach ($this->sys->getIdeDevices() as $finddev) {
554
                    if (strpos($finddev->getName(), ': ') !== false)
555
                        $finddev->setName(substr(strstr($finddev->getName(), ': '), 2));
556
        }
557
    }
558
 
559
    /**
560
     * Physical memory information and Swap Space information
561
     *
562
     * @return void
563
     */
564
    protected function memory()
565
    {
566
        if (PSI_OS == 'FreeBSD' || PSI_OS == 'OpenBSD') {
567
            // vmstat on fbsd 4.4 or greater outputs kbytes not hw.pagesize
568
            // I should probably add some version checking here, but for now
569
            // we only support fbsd 4.4
570
            $pagesize = 1024;
571
        } else {
572
            $pagesize = $this->grabkey('hw.pagesize');
573
        }
574
        if (CommonFunctions::executeProgram('vmstat', '', $vmstat, PSI_DEBUG)) {
575
            $lines = preg_split("/\n/", $vmstat, -1, PREG_SPLIT_NO_EMPTY);
576
            $ar_buf = preg_split("/\s+/", trim($lines[2]), 19);
577
            if (PSI_OS == 'NetBSD' || PSI_OS == 'DragonFly') {
578
                $this->sys->setMemFree($ar_buf[4] * 1024);
579
            } else {
580
                $this->sys->setMemFree($ar_buf[4] * $pagesize);
581
            }
582
            $this->sys->setMemTotal($this->grabkey('hw.physmem'));
583
            $this->sys->setMemUsed($this->sys->getMemTotal() - $this->sys->getMemFree());
584
 
585
            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);
587
                foreach ($lines as $line) {
588
                    $ar_buf = preg_split("/\s+/", $line, 6);
589
                    if (($ar_buf[0] != 'Total') && ($ar_buf[0] != 'Device')) {
590
                        $dev = new DiskDevice();
591
                        $dev->setMountPoint($ar_buf[0]);
592
                        $dev->setName("SWAP");
593
                        $dev->setFsType('swap');
594
                        $dev->setTotal($ar_buf[1] * 1024);
595
                        $dev->setUsed($ar_buf[2] * 1024);
596
                        $dev->setFree($dev->getTotal() - $dev->getUsed());
597
                        $this->sys->setSwapDevices($dev);
598
                    }
599
                }
600
            }
601
        }
602
    }
603
 
604
    /**
605
     * USB devices
606
     * get the ide device information out of dmesg
607
     *
608
     * @return void
609
     */
610
    protected function usb()
611
    {
2976 rexy 612
        $notwas = true;
613
        if ((PSI_OS == 'FreeBSD') && CommonFunctions::executeProgram('usbconfig', '', $bufr, false)) {
614
            $lines = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
615
            foreach ($lines as $line) {
616
                if (preg_match('/^(ugen[0-9]+\.[0-9]+): <([^,]*)(.*)> at (usbus[0-9]+)/', $line, $ar_buf)) {
617
                    $notwas = false;
618
                    $dev = new HWDevice();
619
                    $dev->setName($ar_buf[2]);
620
                    $this->sys->setUSBDevices($dev);
621
                }
622
            }
623
        }
624
        if ($notwas) foreach ($this->readdmesg() as $line) {
2770 rexy 625
//            if (preg_match('/^(ugen[0-9\.]+): <(.*)> (.*) (.*)/', $line, $ar_buf)) {
626
//                    $dev->setName($ar_buf[1].": ".$ar_buf[2]);
627
            if (preg_match('/^(u[a-z]+[0-9]+): <([^,]*)(.*)> on (usbus[0-9]+)/', $line, $ar_buf)) {
628
                    $dev = new HWDevice();
629
                    $dev->setName($ar_buf[2]);
630
                    $this->sys->setUSBDevices($dev);
631
            }
632
        }
633
    }
634
 
635
    /**
636
     * filesystem information
637
     *
638
     * @return void
639
     */
640
    protected function filesystems()
641
    {
642
        $arrResult = Parser::df();
643
        foreach ($arrResult as $dev) {
644
            $this->sys->setDiskDevices($dev);
645
        }
646
    }
647
 
648
    /**
649
     * Distribution
650
     *
651
     * @return void
652
     */
653
    protected function distro()
654
    {
655
        if (CommonFunctions::executeProgram('uname', '-s', $result, PSI_DEBUG)) {
656
            $this->sys->setDistribution($result);
657
        }
658
    }
659
 
660
    /**
661
     * get the information
662
     *
663
     * @see PSI_Interface_OS::build()
664
     *
665
     * @return Void
666
     */
667
    public function build()
668
    {
669
        if (!$this->blockname || $this->blockname==='vitals') {
670
            $this->distro();
671
            $this->hostname();
672
            $this->kernel();
673
            $this->_users();
674
            $this->loadavg();
675
        }
676
        if (!$this->blockname || $this->blockname==='hardware') {
677
            $this->cpuinfo();
678
            $this->pci();
679
            $this->ide();
680
            $this->scsi();
681
            $this->usb();
682
        }
683
        if (!$this->blockname || $this->blockname==='memory') {
684
            $this->memory();
685
        }
686
        if (!$this->blockname || $this->blockname==='filesystem') {
687
            $this->filesystems();
688
        }
689
    }
690
}