|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Haiku System Class |
|
4
|
|
|
* |
|
5
|
|
|
* PHP version 5 |
|
6
|
|
|
* |
|
7
|
|
|
* @category PHP |
|
8
|
|
|
* @package PSI Haiku OS class |
|
9
|
|
|
* @author Mieczyslaw Nalewaj <[email protected]> |
|
10
|
|
|
* @copyright 2012 phpSysInfo |
|
11
|
|
|
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
|
12
|
|
|
* @version SVN: $Id: class.Haiku.inc.php 687 2012-09-06 20:54:49Z namiltd $ |
|
13
|
|
|
* @link http://phpsysinfo.sourceforge.net |
|
14
|
|
|
*/ |
|
15
|
|
|
/** |
|
16
|
|
|
* Haiku sysinfo class |
|
17
|
|
|
* get all the required information from Haiku system |
|
18
|
|
|
* |
|
19
|
|
|
* @category PHP |
|
20
|
|
|
* @package PSI Haiku OS class |
|
21
|
|
|
* @author Mieczyslaw Nalewaj <[email protected]> |
|
22
|
|
|
* @copyright 2012 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 Haiku extends OS |
|
|
|
|
|
|
28
|
|
|
{ |
|
29
|
|
|
/** |
|
30
|
|
|
* call parent constructor |
|
31
|
|
|
*/ |
|
32
|
|
|
public function __construct() |
|
33
|
|
|
{ |
|
34
|
|
|
parent::__construct(); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* get the cpu information |
|
39
|
|
|
* |
|
40
|
|
|
* @return array |
|
|
|
|
|
|
41
|
|
|
*/ |
|
42
|
|
|
protected function _cpuinfo() |
|
43
|
|
|
{ |
|
44
|
|
|
|
|
45
|
|
|
if (CommonFunctions::executeProgram('sysinfo', '-cpu', $bufr, PSI_DEBUG)) { |
|
46
|
|
|
$cpus = preg_split("/\nCPU #\d+/", $bufr, -1, PREG_SPLIT_NO_EMPTY); |
|
47
|
|
|
$cpuspeed = ""; |
|
48
|
|
|
foreach ($cpus as $cpu) { |
|
49
|
|
|
if (preg_match("/^.*running at (\d+)MHz/", $cpu, $ar_buf)) { |
|
50
|
|
|
$cpuspeed = $ar_buf[1]; |
|
51
|
|
|
} elseif (preg_match("/^: \"(.*)\"/", $cpu, $ar_buf)) { |
|
52
|
|
|
$dev = new CpuDevice(); |
|
53
|
|
|
$dev->setModel($ar_buf[1]); |
|
54
|
|
|
$arrLines = preg_split("/\n/", $cpu, -1, PREG_SPLIT_NO_EMPTY); |
|
55
|
|
|
foreach ($arrLines as $Line) { |
|
56
|
|
|
if (preg_match("/^\s+Data TLB:\s+(.*)K-byte/", $Line, $Line_buf)) { |
|
57
|
|
|
$dev->setCache(max($Line_buf[1]*1024, $dev->getCache())); |
|
58
|
|
|
} elseif (preg_match("/^\s+Data TLB:\s+(.*)M-byte/", $Line, $Line_buf)) { |
|
59
|
|
|
$dev->setCache(max($Line_buf[1]*1024*1024, $dev->getCache())); |
|
60
|
|
|
} elseif (preg_match("/^\s+Data TLB:\s+(.*)G-byte/", $Line, $Line_buf)) { |
|
61
|
|
|
$dev->setCache(max($Line_buf[1]*1024*1024*1024, $dev->getCache())); |
|
62
|
|
|
} elseif (preg_match("/\s+VMX/", $Line, $Line_buf)) { |
|
63
|
|
|
$dev->setVirt("vmx"); |
|
64
|
|
|
} elseif (preg_match("/\s+SVM/", $Line, $Line_buf)) { |
|
65
|
|
|
$dev->setVirt("svm"); |
|
66
|
|
|
} |
|
67
|
|
|
} |
|
68
|
|
|
if ($cpuspeed != "")$dev->setCpuSpeed($cpuspeed); |
|
69
|
|
|
$this->sys->setCpus($dev); |
|
|
|
|
|
|
70
|
|
|
//echo ">>>>>".$cpu; |
|
|
|
|
|
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* PCI devices |
|
78
|
|
|
* get the pci device information |
|
79
|
|
|
* |
|
80
|
|
|
* @return void |
|
81
|
|
|
*/ |
|
82
|
|
|
protected function _pci() |
|
83
|
|
|
{ |
|
84
|
|
|
if (CommonFunctions::executeProgram('listdev', '', $bufr, PSI_DEBUG)) { |
|
85
|
|
|
// $devices = preg_split("/^device |\ndevice /", $bufr, -1, PREG_SPLIT_NO_EMPTY); |
|
|
|
|
|
|
86
|
|
|
$devices = preg_split("/^device /m", $bufr, -1, PREG_SPLIT_NO_EMPTY); |
|
87
|
|
|
foreach ($devices as $device) { |
|
88
|
|
|
$ar_buf = preg_split("/\n/", $device); |
|
89
|
|
|
if (count($ar_buf) >= 3) { |
|
90
|
|
|
if (preg_match("/^([^\(\[\n]*)/", $device, $ar_buf2)) { |
|
91
|
|
|
if (preg_match("/^[^\(]*\((.*)\)/", $device, $ar_buf3)) { |
|
92
|
|
|
$ar_buf2[1] = $ar_buf3[1]; |
|
93
|
|
|
} |
|
94
|
|
|
$name = trim($ar_buf2[1]).": "; |
|
95
|
|
|
|
|
96
|
|
|
if (preg_match("/^\s+vendor\s+[0-9a-fA-F]{4}:\s+(.*)/", $ar_buf[1], $ar_buf3)) { |
|
97
|
|
|
$name .=$ar_buf3[1]." "; |
|
98
|
|
|
} |
|
99
|
|
|
if (preg_match("/^\s+device\s+[0-9a-fA-F]{4}:\s+(.*)/", $ar_buf[2], $ar_buf3)) { |
|
100
|
|
|
$name .=$ar_buf3[1]." "; |
|
101
|
|
|
} |
|
102
|
|
|
$dev = new HWDevice(); |
|
103
|
|
|
$dev->setName(trim($name)); |
|
104
|
|
|
$this->sys->setPciDevices($dev); |
|
105
|
|
|
} |
|
106
|
|
|
} |
|
107
|
|
|
} |
|
108
|
|
|
} |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* USB devices |
|
113
|
|
|
* get the usb device information |
|
114
|
|
|
* |
|
115
|
|
|
* @return void |
|
116
|
|
|
*/ |
|
117
|
|
View Code Duplication |
protected function _usb() |
|
|
|
|
|
|
118
|
|
|
{ |
|
119
|
|
|
if (CommonFunctions::executeProgram('listusb', '', $bufr, PSI_DEBUG)) { |
|
120
|
|
|
$devices = preg_split("/\n/", $bufr); |
|
121
|
|
|
foreach ($devices as $device) { |
|
122
|
|
|
if (preg_match("/^\S+\s+\S+\s+\"(.*)\"\s+\"(.*)\"/", $device, $ar_buf)) { |
|
123
|
|
|
$dev = new HWDevice(); |
|
124
|
|
|
$dev->setName(trim($ar_buf[1]." ".$ar_buf[2])); |
|
125
|
|
|
$this->sys->setUSBDevices($dev); |
|
126
|
|
|
} |
|
127
|
|
|
} |
|
128
|
|
|
} |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
/** |
|
132
|
|
|
* Haiku Version |
|
133
|
|
|
* |
|
134
|
|
|
* @return void |
|
135
|
|
|
*/ |
|
136
|
|
|
private function _kernel() |
|
137
|
|
|
{ |
|
138
|
|
|
if (CommonFunctions::executeProgram('uname', '-rvm', $ret)) { |
|
139
|
|
|
$this->sys->setKernel($ret); |
|
140
|
|
|
} |
|
141
|
|
|
} |
|
142
|
|
|
|
|
143
|
|
|
/** |
|
144
|
|
|
* Distribution |
|
145
|
|
|
* |
|
146
|
|
|
* @return void |
|
147
|
|
|
*/ |
|
148
|
|
|
protected function _distro() |
|
149
|
|
|
{ |
|
150
|
|
|
if (CommonFunctions::executeProgram('uname', '-sr', $ret)) |
|
151
|
|
|
$this->sys->setDistribution($ret); |
|
152
|
|
|
else |
|
153
|
|
|
$this->sys->setDistribution('Haiku'); |
|
154
|
|
|
|
|
155
|
|
|
$this->sys->setDistributionIcon('Haiku.png'); |
|
156
|
|
|
} |
|
157
|
|
|
|
|
158
|
|
|
/** |
|
159
|
|
|
* UpTime |
|
160
|
|
|
* time the system is running |
|
161
|
|
|
* |
|
162
|
|
|
* @return void |
|
163
|
|
|
*/ |
|
164
|
|
|
private function _uptime() |
|
165
|
|
|
{ |
|
166
|
|
|
if (CommonFunctions::executeProgram('uptime', '-u', $buf)) { |
|
167
|
|
|
if (preg_match("/^up (\d+) minute[s]?/", $buf, $ar_buf)) { |
|
168
|
|
|
$min = $ar_buf[1]; |
|
169
|
|
|
$this->sys->setUptime($min * 60); |
|
|
|
|
|
|
170
|
|
|
} elseif (preg_match("/^up (\d+) hour[s]?, (\d+) minute[s]?/", $buf, $ar_buf)) { |
|
171
|
|
|
$min = $ar_buf[2]; |
|
172
|
|
|
$hours = $ar_buf[1]; |
|
173
|
|
|
$this->sys->setUptime($hours * 3600 + $min * 60); |
|
|
|
|
|
|
174
|
|
|
} elseif (preg_match("/^up (\d+) day[s]?, (\d+) hour[s]?, (\d+) minute[s]?/", $buf, $ar_buf)) { |
|
175
|
|
|
$min = $ar_buf[3]; |
|
176
|
|
|
$hours = $ar_buf[2]; |
|
177
|
|
|
$days = $ar_buf[1]; |
|
178
|
|
|
$this->sys->setUptime($days * 86400 + $hours * 3600 + $min * 60); |
|
|
|
|
|
|
179
|
|
|
} |
|
180
|
|
|
} |
|
181
|
|
|
} |
|
182
|
|
|
|
|
183
|
|
|
/** |
|
184
|
|
|
* Processor Load |
|
185
|
|
|
* optionally create a loadbar |
|
186
|
|
|
* |
|
187
|
|
|
* @return void |
|
188
|
|
|
*/ |
|
189
|
|
|
private function _loadavg() |
|
190
|
|
|
{ |
|
191
|
|
|
if (CommonFunctions::executeProgram('top', '-n 1 -i 1', $buf)) { |
|
192
|
|
|
if (preg_match("/\s+(\S+)%\s+TOTAL\s+\(\S+%\s+idle time/", $buf, $ar_buf)) { |
|
193
|
|
|
$this->sys->setLoad($ar_buf[1]); |
|
194
|
|
|
if (PSI_LOAD_BAR) { |
|
195
|
|
|
$this->sys->setLoadPercent(round($ar_buf[1])); |
|
196
|
|
|
} |
|
197
|
|
|
} |
|
198
|
|
|
} |
|
199
|
|
|
} |
|
200
|
|
|
|
|
201
|
|
|
/** |
|
202
|
|
|
* Number of Users |
|
203
|
|
|
* |
|
204
|
|
|
* @return void |
|
205
|
|
|
*/ |
|
206
|
|
|
protected function _users() |
|
207
|
|
|
{ |
|
208
|
|
|
$this->sys->setUsers(1); |
|
209
|
|
|
} |
|
210
|
|
|
|
|
211
|
|
|
/** |
|
212
|
|
|
* Virtual Host Name |
|
213
|
|
|
* |
|
214
|
|
|
* @return void |
|
215
|
|
|
*/ |
|
216
|
|
View Code Duplication |
private function _hostname() |
|
|
|
|
|
|
217
|
|
|
{ |
|
218
|
|
|
if (PSI_USE_VHOST === true) { |
|
219
|
|
|
$this->sys->setHostname(getenv('SERVER_NAME')); |
|
220
|
|
|
} else { |
|
221
|
|
|
if (CommonFunctions::executeProgram('uname', '-n', $result, PSI_DEBUG)) { |
|
222
|
|
|
$ip = gethostbyname($result); |
|
223
|
|
|
if ($ip != $result) { |
|
224
|
|
|
$this->sys->setHostname(gethostbyaddr($ip)); |
|
225
|
|
|
} |
|
226
|
|
|
} |
|
227
|
|
|
} |
|
228
|
|
|
} |
|
229
|
|
|
|
|
230
|
|
|
/** |
|
231
|
|
|
* Physical memory information and Swap Space information |
|
232
|
|
|
* |
|
233
|
|
|
* @return void |
|
234
|
|
|
*/ |
|
235
|
|
|
private function _memory() |
|
236
|
|
|
{ |
|
237
|
|
|
if (CommonFunctions::executeProgram('sysinfo', '-mem', $bufr, PSI_DEBUG)) { |
|
238
|
|
|
if (preg_match("/(.*)bytes free\s+\(used\/max\s+(.*)\s+\/\s+(.*)\)\s*\n\s+\(cached\s+(.*)\)/", $bufr, $ar_buf)) { |
|
239
|
|
|
$this->sys->setMemTotal($ar_buf[3]); |
|
240
|
|
|
$this->sys->setMemFree($ar_buf[1]); |
|
241
|
|
|
$this->sys->setMemCache($ar_buf[4]); |
|
242
|
|
|
$this->sys->setMemUsed($ar_buf[2]); |
|
243
|
|
|
} |
|
244
|
|
|
} |
|
245
|
|
|
if (CommonFunctions::executeProgram('vmstat', '', $bufr, PSI_DEBUG)) { |
|
246
|
|
|
if (preg_match("/max swap space:\s+(.*)\nfree swap space:\s+(.*)\n/", $bufr, $ar_buf)) { |
|
247
|
|
|
if ($ar_buf[1]>0) { |
|
248
|
|
|
$dev = new DiskDevice(); |
|
249
|
|
|
$dev->setMountPoint("/boot/common/var/swap"); |
|
250
|
|
|
$dev->setName("SWAP"); |
|
251
|
|
|
$dev->setTotal($ar_buf[1]); |
|
252
|
|
|
$dev->setFree($ar_buf[2]); |
|
253
|
|
|
$dev->setUSed($ar_buf[1]-$ar_buf[2]); |
|
254
|
|
|
$this->sys->setSwapDevices($dev); |
|
255
|
|
|
} |
|
256
|
|
|
} |
|
257
|
|
|
} |
|
258
|
|
|
} |
|
259
|
|
|
|
|
260
|
|
|
/** |
|
261
|
|
|
* filesystem information |
|
262
|
|
|
* |
|
263
|
|
|
* @return void |
|
264
|
|
|
*/ |
|
265
|
|
|
private function _filesystems() |
|
266
|
|
|
{ |
|
267
|
|
|
if (CommonFunctions::executeProgram('df', '-b', $df, PSI_DEBUG)) { |
|
268
|
|
|
$df = preg_split("/\n/", $df, -1, PREG_SPLIT_NO_EMPTY); |
|
269
|
|
|
foreach ($df as $df_line) { |
|
270
|
|
|
$ar_buf = preg_split("/\s+/", $df_line); |
|
271
|
|
|
if ((substr($df_line, 0, 1) == "/") && (count($ar_buf) == 6)) { |
|
272
|
|
|
$dev = new DiskDevice(); |
|
273
|
|
|
$dev->setMountPoint($ar_buf[0]); |
|
274
|
|
|
$dev->setName($ar_buf[5]); |
|
275
|
|
|
$dev->setFsType($ar_buf[1]); |
|
276
|
|
|
$dev->setOptions($ar_buf[4]); |
|
277
|
|
|
$dev->setTotal($ar_buf[2] * 1024); |
|
278
|
|
|
$dev->setFree($ar_buf[3] * 1024); |
|
279
|
|
|
$dev->setUsed($dev->getTotal() - $dev->getFree()); |
|
280
|
|
|
$this->sys->setDiskDevices($dev); |
|
281
|
|
|
} |
|
282
|
|
|
} |
|
283
|
|
|
} |
|
284
|
|
|
} |
|
285
|
|
|
|
|
286
|
|
|
/** |
|
287
|
|
|
* network information |
|
288
|
|
|
* |
|
289
|
|
|
* @return void |
|
290
|
|
|
*/ |
|
291
|
|
|
private function _network() |
|
292
|
|
|
{ |
|
293
|
|
|
if (CommonFunctions::executeProgram('ifconfig', '', $bufr, PSI_DEBUG)) { |
|
294
|
|
|
$lines = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY); |
|
295
|
|
|
$was = false; |
|
296
|
|
|
foreach ($lines as $line) { |
|
297
|
|
|
if (preg_match("/^(\S+)/", $line, $ar_buf)) { |
|
298
|
|
|
if ($was) { |
|
299
|
|
|
$dev->setErrors($errors); |
|
|
|
|
|
|
300
|
|
|
$dev->setDrops($drops); |
|
|
|
|
|
|
301
|
|
|
$this->sys->setNetDevices($dev); |
|
302
|
|
|
} |
|
303
|
|
|
$errors = 0; |
|
304
|
|
|
$drops = 0; |
|
305
|
|
|
$dev = new NetDevice(); |
|
306
|
|
|
$dev->setName($ar_buf[1]); |
|
307
|
|
|
$was = true; |
|
308
|
|
|
} else { |
|
309
|
|
|
if ($was) { |
|
310
|
|
|
if (preg_match('/\sReceive:\s\d+\spackets,\s(\d+)\serrors,\s(\d+)\sbytes,\s\d+\smcasts,\s(\d+)\sdropped/i', $line, $ar_buf2)) { |
|
311
|
|
|
$errors +=$ar_buf2[1]; |
|
312
|
|
|
$drops +=$ar_buf2[3]; |
|
313
|
|
|
$dev->setRxBytes($ar_buf2[2]); |
|
314
|
|
View Code Duplication |
} elseif (preg_match('/\sTransmit:\s\d+\spackets,\s(\d+)\serrors,\s(\d+)\sbytes,\s\d+\smcasts,\s(\d+)\sdropped/i', $line, $ar_buf2)) { |
|
|
|
|
|
|
315
|
|
|
$errors +=$ar_buf2[1]; |
|
316
|
|
|
$drops +=$ar_buf2[3]; |
|
317
|
|
|
$dev->setTxBytes($ar_buf2[2]); |
|
318
|
|
|
} |
|
319
|
|
|
|
|
320
|
|
|
if (defined('PSI_SHOW_NETWORK_INFOS') && (PSI_SHOW_NETWORK_INFOS)) { |
|
321
|
|
|
if (preg_match('/\sEthernet,\s+Address:\s(\S*)/i', $line, $ar_buf2)) |
|
322
|
|
|
$dev->setInfo(preg_replace('/:/', '-', strtoupper($ar_buf2[1]))); |
|
323
|
|
|
elseif (preg_match('/^\s+inet\saddr:\s(\S*),/i', $line, $ar_buf2)) |
|
324
|
|
|
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$ar_buf2[1]); |
|
325
|
|
View Code Duplication |
elseif (preg_match('/^\s+inet6\saddr:\s(\S*),/i', $line, $ar_buf2) |
|
|
|
|
|
|
326
|
|
|
&& ($ar_buf2[1]!="::") && !preg_match('/^fe80::/i', $ar_buf2[1])) |
|
327
|
|
|
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').strtolower($ar_buf2[1])); |
|
328
|
|
|
} |
|
329
|
|
|
} |
|
330
|
|
|
} |
|
331
|
|
|
} |
|
332
|
|
|
if ($was) { |
|
333
|
|
|
$dev->setErrors($errors); |
|
334
|
|
|
$dev->setDrops($drops); |
|
335
|
|
|
$this->sys->setNetDevices($dev); |
|
336
|
|
|
} |
|
337
|
|
|
} |
|
338
|
|
|
} |
|
339
|
|
|
|
|
340
|
|
|
/** |
|
341
|
|
|
* Processes |
|
342
|
|
|
* |
|
343
|
|
|
* @return void |
|
344
|
|
|
*/ |
|
345
|
|
|
protected function _processes() |
|
346
|
|
|
{ |
|
347
|
|
|
if (CommonFunctions::executeProgram('ps', '', $bufr, PSI_DEBUG)) { |
|
348
|
|
|
$lines = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY); |
|
349
|
|
|
$processes['*'] = 0; |
|
|
|
|
|
|
350
|
|
|
foreach ($lines as $line) { |
|
351
|
|
|
if (preg_match("/^(kernel_team|\/)/", $line, $ar_buf)) { |
|
352
|
|
|
$processes['*']++; |
|
353
|
|
|
} |
|
354
|
|
|
} |
|
355
|
|
|
if ($processes['*'] > 0) { |
|
356
|
|
|
$processes[' '] = $processes['*']; |
|
357
|
|
|
$this->sys->setProcesses($processes); |
|
358
|
|
|
} |
|
359
|
|
|
} |
|
360
|
|
|
} |
|
361
|
|
|
|
|
362
|
|
|
/** |
|
363
|
|
|
* get the information |
|
364
|
|
|
* |
|
365
|
|
|
* @return Void |
|
366
|
|
|
*/ |
|
367
|
|
View Code Duplication |
public function build() |
|
|
|
|
|
|
368
|
|
|
{ |
|
369
|
|
|
$this->error->addError("WARN", "The Haiku version of phpSysInfo is a work in progress, some things currently don't work"); |
|
370
|
|
|
$this->_distro(); |
|
371
|
|
|
$this->_hostname(); |
|
372
|
|
|
$this->_kernel(); |
|
373
|
|
|
$this->_uptime(); |
|
374
|
|
|
$this->_users(); |
|
375
|
|
|
$this->_loadavg(); |
|
376
|
|
|
$this->_pci(); |
|
377
|
|
|
$this->_usb(); |
|
378
|
|
|
$this->_cpuinfo(); |
|
379
|
|
|
$this->_memory(); |
|
380
|
|
|
$this->_filesystems(); |
|
381
|
|
|
$this->_network(); |
|
382
|
|
|
$this->_processes(); |
|
383
|
|
|
} |
|
384
|
|
|
} |
|
385
|
|
|
|
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.