#!/usr/bin/perl

print "Content-Type: text/html\n";
print "Cache-Control: no-cache\n\n";

print <<EOF;
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>Internet</title>
  </head>
EOF

my $gen;   
if ($ENV{"QUERY_STRING"} =~ /gen=(.+)[&]?/) {
    $gen = $1;
}
$gen = 0 if (!$gen);

my $solid = ( int(rand(5)) == 0 );
if ( ($solid && $gen >= 3) || ($gen > 6) ) { # be solid color
    my $r = int(rand(240))+16;
    my $g = int(rand(240))+16;
    my $b = int(rand(240))+16;
    $col = dechex($r) . dechex($g) . dechex($b);
    print "<body bgcolor=\"#000000\">\n";
    print "<table width=100% height=100% border=0 cellspacing=0 cellpadding=0>\n";
    print "<tr><td bgcolor=\"#$col\" width=\"100%\" height=\"100%\"></td></tr>\n";
    print "</table>\n</body>\n";

} else { # Split into two more frames.
    
    if ($gen%2) {
	my $size = int(rand(61))+20;
	print "<frameset cols=\"$size%,*%\" border=0 frameborder=0 framespacing=0 marginheight=0 scrolling=\"off\">\n";
    } else {
	my $size = int(rand(31))+35;
	print "<frameset rows=\"$size%,*%\" border=0 frameborder=0 scrolling=\"off\" marginheight=0 framespacing=0>\n";
    }
    my $opt = "frameborder=0 border=0 resize scrolling=off framespacing=0 cellpadding=0";
    
    $gen++;
    print "<frame src=\"?gen=$gen\" $opt>\n";
    print "<frame src=\"?gen=$gen\" $opt>\n";
    print "<noframes>You need frames for this to work. :(</noframes>\n";
    print "</frameset>\n";
}

print "</html>\n";


sub dechex {
    ($val) = @_;
    return sprintf "%02x", $val;
}
