Project

General

Profile

« Previous | Next » 

Revision 3175

Added by Jing Tao almost 18 years ago

Change the behavior if the ldap server is down. Now main server is down, a html will be sent back. If it is referral, it will ignore it.

View differences:

ldapweb.cgi
39 39

  
40 40
# Set up our default configuration
41 41
my $ldapurl = "@ldapurl@";
42
my $mainldapurl = "@ldapurl@";
42 43
my $root = "@user@";
43 44
my $rootpw = "@password@";
44 45
my $searchBase = "@ldapSearchBase@";
45 46
my $templatesDir = "@templates.dir@";
46 47
my $mailhost = "@mailhost@";
47 48
my $sender = "@sender@";
49
my $TIMEOUT = 20;
48 50

  
49 51
# Get the CGI input variables
50 52
my $query = new CGI;
......
207 209
    }
208 210

  
209 211
    my @attrs = [ 'uid', 'o', 'cn', 'mail', 'telephoneNumber', 'title' ];
210

  
211 212
    my $found = findExistingAccounts($ldapurl, $searchBase, $filter, \@attrs);
212 213

  
213 214
    # If entries match, send back a request to confirm new-user creation
......
224 225

  
225 226
    # Otherwise, create a new user in the LDAP directory
226 227
    } else {
228
        #print("ingore create account\n");
227 229
        createAccount($allParams);
228 230
    }
229 231

  
......
643 645
    my $base = shift;
644 646
    my $filter = shift;
645 647
    my $attref = shift;
648
    my $ldap;
646 649

  
647 650
    my $foundAccounts = 0;
648

  
649
    my $ldap = Net::LDAP->new($ldapurl) or die "$@";
651
    #print("the ldapurl in findExstingAccounts is ", $ldapurl, "\n");
652
    if ($ldapurl =~ $mainldapurl){
653
        #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();
655
    }
656
    else{
657
        #if a referral ldap server is down, we will ignore it silently
658
        $ldap = Net::LDAP->new($ldapurl, timeout => $TIMEOUT) or return;
659
    }
650 660
    $ldap->start_tls( verify => 'none');
651 661
    $ldap->bind( version => 3, anonymous => 1);
652 662
    my $mesg = $ldap->search (
......
968 978
        print STDERR "$msg\n";
969 979
    }
970 980
}
981

  
982
sub handleMainLdapServerFailure {
983
    my $errorMessage = "The main ldap server " . $ldapurl . " is down!";
984
    my $templateVars = { cfg => $cfg,
985
                         errorMessage => $errorMessage };
986
    $template->process( "@defaultHeader@", $templateVars);
987
    $template->process( "@ldapMainServerFailure@", $templateVars);
988
    $template->process( "@defaultFooter@", $templateVars);
989
    exit(0);   
990
   }
991
    
992

  

Also available in: Unified diff