Subversion Repositories ALCASAR

Rev

Rev 2770 | Details | Compare with Previous | Last modification | View Log

Rev Author Line No. Line
2770 rexy 1
<?php
2
/**
3
 * DragonFly System Class
4
 *
5
 * PHP version 5
6
 *
7
 * @category  PHP
8
 * @package   PSI DragonFly 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.DragonFly.inc.php 287 2009-06-26 12:11:59Z bigmichi1 $
13
 * @link      http://phpsysinfo.sourceforge.net
14
 */
15
 /**
16
 * DragonFly sysinfo class
17
 * get all the required information from DragonFly system
18
 *
19
 * @category  PHP
20
 * @package   PSI DragonFly OS class
21
 * @author    Michael Cramer <BigMichi1@users.sourceforge.net>
22
 * @copyright 2009 phpSysInfo
23
 * @license   http://opensource.org/licenses/gpl-2.0.php GNU General Public License version 2, or (at your option) any later version
24
 * @version   Release: 3.0
25
 * @link      http://phpsysinfo.sourceforge.net
26
 */
27
class DragonFly extends BSDCommon
28
{
29
    /**
30
     * define the regexp for log parser
31
     */
32
    public function __construct($blockname = false)
33
    {
34
        parent::__construct($blockname);
3037 rexy 35
        $this->setCPURegExp1("/^cpu(.*)\, (.*) MHz/\n/^CPU: (.*) \((.*)-MHz (.*)\)/"); // multiple regexp separated by \n
2770 rexy 36
        $this->setCPURegExp2("/^(.*) at scsibus.*: <(.*)> .*/");
37
        $this->setSCSIRegExp2("/^(da[0-9]+): (.*)MB /");
38
        $this->setPCIRegExp1("/(.*): <(.*)>(.*) (pci|legacypci)[0-9]+$/");
39
        $this->setPCIRegExp2("/(.*): <(.*)>.* at [0-9\.]+$/");
40
    }
41
 
42
    /**
43
     * get network information
44
     *
45
     * @return void
46
     */
47
    private function _network()
48
    {
49
        CommonFunctions::executeProgram('netstat', '-nbdi | cut -c1-25,44- | grep "^[a-z]*[0-9][ \t].*Link"', $netstat_b);
50
        CommonFunctions::executeProgram('netstat', '-ndi | cut -c1-25,44- | grep "^[a-z]*[0-9][ \t].*Link"', $netstat_n);
51
        $lines_b = preg_split("/\n/", $netstat_b, -1, PREG_SPLIT_NO_EMPTY);
52
        $lines_n = preg_split("/\n/", $netstat_n, -1, PREG_SPLIT_NO_EMPTY);
53
        for ($i = 0, $max = sizeof($lines_b); $i < $max; $i++) {
54
            $ar_buf_b = preg_split("/\s+/", $lines_b[$i]);
55
            $ar_buf_n = preg_split("/\s+/", $lines_n[$i]);
56
            if (!empty($ar_buf_b[0]) && (!empty($ar_buf_n[5]) || ($ar_buf_n[5] === "0"))) {
57
                $dev = new NetDevice();
58
                $dev->setName($ar_buf_b[0]);
59
                $dev->setTxBytes($ar_buf_b[8]);
60
                $dev->setRxBytes($ar_buf_b[5]);
61
                $dev->setErrors($ar_buf_n[4] + $ar_buf_n[6]);
62
                $dev->setDrops($ar_buf_n[8]);
63
                $this->sys->setNetDevices($dev);
64
            }
65
        }
66
    }
67
 
68
    /**
69
     * get the ide information
70
     *
71
     * @return void
72
     */
73
    protected function ide()
74
    {
75
        foreach ($this->readdmesg() as $line) {
76
            if (preg_match('/^(.*): (.*) <(.*)> at (ata[0-9]+\-(.*)) (.*)/', $line, $ar_buf)) {
77
                $dev = new HWDevice();
78
                $dev->setName($ar_buf[1]);
79
                if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS && !preg_match("/^acd[0-9]+(.*)/", $ar_buf[1])) {
80
                    $dev->setCapacity($ar_buf[2] * 1024 * 1024);
81
                }
82
                $this->sys->setIdeDevices($dev);
83
            }
84
        }
85
    }
86
 
87
    /**
88
     * get icon name
89
     *
90
     * @return void
91
     */
92
    private function _distroicon()
93
    {
94
        $this->sys->setDistributionIcon('DragonFly.png');
95
    }
96
 
97
    /**
98
     * Processes
99
     *
100
     * @return void
101
     */
102
    protected function _processes()
103
    {
104
        if (CommonFunctions::executeProgram('ps', 'aux', $bufr, PSI_DEBUG)) {
105
            $lines = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
106
            $processes['*'] = 0;
107
            foreach ($lines as $line) {
108
                if (preg_match("/^\S+\s+\d+\s+\S+\s+\S+\s+\d+\s+\d+\s+\S+\s+(\w)/", $line, $ar_buf)) {
109
                    $processes['*']++;
110
                    $state = $ar_buf[1];
111
                    if ($state == 'I') $state = 'S'; //linux format
112
                    if (isset($processes[$state])) {
113
                        $processes[$state]++;
114
                    } else {
115
                        $processes[$state] = 1;
116
                    }
117
                }
118
            }
119
            if ($processes['*'] > 0) {
120
                $this->sys->setProcesses($processes);
121
            }
122
        }
123
    }
124
 
125
    /**
126
     * get the information
127
     *
128
     * @see BSDCommon::build()
129
     *
3037 rexy 130
     * @return void
2770 rexy 131
     */
132
    public function build()
133
    {
134
        parent::build();
135
        if (!$this->blockname || $this->blockname==='vitals') {
136
            $this->_distroicon();
137
            $this->_processes();
138
        }
139
        if (!$this->blockname || $this->blockname==='network') {
140
            $this->_network();
141
        }
142
    }
143
}