<?php
//Created by J.P. Pasnak, Warped Systems
//
//Additional code by:
//Jean Segers - >10 partition fix
//Jeff Hover - Who's Online code
//Joacher - No swap code
//
//Copyright 2001-2002 Warped Systems
//
//Include variables 
include("config.php");
// Get the Time
$time = (exec("date"));
// Get kernel info
list($system, $host, $kernel) = split(" ", exec("uname -a"), 5);
// Go out and get the IP
$ip=gethostbyname($host);
// Grab uptime output
$uptime = (exec("uptime"));
// Get the kernel info, and grab the cool stuff
$cpuinfo = file("/proc/cpuinfo");
for ($i = 0; $i < count($cpuinfo); $i++) {
		list($item, $data) = split(":", $cpuinfo[$i], 2);
		$item = chop($item);
		$data = chop($data);
		if ($item == "processor") {
				$total_cpu++;
				$cpu_info = $total_cpu;
		}
		if ($item == "vendor_id") { $cpu_info .= $data; }
		if ($item == "model name") { $cpu_info .= $data; }
		if ($item == "cpu MHz") { 
				$cpu_info .= " " . floor($data); 
				$found_cpu = "yes";
		}
		if ($item == "cache size") { $cache = $data;}
		if ($item == "bogomips") { $bogomips = $data;}
}
if($found_cpu != "yes") { $cpu_info .= " <b>unknown</b>"; } 
$cpu_info .= " MHz\n";

//Get the memory info, and grab the cool stuf
$meminfo = file("/proc/meminfo");
for ($i = 0; $i < count($meminfo); $i++) {
		list($item, $data) = split(":", $meminfo[$i], 2);
		$item = chop($item);
		$data = chop($data);
		if ($item == "MemTotal") { $total_mem =$data;	}
		if ($item == "MemFree") { $free_mem = $data; }
		if ($item == "SwapTotal") { $total_swap = $data; }
		if ($item == "SwapFree") { $free_swap = $data; }
		if ($item == "Buffers") { $buffer_mem = $data; }
		if ($item == "Cached") { $cache_mem = $data; }
		if ($item == "MemShared") {$shared_mem = $data; }
}
$used_mem = ( $total_mem - $free_mem ); 
$used_swap = ( $total_swap - $free_swap );
$percent_free = round( $free_mem / $total_mem * 100 );
$percent_used = round( $used_mem / $total_mem * 100 );
// Checks to see if there is no swap - contributed by Joacher
if ($total_swap != 0) 
{ 
$percent_swap = round( ( $total_swap - $free_swap ) / $total_swap * 100 ); 
$percent_swap_free = round( $free_swap / $total_swap * 100 ); 
} 

 else { 
$percent_swap = "N/A "; 
$percent_swap_free = "N/A "; 
}; 
$percent_buff = round( $buffer_mem / $total_mem * 100 );
$percent_cach = round( $cache_mem / $total_mem * 100 );
$percent_shar = round( $shared_mem / $total_mem * 100 );
//Now it's time to grab the cool stuff from the hard drive
//This one is not quite as straight forward.....
exec ("df -h", $x);
$count = 1;
while ($count < sizeof($x)) {
		list($drive[$count], $size[$count], $used[$count], $avail[$count], $percent[$count], $mount[$count]) = split(" +", $x[$count]);
		$percent_part[$count] = str_replace( "%", "", $percent[$count] );	
$count++;
}


// Find out who is logged in
 exec ("w", $who);
  $countwho = 1;
   $up_header = array_shift ($who);
    while ($countwho < sizeof($who)) {
	    list($user[$countwho], $tty[$countwho], $from[$countwho], 
		$login[$countwho], $idle[$countwho], $jcpu[$countwho],
		$pcpu[$countwho], 
		$what[$countwho]) = split(" +", $who[$countwho]);
		    $countwho++;
			 }

// Look for www, ftp, etc sessions.  Remove 'TIME_WAIT' and 'CLOSE_WAIT'
// Still have to work on removing 'localhost' services.
$list = `netstat -t|grep ESTABLISHED`;
$svc = 1;
$svctot = count ($service);
while ($svc <= $svctot){
$daemon[$svc] = substr_count($list, $service[$svc]);
$svc++;
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>

<head>
	<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
	<meta http-equiv="Pragma" content="no-cache">
	<link rel="stylesheet" type="text/css" href="style.css">
	<title>phpSystem : <?php
		echo "$host ($ip)";
	?></title>
</head>

<body bgcolor="#ffffff">
<? include ('output.php'); ?>
<p align="center"><?php
echo $msg_generated;
?> <a href="http://www.warpedsystems.sk.ca/modules.php?op=modload&name=NS-Sections&file=index&req=viewarticle&artid=11">phpSystem</a></p>
</body>

</html>
