#  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 without proper 
#  credit to SARA (tm) and the Advanced Research Corporation (r).
#  
#
#  Developed and distributed by the Advanced Research Corporation.
require 'config/sara.cf';
$xml_file = "results/$sara_data/$report_xml";
$csv_file = "results/$sara_data/$report_csv";
$htm_file = "results/$sara_data/$report_htm";
$old_vuls = $novul;
$novul   = $novuls;
select CLIENT;
 if ($regenerate eq "on") {
   $old_correction = $correction;
   $correction = $corrections;
   &read_sara_data();
   &save_xml($xml_file);
   &save_csv($csv_file);
   &save_htm($htm_file);
   $correction = $old_correction;
 } 
  $novul = $old_vuls;
  $report_flag = 0;
  if ($report_type eq "html") {
    open(TMP,"$htm_file");
    while (<TMP>) {
      $report_flag = 1;
      print CLIENT "$_";
    }
    close(TMP);
  } elsif($report_type eq "xml") {
    open(TMP,"$xml_file");
    while (<TMP>) {
      $report_flag = 1;
      chomp;
      $_ =~ s/\</\&lt;/g;
      $_ =~ s/\</\&gt;/g;
      $_ =~ s/ /\&nbsp\;/g;
      print CLIENT "$_ <BR>\n";
    }
    close(TMP);
  } elsif($report_type eq "comma") {
    open(TMP,"$csv_file");
    print CLIENT "<PRE>\n";
    while (<TMP>) {
      $report_flag = 1;
      chomp;
      $_ =~ s/\</\&lt;/g;
      $_ =~ s/\</\&gt;/g;
      print CLIENT "$_ <BR>\n";
    }
    print CLIENT "</PRE>\n";
    close(TMP);
  }
  if ($report_flag == 0) {
    print CLIENT <<EOF;
    <TITLE>No Report</TITLE>
<TABLE BORDER="0" WIDTH="650"
<TR><TD BGCOLOR="#000000">
<Font Color="#FFFFFF">
<Center> <H2>No Report</H2></Center>
</FONT>
</TD></TR></TABLE>
    <P>
    No reports were generated.  Go back to 
    <A HREF="$HTML_SERVER/running/sara_report_form.pl">ReportWriter </A>
    and select "Regenerate".
EOF
  }

