3 # (c) 1999 Debian and Randolph Chung. Licensed under the GPL. <tausq@debian.org>
12 use Net::LDAP qw(:all);
14 my %config = &Util::ReadConfigFile;
17 my $proto = ($ENV{HTTPS} ? "https" : "http");
19 if (!($query->param('username')) || !($query->param('password'))) {
20 print "Location: $proto://$ENV{SERVER_NAME}/$config{webloginurl}\n\n";
24 my $key = &Util::CreateKey($config{blowfishkeylen}); # human-readable version of the key
25 my $hrkey = unpack("H".($config{blowfishkeylen}*2), $key);
26 my $cipher = new Crypt::Blowfish $key;
28 my $ldap = Net::LDAP->new($config{ldaphost}) || &Util::HTMLError($!);
30 my $username = $query->param('username');
31 my $password = $query->param('password');
32 my $binddn = "uid=$username,$config{basedn}";
34 my $mesg = $ldap->bind($binddn, password => $password);
37 if ($mesg->code == LDAP_SUCCESS) {
38 my $cryptid = &Util::SavePasswordToFile($username, $password, $cipher);
40 if ($query->param('update')) {
41 my $url = "$proto://$ENV{SERVER_NAME}/$config{webupdateurl}?id=$username&authtoken=$cryptid:$hrkey&editdn=";
42 $url .= uri_escape("uid=$username,$config{basedn}", "\x00-\x40\x7f-\xff");
43 print "Location: $url\n\n";
45 print "Location: $proto://$ENV{SERVER_NAME}/$config{websearchurl}?id=$username&authtoken=$cryptid:$hrkey\n\n";
50 print "Content-type: text/html\n\n";
51 print "<html><body><h1>Not authenticated</h1></body></html>\n";