#!/client/bin/perl

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

@pairs = split(/&/, $ENV{'QUERY_STRING'});
foreach $pair (@pairs) {
  $pair =~ tr/+/ /;
  $pair =~ s/%(..)/pack("c",hex($1))/ge;

  $pos = index($pair,"=");

  $entry{substr($pair,0,$pos)} = substr($pair,$pos+1);
}

chop($today = `/bin/date`);
# make sure that this logging directory is writable.
# to find out: fs listacl
# to set: fs setacl . system:anyuser write
if (open(LOG, ">>/tmp/ex4_out.html")) {
   print LOG<<END_OF_PRINT;
[$today] host=$ENV{'REMOTE_HOST'} name=$entry{'my_name'} status=$entry{'my_status'}<br>
END_OF_PRINT
   close(LOG);

   print<<END_OF_PRINT;
log message successfully written (as far as I am concerned.)<br>

[$today] host=$ENV{'REMOTE_HOST'} name=$entry{'my_name'} status=$entry{'my_status'}
<p>
<a href="/tmp/ex4_out.html">log</a>
END_OF_PRINT
}
else {
   print<<END_OF_PRINT;
error in writing.
END_OF_PRINT
}