/[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 28 - (show annotations)
Mon Mar 17 21:42:21 2008 UTC (11 years, 5 months ago) by dpavlin
Original Path: bin/ldap.pl
File MIME type: text/plain
File size: 1680 byte(s)
just blindly create record in hope of speedup

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 use Getopt::Long;
12
13 BEGIN { Jifty->new; };
14
15 my $limit = 0;
16 GetOptions(
17 'limit=i', => \$limit,
18 );
19
20 my $ldap_config = Jifty->config->app('LDAP');
21 Jifty->log->debug( "config->app(LDAP) = ",dump( $ldap_config ) );
22
23 my $ldap = Net::LDAP->new( $ldap_config->{Server} ) or die "$@";
24
25 # an anonymous bind
26 #my $mesg = $ldap->bind;
27 my $mesg = $ldap->bind( $ldap_config->{DN}, password => $ldap_config->{Password} );
28
29 Jifty->log->info("Connected to ", $ldap_config->{Server}, " with DN ", $ldap_config->{DN});
30
31 # perform a search
32 $mesg = $ldap->search(
33 base => "dc=skole,dc=hr",
34 # filter => "(&(sn=Barr) (o=Texas Instruments))",
35 filter => "(objectClass=hrEduPerson)",
36 sizelimit => $limit, # 0 = off
37 );
38
39 if ( $mesg->code ) {
40 Jifty->log->error( $mesg->code, ": ", $mesg->error );
41 }
42
43 Jifty->log->info( "found ", $mesg->count, " entries" );
44
45 #foreach my $entry ( $mesg->entries ) {
46 while ( my $entry = $mesg->shift_entry ) {
47
48 # $entry->dump;
49
50 my $data;
51 my $user = A3C::Model::User->new;
52
53 my @columns = map { $_->name } $user->columns;
54 #warn "# columns = ",dump( @columns );
55
56 foreach my $attr ( $entry->attributes ) {
57 if ( grep(/^\Q$attr\E$/, @columns ) ) {
58 $data->{$attr} = $entry->get_value( $attr );
59 } elsif ( $attr !~ m/^(objectClass)$/i ) {
60 Jifty->log->error(ref($user)," doesn't have $attr");
61 }
62 }
63
64 Jifty->log->debug( dump( $data ) );
65
66 # my ( $id, $message ) = $user->load_or_create( %$data );
67 my ( $id, $message ) = $user->create( %$data );
68
69 if ( $id ) {
70 Jifty->log->info("added $id ", $data->{uid});
71 } else {
72 Jifty->log->error( $message );
73 }
74 }
75

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26