3 # $Id: update.cgi,v 1.5 1999/12/13 04:56:48 tausq Exp $
4 # (c) 1999 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 my $id = $query->param('id');
20 my $authtoken = $query->param('authtoken');
21 my $password = &Util::CheckAuthToken($authtoken);
22 my $editdn = $query->param('editdn');
24 if (!($id && $password)) {
25 print "Location: $proto://$ENV{SERVER_NAME}/$config{webloginurl}\n\n";
32 $ldap->unbind if (defined($ldap));
35 $SIG{__DIE__} = \&DieHandler;
37 $ldap = Net::LDAP->new($config{ldaphost});
40 $mesg = $ldap->bind($editdn, password => $password);
42 $auth = ($mesg->code == LDAP_SUCCESS);
46 &Util::HTMLError("You have not been authenticated. Please <a href=\"$proto://$ENV{SERVER_NAME}/$config{webloginurl}\">Login</a>");
51 $mesg = $ldap->search(base => $editdn,
53 $mesg->code && &Util::HTMLError($mesg->error);
55 my $entries = $mesg->as_struct;
56 if ($mesg->count != 1) {
60 my @dns = keys(%$entries);
61 my $entry = $entries->{$dns[0]};
63 if (!($query->param('doupdate'))) {
64 # Not yet update, just fill in the form with the current values
68 # First do the easy stuff - this catches most of the cases
69 foreach (keys(%$entry)) {
70 $data{$_} = $entry->{$_}->[0];
73 # Now we have to fill in the rest that needs some processing...
75 $data{authtoken} = $authtoken;
76 $data{editdn} = $editdn;
77 $data{staddress} = $entry->{postaladdress}->[0];
78 $data{staddress} =~ s/\$/\n/;
79 $data{countryname} = &Util::LookupCountry($data{c});
81 $data{email} = join(", ", @{$entry->{emailforward}});
83 # finally we can send output...
85 &Util::HTMLSendHeader;
86 open (F, "<$config{webupdatehtml}") || &Util::HTMLError($!);
88 s/~(.+?)~/$data{$1}/g;
94 # Actually update stuff...
95 my ($newpassword, $newstaddress);
97 if (($query->param('labeledurl')) &&
98 ($query->param('labeledurl') !~ /^https?:\/\//i)) {
99 &Util::HTMLError("Your homepage URL is invalid");
102 if ($query->param('newpass') && $query->param('newpassvrfy')) {
103 if ($query->param('newpass') ne $query->param('newpassvrfy')) {
104 # passwords don't match...
105 &Util::HTMLError("The passwords you specified do not match. Please go back and try again.");
107 # create a md5 crypted password
108 $newpassword = '{crypt}'.crypt($query->param('newpass'), &Util::CreateCryptSalt(1));
110 LDAPUpdate($ldap, $editdn, 'userPassword', $newpassword);
111 &Util::UpdateAuthToken($authtoken, $query->param('newpass'));
114 $newstaddress = $query->param('staddress');
115 $newstaddress =~ s/\n/\$/m;
118 ($lat, $long) = &Util::CheckLatLong($query->param('latitude'),
119 $query->param('longitude'));
121 LDAPUpdate($ldap, $editdn, 'postalAddress', $newstaddress);
122 LDAPUpdate($ldap, $editdn, 'l', $query->param('l'));
123 LDAPUpdate($ldap, $editdn, 'latitude', $lat);
124 LDAPUpdate($ldap, $editdn, 'longitude', $long);
125 LDAPUpdate($ldap, $editdn, 'c', $query->param('country'));
126 LDAPUpdate($ldap, $editdn, 'postalcode', $query->param('postalcode'));
127 LDAPUpdate($ldap, $editdn, 'telephoneNumber', $query->param('telephonenumber'));
128 LDAPUpdate($ldap, $editdn, 'facsimileTelephoneNumber', $query->param('facsimiletelephonenumber'));
129 LDAPUpdate($ldap, $editdn, 'loginShell', $query->param('loginshell'));
130 LDAPUpdate($ldap, $editdn, 'emailForward', $query->param('email'));
131 LDAPUpdate($ldap, $editdn, 'privatesub', $query->param('privatesub'));
132 LDAPUpdate($ldap, $editdn, 'ircNick', $query->param('ircnick'));
133 LDAPUpdate($ldap, $editdn, 'labeledUrl', $query->param('labeledurl'));
134 LDAPUpdate($ldap, $editdn, 'onvacation', $query->param('onvacation'));
136 # when we are done, reload the page with the updated details.
137 my $url = "$proto://$ENV{SERVER_NAME}/$config{webupdateurl}?id=$id&authtoken=$authtoken&editdn=";
138 $url .= uri_escape($editdn, "\x00-\x40\x7f-\xff");
139 print "Location: $url\n\n";
152 $mesg = $ldap->modify($dn, delete => { $attr => [] });
154 $val = [ $val ] if (!ref($val));
155 $mesg = $ldap->modify($dn, replace => { $attr => $val });
156 $mesg->code && &Util::HTMLError("error updating $attr: ".$mesg->error);