[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Phpgroupware-cvs] phpsysinfo/includes/os class.Linux.inc.php, 1.2 class
From: |
skwashd |
Subject: |
[Phpgroupware-cvs] phpsysinfo/includes/os class.Linux.inc.php, 1.2 class.HP-UX.inc.php, 1.1 class.NetBSD.inc.php, 1.2 class.OpenBSD.inc.php, 1.2 index.html, 1.1 class.WINNT.inc.php, 1.1 class.FreeBSD.inc.php, 1.2 class.Darwin.inc.php, 1.2 class.BSD.common.inc.php, 1.2 class.SunOS.inc.php, 1.1 |
Date: |
Sat, 19 Nov 2005 06:29:00 +0100 |
Update of phpsysinfo/includes/os
Added Files:
Branch: MAIN
class.Linux.inc.php lines: +516 -0
class.HP-UX.inc.php
class.NetBSD.inc.php lines: +150 -0
class.OpenBSD.inc.php lines: +117 -0
index.html
class.WINNT.inc.php
class.FreeBSD.inc.php lines: +89 -0
class.Darwin.inc.php lines: +227 -0
class.BSD.common.inc.php lines: +287 -0
class.SunOS.inc.php
Log Message:
sync with current stable from upstream - version 2.4.1, added some fixes and
improvements along the way
====================================================
Index: class.Linux.inc.php
<?php
// phpSysInfo - A PHP System Information Script
// http://phpsysinfo.sourceforge.net/
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
// $Id: class.Linux.inc.php,v 1.2 2005/11/19 05:29:55 skwashd Exp $
class sysinfo {
// get our apache SERVER_NAME or vhost
function vhostname () {
if (! ($result = getenv('SERVER_NAME'))) {
$result = 'N.A.';
}
return $result;
}
// get our canonical hostname
function chostname () {
if ($fp = fopen('/proc/sys/kernel/hostname', 'r')) {
$result = trim(fgets($fp, 4096));
fclose($fp);
$result = gethostbyaddr(gethostbyname($result));
} else {
$result = 'N.A.';
}
return $result;
}
// get the IP address of our canonical hostname
function ip_addr () {
if (!($result = getenv('SERVER_ADDR'))) {
$result = gethostbyname($this->chostname());
}
return $result;
}
function kernel () {
if ($fd = fopen('/proc/version', 'r')) {
$buf = fgets($fd, 4096);
fclose($fd);
if (preg_match('/version (.*?) /', $buf, $ar_buf)) {
$result = $ar_buf[1];
if (preg_match('/SMP/', $buf)) {
$result .= ' (SMP)';
}
} else {
$result = 'N.A.';
}
} else {
$result = 'N.A.';
}
return $result;
}
function uptime () {
$fd = fopen('/proc/uptime', 'r');
$ar_buf = split(' ', fgets($fd, 4096));
fclose($fd);
$result = trim($ar_buf[0]);
return $result;
}
function users () {
$who = split('=', execute_program('who', '-q'));
$result = $who[1];
return $result;
}
function loadavg () {
if ($fd = fopen('/proc/loadavg', 'r')) {
$results = split(' ', fgets($fd, 4096));
fclose($fd);
} else {
$results = array('N.A.', 'N.A.', 'N.A.');
}
return $results;
}
function cpu_info () {
$results = array();
$ar_buf = array();
if ($fd = fopen('/proc/cpuinfo', 'r')) {
while ($buf = fgets($fd, 4096)) {
list($key, $value) = preg_split('/\s+:\s+/', trim($buf), 2);
// All of the tags here are highly architecture dependant.
// the only way I could reconstruct them for machines I don't
// have is to browse the kernel source. So if your arch isn't
// supported, tell me you want it written in.
switch ($key) {
case 'model name':
$results['model'] = $value;
break;
case 'cpu MHz':
$results['cpuspeed'] = sprintf('%.2f', $value);
break;
case 'cycle frequency [Hz]': // For Alpha arch - 2.2.x
$results['cpuspeed'] = sprintf('%.2f', $value / 1000000);
break;
case 'clock': // For PPC arch (damn borked POS)
$results['cpuspeed'] = sprintf('%.2f', $value);
break;
case 'cpu': // For PPC arch (damn borked POS)
$results['model'] = $value;
break;
case 'L2 cache': // More for PPC
$results['cache'] = $value;
break;
case 'revision': // For PPC arch (damn borked POS)
$results['model'] .= ' ( rev: ' . $value . ')';
break;
case 'cpu model': // For Alpha arch - 2.2.x
$results['model'] .= ' (' . $value . ')';
break;
case 'cache size':
$results['cache'] = $value;
break;
case 'bogomips':
$results['bogomips'] += $value;
break;
case 'BogoMIPS': // For alpha arch - 2.2.x
$results['bogomips'] += $value;
break;
case 'BogoMips': // For sparc arch
$results['bogomips'] += $value;
break;
case 'cpus detected': // For Alpha arch - 2.2.x
$results['cpus'] += $value;
break;
case 'system type': // Alpha arch - 2.2.x
$results['model'] .= ', ' . $value . ' ';
break;
case 'platform string': // Alpha arch - 2.2.x
$results['model'] .= ' (' . $value . ')';
break;
case 'processor':
$results['cpus'] += 1;
break;
case 'Cpu0ClkTck': // Linux sparc64
$results['cpuspeed'] = sprintf('%.2f', hexdec($value) / 1000000);
break;
case 'Cpu0Bogo': // Linux sparc64 & sparc32
$results['bogomips'] = $value;
break;
case 'ncpus probed': // Linux sparc64 & sparc32
$results['cpus'] = $value;
break;
}
}
fclose($fd);
}
$keys = array_keys($results);
$keys2be = array('model', 'cpuspeed', 'cache', 'bogomips', 'cpus');
while ($ar_buf = each($keys2be)) {
if (! in_array($ar_buf[1], $keys)) {
$results[$ar_buf[1]] = 'N.A.';
}
}
return $results;
}
function pci () {
$results = array();
if ($_results = execute_program('lspci')) {
$lines = split("\n", $_results);
for ($i = 0, $max = sizeof($lines); $i < $max; $i++) {
list($addr, $name) = explode(' ', trim($lines[$i]), 2);
if (!preg_match('/bridge/i', $name) && !preg_match('/USB/i', $name)) {
// remove all the version strings
$name = preg_replace('/\(.*\)/', '', $name);
$results[] = $addr . ' ' . $name;
}
}
} elseif ($fd = fopen('/proc/pci', 'r')) {
while ($buf = fgets($fd, 4096)) {
if (preg_match('/Bus/', $buf)) {
$device = 1;
continue;
}
if ($device) {
list($key, $value) = split(': ', $buf, 2);
if (!preg_match('/bridge/i', $key) && !preg_match('/USB/i', $key)) {
$results[] = preg_replace('/\([^\)]+\)\.$/', '', trim($value));
}
$device = 0;
}
}
}
asort($results);
return $results;
}
function ide () {
$results = array();
$handle = opendir('/proc/ide');
while ($file = readdir($handle)) {
if (preg_match('/^hd/', $file)) {
$results[$file] = array();
// Check if device is CD-ROM (CD-ROM capacity shows as 1024 GB)
if ($fd = fopen("/proc/ide/$file/media", 'r')) {
$results[$file]['media'] = trim(fgets($fd, 4096));
if ($results[$file]['media'] == 'disk') {
$results[$file]['media'] = 'Hard Disk';
}
if ($results[$file]['media'] == 'cdrom') {
$results[$file]['media'] = 'CD-ROM';
}
fclose($fd);
}
if ($fd = fopen("/proc/ide/$file/model", 'r')) {
$results[$file]['model'] = trim(fgets($fd, 4096));
if (preg_match('/WDC/', $results[$file]['model'])) {
$results[$file]['manufacture'] = 'Western Digital';
} elseif (preg_match('/IBM/', $results[$file]['model'])) {
$results[$file]['manufacture'] = 'IBM';
} elseif (preg_match('/FUJITSU/', $results[$file]['model'])) {
$results[$file]['manufacture'] = 'Fujitsu';
} else {
$results[$file]['manufacture'] = 'Unknown';
}
fclose($fd);
}
if ($fd = fopen("/proc/ide/$file/capacity", 'r')) {
$results[$file]['capacity'] = trim(fgets($fd, 4096));
if ($results[$file]['media'] == 'CD-ROM') {
unset($results[$file]['capacity']);
}
fclose($fd);
}
}
}
closedir($handle);
asort($results);
return $results;
}
function scsi () {
$results = array();
$dev_vendor = '';
$dev_model = '';
$dev_rev = '';
$dev_type = '';
$s = 1;
if ($fd = fopen('/proc/scsi/scsi', 'r')) {
while ($buf = fgets($fd, 4096)) {
if (preg_match('/Vendor/', $buf)) {
preg_match('/Vendor: (.*) Model: (.*) Rev: (.*)/i', $buf, $dev);
list($key, $value) = split(': ', $buf, 2);
$dev_str = $value;
$get_type = 1;
continue;
}
if ($get_type) {
preg_match('/Type:\s+(\S+)/i', $buf, $dev_type);
$results[$s]['model'] = "$dev[1] $dev[2] ($dev_type[1])";
$results[$s]['media'] = "Hard Disk";
$s++;
$get_type = 0;
}
}
}
asort($results);
return $results;
}
function usb () {
$results = array();
$devstring = 0;
$devnum = -1;
if ($fd = fopen('/proc/bus/usb/devices', 'r')) {
while ($buf = fgets($fd, 4096)) {
if (preg_match('/^T/', $buf)) {
$devnum += 1;
}
if (preg_match('/^S/', $buf)) {
$devstring = 1;
}
if ($devstring) {
list($key, $value) = split(': ', $buf, 2);
list($key, $value2) = split('=', $value, 2);
$results[$devnum] .= " " . trim($value2);
$devstring = 0;
}
}
}
return $results;
}
function sbus () {
$results = array();
$_results[0] = "";
// TODO. Nothing here yet. Move along.
$results = $_results;
return $results;
}
function network () {
$results = array();
if ($fd = fopen('/proc/net/dev', 'r')) {
while ($buf = fgets($fd, 4096)) {
if (preg_match('/:/', $buf)) {
list($dev_name, $stats_list) = preg_split('/:/', $buf, 2);
$stats = preg_split('/\s+/', trim($stats_list));
$results[$dev_name] = array();
$results[$dev_name]['rx_bytes'] = $stats[0];
$results[$dev_name]['rx_packets'] = $stats[1];
$results[$dev_name]['rx_errs'] = $stats[2];
$results[$dev_name]['rx_drop'] = $stats[3];
$results[$dev_name]['tx_bytes'] = $stats[8];
$results[$dev_name]['tx_packets'] = $stats[9];
$results[$dev_name]['tx_errs'] = $stats[10];
$results[$dev_name]['tx_drop'] = $stats[11];
$results[$dev_name]['errs'] = $stats[2] + $stats[10];
$results[$dev_name]['drop'] = $stats[3] + $stats[11];
}
}
}
return $results;
}
function memory () {
if ($fd = fopen('/proc/meminfo', 'r')) {
$results['ram'] = array();
$results['swap'] = array();
$results['devswap'] = array();
while ($buf = fgets($fd, 4096)) {
if (preg_match('/^MemTotal:\s+(.*)\s*kB/i', $buf, $ar_buf)) {
$results['ram']['total'] = $ar_buf[1];
} else if (preg_match('/^MemFree:\s+(.*)\s*kB/i', $buf, $ar_buf)) {
$results['ram']['free'] = $ar_buf[1];
} else if (preg_match('/^Cached:\s+(.*)\s*kB/i', $buf, $ar_buf)) {
$results['ram']['cached'] = $ar_buf[1];
} else if (preg_match('/^Buffers:\s+(.*)\s*kB/i', $buf, $ar_buf)) {
$results['ram']['buffers'] = $ar_buf[1];
} else if (preg_match('/^SwapTotal:\s+(.*)\s*kB/i', $buf, $ar_buf)) {
$results['swap']['total'] = $ar_buf[1];
} else if (preg_match('/^SwapFree:\s+(.*)\s*kB/i', $buf, $ar_buf)) {
$results['swap']['free'] = $ar_buf[1];
}
}
$results['ram']['shared'] = 0;
$results['ram']['used'] = $results['ram']['total'] -
$results['ram']['free'];
$results['swap']['used'] = $results['swap']['total'] -
$results['swap']['free'];
fclose($fd);
$swaps = file ('/proc/swaps');
$swapdevs = split("\n", $swaps);
for ($i = 1; $i < (sizeof($swapdevs) - 1); $i++) {
$ar_buf = preg_split('/\s+/', $swapdevs[$i], 6);
$results['devswap'][$i - 1] = array();
$results['devswap'][$i - 1]['dev'] = $ar_buf[0];
$results['devswap'][$i - 1]['total'] = $ar_buf[2];
$results['devswap'][$i - 1]['used'] = $ar_buf[3];
$results['devswap'][$i - 1]['free'] = ($results['devswap'][$i -
1]['total'] - $results['devswap'][$i - 1]['used']);
$results['devswap'][$i - 1]['percent'] = round(($ar_buf[3] * 100) /
$ar_buf[2]);
}
// I don't like this since buffers and cache really aren't
// 'used' per say, but I get too many emails about it.
$results['ram']['t_used'] = $results['ram']['used'];
$results['ram']['t_free'] = $results['ram']['total'] -
$results['ram']['t_used'];
$results['ram']['percent'] = round(($results['ram']['t_used'] * 100) /
$results['ram']['total']);
$results['swap']['percent'] = round(($results['swap']['used'] * 100) /
$results['swap']['total']);
} else {
$results['ram'] = array();
$results['swap'] = array();
$results['devswap'] = array();
}
return $results;
}
function filesystems () {
$df = execute_program('df', '-kP');
$mounts = split("\n", $df);
$fstype = array();
if ($fd = fopen('/proc/mounts', 'r')) {
while ($buf = fgets($fd, 4096)) {
list($dev, $mpoint, $type) = preg_split('/\s+/', trim($buf), 4);
$fstype[$mpoint] = $type;
$fsdev[$dev] = $type;
}
fclose($fd);
}
for ($i = 1, $max = sizeof($mounts); $i < $max; $i++) {
$ar_buf = preg_split('/\s+/', $mounts[$i], 6);
$results[$i - 1] = array();
$results[$i - 1]['disk'] = $ar_buf[0];
$results[$i - 1]['size'] = $ar_buf[1];
$results[$i - 1]['used'] = $ar_buf[2];
$results[$i - 1]['free'] = $ar_buf[3];
$results[$i - 1]['percent'] = round(($results[$i - 1]['used'] * 100) /
$results[$i - 1]['size']) . '%';
$results[$i - 1]['mount'] = $ar_buf[5];
($fstype[$ar_buf[5]]) ? $results[$i - 1]['fstype'] = $fstype[$ar_buf[5]]
: $results[$i - 1]['fstype'] = $fsdev[$ar_buf[0]];
}
return $results;
}
function distro () {
if ($fd = fopen('/etc/debian_version', 'r')) {
$buf = fgets($fd, 1024);
fclose($fd);
$result = 'Debian ' . trim($buf);
} elseif ($fd = fopen('/etc/SuSE-release', 'r')) {
$buf = fgets($fd, 1024);
fclose($fd);
$result = trim($buf);
} elseif ($fd = fopen('/etc/mandrake-release', 'r')) {
$buf = fgets($fd, 1024);
fclose($fd);
$result = trim($buf);
} elseif ($fd = fopen('/etc/fedora-release', 'r')) {
$buf = fgets($fd, 1024);
fclose($fd);
$result = trim($buf);
} elseif ($fd = fopen('/etc/redhat-release', 'r')) {
$buf = fgets($fd, 1024);
fclose($fd);
$result = trim($buf);
} elseif ($fd = fopen('/etc/gentoo-release', 'r')) {
$buf = fgets($fd, 1024);
fclose($fd);
$result = trim($buf);
} elseif ($fd = fopen('/etc/slackware-version', 'r')) {
$buf = fgets($fd, 1024);
fclose($fd);
$result = trim($buf);
} elseif ($fd = fopen('/etc/eos-version', 'r')) {
$buf = fgets($fd, 1024);
fclose($fd);
$result = trim($buf);
} elseif ($fd = fopen('/etc/trustix-release', 'r')) {
$buf = fgets($fd, 1024);
fclose($fd);
$result = trim($buf);
} elseif ($fd = fopen('/etc/arch-release', 'r')) {
$buf = fgets($fd, 1024);
fclose($fd);
$result = trim($buf);
} elseif ($fd = fopen('/etc/cobalt-release', 'r')) {
$buf = fgets($fd, 1024);
fclose($fd);
$result = trim($buf);
} else {
$result = 'N.A.';
}
return $result;
}
function distroicon () {
if (file_exists('/etc/debian_version')) {
$result = 'Debian.gif';
} elseif (file_exists('/etc/SuSE-release')) {
$result = 'Suse.gif';
} elseif (file_exists('/etc/mandrake-release')) {
$result = 'Mandrake.gif';
} elseif (file_exists('/etc/fedora-release')) {
$result = 'Fedora.gif';
} elseif (file_exists('/etc/redhat-release')) {
$result = 'Redhat.gif';
} elseif (file_exists('/etc/gentoo-release')) {
$result = 'Gentoo.gif';
} elseif (file_exists('/etc/slackware-version')) {
$result = 'Slackware.gif';
} elseif (file_exists('/etc/eos-version')) {
$result = 'free-eos.gif';
} elseif (file_exists('/etc/trustix-release')) {
$result = 'Trustix.gif';
} elseif (file_exists('/etc/arch-release')) {
$result = 'Arch.gif';
} elseif (file_exists('/etc/cobalt-release')) {
$result = 'Cobalt.gif';
} else {
$result = 'xp.gif';
}
return $result;
}
}
?>
====================================================
Index: class.HP-UX.inc.php
<?php
// phpSysInfo - A PHP System Information Script
// http://phpsysinfo.sourceforge.net/
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
// $Id: class.HP-UX.inc.php,v 1.1 2005/11/19 05:29:55 skwashd Exp $
class sysinfo {
// get our apache SERVER_NAME or vhost
function vhostname () {
if (! ($result = getenv('SERVER_NAME'))) {
$result = 'N.A.';
}
return $result;
}
// get our canonical hostname
function chostname () {
return execute_program('hostname');
}
// get the IP address of our canonical hostname
function ip_addr () {
if (!($result = getenv('SERVER_ADDR'))) {
$result = gethostbyname($this->chostname());
}
return $result;
}
function kernel () {
return execute_program('uname', '-srvm');
}
function uptime () {
$result = 0;
$ar_buf = array();
$buf = execute_program('uptime');
if (preg_match("/up (\d+) days,\s*(\d+):(\d+),/", $buf, $ar_buf)) {
$min = $ar_buf[3];
$hours = $ar_buf[2];
$days = $ar_buf[1];
$result = $days * 86400 + $hours * 3600 + $min * 60;
}
return $result;
}
function users () {
$who = split('=', execute_program('who', '-q'));
$result = $who[1];
return $result;
}
function loadavg () {
$ar_buf = array();
$buf = execute_program('uptime');
if (preg_match("/average: (.*), (.*), (.*)$/", $buf, $ar_buf)) {
$results = array($ar_buf[1], $ar_buf[2], $ar_buf[3]);
} else {
$results = array('N.A.', 'N.A.', 'N.A.');
}
return $results;
}
function cpu_info () {
$results = array();
$ar_buf = array();
if ($fd = fopen('/proc/cpuinfo', 'r')) {
while ($buf = fgets($fd, 4096)) {
list($key, $value) = preg_split('/\s+:\s+/', trim($buf), 2);
// All of the tags here are highly architecture dependant.
// the only way I could reconstruct them for machines I don't
// have is to browse the kernel source. So if your arch isn't
// supported, tell me you want it written in.
switch ($key) {
case 'model name':
$results['model'] = $value;
break;
case 'cpu MHz':
$results['cpuspeed'] = sprintf('%.2f', $value);
break;
case 'cycle frequency [Hz]': // For Alpha arch - 2.2.x
$results['cpuspeed'] = sprintf('%.2f', $value / 1000000);
break;
case 'clock': // For PPC arch (damn borked POS)
$results['cpuspeed'] = sprintf('%.2f', $value);
break;
case 'cpu': // For PPC arch (damn borked POS)
$results['model'] = $value;
break;
case 'revision': // For PPC arch (damn borked POS)
$results['model'] .= ' ( rev: ' . $value . ')';
break;
case 'cpu model': // For Alpha arch - 2.2.x
$results['model'] .= ' (' . $value . ')';
break;
case 'cache size':
$results['cache'] = $value;
break;
case 'bogomips':
$results['bogomips'] += $value;
break;
case 'BogoMIPS': // For alpha arch - 2.2.x
$results['bogomips'] += $value;
break;
case 'BogoMips': // For sparc arch
$results['bogomips'] += $value;
break;
case 'cpus detected': // For Alpha arch - 2.2.x
$results['cpus'] += $value;
break;
case 'system type': // Alpha arch - 2.2.x
$results['model'] .= ', ' . $value . ' ';
break;
case 'platform string': // Alpha arch - 2.2.x
$results['model'] .= ' (' . $value . ')';
break;
case 'processor':
$results['cpus'] += 1;
break;
}
}
fclose($fd);
}
$keys = array_keys($results);
$keys2be = array('model', 'cpuspeed', 'cache', 'bogomips', 'cpus');
while ($ar_buf = each($keys2be)) {
if (! in_array($ar_buf[1], $keys)) {
$results[$ar_buf[1]] = 'N.A.';
}
}
return $results;
}
function pci () {
$results = array();
if ($fd = fopen('/proc/pci', 'r')) {
while ($buf = fgets($fd, 4096)) {
if (preg_match('/Bus/', $buf)) {
$device = 1;
continue;
}
if ($device) {
list($key, $value) = split(': ', $buf, 2);
if (!preg_match('/bridge/i', $key) && !preg_match('/USB/i', $key)) {
$results[] = preg_replace('/\([^\)]+\)\.$/', '', trim($value));
}
$device = 0;
}
}
}
asort($results);
return $results;
}
function ide () {
$results = array();
$handle = opendir('/proc/ide');
while ($file = readdir($handle)) {
if (preg_match('/^hd/', $file)) {
$results[$file] = array();
// Check if device is CD-ROM (CD-ROM capacity shows as 1024 GB)
if ($fd = fopen("/proc/ide/$file/media", 'r')) {
$results[$file]['media'] = trim(fgets($fd, 4096));
if ($results[$file]['media'] == 'disk') {
$results[$file]['media'] = 'Hard Disk';
}
if ($results[$file]['media'] == 'cdrom') {
$results[$file]['media'] = 'CD-ROM';
}
fclose($fd);
}
if ($fd = fopen("/proc/ide/$file/model", 'r')) {
$results[$file]['model'] = trim(fgets($fd, 4096));
if (preg_match('/WDC/', $results[$file]['model'])) {
$results[$file]['manufacture'] = 'Western Digital';
} elseif (preg_match('/IBM/', $results[$file]['model'])) {
$results[$file]['manufacture'] = 'IBM';
} elseif (preg_match('/FUJITSU/', $results[$file]['model'])) {
$results[$file]['manufacture'] = 'Fujitsu';
} else {
$results[$file]['manufacture'] = 'Unknown';
}
fclose($fd);
}
if ($fd = fopen("/proc/ide/$file/capacity", 'r')) {
$results[$file]['capacity'] = trim(fgets($fd, 4096));
if ($results[$file]['media'] == 'CD-ROM') {
unset($results[$file]['capacity']);
}
fclose($fd);
}
}
}
closedir($handle);
asort($results);
return $results;
}
function scsi () {
$results = array();
$dev_vendor = '';
$dev_model = '';
$dev_rev = '';
$dev_type = '';
$s = 1;
if ($fd = fopen('/proc/scsi/scsi', 'r')) {
while ($buf = fgets($fd, 4096)) {
if (preg_match('/Vendor/', $buf)) {
preg_match('/Vendor: (.*) Model: (.*) Rev: (.*)/i', $buf, $dev);
list($key, $value) = split(': ', $buf, 2);
$dev_str = $value;
$get_type = 1;
continue;
}
if ($get_type) {
preg_match('/Type:\s+(\S+)/i', $buf, $dev_type);
$results[$s]['model'] = "$dev[1] $dev[2] ($dev_type[1])";
$results[$s]['media'] = "Hard Disk";
$s++;
$get_type = 0;
}
}
}
asort($results);
return $results;
}
function usb () {
$results = array();
$devstring = 0;
$devnum = -1;
if ($fd = fopen('/proc/bus/usb/devices', 'r')) {
while ($buf = fgets($fd, 4096)) {
if (preg_match('/^T/', $buf)) {
$devnum += 1;
}
if (preg_match('/^S/', $buf)) {
$devstring = 1;
}
if ($devstring) {
list($key, $value) = split(': ', $buf, 2);
list($key, $value2) = split('=', $value, 2);
$results[$devnum] .= " " . trim($value2);
$devstring = 0;
}
}
}
return $results;
}
function sbus () {
$results = array();
$_results[0] = "";
// TODO. Nothing here yet. Move along.
$results = $_results;
return $results;
}
function network () {
$netstat = execute_program('netstat', '-ni | tail -n +2');
$lines = split("\n", $netstat);
$results = array();
for ($i = 0, $max = sizeof($lines); $i < $max; $i++) {
$ar_buf = preg_split("/\s+/", $lines[$i]);
if (!empty($ar_buf[0]) && !empty($ar_buf[3])) {
$results[$ar_buf[0]] = array();
$results[$ar_buf[0]]['rx_bytes'] = $ar_buf[4];
$results[$ar_buf[0]]['rx_packets'] = $ar_buf[4];
$results[$ar_buf[0]]['rx_errs'] = $ar_buf[5];
$results[$ar_buf[0]]['rx_drop'] = $ar_buf[8];
$results[$ar_buf[0]]['tx_bytes'] = $ar_buf[6];
$results[$ar_buf[0]]['tx_packets'] = $ar_buf[6];
$results[$ar_buf[0]]['tx_errs'] = $ar_buf[7];
$results[$ar_buf[0]]['tx_drop'] = $ar_buf[8];
$results[$ar_buf[0]]['errs'] = $ar_buf[5] + $ar_buf[7];
$results[$ar_buf[0]]['drop'] = $ar_buf[8];
}
}
return $results;
}
function memory () {
if ($fd = fopen('/proc/meminfo', 'r')) {
while ($buf = fgets($fd, 4096)) {
if (preg_match('/Mem:\s+(.*)$/', $buf, $ar_buf)) {
$ar_buf = preg_split('/\s+/', $ar_buf[1], 6);
$results['ram'] = array();
$results['ram']['total'] = $ar_buf[0] / 1024;
$results['ram']['used'] = $ar_buf[1] / 1024;
$results['ram']['free'] = $ar_buf[2] / 1024;
$results['ram']['shared'] = $ar_buf[3] / 1024;
$results['ram']['buffers'] = $ar_buf[4] / 1024;
$results['ram']['cached'] = $ar_buf[5] / 1024;
// I don't like this since buffers and cache really aren't
// 'used' per say, but I get too many emails about it.
$results['ram']['t_used'] = $results['ram']['used'];
$results['ram']['t_free'] = $results['ram']['total'] -
$results['ram']['t_used'];
$results['ram']['percent'] = round(($results['ram']['t_used'] * 100)
/ $results['ram']['total']);
}
if (preg_match('/Swap:\s+(.*)$/', $buf, $ar_buf)) {
$ar_buf = preg_split('/\s+/', $ar_buf[1], 3);
$results['swap'] = array();
$results['swap']['total'] = $ar_buf[0] / 1024;
$results['swap']['used'] = $ar_buf[1] / 1024;
$results['swap']['free'] = $ar_buf[2] / 1024;
$results['swap']['percent'] = round(($ar_buf[1] * 100) / $ar_buf[0]);
// Get info on individual swap files
$swaps = file ('/proc/swaps');
$swapdevs = split("\n", $swaps);
for ($i = 1, $max = (sizeof($swapdevs) - 1); $i < $max; $i++) {
$ar_buf = preg_split('/\s+/', $swapdevs[$i], 6);
$results['devswap'][$i - 1] = array();
$results['devswap'][$i - 1]['dev'] = $ar_buf[0];
$results['devswap'][$i - 1]['total'] = $ar_buf[2];
$results['devswap'][$i - 1]['used'] = $ar_buf[3];
$results['devswap'][$i - 1]['free'] = ($results['devswap'][$i -
1]['total'] - $results['devswap'][$i - 1]['used']);
$results['devswap'][$i - 1]['percent'] = round(($ar_buf[3] * 100) /
$ar_buf[2]);
}
break;
}
}
fclose($fd);
} else {
$results['ram'] = array();
$results['swap'] = array();
$results['devswap'] = array();
}
return $results;
}
function filesystems () {
$df = execute_program('df', '-kP');
$mounts = split("\n", $df);
$fstype = array();
$s = execute_program('mount', '-v');
$lines = explode("\n", $s);
$i = 0;
while (list(, $line) = each($lines)) {
$a = split(' ', $line);
$fsdev[$a[0]] = $a[4];
}
for ($i = 1, $j = 0, $max = sizeof($mounts); $i < $max; $i++) {
$ar_buf = preg_split("/\s+/", $mounts[$i], 6);
$results[$j] = array();
$results[$j]['disk'] = $ar_buf[0];
$results[$j]['size'] = $ar_buf[1];
$results[$j]['used'] = $ar_buf[2];
$results[$j]['free'] = $ar_buf[3];
$results[$j]['percent'] = $ar_buf[4];
$results[$j]['mount'] = $ar_buf[5];
($fstype[$ar_buf[5]]) ? $results[$j]['fstype'] = $fstype[$ar_buf[5]] :
$results[$j]['fstype'] = $fsdev[$ar_buf[0]];
$j++;
}
return $results;
}
function distro () {
$result = 'HP-UX';
return($result);
}
function distroicon () {
$result = 'xp.gif';
return($result);
}
}
?>
====================================================
Index: class.NetBSD.inc.php
<?php
// phpSysInfo - A PHP System Information Script
// http://phpsysinfo.sourceforge.net/
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
// $Id: class.NetBSD.inc.php,v 1.2 2005/11/19 05:29:55 skwashd Exp $
require('./includes/os/class.BSD.common.inc.php');
class sysinfo extends bsd_common {
var $cpu_regexp;
var $scsi_regexp;
// Our contstructor
// this function is run on the initialization of this class
function sysinfo () {
$this->cpu_regexp = "^cpu(.*)\, (.*) MHz";
$this->scsi_regexp1 = "^(.*) at scsibus.*: <(.*)> .*";
$this->scsi_regexp2 = "^(da[0-9]): (.*)MB ";
}
function get_sys_ticks () {
$a = $this->grab_key('kern.boottime');
$sys_ticks = time() - $a;
return $sys_ticks;
}
// get the pci device information out of dmesg
function pci () {
$results = array();
for ($i = 0, $max = count($this->read_dmesg()); $i < $max; $i++) {
$buf = $this->dmesg[$i];
if (preg_match('/(.*) at pci[0-9] dev [0-9]* function [0-9]*: (.*)$/',
$buf, $ar_buf)) {
$results[$i] = $ar_buf[1] . ": " . $ar_buf[2];
} elseif (preg_match('/"(.*)" (.*).* at [.0-9]+ irq/', $buf, $ar_buf)) {
$results[$i] = $ar_buf[1] . ": " . $ar_buf[2];
}
}
asort($results);
return $results;
}
function network () {
$netstat_b = execute_program('netstat', '-nbdi | cut -c1-25,44- | grep
"^[a-z]*[0-9][ \t].*Link"');
$netstat_n = execute_program('netstat', '-ndi | cut -c1-25,44- | grep
"^[a-z]*[0-9][ \t].*Link"');
$lines_b = split("\n", $netstat_b);
$lines_n = split("\n", $netstat_n);
$results = array();
for ($i = 0, $max = sizeof($lines_b); $i < $max; $i++) {
$ar_buf_b = preg_split("/\s+/", $lines_b[$i]);
$ar_buf_n = preg_split("/\s+/", $lines_n[$i]);
if (!empty($ar_buf_b[0]) && !empty($ar_buf_n[3])) {
$results[$ar_buf_b[0]] = array();
$results[$ar_buf_b[0]]['rx_bytes'] = $ar_buf_b[3];
$results[$ar_buf_b[0]]['rx_packets'] = $ar_buf_n[3];
$results[$ar_buf_b[0]]['rx_errs'] = $ar_buf_n[4];
$results[$ar_buf_b[0]]['rx_drop'] = $ar_buf_n[8];
$results[$ar_buf_b[0]]['tx_bytes'] = $ar_buf_b[4];
$results[$ar_buf_b[0]]['tx_packets'] = $ar_buf_n[5];
$results[$ar_buf_b[0]]['tx_errs'] = $ar_buf_n[6];
$results[$ar_buf_b[0]]['tx_drop'] = $ar_buf_n[8];
$results[$ar_buf_b[0]]['errs'] = $ar_buf_n[4] + $ar_buf_n[6];
$results[$ar_buf_b[0]]['drop'] = $ar_buf_n[8];
}
}
return $results;
}
function memory () {
$s = $this->grab_key('hw.physmem');
$pagesize = $this->grab_key('hw.pagesize');
$results['ram'] = array();
$pstat = execute_program('vmstat', '-s');
$lines = split("\n", $pstat);
for ($i = 0, $max = sizeof($lines); $i < $max; $i++) {
$ar_buf = preg_split("/\s+/", $lines[$i], 19);
if ($i == 3) {
$results['ram']['free'] = $ar_buf[1] * $pagesize / 1024;
} elseif ($i == 19) {
$results['swap']['total'] = $ar_buf[1] * $pagesize / 1024;
} elseif ($i == 20) {
$results['swap']['used'] = $ar_buf[1] * $pagesize / 1024;
}
}
$results['ram']['total'] = $s / 1024;
$results['ram']['shared'] = 0;
$results['ram']['buffers'] = 0;
$results['ram']['used'] = $results['ram']['total'] -
$results['ram']['free'];
$results['ram']['cached'] = 0;
$results['ram']['t_used'] = $results['ram']['used'];
$results['ram']['t_free'] = $results['ram']['free'];
$results['ram']['percent'] = round(($results['ram']['used'] * 100) /
$results['ram']['total']);
$results['swap']['free'] = $results['swap']['total'] -
$results['swap']['used'];
$results['swap']['percent'] = round(($results['swap']['used'] * 100) /
$results['swap']['total']);
return $results;
}
// get the ide device information out of dmesg
function ide () {
$results = array();
$s = 0;
for ($i = 0, $max = count($this->read_dmesg()); $i < $max; $i++) {
$buf = $this->dmesg[$i];
if (preg_match('/^(.*) at (pciide|wdc)[0-9] (.*): <(.*)>/', $buf,
$ar_buf)) {
$s = $ar_buf[1];
$results[$s]['model'] = $ar_buf[4];
$results[$s]['media'] = 'Hard Disk';
// now loop again and find the capacity
for ($j = 0, $max1 = count($this->read_dmesg()); $j < $max1; $j++) {
$buf_n = $this->dmesg[$j];
if (preg_match("/^($s): (.*), (.*), (.*)MB, .*$/", $buf_n,
$ar_buf_n)) {
$results[$s]['capacity'] = $ar_buf_n[4] * 2048 * 1.049;;
}
}
}
}
asort($results);
return $results;
}
function distroicon () {
$result = 'NetBSD.gif';
return($result);
}
}
?>
====================================================
Index: class.OpenBSD.inc.php
<?php
// phpSysInfo - A PHP System Information Script
// http://phpsysinfo.sourceforge.net/
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
// $Id: class.OpenBSD.inc.php,v 1.2 2005/11/19 05:29:55 skwashd Exp $
require('./includes/os/class.BSD.common.inc.php');
class sysinfo extends bsd_common {
var $cpu_regexp;
var $scsi_regexp;
// Our contstructor
// this function is run on the initialization of this class
function sysinfo () {
$this->cpu_regexp = "^cpu(.*) (.*) MHz";
$this->scsi_regexp1 = "^(.*) at scsibus.*: <(.*)> .*";
$this->scsi_regexp2 = "^(da[0-9]): (.*)MB ";
}
function get_sys_ticks () {
$a = $this->grab_key('kern.boottime');
$sys_ticks = time() - $a;
return $sys_ticks;
}
// get the pci device information out of dmesg
function pci () {
$results = array();
for ($i = 0, $s = 0, $max = count($this->read_dmesg()); $i < $max; $i++) {
$buf = $this->dmesg[$i];
if (preg_match('/(.*) at pci[0-9] .* "(.*)"/', $buf, $ar_buf)) {
$results[$s++] = $ar_buf[1] . ": " . $ar_buf[2];
} elseif (preg_match('/"(.*)" (.*).* at [.0-9]+ irq/', $buf, $ar_buf)) {
$results[$s++] = $ar_buf[1] . ": " . $ar_buf[2];
}
}
$results = array_unique($results);
asort($results);
return $results;
}
function network () {
$netstat_b = execute_program('netstat', '-nbdi | cut -c1-25,44- | grep Link
| grep -v \'* \'');
$netstat_n = execute_program('netstat', '-ndi | cut -c1-25,44- | grep Link
| grep -v \'* \'');
$lines_b = split("\n", $netstat_b);
$lines_n = split("\n", $netstat_n);
$results = array();
for ($i = 0, $max = sizeof($lines_b); $i < $max; $i++) {
$ar_buf_b = preg_split("/\s+/", $lines_b[$i]);
$ar_buf_n = preg_split("/\s+/", $lines_n[$i]);
if (!empty($ar_buf_b[0]) && !empty($ar_buf_n[3])) {
$results[$ar_buf_b[0]] = array();
$results[$ar_buf_b[0]]['rx_bytes'] = $ar_buf_b[3];
$results[$ar_buf_b[0]]['rx_packets'] = $ar_buf_n[3];
$results[$ar_buf_b[0]]['rx_errs'] = $ar_buf_n[4];
$results[$ar_buf_b[0]]['rx_drop'] = $ar_buf_n[8];
$results[$ar_buf_b[0]]['tx_bytes'] = $ar_buf_b[4];
$results[$ar_buf_b[0]]['tx_packets'] = $ar_buf_n[5];
$results[$ar_buf_b[0]]['tx_errs'] = $ar_buf_n[6];
$results[$ar_buf_b[0]]['tx_drop'] = $ar_buf_n[8];
$results[$ar_buf_b[0]]['errs'] = $ar_buf_n[4] + $ar_buf_n[6];
$results[$ar_buf_b[0]]['drop'] = $ar_buf_n[8];
}
}
return $results;
}
// get the ide device information out of dmesg
function ide () {
$results = array();
$s = 0;
for ($i = 0, $max = count($this->read_dmesg()); $i < $max; $i++) {
$buf = $this->dmesg[$i];
if (preg_match('/^(.*) at pciide[0-9] (.*): <(.*)>/', $buf, $ar_buf)) {
$s = $ar_buf[1];
$results[$s]['model'] = $ar_buf[3];
$results[$s]['media'] = 'Hard Disk';
// now loop again and find the capacity
for ($j = 0, $max1 = count($this->read_dmesg()); $j < $max1; $j++) {
$buf_n = $this->dmesg[$j];
if (preg_match("/^($s): (.*), (.*), (.*)MB, .*$/", $buf_n,
$ar_buf_n)) {
$results[$s]['capacity'] = $ar_buf_n[4] * 2048 * 1.049;;
}
}
}
}
asort($results);
return $results;
}
function distroicon () {
$result = 'OpenBSD.gif';
return($result);
}
}
?>
====================================================
Index: index.html
====================================================
Index: class.WINNT.inc.php
<?php
// phpSysInfo - A PHP System Information Script
// http://phpsysinfo.sourceforge.net/
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
// WINNT implementation written by Carl C. Longnecker, address@hidden
// $Id: class.WINNT.inc.php,v 1.1 2005/11/19 05:29:55 skwashd Exp $
class sysinfo {
// winnt needs some special prep
// $wmi holds the COM object that we pull all the WMI data from
var $wmi;
// this constructor initialis the $wmi object
function sysinfo ()
{
$this->wmi = new COM("WinMgmts:\\\\.");
}
// get our apache SERVER_NAME or vhost
function vhostname ()
{
if (! ($result = getenv('SERVER_NAME'))) {
$result = 'N.A.';
}
return $result;
}
// get our canonical hostname
function chostname ()
{
if (! ($result = getenv('SERVER_NAME'))) {
$result = 'N.A.';
}
return $result;
}
// get the IP address of our canonical hostname
function ip_addr ()
{
if (!($result = getenv('SERVER_ADDR'))) {
$result = 'N.A.';
}
return $result;
}
function kernel ()
{
$objInstance = $this->wmi->InstancesOf("Win32_OperatingSystem");
foreach ($objInstance as $obj) {
$result = $obj->Version;
if ($obj->ServicePackMajorVersion > 0) {
$result .= ' SP' . $obj->ServicePackMajorVersion;
}
}
return $result;
}
function uptime ()
{
$objInstance = $this->wmi->InstancesOf("Win32_OperatingSystem");
foreach ($objInstance as $obj) {
$result = 0;
$year = intval(substr($obj->LastBootUpTime, 0, 4));
$month = intval(substr($obj->LastBootUpTime, 4, 2));
$day = intval(substr($obj->LastBootUpTime, 6, 2));
$hour = intval(substr($obj->LastBootUpTime, 8, 2));
$minute = intval(substr($obj->LastBootUpTime, 10, 2));
$seconds = intval(substr($obj->LastBootUpTime, 12, 2));
$boottime = mktime($hour, $minute, $seconds, $month, $day, $year);
$diff_seconds = mktime() - $boottime;
$result = $diff_seconds;
}
return $result;
}
function users ()
{
$objInstance =
$this->wmi->InstancesOf("Win32_PerfRawData_TermService_TerminalServices");
foreach ($objInstance as $obj) {
return $obj->TotalSessions;
}
}
function loadavg ()
{
$objInstance = $this->wmi->InstancesOf("Win32_Processor");
$cpuload = array();
foreach ($objInstance as $obj) {
$cpuload[] = $obj->LoadPercentage;
}
// while
return $cpuload;
}
function cpu_info ()
{
$objInstance = $this->wmi->InstancesOf("Win32_Processor");
foreach ($objInstance as $obj) {
// still need bogomips (wtf are bogomips?)
$results['cpus'] = getenv('NUMBER_OF_PROCESSORS');
$results['model'] = $obj->Name;
$results['cache'] = $obj->L2CacheSize;
$results['mhz'] = $obj->CurrentClockSpeed . "/" . $obj->ExtClock;
}
return $results;
}
function pci ()
{
$objInstance = $this->wmi->InstancesOf("Win32_PnPEntity");
$pci = array();
foreach ($objInstance as $obj) {
if (substr($obj->PNPDeviceID, 0, 4) == "PCI\\") {
$pci[] = $obj->Name;
}
} // while
return $pci;
}
function ide ()
{
$objInstance = $this->wmi->InstancesOf("Win32_PnPEntity");
$ide = array();
foreach ($objInstance as $obj) {
if (substr($obj->PNPDeviceID, 0, 4) == "IDE\\") {
$ide[]['model'] = $obj->Name;
}
} // while
return $ide;
}
function scsi ()
{
$objInstance = $this->wmi->InstancesOf("Win32_PnPEntity");
$scsi = array();
foreach ($objInstance as $obj) {
if (substr($obj->PNPDeviceID, 0, 5) == "SCSI\\") {
$scsi[] = $obj->Name;
}
} // while
return $scsi;
}
function usb ()
{
$objInstance = $this->wmi->InstancesOf("Win32_PnPEntity");
$usb = array();
foreach ($objInstance as $obj) {
if (substr($obj->PNPDeviceID, 0, 4) == "USB\\") {
$usb[] = $obj->Name;
}
} // while
return $usb;
}
function sbus ()
{
$objInstance = $this->wmi->InstancesOf("Win32_PnPEntity");
$sbus = array();
foreach ($objInstance as $obj) {
if (substr($obj->PNPDeviceID, 0, 5) == "SBUS\\") {
$sbus[] = $obj->Name;
}
} // while
return $sbus;
}
function network ()
{
/**
* need this for documentation in case i find some better net stats
* $results[$dev_name]['rx_bytes'] = $stats[0];
* $results[$dev_name]['rx_packets'] = $stats[1];
* $results[$dev_name]['rx_errs'] = $stats[2];
* $results[$dev_name]['rx_drop'] = $stats[3];
*
* $results[$dev_name]['tx_bytes'] = $stats[8];
* $results[$dev_name]['tx_packets'] = $stats[9];
* $results[$dev_name]['tx_errs'] = $stats[10];
* $results[$dev_name]['tx_drop'] = $stats[11];
*
* $results[$dev_name]['errs'] = $stats[2] + $stats[10];
* $results[$dev_name]['drop'] = $stats[3] + $stats[11];
*/
$objInstance =
$this->wmi->InstancesOf("Win32_PerfRawData_Tcpip_NetworkInterface");
$results = array();
foreach ($objInstance as $obj) {
$results[$obj->Name]['errs'] = $obj->PacketsReceivedErrors;
$results[$obj->Name]['drop'] = $obj->PacketsReceivedDiscarded;
} // while
return $results;
}
function memory ()
{
$objInstance = $this->wmi->InstancesOf("Win32_LogicalMemoryConfiguration");
foreach ($objInstance as $obj) {
$results['ram']['total'] = $obj->TotalPhysicalMemory;
}
$objInstance = $this->wmi->InstancesOf("Win32_PerfRawData_PerfOS_Memory");
foreach ($objInstance as $obj) {
$results['ram']['free'] = $obj->AvailableKBytes;
}
$results['ram']['used'] = $results['ram']['total'] -
$results['ram']['free'];
$results['ram']['t_used'] = $results['ram']['used'];
$results['ram']['t_free'] = $results['ram']['total'] -
$results['ram']['t_used'];
$results['ram']['percent'] = round(($results['ram']['t_used'] * 100) /
$results['ram']['total']);
$results['swap']['total'] = 0;
$results['swap']['used'] = 0;
$results['swap']['free'] = 0;
$objInstance = $this->wmi->InstancesOf("Win32_PageFileUsage");
$k = 0;
foreach ($objInstance as $obj) {
$results['devswap'][$k]['dev'] = $obj->Name;
$results['devswap'][$k]['total'] = $obj->AllocatedBaseSize * 1024;
$results['devswap'][$k]['used'] = $obj->CurrentUsage * 1024;
$results['devswap'][$k]['free'] = ($obj->AllocatedBaseSize -
$obj->CurrentUsage) * 1024;
$results['devswap'][$k]['percent'] = $obj->CurrentUsage /
$obj->AllocatedBaseSize;
$results['swap']['total'] += $results['devswap'][$k]['total'];
$results['swap']['used'] += $results['devswap'][$k]['used'];
$results['swap']['free'] += $results['devswap'][$k]['free'];
$k += 1;
}
$results['swap']['percent'] = round($results['swap']['used'] /
$results['swap']['total'] * 100);
return $results;
}
function filesystems ()
{
$objInstance = $this->wmi->InstancesOf("Win32_LogicalDisk");
$k = 0;
foreach ($objInstance as $obj) {
$results[$k]['mount'] = $obj->Name;
$results[$k]['size'] = $obj->Size / 1024;
$results[$k]['used'] = ($obj->Size - $obj->FreeSpace) / 1024;
$results[$k]['free'] = $obj->FreeSpace / 1024;
$results[$k]['percent'] = round($results[$k]['used'] /
$results[$k]['size'] * 100);
$results[$k]['fstype'] = $obj->FileSystem;
$typearray = array("Unknown", "No Root Directory", "Removeable Disk",
"Local Disk", "Network Drive", "Compact Disc", "RAM Disk");
$floppyarray = array("Unknown", "5 1/4 in.", "3 1/2 in.", "3 1/2 in.",
"3 1/2 in.", "3 1/2 in.", "5 1/4 in.", "5 1/4 in.", "5 1/4 in.",
"5 1/4 in.", "5 1/4 in.", "Other", "HD", "3 1/2 in.", "3 1/2 in.",
"5 1/4 in.", "5 1/4 in.", "3 1/2 in.", "3 1/2 in.", "5 1/4 in.",
"3 1/2 in.", "3 1/2 in.", "8 in.");
$results[$k]['disk'] = $typearray[$obj->DriveType];
if ($obj->DriveType == 2) $results[$k]['disk'] .= " (" .
$floppyarray[$obj->MediaType] . ")";
$k += 1;
}
return $results;
}
function distro ()
{
$objInstance = $this->wmi->InstancesOf("Win32_OperatingSystem");
foreach ($objInstance as $obj) {
return $obj->Caption;
}
}
function distroicon ()
{
return 'xp.gif';
}
}
?>
====================================================
Index: class.FreeBSD.inc.php
<?php
// phpSysInfo - A PHP System Information Script
// http://phpsysinfo.sourceforge.net/
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
// $Id: class.FreeBSD.inc.php,v 1.2 2005/11/19 05:29:55 skwashd Exp $
require('./includes/os/class.BSD.common.inc.php');
class sysinfo extends bsd_common {
var $cpu_regexp;
var $scsi_regexp;
// Our contstructor
// this function is run on the initialization of this class
function sysinfo () {
$this->cpu_regexp = "CPU: (.*) \((.*)-MHz (.*)\)";
$this->scsi_regexp1 = "^(.*): <(.*)> .*SCSI.*device";
$this->scsi_regexp2 = "^(da[0-9]): (.*)MB ";
}
function get_sys_ticks () {
$s = explode(' ', $this->grab_key('kern.boottime'));
$a = ereg_replace('{ ', '', $s[3]);
$sys_ticks = time() - $a;
return $sys_ticks;
}
function network () {
$netstat = execute_program('netstat', '-nibd | grep Link');
$lines = split("\n", $netstat);
$results = array();
for ($i = 0, $max = sizeof($lines); $i < $max; $i++) {
$ar_buf = preg_split("/\s+/", $lines[$i]);
if (!empty($ar_buf[0])) {
$results[$ar_buf[0]] = array();
if (strlen($ar_buf[3]) < 15) {
$results[$ar_buf[0]]['rx_bytes'] = $ar_buf[5];
$results[$ar_buf[0]]['rx_packets'] = $ar_buf[3];
$results[$ar_buf[0]]['rx_errs'] = $ar_buf[4];
$results[$ar_buf[0]]['rx_drop'] = $ar_buf[10];
$results[$ar_buf[0]]['tx_bytes'] = $ar_buf[8];
$results[$ar_buf[0]]['tx_packets'] = $ar_buf[6];
$results[$ar_buf[0]]['tx_errs'] = $ar_buf[7];
$results[$ar_buf[0]]['tx_drop'] = $ar_buf[10];
$results[$ar_buf[0]]['errs'] = $ar_buf[4] + $ar_buf[7];
$results[$ar_buf[0]]['drop'] = $ar_buf[10];
} else {
$results[$ar_buf[0]]['rx_bytes'] = $ar_buf[6];
$results[$ar_buf[0]]['rx_packets'] = $ar_buf[4];
$results[$ar_buf[0]]['rx_errs'] = $ar_buf[5];
$results[$ar_buf[0]]['rx_drop'] = $ar_buf[11];
$results[$ar_buf[0]]['tx_bytes'] = $ar_buf[9];
$results[$ar_buf[0]]['tx_packets'] = $ar_buf[7];
$results[$ar_buf[0]]['tx_errs'] = $ar_buf[8];
$results[$ar_buf[0]]['tx_drop'] = $ar_buf[11];
$results[$ar_buf[0]]['errs'] = $ar_buf[5] + $ar_buf[8];
$results[$ar_buf[0]]['drop'] = $ar_buf[11];
}
}
}
return $results;
}
function distroicon () {
$result = 'FreeBSD.gif';
return($result);
}
}
?>
====================================================
Index: class.Darwin.inc.php
<?php
// phpSysInfo - A PHP System Information Script
// http://phpsysinfo.sourceforge.net/
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
// $Id: class.Darwin.inc.php,v 1.2 2005/11/19 05:29:55 skwashd Exp $
require('./includes/os/class.BSD.common.inc.php');
echo "<p align=center><b>Note: The Darwin version of phpSysInfo is work in
progress, some things currently don't work</b></p>";
class sysinfo extends bsd_common {
var $cpu_regexp;
var $scsi_regexp;
// Our contstructor
// this function is run on the initialization of this class
function sysinfo () {
// $this->cpu_regexp = "CPU: (.*) \((.*)-MHz (.*)\)";
// $this->scsi_regexp1 = "^(.*): <(.*)> .*SCSI.*device";
}
function grab_key ($key) {
$s = execute_program('sysctl', $key);
$s = ereg_replace($key . ': ', '', $s);
$s = ereg_replace($key . ' = ', '', $s); // fix Apple set keys
return $s;
}
function grab_ioreg ($key) {
$s = execute_program('ioreg', '-cls "' . $key . '" | grep "' . $key . '"');
//ioreg -cls "$key" | grep "$key"
$s = ereg_replace('\|', '', $s);
$s = ereg_replace('\+\-\o', '', $s);
$s = ereg_replace('[ ]+', '', $s);
$s = ereg_replace('<[^>]+>', '', $s); // remove possible XML conflicts
return $s;
}
function get_sys_ticks () {
$a = execute_program('sysctl', '-n kern.boottime'); // get boottime (value
in seconds)
$sys_ticks = time() - $a;
return $sys_ticks;
}
function cpu_info () {
$results = array();
// $results['model'] = $this->grab_key('hw.model'); // need to expand this
somehow...
// $results['model'] = $this->grab_key('hw.machine');
$results['model'] = ereg_replace('Processor type: ', '',
execute_program('hostinfo', '| grep "Processor type"')); // get processor type
$results['cpus'] = $this->grab_key('hw.ncpu');
$results['cpuspeed'] = round($this->grab_key('hw.cpufrequency') / 1000000);
// return cpu speed - Mhz
$results['busspeed'] = round($this->grab_key('hw.busfrequency') / 1000000);
// return bus speed - Mhz
$results['cache'] = round($this->grab_key('hw.l2cachesize') / 1024); //
return l2 cache
return $results;
}
// get the pci device information out of ioreg
function pci () {
$results = array();
$s = $this->grab_ioreg('IOPCIDevice');
$lines = split("\n", $s);
for ($i = 0, $max = sizeof($lines); $i < $max; $i++) {
$ar_buf = preg_split("/\s+/", $lines[$i], 19);
$results[$i] = $ar_buf[0];
}
asort($results);
return array_values(array_unique($results));
}
// get the ide device information out of ioreg
function ide () {
$results = array();
// ioreg | grep "Media <class IOMedia>"
$s = $this->grab_ioreg('IOATABlockStorageDevice');
$lines = split("\n", $s);
$j = 0;
for ($i = 0, $max = sizeof($lines); $i < $max; $i++) {
$ar_buf = preg_split("/\/\//", $lines[$i], 19);
if ($ar_buf[1] == 'class IOMedia' && preg_match('/Media/', $ar_buf[0])) {
$results[$j++]['model'] = $ar_buf[0];
}
}
asort($results);
return array_values(array_unique($results));
}
function memory () {
$s = $this->grab_key('hw.physmem');
$results['ram'] = array();
$pstat = execute_program('vm_stat'); // use darwin's vm_stat
$lines = split("\n", $pstat);
for ($i = 0, $max = sizeof($lines); $i < $max; $i++) {
$ar_buf = preg_split("/\s+/", $lines[$i], 19);
if ($i == 1) {
$results['ram']['free'] = $ar_buf[2] * 4; // calculate free memory from
page sizes (each page = 4MB)
}
}
$results['ram']['total'] = $s / 1024;
$results['ram']['shared'] = 0;
$results['ram']['buffers'] = 0;
$results['ram']['used'] = $results['ram']['total'] -
$results['ram']['free'];
$results['ram']['cached'] = 0;
$results['ram']['t_used'] = $results['ram']['used'];
$results['ram']['t_free'] = $results['ram']['free'];
$results['ram']['percent'] = round(($results['ram']['used'] * 100) /
$results['ram']['total']);
// need to fix the swap info...
$pstat = execute_program('swapinfo', '-k');
$lines = split("\n", $pstat);
for ($i = 0, $max = sizeof($lines); $i < $max; $i++) {
$ar_buf = preg_split("/\s+/", $lines[$i], 6);
if ($i == 0) {
$results['swap']['total'] = 0;
$results['swap']['used'] = 0;
$results['swap']['free'] = 0;
} else {
$results['swap']['total'] = $results['swap']['total'] + $ar_buf[1];
$results['swap']['used'] = $results['swap']['used'] + $ar_buf[2];
$results['swap']['free'] = $results['swap']['free'] + $ar_buf[3];
}
}
$results['swap']['percent'] = round(($results['swap']['used'] * 100) /
$results['swap']['total']);
return $results;
}
function network () {
$netstat = execute_program('netstat', '-nbdi | cut -c1-24,42- | grep Link');
$lines = split("\n", $netstat);
$results = array();
for ($i = 0, $max = sizeof($lines); $i < $max; $i++) {
$ar_buf = preg_split("/\s+/", $lines[$i]);
if (!empty($ar_buf[0])) {
$results[$ar_buf[0]] = array();
$results[$ar_buf[0]]['rx_bytes'] = $ar_buf[5];
$results[$ar_buf[0]]['rx_packets'] = $ar_buf[3];
$results[$ar_buf[0]]['rx_errs'] = $ar_buf[4];
$results[$ar_buf[0]]['rx_drop'] = $ar_buf[10];
$results[$ar_buf[0]]['tx_bytes'] = $ar_buf[8];
$results[$ar_buf[0]]['tx_packets'] = $ar_buf[6];
$results[$ar_buf[0]]['tx_errs'] = $ar_buf[7];
$results[$ar_buf[0]]['tx_drop'] = $ar_buf[10];
$results[$ar_buf[0]]['errs'] = $ar_buf[4] + $ar_buf[7];
$results[$ar_buf[0]]['drop'] = $ar_buf[10];
}
}
return $results;
}
function filesystems () {
$df = execute_program('df', '-k');
$mounts = split("\n", $df);
$fstype = array();
$s = execute_program('mount');
$lines = explode("\n", $s);
$i = 0;
while (list(, $line) = each($lines)) {
ereg('(.*) \((.*)\)', $line, $a);
$m = explode(' ', $a[0]);
$fsdev[$m[0]] = $a[2];
}
for ($i = 1, $j = 0, $max = sizeof($mounts); $i < $max; $i++) {
$ar_buf = preg_split("/\s+/", $mounts[$i], 6);
switch ($ar_buf[0]) {
case 'automount': // skip the automount entries
case 'devfs': // skip the dev filesystem
case 'fdesc': // skip the fdesc
case 'procfs': // skip the proc filesystem
case '<volfs>': // skip the vol filesystem
continue 2;
break;
}
$results[$j] = array();
$results[$j]['disk'] = $ar_buf[0];
$results[$j]['size'] = $ar_buf[1];
$results[$j]['used'] = $ar_buf[2];
$results[$j]['free'] = $ar_buf[3];
$results[$j]['percent'] = $ar_buf[4];
$results[$j]['mount'] = $ar_buf[5];
($fstype[$ar_buf[5]]) ? $results[$j]['fstype'] = $fstype[$ar_buf[5]] :
$results[$j]['fstype'] = $fsdev[$ar_buf[0]];
$j++;
}
return $results;
}
function distroicon () {
$result = 'Darwin.gif';
return($result);
}
}
?>
====================================================
Index: class.BSD.common.inc.php
<?php
// phpSysInfo - A PHP System Information Script
// http://phpsysinfo.sourceforge.net/
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
// $Id: class.BSD.common.inc.php,v 1.2 2005/11/19 05:29:55 skwashd Exp $
class bsd_common {
var $dmesg;
// Our constructor
// this function is run on the initialization of this class
function bsd_common () {
// initialize all the variables we need from our parent class
$this->sysinfo();
}
// read /var/run/dmesg.boot, but only if we haven't already.
function read_dmesg () {
if (! $this->dmesg) {
$this->dmesg = file ('/var/run/dmesg.boot');
}
return $this->dmesg;
}
// grabs a key from sysctl(8)
function grab_key ($key) {
return execute_program('sysctl', "-n $key");
}
// get our apache SERVER_NAME or vhost
function hostname () {
if (!($result = getenv('SERVER_NAME'))) {
$result = "N.A.";
}
return $result;
}
// get our canonical hostname
function chostname () {
return execute_program('hostname');
}
// get the IP address of our canonical hostname
function ip_addr () {
if (!($result = getenv('SERVER_ADDR'))) {
$result = gethostbyname($this->chostname());
}
return $result;
}
function kernel () {
$s = $this->grab_key('kern.version');
$a = explode(':', $s);
return $a[0] . $a[1] . ':' . $a[2];
}
function uptime () {
$result = $this->get_sys_ticks();
return $result;
}
function users () {
return execute_program('who', '| wc -l');
}
function loadavg () {
$s = $this->grab_key('vm.loadavg');
$s = ereg_replace('{ ', '', $s);
$s = ereg_replace(' }', '', $s);
$results = explode(' ', $s);
return $results;
}
function cpu_info () {
$results = array();
$ar_buf = array();
$results['model'] = $this->grab_key('hw.model');
$results['cpus'] = $this->grab_key('hw.ncpu');
for ($i = 0, $max = count($this->read_dmesg()); $i < $max; $i++) {
$buf = $this->dmesg[$i];
if (preg_match("/$this->cpu_regexp/", $buf, $ar_buf)) {
$results['cpuspeed'] = round($ar_buf[2]);
break;
}
}
return $results;
}
// get the scsi device information out of dmesg
function scsi () {
$results = array();
$ar_buf = array();
for ($i = 0, $max = count($this->read_dmesg()); $i < $max; $i++) {
$buf = $this->dmesg[$i];
if (preg_match("/$this->scsi_regexp1/", $buf, $ar_buf)) {
$s = $ar_buf[1];
$results[$s]['model'] = $ar_buf[2];
$results[$s]['media'] = 'Hard Disk';
} elseif (preg_match("/$this->scsi_regexp2/", $buf, $ar_buf)) {
$s = $ar_buf[1];
$results[$s]['capacity'] = $ar_buf[2] * 2048 * 1.049;
}
}
// return array_values(array_unique($results));
// 1. more useful to have device names
// 2. php 4.1.1 array_unique() deletes non-unique values.
asort($results);
return $results;
}
// get the pci device information out of dmesg
function pci () {
$results = array();
for ($i = 0, $s = 0; $i < count($this->read_dmesg()); $i++) {
$buf = $this->dmesg[$i];
if (preg_match('/(.*): <(.*)>(.*) pci[0-9]$/', $buf, $ar_buf)) {
$results[$s++] = $ar_buf[1] . ": " . $ar_buf[2];
} elseif (preg_match('/(.*): <(.*)>.* at [.0-9]+ irq/', $buf, $ar_buf)) {
$results[$s++] = $ar_buf[1] . ": " . $ar_buf[2];
}
}
$results = array_unique($results);
asort($results);
return $results;
}
// get the ide device information out of dmesg
function ide () {
$results = array();
$s = 0;
for ($i = 0, $max = count($this->read_dmesg()); $i < $max; $i++) {
$buf = $this->dmesg[$i];
if (preg_match('/^(ad[0-9]): (.*)MB <(.*)> (.*) (.*)/', $buf, $ar_buf)) {
$s = $ar_buf[1];
$results[$s]['model'] = $ar_buf[3];
$results[$s]['media'] = 'Hard Disk';
$results[$s]['capacity'] = $ar_buf[2] * 2048 * 1.049;
} elseif (preg_match('/^(acd[0-9]): (.*) <(.*)> (.*)/', $buf, $ar_buf)) {
$s = $ar_buf[1];
$results[$s]['model'] = $ar_buf[3];
$results[$s]['media'] = 'CD-ROM';
}
}
// return array_values(array_unique($results));
// 1. more useful to have device names
// 2. php 4.1.1 array_unique() deletes non-unique values.
asort($results);
return $results;
}
// place holder function until we add acual usb detection
function usb () {
return array();
}
function sbus () {
$results = array();
$_results[0] = "";
// TODO. Nothing here yet. Move along.
$results = $_results;
return $results;
}
function memory () {
$s = $this->grab_key('hw.physmem');
if (PHP_OS == 'FreeBSD' || PHP_OS == 'OpenBSD') {
// vmstat on fbsd 4.4 or greater outputs kbytes not hw.pagesize
// I should probably add some version checking here, but for now
// we only support fbsd 4.4
$pagesize = 1024;
} else {
$pagesize = $this->grab_key('hw.pagesize');
}
$results['ram'] = array();
$pstat = execute_program('vmstat');
$lines = split("\n", $pstat);
for ($i = 0, $max = sizeof($lines); $i < $max; $i++) {
$ar_buf = preg_split("/\s+/", $lines[$i], 19);
if ($i == 2) {
$results['ram']['free'] = $ar_buf[5] * $pagesize / 1024;
}
}
$results['ram']['total'] = $s / 1024;
$results['ram']['shared'] = 0;
$results['ram']['buffers'] = 0;
$results['ram']['used'] = $results['ram']['total'] -
$results['ram']['free'];
$results['ram']['cached'] = 0;
$results['ram']['t_used'] = $results['ram']['used'];
$results['ram']['t_free'] = $results['ram']['free'];
$results['ram']['percent'] = round(($results['ram']['used'] * 100) /
$results['ram']['total']);
if (PHP_OS == 'OpenBSD') {
$pstat = execute_program('swapctl', '-l -k');
} else {
$pstat = execute_program('swapinfo', '-k');
}
$lines = split("\n", $pstat);
$results['swap']['total'] = 0;
$results['swap']['used'] = 0;
$results['swap']['free'] = 0;
for ($i = 0, $max = sizeof($lines); $i < $max; $i++) {
$ar_buf = preg_split("/\s+/", $lines[$i], 6);
if ($ar_buf[0] != 'Total') {
$results['swap']['total'] = $results['swap']['total'] + $ar_buf[1];
$results['swap']['used'] = $results['swap']['used'] + $ar_buf[2];
$results['swap']['free'] = $results['swap']['free'] + $ar_buf[3];
}
}
$results['swap']['percent'] = round(($results['swap']['used'] * 100) /
$results['swap']['total']);
return $results;
}
function filesystems () {
$df = execute_program('df', '-k');
$mounts = split("\n", $df);
$fstype = array();
$s = execute_program('mount');
$lines = explode("\n", $s);
$i = 0;
while (list(, $line) = each($lines)) {
ereg('(.*) \((.*)\)', $line, $a);
$m = explode(' ', $a[0]);
$fsdev[$m[0]] = $a[2];
}
for ($i = 1, $j = 0, $max = sizeof($mounts); $i < $max; $i++) {
$ar_buf = preg_split("/\s+/", $mounts[$i], 6);
// skip the proc filesystem
if ($ar_buf[0] == 'procfs' || $ar_buf[0] == 'linprocfs' || $ar_buf[0] ==
'kernfs' || $ar_buf[0] == 'devfs') {
continue;
}
$results[$j] = array();
$results[$j]['disk'] = $ar_buf[0];
$results[$j]['size'] = $ar_buf[1];
$results[$j]['used'] = $ar_buf[2];
$results[$j]['free'] = $ar_buf[3];
$results[$j]['percent'] = $ar_buf[4];
$results[$j]['mount'] = $ar_buf[5];
($fstype[$ar_buf[5]]) ? $results[$j]['fstype'] = $fstype[$ar_buf[5]] :
$results[$j]['fstype'] = $fsdev[$ar_buf[0]];
$j++;
}
return $results;
}
function distro () {
$distro = execute_program('uname', '-s');
$result = $distro;
return($result);
}
}
?>
====================================================
Index: class.SunOS.inc.php
<?php
// phpSysInfo - A PHP System Information Script
// http://phpsysinfo.sourceforge.net/
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
// $Id: class.SunOS.inc.php,v 1.1 2005/11/19 05:29:55 skwashd Exp $
echo "<center><b>Note: The SunOS version of phpSysInfo is work in progress,
some things currently don't work";
class sysinfo {
// Extract kernel values via kstat() interface
function kstat ($key) {
$m = execute_program('kstat', "-p d $key");
list($key, $value) = split("\t", trim($m), 2);
return $value;
}
function vhostname () {
if (! ($result = getenv('SERVER_NAME'))) {
$result = 'N.A.';
}
return $result;
}
// get our canonical hostname
function chostname () {
if ($result = execute_program('uname', '-n')) {
$result = gethostbyaddr(gethostbyname($result));
} else {
$result = 'N.A.';
}
return $result;
}
// get the IP address of our canonical hostname
function ip_addr () {
if (!($result = getenv('SERVER_ADDR'))) {
$result = gethostbyname($this->chostname());
}
return $result;
}
function kernel () {
$os = execute_program('uname', '-s');
$version = execute_program('uname', '-r');
return $os . ' ' . $version;
}
function uptime () {
$result = time() - $this->kstat('unix:0:system_misc:boot_time');
return $result;
}
function users () {
$who = split('=', execute_program('who', '-q'));
$result = $who[1];
return $result;
}
function loadavg () {
$load1 = $this->kstat('unix:0:system_misc:avenrun_1min');
$load5 = $this->kstat('unix:0:system_misc:avenrun_5min');
$load15 = $this->kstat('unix:0:system_misc:avenrun_15min');
$results = array($load1, $load5, $load15);
return $results;
}
function cpu_info () {
$results = array();
$ar_buf = array();
$results['model'] = execute_program('uname', '-i');
$results['cpuspeed'] = $this->kstat('cpu_info:0:cpu_info0:clock_MHz');
$results['cache'] = $this->kstat('cpu_info:0:cpu_info0:cpu_type');
$results['bogomips'] = 1;
$results['cpus'] = $this->kstat('unix:0:system_misc:ncpus');
$keys = array_keys($results);
$keys2be = array('model', 'cpuspeed', 'cache', 'bogomips', 'cpus');
while ($ar_buf = each($keys2be)) {
if (! in_array($ar_buf[1], $keys)) {
$results[$ar_buf[1]] = 'N.A.';
}
}
return $results;
}
function pci () {
// FIXME
$results = array();
return $results;
}
function ide () {
// FIXME
$results = array();
return $results;
}
function scsi () {
// FIXME
$results = array();
return $results;
}
function usb () {
// FIXME
$results = array();
return $results;
}
function sbus () {
$results = array();
$_results[0] = "";
// TODO. Nothing here yet. Move along.
$results = $_results;
return $results;
}
function network () {
$results = array();
$netstat = execute_program('netstat', '-ni | awk \'(NF ==10){print;}\'');
$lines = split("\n", $netstat);
$results = array();
for ($i = 0, $max = sizeof($lines); $i < $max; $i++) {
$ar_buf = preg_split("/\s+/", $lines[$i]);
if ((!empty($ar_buf[0])) && ($ar_buf[0] != 'Name')) {
$results[$ar_buf[0]] = array();
$results[$ar_buf[0]]['rx_bytes'] = 0;
$results[$ar_buf[0]]['rx_packets'] = $ar_buf[4];
$results[$ar_buf[0]]['rx_errs'] = $ar_buf[5];
$results[$ar_buf[0]]['rx_drop'] = 0;
$results[$ar_buf[0]]['tx_bytes'] = 0;
$results[$ar_buf[0]]['tx_packets'] = $ar_buf[6];
$results[$ar_buf[0]]['tx_errs'] = $ar_buf[7];
$results[$ar_buf[0]]['tx_drop'] = 0;
$results[$ar_buf[0]]['errs'] = $ar_buf[4] + $ar_buf[
7];
$results[$ar_buf[0]]['drop'] = 0;
preg_match('/^(\D+)(\d+)$/', $ar_buf[0], $intf);
$prefix = $intf[1] . ':' . $intf[2] . ':' . $intf[1] . $intf[2] . ':';
$cnt = $this->kstat($prefix . 'drop');
if ($cnt > 0) {
$results[$ar_buf[0]]['rx_drop'] = $cnt;
}
$cnt = $this->kstat($prefix . 'obytes64');
if ($cnt > 0) {
$results[$ar_buf[0]]['tx_bytes'] = $cnt;
}
}
}
return $results;
}
function memory () {
$results['devswap'] = array();
$results['ram'] = array();
$pagesize = $this->kstat('unix:0:seg_cache:slab_size');
$results['ram']['total'] = $this->kstat('unix:0:system_pages:pagestotal') *
$pagesize;
$results['ram']['used'] = $this->kstat('unix:0:system_pages:pageslocked') *
$pagesize;
$results['ram']['free'] = $this->kstat('unix:0:system_pages:pagesfree') *
$pagesize;
$results['ram']['shared'] = 0;
$results['ram']['buffers'] = 0;
$results['ram']['cached'] = 0;
$results['ram']['t_used'] = $results['ram']['used'] -
$results['ram']['cached'] - $results['ram']['buffers'];
$results['ram']['t_free'] = $results['ram']['total'] -
$results['ram']['t_used'];
$results['ram']['percent'] = round(($results['ram']['used'] * 100) /
$results['ram']['total']);
$results['swap'] = array();
$results['swap']['total'] = $this->kstat('unix:0:vminfo:swap_avail') / 1024;
$results['swap']['used'] = $this->kstat('unix:0:vminfo:swap_alloc') / 1024;
$results['swap']['free'] = $this->kstat('unix:0:vminfo:swap_free') / 1024;
$results['swap']['percent'] = round(($ar_buf[1] * 100) / $ar_buf[0]);
$results['swap']['percent'] = round(($results['swap']['used'] * 100) /
$results['swap']['total']);
return $results;
}
function filesystems () {
$df = execute_program('df', '-k');
$mounts = split("\n", $df);
$dftypes = execute_program('df', '-n');
$mounttypes = split("\n", $dftypes);
for ($i = 1, $max = sizeof($mounts); $i < $max; $i++) {
$ar_buf = preg_split('/\s+/', $mounts[$i], 6);
$ty_buf = split(':', $mounttypes[$i-1], 2);
$results[$i - 1] = array();
$results[$i - 1]['disk'] = $ar_buf[0];
$results[$i - 1]['size'] = $ar_buf[1];
$results[$i - 1]['used'] = $ar_buf[2];
$results[$i - 1]['free'] = $ar_buf[3];
$results[$i - 1]['percent'] = round(($results[$i - 1]['used'] * 100) /
$results[$i - 1]['size']) . '%';
$results[$i - 1]['mount'] = $ar_buf[5];
$results[$i - 1]['fstype'] = $ty_buf[1];
}
return $results;
}
function distro () {
$result = 'SunOS';
return($result);
}
function distroicon () {
$result = 'xp.gif';
return($result);
}
}
?>
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Phpgroupware-cvs] phpsysinfo/includes/os class.Linux.inc.php, 1.2 class.HP-UX.inc.php, 1.1 class.NetBSD.inc.php, 1.2 class.OpenBSD.inc.php, 1.2 index.html, 1.1 class.WINNT.inc.php, 1.1 class.FreeBSD.inc.php, 1.2 class.Darwin.inc.php, 1.2 class.BSD.common.inc.php, 1.2 class.SunOS.inc.php, 1.1,
skwashd <=
- Prev by Date:
[Phpgroupware-cvs] phpsysinfo/templates/orange/images bar_right.gif, 1.2 bar_middle.gif, 1.2 index.html, 1.1 trans.gif, 1.2 redbar_right.gif, 1.2 redbar_middle.gif, 1.2 redbar_left.gif, 1.2 bar_left.gif, 1.2
- Next by Date:
[Phpgroupware-cvs] phpsysinfo/templates/aq aq.css, 1.2 form.tpl, 1.2 box.tpl, 1.2 index.html, 1.1
- Previous by thread:
[Phpgroupware-cvs] phpsysinfo/templates/orange/images bar_right.gif, 1.2 bar_middle.gif, 1.2 index.html, 1.1 trans.gif, 1.2 redbar_right.gif, 1.2 redbar_middle.gif, 1.2 redbar_left.gif, 1.2 bar_left.gif, 1.2
- Next by thread:
[Phpgroupware-cvs] phpsysinfo/templates/aq aq.css, 1.2 form.tpl, 1.2 box.tpl, 1.2 index.html, 1.1
- Index(es):