/[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 7 - (hide annotations)
Thu Mar 13 13:12:46 2008 UTC (16 years ago) by dpavlin
Original Path: bin/ldap.pl
File MIME type: text/plain
File size: 1015 byte(s)
first try at script which imports data from ldap

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     my $ldap = Net::LDAP->new( 'ldap1.skole.local' ) or die "$@";
15    
16     # an anonymous bind
17     my $mesg = $ldap->bind;
18    
19     # perform a search
20     $mesg = $ldap->search(
21     base => "dc=skole,dc=hr",
22     # filter => "(&(sn=Barr) (o=Texas Instruments))",
23     filter => "(objectClass=hrEduPerson)",
24 dpavlin 7 sizelimit => 100, # off
25 dpavlin 5 );
26    
27     if ( $mesg->code ) {
28     warn $mesg->code, ": ", $mesg->error, "\n";
29     }
30    
31 dpavlin 7 warn "# found ", $mesg->count, " entries\n";
32    
33 dpavlin 5 foreach my $entry ( $mesg->entries ) {
34 dpavlin 7
35 dpavlin 5 $entry->dump;
36 dpavlin 7
37     my $data;
38     my $user = CAdmin::Model::User->new;
39    
40     my @columns = map { $_->name } $user->columns;
41     #warn "# columns = ",dump( @columns );
42    
43     foreach my $attr ( $entry->attributes ) {
44     if ( grep(/^\Q$attr\E$/, @columns ) ) {
45     $data->{$attr} = $entry->get_value( $attr );
46     } else {
47     warn "model ",ref($user)," doesn't have column $attr\n";
48     }
49     }
50    
51     warn dump( $data );
52    
53     $user->load_or_create( %$data );
54 dpavlin 5 }
55    

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26