Subversion Repositories ALCASAR

Rev

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

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