%dataset = ();
do "config/saintwriter/saintwriter.cf";

%report_checked = ();
if ($report =~ /^(full|long_exec|short_exec|tech|linked_tech|detail|trend)$/) {
    $report_checked{$report} = "checked";
} else {
    $report_checked{"other"} = "checked";
}
@format_checked = ();
$format_checked[$format] = "selected";
$report_title =~ s/\+/ /g;
$riskwatch_checked = ($riskwatch eq "on") ? "checked" : "";

print CLIENT <<EOF
<HTML>
<HEAD>
<TITLE>SAINTwriter</TITLE>
<LINK REV="made" HREF="mailto:saint\@saintcorporation.com">
</HEAD>
<BODY BGCOLOR="white" vlink="#000000" link="#04289D">

<P></P>

<P>
<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0">
	<TR>
		<TD COLSPAN="2"><IMG SRC="$HTML_ROOT/images/saintwriter_config_banner.gif" WIDTH="621" HEIGHT="106" ALIGN="BOTTOM" ALT="Configuration Management" 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>
<FORM METHOD=POST ACTION=saintwriter_action.pl>
EOF
;
if (-x "bin/saintwriter") {
  open (SERIAL, "bin/saintwriter -s|");
  $serial = <SERIAL>;
  close (SERIAL);
  print CLIENT "Serial Number  <tt>$serial</tt><BR>"
} else {
  print CLIENT "Serial Number  <tt>none: SAINTwriter not installed</tt><BR>\n";
  print CLIENT "See <A HREF=\"http://www.saintcorporation.com/saintwriter\">http://www.saintcorporation.com/saintwriter</A><P>\n";
}
print CLIENT <<EOF
<P>Report type:
<DL>
<DT><INPUT TYPE=radio NAME="report" VALUE="full" $report_checked{full}><B>Full Report</B>
<DD>All available information, including charts, tables, host lists, vulnerability
lists, and technical details.
<DT><INPUT TYPE=radio NAME="report" VALUE="short_exec" $report_checked{short_exec}><B>Short Executive Report</B>
<DD>Bar graphs which summarize the vulnerabilities found on the
network. This report is best for quickly identifying the biggest problem
areas on the network. (Use HTML format.)
<DT><INPUT TYPE=radio NAME="report" VALUE="long_exec" $report_checked{long_exec}><B>Long Executive Report</B>
<DD>Pie charts, bar graphs, and tables which summarize the vulnerabilities
found on the network. (Use HTML format. Pie charts are only visible in
Internet Explorer browsers.)
<DT><INPUT TYPE=radio NAME="report" VALUE="tech" $report_checked{tech}><B>Technical Overview</B>
<DD>Lists of hosts, vulnerabilities, services, and associated information. This report
is best for planning a remediation strategy, or for importing into spreadsheet
or database applications.
<DT><INPUT TYPE=radio NAME="report" VALUE="linked_tech" $report_checked{linked_tech}><B>Linked Technical Overview</B>
<DD>List of vulnerabilities and associated information, hyperlinked to an
appendix containing technical details on each vulnerability. (Use HTML format.)
<DT><INPUT TYPE=radio NAME="report" VALUE="detail" $report_checked{detail}><B>Technical Details</B>
<DD>Long report containing technical details on each vulnerability. This report
is the most helpful to the administrator responsible for implementing the fixes.
<DT><INPUT TYPE=radio NAME="report" VALUE="trend" $report_checked{trend}><B>Trend Analysis</B>
<FONT COLOR=red><I>Requires SAINTwriter&#153; 2.0 or higher</I></FONT>
<DD>Full report which includes tracking of hosts and vulnerabilities
chronologically across multiple data sets.
<DD><I>Choose data sets to analyze:</I>
EOF
;
for $data_set (<results/*>) {
    if (-f "$data_set/facts") {
	$data_set =~ s#results/##;
	$var = "dataset_" . $data_set;
	$checked = ($dataset{$data_set} eq "on") ? "checked" : "";
	print CLIENT "<INPUT TYPE=checkbox NAME=\"$var\" $checked>$data_set\n";
    }
}
print CLIENT <<EOF
<DT><INPUT TYPE=radio NAME="report" VALUE="other" $report_checked{other}><B>Other</B>
EOF
;
@saved_configs = <config/saintwriter/*.cf>;
if ($#saved_configs > 7) {
  print CLIENT "<DD><I>Saved report type:</I>&nbsp;<SELECT NAME=\"saved\">\n";
  print CLIENT "<OPTION></OPTION>\n";
  for (@saved_configs) {
    s/config\/saintwriter\/(.*)\.cf/$1/;
    if (!/^(saintwriter|full|long_exec|short_exec|tech|linked_tech|detail|trend)$/) {
	print CLIENT "<OPTION>$_</OPTION>\n"
    }
  }
  print CLIENT "</SELECT>\n";
  print CLIENT "<INPUT TYPE=checkbox NAME=customize>Modify\n";
}
print CLIENT <<EOF
<DD><I>New report type</I>&nbsp;File name:<INPUT TYPE=text NAME=new_file SIZE=15>
Template:<SELECT NAME=template>
<OPTION VALUE="full">Full</OPTION>
<OPTION VALUE="short_exec">Short Executive</OPTION>
<OPTION VALUE="long_exec">Long Executive</OPTION>
<OPTION VALUE="tech">Technical Overview</OPTION>
<OPTION VALUE="linked_tech">Linked Tech. Overview</OPTION>
<OPTION VALUE="detail">Technical Details</OPTION>
<OPTION VALUE="trend">Trend Analysis</OPTION>
</SELECT>
</DL>
<HR>
Report title: <INPUT TYPE=text NAME="report_title" VALUE="$report_title" SIZE=32>
<BR>Report format:
<SELECT NAME="format">
<OPTION VALUE="0" $format_checked[0]>HTML</OPTION>
<OPTION VALUE="1" $format_checked[1]>Text</OPTION>
<OPTION VALUE="2" $format_checked[2]>Tab-separated text</OPTION>
<OPTION VALUE="3" $format_checked[3]>Comma-separated text</OPTION>
</SELECT>
<BR><INPUT TYPE=checkbox NAME="riskwatch" $riskwatch_checked> Export to RiskWatch
<FONT COLOR=red><I>Requires SAINTwriter&#153; 2.0 or higher</I></FONT>
<INPUT TYPE="hidden" NAME="data_dir" VALUE="$saint_data">
<INPUT TYPE="hidden" NAME="exclusions_file" VALUE="$Exclusions::savefile">
<P><INPUT TYPE="submit" VALUE="Continue">
</FORM>
	  </TD>
	</TR>
</TABLE>
</BODY>
</HTML>
EOF
