#
# Collect data and keep the user informed.
#

#
# Make sure they specified a host at all.
#
if (($primary_target eq "" && !$use_target_file) ||
    ($target_file eq "" && $use_target_file)) {
	print CLIENT <<EOF
<HTML>
<HEAD>
<TITLE>Error - Missing input </TITLE>
<LINK REV="made" HREF="mailto:saint\@saintcorporation.com">
</HEAD>
<BODY BGCOLOR="white">

<P></P>

<P>
<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0">
	<TR>
		<TD COLSPAN="2"><IMG SRC="$HTML_ROOT/images/target_sel_banner.gif" WIDTH="621" HEIGHT="106" ALIGN="BOTTOM" ALT="Target Selection" BORDER="0"></TD>
	</TR>
	<TR>
	  <TD WIDTH="86" VALIGN="TOP">
	    <TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0">
		<TR>
		    <TD WIDTH="86"><A HREF="http://www.saintcorporation.com"><IMG SRC="$HTML_ROOT/images/home.gif" WIDTH="86" HEIGHT="55" ALIGN="BOTTOM" ALT="SAINT Corporation"
			BORDER="0"></A></TD>
		</TR>
		<TR>
		    <TD WIDTH="86"><A HREF="$HTML_ROOT/saint.html"><IMG SRC="$HTML_ROOT/images/home_button.gif" WIDTH="86" HEIGHT="46"
			ALIGN="BOTTOM" ALT="SAINT Home" BORDER="0" STYLE="Background-Image : none"></A></TD>
		</TR>
		<TR>
		    <TD WIDTH="86"><A HREF="$HTML_SERVER/data/saint_data_form.pl"><IMG SRC="$HTML_ROOT/images/data_mgmt_button.gif" WIDTH="86"
			HEIGHT="46" ALIGN="BOTTOM" ALT="Data Management" BORDER="0"></A></TD>
		</TR>
		<TR>
		    <TD WIDTH="86"><A HREF="$HTML_SERVER/running/saint_run_form.pl"><IMG SRC="$HTML_ROOT/images/target_selection_button.gif"
			WIDTH="86" HEIGHT="46" ALIGN="BOTTOM" ALT="Target Selection" BORDER="0"></A></TD>
		</TR>
		<TR>
		    <TD WIDTH="86"><A HREF="$HTML_SERVER/reporting/analysis.pl"><IMG SRC="$HTML_ROOT/images/data_analysis_button.gif" WIDTH="86"
			HEIGHT="46" ALIGN="BOTTOM" ALT="Data Analysis" BORDER="0"></A></TD>
		</TR>
		<TR>
		    <TD WIDTH="86"><A HREF="$HTML_SERVER/admin/saint_cf_form.pl"><IMG SRC="$HTML_ROOT/images/config_mgmt_button.gif" WIDTH="86"
			HEIGHT="46" ALIGN="BOTTOM" ALT="Configuration Management" BORDER="0"></A></TD>
		</TR>
		<TR>
		    <TD WIDTH="86"><A HREF="$HTML_ROOT/saint_documentation.html"><IMG SRC="$HTML_ROOT/images/documentation_button.gif"
			WIDTH="86" HEIGHT="46" ALIGN="BOTTOM" ALT="SAINT Documentation" BORDER="0"></A></TD>
		</TR>
		<TR>
		    <TD WIDTH="86" HEIGHT="46"><A HREF="$HTML_ROOT/docs/FAQ.html#trouble"><IMG SRC="$HTML_ROOT/images/troubleshooting_button.gif" WIDTH="86"
			HEIGHT="46" ALIGN="BOTTOM" ALT="Troubleshooting" BORDER="0"></A></TD>
		</TR>
		<TR>
		    <TD WIDTH="86" HEIGHT="65"><IMG SRC="$HTML_ROOT/images/bottom_border.gif" WIDTH="86" HEIGHT="75" ALIGN="BOTTOM" ALT="--------" BORDER="0"></TD>
		</TR>
	    </TABLE>
	  </TD>
	  <TD VALIGN="TOP">
		<DL>
			<P>
		</DL>
<H1> Error - Missing input </H1>
<hr>
No primary host or network was specified.
	  </TD>
	</TR>
</TABLE>
</BODY>
</HTML>
EOF
;
	die "\n";
}

if ($use_target_file) {
  if (open(TARGET_FILE, $target_file)) {
    $primary_target = "";  
    while (<TARGET_FILE>) {
      chop;
      $primary_target = $primary_target . $_ . " " if $_;
    }
    close(TARGET_FILE);
  } else {
    print CLIENT <<EOF
<HTML>
<HEAD>
<TITLE>Error - Cannot open target file </TITLE>
<LINK REV="made" HREF="mailto:saint\@saintcorporation.com">
</HEAD>
<BODY BGCOLOR="white">

<P></P>

<P>
<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0">
	<TR>
		<TD COLSPAN="2"><IMG SRC="$HTML_ROOT/images/target_sel_banner.gif" WIDTH="621" HEIGHT="106" ALIGN="BOTTOM" ALT="Target Selection" BORDER="0"></TD>
	</TR>
	<TR>
	  <TD WIDTH="86" VALIGN="TOP">
	    <TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0">
		<TR>
		    <TD WIDTH="86"><A HREF="http://www.saintcorporation.com"><IMG SRC="$HTML_ROOT/images/home.gif" WIDTH="86" HEIGHT="55" ALIGN="BOTTOM" ALT="SAINT Corporation"
			BORDER="0"></A></TD>
		</TR>
		<TR>
		    <TD WIDTH="86"><A HREF="$HTML_ROOT/saint.html"><IMG SRC="$HTML_ROOT/images/home_button.gif" WIDTH="86" HEIGHT="46"
			ALIGN="BOTTOM" ALT="SAINT Home" BORDER="0" STYLE="Background-Image : none"></A></TD>
		</TR>
		<TR>
		    <TD WIDTH="86"><A HREF="$HTML_SERVER/data/saint_data_form.pl"><IMG SRC="$HTML_ROOT/images/data_mgmt_button.gif" WIDTH="86"
			HEIGHT="46" ALIGN="BOTTOM" ALT="Data Management" BORDER="0"></A></TD>
		</TR>
		<TR>
		    <TD WIDTH="86"><A HREF="$HTML_SERVER/running/saint_run_form.pl"><IMG SRC="$HTML_ROOT/images/target_selection_button.gif"
			WIDTH="86" HEIGHT="46" ALIGN="BOTTOM" ALT="Target Selection" BORDER="0"></A></TD>
		</TR>
		<TR>
		    <TD WIDTH="86"><A HREF="$HTML_SERVER/reporting/analysis.pl"><IMG SRC="$HTML_ROOT/images/data_analysis_button.gif" WIDTH="86"
			HEIGHT="46" ALIGN="BOTTOM" ALT="Data Analysis" BORDER="0"></A></TD>
		</TR>
		<TR>
		    <TD WIDTH="86"><A HREF="$HTML_SERVER/admin/saint_cf_form.pl"><IMG SRC="$HTML_ROOT/images/config_mgmt_button.gif" WIDTH="86"
			HEIGHT="46" ALIGN="BOTTOM" ALT="Configuration Management" BORDER="0"></A></TD>
		</TR>
		<TR>
		    <TD WIDTH="86"><A HREF="$HTML_ROOT/saint_documentation.html"><IMG SRC="$HTML_ROOT/images/documentation_button.gif"
			WIDTH="86" HEIGHT="46" ALIGN="BOTTOM" ALT="SAINT Documentation" BORDER="0"></A></TD>
		</TR>
		<TR>
		    <TD WIDTH="86" HEIGHT="46"><A HREF="$HTML_ROOT/docs/FAQ.html#trouble"><IMG SRC="$HTML_ROOT/images/troubleshooting_button.gif" WIDTH="86"
			HEIGHT="46" ALIGN="BOTTOM" ALT="Troubleshooting" BORDER="0"></A></TD>
		</TR>
		<TR>
		    <TD WIDTH="86" HEIGHT="65"><IMG SRC="$HTML_ROOT/images/bottom_border.gif" WIDTH="86" HEIGHT="75" ALIGN="BOTTOM" ALT="--------" BORDER="0"></TD>
		</TR>
	    </TABLE>
	  </TD>
	  <TD VALIGN="TOP">
		<DL>
			<P>
		</DL>
<H1> Error - Cannot open target file </H1>
<hr>
The specified target file could not be opened.
	  </TD>
	</TR>
</TABLE>
</BODY>
</HTML>
EOF
;
	die "\n";
  }
} else {
  # convert plusses from HTML form to spaces  
  $primary_target =~ s/\+/ /g;
}

# remove spaces around dashes, so ranges will not
# be parsed apart
$primary_target =~ s/\s*-\s*/-/g;

#
# Check each primary target
# If a host name was specified look up the official name.
#
@all_primaries = split (/\s+/, $primary_target);
if ($#all_primaries < 0) {
  print CLIENT <<EOF
<HTML>
<HEAD>
<TITLE>Error - Missing Input </TITLE>
<LINK REV="made" HREF="mailto:saint\@saintcorporation.com">
</HEAD>
<BODY BGCOLOR="white">

<P></P>

<P>
<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0">
	<TR>
		<TD COLSPAN="2"><IMG SRC="$HTML_ROOT/images/target_sel_banner.gif" WIDTH="621" HEIGHT="106" ALIGN="BOTTOM" ALT="Target Selection" BORDER="0"></TD>
	</TR>
	<TR>
	  <TD WIDTH="86" VALIGN="TOP">
	    <TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0">
		<TR>
		    <TD WIDTH="86"><A HREF="http://www.saintcorporation.com"><IMG SRC="$HTML_ROOT/images/home.gif" WIDTH="86" HEIGHT="55" ALIGN="BOTTOM" ALT="SAINT Corporation"
			BORDER="0"></A></TD>
		</TR>
		<TR>
		    <TD WIDTH="86"><A HREF="$HTML_ROOT/saint.html"><IMG SRC="$HTML_ROOT/images/home_button.gif" WIDTH="86" HEIGHT="46"
			ALIGN="BOTTOM" ALT="SAINT Home" BORDER="0" STYLE="Background-Image : none"></A></TD>
		</TR>
		<TR>
		    <TD WIDTH="86"><A HREF="$HTML_SERVER/data/saint_data_form.pl"><IMG SRC="$HTML_ROOT/images/data_mgmt_button.gif" WIDTH="86"
			HEIGHT="46" ALIGN="BOTTOM" ALT="Data Management" BORDER="0"></A></TD>
		</TR>
		<TR>
		    <TD WIDTH="86"><A HREF="$HTML_SERVER/running/saint_run_form.pl"><IMG SRC="$HTML_ROOT/images/target_selection_button.gif"
			WIDTH="86" HEIGHT="46" ALIGN="BOTTOM" ALT="Target Selection" BORDER="0"></A></TD>
		</TR>
		<TR>
		    <TD WIDTH="86"><A HREF="$HTML_SERVER/reporting/analysis.pl"><IMG SRC="$HTML_ROOT/images/data_analysis_button.gif" WIDTH="86"
			HEIGHT="46" ALIGN="BOTTOM" ALT="Data Analysis" BORDER="0"></A></TD>
		</TR>
		<TR>
		    <TD WIDTH="86"><A HREF="$HTML_SERVER/admin/saint_cf_form.pl"><IMG SRC="$HTML_ROOT/images/config_mgmt_button.gif" WIDTH="86"
			HEIGHT="46" ALIGN="BOTTOM" ALT="Configuration Management" BORDER="0"></A></TD>
		</TR>
		<TR>
		    <TD WIDTH="86"><A HREF="$HTML_ROOT/saint_documentation.html"><IMG SRC="$HTML_ROOT/images/documentation_button.gif"
			WIDTH="86" HEIGHT="46" ALIGN="BOTTOM" ALT="SAINT Documentation" BORDER="0"></A></TD>
		</TR>
		<TR>
		    <TD WIDTH="86" HEIGHT="46"><A HREF="$HTML_ROOT/docs/FAQ.html#trouble"><IMG SRC="$HTML_ROOT/images/troubleshooting_button.gif" WIDTH="86"
			HEIGHT="46" ALIGN="BOTTOM" ALT="Troubleshooting" BORDER="0"></A></TD>
		</TR>
		<TR>
		    <TD WIDTH="86" HEIGHT="65"><IMG SRC="$HTML_ROOT/images/bottom_border.gif" WIDTH="86" HEIGHT="75" ALIGN="BOTTOM" ALT="--------" BORDER="0"></TD>
		</TR>
	    </TABLE>
	  </TD>
	  <TD VALIGN="TOP">
		<DL>
			<P>
		</DL>
<H1> Error - Missing Input </H1>
<hr>
No primary host or network was specified.
	  </TD>
	</TR>
</TABLE>
</BODY>
</HTML>
EOF
;
	die "\n";
}
for (@all_primaries) {
  if ($_ !~ /^\d+\./) {
	$tmp_target = &getfqdn(&get_host_name(&get_host_addr($_)));
	if ($tmp_target eq "") {
		print CLIENT <<EOF
<HTML>
<HEAD>
<TITLE>Error - Unknown host</TITLE>
<LINK REV="made" HREF="mailto:saint\@saintcorporation.com">
</HEAD>
<BODY BGCOLOR="white">

<P></P>

<P>
<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0">
	<TR>
		<TD COLSPAN="2"><IMG SRC="$HTML_ROOT/images/target_sel_banner.gif" WIDTH="621" HEIGHT="106" ALIGN="BOTTOM" ALT="Target Selection" BORDER="0"></TD>
	</TR>
	<TR>
	  <TD WIDTH="86" VALIGN="TOP">
	    <TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0">
		<TR>
		    <TD WIDTH="86"><A HREF="http://www.saintcorporation.com"><IMG SRC="$HTML_ROOT/images/home.gif" WIDTH="86" HEIGHT="55" ALIGN="BOTTOM" ALT="SAINT Corporation"
			BORDER="0"></A></TD>
		</TR>
		<TR>
		    <TD WIDTH="86"><A HREF="$HTML_ROOT/saint.html"><IMG SRC="$HTML_ROOT/images/home_button.gif" WIDTH="86" HEIGHT="46"
			ALIGN="BOTTOM" ALT="SAINT Home" BORDER="0" STYLE="Background-Image : none"></A></TD>
		</TR>
		<TR>
		    <TD WIDTH="86"><A HREF="$HTML_SERVER/data/saint_data_form.pl"><IMG SRC="$HTML_ROOT/images/data_mgmt_button.gif" WIDTH="86"
			HEIGHT="46" ALIGN="BOTTOM" ALT="Data Management" BORDER="0"></A></TD>
		</TR>
		<TR>
		    <TD WIDTH="86"><A HREF="$HTML_SERVER/running/saint_run_form.pl"><IMG SRC="$HTML_ROOT/images/target_selection_button.gif"
			WIDTH="86" HEIGHT="46" ALIGN="BOTTOM" ALT="Target Selection" BORDER="0"></A></TD>
		</TR>
		<TR>
		    <TD WIDTH="86"><A HREF="$HTML_SERVER/reporting/analysis.pl"><IMG SRC="$HTML_ROOT/images/data_analysis_button.gif" WIDTH="86"
			HEIGHT="46" ALIGN="BOTTOM" ALT="Data Analysis" BORDER="0"></A></TD>
		</TR>
		<TR>
		    <TD WIDTH="86"><A HREF="$HTML_SERVER/admin/saint_cf_form.pl"><IMG SRC="$HTML_ROOT/images/config_mgmt_button.gif" WIDTH="86"
			HEIGHT="46" ALIGN="BOTTOM" ALT="Configuration Management" BORDER="0"></A></TD>
		</TR>
		<TR>
		    <TD WIDTH="86"><A HREF="$HTML_ROOT/saint_documentation.html"><IMG SRC="$HTML_ROOT/images/documentation_button.gif"
			WIDTH="86" HEIGHT="46" ALIGN="BOTTOM" ALT="SAINT Documentation" BORDER="0"></A></TD>
		</TR>
		<TR>
		    <TD WIDTH="86" HEIGHT="46"><A HREF="$HTML_ROOT/docs/FAQ.html#trouble"><IMG SRC="$HTML_ROOT/images/troubleshooting_button.gif" WIDTH="86"
			HEIGHT="46" ALIGN="BOTTOM" ALT="Troubleshooting" BORDER="0"></A></TD>
		</TR>
		<TR>
		    <TD WIDTH="86" HEIGHT="65"><IMG SRC="$HTML_ROOT/images/bottom_border.gif" WIDTH="86" HEIGHT="75" ALIGN="BOTTOM" ALT="--------" BORDER="0"></TD>
		</TR>
	    </TABLE>
	  </TD>
	  <TD VALIGN="TOP">
		<DL>
			<P>
		</DL>
<H1>Error - Unknown host</H1>
<hr>
Unable to look up host <TT> $_ </TT>
	  </TD>
	</TR>
</TABLE>
</BODY>
</HTML>
EOF
;	
		die "\n";
	}
	$_ = $tmp_target;
  }
  else {
	$tmp_target = "";
  }
}

#
# Primary targets are OK, start data collection.
#
print CLIENT <<EOF
<HTML>
<HEAD>
<TITLE>SAINT data collection </TITLE>
<LINK REV="made" HREF="mailto:saint\@saintcorporation.com">
</HEAD>
<BODY BGCOLOR=#FFFFFF>
<H1>SAINT data collection</H1>
<hr>
<B>Data collection in progress...</B>

<P>

EOF
;
$all_attacks[5] = \@$custom_level;

$_live_hosts = $live_hosts;

&run_saint(join(' ', @all_primaries));

$_live_hosts = $live_hosts - $_live_hosts;

print CLIENT <<EOF;
<P>

<B>Data collection completed ($_live_hosts host(s) visited).</B>
<hr> <a href=$HTML_STARTPAGE> Back to the SAINT start page </a> |
<a href=../reporting/analysis.pl>Continue with report and analysis</a>
EOF

if (&getfqdn($tmp_target) && $#all_primaries==0) {
	print CLIENT <<EOF;
| <a href="../reporting/saint_info_host.pl,$tmp_target,">
View primary target results</a>
EOF
}
print CLIENT <<EOF
</BODY>
</HTML>
EOF
