Subversion Repositories ALCASAR

Rev

Rev 325 | Rev 3037 | 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
 
2
/**
3
// phpSysInfo - A PHP System Information Script
3
 * FreeBSD System Class
-
 
4
 *
4
// http://phpsysinfo.sourceforge.net/
5
 * PHP version 5
5
 
6
 *
-
 
7
 * @category  PHP
6
// This program is free software; you can redistribute it and/or
8
 * @package   PSI FreeBSD OS class
7
// modify it under the terms of the GNU General Public License
9
 * @author    Michael Cramer <BigMichi1@users.sourceforge.net>
8
// as published by the Free Software Foundation; either version 2
10
 * @copyright 2009 phpSysInfo
9
// of the License, 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
10
 
-
 
11
// This program is distributed in the hope that it will be useful,
12
 * @version   SVN: $Id: class.FreeBSD.inc.php 696 2012-09-09 11:24:04Z namiltd $
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * @link      http://phpsysinfo.sourceforge.net
-
 
14
 */
-
 
15
 /**
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * FreeBSD sysinfo class
14
// GNU General Public License for more details.
17
 * get all the required information from FreeBSD system
15
 
18
 *
-
 
19
 * @category  PHP
16
// You should have received a copy of the GNU General Public License
20
 * @package   PSI FreeBSD OS class
17
// along with this program; if not, write to the Free Software
21
 * @author    Michael Cramer <BigMichi1@users.sourceforge.net>
18
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22
 * @copyright 2009 phpSysInfo
19
 
-
 
20
// $Id: class.FreeBSD.inc.php,v 1.17 2006/04/18 16:22:26 bigmichi1 Exp $
23
 * @license   http://opensource.org/licenses/gpl-2.0.php GNU General Public License version 2, or (at your option) any later version
21
if (!defined('IN_PHPSYSINFO')) {
24
 * @version   Release: 3.0
22
    die("No Hacking");
25
 * @link      http://phpsysinfo.sourceforge.net
23
}
26
 */
24
 
-
 
25
require_once(APP_ROOT . '/includes/os/class.BSD.common.inc.php');
27
class FreeBSD extends BSDCommon
26
 
28
{
27
class sysinfo extends bsd_common {
-
 
28
  var $cpu_regexp   = "";
29
    /**
29
  var $scsi_regexp1 = "";
30
     * define the regexp for log parser
30
  var $scsi_regexp2 = "";
31
     */
31
  var $cpu_regexp2  = "";
32
    public function __construct($blockname = false)
32
  
33
    {
33
  // Our contstructor
34
        parent::__construct($blockname);
34
  // this function is run on the initialization of this class
35
        $this->setCPURegExp1("/CPU: (.*) \((.*)-MHz (.*)\)/");
35
  function sysinfo () {
-
 
36
    $this->bsd_common();
-
 
37
    $this->cpu_regexp = "CPU: (.*) \((.*)-MHz (.*)\)";
36
        $this->setCPURegExp2("/(.*) ([0-9]+) ([0-9]+) ([0-9]+) ([0-9]+)/");
38
    $this->scsi_regexp1 = "^(.*): <(.*)> .*SCSI.*device";
37
        $this->setSCSIRegExp1("/^(.*): <(.*)> .*SCSI.*device/");
39
    $this->scsi_regexp2 = "^(da[0-9]): (.*)MB ";
38
        $this->setSCSIRegExp2("/^(da[0-9]+): (.*)MB /");
40
    $this->cpu_regexp2 = "/(.*) ([0-9]+) ([0-9]+) ([0-9]+) ([0-9]+)/";
39
        $this->setSCSIRegExp3("/^(da[0-9]+|cd[0-9]+): Serial Number (.*)/");
-
 
40
        $this->setPCIRegExp1("/(.*): <(.*)>(.*) pci[0-9]+$/");
-
 
41
        $this->setPCIRegExp2("/(.*): <(.*)>.* at [.0-9]+ irq/");
41
  } 
42
    }
42
 
43
 
-
 
44
    /**
-
 
45
     * UpTime
43
  function get_sys_ticks () {
46
     * time the system is running
-
 
47
     *
-
 
48
     * @return void
-
 
49
     */
-
 
50
    private function _uptime()
-
 
51
    {
44
    $s = explode(' ', $this->grab_key('kern.boottime'));
52
        $s = preg_split('/ /', $this->grabkey('kern.boottime'));
45
    $a = ereg_replace('{ ', '', $s[3]);
53
        $a = preg_replace('/,/', '', $s[3]);
46
    $sys_ticks = time() - $a;
54
        $this->sys->setUptime(time() - $a);
47
    return $sys_ticks;
-
 
48
  } 
55
    }
49
 
56
 
-
 
57
    /**
50
  function network () {
58
     * get network information
-
 
59
     *
51
    $netstat = execute_program('netstat', '-nibd | grep Link');
60
     * @return void
-
 
61
     */
52
    $lines = explode("\n", $netstat);
62
    private function _network()
-
 
63
    {
53
    $results = array();
64
        $dev = null;
-
 
65
        if (CommonFunctions::executeProgram('netstat', '-nibd', $netstat, PSI_DEBUG)) {
-
 
66
            $lines = preg_split("/\n/", $netstat, -1, PREG_SPLIT_NO_EMPTY);
54
    for ($i = 0, $max = sizeof($lines); $i < $max; $i++) {
67
            foreach ($lines as $line) {
55
      $ar_buf = preg_split("/\s+/", $lines[$i]);
68
                $ar_buf = preg_split("/\s+/", $line);
56
      if (!empty($ar_buf[0])) {
69
                if (!empty($ar_buf[0])) {
-
 
70
                    if (preg_match('/^<Link/i', $ar_buf[2])) {
57
        $results[$ar_buf[0]] = array();
71
                        $dev = new NetDevice();
58
 
-
 
-
 
72
                        $dev->setName($ar_buf[0]);
-
 
73
                        if ((strlen($ar_buf[3]) < 17) && ($ar_buf[0] != $ar_buf[3])) { /* no MAC or dev name*/
-
 
74
                            if (isset($ar_buf[11]) && (trim($ar_buf[11]) != '')) { /* Idrop column exist*/
-
 
75
                              $dev->setTxBytes($ar_buf[9]);
-
 
76
                              $dev->setRxBytes($ar_buf[6]);
-
 
77
                              $dev->setErrors($ar_buf[4] + $ar_buf[8]);
-
 
78
                              $dev->setDrops($ar_buf[11] + $ar_buf[5]);
59
        if (strlen($ar_buf[3]) < 15) {
79
                            } else {
60
          $results[$ar_buf[0]]['rx_bytes'] = $ar_buf[5];
80
                              $dev->setTxBytes($ar_buf[8]);
61
          $results[$ar_buf[0]]['rx_packets'] = $ar_buf[3];
81
                              $dev->setRxBytes($ar_buf[5]);
-
 
82
                              $dev->setErrors($ar_buf[4] + $ar_buf[7]);
62
          $results[$ar_buf[0]]['rx_errs'] = $ar_buf[4];
83
                              $dev->setDrops($ar_buf[10]);
-
 
84
                            }
-
 
85
                        } else {
-
 
86
                            if (isset($ar_buf[12]) && (trim($ar_buf[12]) != '')) { /* Idrop column exist*/
63
          $results[$ar_buf[0]]['rx_drop'] = $ar_buf[10];
87
                              $dev->setTxBytes($ar_buf[10]);
64
 
-
 
65
          $results[$ar_buf[0]]['tx_bytes'] = $ar_buf[8];
88
                              $dev->setRxBytes($ar_buf[7]);
-
 
89
                              $dev->setErrors($ar_buf[5] + $ar_buf[9]);
-
 
90
                              $dev->setDrops($ar_buf[12] + $ar_buf[6]);
-
 
91
                            } else {
66
          $results[$ar_buf[0]]['tx_packets'] = $ar_buf[6];
92
                              $dev->setTxBytes($ar_buf[9]);
67
          $results[$ar_buf[0]]['tx_errs'] = $ar_buf[7];
93
                              $dev->setRxBytes($ar_buf[6]);
-
 
94
                              $dev->setErrors($ar_buf[5] + $ar_buf[8]);
68
          $results[$ar_buf[0]]['tx_drop'] = $ar_buf[10];
95
                              $dev->setDrops($ar_buf[11]);
-
 
96
                            }
-
 
97
                        }
-
 
98
                        if (defined('PSI_SHOW_NETWORK_INFOS') && (PSI_SHOW_NETWORK_INFOS) && (CommonFunctions::executeProgram('ifconfig', $ar_buf[0].' 2>/dev/null', $bufr2, PSI_DEBUG))) {
-
 
99
                            $bufe2 = preg_split("/\n/", $bufr2, -1, PREG_SPLIT_NO_EMPTY);
-
 
100
                            foreach ($bufe2 as $buf2) {
-
 
101
                                if (preg_match('/^\s+ether\s+(\S+)/i', $buf2, $ar_buf2)) {
-
 
102
                                    if (!defined('PSI_HIDE_NETWORK_MACADDR') || !PSI_HIDE_NETWORK_MACADDR) $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').preg_replace('/:/', '-', strtoupper($ar_buf2[1])));
-
 
103
                                } elseif (preg_match('/^\s+inet\s+(\S+)\s+netmask/i', $buf2, $ar_buf2)) {
-
 
104
                                    $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$ar_buf2[1]);
-
 
105
                                } elseif ((preg_match('/^\s+inet6\s+([^\s%]+)\s+prefixlen/i', $buf2, $ar_buf2)
-
 
106
                                      || preg_match('/^\s+inet6\s+([^\s%]+)%\S+\s+prefixlen/i', $buf2, $ar_buf2))
-
 
107
                                      && ($ar_buf2[1]!="::") && !preg_match('/^fe80::/i', $ar_buf2[1])) {
-
 
108
                                    $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').strtolower($ar_buf2[1]));
-
 
109
                                } elseif (preg_match('/^\s+media:\s+/i', $buf2) && preg_match('/[\(\s](\d+)(G*)base/i', $buf2, $ar_buf2)) {
-
 
110
                                    if (isset($ar_buf2[2]) && strtoupper($ar_buf2[2])=="G") {
-
 
111
                                        $unit = "G";
-
 
112
                                    } else {
-
 
113
                                        $unit = "M";
-
 
114
                                    }
-
 
115
                                    if (preg_match('/[<\s]([^\s<]+)-duplex/i', $buf2, $ar_buf3))
-
 
116
                                        $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$ar_buf2[1].$unit.'b/s '.strtolower($ar_buf3[1]));
-
 
117
                                    else
-
 
118
                                        $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$ar_buf2[1].$unit.'b/s');
-
 
119
                                }
-
 
120
                            }
-
 
121
                        }
-
 
122
                        $this->sys->setNetDevices($dev);
-
 
123
                    }
-
 
124
                }
-
 
125
            }
-
 
126
        }
-
 
127
    }
69
 
128
 
-
 
129
    /**
-
 
130
     * get icon name and distro extended check
-
 
131
     *
-
 
132
     * @return void
-
 
133
     */
-
 
134
    private function _distroicon()
-
 
135
    {
-
 
136
        if (extension_loaded('pfSense') && CommonFunctions::rfts('/etc/version', $version, 1, 4096, false) && (trim($version) != '')) { // pfSense detection
70
          $results[$ar_buf[0]]['errs'] = $ar_buf[4] + $ar_buf[7];
137
            $this->sys->setDistribution('pfSense '. trim($version));
71
          $results[$ar_buf[0]]['drop'] = $ar_buf[10];
138
            $this->sys->setDistributionIcon('pfSense.png');
72
        } else {
139
        } else {
73
          $results[$ar_buf[0]]['rx_bytes'] = $ar_buf[6];
140
            $this->sys->setDistributionIcon('FreeBSD.png');
-
 
141
        }
-
 
142
    }
-
 
143
 
-
 
144
    /**
74
          $results[$ar_buf[0]]['rx_packets'] = $ar_buf[4];
145
     * extend the memory information with additional values
-
 
146
     *
-
 
147
     * @return void
-
 
148
     */
-
 
149
    private function _memoryadditional()
-
 
150
    {
75
          $results[$ar_buf[0]]['rx_errs'] = $ar_buf[5];
151
        $pagesize = $this->grabkey("hw.pagesize");
76
          $results[$ar_buf[0]]['rx_drop'] = $ar_buf[11];
152
        $this->sys->setMemCache($this->grabkey("vm.stats.vm.v_cache_count") * $pagesize);
-
 
153
        $this->sys->setMemApplication(($this->grabkey("vm.stats.vm.v_active_count") + $this->grabkey("vm.stats.vm.v_wire_count")) * $pagesize);
-
 
154
        $this->sys->setMemBuffer($this->sys->getMemUsed() - $this->sys->getMemApplication() - $this->sys->getMemCache());
-
 
155
    }
77
 
156
 
-
 
157
    /**
-
 
158
     * Processes
-
 
159
     *
-
 
160
     * @return void
-
 
161
     */
-
 
162
    protected function _processes()
-
 
163
    {
-
 
164
        if (CommonFunctions::executeProgram('ps', 'aux', $bufr, PSI_DEBUG)) {
-
 
165
            $lines = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
-
 
166
            $processes['*'] = 0;
-
 
167
            foreach ($lines as $line) {
-
 
168
                if (preg_match("/^\S+\s+\d+\s+\S+\s+\S+\s+\d+\s+\d+\s+\S+\s+(\w)/", $line, $ar_buf)) {
-
 
169
                    $processes['*']++;
78
          $results[$ar_buf[0]]['tx_bytes'] = $ar_buf[9];
170
                    $state = $ar_buf[1];
79
          $results[$ar_buf[0]]['tx_packets'] = $ar_buf[7];
171
                    if ($state == 'L') $state = 'D'; //linux format
80
          $results[$ar_buf[0]]['tx_errs'] = $ar_buf[8];
172
                    elseif ($state == 'I') $state = 'S';
81
          $results[$ar_buf[0]]['tx_drop'] = $ar_buf[11];
173
                    if (isset($processes[$state])) {
82
 
-
 
83
          $results[$ar_buf[0]]['errs'] = $ar_buf[5] + $ar_buf[8];
174
                        $processes[$state]++;
-
 
175
                    } else {
84
          $results[$ar_buf[0]]['drop'] = $ar_buf[11];
176
                        $processes[$state] = 1;
-
 
177
                    }
85
        } 
178
                }
86
      } 
179
            }
-
 
180
            if ($processes['*'] > 0) {
-
 
181
                $this->sys->setProcesses($processes);
87
    } 
182
            }
88
    return $results;
183
        }
89
  } 
184
    }
90
 
185
 
-
 
186
    /**
91
  function distroicon () {
187
     * get the information
-
 
188
     *
92
    $result = 'FreeBSD.png';
189
     * @see BSDCommon::build()
-
 
190
     *
93
    return($result);
191
     * @return Void
94
  }
192
     */
-
 
193
    public function build()
95
  
194
    {
96
  function memory_additional($results) {
195
        parent::build();
97
    $pagesize = $this->grab_key("hw.pagesize");
196
        if (!$this->blockname || $this->blockname==='vitals') {
98
    $results['ram']['cached'] = $this->grab_key("vm.stats.vm.v_cache_count") * $pagesize / 1024;
197
            $this->_distroicon();
99
    $results['ram']['cached_percent'] = round( $results['ram']['cached'] * 100 / $results['ram']['total']);
198
            $this->_uptime();
100
    $results['ram']['app'] = $this->grab_key("vm.stats.vm.v_active_count") * $pagesize / 1024;
199
            $this->_processes();
-
 
200
        }
101
    $results['ram']['app_percent'] = round( $results['ram']['app'] * 100 / $results['ram']['total']);
201
        if (!$this->blockname || $this->blockname==='network') {
102
    $results['ram']['buffers'] = $results['ram']['used'] - $results['ram']['app'] - $results['ram']['cached'];
202
            $this->_network();
-
 
203
        }
103
    $results['ram']['buffers_percent'] = round( $results['ram']['buffers'] * 100 / $results['ram']['total']);
204
        if (!$this->blockname || $this->blockname==='memory') {
104
    return $results;
205
            $this->_memoryadditional();
105
  }
206
        }
106
} 
207
    }
107
 
208
}
108
?>
-