#!/usr/local/bin/perl 

require "cgi-lib.pl";
## require "cgi-utils.pl";
binmode STDIN;
&ReadParse(*input);

$remote_host=$ENV{'REMOTE_HOST'};
if ($remote_host =~/sdsc\.edu/) {
   print "Content-type: text/html\n\n";
##   print "<B>Status: 200 OK, You are from SDSC's domain.</B><BR><P>\n";
}
else {
   print "Content-type: text/html\n\n";
   print "<B>Sorry, you must be Registered to see me!!</B>\n";
   
##   print "remote_host is $remote_host\n";
   exit(0);
}

########################### GLOBALS #################################

$webdir = "/misc/www/users/damartin/cgi-bin/temp/";


#-------------------------------------------------------------
# convert hex characters passed in directory value
#-------------------------------------------------------------

for $i (0..$#input) {
# convert hex versions of :,/,\ to ascii
   $input[$i] =~s/%(..)/pack("c",hex($1))/ge;
}

#-------------------------------------------------------------
# Print out input to see what we got
#-------------------------------------------------------------

@input1 = split(/=/, $input[0]);
## print "<PRE>";
## print "$input1[1]<BR>\n";
## print "</PRE>";


#-------------------------------------------------------------
# Print out that not much is ready at this time
#-------------------------------------------------------------

print "Kenji is not ready at this time, but please return sometime soon!\n";


#-------------------------------------------------------------
# Read info file to see who is registered
#-------------------------------------------------------------

# for error checking
#if ( !(-e $info_file) ) {
#   print "sequence database file $info_file doesn't exist!\n";
#   print "Bailing out..\n";
#   exit(1);
#}

#open(INFILE1, "<$info_file") || die "Unable to open filename \"$!\".\n";
#while($line=<INFILE1>) {
#    @fields = split(' ',$line);
#    if ($fields[0] eq "directory") { $direct=$fields[1]; }
#    elsif ($fields[0] eq "file") { $filena=$fields[1]; }
#}
#close INFILE1;  

#-------------------------------------------------------------
# Write out remote hosts visited to file remhst.dat
#-------------------------------------------------------------
$remhst=$webdir."remhst.dat";
$outfilename = $remhst;

#-------------------------------------------------------------
# start creating output file
#-------------------------------------------------------------
if ( !open(OUTFILE,"> $outfilename") ) {
    print "Error opening an output file $outfilename: $!\n";
    print "Bailing out..\n";
    exit(1);
}
## append info gathered to remhst file
print OUTFILE "$remote_host\n";
close OUTFILE;
