3 # $Id: update.cgi,v 1.9 2003/03/13 04:25:56 rmurray 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=\"https://$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 &Util::FixParams($query);
99 if (($query->param('labeledurl')) &&
100 ($query->param('labeledurl') !~ /^https?:\/\//i)) {
101 &Util::HTMLError("Your homepage URL is invalid");
104 if ($query->param('newpass') && $query->param('newpassvrfy')) {
105 if ($query->param('newpass') ne $query->param('newpassvrfy')) {
106 # passwords don't match...
107 &Util::HTMLError("The passwords you specified do not match. Please go back and try again.");
109 # create a md5 crypted password
110 $newpassword = '{crypt}'.crypt($query->param('newpass'), &Util::CreateCryptSalt(1));
112 &Util::LDAPUpdate($ldap, $editdn, 'userPassword', $newpassword);
113 &Util::UpdateAuthToken($authtoken, $query->param('newpass'));
116 $newstaddress = $query->param('staddress');
117 $newstaddress =~ s/\n/\$/m;
120 ($lat, $long) = &Util::CheckLatLong($query->param('latitude'),
121 $query->param('longitude'));
123 &Util::LDAPUpdate($ldap, $editdn, 'postalAddress', $newstaddress);
124 &Util::LDAPUpdate($ldap, $editdn, 'l', $query->param('l'));
125 &Util::LDAPUpdate($ldap, $editdn, 'latitude', $lat);
126 &Util::LDAPUpdate($ldap, $editdn, 'longitude', $long);
127 &Util::LDAPUpdate($ldap, $editdn, 'c', $query->param('country'));
128 &Util::LDAPUpdate($ldap, $editdn, 'postalcode', $query->param('postalcode'));
129 &Util::LDAPUpdate($ldap, $editdn, 'telephoneNumber', $query->param('telephonenumber'));
130 &Util::LDAPUpdate($ldap, $editdn, 'facsimileTelephoneNumber', $query->param('facsimiletelephonenumber'));
131 &Util::LDAPUpdate($ldap, $editdn, 'loginShell', $query->param('loginshell'));
132 &Util::LDAPUpdate($ldap, $editdn, 'emailForward', $query->param('email'));
133 &Util::LDAPUpdate($ldap, $editdn, 'privatesub', $query->param('privatesub'));
134 &Util::LDAPUpdate($ldap, $editdn, 'ircNick', $query->param('ircnick'));
135 &Util::LDAPUpdate($ldap, $editdn, 'icquin', $query->param('icquin'));
136 &Util::LDAPUpdate($ldap, $editdn, 'labeledUrl', $query->param('labeledurl'));
137 &Util::LDAPUpdate($ldap, $editdn, 'onvacation', $query->param('onvacation'));
139 # when we are done, reload the page with the updated details.
140 my $url = "$proto://$ENV{SERVER_NAME}/$config{webupdateurl}?id=$id&authtoken=$authtoken&editdn=";
141 $url .= uri_escape($editdn, "\x00-\x40\x7f-\xff");
142 print "Location: $url\n\n";