3 # (c) 1999 Debian and Randolph Chung. Licensed under the GPL. <tausq@debian.org>
11 use Net::LDAP qw(:all);
13 my %config = &Util::ReadConfigFile;
16 my $proto = ($ENV{HTTPS} ? "https" : "http");
18 my $id = $query->param('id');
19 my $authtoken = $query->param('authtoken');
20 my $password = &Util::CheckAuthToken($authtoken);
21 my $editdn = $query->param('editdn');
23 if (!($id && $password)) {
24 print "Location: $proto://$ENV{SERVER_NAME}/$config{webloginurl}\n\n";
31 $ldap->unbind if (defined($ldap));
34 $SIG{__DIE__} = \&DieHandler;
36 $ldap = Net::LDAP->new($config{ldaphost});
39 $mesg = $ldap->bind($editdn, password => $password);
41 $auth = ($mesg->code == LDAP_SUCCESS);
45 &Util::HTMLError("You have not been authenticated. Please <a href=\"$proto://$ENV{SERVER_NAME}/$config{webloginurl}\">Login</a>");
50 $mesg = $ldap->search(base => $editdn,
52 $mesg->code && &Util::HTMLError($mesg->error);
54 my $entries = $mesg->as_struct;
55 if ($mesg->count != 1) {
59 my @dns = keys(%$entries);
60 my $entry = $entries->{$dns[0]};
62 if (!($query->param('doupdate'))) {
63 # Not yet update, just fill in the form with the current values
67 # First do the easy stuff - this catches most of the cases
68 foreach (keys(%$entry)) {
69 $data{$_} = $entry->{$_}->[0];
72 # Now we have to fill in the rest that needs some processing...
74 $data{authtoken} = $authtoken;
75 $data{editdn} = $editdn;
76 $data{staddress} = $entry->{postaladdress}->[0];
77 $data{staddress} =~ s/\$/\n/;
78 $data{countryname} = &Util::LookupCountry($data{c});
80 $data{email} = join(", ", @{$entry->{emailforward}});
82 # finally we can send output...
84 &Util::HTMLSendHeader;
85 open (F, "<$config{webupdatehtml}") || &Util::HTMLError($!);
87 s/~(.+?)~/$data{$1}/g;
93 # Actually update stuff...
94 my ($newpassword, $newstaddress);
96 if ($query->param('newpass') && $query->param('newpassvrfy')) {
97 if ($query->param('newpass') ne $query->param('newpassvrfy')) {
98 # passwords don't match...
99 &Util::HTMLError("The passwords you specified do not match. Please go back and try again.");
101 # create a md5 crypted password
102 $newpassword = '{crypt}'.crypt($query->param('newpass'), &Util::CreateCryptSalt(1));
104 LDAPUpdate($ldap, $editdn, 'userPassword', $newpassword);
105 &Util::UpdateAuthToken($authtoken, $query->param('newpass'));
108 $newstaddress = $query->param('staddress');
109 $newstaddress =~ s/\n/\$/m;
112 ($lat, $long) = &Util::CheckLatLong($query->param('latitude'),
113 $query->param('longitude'));
115 LDAPUpdate($ldap, $editdn, 'postalAddress', $newstaddress);
116 LDAPUpdate($ldap, $editdn, 'l', $query->param('l'));
117 LDAPUpdate($ldap, $editdn, 'latitude', $lat);
118 LDAPUpdate($ldap, $editdn, 'longitude', $long);
119 LDAPUpdate($ldap, $editdn, 'c', $query->param('country'));
120 LDAPUpdate($ldap, $editdn, 'postalcode', $query->param('postalcode'));
121 LDAPUpdate($ldap, $editdn, 'telephoneNumber', $query->param('telephonenumber'));
122 LDAPUpdate($ldap, $editdn, 'facsimileTelephoneNumber', $query->param('facsimiletelephonenumber'));
123 LDAPUpdate($ldap, $editdn, 'loginShell', $query->param('loginshell'));
124 LDAPUpdate($ldap, $editdn, 'emailForward', $query->param('email'));
125 LDAPUpdate($ldap, $editdn, 'privatesub', $query->param('privatesub'));
126 LDAPUpdate($ldap, $editdn, 'ircNick', $query->param('ircnick'));
127 LDAPUpdate($ldap, $editdn, 'labeledUrl', $query->param('labeledurl'));
128 LDAPUpdate($ldap, $editdn, 'onvacation', $query->param('onvacation'));
130 # when we are done, reload the page with the updated details.
131 my $url = "$proto://$ENV{SERVER_NAME}/$config{webupdateurl}?id=$id&authtoken=$authtoken&editdn=";
132 $url .= uri_escape($editdn, "\x00-\x40\x7f-\xff");
133 print "Location: $url\n\n";
146 $mesg = $ldap->modify($dn, delete => { $attr => [] });
148 $val = [ $val ] if (!ref($val));
149 $mesg = $ldap->modify($dn, replace => { $attr => $val });
150 $mesg->code && &Util::HTMLError("error updating $attr: ".$mesg->error);