#!/usr/local/bin/perl

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

# Set up knowledge of data and executable dirs

use TimeUtilities ;
use ChatSign ;
$data_basedir=ChatSign::data_basedir ;
$URLdir_executables=ChatSign::URLdir_executables ;

$request_method=$ENV{'REQUEST_METHOD'} ;

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 ;
}

$now=time ;

$websites="$data_basedir/websites.dat" ;

print <<ENUF;
<HTML>
<TITLE>
List Domains for $FORM{operator}
</TITLE>
<BODY>
<CENTER>
<H3>List Domains for $FORM{operator}</H3>
<TABLE BORDER=1 CELLSPACING=0 CELLPADDING=2>
ENUF

open (PASSWD,$websites) || die "Cannot open $websites file\n" ;
while (<PASSWD>) {
	chomp ;
	($domain,$password,$default_email_address,$operators)=split(/,/) ;
	foreach $operator (split(/:/,$operators)) {
		if ($operator eq $FORM{operator}) {
			print "<TR><TD><A HREF=\"http\:\/\/$domain\">$domain</A></TD></TR>" ;
		}
	}
}

print <<ENUF;
</TABLE>
</CENTER>
</BODY>
</HTML>
ENUF
exit (0) ;

