Project

General

Profile

Revision 8176

Added by Jing Tao over 7 years ago

Add code to generate temporary subtree if it didn't exist.

View differences:

ldapweb.cgi
870 870
    my $allParams = shift;
871 871
    #my $org = $query->param('o'); 
872 872
    my $org = 'LTER';
873
    my $ou = $query-param('ou');
873
    my $ou = $query->param('ou');
874
    #my $ou = 'LTER';
874 875
    my $uid = $query->param('uid');
875 876
    
876 877
    #to see if the organizaton exist
877
    my $tmpSearchBase = 'dc=tmp,' . $authBase;
878
     
878
    my $tmpSearchBase = 'dc=tmp,' . $authBase; 
879 879
    print "Content-type: text/html\n\n";
880 880

  
881

  
882
    # Search LDAP for matching entries that already exist
883
    my $filter = "(o" 
881
    my $filter;
882
    # Search LDAP for matching o or ou that already exist
883
    if($org) {
884
        $filter = "(o" 
884 885
                  . "=" . $org .
885 886
                 ")";
886

  
887
    } else {
888
        $filter = "(ou" 
889
                  . "=" . $ou .
890
                 ")";
891
    }
892
    debug("search filer " . $filter);
893
    debug("ldap server ". $ldapurl);
894
    debug("sesarch base " . $tmpSearchBase);
887 895
    my @attrs = ['o', 'ou' ];
888 896
    my $found = searchDirectory($ldapurl, $tmpSearchBase, $filter, \@attrs);
897
    if(!$found) {
898
        #need to generate the subtree o or ou
899
        my $ldapUsername = $ldapConfig->{$org}{'user'};
900
        my $ldapPassword = $ldapConfig->{$org}{'password'};
901
        debug("LDAP connection to $ldapurl...");    
902
        #if main ldap server is down, a html file containing warning message will be returned
903
        my $ldap = Net::LDAP->new($ldapurl, timeout => $timeout) or handleLDAPBindFailure($ldapurl);
904
        
905
        if ($ldap) {
906
            $ldap->start_tls( verify => 'none');
907
            debug("Attempting to bind to LDAP server with dn = $ldapUsername, pwd = $ldapPassword");
908
            $ldap->bind( version => 3, dn => $ldapUsername, password => $ldapPassword );
889 909

  
890
    if($found) {
891
      print "ldap server ". $ldapurl;
892
      print "sesarch base" . $tmpSearchBase;
893
      print "find the organization " . $org;
894
    } else {
895
      print "ldap server ". $ldapurl;
896
      print "sesarch base " . $tmpSearchBase;
897
      print "not find the organization " . $org;
898
    }
910
            # Do the insertion
911
            my $additions;
912
             if($org) {
913
                $additions = [ 
914
                'o'   => $org,
915
                'objectclass' => ['top', 'organization']
916
                ];
917
             } else {
918
                $additions = [ 
919
                'ou'   => $ou,
920
                'objectclass' => ['top', 'organizationalUnit']
921
                ];
922
             }
923
            
924
            my $result = $ldap->add ( 'dn' => $tmpSearchBase, 'attr' => [ @$additions ]);
925
            if ($result->code()) {
926
                fullTemplate( ['registerFailed', 'register'], { stage => "register",
927
                                                            allParams => $allParams,
928
                                                            errorMessage => $result->error });
929
                # TODO SCW was included as separate errors, test this
930
                #$templateVars    = setVars({ stage => "register",
931
                #                     allParams => $allParams });
932
                #$template->process( $templates->{'register'}, $templateVars);
933
            } 
934
            $ldap->unbind;   # take down session
935
         } else {
936
            fullTemplate( ['registerFailed', 'register'], { stage => "register",
937
                                                            allParams => $allParams,
938
                                                            errorMessage => "The ldap server is not available now. Please try it later"});
939
            exit(0);
940
         }
941
    } 
899 942
    
943
    
944
    
900 945
    #$query->param('o','tmp');
901 946
    #createAccount($allParams);
902 947
    #$query->param('o',$org);

Also available in: Unified diff