Subversion Repositories ALCASAR

Rev

Rev 3037 | 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');
3100 rexy 130
            } elseif (preg_match('/^TrueNAS/i', $version)) { // TrueNAS detection
131
                $this->sys->setDistribution($version);
132
                $this->sys->setDistributionIcon('TrueNAS.png');
2976 rexy 133
            } else {
134
                $this->sys->setDistributionIcon('FreeBSD.png');
135
            }
325 richard 136
        } else {
2770 rexy 137
            $this->sys->setDistributionIcon('FreeBSD.png');
138
        }
139
    }
325 richard 140
 
2770 rexy 141
    /**
142
     * extend the memory information with additional values
143
     *
144
     * @return void
145
     */
146
    private function _memoryadditional()
147
    {
148
        $pagesize = $this->grabkey("hw.pagesize");
149
        $this->sys->setMemCache($this->grabkey("vm.stats.vm.v_cache_count") * $pagesize);
150
        $this->sys->setMemApplication(($this->grabkey("vm.stats.vm.v_active_count") + $this->grabkey("vm.stats.vm.v_wire_count")) * $pagesize);
151
        $this->sys->setMemBuffer($this->sys->getMemUsed() - $this->sys->getMemApplication() - $this->sys->getMemCache());
152
    }
325 richard 153
 
2770 rexy 154
    /**
155
     * Processes
156
     *
157
     * @return void
158
     */
159
    protected function _processes()
160
    {
161
        if (CommonFunctions::executeProgram('ps', 'aux', $bufr, PSI_DEBUG)) {
162
            $lines = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
163
            $processes['*'] = 0;
164
            foreach ($lines as $line) {
165
                if (preg_match("/^\S+\s+\d+\s+\S+\s+\S+\s+\d+\s+\d+\s+\S+\s+(\w)/", $line, $ar_buf)) {
166
                    $processes['*']++;
167
                    $state = $ar_buf[1];
168
                    if ($state == 'L') $state = 'D'; //linux format
169
                    elseif ($state == 'I') $state = 'S';
170
                    if (isset($processes[$state])) {
171
                        $processes[$state]++;
172
                    } else {
173
                        $processes[$state] = 1;
174
                    }
175
                }
176
            }
177
            if ($processes['*'] > 0) {
178
                $this->sys->setProcesses($processes);
179
            }
180
        }
181
    }
325 richard 182
 
2770 rexy 183
    /**
184
     * get the information
185
     *
186
     * @see BSDCommon::build()
187
     *
3037 rexy 188
     * @return void
2770 rexy 189
     */
190
    public function build()
191
    {
192
        parent::build();
193
        if (!$this->blockname || $this->blockname==='vitals') {
194
            $this->_distroicon();
195
            $this->_processes();
196
        }
3037 rexy 197
        if (!$this->blockname || $this->blockname==='memory') {
198
            $this->_memoryadditional();
199
        }
2770 rexy 200
        if (!$this->blockname || $this->blockname==='network') {
201
            $this->_network();
202
        }
203
    }
204
}