#  This software was derived from SATAN 1.1.1 by Dan Farmer and Wietse Venema
#  (http://www.porcupine.org/satan).
#
#
# Report subnets
#

# generate the tables for looking subnets/hosts in:
&make_subnet_info();
$_subnets = keys %all_subnets;

sub sort_ip {
    local($aip,$bip);
    for $ip (split(/\./,$a)) { $aip = $aip * 256 + $ip; }
    for $ip (split(/\./,$b)) { $bip = $bip * 256 + $ip; }
    return $aip <=> $bip;
}

print CLIENT <<EOF;
<HTML>
<HEAD>
<SCRIPT language="JavaScript">
  function movepic(img_name,img_src) {
  document[img_name].src=img_src;
}
</SCRIPT>
<title> Host Tables - By Subnet  </title>
<LINK REV="made" HREF="mailto:satan\@fish.com">
<LINK REV="made" HREF="mailto:sara\@arc.com">
</HEAD>
<BODY>
EOF
if ($pi_menu) {
  $screen = &$pi_menu;
} else {
  $screen = print_menu();
}
$screen =~ s/\\n/\n/g;
print CLIENT $screen;
print CLIENT <<EOF;
</TD><TD valign=top>
<CENTER><H1>Host Tables - By Subnet </H1></CENTER>
<hr>
<h3>$_subnets Subnets. Number of hosts per subnet (vulnerable/total). </h3>
<strong>Subnets with a red dot next to them have a vulnerable host contained within.</strong>
<ul>
EOF

# until the subnet is all looked at...
for $_net (sort sort_ip keys %all_subnets) {
    $dot = $subnet_severities{$_net} ? "red" : "black";
    print CLIENT <<EOF;
	    <dt><IMG SRC=$HTML_ROOT/dots/$dot\dot.gif ALT="$dot">
	    <a href="sara_results_subnet.pl,$_net,"> $_net </a> 
	    ($subnet_severities{$_net}/$subnet_count{$_net})
EOF
    }

print CLIENT <<EOF;
</ul>
<hr> <a href="/"> Back to the SARA start page </a> |
<a href=/reporting/analysis.pl> Back to SARA Reporting and Analysis </a>
</UL></UL></TABLE>
</BODY>
</HTML>
EOF
