<? 
 
Function dmzsdbQuery$server$user$password$db$statement )
        { 
        global 
$dbconfig;
                         
        
mysql_pconnect$server$user$password );
        
mysql_select_db$db );
        
$result = @mysql_query$statement );

        if( 
mysql_error() )
                {
                
PrintErrormysql_error() );
                }

        return 
$result;
        } 

 Function 
dbNumRows$result )
        {
        return 
mysql_numrows$result );
        }

 Function 
dbResultArray$result$i )
        { 
        @
mysql_data_seek$result$i );

        return 
mysql_fetch_array$result );
        } 

  
$hostquery="select distinct(hostname) from bbhistory";
  if (
$gethost)
    
$gethost=rawurldecode($gethost);
  if (
$getservice)
    
$getservice=rawurldecode($getservice);
  if (
$timestamp)
    
$timestamp=rawurldecode($timestamp);
  
$hostquery .= " order by hostname";

  if (
$gethost)
    
$timequery "select DATE_FORMAT(timestamp,\"%M %D,%Y, %l:%i:%s %p\") as date from bbhistory where hostname='" $gethost "' order by timestamp desc limit 1";
  else
    
$timequery "select DATE_FORMAT(timestamp,\"%M %D,%Y, %l:%i:%s %p\") as date from bbhistory order by timestamp desc limit 1";
  
$timeresult dmzsdbQuery("localhost","<dbuser>","<password>","monitor",$timequery);
  
$timelog dbResultArray($timeresult,0);

  echo 
"<table width=\"100%\"><tr><td align=left><a href=\"http://bb.com\"><img src=\"/gifs/bb.gif\" alt=\"Big Brother Logo\" border=0 align=left></a></td><td align=right><b>last update:<br>" $timelog["date"] . "</b></td></tr></table><br>";
  if (!
$getservice)
  {
    echo 
"<table width=100% border=1>";
    
$hostresults dmzsdbQuery("localhost","<dbuser>","<password>","monitor",$hostquery);
    
$serviceresults dmzsdbQuery("localhost","<dbuser>","<password>","monitor","select distinct(service) from bbhistory order by service");
    
$numhost dbNumRows($hostresults);
    
$numservice dbNumRows($serviceresults);
    
$i=0;
    
$j=0;
    echo 
"<tr><td>&nbsp;</td>";
    while (
$j $numservice)
    {
      
$service dbResultArray($serviceresults,$j);
      echo 
"<td align=center>" $service["service"] . "</td>";
      
$j++;
    }
    echo 
"</tr>";
    
$j=0;
    while (
$i $numhost)
    {
      
$hostname dbResultArray($hostresults,$i);
        echo 
"<tr><td align=right>" $hostname["hostname"] . "</td>";
      while (
$j $numservice)
      {
        
$service dbResultArray($serviceresults,$j);
        
$query "select status,timestamp from bbhistory where hostname='" $hostname["hostname"] . "' and service='" $service["service"] . "' order by timestamp desc limit 1";
        
$servicestatusresult dmzsdbQuery("localhost","<dbuser>","<password>","monitor",$query);
        
$serverstatus dbResultArray($servicestatusresult,0);
        if (
$serverstatus["status"] != "")
      echo 
"<td align=center><a href=\"bb4.php3?gethost=" rawurlencode($hostname["hostname"]) . "&getservice=" rawurlencode($service["service"]) . "&timestamp=" rawurlencode($serverstatus["timestamp"]) . "\"><img border=0 src=\"/gifs/" $serverstatus["status"] . ".gif\"></a></td>";
        else
          echo 
"<td>&nbsp;</td>";
        
$j++;
      }
      echo 
"</tr>";
      
$j=0;
      
$i++;
    }
    echo 
"</table>";
  }
  else
  {
    
$query "select log from bbhistory where hostname='" $gethost "' and service='" $getservice "' and timestamp='" $timestamp "' order by timestamp desc limit 1";
    
$hostlogresult dmzsdbQuery("localhost","<dbuser>","<password>","monitor",$query);
    
$hostlog dbResultArray($hostlogresult,0);
    echo 
"<center><b>" $gethost "<br>" $getservice "</b><p><pre>" $hostlog["log"] . "</pre><hr>";
  }
    echo 
"<a href=\"bb4.php3\">Back</a>";
?>
<CENTER><BR><BR><HR WIDTH="80%">
<TABLE SUMMARY="Footer" WIDTH="80%" BORDER=0><TR>
<TD ALIGN="center" WIDTH="13%">
        <FONT FACE="Arial, Helvetica" COLOR="silver">
        <A HREF="/bb/help/bb-help.html#blue">
        <IMG SRC="/gifs/green.gif" WIDTH="16" HEIGHT="16" BORDER="0"
        ALIGN="middle" ALT="green"></a>ok</FONT></TD>                                                         
<TD ALIGN="center" WIDTH="13%">
        <FONT FACE="Arial, Helvetica" COLOR="silver">
        <A HREF="/bb/help/bb-help.html#blue">
        <IMG SRC="/gifs/yellow.gif" WIDTH="16" HEIGHT="16" BORDER="0"                      
        ALIGN="middle" ALT="yellow"></a>attention</FONT></TD>              
<TD ALIGN="center" WIDTH="13%">
        <FONT FACE="Arial, Helvetica" COLOR="silver">
        <A HREF="/bb/help/bb-help.html#blue">
        <IMG SRC="/gifs/red.gif" WIDTH="16" HEIGHT="16" BORDER="0"                          
        ALIGN="middle" ALT="red"></a>trouble</FONT></TD>                                           
<TD ALIGN="center" WIDTH="13%">
        <FONT FACE="Arial, Helvetica" COLOR="silver">
        <A HREF="/bb/help/bb-help.html#blue">
        <IMG SRC="/gifs/purple.gif" WIDTH="16" HEIGHT="16" BORDER="0"
        ALIGN="middle" ALT="purple"></a>no report</FONT></TD>
<TD ALIGN="center" WIDTH="13%">
        <FONT FACE="Arial, Helvetica" COLOR="silver">
        <A HREF="/bb/help/bb-help.html#blue">
        <IMG SRC="/gifs/clear.gif" WIDTH="16" HEIGHT="16" BORDER="0"
        ALIGN="middle" ALT="clear"></a>unavailable</FONT></TD>
<TD ALIGN="center" WIDTH="13%">
        <FONT FACE="Arial, Helvetica" COLOR="silver">
        <A HREF="/bb/help/bb-help.html#blue">
        <IMG SRC="/gifs/blue.gif" WIDTH="16" HEIGHT="16" BORDER="0"
        ALIGN="middle" ALT="blue"></a>offline</FONT></TD>
</TR></TABLE>
</CENTER>
<HR WIDTH="80%">
<BR><BR>
<CENTER>
<H6><I>
<!-- The license agreement requires a link back to the BB main site -->
<FONT FACE="Arial, Helvetica" COLOR="silver">
<div align=right>
<a href="http://www.dmzs.com/~dmz/projects/bb/">[Modified]</a>
<A HREF="http://bb4.com">
<IMG SRC="/gifs/bblogo.gif" BORDER=0 ALIGN=RIGHT ALT="BB Logo"></A><BR>
</div>
</FONT></I></H6></CENTER>