Subversion Repositories ALCASAR

Rev

Rev 2976 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log

Rev Author Line No. Line
2770 rexy 1
<?php
2
/**
3
 * FreeBSD System Class
4
 *
5
 * PHP version 5
6
 *
7
 * @category  PHP
8
 * @package   PSI FreeBSD 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.FreeBSD.inc.php 696 2012-09-09 11:24:04Z namiltd $
13
 * @link      http://phpsysinfo.sourceforge.net
14
 */
15
 /**
16
 * FreeBSD sysinfo class
17
 * get all the required information from FreeBSD system
18
 *
19
 * @category  PHP
20
 * @package   PSI FreeBSD 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 FreeBSD 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("/(.*) ([0-9]+) ([0-9]+) ([0-9]+) ([0-9]+)/");
37
        $this->setSCSIRegExp1("/^(.*): <(.*)> .*SCSI.*device/");
38
        $this->setSCSIRegExp2("/^(da[0-9]+): (.*)MB /");
39
        $this->setSCSIRegExp3("/^(da[0-9]+|cd[0-9]+): Serial Number (.*)/");
40
        $this->setPCIRegExp1("/(.*): <(.*)>(.*) pci[0-9]+$/");
41
        $this->setPCIRegExp2("/(.*): <(.*)>.* at [.0-9]+ irq/");
42
    }
325 richard 43
 
2770 rexy 44
    /**
45
     * get network information
46
     *
47
     * @return void
48
     */
49
    private function _network()
50
    {
51
        $dev = null;
52
        if (CommonFunctions::executeProgram('netstat', '-nibd', $netstat, PSI_DEBUG)) {
53
            $lines = preg_split("/\n/", $netstat, -1, PREG_SPLIT_NO_EMPTY);
54
            foreach ($lines as $line) {
55
                $ar_buf = preg_split("/\s+/", $line);
56
                if (!empty($ar_buf[0])) {
57
                    if (preg_match('/^<Link/i', $ar_buf[2])) {
58
                        $dev = new NetDevice();
59
                        $dev->setName($ar_buf[0]);
60
                        if ((strlen($ar_buf[3]) < 17) && ($ar_buf[0] != $ar_buf[3])) { /* no MAC or dev name*/
61
                            if (isset($ar_buf[11]) && (trim($ar_buf[11]) != '')) { /* Idrop column exist*/
62
                              $dev->setTxBytes($ar_buf[9]);
63
                              $dev->setRxBytes($ar_buf[6]);
64
                              $dev->setErrors($ar_buf[4] + $ar_buf[8]);
65
                              $dev->setDrops($ar_buf[11] + $ar_buf[5]);
66
                            } else {
67
                              $dev->setTxBytes($ar_buf[8]);
68
                              $dev->setRxBytes($ar_buf[5]);
69
                              $dev->setErrors($ar_buf[4] + $ar_buf[7]);
70
                              $dev->setDrops($ar_buf[10]);
71
                            }
72
                        } else {
73
                            if (isset($ar_buf[12]) && (trim($ar_buf[12]) != '')) { /* Idrop column exist*/
74
                              $dev->setTxBytes($ar_buf[10]);
75
                              $dev->setRxBytes($ar_buf[7]);
76
                              $dev->setErrors($ar_buf[5] + $ar_buf[9]);
77
                              $dev->setDrops($ar_buf[12] + $ar_buf[6]);
78
                            } else {
79
                              $dev->setTxBytes($ar_buf[9]);
80
                              $dev->setRxBytes($ar_buf[6]);
81
                              $dev->setErrors($ar_buf[5] + $ar_buf[8]);
82
                              $dev->setDrops($ar_buf[11]);
83
                            }
84
                        }
85
                        if (defined('PSI_SHOW_NETWORK_INFOS') && (PSI_SHOW_NETWORK_INFOS) && (CommonFunctions::executeProgram('ifconfig', $ar_buf[0].' 2>/dev/null', $bufr2, PSI_DEBUG))) {
86
                            $bufe2 = preg_split("/\n/", $bufr2, -1, PREG_SPLIT_NO_EMPTY);
87
                            foreach ($bufe2 as $buf2) {
88
                                if (preg_match('/^\s+ether\s+(\S+)/i', $buf2, $ar_buf2)) {
89
                                    if (!defined('PSI_HIDE_NETWORK_MACADDR') || !PSI_HIDE_NETWORK_MACADDR) $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').preg_replace('/:/', '-', strtoupper($ar_buf2[1])));
90
                                } elseif (preg_match('/^\s+inet\s+(\S+)\s+netmask/i', $buf2, $ar_buf2)) {
91
                                    $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$ar_buf2[1]);
92
                                } elseif ((preg_match('/^\s+inet6\s+([^\s%]+)\s+prefixlen/i', $buf2, $ar_buf2)
93
                                      || preg_match('/^\s+inet6\s+([^\s%]+)%\S+\s+prefixlen/i', $buf2, $ar_buf2))
94
                                      && ($ar_buf2[1]!="::") && !preg_match('/^fe80::/i', $ar_buf2[1])) {
95
                                    $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').strtolower($ar_buf2[1]));
96
                                } elseif (preg_match('/^\s+media:\s+/i', $buf2) && preg_match('/[\(\s](\d+)(G*)base/i', $buf2, $ar_buf2)) {
97
                                    if (isset($ar_buf2[2]) && strtoupper($ar_buf2[2])=="G") {
98
                                        $unit = "G";
99
                                    } else {
100
                                        $unit = "M";
101
                                    }
102
                                    if (preg_match('/[<\s]([^\s<]+)-duplex/i', $buf2, $ar_buf3))
103
                                        $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$ar_buf2[1].$unit.'b/s '.strtolower($ar_buf3[1]));
104
                                    else
105
                                        $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$ar_buf2[1].$unit.'b/s');
106
                                }
107
                            }
108
                        }
109
                        $this->sys->setNetDevices($dev);
110
                    }
111
                }
112
            }
113
        }
114
    }
325 richard 115
 
2770 rexy 116
    /**
117
     * get icon name and distro extended check
118
     *
119
     * @return void
120
     */
121
    private function _distroicon()
122
    {
2976 rexy 123
        if (CommonFunctions::rfts('/etc/version', $version, 1, 4096, false) && (($version=trim($version)) != '')) {
124
            if (extension_loaded('pfSense')) { // pfSense detection
125
                $this->sys->setDistribution('pfSense '. $version);
126
                $this->sys->setDistributionIcon('pfSense.png');
127
            } elseif (preg_match('/^FreeNAS/i', $version)) { // FreeNAS detection
128
                $this->sys->setDistribution($version);
129
                $this->sys->setDistributionIcon('FreeNAS.png');
130
            } else {
131
                $this->sys->setDistributionIcon('FreeBSD.png');
132
            }
325 richard 133
        } else {
2770 rexy 134
            $this->sys->setDistributionIcon('FreeBSD.png');
135
        }
136
    }
325 richard 137
 
2770 rexy 138
    /**
139
     * extend the memory information with additional values
140
     *
141
     * @return void
142
     */
143
    private function _memoryadditional()
144
    {
145
        $pagesize = $this->grabkey("hw.pagesize");
146
        $this->sys->setMemCache($this->grabkey("vm.stats.vm.v_cache_count") * $pagesize);
147
        $this->sys->setMemApplication(($this->grabkey("vm.stats.vm.v_active_count") + $this->grabkey("vm.stats.vm.v_wire_count")) * $pagesize);
148
        $this->sys->setMemBuffer($this->sys->getMemUsed() - $this->sys->getMemApplication() - $this->sys->getMemCache());
149
    }
325 richard 150
 
2770 rexy 151
    /**
152
     * Processes
153
     *
154
     * @return void
155
     */
156
    protected function _processes()
157
    {
158
        if (CommonFunctions::executeProgram('ps', 'aux', $bufr, PSI_DEBUG)) {
159
            $lines = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
160
            $processes['*'] = 0;
161
            foreach ($lines as $line) {
162
                if (preg_match("/^\S+\s+\d+\s+\S+\s+\S+\s+\d+\s+\d+\s+\S+\s+(\w)/", $line, $ar_buf)) {
163
                    $processes['*']++;
164
                    $state = $ar_buf[1];
165
                    if ($state == 'L') $state = 'D'; //linux format
166
                    elseif ($state == 'I') $state = 'S';
167
                    if (isset($processes[$state])) {
168
                        $processes[$state]++;
169
                    } else {
170
                        $processes[$state] = 1;
171
                    }
172
                }
173
            }
174
            if ($processes['*'] > 0) {
175
                $this->sys->setProcesses($processes);
176
            }
177
        }
178
    }
325 richard 179
 
2770 rexy 180
    /**
181
     * get the information
182
     *
183
     * @see BSDCommon::build()
184
     *
3037 rexy 185
     * @return void
2770 rexy 186
     */
187
    public function build()
188
    {
189
        parent::build();
190
        if (!$this->blockname || $this->blockname==='vitals') {
191
            $this->_distroicon();
192
            $this->_processes();
193
        }
3037 rexy 194
        if (!$this->blockname || $this->blockname==='memory') {
195
            $this->_memoryadditional();
196
        }
2770 rexy 197
        if (!$this->blockname || $this->blockname==='network') {
198
            $this->_network();
199
        }
200
    }
201
}