#!/usr/local/bin/perl

print "Content-type: text/html", "\n\n"  ;

require ChatSign ;
require TimeUtilities ;
$data_basedir=&ChatSign::data_basedir ;
$URLdir_executables=&ChatSign::URLdir_executables ;

$request_method=$ENV{'REQUEST_METHOD'} ;


$browser=$ENV{'HTTP_USER_AGENT'} ;
$browser=~ s/Mozilla/Netscape/g ;
$browser=~ s/MSIE/Microsoft Internet Explorer/g ;

if ($request_method eq "GET") {
$query_string=$ENV{'QUERY_STRING'} ;
# exit (1) ;
} else {
$size_of_form=$ENV{'CONTENT_LENGTH'} ;
read(STDIN, $query_string, $size_of_form) ;
}

# Split the name-value pairs
@pairs = split(/&/, $query_string);

foreach $pair (@pairs) {
	($name, $value) = split(/=/, $pair);
	# Un-Webify plus signs and %-encoding
	$value =~ tr/+/ /;
	# Get rid of all non-alpha/numeric stuff esp " ' ,
	$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
	# $value =~ s/['|"|`|,]//g;
	# Stop people from using subshells to execute commands
	# when using UCB mail (aka mailx).
	$value =~ s/~!/ ~!/g;
	$FORM{$name}=$value ;
}

$FORM{requestor}="Anonymous" ;

print <<ENUF;
<HTML>
<SCRIPT Language="JavaScript">
function make_and_focus(address)
{
chatWindow=window.open('',address,'scrollbars=auto,resizable=yes,width=600,height=600')
chatWindow.focus(address) ;
return (true) ;
}
</SCRIPT>
<TITLE>
ChatSign
</TITLE>
<BODY>
<font face=\"Arial, Helvetica, sans-serif\" size=\"2\">
<CENTER>
<H3>Hello $FORM{requestor}</H3>

<P>JavaScript is a scripting language built into most modern browsers. It is required for ChatSign to work.

<P>If you don't see a red text message below confirming you have Javascript active, then either your browser doesn't support it or it's turned off

<SCRIPT Language=JavaScript>
<!-- Hide
document.write("<P><FONT COLOR=red>You have JavaScript active on your browser</FONT>") ;

//-->
</SCRIPT>

<P>You are using $browser

<P>JavaScript can be turned on in Netscape 4.x by going to the
	<UL>
	<LI>Edit Menu</LI>
	<LI>Preferences</LI>
	<LI>Advanced</LI>
	<LI>and ensuring there is a Tick next to JavaScript on the right side.</LI>
	</UL>


</BODY>
</HTML>
ENUF

exit (0) ;
