Subversion Repositories ALCASAR

Rev

Rev 2770 | Details | Compare with Previous | Last modification | View Log

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