/[A3C]/bin/import-ldap.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /bin/import-ldap.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 10 by dpavlin, Thu Mar 13 14:08:41 2008 UTC revision 48 by dpavlin, Mon Mar 31 21:50:52 2008 UTC
# Line 6  use strict; Line 6  use strict;
6  use lib 'lib';  use lib 'lib';
7    
8  use Jifty;  use Jifty;
9  use Net::LDAP;  use A3C::LDAP;
10  use Data::Dump qw/dump/;  use Data::Dump qw/dump/;
11    use Getopt::Long;
12    
13  BEGIN { Jifty->new; };  BEGIN { Jifty->new; };
14    
15  my $ldap_config = Jifty->config->app('LDAP');  my $limit = 0;
16  Jifty->log->debug( "config->app(LDAP) = ",dump( $ldap_config ) );  my @models;
17    GetOptions(
18  my $ldap = Net::LDAP->new( Jifty->config->app('LDAP')->{Server} ) or die "$@";          'limit=i', => \$limit,
19            'model=s', => \@models,
 # an anonymous bind  
 #my $mesg = $ldap->bind;  
 my $mesg = $ldap->bind(  
         DN       => Jifty->config->app('LDAP')->{DN},  
         password => Jifty->config->app('LDAP')->{Password},  
20  );  );
21    
22  # perform a search  @models = ( 'Organization' ) unless @models;
 $mesg = $ldap->search(  
         base   => "dc=skole,dc=hr",  
 #       filter => "(&(sn=Barr) (o=Texas Instruments))",  
         filter => "(objectClass=hrEduPerson)",  
         sizelimit => 100, # 0 = off  
 );  
   
 if ( $mesg->code ) {  
         warn $mesg->code, ": ", $mesg->error, "\n";  
 }  
   
 Jifty->log->info( "found ", $mesg->count, " entries" );  
   
 foreach my $entry ( $mesg->entries ) {  
   
         $entry->dump;  
   
         my $data;  
         my $user = CAdmin::Model::User->new;  
   
         my @columns = map { $_->name } $user->columns;  
         #warn "# columns = ",dump( @columns );  
23    
24          foreach my $attr ( $entry->attributes ) {  my $ldap = A3C::LDAP->new;
                 if ( grep(/^\Q$attr\E$/, @columns ) ) {  
                         $data->{$attr} = $entry->get_value( $attr );  
                 } else {  
                         warn "model ",ref($user)," doesn't have column $attr\n";  
                 }  
         }  
25    
26          Jifty->log->debug( dump( $data ) );  Jifty->log->info( 'syncing: ', join(',', @models) );
27    
28          $user->load_or_create( %$data );  foreach my $model ( @models ) {
29            my $collection = $ldap->collection( $model, limit => $limit );
30            Jifty->log->info( "found ", $collection->count, " entries for $model" );
31  }  }
32    

Legend:
Removed from v.10  
changed lines
  Added in v.48

  ViewVC Help
Powered by ViewVC 1.1.26