#!/usr/bin/perl
# Update My home page with stats
# Feed this procedure with output from hits script
# Gerry Patterson, May 2002
$home_html = "/MyHTML/index.html";
while (<>){
	@t = split( ' ',$_);
	($virus_bum,$virus_hit) = ($t[1],$t[2]) if ($t[0] eq "Virus");
	($robot_bum,$robot_hit) = ($t[1],$t[2]) if ($t[0] eq "Robot");
	($visitor_bum,$visitor_hit) = ($t[1],$t[2]) if ($t[0] eq "Visitor");
}
open(HTML,$home_html) || die "Cannot open $home_html\n";
$stats_flag = 0;
$visitor_num = $visitor_bum + 1;
while (<HTML>){
	$stats_flag++ if (/<!-- Site Stats -->/);
	if (/<!-- End Site Stats -->/){
		$stats_flag = 0;
		next;
	}
	if ( $stats_flag == 0 ){
		print $_;
		next;
	}
	# replace text between <!-- Site Stats --> .. <!-- End Site Stats -->
	print '  <!-- Site Stats -->
  <p align=center><font face="Arial" color=#004010 size=2>
  <b>You are Visitor Number ' . $visitor_num . ' to this site</b></font></p>
  <center>
  <table border=1 border-style="solid" frame="box" cellspacing=0 cellpadding=6>
    <tr>
      <th rowspan=1 colspan=3 align="center" valign="top"
          style="font-size: 14px; font-weight: bold; font-family: Arial;">
          PGTS Site Statistics</th>
    </tr>
    <tr>
	<td style="font-size: 12px; font-weight: bold; font-family: Arial;">
	 Type of Visitor</td>
	<td style="font-size: 12px; font-weight: bold; font-family: Arial;"
	 align=right>Number of Visits</td>
	<td style="font-size: 12px; font-weight: bold; font-family: Arial;"
	 align=right>Number of Hits</td>
    </tr>
    <tr>
	<td style="font-size: 12px; font-family: Arial;">MS Worms</td>
	<td style="font-size: 12px; font-family: Arial;" align=right>' . $virus_bum . '</td>
	<td style="font-size: 12px; font-family: Arial;" align=right>' . $virus_hit . '</td>
    </tr>
    <tr>
	<td style="font-size: 12px; font-family: Arial;">Robots</td>
	<td style="font-size: 12px; font-family: Arial;" align=right>' . $robot_bum . '</td>
	<td style="font-size: 12px; font-family: Arial;" align=right>' . $robot_hit . '</td>
    </tr>
    <tr>
	<td style="font-size: 12px; font-family: Arial;">Visitors</td>
	<td style="font-size: 12px; font-family: Arial;" align=right>' . $visitor_bum . '</td>
	<td style="font-size: 12px; font-family: Arial;" align=right>' . $visitor_hit . '</td>
    </tr>
  </table>
  </center>
  <!-- End Site Stats -->
' if ( $stats_flag == 1);
		$stats_flag++;
}
