#!/opt/bin/perl

print "Content-type: text/html\n\n";
$auth = "F";
while (($key, $val) = each %ENV) {
  if ($key eq "QUERY_STRING") {
     # Split the name-value pairs
     @pairs = split(/&/, $val);
     foreach $pair (@pairs) {
       ($name, $value) = split(/=/, $pair);
       $FORM{$name} = $value;
     }
  }
  if ($key eq "HTTP_REFERER" && $val eq "http://teal.duc.auburn.edu/ldap/auth_ldap.html" ||
      $key eq "HTTP_REFERER" && $val eq "http://teal.duc.auburn.edu/rbd/auth_ldap.html") {
     $auth = "T";
  }
}
if ($auth eq "T") {
   print "<h1>Welcome $FORM{'givenName'} $FORM{'sn'} ($FORM{'userid'})!</h1>\n";
} else {
   print "<h1>Unauthorized Connection!</h1>";
}
