Revision 3177
Added by Jing Tao almost 18 years ago
src/perl/ldapweb.cgi | ||
---|---|---|
47 | 47 |
my $mailhost = "@mailhost@"; |
48 | 48 |
my $sender = "@sender@"; |
49 | 49 |
my $TIMEOUT = 20; |
50 |
my $mainldapdownmessage = "The main ldap server " . $mainldapurl . " is down!"; |
|
50 | 51 |
|
51 | 52 |
# Get the CGI input variables |
52 | 53 |
my $query = new CGI; |
... | ... | |
65 | 66 |
}; |
66 | 67 |
|
67 | 68 |
# create an instance of the template |
68 |
my $template = Template->new($config_templates) || die $Template::ERROR, "\n";
|
|
69 |
my $template = Template->new($config_templates) || handleGeneralServerFailure($Template::ERROR);
|
|
69 | 70 |
|
70 | 71 |
# Read the ldapweb.cfg file |
71 | 72 |
my $config = AppConfig->new({ |
... | ... | |
499 | 500 |
my $searchBase = $config_ldapsearchbase->{$o}; |
500 | 501 |
|
501 | 502 |
my $errorMessage = 0; |
502 |
my $ldap = Net::LDAP->new($ldapurl) or die "$@"; |
|
503 |
my $ldap; |
|
504 |
if ($ldapurl =~ $mainldapurl){ |
|
505 |
#if main ldap server is down, a html file containing warning message will be returned |
|
506 |
$ldap = Net::LDAP->new($ldapurl, timeout => $TIMEOUT) or handleGeneralServerFailure($mainldapdownmessage); |
|
507 |
} |
|
508 |
else{ |
|
509 |
#if a referral ldap server is down, we will ignore it silently |
|
510 |
$ldap = Net::LDAP->new($ldapurl, timeout => $TIMEOUT) or return; |
|
511 |
} |
|
503 | 512 |
#$ldap->start_tls( verify => 'require', |
504 | 513 |
#cafile => '/usr/share/ssl/ldapcerts/cacert.pem'); |
505 | 514 |
$ldap->start_tls( verify => 'none'); |
... | ... | |
555 | 564 |
|
556 | 565 |
my $entry = ""; |
557 | 566 |
my $mesg; |
558 |
my $ldap = Net::LDAP->new($ldapurl) or die "$@"; |
|
567 |
my $ldap; |
|
568 |
print("ldap server ", $ldapurl, "\n"); |
|
569 |
if ($ldapurl =~ $mainldapurl){ |
|
570 |
#if main ldap server is down, a html file containing warning message will be returned |
|
571 |
$ldap = Net::LDAP->new($ldapurl, timeout => $TIMEOUT) or handleGeneralServerFailure($mainldapdownmessage); |
|
572 |
} |
|
573 |
else{ |
|
574 |
#if a referral ldap server is down, we will ignore it silently |
|
575 |
$ldap = Net::LDAP->new($ldapurl, timeout => $TIMEOUT) or return; |
|
576 |
} |
|
559 | 577 |
$ldap->start_tls( verify => 'none'); |
560 | 578 |
my $bindresult = $ldap->bind; |
561 | 579 |
if ($bindresult->code) { |
... | ... | |
568 | 586 |
} else { |
569 | 587 |
$mesg = $ldap->search ( base => $base, filter => "(uid=$username)"); |
570 | 588 |
} |
571 |
|
|
589 |
|
|
572 | 590 |
if ($mesg->count > 0) { |
573 | 591 |
$entry = $mesg->pop_entry; |
574 | 592 |
$ldap->unbind; # take down session |
... | ... | |
651 | 669 |
#print("the ldapurl in findExstingAccounts is ", $ldapurl, "\n"); |
652 | 670 |
if ($ldapurl =~ $mainldapurl){ |
653 | 671 |
#if main ldap server is down, a html file containing warning message will be returned |
654 |
$ldap = Net::LDAP->new($ldapurl, timeout => $TIMEOUT) or handleMainLdapServerFailure();
|
|
672 |
$ldap = Net::LDAP->new($ldapurl, timeout => $TIMEOUT) or handleGeneralServerFailure($mainldapdownmessage);
|
|
655 | 673 |
} |
656 | 674 |
else{ |
657 | 675 |
#if a referral ldap server is down, we will ignore it silently |
... | ... | |
759 | 777 |
my $searchBase = $config_ldapsearchbase->{$o}; |
760 | 778 |
my $dnBase = $config_dn->{$o}; |
761 | 779 |
|
762 |
my $ldap = Net::LDAP->new($ldapurl) or die "$@"; |
|
780 |
|
|
781 |
#if main ldap server is down, a html file containing warning message will be returned |
|
782 |
my $ldap = Net::LDAP->new($ldapurl, timeout => $TIMEOUT) or handleGeneralServerFailure("The ldap server " . $ldapurl . " is down!"); |
|
783 |
|
|
784 |
|
|
763 | 785 |
$ldap->start_tls( verify => 'none'); |
764 | 786 |
$ldap->bind( version => 3, dn => $root, password => $rootpw ); |
765 | 787 |
#print "Inserting new entry...\n"; |
... | ... | |
923 | 945 |
|
924 | 946 |
my $foundAccounts = 0; |
925 | 947 |
|
926 |
my $ldap = Net::LDAP->new($ldapurl) or die "$@"; |
|
948 |
|
|
949 |
|
|
950 |
#if ldap server is down, a html file containing warning message will be returned |
|
951 |
my $ldap = Net::LDAP->new($ldapurl, timeout => $TIMEOUT) or handleGeneralServerFailure("The ldap server " . $ldapurl . " is down!"); |
|
952 |
|
|
927 | 953 |
$ldap->start_tls( verify => 'none'); |
928 | 954 |
$ldap->bind( version => 3, anonymous => 1); |
929 | 955 |
my $mesg = $ldap->search ( |
... | ... | |
979 | 1005 |
} |
980 | 1006 |
} |
981 | 1007 |
|
982 |
sub handleMainLdapServerFailure {
|
|
983 |
my $errorMessage = "The main ldap server " . $ldapurl . " is down!";
|
|
1008 |
sub handleGeneralServerFailure {
|
|
1009 |
my $errorMessage = shift;
|
|
984 | 1010 |
my $templateVars = { cfg => $cfg, |
985 | 1011 |
errorMessage => $errorMessage }; |
986 | 1012 |
$template->process( "@defaultHeader@", $templateVars); |
Also available in: Unified diff
Replace die statement in the script