#!/usr/bin/perl

use CGI;
require "pong3.conf";

my $form = new CGI;

my $host = $form->param('host');
my $service = $form->param('service');
my $color = $form->param('color');

open SUMMARY, "$pongstatusdir/$host\-$service\-$color";
@foo = <SUMMARY>;
close SUMMARY;

if ($service eq 'http')
{
    foreach $line (@foo)
    {
	push @summary,$line if $line !~ /^[\r\n]+$/;
    }
}
elsif ($service eq 'df')
{
    $line = $foo[0];
    ($space) = $line =~ /(\d+)/;
    $line = "Closest to capacity is $space\%";
    push @summary,$line;
}
elsif ($service eq 'dns')
{
    push @summary,$foo[0];
}
elsif ($service eq 'free')
{
    ($freemem) = $foo[0] =~ /(\d+)/;
    push @summary, "$host has $freemem kbytes free";
}
elsif ($service eq 'load')
{
    ($load) = $foo[0] =~ /([\d\.]+)/;
    push @summary, "Highest Average Load: $load";
}
elsif ($service eq 'ping')
{
    push @summary, $foo[0];
}
elsif ($service eq 'pop3')
{
    push @summary, $foo[0];
}
elsif ($service eq 'smtp')
{
    push @summary, $foo[0];
}
else
{
    push @summary, $foo[0];
}

print "Content-type: text/html\n\n";

print <<EOF;
<HTML>
<HEAD>
<TITLE>Current Status of $servicename{$service} for $host</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000">
<CENTER>
<IMG SRC="/images/speed.gif">
<P>
<H2>Current Status of $servicename{$service} for $host</H2>
<P>

<TABLE BORDER=1>
<TR>
  <TH>Host</TH>
  <TD>$host</TD>
</TR>
<TR>
  <TH>Service Name</TH>
  <TD ALIGN="CENTER">$servicename{$service}</TD>
<TR>
  <TH>Current Status</TH>
  <TD ALIGN="CENTER"><IMG SRC="images/$color.gif" ALIGN="LEFT"><IMG ALIGN="RIGHT" SRC="images/$color.gif">$color</TD>
</TR>
<TR>
  <TH>Summary</TH>
  <TD HALIGN="CENTER"> 
    <PRE>@summary</PRE>
  </TD>
</TR>
</TABLE>

EOF
    ;
