#  This software was derived from SATAN 1.1.1 by Dan Farmer and Wietse Venema
#  (http://www.porcupine.org/satan).
#
#
# Show information about a specific host.
#
($_host) = split(/,/, $html_script_args);
($_type = $hosttype{$_host}) =~ tr / \//+!/;

print CLIENT <<EOF;
<HTML>
<HEAD>
<SCRIPT language="JavaScript">
  function movepic(img_name,img_src) {
  document[img_name].src=img_src;
}
<!-- Begin
function NewWindow(mypage, myname, w, h, scroll) {
var winl = (screen.width - w) / 2;
var wint = (screen.height - h) / 2;
winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable'
win = window.open(mypage, myname, winprops)
if (parseInt(navigator.appVersion) >= 2) { win.window.focus(); }
}
//  End -->
</SCRIPT>
<title> Results - $_host </title>
<LINK REV="made" HREF="mailto:satan\@fish.com">
<LINK REV="updated" 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>
<TABLE BORDER="0" WIDTH="650"
<TR><TD BGCOLOR="#000000">
<Font Color="#FFFFFF">
<Center> <H2>Results - $_host</H2></Center>
</FONT>
</TD></TR></TABLE>
<UL>
<h3>General host information:</h3>
EOF

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

$_exists = 0;
$_dot = "blackdot";
$_alt = "BLACK";
if (exists($all_hosts{$_host})) {
  print CLIENT "<dt><IMG SRC=\"$HTML_ROOT/dots/$_dot.gif\" ALT=\"$_alt\">\n";
  print CLIENT "IP Address: $all_hosts{$_host}{'IP'}\n<BR>";
  if (exists($all_hosts{$_host})) {
    ($_subnet = $all_hosts{$_host}{IP}) =~ s/\.[^.]*$//;
    $_dot = "blackdot";
    print CLIENT <<EOF;
    <dt><IMG SRC="$HTML_ROOT/dots/$_dot.gif" ALT="$_alt">
    Subnet <A HREF="sara_results_subnet.pl,$_subnet,"> $_subnet </A>
EOF
    $_exists = 1;
  }
  $nbname = $domname = "";
  open (NB, $facts_file);
  while (<NB>) {
    chop;
    if (/Netbios Name/ && /$_host/) {
       @nb=split(/\|/,$_);
       $nbname  = $nb[7];
    } elsif (/Netbios Domain/ && /$_host/) {
       @dn = split(/\|/,$_);
       $domname = $dn[7];
    }
  }
  close NB;
  if($nbname) {
     print CLIENT "<dt><IMG SRC=\"$HTML_ROOT/dots/$_dot.gif\" ALT=\"$_alt\">\n";
     print CLIENT "NetBios Name: $nbname</A>\n<BR>";
  }
  if ($domname) {
     print CLIENT "<dt><IMG SRC=\"$HTML_ROOT/dots/$_dot.gif\" ALT=\"$_alt\">\n";
     print CLIENT "NetBios Domain: $domname</A>\n<BR>";
  }
}
if (exists($hosttype{$_host})) {
	print CLIENT <<EOF;
        <dt><IMG SRC="$HTML_ROOT/dots/$_dot.gif" ALT="$_alt">
	Host type: <A HREF="sara_info_OStype.pl,$_type,">$hosttype{$_host}</A>
EOF
	$_exists = 1;
}
if (exists($all_hosts{$_host}) && defined($all_hosts{$_host}{'attack'})) {
        @_level = ('none', 'light', 'normal', 'heavy', 'all out');
        print CLIENT <<EOF;
        <dt><IMG SRC="$HTML_ROOT/dots/$_dot.gif" ALT="$_alt">
        Scanning level: @_level[1 + $all_hosts{$_host}{'attack'}]
EOF
        $_exists = 1;
}

if (exists($all_hosts{$_host}) && defined($all_hosts{$_host}{'time'})
        && $all_hosts{$_host}{'time'} > 1) {
        $_time = &ctime($all_hosts{$_host}{'time'});
        print CLIENT <<EOF;
        <dt><IMG SRC="$HTML_ROOT/dots/$_dot.gif" ALT="$_alt">
        Last scan: $_time
EOF
        $_exists = 1;
}
$svc_cnt  = 0;
$svc_list = "";
$svc_hdr  = "<h3>Well Known Services Running:</h3>\n";
if (exists($server_info{$_host})) {
   for (sort split(/\n/, $server_info{$_host})) {
      ($_service = $_) =~ tr / \//+!/;
      $svc_list .= "<A HREF=\"sara_info_servers.pl,$_service,\">$_</A> ";
      $svc_cnt++;
      if ($svc_cnt >= 7) {
        $svc_list .= "<BR>\n";
        $svc_cnt  = 0;
      }
   }
   if ($svc_list) {
     $svc_hdr .= "$svc_list";
   } else {
     $svc_hdr  = "<dt><IMG SRC=\"$HTML_ROOT/dots/$_dot.gif\" ALT=\"$_alt\">No Services Running\n";
   }
   print CLIENT "$svc_hdr";
   $_exists = 1;
}

#if (exists($client_info{$_host})) {
#	for (sort split(/\n/, $client_info{$_host})) {
#		# Mask blanks and slashes
#		($_service = $_) =~ tr / \//+!/;
#		print CLIENT <<EOF;
#                <dt><IMG SRC="$HTML_ROOT/dots/$_dot.gif" ALT="$_alt">
#		<A HREF="sara_info_clients.pl,$_service,"> $_ </A> client
#EOF
#	}
#	$_exists = 1
#}

$vul    = "";
$fpvul  = "";
if (exists($severity_host_type_info{$_host})) {
	for (keys %{$severity_host_type_info{$_host}}) {
		($_tutorials = $_) =~ tr / /_/;
		for (sort split(/\n/, $severity_host_type_info{$_host}{$_})) {
	   	       &sara_split($_);
                         if($severity_red_type_info{$service_output}) {
                            $_dot = "reddot";
                            $_alt = "RED";
                           $cve = &get_cve($service_output, $text);
                           $TUT = "nvd/$cve.html";
                           $TUT = "nvd/NOCVE.html" if (! $cve);
                           $html_txt = "";
                           if ($html_txt = &get_sans($cve)) {
                              $html_txt = "<A HREF=\"http://www.sans.org/top20\">$html_txt</A>\n";
                           }
                           if (correction("$_host|$text") == 0 ) {
                              $_text  = $text;
                              $_text =~ s/ /%20/g;
                              $_text =~ s/\///g;
                              $vul .= "<A HREF=\"add_correction_form.pl,$_text\"\n";
                              $vul .= "onclick=\"NewWindow(this.href, 'name','380', '150','yes');return false;\">\n";
                              $vul .= "<IMG border=0 SRC=\"$HTML_ROOT/dots/$_dot.gif\" ALT=\"$_alt\"></A>";
	                      $vul .= "<A HREF=\"$HTML_ROOT/$TUT\">$text</A> $html_txt<BR>\n";
                           } else {
                              $_dot = "bluedot";
                              $_alt = "BLUE";
                              $_text  = $text;
                              $_text =~ s/ /%20/g;
                              $_text =~ s/\///g;
                              $fpvul .= "<A HREF=\"drop_correction_form.pl,$_text\"\n";
                              $fpvul .= "onclick=\"NewWindow(this.href, 'name','380', '150','yes');return false;\">\n";
                              $fpvul .= "<IMG border=0 SRC=\"$HTML_ROOT/dots/$_dot.gif\" ALT=\"$_alt\">";
                              $fpvul .= "<A HREF=\"$HTML_ROOT/$TUT\">$text</A> $html_txt<BR>\n";
                           }
                         }
		}
	}
	$_exists = 1;
        for (keys %{$severity_host_type_info{$_host}}) {
                for (sort split(/\n/, $severity_host_type_info{$_host}{$_})) {
                       &sara_split($_);
                         if($severity_yellow_type_info{$service_output}) {
                           $_dot = "yellowdot";
                           $_alt = "YELLOW";
                           $cve = &get_cve($service_output, $text);
                           $TUT = "nvd/$cve.html";
                           $TUT = "nvd/NOCVE.html" if (!$cve);
                           $html_txt = "";
                           if ($html_txt = &get_sans($cve)) {
                              $html_txt = "<A HREF=\"http://www.sans.org/top20\">$html_txt</A>\n";
                           }
                           if (correction("$_host|$text") == 0 ) {
                              $_text  = $text;
                              $_text =~ s/ /%20/g;
                              $_text =~ s/\///g;
                              $vul .= "<A HREF=\"add_correction_form.pl,$_text\"\n";
                              $vul .= "onclick=\"NewWindow(this.href, 'name','380', '150','yes');return false;\">\n";
                              $vul .= "<IMG border=0 SRC=\"$HTML_ROOT/dots/$_dot.gif\" ALT=\"$_alt\"></A>";
                              $vul .= "<A HREF=\"$HTML_ROOT/$TUT\">$text</A> $html_txt<BR>\n";
                           } else {
                              $_dot = "bluedot";
                              $_alt = "BLUE";
                              $_text  = $text;
                              $_text =~ s/ /%20/g;
                              $_text =~ s/\///g;
                              $fpvul .= "<A HREF=\"drop_correction_form.pl,$_text\"\n";
                              $fpvul .= "onclick=\"NewWindow(this.href, 'name','380', '150','yes');return false;\">\n";
                              $fpvul .= "<IMG border=0 SRC=\"$HTML_ROOT/dots/$_dot.gif\" ALT=\"$_alt\">";
                              $fpvul .= "<A HREF=\"$HTML_ROOT/$TUT\">$text</A> $html_txt<BR>\n";
                           }

                         }
                }
        }
        $_exists = 1;
        for (keys %{$severity_host_type_info{$_host}}) {
                ($_tutorials = $_) =~ tr / /_/;
                for (sort split(/\n/, $severity_host_type_info{$_host}{$_})) {
                       &sara_split($_);
                         if($severity_brown_type_info{$service_output}) {
                            $_dot = "browndot";
                            $_alt = "BROWN";
                           $cve = &get_cve($service_output, $text);
                           $TUT = "nvd/$cve.html";
                          $TUT = "nvd/NOCVE.html" if (! $cve);
                           $html_txt = "";
                           if ($html_txt = &get_sans($cve)) {
                              $html_txt = "<A HREF=\"http://www.sans.org/top20\">$html_txt</A>\n";
                           }
                           if (correction("$_host|$text") == 0 ) {
                              $_text  = $text;
                              $_text =~ s/ /%20/g;
                              $_text =~ s/\///g;
                              $vul .= "<A HREF=\"add_correction_form.pl,$_text\"\n";
                              $vul .= "onclick=\"NewWindow(this.href, 'name','380', '150','yes');return false;\">\n";
                              $vul .= "<IMG border=0 SRC=\"$HTML_ROOT/dots/$_dot.gif\" ALT=\"$_alt\"></A>";
                              $vul .= "<A HREF=\"$HTML_ROOT/$TUT\">$text</A> $html_txt<BR>\n";
                           } else {
                              $_dot = "bluedot";
                              $_alt = "BLUE";
                              $_text  = $text;
                              $_text =~ s/ /%20/g;
                              $_text =~ s/\///g;
                              $fpvul .= "<A HREF=\"drop_correction_form.pl,$_text\"\n";
                              $fpvul .= "onclick=\"NewWindow(this.href, 'name','380', '150','yes');return false;\">\n";
                              $fpvul .= "<IMG border=0 SRC=\"$HTML_ROOT/dots/$_dot.gif\" ALT=\"$_alt\">";
                              $fpvul .= "<A HREF=\"$HTML_ROOT/$TUT\">$text</A> $html_txt<BR>\n";
                           }

                         }
                }
        }
        $_exists = 1;

}
if ($vul) {
   print CLIENT "<h3>Vulnerability information:</h3>\n";
   print CLIENT "$vul\n";
}
if ($fpvul) {
   print CLIENT "<h3>False positive information:</h3>\n";
   print CLIENT "$fpvul\n";
}
# List host service info

if ($_exists) {
        $_dot = "blackdot";
	print CLIENT <<EOF;
	<h3>Actions:</h3>
        <dt><IMG SRC="/dots/$_dot.gif" ALT="$_alt">
        Click on colored dot to change status<BR>
        <dt><IMG SRC="/dots/$_dot.gif" ALT="$_alt">
        Click on vulnerability to read tutorial<BR>
        <dt><IMG SRC="/dots/$_dot.gif" ALT="$_alt">
	<A HREF="/running/sara_run_form.pl,$_host,">Scan this host</a>
EOF
} else {
	print CLIENT <<EOF;
	<h3>No information found on host $_host.</h3>
EOF
}

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