Subversion Repositories ALCASAR

Rev

Rev 3037 | Go to most recent revision | Details | Last modification | View Log

Rev Author Line No. Line
2770 rexy 1
<?php
2
/**
3
 * Android System Class
4
 *
5
 * PHP version 5
6
 *
7
 * @category  PHP
8
 * @package   PSI Android 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.Linux.inc.php 712 2012-12-05 14:09:18Z namiltd $
13
 * @link      http://phpsysinfo.sourceforge.net
14
 */
15
 /**
16
 * Android sysinfo class
17
 * get all the required information from Android system
18
 *
19
 * @category  PHP
20
 * @package   PSI Android 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 Android extends Linux
28
{
29
    /**
30
     * holds the data from /system/build.prop file
31
     *
32
     * @var string
33
     */
34
    private $_buildprop = null;
35
 
36
    /**
37
     * reads the data from /system/build.prop file
38
     *
39
     * @return string
40
     */
41
    private function _get_buildprop()
42
    {
43
        if ($this->_buildprop === null) {
44
           if (!CommonFunctions::rfts('/system/build.prop', $this->_buildprop, 0, 4096, false)) {
45
               CommonFunctions::rfts('/system//build.prop', $this->_buildprop, 0, 4096, false); //fix some access issues
46
           }
47
        }
48
 
49
        return $this->_buildprop;
50
    }
51
 
52
    /**
53
     * Kernel Version
54
     *
55
     * @return void
56
     */
57
    private function _kernel()
58
    {
59
        if (CommonFunctions::executeProgram('uname', '-r', $strBuf, false)) {
60
            $result = $strBuf;
61
            if (CommonFunctions::executeProgram('uname', '-v', $strBuf, PSI_DEBUG)) {
62
                if (preg_match('/SMP/', $strBuf)) {
63
                    $result .= ' (SMP)';
64
                }
65
            }
66
            if (CommonFunctions::executeProgram('uname', '-m', $strBuf, PSI_DEBUG)) {
67
                $result .= ' '.$strBuf;
68
            }
69
            $this->sys->setKernel($result);
70
        } elseif (CommonFunctions::rfts('/proc/version', $strBuf, 1) && preg_match('/version\s+(\S+)/', $strBuf, $ar_buf)) {
71
            $result = $ar_buf[1];
72
            if (preg_match('/SMP/', $strBuf)) {
73
                $result .= ' (SMP)';
74
            }
75
            $this->sys->setKernel($result);
76
        }
77
    }
78
 
79
    /**
80
     * Number of Users
81
     *
82
     * @return void
83
     */
84
    protected function _users()
85
    {
86
        $this->sys->setUsers(1);
87
    }
88
 
89
    /**
90
     * filesystem information
91
     *
92
     * @return void
93
     */
94
    private function _filesystems()
95
    {
96
        $notwas = true;
97
        if (CommonFunctions::executeProgram('df', '2>/dev/null ', $df, PSI_DEBUG) && preg_match("/\s+[0-9\.]+[KMGT]\s+/", $df)) {
98
            $df = preg_split("/\n/", $df, -1, PREG_SPLIT_NO_EMPTY);
99
            if (CommonFunctions::executeProgram('mount', '', $mount, PSI_DEBUG)) {
100
                $mount = preg_split("/\n/", $mount, -1, PREG_SPLIT_NO_EMPTY);
101
                foreach ($mount as $mount_line) {
102
                    $mount_buf = preg_split('/\s+/', $mount_line);
103
                    if (count($mount_buf) == 6) {
104
                        $mount_parm[$mount_buf[1]]['fstype'] = $mount_buf[2];
105
                        if (PSI_SHOW_MOUNT_OPTION) $mount_parm[$mount_buf[1]]['options'] = $mount_buf[3];
106
                        $mount_parm[$mount_buf[1]]['mountdev'] = $mount_buf[0];
107
                    }
108
                }
109
                foreach ($df as $df_line) {
110
                    if ((preg_match("/^(\/\S+)(\s+)(([0-9\.]+)([KMGT])(\s+)([0-9\.]+)([KMGT])(\s+)([0-9\.]+)([KMGT])(\s+))/", $df_line, $df_buf)
111
                         || preg_match("/^(\/[^\s\:]+)\:(\s+)(([0-9\.]+)([KMGT])(\s+total\,\s+)([0-9\.]+)([KMGT])(\s+used\,\s+)([0-9\.]+)([KMGT])(\s+available))/", $df_line, $df_buf))
112
                         && !preg_match('/^\/mnt\/asec\/com\./', $df_buf[1])) {
113
                        $dev = new DiskDevice();
114
                        if (PSI_SHOW_MOUNT_POINT) $dev->setMountPoint($df_buf[1]);
115
 
116
                        if ($df_buf[5] == 'K') $dev->setTotal($df_buf[4] * 1024);
117
                        elseif ($df_buf[5] == 'M') $dev->setTotal($df_buf[4] * 1024*1024);
118
                        elseif ($df_buf[5] == 'G') $dev->setTotal($df_buf[4] * 1024*1024*1024);
119
                        elseif ($df_buf[5] == 'T') $dev->setTotal($df_buf[4] * 1024*1024*1024*1024);
120
 
121
                        if ($df_buf[8] == 'K') $dev->setUsed($df_buf[7] * 1024);
122
                        elseif ($df_buf[8] == 'M') $dev->setUsed($df_buf[7] * 1024*1024);
123
                        elseif ($df_buf[8] == 'G') $dev->setUsed($df_buf[7] * 1024*1024*1024);
124
                        elseif ($df_buf[8] == 'T') $dev->setUsed($df_buf[7] * 1024*1024*1024*1024);
125
 
126
                        if ($df_buf[11] == 'K') $dev->setFree($df_buf[10] * 1024);
127
                        elseif ($df_buf[11] == 'M') $dev->setFree($df_buf[10] * 1024*1024);
128
                        elseif ($df_buf[11] == 'G') $dev->setFree($df_buf[10] * 1024*1024*1024);
129
                        elseif ($df_buf[11] == 'T') $dev->setFree($df_buf[10] * 1024*1024*1024*1024);
130
 
131
                        if (isset($mount_parm[$df_buf[1]])) {
132
                            $dev->setFsType($mount_parm[$df_buf[1]]['fstype']);
133
                            $dev->setName($mount_parm[$df_buf[1]]['mountdev']);
134
 
135
                            if (PSI_SHOW_MOUNT_OPTION) {
136
                                if (PSI_SHOW_MOUNT_CREDENTIALS) {
137
                                    $dev->setOptions($mount_parm[$df_buf[1]]['options']);
138
                                } else {
139
                                    $mpo=$mount_parm[$df_buf[1]]['options'];
140
 
141
                                    $mpo=preg_replace('/(^guest,)|(^guest$)|(,guest$)/i', '', $mpo);
142
                                    $mpo=preg_replace('/,guest,/i', ',', $mpo);
143
 
144
                                    $mpo=preg_replace('/(^user=[^,]*,)|(^user=[^,]*$)|(,user=[^,]*$)/i', '', $mpo);
145
                                    $mpo=preg_replace('/,user=[^,]*,/i', ',', $mpo);
146
 
147
                                    $mpo=preg_replace('/(^username=[^,]*,)|(^username=[^,]*$)|(,username=[^,]*$)/i', '', $mpo);
148
                                    $mpo=preg_replace('/,username=[^,]*,/i', ',', $mpo);
149
 
150
                                    $mpo=preg_replace('/(^password=[^,]*,)|(^password=[^,]*$)|(,password=[^,]*$)/i', '', $mpo);
151
                                    $mpo=preg_replace('/,password=[^,]*,/i', ',', $mpo);
152
 
153
                                    $dev->setOptions($mpo);
154
                                }
155
                            }
156
                        }
157
                        $this->sys->setDiskDevices($dev);
158
                        $notwas = false;
159
                    }
160
                }
161
            }
162
        }
163
        if ($notwas) { // try Linux df style
164
            $arrResult = Parser::df("-P 2>/dev/null", false);
165
            foreach ($arrResult as $dev) {
166
                $this->sys->setDiskDevices($dev);
167
            }
168
        }
169
    }
170
 
171
    /**
172
     * Distribution
173
     *
174
     * @return void
175
     */
176
    protected function _distro()
177
    {
178
        $buf = "";
179
        if (($lines = $this->_get_buildprop()) && preg_match('/^ro\.build\.version\.release=([^\n]+)/m', $lines, $ar_buf)) {
180
                $buf = trim($ar_buf[1]);
181
        }
182
        if (is_null($buf) || ($buf == "")) {
183
            $this->sys->setDistribution('Android');
184
        } else {
185
            if (preg_match('/^(\d+\.\d+)/', $buf, $ver)
186
                && ($list = @parse_ini_file(PSI_APP_ROOT."/data/osnames.ini", true))
187
                && isset($list['Android'][$ver[1]])) {
188
                    $buf.=' '.$list['Android'][$ver[1]];
189
            }
190
            $this->sys->setDistribution('Android '.$buf);
191
        }
192
        $this->sys->setDistributionIcon('Android.png');
193
    }
194
 
195
    /**
196
     * Machine
197
     *
198
     * @return void
199
     */
200
    private function _machine()
201
    {
202
        if ($lines = $this->_get_buildprop()) {
203
            $buf = "";
204
            if (preg_match('/^ro\.product\.manufacturer=([^\n]+)/m', $lines, $ar_buf) && (trim($ar_buf[1]) !== "unknown")) {
205
                $buf .= ' '.trim($ar_buf[1]);
206
            }
207
            if (preg_match('/^ro\.product\.model=([^\n]+)/m', $lines, $ar_buf) && (trim($ar_buf[1]) !== trim($buf))) {
208
                $buf .= ' '.trim($ar_buf[1]);
209
            }
210
            if (preg_match('/^ro\.semc\.product\.name=([^\n]+)/m', $lines, $ar_buf)) {
211
                $buf .= ' '.trim($ar_buf[1]);
212
            }
213
            if (trim($buf) != "") {
214
                $this->sys->setMachine(trim($buf));
215
            }
216
        }
217
    }
218
 
219
    /**
220
     * PCI devices
221
     *
222
     * @return void
223
     */
224
    private function _pci()
225
    {
226
        if (CommonFunctions::executeProgram('lspci', '', $bufr, false)) {
227
            $bufe = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
228
            foreach ($bufe as $buf) {
229
                $device = preg_split("/ /", $buf, 4);
230
                if (isset($device[3]) && trim($device[3]) != "") {
231
                    $dev = new HWDevice();
232
                    $dev->setName('Class '.trim($device[2]).' Device '.trim($device[3]));
233
                    $this->sys->setPciDevices($dev);
234
                }
235
            }
236
        }
237
    }
238
 
239
    /**
240
     * get the information
241
     *
242
     * @see PSI_Interface_OS::build()
243
     *
244
     * @return Void
245
     */
246
    public function build()
247
    {
248
        if (!$this->blockname || $this->blockname==='vitals') {
249
            $this->_distro();
250
            $this->_hostname();
251
            $this->_kernel();
252
            $this->_uptime();
253
            $this->_users();
254
            $this->_loadavg();
255
            $this->_processes();
256
        }
257
        if (!$this->blockname || $this->blockname==='hardware') {
258
            $this->_machine();
259
            $this->_cpuinfo();
260
            $this->_pci();
261
            $this->_usb();
262
            $this->_i2c();
263
        }
264
        if (!$this->blockname || $this->blockname==='network') {
265
            $this->_network();
266
        }
267
        if (!$this->blockname || $this->blockname==='memory') {
268
            $this->_memory();
269
        }
270
        if (!$this->blockname || $this->blockname==='filesystem') {
271
            $this->_filesystems();
272
        }
273
    }
274
}