#  This software was derived from SATAN 1.1.1 by Dan Farmer and Wietse Venema
#  (http://www.porcupine.org/satan).
#
#
# Collect data and keep the user informed.
#

require "perl/config.pl";

#
# Make sure they specified a data file
if ($sara_data eq "") {
	print CLIENT <<EOF;
<HTML>
<HEAD>
<TITLE>Error - Missing input (no SARA data file found)</TITLE>
<LINK REV="made" HREF="mailto:satan\@fish.com">
<LINK REV="update" HREF="mailto:sara\@arc.com">
</HEAD>
<BODY>
<H1><IMG SRC=$HTML_ROOT/images/sara.gif> Error - Missing input </H1>
<hr>
No data directory was specified.
</BODY>
</HTML>
EOF
	die "\n";
	}

#
#Build custom attack strings
#
if ($custom0_mode == 0) {
  $custom_0="";
  $custom_0_string ="discovery only";
}
elsif ($custom0_mode == 1) {
  $custom_0 = "";
  $custom_0_string ="";
  if ($dns0 eq "on") {
    $custom_0 .= "dns_chk.sara|";
    $custom_0_string .= 'DNS,';
  } else {
    $dns0="off";
    $html_post_attributes .=  "\ndns0=off";
  }

  if ($smb0 eq "on") {
    $custom_0 .= "udpscan.sara 137|tcpscan.sara 139|";
    $custom_0_string .= 'SMB,';
  } else {
    $smb0="off";
    $html_post_attributes .=  "\nsmb0=off";
  }
  if ($http0 eq "on") {
    $custom_0 .= "tcpscan.sara 80,139|";
    $custom_0_string .= 'Web,';
  } else {
    $http0="off";
    $html_post_attributes .=  "\nhttp0=off";
  }
  if ($mail0 eq "on") {
    $custom_0 .= "tcpscan.sara 25|";
    $custom_0_string .= 'Mail,';
  } else {
    $mail0="off";
    $html_post_attributes .=  "\nmail0=off";
  }
  if ($tel0 eq "on") {
    $custom_0 .= "tcpscan.sara 23|";
    $custom_0_string .= 'Telnet,';
  } else {
    $tel0="off";
    $html_post_attributes .=  "\ntel0=off";
  }
  if ($ftp0 eq "on") {
    $custom_0 .= "tcpscan.sara 21|";
    $custom_0_string .= 'FTP,';
  } else {
    $ftp0="off";
    $html_post_attributes .=  "\nftp0=off";
  }
  if ($rpc0 eq "on") {
    $custom_0 .= "rpc.sara|showmount.sara|";
    $custom_0_string .= 'RPC,';
  } else {
    $rpc0="off";
    $html_post_attributes .=  "\nrpc0=off";
  }
  $custom_0 .= '*?|';
}
elsif ($custom0_mode == 2) {
  $custom_0  = "tcpscan.sara $custom0_tcp|" if $custom0_tcp;
  $custom_0 .= "udpscan.sara $custom0_udp|" if $custom0_udp;
  $custom_0 .= "*?|";
  $custom_0_string = "";
  $custom_0_string .= "TCP scan of $custom0_tcp," if $custom0_tcp;
  $custom_0_string .= "UDP scan of $custom0_udp"  if $custom0_udp;
}
$custom0_cmd = $custom_0;
$custom_0 = "custom0_cmd=$custom0_cmd";
$custom_0_string =~ s/\,$//;
$custom_0_string =  "Custom($custom_0_string)";
$custom0_string = $custom_0_string;
$custom_0_string = "custom0_string=$custom0_string";

$html_post_attributes .= " \n$custom_0\n$custom_0_string\n";
$cf_dns0 = $cf_smb0 = $cf_http0 = $cf_mail0 = $cf_tel0 = $cf_ftp0 = $cf_rpc0 ="";

if ($custom1_mode == 0) {
  $custom_1='';
  $custom_1_string ="discovery only";
}
elsif ($custom1_mode == 1) {
  $custom_1 = "";
  $custom_1_string ="";
  if ($dns1 eq "on") {
    $custom_1 .= "dns_chk.sara|";
    $custom_1_string .= 'DNS,';
  } else {
    $dns1="off";
    $html_post_attributes .=  "\ndns1=off";
  }
  if ($smb1 eq "on") {
    $custom_1 .=  "udpscan.sara 137|tcpscan.sara 139|";
    $custom_1_string .= 'SMB,';
  } else {
    $smb1="off";
    $html_post_attributes .=  "\nsmb1=off";
  }
  if ($http1 eq "on") {
    $custom_1 .= "tcpscan.sara 80,tcpscan.sara 139|";
    $custom_1_string .= 'Web,';
  } else {
    $http1="off";
    $html_post_attributes .=  "\nhttp1=off";
  }
  if ($mail1 eq "on") {
    $custom_1 .= "tcpscan.sara 25|";
    $custom_1_string .= 'Mail,';
  } else {
    $mail1="off";
    $html_post_attributes .=  "\nmail1=off";
  }
  if ($tel1 eq "on") {
    $custom_1 .= "tcpscan.sara 23|";
    $custom_1_string .= 'Telnet,';
  } else {
    $tel1="off";
    $html_post_attributes .=  "\ntel1=off";
  }
  if ($ftp1 eq "on") {
    $custom_1 .= "tcpscan.sara 21|";
    $custom_1_string .= 'FTP,';
  } else {
    $ftp1="off";
    $html_post_attributes .=  "\nftp1=off";
  }
  if ($rpc1 eq "on") {
    $custom_1 .= "rpc.sara|showmount.sara|";
    $custom_1_string .= 'RPC,';
  } else {
    $rpc1="off";
    $html_post_attributes .=  "\nrpc1=off";
  }
  $custom_1 .= '*?|';
}
elsif ($custom1_mode == 2) {
  $custom_1  = "tcpscan.sara $custom1_tcp|" if $custom1_tcp;
  $custom_1 .= "udpscan.sara $custom1_udp|" if $custom1_udp;
  $custom_1 .= "*?|";
  $custom_1_string = "";
  $custom_1_string .= "TCP scan of $custom1_tcp," if $custom1_tcp;
  $custom_1_string .= "UDP scan of $custom1_udp"  if $custom1_udp;
}
$custom1_cmd = $custom_1;
$custom_1 = "custom1_cmd=$custom1_cmd";
$custom_1_string =~ s/\,$//;
$custom_1_string =  "Custom($custom_1_string)";
$custom1_string = $custom_1_string;
$custom_1_string = "custom1_string=$custom1_string";
$html_post_attributes .= " \n$custom_1\n$custom_1_string\n";
$cf_dns1 = $cf_smb1 = $cf_http1 = $cf_mail1 = $cf_tel1 = $cf_ftp1 = $cf_rpc1 =""
;

if ($custom2_mode == 0) {
  $custom_2="";
  $custom_2_string ="discovery only";
}
elsif ($custom2_mode == 1) {
  $custom_2 = "";
  $custom_2_string ="";
  if ($dns2 eq "on") {
    $custom_2 .= "dns_chk.sara|";
    $custom_2_string .= 'DNS,';
  } else {
    $dns2="off";
    $html_post_attributes .=  "\ndns2=off";
  }

  if ($smb2 eq "on") {
    $custom_2 .=  "udpscan.sara 137|tcpscan.sara 139|";
    $custom_2_string .= 'SMB,';
  } else {
    $smb2="off";
    $html_post_attributes .=  "\nsmb2=off";
  }
  if ($http2 eq "on") {
    $custom_2 .= "tcpscan.sara 80|tcpscan.sara 139|";
    $custom_2_string .= 'Web,';
  } else {
    $http2="off";
    $html_post_attributes .=  "\nhttp2=off";
  }
  if ($mail2 eq "on") {
    $custom_2 .= "tcpscan.sara 25|";
    $custom_2_string .= 'Mail,';
  } else {
    $mail2="off";
    $html_post_attributes .=  "\nmail2=off";
  }
  if ($tel2 eq "on") {
    $custom_2 .= "tcpscan.sara 23|";
    $custom_2_string .= 'Telnet,';
  } else {
    $tel2="off";
    $html_post_attributes .=  "\ntel2=off";
  }
  if ($ftp2 eq "on") {
    $custom_2 .= "tcpscan.sara 21|";
    $custom_2_string .= 'FTP,';
  } else {
    $ftp2="off";
    $html_post_attributes .=  "\nftp2=off";
  }
  if ($rpc2 eq "on") {
    $custom_2 .= "rpc.sara|showmount.sara|";
    $custom_2_string .= 'RPC,';
  } else {
    $rpc2="off";
    $html_post_attributes .=  "\nrpc2=off";
  }
  $custom_2 .= '*?|';
}
elsif ($custom2_mode == 2) {
  $custom_2  = "tcpscan.sara $custom2_tcp|" if $custom2_tcp;
  $custom_2 .= "udpscan.sara $custom2_udp|" if $custom2_udp;
  $custom_2 .= "*?|";
  $custom_2_string = "";
  $custom_2_string .= "TCP scan of $custom2_tcp," if $custom2_tcp;
  $custom_2_string .= "UDP scan of $custom2_udp"  if $custom2_udp;
}
$custom2_cmd = $custom_2;
$custom_2 = "custom2_cmd=$custom2_cmd";
$custom_2_string =~ s/\,$//;
$custom_2_string =  "Custom($custom_2_string)";
$custom2_string = $custom_2_string;
$custom_2_string = "custom2_string=$custom2_string";
$html_post_attributes .= " \n$custom_2\n$custom_2_string\n";
$cf_dns2 = $cf_smb2 = $cf_http2 = $cf_mail2 = $cf_tel2 = $cf_ftp2 = $cf_rpc2 ="";
# Write the data...
&write_config_file($html_post_attributes);

print CLIENT <<EOF;
<HTML>
<HEAD>
<TITLE>SARA Configuration Management</TITLE>
<LINK REV="made" HREF="mailto:satan\@fish.com">
<LINK REV="updated" HREF="mailto:sara\@arc.com">
</HEAD>
<BODY>
<H1><IMG SRC=$HTML_ROOT/images/sara.gif> SARA Configuration Management </H1>
<hr>
<B>Configuration file changed</B>
<UL>
Restart SARA for changes to take effect!!
</UL>
<P>
<hr> <a href=$HTML_SERVER> Back to the SARA start page </a>
</BODY>
</HTML>
EOF
