#!/usr/bin/perl -w

#####################################################################################
# All information, data, source code, compiled binaries, information, documentation #
# contained within this document is the sole property of "WhiteHat Security, Inc"   #     
# and may not be sold, reused or distributed.                                       #
# Copyright 2002 WhiteHat Security, Inc.  ALL RIGHTS RESERVED                       #
#####################################################################################

use strict;
use URI;
use LW;
use Time::HiRes qw(usleep ualarm gettimeofday tv_interval);
require "./Subs.pm";


## TODO ##

### Global Variable #############################################################

my $Debug = 0;	# Debug Flag (0 == Off | 1 == On)
$|++;		# Flush Ouput

my $useragent = "WhiteHat Arsenal 1.07 Beta"; # Default User-Agent
my %FORM;	# FORM Input Array


# Ripper Control Variables and Options
my %mData = ("SESSION" => "",		# Current Session. What session to log request in.
		"CMD" => "",		# 
		"MIMICK" => "",		# Browser Mimic. Mimic HTTP Request Headers of a common web browser
		"HTTP_FIX" => "",	# HTTP Fixup
		"HOST_FIX" => "",	# HTTP Fixup
		"REFERER" => "",	# Set Referer Header Option in Rip Results
		"WHPROXY" => "",	# WH Proxy. Convert all HTML links in response pages to request through ripper
	);


# Ripper HTTP(s) Request Information
my %rData = ("HOST" => "",		# Host
		"PATH" => "",		# URI Path
		"CONTENT" => "",	# HTTP Content
		"PROTOCOL" => "",	# Protocol (HTTP|HTTPS)
		"PORT" => "",		# Port
		"METHOD" => "",		# HTTP Request Method
		"VERSION" => "1.1",	# HTTP Version
		"USERNAME" => "",	# WebAuth Username
		"PASSWORD" => "",	# WebAuth Password
		"HEADERS" => "",	# HTTP Request Headers
	);

# Ripper Input Data to be sent to remote web application
my %iData =();	# Variable Data Sent to Target CGI

# Browser Mimic HTTP Request Headers
my %mimickhdrs = ("Accept" => "text/xml, application/xml, application/xhtml+xml, text/html;q=0.9, image/png, image/jpeg, image/gif;q=0.2, text/plain;q=0.8, text/css, */*;q=0.1",
		"Accept-Language" => "en-us",
		"Accept-Charset" => "ISO-8859-1, utf-8;q=0.66, *;q=0.66",
		"Keep-Alive" => "300",
		"Connection" => "keep-alive",
);

my @req_headers = ();	# HTTP Request Headers
my @res_headers = ();	# HTTP Response Headers

### Page Properties ###
my $bgcolor = "#FFFFFF";			# Page BGCOLOR
my $link = "#0099FF";			# Page LINK COLOR
my $vlink = "#FF9933";			# Page VLINK COLOR

# System/Session Path Information
my $doc_root = $ENV{'DOCUMENT_ROOT'} || "/home/apache/htdocs";	# Document Root Directory
my $session_dir = $doc_root . "/" . "wharsenal/sessions/";	# Session Directory
my $session_path = "";						# Current Session Directory Path
my $results_file = "attempts.xml";				# Results Filename
my $html_file = "html.html";					# Results HTML Filename
my $results_path;						# Current Session Results Path
my $html_path;							# Current HTML Results File



my @v = ('FORM', 'INPUT', 'SELECT', 'OPTION', 'TEXTAREA', 'SCRIPT', 'STYLE'); # Form Tags
my %radio_names = ();
my $form_count = 0;
my $cselect_name = "";

### Parse On|Off ########
# Stop parsing when you see the following
# <SCRIPT <STYLE
# Start parsing when you see the following
# </SCRIPT> </STYLE>
my @pChk = ("<STYLE", "<SCRIPT", "</STYLE>", "</SCRIPT>", "<!");
my $parseFlag = 1;      # Parse Default On (Off = 0)

##################################################################################

### MAIN #########################################################################
print "Content-Type: text/html\n\n";	# Print HTTP Content Type Header

# Print XHTML Header
print <<EOF;
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
        "http://www.w3.org/TR/2000/REC-xhtml1-20000126/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US" xml:lang="en-US">
<HEAD>
EOF


RequestMethod();	# Load in CGI input
sanityCheck();		# Sanity Check and Secure all input data


styleScript();


print "</HEAD>\n<TITLE>WhiteHat Arsenal 1.07 Beta Ripper</TITLE>\n";
print "<BODY TEXT=\"000000\" LINK=\"$link\" VLINK=\"$vlink\" BGCOLOR=\"$bgcolor\" OnLoad=\"tabInit();\">\n";

controller();		

	if ($Debug == 1) {
	print "<HR>\n";
		foreach my $i (keys %mData) {
			print "M: $i VALUE: $mData{$i}<BR>\n";
		}
	}
	
	
	if ($Debug == 1) {
	print "<HR>\n";
		foreach my $i (keys %rData) {
			print "R: $i VALUE: $rData{$i}<BR>\n";
		}
	}
	if ($Debug == 1) {
	print "<HR>\n";
		foreach my $i (keys %iData) {
			print "I: $i VALUE: $iData{$i}<BR>\n";
		}
	}
print "</BODY></HTML>\n";
exit;
##################################################################################

### Subroutines ##################################################################



##################
##  Controller  ##
##################
# Controls the flow and output of the application base upon Output Mode specified
# Params: Nothing. Takes its input from the globally accessible %mData.
# Return: Nothing. Outputs HTML results based on the application flow
# Usage: controller()
sub controller {

	if ($mData{'CMD'} eq "RIPPER") { # RIPPER 
		titlebarHTMLBlock("Ripper", "Ripper output results. View <A HREF=\"/wharsenal/sessions/$mData{'SESSION'}/$html_file\"> HTML Output</A>.");
		httpRequest();
	} elsif ($mData{'CMD'} eq "RIPURL") { # Rip a URL and place into edittable Form fields
		titlebarHTMLBlock("Rip URL", "Convert a full URL into an HTML Form.");
		ripURL();
	}
	
} # End Controller SubRoutine




####################
##  HTTP Request  ##
####################
# Submit HTTP Request
# Log HTTP Request/Response

sub httpRequest { # HTTP Reqest


	# Start HTTP Request Objects
	my (%hin, %hout, %jar);
	
	# Initialize HTTP input
	LW::http_init_request(\%hin);
	
	# HTTP Request Response Time
	my $msec;
	
	
	# HTML Data
	my $html_data = "";
	
	# Size of Return Data
	my $size;
	
	# Load in Connection Properties and Attributes
	$hin{'whisker'}->{'host'} = $rData{'HOST'};		# Set Host
	$hin{'whisker'}->{'uri'} = $rData{'PATH'};		# Set Path
	$hin{'whisker'}->{'port'} = $rData{'PORT'};		# Set Port
	$hin{'whisker'}->{'method'} = $rData{'METHOD'};		# Set Method
	$hin{'whisker'}->{'http_ver'} = $rData{'VERSION'};	# Set Version
	$hin{'User-Agent'} = $useragent;			# heh back at ya
	

	# SSL Support
	if ($rData{'PROTOCOL'} =~ /^https$/i) { # if protocol is SSL
		print "GO SSL<BR>\n" if ($Debug == 1);
		$hin{'whisker'}->{'ssl'} = 1;
		$hin{'whisker'}->{'save_ssl_info'} = 1;
	} # End SSL Support If

	# Web Auth Support
	if (($rData{'USERNAME'} ne "") || ($rData{'PASSWORD'} ne "")) { # If Username or Password has a value
		LW::auth_set_header('basic', \%hin, $rData{'USERNAME'}, $rData{'PASSWORD'}); # Set Basic Auth Credentials
	} # End Web Auth if
	
	
	
	# Load in Query Data
	if ($rData{'METHOD'} eq "POST") { # If POST Method use Content
		print "POSTing<BR>\n" if ($Debug == 1);
		
		# Loop Thru Input Data
		foreach my $name (keys %iData) {
		
			print "INDATA: $name VALUE: $iData{$name}<BR>\n" if ($Debug == 1);
			$iData{$name} = "0" unless($iData{$name});
			
			# Build Content Line with parameter information
			if (($rData{'CONTENT'} =~ /(&)$/) || ($rData{'CONTENT'} eq "")) {
				$rData{'CONTENT'} = $rData{'CONTENT'} . $name . "=" . $iData{$name};
			} else {
				$rData{'CONTENT'} = $rData{'CONTENT'} . "&" . $name . "=" . $iData{$name};
			}
		}
		
		
		#print "CONTENT: $rData{'CONTENT'}<BR>\n";
		#$rData{'CONTENT'} =~s/([^a-zA-Z0-9_\-.])/uc sprintf("%%%02x",ord($1))/eg;
		
		# Set Content
		$hin{'whisker'}->{'data'} = $rData{'CONTENT'};

		$hin{'Content-Type'} = "application/x-www-form-urlencoded";
		
		
	} elsif ($rData{'METHOD'} =~ /^(GET|HEAD)/) { # if GET|HEAD Method use Path
	
		# Loop Thru Input Data
		foreach my $name (keys %iData) {
			print "$rData{'PATH'}<BR>\n" if ($Debug == 1);
			print "NAME: $name<BR>\n" if ($Debug == 1);
			
			# Build Query Path
			if ($rData{'PATH'} =~ /(&)$/) {
				$rData{'PATH'} = $rData{'PATH'} . $name . "=" . $iData{$name};
			} elsif ($rData{'PATH'} =~ /(\?)$/) {
				$rData{'PATH'} = $rData{'PATH'} . $name . "=" . $iData{$name};
			} elsif (($rData{'PATH'} !~ /(\?)/) && ($rData{'PATH'} !~ /(=)$/)) {
				$rData{'PATH'} = $rData{'PATH'} . "?" . $name . "=" . $iData{$name};
			} else {
				$rData{'PATH'} = $rData{'PATH'} . "&" . $name . "=" . $iData{$name};
			}
		}
		
		# Cleanup white space is URL path
		$rData{'PATH'} =~ s/ /%20/g;
		$rData{'PATH'} =~ s/\t/%09/g;
		$rData{'PATH'} =~ s/\r/%0D/g;
		$rData{'PATH'} =~ s/\n/%0A/g;
		$rData{'PATH'} =~ s/\s/+/g;
		
		$hin{'whisker'}->{'uri'} = $rData{'PATH'};
	} # End Load Query Data If
	
	
	
	# If HTTP Request Headers Exist
	if (length @req_headers > 0) {
		
		foreach my $hdr (@req_headers) { # Loop thru HTTP Request Headers
			if ($hdr =~ /([^:]+)(:)([\s]+)(.+)/i) {
				my $hname = $1;
				my $hvalue = $4;
				$hname =~ s/(\r|\n)//g;
				$hvalue =~ s/(\r|\n)//g;
				
				print "H NAME: $hname<BR>\n" if ($Debug == 1);
				print "H VALUE: $hvalue<BR>\n" if ($Debug == 1);
				
				$hin{$hname} = $hvalue; # Set HTTP Request Header
				
			} # End Header Format if
		} # End Foreach
		
	} # End Load HTTP Request Headers If
	
	# Add Referer Header
	$hin{'REFERER'} = $mData{'REFERER'} if ($mData{'REFERER'} ne "");
	
	# Check for HTTP Fixup Flag
	if ($mData{'HTTP_FIX'} eq "ON") { # Fix HTTP Request
		print "FIXING<BR>\n" if ($Debug == 1);
		LW::http_fixup_request(\%hin); # Fix HTTP Request
	} # End Fix HTTP Request
	
	
	# Check for Host Fixup Flag
	if ($mData{'HOST_FIX'} eq "ON") { # Fix Host Request
		print "FIXING Host<BR>\n" if ($Debug == 1);
		$hin{'Host'} = $rData{'HOST'}; # Set HTTP Request Header
	} # End Fix Host
	
	
	if ($Debug == 1) {
		foreach my $i (keys %hin) {
			if ($i eq "whisker") {
				foreach my $x (keys %{$hin{$i}}) {
					print "<B>$x</B> : ${$hin{$i}}{$x}<BR>\n";
				}
			} else {
				print "<B><I>$i</I></B> : $hin{$i}<BR>\n";
			}
		}
	}
	
	
	
	# Starting Seconds
	my ($s, $usec) = gettimeofday;
	print "S: $usec M: $s<BR>\n" if ($Debug == 1);
	
	if(LW::http_do_request(\%hin,\%hout)){
		
        	print $hout{'whisker'}->{'error'};
        	return $hout{'whisker'}->{'error'};

		
		
	} else {
	
		# Ending Seconds
		my ($s1, $usec1) = gettimeofday;
		print "MICRO: $usec1 - $usec<BR>\n" if ($Debug == 1);
		
		# Elapsed Milli Seconds
		$msec = ($usec1 - $usec)/1000;
		print "TOTAL: $msec<BR>\n" if ($Debug == 1);
		
		# Hack to make response time possitive. Cant find the bug.
		$msec =~ s/([\-])//g;
		
		if (defined $hout{'whisker'}->{'data'}) {
			$size = SizeConvert(length $hout{'whisker'}->{'data'});
			$html_data = $hout{'whisker'}->{'data'};
					
		} else {
			$size = 0;
		}
		
		
		
		
	} # End Do HTTP Request
	
	# Clean Up the Mess
	&LW::http_reset;
	
	
	
	# BASE URI
	my $base_url = $rData{'PROTOCOL'} . "://" . $rData{'HOST'} . $rData{'PATH'};
	$base_url = URI->new($base_url);
	
	open(HTML, ">$html_path") || die "Cant create $html_path $!\n";
	print HTML "<BASE HREF=\"$base_url\">\n";
	print HTML $html_data;
	close(HTML);
	
			
	# 302|301 Redirect If
	if ((defined $hout{'Location'}) && ($hout{'whisker'}->{'code'} =~ /^(301|302)$/)) {
	
		printFont("HTTP \"<A HREF=\"/cgi-bin/wharsenalcgi/http_rc.pl?rc=$hout{'whisker'}->{'code'}\">$hout{'whisker'}->{'code'}</A>\" Re-direct encountered. <A HREF=\"javascript:void(0);\" OnClick=\"parent.topbar.document.control.URL.value = \'$hout{'Location'}\'\">Load Re-direct</A>. <BR>", 12);
		printFont("Pointing to URL: <A HREF=\"$hout{'Location'}\" TARGET=\"_BLANK\">$hout{'Location'}</A>", 12);
	
	} # End 302 Redirect If


		# Print Response headers
		foreach my $hdr (keys %hout) {	# Loop thru Response Headers
			# Combine Header into one line for checking
			
			if (($hdr ne "whisker") && (length $hout{$hdr} > 1)) {
				my $hline = $hdr . ": " . $hout{$hdr} unless ($hdr eq "whisker");
				
				
				push(@res_headers, $hline);
				
			} # End Whisker Check
			
		} # End Response Header Check Method Loop
		
		
		


print <<EOF;
<div id="tabs">
	<span id="tab1" class="tab">Forms</span>
	<span id="tab2" class="tab">Source</span>
	<span id="tab3" class="tab">Links</span>
	<span id="tab4" class="tab">Request</span>
	<span id="tab5" class="tab">Response</span>
</div>


EOF
	
	
	# Forms Output
	print "<div class=\"content\" id=\"content1\">\n";	
	parseResponse($html_data);
	print "</div>\n";
	
	
	print "<div class=\"content\" id=\"content2\">\n";
	print "<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0><TR>\n";
	print "<TD WIDTH=550>\n";	
	
	print "<font style=\"font-size: 10pt; font-family:verdana, arial,sans-serif;\">\n";
	print "<XMP>\n";
	print $html_data;
	print "</XMP>\n";
	print "</font>\n";
	print "</TD>\n";
	print "</TR></TABLE>\n";
	
	print "</div>\n";

	print "<div class=\"content\" id=\"content3\">\n";	
	linksOutput($html_data, $base_url);
	print "</div>\n";

	# Request Output
	print "<div class=\"content\" id=\"content4\">\n";
	httpReqTable(\%hin);
	print "</div>\n";
	
	
	# Response Output
	print "<div class=\"content\" id=\"content5\">\n";
	print "<TABLE BGCOLOR=\"#fdbe50\" BORDER=\"0\" CELLSPACING=\"2\" CELLPADDING=\"0\">\n";
		print "<TR><TD WIDTH=\"565\" ALIGN=\"LEFT\" VALIGN=\"TOP\">\n";

		print "<TABLE BORDER=\"0\" CELLSPACING=\"0\" CELLPADDING=\"1\">\n";
		print "<TR><TD BGCOLOR=\"#FFFFFF\" ALIGN=\"LEFT\" VALIGN=\"TOP\">\n";

			print "<TABLE BORDER=\"0\" CELLSPACING=\"0\" CELLPADDING=\"2\">\n";
	
			print "<TR WIDTH=\"565\" BGCOLOR=\"#fdbe50\"><TD ALIGN=\"LEFT\" VALIGN=\"TOP\">\n";
			printFont("<B>Response Information</B>", "12");
			print "</TD></TR>\n";



			print "<TR BGCOLOR=\"#fef5c7\" ALIGN=\"LEFT\" VALIGN=\"TOP\"><TD>\n";
		
				print "<TABLE BORDER=\"0\" CELLSPACING=\"0\" CELLPADDING=\"2\">\n";
				print "<TR>\n";
				print "<TD WIDTH=\"200\" ALIGN=\"LEFT\" VALIGN=\"TOP\" BGCOLOR=\"#fef5c7\">\n";
				printFont("<B>Code:</B>" . HTMLEsc($hout{'whisker'}->{'code'}), "12");
				print "</TD>\n";
			
				print "<TD WIDTH=\"200\" ALIGN=\"LEFT\" VALIGN=\"TOP\" BGCOLOR=\"#fef5c7\">\n";
				printFont("<B>Time:</B>" . $msec . "ms", "12");
				print "</TD>\n";
	
				print "<TD WIDTH=\"144\" ALIGN=\"LEFT\" VALIGN=\"TOP\" BGCOLOR=\"#fef5c7\">\n";
				printFont("<B>Size:</B>" . $size, "12");
				print "</TD>\n";
	
				print "</TR>\n";
			
				print "</TABLE>\n";
			
			print "</TD></TR>\n";
			
			
			print "</TABLE>\n";
	
		print "</TD></TR>\n";
		print "</TABLE>\n";

		print "</TD></TR>\n";
		print "</TABLE>\n";

		
		
			print "<TABLE BGCOLOR=\"#cee3f0\" BORDER=\"0\" CELLSPACING=\"2\" CELLPADDING=\"0\">\n";
			print "<TR><TD WIDTH=\"565\" ALIGN=\"LEFT\" VALIGN=\"TOP\">\n";

			print "<TABLE BORDER=\"0\" CELLSPACING=\"0\" CELLPADDING=\"1\">\n";
			print "<TR><TD BGCOLOR=\"#EEEEEE\" ALIGN=\"LEFT\" VALIGN=\"TOP\">\n";

				print "<TABLE BORDER=\"0\" CELLSPACING=\"1\" CELLPADDING=\"2\">\n";
	
				print "<TR WIDTH=\"565\" BGCOLOR=\"#cee3f0\"><TD ALIGN=\"LEFT\" VALIGN=\"TOP\">\n";
				printFont("<B>Response Headers</B>", "12");
				print "</TD></TR>\n";

		
			
		# Print Response headers
		foreach my $hdr (keys %hout) {	# Loop thru Response Headers
			# Combine Header into one line for checking
			
			if (($hdr ne "whisker") && (length $hout{$hdr} > 1)) {
				my $hline = $hdr . ": " . $hout{$hdr} unless ($hdr eq "whisker");
				
					print "<TR WIDTH=\"565\" BGCOLOR=\"#FFFFFF\"><TD ALIGN=\"LEFT\" VALIGN=\"TOP\" WIDTH=\"565\">\n";
					printFont(HTMLEsc(WrapString($hline, 40)), "12") if ($hline);
					print "</TD></TR>\n";
				
			} # End Whisker Check
			
		} # End Response Header Check Method Loop
		
		
			if (defined $hin{whisker}->{save_ssl_info}) {
			
			
				print "<TR WIDTH=\"565\" BGCOLOR=\"#FFFFFF\"><TD ALIGN=\"LEFT\" VALIGN=\"TOP\">\n";
				printFont(HTMLEsc("SSL cipher: " . $hout{whisker}->{ssl_cipher}), "12");
				print "</TD></TR>\n";
				
				
				print "<TR WIDTH=\"565\" BGCOLOR=\"#FFFFFF\"><TD ALIGN=\"LEFT\" VALIGN=\"TOP\">\n";
				printFont(HTMLEsc("Server cert: " . $hout{whisker}->{ssl_cert_subject}), "12");
				print "</TD></TR>\n";
				
				
				print "<TR WIDTH=\"565\" BGCOLOR=\"#FFFFFF\"><TD ALIGN=\"LEFT\" VALIGN=\"TOP\">\n";
				printFont(HTMLEsc("Cert issuer: " . $hout{whisker}->{ssl_cert_issuer}), "12");
				print "</TD></TR>\n";
				
			} # End SSL Response If
		
	print "</div>\n";
	
	
	
	
	
	##### BEGIN XML HTTP REQUEST/RESPONSE LOGGING ######
	
	# Current Data/Time
	my $date_time = dtime() || "";



		
	if ((-e $results_path) && (-w $results_path)) {
		
		cutEnd($results_path);
			
		# Open Resuls File for loggin
		open(ALOG, ">>$results_path") or die "Cant open results path $!\n";
	
		print ALOG "\t<ATTEMPT>\n";
		
		print ALOG "\t\t<TEST-INFORMATION>\n";
		
		print ALOG "\t\t\t<TIME>" . XMLEsc($date_time) . "</TIME>\n";
		
		print ALOG "\t\t</TEST-INFORMATION>\n";
		
		
		print ALOG "\t\t<REQUEST-INFORMATION>\n";
		
		print ALOG "\t\t\t<HOST><![CDATA[$rData{'HOST'}]]></HOST>\n";
		print ALOG "\t\t\t<PORT><![CDATA[$rData{'PORT'}]]></PORT>\n";
		print ALOG "\t\t\t<USERNAME><![CDATA[$rData{'USERNAME'}]]></USERNAME>\n";
		print ALOG "\t\t\t<PASSWORD><![CDATA[$rData{'PASSWORD'}]]></PASSWORD>\n";
		print ALOG "\t\t\t<PROTOCOL><![CDATA[$rData{'PROTOCOL'}]]></PROTOCOL>\n";
		print ALOG "\t\t\t<PATH><![CDATA[$rData{'PATH'}]]></PATH>\n";
		print ALOG "\t\t\t<METHOD><![CDATA[$rData{'METHOD'}]]></METHOD>\n";
		print ALOG "\t\t\t<VERSION><![CDATA[$rData{'VERSION'}]]></VERSION>\n";
	
		
		print ALOG "\t\t\t<REQUEST-HEADERS>\n";
		foreach my $hdr (keys %hin) {
			
			unless ($hdr eq "whisker") {
				my $hname = XMLEsc(substr($hdr, 0, 128));
				my $hvalue = substr($hin{$hdr}, 0, 2056) || "";
			
				$hname =~ s/(\r|\n)//g;
				$hvalue =~ s/(\r|\n)//g;
				
				print "REQ HDRS: $hname $hvalue<BR>\n" if ($Debug == 1);
				print ALOG "\t\t\t\t<REQUEST-HEADER ENOCODING=\"TEXT\" NAME=\"$hname\"><![CDATA[$hvalue]]></REQUEST-HEADER>\n";
				
			}
			
				
		}
		print ALOG "\t\t\t</REQUEST-HEADERS>\n";
		
		
	
		my $csize = length $rData{'CONTENT'} || "0";
		
		print ALOG "\t\t\t<CONTENT LENGTH=\"$csize\"><![CDATA[$rData{'CONTENT'}]]></CONTENT>\n" if ($rData{'CONTENT'} ne "");
		
		print ALOG "\t\t</REQUEST-INFORMATION>\n";
		
		print ALOG "\t\t<RESPONSE-INFORMATION>\n";
		print ALOG "\t\t\t<TIME>" . XMLEsc($msec) . "</TIME>\n";
		print ALOG "\t\t\t<CODE><![CDATA[$hout{'whisker'}->{'code'}]]></CODE>\n";
		print ALOG "\t\t\t<RESPONSE-HEADERS>\n";	
		foreach my $hdr (keys %hout) {
			
			my $value = XMLEsc(substr($hout{$hdr}, 0, 1024)) unless ($hdr eq "whisker") || "";
			my $name = XMLEsc(substr($hdr, 0, 128));
			
			print ALOG "\t\t\t\t<RESPONSE-HEADER NAME=\"$name\">$value</RESPONSE-HEADER>\n" unless ($hdr eq "whisker");
		}
		print ALOG "\t\t\t</RESPONSE-HEADERS>\n";
		
		# Size of Data
		if (defined $hout{'whisker'}->{'data'}) { # Check if there is data
			my $dlen = length $hout{'whisker'}->{'data'};
			
			print ALOG "\t\t\t<DATA SIZE=\"$dlen\" ENCODING=\"BASE64\">";
			#my $html_data = LW::encode_base64($hout{'whisker'}->{'data'});
			#$html_data =~ s/(\r|\n)//g;
			#print ALOG $html_data;
			print ALOG "</DATA>\n";
		} 
		
		print ALOG "\t\t</RESPONSE-INFORMATION>\n";
		
		print ALOG "\t</ATTEMPT>\n";
		print ALOG "</ATTEMPTS>\n";
	
		close(ALOG); # Close Log File
	}
	
	
	
	
} # End HTTP Request SubRoutine





###################
##  Link Target  ##
###################
# For WH-Proxy Support
# Used to re-code links that are in HTML page to pass through ripper.
# Takes 2 parameters. HTML Data and the BaseURL of the page.
sub linkTarget {
	my $html = shift;
	my $base_url = URI->new(shift);
	
	my @uri_parts;
	my $path;
	my $protocol;
	my $host;
	my $port;
	my $params;
	
	my $script_flag = 0;
	
	print "BASE URL: $base_url<BR>\n" if ($Debug == 1);

print <<EOF;
<TABLE BGCOLOR="#9BBAD6" BORDER="0" CELLSPACING="2" CELLPADDING="0">
<TR><TD WIDTH="590" ALIGN="LEFT" VALIGN="TOP">
	
	<TABLE BORDER="0" CELLSPACING="0" CELLPADDING="1">
	<TR><TD BGCOLOR="#FFFFFF" ALIGN="LEFT" VALIGN="TOP">
	
		<TABLE BORDER="0" CELLSPACING="0" CELLPADDING="2">
EOF


	print "<TR WIDTH=\"590\" BGCOLOR=\"#9BBAD6\"><TD ALIGN=\"LEFT\" VALIGN=\"TOP\" WIDTH=\"590\">\n";
	printFont("<B>HTML Output </B>", "14");
	print "</TD></TR>\n";
	

	
print <<EOF;
		</TABLE>
		
	</TD></TR>
	</TABLE>
		
</TD></TR>
</TABLE>
<BR>
EOF
								
						
	my @lins = split(/>/, $html);       # Split HTTP Response By Tag

	foreach my $lin (@lins) { # Look for FILE URLs
                $lin = $lin . ">";    # Fix Split Routine
		
		
		print "LIN: <XMP>$lin</XMP>" if ($Debug == 1);

		if ($lin =~ /(<)SCRIPT/i) {
			$script_flag = 1;
		} elsif ($lin =~ /(<)([\/])SCRIPT/i) {
			$script_flag = 0;
		}
		
		print "SCRIPT FLAG : $script_flag<BR>\n" if ($Debug == 1);
		
		$lin = "" if ($script_flag eq "1");
		
		
		if ($mData{'WHPROXY'} eq "ON") {
			#print "PROXING<BR>\n";
			
			if (($lin =~ /<A/i) && ($lin =~ /(HREF)(=)(["]?|[']?)([\w\d\`\~\!\@\#\$\%\^\&\*\(\)\-\_\=\+\[\]\{\}\;\:\,\.\/\?\\\']+)(["]?|[']?|[>]?)/i)){
				
				#print "P: REPLACE<BR>\n";
				
				my $n_url = URI->new($4);
				my $new_url = $n_url->abs($base_url);
				
				@uri_parts = LW::utils_split_uri($new_url);
		
				$path =  $uri_parts[0] || "/";
				$protocol = $uri_parts[1] || "http";
				$host = $uri_parts[2] || "";
				$port = $uri_parts[3] || "80";
				$params = $uri_parts[4] || "";
		
				if ($params ne "") {
					$path = $path . "?" . $params;
				} else {
					$path .= $params;
				}
				
				#print "PATH: $path : $params <BR>\n";
				
				$lin =~ s/(HREF)(=)(["]?|[']?)([\w\d\`\~\!\@\#\$\%\^\&\*\(\)\-\_\=\+\[\]\{\}\;\:\,\.\/\?\\\']+)(["]?|[']?|[>]?)/HREF=\"javascript:void(0)\;\" OnClick=\"parent.tools.document.control.host.value=\'$host\'\; parent.tools.document.control.port.value=\'$port\'\; parent.tools.document.control.path.value=\'$path\'\;\"/i;
				print $lin;
				
			} else {
				#print "<XMP>$lin</XMP>\n";
				print $lin;
			}
			
			
		} else {
		
			if (($lin =~ /<A/i) && ($lin =~ /(HREF)(=)(["]?|[']?)([\w\d\`\~\!\@\#\$\%\^\&\*\(\)\-\_\=\+\[\]\{\}\;\:\,\.\/\?\\\']+)(["]?|[']?|[>]?)/i)){
				my $n_url = URI->new($4);
				my $new_url = $n_url->abs($base_url);
			
				@uri_parts = LW::utils_split_uri($new_url);
		
				$path =  $uri_parts[0] || "/";
				$protocol = $uri_parts[1] || "http";
				$host = $uri_parts[2] || "";
				$port = $uri_parts[3] || "80";
				$params = $uri_parts[4] || "";
		
				$path .= $params;
				
				#print "ANCHOR: <XMP>$lin $n_url $new_url</XMP>\n";
				$lin =~ s/(>)/ TARGET=\"body\" OnClick=\"parent.tools.document.control.host.value=\'$host\'\; parent.tools.document.control.port.value=\'$port\'\; parent.tools.document.control.path.value=\'$path\'\;\">/;
				#print "<XMP>$lin</XMP>\n";
				print $lin;
			} else {
				#print "<XMP>$lin</XMP>\n";
				print $lin;
			}
		}
		
	} # End Foreach
} # End Link Target SubRoutine




#####################
##  Parse Response ##
#####################
# Parse HTML data for HTML Forms
# Takes one parameter. HTML Data
sub parseResponse {
	my $response = shift || "";
	my $m = 0;


	print "RESPONSE HERE<BR>\n" if ($Debug == 1);
	
	# Check for Response data
	if ((defined $response) && ($response ne "")) { # Has HTML Data
	
		my @lins = split(/>/, $response);       # Split HTTP Response By Tag

		foreach my $lin (@lins) { # Look for FILE URLs
               		$lin = $lin . ">";    # Fix Split Routine
                	$lin =~ s/(.*)(<)/$2/eg;
                	$lin =~ s/\n/ /g;
                	$lin =~ s/\t/ /g;

			print "LIN: <XMP>$lin</XMP>" if ($Debug == 1);

                	# Turn Parsing On|Off
                	if ($lin =~ /($pChk[0]|$pChk[1])/i) {                   # Parser Off
                        	$parseFlag = 0;                                 # Set Parse Flag Off
                        	print "ParseOff<BR>\n" if ($Debug == 1);        # Parser Status
                	} elsif ($lin =~ /($pChk[2]|$pChk[3])/i) {              # Parse On
                        	$parseFlag = 1;                                 # Set Parse Flag On
                        	print "ParseOn<BR>\n" if ($Debug == 1);         # Parser Status
                	} # Enf If

			if($parseFlag == 1) { # Check Parse Status
				if ($lin =~ /<$v[0]/i){ # Form Tag
					print "FORM: <XMP>$lin</XMP>\n" if ($Debug == 1);
					formTag($lin);
					$m++;
				} elsif ($lin =~ /(<)([\/])$v[0]/i) { # End Form Tag
					print "</FORM><BR>\n";
					print "<BR>\n";
					
					print "</TD></TR>\n";
					print "</TABLE>\n";

					print "</TD></TR>\n";
					print "</TABLE>\n";
					$form_count++;

				} elsif ($lin =~ /<$v[1]/i){ # Input Tag
					print "INPUT: $lin\n" if ($Debug == 1);
					inputTag($lin);
				} elsif ($lin =~ /<($v[2])/i) { # Select Tag
					#print "$lin<BR>\n";
					selectTag($lin);
				} elsif ($lin =~ /<([\/]?)($v[2])/i) { # End Select Tag
					print "$lin<BR>\n";
				} elsif ($lin =~ /<([\/]?)($v[4])/i) { # Textarea Tag
					print "$lin<BR>\n";
				} elsif ($lin =~ /<($v[3])/i) { # Option Tag
				
					my $ovalue = "";
					
					if($lin =~ /(VALUE)(=)(["]?|[']?)([\w\d\_\-\'\s\.\:\\\/,\?]+)(["]?|[']?|[>]?)/i) { # 'VALUE ELEMENT
						$ovalue = $4;
					}
					
					unless ($ovalue eq "") {
						#print "<XMP>\n";
						print "<SCRIPT>\n";
						print "var nOption = new Option(\"$ovalue\", \"$ovalue\");\n";
						print "var x = document.forms[$form_count].XX_$cselect_name.options.length;\n";
						print "document.forms[$form_count].XX_$cselect_name.options[x]=nOption;\n";
						print "document.forms[$form_count].XX_$cselect_name.options[x].selected = true;\n";
						print "</SCRIPT>\n";
						#print "</XMP>\n";
					}
				} # End Option Tag

			} # End Parse Flag If

		} # End Foreach
	} # End Check for Response Data If

} # End Parse Response SubRoutine


sub selectTag {
	my $lin = shift;
	
	my $select_name = "NO_NAME";
	
        if($lin =~ /(NAME)(=)(["]?|[']?)([\w\d\_\-]+)(["]?[']?[>]?)/i) { # 'NAME ELEMENT
                $select_name = $4;
		$cselect_name = $select_name;
        } # End Name
	
	
	print "<TABLE BGCOLOR=\"#cee3f0\" BORDER=\"0\" CELLSPACING=\"2\" CELLPADDING=\"0\">\n";
	print "<TR><TD WIDTH=\"565\" ALIGN=\"LEFT\" VALIGN=\"TOP\">\n";

		print "<TABLE BORDER=\"0\" CELLSPACING=\"0\" CELLPADDING=\"1\">\n";
		print "<TR><TD BGCOLOR=\"#FFFFFF\" ALIGN=\"LEFT\" VALIGN=\"TOP\">\n";

			print "<TABLE BORDER=\"0\" CELLSPACING=\"0\" CELLPADDING=\"2\">\n";
	
			print "<TR WIDTH=\"565\"><TD ALIGN=\"LEFT\" VALIGN=\"TOP\" WIDTH=\"565\" BGCOLOR=\"#cee3f0\">\n";
			
				print "<FONT COLOR=3300FF STYLE=\"font-size: 14px\; font-family:verdana, arial, sans-serif\">\n";
				print "<B>Select Menu</B>\n";
				print "</FONT>\n";
				
				
			print "</TD></TR>\n";

			print "<TR WIDTH=\"565\"><TD ALIGN=\"LEFT\" VALIGN=\"TOP\" WIDTH=\"565\">\n";
			
			
				print "<TABLE BORDER=\"0\" CELLSPACING=\"0\" CELLPADDING=\"2\"><TR>\n";
				
				
				print "<TD ALIGN=\"LEFT\" VALIGN=\"TOP\" BGCOLOR=\"#cee3f0\" WIDTH=\"60\">\n";
				print "<FONT COLOR=3300FF STYLE=\"font-size: 12px\; font-family:verdana, arial, sans-serif\">\n";
				print "<B>Name</B>";
				print "</FONT>\n";
				print "</TD>\n";
				
				
				print "<TD ALIGN=\"LEFT\" VALIGN=\"TOP\" BGCOLOR=\"#FFFFFF\" WIDTH=\"450\">\n";
				print "<FONT COLOR=3300FF STYLE=\"font-size: 12px\; font-family:verdana, arial, sans-serif\">\n";
				print WrapString($select_name,50);
				print "</FONT>\n";
				print "</TD>\n";
				
				
				print "</TR></TABLE>\n";
				
				
			print "</TD></TR>\n";
			
			
			print "<TR WIDTH=\"565\"><TD ALIGN=\"LEFT\" VALIGN=\"TOP\" WIDTH=\"565\">\n";
			
			
				print "<TABLE BORDER=\"0\" CELLSPACING=\"0\" CELLPADDING=\"2\"><TR>\n";
				
				
				print "<TD ALIGN=\"LEFT\" VALIGN=\"TOP\" BGCOLOR=\"#cee3f0\" WIDTH=\"60\">\n";
				print "<FONT SIZE=2 COLOR=3300FF STYLE=\"font-size: 12px\; font-family:verdana, arial, sans-serif\">\n";
				print "<B>Value</B>";
				print "</TD>\n";
				
				
				print "<TD ALIGN=\"LEFT\" VALIGN=\"TOP\" BGCOLOR=\"#FFFFFF\" WIDTH=\"450\">\n";
				print "<FONT SIZE=2 COLOR=3300FF STYLE=\"font-size: 12px\; font-family:verdana, arial, sans-serif\">\n";
				print "<INPUT TYPE=TEXT VALUE=\"\" NAME=\"$select_name\"  STYLE=\"WIDTH: 450px\; font-size: 12px\; font-family:verdana, arial, sans-serif\">\n";
				print "</TD>\n";
				
				
				print "</TR></TABLE>\n";
				
				
			print "</TD></TR>\n";
			
			
				
					
			print "<TR WIDTH=\"565\"><TD ALIGN=\"LEFT\" VALIGN=\"TOP\" WIDTH=\"565\">\n";
			
			
				print "<TABLE BORDER=\"0\" CELLSPACING=\"0\" CELLPADDING=\"2\"><TR>\n";
				
				
				print "<TD ALIGN=\"LEFT\" VALIGN=\"TOP\" BGCOLOR=\"#cee3f0\" WIDTH=\"60\">\n";
				print "<FONT SIZE=2 COLOR=3300FF STYLE=\"font-size: 12px\; font-family:verdana, arial, sans-serif\">\n";
				print "<B>Values</B>";
				print "</TD>\n";
				
				
				print "<TD ALIGN=\"LEFT\" VALIGN=\"TOP\" BGCOLOR=\"#FFFFFF\" WIDTH=\"450\">\n";
				print "<FONT SIZE=2 COLOR=3300FF STYLE=\"font-size: 12px\; font-family:verdana, arial, sans-serif\">\n";
				print "<SELECT NAME=\"XX_$select_name\" STYLE=\"WIDTH: 200px; font-size: 12px\; font-family:verdana, arial, sans-serif\" OnChange=\"this.form.$select_name.value=this.value\;\">\n";
				print "</SELECT>\n";
				
				
				print "</TD>\n";
				
				
				print "</TR></TABLE>\n";
				
				
			print "</TD></TR>\n";
			
			
				
			
			
			print "</TABLE>\n";
	
		print "</TD></TR>\n";
		print "</TABLE>\n";

	print "</TD></TR>\n";
	print "</TABLE><BR>\n";
	

	return;
	
	
}


sub formTag {
        my $lin = $_[0];
        my $form_name = "NO_NAME";
        my $form_action = "NONE";
        my $form_method = "GET";
	
	my @uri_parts;
	my $path =  $uri_parts[0] || "/";
	my $protocol = $uri_parts[1] || "http";
	my $host = $uri_parts[2] || "";
	my $port = $uri_parts[3] || "80";
	my $params = $uri_parts[4] || "";
	
	# BASE URI
	my $base_url = $rData{'PROTOCOL'} . "://" . $rData{'HOST'} . $rData{'PATH'};
	$base_url = URI->new($base_url);
	

	print "FORM TAG: <XMP>$lin</XMP>\n" if ($Debug == 1);

        if($lin =~ /(NAME)(=)(["]?|[']?)([\w\d\_\-]+)(["]?[']?[>]?)/i) { # 'NAME ELEMENT
                $form_name = $4;
        } # End Name
	
        if($lin =~ /(ACTION)(=)(["]?|[']?)([\w\d\~\!\@\#\$\%\^\&\*\(\)\-\_\=\+\[\]\{\}\;\:\,\.\/\?\\]+)(["]?[']?[>]?)/i) { # 'ACTION ELEMENT
                $form_action = URI->new($4);
                # Make the Action URL Absolute
                $form_action = $form_action->abs($base_url);       # Absolute Target
        } # End Action

        if($lin =~ /(METHOD)(=)(["]?|[']?)(GET|POST|HEAD)(["]?|[']?|[>]?)/i) { # 'METHOD ELEMENT
                $form_method = uc($4);
        } # End METHOD
	
	
	if (($form_action ne "") && ($form_action ne "NONE")) {
		@uri_parts = LW::utils_split_uri($form_action);
		
		$path =  $uri_parts[0] || "/";
		$protocol = $uri_parts[1] || "http";
		$host = $uri_parts[2] || "";
		$port = $uri_parts[3] || "80";
		$params = $uri_parts[4] || "";
		
		if (length $params > 0) {
			$path .= "?$params";
		} else {
			$path .= "$params";
		}
		
	}
	
	
print "<FORM METHOD=POST ACTION=\"/cgi-bin/wharsenalcgi/ripper.pl\">\n";

print <<EOF;
	<input TYPE="HIDDEN" NAME="M_MIMICK" VALUE="ON">
	<input TYPE="HIDDEN" NAME="M_HTTP_FIX" VALUE="ON">
	<input TYPE="HIDDEN" NAME="M_HOST_FIX" VALUE="ON">
	<input TYPE="HIDDEN" NAME="M_WHPROXY" VALUE="ON">
	<input TYPE="HIDDEN" NAME="M_SESSION" VALUE="">
	<input TYPE="HIDDEN" NAME="M_CMD" VALUE="">
	<input TYPE="HIDDEN" NAME="M_MAX" VALUE="">
	<input TYPE="HIDDEN" NAME="R_USERNAME" VALUE="">
	<input TYPE="HIDDEN" NAME="R_PASSWORD" VALUE="">
	<input TYPE="HIDDEN" NAME="R_HEADERS" VALUE="">
EOF
	
	
	print "<BR><TABLE BGCOLOR=\"#fdbe50\" BORDER=\"0\" CELLSPACING=\"2\" CELLPADDING=\"0\">\n";
	print "<TR><TD WIDTH=\"565\" ALIGN=\"LEFT\" VALIGN=\"TOP\">\n";

		print "<TABLE BORDER=\"0\" CELLSPACING=\"0\" CELLPADDING=\"1\">\n";
		print "<TR><TD BGCOLOR=\"#FFFFFF\" ALIGN=\"LEFT\" VALIGN=\"TOP\">\n";
		
		
			print "<TABLE BORDER=\"0\" CELLSPACING=\"0\" CELLPADDING=\"2\">\n";
	
			print "<TR BGCOLOR=\"#fdbe50\"><TD ALIGN=\"LEFT\" VALIGN=\"TOP\" WIDTH=\"565\" >\n";
			print "<FONT FACE=\"Arial\"><B>Form</B> ($form_name)</FONT>\n";
			print "</TD></TR>\n";
			
			print "</TABLE>\n";
			
			
print <<EOF;

<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0" BGCOLOR="#f3f6f9" STYLE="border-bottom: #000000 solid 1px;"><TR>
	
	
	<TD WIDTH="570" ALIGN="LEFT" VALIGN="TOP">
	
	
	
		<TABLE BORDER="0" CELLPADDING="2" CELLSPACING="0">
		
		<TR>
		<TD WIDTH="570" ALIGN="LEFT" VALIGN="MIDDLE">
			<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0">
			<TR>
			<TD WIDTH="60" ALIGN="LEFT" VALIGN="MIDDLE">
			<FONT style="font-size: 10pt; font-family:verdana, arial,sans-serif; font-weight: 600 !important;">
			Address
			</FONT>
			</TD>
			<!-- URL Input field -->
			<TD WIDTH="500" ALIGN="LEFT" VALIGN="MIDDLE">
EOF
print "<INPUT TYPE=\"TEXT\" NAME=\"R_URL\" VALUE=\"$form_action\" style=\"WIDTH: 500px; font-size: 10pt; font-family:verdana, arial,sans-serif\">\n";
	
print <<EOF;	
			</TD>
			</TR>
			</TABLE>
		</TD>
		</TR>
	
		
		<TR>
		<TD WIDTH="570" ALIGN="LEFT" VALIGN="MIDDLE">
			<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0">
			
			<TR>
			
			<TD WIDTH="60" ALIGN="LEFT" VALIGN="MIDDLE">
			<FONT style="font-size: 10pt; font-family:verdana, arial,sans-serif; font-weight: 600 !important;">
			Referer
			</FONT>
			</TD>
		
			<!-- HTTP Request Method Input field -->
			<TD WIDTH="500" ALIGN="LEFT" VALIGN="MIDDLE">
			<INPUT TYPE="TEXT" NAME="R_REFERER" VALUE="$base_url" style="WIDTH: 490px; font-size: 10pt; font-family:verdana, arial,sans-serif">
			</TD>
			
			
			</TR>
			
			</TABLE>
		</TD>
		</TR>
		
		
			
		<TR>
		<TD WIDTH="570" ALIGN="LEFT" VALIGN="MIDDLE">
			<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0">
			
			<TR>
			
			<TD WIDTH="60" ALIGN="LEFT" VALIGN="MIDDLE">
			<FONT style="font-size: 10pt; font-family:verdana, arial,sans-serif; font-weight: 600 !important;">
			Method
			</FONT>
			</TD>
		
			<!-- HTTP Request Method Input field -->
			<TD WIDTH="100" ALIGN="LEFT" VALIGN="MIDDLE">
			<INPUT TYPE="TEXT" NAME="R_METHOD" VALUE="$form_method" style="WIDTH: 100px; font-size: 10pt; font-family:verdana, arial,sans-serif">
			</TD>
			
			
			
			<!-- Spider/Ripper/RipURL Buttons -->
			<TD WIDTH="350" ALIGN="RIGHT" VALIGN="MIDDLE">
			<INPUT TYPE="BUTTON" VALUE="Spider" style="font-size: 10pt; font-family:verdana, arial,sans-serif" OnClick="sender('SPIDER', this.form);">
			<INPUT TYPE="BUTTON" VALUE="Ripper" style="font-size: 10pt; font-family:verdana, arial,sans-serif" OnClick="sender('RIPPER', this.form);">
			</TD>
			
			</TR>
			
			
			</TABLE>
		</TD>
		</TR>
		
		
		</TABLE>
		
		
	</TD>
	
	</TR></TABLE><BR>
	
EOF



	return;

} # End Form Tag SubRoutine


sub inputTag {
	my $lin = $_[0];
	my $input_name = "X_NO_NAME";
	my $input_type = "TEXT";
	my $input_value = "";
	my $input_src = ""; # 


	# BASE URI
	my $base_url = $rData{'PROTOCOL'} . "://" . $rData{'HOST'} . $rData{'PATH'};
	$base_url = URI->new($base_url);
	
	
	if($lin =~ /(NAME)(=)(["]?|[']?)([\w\d\_\-\.]+)(["]?|[']?|[>]?)/i) { # 'NAME ELEMENT
		$input_name = $4;
	} # End Name

	if($lin =~ /(TYPE)(=)(["]?|[']?)(TEXT|PASSWORD|HIDDEN|CHECKBOX|RADIO)(["]?|[']?|[>]?)/i) { # 'TYPE ELEMENT
		if ($4 =~ /^RADIO$/i) {
			if (defined $radio_names{$input_name}) {
				return;
			} else {
				$radio_names{$input_name} = 1;
			}
		}
		
		$input_type = "TEXT";
	} elsif ($lin =~ /(TYPE)(=)(["]?|[']?)(BUTTON|SUBMIT|RESET|IMAGE)(["]?|[']?|[>])/i) {
		$input_type = $4;

		if($lin =~ /(SRC)(=)(["]?|[']?)([\w\d\_\-\:\/\?\.\&\@\#]+)(["]?|[']?|[>]?)/i) { # Catch the SRC
			$input_src = URI->new($4);
			$input_src = $input_src->abs($base_url);       # Absolute Input SRC
		}

	} # End TYPE

	
	if($lin =~ /(VALUE)(=)(["]?|[']?)([\w\d\s!@#\$%\^&\*\(\)\-_=\+\[\]\{\}\;:\.,\?\/\\\|\']+)(["]?|[']?|[>]?)/i) { # 'VALUE ELEMENT
		$input_value = $4;
	} # End VALUE

	print "INPUTTAG NAME: $input_name TYPE: $input_type SRC: $input_src VALUE: $input_value\n" if ($Debug == 1);


	$lin =~ s/</\&lt\;/g;
	$lin =~ s/>/\&gt\;/g;
	$lin =~ s/(["])/\&quot\;/g;
	
	print "<TABLE BGCOLOR=\"#cee3f0\" BORDER=\"0\" CELLSPACING=\"2\" CELLPADDING=\"0\">\n";
	print "<TR><TD WIDTH=\"565\" ALIGN=\"LEFT\" VALIGN=\"TOP\">\n";

		print "<TABLE BORDER=\"0\" CELLSPACING=\"0\" CELLPADDING=\"1\">\n";
		print "<TR><TD BGCOLOR=\"#FFFFFF\" ALIGN=\"LEFT\" VALIGN=\"TOP\">\n";

			print "<TABLE BORDER=\"0\" CELLSPACING=\"0\" CELLPADDING=\"2\">\n";
	
	

			print "<TR WIDTH=\"565\"><TD ALIGN=\"LEFT\" VALIGN=\"TOP\" WIDTH=\"565\">\n";
			
			
				print "<TABLE BORDER=\"0\" CELLSPACING=\"0\" CELLPADDING=\"2\"><TR>\n";
				
				
				print "<TD ALIGN=\"LEFT\" VALIGN=\"TOP\" BGCOLOR=\"#cee3f0\" WIDTH=\"60\">\n";
				print "<FONT SIZE=2 COLOR=3300FF STYLE=\"font-size: 12px\; font-family:verdana, arial, sans-serif\">\n";
				print "<B>Name</B>";
				print "</TD>\n";
				
				
				print "<TD ALIGN=\"LEFT\" VALIGN=\"TOP\" BGCOLOR=\"#FFFFFF\" WIDTH=\"450\">\n";
				print "<FONT SIZE=2 COLOR=3300FF STYLE=\"font-size: 12px\; font-family:verdana, arial, sans-serif\">\n";
				print WrapString($input_name,50);
				print "</TD>\n";
				
				
				print "</TR></TABLE>\n";
				
				
				print "<TR WIDTH=\"565\"><TD ALIGN=\"LEFT\" VALIGN=\"TOP\" WIDTH=\"565\">\n";
			
			
				print "<TABLE BORDER=\"0\" CELLSPACING=\"0\" CELLPADDING=\"2\"><TR>\n";
				
				
				print "<TD ALIGN=\"LEFT\" VALIGN=\"TOP\" BGCOLOR=\"#cee3f0\" WIDTH=\"60\">\n";
				print "<FONT SIZE=2 COLOR=3300FF STYLE=\"font-size: 12px\; font-family:verdana, arial, sans-serif\">\n";
				print "<B>Value</B>";
				print "</TD>\n";
				
				
		if($input_src eq "") {
			my $style;
			
			if($input_type =~ /^(SUBMIT|BUTTON|RESET)$/i) {
				$style = "font-size: 10px\; font-family:verdana, arial, sans-serif";
			} else {
				$style = "WIDTH:450px; font-size: 10px\; font-family:verdana, arial, sans-serif";
			}
		
			print "<TD ALIGN=\"LEFT\" VALIGN=\"TOP\" BGCOLOR=\"#FFFFFF\" WIDTH=\"450\">\n";
			print "<FONT SIZE=2 COLOR=3300FF STYLE=\"font-size: 12px\; font-family:verdana, arial, sans-serif\">\n";
			print "<INPUT TYPE=\"$input_type\" NAME=\"$input_name\"  STYLE=\"$style\" VALUE=\"$input_value\"  OnFocus=\"this.value = parent.menubar.Convert(this.value);\"\;><BR>\n";
			print "<FONT SIZE=2 COLOR=3300FF STYLE=\"font-size: 10px\; font-family: arial, sans-serif\">(<I>$lin</I></FONT>)\n";
			print "</TD>\n";
		
		} else {
			print "<TD ALIGN=\"LEFT\" VALIGN=\"TOP\" BGCOLOR=\"#FFFFFF\" WIDTH=\"450\">\n";
			print "<FONT SIZE=2 COLOR=3300FF STYLE=\"font-size: 12px\; font-family:verdana, arial, sans-serif\">\n";
			print "<INPUT TYPE=\"$input_type\" NAME=\"$input_name\"  SRC=\"$input_src\" NAME=\"$input_name\" STYLE=\"font-family:verdana, arial, sans-serif\" VALUE=\"$input_value\"><BR>\n";
			print "<FONT SIZE=2 COLOR=3300FF STYLE=\"font-size: 10px\; font-family: arial, sans-serif\">(<I>$lin</I></FONT>)\n";
		
			print "</TD>\n";
		}
	


				
				
				print "</TR></TABLE>\n";
				
				
			print "</TD></TR>\n";
			
				
			print "</TD></TR>\n";
			
			
			print "</TABLE>\n";
	
		print "</TD></TR>\n";
		print "</TABLE>\n";

	print "</TD></TR>\n";
	print "</TABLE><BR>\n";
	

	return;
} # End Input Tag SubRoutine






###########################
##  Request Output Mode  ##
###########################
# Print HTML Select Menu of output modes
# Takes in one parameter. Default Output Mode.
sub rOutput {

	# Set Default Output Mode
	my $mode = shift || "";

	# Start HTML Select Menu
	print "<SELECT NAME=\"M_OUTPUT\" style=\"WIDTH: 90px\; font-size: 10px\; font-family:arial,sans-serif\">\n";
	
	
	# RIP Output Mode
	# Check if Default
	if($mode eq "RIP") { # Rip Default
		print "<OPTION VALUE=\"RIPPER\">RIPPER</OPTION>\n";
		print "<OPTION VALUE=\"RIPURL\">RIPURL</OPTION>\n";
	} else { # Not Default
		print "<OPTION VALUE=\"RIPPER\">RIPPER</OPTION>\n";
		print "<OPTION VALUE=\"RIPURL\">RIPURL</OPTION>\n";
	} # End Default Check If
	
		
	print "</SELECT>\n";
	return;
} # End rOutput Subroutine







#########################
##  HTTP Requst Table  ##
#########################
# Print out the HTML HTTP Request Table.
# Show what the HTTP Request information was.

sub httpReqTable {

	my $hin = shift;
	

	print "<TABLE BGCOLOR=\"#fdbe50\" BORDER=\"0\" CELLSPACING=\"2\" CELLPADDING=\"0\">\n";
	print "<TR><TD WIDTH=\"565\" ALIGN=\"LEFT\" VALIGN=\"TOP\">\n";

		print "<TABLE BORDER=\"0\" CELLSPACING=\"0\" CELLPADDING=\"1\">\n";
		print "<TR><TD BGCOLOR=\"#FFFFFF\" ALIGN=\"LEFT\" VALIGN=\"TOP\">\n";

			print "<TABLE BORDER=\"0\" CELLSPACING=\"0\" CELLPADDING=\"2\">\n";
	
			print "<TR WIDTH=\"565\" BGCOLOR=\"#fdbe50\"><TD ALIGN=\"LEFT\" VALIGN=\"TOP\">\n";
			print "<FONT FACE=\"Arial\"><B>Request Information</B></FONT>\n";
			print "</TD></TR>\n";



			print "<TR BGCOLOR=\"#fef5c7\" ALIGN=\"LEFT\" VALIGN=\"TOP\"><TD>\n";
		
				print "<TABLE BORDER=\"0\" CELLSPACING=\"0\" CELLPADDING=\"2\">\n";
				print "<TR>\n";
				print "<TD WIDTH=\"270\" ALIGN=\"LEFT\" VALIGN=\"TOP\" BGCOLOR=\"#fef5c7\">\n";
				printFont("<B>Host:</B> " . HTMLEsc(WrapString(${$hin}{'whisker'}->{'host'}, 40)), "12");
				print "</TD>\n";
			
				print "<TD WIDTH=\"75\" ALIGN=\"LEFT\" VALIGN=\"TOP\" BGCOLOR=\"#fef5c7\">\n";
				printFont("<B>Port:</B>" . HTMLEsc(WrapString(${$hin}{'whisker'}->{'port'}, 40)), "12");
				print "</TD>\n";
	
				print "<TD WIDTH=\"85\" ALIGN=\"LEFT\" VALIGN=\"TOP\" BGCOLOR=\"#fef5c7\">\n";
				printFont("<B>Protocol:</B>" . HTMLEsc(WrapString($rData{'PROTOCOL'}, 40)), "12");
				print "</TD>\n";
	
				print "<TD WIDTH=\"110\" ALIGN=\"LEFT\" VALIGN=\"TOP\" BGCOLOR=\"#fef5c7\">\n";
				printFont("<B>Version:</B> HTTP/" . HTMLEsc(WrapString(${$hin}{'whisker'}->{'http_ver'}, 40)), "12");
				print "</TD>\n";
			
				print "</TR>\n";
			
				print "</TABLE>\n";
			
			print "</TD></TR>\n";
			
			
			
			print "<TR BGCOLOR=\"#fef5c7\" ALIGN=\"LEFT\" VALIGN=\"TOP\"><TD>\n";
		
				print "<TABLE BORDER=\"0\" CELLSPACING=\"0\" CELLPADDING=\"2\">\n";
				print "<TR>\n";
				print "<TD WIDTH=\"100\" ALIGN=\"LEFT\" VALIGN=\"TOP\" BGCOLOR=\"#fef5c7\">\n";
				printFont("<B>Method:</B>" . HTMLEsc(${$hin}{'whisker'}->{'method'}), "12");
				print "</TD>\n";
			
				print "<TD WIDTH=\"200\" ALIGN=\"LEFT\" VALIGN=\"TOP\" BGCOLOR=\"#fef5c7\">\n";
						
				if ((defined $rData{'USERNAME'}) && ($rData{'USERNAME'} ne "")) {
					printFont("<B>Username:</B>" . HTMLEsc($rData{'USERNAME'}), "12");
				} else {
					printFont("<B>Username:</B>", "12");
				}
				print "</TD>\n";
	
				print "<TD WIDTH=\"200\" ALIGN=\"LEFT\" VALIGN=\"TOP\" BGCOLOR=\"#fef5c7\">\n";
				if ((defined $rData{'PASSWORD'}) && ($rData{'PASSWORD'} ne "")) {
					printFont("<B>Password:</B>" . HTMLEsc($rData{'PASSWORD'}), "12");
				} else {
					printFont("<B>Password:</B>", "12");
				}
				print "</TD>\n";
	
			
				print "</TR>\n";
			
				print "</TABLE>\n";
			
			print "</TD></TR>\n";
			
			
			print "<TR BGCOLOR=\"#fdbe50\" ALIGN=\"LEFT\" VALIGN=\"TOP\"><TD>\n";
		
				print "<TABLE BORDER=\"0\" CELLSPACING=\"0\" CELLPADDING=\"2\">\n";
				print "<TR>\n";
				print "<TD WIDTH=\"500\" ALIGN=\"LEFT\" VALIGN=\"TOP\" BGCOLOR=\"#fdbe50\">\n";
				printFont("<B>Path:</B>" . HTMLEsc(WrapString(${$hin}{'whisker'}->{'uri'},40)), "12");
				print "</TD>\n";
			
				print "</TR>\n";
			
				print "</TABLE>\n";
			
			print "</TD></TR>\n";
			
			print "<TR BGCOLOR=\"#fdbe50\" ALIGN=\"LEFT\" VALIGN=\"TOP\"><TD>\n";
		
				print "<TABLE BORDER=\"0\" CELLSPACING=\"0\" CELLPADDING=\"2\">\n";
				print "<TR>\n";
				print "<TD WIDTH=\"500\" ALIGN=\"LEFT\" VALIGN=\"TOP\" BGCOLOR=\"#fdbe50\">\n";
				if ((defined $rData{'CONTENT'}) && ($rData{'CONTENT'} ne "")) {
					printFont("<B>Content:</B>" . HTMLEsc(WrapString(${$hin}{'whisker'}->{'data'},40)), "12");
				} else {
					printFont("<B>Content:</B>", "12");
				}
				print "</TD>\n";
			
				print "</TR>\n";
			
				print "</TABLE>\n";
			
			print "</TD></TR>\n";
			
			
			print "</TABLE>\n";
	
		print "</TD></TR>\n";
		print "</TABLE>\n";

	print "</TD></TR>\n";
	print "</TABLE>\n";

	
	my $req_hdr_len = (scalar @req_headers + 1) || "0";
	# plus one to compensate for setting of User-Agent all the time.
	
	
	if ($req_hdr_len > 0) {
		print "<TABLE BGCOLOR=\"#cee3f0\" BORDER=\"0\" CELLSPACING=\"2\" CELLPADDING=\"0\">\n";
		print "<TR><TD WIDTH=\"565\" ALIGN=\"LEFT\" VALIGN=\"TOP\">\n";

			print "<TABLE BORDER=\"0\" CELLSPACING=\"0\" CELLPADDING=\"1\">\n";
			print "<TR><TD BGCOLOR=\"#FFFFFF\" ALIGN=\"LEFT\" VALIGN=\"TOP\">\n";

				print "<TABLE BORDER=\"0\" CELLSPACING=\"0\" CELLPADDING=\"1\">\n";
	
					print "<TR WIDTH=\"565\" BGCOLOR=\"#cee3f0\"><TD ALIGN=\"LEFT\" VALIGN=\"TOP\">\n";
					printFont("<B>Request Headers</B> ($req_hdr_len)", "12");
					print "</TD></TR>\n";
				
				
				
					foreach my $hdr (keys %{$hin}) {

						unless ($hdr eq "whisker") {
					
						print "<TR BGCOLOR=\"#EEEEEE\" ALIGN=\"LEFT\" VALIGN=\"TOP\"><TD>\n";
		
						print "<TABLE BORDER=\"0\" CELLSPACING=\"0\" CELLPADDING=\"2\">\n";
					
						print "<TR>\n";
						print "<TD WIDTH=\"554\" ALIGN=\"LEFT\" VALIGN=\"TOP\" BGCOLOR=\"#FFFFFF\">\n";
						printFont(HTMLEsc($hdr) . ": " . WrapString(${$hin}{$hdr},40), "12");
						print "</TD>\n";
	
	
						print "</TR>\n";
			
						print "</TABLE>\n";
			
						print "</TD></TR>\n";
				
						}
					}
					
				print "</TABLE>\n";
	
			print "</TD></TR>\n";
			print "</TABLE>\n";

		print "</TD></TR>\n";
		print "</TABLE>\n";
	
	}
	
} # End SubRoutine





####################
##  Links Output  ##
####################
sub linksOutput {

	my $html = shift;
	my $base_url = URI->new(shift);
	
	my @lins = split(/>/, $html);       # Split HTTP Response By Tag


	print "<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0>\n";
	print "<FONT style=\"font-size: 9pt; font-family:verdana, arial,sans-serif; font-weight: 500 !important;\">\n";
	
	foreach my $lin (@lins) { # Look for FILE URLs
                $lin = $lin . ">";    # Fix Split Routine
		
		
		print "LIN: <XMP>$lin</XMP>" if ($Debug == 1);
		
		if (($lin =~ /<A/i) && ($lin =~ /(HREF)(=)(["]?|[']?)([\w\d\`\~\!\@\#\$\%\^\&\*\(\)\-\_\=\+\[\]\{\}\;\:\,\.\/\?\\\']+)(["]?|[']?|[>]?)/i)){
		
			my $n_url = URI->new($4);
			my $new_url = $n_url->abs($base_url);
			my $cnew_url = $new_url;
			$cnew_url =~ s/%([a-fA-F0-9]{2,2})/chr(hex($1))/eg; # URL Decode
			$cnew_url = WrapString($cnew_url, 40);
			print "<TR>\n";
			print "<TD ALIGN=LEFT VALIGN=TOP>\n";
			print "<A HREF=\"javascript:void(0)\;\" OnClick=\"parent.topbar.document.control.URL.value = \'$new_url\'\;\">\n";
			print "<IMG SRC=\"/wharsenal/images/bullseye.jpg\" BORDER=0>\n";
			print "</TD>\n";
			print "<TD ALIGN=LEFT VALIGN=TOP>&nbsp;&nbsp;<A HREF=\"$new_url\" TARGET=\"_BLANK\">$cnew_url</A></TD>\n";
			print "</TR>\n";
				
				
		}
			
		
	}
	print "</FONT>\n";
	
	print "</TABLE>\n";
	
} # End Links Output Sub Routine







###############
##  RIP URL  ##
###############
# Takes in a Fully qualified URL and then creates and edittable HTML form with all the URL properties contained.
# Params: Nothing. Uses $FORM{'R_HOST'} as the URL
# Returns: Nothing. Print HTML Form
# Usage: ripURL();
sub ripURL {

my @uri_parts = LW::utils_split_uri($FORM{'R_URL'});

my $url = "$uri_parts[1]://$uri_parts[2]$uri_parts[0]";



print "<FORM METHOD=\"POST\" NAME=\"control\" ACTION=\"/cgi-bin/wharsenalcgi/ripper.pl\">\n";
print "<INPUT TYPE=\"HIDDEN\" NAME=\"M_SESSION\" VALUE=\"$mData{'SESSION'}\">\n";
print "<INPUT TYPE=\"HIDDEN\" NAME=\"M_CMD\" VALUE=\"RIPPER\">\n";


print "<INPUT TYPE=\"HIDDEN\" NAME=\"M_MIMICK\" VALUE=\"$mData{'MIMICK'}\">\n";
print "<INPUT TYPE=\"HIDDEN\" NAME=\"M_HTTP_FIX\" VALUE=\"$mData{'HTTP_FIX'}\">\n";
print "<INPUT TYPE=\"HIDDEN\" NAME=\"M_HOST_FIX\" VALUE=\"$mData{'HOST_FIX'}\">\n";
print "<INPUT TYPE=\"HIDDEN\" NAME=\"M_REFERER\" VALUE=\"$mData{'REFERER'}\">\n";
print "<INPUT TYPE=\"HIDDEN\" NAME=\"M_WHPROXY\" VALUE=\"$mData{'WHPROXY'}\">\n";


print <<EOF;





<!-- Tab Menu -->
<DIV ID="tabs">
	<SPAN ID="tab1" CLASS="tab tabActive">Connection</SPAN>
	<SPAN ID="tab2" CLASS="tab">Headers</SPAN>
	<SPAN ID="tab3" CLASS="tab">WebAuth</SPAN>
	<SPAN ID="tab4" CLASS="tab">Parameters</SPAN>
</DIV>




<!-- Connect Content -->	
<DIV ID="content1" CLASS="content">


	<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0"><TR>
	
	
	<TD WIDTH="420" ALIGN="LEFT" VALIGN="TOP">
	
	
	
		<TABLE BORDER="0" CELLPADDING="2" CELLSPACING="0">
		
		<TR>
		<TD WIDTH="420" ALIGN="LEFT" VALIGN="MIDDLE">
			<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0">
			<TR>
			<TD WIDTH="60" ALIGN="LEFT" VALIGN="MIDDLE">
			<FONT style="font-size: 10pt; font-family:verdana, arial,sans-serif; font-weight: 600 !important;">
			Address
			</FONT>
			</TD>
			<!-- URL Input field -->
			<TD WIDTH="350" ALIGN="LEFT" VALIGN="MIDDLE">
EOF
print "<INPUT TYPE=\"TEXT\" NAME=\"R_URL\" VALUE=\"$url\" style=\"WIDTH: 350px; font-size: 10pt; font-family:verdana, arial,sans-serif\">\n";
print <<EOF;			
			</TD>
			</TR>
			</TABLE>
		</TD>
		</TR>
		
		<TR>
		<TD WIDTH="420" ALIGN="LEFT" VALIGN="MIDDLE">
			<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0">
			
			<TR>
			
			<TD WIDTH="60" ALIGN="LEFT" VALIGN="MIDDLE">
			<FONT style="font-size: 10pt; font-family:verdana, arial,sans-serif; font-weight: 600 !important;">
			Method
			</FONT>
			</TD>
		
			<!-- HTTP Request Method Input field -->
			<TD WIDTH="60" ALIGN="LEFT" VALIGN="MIDDLE">
EOF
print "<INPUT TYPE=\"TEXT\" NAME=\"R_METHOD\" VALUE=\"$rData{'METHOD'}\" style=\"WIDTH: 50px; font-size: 10pt; font-family:verdana, arial,sans-serif\">\n";
print <<EOF;
</TD>
			
			
			
			
			<!-- Spider/Ripper/RipURL Buttons -->
			<TD WIDTH="200" ALIGN="LEFT" VALIGN="MIDDLE">
			<INPUT TYPE="SUBMIT" VALUE="Ripper" style="font-size: 10pt; font-family:verdana, arial,sans-serif">
			</TD>
			
			</TR>
			
			
			</TABLE>
		</TD>
		</TR>
		
		
		
		</TABLE>
		
		
	</TD>
	
	
	<TD WIDTH="150" ALIGN="LEFT" VALIGN="TOP">
	
	
	
	</TD>
	
	</TR></TABLE>

</DIV>
<!-- End Connect Content -->

	
	
<!-- HTTP Request Headers -->
<DIV ID="content2" CLASS="content">

	<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0">
	
	<TR>
	<TD WIDTH="570" ALIGN="LEFT" VALIGN="TOP">
	
		<TABLE BORDER="0" CELLPADDING="2" CELLSPACING="0">
		<TR>
		
		
		<TD WIDTH="50" ALIGN="RIGHT" VALIGN="MIDDLE">
		<FONT style="font-size: 10pt; font-family:verdana, arial,sans-serif; font-weight: 600 !important;">
		Name
		</FONT>
		</TD>
		
		<!-- Header Name Input field -->
		<TD WIDTH="130" ALIGN="LEFT" VALIGN="MIDDLE">
		<INPUT TYPE="TEXT" NAME="HNAME" VALUE="" style="WIDTH: 120px; font-size: 10pt; font-family:verdana, arial,sans-serif">
		</TD>
		
		<TD WIDTH="50" ALIGN="RIGHT" VALIGN="MIDDLE">
		<FONT style="font-size: 10pt; font-family:verdana, arial,sans-serif; font-weight: 600 !important;">
		Value
		</FONT>
		</TD>
		
		<!-- Header Value Input field -->
		<TD WIDTH="250" ALIGN="LEFT" VALIGN="MIDDLE">
		<INPUT TYPE="TEXT" NAME="HVALUE" VALUE="" style="WIDTH: 240px; font-size: 10pt; font-family:verdana, arial,sans-serif">
		</TD>
		
		<!-- Add Header Button -->
		<TD WIDTH="50" ALIGN="LEFT" VALIGN="MIDDLE">
		<INPUT TYPE="BUTTON" VALUE="Add" OnClick="addHeader();" style="font-size: 10pt; font-family:verdana, arial,sans-serif">
		</TD>
		
		</TR>
		</TABLE>
	
	</TD>
	</TR>
	
	<TR>
	<TD WIDTH="570" ALIGN="LEFT" VALIGN="TOP">
	
		<!-- HTTP Request Headers Input field -->
<TEXTAREA NAME="R_HEADERS" style="WIDTH: 560px; HEIGHT: 200px; font-size: 10pt; font-family:verdana, arial,sans-serif">
EOF

foreach my $hdr (@req_headers) {
	print "$hdr\n";
}

print <<EOF;

</TEXTAREA>
	
	</TD>
	</TR>
	
	</TABLE>
</DIV>

<!-- END HTTP Request Headers -->	


<!-- Web Authentication -->	
<DIV ID="content3" CLASS="content">
	<TABLE BORDER="0" CELLPADDING="2" CELLSPACING="0">
	
	<TR>
	<TD WIDTH="70" ALIGN="RIGHT" VALIGN="MIDDLE">
	<FONT style="font-size: 10pt; font-family:verdana, arial,sans-serif; font-weight: 600 !important;">
	Username
	</FONT>
	</TD>
	
	
	<!-- Username Input field -->
	<TD WIDTH="160" ALIGN="LEFT" VALIGN="MIDDLE">
EOF
print "<INPUT TYPE=\"TEXT\" NAME=\"R_USERNAME\" VALUE=\"$rData{'USERNAME'}\" style=\"WIDTH: 150px; font-size: 10pt; font-family:verdana, arial,sans-serif\">\n";
	
print <<EOF;
	</TD>
	</TR>
	
	
	<TR>
	<TD WIDTH="70" ALIGN="RIGHT" VALIGN="MIDDLE">
	<FONT style="font-size: 10pt; font-family:verdana, arial,sans-serif; font-weight: 600 !important;">
	Password
	</FONT>
	</TD>
		
	<!-- Password Input field -->
	<TD WIDTH="160" ALIGN="LEFT" VALIGN="MIDDLE">
EOF
print "<INPUT TYPE=\"TEXT\" NAME=\"R_PASSWORD\" VALUE=\"$rData{'PASSWORD'}\" style=\"WIDTH: 150px; font-size: 10pt; font-family:verdana, arial,sans-serif\">\n";
	
print <<EOF;
	</TD>
		
	</TR>
	</TABLE>
	
</DIV>
	
<!-- End Web Authentication -->

<!-- Parameters -->	
<DIV ID="content4" CLASS="content">
	
EOF





		
		
 	if (defined $uri_parts[4]) {
		print "Query Defined<BR>\n" if ($Debug == 1);
	
		# Split the name-value pairs
		my @pairs = split(/&/, $uri_parts[4]);
			
		foreach my $pair (@pairs) {
			print "PAIR $pair<BR>\n" if ($Debug == 1);
		
			my $name = "";
			my $value = "";
        		($name, $value) = split(/=/, $pair);
 
 			# Check if Name Exists
			if (defined $name) { # Name Exists
			
				if ($name ne "") { # Name is Not Empty
			
			
					$name =~ s/[\n\r]//g;	# Don't allow newlines
			
 					# Check if Value Exists
					if (defined $value) { # Value Exists
					
						# Check if Value is Empty
						if ($value ne "") { # Value is not Empty
        						$value =~ tr/+/ /; # Un webify value
						} else { # Value is Empty Set Default.
							$value = "";
						} # End Check Value Empty If
			
					} else { # Value not given. Set Default
						$value = "";
					} # End Check Value given if
			
			
					print "NAME: $name VALUE: $value<BR>\n" if ($Debug == 1);
		
		
		
	print "<TABLE BGCOLOR=\"#cee3f0\" BORDER=\"0\" CELLSPACING=\"2\" CELLPADDING=\"0\">\n";
	print "<TR><TD WIDTH=\"565\" ALIGN=\"LEFT\" VALIGN=\"TOP\">\n";

		print "<TABLE BORDER=\"0\" CELLSPACING=\"0\" CELLPADDING=\"1\">\n";
		print "<TR><TD BGCOLOR=\"#FFFFFF\" ALIGN=\"LEFT\" VALIGN=\"TOP\">\n";

			print "<TABLE BORDER=\"0\" CELLSPACING=\"0\" CELLPADDING=\"2\">\n";
	
	

			print "<TR WIDTH=\"565\"><TD ALIGN=\"LEFT\" VALIGN=\"TOP\" WIDTH=\"565\">\n";
			
			
				print "<TABLE BORDER=\"0\" CELLSPACING=\"0\" CELLPADDING=\"2\"><TR>\n";
				
				
				print "<TD ALIGN=\"LEFT\" VALIGN=\"TOP\" BGCOLOR=\"#cee3f0\" WIDTH=\"60\">\n";
				print "<FONT SIZE=2 COLOR=3300FF STYLE=\"font-size: 11pt\; font-family:verdana, arial, sans-serif\">\n";
				print "<B>Name</B>";
				print "</TD>\n";
				
				
				print "<TD ALIGN=\"LEFT\" VALIGN=\"TOP\" BGCOLOR=\"#FFFFFF\" WIDTH=\"450\">\n";
				print "<FONT SIZE=2 COLOR=3300FF STYLE=\"font-size: 11pt\; font-family:verdana, arial, sans-serif\">\n";
				print WrapString($name,50);
				print "</TD>\n";
				
				
				print "</TR></TABLE>\n";
				
				
			print "</TD></TR>\n";


			print "<TR WIDTH=\"565\"><TD ALIGN=\"LEFT\" VALIGN=\"TOP\" WIDTH=\"565\">\n";
			
			
				print "<TABLE BORDER=\"0\" CELLSPACING=\"0\" CELLPADDING=\"2\"><TR>\n";
				
				
				print "<TD ALIGN=\"LEFT\" VALIGN=\"TOP\" BGCOLOR=\"#cee3f0\" WIDTH=\"60\">\n";
				print "<FONT SIZE=2 COLOR=3300FF STYLE=\"font-size: 11pt\; font-family:verdana, arial, sans-serif\">\n";
				print "<B>Value</B>";
				print "</TD>\n";
				
				
				print "<TD ALIGN=\"LEFT\" VALIGN=\"TOP\" BGCOLOR=\"#FFFFFF\" WIDTH=\"450\">\n";
				print "<FONT SIZE=2 COLOR=3300FF STYLE=\"font-size: 11pt\; font-family:verdana, arial, sans-serif\">\n";
				print "<INPUT TYPE=\"TEXT\" NAME=\"$name\"  STYLE=\"WIDTH:450px; font-size: 10pt\; font-family:verdana, arial, sans-serif\" VALUE=\"$value\">\n";
				print "</TD>\n";
				
				
				print "</TR></TABLE>\n";
				
				
			print "</TD></TR>\n";
			
			
			print "</TABLE>\n";
	
		print "</TD></TR>\n";
		print "</TABLE>\n";

	print "</TD></TR>\n";
	print "</TABLE><BR>\n";
	
		
				
				} # End Check Name is empty If
			
			} # End Name Exists Check if
			
		} # end pairs foreach
			
	} # End Check if Query String Exists
	


		

print <<EOF;	
	
</DIV>
	
<!-- End Parameters -->


EOF
	
	
	
		

} # End Rip Url SubRoutine




###################
##  Style Script ##
###################
sub styleScript {

print <<EOF;

<STYLE TYPE="text/css">
	/* <![CDATA[ */
	    body{
	   	    margin: 0;
	    }



		/*               LEGEND               
		| .content    -- the content div             |
		| #tabs       -- the div that holds all tabs |
		| .tab        -- an inactive tab             |
		| .tabActive  -- an active tab               |
		| .tabHover  -- an inactive tab onMouseOver  |
		|___________________________________________*/
		
     .content {
         position: absolute;
         left: 5px;
         top: 116px;
         font-family: Trebuchet MS, Arial, sans-serif;
         padding: 3px 5px 0px 5px;
         margin: 0 3px;
         border: 1px solid #000;
         width: 570px;
         border-top: 1px solid #000;
         border-left: 1px solid #000;
         z-index: 500;
         background-color: #FFFFFF;
     }
     #content2,#content3,#content4,#content5,#content6,#content7,#content8{
          z-index:1;visibility:hidden
     }
      #tabs {
         position: absolute;
         top: 100px;
         left: 8px;
         height: 22px;
         white-space: nowrap;
         width: 600px;
         font-size: 10pt;
         font: Menu;
         cursor: default !important;
         font-weight: 700 !important;
         white-space:nowrap;
         z-index: 10000;
      }
      .tab {
         font: inherit;
         position: relative;
         border: 1px solid #000;
         border-bottom: 0;
         padding:2px 9px 1px 9px;
         background-color: #fdbe50;
         color:#303036;
         z-index: 100;
         border-bottom: 0;
    }
      .tabActive {
         padding: 3px 9px 1px 9px;
         color: #060610 !important;
         background-color: #fef5c7 !important;
         top: 1px;
         z-index: 10000;
         border-bottom: 0;
      }
      .tabHover {
         border: 1px solid #347;
         padding:2px 9px 1px 9px;
         background-color: #46596f;
         color:#fff;
         z-index: 1200;
         border-bottom: 0;
      }	
	/* ]]> */
</STYLE>

<SCRIPT TYPE="text/javascript">
// <![CDATA[


function sender(rtype, f) {


	if (rtype == "SPIDER") {
		f.action = "/cgi-bin/wharsenalcgi/spider.pl"
	}
	
	if (rtype == "RIPPER") {
		f.M_CMD.value = "RIPPER";
		f.action = "/cgi-bin/wharsenalcgi/ripper.pl"
	} 
	
	
	for (var x = 0; x < parent.topbar.document.control.OPTIONS.options.length; x++) {
	
		if (parent.topbar.document.control.OPTIONS.options[x].selected) {
			f.elements[x].value = "ON"
		} else {
			f.elements[x].value = "OFF"
		}
		
	}
	
	f.M_SESSION.value = parent.menubar.document.SESSIONS.SESSION.options[parent.menubar.document.SESSIONS.SESSION.selectedIndex].value;
	f.M_MAX.value = parent.topbar.document.control.MAX.options[parent.topbar.document.control.MAX.selectedIndex].value;
	f.R_USERNAME.value = parent.topbar.document.control.USERNAME.value;
	f.R_PASSWORD.value = parent.topbar.document.control.PASSWORD.value;
	f.R_HEADERS.value = parent.topbar.document.control.HEADERS.value;
	
	f.submit();
	
}




/**
* Copyright©2001 Garrett S. Smith                     	
* Web: http://dhtmlitchen.com/                         
* This code may be used without permission, for free. This copyright must remain 
* in the code. See http://dhtmlitchen.com/ for usage instructions and terms of use. 
*/                                       
var ua= navigator.userAgent;
var OPERA = (ua.indexOf("Opera") > 0);
var OMNI = (ua.indexOf("Omni") > 0);
var MAC = (navigator.platform.indexOf("PPC") > 0);
var WIN = (navigator.platform=="Win32");
var IE5_0, IE5,IE6,IE5_5,N4,N5,NS6,MAC_IE5,MOZ;
if(!OPERA && !OMNI){
	IE6 = (ua.indexOf("MSIE 6") > 0);
	IE5_0 = (ua.indexOf("MSIE 5.0") > 0);
	IE5_5 = (ua.indexOf("MSIE 5.5") > 0);
	IE5 = (ua.indexOf("MSIE 5") > 0  || IE6 || IE5_5);
	N4 = (document.layers) ? 1 : 0;
	NS6= N5 = (ua.indexOf("Gecko") > 0);
	MAC_IE5 = (MAC && IE5) ? 1 : 0;
	MAC_IE5_1b = (MAC && ua.indexOf("MSIE 5.1b") >= 0);
	WIN_IE5= IE5 && !MAC;
	MOZ= N5 && !(ua.indexOf("Netscape") > 0);
}
request = {
	getParameter : function(testStr){
		var result= "";
		var q = window.location.search;
		var match= q.match(testStr);
		if(match){
			result= q.substring(
				q.indexOf(String(match))+String(match).length+1);
				
		var end= (result.indexOf("&") > 0) ? (result.indexOf("&")) : result.length
			return result.substring(
				result, end)
		}
		return "";
	}
};

var tabs, tabsClone, tabArray, activeTab, relatedTab = null;

TabParams = {
	useCloneOnBottom : true,
	showRemoveLink : true,
	alwaysShowClone : (request.getParameter("alwaysshow") == "true" || window.alwaysshow)
};


function tabInit() {
	if(window.tabInited) return;

	tabs= document.getElementById('tabs');
	tabs.getElementsByClass= objectGetElementsByClass;
	tabArray= tabs.getElementsByClass("*", "tab tabActive");
	activeTab= tabs.getElementsByClass("*", "tabActive")[0] || tabArray[0];
	
	tabArray.isImg= tabArray[0].tagName.toLowerCase() == "img";
	IE5_0noImg= (IE5_0 && !tabArray.isImg && !MAC);
	if(!Boolean(tabs.cloneNode) || !Boolean(tabs.cloneNode(true))
		|| tabArray.isImg) TabParams.useCloneOnBottom = false;
		
	if(TabParams.useCloneOnBottom){
		tabsClone = document.body.appendChild(tabs.cloneNode(true));
		tabsClone.className = "tabsClone";
		
		tabsClone.getElementsByClass= objectGetElementsByClass;
		tabsCloneArray= tabsClone.getElementsByClass("*", "tab tabActive");
	}
	for(var i = 0;i < tabArray.length; i++){
		tabArray[i].content= new Object(document.getElementById("content"+(i+1)));
		if(OPERA) 
			tabArray[i].num = i+1;
			
		if(TabParams.useCloneOnBottom) 
			tabsCloneArray[i].content= document.getElementById("content"+(i+1));
		
		// deal with any img tab.
		if(tabArray[i].tagName.toLowerCase() == "img"){
			tabArray[i]["normalsrc"] = new String(tabArray[i].src);
			tabArray[i].hover= new Image();
			tabArray[i].hover.src= tabArray[i].getAttribute("hoversrc");
			tabArray[i].active= new Image();
			tabArray[i].active.src= tabArray[i].getAttribute("activesrc");
		}
		
		// add Event Listeners for Moz, or override any given handler for IE.
		if(tabArray[i].addEventListener){
			tabArray[i].addEventListener("mouseover", hoverTab ,false);
			tabArray[i].addEventListener("mouseout", hoverOff ,false);
			tabArray[i].addEventListener("mousedown", depressTab ,false);
			if(TabParams.useCloneOnBottom){
				tabsCloneArray[i].addEventListener("mouseover", hoverTab ,false);
				tabsCloneArray[i].addEventListener("mouseout", hoverOff ,false);
				tabsCloneArray[i].addEventListener("mousedown", depressClonedTab ,false);
			}
		}
		else {
			tabArray[i].onmouseover= hoverTab;
			tabArray[i].onmouseout= hoverOff;
			tabArray[i].onmousedown= depressTab;
			if(TabParams.useCloneOnBottom){
				tabsCloneArray[i].onmouseover= hoverTab;
				tabsCloneArray[i].onmouseout= hoverOff;
				tabsCloneArray[i].onmousedown= depressClonedTab;
			}
		}
		if(TabParams.useCloneOnBottom){
			tabsCloneArray[i].depressTab= depressClonedTab;
			tabsCloneArray[i].controller = tabArray[i];
		}
		tabArray[i].bottomTab = tabsCloneArray[i];
		tabArray[i].depressTab= depressTab;
		
		if(TabParams.showRemoveLink){
			tabArray[i].content.appendChild(document.createElement("br"))
			removeTabLink = new Object(
				tabArray[i].content.removeTabLink = 
				tabArray[i].content.appendChild(document.createElement("a"))
			);
			removeTabLink.id = "removeTabLink"+(i+1);
			removeTabLink.href="javascript:removeTabs("+(i+1)+")";
			removeTabLink.appendChild(document.createTextNode(""));
			
			// better to use a className for .removeTabLink in css
			removeTabLink.className = "removeTab";
		}
		
		// Unsightly IE 5.0 hacks (inline boxes not supported, 
		// converting to block elements...)		
		if(IE5_0noImg) {
			// add the width of previous tab plus padding
	
			tabs.tabOffset= tabs.tabOffset ? tabs.tabOffset : 0;
			var tabWidth = tabArray[i].offsetWidth+18;

			tabArray[i].style.left= tabs.tabOffset +"px";

			//add 9px padding to l and r sides
			tabArray[i].style.width= tabWidth +"px";

			if(TabParams.useCloneOnBottom){
				tabsCloneArray[i].style.left= tabs.tabOffset +"px";
				tabsCloneArray[i].style.width = tabWidth +"px";
			}
			tabArray[i].style.display= "block";
			tabArray[i].style.position= "absolute";
			tabArray[i].style.whiteSpace= "nowrap"; // css ignored here.
			if(TabParams.useCloneOnBottom){
				tabsCloneArray[i].style.display = "block";
				tabsCloneArray[i].style.position = "absolute";
				tabsCloneArray[i].style.whiteSpace = "nowrap"; // css ignored here.
			}
			// add the width of previous tab plus tab-spacing (4)
			tabs.tabOffset += parseInt(tabArray[i].offsetWidth) + 4;
		}
		
		// Mac IE bug:
		// when a word ends in white space, Mac IE does not clone it 
		// completetly. Mac IE removes the trailing white-space plus the 
		// last letter of any word, so innerHTML is necessary.
		if(MAC_IE5) tabsCloneArray[i].innerHTML =  tabArray[i].innerHTML;
	}
	
	tabs.onchange= new Function();

	var q = String(window.location.search);
	if(q && q.indexOf("tab=") > 0)
		switchTabs(q.substring(q.indexOf("tab=")+4,q.indexOf("tab=")+8))
	// depress tab 1.
    if(tabArray.isImg) 
    	activeTab.src = activeTab.getAttribute("activesrc");
	
	else{
		activeTab.className = "tab tabActive";
		activeTab.bottomTab.className = activeTab.className;
	}

	
	// Switch to a tab in the search string.
	// Unsightly IE hacks saved for last.
	if(IE5_0 && !MAC && !tabArray.isImg)
		window.defaultStatus= "IE 5.0 does not support inline boxes. Please upgrade to IE 5.5 or 6.0 for better performance.";

		
	if(TabParams.useCloneOnBottom){
		setTabsClonePosition();
		tabsClone.style.height = (activeTab.offsetHeight+1)+"px";
		showTabsCloneIfNecessary();
		if(window.addEventListener)
			window.addEventListener("resize",updateTabsClonePosition, false);
		else window.onresize = updateTabsClonePosition;
	}
	window.tabInited = true;
} // end tabInit
 
 
	function updateTabsClonePosition(e){
		if(activeTab != null)
			setTimeout("setTabsClonePosition();",500);
	}
	function setTabsClonePosition(){
		var adjustment = 0;
		if(MAC_IE5) adjustment = -1 *
			parseInt(activeTab.content.currentStyle.paddingBottom);
		else if(IE5_0) adjustment = -1;
		else adjustment = 1;
		tabsClone.style.top = (activeTab.content.offsetHeight 
							+activeTab.content.offsetTop+adjustment)+"px";
	}
	
	function showTabsCloneIfNecessary(){
		
		var contentBottom = activeTab.content.offsetTop+
		activeTab.content.offsetHeight;
		var visibility = 
			(contentBottom > getViewportHeight() || TabParams.alwaysShowClone) ?
			 "hidden" : "hidden";
		tabsClone.style.visibility = visibility;
	}
	
	function switchTabs(tab,e,hash){
		try{
			document.getElementById(tab).depressTab(e);
 		}
 		catch(exception){}
		if(hash && document.getElementById(hash.substring(1)))
			scrollToElement(hash);
 		else window.scrollTo(0,0);
	}
	function scrollToElement(hash){
		try{
			if(N5) window.location.href=hash;
			if(IE5) document.getElementById(hash.substring(1)).scrollIntoView();
		}
		catch(ex){}
	}

	/**
		tab methods
		hoverTab, hoverOff, and depressTab 
		control the appearance of each tab
	*/
	function hoverTab() {
		if(activeTab==this || activeTab==this.controller) return;
		this.className= "tabHover tab";
		this.src= this.getAttribute("hoversrc");
		if(TabParams.useCloneOnBottom){
			if(this.bottomTab) this.bottomTab.className = "tabHover tab";
			else this.controller.className = "tabHover tab";
		}
			
	}
	function hoverOff() {
		if(activeTab==this || activeTab==this.controller) return;
		this.className= "tab";
		this.src= this["normalsrc"];
		if(TabParams.useCloneOnBottom){
			if(this.bottomTab) this.bottomTab.className = "tab";
			else this.controller.className = "tab";
		}
	}
	function depressTab(e) {
		if(activeTab == this) return;
		relatedTab= activeTab;
		this.className= "tab";
	 	this.className= "tab tabActive";
		this.src= this.getAttribute("activesrc");
		if(activeTab)
			resetTab(activeTab);
		
		activeTab= this;
		if(TabParams.useCloneOnBottom){
			setTabsClonePosition();
			this.bottomTab.className=this.className;
			showTabsCloneIfNecessary();
		}
		tabs.onchange(e);
		if(!OPERA)
			this.content.style.visibility = "visible";

	 	else document.getElementById("content"+this.num).style.visibility = "visible";
	}
	
	// this method is called from the click event listener of a 
	// bottom tab.
	function depressClonedTab(e){
		if(activeTab == this.controller) return;
		this.controller.depressTab(e);
		this.className= "tab";
	 	this.className= "tab tabActive";
		window.scrollTo(0,
			(tabsClone.offsetTop+ tabsClone.offsetHeight) - getViewportHeight()
			);
		
		
	}

	// this function resets a tab and 
	// reset's the tabs bottom tab.
	function resetTab(tab) {
		tab.className= "tab";
		tab.src= tab["normalsrc"];
		if(activeTab.bottomTab) 
			activeTab.bottomTab.className="tab";
			
		if(!OPERA)
			tab.content.style.visibility = "hidden";
			
	 	else document.getElementById("content"+tab.num).style.visibility = "hidden";
	}
	
	
	/**
	* objectGetElementsByClass  -- returns an array of descendant elements 
	* whose class attribute contains the className param.
	* 
	* tagName  -  If tagName if indeterminable, use "*".
	* className  -  one or more classNames. 
	*   (If more than one className is used, they should be separated with a space.) 
	*/
	function objectGetElementsByClass(tagName, className){
		var collection;
		var returnedCollection = [];
		var classArray = className.split(" ");
		if(this.all && tagName == "*") collection = this.all;
		else collection = this.getElementsByTagName(tagName);
 		for(var i = 0, counter = 0; i < collection.length; i++){
 			if(!collection[i].className) continue;
 			var elmClassArray = collection[i].className.split(" ");
 			jloop : for(var j = 0; j < elmClassArray.length; j++)
				for(var k = 0; k < classArray.length; k++)
				if(elmClassArray[j] == classArray[k]){
						returnedCollection[counter++] = collection[i];
						break jloop;
				}
		}
		return returnedCollection;
	}


function getScrollTop(){
	if(NS6) return(window.pageYOffset);
	if(IE6) return(document.documentElement.scrollTop);
	return(document.body.scrollTop);
}
function getViewportHeight(){
	if(NS6) return window.innerHeight;
	if(IE6) return document.documentElement.clientHeight;
	return document.body.clientHeight-2;
}


	/** removes all tabs.
	* sets content position to relative.
	* scrolls activeTab's content into view.
	*/
function removeTabs(index){

	// remove tabs and scroll to activeTab.content.
	// if activeTab is tab1, noScrollFlag = true. don't scroll.
	var noScrollFlag = activeTab.id == "tab1";
	
	resetTab(activeTab);

	var removeTabLink;
	for(var i = 0; i < tabArray.length; i++)
		if(Boolean(tabArray[i].content) && tabArray[i].content.style){
			tabArray[i].content.style.position = "relative";
			if(i != 0){
				tabArray[i].content.style.borderTopWidth = "0";
				if(!MOZ) tabArray[i].content.style.top = "0";
			}
			if(i != tabArray.length-1)
				tabArray[i].content.style.borderBottomWidth = "0";
				
			else tabArray[i].content.style.marginBottom = "10px";
			
			tabArray[i].content.style.visibility = "visible";
			
			removeTabLink = tabArray[i].content.removeTabLink;
			
			if( removeTabLink != null
			&& removeTabLink.firstChild != null
			&& removeTabLink.firstChild.nodeName =="#text") {
			
				var newIndex = 
					parseInt(removeTabLink.id.substring(removeTabLink.id.length-1));
				
				// set up activation for the next consecutive tab.
				if(newIndex < tabArray.length-1)
					newIndex += 1;
				removeTabLink.href = "javascript:undoRemoveTabs('tab"+newIndex+"')";
				
				removeTabLink.firstChild.nodeValue = "show tabs";
			}
			if(NS6) tabArray[tabArray.length-1].content.style.marginBottom = 
				tabArray[0].content.offsetTop + "px";
			
		}
		
		tabs.style.display="none";
		if(TabParams.useCloneOnBottom)tabsClone.style.display = "none";
		
		if(noScrollFlag) return;
 		
 		if(MOZ) window.scrollTo(0, document.getElementById("content"+index).offsetTop);
 		else window.location.hash = 'content'+index;
			
 }


	/** 
	*  sets content position to absolute.
	*  calls switchTabs with sTabToActivate.
	*/
function undoRemoveTabs(sTabToActivate){

	for(var i = 0; i < tabArray.length; i++)
		if(Boolean(tabArray[i].content) && tabArray[i].content.style){
			tabArray[i].content.style.position = "absolute";
			if(i != 0){
				tabArray[i].content.style.top = "";
				tabArray[i].content.style.borderTopWidth = "";
			}
			
			if(i != tabArray.length-1) tabArray[i].content.style.borderBottomWidth = "";
			else tabArray[i].content.style.marginBottom = "";
			
			tabArray[i].content.style.visibility = "hidden";
			
			var removeTabLink = tabArray[i].content.removeTabLink;
			if( removeTabLink != null
				&& removeTabLink.firstChild != null
				&& removeTabLink.firstChild.nodeName =="#text"){
				removeTabLink.firstChild.nodeValue = "";
				removeTabLink.href = "javascript:removeTabs("+(i+1)+")";
			}	
		}
		
		tabs.style.display="block";
		if(TabParams.useCloneOnBottom) 
			tabsClone.style.display = "block";
			
		activeTab = null;
		switchTabs(sTabToActivate, null);
		activeTab = document.getElementById(sTabToActivate);
		if(NS6) tabArray[tabArray.length-1].content.style.marginBottom = "";
		
}
	function myFunction(){
		status=("You just triggered the onchange method by clicking "+activeTab.id);
	}
	function init(){
		tabInit();
		
		//function pointer to function myFunction().
		tabs.onchange=myFunction;
	}
// ]]>
</SCRIPT>


EOF

} # End styleScript Subroutine




###################
##  Sanity Check ##
###################
# Sanity checks all %FORM data as its passing into the cgi.
# Params: Nothing. Just grabs the globally accessible %FORM array for sanity checking
# Return: Nothing. Takes proper action based on the sanity result of each expect input.
# Usage: sanityCheck()
sub sanityCheck {

	print "CHECKING SANITY<BR>\n" if ($Debug == 1);
	
	# Session Name Sanity Checks
	if (defined $FORM{'M_SESSION'}) { # Session Name Exists
	
		if (($FORM{'M_SESSION'} ne "NO SESSION") && ($FORM{'M_SESSION'} =~ /^([\w\d\s]{1,32})$/i)) { # Session Name Exists, but Valid?
	
			# Path to Current Session Directory
			$session_path = $session_dir . $FORM{'M_SESSION'};
			
			# Session path test if Exists
			if (-e $session_path) { # Session Dir Exists
				
				# check if session path is a directory
				if (-d $session_path) { # Session path is a directory
					
					# check if session path is writable
					if (-w $session_path) { # Session path is writable
						$mData{'SESSION'} = $FORM{'M_SESSION'};	# Set Session Name
			
						# Set Results Path
						$results_path = $session_path . "/" . $results_file;
						
						# Set Results Path
						$html_path = $session_path . "/" . $html_file;
			
                				print "RESULTS_PATH: $results_path<BR>\n" if ($Debug == 1);
	
						if (!-e $results_path) {
							open(RES, ">$results_path") || die "Cant create $results_path $!\n";
							print RES "<?xml version=\"1.0\"?>\n";
							print RES "<?xml-stylesheet type=\"text/xsl\" href=\"/wharsenal/styles/ripper.xsl\"?>\n";
							print RES "<ATTEMPTS>\n";
							print RES "</ATTEMPTS>";
							close(RES);
						}
						
						
						

					} else { # Session path not writable
						print "<META HTTP-EQUIV=\"refresh\" CONTENT=\"30; URL=/cgi-bin/wharsenalcgi/session.pl\">\n";
						my $error_string = HTMLEsc("Session \"$FORM{'M_SESSION'}\" is not a writable by the web server. Please change the \"sessions\" directory permissions and all the the files within to the process owner and group of the web server. Or, please choose a or create another session.");
						errorOut("$error_string <A HREF=\"/cgi-bin/wharsenalcgi/session.pl\">session</A>. <BR><I>Re-direct in 30 seconds.</I>");
	
					} # End Session Path is writable if
	

				} else { # Session path not a directory
					print "<META HTTP-EQUIV=\"refresh\" CONTENT=\"4; URL=/cgi-bin/wharsenalcgi/session.pl\">\n";
					my $error_string = HTMLEsc("Session \"$FORM{'M_SESSION'}\" is not a directory. Please choose another session. ");
					errorOut("$error_string <A HREF=\"/cgi-bin/wharsenalcgi/session.pl\">session</A>. <BR><I>Re-direct in 4 seconds.</I>");
	
				} # End Session Path Directory if
	

			} else { # Session path not exist
				print "<META HTTP-EQUIV=\"refresh\" CONTENT=\"4; URL=/cgi-bin/wharsenalcgi/session.pl\">\n";
				my $error_string = HTMLEsc("Session \"$FORM{'M_SESSION'}\" doesnt not exist. Please choose a new session. ");
				errorOut("$error_string <A HREF=\"/cgi-bin/wharsenalcgi/session.pl\">session</A>. <BR><I>Re-direct in 4 seconds.</I>");
	
			} # End Session Path Exists if
	
		} else { # Session Name not valid
		
			my $error_string = HTMLEsc("Session Name \"$FORM{'M_SESSION'}\" is not valid. Please choose a valid session.");
			
			print "<META HTTP-EQUIV=\"refresh\" CONTENT=\"4; URL=/cgi-bin/wharsenalcgi/session.pl\">\n";
			errorOut("$error_string <A HREF=\"/cgi-bin/wharsenalcgi/session.pl\">session</A>. <BR><I>Re-direct in 4 seconds.</I>");
	
		} # End Session Name Sanity Check If
	
	} else { # No Session name given
		print "<META HTTP-EQUIV=\"refresh\" CONTENT=\"4; URL=/cgi-bin/wharsenalcgi/session.pl\">\n";
		errorOut("No session name given. Please set a new <A HREF=\"/cgi-bin/wharsenalcgi/session.pl\">session</A>. <BR><I>Re-direct in 4 seconds.</I>");
	}# End Session Name Sanity Checks
	
	
	
	# Sanity Check Method
	if (defined $FORM{'R_METHOD'}) { # If Method Given
		if($FORM{'R_METHOD'} =~ /^([\w\d\-]){1,36}/) { # Method
			$rData{'METHOD'} = $FORM{'R_METHOD'};	# Set Method
			print "R: METHOD: $rData{'METHOD'}<BR>\n" if ($Debug == 1);
		} else { # No Valid METHOD Given. Default
			$rData{'METHOD'} = "GET";	# Set Method
		} # End Method Sanity Check if
	
	} else { # No Method Given
		$rData{'METHOD'} = "GET";	# Set Method
	} # End Method Check If
			
			
			
	
	# Check if URL is absoulute
	if ($FORM{'R_URL'} =~ /^(http)([s]?)(:\/\/)(.*)/) {
		print "URL " . $FORM{'R_URL'} . "<BR>\n" if ($Debug == 1);
		
		
		my @uri_parts = LW::utils_split_uri($FORM{'R_URL'});
		
		if ($Debug == 1) {
			foreach my $x (@uri_parts) {
				print "$x <BR>\n";
			}
		}
		
		
		
		$rData{'PATH'} =  substr($uri_parts[0], 0, 1024) || "/";
		$rData{'PROTOCOL'} = $uri_parts[1];
		
		# Sanity Check Hostname
		if(defined $uri_parts[2]) {
		
			# Sanity Check Hostname
			if($uri_parts[2] =~ /^([a-zA-Z0-9\.\-]{1,256})$/i) { # Hostname OK.
				$rData{'HOST'} = $uri_parts[2];	# Set Host
				print "R: REQUEST HOST: $rData{'HOST'}<BR>\n" if ($Debug == 1);
			} else { # Hostname Invalid
				my $error_string = HTMLEsc("Hostname \"$uri_parts[2]\" is not valid. Valid hostname or IP Address only.");
				errorOut($error_string);
			} # End Hostname Sanity Check if

		} else { # Hostname Invalid
			my $error_string = HTMLEsc("No hostname given. Please enter a valid hostname");
			errorOut($error_string);
		} # End Hostname Sanity Check if
		
		
		# Sanity Check Port
		if(defined $uri_parts[3]) { # Port
		
			# Sanity Check Port
			if ($uri_parts[3] =~ /^([\d]{1,5})$/) { # Port
				$rData{'PORT'} = $uri_parts[3];	# Set Port
				print "R: PORT: $rData{'PORT'}<BR>\n" if ($Debug == 1);
			} else { # No Valid Port Given. Default
			
				if ($rData{'PROTOCOL'} =~ /^http$/i) {
					$rData{'PORT'} = "80";	# Set Port
				} elsif ($rData{'PROTOCOL'} =~ /^https$/i) {
					$rData{'PORT'} = "443";	# Set Port
				} else {
					$rData{'PORT'} = "80";	# Set Port
				} # End Port Sanity Check if
			}
				
		} else { # No Valid Port Given. Default
			if ($rData{'PROTOCOL'} =~ /^http$/i) {
				$rData{'PORT'} = "80";	# Set Port
			} elsif ($rData{'PROTOCOL'} =~ /^https$/i) {
				$rData{'PORT'} = "443";	# Set Port
			} else {
				$rData{'PORT'} = "80";	# Set Port
			} # End Port Sanity Check
			
		} # End Port Sanity Check if
		
		
		my $params = "";
		if (defined $uri_parts[4]) {
			$params = substr($uri_parts[4], 0, 1024);
		}
		
		if ($params ne "") {
			if ($rData{'METHOD'} eq "POST") {
				$rData{'CONTENT'} = $params;
			} else {
				$rData{'PATH'} = $rData{'PATH'} . "?" . $params if ($params ne "");
			}
		}
		
	
		# username from URL
		if (defined $uri_parts[6]) {
			$rData{'USERNAME'} = substr($uri_parts[6], 0, 256) || "";
		}
		
		# password from URL
		if (defined $uri_parts[7]) {
			$rData{'PASSWORD'} = substr($uri_parts[7], 0, 256) || "";
		}
		
	
	
	$rData{'USERNAME'} = substr($FORM{'R_USERNAME'}, 0, 256) unless ($rData{'USERNAME'} ne "");
	$rData{'PASSWORD'} = substr($FORM{'R_PASSWORD'}, 0, 256) unless ($rData{'PASSWORD'} ne "");
	
	
	
	} else { # URL is Not absolute
	
		my $error_string = HTMLEsc("URL Must begin with \"http(s)://\".");
		errorOut($error_string);
		exit;
		
		
	} # End Check if URL is absolute
	
	
			
	
	
			
			
	# Sanity Mimic
	if (defined $FORM{'M_MIMICK'}) { # If Mimic Given
	
		# Browser Mimic Sanity Check
		if($FORM{'M_MIMICK'} =~ /^(ON|OFF)$/i) {
			$mData{'MIMICK'} = $FORM{'M_MIMICK'};
			print "M: MIMICK: $mData{'MIMICK'}<BR>\n" if ($Debug == 1);
		} else {
			$mData{'MIMICK'} = "ON"; # Browser Mimic Default On.
		} # End Mimic Sanity Check
	
	} else { # No Mimic Given
		$mData{'MIMICK'} = "ON"; # Default Mimic
	} # End Mimic If
	
	
	
	if(defined $FORM{'M_HTTP_FIX'}) {
		if ($FORM{'M_HTTP_FIX'} =~ /^(ON|OFF)$/i) {
			$mData{'HTTP_FIX'} = $FORM{'M_HTTP_FIX'};
			print "M: HTTP FIX: $mData{'HTTP_FIX'}<BR>\n" if ($Debug == 1);
		} else {
			$mData{'HTTP_FIX'} = "ON"; 
		} 
	
	} else {
		$mData{'HTTP_FIX'} = "ON";  
	} 
	
	
	
	
	if(defined $FORM{'M_HOST_FIX'}) {
		if ($FORM{'M_HOST_FIX'} =~ /^(ON|OFF)$/i) {
			$mData{'HOST_FIX'} = $FORM{'M_HOST_FIX'};
			print "M: HOST FIX: $mData{'HOST_FIX'}<BR>\n" if ($Debug == 1);
		} else {
			$mData{'HOST_FIX'} = "ON"; 
		} 
	
	} else {
		$mData{'HOST_FIX'} = "ON";  
	} 
	
	
	# Sanity Check REFERER
	if (defined $FORM{'M_REFERER'}) { # If Proxy Given
		$mData{'REFERER'} = substr($FORM{'M_REFERER'}, 0, 1024) if ($FORM{'M_REFERER'} ne "");
	} else { # No REFERER Given
		$mData{'REFERER'} = "";
	} # End REFERER If
	
	
	
	
	# Sanity Check WHProxy
	if (defined $FORM{'M_WHPROXY'}) { # If Proxy Given
	
		# Sanity Check Proxy
		if($FORM{'M_WHPROXY'} =~ /^(ON|OFF)$/) { # PROXY
			$mData{'WHPROXY'} = $FORM{'M_WHPROXY'};	# Set PROXY
			print "M: WHPROXY: $mData{'WHPROXY'}<BR>\n" if ($Debug == 1);
		} else { # No Valid PROXY Given. Default
			$mData{'WHPROXY'} = "ON";	# Set PROXY
		} # End PROXY Sanity Check if
	
	} else { # No Proxy Given
		print "NO: WHPROXY: $mData{'WHPROXY'}<BR>\n" if ($Debug == 1);
		$mData{'WHPROXY'} = "ON"; # Default Proxy
	} # End Proxy If
	
	
	
	
	# Sanity Check Output Mode
	if (defined $FORM{'M_CMD'}) { # If Output Mode Given
		# Output Mode Sanity Check
		if($FORM{'M_CMD'} =~ /^(RIPPER)$/) {
			$mData{'CMD'} = $FORM{'M_CMD'};	# Set Output Mode
			print "M: REQUEST CMD: $mData{'CMD'}<BR>\n" if ($Debug == 1);
		} else { # Output Mode invalid
			$mData{'CMD'} = "RIPPER"; # Default Output Mode
		} # End Output Mode Sanity If
	} else { # No Output Mode Given
		$mData{'CMD'} = "RIPPER"; # Default Output Mode
	} # End Output Mode If
	
	
	
	# Set HTTP Request Headers
	$rData{'HEADERS'} = $FORM{'R_HEADERS'} || "";
	@req_headers = split(/\n/, $rData{'HEADERS'}); # Parse Request Headers
	
	
	# Mimic Flag
	my $mimick_flag = "NONE";
	# Check if Mimick Headers are already going in to stop duplication
	foreach my $hdr (@req_headers) {
		if ($hdr =~ /Accept/) {
			$mimick_flag = "ON";
		}
	}
	
	# Browser Header Mimick
	if (($mData{'MIMICK'} eq "ON") && ($mimick_flag eq "NONE")) { # Mimick is On
		print "MIMICKING <BR>\n" if ($Debug == 1);
		foreach my $name (keys %mimickhdrs) { # Loop thru mimick headers
			my $hline = $name . ": " . $mimickhdrs{$name};
			push(@req_headers, $hline);
		} # End Header Loop
	} # End Mimic Header If
	
	

	if ($Debug == 1) { # Print Out Request Headers
		foreach my $hdr (@req_headers) { # Loop Thru Request Headers
			print "REQ HEADER: $hdr<BR>\n";	# Print Header
		} # End Request Header Loop
	} # End Request header if
	
		
	print "IN-INPUT DATA: <BR>\n" if ($Debug == 1);
	foreach my $key (keys %FORM) {
		if (($key !~ /^(M|R|XX|HNAME|HVALUE)(_)/) && ($key !~ /^(X_NO_NAME|HNAME|HVALUE)$/)) {
			print "LIST: $key<BR>\n" if ($Debug == 1);
			$iData{$key} = "$FORM{$key}" || "";
		}
	}
	
	
} # End Check SubRoutine



#####################
### RequestMethod ###
#####################
# This will populate the %FORM hash with paramaters and values.
sub RequestMethod {
	# Determine the request method and then get the input
	
	my $buffer = "";
	
	if (!defined $ENV{'REQUEST_METHOD'}) {
		$ENV{'REQUEST_METHOD'} = "GET";
	}
	
	if ($ENV{'REQUEST_METHOD'} eq 'POST') {
        	read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); # For POST methods
	} else {        
        	$buffer = $ENV{'QUERY_STRING'} || ""; # for GET methods
	} # end if
	
	# Data Clean-up
	if ($buffer ne "") {
		$buffer =~ s/(\0|%00)//g;	# Remove Hidden Nulls
        	$buffer =~ s/[\n]/%0A/g;	# URL Encode Newline
        	$buffer =~ s/[\r]/%0D/g; 	# URL Encode Carriage Returns
	}
	
	# Split the name-value pairs
	my @pairs = split(/&/, $buffer);
 
	foreach my $pair (@pairs) {
        	my ($name, $value) = split(/=/, $pair);
 
		# What happens to Lack of name or value after/before the equals?
		
       		# Un-Webify plus signs and %-encoding
        	$value =~ tr/+/ /;
		$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; # URL Decode Name

        	$name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; # URL Decode Name
		$name =~ s/[\n\r]//g;	# Don't allow newlines
		
		print "NAME: $name VALUE: $value<BR>\n" if ($Debug == 1);
		
                $FORM{$name} = $value; # Build a hash the input parameters
		
	} # end foreach


} # End sub RequestMethod


##################################################################################
