Subversion Repositories ALCASAR

Rev

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

Rev 2770 Rev 3037
1
<?php
1
<?php
2
/**
2
/**
3
 * QNX System Class
3
 * QNX System Class
4
 *
4
 *
5
 * PHP version 5
5
 * PHP version 5
6
 *
6
 *
7
 * @category  PHP
7
 * @category  PHP
8
 * @package   PSI QNX OS class
8
 * @package   PSI QNX OS class
9
 * @author    Mieczyslaw Nalewaj <namiltd@users.sourceforge.net>
9
 * @author    Mieczyslaw Nalewaj <namiltd@users.sourceforge.net>
10
 * @copyright 2012 phpSysInfo
10
 * @copyright 2012 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.QNX.inc.php 687 2012-09-06 20:54:49Z namiltd $
12
 * @version   SVN: $Id: class.QNX.inc.php 687 2012-09-06 20:54:49Z namiltd $
13
 * @link      http://phpsysinfo.sourceforge.net
13
 * @link      http://phpsysinfo.sourceforge.net
14
 */
14
 */
15
 /**
15
 /**
16
 * QNX sysinfo class
16
 * QNX sysinfo class
17
 * get all the required information from QNX system
17
 * get all the required information from QNX system
18
 *
18
 *
19
 * @category  PHP
19
 * @category  PHP
20
 * @package   PSI QNX OS class
20
 * @package   PSI QNX OS class
21
 * @author    Mieczyslaw Nalewaj <namiltd@users.sourceforge.net>
21
 * @author    Mieczyslaw Nalewaj <namiltd@users.sourceforge.net>
22
 * @copyright 2012 phpSysInfo
22
 * @copyright 2012 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 QNX extends OS
27
class QNX extends OS
28
{
28
{
29
    /**
29
    /**
30
     * get the cpu information
30
     * get the cpu information
31
     *
31
     *
32
     * @return void
32
     * @return void
33
     */
33
     */
34
    protected function _cpuinfo()
34
    protected function _cpuinfo()
35
    {
35
    {
36
        if (CommonFunctions::executeProgram('pidin', 'info', $buf)
36
        if (CommonFunctions::executeProgram('pidin', 'info', $buf)
37
           && preg_match('/^Processor\d+: (.*)/m', $buf)) {
37
           && preg_match('/^Processor\d+: (.*)/m', $buf)) {
38
            $lines = preg_split("/\n/", $buf, -1, PREG_SPLIT_NO_EMPTY);
38
            $lines = preg_split("/\n/", $buf, -1, PREG_SPLIT_NO_EMPTY);
39
            foreach ($lines as $line) {
39
            foreach ($lines as $line) {
40
                if (preg_match('/^Processor\d+: (.+)/', $line, $proc)) {
40
                if (preg_match('/^Processor\d+: (.+)/', $line, $proc)) {
41
                    $dev = new CpuDevice();
41
                    $dev = new CpuDevice();
42
                    $dev->SetModel(trim($proc[1]));
42
                    $dev->SetModel(trim($proc[1]));
43
                    if (preg_match('/(\d+)MHz/', $proc[1], $mhz)) {
43
                    if (preg_match('/(\d+)MHz/', $proc[1], $mhz)) {
44
                        $dev->setCpuSpeed($mhz[1]);
44
                        $dev->setCpuSpeed($mhz[1]);
45
                    }
45
                    }
46
                    $this->sys->setCpus($dev);
46
                    $this->sys->setCpus($dev);
47
                }
47
                }
48
            }
48
            }
49
        }
49
        }
50
    }
50
    }
51
 
51
 
52
    /**
52
    /**
53
     * QNX Version
53
     * QNX Version
54
     *
54
     *
55
     * @return void
55
     * @return void
56
     */
56
     */
57
    private function _kernel()
57
    private function _kernel()
58
    {
58
    {
59
        if (CommonFunctions::executeProgram('uname', '-rvm', $ret)) {
59
        if (CommonFunctions::executeProgram('uname', '-rvm', $ret)) {
60
            $this->sys->setKernel($ret);
60
            $this->sys->setKernel($ret);
61
        }
61
        }
62
    }
62
    }
63
 
63
 
64
    /**
64
    /**
65
     * Distribution
65
     * Distribution
66
     *
66
     *
67
     * @return void
67
     * @return void
68
     */
68
     */
69
    protected function _distro()
69
    protected function _distro()
70
    {
70
    {
71
        if (CommonFunctions::executeProgram('uname', '-sr', $ret))
71
        if (CommonFunctions::executeProgram('uname', '-sr', $ret))
72
            $this->sys->setDistribution($ret);
72
            $this->sys->setDistribution($ret);
73
        else
73
        else
74
            $this->sys->setDistribution('QNX');
74
            $this->sys->setDistribution('QNX');
75
 
75
 
76
        $this->sys->setDistributionIcon('QNX.png');
76
        $this->sys->setDistributionIcon('QNX.png');
77
    }
77
    }
78
 
78
 
79
    /**
79
    /**
80
     * UpTime
80
     * UpTime
81
     * time the system is running
81
     * time the system is running
82
     *
82
     *
83
     * @return void
83
     * @return void
84
     */
84
     */
85
    private function _uptime()
85
    private function _uptime()
86
    {
86
    {
87
 
87
 
88
        if (CommonFunctions::executeProgram('pidin', 'info', $buf)
88
        if (CommonFunctions::executeProgram('pidin', 'info', $buf)
89
           && preg_match('/^.* BootTime:(.*)/', $buf, $bstart)
89
           && preg_match('/^.* BootTime:(.*)/', $buf, $bstart)
90
           && CommonFunctions::executeProgram('date', '', $bstop)) {
90
           && CommonFunctions::executeProgram('date', '', $bstop)) {
91
            /* default error handler */
91
            date_default_timezone_set('UTC');
92
            if (function_exists('errorHandlerPsi')) {
-
 
93
                restore_error_handler();
-
 
94
            }
-
 
95
            /* fatal errors only */
-
 
96
            $old_err_rep = error_reporting();
-
 
97
            error_reporting(E_ERROR);
-
 
98
 
-
 
99
            $uptime = strtotime($bstop)-strtotime($bstart[1]);
92
            $uptime = strtotime($bstop)-strtotime($bstart[1]);
100
            if ($uptime > 0) $this->sys->setUptime($uptime);
93
            if ($uptime > 0) $this->sys->setUptime($uptime);
101
 
-
 
102
            /* restore error level */
-
 
103
            error_reporting($old_err_rep);
-
 
104
            /* restore error handler */
-
 
105
            if (function_exists('errorHandlerPsi')) {
-
 
106
                set_error_handler('errorHandlerPsi');
-
 
107
            }
-
 
108
        }
94
        }
109
    }
95
    }
110
 
96
 
111
    /**
97
    /**
112
     * Number of Users
98
     * Number of Users
113
     *
99
     *
114
     * @return void
100
     * @return void
115
     */
101
     */
116
    protected function _users()
102
    protected function _users()
117
    {
103
    {
118
        $this->sys->setUsers(1);
104
        $this->sys->setUsers(1);
119
    }
105
    }
120
 
106
 
121
    /**
107
    /**
122
     * Virtual Host Name
108
     * Virtual Host Name
123
     *
109
     *
124
     * @return void
110
     * @return void
125
     */
111
     */
126
    private function _hostname()
112
    private function _hostname()
127
    {
113
    {
128
        if (PSI_USE_VHOST === true) {
114
        if (PSI_USE_VHOST) {
129
            if (CommonFunctions::readenv('SERVER_NAME', $hnm)) $this->sys->setHostname($hnm);
115
            if (CommonFunctions::readenv('SERVER_NAME', $hnm)) $this->sys->setHostname($hnm);
130
        } else {
116
        } else {
131
            if (CommonFunctions::executeProgram('uname', '-n', $result, PSI_DEBUG)) {
117
            if (CommonFunctions::executeProgram('uname', '-n', $result, PSI_DEBUG)) {
132
                $ip = gethostbyname($result);
118
                $ip = gethostbyname($result);
133
                if ($ip != $result) {
119
                if ($ip != $result) {
134
                    $this->sys->setHostname(gethostbyaddr($ip));
120
                    $this->sys->setHostname(gethostbyaddr($ip));
135
                }
121
                }
136
            }
122
            }
137
        }
123
        }
138
    }
124
    }
139
 
125
 
140
    /**
126
    /**
141
     *  Physical memory information and Swap Space information
127
     *  Physical memory information and Swap Space information
142
     *
128
     *
143
     *  @return void
129
     *  @return void
144
     */
130
     */
145
    private function _memory()
131
    private function _memory()
146
    {
132
    {
147
        if (CommonFunctions::executeProgram('pidin', 'info', $buf)
133
        if (CommonFunctions::executeProgram('pidin', 'info', $buf)
148
           && preg_match('/^.* FreeMem:(\S+)Mb\/(\S+)Mb/', $buf, $memm)) {
134
           && preg_match('/^.* FreeMem:(\S+)Mb\/(\S+)Mb/', $buf, $memm)) {
149
            $this->sys->setMemTotal(1024*1024*$memm[2]);
135
            $this->sys->setMemTotal(1024*1024*$memm[2]);
150
            $this->sys->setMemFree(1024*1024*$memm[1]);
136
            $this->sys->setMemFree(1024*1024*$memm[1]);
151
            $this->sys->setMemUsed(1024*1024*($memm[2]-$memm[1]));
137
            $this->sys->setMemUsed(1024*1024*($memm[2]-$memm[1]));
152
        }
138
        }
153
    }
139
    }
154
 
140
 
155
    /**
141
    /**
156
     * filesystem information
142
     * filesystem information
157
     *
143
     *
158
     * @return void
144
     * @return void
159
     */
145
     */
160
    private function _filesystems()
146
    private function _filesystems()
161
    {
147
    {
162
        $arrResult = Parser::df("-P 2>/dev/null");
148
        $arrResult = Parser::df("-P 2>/dev/null");
163
        foreach ($arrResult as $dev) {
149
        foreach ($arrResult as $dev) {
164
            $this->sys->setDiskDevices($dev);
150
            $this->sys->setDiskDevices($dev);
165
        }
151
        }
166
    }
152
    }
167
 
153
 
168
    /**
154
    /**
169
     * network information
155
     * network information
170
     *
156
     *
171
     * @return void
157
     * @return void
172
     */
158
     */
173
    private function _network()
159
    private function _network()
174
    {
160
    {
175
        if (CommonFunctions::executeProgram('ifconfig', '', $bufr, PSI_DEBUG)) {
161
        if (CommonFunctions::executeProgram('ifconfig', '', $bufr, PSI_DEBUG)) {
176
            $lines = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
162
            $lines = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
177
            $was = false;
163
            $was = false;
178
            $dev = null;
164
            $dev = null;
179
            foreach ($lines as $line) {
165
            foreach ($lines as $line) {
180
                if (preg_match("/^([^\s:]+)/", $line, $ar_buf)) {
166
                if (preg_match("/^([^\s:]+)/", $line, $ar_buf)) {
181
                    if ($was) {
167
                    if ($was) {
182
                        $this->sys->setNetDevices($dev);
168
                        $this->sys->setNetDevices($dev);
183
                    }
169
                    }
184
                    $dev = new NetDevice();
170
                    $dev = new NetDevice();
185
                    $dev->setName($ar_buf[1]);
171
                    $dev->setName($ar_buf[1]);
186
                    $was = true;
172
                    $was = true;
187
                } else {
173
                } else {
188
                    if ($was) {
174
                    if ($was) {
189
                        if (defined('PSI_SHOW_NETWORK_INFOS') && (PSI_SHOW_NETWORK_INFOS)) {
175
                        if (defined('PSI_SHOW_NETWORK_INFOS') && (PSI_SHOW_NETWORK_INFOS)) {
190
                            if (preg_match('/^\s+address:\s*(\S+)/i', $line, $ar_buf2)) {
176
                            if (preg_match('/^\s+address:\s*(\S+)/i', $line, $ar_buf2)) {
191
                                if (!defined('PSI_HIDE_NETWORK_MACADDR') || !PSI_HIDE_NETWORK_MACADDR) $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').preg_replace('/:/', '-', strtoupper($ar_buf2[1])));
177
                                if (!defined('PSI_HIDE_NETWORK_MACADDR') || !PSI_HIDE_NETWORK_MACADDR) $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').preg_replace('/:/', '-', strtoupper($ar_buf2[1])));
192
                            } elseif (preg_match('/^\s+inet\s+(\S+)\s+netmask/i', $line, $ar_buf2))
178
                            } elseif (preg_match('/^\s+inet\s+(\S+)\s+netmask/i', $line, $ar_buf2))
193
                                $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$ar_buf2[1]);
179
                                $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$ar_buf2[1]);
194
 
180
 
195
                        }
181
                        }
196
                    }
182
                    }
197
                }
183
                }
198
            }
184
            }
199
            if ($was) {
185
            if ($was) {
200
                $this->sys->setNetDevices($dev);
186
                $this->sys->setNetDevices($dev);
201
            }
187
            }
202
        }
188
        }
203
    }
189
    }
204
 
190
 
205
    /**
191
    /**
206
     * get the information
192
     * get the information
207
     *
193
     *
208
     * @return Void
194
     * @return void
209
     */
195
     */
210
    public function build()
196
    public function build()
211
    {
197
    {
212
        $this->error->addError("WARN", "The QNX version of phpSysInfo is a work in progress, some things currently don't work");
198
        $this->error->addWarning("The QNX version of phpSysInfo is a work in progress, some things currently don't work");
213
        if (!$this->blockname || $this->blockname==='vitals') {
199
        if (!$this->blockname || $this->blockname==='vitals') {
214
            $this->_distro();
200
            $this->_distro();
215
            $this->_hostname();
201
            $this->_hostname();
216
            $this->_kernel();
202
            $this->_kernel();
217
            $this->_uptime();
203
            $this->_uptime();
218
            $this->_users();
204
            $this->_users();
219
        }
205
        }
220
        if (!$this->blockname || $this->blockname==='hardware') {
206
        if (!$this->blockname || $this->blockname==='hardware') {
221
            $this->_cpuinfo();
207
            $this->_cpuinfo();
222
        }
208
        }
223
        if (!$this->blockname || $this->blockname==='network') {
-
 
224
            $this->_network();
-
 
225
        }
-
 
226
        if (!$this->blockname || $this->blockname==='memory') {
209
        if (!$this->blockname || $this->blockname==='memory') {
227
            $this->_memory();
210
            $this->_memory();
228
        }
211
        }
229
        if (!$this->blockname || $this->blockname==='filesystem') {
212
        if (!$this->blockname || $this->blockname==='filesystem') {
230
            $this->_filesystems();
213
            $this->_filesystems();
231
        }
214
        }
-
 
215
        if (!$this->blockname || $this->blockname==='network') {
-
 
216
            $this->_network();
-
 
217
        }
232
    }
218
    }
233
}
219
}
234
 
220