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

Legend:
Removed from v.7  
changed lines
  Added in v.17

  ViewVC Help
Powered by ViewVC 1.1.26