Subversion Repositories ALCASAR

Rev

Rev 325 | Rev 2976 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log

Rev 325 Rev 2770
Line 1... Line 1...
1
<?php 
1
<?php
-
 
2
/**
-
 
3
 * OpenBSD System Class
-
 
4
 *
-
 
5
 * PHP version 5
-
 
6
 *
-
 
7
 * @category  PHP
-
 
8
 * @package   PSI OpenBSD 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.OpenBSD.inc.php 621 2012-07-29 18:49:04Z namiltd $
-
 
13
 * @link      http://phpsysinfo.sourceforge.net
-
 
14
 */
-
 
15
 /**
-
 
16
 * OpenBSD sysinfo class
-
 
17
 * get all the required information from OpenBSD systems
-
 
18
 *
-
 
19
 * @category  PHP
-
 
20
 * @package   PSI OpenBSD 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 OpenBSD extends BSDCommon
-
 
28
{
-
 
29
    /**
-
 
30
     * define the regexp for log parser
-
 
31
     */
-
 
32
    public function __construct($blockname = false)
-
 
33
    {
-
 
34
        parent::__construct($blockname);
-
 
35
//        $this->setCPURegExp1("/^cpu(.*) (.*) MHz/");
-
 
36
        $this->setCPURegExp2("/(.*),(.*),(.*),(.*),(.*)/");
-
 
37
        $this->setSCSIRegExp1("/^(.*) at scsibus.*: <(.*)> .*/");
-
 
38
        $this->setSCSIRegExp2("/^(sd[0-9]+): (.*)MB,/");
-
 
39
        $this->setPCIRegExp1("/(.*) at pci[0-9]+ .* \"(.*)\"/");
-
 
40
        $this->setPCIRegExp2("/\"(.*)\" (.*).* at [.0-9]+ irq/");
-
 
41
    }
2
 
42
 
-
 
43
    /**
-
 
44
     * UpTime
3
// phpSysInfo - A PHP System Information Script
45
     * time the system is running
-
 
46
     *
-
 
47
     * @return void
-
 
48
     */
-
 
49
    private function _uptime()
-
 
50
    {
-
 
51
        $a = $this->grabkey('kern.boottime');
4
// http://phpsysinfo.sourceforge.net/
52
        $this->sys->setUptime(time() - $a);
-
 
53
    }
5
 
54
 
-
 
55
    /**
-
 
56
     * get network information
-
 
57
     *
-
 
58
     * @return void
-
 
59
     */
-
 
60
    private function _network()
-
 
61
    {
-
 
62
        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);
-
 
64
        $lines_b = preg_split("/\n/", $netstat_b, -1, PREG_SPLIT_NO_EMPTY);
6
// This program is free software; you can redistribute it and/or
65
        $lines_n = preg_split("/\n/", $netstat_n, -1, PREG_SPLIT_NO_EMPTY);
7
// modify it under the terms of the GNU General Public License
66
        for ($i = 0, $max = sizeof($lines_b); $i < $max; $i++) {
8
// as published by the Free Software Foundation; either version 2
67
            $ar_buf_b = preg_split("/\s+/", $lines_b[$i]);
9
// of the License, or (at your option) any later version.
68
            $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"))) {
-
 
70
                $dev = new NetDevice();
-
 
71
                $dev->setName($ar_buf_b[0]);
-
 
72
                $dev->setTxBytes($ar_buf_b[4]);
-
 
73
                $dev->setRxBytes($ar_buf_b[3]);
-
 
74
                $dev->setErrors($ar_buf_n[4] + $ar_buf_n[6]);
-
 
75
                $dev->setDrops($ar_buf_n[8]);
-
 
76
                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 = "";
-
 
78
                    $bufe2 = preg_split("/\n/", $bufr2, -1, PREG_SPLIT_NO_EMPTY);
-
 
79
                    foreach ($bufe2 as $buf2) {
-
 
80
                        if (preg_match('/^\s+lladdr\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])));
-
 
82
                        } elseif (preg_match('/^\s+inet\s+(\S+)\s+netmask/i', $buf2, $ar_buf2)) {
-
 
83
                            $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$ar_buf2[1]);
-
 
84
                        } 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))
-
 
86
                              && ($ar_buf2[1]!="::") && !preg_match('/^fe80::/i', $ar_buf2[1])) {
-
 
87
                            $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)) {
-
 
89
                            if (isset($ar_buf2[2]) && strtoupper($ar_buf2[2])=="G") {
-
 
90
                                $unit = "G";
-
 
91
                            } else {
-
 
92
                                $unit = "M";
-
 
93
                            }
-
 
94
                            if (preg_match('/\s(\S+)-duplex/i', $buf2, $ar_buf3))
-
 
95
                                $speedinfo = $ar_buf2[1].$unit.'b/s '.strtolower($ar_buf3[1]);
-
 
96
                            else
-
 
97
                                $speedinfo = $ar_buf2[1].$unit.'b/s';
-
 
98
                        }
-
 
99
                    }
-
 
100
                    if ($speedinfo != "") $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$speedinfo);
-
 
101
                }
-
 
102
                $this->sys->setNetDevices($dev);
-
 
103
            }
-
 
104
        }
-
 
105
    }
10
 
106
 
-
 
107
    /**
-
 
108
     * IDE information
-
 
109
     *
-
 
110
     * @return void
-
 
111
     */
-
 
112
    protected function ide()
-
 
113
    {
-
 
114
        foreach ($this->readdmesg() as $line) {
-
 
115
            if (preg_match('/^(.*) at pciide[0-9]+ (.*): <(.*)>/', $line, $ar_buf)) {
-
 
116
                $dev = new HWDevice();
-
 
117
                $dev->setName($ar_buf[3]);
-
 
118
                if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS) {
11
// This program is distributed in the hope that it will be useful,
119
                    // now loop again and find the capacity
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of
120
                    foreach ($this->readdmesg() as $line2) {
-
 
121
                        if (preg_match("/^(".$ar_buf[1]."): (.*), (.*), (.*)MB, .*$/", $line2, $ar_buf_n)) {
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
122
                            $dev->setCapacity($ar_buf_n[4] * 1024 * 1024);
-
 
123
                            break;
-
 
124
                        }
-
 
125
                    }
-
 
126
                }
14
// GNU General Public License for more details.
127
                $this->sys->setIdeDevices($dev);
-
 
128
            }
-
 
129
        }
-
 
130
    }
15
 
131
 
-
 
132
    /**
-
 
133
     * get CPU information
-
 
134
     *
-
 
135
     * @return void
-
 
136
     */
-
 
137
    protected function cpuinfo()
-
 
138
    {
-
 
139
        $dev = new CpuDevice();
-
 
140
        $dev->setModel($this->grabkey('hw.model'));
-
 
141
        $dev->setCpuSpeed($this->grabkey('hw.cpuspeed'));
-
 
142
        $was = false;
-
 
143
        foreach ($this->readdmesg() as $line) {
16
// You should have received a copy of the GNU General Public License
144
            if (preg_match("/^cpu[0-9]+: (.*)/", $line, $ar_buf)) {
-
 
145
                $was = true;
-
 
146
                if (preg_match("/^cpu[0-9]+: (\d+)([KM])B (.*) L2 cache/", $line, $ar_buf2)) {
-
 
147
                    if ($ar_buf2[2]=="M") {
-
 
148
                        $dev->setCache($ar_buf2[1]*1024*1024);
-
 
149
                    } elseif ($ar_buf2[2]=="K") {
-
 
150
                        $dev->setCache($ar_buf2[1]*1024);
-
 
151
                    }
-
 
152
                } else {
-
 
153
                    $feats = preg_split("/,/", strtolower(trim($ar_buf[1])), -1, PREG_SPLIT_NO_EMPTY);
17
// along with this program; if not, write to the Free Software
154
                    foreach ($feats as $feat) {
-
 
155
                        if (($feat=="vmx") || ($feat=="svm")) {
-
 
156
                            $dev->setVirt($feat);
-
 
157
                        }
-
 
158
                    }
-
 
159
                }
-
 
160
            } elseif ($was) {
-
 
161
                break;
-
 
162
            }
-
 
163
        }
-
 
164
        $ncpu = $this->grabkey('hw.ncpu');
18
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
165
        if (is_null($ncpu) || (trim($ncpu) == "") || (!($ncpu >= 1)))
-
 
166
            $ncpu = 1;
-
 
167
        for ($ncpu ; $ncpu > 0 ; $ncpu--) {
-
 
168
            $this->sys->setCpus($dev);
-
 
169
        }
-
 
170
    }
-
 
171
 
-
 
172
    /**
-
 
173
     * get icon name
-
 
174
     *
-
 
175
     * @return void
-
 
176
     */
-
 
177
    private function _distroicon()
-
 
178
    {
-
 
179
        $this->sys->setDistributionIcon('OpenBSD.png');
-
 
180
    }
19
 
181
 
-
 
182
    /**
-
 
183
     * Processes
-
 
184
     *
-
 
185
     * @return void
-
 
186
     */
-
 
187
    protected function _processes()
-
 
188
    {
20
// $Id: class.OpenBSD.inc.php,v 1.21 2006/04/18 17:46:15 bigmichi1 Exp $
189
        if (CommonFunctions::executeProgram('ps', 'aux', $bufr, PSI_DEBUG)) {
-
 
190
            $lines = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
-
 
191
            $processes['*'] = 0;
-
 
192
            foreach ($lines as $line) {
-
 
193
                if (preg_match("/^\S+\s+\d+\s+\S+\s+\S+\s+\d+\s+\d+\s+\S+\s+(\w)/", $line, $ar_buf)) {
-
 
194
                    $processes['*']++;
-
 
195
                    $state = $ar_buf[1];
-
 
196
                    if ($state == 'I') $state = 'S'; //linux format
-
 
197
                    if (isset($processes[$state])) {
-
 
198
                        $processes[$state]++;
-
 
199
                    } else {
-
 
200
                        $processes[$state] = 1;
-
 
201
                    }
-
 
202
                }
-
 
203
            }
-
 
204
            if ($processes['*'] > 0) {
-
 
205
                $this->sys->setProcesses($processes);
-
 
206
            }
-
 
207
        }
-
 
208
    }
-
 
209
 
-
 
210
    /**
-
 
211
     * get the information
-
 
212
     *
21
if (!defined('IN_PHPSYSINFO')) {
213
     * @see BSDCommon::build()
-
 
214
     *
-
 
215
     * @return Void
-
 
216
     */
-
 
217
    public function build()
-
 
218
    {
22
    die("No Hacking");
219
        parent::build();
-
 
220
        if (!$this->blockname || $this->blockname==='vitals') {
-
 
221
            $this->_distroicon();
-
 
222
            $this->_uptime();
-
 
223
            $this->_processes();
-
 
224
        }
-
 
225
        if (!$this->blockname || $this->blockname==='network') {
-
 
226
            $this->_network();
-
 
227
        }
-
 
228
    }
23
}
229
}
24
 
-
 
25
require_once(APP_ROOT . '/includes/os/class.BSD.common.inc.php');
-
 
26
 
-
 
27
class sysinfo extends bsd_common {
-
 
28
  var $cpu_regexp   = "";
-
 
29
  var $scsi_regexp1 = "";
-
 
30
  var $scsi_regexp2 = "";
-
 
31
  var $cpu_regexp2  = "";
-
 
32
  
-
 
33
  // Our contstructor
-
 
34
  // this function is run on the initialization of this class
-
 
35
  function sysinfo () {
-
 
36
    $this->bsd_common();
-
 
37
    $this->cpu_regexp = "^cpu(.*) (.*) MHz";
-
 
38
    $this->scsi_regexp1 = "^(.*) at scsibus.*: <(.*)> .*";
-
 
39
    $this->scsi_regexp2 = "^(da[0-9]): (.*)MB ";
-
 
40
    $this->cpu_regexp2 = "/(.*),(.*),(.*),(.*),(.*)/";
-
 
41
    $this->pci_regexp1 = '/(.*) at pci[0-9] .* "(.*)"/';
-
 
42
    $this->pci_regexp2 = '/"(.*)" (.*).* at [.0-9]+ irq/';
-
 
43
  } 
-
 
44
 
-
 
45
  function get_sys_ticks () {
-
 
46
    $a = $this->grab_key('kern.boottime');
-
 
47
    $sys_ticks = time() - $a;
-
 
48
    return $sys_ticks;
-
 
49
  } 
-
 
50
 
-
 
51
  function network () {
-
 
52
    $netstat_b = execute_program('netstat', '-nbdi | cut -c1-25,44- | grep Link | grep -v \'* \'');
-
 
53
    $netstat_n = execute_program('netstat', '-ndi | cut -c1-25,44- | grep Link | grep -v \'* \'');
-
 
54
    $lines_b = explode("\n", $netstat_b);
-
 
55
    $lines_n = explode("\n", $netstat_n);
-
 
56
    $results = array();
-
 
57
    for ($i = 0, $max = sizeof($lines_b); $i < $max; $i++) {
-
 
58
      $ar_buf_b = preg_split("/\s+/", $lines_b[$i]);
-
 
59
      $ar_buf_n = preg_split("/\s+/", $lines_n[$i]);
-
 
60
      if (!empty($ar_buf_b[0]) && !empty($ar_buf_n[3])) {
-
 
61
        $results[$ar_buf_b[0]] = array();
-
 
62
 
-
 
63
        $results[$ar_buf_b[0]]['rx_bytes'] = $ar_buf_b[3];
-
 
64
        $results[$ar_buf_b[0]]['rx_packets'] = $ar_buf_n[3];
-
 
65
        $results[$ar_buf_b[0]]['rx_errs'] = $ar_buf_n[4];
-
 
66
        $results[$ar_buf_b[0]]['rx_drop'] = $ar_buf_n[8];
-
 
67
 
-
 
68
        $results[$ar_buf_b[0]]['tx_bytes'] = $ar_buf_b[4];
-
 
69
        $results[$ar_buf_b[0]]['tx_packets'] = $ar_buf_n[5];
-
 
70
        $results[$ar_buf_b[0]]['tx_errs'] = $ar_buf_n[6];
-
 
71
        $results[$ar_buf_b[0]]['tx_drop'] = $ar_buf_n[8];
-
 
72
 
-
 
73
        $results[$ar_buf_b[0]]['errs'] = $ar_buf_n[4] + $ar_buf_n[6];
-
 
74
        $results[$ar_buf_b[0]]['drop'] = $ar_buf_n[8];
-
 
75
      } 
-
 
76
    } 
-
 
77
    return $results;
-
 
78
  } 
-
 
79
  // get the ide device information out of dmesg
-
 
80
  function ide () {
-
 
81
    $results = array();
-
 
82
 
-
 
83
    $s = 0;
-
 
84
    for ($i = 0, $max = count($this->read_dmesg()); $i < $max; $i++) {
-
 
85
      $buf = $this->dmesg[$i];
-
 
86
      if (preg_match('/^(.*) at pciide[0-9] (.*): <(.*)>/', $buf, $ar_buf)) {
-
 
87
        $s = $ar_buf[1];
-
 
88
        $results[$s]['model'] = $ar_buf[3];
-
 
89
        $results[$s]['media'] = 'Hard Disk'; 
-
 
90
        // now loop again and find the capacity
-
 
91
        for ($j = 0, $max1 = count($this->read_dmesg()); $j < $max1; $j++) {
-
 
92
          $buf_n = $this->dmesg[$j];
-
 
93
          if (preg_match("/^($s): (.*), (.*), (.*)MB, .*$/", $buf_n, $ar_buf_n)) {
-
 
94
            $results[$s]['capacity'] = $ar_buf_n[4] * 2048 * 1.049;;
-
 
95
          } 
-
 
96
        } 
-
 
97
      } 
-
 
98
    } 
-
 
99
    asort($results);
-
 
100
    return $results;
-
 
101
  } 
-
 
102
 
-
 
103
  function distroicon () {
-
 
104
    $result = 'OpenBSD.png';
-
 
105
    return($result);
-
 
106
  }
-
 
107
  
-
 
108
} 
-
 
109
 
-
 
110
?>
-