#  This software was derived from SATAN 1.1.1 by Dan Farmer and Wietse Venema
#  (http://www.porcupine.org/satan).
#
#  This code update is provided by the Advanced Research Corporation (r) to
#  further the utility of the SARA Report Writer.  We request that the
#  developers do not modify or reverse engineer this code for
#  their own gain.
#
#  Developed and distributed by the Advanced Research Corporation.
#
#
($_host) = split(/,/, $html_script_args);
$_ip = $all_hosts{$_host}{IP};
($_type = $hosttype{$_host}) =~ tr / \//+!/;
$_hosttype=substr($hosttype{$_host},0,22);

#
# Refresh the host type and service tables.
#
&make_hosttype_info();
&make_service_info();
&make_subnet_info();
&make_severity_info();

$_red_cnt=0;
$_yellow_cnt=0;
$_brown_cnt=0;
$_green_cnt=0;

	for (keys %{$severity_host_type_info{$_host}}) {
		($_tutorials = $_) =~ tr / /_/;
		for (sort split(/\n/, $severity_host_type_info{$_host}{$_})) {
                        &sara_split($_) if ($system eq "sara");
                        &saint_split($_) if ($system eq "saint");
                        &satan_split($_) if ($system eq "satan");

                         if($severity_red_type_info{$service_output}) {
                          if (correction("$_host|$text") == 0 ) {
			    $_red_cnt=$_red_cnt + 1 if sans10($service_output);
                          }
		}
	    }
	}

        for (keys %{$severity_host_type_info{$_host}}) {
                ($_tutorials = $_) =~ tr / /_/;
                for (sort split(/\n/, $severity_host_type_info{$_host}{$_})) {
                        &sara_split($_) if ($system eq "sara");
                        &saint_split($_) if ($system eq "saint");
                        &satan_split($_) if ($system eq "satan");

                         if ($severity_yellow_type_info{$service_output}) {
                          if (correction("$_host|$text") == 0 ) {
                            $_yellow_cnt = $_yellow_cnt + 1  if sans10($service_output);
                          }
			}
	    }
	}

        for (keys %{$severity_host_type_info{$_host}}) {
                ($_tutorials = $_) =~ tr / /_/;
                for (sort split(/\n/, $severity_host_type_info{$_host}{$_})) {
                        &sara_split($_) if ($system eq "sara");
                        &saint_split($_) if ($system eq "saint");
                        &satan_split($_) if ($system eq "satan");

                  $_severity= $severity_brown_type_info{$service_output};
                  if(($_severity)) {
                    $_pro_filter="FALSE";
                    if ($pro_filter) {
                      for (split(/\,/, $pro_filter)){
                        $_tmp = $_;
                        $_tmp =~ s/\ //;
                        if ( $_severity =~ "$_tmp") {
                          $_pro_filter = "TRUE";
                        }
                      }
                    }
                    if ($_pro_filter eq "FALSE") {
                     if (correction("$_host|$text") == 0 ) {
                       $_brown_cnt = $_brown_cnt + 1 if sans10($service_output);
                     }
                    }
                   }
             }
	}
if (exists($server_info{$_host})) {
        for (sort split(/\n/, $server_info{$_host})) {
	$_green_cnt = $_green_cnt + 1;
        }
}
if ( $hosttype{$_host} ne "not scanned") 
{
#    $_ip = &get_host_addr($_host);
     $_ip = $all_hosts{$_host}{IP};

#Kludge so that it will import into MS Word
    $hostname = $_host;
    $hostname =~ s/\./\_/g;
    $hostname =~ s/\-/\_/g;


    $todo = "print";
#  Check and see if filters are active
    if ($option ne "default"){
#  Filter out hosts without vulnerabilities
    if ($novul eq "on" || $sans eq "on") {
      if ( ( $_red_cnt+$_yellow_cnt+$_brown_cnt) == 0) {
        $todo="noprint";
      }
    }
#  Filter out all Windows
    if ( $hosttype{$_host} =~ /Windows/ ) {
      if ($nowin1 eq "on"){
        if (($_red_cnt+$_yellow_cnt) == 0) {
          $todo="noprint";
        }
      }elsif ($nowin eq "on"){
        $todo="noprint";
      }
    }
   }
   if ( $todo eq "print" || $chart_option eq "off") {
   if ($_green_cnt == 0 && $_red_cnt == 0 && $_yellow_cnt == 00 && $_brown_cnt == 0) {
     $black_bar = $black_bar + 1;
   }
   if ($_green_cnt > 0 && $_red_cnt == 0 && $_yellow_cnt == 0 && $_brown_cnt == 0){
     $green_bar = $green_bar + 1;
   }
   if ($_red_cnt > 0) {
     $red_bar = $red_bar + 1;
   }
   if ($_red_cnt == 0 && $_yellow_cnt > 0 ) {
     $yellow_bar = $yellow_bar +1;
   }
   if ($_red_cnt == 0 && $_yellow_cnt == 0 && $_brown_cnt > 0) {
     $brown_bar = $brown_bar + 1;
   }
}
}
