--- bin/ldap.pl 2008/03/13 19:21:21 17 +++ bin/ldap.pl 2008/03/17 13:20:37 26 @@ -8,9 +8,15 @@ use Jifty; use Net::LDAP; use Data::Dump qw/dump/; +use Getopt::Long; BEGIN { Jifty->new; }; +my $limit = 0; +GetOptions( + 'limit=i', => \$limit, +); + my $ldap_config = Jifty->config->app('LDAP'); Jifty->log->debug( "config->app(LDAP) = ",dump( $ldap_config ) ); @@ -18,10 +24,7 @@ # an anonymous bind #my $mesg = $ldap->bind; -my $mesg = $ldap->bind( - DN => $ldap_config->{DN}, - password => $ldap_config->{Password}, -); +my $mesg = $ldap->bind( $ldap_config->{DN}, password => $ldap_config->{Password} ); Jifty->log->info("Connected to ", $ldap_config->{Server}, " with DN ", $ldap_config->{DN}); @@ -30,18 +33,19 @@ base => "dc=skole,dc=hr", # filter => "(&(sn=Barr) (o=Texas Instruments))", filter => "(objectClass=hrEduPerson)", - sizelimit => 100, # 0 = off + sizelimit => $limit, # 0 = off ); if ( $mesg->code ) { - warn $mesg->code, ": ", $mesg->error, "\n"; + Jifty->log->error( $mesg->code, ": ", $mesg->error ); } Jifty->log->info( "found ", $mesg->count, " entries" ); -foreach my $entry ( $mesg->entries ) { +#foreach my $entry ( $mesg->entries ) { +while ( my $entry = $mesg->shift_entry ) { - $entry->dump; +# $entry->dump; my $data; my $user = A3C::Model::User->new; @@ -52,7 +56,7 @@ foreach my $attr ( $entry->attributes ) { if ( grep(/^\Q$attr\E$/, @columns ) ) { $data->{$attr} = $entry->get_value( $attr ); - } else { + } elsif ( $attr !~ m/^(objectClass)$/i ) { Jifty->log->error(ref($user)," doesn't have $attr"); } } @@ -61,6 +65,10 @@ my ( $id, $message ) = $user->load_or_create( %$data ); - Jifty->log->error( $message ) if ! $id; + if ( $id ) { + Jifty->log->info("added $id ", $data->{uid}); + } else { + Jifty->log->error( $message ); + } }