325 |
richard |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
// phpSysInfo - A PHP System Information Script
|
|
|
4 |
// http://phpsysinfo.sourceforge.net/
|
|
|
5 |
|
|
|
6 |
// This program is free software; you can redistribute it and/or
|
|
|
7 |
// modify it under the terms of the GNU General Public License
|
|
|
8 |
// as published by the Free Software Foundation; either version 2
|
|
|
9 |
// of the License, or (at your option) any later version.
|
|
|
10 |
|
|
|
11 |
// This program is distributed in the hope that it will be useful,
|
|
|
12 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
13 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
14 |
// GNU General Public License for more details.
|
|
|
15 |
|
|
|
16 |
// You should have received a copy of the GNU General Public License
|
|
|
17 |
// along with this program; if not, write to the Free Software
|
|
|
18 |
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
19 |
|
|
|
20 |
// $Id: class.HP-UX.inc.php,v 1.20 2007/02/18 18:59:54 bigmichi1 Exp $
|
|
|
21 |
|
|
|
22 |
class sysinfo {
|
|
|
23 |
// get our apache SERVER_NAME or vhost
|
|
|
24 |
function vhostname () {
|
|
|
25 |
if (! ($result = getenv('SERVER_NAME'))) {
|
|
|
26 |
$result = 'N.A.';
|
|
|
27 |
}
|
|
|
28 |
return $result;
|
|
|
29 |
}
|
|
|
30 |
// get the IP address of our vhost name
|
|
|
31 |
function vip_addr () {
|
|
|
32 |
return gethostbyname($this->vhostname());
|
|
|
33 |
}
|
|
|
34 |
// get our canonical hostname
|
|
|
35 |
function chostname () {
|
|
|
36 |
return execute_program('hostname');
|
|
|
37 |
}
|
|
|
38 |
// get the IP address of our canonical hostname
|
|
|
39 |
function ip_addr () {
|
|
|
40 |
if (!($result = getenv('SERVER_ADDR'))) {
|
|
|
41 |
$result = gethostbyname($this->chostname());
|
|
|
42 |
}
|
|
|
43 |
return $result;
|
|
|
44 |
}
|
|
|
45 |
|
|
|
46 |
function kernel () {
|
|
|
47 |
return execute_program('uname', '-srvm');
|
|
|
48 |
}
|
|
|
49 |
|
|
|
50 |
function uptime () {
|
|
|
51 |
$result = 0;
|
|
|
52 |
$ar_buf = array();
|
|
|
53 |
|
|
|
54 |
$buf = execute_program('uptime');
|
|
|
55 |
if (preg_match("/up (\d+) days,\s*(\d+):(\d+),/", $buf, $ar_buf)) {
|
|
|
56 |
$min = $ar_buf[3];
|
|
|
57 |
$hours = $ar_buf[2];
|
|
|
58 |
$days = $ar_buf[1];
|
|
|
59 |
$result = $days * 86400 + $hours * 3600 + $min * 60;
|
|
|
60 |
}
|
|
|
61 |
|
|
|
62 |
return $result;
|
|
|
63 |
}
|
|
|
64 |
|
|
|
65 |
function users () {
|
|
|
66 |
$who = explode('=', execute_program('who', '-q'));
|
|
|
67 |
$result = $who[1];
|
|
|
68 |
return $result;
|
|
|
69 |
}
|
|
|
70 |
|
|
|
71 |
function loadavg ($bar = false) {
|
|
|
72 |
$ar_buf = array();
|
|
|
73 |
|
|
|
74 |
$buf = execute_program('uptime');
|
|
|
75 |
|
|
|
76 |
if (preg_match("/average: (.*), (.*), (.*)$/", $buf, $ar_buf)) {
|
|
|
77 |
$results['avg'] = array($ar_buf[1], $ar_buf[2], $ar_buf[3]);
|
|
|
78 |
} else {
|
|
|
79 |
$results['avg'] = array('N.A.', 'N.A.', 'N.A.');
|
|
|
80 |
}
|
|
|
81 |
return $results;
|
|
|
82 |
}
|
|
|
83 |
|
|
|
84 |
function cpu_info () {
|
|
|
85 |
$results = array();
|
|
|
86 |
$ar_buf = array();
|
|
|
87 |
|
|
|
88 |
$bufr = rfts( '/proc/cpuinfo' );
|
|
|
89 |
if( $bufr != "ERROR" ) {
|
|
|
90 |
$bufe = explode( "\n", $bufr );
|
|
|
91 |
foreach( $bufe as $buf ) {
|
|
|
92 |
list($key, $value) = preg_split('/\s+:\s+/', trim($buf), 2);
|
|
|
93 |
// All of the tags here are highly architecture dependant.
|
|
|
94 |
// the only way I could reconstruct them for machines I don't
|
|
|
95 |
// have is to browse the kernel source. So if your arch isn't
|
|
|
96 |
// supported, tell me you want it written in.
|
|
|
97 |
switch ($key) {
|
|
|
98 |
case 'model name':
|
|
|
99 |
$results['model'] = $value;
|
|
|
100 |
break;
|
|
|
101 |
case 'cpu MHz':
|
|
|
102 |
$results['cpuspeed'] = sprintf('%.2f', $value);
|
|
|
103 |
break;
|
|
|
104 |
case 'cycle frequency [Hz]': // For Alpha arch - 2.2.x
|
|
|
105 |
$results['cpuspeed'] = sprintf('%.2f', $value / 1000000);
|
|
|
106 |
break;
|
|
|
107 |
case 'clock': // For PPC arch (damn borked POS)
|
|
|
108 |
$results['cpuspeed'] = sprintf('%.2f', $value);
|
|
|
109 |
break;
|
|
|
110 |
case 'cpu': // For PPC arch (damn borked POS)
|
|
|
111 |
$results['model'] = $value;
|
|
|
112 |
break;
|
|
|
113 |
case 'revision': // For PPC arch (damn borked POS)
|
|
|
114 |
$results['model'] .= ' ( rev: ' . $value . ')';
|
|
|
115 |
break;
|
|
|
116 |
case 'cpu model': // For Alpha arch - 2.2.x
|
|
|
117 |
$results['model'] .= ' (' . $value . ')';
|
|
|
118 |
break;
|
|
|
119 |
case 'cache size':
|
|
|
120 |
$results['cache'] = $value;
|
|
|
121 |
break;
|
|
|
122 |
case 'bogomips':
|
|
|
123 |
$results['bogomips'] += $value;
|
|
|
124 |
break;
|
|
|
125 |
case 'BogoMIPS': // For alpha arch - 2.2.x
|
|
|
126 |
$results['bogomips'] += $value;
|
|
|
127 |
break;
|
|
|
128 |
case 'BogoMips': // For sparc arch
|
|
|
129 |
$results['bogomips'] += $value;
|
|
|
130 |
break;
|
|
|
131 |
case 'cpus detected': // For Alpha arch - 2.2.x
|
|
|
132 |
$results['cpus'] += $value;
|
|
|
133 |
break;
|
|
|
134 |
case 'system type': // Alpha arch - 2.2.x
|
|
|
135 |
$results['model'] .= ', ' . $value . ' ';
|
|
|
136 |
break;
|
|
|
137 |
case 'platform string': // Alpha arch - 2.2.x
|
|
|
138 |
$results['model'] .= ' (' . $value . ')';
|
|
|
139 |
break;
|
|
|
140 |
case 'processor':
|
|
|
141 |
$results['cpus'] += 1;
|
|
|
142 |
break;
|
|
|
143 |
}
|
|
|
144 |
}
|
|
|
145 |
fclose($fd);
|
|
|
146 |
}
|
|
|
147 |
|
|
|
148 |
$keys = array_keys($results);
|
|
|
149 |
$keys2be = array('model', 'cpuspeed', 'cache', 'bogomips', 'cpus');
|
|
|
150 |
|
|
|
151 |
while ($ar_buf = each($keys2be)) {
|
|
|
152 |
if (! in_array($ar_buf[1], $keys)) {
|
|
|
153 |
$results[$ar_buf[1]] = 'N.A.';
|
|
|
154 |
}
|
|
|
155 |
}
|
|
|
156 |
return $results;
|
|
|
157 |
}
|
|
|
158 |
|
|
|
159 |
function pci () {
|
|
|
160 |
$results = array();
|
|
|
161 |
|
|
|
162 |
$bufr = rfts( '/proc/pci' );
|
|
|
163 |
if( $bufr != "ERROR" ) {
|
|
|
164 |
$bufe = explode( "\n", $bufr );
|
|
|
165 |
foreach( $bufe as $buf ) {
|
|
|
166 |
if (preg_match('/Bus/', $buf)) {
|
|
|
167 |
$device = true;
|
|
|
168 |
continue;
|
|
|
169 |
}
|
|
|
170 |
|
|
|
171 |
if ($device) {
|
|
|
172 |
list($key, $value) = explode(': ', $buf, 2);
|
|
|
173 |
|
|
|
174 |
if (!preg_match('/bridge/i', $key) && !preg_match('/USB/i', $key)) {
|
|
|
175 |
$results[] = preg_replace('/\([^\)]+\)\.$/', '', trim($value));
|
|
|
176 |
}
|
|
|
177 |
$device = false;
|
|
|
178 |
}
|
|
|
179 |
}
|
|
|
180 |
}
|
|
|
181 |
asort($results);
|
|
|
182 |
return $results;
|
|
|
183 |
}
|
|
|
184 |
|
|
|
185 |
function ide () {
|
|
|
186 |
$results = array();
|
|
|
187 |
|
|
|
188 |
$bufd = gdc( '/proc/ide' );
|
|
|
189 |
|
|
|
190 |
foreach( $bufd as $file ) {
|
|
|
191 |
if (preg_match('/^hd/', $file)) {
|
|
|
192 |
$results[$file] = array();
|
|
|
193 |
// Check if device is CD-ROM (CD-ROM capacity shows as 1024 GB)
|
|
|
194 |
$buf = rfts( "/proc/ide/" . $file . "/media", 1 );
|
|
|
195 |
if( $buf != "ERROR" ) {
|
|
|
196 |
$results[$file]['media'] = trim( $buf );
|
|
|
197 |
if ($results[$file]['media'] == 'disk') {
|
|
|
198 |
$results[$file]['media'] = 'Hard Disk';
|
|
|
199 |
}
|
|
|
200 |
if ($results[$file]['media'] == 'cdrom') {
|
|
|
201 |
$results[$file]['media'] = 'CD-ROM';
|
|
|
202 |
}
|
|
|
203 |
}
|
|
|
204 |
|
|
|
205 |
$buf = rfts( "/proc/ide/" . $file . "/model", 1 );
|
|
|
206 |
if( $buf != "ERROR" ) {
|
|
|
207 |
$results[$file]['model'] = trim( $buf );
|
|
|
208 |
if (preg_match('/WDC/', $results[$file]['model'])) {
|
|
|
209 |
$results[$file]['manufacture'] = 'Western Digital';
|
|
|
210 |
} elseif (preg_match('/IBM/', $results[$file]['model'])) {
|
|
|
211 |
$results[$file]['manufacture'] = 'IBM';
|
|
|
212 |
} elseif (preg_match('/FUJITSU/', $results[$file]['model'])) {
|
|
|
213 |
$results[$file]['manufacture'] = 'Fujitsu';
|
|
|
214 |
} else {
|
|
|
215 |
$results[$file]['manufacture'] = 'Unknown';
|
|
|
216 |
}
|
|
|
217 |
}
|
|
|
218 |
|
|
|
219 |
$buf = rfts( "/proc/ide/" . $file . "/capacity", 1 );
|
|
|
220 |
if( $buf != "ERROR" ) {
|
|
|
221 |
$results[$file]['capacity'] = trim( $buf );
|
|
|
222 |
if ($results[$file]['media'] == 'CD-ROM') {
|
|
|
223 |
unset($results[$file]['capacity']);
|
|
|
224 |
}
|
|
|
225 |
}
|
|
|
226 |
}
|
|
|
227 |
}
|
|
|
228 |
asort($results);
|
|
|
229 |
return $results;
|
|
|
230 |
}
|
|
|
231 |
|
|
|
232 |
function scsi () {
|
|
|
233 |
$results = array();
|
|
|
234 |
$dev_vendor = '';
|
|
|
235 |
$dev_model = '';
|
|
|
236 |
$dev_rev = '';
|
|
|
237 |
$dev_type = '';
|
|
|
238 |
$s = 1;
|
|
|
239 |
|
|
|
240 |
$bufr = rfts( '/proc/scsi/scsi' );
|
|
|
241 |
if( $bufr != "ERROR" ) {
|
|
|
242 |
$bufe = explode( "\n", $bufr );
|
|
|
243 |
foreach( $bufe as $buf ) {
|
|
|
244 |
if (preg_match('/Vendor/', $buf)) {
|
|
|
245 |
preg_match('/Vendor: (.*) Model: (.*) Rev: (.*)/i', $buf, $dev);
|
|
|
246 |
list($key, $value) = explode(': ', $buf, 2);
|
|
|
247 |
$dev_str = $value;
|
|
|
248 |
$get_type = 1;
|
|
|
249 |
continue;
|
|
|
250 |
}
|
|
|
251 |
|
|
|
252 |
if ($get_type) {
|
|
|
253 |
preg_match('/Type:\s+(\S+)/i', $buf, $dev_type);
|
|
|
254 |
$results[$s]['model'] = "$dev[1] $dev[2] ($dev_type[1])";
|
|
|
255 |
$results[$s]['media'] = "Hard Disk";
|
|
|
256 |
$s++;
|
|
|
257 |
$get_type = 0;
|
|
|
258 |
}
|
|
|
259 |
}
|
|
|
260 |
}
|
|
|
261 |
asort($results);
|
|
|
262 |
return $results;
|
|
|
263 |
}
|
|
|
264 |
|
|
|
265 |
function usb () {
|
|
|
266 |
$results = array();
|
|
|
267 |
$devstring = 0;
|
|
|
268 |
$devnum = -1;
|
|
|
269 |
|
|
|
270 |
$bufr = rfts( '/proc/bus/usb/devices' );
|
|
|
271 |
if( $bufr != "ERROR" ) {
|
|
|
272 |
$bufe = explode( "\n", $bufr );
|
|
|
273 |
foreach( $bufe as $buf ) {
|
|
|
274 |
if (preg_match('/^T/', $buf)) {
|
|
|
275 |
$devnum += 1;
|
|
|
276 |
}
|
|
|
277 |
if (preg_match('/^S/', $buf)) {
|
|
|
278 |
$devstring = 1;
|
|
|
279 |
}
|
|
|
280 |
|
|
|
281 |
if ($devstring) {
|
|
|
282 |
list($key, $value) = explode(': ', $buf, 2);
|
|
|
283 |
list($key, $value2) = explode('=', $value, 2);
|
|
|
284 |
$results[$devnum] .= " " . trim($value2);
|
|
|
285 |
$devstring = 0;
|
|
|
286 |
}
|
|
|
287 |
}
|
|
|
288 |
}
|
|
|
289 |
return $results;
|
|
|
290 |
}
|
|
|
291 |
|
|
|
292 |
function sbus () {
|
|
|
293 |
$results = array();
|
|
|
294 |
$_results[0] = "";
|
|
|
295 |
// TODO. Nothing here yet. Move along.
|
|
|
296 |
$results = $_results;
|
|
|
297 |
return $results;
|
|
|
298 |
}
|
|
|
299 |
|
|
|
300 |
function network () {
|
|
|
301 |
$netstat = execute_program('netstat', '-ni | tail -n +2');
|
|
|
302 |
$lines = explode("\n", $netstat);
|
|
|
303 |
$results = array();
|
|
|
304 |
for ($i = 0, $max = sizeof($lines); $i < $max; $i++) {
|
|
|
305 |
$ar_buf = preg_split("/\s+/", $lines[$i]);
|
|
|
306 |
if (!empty($ar_buf[0]) && !empty($ar_buf[3])) {
|
|
|
307 |
$results[$ar_buf[0]] = array();
|
|
|
308 |
|
|
|
309 |
$results[$ar_buf[0]]['rx_bytes'] = $ar_buf[4];
|
|
|
310 |
$results[$ar_buf[0]]['rx_packets'] = $ar_buf[4];
|
|
|
311 |
$results[$ar_buf[0]]['rx_errs'] = $ar_buf[5];
|
|
|
312 |
$results[$ar_buf[0]]['rx_drop'] = $ar_buf[8];
|
|
|
313 |
|
|
|
314 |
$results[$ar_buf[0]]['tx_bytes'] = $ar_buf[6];
|
|
|
315 |
$results[$ar_buf[0]]['tx_packets'] = $ar_buf[6];
|
|
|
316 |
$results[$ar_buf[0]]['tx_errs'] = $ar_buf[7];
|
|
|
317 |
$results[$ar_buf[0]]['tx_drop'] = $ar_buf[8];
|
|
|
318 |
|
|
|
319 |
$results[$ar_buf[0]]['errs'] = $ar_buf[5] + $ar_buf[7];
|
|
|
320 |
$results[$ar_buf[0]]['drop'] = $ar_buf[8];
|
|
|
321 |
}
|
|
|
322 |
}
|
|
|
323 |
return $results;
|
|
|
324 |
}
|
|
|
325 |
function memory () {
|
|
|
326 |
$results['ram'] = array();
|
|
|
327 |
$results['swap'] = array();
|
|
|
328 |
$results['devswap'] = array();
|
|
|
329 |
|
|
|
330 |
$bufr = rfts( '/proc/meminfo' );
|
|
|
331 |
if( $bufr != "ERROR" ) {
|
|
|
332 |
$bufe = explode( "\n", $bufr );
|
|
|
333 |
foreach( $bufe as $buf ) {
|
|
|
334 |
if (preg_match('/Mem:\s+(.*)$/', $buf, $ar_buf)) {
|
|
|
335 |
$ar_buf = preg_split('/\s+/', $ar_buf[1], 6);
|
|
|
336 |
|
|
|
337 |
$results['ram']['total'] = $ar_buf[0] / 1024;
|
|
|
338 |
$results['ram']['used'] = $ar_buf[1] / 1024;
|
|
|
339 |
$results['ram']['free'] = $ar_buf[2] / 1024;
|
|
|
340 |
$results['ram']['shared'] = $ar_buf[3] / 1024;
|
|
|
341 |
$results['ram']['buffers'] = $ar_buf[4] / 1024;
|
|
|
342 |
$results['ram']['cached'] = $ar_buf[5] / 1024;
|
|
|
343 |
// I don't like this since buffers and cache really aren't
|
|
|
344 |
// 'used' per say, but I get too many emails about it.
|
|
|
345 |
$results['ram']['percent'] = round(($results['ram']['used'] * 100) / $results['ram']['total']);
|
|
|
346 |
}
|
|
|
347 |
|
|
|
348 |
if (preg_match('/Swap:\s+(.*)$/', $buf, $ar_buf)) {
|
|
|
349 |
$ar_buf = preg_split('/\s+/', $ar_buf[1], 3);
|
|
|
350 |
|
|
|
351 |
$results['swap']['total'] = $ar_buf[0] / 1024;
|
|
|
352 |
$results['swap']['used'] = $ar_buf[1] / 1024;
|
|
|
353 |
$results['swap']['free'] = $ar_buf[2] / 1024;
|
|
|
354 |
$results['swap']['percent'] = round(($ar_buf[1] * 100) / $ar_buf[0]);
|
|
|
355 |
// Get info on individual swap files
|
|
|
356 |
$swaps = rfts( '/proc/swaps' );
|
|
|
357 |
if( $swaps != "ERROR" ) {
|
|
|
358 |
$swapdevs = explode("\n", $swaps);
|
|
|
359 |
|
|
|
360 |
for ($i = 1, $max = (sizeof($swapdevs) - 1); $i < $max; $i++) {
|
|
|
361 |
$ar_buf = preg_split('/\s+/', $swapdevs[$i], 6);
|
|
|
362 |
$results['devswap'][$i - 1] = array();
|
|
|
363 |
$results['devswap'][$i - 1]['dev'] = $ar_buf[0];
|
|
|
364 |
$results['devswap'][$i - 1]['total'] = $ar_buf[2];
|
|
|
365 |
$results['devswap'][$i - 1]['used'] = $ar_buf[3];
|
|
|
366 |
$results['devswap'][$i - 1]['free'] = ($results['devswap'][$i - 1]['total'] - $results['devswap'][$i - 1]['used']);
|
|
|
367 |
$results['devswap'][$i - 1]['percent'] = round(($ar_buf[3] * 100) / $ar_buf[2]);
|
|
|
368 |
}
|
|
|
369 |
break;
|
|
|
370 |
}
|
|
|
371 |
}
|
|
|
372 |
}
|
|
|
373 |
}
|
|
|
374 |
return $results;
|
|
|
375 |
}
|
|
|
376 |
|
|
|
377 |
function filesystems () {
|
|
|
378 |
$df = execute_program('df', '-kP');
|
|
|
379 |
$mounts = explode("\n", $df);
|
|
|
380 |
$fstype = array();
|
|
|
381 |
|
|
|
382 |
$s = execute_program('mount', '-v');
|
|
|
383 |
$lines = explode("\n", $s);
|
|
|
384 |
|
|
|
385 |
$i = 0;
|
|
|
386 |
while (list(, $line) = each($lines)) {
|
|
|
387 |
$a = explode(' ', $line);
|
|
|
388 |
$fsdev[$a[0]] = $a[4];
|
|
|
389 |
}
|
|
|
390 |
|
|
|
391 |
for ($i = 1, $j = 0, $max = sizeof($mounts); $i < $max; $i++) {
|
|
|
392 |
$ar_buf = preg_split("/\s+/", $mounts[$i], 6);
|
|
|
393 |
|
|
|
394 |
if (hide_mount($ar_buf[5])) {
|
|
|
395 |
continue;
|
|
|
396 |
}
|
|
|
397 |
|
|
|
398 |
$results[$j] = array();
|
|
|
399 |
|
|
|
400 |
$results[$j]['disk'] = $ar_buf[0];
|
|
|
401 |
$results[$j]['size'] = $ar_buf[1];
|
|
|
402 |
$results[$j]['used'] = $ar_buf[2];
|
|
|
403 |
$results[$j]['free'] = $ar_buf[3];
|
|
|
404 |
$results[$j]['percent'] = $ar_buf[4];
|
|
|
405 |
$results[$j]['mount'] = $ar_buf[5];
|
|
|
406 |
($fstype[$ar_buf[5]]) ? $results[$j]['fstype'] = $fstype[$ar_buf[5]] : $results[$j]['fstype'] = $fsdev[$ar_buf[0]];
|
|
|
407 |
$j++;
|
|
|
408 |
}
|
|
|
409 |
return $results;
|
|
|
410 |
}
|
|
|
411 |
|
|
|
412 |
function distro () {
|
|
|
413 |
$result = 'HP-UX';
|
|
|
414 |
return($result);
|
|
|
415 |
}
|
|
|
416 |
|
|
|
417 |
function distroicon () {
|
|
|
418 |
$result = 'unknown.png';
|
|
|
419 |
return($result);
|
|
|
420 |
}
|
|
|
421 |
}
|
|
|
422 |
|
|
|
423 |
?>
|