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