Subversion Repositories ALCASAR

Rev

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

Rev 2770 Rev 3037
1
<?php
1
<?php
2
/**
2
/**
3
 * NetBSD System Class
3
 * NetBSD System Class
4
 *
4
 *
5
 * PHP version 5
5
 * PHP version 5
6
 *
6
 *
7
 * @category  PHP
7
 * @category  PHP
8
 * @package   PSI NetBSD OS class
8
 * @package   PSI NetBSD 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.NetBSD.inc.php 287 2009-06-26 12:11:59Z bigmichi1 $
12
 * @version   SVN: $Id: class.NetBSD.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
 * NetBSD sysinfo class
16
 * NetBSD sysinfo class
17
 * get all the required information from NetBSD systems
17
 * get all the required information from NetBSD systems
18
 *
18
 *
19
 * @category  PHP
19
 * @category  PHP
20
 * @package   PSI NetBSD OS class
20
 * @package   PSI NetBSD 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 NetBSD extends BSDCommon
27
class NetBSD 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/");
36
        $this->setCPURegExp2("/user = (.*), nice = (.*), sys = (.*), intr = (.*), idle = (.*)/");
36
        $this->setCPURegExp2("/user = (.*), nice = (.*), sys = (.*), intr = (.*), idle = (.*)/");
37
        $this->setSCSIRegExp1("/^(.*) at scsibus.*: <(.*)> .*/");
37
        $this->setSCSIRegExp1("/^(.*) at scsibus.*: <(.*)> .*/");
38
        $this->setSCSIRegExp2("/^(sd[0-9]+): (.*)([MG])B,/");
38
        $this->setSCSIRegExp2("/^(sd[0-9]+): (.*)([MG])B,/");
39
        $this->setPCIRegExp1("/(.*) at pci[0-9]+ dev [0-9]* function [0-9]*: (.*)$/");
39
        $this->setPCIRegExp1("/(.*) at pci[0-9]+ dev [0-9]* function [0-9]*: (.*)$/");
40
        $this->setPCIRegExp2("/\"(.*)\" (.*).* at [.0-9]+ irq/");
40
        $this->setPCIRegExp2("/\"(.*)\" (.*).* at [.0-9]+ irq/");
41
    }
41
    }
42
 
42
 
43
    /**
43
    /**
44
     * UpTime
-
 
45
     * time the system is running
-
 
46
     *
-
 
47
     * @return void
-
 
48
     */
-
 
49
    private function _uptime()
-
 
50
    {
-
 
51
        $a = $this->grabkey('kern.boottime');
-
 
52
        $this->sys->setUptime(time() - $a);
-
 
53
    }
-
 
54
 
-
 
55
    /**
-
 
56
     * get network information
44
     * get network information
57
     *
45
     *
58
     * @return void
46
     * @return void
59
     */
47
     */
60
    private function _network()
48
    private function _network()
61
    {
49
    {
62
        CommonFunctions::executeProgram('netstat', '-nbdi | cut -c1-25,44- | grep "^[a-z]*[0-9][ \t].*Link"', $netstat_b);
50
        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);
51
        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);
52
        $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);
53
        $lines_n = preg_split("/\n/", $netstat_n, -1, PREG_SPLIT_NO_EMPTY);
66
        for ($i = 0, $max = sizeof($lines_b); $i < $max; $i++) {
54
        for ($i = 0, $max = sizeof($lines_b); $i < $max; $i++) {
67
            $ar_buf_b = preg_split("/\s+/", $lines_b[$i]);
55
            $ar_buf_b = preg_split("/\s+/", $lines_b[$i]);
68
            $ar_buf_n = preg_split("/\s+/", $lines_n[$i]);
56
            $ar_buf_n = preg_split("/\s+/", $lines_n[$i]);
69
            if (!empty($ar_buf_b[0]) && (!empty($ar_buf_n[3]) || ($ar_buf_n[3] === "0"))) {
57
            if (!empty($ar_buf_b[0]) && (!empty($ar_buf_n[3]) || ($ar_buf_n[3] === "0"))) {
70
                $dev = new NetDevice();
58
                $dev = new NetDevice();
71
                $dev->setName($ar_buf_b[0]);
59
                $dev->setName($ar_buf_b[0]);
72
                $dev->setTxBytes($ar_buf_b[4]);
60
                $dev->setTxBytes($ar_buf_b[4]);
73
                $dev->setRxBytes($ar_buf_b[3]);
61
                $dev->setRxBytes($ar_buf_b[3]);
74
                $dev->setDrops($ar_buf_n[8]);
62
                $dev->setDrops($ar_buf_n[8]);
75
                $dev->setErrors($ar_buf_n[4] + $ar_buf_n[6]);
63
                $dev->setErrors($ar_buf_n[4] + $ar_buf_n[6]);
76
                if (defined('PSI_SHOW_NETWORK_INFOS') && (PSI_SHOW_NETWORK_INFOS) && (CommonFunctions::executeProgram('ifconfig', $ar_buf_b[0].' 2>/dev/null', $bufr2, PSI_DEBUG))) {
64
                if (defined('PSI_SHOW_NETWORK_INFOS') && (PSI_SHOW_NETWORK_INFOS) && (CommonFunctions::executeProgram('ifconfig', $ar_buf_b[0].' 2>/dev/null', $bufr2, PSI_DEBUG))) {
77
                    $speedinfo = "";
65
                    $speedinfo = "";
78
                    $bufe2 = preg_split("/\n/", $bufr2, -1, PREG_SPLIT_NO_EMPTY);
66
                    $bufe2 = preg_split("/\n/", $bufr2, -1, PREG_SPLIT_NO_EMPTY);
79
                    foreach ($bufe2 as $buf2) {
67
                    foreach ($bufe2 as $buf2) {
80
                        if (preg_match('/^\s+address:\s+(\S+)/i', $buf2, $ar_buf2)) {
68
                        if (preg_match('/^\s+address:\s+(\S+)/i', $buf2, $ar_buf2)) {
81
                            if (!defined('PSI_HIDE_NETWORK_MACADDR') || !PSI_HIDE_NETWORK_MACADDR) $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').preg_replace('/:/', '-', strtoupper($ar_buf2[1])));
69
                            if (!defined('PSI_HIDE_NETWORK_MACADDR') || !PSI_HIDE_NETWORK_MACADDR) $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').preg_replace('/:/', '-', strtoupper($ar_buf2[1])));
82
                        } elseif (preg_match('/^\s+inet\s+(\S+)\s+netmask/i', $buf2, $ar_buf2)) {
70
                        } elseif (preg_match('/^\s+inet\s+(\S+)\s+netmask/i', $buf2, $ar_buf2)) {
83
                            $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$ar_buf2[1]);
71
                            $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$ar_buf2[1]);
84
                        } elseif ((preg_match('/^\s+inet6\s+([^\s%]+)\s+prefixlen/i', $buf2, $ar_buf2)
72
                        } elseif ((preg_match('/^\s+inet6\s+([^\s%]+)\s+prefixlen/i', $buf2, $ar_buf2)
85
                              || preg_match('/^\s+inet6\s+([^\s%]+)%\S+\s+prefixlen/i', $buf2, $ar_buf2))
73
                              || preg_match('/^\s+inet6\s+([^\s%]+)%\S+\s+prefixlen/i', $buf2, $ar_buf2))
86
                              && ($ar_buf2[1]!="::") && !preg_match('/^fe80::/i', $ar_buf2[1])) {
74
                              && ($ar_buf2[1]!="::") && !preg_match('/^fe80::/i', $ar_buf2[1])) {
87
                            $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').strtolower($ar_buf2[1]));
75
                            $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').strtolower($ar_buf2[1]));
88
                        } elseif (preg_match('/^\s+media:\s+/i', $buf2) && preg_match('/[\(\s](\d+)(G*)base/i', $buf2, $ar_buf2)) {
76
                        } elseif (preg_match('/^\s+media:\s+/i', $buf2) && preg_match('/[\(\s](\d+)(G*)base/i', $buf2, $ar_buf2)) {
89
                            if (isset($ar_buf2[2]) && strtoupper($ar_buf2[2])=="G") {
77
                            if (isset($ar_buf2[2]) && strtoupper($ar_buf2[2])=="G") {
90
                                $unit = "G";
78
                                $unit = "G";
91
                            } else {
79
                            } else {
92
                                $unit = "M";
80
                                $unit = "M";
93
                            }
81
                            }
94
                            if (preg_match('/\s(\S+)-duplex/i', $buf2, $ar_buf3))
82
                            if (preg_match('/\s(\S+)-duplex/i', $buf2, $ar_buf3))
95
                                $speedinfo = $ar_buf2[1].$unit.'b/s '.strtolower($ar_buf3[1]);
83
                                $speedinfo = $ar_buf2[1].$unit.'b/s '.strtolower($ar_buf3[1]);
96
                            else
84
                            else
97
                                $speedinfo = $ar_buf2[1].$unit.'b/s';
85
                                $speedinfo = $ar_buf2[1].$unit.'b/s';
98
                        }
86
                        }
99
                    }
87
                    }
100
                    if ($speedinfo != "") $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$speedinfo);
88
                    if ($speedinfo != "") $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$speedinfo);
101
                }
89
                }
102
                $this->sys->setNetDevices($dev);
90
                $this->sys->setNetDevices($dev);
103
            }
91
            }
104
        }
92
        }
105
    }
93
    }
106
 
94
 
107
    /**
95
    /**
108
     * IDE information
96
     * IDE information
109
     *
97
     *
110
     * @return void
98
     * @return void
111
     */
99
     */
112
    protected function ide()
100
    protected function ide()
113
    {
101
    {
114
        foreach ($this->readdmesg() as $line) {
102
        foreach ($this->readdmesg() as $line) {
115
            if (preg_match('/^(.*) at (pciide|wdc|atabus|atapibus)[0-9]+ (.*): <(.*)>/', $line, $ar_buf)
103
            if (preg_match('/^(.*) at (pciide|wdc|atabus|atapibus)[0-9]+ (.*): <(.*)>/', $line, $ar_buf)
116
               || preg_match('/^(.*) at (pciide|wdc|atabus|atapibus)[0-9]+ /', $line, $ar_buf)) {
104
               || preg_match('/^(.*) at (pciide|wdc|atabus|atapibus)[0-9]+ /', $line, $ar_buf)) {
117
                $dev = new HWDevice();
105
                $dev = new HWDevice();
118
                if (isset($ar_buf[4])) {
106
                if (isset($ar_buf[4])) {
119
                    $dev->setName($ar_buf[4]);
107
                    $dev->setName($ar_buf[4]);
120
                } else {
108
                } else {
121
                    $dev->setName($ar_buf[1]);
109
                    $dev->setName($ar_buf[1]);
122
                    // now loop again and find the name
110
                    // now loop again and find the name
123
                    foreach ($this->readdmesg() as $line2) {
111
                    foreach ($this->readdmesg() as $line2) {
124
                        if (preg_match("/^(".$ar_buf[1]."): <(.*)>$/", $line2, $ar_buf_n)) {
112
                        if (preg_match("/^(".$ar_buf[1]."): <(.*)>$/", $line2, $ar_buf_n)) {
125
                            $dev->setName($ar_buf_n[2]);
113
                            $dev->setName($ar_buf_n[2]);
126
                            break;
114
                            break;
127
                        }
115
                        }
128
                    }
116
                    }
129
                }
117
                }
130
                if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS) {
118
                if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS) {
131
                    // now loop again and find the capacity
119
                    // now loop again and find the capacity
132
                    foreach ($this->readdmesg() as $line2) {
120
                    foreach ($this->readdmesg() as $line2) {
133
                        if (preg_match("/^(".$ar_buf[1]."): (.*), (.*), (.*)MB, .*$/", $line2, $ar_buf_n)) {
121
                        if (preg_match("/^(".$ar_buf[1]."): (.*), (.*), (.*)MB, .*$/", $line2, $ar_buf_n)) {
134
                            $dev->setCapacity($ar_buf_n[4] * 1024 * 1024);
122
                            $dev->setCapacity($ar_buf_n[4] * 1024 * 1024);
135
                            break;
123
                            break;
136
                        } elseif (preg_match("/^(".$ar_buf[1]."): (.*) MB, (.*), (.*), .*$/", $line2, $ar_buf_n)) {
124
                        } elseif (preg_match("/^(".$ar_buf[1]."): (.*) MB, (.*), (.*), .*$/", $line2, $ar_buf_n)) {
137
                            $dev->setCapacity($ar_buf_n[2] * 1024 * 1024);
125
                            $dev->setCapacity($ar_buf_n[2] * 1024 * 1024);
138
                            break;
126
                            break;
139
                        } elseif (preg_match("/^(".$ar_buf[1]."): (.*) GB, (.*), (.*), .*$/", $line2, $ar_buf_n)) {
127
                        } elseif (preg_match("/^(".$ar_buf[1]."): (.*) GB, (.*), (.*), .*$/", $line2, $ar_buf_n)) {
140
                            $dev->setCapacity($ar_buf_n[2] * 1024 * 1024 * 1024);
128
                            $dev->setCapacity($ar_buf_n[2] * 1024 * 1024 * 1024);
141
                            break;
129
                            break;
142
                        }
130
                        }
143
                    }
131
                    }
144
                }
132
                }
145
                $this->sys->setIdeDevices($dev);
133
                $this->sys->setIdeDevices($dev);
146
            }
134
            }
147
        }
135
        }
148
    }
136
    }
149
 
137
 
150
    /**
138
    /**
-
 
139
     * CPU information
-
 
140
     *
-
 
141
     * @return void
-
 
142
     */
-
 
143
    protected function cpuinfo()
-
 
144
    {
-
 
145
        $was = false;
-
 
146
        $cpuarray = array();
-
 
147
        foreach ($this->readdmesg() as $line) {
-
 
148
            if (preg_match("/^cpu([0-9])+: (.*)/", $line, $ar_buf)) {
-
 
149
                $was = true;
-
 
150
                $ar_buf[2] = trim($ar_buf[2]);
-
 
151
                if (preg_match("/^(.+), ([\d\.]+) MHz/", $ar_buf[2], $ar_buf2)) {
-
 
152
                    if (($model = trim($ar_buf2[1])) !== "") {
-
 
153
                        $cpuarray[$ar_buf[1]]['model'] = $model;
-
 
154
                    }
-
 
155
                    if (($speed = trim($ar_buf2[2])) > 0) {
-
 
156
                        $cpuarray[$ar_buf[1]]['speed'] = $speed;
-
 
157
                    }
-
 
158
                } elseif (preg_match("/^L2 cache (\d+) ([KM])B /", $ar_buf[2], $ar_buf2)) {
-
 
159
                    if ($ar_buf2[2]=="M") {
-
 
160
                        $cpuarray[$ar_buf[1]]['cache'] = $ar_buf2[1]*1024*1024;
-
 
161
                    } elseif ($ar_buf2[2]=="K") {
-
 
162
                        $cpuarray[$ar_buf[1]]['cache'] = $ar_buf2[1]*1024;
-
 
163
                    }
-
 
164
                }
-
 
165
            } elseif (!preg_match("/^cpu[0-9]+ /", $line) && $was) {
-
 
166
                break;
-
 
167
            }
-
 
168
        }
-
 
169
 
-
 
170
        $ncpu = $this->grabkey('hw.ncpu');
-
 
171
        if (($ncpu === "") || !($ncpu >= 1)) {
-
 
172
            $ncpu = 1;
-
 
173
        }
-
 
174
        $ncpu = max($ncpu, count($cpuarray));
-
 
175
 
-
 
176
        $model = $this->grabkey('machdep.cpu_brand');
-
 
177
        $model2 = $this->grabkey('hw.model');
-
 
178
        if ($cpuspeed = $this->grabkey('machdep.tsc_freq')) {
-
 
179
            $speed = round($cpuspeed / 1000000);
-
 
180
        } else {
-
 
181
            $speed = "";
-
 
182
        }
-
 
183
 
-
 
184
        for ($cpu = 0 ; $cpu < $ncpu ; $cpu++) {
-
 
185
            $dev = new CpuDevice();
-
 
186
 
-
 
187
            if (isset($cpuarray[$cpu]['model'])) {
-
 
188
                $dev->setModel($cpuarray[$cpu]['model']);
-
 
189
            } elseif ($model !== "") {
-
 
190
                $dev->setModel($model);
-
 
191
            } elseif ($model2 !== "") {
-
 
192
                $dev->setModel($model2);
-
 
193
            }
-
 
194
            if (isset($cpuarray[$cpu]['speed'])) {
-
 
195
                $dev->setCpuSpeed($cpuarray[$cpu]['speed']);
-
 
196
            } elseif ($speed !== "") {
-
 
197
                $dev->setCpuSpeed($speed);
-
 
198
            }
-
 
199
            if (isset($cpuarray[$cpu]['cache'])) {
-
 
200
                $dev->setCache($cpuarray[$cpu]['cache']);
-
 
201
            }
-
 
202
            if (($ncpu == 1) && PSI_LOAD_BAR) {
-
 
203
                $dev->setLoad($this->cpuusage());
-
 
204
            }
-
 
205
            $this->sys->setCpus($dev);
-
 
206
        }
-
 
207
    }
-
 
208
 
-
 
209
    /**
151
     * get icon name
210
     * get icon name
152
     *
211
     *
153
     * @return void
212
     * @return void
154
     */
213
     */
155
    private function _distroicon()
214
    private function _distroicon()
156
    {
215
    {
157
        $this->sys->setDistributionIcon('NetBSD.png');
216
        $this->sys->setDistributionIcon('NetBSD.png');
158
    }
217
    }
159
 
218
 
160
    /**
219
    /**
161
     * Processes
220
     * Processes
162
     *
221
     *
163
     * @return void
222
     * @return void
164
     */
223
     */
165
    protected function _processes()
224
    protected function _processes()
166
    {
225
    {
167
        if (CommonFunctions::executeProgram('ps', 'aux', $bufr, PSI_DEBUG)) {
226
        if (CommonFunctions::executeProgram('ps', 'aux', $bufr, PSI_DEBUG)) {
168
            $lines = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
227
            $lines = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
169
            $processes['*'] = 0;
228
            $processes['*'] = 0;
170
            foreach ($lines as $line) {
229
            foreach ($lines as $line) {
171
                if (preg_match("/^\S+\s+\d+\s+\S+\s+\S+\s+\d+\s+\d+\s+\S+\s+(\w)/", $line, $ar_buf)) {
230
                if (preg_match("/^\S+\s+\d+\s+\S+\s+\S+\s+\d+\s+\d+\s+\S+\s+(\w)/", $line, $ar_buf)) {
172
                    $processes['*']++;
231
                    $processes['*']++;
173
                    $state = $ar_buf[1];
232
                    $state = $ar_buf[1];
174
                    if ($state == 'O') $state = 'R'; //linux format
233
                    if ($state == 'O') $state = 'R'; //linux format
175
                    elseif ($state == 'I') $state = 'S';
234
                    elseif ($state == 'I') $state = 'S';
176
                    if (isset($processes[$state])) {
235
                    if (isset($processes[$state])) {
177
                        $processes[$state]++;
236
                        $processes[$state]++;
178
                    } else {
237
                    } else {
179
                        $processes[$state] = 1;
238
                        $processes[$state] = 1;
180
                    }
239
                    }
181
                }
240
                }
182
            }
241
            }
183
            if ($processes['*'] > 0) {
242
            if ($processes['*'] > 0) {
184
                $this->sys->setProcesses($processes);
243
                $this->sys->setProcesses($processes);
185
            }
244
            }
186
        }
245
        }
187
    }
246
    }
188
 
247
 
189
    /**
248
    /**
190
     * get the information
249
     * get the information
191
     *
250
     *
192
     * @see BSDCommon::build()
251
     * @see BSDCommon::build()
193
     *
252
     *
194
     * @return Void
253
     * @return void
195
     */
254
     */
196
    public function build()
255
    public function build()
197
    {
256
    {
198
        parent::build();
257
        parent::build();
199
        if (!$this->blockname || $this->blockname==='vitals') {
258
        if (!$this->blockname || $this->blockname==='vitals') {
200
            $this->_distroicon();
259
            $this->_distroicon();
201
            $this->_uptime();
-
 
202
            $this->_processes();
260
            $this->_processes();
203
        }
261
        }
204
        if (!$this->blockname || $this->blockname==='network') {
262
        if (!$this->blockname || $this->blockname==='network') {
205
            $this->_network();
263
            $this->_network();
206
        }
264
        }
207
    }
265
    }
208
}
266
}
209
 
267