/[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 5 by dpavlin, Wed Mar 12 23:14:13 2008 UTC revision 8 by dpavlin, Thu Mar 13 13:49:41 2008 UTC
# Line 7  use lib 'lib'; Line 7  use lib 'lib';
7    
8  use Jifty;  use Jifty;
9  use Net::LDAP;  use Net::LDAP;
10    use Data::Dump qw/dump/;
11    
12  BEGIN { Jifty->new; };  BEGIN { Jifty->new; };
13    
14  my $ldap = Net::LDAP->new( 'ldap1.skole.local' ) or die "$@";  #warn "# config->app(LDAP) = ",dump( Jifty->config->app('LDAP') );
15    
16    my $ldap = Net::LDAP->new( Jifty->config->app('LDAP')->{Server} ) or die "$@";
17    
18  # an anonymous bind  # an anonymous bind
19  my $mesg = $ldap->bind;  #my $mesg = $ldap->bind;
20    my $mesg = $ldap->bind(
21            DN       => Jifty->config->app('LDAP')->{DN},
22            password => Jifty->config->app('LDAP')->{Password},
23    );
24    
25  # perform a search  # perform a search
26  $mesg = $ldap->search(  $mesg = $ldap->search(
27          base   => "dc=skole,dc=hr",          base   => "dc=skole,dc=hr",
28  #       filter => "(&(sn=Barr) (o=Texas Instruments))",  #       filter => "(&(sn=Barr) (o=Texas Instruments))",
29          filter => "(objectClass=hrEduPerson)",          filter => "(objectClass=hrEduPerson)",
30          sizelimit => 0, # off          sizelimit => 3, # 0 = off
31  );  );
32    
33  if ( $mesg->code ) {  if ( $mesg->code ) {
34          warn $mesg->code, ": ", $mesg->error, "\n";          warn $mesg->code, ": ", $mesg->error, "\n";
35  }  }
36    
37    warn "# found ", $mesg->count, " entries\n";
38    
39  foreach my $entry ( $mesg->entries ) {  foreach my $entry ( $mesg->entries ) {
40    
41          $entry->dump;          $entry->dump;
42    
43            my $data;
44            my $user = CAdmin::Model::User->new;
45    
46            my @columns = map { $_->name } $user->columns;
47            #warn "# columns = ",dump( @columns );
48    
49            foreach my $attr ( $entry->attributes ) {
50                    if ( grep(/^\Q$attr\E$/, @columns ) ) {
51                            $data->{$attr} = $entry->get_value( $attr );
52                    } else {
53                            warn "model ",ref($user)," doesn't have column $attr\n";
54                    }
55            }
56    
57            warn dump( $data );
58    
59            $user->load_or_create( %$data );
60  }  }
61    

Legend:
Removed from v.5  
changed lines
  Added in v.8

  ViewVC Help
Powered by ViewVC 1.1.26