Subversion Repositories ALCASAR

Rev

Rev 1764 | Rev 2976 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log

Rev 1764 Rev 2770
Line 1... Line 1...
1
<?php 
1
<?php
-
 
2
/**
2
// phpSysInfo - A PHP System Information Script
3
 * Linux System Class
-
 
4
 *
3
// http://phpsysinfo.sourceforge.net/
5
 * PHP version 5
-
 
6
 *
-
 
7
 * @category  PHP
4
// This program is free software; you can redistribute it and/or
8
 * @package   PSI Linux OS class
5
// modify it under the terms of the GNU General Public License
9
 * @author    Michael Cramer <BigMichi1@users.sourceforge.net>
6
// as published by the Free Software Foundation; either version 2
10
 * @copyright 2009 phpSysInfo
7
// of the License, 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
8
// This program is distributed in the hope that it will be useful,
12
 * @version   SVN: $Id: class.Linux.inc.php 712 2012-12-05 14:09:18Z namiltd $
9
// but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * @link      http://phpsysinfo.sourceforge.net
-
 
14
 */
-
 
15
 /**
-
 
16
 * Linux sysinfo class
10
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 * get all the required information from Linux system
-
 
18
 *
-
 
19
 * @category  PHP
11
// GNU General Public License for more details.
20
 * @package   PSI Linux OS class
12
// You should have received a copy of the GNU General Public License
21
 * @author    Michael Cramer <BigMichi1@users.sourceforge.net>
13
// along with this program; if not, write to the Free Software
22
 * @copyright 2009 phpSysInfo
14
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
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
15
// $Id: class.Linux.inc.php,v 1.88 2007/02/25 20:50:52 bigmichi1 Exp $
25
 * @link      http://phpsysinfo.sourceforge.net
-
 
26
 */
-
 
27
class Linux extends OS
16
 
28
{
-
 
29
    /**
17
if (!defined('IN_PHPSYSINFO')) {
30
     * Assoc array of all CPUs loads.
-
 
31
     */
18
    die("No Hacking");
32
    protected $_cpu_loads;
19
}
33
 
-
 
34
    /**
-
 
35
     * Machine
20
 
36
     *
-
 
37
     * @return void
-
 
38
     */
21
require_once(APP_ROOT . '/includes/os/class.BSD.common.inc.php');
39
    private function _machine()
22
 
40
    {
23
class sysinfo {
41
        $machine = "";
-
 
42
        if ((CommonFunctions::rfts('/var/log/dmesg', $result, 0, 4096, false)
-
 
43
              && preg_match('/^[\s\[\]\.\d]*DMI:\s*(.*)/m', $result, $ar_buf))
-
 
44
           ||(CommonFunctions::executeProgram('dmesg', '', $result, false)
-
 
45
              && preg_match('/^[\s\[\]\.\d]*DMI:\s*(.*)/m', $result, $ar_buf))) {
24
	var $inifile = "distros.ini";
46
            $machine = trim($ar_buf[1]);
-
 
47
        } else { //data from /sys/devices/virtual/dmi/id/
25
	var $icon = "unknown.png";
48
            $product = "";
26
	var $distro = "unknown";
49
            $board = "";
-
 
50
            $bios = "";
-
 
51
            if (CommonFunctions::rfts('/sys/devices/virtual/dmi/id/board_vendor', $buf, 1, 4096, false) && (trim($buf)!="")) {
-
 
52
                $machine = trim($buf);
-
 
53
            }
-
 
54
            if (CommonFunctions::rfts('/sys/devices/virtual/dmi/id/product_name', $buf, 1, 4096, false) && (trim($buf)!="")) {
-
 
55
                $product = trim($buf);
-
 
56
            }
-
 
57
            if (CommonFunctions::rfts('/sys/devices/virtual/dmi/id/board_name', $buf, 1, 4096, false) && (trim($buf)!="")) {
-
 
58
                $board = trim($buf);
27
	var $parser;
59
            }
-
 
60
            if (CommonFunctions::rfts('/sys/devices/virtual/dmi/id/bios_version', $buf, 1, 4096, false) && (trim($buf)!="")) {
-
 
61
                $bios = trim($buf);
28
	
62
            }
-
 
63
            if (CommonFunctions::rfts('/sys/devices/virtual/dmi/id/bios_date', $buf, 1, 4096, false) && (trim($buf)!="")) {
29
	// get the distro name and icon when create the sysinfo object
64
                $bios = trim($bios." ".trim($buf));
-
 
65
            }
30
	function sysinfo() {
66
            if ($product != "") {
31
  		$this->parser = new Parser();
67
                $machine .= " ".$product;
-
 
68
            }
32
		$this->parser->df_param = 'P';
69
            if ($board != "") {
-
 
70
                $machine .= "/".$board;
-
 
71
            }
-
 
72
            if ($bios != "") {
-
 
73
                $machine .= ", BIOS ".$bios;
-
 
74
            }
-
 
75
        }
-
 
76
 
-
 
77
        if ($machine != "") {
-
 
78
            $machine = trim(preg_replace("/^\/,?/", "", preg_replace("/ ?(To be filled by O\.E\.M\.|System manufacturer|System Product Name|Not Specified) ?/i", "", $machine)));
-
 
79
        }
33
		
80
 
-
 
81
        if (CommonFunctions::fileexists($filename="/etc/config/uLinux.conf") // QNAP detection
-
 
82
           && CommonFunctions::rfts($filename, $buf, 0, 4096, false)
34
		$list = @parse_ini_file(APP_ROOT . "/" . $this->inifile, true);
83
           && preg_match("/^Rsync\sModel\s*=\s*QNAP/m", $buf)
-
 
84
           && CommonFunctions::fileexists($filename="/etc/platform.conf") // Platform detection
-
 
85
           && CommonFunctions::rfts($filename, $buf, 0, 4096, false)
-
 
86
           && preg_match("/^DISPLAY_NAME\s*=\s*(\S+)/m", $buf, $mach_buf) && ($mach_buf[1]!=="")) {
-
 
87
            if ($machine != "") {
-
 
88
                $machine = "QNAP ".$mach_buf[1].' - '.$machine;
35
		if (!$list) {
89
            } else {
-
 
90
                $machine = "QNAP ".$mach_buf[1];
36
			return;
91
            }
37
		}
92
        }
38
		
93
 
39
		$distro_info = execute_program('lsb_release','-a 2> /dev/null', false);  // We have the '2> /dev/null' because Ubuntu gives an error on this command which causes the distro to be unknown
-
 
40
		if ( $distro_info != 'ERROR') {
94
        if ($machine != "") {
41
			$distro_tmp = explode("\n",$distro_info);
95
            $this->sys->setMachine($machine);
42
			foreach( $distro_tmp as $info ) {
-
 
43
				$info_tmp = explode(':', $info, 2);
-
 
44
				$distro[ $info_tmp[0] ] = trim($info_tmp[1]);
-
 
45
			}
96
        }
46
			if( !isset( $list[$distro['Distributor ID']] ) ){
-
 
47
				return;
-
 
48
			}
97
    }
49
			$this->icon = isset($list[$distro['Distributor ID']]["Image"]) ? $list[$distro['Distributor ID']]["Image"] : $this->icon;
-
 
-
 
98
 
-
 
99
    /**
50
			$this->distro = $distro['Description'];
100
     * Hostname
-
 
101
     *
51
		} else {  // Fall back in case 'lsb_release' does not exist ;)
102
     * @return void
-
 
103
     */
52
			foreach ($list as $section => $distribution) {
104
    protected function _hostname()
-
 
105
    {
53
				if (!isset($distribution["Files"])) {
106
        if (PSI_USE_VHOST === true) {
54
					continue;
107
            if (CommonFunctions::readenv('SERVER_NAME', $hnm)) $this->sys->setHostname($hnm);
55
				} else {
108
        } else {
56
					foreach (explode(";", $distribution["Files"]) as $filename) {
109
            if (CommonFunctions::rfts('/proc/sys/kernel/hostname', $result, 1, 4096, PSI_DEBUG && (PSI_OS != 'Android'))) {
57
						if (file_exists($filename)) {
110
                $result = trim($result);
58
							$buf = rfts( $filename );
111
                $ip = gethostbyname($result);
59
							$this->icon = isset($distribution["Image"]) ? $distribution["Image"] : $this->icon;
112
                if ($ip != $result) {
60
							$this->distro = isset($distribution["Name"]) ? $distribution["Name"] . " " . trim($buf) : trim($buf);
113
                    $this->sys->setHostname(gethostbyaddr($ip));
61
							break 2;
114
                }
-
 
115
            } elseif (CommonFunctions::executeProgram('hostname', '', $ret)) {
-
 
116
                $this->sys->setHostname($ret);
62
						}
117
            }
-
 
118
 
63
					}
119
        }
64
				}
120
    }
-
 
121
 
-
 
122
    /**
-
 
123
     * Kernel Version
-
 
124
     *
-
 
125
     * @return void
-
 
126
     */
-
 
127
    private function _kernel()
-
 
128
    {
-
 
129
        $result = "";
-
 
130
        if (CommonFunctions::executeProgram($uname="uptrack-uname", '-r', $strBuf, false) || // show effective kernel if ksplice uptrack is installed
-
 
131
            CommonFunctions::executeProgram($uname="uname", '-r', $strBuf, PSI_DEBUG)) {
-
 
132
            $result = $strBuf;
-
 
133
            if (CommonFunctions::executeProgram($uname, '-v', $strBuf, PSI_DEBUG)) {
-
 
134
                if (preg_match('/SMP/', $strBuf)) {
-
 
135
                    $result .= ' (SMP)';
65
			}
136
                }
66
		}
137
            }
-
 
138
            if (CommonFunctions::executeProgram($uname, '-m', $strBuf, PSI_DEBUG)) {
-
 
139
                $result .= ' '.$strBuf;
67
	}
140
            }
68
  
-
 
69
  // get our apache SERVER_NAME or vhost
-
 
70
  function vhostname () {
-
 
71
    if (! ($result = getenv('SERVER_NAME'))) {
-
 
72
      $result = 'N.A.';
-
 
73
    } 
-
 
74
    return $result;
-
 
75
  } 
-
 
76
  // get the IP address of our vhost name
-
 
77
  function vip_addr () {
-
 
78
    return gethostbyname($this->vhostname());
-
 
79
  }
-
 
80
  // get our canonical hostname
-
 
81
  function chostname () {
-
 
82
    $result = rfts( '/proc/sys/kernel/hostname', 1 );
-
 
83
    if ( $result == "ERROR" ) {
-
 
84
      $result = "N.A.";
-
 
85
    }
-
 
86
    //else {
-
 
87
    //  $result = gethostbyaddr( gethostbyname( trim( $result ) ) );
-
 
88
    //} 
-
 
89
    return $result;
-
 
90
  } 
-
 
91
  // get the IP address of our canonical hostname
-
 
92
  function ip_addr () {
-
 
93
    if (!($result = getenv('SERVER_ADDR'))) {
-
 
94
      $result = gethostbyname($this->chostname());
-
 
95
    } 
-
 
96
    return $result;
-
 
97
  } 
-
 
98
 
-
 
99
  function kernel () {
-
 
100
    $buf = rfts( '/proc/version', 1 );
-
 
101
    if ( $buf == "ERROR" ) {
-
 
102
      $result = "N.A.";
-
 
103
    } else {
-
 
104
      if (preg_match('/version (.*?) /', $buf, $ar_buf)) {
141
        } elseif (CommonFunctions::rfts('/proc/version', $strBuf, 1) &&  preg_match('/version\s+(\S+)/', $strBuf, $ar_buf)) {
105
        $result = $ar_buf[1];
142
            $result = $ar_buf[1];
106
 
-
 
107
        if (preg_match('/SMP/', $buf)) {
143
            if (preg_match('/SMP/', $strBuf)) {
108
          $result .= ' (SMP)';
144
                $result .= ' (SMP)';
109
        } 
145
            }
110
      } 
146
        }
-
 
147
        if ($result != "") {
-
 
148
            if (CommonFunctions::rfts('/proc/self/cgroup', $strBuf2, 0, 4096, false)) {
-
 
149
                if (preg_match('/:\/lxc\//m', $strBuf2)) {
-
 
150
                    $result .= ' [lxc]';
-
 
151
                } elseif (preg_match('/:\/docker\//m', $strBuf2)) {
-
 
152
                    $result .= ' [docker]';
-
 
153
                } elseif (preg_match('/:\/system\.slice\/docker\-/m', $strBuf2)) {
-
 
154
                    $result .= ' [docker]';
-
 
155
                }
-
 
156
            }
-
 
157
            if (CommonFunctions::rfts('/proc/version', $strBuf2, 1, 4096, false)
-
 
158
                && preg_match('/^Linux version [\d\.-]+-Microsoft/', $strBuf2)) {
-
 
159
                    $result .= ' [lxss]';
-
 
160
            }
-
 
161
            $this->sys->setKernel($result);
-
 
162
        }
-
 
163
    }
-
 
164
 
-
 
165
    /**
-
 
166
     * UpTime
-
 
167
     * time the system is running
-
 
168
     *
-
 
169
     * @return void
-
 
170
     */
-
 
171
    protected function _uptime()
-
 
172
    {
-
 
173
        if (CommonFunctions::rfts('/proc/uptime', $buf, 1, 4096, PSI_OS != 'Android')) {
-
 
174
            $ar_buf = preg_split('/ /', $buf);
-
 
175
            $this->sys->setUptime(trim($ar_buf[0]));
-
 
176
        } elseif (CommonFunctions::executeProgram('uptime', '', $buf)) {
-
 
177
            if (preg_match("/up (\d+) day[s]?,[ ]+(\d+):(\d+),/", $buf, $ar_buf)) {
-
 
178
                $min = $ar_buf[3];
-
 
179
                $hours = $ar_buf[2];
-
 
180
                $days = $ar_buf[1];
-
 
181
                $this->sys->setUptime($days * 86400 + $hours * 3600 + $min * 60);
-
 
182
            } elseif (preg_match("/up (\d+) day[s]?,[ ]+(\d+) min,/", $buf, $ar_buf)) {
-
 
183
                $min = $ar_buf[2];
-
 
184
                $days = $ar_buf[1];
-
 
185
                $this->sys->setUptime($days * 86400 + $min * 60);
-
 
186
            } elseif (preg_match("/up[ ]+(\d+):(\d+),/", $buf, $ar_buf)) {
-
 
187
                $min = $ar_buf[2];
-
 
188
                $hours = $ar_buf[1];
-
 
189
                $this->sys->setUptime($hours * 3600 + $min * 60);
-
 
190
            } elseif (preg_match("/up[ ]+(\d+) min,/", $buf, $ar_buf)) {
-
 
191
                $min = $ar_buf[1];
-
 
192
                $this->sys->setUptime($min * 60);
-
 
193
            }
-
 
194
        }
-
 
195
    }
-
 
196
 
-
 
197
    /**
-
 
198
     * Processor Load
-
 
199
     * optionally create a loadbar
-
 
200
     *
-
 
201
     * @return void
-
 
202
     */
-
 
203
    protected function _loadavg()
-
 
204
    {
-
 
205
        if (CommonFunctions::rfts('/proc/loadavg', $buf, 1, 4096, PSI_OS != 'Android')) {
-
 
206
            $result = preg_split("/\s/", $buf, 4);
-
 
207
            // don't need the extra values, only first three
-
 
208
            unset($result[3]);
-
 
209
            $this->sys->setLoad(implode(' ', $result));
-
 
210
        } elseif (CommonFunctions::executeProgram('uptime', '', $buf) && preg_match("/load average: (.*), (.*), (.*)$/", $buf, $ar_buf)) {
-
 
211
            $this->sys->setLoad($ar_buf[1].' '.$ar_buf[2].' '.$ar_buf[3]);
-
 
212
        }
-
 
213
        if (PSI_LOAD_BAR) {
-
 
214
            $this->sys->setLoadPercent($this->_parseProcStat('cpu'));
-
 
215
        }
-
 
216
    }
-
 
217
 
-
 
218
    /**
-
 
219
     * fill the load for a individual cpu, through parsing /proc/stat for the specified cpu
-
 
220
     *
-
 
221
     * @param String $cpuline cpu for which load should be meassured
-
 
222
     *
-
 
223
     * @return Integer
-
 
224
     */
-
 
225
    protected function _parseProcStat($cpuline)
-
 
226
    {
-
 
227
        if (is_null($this->_cpu_loads)) {
-
 
228
            $this->_cpu_loads = array();
-
 
229
 
-
 
230
            $cpu_tmp = array();
-
 
231
            if (CommonFunctions::rfts('/proc/stat', $buf)) {
-
 
232
                if (preg_match_all('/^(cpu[0-9]*) (.*)/m', $buf, $matches, PREG_SET_ORDER)) {
-
 
233
                    foreach ($matches as $line) {
-
 
234
                        $cpu = $line[1];
-
 
235
                        $buf2 = $line[2];
-
 
236
 
-
 
237
                        $cpu_tmp[$cpu] = array();
-
 
238
 
-
 
239
                        $ab = 0;
-
 
240
                        $ac = 0;
-
 
241
                        $ad = 0;
-
 
242
                        $ae = 0;
-
 
243
                        sscanf($buf2, "%Ld %Ld %Ld %Ld", $ab, $ac, $ad, $ae);
-
 
244
                        $cpu_tmp[$cpu]['load'] = $ab + $ac + $ad; // cpu.user + cpu.sys
-
 
245
                        $cpu_tmp[$cpu]['total'] = $ab + $ac + $ad + $ae; // cpu.total
111
    } 
246
                    }
112
    return $result;
-
 
113
  } 
247
                }
114
  
248
 
115
  function uptime () {
-
 
116
    $buf = rfts( '/proc/uptime', 1 );
-
 
117
    $ar_buf = explode( ' ', $buf );
249
                // we need a second value, wait 1 second befor getting (< 1 second no good value will occour)
118
    $result = trim( $ar_buf[0] );
250
                sleep(1);
119
 
251
 
-
 
252
                if (CommonFunctions::rfts('/proc/stat', $buf)) {
-
 
253
                    if (preg_match_all('/^(cpu[0-9]*) (.*)/m', $buf, $matches, PREG_SET_ORDER)) {
-
 
254
                        foreach ($matches as $line) {
120
    return $result;
255
                            $cpu = $line[1];
121
  } 
-
 
-
 
256
                            if (isset($cpu_tmp[$cpu])) {
-
 
257
                                $buf2 = $line[2];
122
 
258
 
123
  function users () {
259
                                $ab = 0;
124
		$strResult = 0;
260
                                $ac = 0;
125
  		$strBuf = execute_program('who', '-q');
261
                                $ad = 0;
-
 
262
                                $ae = 0;
-
 
263
                                sscanf($buf2, "%Ld %Ld %Ld %Ld", $ab, $ac, $ad, $ae);
-
 
264
                                $load2 = $ab + $ac + $ad; // cpu.user + cpu.sys
-
 
265
                                $total2 = $ab + $ac + $ad + $ae; // cpu.total
-
 
266
                                $total = $cpu_tmp[$cpu]['total'];
-
 
267
                                $load = $cpu_tmp[$cpu]['load'];
-
 
268
                                $this->_cpu_loads[$cpu] = 0;
-
 
269
                                if ($total > 0 && $total2 > 0 && $load > 0 && $load2 > 0 && $total2 != $total && $load2 != $load) {
-
 
270
                                    $this->_cpu_loads[$cpu] = (100 * ($load2 - $load)) / ($total2 - $total);
126
		if( $strBuf != "ERROR" ) {
271
                                }
127
			$arrWho = explode( '=', $strBuf );
272
                            }
128
    			$strResult = $arrWho[1];
273
                        }
-
 
274
                    }
129
		}
275
                }
130
		return $strResult;
-
 
131
  }
276
            }
132
  
-
 
133
  function loadavg ($bar = false) {
-
 
134
    $buf = rfts( '/proc/loadavg' );
-
 
135
    if( $buf == "ERROR" ) {
-
 
136
      $results['avg'] = array('N.A.', 'N.A.', 'N.A.');
-
 
137
    } else {
-
 
138
      $results['avg'] = preg_split("/\s/", $buf, 4);
-
 
139
      unset($results['avg'][3]);	// don't need the extra values, only first three
-
 
140
    } 
277
        }
141
    if ($bar) {
-
 
142
      $buf = rfts( '/proc/stat', 1 );
-
 
143
      if( $buf != "ERROR" ) {
-
 
144
	sscanf($buf, "%*s %Ld %Ld %Ld %Ld", $ab, $ac, $ad, $ae);
-
 
145
	// Find out the CPU load
-
 
146
	// user + sys = load 
-
 
147
	// total = total
-
 
148
	$load = $ab + $ac + $ad;	// cpu.user + cpu.sys
-
 
149
	$total = $ab + $ac + $ad + $ae;	// cpu.total
-
 
150
 
278
 
151
	// we need a second value, wait 1 second befor getting (< 1 second no good value will occour)
-
 
152
	sleep(1);
-
 
153
	$buf = rfts( '/proc/stat', 1 );
279
        if (isset($this->_cpu_loads[$cpuline])) {
154
	sscanf($buf, "%*s %Ld %Ld %Ld %Ld", $ab, $ac, $ad, $ae);
280
            return $this->_cpu_loads[$cpuline];
155
	$load2 = $ab + $ac + $ad;
281
        } else {
156
	$total2 = $ab + $ac + $ad + $ae;
282
            return 0;
157
	$results['cpupercent'] = (100*($load2 - $load)) / ($total2 - $total);
-
 
158
      }
283
        }
159
    }
284
    }
-
 
285
 
-
 
286
    /**
-
 
287
     * CPU information
-
 
288
     * All of the tags here are highly architecture dependant.
-
 
289
     *
160
    return $results;
290
     * @return void
-
 
291
     */
-
 
292
    protected function _cpuinfo()
-
 
293
    {
-
 
294
        if (CommonFunctions::rfts('/proc/cpuinfo', $bufr)) {
-
 
295
            $cpulist = null;
-
 
296
            $raslist = null;
-
 
297
 
-
 
298
            // sparc
-
 
299
            if (preg_match('/\nCpu(\d+)Bogo\s*:/i', $bufr)) {
-
 
300
                $bufr = preg_replace('/\nCpu(\d+)ClkTck\s*:/i', "\nCpu0ClkTck:", preg_replace('/\nCpu(\d+)Bogo\s*:/i', "\n\nprocessor: $1\nCpu0Bogo:", $bufr));
-
 
301
            } else {
-
 
302
                $bufr = preg_replace('/\nCpu(\d+)ClkTck\s*:/i', "\n\nprocessor: $1\nCpu0ClkTck:", $bufr);
161
  } 
303
            }
162
 
304
 
163
	function cpu_info () {
305
            if (preg_match('/\nprocessor\s*:\s*\d+\r?\nprocessor\s*:\s*\d+/', $bufr)) {
164
		$bufr = rfts( '/proc/cpuinfo' );
306
                $bufr = preg_replace('/^(processor\s*:\s*\d+)\r?$/m', "$1\n", $bufr);
165
		$results = array("cpus" => 0);
307
            }
166
		
308
 
167
		if ( $bufr != "ERROR" ) {
309
            // IBM/S390
168
			$bufe = explode("\n", $bufr);
310
            $bufr = preg_replace('/\ncpu number\s*:\s*(\d+)\r?\ncpu MHz dynamic\s*:\s*(\d+)/m', "\nprocessor:$1\nclock:$2", $bufr);
169
			
311
 
170
			$results = array('cpus' => 0, 'bogomips' => 0);
312
            $processors = preg_split('/\s?\n\s?\n/', trim($bufr));
171
			$ar_buf = array();
-
 
172
			
313
 
-
 
314
            //first stage
173
			foreach( $bufe as $buf ) {
315
            $_arch = null;
174
				$arrBuff = preg_split('/\s+:\s+/', trim($buf));
316
            $_impl = null;
175
				if( count( $arrBuff ) == 2 ) {
317
            $_part = null;
176
					$key = $arrBuff[0];
318
            $_hard = null;
177
					$value = $arrBuff[1];
319
            $_revi = null;
-
 
320
            $_cpus = null;
-
 
321
            $_buss = null;
-
 
322
            $_bogo = null;
-
 
323
            $_vend = null;
-
 
324
            $procname = null;
-
 
325
            foreach ($processors as $processor) if (!preg_match('/^\s*processor\s*:/mi', $processor)) {
178
					// All of the tags here are highly architecture dependant.
326
                $details = preg_split("/\n/", $processor, -1, PREG_SPLIT_NO_EMPTY);
179
					// the only way I could reconstruct them for machines I don't
327
                foreach ($details as $detail) {
180
					// have is to browse the kernel source.  So if your arch isn't
328
                    $arrBuff = preg_split('/\s*:\s*/', trim($detail));
181
					// supported, tell me you want it written in.
329
                    if ((count($arrBuff) == 2) && (($arrBuff1 = trim($arrBuff[1])) !== '')) {
182
					switch ($key) {
330
                        switch (strtolower($arrBuff[0])) {
183
						case 'model name':
331
                        case 'cpu architecture':
184
							$results['model'] = $value;
332
                            $_arch = $arrBuff1;
185
							break;
333
                            break;
186
						case 'cpu MHz':
334
                        case 'cpu implementer':
187
							$results['cpuspeed'] = sprintf('%.2f', $value);
335
                            $_impl = $arrBuff1;
188
							break;
336
                            break;
189
						case 'cycle frequency [Hz]': // For Alpha arch - 2.2.x
337
                        case 'cpu part':
190
							$results['cpuspeed'] = sprintf('%.2f', $value / 1000000);
338
                            $_part = $arrBuff1;
191
							break;
339
                            break;
192
						case 'clock': // For PPC arch (damn borked POS)
340
                        case 'hardware':
193
							$results['cpuspeed'] = sprintf('%.2f', $value);
341
                            $_hard = $arrBuff1;
194
							break;
342
                            break;
195
						case 'cpu': // For PPC arch (damn borked POS)
343
                        case 'revision':
196
							$results['model'] = $value;
344
                            $_revi = $arrBuff1;
197
							break;
345
                            break;
198
						case 'L2 cache': // More for PPC
346
                        case 'cpu frequency':
-
 
347
                            if (preg_match('/^(\d+)\s+Hz/i', $arrBuff1, $bufr2)) {
-
 
348
                                $_cpus = round($bufr2[1]/1000000);
199
							$results['cache'] = $value;
349
                            }
200
							break;
350
                            break;
201
						case 'revision': // For PPC arch (damn borked POS)
351
                        case 'system bus frequency':
-
 
352
                            if (preg_match('/^(\d+)\s+Hz/i', $arrBuff1, $bufr2)) {
202
							$results['model'] .= ' ( rev: ' . $value . ')';
353
                                $_buss = round($bufr2[1]/1000000);
-
 
354
                            }
203
							break;
355
                            break;
204
						case 'cpu model': // For Alpha arch - 2.2.x
356
                        case 'bogomips per cpu':
205
							$results['model'] .= ' (' . $value . ')';
357
                            $_bogo = round($arrBuff1);
206
							break;
358
                            break;
207
						case 'cache size':
359
                        case 'vendor_id':
-
 
360
                            $_vend = $arrBuff1;
208
							$results['cache'] = $value;
361
                        case 'cpu':
-
 
362
                            $procname = $arrBuff1;
209
							break;
363
                            break;
-
 
364
                        }
-
 
365
                    }
-
 
366
                }
-
 
367
            }
-
 
368
 
210
						case 'bogomips':
369
            //second stage
-
 
370
            $cpucount = 0;
211
							$results['bogomips'] += $value;
371
            $speedset = false;
-
 
372
            foreach ($processors as $processor) if (preg_match('/^\s*processor\s*:/mi', $processor)) {
-
 
373
                $proc = null;
-
 
374
                $arch = null;
-
 
375
                $impl = null;
-
 
376
                $part = null;
-
 
377
                $dev = new CpuDevice();
-
 
378
                $details = preg_split("/\n/", $processor, -1, PREG_SPLIT_NO_EMPTY);
-
 
379
                foreach ($details as $detail) {
-
 
380
                    $arrBuff = preg_split('/\s*:\s*/', trim($detail));
-
 
381
                    if ((count($arrBuff) == 2) && (($arrBuff1 = trim($arrBuff[1])) !== '')) {
-
 
382
                        switch (strtolower($arrBuff[0])) {
-
 
383
                        case 'processor':
-
 
384
                            $proc = $arrBuff1;
-
 
385
                            if (is_numeric($proc)) {
-
 
386
                                if (strlen($procname)>0) {
-
 
387
                                    $dev->setModel($procname);
-
 
388
                                }
-
 
389
                            } else {
-
 
390
                                $procname = $proc;
-
 
391
                                $dev->setModel($procname);
-
 
392
                            }
212
							break;
393
                            break;
-
 
394
                        case 'model name':
213
						case 'BogoMIPS': // For alpha arch - 2.2.x
395
                        case 'cpu model':
214
							$results['bogomips'] += $value;
396
                        case 'cpu type':
-
 
397
                        case 'cpu':
-
 
398
                            $dev->setModel($arrBuff1);
215
							break;
399
                            break;
-
 
400
                        case 'cpu mhz':
216
						case 'BogoMips': // For sparc arch
401
                        case 'clock':
-
 
402
                            if ($arrBuff1 > 0) { //openSUSE fix
-
 
403
                                $dev->setCpuSpeed($arrBuff1);
217
							$results['bogomips'] += $value;
404
                                $speedset = true;
-
 
405
                            }
218
							break;
406
                            break;
-
 
407
                        case 'cpu mhz static':
219
						case 'cpus detected': // For Alpha arch - 2.2.x
408
                            if ($arrBuff1 > 0) { //openSUSE fix
-
 
409
                                $dev->setCpuSpeedMax($arrBuff1);
220
							$results['cpus'] += $value;
410
                            }
221
							break;
411
                            break;
222
						case 'system type': // Alpha arch - 2.2.x
412
                        case 'cycle frequency [hz]':
-
 
413
                            $dev->setCpuSpeed($arrBuff1 / 1000000);
223
							$results['model'] .= ', ' . $value . ' ';
414
                            $speedset = true;
224
							break;
415
                            break;
225
						case 'platform string': // Alpha arch - 2.2.x
416
                        case 'cpu0clktck':
-
 
417
                            $dev->setCpuSpeed(hexdec($arrBuff1) / 1000000); // Linux sparc64
226
							$results['model'] .= ' (' . $value . ')';
418
                            $speedset = true;
227
							break;
419
                            break;
-
 
420
                        case 'l3 cache':
228
						case 'processor':
421
                        case 'cache size':
-
 
422
                            $dev->setCache(trim(preg_replace("/[a-zA-Z]/", "", $arrBuff1)) * 1024);
229
							$results['cpus'] += 1;
423
                            break;
-
 
424
                        case 'initial bogomips':
-
 
425
                        case 'bogomips':
-
 
426
                        case 'cpu0bogo':
-
 
427
                            $dev->setBogomips(round($arrBuff1));
230
							break;
428
                            break;
-
 
429
                        case 'flags':
-
 
430
                            if (preg_match("/ vmx/", $arrBuff1)) {
-
 
431
                                $dev->setVirt("vmx");
-
 
432
                            } elseif (preg_match("/ svm/", $arrBuff1)) {
-
 
433
                                $dev->setVirt("svm");
-
 
434
                            } elseif (preg_match("/ hypervisor/", $arrBuff1)) {
-
 
435
                                $dev->setVirt("hypervisor");
-
 
436
                            }
-
 
437
                            break;
231
						case 'Cpu0ClkTck': // Linux sparc64
438
                        case 'i size':
-
 
439
                        case 'd size':
-
 
440
                            if ($dev->getCache() === null) {
232
							$results['cpuspeed'] = sprintf('%.2f', hexdec($value) / 1000000);
441
                                $dev->setCache($arrBuff1 * 1024);
-
 
442
                            } else {
-
 
443
                                $dev->setCache($dev->getCache() + ($arrBuff1 * 1024));
-
 
444
                            }
-
 
445
                            break;
-
 
446
                        case 'cpu architecture':
-
 
447
                            $arch = $arrBuff1;
233
							break;
448
                            break;
234
						case 'Cpu0Bogo': // Linux sparc64 & sparc32
449
                        case 'cpu implementer':
235
							$results['bogomips'] = $value;
450
                            $impl = $arrBuff1;
236
							break;
451
                            break;
-
 
452
                        case 'cpu part':
237
						case 'ncpus probed': // Linux sparc64 & sparc32
453
                            $part = $arrBuff1;
238
							$results['cpus'] = $value;
454
                            break;
-
 
455
                        case 'vendor_id':
-
 
456
                            $dev->setVendorId($arrBuff1);
239
							break;
457
                            break;
240
		 			}
458
                        }
241
				}
459
                    }
242
			}
460
                }
-
 
461
                if ($arch === null) $arch = $_arch;
-
 
462
                if ($impl === null) $impl = $_impl;
-
 
463
                if ($part === null) $part = $_part;
243
		
464
 
244
			// sparc64 specific code follows
465
                // sparc64 specific code follows
245
			// This adds the ability to display the cache that a CPU has
466
                // This adds the ability to display the cache that a CPU has
246
			// Originally made by Sven Blumenstein <bazik@gentoo.org> in 2004
467
                // Originally made by Sven Blumenstein <bazik@gentoo.org> in 2004
247
			// Modified by Tom Weustink <freshy98@gmx.net> in 2004
468
                // Modified by Tom Weustink <freshy98@gmx.net> in 2004
248
			$sparclist = array('SUNW,UltraSPARC@0,0', 'SUNW,UltraSPARC-II@0,0', 'SUNW,UltraSPARC@1c,0', 'SUNW,UltraSPARC-IIi@1c,0', 'SUNW,UltraSPARC-II@1c,0', 'SUNW,UltraSPARC-IIe@0,0');
469
                $sparclist = array('SUNW,UltraSPARC@0,0', 'SUNW,UltraSPARC-II@0,0', 'SUNW,UltraSPARC@1c,0', 'SUNW,UltraSPARC-IIi@1c,0', 'SUNW,UltraSPARC-II@1c,0', 'SUNW,UltraSPARC-IIe@0,0');
249
			foreach ($sparclist as $name) {
470
                foreach ($sparclist as $name) {
250
				$buf = rfts( '/proc/openprom/' . $name . '/ecache-size',1 , 32, false );
471
                    if (CommonFunctions::rfts('/proc/openprom/'.$name.'/ecache-size', $buf, 1, 32, false)) {
251
				if( $buf != "ERROR" ) {
-
 
252
					$results['cache'] = base_convert($buf, 16, 10)/1024 . ' KB';
472
                        $dev->setCache(base_convert(trim($buf), 16, 10));
253
				}
473
                    }
254
			}
474
                }
255
			// sparc64 specific code ends
475
                // sparc64 specific code ends
256
	
476
 
257
			// XScale detection code
477
                // XScale detection code
-
 
478
                if (($arch === "5TE") && ($dev->getBogomips() != null)) {
-
 
479
                    $dev->setCpuSpeed($dev->getBogomips()); //BogoMIPS are not BogoMIPS on this CPU, it's the speed
258
			if ( $results['cpus'] == 0 ) {
480
                    $speedset = true;
-
 
481
                    $dev->setBogomips(null); // no BogoMIPS available, unset previously set BogoMIPS
259
				foreach( $bufe as $buf ) {
482
                }
-
 
483
 
-
 
484
                if (($dev->getBusSpeed() == 0) && ($_buss !== null)) {
260
					$fields = preg_split('/\s*:\s*/', trim($buf), 2);
485
                    $dev->setBusSpeed($_buss);
-
 
486
                }
-
 
487
                if (($dev->getCpuSpeed() == 0) && ($_cpus !== null)) {
-
 
488
                    $dev->setCpuSpeed($_cpus);
261
					if (sizeof($fields) == 2) {
489
                    $speedset = true;
-
 
490
                }
-
 
491
                if (($dev->getBogomips() == 0) && ($_bogo !== null)) {
262
						list($key, $value) = $fields;
492
                    $dev->setBogomips($_bogo);
263
						switch($key) {
493
                }
-
 
494
                if (($dev->getVendorId() === null) && ($_vend !== null)) {
-
 
495
                    $dev->setVendorId($_vend);
264
							case 'Processor':
496
                }
-
 
497
 
265
								$results['cpus'] += 1;
498
                if ($proc != null) {
-
 
499
                    if (!is_numeric($proc)) {
266
								$results['model'] = $value;
500
                        $proc = 0;
267
								break;
501
                    }
268
							case 'BogoMIPS': //BogoMIPS are not BogoMIPS on this CPU, it's the speed, no BogoMIPS available
502
                    // variable speed processors specific code follows
-
 
503
                    if (CommonFunctions::rfts('/sys/devices/system/cpu/cpu'.$proc.'/cpufreq/cpuinfo_cur_freq', $buf, 1, 4096, false)) {
-
 
504
                        $dev->setCpuSpeed(trim($buf) / 1000);
-
 
505
                        $speedset = true;
-
 
506
                    } elseif (CommonFunctions::rfts('/sys/devices/system/cpu/cpu'.$proc.'/cpufreq/scaling_cur_freq', $buf, 1, 4096, false)) {
-
 
507
                        $dev->setCpuSpeed(trim($buf) / 1000);
269
								$results['cpuspeed'] = $value;
508
                        $speedset = true;
270
								break;
509
                    }
-
 
510
                    if (CommonFunctions::rfts('/sys/devices/system/cpu/cpu'.$proc.'/cpufreq/cpuinfo_max_freq', $buf, 1, 4096, false)) {
-
 
511
                        $dev->setCpuSpeedMax(trim($buf) / 1000);
271
							case 'I size':
512
                    }
-
 
513
                    if (CommonFunctions::rfts('/sys/devices/system/cpu/cpu'.$proc.'/cpufreq/cpuinfo_min_freq', $buf, 1, 4096, false)) {
272
								$results['cache'] = $value;
514
                        $dev->setCpuSpeedMin(trim($buf) / 1000);
273
								break;
515
                    }
-
 
516
                    // variable speed processors specific code ends
-
 
517
                    if (PSI_LOAD_BAR) {
-
 
518
                            $dev->setLoad($this->_parseProcStat('cpu'.$proc));
274
							case 'D size':
519
                    }
-
 
520
/*
-
 
521
                    if (CommonFunctions::rfts('/proc/acpi/thermal_zone/THRM/temperature', $buf, 1, 4096, false)
-
 
522
                       &&  preg_match("/(\S+)\sC$/", $buf, $value)) {
275
								$results['cache'] += $value;
523
                        $dev->setTemp(value[1]);
276
								break;
524
                    }
-
 
525
*/
-
 
526
                    if (($arch !== null) && ($impl !== null) && ($part !== null)) {
-
 
527
                        if (($impl === '0x41')
-
 
528
                           && (($_hard === 'BCM2708') || ($_hard === 'BCM2835') || ($_hard === 'BCM2709') || ($_hard === 'BCM2836') || ($_hard === 'BCM2710') || ($_hard === 'BCM2837') || ($_hard === 'BCM2711') || ($_hard === 'BCM2838'))
-
 
529
                           && ($_revi !== null)) { // Raspberry Pi detection (instead of 'cat /proc/device-tree/model')
-
 
530
                            if ($raslist === null) $raslist = @parse_ini_file(PSI_APP_ROOT."/data/raspberry.ini", true);
-
 
531
                            if ($raslist && !preg_match('/[^0-9a-f]/', $_revi)) {
-
 
532
                                if (($revidec = hexdec($_revi)) & 0x800000) {
-
 
533
                                    if ($this->sys->getMachine() === '') {
-
 
534
                                        $manufacturer = ($revidec >> 16) & 15;
-
 
535
                                        if (isset($raslist['manufacturer'][$manufacturer])) {
-
 
536
                                            $manuf = ' '.$raslist['manufacturer'][$manufacturer];
-
 
537
                                        } else {
-
 
538
                                            $manuf = '';
277
						}
539
                                        }
-
 
540
                                        $model = ($revidec >> 4) & 255;
-
 
541
                                        if (isset($raslist['model'][$model])) {
-
 
542
                                            $this->sys->setMachine('Raspberry Pi '.$raslist['model'][$model].' (PCB 1.'.($revidec & 15).$manuf.')');
-
 
543
                                        } else {
-
 
544
                                            $this->sys->setMachine('Raspberry Pi (PCB 1.'.($revidec & 15).$manuf.')');
278
					}
545
                                        }
279
				}
546
                                    }
-
 
547
                                } else {
-
 
548
                                    if ($this->sys->getMachine() === '') {
-
 
549
                                        if (isset($raslist['old'][$revidec & 0x7fffff])) {
-
 
550
                                            $this->sys->setMachine('Raspberry Pi '.$raslist['old'][$revidec & 0x7fffff]);
280
				$results['cache'] = $results['cache'] / 1024 . " KB";
551
                                        } else {
-
 
552
                                            $this->sys->setMachine('Raspberry Pi');
281
			}
553
                                        }
282
		}		
554
                                    }
283
		$keys = array_keys($results);
-
 
284
		$keys2be = array('model', 'cpuspeed', 'cache', 'bogomips', 'cpus');
-
 
285
		
-
 
286
		while ($ar_buf = each($keys2be)) {
-
 
287
			if (! in_array($ar_buf[1], $keys)) {
-
 
288
				$results[$ar_buf[1]] = 'N.A.';
-
 
289
			} 
555
                                }
290
		}
556
                            }
-
 
557
                        } elseif (($_hard !== null) && ($this->sys->getMachine() === '')) { // other ARM hardware
-
 
558
                            $this->sys->setMachine($_hard);
-
 
559
                        }
-
 
560
                        if ($cpulist === null) $cpulist = @parse_ini_file(PSI_APP_ROOT."/data/cpus.ini", true);
-
 
561
                        if ($cpulist && (isset($cpulist['cpu'][$cpuimplpart = strtolower($impl.','.$part)]))) {
-
 
562
                            if (($cpumodel = $dev->getModel()) !== '') {
-
 
563
                                $dev->setModel($cpumodel.' - '.$cpulist['cpu'][$cpuimplpart]);
-
 
564
                            } else {
-
 
565
                                $dev->setModel($cpulist['cpu'][$cpuimplpart]);
-
 
566
                            }
-
 
567
                        }
-
 
568
                    } elseif (($_hard !== null) && ($this->sys->getMachine() === '')) { // other hardware
-
 
569
                        $this->sys->setMachine($_hard);
-
 
570
                    }
291
		
571
 
-
 
572
                    if ($dev->getModel() === "") {
292
		$buf = rfts( '/proc/acpi/thermal_zone/THRM/temperature', 1, 4096, false );
573
                        $dev->setModel("unknown");
293
		if ( $buf != "ERROR" ) {
574
                    }
-
 
575
                    $cpucount++;
294
			$results['temp'] = substr( $buf, 25, 2 );
576
                    $this->sys->setCpus($dev);
-
 
577
                }
295
		}
578
            }
296
		
579
 
-
 
580
            $cpudevices = glob('/sys/devices/system/cpu/cpu*/uevent', GLOB_NOSORT);
-
 
581
            if (is_array($cpudevices) && (($cpustopped = count($cpudevices)-$cpucount) > 0)) {
-
 
582
                for (; $cpustopped > 0; $cpustopped--) {
-
 
583
                    $dev = new CpuDevice();
-
 
584
                    $dev->setModel("stopped");
-
 
585
                    if ($speedset) {
-
 
586
                        $dev->setCpuSpeed(-1);
-
 
587
                    }
-
 
588
                    $this->sys->setCpus($dev);
297
		return $results;
589
                }
-
 
590
            }
-
 
591
        }
298
	}
592
    }
299
 
593
 
-
 
594
    /**
-
 
595
     * PCI devices
-
 
596
     *
-
 
597
     * @return void
-
 
598
     */
300
	function pci () {
599
    private function _pci()
-
 
600
    {
301
		$arrResults = array();
601
        if ($arrResults = Parser::lspci()) {
-
 
602
            foreach ($arrResults as $dev) {
-
 
603
                $this->sys->setPciDevices($dev);
-
 
604
            }
-
 
605
        } elseif (CommonFunctions::rfts('/proc/pci', $strBuf, 0, 4096, false)) {
302
		$booDevice = false;
606
            $booDevice = false;
303
		
-
 
304
		if( ! $arrResults = $this->parser->parse_lspci() ) {
-
 
305
			$strBuf = rfts( '/proc/pci', 0, 4096, false );
-
 
306
			if( $strBuf != "ERROR" ) {
-
 
307
				$arrBuf = explode( "\n", $strBuf );
607
            $arrBuf = preg_split("/\n/", $strBuf, -1, PREG_SPLIT_NO_EMPTY);
308
				foreach( $arrBuf as $strLine ) {
608
            foreach ($arrBuf as $strLine) {
309
					if( preg_match( '/Bus/', $strLine ) ) {
609
                if (preg_match('/^\s*Bus\s/', $strLine)) {
310
						$booDevice = true;
610
                    $booDevice = true;
311
						continue;
611
                    continue;
312
					}
612
                }
313
					if( $booDevice ) {
613
                if ($booDevice) {
-
 
614
                    $dev = new HWDevice();
-
 
615
                    $dev->setName(preg_replace('/\([^\)]+\)\.$/', '', trim($strLine)));
-
 
616
                    $this->sys->setPciDevices($dev);
-
 
617
/*
314
						list( $strKey, $strValue ) = explode( ': ', $strLine, 2 );
618
                    list($strKey, $strValue) = preg_split('/: /', $strLine, 2);
315
						if( ! preg_match( '/bridge/i', $strKey ) && ! preg_match( '/USB/i ', $strKey ) ) {
619
                    if (!preg_match('/bridge/i', $strKey) && !preg_match('/USB/i ', $strKey)) {
-
 
620
                        $dev = new HWDevice();
316
							$arrResults[] = preg_replace( '/\([^\)]+\)\.$/', '', trim( $strValue ) );
621
                        $dev->setName(preg_replace('/\([^\)]+\)\.$/', '', trim($strValue)));
-
 
622
                        $this->sys->setPciDevices($dev);
317
						}
623
                    }
-
 
624
*/
318
						$booDevice = false;
625
                    $booDevice = false;
319
					}
626
                }
320
				}
627
            }
-
 
628
        } else {
-
 
629
            $pcidevices = glob('/sys/bus/pci/devices/*/uevent', GLOB_NOSORT);
-
 
630
            if (is_array($pcidevices) && (($total = count($pcidevices)) > 0)) {
321
				asort( $arrResults );
631
                $buf = "";
-
 
632
                for ($i = 0; $i < $total; $i++) {
-
 
633
                    if (CommonFunctions::rfts($pcidevices[$i], $buf, 0, 4096, false) && (trim($buf) != "")) {
-
 
634
                        $pcibuf = "";
-
 
635
                        if (preg_match("/^PCI_CLASS=(\S+)/m", trim($buf), $subbuf)) {
-
 
636
                            $pcibuf = "Class ".$subbuf[1].":";
-
 
637
                        }
-
 
638
                        if (preg_match("/^PCI_ID=(\S+)/m", trim($buf), $subbuf)) {
-
 
639
                            $pcibuf .= " Device ".$subbuf[1];
-
 
640
                        }
-
 
641
                        if (preg_match("/^DRIVER=(\S+)/m", trim($buf), $subbuf)) {
-
 
642
                            $pcibuf .= " Driver ".$subbuf[1];
-
 
643
                        }
-
 
644
                        $dev = new HWDevice();
-
 
645
                        if (trim($pcibuf) != "") {
-
 
646
                            $dev->setName(trim($pcibuf));
-
 
647
                        } else {
-
 
648
                            $dev->setName("unknown");
-
 
649
                        }
-
 
650
                        $this->sys->setPciDevices($dev);
-
 
651
                    }
-
 
652
                }
322
			}
653
            }
323
		}
654
        }
324
		return $arrResults;
-
 
325
	} 
655
    }
326
 
656
 
-
 
657
    /**
327
  function ide () {
658
     * IDE devices
-
 
659
     *
328
    $results = array();
660
     * @return void
-
 
661
     */
329
    $bufd = gdc( '/proc/ide', false );
662
    private function _ide()
330
 
663
    {
-
 
664
        $bufd = CommonFunctions::gdc('/proc/ide', false);
331
    foreach( $bufd as $file ) {
665
        foreach ($bufd as $file) {
332
      if (preg_match('/^hd/', $file)) {
666
            if (preg_match('/^hd/', $file)) {
333
        $results[$file] = array(); 
667
                $dev = new HWDevice();
334
	$buf = rfts("/proc/ide/" . $file . "/media", 1 );
-
 
335
        if ( $buf != "ERROR" ) {
-
 
336
          $results[$file]['media'] = trim($buf);
668
                $dev->setName(trim($file));
337
          if ($results[$file]['media'] == 'disk') {
669
                if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS && CommonFunctions::rfts("/proc/ide/".$file."/media", $buf, 1)) {
338
            $results[$file]['media'] = 'Hard Disk';
670
                    if (trim($buf) == 'disk') {
339
	    $buf = rfts( "/proc/ide/" . $file . "/capacity", 1, 4096, false);
671
                        if (CommonFunctions::rfts("/proc/ide/".$file."/capacity", $buf, 1, 4096, false) || CommonFunctions::rfts("/sys/block/".$file."/size", $buf, 1, 4096, false)) {
340
	    if( $buf == "ERROR" ) {
-
 
341
		$buf = rfts( "/sys/block/" . $file . "/size", 1, 4096, false);
-
 
342
	    }
-
 
343
	    if ( $buf != "ERROR" ) {
-
 
344
    	        $results[$file]['capacity'] = trim( $buf );
672
                            $dev->setCapacity(trim($buf) * 512);
345
    	    } 
673
                        }
346
          } elseif ($results[$file]['media'] == 'cdrom') {
-
 
347
            $results[$file]['media'] = 'CD-ROM';
-
 
348
	    unset($results[$file]['capacity']);
-
 
349
          } 
674
                    }
350
        } else {
-
 
351
		unset($results[$file]);
-
 
352
	} 
675
                }
353
 
-
 
354
	$buf = rfts( "/proc/ide/" . $file . "/model", 1 );
676
                if (CommonFunctions::rfts("/proc/ide/".$file."/model", $buf, 1)) {
355
        if ( $buf != "ERROR" ) {
-
 
356
          $results[$file]['model'] = trim( $buf );
677
                    $dev->setName($dev->getName().": ".trim($buf));
357
          if (preg_match('/WDC/', $results[$file]['model'])) {
-
 
358
            $results[$file]['manufacture'] = 'Western Digital';
-
 
359
          } elseif (preg_match('/IBM/', $results[$file]['model'])) {
-
 
360
            $results[$file]['manufacture'] = 'IBM';
-
 
361
          } elseif (preg_match('/FUJITSU/', $results[$file]['model'])) {
-
 
362
            $results[$file]['manufacture'] = 'Fujitsu';
-
 
363
          } else {
-
 
364
            $results[$file]['manufacture'] = 'Unknown';
-
 
365
          } 
678
                }
-
 
679
                $this->sys->setIdeDevices($dev);
366
        } 
680
            }
367
	
-
 
368
      } 
681
        }
369
    } 
682
    }
370
 
683
 
-
 
684
    /**
371
    asort($results);
685
     * SCSI devices
-
 
686
     *
372
    return $results;
687
     * @return void
-
 
688
     */
-
 
689
    private function _scsi()
-
 
690
    {
-
 
691
        $getline = 0;
-
 
692
        $device = null;
-
 
693
        $scsiid = null;
-
 
694
        if (CommonFunctions::executeProgram('lsscsi', '-c', $bufr, PSI_DEBUG) || CommonFunctions::rfts('/proc/scsi/scsi', $bufr, 0, 4096, PSI_DEBUG)) {
-
 
695
            $bufe = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
-
 
696
            foreach ($bufe as $buf) {
-
 
697
                if (preg_match('/Host: scsi(\d+) Channel: (\d+) Target: (\d+) Lun: (\d+)/i', $buf, $scsiids)
-
 
698
                   || preg_match('/Host: scsi(\d+) Channel: (\d+) Id: (\d+) Lun: (\d+)/i', $buf, $scsiids)) {
-
 
699
                    $scsiid = $scsiids;
-
 
700
                    $getline = 1;
-
 
701
                    continue;
373
  } 
702
                }
-
 
703
                if ($getline == 1) {
-
 
704
                    preg_match('/Vendor: (.*) Model: (.*) Rev: (.*)/i', $buf, $devices);
-
 
705
                    $getline = 2;
-
 
706
                    $device = $devices;
-
 
707
                    continue;
-
 
708
                }
-
 
709
                if ($getline == 2) {
-
 
710
                    preg_match('/Type:\s+(\S+)/i', $buf, $dev_type);
374
 
711
 
375
  function scsi () {
-
 
376
    $results = array();
712
                    $dev = new HWDevice();
377
    $dev_vendor = '';
-
 
378
    $dev_model = '';
713
                    $dev->setName($device[1].' '.$device[2].' ('.$dev_type[1].')');
379
    $dev_rev = '';
-
 
380
    $dev_type = '';
-
 
381
    $s = 1;
-
 
382
    $get_type = 0;
-
 
383
 
714
 
-
 
715
                    if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS
-
 
716
                       && ($dev_type[1]==='Direct-Access')) {
-
 
717
                       $sizelist = glob('/sys/bus/scsi/devices/'.intval($scsiid[1]).':'.intval($scsiid[2]).':'.intval($scsiid[3]).':'.intval($scsiid[4]).'/*/*/size', GLOB_NOSORT);
-
 
718
                       if (is_array($sizelist) && (($total = count($sizelist)) > 0)) {
-
 
719
                           $buf = "";
384
    $bufr = execute_program('lsscsi', '-c', false);
720
                           for ($i = 0; $i < $total; $i++) {
-
 
721
                               if (CommonFunctions::rfts($sizelist[$i], $buf, 1, 4096, false) && (($buf=trim($buf)) != "") && ($buf > 0)) {
-
 
722
                                   $dev->setCapacity($buf * 512);
-
 
723
                                   break;
-
 
724
                               }
385
    if( $bufr == "ERROR" ) {
725
                           }
-
 
726
                       }
-
 
727
                    }
386
    	$bufr = rfts( '/proc/scsi/scsi', 0, 4096, false);
728
                    $this->sys->setScsiDevices($dev);
-
 
729
                    $getline = 0;
-
 
730
                }
387
    }
731
            }
-
 
732
        }
-
 
733
    }
-
 
734
 
-
 
735
    /**
-
 
736
     * USB devices
-
 
737
     *
-
 
738
     * @return void
-
 
739
     */
-
 
740
    protected function _usb()
-
 
741
    {
388
    if ( $bufr != "ERROR" ) {
742
        $usbarray = array();
-
 
743
        if (CommonFunctions::executeProgram('lsusb', (PSI_OS != 'Android')?'':'2>/dev/null', $bufr, PSI_DEBUG && (PSI_OS != 'Android'), 5) && ($bufr !== "")) {
389
      $bufe = explode("\n", $bufr);
744
            $bufe = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
390
      foreach( $bufe as $buf ) {
745
            foreach ($bufe as $buf) {
391
        if (preg_match('/Vendor/', $buf)) {
746
                $device = preg_split("/ /", $buf, 7);
392
          preg_match('/Vendor: (.*) Model: (.*) Rev: (.*)/i', $buf, $dev);
747
                if (((isset($device[6]) && trim($device[6]) != "")) ||
393
          list($key, $value) = explode(': ', $buf, 2);
748
                    ((isset($device[5]) && trim($device[5]) != ""))) {
-
 
749
                    $usbid = intval($device[1]).'-'.intval(trim($device[3],':')).' '.$device[5];
-
 
750
                    if ((isset($device[6]) && trim($device[6]) != "")) {
-
 
751
                        $usbarray[$usbid]['name'] = trim($device[6]);
394
          $dev_str = $value;
752
                    } else {
-
 
753
                        $usbarray[$usbid]['name'] = 'unknown';
395
          $get_type = true;
754
                    }
396
          continue;
755
                }
-
 
756
            }
397
        } 
757
        }
398
 
758
 
-
 
759
        $usbdevices = glob('/sys/bus/usb/devices/*/idProduct', GLOB_NOSORT);
-
 
760
        if (is_array($usbdevices) && (($total = count($usbdevices)) > 0)) {
-
 
761
            for ($i = 0; $i < $total; $i++) {
-
 
762
                if (CommonFunctions::rfts($usbdevices[$i], $idproduct, 1, 4096, false) && (($idproduct=trim($idproduct)) != "")) { //is readable
-
 
763
                    $busnum = CommonFunctions::rolv($usbdevices[$i], '/\/idProduct$/', '/busnum');
-
 
764
                    $devnum = CommonFunctions::rolv($usbdevices[$i], '/\/idProduct$/', '/devnum');
-
 
765
                    $idvendor = CommonFunctions::rolv($usbdevices[$i], '/\/idProduct$/', '/idVendor');
-
 
766
                    if (($busnum!==null) && ($devnum!==null) && ($idvendor!==null)) {
-
 
767
                        $usbid = intval($busnum).'-'.intval($devnum).' '.$idvendor.':'.$idproduct;
-
 
768
                        $manufacturer = CommonFunctions::rolv($usbdevices[$i], '/\/idProduct$/', '/manufacturer');
-
 
769
                        if ($manufacturer!==null) {
-
 
770
                            $usbarray[$usbid]['manufacturer'] = $manufacturer;
399
        if ($get_type) {
771
                        }
-
 
772
                        $product = CommonFunctions::rolv($usbdevices[$i], '/\/idProduct$/', '/product');
-
 
773
                        if ($product!==null) {
400
          preg_match('/Type:\s+(\S+)/i', $buf, $dev_type);
774
                            $usbarray[$usbid]['product'] = $product;
-
 
775
                        }
-
 
776
                        if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS
-
 
777
                           && defined('PSI_SHOW_DEVICES_SERIAL') && PSI_SHOW_DEVICES_SERIAL) {
-
 
778
                            $serial = CommonFunctions::rolv($usbdevices[$i], '/\/idProduct$/', '/serial');
401
          $results[$s]['model'] = "$dev[1] $dev[2] ($dev_type[1])";
779
                            if (($serial!==null) && !preg_match('/\W/', $serial)) {
402
          $results[$s]['media'] = "Hard Disk";
780
                                $usbarray[$usbid]['serial'] = $serial;
403
          $s++;
781
                            }
404
          $get_type = false;
782
                        }
405
        } 
783
                    }
406
      } 
784
                }
407
    } 
785
            }
408
    asort($results);
-
 
409
    return $results;
-
 
410
  } 
786
        }
411
 
787
 
412
  function usb () {
788
        if ((count($usbarray) == 0) && CommonFunctions::rfts('/proc/bus/usb/devices', $bufr, 0, 4096, false)) {
413
    $results = array();
-
 
414
    $devnum = -1;
789
            $devnum = -1;
415
 
-
 
416
    $bufr = execute_program('lsusb', '', false);
-
 
417
    if( $bufr == "ERROR" ) {
-
 
418
	$bufr = rfts( '/proc/bus/usb/devices', 0, 4096, false );
-
 
419
        if ( $bufr != "ERROR" ) {
-
 
420
    	    $bufe = explode("\n", $bufr);
790
            $bufe = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
421
	    foreach( $bufe as $buf ) {
791
            foreach ($bufe as $buf) {
422
        	if (preg_match('/^T/', $buf)) {
792
                if (preg_match('/^T/', $buf)) {
423
            	    $devnum += 1;
793
                    $devnum++;
424
    		    $results[$devnum] = "";
-
 
425
        	} elseif (preg_match('/^S:/', $buf)) {
794
                } elseif (preg_match('/^S:/', $buf)) {
426
            	    list($key, $value) = explode(': ', $buf, 2);
795
                    list($key, $value) = preg_split('/: /', $buf, 2);
427
            	    list($key, $value2) = explode('=', $value, 2);
796
                    list($key, $value2) = preg_split('/=/', $value, 2);
428
    		    if (trim($key) != "SerialNumber") {
797
                    switch (trim($key)) {
-
 
798
                    case 'Manufacturer':
-
 
799
                        $usbarray[$devnum]['manufacturer'] = trim($value2);
-
 
800
                        break;
-
 
801
                    case 'Product':
429
            		$results[$devnum] .= " " . trim($value2);
802
                        $usbarray[$devnum]['product'] = trim($value2);
430
            		$devstring = 0;
803
                        break;
-
 
804
                    case 'SerialNumber':
-
 
805
                        if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS
-
 
806
                           && defined('PSI_SHOW_DEVICES_SERIAL') && PSI_SHOW_DEVICES_SERIAL
-
 
807
                           && !preg_match('/\W/', trim($value2))) {
-
 
808
                            $usbarray[$devnum]['serial'] = trim($value2);
431
    		    }
809
                         }
-
 
810
                         break;
432
        	} 
811
                    }
433
            }
812
                }
434
        } 
813
            }
435
    } else {
-
 
436
	$bufe = explode( "\n", $bufr );
-
 
437
	foreach( $bufe as $buf ) {
-
 
438
	    $device = preg_split("/ /", $buf, 7);
-
 
439
	    if( isset( $device[6] ) && trim( $device[6] ) != "" ) {
-
 
440
		$results[$devnum++] = trim( $device[6] );
-
 
441
	    }
814
        }
-
 
815
 
-
 
816
        if ((count($usbarray) == 0) && CommonFunctions::rfts('/proc/bus/input/devices', $bufr, 0, 4096, false)) {
-
 
817
            $devnam = "unknown";
-
 
818
            $bufe = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
-
 
819
            foreach ($bufe as $buf) {
-
 
820
                if (preg_match('/^I:\s+(.+)/', $buf, $bufr)
-
 
821
                   && isset($bufr[1]) && (trim($bufr[1])!=="")) {
-
 
822
                    $devnam = trim($bufr[1]);
-
 
823
                    $usbarray[$devnam]['phys'] = 'unknown';
-
 
824
                } elseif (preg_match('/^N:\s+Name="([^"]+)"/', $buf, $bufr2)
-
 
825
                   && isset($bufr2[1]) && (trim($bufr2[1])!=="")) {
-
 
826
                    $usbarray[$devnam]['name'] = trim($bufr2[1]);
-
 
827
                } elseif (preg_match('/^P:\s+Phys=(.*)/', $buf, $bufr2)
-
 
828
                   && isset($bufr2[1]) && (trim($bufr2[1])!=="")) {
-
 
829
                    $usbarray[$devnam]['phys'] = trim($bufr2[1]);
-
 
830
                } elseif (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS
-
 
831
                   && defined('PSI_SHOW_DEVICES_SERIAL') && PSI_SHOW_DEVICES_SERIAL
-
 
832
                   && preg_match('/^U:\s+Uniq=(.+)/', $buf, $bufr2)
-
 
833
                   && isset($bufr2[1]) && (trim($bufr2[1])!=="")) {
-
 
834
                    $usbarray[$devnam]['serial'] = trim($bufr2[1]);
442
	}
835
                }
443
    }
836
            }
444
    return $results;
-
 
445
  } 
837
        }
446
 
838
 
-
 
839
        foreach ($usbarray as $usbdev) if (!isset($usbdev['phys']) || preg_match('/^usb-/', $usbdev['phys'])) {
447
  function sbus () {
840
            $dev = new HWDevice();
-
 
841
 
-
 
842
            if (isset($usbdev['manufacturer']) && (($manufacturer=$usbdev['manufacturer']) !== 'no manufacturer')) {
-
 
843
                if (preg_match("/^linux\s/i", $manufacturer)) {
448
    $results = array();
844
                    $manufacturer = 'Linux Foundation';
449
    $_results[0] = ""; 
845
                }
-
 
846
                if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS) {
450
    // TODO. Nothing here yet. Move along.
847
                    $dev->setManufacturer($manufacturer);
451
    $results = $_results;
848
                }
452
    return $results;
849
            } else {
-
 
850
                $manufacturer = '';
453
  } 
851
            }
454
 
852
 
-
 
853
            if (isset($usbdev['product'])) {
-
 
854
                $product = $usbdev['product'];
-
 
855
                if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS) {
-
 
856
                    $dev->setProduct($product);
-
 
857
                }
455
  function network () {
858
            } else {
456
    $results = array();
859
                $product = '';
-
 
860
            }
457
 
861
 
458
    $bufr = rfts( '/proc/net/dev' );
862
            if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS
459
    if ( $bufr != "ERROR" ) {
-
 
460
      $bufe = explode("\n", $bufr);
863
                && defined('PSI_SHOW_DEVICES_SERIAL') && PSI_SHOW_DEVICES_SERIAL
461
      foreach( $bufe as $buf ) {
-
 
462
        if (preg_match('/:/', $buf)) {
864
                && isset($usbdev['serial'])) {
463
          list($dev_name, $stats_list) = preg_split('/:/', $buf, 2);
-
 
464
          $stats = preg_split('/\s+/', trim($stats_list));
865
                $dev->setSerial($usbdev['serial']);
465
          $results[$dev_name] = array();
866
            }
466
 
867
 
-
 
868
            if (isset($usbdev['name']) && (($name=$usbdev['name']) !== 'unknown')) {
467
          $results[$dev_name]['rx_bytes'] = $stats[0];
869
                $dev->setName($name);
-
 
870
            } else {
468
          $results[$dev_name]['rx_packets'] = $stats[1];
871
                if (($newname = trim($manufacturer.' '.$product)) !== '') {
469
          $results[$dev_name]['rx_errs'] = $stats[2];
872
                    $dev->setName($newname);
-
 
873
                } else {
470
          $results[$dev_name]['rx_drop'] = $stats[3];
874
                    $dev->setName('unknown');
-
 
875
                }
-
 
876
            }
471
 
877
 
472
          $results[$dev_name]['tx_bytes'] = $stats[8];
878
            $this->sys->setUsbDevices($dev);
473
          $results[$dev_name]['tx_packets'] = $stats[9];
-
 
474
          $results[$dev_name]['tx_errs'] = $stats[10];
879
        }
475
          $results[$dev_name]['tx_drop'] = $stats[11];
880
    }
476
 
881
 
-
 
882
    /**
-
 
883
     * I2C devices
-
 
884
     *
-
 
885
     * @return void
-
 
886
     */
-
 
887
    protected function _i2c()
-
 
888
    {
-
 
889
        $i2cdevices = glob('/sys/bus/i2c/devices/*/name', GLOB_NOSORT);
477
          $results[$dev_name]['errs'] = $stats[2] + $stats[10];
890
        if (is_array($i2cdevices) && (($total = count($i2cdevices)) > 0)) {
-
 
891
            $buf = "";
478
          $results[$dev_name]['drop'] = $stats[3] + $stats[11];
892
            for ($i = 0; $i < $total; $i++) {
-
 
893
                if (CommonFunctions::rfts($i2cdevices[$i], $buf, 1, 4096, false) && (trim($buf) != "")) {
-
 
894
                    $dev = new HWDevice();
-
 
895
                    $dev->setName(trim($buf));
-
 
896
                    $this->sys->setI2cDevices($dev);
479
        } 
897
                }
480
      }
898
            }
481
    }
899
        }
482
    return $results;
-
 
483
  } 
900
    }
484
 
901
 
-
 
902
    /**
-
 
903
     * NVMe devices
-
 
904
     *
485
  function memory () {
905
     * @return void
-
 
906
     */
486
    $results['ram'] = array('total' => 0, 'free' => 0, 'used' => 0, 'percent' => 0);
907
    protected function _nvme()
-
 
908
    {
487
    $results['swap'] = array('total' => 0, 'free' => 0, 'used' => 0, 'percent' => 0);
909
        if (CommonFunctions::executeProgram('nvme', 'list', $bufr, PSI_DEBUG) && ($bufr!="")) {
488
    $results['devswap'] = array();
910
            $bufe = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
489
 
-
 
490
    $bufr = rfts( '/proc/meminfo' );
911
            $count = 0;
491
    if ( $bufr != "ERROR" ) {
912
            $nlocate = array();
492
      $bufe = explode("\n", $bufr);
913
            $nsize = array();
493
      foreach( $bufe as $buf ) {
914
            foreach ($bufe as $buf) {
-
 
915
                if ($count == 1) {
-
 
916
                    $locid = 0;
-
 
917
                    $nlocate[0] = 0;
-
 
918
                    $total = strlen($buf);
-
 
919
                    $begin = true;
-
 
920
                    for ($i = 0; $i < $total; $i++) {
-
 
921
                        if ($begin) {
-
 
922
                            if ($buf[$i] !== '-') {
-
 
923
                                $nsize[$locid] = $i - $nlocate[$locid];
-
 
924
                                $locid++;
-
 
925
                                $begin = false;
-
 
926
                            }
-
 
927
                        } else {
-
 
928
                            if ($buf[$i] === '-') {
-
 
929
                                $nlocate[$locid] = $i;
-
 
930
                                $begin = true;
-
 
931
                            }
-
 
932
                        }
-
 
933
                    }
-
 
934
                    if ($begin) {
-
 
935
                        $nsize[$locid] = $i - $nlocate[$locid];
-
 
936
                    }
-
 
937
                } elseif ($count > 1) {
494
        if (preg_match('/^MemTotal:\s+(.*)\s*kB/i', $buf, $ar_buf)) {
938
                    if (isset($nlocate[2]) && isset($nsize[2])) {
495
          $results['ram']['total'] = $ar_buf[1];
939
                        $dev = new HWDevice();
496
        } else if (preg_match('/^MemFree:\s+(.*)\s*kB/i', $buf, $ar_buf)) {
940
                        $dev->setName(trim(substr($buf, $nlocate[2], $nsize[2])));
-
 
941
                        if (defined('PSI_SHOW_DEVICES_INFOS') && (PSI_SHOW_DEVICES_INFOS)) {
-
 
942
                            if (isset($nlocate[4]) && isset($nsize[4])) {
-
 
943
                                if (preg_match('/\/\s*([0-9\.]+)\s*(B|KB|MB|GB|TB|PB)$/', str_replace(',', '.', trim(substr($buf, $nlocate[4], $nsize[4]))), $tmpbuf)) {
497
          $results['ram']['free'] = $ar_buf[1];
944
                                    switch ($tmpbuf[2]) {
-
 
945
                                        case 'B':
498
        } else if (preg_match('/^Cached:\s+(.*)\s*kB/i', $buf, $ar_buf)) {
946
                                            $dev->setCapacity($tmpbuf[1]);
499
          $results['ram']['cached'] = $ar_buf[1];
947
                                            break;
-
 
948
                                        case 'KB':
500
        } else if (preg_match('/^Buffers:\s+(.*)\s*kB/i', $buf, $ar_buf)) {
949
                                            $dev->setCapacity(1000*$tmpbuf[1]);
-
 
950
                                            break;
-
 
951
                                        case 'MB':
-
 
952
                                            $dev->setCapacity(1000*1000*$tmpbuf[1]);
-
 
953
                                            break;
-
 
954
                                        case 'GB':
-
 
955
                                            $dev->setCapacity(1000*1000*1000*$tmpbuf[1]);
-
 
956
                                            break;
-
 
957
                                        case 'TB':
-
 
958
                                            $dev->setCapacity(1000*1000*1000*1000*$tmpbuf[1]);
501
          $results['ram']['buffers'] = $ar_buf[1];
959
                                            break;
-
 
960
                                        case 'PB':
-
 
961
                                            $dev->setCapacity(1000*1000*1000*1000*1000*$tmpbuf[1]);
-
 
962
                                            break;
-
 
963
                                    }
-
 
964
                                }
-
 
965
                            }
-
 
966
                            if (defined('PSI_SHOW_DEVICES_SERIAL') && PSI_SHOW_DEVICES_SERIAL) {
-
 
967
                                if (isset($nlocate[1]) && isset($nsize[1])) {
-
 
968
                                    $dev->setSerial(trim(substr($buf, $nlocate[1], $nsize[1])));
-
 
969
                                }
-
 
970
                            }
-
 
971
                        }
-
 
972
                        $this->sys->setNvmeDevices($dev);
-
 
973
                    }
-
 
974
                }
-
 
975
                $count++;
-
 
976
            }
502
        } 
977
        }
503
      } 
978
    }
504
 
979
 
-
 
980
    /**
-
 
981
     * Network devices
-
 
982
     * includes also rx/tx bytes
-
 
983
     *
-
 
984
     * @return void
-
 
985
     */
-
 
986
    protected function _network()
-
 
987
    {
-
 
988
        if (CommonFunctions::rfts('/proc/net/dev', $bufr, 0, 4096, PSI_DEBUG)) {
-
 
989
            $bufe = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
-
 
990
            foreach ($bufe as $buf) {
-
 
991
                if (preg_match('/:/', $buf)) {
505
      $results['ram']['used'] = $results['ram']['total'] - $results['ram']['free'];
992
                    list($dev_name, $stats_list) = preg_split('/:/', $buf, 2);
-
 
993
                    $stats = preg_split('/\s+/', trim($stats_list));
-
 
994
                    $dev = new NetDevice();
-
 
995
                    $dev->setName(trim($dev_name));
-
 
996
                    $dev->setRxBytes($stats[0]);
-
 
997
                    $dev->setTxBytes($stats[8]);
-
 
998
                    $dev->setErrors($stats[2] + $stats[10]);
-
 
999
                    $dev->setDrops($stats[3] + $stats[11]);
-
 
1000
                    if (defined('PSI_SHOW_NETWORK_INFOS') && (PSI_SHOW_NETWORK_INFOS)) {
-
 
1001
                        $macaddr = "";
-
 
1002
                        if ((CommonFunctions::executeProgram('ip', 'addr show '.trim($dev_name), $bufr2, PSI_DEBUG) && ($bufr2!=""))
-
 
1003
                           || CommonFunctions::executeProgram('ifconfig', trim($dev_name).' 2>/dev/null', $bufr2, PSI_DEBUG)) {
-
 
1004
                            $bufe2 = preg_split("/\n/", $bufr2, -1, PREG_SPLIT_NO_EMPTY);
-
 
1005
                            foreach ($bufe2 as $buf2) {
-
 
1006
//                                if (preg_match('/^'.trim($dev_name).'\s+Link\sencap:Ethernet\s+HWaddr\s(\S+)/i', $buf2, $ar_buf2)
-
 
1007
                                if (preg_match('/\s+encap:Ethernet\s+HWaddr\s(\S+)/i', $buf2, $ar_buf2)
-
 
1008
                                   || preg_match('/\s+encap:UNSPEC\s+HWaddr\s(\S+)-00-00-00-00-00-00-00-00-00-00\s*$/i', $buf2, $ar_buf2)
-
 
1009
                                   || preg_match('/^\s+ether\s+(\S+)\s+txqueuelen/i', $buf2, $ar_buf2)
-
 
1010
                                   || preg_match('/^\s+link\/ether\s+(\S+)\s+brd/i', $buf2, $ar_buf2)
-
 
1011
                                   || preg_match('/^\s+link\/ether\s+(\S+)$/i', $buf2, $ar_buf2)
-
 
1012
                                   || preg_match('/^\s+link\/ieee802.11\s+(\S+)$/i', $buf2, $ar_buf2)) {
-
 
1013
                                    if (!defined('PSI_HIDE_NETWORK_MACADDR') || !PSI_HIDE_NETWORK_MACADDR) {
506
      $results['ram']['percent'] = round(($results['ram']['used'] * 100) / $results['ram']['total']);
1014
                                        $macaddr = preg_replace('/:/', '-', strtoupper($ar_buf2[1]));
-
 
1015
                                        if ($macaddr === '00-00-00-00-00-00') { // empty
-
 
1016
                                            $macaddr = "";
-
 
1017
                                        }
-
 
1018
                                    }
-
 
1019
                                } elseif (preg_match('/^\s+inet\saddr:(\S+)\s+P-t-P:(\S+)/i', $buf2, $ar_buf2)
-
 
1020
                                       || preg_match('/^\s+inet\s+(\S+)\s+netmask.+destination\s+(\S+)/i', $buf2, $ar_buf2)
-
 
1021
                                       || preg_match('/^\s+inet\s+([^\/\s]+).*peer\s+([^\/\s]+).*\s+scope\s((global)|(host))/i', $buf2, $ar_buf2)) {
-
 
1022
                                    if ($ar_buf2[1] != $ar_buf2[2]) {
-
 
1023
                                        $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$ar_buf2[1].";:".$ar_buf2[2]);
-
 
1024
                                    } else {
-
 
1025
                                        $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$ar_buf2[1]);
-
 
1026
                                    }
-
 
1027
                                } elseif ((preg_match('/^\s+inet\saddr:(\S+)/i', $buf2, $ar_buf2)
-
 
1028
                                   || preg_match('/^\s+inet\s+(\S+)\s+netmask/i', $buf2, $ar_buf2)
-
 
1029
                                   || preg_match('/^'.trim($dev_name).':\s+ip\s+(\S+)\s+mask/i', $buf2, $ar_buf2)
-
 
1030
                                   || preg_match('/^\s+inet6\saddr:\s([^\/\s]+)(.+)\s+Scope:[GH]/i', $buf2, $ar_buf2)
-
 
1031
                                   || preg_match('/^\s+inet6\s+(\S+)\s+prefixlen(.+)((<global>)|(<host>))/i', $buf2, $ar_buf2)
-
 
1032
                                   || preg_match('/^\s+inet6?\s+([^\/\s]+).*\s+scope\s((global)|(host))/i', $buf2, $ar_buf2))
-
 
1033
                                   && ($ar_buf2[1]!="::") && !preg_match('/^fe80::/i', $ar_buf2[1])) {
-
 
1034
                                    $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').strtolower($ar_buf2[1]));
-
 
1035
                                }
-
 
1036
                            }
-
 
1037
                        }
-
 
1038
                        if ($macaddr != "") {
-
 
1039
                            $dev->setInfo($macaddr.($dev->getInfo()?';'.$dev->getInfo():''));
-
 
1040
                        }
-
 
1041
                        if (CommonFunctions::rfts('/sys/class/net/'.trim($dev_name).'/speed', $buf, 1, 4096, false) && (($speed=trim($buf))!="") && ($buf > 0) && ($buf < 65535)) {
-
 
1042
                            if ($speed > 1000) {
-
 
1043
                                $speed = $speed/1000;
-
 
1044
                                $unit = "G";
-
 
1045
                            } else {
-
 
1046
                                $unit = "M";
-
 
1047
                            }
-
 
1048
                            if (CommonFunctions::rfts('/sys/class/net/'.trim($dev_name).'/duplex', $buf, 1, 4096, false) && (($duplex=strtolower(trim($buf)))!="") && ($duplex!='unknown')) {
-
 
1049
                                $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$speed.$unit.'b/s '.$duplex);
-
 
1050
                            } else {
-
 
1051
                                $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$speed.$unit.'b/s');
-
 
1052
                            }
-
 
1053
                        }
-
 
1054
                    }
-
 
1055
                    $this->sys->setNetDevices($dev);
-
 
1056
                }
-
 
1057
            }
-
 
1058
        } elseif (CommonFunctions::executeProgram('ip', 'addr show', $bufr, PSI_DEBUG) && ($bufr!="")) {
-
 
1059
            $lines = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
-
 
1060
            $was = false;
-
 
1061
            $macaddr = "";
-
 
1062
            $speedinfo = "";
-
 
1063
            $dev = null;
-
 
1064
            foreach ($lines as $line) {
-
 
1065
                if (preg_match("/^\d+:\s+([^\s:]+)/", $line, $ar_buf)) {
-
 
1066
                    if ($was) {
-
 
1067
                        if ($macaddr != "") {
-
 
1068
                            $dev->setInfo($macaddr.($dev->getInfo()?';'.$dev->getInfo():''));
-
 
1069
                        }
-
 
1070
                        if ($speedinfo != "") {
-
 
1071
                            $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$speedinfo);
-
 
1072
                        }
-
 
1073
                        $this->sys->setNetDevices($dev);
-
 
1074
                    }
-
 
1075
                    $speedinfo = "";
-
 
1076
                    $macaddr = "";
-
 
1077
                    $dev = new NetDevice();
-
 
1078
                    $dev->setName($ar_buf[1]);
-
 
1079
                    if (CommonFunctions::executeProgram('ip', '-s link show '.$ar_buf[1], $bufr2, PSI_DEBUG) && ($bufr2!="")
-
 
1080
                       && preg_match("/\n\s+RX:\s[^\n]+\n\s+(\d+)\s+\d+\s+(\d+)\s+(\d+)[^\n]+\n\s+TX:\s[^\n]+\n\s+(\d+)\s+\d+\s+(\d+)\s+(\d+)/m", $bufr2, $ar_buf2)) {
-
 
1081
                        $dev->setRxBytes($ar_buf2[1]);
-
 
1082
                        $dev->setTxBytes($ar_buf2[4]);
-
 
1083
                        $dev->setErrors($ar_buf2[2]+$ar_buf2[5]);
-
 
1084
                        $dev->setDrops($ar_buf2[3]+$ar_buf2[6]);
-
 
1085
                    }
-
 
1086
                    $was = true;
-
 
1087
                    if (defined('PSI_SHOW_NETWORK_INFOS') && (PSI_SHOW_NETWORK_INFOS)) {
-
 
1088
                        if (CommonFunctions::rfts('/sys/class/net/'.$ar_buf[1].'/speed', $buf, 1, 4096, false) && (trim($buf)!="")) {
-
 
1089
                            $speed = trim($buf);
-
 
1090
                            if ($speed > 1000) {
-
 
1091
                                $speed = $speed/1000;
-
 
1092
                                $unit = "G";
-
 
1093
                            } else {
-
 
1094
                                $unit = "M";
-
 
1095
                            }
-
 
1096
                            if (CommonFunctions::rfts('/sys/class/net/'.$ar_buf[1].'/duplex', $buf, 1, 4096, false) && (trim($buf)!="")) {
-
 
1097
                                $speedinfo = $speed.$unit.'b/s '.strtolower(trim($buf));
-
 
1098
                            } else {
-
 
1099
                                $speedinfo = $speed.$unit.'b/s';
-
 
1100
                            }
-
 
1101
                        }
-
 
1102
                    }
-
 
1103
                } else {
-
 
1104
                    if ($was) {
-
 
1105
                        if (defined('PSI_SHOW_NETWORK_INFOS') && (PSI_SHOW_NETWORK_INFOS)) {
-
 
1106
                            if (preg_match('/^\s+link\/ether\s+(\S+)\s+brd/i', $line, $ar_buf2)) {
-
 
1107
                                if (!defined('PSI_HIDE_NETWORK_MACADDR') || !PSI_HIDE_NETWORK_MACADDR) $macaddr = preg_replace('/:/', '-', strtoupper($ar_buf2[1]));
-
 
1108
                            } elseif (preg_match('/^\s+inet\s+([^\/\s]+).*peer\s+([^\/\s]+).*\s+scope\s((global)|(host))/i', $line, $ar_buf2)) {
-
 
1109
                                if ($ar_buf2[1] != $ar_buf2[2]) {
-
 
1110
                                     $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$ar_buf2[1].";:".$ar_buf2[2]);
-
 
1111
                                } else {
-
 
1112
                                     $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$ar_buf2[1]);
-
 
1113
                                }
-
 
1114
                            } elseif (preg_match('/^\s+inet6?\s+([^\/\s]+).*\s+scope\s((global)|(host))/i', $line, $ar_buf2)
-
 
1115
                                     && ($ar_buf2[1]!="::") && !preg_match('/^fe80::/i', $ar_buf2[1])) {
-
 
1116
                                $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').strtolower($ar_buf2[1]));
-
 
1117
                            }
-
 
1118
                        }
-
 
1119
                    }
-
 
1120
                }
-
 
1121
            }
-
 
1122
            if ($was) {
-
 
1123
                if ($macaddr != "") {
-
 
1124
                    $dev->setInfo($macaddr.($dev->getInfo()?';'.$dev->getInfo():''));
-
 
1125
                }
-
 
1126
                if ($speedinfo != "") {
-
 
1127
                    $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$speedinfo);
-
 
1128
                }
-
 
1129
                $this->sys->setNetDevices($dev);
-
 
1130
            }
-
 
1131
        } elseif (CommonFunctions::executeProgram('ifconfig', '-a', $bufr, PSI_DEBUG)) {
-
 
1132
            $lines = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
-
 
1133
            $was = false;
-
 
1134
            $errors = 0;
-
 
1135
            $drops = 0;
-
 
1136
            $macaddr = "";
-
 
1137
            $speedinfo = "";
-
 
1138
            $dev = null;
-
 
1139
            foreach ($lines as $line) {
-
 
1140
                if (preg_match("/^([^\s:]+)/", $line, $ar_buf)) {
-
 
1141
                    if ($was) {
-
 
1142
                        $dev->setErrors($errors);
-
 
1143
                        $dev->setDrops($drops);
-
 
1144
                        if ($macaddr != "") {
-
 
1145
                            $dev->setInfo($macaddr.($dev->getInfo()?';'.$dev->getInfo():''));
-
 
1146
                        }
-
 
1147
                        if ($speedinfo != "") {
-
 
1148
                            $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$speedinfo);
-
 
1149
                        }
-
 
1150
                        $this->sys->setNetDevices($dev);
-
 
1151
                    }
-
 
1152
                    $errors = 0;
-
 
1153
                    $drops = 0;
-
 
1154
                    $speedinfo = "";
-
 
1155
                    $macaddr = "";
-
 
1156
                    $dev = new NetDevice();
-
 
1157
                    $dev->setName($ar_buf[1]);
-
 
1158
                    $was = true;
-
 
1159
                    if (defined('PSI_SHOW_NETWORK_INFOS') && (PSI_SHOW_NETWORK_INFOS)) {
-
 
1160
                        if (CommonFunctions::rfts('/sys/class/net/'.$ar_buf[1].'/speed', $buf, 1, 4096, false) && (trim($buf)!="")) {
-
 
1161
                            $speed = trim($buf);
-
 
1162
                            if ($speed > 1000) {
-
 
1163
                                $speed = $speed/1000;
-
 
1164
                                $unit = "G";
-
 
1165
                            } else {
-
 
1166
                                $unit = "M";
-
 
1167
                            }
-
 
1168
                            if (CommonFunctions::rfts('/sys/class/net/'.$ar_buf[1].'/duplex', $buf, 1, 4096, false) && (trim($buf)!="")) {
-
 
1169
                                $speedinfo = $speed.$unit.'b/s '.strtolower(trim($buf));
-
 
1170
                            } else {
-
 
1171
                                $speedinfo = $speed.$unit.'b/s';
-
 
1172
                            }
-
 
1173
                        }
-
 
1174
                        if (preg_match('/^'.$ar_buf[1].'\s+Link\sencap:Ethernet\s+HWaddr\s(\S+)/i', $line, $ar_buf2))
-
 
1175
                            if (!defined('PSI_HIDE_NETWORK_MACADDR') || !PSI_HIDE_NETWORK_MACADDR) $macaddr = preg_replace('/:/', '-', strtoupper($ar_buf2[1]));
-
 
1176
                        elseif (preg_match('/^'.$ar_buf[1].':\s+ip\s+(\S+)\s+mask/i', $line, $ar_buf2))
-
 
1177
                            $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$ar_buf2[1]);
-
 
1178
                    }
-
 
1179
                } else {
-
 
1180
                    if ($was) {
-
 
1181
                        if (preg_match('/\sRX bytes:(\d+)\s/i', $line, $ar_buf2)) {
-
 
1182
                            $dev->setRxBytes($ar_buf2[1]);
-
 
1183
                        }
-
 
1184
                        if (preg_match('/\sTX bytes:(\d+)\s/i', $line, $ar_buf2)) {
-
 
1185
                            $dev->setTxBytes($ar_buf2[1]);
-
 
1186
                        }
-
 
1187
 
-
 
1188
                        if (preg_match('/\sRX packets:\d+\serrors:(\d+)\sdropped:(\d+)/i', $line, $ar_buf2)) {
-
 
1189
                            $errors +=$ar_buf2[1];
-
 
1190
                            $drops +=$ar_buf2[2];
-
 
1191
                        } elseif (preg_match('/\sTX packets:\d+\serrors:(\d+)\sdropped:(\d+)/i', $line, $ar_buf2)) {
-
 
1192
                            $errors +=$ar_buf2[1];
-
 
1193
                            $drops +=$ar_buf2[2];
-
 
1194
                        }
-
 
1195
 
-
 
1196
                        if (defined('PSI_SHOW_NETWORK_INFOS') && (PSI_SHOW_NETWORK_INFOS)) {
-
 
1197
                            if (preg_match('/\s+encap:Ethernet\s+HWaddr\s(\S+)/i', $line, $ar_buf2)
-
 
1198
                             || preg_match('/^\s+ether\s+(\S+)\s+txqueuelen/i', $line, $ar_buf2)) {
-
 
1199
                                if (!defined('PSI_HIDE_NETWORK_MACADDR') || !PSI_HIDE_NETWORK_MACADDR) $macaddr = preg_replace('/:/', '-', strtoupper($ar_buf2[1]));
-
 
1200
                            } elseif (preg_match('/^\s+inet\saddr:(\S+)\s+P-t-P:(\S+)/i', $line, $ar_buf2)
-
 
1201
                                  || preg_match('/^\s+inet\s+(\S+)\s+netmask.+destination\s+(\S+)/i', $line, $ar_buf2)) {
-
 
1202
                                if ($ar_buf2[1] != $ar_buf2[2]) {
-
 
1203
                                     $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$ar_buf2[1].";:".$ar_buf2[2]);
-
 
1204
                                } else {
-
 
1205
                                     $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$ar_buf2[1]);
-
 
1206
                                }
-
 
1207
                            } elseif ((preg_match('/^\s+inet\saddr:(\S+)/i', $line, $ar_buf2)
-
 
1208
                                  || preg_match('/^\s+inet\s+(\S+)\s+netmask/i', $line, $ar_buf2)
-
 
1209
                                  || preg_match('/^\s+inet6\saddr:\s([^\/\s]+)(.+)\s+Scope:[GH]/i', $line, $ar_buf2)
-
 
1210
                                  || preg_match('/^\s+inet6\s+(\S+)\s+prefixlen(.+)((<global>)|(<host>))/i', $line, $ar_buf2))
-
 
1211
                                  && ($ar_buf2[1]!="::") && !preg_match('/^fe80::/i', $ar_buf2[1])) {
-
 
1212
                                $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').strtolower($ar_buf2[1]));
-
 
1213
                            }
-
 
1214
                        }
-
 
1215
                    }
-
 
1216
                }
-
 
1217
            }
-
 
1218
            if ($was) {
-
 
1219
                $dev->setErrors($errors);
-
 
1220
                $dev->setDrops($drops);
-
 
1221
                if ($macaddr != "") {
-
 
1222
                    $dev->setInfo($macaddr.($dev->getInfo()?';'.$dev->getInfo():''));
-
 
1223
                }
-
 
1224
                if ($speedinfo != "") {
-
 
1225
                    $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$speedinfo);
-
 
1226
                }
-
 
1227
                $this->sys->setNetDevices($dev);
-
 
1228
            }
-
 
1229
        }
-
 
1230
    }
507
      
1231
 
-
 
1232
    /**
-
 
1233
     * Physical memory information and Swap Space information
-
 
1234
     *
-
 
1235
     * @return void
-
 
1236
     */
-
 
1237
    protected function _memory()
-
 
1238
    {
-
 
1239
        if (CommonFunctions::rfts('/proc/meminfo', $mbuf)) {
-
 
1240
            $bufe = preg_split("/\n/", $mbuf, -1, PREG_SPLIT_NO_EMPTY);
-
 
1241
            foreach ($bufe as $buf) {
-
 
1242
                if (preg_match('/^MemTotal:\s+(\d+)\s*kB/i', $buf, $ar_buf)) {
-
 
1243
                    $this->sys->setMemTotal($ar_buf[1] * 1024);
-
 
1244
                } elseif (preg_match('/^MemFree:\s+(\d+)\s*kB/i', $buf, $ar_buf)) {
-
 
1245
                    $this->sys->setMemFree($ar_buf[1] * 1024);
-
 
1246
                } elseif (preg_match('/^Cached:\s+(\d+)\s*kB/i', $buf, $ar_buf)) {
-
 
1247
                    $this->sys->setMemCache($ar_buf[1] * 1024);
-
 
1248
                } elseif (preg_match('/^Buffers:\s+(\d+)\s*kB/i', $buf, $ar_buf)) {
-
 
1249
                    $this->sys->setMemBuffer($ar_buf[1] * 1024);
-
 
1250
                }
-
 
1251
            }
-
 
1252
            $this->sys->setMemUsed($this->sys->getMemTotal() - $this->sys->getMemFree());
508
      // values for splitting memory usage
1253
            // values for splitting memory usage
509
      if (isset($results['ram']['cached']) && isset($results['ram']['buffers'])) {
1254
            if ($this->sys->getMemCache() !== null && $this->sys->getMemBuffer() !== null) {
510
        $results['ram']['app'] = $results['ram']['used'] - $results['ram']['cached'] - $results['ram']['buffers'];
1255
                $this->sys->setMemApplication($this->sys->getMemUsed() - $this->sys->getMemCache() - $this->sys->getMemBuffer());
-
 
1256
            }
511
	$results['ram']['app_percent'] = round(($results['ram']['app'] * 100) / $results['ram']['total']);
1257
            if (CommonFunctions::rfts('/proc/swaps', $sbuf, 0, 4096, false)) {
512
	$results['ram']['buffers_percent'] = round(($results['ram']['buffers'] * 100) / $results['ram']['total']);
1258
                $swaps = preg_split("/\n/", $sbuf, -1, PREG_SPLIT_NO_EMPTY);
-
 
1259
                unset($swaps[0]);
-
 
1260
                foreach ($swaps as $swap) {
-
 
1261
                    $ar_buf = preg_split('/\s+/', $swap, 5);
-
 
1262
                    $dev = new DiskDevice();
-
 
1263
                    $dev->setMountPoint($ar_buf[0]);
-
 
1264
                    $dev->setName("SWAP");
-
 
1265
                    $dev->setTotal($ar_buf[2] * 1024);
-
 
1266
                    $dev->setUsed($ar_buf[3] * 1024);
513
	$results['ram']['cached_percent'] = round(($results['ram']['cached'] * 100) / $results['ram']['total']);
1267
                    $dev->setFree($dev->getTotal() - $dev->getUsed());
-
 
1268
                    $this->sys->setSwapDevices($dev);
-
 
1269
                }
-
 
1270
            }
-
 
1271
        }
514
      }
1272
    }
515
 
1273
 
-
 
1274
    /**
516
      $bufr = rfts( '/proc/swaps' );
1275
     * filesystem information
-
 
1276
     *
517
      if ( $bufr != "ERROR" ) {
1277
     * @return void
518
        $swaps = explode("\n", $bufr);
1278
     */
519
        for ($i = 1; $i < (sizeof($swaps)); $i++) {
1279
    private function _filesystems()
520
	  if( trim( $swaps[$i] ) != "" ) {
1280
    {
521
            $ar_buf = preg_split('/\s+/', $swaps[$i], 6);
1281
        $df_args = "";
522
            $results['devswap'][$i - 1] = array();
1282
        $hideFstypes = array();
523
            $results['devswap'][$i - 1]['dev'] = $ar_buf[0];
1283
        if (defined('PSI_HIDE_FS_TYPES') && is_string(PSI_HIDE_FS_TYPES)) {
524
            $results['devswap'][$i - 1]['total'] = $ar_buf[2];
1284
            if (preg_match(ARRAY_EXP, PSI_HIDE_FS_TYPES)) {
525
            $results['devswap'][$i - 1]['used'] = $ar_buf[3];
1285
                $hideFstypes = eval(PSI_HIDE_FS_TYPES);
526
            $results['devswap'][$i - 1]['free'] = ($results['devswap'][$i - 1]['total'] - $results['devswap'][$i - 1]['used']);
-
 
527
            $results['devswap'][$i - 1]['percent'] = round(($ar_buf[3] * 100) / $ar_buf[2]);
-
 
528
	    $results['swap']['total'] += $ar_buf[2];
1286
            } else {
529
	    $results['swap']['used'] += $ar_buf[3];
1287
                $hideFstypes = array(PSI_HIDE_FS_TYPES);
530
	    $results['swap']['free'] = $results['swap']['total'] - $results['swap']['used'];
-
 
531
	    $results['swap']['percent'] = round(($results['swap']['used'] * 100) / $results['swap']['total']);
-
 
532
	  }
1288
            }
533
        } 
1289
        }
-
 
1290
        foreach ($hideFstypes as $Fstype) {
-
 
1291
            $df_args .= "-x $Fstype ";
534
      }
1292
        }
-
 
1293
        if ($df_args !== "") {
-
 
1294
            $df_args = trim($df_args); //trim spaces
-
 
1295
            $arrResult = Parser::df("-P $df_args 2>/dev/null");
-
 
1296
        } else {
-
 
1297
            $arrResult = Parser::df("-P 2>/dev/null");
535
    }
1298
        }
536
    return $results;
1299
        foreach ($arrResult as $dev) {
-
 
1300
            $this->sys->setDiskDevices($dev);
537
  } 
1301
        }
538
  
-
 
539
  function filesystems () {
-
 
540
    return $this->parser->parse_filesystems();
-
 
541
  } 
1302
    }
542
 
1303
 
-
 
1304
    /**
-
 
1305
     * Distribution
-
 
1306
     *
-
 
1307
     * @return void
-
 
1308
     */
543
  function distro () {
1309
    protected function _distro()
-
 
1310
    {
-
 
1311
        $this->sys->setDistribution("Linux");
-
 
1312
        $list = @parse_ini_file(PSI_APP_ROOT."/data/distros.ini", true);
544
   return $this->distro;
1313
        if (!$list) {
-
 
1314
            return;
-
 
1315
        }
-
 
1316
        // We have the '2>/dev/null' because Ubuntu gives an error on this command which causes the distro to be unknown
-
 
1317
        if (CommonFunctions::executeProgram('lsb_release', '-a 2>/dev/null', $distro_info, PSI_DEBUG) && (strlen($distro_info) > 0)) {
-
 
1318
            $distro_tmp = preg_split("/\n/", $distro_info, -1, PREG_SPLIT_NO_EMPTY);
-
 
1319
            foreach ($distro_tmp as $info) {
-
 
1320
                $info_tmp = preg_split('/:/', $info, 2);
-
 
1321
                if (isset($distro_tmp[0]) && !is_null($distro_tmp[0]) && (trim($distro_tmp[0]) != "") &&
-
 
1322
                     isset($distro_tmp[1]) && !is_null($distro_tmp[1]) && (trim($distro_tmp[1]) != "")) {
-
 
1323
                    $distro[trim($info_tmp[0])] = trim($info_tmp[1]);
-
 
1324
                }
-
 
1325
            }
-
 
1326
            if (!isset($distro['Distributor ID']) && !isset($distro['Description'])) { // Systems like StartOS
-
 
1327
                if (isset($distro_tmp[0]) && !is_null($distro_tmp[0]) && (trim($distro_tmp[0]) != "")) {
-
 
1328
                    $this->sys->setDistribution(trim($distro_tmp[0]));
-
 
1329
                    if (preg_match('/^(\S+)\s*/', $distro_tmp[0], $id_buf)
-
 
1330
                        && isset($list[trim($id_buf[1])]['Image'])) {
-
 
1331
                            $this->sys->setDistributionIcon($list[trim($id_buf[1])]['Image']);
-
 
1332
                    }
-
 
1333
                }
-
 
1334
            } else {
-
 
1335
                if (isset($distro['Description'])
-
 
1336
                   && preg_match('/^NAME=\s*"?([^"\n]+)"?\s*$/', $distro['Description'], $name_tmp)) {
-
 
1337
                   $distro['Description'] = $name_tmp[1];
-
 
1338
                }
-
 
1339
                if (isset($distro['Description'])
-
 
1340
                   && ($distro['Description'] != "n/a")
-
 
1341
                   && (!isset($distro['Distributor ID'])
-
 
1342
                   || (($distro['Distributor ID'] != "n/a")
-
 
1343
                   && ($distro['Description'] != $distro['Distributor ID'])))) {
-
 
1344
                    $this->sys->setDistribution($distro['Description']);
-
 
1345
                    if (isset($distro['Release']) && ($distro['Release'] != "n/a")
-
 
1346
                       && ($distro['Release'] != $distro['Description']) && strstr($distro['Release'], ".")){
-
 
1347
                        if (preg_match("/^(\d+)\.[0]+$/", $distro['Release'], $match_buf)) {
-
 
1348
                            $tofind = $match_buf[1];
-
 
1349
                        } else {
-
 
1350
                            $tofind = $distro['Release'];
-
 
1351
                        }
-
 
1352
                        if (!preg_match("/^".$tofind."[\s\.]|[\(\[]".$tofind."[\.\)\]]|\s".$tofind."$|\s".$tofind."[\s\.]/", $distro['Description'])) {
-
 
1353
                            $this->sys->setDistribution($this->sys->getDistribution()." ".$distro['Release']);
-
 
1354
                        }
-
 
1355
                    }
-
 
1356
                } elseif (isset($distro['Distributor ID']) && ($distro['Distributor ID'] != "n/a")) {
-
 
1357
                    $this->sys->setDistribution($distro['Distributor ID']);
-
 
1358
                    if (isset($distro['Release']) && ($distro['Release'] != "n/a")) {
-
 
1359
                        $this->sys->setDistribution($this->sys->getDistribution()." ".$distro['Release']);
-
 
1360
                    }
-
 
1361
                    if (isset($distro['Codename']) && ($distro['Codename'] != "n/a")) {
-
 
1362
                        $this->sys->setDistribution($this->sys->getDistribution()." (".$distro['Codename'].")");
-
 
1363
                    }
-
 
1364
                }
-
 
1365
                if (isset($distro['Distributor ID']) && ($distro['Distributor ID'] != "n/a") && isset($list[$distro['Distributor ID']]['Image'])) {
-
 
1366
                    $this->sys->setDistributionIcon($list[$distro['Distributor ID']]['Image']);
-
 
1367
                } elseif (isset($distro['Description']) && ($distro['Description'] != "n/a")) {
-
 
1368
                    $this->sys->setDistribution($distro['Description']);
-
 
1369
                    if (isset($list[$distro['Description']]['Image'])) {
-
 
1370
                        $this->sys->setDistributionIcon($list[$distro['Description']]['Image']);
-
 
1371
                    }
-
 
1372
                }
-
 
1373
            }
-
 
1374
        } else {
-
 
1375
            /* default error handler */
-
 
1376
            if (function_exists('errorHandlerPsi')) {
-
 
1377
                restore_error_handler();
-
 
1378
            }
-
 
1379
            /* fatal errors only */
-
 
1380
            $old_err_rep = error_reporting();
-
 
1381
            error_reporting(E_ERROR);
-
 
1382
 
-
 
1383
            // Fall back in case 'lsb_release' does not exist but exist /etc/lsb-release
-
 
1384
            if (CommonFunctions::fileexists($filename="/etc/lsb-release")
-
 
1385
               && CommonFunctions::rfts($filename, $buf, 0, 4096, false)
-
 
1386
               && preg_match('/^DISTRIB_ID="?([^"\n]+)"?/m', $buf, $id_buf)) {
-
 
1387
                if (preg_match('/^DISTRIB_DESCRIPTION="?([^"\n]+)"?/m', $buf, $desc_buf)
-
 
1388
                   && (trim($desc_buf[1])!=trim($id_buf[1]))) {
-
 
1389
                    $this->sys->setDistribution(trim($desc_buf[1]));
-
 
1390
                    if (preg_match('/^DISTRIB_RELEASE="?([^"\n]+)"?/m', $buf, $vers_buf)
-
 
1391
                       && (trim($vers_buf[1])!=trim($desc_buf[1])) && strstr($vers_buf[1], ".")){
-
 
1392
                        if (preg_match("/^(\d+)\.[0]+$/", trim($vers_buf[1]), $match_buf)) {
-
 
1393
                            $tofind = $match_buf[1];
-
 
1394
                        } else {
-
 
1395
                            $tofind = trim($vers_buf[1]);
-
 
1396
                        }
-
 
1397
                        if (!preg_match("/^".$tofind."[\s\.]|[\(\[]".$tofind."[\.\)\]]|\s".$tofind."$|\s".$tofind."[\s\.]/", trim($desc_buf[1]))) {
-
 
1398
                            $this->sys->setDistribution($this->sys->getDistribution()." ".trim($vers_buf[1]));
-
 
1399
                        }
-
 
1400
                    }
-
 
1401
                } else {
-
 
1402
                    if (isset($list[trim($id_buf[1])]['Name'])) {
-
 
1403
                        $this->sys->setDistribution(trim($list[trim($id_buf[1])]['Name']));
-
 
1404
                    } else {
-
 
1405
                        $this->sys->setDistribution(trim($id_buf[1]));
-
 
1406
                    }
-
 
1407
                    if (preg_match('/^DISTRIB_RELEASE="?([^"\n]+)"?/m', $buf, $vers_buf)) {
-
 
1408
                        $this->sys->setDistribution($this->sys->getDistribution()." ".trim($vers_buf[1]));
-
 
1409
                    }
-
 
1410
                    if (preg_match('/^DISTRIB_CODENAME="?([^"\n]+)"?/m', $buf, $vers_buf)) {
-
 
1411
                        $this->sys->setDistribution($this->sys->getDistribution()." (".trim($vers_buf[1]).")");
-
 
1412
                    }
-
 
1413
                }
-
 
1414
                if (isset($list[trim($id_buf[1])]['Image'])) {
-
 
1415
                    $this->sys->setDistributionIcon($list[trim($id_buf[1])]['Image']);
-
 
1416
                }
-
 
1417
            } else { // otherwise find files specific for distribution
-
 
1418
                foreach ($list as $section=>$distribution) {
-
 
1419
                    if (!isset($distribution['Files'])) {
-
 
1420
                        continue;
-
 
1421
                    } else {
-
 
1422
                        foreach (preg_split("/;/", $distribution['Files'], -1, PREG_SPLIT_NO_EMPTY) as $filename) {
-
 
1423
                            if (CommonFunctions::fileexists($filename)) {
-
 
1424
                                $distro = $distribution;
-
 
1425
                                if (isset($distribution['Mode'])&&(strtolower($distribution['Mode'])=="detection")) {
-
 
1426
                                    $buf = "";
-
 
1427
                                } elseif (isset($distribution['Mode'])&&(strtolower($distribution['Mode'])=="execute")) {
-
 
1428
                                    if (!CommonFunctions::executeProgram($filename, '2>/dev/null', $buf, PSI_DEBUG)) {
-
 
1429
                                        $buf = "";
-
 
1430
                                    }
-
 
1431
                                } else {
-
 
1432
                                    if (!CommonFunctions::rfts($filename, $buf, 1, 4096, false)) {
-
 
1433
                                        $buf = "";
-
 
1434
                                    } elseif (isset($distribution['Mode'])&&(strtolower($distribution['Mode'])=="analyse")) {
-
 
1435
                                        if (preg_match('/^(\S+)\s*/', preg_replace('/^Red\s+/', 'Red', $buf), $id_buf)
-
 
1436
                                           && isset($list[trim($id_buf[1])]['Image'])) {
-
 
1437
                                            $distro = $list[trim($id_buf[1])];
-
 
1438
                                        }
-
 
1439
                                    }
-
 
1440
                                }
-
 
1441
                                if (isset($distro['Image'])) {
-
 
1442
                                    $this->sys->setDistributionIcon($distro['Image']);
-
 
1443
                                }
-
 
1444
                                if (isset($distribution['Name'])) {
-
 
1445
                                    if (is_null($buf) || (trim($buf) == "")) {
-
 
1446
                                        $this->sys->setDistribution($distribution['Name']);
-
 
1447
                                    } else {
-
 
1448
                                        $this->sys->setDistribution($distribution['Name']." ".trim($buf));
-
 
1449
                                    }
-
 
1450
                                } else {
-
 
1451
                                    if (is_null($buf) || (trim($buf) == "")) {
-
 
1452
                                        $this->sys->setDistribution($section);
-
 
1453
                                    } else {
-
 
1454
                                        $this->sys->setDistribution(trim($buf));
-
 
1455
                                    }
-
 
1456
                                }
-
 
1457
                                if (isset($distribution['Files2'])) {
-
 
1458
                                    foreach (preg_split("/;/", $distribution['Files2'], -1, PREG_SPLIT_NO_EMPTY) as $filename2) {
-
 
1459
                                        if (CommonFunctions::fileexists($filename2) && CommonFunctions::rfts($filename2, $buf, 0, 4096, false)) {
-
 
1460
                                            if (preg_match('/^majorversion="?([^"\n]+)"?/m', $buf, $maj_buf)
-
 
1461
                                               && preg_match('/^minorversion="?([^"\n]+)"?/m', $buf, $min_buf)) {
-
 
1462
                                                $distr2=$maj_buf[1].'.'.$min_buf[1];
-
 
1463
                                                if (preg_match('/^buildphase="?([^"\n]+)"?/m', $buf, $pha_buf) && ($pha_buf[1]!=="0")) {
-
 
1464
                                                    $distr2.='.'.$pha_buf[1];
-
 
1465
                                                }
-
 
1466
                                                if (preg_match('/^buildnumber="?([^"\n]+)"?/m', $buf, $num_buf)) {
-
 
1467
                                                    $distr2.='-'.$num_buf[1];
-
 
1468
                                                }
-
 
1469
                                                if (preg_match('/^builddate="?([^"\n]+)"?/m', $buf, $dat_buf)) {
-
 
1470
                                                    $distr2.=' ('.$dat_buf[1].')';
-
 
1471
                                                }
-
 
1472
                                                $this->sys->setDistribution($this->sys->getDistribution()." ".$distr2);
-
 
1473
                                            } else {
-
 
1474
                                                $distr2=trim(substr($buf, 0, strpos($buf, "\n")));
-
 
1475
                                                if (!is_null($distr2) && ($distr2 != "")) {
-
 
1476
                                                    $this->sys->setDistribution($this->sys->getDistribution()." ".$distr2);
-
 
1477
                                                }
-
 
1478
                                            }
-
 
1479
                                            break;
-
 
1480
                                        }
-
 
1481
                                    }
-
 
1482
                                }
-
 
1483
                                break 2;
-
 
1484
                            }
-
 
1485
                        }
-
 
1486
                    }
-
 
1487
                }
-
 
1488
            }
-
 
1489
            // if the distribution is still unknown
-
 
1490
            if ($this->sys->getDistribution() == "Linux") {
-
 
1491
                if (CommonFunctions::fileexists($filename="/etc/DISTRO_SPECS")
-
 
1492
                   && CommonFunctions::rfts($filename, $buf, 0, 4096, false)
-
 
1493
                   && preg_match('/^DISTRO_NAME=\'(.+)\'/m', $buf, $id_buf)) {
-
 
1494
                    if (isset($list[trim($id_buf[1])]['Name'])) {
-
 
1495
                        $dist = trim($list[trim($id_buf[1])]['Name']);
-
 
1496
                    } else {
-
 
1497
                        $dist = trim($id_buf[1]);
-
 
1498
                    }
-
 
1499
                    if (preg_match('/^DISTRO_VERSION=([^#\n\r]+)/m', $buf, $vers_buf)) {
-
 
1500
                        $this->sys->setDistribution(trim($dist." ".trim($vers_buf[1])));
-
 
1501
                    } else {
-
 
1502
                        $this->sys->setDistribution($dist);
-
 
1503
                    }
-
 
1504
                    if (isset($list[trim($id_buf[1])]['Image'])) {
-
 
1505
                        $this->sys->setDistributionIcon($list[trim($id_buf[1])]['Image']);
-
 
1506
                    } else {
-
 
1507
                        if (isset($list['Puppy']['Image'])) {
-
 
1508
                            $this->sys->setDistributionIcon($list['Puppy']['Image']);
-
 
1509
                        }
-
 
1510
                    }
-
 
1511
                } elseif ((CommonFunctions::fileexists($filename="/etc/distro-release")
-
 
1512
                        && CommonFunctions::rfts($filename, $buf, 1, 4096, false)
-
 
1513
                        && !is_null($buf) && (trim($buf) != ""))
-
 
1514
                    || (CommonFunctions::fileexists($filename="/etc/system-release")
-
 
1515
                        && CommonFunctions::rfts($filename, $buf, 1, 4096, false)
-
 
1516
                        && !is_null($buf) && (trim($buf) != ""))) {
-
 
1517
                    $this->sys->setDistribution(trim($buf));
-
 
1518
                    if (preg_match('/^(\S+)\s*/', preg_replace('/^Red\s+/', 'Red', $buf), $id_buf)
-
 
1519
                        && isset($list[trim($id_buf[1])]['Image'])) {
-
 
1520
                            $this->sys->setDistributionIcon($list[trim($id_buf[1])]['Image']);
-
 
1521
                    }
-
 
1522
                } elseif (CommonFunctions::fileexists($filename="/etc/solydxk/info")
-
 
1523
                   && CommonFunctions::rfts($filename, $buf, 0, 4096, false)
-
 
1524
                   && preg_match('/^DISTRIB_ID="?([^"\n]+)"?/m', $buf, $id_buf)) {
-
 
1525
                    if (preg_match('/^DESCRIPTION="?([^"\n]+)"?/m', $buf, $desc_buf)
-
 
1526
                       && (trim($desc_buf[1])!=trim($id_buf[1]))) {
-
 
1527
                        $this->sys->setDistribution(trim($desc_buf[1]));
-
 
1528
                    } else {
-
 
1529
                        if (isset($list[trim($id_buf[1])]['Name'])) {
-
 
1530
                            $this->sys->setDistribution(trim($list[trim($id_buf[1])]['Name']));
-
 
1531
                        } else {
-
 
1532
                            $this->sys->setDistribution(trim($id_buf[1]));
-
 
1533
                        }
-
 
1534
                        if (preg_match('/^RELEASE="?([^"\n]+)"?/m', $buf, $vers_buf)) {
-
 
1535
                            $this->sys->setDistribution($this->sys->getDistribution()." ".trim($vers_buf[1]));
-
 
1536
                        }
-
 
1537
                        if (preg_match('/^CODENAME="?([^"\n]+)"?/m', $buf, $vers_buf)) {
-
 
1538
                            $this->sys->setDistribution($this->sys->getDistribution()." (".trim($vers_buf[1]).")");
-
 
1539
                        }
-
 
1540
                    }
-
 
1541
                    if (isset($list[trim($id_buf[1])]['Image'])) {
-
 
1542
                        $this->sys->setDistributionIcon($list[trim($id_buf[1])]['Image']);
-
 
1543
                    } else {
-
 
1544
                        $this->sys->setDistributionIcon($list['SolydXK']['Image']);
-
 
1545
                    }
-
 
1546
                } elseif (CommonFunctions::fileexists($filename="/etc/os-release")
-
 
1547
                   && CommonFunctions::rfts($filename, $buf, 0, 4096, false)
-
 
1548
                   && (preg_match('/^TAILS_VERSION_ID="?([^"\n]+)"?/m', $buf, $tid_buf)
-
 
1549
                   || preg_match('/^NAME="?([^"\n]+)"?/m', $buf, $id_buf))) {
-
 
1550
                    if (preg_match('/^TAILS_VERSION_ID="?([^"\n]+)"?/m', $buf, $tid_buf)) {
-
 
1551
                        if (preg_match('/^TAILS_PRODUCT_NAME="?([^"\n]+)"?/m', $buf, $desc_buf)) {
-
 
1552
                            $this->sys->setDistribution(trim($desc_buf[1])." ".trim($tid_buf[1]));
-
 
1553
                        } else {
-
 
1554
                            if (isset($list['Tails']['Name'])) {
-
 
1555
                                $this->sys->setDistribution(trim($list['Tails']['Name'])." ".trim($tid_buf[1]));
-
 
1556
                            } else {
-
 
1557
                                $this->sys->setDistribution('Tails'." ".trim($tid_buf[1]));
-
 
1558
                            }
-
 
1559
                        }
-
 
1560
                        $this->sys->setDistributionIcon($list['Tails']['Image']);
-
 
1561
                    } else {
-
 
1562
                        if (preg_match('/^PRETTY_NAME="?([^"\n]+)"?/m', $buf, $desc_buf)
-
 
1563
                           && !preg_match('/\$/', $desc_buf[1])) { //if is not defined by variable
-
 
1564
                            $this->sys->setDistribution(trim($desc_buf[1]));
-
 
1565
                        } else {
-
 
1566
                            if (isset($list[trim($id_buf[1])]['Name'])) {
-
 
1567
                                $this->sys->setDistribution(trim($list[trim($id_buf[1])]['Name']));
-
 
1568
                            } else {
-
 
1569
                                $this->sys->setDistribution(trim($id_buf[1]));
-
 
1570
                            }
-
 
1571
                            if (preg_match('/^VERSION="?([^"\n]+)"?/m', $buf, $vers_buf)) {
-
 
1572
                                $this->sys->setDistribution($this->sys->getDistribution()." ".trim($vers_buf[1]));
-
 
1573
                            } elseif (preg_match('/^VERSION_ID="?([^"\n]+)"?/m', $buf, $vers_buf)) {
-
 
1574
                                $this->sys->setDistribution($this->sys->getDistribution()." ".trim($vers_buf[1]));
-
 
1575
                            }
-
 
1576
                        }
-
 
1577
                        if (isset($list[trim($id_buf[1])]['Image'])) {
-
 
1578
                            $this->sys->setDistributionIcon($list[trim($id_buf[1])]['Image']);
-
 
1579
                        }
-
 
1580
                    }
-
 
1581
                } elseif (CommonFunctions::fileexists($filename="/etc/debian_version")) {
-
 
1582
                    if (!CommonFunctions::rfts($filename, $buf, 1, 4096, false)) {
-
 
1583
                        $buf = "";
-
 
1584
                    }
-
 
1585
                    if (isset($list['Debian']['Image'])) {
-
 
1586
                        $this->sys->setDistributionIcon($list['Debian']['Image']);
-
 
1587
                    }
-
 
1588
                    if (isset($list['Debian']['Name'])) {
-
 
1589
                        if (is_null($buf) || (trim($buf) == "")) {
-
 
1590
                            $this->sys->setDistribution($list['Debian']['Name']);
-
 
1591
                        } else {
-
 
1592
                            $this->sys->setDistribution($list['Debian']['Name']." ".trim($buf));
-
 
1593
                        }
-
 
1594
                    } else {
-
 
1595
                        if (is_null($buf) || (trim($buf) == "")) {
-
 
1596
                            $this->sys->setDistribution('Debian');
-
 
1597
                        } else {
-
 
1598
                            $this->sys->setDistribution(trim($buf));
-
 
1599
                        }
-
 
1600
                    }
-
 
1601
                } elseif (CommonFunctions::fileexists($filename="/etc/config/uLinux.conf")
-
 
1602
                   && CommonFunctions::rfts($filename, $buf, 0, 4096, false)
-
 
1603
                   && preg_match("/^Rsync\sModel\s*=\s*QNAP/m", $buf)
-
 
1604
                   && preg_match("/^Version\s*=\s*([\d\.]+)\r?\nBuild\sNumber\s*=\s*(\S+)/m", $buf, $ver_buf)) {
-
 
1605
                    $buf = $ver_buf[1]."-".$ver_buf[2];
-
 
1606
                    if (isset($list['QTS']['Image'])) {
-
 
1607
                        $this->sys->setDistributionIcon($list['QTS']['Image']);
-
 
1608
                    }
-
 
1609
                    if (isset($list['QTS']['Name'])) {
-
 
1610
                        $this->sys->setDistribution($list['QTS']['Name']." ".trim($buf));
-
 
1611
                    } else {
-
 
1612
                        $this->sys->setDistribution(trim($buf));
-
 
1613
                    }
-
 
1614
                }
-
 
1615
            }
-
 
1616
            /* restore error level */
-
 
1617
            error_reporting($old_err_rep);
-
 
1618
            /* restore error handler */
-
 
1619
            if (function_exists('errorHandlerPsi')) {
-
 
1620
                set_error_handler('errorHandlerPsi');
-
 
1621
            }
545
  }
1622
        }
546
 
-
 
547
  function distroicon () {   
-
 
548
   return $this->icon;
-
 
549
  }
1623
    }
550
 
1624
 
-
 
1625
    /**
-
 
1626
     * Processes
-
 
1627
     *
-
 
1628
     * @return void
-
 
1629
     */
-
 
1630
    protected function _processes()
-
 
1631
    {
-
 
1632
        $process = glob('/proc/*/status', GLOB_NOSORT);
-
 
1633
        if (is_array($process) && (($total = count($process)) > 0)) {
-
 
1634
            $processes['*'] = 0;
-
 
1635
            $buf = "";
-
 
1636
            for ($i = 0; $i < $total; $i++) {
-
 
1637
                if (CommonFunctions::rfts($process[$i], $buf, 0, 4096, false)) {
-
 
1638
                    $processes['*']++; //current total
-
 
1639
                    if (preg_match('/^State:\s+(\w)/m', $buf, $state)) {
-
 
1640
                        if (isset($processes[$state[1]])) {
-
 
1641
                            $processes[$state[1]]++;
-
 
1642
                        } else {
-
 
1643
                            $processes[$state[1]] = 1;
-
 
1644
                        }
-
 
1645
                    }
-
 
1646
                }
-
 
1647
            }
-
 
1648
            if (!($processes['*'] > 0)) {
-
 
1649
                $processes['*'] = $processes[' '] = $total; //all unknown
-
 
1650
            }
-
 
1651
            $this->sys->setProcesses($processes);
-
 
1652
        }
551
} 
1653
    }
552
 
1654
 
-
 
1655
    /**
-
 
1656
     * get the information
-
 
1657
     *
-
 
1658
     * @see PSI_Interface_OS::build()
-
 
1659
     *
-
 
1660
     * @return Void
-
 
1661
     */
-
 
1662
    public function build()
-
 
1663
    {
-
 
1664
        if (!$this->blockname || $this->blockname==='vitals') {
-
 
1665
            $this->_distro();
-
 
1666
            $this->_hostname();
-
 
1667
            $this->_kernel();
-
 
1668
            $this->_uptime();
-
 
1669
            $this->_users();
-
 
1670
            $this->_loadavg();
-
 
1671
            $this->_processes();
-
 
1672
        }
-
 
1673
        if (!$this->blockname || $this->blockname==='hardware') {
-
 
1674
            $this->_machine();
-
 
1675
            $this->_cpuinfo();
-
 
1676
            $this->_pci();
-
 
1677
            $this->_ide();
-
 
1678
            $this->_scsi();
-
 
1679
            $this->_nvme();
-
 
1680
            $this->_usb();
-
 
1681
            $this->_i2c();
-
 
1682
        }
-
 
1683
        if (!$this->blockname || $this->blockname==='network') {
-
 
1684
            $this->_network();
-
 
1685
        }
-
 
1686
        if (!$this->blockname || $this->blockname==='memory') {
-
 
1687
            $this->_memory();
-
 
1688
        }
-
 
1689
        if (!$this->blockname || $this->blockname==='filesystem') {
-
 
1690
            $this->_filesystems();
-
 
1691
        }
-
 
1692
    }
553
?>
1693
}