|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Linux System Class |
|
4
|
|
|
* |
|
5
|
|
|
* PHP version 5 |
|
6
|
|
|
* |
|
7
|
|
|
* @category PHP |
|
8
|
|
|
* @package PSI Linux OS class |
|
9
|
|
|
* @author Michael Cramer <[email protected]> |
|
10
|
|
|
* @copyright 2009 phpSysInfo |
|
11
|
|
|
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
|
12
|
|
|
* @version SVN: $Id: class.Linux.inc.php 712 2012-12-05 14:09:18Z namiltd $ |
|
13
|
|
|
* @link http://phpsysinfo.sourceforge.net |
|
14
|
|
|
*/ |
|
15
|
|
|
/** |
|
16
|
|
|
* Linux sysinfo class |
|
17
|
|
|
* get all the required information from Linux system |
|
18
|
|
|
* |
|
19
|
|
|
* @category PHP |
|
20
|
|
|
* @package PSI Linux OS class |
|
21
|
|
|
* @author Michael Cramer <[email protected]> |
|
22
|
|
|
* @copyright 2009 phpSysInfo |
|
23
|
|
|
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
|
24
|
|
|
* @version Release: 3.0 |
|
25
|
|
|
* @link http://phpsysinfo.sourceforge.net |
|
26
|
|
|
*/ |
|
27
|
|
|
class Linux extends OS |
|
|
|
|
|
|
28
|
|
|
{ |
|
29
|
|
|
/** |
|
30
|
|
|
* Assoc array of all CPUs loads. |
|
31
|
|
|
*/ |
|
32
|
|
|
protected $_cpu_loads; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* call parent constructor |
|
36
|
|
|
*/ |
|
37
|
|
|
public function __construct() |
|
38
|
|
|
{ |
|
39
|
|
|
parent::__construct(); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Machine |
|
44
|
|
|
* |
|
45
|
|
|
* @return void |
|
46
|
|
|
*/ |
|
47
|
|
|
private function _machine() |
|
48
|
|
|
{ |
|
49
|
|
|
if ((CommonFunctions::rfts('/var/log/dmesg', $result, 0, 4096, false) |
|
50
|
|
|
&& preg_match('/^[\s\[\]\.\d]*DMI:\s*(.*)/m', $result, $ar_buf)) |
|
51
|
|
|
||(CommonFunctions::executeProgram('dmesg', '', $result, false) |
|
52
|
|
|
&& preg_match('/^[\s\[\]\.\d]*DMI:\s*(.*)/m', $result, $ar_buf))) { |
|
53
|
|
|
$this->sys->setMachine(trim($ar_buf[1])); |
|
|
|
|
|
|
54
|
|
|
} else { //data from /sys/devices/virtual/dmi/id/ |
|
55
|
|
|
$machine = ""; |
|
56
|
|
|
$product = ""; |
|
57
|
|
|
$board = ""; |
|
58
|
|
|
$bios = ""; |
|
59
|
|
|
if (CommonFunctions::rfts('/sys/devices/virtual/dmi/id/board_vendor', $buf, 1, 4096, false) && (trim($buf)!="")) { |
|
60
|
|
|
$machine = trim($buf); |
|
61
|
|
|
} |
|
62
|
|
|
if (CommonFunctions::rfts('/sys/devices/virtual/dmi/id/product_name', $buf, 1, 4096, false) && (trim($buf)!="")) { |
|
63
|
|
|
$product = trim($buf); |
|
64
|
|
|
} |
|
65
|
|
|
if (CommonFunctions::rfts('/sys/devices/virtual/dmi/id/board_name', $buf, 1, 4096, false) && (trim($buf)!="")) { |
|
66
|
|
|
$board = trim($buf); |
|
67
|
|
|
} |
|
68
|
|
View Code Duplication |
if (CommonFunctions::rfts('/sys/devices/virtual/dmi/id/bios_version', $buf, 1, 4096, false) && (trim($buf)!="")) { |
|
|
|
|
|
|
69
|
|
|
$bios = trim($buf); |
|
70
|
|
|
} |
|
71
|
|
View Code Duplication |
if (CommonFunctions::rfts('/sys/devices/virtual/dmi/id/bios_date', $buf, 1, 4096, false) && (trim($buf)!="")) { |
|
|
|
|
|
|
72
|
|
|
$bios = trim($bios." ".trim($buf)); |
|
73
|
|
|
} |
|
74
|
|
|
if ($product != "") { |
|
75
|
|
|
$machine .= " ".$product; |
|
76
|
|
|
} |
|
77
|
|
|
if ($board != "") { |
|
78
|
|
|
$machine .= "/".$board; |
|
79
|
|
|
} |
|
80
|
|
|
if ($bios != "") { |
|
81
|
|
|
$machine .= ", BIOS ".$bios; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
if ($machine != "") { |
|
85
|
|
|
$this->sys->setMachine(trim($machine)); |
|
|
|
|
|
|
86
|
|
|
} elseif (CommonFunctions::fileexists($filename="/etc/config/uLinux.conf") // QNAP detection |
|
87
|
|
|
&& CommonFunctions::rfts($filename, $buf, 0, 4096, false) |
|
88
|
|
|
&& preg_match("/^Rsync\sModel\s*=\s*QNAP/m", $buf) |
|
89
|
|
|
&& CommonFunctions::fileexists($filename="/etc/platform.conf") // Platform detection |
|
90
|
|
|
&& CommonFunctions::rfts($filename, $buf, 0, 4096, false) |
|
91
|
|
|
&& preg_match("/^DISPLAY_NAME\s*=\s*(\S+)/m", $buf, $mach_buf) && ($mach_buf[1]!=="")) { |
|
92
|
|
|
$this->sys->setMachine("QNAP ".$mach_buf[1]); |
|
|
|
|
|
|
93
|
|
|
} |
|
94
|
|
|
} |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* Hostname |
|
99
|
|
|
* |
|
100
|
|
|
* @return void |
|
101
|
|
|
*/ |
|
102
|
|
View Code Duplication |
protected function _hostname() |
|
|
|
|
|
|
103
|
|
|
{ |
|
104
|
|
|
if (PSI_USE_VHOST === true) { |
|
105
|
|
|
$this->sys->setHostname(getenv('SERVER_NAME')); |
|
106
|
|
|
} else { |
|
107
|
|
|
if (CommonFunctions::rfts('/proc/sys/kernel/hostname', $result, 1)) { |
|
108
|
|
|
$result = trim($result); |
|
109
|
|
|
$ip = gethostbyname($result); |
|
110
|
|
|
if ($ip != $result) { |
|
111
|
|
|
$this->sys->setHostname(gethostbyaddr($ip)); |
|
112
|
|
|
} |
|
113
|
|
|
} |
|
114
|
|
|
} |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
/** |
|
118
|
|
|
* Kernel Version |
|
119
|
|
|
* |
|
120
|
|
|
* @return void |
|
121
|
|
|
*/ |
|
122
|
|
|
private function _kernel() |
|
123
|
|
|
{ |
|
124
|
|
|
$result = ""; |
|
125
|
|
|
if (CommonFunctions::executeProgram($uname="uptrack-uname", '-r', $strBuf, false) || // show effective kernel if ksplice uptrack is installed |
|
126
|
|
|
CommonFunctions::executeProgram($uname="uname", '-r', $strBuf, PSI_DEBUG)) { |
|
127
|
|
|
$result = $strBuf; |
|
128
|
|
|
if (CommonFunctions::executeProgram($uname, '-v', $strBuf, PSI_DEBUG)) { |
|
129
|
|
|
if (preg_match('/SMP/', $strBuf)) { |
|
130
|
|
|
$result .= ' (SMP)'; |
|
131
|
|
|
} |
|
132
|
|
|
} |
|
133
|
|
|
if (CommonFunctions::executeProgram($uname, '-m', $strBuf, PSI_DEBUG)) { |
|
134
|
|
|
$result .= ' '.$strBuf; |
|
135
|
|
|
} |
|
136
|
|
View Code Duplication |
} elseif (CommonFunctions::rfts('/proc/version', $strBuf, 1) && preg_match('/version (.*?) /', $strBuf, $ar_buf)) { |
|
|
|
|
|
|
137
|
|
|
$result = $ar_buf[1]; |
|
138
|
|
|
if (preg_match('/SMP/', $strBuf)) { |
|
139
|
|
|
$result .= ' (SMP)'; |
|
140
|
|
|
} |
|
141
|
|
|
} |
|
142
|
|
|
if ($result != "") { |
|
143
|
|
|
if (CommonFunctions::rfts('/proc/self/cgroup', $strBuf2, 0, 4096, false)) { |
|
144
|
|
|
if (preg_match('/:\/lxc\//m', $strBuf2)) { |
|
145
|
|
|
$result .= ' [lxc]'; |
|
146
|
|
|
} elseif (preg_match('/:\/docker\//m', $strBuf2)) { |
|
147
|
|
|
$result .= ' [docker]'; |
|
148
|
|
|
} elseif (preg_match('/:\/system\.slice\/docker\-/m', $strBuf2)) { |
|
149
|
|
|
$result .= ' [docker]'; |
|
150
|
|
|
} |
|
151
|
|
|
} |
|
152
|
|
|
$this->sys->setKernel($result); |
|
153
|
|
|
} |
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
|
|
/** |
|
157
|
|
|
* UpTime |
|
158
|
|
|
* time the system is running |
|
159
|
|
|
* |
|
160
|
|
|
* @return void |
|
161
|
|
|
*/ |
|
162
|
|
|
protected function _uptime() |
|
163
|
|
|
{ |
|
164
|
|
|
CommonFunctions::rfts('/proc/uptime', $buf, 1); |
|
165
|
|
|
$ar_buf = preg_split('/ /', $buf); |
|
166
|
|
|
$this->sys->setUptime(trim($ar_buf[0])); |
|
|
|
|
|
|
167
|
|
|
} |
|
168
|
|
|
|
|
169
|
|
|
/** |
|
170
|
|
|
* Processor Load |
|
171
|
|
|
* optionally create a loadbar |
|
172
|
|
|
* |
|
173
|
|
|
* @return void |
|
174
|
|
|
*/ |
|
175
|
|
|
protected function _loadavg() |
|
176
|
|
|
{ |
|
177
|
|
|
if (CommonFunctions::rfts('/proc/loadavg', $buf)) { |
|
178
|
|
|
$result = preg_split("/\s/", $buf, 4); |
|
179
|
|
|
// don't need the extra values, only first three |
|
180
|
|
|
unset($result[3]); |
|
181
|
|
|
$this->sys->setLoad(implode(' ', $result)); |
|
182
|
|
|
} |
|
183
|
|
|
if (PSI_LOAD_BAR) { |
|
184
|
|
|
$this->sys->setLoadPercent($this->_parseProcStat('cpu')); |
|
185
|
|
|
} |
|
186
|
|
|
} |
|
187
|
|
|
|
|
188
|
|
|
/** |
|
189
|
|
|
* fill the load for a individual cpu, through parsing /proc/stat for the specified cpu |
|
190
|
|
|
* |
|
191
|
|
|
* @param String $cpuline cpu for which load should be meassured |
|
192
|
|
|
* |
|
193
|
|
|
* @return Integer |
|
194
|
|
|
*/ |
|
195
|
|
|
protected function _parseProcStat($cpuline) |
|
196
|
|
|
{ |
|
197
|
|
|
if (is_null($this->_cpu_loads)) { |
|
198
|
|
|
$this->_cpu_loads = array(); |
|
199
|
|
|
|
|
200
|
|
|
if (CommonFunctions::rfts('/proc/stat', $buf)) { |
|
201
|
|
|
if (preg_match_all('/^(cpu[0-9]*) (.*)/m', $buf, $matches, PREG_SET_ORDER)) { |
|
202
|
|
|
foreach ($matches as $line) { |
|
203
|
|
|
$cpu = $line[1]; |
|
204
|
|
|
$buf2 = $line[2]; |
|
205
|
|
|
|
|
206
|
|
|
$this->_cpu_loads[$cpu] = array(); |
|
207
|
|
|
|
|
208
|
|
|
$ab = 0; |
|
209
|
|
|
$ac = 0; |
|
210
|
|
|
$ad = 0; |
|
211
|
|
|
$ae = 0; |
|
212
|
|
|
sscanf($buf2, "%Ld %Ld %Ld %Ld", $ab, $ac, $ad, $ae); |
|
213
|
|
|
$this->_cpu_loads[$cpu]['load'] = $ab + $ac + $ad; // cpu.user + cpu.sys |
|
214
|
|
|
$this->_cpu_loads[$cpu]['total'] = $ab + $ac + $ad + $ae; // cpu.total |
|
215
|
|
|
} |
|
216
|
|
|
} |
|
217
|
|
|
} |
|
218
|
|
|
// we need a second value, wait 1 second befor getting (< 1 second no good value will occour) |
|
219
|
|
|
if (PSI_LOAD_BAR) { |
|
220
|
|
|
sleep(1); |
|
221
|
|
|
} |
|
222
|
|
|
if (CommonFunctions::rfts('/proc/stat', $buf)) { |
|
223
|
|
|
if (preg_match_all('/^(cpu[0-9]*) (.*)/m', $buf, $matches, PREG_SET_ORDER)) { |
|
224
|
|
|
foreach ($matches as $line) { |
|
225
|
|
|
$cpu = $line[1]; |
|
226
|
|
|
$buf2 = $line[2]; |
|
227
|
|
|
|
|
228
|
|
|
$ab = 0; |
|
229
|
|
|
$ac = 0; |
|
230
|
|
|
$ad = 0; |
|
231
|
|
|
$ae = 0; |
|
232
|
|
|
sscanf($buf2, "%Ld %Ld %Ld %Ld", $ab, $ac, $ad, $ae); |
|
233
|
|
|
$load2 = $ab + $ac + $ad; // cpu.user + cpu.sys |
|
234
|
|
|
$total2 = $ab + $ac + $ad + $ae; // cpu.total |
|
235
|
|
|
$total = $this->_cpu_loads[$cpu]['total']; |
|
236
|
|
|
$load = $this->_cpu_loads[$cpu]['load']; |
|
237
|
|
|
$this->_cpu_loads[$cpu] = 0; |
|
238
|
|
|
if ($total > 0 && $total2 > 0 && $load > 0 && $load2 > 0 && $total2 != $total && $load2 != $load) { |
|
239
|
|
|
$this->_cpu_loads[$cpu] = (100 * ($load2 - $load)) / ($total2 - $total); |
|
240
|
|
|
} |
|
241
|
|
|
} |
|
242
|
|
|
} |
|
243
|
|
|
} |
|
244
|
|
|
} |
|
245
|
|
|
|
|
246
|
|
|
if (isset($this->_cpu_loads[$cpuline])) { |
|
247
|
|
|
return $this->_cpu_loads[$cpuline]; |
|
248
|
|
|
} |
|
249
|
|
|
|
|
250
|
|
|
return 0; |
|
251
|
|
|
} |
|
252
|
|
|
|
|
253
|
|
|
/** |
|
254
|
|
|
* CPU information |
|
255
|
|
|
* All of the tags here are highly architecture dependant. |
|
256
|
|
|
* |
|
257
|
|
|
* @return void |
|
258
|
|
|
*/ |
|
259
|
|
|
protected function _cpuinfo() |
|
260
|
|
|
{ |
|
261
|
|
|
if (CommonFunctions::rfts('/proc/cpuinfo', $bufr)) { |
|
262
|
|
|
$processors = preg_split('/\s?\n\s?\n/', trim($bufr)); |
|
263
|
|
|
$procname = null; |
|
264
|
|
|
foreach ($processors as $processor) { |
|
265
|
|
|
$proc = null; |
|
266
|
|
|
$arch = null; |
|
267
|
|
|
$dev = new CpuDevice(); |
|
268
|
|
|
$details = preg_split("/\n/", $processor, -1, PREG_SPLIT_NO_EMPTY); |
|
269
|
|
|
foreach ($details as $detail) { |
|
270
|
|
|
$arrBuff = preg_split('/\s*:\s*/', trim($detail)); |
|
271
|
|
|
if (count($arrBuff) == 2) { |
|
272
|
|
|
switch (strtolower($arrBuff[0])) { |
|
273
|
|
|
case 'processor': |
|
274
|
|
|
$proc = trim($arrBuff[1]); |
|
275
|
|
|
if (is_numeric($proc)) { |
|
276
|
|
|
if (strlen($procname)>0) { |
|
277
|
|
|
$dev->setModel($procname); |
|
278
|
|
|
} |
|
279
|
|
|
} else { |
|
280
|
|
|
$procname = $proc; |
|
281
|
|
|
$dev->setModel($procname); |
|
282
|
|
|
} |
|
283
|
|
|
break; |
|
284
|
|
|
case 'model name': |
|
285
|
|
|
case 'cpu model': |
|
286
|
|
|
case 'cpu type': |
|
287
|
|
|
case 'cpu': |
|
288
|
|
|
$dev->setModel($arrBuff[1]); |
|
289
|
|
|
break; |
|
290
|
|
|
case 'cpu mhz': |
|
291
|
|
|
case 'clock': |
|
292
|
|
|
if ($arrBuff[1] > 0) { //openSUSE fix |
|
293
|
|
|
$dev->setCpuSpeed($arrBuff[1]); |
|
294
|
|
|
} |
|
295
|
|
|
break; |
|
296
|
|
|
case 'cycle frequency [hz]': |
|
297
|
|
|
$dev->setCpuSpeed($arrBuff[1] / 1000000); |
|
298
|
|
|
break; |
|
299
|
|
|
case 'cpu0clktck': |
|
300
|
|
|
$dev->setCpuSpeed(hexdec($arrBuff[1]) / 1000000); // Linux sparc64 |
|
301
|
|
|
break; |
|
302
|
|
|
case 'l2 cache': |
|
303
|
|
|
case 'cache size': |
|
304
|
|
|
$dev->setCache(preg_replace("/[a-zA-Z]/", "", $arrBuff[1]) * 1024); |
|
305
|
|
|
break; |
|
306
|
|
|
case 'initial bogomips': |
|
307
|
|
|
case 'bogomips': |
|
308
|
|
|
case 'cpu0bogo': |
|
309
|
|
|
$dev->setBogomips($arrBuff[1]); |
|
310
|
|
|
break; |
|
311
|
|
|
case 'flags': |
|
312
|
|
|
if (preg_match("/ vmx/", $arrBuff[1])) { |
|
313
|
|
|
$dev->setVirt("vmx"); |
|
314
|
|
|
} elseif (preg_match("/ svm/", $arrBuff[1])) { |
|
315
|
|
|
$dev->setVirt("svm"); |
|
316
|
|
|
} elseif (preg_match("/ hypervisor/", $arrBuff[1])) { |
|
317
|
|
|
$dev->setVirt("hypervisor"); |
|
318
|
|
|
} |
|
319
|
|
|
break; |
|
320
|
|
|
case 'i size': |
|
321
|
|
|
case 'd size': |
|
322
|
|
|
if ($dev->getCache() === null) { |
|
323
|
|
|
$dev->setCache($arrBuff[1] * 1024); |
|
324
|
|
|
} else { |
|
325
|
|
|
$dev->setCache($dev->getCache() + ($arrBuff[1] * 1024)); |
|
326
|
|
|
} |
|
327
|
|
|
break; |
|
328
|
|
|
case 'cpu architecture': |
|
329
|
|
|
$arch = trim($arrBuff[1]); |
|
330
|
|
|
break; |
|
331
|
|
|
} |
|
332
|
|
|
} |
|
333
|
|
|
} |
|
334
|
|
|
// sparc64 specific code follows |
|
335
|
|
|
// This adds the ability to display the cache that a CPU has |
|
336
|
|
|
// Originally made by Sven Blumenstein <[email protected]> in 2004 |
|
337
|
|
|
// Modified by Tom Weustink <[email protected]> in 2004 |
|
338
|
|
|
$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'); |
|
339
|
|
|
foreach ($sparclist as $name) { |
|
340
|
|
|
if (CommonFunctions::rfts('/proc/openprom/'.$name.'/ecache-size', $buf, 1, 32, false)) { |
|
341
|
|
|
$dev->setCache(base_convert($buf, 16, 10)); |
|
342
|
|
|
} |
|
343
|
|
|
} |
|
344
|
|
|
// sparc64 specific code ends |
|
345
|
|
|
|
|
346
|
|
|
// XScale detection code |
|
347
|
|
|
if (($arch === "5TE") && ($dev->getBogomips() != null)) { |
|
348
|
|
|
$dev->setCpuSpeed($dev->getBogomips()); //BogoMIPS are not BogoMIPS on this CPU, it's the speed |
|
349
|
|
|
$dev->setBogomips(null); // no BogoMIPS available, unset previously set BogoMIPS |
|
350
|
|
|
} |
|
351
|
|
|
|
|
352
|
|
|
if ($proc != null) { |
|
353
|
|
|
if (!is_numeric($proc)) { |
|
354
|
|
|
$proc = 0; |
|
355
|
|
|
} |
|
356
|
|
|
// variable speed processors specific code follows |
|
357
|
|
|
if (CommonFunctions::rfts('/sys/devices/system/cpu/cpu'.$proc.'/cpufreq/cpuinfo_cur_freq', $buf, 1, 4096, false)) { |
|
358
|
|
|
$dev->setCpuSpeed($buf / 1000); |
|
359
|
|
|
} elseif (CommonFunctions::rfts('/sys/devices/system/cpu/cpu'.$proc.'/cpufreq/scaling_cur_freq', $buf, 1, 4096, false)) { |
|
360
|
|
|
$dev->setCpuSpeed($buf / 1000); |
|
361
|
|
|
} |
|
362
|
|
|
if (CommonFunctions::rfts('/sys/devices/system/cpu/cpu'.$proc.'/cpufreq/cpuinfo_max_freq', $buf, 1, 4096, false)) { |
|
363
|
|
|
$dev->setCpuSpeedMax($buf / 1000); |
|
364
|
|
|
} |
|
365
|
|
|
if (CommonFunctions::rfts('/sys/devices/system/cpu/cpu'.$proc.'/cpufreq/cpuinfo_min_freq', $buf, 1, 4096, false)) { |
|
366
|
|
|
$dev->setCpuSpeedMin($buf / 1000); |
|
367
|
|
|
} |
|
368
|
|
|
// variable speed processors specific code ends |
|
369
|
|
|
if (PSI_LOAD_BAR) { |
|
370
|
|
|
$dev->setLoad($this->_parseProcStat('cpu'.$proc)); |
|
371
|
|
|
} |
|
372
|
|
|
|
|
373
|
|
|
if (CommonFunctions::rfts('/proc/acpi/thermal_zone/THRM/temperature', $buf, 1, 4096, false)) { |
|
374
|
|
|
$dev->setTemp(substr($buf, 25, 2)); |
|
375
|
|
|
} |
|
376
|
|
|
if ($dev->getModel() === "") { |
|
377
|
|
|
$dev->setModel("unknown"); |
|
378
|
|
|
} |
|
379
|
|
|
$this->sys->setCpus($dev); |
|
|
|
|
|
|
380
|
|
|
} |
|
381
|
|
|
} |
|
382
|
|
|
} |
|
383
|
|
|
} |
|
384
|
|
|
|
|
385
|
|
|
/** |
|
386
|
|
|
* PCI devices |
|
387
|
|
|
* |
|
388
|
|
|
* @return void |
|
389
|
|
|
*/ |
|
390
|
|
|
private function _pci() |
|
391
|
|
|
{ |
|
392
|
|
|
if ($arrResults = Parser::lspci()) { |
|
393
|
|
|
foreach ($arrResults as $dev) { |
|
394
|
|
|
$this->sys->setPciDevices($dev); |
|
395
|
|
|
} |
|
396
|
|
|
} elseif (CommonFunctions::rfts('/proc/pci', $strBuf, 0, 4096, false)) { |
|
397
|
|
|
$booDevice = false; |
|
398
|
|
|
$arrBuf = preg_split("/\n/", $strBuf, -1, PREG_SPLIT_NO_EMPTY); |
|
399
|
|
View Code Duplication |
foreach ($arrBuf as $strLine) { |
|
|
|
|
|
|
400
|
|
|
if (preg_match('/^\s*Bus\s/', $strLine)) { |
|
401
|
|
|
$booDevice = true; |
|
402
|
|
|
continue; |
|
403
|
|
|
} |
|
404
|
|
|
if ($booDevice) { |
|
405
|
|
|
$dev = new HWDevice(); |
|
406
|
|
|
$dev->setName(preg_replace('/\([^\)]+\)\.$/', '', trim($strLine))); |
|
407
|
|
|
$this->sys->setPciDevices($dev); |
|
408
|
|
|
/* |
|
|
|
|
|
|
409
|
|
|
list($strKey, $strValue) = preg_split('/: /', $strLine, 2); |
|
410
|
|
|
if (!preg_match('/bridge/i', $strKey) && !preg_match('/USB/i ', $strKey)) { |
|
411
|
|
|
$dev = new HWDevice(); |
|
412
|
|
|
$dev->setName(preg_replace('/\([^\)]+\)\.$/', '', trim($strValue))); |
|
413
|
|
|
$this->sys->setPciDevices($dev); |
|
414
|
|
|
} |
|
415
|
|
|
*/ |
|
416
|
|
|
$booDevice = false; |
|
417
|
|
|
} |
|
418
|
|
|
} |
|
419
|
|
|
} else { |
|
420
|
|
|
$pcidevices = glob('/sys/bus/pci/devices/*/uevent', GLOB_NOSORT); |
|
421
|
|
|
if (($total = count($pcidevices)) > 0) { |
|
422
|
|
|
$buf = ""; |
|
423
|
|
|
for ($i = 0; $i < $total; $i++) { |
|
424
|
|
|
if (CommonFunctions::rfts($pcidevices[$i], $buf, 0, 4096, false) && (trim($buf) != "")) { |
|
425
|
|
|
$pcibuf = ""; |
|
426
|
|
|
if (preg_match("/^PCI_CLASS=(\S+)/m", trim($buf), $subbuf)) { |
|
427
|
|
|
$pcibuf = "Class ".$subbuf[1].":"; |
|
428
|
|
|
} |
|
429
|
|
|
if (preg_match("/^PCI_ID=(\S+)/m", trim($buf), $subbuf)) { |
|
430
|
|
|
$pcibuf .= " Device ".$subbuf[1]; |
|
431
|
|
|
} |
|
432
|
|
|
if (preg_match("/^DRIVER=(\S+)/m", trim($buf), $subbuf)) { |
|
433
|
|
|
$pcibuf .= " Driver ".$subbuf[1]; |
|
434
|
|
|
} |
|
435
|
|
|
$dev = new HWDevice(); |
|
436
|
|
|
if (trim($pcibuf) != "") { |
|
437
|
|
|
$dev->setName(trim($pcibuf)); |
|
438
|
|
|
} else { |
|
439
|
|
|
$dev->setName("unknown"); |
|
440
|
|
|
} |
|
441
|
|
|
$this->sys->setPciDevices($dev); |
|
442
|
|
|
} |
|
443
|
|
|
} |
|
444
|
|
|
} |
|
445
|
|
|
} |
|
446
|
|
|
} |
|
447
|
|
|
|
|
448
|
|
|
/** |
|
449
|
|
|
* IDE devices |
|
450
|
|
|
* |
|
451
|
|
|
* @return void |
|
452
|
|
|
*/ |
|
453
|
|
|
private function _ide() |
|
454
|
|
|
{ |
|
455
|
|
|
$bufd = CommonFunctions::gdc('/proc/ide', false); |
|
456
|
|
|
foreach ($bufd as $file) { |
|
457
|
|
|
if (preg_match('/^hd/', $file)) { |
|
458
|
|
|
$dev = new HWDevice(); |
|
459
|
|
|
$dev->setName(trim($file)); |
|
460
|
|
|
if (CommonFunctions::rfts("/proc/ide/".$file."/media", $buf, 1)) { |
|
461
|
|
View Code Duplication |
if (trim($buf) == 'disk') { |
|
|
|
|
|
|
462
|
|
|
if (CommonFunctions::rfts("/proc/ide/".$file."/capacity", $buf, 1, 4096, false) || CommonFunctions::rfts("/sys/block/".$file."/size", $buf, 1, 4096, false)) { |
|
463
|
|
|
$dev->setCapacity(trim($buf) * 512 / 1024); |
|
464
|
|
|
} |
|
465
|
|
|
} |
|
466
|
|
|
} |
|
467
|
|
|
if (CommonFunctions::rfts("/proc/ide/".$file."/model", $buf, 1)) { |
|
468
|
|
|
$dev->setName($dev->getName().": ".trim($buf)); |
|
469
|
|
|
} |
|
470
|
|
|
$this->sys->setIdeDevices($dev); |
|
471
|
|
|
} |
|
472
|
|
|
} |
|
473
|
|
|
} |
|
474
|
|
|
|
|
475
|
|
|
/** |
|
476
|
|
|
* SCSI devices |
|
477
|
|
|
* |
|
478
|
|
|
* @return void |
|
479
|
|
|
*/ |
|
480
|
|
|
private function _scsi() |
|
481
|
|
|
{ |
|
482
|
|
|
$get_type = false; |
|
483
|
|
|
$device = null; |
|
484
|
|
|
if (CommonFunctions::executeProgram('lsscsi', '-c', $bufr, PSI_DEBUG) || CommonFunctions::rfts('/proc/scsi/scsi', $bufr, 0, 4096, PSI_DEBUG)) { |
|
485
|
|
|
$bufe = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY); |
|
486
|
|
View Code Duplication |
foreach ($bufe as $buf) { |
|
|
|
|
|
|
487
|
|
|
if (preg_match('/Vendor: (.*) Model: (.*) Rev: (.*)/i', $buf, $devices)) { |
|
488
|
|
|
$get_type = true; |
|
489
|
|
|
$device = $devices; |
|
490
|
|
|
continue; |
|
491
|
|
|
} |
|
492
|
|
|
if ($get_type) { |
|
493
|
|
|
preg_match('/Type:\s+(\S+)/i', $buf, $dev_type); |
|
494
|
|
|
$dev = new HWDevice(); |
|
495
|
|
|
$dev->setName($device[1].' '.$device[2].' ('.$dev_type[1].')'); |
|
496
|
|
|
$this->sys->setScsiDevices($dev); |
|
497
|
|
|
$get_type = false; |
|
498
|
|
|
} |
|
499
|
|
|
} |
|
500
|
|
|
} |
|
501
|
|
|
} |
|
502
|
|
|
|
|
503
|
|
|
/** |
|
504
|
|
|
* USB devices |
|
505
|
|
|
* |
|
506
|
|
|
* @return array |
|
|
|
|
|
|
507
|
|
|
*/ |
|
508
|
|
|
private function _usb() |
|
509
|
|
|
{ |
|
510
|
|
|
$devnum = -1; |
|
511
|
|
|
if (CommonFunctions::executeProgram('lsusb', '', $bufr, PSI_DEBUG) && (trim($bufr) !== "")) { |
|
512
|
|
|
$bufe = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY); |
|
513
|
|
|
foreach ($bufe as $buf) { |
|
514
|
|
|
$device = preg_split("/ /", $buf, 7); |
|
515
|
|
|
if (isset($device[6]) && trim($device[6]) != "") { |
|
516
|
|
|
$dev = new HWDevice(); |
|
517
|
|
|
$dev->setName(trim($device[6])); |
|
518
|
|
|
$this->sys->setUsbDevices($dev); |
|
519
|
|
|
} elseif (isset($device[5]) && trim($device[5]) != "") { |
|
520
|
|
|
$dev = new HWDevice(); |
|
521
|
|
|
$dev->setName("unknown"); |
|
522
|
|
|
$this->sys->setUsbDevices($dev); |
|
523
|
|
|
} |
|
524
|
|
|
} |
|
525
|
|
|
} elseif (CommonFunctions::rfts('/proc/bus/usb/devices', $bufr, 0, 4096, false)) { |
|
526
|
|
|
$bufe = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY); |
|
527
|
|
|
foreach ($bufe as $buf) { |
|
528
|
|
|
if (preg_match('/^T/', $buf)) { |
|
529
|
|
|
$devnum += 1; |
|
530
|
|
|
$results[$devnum] = ""; |
|
|
|
|
|
|
531
|
|
|
} elseif (preg_match('/^S:/', $buf)) { |
|
532
|
|
|
list($key, $value) = preg_split('/: /', $buf, 2); |
|
533
|
|
|
list($key, $value2) = preg_split('/=/', $value, 2); |
|
534
|
|
|
if ((trim($key) == "Manufacturer") && (preg_match("/^linux\s/i", trim($value2)))) { |
|
535
|
|
|
$value2 = "Linux"; |
|
536
|
|
|
} |
|
537
|
|
|
if (trim($key) != "SerialNumber") { |
|
538
|
|
|
$results[$devnum] .= " ".trim($value2); |
|
|
|
|
|
|
539
|
|
|
} |
|
540
|
|
|
} |
|
541
|
|
|
} |
|
542
|
|
|
foreach ($results as $var) { |
|
543
|
|
|
$dev = new HWDevice(); |
|
544
|
|
|
$var = trim($var); |
|
545
|
|
|
if ($var != "") { |
|
546
|
|
|
$dev->setName($var); |
|
547
|
|
|
} else { |
|
548
|
|
|
$dev->setName("unknown"); |
|
549
|
|
|
} |
|
550
|
|
|
$this->sys->setUsbDevices($dev); |
|
551
|
|
|
} |
|
552
|
|
|
} else { |
|
553
|
|
|
$usbdevices = glob('/sys/bus/usb/devices/*/idProduct', GLOB_NOSORT); |
|
554
|
|
|
if (($total = count($usbdevices)) > 0) { |
|
555
|
|
|
$buf = ""; |
|
556
|
|
|
for ($i = 0; $i < $total; $i++) { |
|
557
|
|
|
if (CommonFunctions::rfts($usbdevices[$i], $buf, 1, 4096, false) && (trim($buf) != "")) { //is readable |
|
558
|
|
|
$product = preg_replace("/\/idProduct$/", "/product", $usbdevices[$i]); |
|
559
|
|
|
$manufacturer = preg_replace("/\/idProduct$/", "/manufacturer", $usbdevices[$i]); |
|
560
|
|
|
$usbbuf = ""; |
|
561
|
|
|
if (CommonFunctions::fileexists($manufacturer) && CommonFunctions::rfts($manufacturer, $buf, 1, 4096, false) && (trim($buf) != "")) { |
|
562
|
|
|
if (preg_match("/^linux\s/i", trim($buf))) { |
|
563
|
|
|
$usbbuf = "Linux"; |
|
564
|
|
|
} else { |
|
565
|
|
|
$usbbuf = trim($buf); |
|
566
|
|
|
} |
|
567
|
|
|
} |
|
568
|
|
|
if (CommonFunctions::fileexists($product) && CommonFunctions::rfts($product, $buf, 1, 4096, false) && (trim($buf) != "")) { |
|
569
|
|
|
$usbbuf .= " ".trim($buf); |
|
570
|
|
|
} |
|
571
|
|
|
$dev = new HWDevice(); |
|
572
|
|
|
if (trim($usbbuf) != "") { |
|
573
|
|
|
$dev->setName(trim($usbbuf)); |
|
574
|
|
|
} else { |
|
575
|
|
|
$dev->setName("unknown"); |
|
576
|
|
|
} |
|
577
|
|
|
$this->sys->setUsbDevices($dev); |
|
578
|
|
|
} |
|
579
|
|
|
} |
|
580
|
|
|
} |
|
581
|
|
|
} |
|
582
|
|
|
} |
|
583
|
|
|
|
|
584
|
|
|
/** |
|
585
|
|
|
* I2C devices |
|
586
|
|
|
* |
|
587
|
|
|
* @return void |
|
588
|
|
|
*/ |
|
589
|
|
|
protected function _i2c() |
|
590
|
|
|
{ |
|
591
|
|
|
$i2cdevices = glob('/sys/bus/i2c/devices/*/name', GLOB_NOSORT); |
|
592
|
|
|
if (($total = count($i2cdevices)) > 0) { |
|
593
|
|
|
$buf = ""; |
|
594
|
|
|
for ($i = 0; $i < $total; $i++) { |
|
595
|
|
|
if (CommonFunctions::rfts($i2cdevices[$i], $buf, 1, 4096, false) && (trim($buf) != "")) { |
|
596
|
|
|
$dev = new HWDevice(); |
|
597
|
|
|
$dev->setName(trim($buf)); |
|
598
|
|
|
$this->sys->setI2cDevices($dev); |
|
599
|
|
|
} |
|
600
|
|
|
} |
|
601
|
|
|
} |
|
602
|
|
|
} |
|
603
|
|
|
|
|
604
|
|
|
/** |
|
605
|
|
|
* Network devices |
|
606
|
|
|
* includes also rx/tx bytes |
|
607
|
|
|
* |
|
608
|
|
|
* @return void |
|
609
|
|
|
*/ |
|
610
|
|
|
protected function _network() |
|
611
|
|
|
{ |
|
612
|
|
|
if (CommonFunctions::rfts('/proc/net/dev', $bufr, 0, 4096, PSI_DEBUG)) { |
|
613
|
|
|
$bufe = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY); |
|
614
|
|
|
foreach ($bufe as $buf) { |
|
615
|
|
|
if (preg_match('/:/', $buf)) { |
|
616
|
|
|
list($dev_name, $stats_list) = preg_split('/:/', $buf, 2); |
|
617
|
|
|
$stats = preg_split('/\s+/', trim($stats_list)); |
|
618
|
|
|
$dev = new NetDevice(); |
|
619
|
|
|
$dev->setName(trim($dev_name)); |
|
620
|
|
|
$dev->setRxBytes($stats[0]); |
|
621
|
|
|
$dev->setTxBytes($stats[8]); |
|
622
|
|
|
$dev->setErrors($stats[2] + $stats[10]); |
|
623
|
|
|
$dev->setDrops($stats[3] + $stats[11]); |
|
624
|
|
|
if (defined('PSI_SHOW_NETWORK_INFOS') && (PSI_SHOW_NETWORK_INFOS)) { |
|
625
|
|
|
if ((CommonFunctions::executeProgram('ip', 'addr show '.trim($dev_name), $bufr2, PSI_DEBUG) && (trim($bufr2)!="")) |
|
626
|
|
|
|| CommonFunctions::executeProgram('ifconfig', trim($dev_name).' 2>/dev/null', $bufr2, PSI_DEBUG)) { |
|
627
|
|
|
$bufe2 = preg_split("/\n/", $bufr2, -1, PREG_SPLIT_NO_EMPTY); |
|
628
|
|
|
$macaddr = ""; |
|
629
|
|
|
foreach ($bufe2 as $buf2) { |
|
630
|
|
|
// if (preg_match('/^'.trim($dev_name).'\s+Link\sencap:Ethernet\s+HWaddr\s(\S+)/i', $buf2, $ar_buf2) |
|
|
|
|
|
|
631
|
|
|
if (preg_match('/\s+encap:Ethernet\s+HWaddr\s(\S+)/i', $buf2, $ar_buf2) |
|
632
|
|
|
|| preg_match('/^\s+ether\s+(\S+)\s+txqueuelen/i', $buf2, $ar_buf2) |
|
633
|
|
|
|| preg_match('/^\s+link\/ether\s+(\S+)\s+brd/i', $buf2, $ar_buf2)) //ip |
|
634
|
|
|
$macaddr = preg_replace('/:/', '-', strtoupper($ar_buf2[1])); |
|
635
|
|
View Code Duplication |
elseif (preg_match('/^\s+inet\saddr:(\S+)\s+P-t-P:(\S+)/i', $buf2, $ar_buf2) |
|
|
|
|
|
|
636
|
|
|
|| preg_match('/^\s+inet\s+(\S+)\s+netmask.+destination\s+(\S+)/i', $buf2, $ar_buf2) |
|
637
|
|
|
|| preg_match('/^\s+inet\s+([^\/\s]+).*peer\s+([^\/\s]+).*\s+scope\s((global)|(host))/i', $buf2, $ar_buf2)) { //ip |
|
638
|
|
|
if ($ar_buf2[1] != $ar_buf2[2]) { |
|
639
|
|
|
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$ar_buf2[1].";:".$ar_buf2[2]); |
|
640
|
|
|
} else { |
|
641
|
|
|
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$ar_buf2[1]); |
|
642
|
|
|
} |
|
643
|
|
|
} elseif (preg_match('/^\s+inet\saddr:(\S+)/i', $buf2, $ar_buf2) |
|
644
|
|
|
|| preg_match('/^\s+inet\s+(\S+)\s+netmask/i', $buf2, $ar_buf2) |
|
645
|
|
|
|| preg_match('/^'.trim($dev_name).':\s+ip\s+(\S+)\s+mask/i', $buf2, $ar_buf2) |
|
646
|
|
|
|| preg_match('/^\s+inet6\saddr:\s([^\/\s]+)(.+)\s+Scope:[GH]/i', $buf2, $ar_buf2) |
|
647
|
|
|
|| preg_match('/^\s+inet6\s+(\S+)\s+prefixlen(.+)((<global>)|(<host>))/i', $buf2, $ar_buf2) |
|
648
|
|
|
|| preg_match('/^\s+inet6?\s+([^\/\s]+).*\s+scope\s((global)|(host))/i', $buf2, $ar_buf2)) //ip |
|
649
|
|
|
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').strtolower($ar_buf2[1])); |
|
650
|
|
|
} |
|
651
|
|
|
} |
|
652
|
|
|
if ($macaddr != "") { |
|
653
|
|
|
$dev->setInfo($macaddr.($dev->getInfo()?';'.$dev->getInfo():'')); |
|
|
|
|
|
|
654
|
|
|
} |
|
655
|
|
|
if (CommonFunctions::rfts('/sys/class/net/'.trim($dev_name).'/speed', $buf, 1, 4096, false) && (trim($buf)!="") && ($buf > 0) && ($buf < 65535)) { |
|
656
|
|
|
$speed = trim($buf); |
|
657
|
|
|
if ($speed > 1000) { |
|
658
|
|
|
$speed = $speed/1000; |
|
659
|
|
|
$unit = "G"; |
|
660
|
|
|
} else { |
|
661
|
|
|
$unit = "M"; |
|
662
|
|
|
} |
|
663
|
|
|
if (CommonFunctions::rfts('/sys/class/net/'.trim($dev_name).'/duplex', $buf, 1, 4096, false) && (trim($buf)!="")) { |
|
664
|
|
|
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$speed.$unit.'b/s '.strtolower(trim($buf))); |
|
665
|
|
|
} else { |
|
666
|
|
|
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$speed.$unit.'b/s'); |
|
667
|
|
|
} |
|
668
|
|
|
} |
|
669
|
|
|
} |
|
670
|
|
|
$this->sys->setNetDevices($dev); |
|
671
|
|
|
} |
|
672
|
|
|
} |
|
673
|
|
|
} elseif (CommonFunctions::executeProgram('ip', 'addr show', $bufr, PSI_DEBUG) && (trim($bufr)!="")) { |
|
674
|
|
|
$lines = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY); |
|
675
|
|
|
$was = false; |
|
676
|
|
|
foreach ($lines as $line) { |
|
677
|
|
|
if (preg_match("/^\d+:\s+([^\s:]+)/", $line, $ar_buf)) { |
|
678
|
|
View Code Duplication |
if ($was) { |
|
|
|
|
|
|
679
|
|
|
if ($macaddr != "") { |
|
680
|
|
|
$dev->setInfo($macaddr.($dev->getInfo()?';'.$dev->getInfo():'')); |
|
|
|
|
|
|
681
|
|
|
} |
|
682
|
|
|
if ($speedinfo != "") { |
|
683
|
|
|
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$speedinfo); |
|
|
|
|
|
|
684
|
|
|
} |
|
685
|
|
|
$this->sys->setNetDevices($dev); |
|
686
|
|
|
} |
|
687
|
|
|
$speedinfo = ""; |
|
688
|
|
|
$macaddr = ""; |
|
689
|
|
|
$dev = new NetDevice(); |
|
690
|
|
|
$dev->setName($ar_buf[1]); |
|
691
|
|
|
if (CommonFunctions::executeProgram('ip', '-s link show '.$ar_buf[1], $bufr2, PSI_DEBUG) && (trim($bufr2)!="") |
|
692
|
|
|
&& 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)) { |
|
693
|
|
|
$dev->setRxBytes($ar_buf2[1]); |
|
694
|
|
|
$dev->setTxBytes($ar_buf2[4]); |
|
695
|
|
|
$dev->setErrors($ar_buf2[2]+$ar_buf2[5]); |
|
696
|
|
|
$dev->setDrops($ar_buf2[3]+$ar_buf2[6]); |
|
697
|
|
|
} |
|
698
|
|
|
$was = true; |
|
699
|
|
View Code Duplication |
if (defined('PSI_SHOW_NETWORK_INFOS') && (PSI_SHOW_NETWORK_INFOS)) { |
|
|
|
|
|
|
700
|
|
|
if (CommonFunctions::rfts('/sys/class/net/'.$ar_buf[1].'/speed', $buf, 1, 4096, false) && (trim($buf)!="")) { |
|
701
|
|
|
$speed = trim($buf); |
|
702
|
|
|
if ($speed > 1000) { |
|
703
|
|
|
$speed = $speed/1000; |
|
704
|
|
|
$unit = "G"; |
|
705
|
|
|
} else { |
|
706
|
|
|
$unit = "M"; |
|
707
|
|
|
} |
|
708
|
|
|
if (CommonFunctions::rfts('/sys/class/net/'.$ar_buf[1].'/duplex', $buf, 1, 4096, false) && (trim($buf)!="")) { |
|
709
|
|
|
$speedinfo = $speed.$unit.'b/s '.strtolower(trim($buf)); |
|
710
|
|
|
} else { |
|
711
|
|
|
$speedinfo = $speed.$unit.'b/s'; |
|
712
|
|
|
} |
|
713
|
|
|
} |
|
714
|
|
|
} |
|
715
|
|
|
} else { |
|
716
|
|
|
if ($was) { |
|
717
|
|
|
if (defined('PSI_SHOW_NETWORK_INFOS') && (PSI_SHOW_NETWORK_INFOS)) { |
|
718
|
|
|
if (preg_match('/^\s+link\/ether\s+(\S+)\s+brd/i', $line, $ar_buf2)) |
|
719
|
|
|
$macaddr = preg_replace('/:/', '-', strtoupper($ar_buf2[1])); |
|
720
|
|
|
elseif (preg_match('/^\s+inet\s+([^\/\s]+).*peer\s+([^\/\s]+).*\s+scope\s((global)|(host))/i', $line, $ar_buf2)) { |
|
721
|
|
|
if ($ar_buf2[1] != $ar_buf2[2]) { |
|
722
|
|
|
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$ar_buf2[1].";:".$ar_buf2[2]); |
|
723
|
|
|
} else { |
|
724
|
|
|
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$ar_buf2[1]); |
|
725
|
|
|
} |
|
726
|
|
|
} elseif (preg_match('/^\s+inet6?\s+([^\/\s]+).*\s+scope\s((global)|(host))/i', $line, $ar_buf2)) |
|
727
|
|
|
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').strtolower($ar_buf2[1])); |
|
728
|
|
|
} |
|
729
|
|
|
} |
|
730
|
|
|
} |
|
731
|
|
|
} |
|
732
|
|
View Code Duplication |
if ($was) { |
|
|
|
|
|
|
733
|
|
|
if ($macaddr != "") { |
|
734
|
|
|
$dev->setInfo($macaddr.($dev->getInfo()?';'.$dev->getInfo():'')); |
|
735
|
|
|
} |
|
736
|
|
|
if ($speedinfo != "") { |
|
737
|
|
|
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$speedinfo); |
|
738
|
|
|
} |
|
739
|
|
|
$this->sys->setNetDevices($dev); |
|
740
|
|
|
} |
|
741
|
|
|
} elseif (CommonFunctions::executeProgram('ifconfig', '-a', $bufr, PSI_DEBUG)) { |
|
742
|
|
|
$lines = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY); |
|
743
|
|
|
$was = false; |
|
744
|
|
|
foreach ($lines as $line) { |
|
745
|
|
|
if (preg_match("/^([^\s:]+)/", $line, $ar_buf)) { |
|
746
|
|
View Code Duplication |
if ($was) { |
|
|
|
|
|
|
747
|
|
|
$dev->setErrors($errors); |
|
|
|
|
|
|
748
|
|
|
$dev->setDrops($drops); |
|
|
|
|
|
|
749
|
|
|
if ($macaddr != "") { |
|
750
|
|
|
$dev->setInfo($macaddr.($dev->getInfo()?';'.$dev->getInfo():'')); |
|
751
|
|
|
} |
|
752
|
|
|
if ($speedinfo != "") { |
|
753
|
|
|
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$speedinfo); |
|
754
|
|
|
} |
|
755
|
|
|
$this->sys->setNetDevices($dev); |
|
756
|
|
|
} |
|
757
|
|
|
$errors = 0; |
|
758
|
|
|
$drops = 0; |
|
759
|
|
|
$speedinfo = ""; |
|
760
|
|
|
$macaddr = ""; |
|
761
|
|
|
$dev = new NetDevice(); |
|
762
|
|
|
$dev->setName($ar_buf[1]); |
|
763
|
|
|
$was = true; |
|
764
|
|
|
if (defined('PSI_SHOW_NETWORK_INFOS') && (PSI_SHOW_NETWORK_INFOS)) { |
|
765
|
|
View Code Duplication |
if (CommonFunctions::rfts('/sys/class/net/'.$ar_buf[1].'/speed', $buf, 1, 4096, false) && (trim($buf)!="")) { |
|
|
|
|
|
|
766
|
|
|
$speed = trim($buf); |
|
767
|
|
|
if ($speed > 1000) { |
|
768
|
|
|
$speed = $speed/1000; |
|
769
|
|
|
$unit = "G"; |
|
770
|
|
|
} else { |
|
771
|
|
|
$unit = "M"; |
|
772
|
|
|
} |
|
773
|
|
|
if (CommonFunctions::rfts('/sys/class/net/'.$ar_buf[1].'/duplex', $buf, 1, 4096, false) && (trim($buf)!="")) { |
|
774
|
|
|
$speedinfo = $speed.$unit.'b/s '.strtolower(trim($buf)); |
|
775
|
|
|
} else { |
|
776
|
|
|
$speedinfo = $speed.$unit.'b/s'; |
|
777
|
|
|
} |
|
778
|
|
|
} |
|
779
|
|
|
if (preg_match('/^'.$ar_buf[1].'\s+Link\sencap:Ethernet\s+HWaddr\s(\S+)/i', $line, $ar_buf2)) |
|
780
|
|
|
$macaddr = preg_replace('/:/', '-', strtoupper($ar_buf2[1])); |
|
781
|
|
|
elseif (preg_match('/^'.$ar_buf[1].':\s+ip\s+(\S+)\s+mask/i', $line, $ar_buf2)) |
|
782
|
|
|
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$ar_buf2[1]); |
|
783
|
|
|
} |
|
784
|
|
|
} else { |
|
785
|
|
|
if ($was) { |
|
786
|
|
|
if (preg_match('/\sRX bytes:(\d+)\s/i', $line, $ar_buf2)) { |
|
787
|
|
|
$dev->setRxBytes($ar_buf2[1]); |
|
788
|
|
|
} |
|
789
|
|
|
if (preg_match('/\sTX bytes:(\d+)\s/i', $line, $ar_buf2)) { |
|
790
|
|
|
$dev->setTxBytes($ar_buf2[1]); |
|
791
|
|
|
} |
|
792
|
|
|
|
|
793
|
|
|
if (preg_match('/\sRX packets:\d+\serrors:(\d+)\sdropped:(\d+)/i', $line, $ar_buf2)) { |
|
794
|
|
|
$errors +=$ar_buf2[1]; |
|
795
|
|
|
$drops +=$ar_buf2[2]; |
|
796
|
|
View Code Duplication |
} elseif (preg_match('/\sTX packets:\d+\serrors:(\d+)\sdropped:(\d+)/i', $line, $ar_buf2)) { |
|
|
|
|
|
|
797
|
|
|
$errors +=$ar_buf2[1]; |
|
798
|
|
|
$drops +=$ar_buf2[2]; |
|
799
|
|
|
} |
|
800
|
|
|
|
|
801
|
|
|
if (defined('PSI_SHOW_NETWORK_INFOS') && (PSI_SHOW_NETWORK_INFOS)) { |
|
802
|
|
|
if (preg_match('/\s+encap:Ethernet\s+HWaddr\s(\S+)/i', $line, $ar_buf2) |
|
803
|
|
|
|| preg_match('/^\s+ether\s+(\S+)\s+txqueuelen/i', $line, $ar_buf2)) |
|
804
|
|
|
$macaddr = preg_replace('/:/', '-', strtoupper($ar_buf2[1])); |
|
805
|
|
View Code Duplication |
elseif (preg_match('/^\s+inet\saddr:(\S+)\s+P-t-P:(\S+)/i', $line, $ar_buf2) |
|
|
|
|
|
|
806
|
|
|
|| preg_match('/^\s+inet\s+(\S+)\s+netmask.+destination\s+(\S+)/i', $line, $ar_buf2)) { |
|
807
|
|
|
if ($ar_buf2[1] != $ar_buf2[2]) { |
|
808
|
|
|
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$ar_buf2[1].";:".$ar_buf2[2]); |
|
809
|
|
|
} else { |
|
810
|
|
|
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$ar_buf2[1]); |
|
811
|
|
|
} |
|
812
|
|
|
} elseif (preg_match('/^\s+inet\saddr:(\S+)/i', $line, $ar_buf2) |
|
813
|
|
|
|| preg_match('/^\s+inet\s+(\S+)\s+netmask/i', $line, $ar_buf2) |
|
814
|
|
|
|| preg_match('/^\s+inet6\saddr:\s([^\/\s]+)(.+)\s+Scope:[GH]/i', $line, $ar_buf2) |
|
815
|
|
|
|| preg_match('/^\s+inet6\s+(\S+)\s+prefixlen(.+)((<global>)|(<host>))/i', $line, $ar_buf2)) |
|
816
|
|
|
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').strtolower($ar_buf2[1])); |
|
817
|
|
|
} |
|
818
|
|
|
} |
|
819
|
|
|
} |
|
820
|
|
|
} |
|
821
|
|
View Code Duplication |
if ($was) { |
|
|
|
|
|
|
822
|
|
|
$dev->setErrors($errors); |
|
823
|
|
|
$dev->setDrops($drops); |
|
824
|
|
|
if ($macaddr != "") { |
|
825
|
|
|
$dev->setInfo($macaddr.($dev->getInfo()?';'.$dev->getInfo():'')); |
|
826
|
|
|
} |
|
827
|
|
|
if ($speedinfo != "") { |
|
828
|
|
|
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$speedinfo); |
|
829
|
|
|
} |
|
830
|
|
|
$this->sys->setNetDevices($dev); |
|
831
|
|
|
} |
|
832
|
|
|
} |
|
833
|
|
|
} |
|
834
|
|
|
|
|
835
|
|
|
/** |
|
836
|
|
|
* Physical memory information and Swap Space information |
|
837
|
|
|
* |
|
838
|
|
|
* @return void |
|
839
|
|
|
*/ |
|
840
|
|
|
protected function _memory() |
|
841
|
|
|
{ |
|
842
|
|
|
if (CommonFunctions::rfts('/proc/meminfo', $mbuf)) { |
|
843
|
|
|
$bufe = preg_split("/\n/", $mbuf, -1, PREG_SPLIT_NO_EMPTY); |
|
844
|
|
|
foreach ($bufe as $buf) { |
|
845
|
|
|
if (preg_match('/^MemTotal:\s+(.*)\s*kB/i', $buf, $ar_buf)) { |
|
846
|
|
|
$this->sys->setMemTotal($ar_buf[1] * 1024); |
|
847
|
|
|
} elseif (preg_match('/^MemFree:\s+(.*)\s*kB/i', $buf, $ar_buf)) { |
|
848
|
|
|
$this->sys->setMemFree($ar_buf[1] * 1024); |
|
849
|
|
|
} elseif (preg_match('/^Cached:\s+(.*)\s*kB/i', $buf, $ar_buf)) { |
|
850
|
|
|
$this->sys->setMemCache($ar_buf[1] * 1024); |
|
851
|
|
|
} elseif (preg_match('/^Buffers:\s+(.*)\s*kB/i', $buf, $ar_buf)) { |
|
852
|
|
|
$this->sys->setMemBuffer($ar_buf[1] * 1024); |
|
853
|
|
|
} |
|
854
|
|
|
} |
|
855
|
|
|
$this->sys->setMemUsed($this->sys->getMemTotal() - $this->sys->getMemFree()); |
|
856
|
|
|
// values for splitting memory usage |
|
857
|
|
|
if ($this->sys->getMemCache() !== null && $this->sys->getMemBuffer() !== null) { |
|
858
|
|
|
$this->sys->setMemApplication($this->sys->getMemUsed() - $this->sys->getMemCache() - $this->sys->getMemBuffer()); |
|
859
|
|
|
} |
|
860
|
|
|
if (CommonFunctions::rfts('/proc/swaps', $sbuf, 0, 4096, false)) { |
|
861
|
|
|
$swaps = preg_split("/\n/", $sbuf, -1, PREG_SPLIT_NO_EMPTY); |
|
862
|
|
|
unset($swaps[0]); |
|
863
|
|
|
foreach ($swaps as $swap) { |
|
864
|
|
|
$ar_buf = preg_split('/\s+/', $swap, 5); |
|
865
|
|
|
$dev = new DiskDevice(); |
|
866
|
|
|
$dev->setMountPoint($ar_buf[0]); |
|
867
|
|
|
$dev->setName("SWAP"); |
|
868
|
|
|
$dev->setTotal($ar_buf[2] * 1024); |
|
869
|
|
|
$dev->setUsed($ar_buf[3] * 1024); |
|
870
|
|
|
$dev->setFree($dev->getTotal() - $dev->getUsed()); |
|
871
|
|
|
$this->sys->setSwapDevices($dev); |
|
872
|
|
|
} |
|
873
|
|
|
} |
|
874
|
|
|
} |
|
875
|
|
|
} |
|
876
|
|
|
|
|
877
|
|
|
/** |
|
878
|
|
|
* filesystem information |
|
879
|
|
|
* |
|
880
|
|
|
* @return void |
|
881
|
|
|
*/ |
|
882
|
|
|
private function _filesystems() |
|
883
|
|
|
{ |
|
884
|
|
|
$df_args = ""; |
|
885
|
|
|
$hideFstypes = array(); |
|
886
|
|
View Code Duplication |
if (defined('PSI_HIDE_FS_TYPES') && is_string(PSI_HIDE_FS_TYPES)) { |
|
|
|
|
|
|
887
|
|
|
if (preg_match(ARRAY_EXP, PSI_HIDE_FS_TYPES)) { |
|
888
|
|
|
$hideFstypes = eval(PSI_HIDE_FS_TYPES); |
|
|
|
|
|
|
889
|
|
|
} else { |
|
890
|
|
|
$hideFstypes = array(PSI_HIDE_FS_TYPES); |
|
891
|
|
|
} |
|
892
|
|
|
} |
|
893
|
|
|
foreach ($hideFstypes as $Fstype) { |
|
894
|
|
|
$df_args .= "-x $Fstype "; |
|
895
|
|
|
} |
|
896
|
|
|
if ($df_args !== "") { |
|
897
|
|
|
$df_args = trim($df_args); //trim spaces |
|
898
|
|
|
$arrResult = Parser::df("-P $df_args 2>/dev/null"); |
|
899
|
|
|
} else { |
|
900
|
|
|
$arrResult = Parser::df("-P 2>/dev/null"); |
|
901
|
|
|
} |
|
902
|
|
|
foreach ($arrResult as $dev) { |
|
903
|
|
|
$this->sys->setDiskDevices($dev); |
|
904
|
|
|
} |
|
905
|
|
|
} |
|
906
|
|
|
|
|
907
|
|
|
/** |
|
908
|
|
|
* Distribution |
|
909
|
|
|
* |
|
910
|
|
|
* @return void |
|
911
|
|
|
*/ |
|
912
|
|
|
protected function _distro() |
|
913
|
|
|
{ |
|
914
|
|
|
$this->sys->setDistribution("Linux"); |
|
915
|
|
|
$list = @parse_ini_file(APP_ROOT."/data/distros.ini", true); |
|
916
|
|
|
if (!$list) { |
|
917
|
|
|
return; |
|
918
|
|
|
} |
|
919
|
|
|
// We have the '2>/dev/null' because Ubuntu gives an error on this command which causes the distro to be unknown |
|
920
|
|
|
if (CommonFunctions::executeProgram('lsb_release', '-a 2>/dev/null', $distro_info, PSI_DEBUG) && (strlen($distro_info) > 0)) { |
|
921
|
|
|
$distro_tmp = preg_split("/\n/", $distro_info, -1, PREG_SPLIT_NO_EMPTY); |
|
922
|
|
|
foreach ($distro_tmp as $info) { |
|
923
|
|
|
$info_tmp = preg_split('/:/', $info, 2); |
|
924
|
|
|
if (isset($distro_tmp[0]) && !is_null($distro_tmp[0]) && (trim($distro_tmp[0]) != "") && |
|
925
|
|
|
isset($distro_tmp[1]) && !is_null($distro_tmp[1]) && (trim($distro_tmp[1]) != "")) { |
|
926
|
|
|
$distro[trim($info_tmp[0])] = trim($info_tmp[1]); |
|
|
|
|
|
|
927
|
|
|
} |
|
928
|
|
|
} |
|
929
|
|
|
if (!isset($distro['Distributor ID']) && !isset($distro['Description'])) { // Systems like StartOS |
|
930
|
|
|
if (isset($distro_tmp[0]) && !is_null($distro_tmp[0]) && (trim($distro_tmp[0]) != "")) { |
|
931
|
|
|
$this->sys->setDistribution(trim($distro_tmp[0])); |
|
932
|
|
|
if (preg_match('/^(\S+)\s*/', $distro_tmp[0], $id_buf) |
|
933
|
|
|
&& isset($list[trim($id_buf[1])]['Image'])) { |
|
934
|
|
|
$this->sys->setDistributionIcon($list[trim($id_buf[1])]['Image']); |
|
935
|
|
|
} |
|
936
|
|
|
} |
|
937
|
|
|
} else { |
|
938
|
|
|
if (isset($distro['Description']) |
|
939
|
|
|
&& preg_match('/^NAME=\s*(.+)\s*$/', $distro['Description'], $name_tmp)) { |
|
940
|
|
|
$distro['Description'] = $name_tmp[1]; |
|
941
|
|
|
} |
|
942
|
|
|
if (isset($distro['Description']) |
|
943
|
|
|
&& ($distro['Description'] != "n/a") |
|
944
|
|
|
&& (!isset($distro['Distributor ID']) |
|
945
|
|
|
|| (($distro['Distributor ID'] != "n/a") |
|
946
|
|
|
&& ($distro['Description'] != $distro['Distributor ID'])))) { |
|
947
|
|
|
$this->sys->setDistribution($distro['Description']); |
|
948
|
|
|
if (isset($distro['Release']) && ($distro['Release'] != "n/a") |
|
949
|
|
|
&& ($distro['Release'] != $distro['Description']) && strstr($distro['Release'], ".")){ |
|
950
|
|
|
if (preg_match("/^(\d+)\.[0]+$/", $distro['Release'], $match_buf)) { |
|
951
|
|
|
$tofind = $match_buf[1]; |
|
952
|
|
|
} else { |
|
953
|
|
|
$tofind = $distro['Release']; |
|
954
|
|
|
} |
|
955
|
|
View Code Duplication |
if (!preg_match("/^".$tofind."[\s\.]|[\(\[]".$tofind."[\.\)\]]|\s".$tofind."$|\s".$tofind."[\s\.]/", $distro['Description'])) { |
|
|
|
|
|
|
956
|
|
|
$this->sys->setDistribution($this->sys->getDistribution()." ".$distro['Release']); |
|
957
|
|
|
} |
|
958
|
|
|
} |
|
959
|
|
|
} elseif (isset($distro['Distributor ID']) && ($distro['Distributor ID'] != "n/a")) { |
|
960
|
|
|
$this->sys->setDistribution($distro['Distributor ID']); |
|
961
|
|
View Code Duplication |
if (isset($distro['Release']) && ($distro['Release'] != "n/a")) { |
|
|
|
|
|
|
962
|
|
|
$this->sys->setDistribution($this->sys->getDistribution()." ".$distro['Release']); |
|
963
|
|
|
} |
|
964
|
|
View Code Duplication |
if (isset($distro['Codename']) && ($distro['Codename'] != "n/a")) { |
|
|
|
|
|
|
965
|
|
|
$this->sys->setDistribution($this->sys->getDistribution()." (".$distro['Codename'].")"); |
|
966
|
|
|
} |
|
967
|
|
|
} |
|
968
|
|
|
if (isset($distro['Distributor ID']) && ($distro['Distributor ID'] != "n/a") && isset($list[$distro['Distributor ID']]['Image'])) { |
|
969
|
|
|
$this->sys->setDistributionIcon($list[$distro['Distributor ID']]['Image']); |
|
970
|
|
|
} |
|
971
|
|
|
} |
|
972
|
|
|
} else { |
|
973
|
|
|
/* default error handler */ |
|
974
|
|
|
if (function_exists('errorHandlerPsi')) { |
|
975
|
|
|
restore_error_handler(); |
|
976
|
|
|
} |
|
977
|
|
|
/* fatal errors only */ |
|
978
|
|
|
$old_err_rep = error_reporting(); |
|
979
|
|
|
error_reporting(E_ERROR); |
|
980
|
|
|
|
|
981
|
|
|
// Fall back in case 'lsb_release' does not exist but exist /etc/lsb-release |
|
982
|
|
|
if (CommonFunctions::fileexists($filename="/etc/lsb-release") |
|
983
|
|
|
&& CommonFunctions::rfts($filename, $buf, 0, 4096, false) |
|
984
|
|
|
&& preg_match('/^DISTRIB_ID="?([^"\n]+)"?/m', $buf, $id_buf)) { |
|
985
|
|
|
if (preg_match('/^DISTRIB_DESCRIPTION="?([^"\n]+)"?/m', $buf, $desc_buf) |
|
986
|
|
|
&& (trim($desc_buf[1])!=trim($id_buf[1]))) { |
|
987
|
|
|
$this->sys->setDistribution(trim($desc_buf[1])); |
|
988
|
|
|
if (preg_match('/^DISTRIB_RELEASE="?([^"\n]+)"?/m', $buf, $vers_buf) |
|
989
|
|
|
&& (trim($vers_buf[1])!=trim($desc_buf[1])) && strstr($vers_buf[1], ".")){ |
|
990
|
|
|
if (preg_match("/^(\d+)\.[0]+$/", trim($vers_buf[1]), $match_buf)) { |
|
991
|
|
|
$tofind = $match_buf[1]; |
|
992
|
|
|
} else { |
|
993
|
|
|
$tofind = trim($vers_buf[1]); |
|
994
|
|
|
} |
|
995
|
|
View Code Duplication |
if (!preg_match("/^".$tofind."[\s\.]|[\(\[]".$tofind."[\.\)\]]|\s".$tofind."$|\s".$tofind."[\s\.]/", trim($desc_buf[1]))) { |
|
|
|
|
|
|
996
|
|
|
$this->sys->setDistribution($this->sys->getDistribution()." ".trim($vers_buf[1])); |
|
997
|
|
|
} |
|
998
|
|
|
} |
|
999
|
|
View Code Duplication |
} else { |
|
|
|
|
|
|
1000
|
|
|
if (isset($list[trim($id_buf[1])]['Name'])) { |
|
1001
|
|
|
$this->sys->setDistribution(trim($list[trim($id_buf[1])]['Name'])); |
|
1002
|
|
|
} else { |
|
1003
|
|
|
$this->sys->setDistribution(trim($id_buf[1])); |
|
1004
|
|
|
} |
|
1005
|
|
|
if (preg_match('/^DISTRIB_RELEASE="?([^"\n]+)"?/m', $buf, $vers_buf)) { |
|
1006
|
|
|
$this->sys->setDistribution($this->sys->getDistribution()." ".trim($vers_buf[1])); |
|
1007
|
|
|
} |
|
1008
|
|
|
if (preg_match('/^DISTRIB_CODENAME="?([^"\n]+)"?/m', $buf, $vers_buf)) { |
|
1009
|
|
|
$this->sys->setDistribution($this->sys->getDistribution()." (".trim($vers_buf[1]).")"); |
|
1010
|
|
|
} |
|
1011
|
|
|
} |
|
1012
|
|
View Code Duplication |
if (isset($list[trim($id_buf[1])]['Image'])) { |
|
|
|
|
|
|
1013
|
|
|
$this->sys->setDistributionIcon($list[trim($id_buf[1])]['Image']); |
|
1014
|
|
|
} |
|
1015
|
|
|
} else { // otherwise find files specific for distribution |
|
1016
|
|
|
foreach ($list as $section=>$distribution) { |
|
1017
|
|
|
if (!isset($distribution['Files'])) { |
|
1018
|
|
|
continue; |
|
1019
|
|
|
} else { |
|
1020
|
|
|
foreach (preg_split("/;/", $distribution['Files'], -1, PREG_SPLIT_NO_EMPTY) as $filename) { |
|
1021
|
|
|
if (CommonFunctions::fileexists($filename)) { |
|
1022
|
|
|
$distro = $distribution; |
|
1023
|
|
|
if (isset($distribution['Mode'])&&(strtolower($distribution['Mode'])=="detection")) { |
|
1024
|
|
|
$buf = ""; |
|
1025
|
|
|
} elseif (isset($distribution['Mode'])&&(strtolower($distribution['Mode'])=="execute")) { |
|
1026
|
|
|
if (!CommonFunctions::executeProgram($filename, '2>/dev/null', $buf, PSI_DEBUG)) { |
|
1027
|
|
|
$buf = ""; |
|
1028
|
|
|
} |
|
1029
|
|
|
} else { |
|
1030
|
|
|
if (!CommonFunctions::rfts($filename, $buf, 1, 4096, false)) { |
|
1031
|
|
|
$buf = ""; |
|
1032
|
|
|
} elseif (isset($distribution['Mode'])&&(strtolower($distribution['Mode'])=="analyse")) { |
|
1033
|
|
|
if (preg_match('/^(\S+)\s*/', preg_replace('/^Red\s+/', 'Red', $buf), $id_buf) |
|
1034
|
|
|
&& isset($list[trim($id_buf[1])]['Image'])) { |
|
1035
|
|
|
$distro = $list[trim($id_buf[1])]; |
|
1036
|
|
|
} |
|
1037
|
|
|
} |
|
1038
|
|
|
} |
|
1039
|
|
|
if (isset($distro['Image'])) { |
|
1040
|
|
|
$this->sys->setDistributionIcon($distro['Image']); |
|
1041
|
|
|
} |
|
1042
|
|
|
if (isset($distribution['Name'])) { |
|
1043
|
|
View Code Duplication |
if (is_null($buf) || (trim($buf) == "")) { |
|
|
|
|
|
|
1044
|
|
|
$this->sys->setDistribution($distribution['Name']); |
|
1045
|
|
|
} else { |
|
1046
|
|
|
$this->sys->setDistribution($distribution['Name']." ".trim($buf)); |
|
1047
|
|
|
} |
|
1048
|
|
View Code Duplication |
} else { |
|
|
|
|
|
|
1049
|
|
|
if (is_null($buf) || (trim($buf) == "")) { |
|
1050
|
|
|
$this->sys->setDistribution($section); |
|
1051
|
|
|
} else { |
|
1052
|
|
|
$this->sys->setDistribution(trim($buf)); |
|
1053
|
|
|
} |
|
1054
|
|
|
} |
|
1055
|
|
|
if (isset($distribution['Files2'])) { |
|
1056
|
|
|
foreach (preg_split("/;/", $distribution['Files2'], -1, PREG_SPLIT_NO_EMPTY) as $filename2) { |
|
1057
|
|
|
if (CommonFunctions::fileexists($filename2) && CommonFunctions::rfts($filename2, $buf, 0, 4096, false)) { |
|
1058
|
|
|
if (preg_match('/^majorversion="?([^"\n]+)"?/m', $buf, $maj_buf) |
|
1059
|
|
|
&& preg_match('/^minorversion="?([^"\n]+)"?/m', $buf, $min_buf)) { |
|
1060
|
|
|
$distr2=$maj_buf[1].'.'.$min_buf[1]; |
|
1061
|
|
|
if (preg_match('/^buildphase="?([^"\n]+)"?/m', $buf, $pha_buf) && ($pha_buf[1]!=="0")) { |
|
1062
|
|
|
$distr2.='.'.$pha_buf[1]; |
|
1063
|
|
|
} |
|
1064
|
|
|
if (preg_match('/^buildnumber="?([^"\n]+)"?/m', $buf, $num_buf)) { |
|
1065
|
|
|
$distr2.='-'.$num_buf[1]; |
|
1066
|
|
|
} |
|
1067
|
|
|
if (preg_match('/^builddate="?([^"\n]+)"?/m', $buf, $dat_buf)) { |
|
1068
|
|
|
$distr2.=' ('.$dat_buf[1].')'; |
|
1069
|
|
|
} |
|
1070
|
|
|
$this->sys->setDistribution($this->sys->getDistribution()." ".$distr2); |
|
1071
|
|
|
} else { |
|
1072
|
|
|
$distr2=trim(substr($buf, 0, strpos($buf, "\n"))); |
|
1073
|
|
|
if (!is_null($distr2) && ($distr2 != "")) { |
|
1074
|
|
|
$this->sys->setDistribution($this->sys->getDistribution()." ".$distr2); |
|
1075
|
|
|
} |
|
1076
|
|
|
} |
|
1077
|
|
|
break; |
|
1078
|
|
|
} |
|
1079
|
|
|
} |
|
1080
|
|
|
} |
|
1081
|
|
|
break 2; |
|
1082
|
|
|
} |
|
1083
|
|
|
} |
|
1084
|
|
|
} |
|
1085
|
|
|
} |
|
1086
|
|
|
} |
|
1087
|
|
|
// if the distribution is still unknown |
|
1088
|
|
|
if ($this->sys->getDistribution() == "Linux") { |
|
1089
|
|
|
if (CommonFunctions::fileexists($filename="/etc/DISTRO_SPECS") |
|
1090
|
|
|
&& CommonFunctions::rfts($filename, $buf, 0, 4096, false) |
|
1091
|
|
|
&& preg_match('/^DISTRO_NAME=\'(.+)\'/m', $buf, $id_buf)) { |
|
1092
|
|
|
if (isset($list[trim($id_buf[1])]['Name'])) { |
|
1093
|
|
|
$dist = trim($list[trim($id_buf[1])]['Name']); |
|
1094
|
|
|
} else { |
|
1095
|
|
|
$dist = trim($id_buf[1]); |
|
1096
|
|
|
} |
|
1097
|
|
|
if (preg_match('/^DISTRO_VERSION=(.+)/m', $buf, $vers_buf)) { |
|
1098
|
|
|
$this->sys->setDistribution(trim($dist." ".trim($vers_buf[1]))); |
|
1099
|
|
|
} else { |
|
1100
|
|
|
$this->sys->setDistribution($dist); |
|
1101
|
|
|
} |
|
1102
|
|
|
if (isset($list[trim($id_buf[1])]['Image'])) { |
|
1103
|
|
|
$this->sys->setDistributionIcon($list[trim($id_buf[1])]['Image']); |
|
1104
|
|
|
} else { |
|
1105
|
|
|
if (isset($list['Puppy']['Image'])) { |
|
1106
|
|
|
$this->sys->setDistributionIcon($list['Puppy']['Image']); |
|
1107
|
|
|
} |
|
1108
|
|
|
} |
|
1109
|
|
|
} elseif ((CommonFunctions::fileexists($filename="/etc/distro-release") |
|
1110
|
|
|
&& CommonFunctions::rfts($filename, $buf, 1, 4096, false) |
|
1111
|
|
|
&& !is_null($buf) && (trim($buf) != "")) |
|
|
|
|
|
|
1112
|
|
|
|| (CommonFunctions::fileexists($filename="/etc/system-release") |
|
1113
|
|
|
&& CommonFunctions::rfts($filename, $buf, 1, 4096, false) |
|
1114
|
|
|
&& !is_null($buf) && (trim($buf) != ""))) { |
|
1115
|
|
|
$this->sys->setDistribution(trim($buf)); |
|
1116
|
|
|
if (preg_match('/^(\S+)\s*/', preg_replace('/^Red\s+/', 'Red', $buf), $id_buf) |
|
1117
|
|
|
&& isset($list[trim($id_buf[1])]['Image'])) { |
|
1118
|
|
|
$this->sys->setDistributionIcon($list[trim($id_buf[1])]['Image']); |
|
1119
|
|
|
} |
|
1120
|
|
|
} elseif (CommonFunctions::fileexists($filename="/etc/solydxk/info") |
|
1121
|
|
|
&& CommonFunctions::rfts($filename, $buf, 0, 4096, false) |
|
1122
|
|
|
&& preg_match('/^DISTRIB_ID="?([^"\n]+)"?/m', $buf, $id_buf)) { |
|
1123
|
|
|
if (preg_match('/^DESCRIPTION="?([^"\n]+)"?/m', $buf, $desc_buf) |
|
1124
|
|
|
&& (trim($desc_buf[1])!=trim($id_buf[1]))) { |
|
1125
|
|
|
$this->sys->setDistribution(trim($desc_buf[1])); |
|
1126
|
|
View Code Duplication |
} else { |
|
|
|
|
|
|
1127
|
|
|
if (isset($list[trim($id_buf[1])]['Name'])) { |
|
1128
|
|
|
$this->sys->setDistribution(trim($list[trim($id_buf[1])]['Name'])); |
|
1129
|
|
|
} else { |
|
1130
|
|
|
$this->sys->setDistribution(trim($id_buf[1])); |
|
1131
|
|
|
} |
|
1132
|
|
|
if (preg_match('/^RELEASE="?([^"\n]+)"?/m', $buf, $vers_buf)) { |
|
1133
|
|
|
$this->sys->setDistribution($this->sys->getDistribution()." ".trim($vers_buf[1])); |
|
1134
|
|
|
} |
|
1135
|
|
|
if (preg_match('/^CODENAME="?([^"\n]+)"?/m', $buf, $vers_buf)) { |
|
1136
|
|
|
$this->sys->setDistribution($this->sys->getDistribution()." (".trim($vers_buf[1]).")"); |
|
1137
|
|
|
} |
|
1138
|
|
|
} |
|
1139
|
|
|
if (isset($list[trim($id_buf[1])]['Image'])) { |
|
1140
|
|
|
$this->sys->setDistributionIcon($list[trim($id_buf[1])]['Image']); |
|
1141
|
|
|
} else { |
|
1142
|
|
|
$this->sys->setDistributionIcon($list['SolydXK']['Image']); |
|
1143
|
|
|
} |
|
1144
|
|
|
} elseif (CommonFunctions::fileexists($filename="/etc/os-release") |
|
1145
|
|
|
&& CommonFunctions::rfts($filename, $buf, 0, 4096, false) |
|
1146
|
|
|
&& (preg_match('/^TAILS_VERSION_ID="?([^"\n]+)"?/m', $buf, $tid_buf) |
|
1147
|
|
|
|| preg_match('/^NAME="?([^"\n]+)"?/m', $buf, $id_buf))) { |
|
1148
|
|
|
if (preg_match('/^TAILS_VERSION_ID="?([^"\n]+)"?/m', $buf, $tid_buf)) { |
|
1149
|
|
|
if (preg_match('/^TAILS_PRODUCT_NAME="?([^"\n]+)"?/m', $buf, $desc_buf)) { |
|
1150
|
|
|
$this->sys->setDistribution(trim($desc_buf[1])." ".trim($tid_buf[1])); |
|
1151
|
|
|
} else { |
|
1152
|
|
|
if (isset($list['Tails']['Name'])) { |
|
1153
|
|
|
$this->sys->setDistribution(trim($list['Tails']['Name'])." ".trim($tid_buf[1])); |
|
1154
|
|
|
} else { |
|
1155
|
|
|
$this->sys->setDistribution('Tails'." ".trim($tid_buf[1])); |
|
1156
|
|
|
} |
|
1157
|
|
|
} |
|
1158
|
|
|
$this->sys->setDistributionIcon($list['Tails']['Image']); |
|
1159
|
|
|
} else { |
|
1160
|
|
|
if (preg_match('/^PRETTY_NAME="?([^"\n]+)"?/m', $buf, $desc_buf) |
|
1161
|
|
|
&& !preg_match('/\$/', $desc_buf[1])) { //if is not defined by variable |
|
1162
|
|
|
$this->sys->setDistribution(trim($desc_buf[1])); |
|
1163
|
|
View Code Duplication |
} else { |
|
|
|
|
|
|
1164
|
|
|
if (isset($list[trim($id_buf[1])]['Name'])) { |
|
1165
|
|
|
$this->sys->setDistribution(trim($list[trim($id_buf[1])]['Name'])); |
|
|
|
|
|
|
1166
|
|
|
} else { |
|
1167
|
|
|
$this->sys->setDistribution(trim($id_buf[1])); |
|
1168
|
|
|
} |
|
1169
|
|
|
if (preg_match('/^VERSION="?([^"\n]+)"?/m', $buf, $vers_buf)) { |
|
1170
|
|
|
$this->sys->setDistribution($this->sys->getDistribution()." ".trim($vers_buf[1])); |
|
1171
|
|
|
} elseif (preg_match('/^VERSION_ID="?([^"\n]+)"?/m', $buf, $vers_buf)) { |
|
1172
|
|
|
$this->sys->setDistribution($this->sys->getDistribution()." ".trim($vers_buf[1])); |
|
1173
|
|
|
} |
|
1174
|
|
|
} |
|
1175
|
|
View Code Duplication |
if (isset($list[trim($id_buf[1])]['Image'])) { |
|
|
|
|
|
|
1176
|
|
|
$this->sys->setDistributionIcon($list[trim($id_buf[1])]['Image']); |
|
1177
|
|
|
} |
|
1178
|
|
|
} |
|
1179
|
|
|
} elseif (CommonFunctions::fileexists($filename="/etc/debian_version")) { |
|
1180
|
|
|
if (!CommonFunctions::rfts($filename, $buf, 1, 4096, false)) { |
|
1181
|
|
|
$buf = ""; |
|
1182
|
|
|
} |
|
1183
|
|
|
if (isset($list['Debian']['Image'])) { |
|
1184
|
|
|
$this->sys->setDistributionIcon($list['Debian']['Image']); |
|
1185
|
|
|
} |
|
1186
|
|
|
if (isset($list['Debian']['Name'])) { |
|
1187
|
|
View Code Duplication |
if (is_null($buf) || (trim($buf) == "")) { |
|
|
|
|
|
|
1188
|
|
|
$this->sys->setDistribution($list['Debian']['Name']); |
|
1189
|
|
|
} else { |
|
1190
|
|
|
$this->sys->setDistribution($list['Debian']['Name']." ".trim($buf)); |
|
1191
|
|
|
} |
|
1192
|
|
View Code Duplication |
} else { |
|
|
|
|
|
|
1193
|
|
|
if (is_null($buf) || (trim($buf) == "")) { |
|
1194
|
|
|
$this->sys->setDistribution('Debian'); |
|
1195
|
|
|
} else { |
|
1196
|
|
|
$this->sys->setDistribution(trim($buf)); |
|
1197
|
|
|
} |
|
1198
|
|
|
} |
|
1199
|
|
|
} elseif (CommonFunctions::fileexists($filename="/etc/config/uLinux.conf") |
|
1200
|
|
|
&& CommonFunctions::rfts($filename, $buf, 0, 4096, false) |
|
1201
|
|
|
&& preg_match("/^Rsync\sModel\s*=\s*QNAP/m", $buf) |
|
1202
|
|
|
&& preg_match("/^Version\s*=\s*([\d\.]+)\r?\nBuild\sNumber\s*=\s*(\S+)/m", $buf, $ver_buf)) { |
|
1203
|
|
|
$buf = $ver_buf[1]."-".$ver_buf[2]; |
|
1204
|
|
|
if (isset($list['QTS']['Image'])) { |
|
1205
|
|
|
$this->sys->setDistributionIcon($list['QTS']['Image']); |
|
1206
|
|
|
} |
|
1207
|
|
|
if (isset($list['QTS']['Name'])) { |
|
1208
|
|
|
$this->sys->setDistribution($list['QTS']['Name']." ".trim($buf)); |
|
1209
|
|
|
} else { |
|
1210
|
|
|
$this->sys->setDistribution(trim($buf)); |
|
1211
|
|
|
} |
|
1212
|
|
|
} |
|
1213
|
|
|
} |
|
1214
|
|
|
/* restore error level */ |
|
1215
|
|
|
error_reporting($old_err_rep); |
|
1216
|
|
|
/* restore error handler */ |
|
1217
|
|
|
if (function_exists('errorHandlerPsi')) { |
|
1218
|
|
|
set_error_handler('errorHandlerPsi'); |
|
1219
|
|
|
} |
|
1220
|
|
|
} |
|
1221
|
|
|
} |
|
1222
|
|
|
|
|
1223
|
|
|
/** |
|
1224
|
|
|
* Processes |
|
1225
|
|
|
* |
|
1226
|
|
|
* @return void |
|
1227
|
|
|
*/ |
|
1228
|
|
|
protected function _processes() |
|
1229
|
|
|
{ |
|
1230
|
|
|
$process = glob('/proc/*/status', GLOB_NOSORT); |
|
1231
|
|
|
if (($total = count($process)) > 0) { |
|
1232
|
|
|
|
|
1233
|
|
|
$processes['*'] = 0; |
|
|
|
|
|
|
1234
|
|
|
$buf = ""; |
|
1235
|
|
|
for ($i = 0; $i < $total; $i++) { |
|
1236
|
|
|
if (CommonFunctions::rfts($process[$i], $buf, 0, 4096, false)) { |
|
1237
|
|
|
$processes['*']++; //current total |
|
1238
|
|
|
if (preg_match('/^State:\s+(\w)/m', $buf, $state)) { |
|
1239
|
|
|
if (isset($processes[$state[1]])) { |
|
1240
|
|
|
$processes[$state[1]]++; |
|
1241
|
|
|
} else { |
|
1242
|
|
|
$processes[$state[1]] = 1; |
|
1243
|
|
|
} |
|
1244
|
|
|
} |
|
1245
|
|
|
} |
|
1246
|
|
|
} |
|
1247
|
|
|
if (!($processes['*'] > 0)) { |
|
1248
|
|
|
$processes['*'] = $processes[' '] = $total; //all unknown |
|
1249
|
|
|
} |
|
1250
|
|
|
$this->sys->setProcesses($processes); |
|
1251
|
|
|
} |
|
1252
|
|
|
} |
|
1253
|
|
|
|
|
1254
|
|
|
/** |
|
1255
|
|
|
* get the information |
|
1256
|
|
|
* |
|
1257
|
|
|
* @see PSI_Interface_OS::build() |
|
1258
|
|
|
* |
|
1259
|
|
|
* @return Void |
|
1260
|
|
|
*/ |
|
1261
|
|
View Code Duplication |
public function build() |
|
|
|
|
|
|
1262
|
|
|
{ |
|
1263
|
|
|
$this->_distro(); |
|
1264
|
|
|
$this->_hostname(); |
|
1265
|
|
|
$this->_kernel(); |
|
1266
|
|
|
$this->_machine(); |
|
1267
|
|
|
$this->_uptime(); |
|
1268
|
|
|
$this->_users(); |
|
1269
|
|
|
$this->_cpuinfo(); |
|
1270
|
|
|
$this->_pci(); |
|
1271
|
|
|
$this->_ide(); |
|
1272
|
|
|
$this->_scsi(); |
|
1273
|
|
|
$this->_usb(); |
|
1274
|
|
|
$this->_i2c(); |
|
1275
|
|
|
$this->_network(); |
|
1276
|
|
|
$this->_memory(); |
|
1277
|
|
|
$this->_filesystems(); |
|
1278
|
|
|
$this->_loadavg(); |
|
1279
|
|
|
$this->_processes(); |
|
1280
|
|
|
} |
|
1281
|
|
|
} |
|
1282
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.