/[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

Annotation of /bin/import-ldap.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 9 - (hide annotations)
Thu Mar 13 14:00:40 2008 UTC (11 years, 5 months ago) by dpavlin
Original Path: bin/ldap.pl
File MIME type: text/plain
File size: 1302 byte(s)
debug logging via Jifty->log->debug

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

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26