Subversion Repositories ALCASAR

Rev

Rev 2976 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log

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