Location: PHPKode > projects > Limph > limph-1.9.7/status.php
<?php
 /*
   Limph Is Monitoring Pingable Hosts
   Copyright (C) 2006 Jonathan Ciesla
   
   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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
  */
require_once("config.php");
require_once("functionlib.php");
favicon();

$link = dbms_connect($dbhost, $dbuser, $dbpass, $dbname);

$date_a = array(date("Y"), date("m"), date("d"));
$date = implode("-", $date_a);
$time_a = array(date("H"), date("i"), date("s"));
$time = implode(":", $time_a);
$datetime = $date . " " . $time;

echo "<meta http-equiv=refresh content=60;url=$siteaddress/status.php />";
echo "<title>Limph: $sitetitle</title>";
echo "<link rel=stylesheet href=style.css>";

$query = "SELECT status_public FROM universal;";
$result = dbms_query($query);
$line = dbms_fetch_array($result, "NUM");
$public = $line[0];
dbms_free_result($result);

if($public=="0"){
  echo "<meta http-equiv=refresh content=0;url=$siteaddress/index.php />";
 } else {
  
  $query = "SELECT COUNT(number) FROM layout;";
  $result = dbms_query($query);
  $line = dbms_fetch_array($result, "NUM");
  $columns = $line[0];
  dbms_free_result($result);
  
  echo "<table border=1 align=center>";
  echo "<tr><th colspan=$columns>Host Status</th></tr>";
  echo "<tr>";
  
  $query = "SELECT number,width FROM layout ORDER BY number ASC;";
  $result3 = dbms_query($query);
  
  while($line3 = dbms_fetch_array($result3, "NUM")){  //column loop
    $pos = $line3[0];
    $width = $line3[1];
    echo "<td align=center bgcolor=#808080 valign=top>";
    $query = "SELECT number,name,collapse FROM groups WHERE col = '$pos' ORDER BY priority ASC;";
    $result = dbms_query($query);
    //group container
    echo "<table border=0 align=center>";
    while($line = dbms_fetch_array($result, "NUM")){  //group loop
      echo "<tr><th align=center>{$line['1']}</th></tr>";
      if($line[2]=="0"){
	echo "<tr>";
	echo "<td align=center bgcolor=#808080>";
	$query2 = "SELECT name,status,enabled,number,port,visible FROM hosts WHERE hostgroup = '{$line['0']}' ORDER BY name ASC;";
	$result2 = dbms_query($query2);
	echo "<table border=0 align=center>";
	echo "<tr>"; 
	$count = 0;
	while($line2 = dbms_fetch_array($result2, "NUM")){  //host loop
	  
	  $count++;
	  
	  if($line2[1]=="1"){ $flag = "bgcolor=#00FF00"; }; #Up
	  
	  $query = "SELECT DISTINCT disk FROM state WHERE hostname = '{$line2['0']}' AND type = 'diskfree';";
	  $result5 = dbms_query($query);
	  while($disks = dbms_fetch_array($result5, "ASSOC")){
	    $query6 = "SELECT data FROM state WHERE type = 'diskfree' AND hostname = '{$line2['0']}' AND disk = '{$disks['disk']}' ORDER BY datetime DESC LIMIT 1;";
	    $result6 = dbms_query($query6);
	    $current_free = dbms_fetch_array($result6, "ASSOC");
	    dbms_free_result($result6);
	    if(disk_thresh_check($line2[0], $disks['disk'], $current_free['data'])==1){ $flag = "bgcolor=#FFA500"; }; #Disk Threshold
	  };
	  dbms_free_result($result5);
	  
	  $query6 = "SELECT data FROM state WHERE type = 'sysload' AND hostname = '{$line2['0']}' ORDER BY datetime DESC LIMIT 1;";
	  $result6 = dbms_query($query6);
	  $current_load = dbms_fetch_array($result6, "ASSOC");
	  dbms_free_result($result6);
	  if(sysload_thresh_check($line2[0], $current_load['data'])==1){ $flag = "bgcolor=#FFA500"; }; #Load Threshold
	  
	  if($line2[5]=="0"){ $flag = "bgcolor=#FF00FF"; }; #Unreachable
	  if($line2[1]=="0"){ $flag = "bgcolor=#FF0000"; }; #Down
	  if($line2[2]=="0"){ $flag = "bgcolor=#808080"; }; #Disabled
	  echo "<td align=center $flag>";
	  //display host
	  if($line2[4]!="0"){
	    echo $line2[0] . " - " . $line2[4];
	  } else {
	    echo $line2[0];
	  };
	  echo "</td>";
	  if($count>=$width){
	    echo "</tr><tr>";
	    $count = 0;
	  };
	};  //end host loop
	echo "</tr>";
	echo "</table>";
	dbms_free_result($result2);
	echo "</td>";
	echo "</tr>";
      } else {
	//group collapsed display.
	$query4 = "SELECT COUNT(number) FROM hosts WHERE hostgroup = '{$line['0']}' AND status = '0' AND enabled = '1';";
	$result4 = dbms_query($query4);
	$down_a = dbms_fetch_array($result4, "NUM");
	$down = $down_a[0];
	dbms_free_result($result4);
	
	$query4 = "SELECT COUNT(number) FROM hosts WHERE hostgroup = '{$line['0']}' AND status = '1' AND enabled = '1';";
	$result4 = dbms_query($query4);
	$up_a = dbms_fetch_array($result4, "NUM");
	$up = $up_a[0];
	dbms_free_result($result4);
	
	$total = $up + $down;
	
	//figure color
	if($total==$up){
	  $bgcolor="#00FF00";
	} else {
	  if(($up/$total)>="0.5"){
	    $bgcolor="#FFFF00";
	  } else {
	    $bgcolor="#FF0000";
	  };
	};
	
	echo "<tr>";
	echo "<td align=center bgcolor=$bgcolor>";
	echo "<h3>Up: $up Down: $down</h3>";
	echo "</td>";
	echo "</tr>";
	
      }; //end collapse loop 
      
    };  //end group loop
    
    dbms_free_result($result);
    echo "</table>"; 
  }; //end column loop
  dbms_free_result($result3); 
  
  echo "</tr>";
  echo "</table>";
  
  echo "<hr>";
  
  limph_key();

  echo "<br />";

  echo "<form action=index.php method=post>";
  echo "<input type=submit value=Login />";
  echo "</form>";
  
 };

$query = "SELECT version,year FROM universal;";
$result = dbms_query($query);
$line = dbms_fetch_array($result, "ASSOC");
dbms_free_result($result);
dbms_close($link);

echo "Limph version {$line['version']} Copyright {$line['year']} Jonathan Ciesla";
echo "<br />";
$time_a = array(date("H"), date("i"), date("s"));
$time = implode(":", $time_a);
$date = $date . " " . $time;
echo "$date<br />";
if($dbtype=="my"){
  echo "Running on MySQL";
  echo "<br />";
 };
if($dbtype=="pg"){
  echo "Running on PostgreSQL ";
  echo "<br />";
 };
if($dbtype=="sl"){
  echo "Running on SQLite";
  echo "<br />";
 };
if($dbtype=="slpdo"){
  echo "Running on SQLite/PDO";
  echo "<br />";
 };
echo "<a href=\"http://limph.sourceforge.net\" target=\"_blank\">Info</a>";

?>
Return current item: Limph