Revision 4080
Added by daigle over 16 years ago
ldapweb.cgi | ||
---|---|---|
27 | 27 |
# account for Metacat access. We currently only support LDAP even |
28 | 28 |
# though metacat could potentially support other types of directories. |
29 | 29 |
# |
30 |
use strict; # turn on strict syntax checking. |
|
31 |
use Template; # load the template-toolkit module. |
|
32 |
use CGI; # load the CGI module. |
|
33 |
use Net::LDAP; # load the LDAP net libraries |
|
34 |
use Net::SMTP; # load the SMTP net libraries |
|
35 |
use Digest::SHA1; # for creating the password hash |
|
36 |
use MIME::Base64; # for creating the password hash |
|
37 |
use URI; # for parsing URL syntax |
|
38 |
use AppConfig qw(:expand :argcount); |
|
30 |
use strict; # turn on strict syntax checking |
|
31 |
use Template; # load the template-toolkit module |
|
32 |
use CGI; # load the CGI module |
|
33 |
use Net::LDAP; # load the LDAP net libraries |
|
34 |
use Net::SMTP; # load the SMTP net libraries |
|
35 |
use Digest::SHA1; # for creating the password hash |
|
36 |
use MIME::Base64; # for creating the password hash |
|
37 |
use URI; # for parsing URL syntax |
|
38 |
use Config::Properties; # for parsing Java .properties files |
|
39 |
use File::Basename; # for path name parsing |
|
39 | 40 |
|
40 |
# Set up our default configuration
|
|
41 |
my $ldapurl = "@ldapurl@";
|
|
42 |
my $mainldapurl = "@ldapurl@";
|
|
43 |
my $root = "@user@";
|
|
44 |
my $rootpw = "@password@";
|
|
45 |
my $searchBase = "@ldapSearchBase@";
|
|
46 |
my $templatesDir = "@templates.dir@";
|
|
47 |
my $mailhost = "@mailhost@";
|
|
48 |
my $sender = "@sender@";
|
|
49 |
my $TIMEOUT = 20;
|
|
50 |
my $mainldapdownmessage = "The main ldap server " . $mainldapurl . " is down!";
|
|
41 |
# Global configuration paramters
|
|
42 |
my $cgiUrl = $ENV{'SCRIPT_FILENAME'};
|
|
43 |
my $workingDirectory = dirname($cgiUrl);
|
|
44 |
my $metacatProps = "${workingDirectory}/../WEB-INF/metacat.properties";
|
|
45 |
my $properties = new Config::Properties();
|
|
46 |
unless (open (METACAT_PROPERTIES, $metacatProps)) {
|
|
47 |
#print "Content-type: text/html\n\n";
|
|
48 |
print "Unable to locate Metacat properties. Working directory is set as " .
|
|
49 |
$workingDirectory .", is this correct?";
|
|
50 |
exit(0);
|
|
51 |
}
|
|
51 | 52 |
|
52 |
# 1.8.1 temporary baseUrl fix |
|
53 |
my $baseUrl = "@systemidserver@@servlet-path@"; |
|
54 |
$baseUrl =~ s/metacat$//; |
|
53 |
$properties->load(*METACAT_PROPERTIES); |
|
55 | 54 |
|
55 |
## Set up our default configuration |
|
56 |
my $ldapProps = $properties->splitToTree(qr/\./, 'ldap'); |
|
57 |
my $ldapurl = $ldapProps->{'url'}; |
|
58 |
my $mainldapurl = $ldapProps->{'mainurl'}; |
|
59 |
my $ldapUsername = $ldapProps->{'user'}; |
|
60 |
my $ldapPassword = $ldapProps->{'password'}; |
|
61 |
my $searchBase = $ldapProps->{'searchbase'}; |
|
62 |
my $mailhost = $properties->getProperty('email.mailhost'); |
|
63 |
my $sender = $properties->getProperty('email.sender'); |
|
64 |
|
|
65 |
# Java uses miliseconds, Perl expects whole seconds |
|
66 |
my $TIMEOUT = $ldapProps->{'connectTimeLimit'} / 1000; |
|
67 |
my $mainldapdownmessage = "The main ldap server $mainldapurl is down!"; |
|
68 |
|
|
56 | 69 |
# Get the CGI input variables |
57 | 70 |
my $query = new CGI; |
58 | 71 |
|
... | ... | |
61 | 74 |
#--------------------------------------------------------------------------80c-> |
62 | 75 |
# Set up the Template Toolkit to read html form templates |
63 | 76 |
|
77 |
# templates hash, imported from ldap.templates tree in metacat.properties |
|
78 |
my $templates = $properties->splitToTree(qr/\./, 'ldap.templates'); |
|
64 | 79 |
|
65 | 80 |
# set some configuration options for the template object |
66 | 81 |
my $config_templates = { |
67 |
INCLUDE_PATH => $templatesDir,
|
|
82 |
INCLUDE_PATH => $properties->getProperty('templates-dir'),
|
|
68 | 83 |
INTERPOLATE => 0, |
69 | 84 |
POST_CHOMP => 1, |
70 | 85 |
}; |
... | ... | |
72 | 87 |
# create an instance of the template |
73 | 88 |
my $template = Template->new($config_templates) || handleGeneralServerFailure($Template::ERROR); |
74 | 89 |
|
75 |
# Read the ldapweb.cfg file |
|
76 |
my $config = AppConfig->new({ |
|
77 |
GLOBAL => { ARGCOUNT => ARGCOUNT_ONE, } }); |
|
90 |
# custom LDAP properties hash |
|
91 |
my $ldapCustom = $properties->splitToTree(qr/\./, 'ldap'); |
|
78 | 92 |
|
79 |
$config->define("ldapurl", { ARGCOUNT => ARGCOUNT_HASH} ); |
|
80 |
$config->define("ldapsearchbase", { ARGCOUNT => ARGCOUNT_HASH} ); |
|
81 |
$config->define("dn", { ARGCOUNT => ARGCOUNT_HASH} ); |
|
82 |
$config->define("filter", { ARGCOUNT => ARGCOUNT_HASH} ); |
|
83 |
$config->define("user", { ARGCOUNT => ARGCOUNT_HASH} ); |
|
84 |
$config->define("password", { ARGCOUNT => ARGCOUNT_HASH} ); |
|
93 |
my @orgList = split(/,/, $properties->getProperty('ldap.organizations')); |
|
94 |
my $ldapConfig; |
|
85 | 95 |
|
86 |
my $cfgfile = "ldapweb.cfg"; |
|
87 |
$config->file($cfgfile); |
|
88 |
my $config_ldapurl = $config->get('ldapurl'); |
|
89 |
my $config_ldapsearchbase = $config->get('ldapsearchbase'); |
|
90 |
my $config_dn = $config->get('dn'); |
|
91 |
my $config_filter = $config->get('filter'); |
|
92 |
my $config_user = $config->get('user'); |
|
93 |
my $config_password = $config->get('password'); |
|
96 |
foreach my $o (@orgList) { |
|
97 |
debug($o); |
|
98 |
# pull the raw tree in to prevent Perl pass-by-value shenanigans |
|
99 |
$ldapConfig->{$o} = $properties->splitToTree(qr/\./, 'ldap'); |
|
94 | 100 |
|
95 |
my @orglist; |
|
96 |
foreach my $neworg (keys %$config_dn) { |
|
97 |
push(@orglist, $neworg); |
|
98 |
debug($neworg); |
|
101 |
# override the defaults set in ldap with the custom values |
|
102 |
if (defined $ldapCustom->{$o}) { |
|
103 |
my $custom = $ldapCustom->{$o}; |
|
104 |
while (my ($key, $value) = each(%$custom)) { |
|
105 |
$ldapConfig->{$o}{$key} = $value; |
|
106 |
} |
|
107 |
} |
|
99 | 108 |
} |
100 | 109 |
|
101 |
|
|
102 | 110 |
#--------------------------------------------------------------------------80c-> |
103 | 111 |
# Define the main program logic that calls subroutines to do the work |
104 | 112 |
#--------------------------------------------------------------------------80c-> |
105 | 113 |
|
106 | 114 |
|
107 | 115 |
# The processing step we are handling |
108 |
my $stage = $query->param('stage') || '@defaultStage@';
|
|
116 |
my $stage = $query->param('stage') || $templates->{'stage'};
|
|
109 | 117 |
|
110 | 118 |
my $cfg = $query->param('cfg'); |
111 | 119 |
|
112 |
# 1.8.1 temporary header/footer fixder = |
|
113 |
|
|
114 |
my $header = ($cfg eq 'nceas') ? 'nceasHeader.tmpl' : '@defaultHeader@'; |
|
115 |
my $footer = ($cfg eq 'nceas') ? 'nceasFooter.tmpl' : '@defaultFooter@'; |
|
116 |
|
|
117 | 120 |
# define the possible stages |
118 | 121 |
my %stages = ( |
119 | 122 |
'initregister' => \&handleInitRegister, |
... | ... | |
149 | 152 |
|
150 | 153 |
print "Content-type: text/html\n\n"; |
151 | 154 |
# process the template files: |
152 |
my $templateVars = { stage => "register", cfg => $cfg }; |
|
153 |
#$$templateVars{'orgList'} = \@orglist; |
|
154 |
$$templateVars{'orgList'} = \@orglist; |
|
155 |
$$templateVars{'baseUrl'} = $baseUrl; |
|
156 |
$template->process( $header, $templateVars); |
|
157 |
$template->process( "@register@", $templateVars); |
|
158 |
$template->process( $footer, $templateVars); |
|
159 |
|
|
155 |
fullTemplate(['register'], {stage => "register"}); |
|
160 | 156 |
exit(); |
161 | 157 |
} |
162 | 158 |
|
... | ... | |
183 | 179 |
if (! paramsAreValid(@requiredParams)) { |
184 | 180 |
my $errorMessage = "Required information is missing. " . |
185 | 181 |
"Please fill in all required fields and resubmit the form."; |
186 |
my $templateVars = { stage => "register", |
|
187 |
cfg => $cfg, |
|
188 |
allParams => $allParams, |
|
189 |
errorMessage => $errorMessage }; |
|
190 |
$$templateVars{'orgList'} = \@orglist; |
|
191 |
$$templateVars{'baseUrl'} = $baseUrl; |
|
192 |
$template->process( $header, $templateVars); |
|
193 |
$template->process( "@register@", $templateVars); |
|
194 |
$template->process( $footer, $templateVars); |
|
195 |
exit(0); |
|
182 |
fullTemplate(['register'], { stage => "register", |
|
183 |
allParams => $allParams, |
|
184 |
errorMessage => $errorMessage }); |
|
185 |
exit(); |
|
196 | 186 |
} else { |
197 | 187 |
my $o = $query->param('o'); |
198 |
$ldapurl = $config_ldapurl->{$o};
|
|
199 |
$searchBase = $config_ldapsearchbase->{$o};
|
|
188 |
$ldapurl = $ldapConfig->{$o}{'url'};
|
|
189 |
$searchBase = $ldapConfig->{$o}{'base'};
|
|
200 | 190 |
} |
201 | 191 |
|
202 | 192 |
# Search LDAP for matching entries that already exist |
... | ... | |
225 | 215 |
|
226 | 216 |
# If entries match, send back a request to confirm new-user creation |
227 | 217 |
if ($found) { |
228 |
my $templateVars = { stage => "registerconfirmed", |
|
229 |
cfg => $cfg, |
|
230 |
allParams => $allParams, |
|
231 |
foundAccounts => $found }; |
|
232 |
$$templateVars{'orgList'} = \@orglist; |
|
233 |
$$templateVars{'baseUrl'} = $baseUrl; |
|
234 |
$template->process( $header, $templateVars); |
|
235 |
$template->process( "@registerMatch@", $templateVars); |
|
236 |
$template->process( "@register@", $templateVars); |
|
237 |
$template->process( $footer, $templateVars); |
|
238 |
|
|
218 |
fullTemplate( ['registerMatch', 'register'], { stage => "registerconfirmed", |
|
219 |
allParams => $allParams, |
|
220 |
foundAccounts => $found }); |
|
239 | 221 |
# Otherwise, create a new user in the LDAP directory |
240 | 222 |
} else { |
241 | 223 |
#print("ingore create account\n"); |
... | ... | |
254 | 236 |
|
255 | 237 |
my $allParams = { 'givenName' => $query->param('givenName'), |
256 | 238 |
'sn' => $query->param('sn'), |
257 |
#'o' => $query->param('o'), |
|
258 |
'o' => 'unaffiliated', |
|
239 |
'o' => 'unaffiliated', # only accept unaffiliated registration |
|
259 | 240 |
'mail' => $query->param('mail'), |
260 | 241 |
'uid' => $query->param('uid'), |
261 | 242 |
'userPassword' => $query->param('userPassword'), |
... | ... | |
264 | 245 |
'telephoneNumber' => $query->param('telephoneNumber') }; |
265 | 246 |
print "Content-type: text/html\n\n"; |
266 | 247 |
createAccount($allParams); |
267 |
|
|
268 | 248 |
exit(); |
269 | 249 |
} |
270 | 250 |
|
... | ... | |
283 | 263 |
$$allParams{'o'} = $query->param('o'); |
284 | 264 |
my $o = $query->param('o'); |
285 | 265 |
|
286 |
$ldapurl = $config_ldapurl->{$o};
|
|
287 |
$searchBase = $config_ldapsearchbase->{$o};
|
|
266 |
$ldapurl = $ldapConfig->{$o}{'url'};
|
|
267 |
$searchBase = $ldapConfig->{$o}{'base'};
|
|
288 | 268 |
} |
289 | 269 |
|
290 | 270 |
|
... | ... | |
294 | 274 |
if (! paramsAreValid(@requiredParams)) { |
295 | 275 |
my $errorMessage = "Required information is missing. " . |
296 | 276 |
"Please fill in all required fields and submit the form."; |
297 |
my $templateVars = { stage => "changepass", |
|
298 |
cfg => $cfg, |
|
299 |
allParams => $allParams, |
|
300 |
errorMessage => $errorMessage }; |
|
301 |
$$templateVars{'orgList'} = \@orglist; |
|
302 |
$$templateVars{'baseUrl'} = $baseUrl; |
|
303 |
$template->process( $header, $templateVars); |
|
304 |
$template->process( "@defaultChangePass@", $templateVars); |
|
305 |
$template->process( $footer, $templateVars); |
|
306 |
exit(0); |
|
277 |
fullTemplate( ['changePass'], { stage => "changepass", |
|
278 |
allParams => $allParams, |
|
279 |
errorMessage => $errorMessage }); |
|
280 |
exit(); |
|
307 | 281 |
} |
308 | 282 |
|
309 | 283 |
# We have all of the info we need, so try to change the password |
310 | 284 |
if ($query->param('userPassword') =~ $query->param('userPassword2')) { |
311 | 285 |
|
312 | 286 |
my $o = $query->param('o'); |
313 |
$ldapurl = $config_ldapurl->{$o};
|
|
314 |
$searchBase = $config_ldapsearchbase->{$o};
|
|
315 |
$root = $config_user->{$o};
|
|
316 |
$rootpw = $config_password->{$o};
|
|
287 |
$ldapurl = $ldapConfig->{$o}{'url'};
|
|
288 |
$searchBase = $ldapConfig->{$o}{'base'};
|
|
289 |
$ldapUsername = $ldapConfig->{$o}{'user'};
|
|
290 |
$ldapPassword = $ldapConfig->{$o}{'password'};
|
|
317 | 291 |
|
318 |
my $dn = "uid=" . $query->param('uid') . "," . $config_dn->{$o};;
|
|
292 |
my $dn = "uid=" . $query->param('uid') . "," . $ldapConfig->{$o}{'dn'};;
|
|
319 | 293 |
if ($query->param('o') =~ "LTER") { |
320 |
$template->process( $header); |
|
321 |
$template->process( "@registerLter@"); |
|
322 |
$template->process( $footer); |
|
294 |
fullTemplate( ['registerLter'] ); |
|
323 | 295 |
} else { |
324 | 296 |
my $errorMessage = changePassword( |
325 | 297 |
$dn, $query->param('userPassword'), |
326 | 298 |
$dn, $query->param('oldpass'), $query->param('o')); |
327 | 299 |
if ($errorMessage) { |
328 |
my $templateVars = { stage => "changepass", |
|
329 |
cfg => $cfg, |
|
330 |
allParams => $allParams, |
|
331 |
errorMessage => $errorMessage }; |
|
332 |
$$templateVars{'orgList'} = \@orglist; |
|
333 |
$$templateVars{'baseUrl'} = $baseUrl; |
|
334 |
$template->process( $header, $templateVars); |
|
335 |
$template->process( "@defaultChangePass@", $templateVars); |
|
336 |
$template->process( $footer, $templateVars); |
|
337 |
exit(0); |
|
300 |
fullTemplate( ['changePass'], { stage => "changepass", |
|
301 |
allParams => $allParams, |
|
302 |
errorMessage => $errorMessage }); |
|
303 |
exit(); |
|
338 | 304 |
} else { |
339 |
my $templateVars = { stage => "changepass", |
|
340 |
cfg => $cfg, |
|
341 |
allParams => $allParams }; |
|
342 |
$$templateVars{'orgList'} = \@orglist; |
|
343 |
$$templateVars{'baseUrl'} = $baseUrl; |
|
344 |
$template->process( $header, $templateVars); |
|
345 |
$template->process( "@changePassSuccess@", $templateVars); |
|
346 |
$template->process( $footer, $templateVars); |
|
347 |
exit(0); |
|
305 |
fullTemplate( ['changePassSuccess'], { stage => "changepass", |
|
306 |
allParams => $allParams }); |
|
307 |
exit(); |
|
348 | 308 |
} |
349 | 309 |
} |
350 | 310 |
} else { |
351 | 311 |
my $errorMessage = "The passwords do not match. Try again."; |
352 |
my $templateVars = { stage => "changepass", |
|
353 |
cfg => $cfg, |
|
354 |
allParams => $allParams, |
|
355 |
errorMessage => $errorMessage }; |
|
356 |
$$templateVars{'orgList'} = \@orglist; |
|
357 |
$$templateVars{'baseUrl'} = $baseUrl; |
|
358 |
$template->process( $header, $templateVars); |
|
359 |
$template->process( "@defaultChangePass@", $templateVars); |
|
360 |
$template->process( $footer, $templateVars); |
|
361 |
exit(0); |
|
312 |
fullTemplate( ['changePass'], { stage => "changepass", |
|
313 |
allParams => $allParams, |
|
314 |
errorMessage => $errorMessage }); |
|
315 |
exit(); |
|
362 | 316 |
} |
363 | 317 |
} |
364 | 318 |
|
... | ... | |
371 | 325 |
|
372 | 326 |
my $allParams = { 'test' => "1", }; |
373 | 327 |
my $errorMessage = ""; |
374 |
my $templateVars = { stage => "changepass", |
|
375 |
cfg => $cfg, |
|
376 |
allParams => $allParams, |
|
377 |
errorMessage => $errorMessage }; |
|
378 |
$$templateVars{'orgList'} = \@orglist; |
|
379 |
$$templateVars{'baseUrl'} = $baseUrl; |
|
380 |
$template->process( $header, $templateVars); |
|
381 |
$template->process( "@defaultChangePass@", $templateVars); |
|
382 |
$template->process( $footer, $templateVars); |
|
383 |
exit(0); |
|
328 |
fullTemplate( ['changePass'], { stage => "changepass", |
|
329 |
errorMessage => $errorMessage }); |
|
330 |
exit(); |
|
384 | 331 |
} |
385 | 332 |
|
386 | 333 |
# |
... | ... | |
398 | 345 |
$$allParams{'o'} = $query->param('o'); |
399 | 346 |
my $o = $query->param('o'); |
400 | 347 |
|
401 |
$ldapurl = $config_ldapurl->{$o};
|
|
402 |
$searchBase = $config_ldapsearchbase->{$o};
|
|
403 |
$root = $config_user->{$o};
|
|
404 |
$rootpw = $config_password->{$o};
|
|
348 |
$ldapurl = $ldapConfig->{$o}{'url'};
|
|
349 |
$searchBase = $ldapConfig->{$o}{'base'};
|
|
350 |
$ldapUsername = $ldapConfig->{$o}{'user'};
|
|
351 |
$ldapPassword = $ldapConfig->{$o}{'password'};
|
|
405 | 352 |
} |
406 | 353 |
|
407 | 354 |
# Check that all required fields are provided and not null |
... | ... | |
409 | 356 |
if (! paramsAreValid(@requiredParams)) { |
410 | 357 |
my $errorMessage = "Required information is missing. " . |
411 | 358 |
"Please fill in all required fields and submit the form."; |
412 |
my $templateVars = { stage => "resetpass", |
|
413 |
cfg => $cfg, |
|
414 |
allParams => $allParams, |
|
415 |
errorMessage => $errorMessage }; |
|
416 |
$$templateVars{'orgList'} = \@orglist; |
|
417 |
$$templateVars{'baseUrl'} = $baseUrl; |
|
418 |
$template->process( $header, $templateVars); |
|
419 |
$template->process( "@defaultResetPass@", $templateVars); |
|
420 |
$template->process( $footer, $templateVars); |
|
421 |
exit(0); |
|
359 |
fullTemplate( ['resetPass'], { stage => "resetpass", |
|
360 |
allParams => $allParams, |
|
361 |
errorMessage => $errorMessage }); |
|
362 |
exit(); |
|
422 | 363 |
} |
423 | 364 |
|
424 | 365 |
# We have all of the info we need, so try to change the password |
425 | 366 |
my $o = $query->param('o'); |
426 |
my $dn = "uid=" . $query->param('uid') . "," . $config_dn->{$o};
|
|
367 |
my $dn = "uid=" . $query->param('uid') . "," . $ldapConfig->{$o}{'dn'};
|
|
427 | 368 |
if ($query->param('o') =~ "LTER") { |
428 |
$template->process( $header); |
|
429 |
$template->process( "@registerLter@"); |
|
430 |
$template->process( $footer); |
|
431 |
exit(0); |
|
369 |
fullTemplate( ['registerLter'] ); |
|
370 |
exit(); |
|
432 | 371 |
} else { |
433 | 372 |
my $errorMessage = ""; |
434 | 373 |
my $recipient; |
... | ... | |
439 | 378 |
if ($entry) { |
440 | 379 |
$recipient = $entry->get_value('mail'); |
441 | 380 |
$userPass = getRandomPassword(); |
442 |
$errorMessage = changePassword($dn, $userPass, $root, $rootpw, $query->param('o'));
|
|
381 |
$errorMessage = changePassword($dn, $userPass, $ldapUsername, $ldapPassword, $query->param('o'));
|
|
443 | 382 |
} else { |
444 | 383 |
$errorMessage = "User not found in database. Please try again."; |
445 | 384 |
} |
446 | 385 |
|
447 | 386 |
if ($errorMessage) { |
448 |
my $templateVars = { stage => "resetpass", |
|
449 |
cfg => $cfg, |
|
450 |
allParams => $allParams, |
|
451 |
errorMessage => $errorMessage }; |
|
452 |
$$templateVars{'orgList'} = \@orglist; |
|
453 |
$$templateVars{'baseUrl'} = $baseUrl; |
|
454 |
$template->process( $header, $templateVars); |
|
455 |
$template->process( "@defaultResetPass@", $templateVars); |
|
456 |
$template->process( $footer, $templateVars); |
|
457 |
exit(0); |
|
387 |
fullTemplate( ['resetPass'], { stage => "resetpass", |
|
388 |
allParams => $allParams, |
|
389 |
errorMessage => $errorMessage }); |
|
390 |
exit(); |
|
458 | 391 |
} else { |
459 | 392 |
my $errorMessage = sendPasswordNotification($query->param('uid'), |
460 | 393 |
$query->param('o'), $userPass, $recipient, $cfg); |
461 |
my $templateVars = { stage => "resetpass", |
|
462 |
cfg => $cfg, |
|
463 |
allParams => $allParams, |
|
464 |
errorMessage => $errorMessage }; |
|
465 |
$$templateVars{'orgList'} = \@orglist; |
|
466 |
$$templateVars{'baseUrl'} = $baseUrl; |
|
467 |
$template->process( $header, $templateVars); |
|
468 |
$template->process( "@resetPassSuccess@", $templateVars); |
|
469 |
$template->process( $footer, $templateVars); |
|
470 |
exit(0); |
|
394 |
fullTemplate( ['resetPassSuccess'], { stage => "resetpass", |
|
395 |
allParams => $allParams, |
|
396 |
errorMessage => $errorMessage }); |
|
397 |
exit(); |
|
471 | 398 |
} |
472 | 399 |
} |
473 | 400 |
} |
... | ... | |
479 | 406 |
sub handleInitialResetPassword { |
480 | 407 |
print "Content-type: text/html\n\n"; |
481 | 408 |
my $errorMessage = ""; |
482 |
my $allParams = { 'test' => "1", }; |
|
483 |
my $templateVars = { stage => "resetpass", |
|
484 |
cfg => $cfg, |
|
485 |
allParams => $allParams, |
|
486 |
errorMessage => $errorMessage }; |
|
487 |
$$templateVars{'orgList'} = \@orglist; |
|
488 |
$$templateVars{'baseUrl'} = $baseUrl; |
|
489 |
$template->process( $header, $templateVars); |
|
490 |
$template->process( "@defaultResetPass@", $templateVars); |
|
491 |
$template->process( $footer, $templateVars); |
|
492 |
exit(0); |
|
409 |
fullTemplate( ['resetPass'], { stage => "resetpass", |
|
410 |
errorMessage => $errorMessage }); |
|
411 |
exit(); |
|
493 | 412 |
} |
494 | 413 |
|
495 | 414 |
# |
... | ... | |
517 | 436 |
my $bindPass = shift; |
518 | 437 |
my $o = shift; |
519 | 438 |
|
520 |
my $ldapurl = $config_ldapurl->{$o};
|
|
521 |
my $searchBase = $config_ldapsearchbase->{$o};
|
|
439 |
my $ldapurl = $ldapConfig->{$o}{'url'};
|
|
440 |
my $searchBase = $ldapConfig->{$o}{'base'};
|
|
522 | 441 |
|
523 | 442 |
my $errorMessage = 0; |
524 | 443 |
my $ldap; |
... | ... | |
601 | 520 |
return $entry; |
602 | 521 |
} |
603 | 522 |
|
604 |
if($config_filter->{$org}){
|
|
523 |
if($ldapConfig->{$org}{'filter'}){
|
|
605 | 524 |
$mesg = $ldap->search ( base => $base, |
606 |
filter => "(&(uid=$username)($config_filter->{$org}))");
|
|
525 |
filter => "(&(uid=$username)($ldapConfig->{$org}{'filter'}))");
|
|
607 | 526 |
} else { |
608 | 527 |
$mesg = $ldap->search ( base => $base, filter => "(uid=$username)"); |
609 | 528 |
} |
... | ... | |
655 | 574 |
This is generally done when somebody forgets their password. Your |
656 | 575 |
password can be changed by visiting the following URL: |
657 | 576 |
|
658 |
@cgiurl@?stage=changepass&cfg=$cfg
|
|
577 |
$cgiUrl?stage=changepass&cfg=$cfg
|
|
659 | 578 |
|
660 | 579 |
Username: $username |
661 | 580 |
Organization: $org |
... | ... | |
770 | 689 |
my $allParams = shift; |
771 | 690 |
|
772 | 691 |
if ($query->param('o') =~ "LTER") { |
773 |
$template->process( $header); |
|
774 |
$template->process( "@registerLter@"); |
|
775 |
$template->process( $footer); |
|
692 |
fullTemplate( ['registerLter'] ); |
|
776 | 693 |
} else { |
777 | 694 |
|
778 | 695 |
# Be sure the passwords match |
779 | 696 |
if ($query->param('userPassword') !~ $query->param('userPassword2')) { |
780 | 697 |
my $errorMessage = "The passwords do not match. Try again."; |
781 |
my $templateVars = { stage => "register", |
|
782 |
cfg => $cfg, |
|
783 |
allParams => $allParams, |
|
784 |
errorMessage => $errorMessage }; |
|
785 |
$$templateVars{'orgList'} = \@orglist; |
|
786 |
$$templateVars{'baseUrl'} = $baseUrl; |
|
787 |
$template->process( $header, $templateVars); |
|
788 |
$template->process( "@registerFailed@", $templateVars); |
|
789 |
$template->process( "@register@", $templateVars); |
|
790 |
$template->process( $footer, $templateVars); |
|
791 |
exit(0); |
|
698 |
fullTemplate( ['registerFailed', 'register'], { stage => "register", |
|
699 |
allParams => $allParams, |
|
700 |
errorMessage => $errorMessage }); |
|
701 |
exit(); |
|
792 | 702 |
} |
793 | 703 |
|
794 | 704 |
my $o = $query->param('o'); |
795 | 705 |
|
796 |
my $ldapurl = $config_ldapurl->{$o};
|
|
797 |
my $root = $config_user->{$o};
|
|
798 |
my $rootpw = $config_password->{$o};
|
|
799 |
my $searchBase = $config_ldapsearchbase->{$o};
|
|
800 |
my $dnBase = $config_dn->{$o};
|
|
706 |
my $ldapurl = $ldapConfig->{$o}{'url'};
|
|
707 |
my $ldapUsername = $ldapConfig->{$o}{'user'};
|
|
708 |
my $ldapPassword = $ldapConfig->{$o}{'password'};
|
|
709 |
my $searchBase = $ldapConfig->{$o}{'base'};
|
|
710 |
my $dnBase = $ldapConfig->{$o}{'dn'};
|
|
801 | 711 |
|
802 | 712 |
|
803 | 713 |
#if main ldap server is down, a html file containing warning message will be returned |
... | ... | |
805 | 715 |
|
806 | 716 |
|
807 | 717 |
$ldap->start_tls( verify => 'none'); |
808 |
$ldap->bind( version => 3, dn => $root, password => $rootpw );
|
|
718 |
$ldap->bind( version => 3, dn => $ldapUsername, password => $ldapPassword );
|
|
809 | 719 |
#print "Inserting new entry...\n"; |
810 | 720 |
my $dn = 'uid=' . $query->param('uid') . ',' . $dnBase; |
811 | 721 |
|
... | ... | |
840 | 750 |
my $result = $ldap->add ( 'dn' => $dn, 'attr' => [ @$additions ]); |
841 | 751 |
|
842 | 752 |
if ($result->code()) { |
843 |
my $templateVars = { stage => "register", |
|
844 |
cfg => $cfg, |
|
845 |
allParams => $allParams, |
|
846 |
errorMessage => $result->error }; |
|
847 |
$$templateVars{'orgList'} = \@orglist; |
|
848 |
$$templateVars{'baseUrl'} = $baseUrl; |
|
849 |
$template->process( $header, $templateVars); |
|
850 |
$template->process( "@registerFailed@", $templateVars); |
|
851 |
$templateVars = { stage => "register", |
|
852 |
cfg => $cfg, |
|
853 |
allParams => $allParams }; |
|
854 |
$$templateVars{'orgList'} = \@orglist; |
|
855 |
$$templateVars{'baseUrl'} = $baseUrl; |
|
856 |
$template->process( "@register@", $templateVars); |
|
857 |
$template->process( $footer, $templateVars); |
|
753 |
fullTemplate( ['registerFailed', 'register'], { stage => "register", |
|
754 |
allParams => $allParams, |
|
755 |
errorMessage => $result->error }); |
|
756 |
# TODO SCW was included as separate errors, test this |
|
757 |
#$templateVars = setVars({ stage => "register", |
|
758 |
# allParams => $allParams }); |
|
759 |
#$template->process( $templates->{'register'}, $templateVars); |
|
858 | 760 |
} else { |
859 |
my $templateVars = { cfg => $cfg }; |
|
860 |
$$templateVars{'baseUrl'} = $baseUrl; |
|
861 |
$template->process( $header, $templateVars); |
|
862 |
$template->process( "@registerSuccess@", $templateVars); |
|
863 |
$template->process( $footer, $templateVars); |
|
761 |
fullTemplate( ['success'] ); |
|
864 | 762 |
} |
865 | 763 |
|
866 | 764 |
$ldap->unbind; # take down session |
... | ... | |
872 | 770 |
print "Content-type: text/html\n\n"; |
873 | 771 |
my $errorMessage = "You provided invalid input to the script. " . |
874 | 772 |
"Try again please."; |
875 |
my $templateVars = { stage => "@defaultStage@", |
|
876 |
cfg => $cfg, |
|
877 |
errorMessage => $errorMessage }; |
|
878 |
$$templateVars{'orgList'} = \@orglist; |
|
879 |
$$templateVars{'baseUrl'} = $baseUrl; |
|
880 |
$template->process( $header, $templateVars); |
|
881 |
$template->process( $footer, $templateVars); |
|
882 |
exit(0); |
|
773 |
fullTemplate( [], { stage => $templates->{'stage'}, |
|
774 |
errorMessage => $errorMessage }); |
|
775 |
exit(); |
|
883 | 776 |
} |
884 | 777 |
|
885 | 778 |
# |
... | ... | |
891 | 784 |
|
892 | 785 |
my $o = $query->param('o'); |
893 | 786 |
|
894 |
my $ldapurl = $config_ldapurl->{$o};
|
|
895 |
my $searchBase = $config_ldapsearchbase->{$o};
|
|
787 |
my $ldapurl = $ldapConfig->{$o}{'url'};
|
|
788 |
my $searchBase = $ldapConfig->{$o}{'base'};
|
|
896 | 789 |
|
897 | 790 |
print "Content-type: text/html\n\n"; |
898 | 791 |
|
... | ... | |
934 | 827 |
|
935 | 828 |
# Send back the search results |
936 | 829 |
if ($found) { |
937 |
my $templateVars = { stage => "searchResults", |
|
938 |
cfg => $cfg, |
|
939 |
allParams => $allParams, |
|
940 |
foundAccounts => $found }; |
|
941 |
$$templateVars{'orgList'} = \@orglist; |
|
942 |
$$templateVars{'baseUrl'} = $baseUrl; |
|
943 |
$template->process( $header, $templateVars); |
|
944 |
$template->process( "@searchResults@", $templateVars); |
|
945 |
$template->process( $footer, $templateVars); |
|
946 |
|
|
830 |
fullTemplate( ('searchResults'), { stage => "searchresults", |
|
831 |
allParams => $allParams, |
|
832 |
foundAccounts => $found }); |
|
947 | 833 |
} else { |
948 | 834 |
$found = "No entries matched your criteria. Please try again\n"; |
949 | 835 |
|
950 |
my $templateVars = { stage => "searchResults", |
|
951 |
cfg => $cfg, |
|
952 |
allParams => $allParams, |
|
953 |
foundAccounts => $found }; |
|
954 |
$$templateVars{'orgList'} = \@orglist; |
|
955 |
$$templateVars{'baseUrl'} = $baseUrl; |
|
956 |
$template->process( $header, $templateVars); |
|
957 |
$template->process( "@searchResults@", $templateVars); |
|
958 |
$template->process( $footer, $templateVars); |
|
959 |
|
|
836 |
fullTemplate( ('searchResults'), { stage => "searchresults", |
|
837 |
allParams => $allParams, |
|
838 |
foundAccounts => $found }); |
|
960 | 839 |
} |
961 | 840 |
|
962 | 841 |
exit(); |
... | ... | |
1035 | 914 |
|
1036 | 915 |
sub handleGeneralServerFailure { |
1037 | 916 |
my $errorMessage = shift; |
1038 |
my $templateVars = { cfg => $cfg, |
|
1039 |
errorMessage => $errorMessage }; |
|
1040 |
$$templateVars{'baseUrl'} = $baseUrl; |
|
1041 |
$template->process( $header, $templateVars); |
|
1042 |
$template->process( "@ldapMainServerFailure@", $templateVars); |
|
1043 |
$template->process( $footer, $templateVars); |
|
917 |
fullTemplate( ('mainServerFailure'), { errorMessage => $errorMessage }); |
|
1044 | 918 |
exit(0); |
1045 | 919 |
} |
1046 | 920 |
|
921 |
sub setVars { |
|
922 |
my $paramVars = shift; |
|
923 |
# initialize default parameters |
|
924 |
my $templateVars = { cfg => $cfg, |
|
925 |
styleSkinsPath => $properties->getProperty('style-skins-path'), |
|
926 |
styleCommonPath => $properties->getProperty('style-common-path'), |
|
927 |
baseUrl => $properties->getProperty('baseUrl'), |
|
928 |
orgList => \@orgList, |
|
929 |
}; |
|
930 |
|
|
931 |
# append customized params |
|
932 |
while (my ($k, $v) = each (%$paramVars)) { |
|
933 |
$templateVars->{$k} = $v; |
|
934 |
} |
|
935 |
|
|
936 |
return $templateVars; |
|
937 |
} |
|
938 |
|
|
939 |
sub fullTemplate { |
|
940 |
my $templateList = shift; |
|
941 |
my $templateVars = setVars(shift); |
|
1047 | 942 |
|
943 |
$template->process( $templates->{'header'}, $templateVars ); |
|
944 |
|
|
945 |
foreach my $tmpl (@{$templateList}) { |
|
946 |
$template->process( $templates->{$tmpl}, $templateVars ); |
|
947 |
} |
|
948 |
$template->process( $templates->{'footer'}, $templateVars ); |
|
949 |
} |
Also available in: Unified diff
Merge 1.9 changes into Head