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

Contents of /bin/import-ldap.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 8 - (show annotations)
Thu Mar 13 13:49:41 2008 UTC (16 years ago) by dpavlin
Original Path: bin/ldap.pl
File MIME type: text/plain
File size: 1230 byte(s)
take ldap config from etc/site_config.yml

1 #!/usr/bin/perl
2
3 use warnings;
4 use strict;
5
6 use lib 'lib';
7
8 use Jifty;
9 use Net::LDAP;
10 use Data::Dump qw/dump/;
11
12 BEGIN { Jifty->new; };
13
14 #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
19 #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
26 $mesg = $ldap->search(
27 base => "dc=skole,dc=hr",
28 # filter => "(&(sn=Barr) (o=Texas Instruments))",
29 filter => "(objectClass=hrEduPerson)",
30 sizelimit => 3, # 0 = off
31 );
32
33 if ( $mesg->code ) {
34 warn $mesg->code, ": ", $mesg->error, "\n";
35 }
36
37 warn "# found ", $mesg->count, " entries\n";
38
39 foreach my $entry ( $mesg->entries ) {
40
41 $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

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26