--- bin/ldap.pl 2008/03/13 13:49:41 8 +++ bin/ldap.pl 2008/03/30 16:58:21 42 @@ -6,56 +6,21 @@ use lib 'lib'; use Jifty; -use Net::LDAP; +use A3C::LDAP; use Data::Dump qw/dump/; +use Getopt::Long; BEGIN { Jifty->new; }; -#warn "# config->app(LDAP) = ",dump( Jifty->config->app('LDAP') ); - -my $ldap = Net::LDAP->new( Jifty->config->app('LDAP')->{Server} ) or die "$@"; - -# an anonymous bind -#my $mesg = $ldap->bind; -my $mesg = $ldap->bind( - DN => Jifty->config->app('LDAP')->{DN}, - password => Jifty->config->app('LDAP')->{Password}, -); - -# perform a search -$mesg = $ldap->search( - base => "dc=skole,dc=hr", -# filter => "(&(sn=Barr) (o=Texas Instruments))", - filter => "(objectClass=hrEduPerson)", - sizelimit => 3, # 0 = off +my $limit = 100; +GetOptions( + 'limit=i', => \$limit, ); -if ( $mesg->code ) { - warn $mesg->code, ": ", $mesg->error, "\n"; -} - -warn "# found ", $mesg->count, " entries\n"; - -foreach my $entry ( $mesg->entries ) { - - $entry->dump; - - my $data; - my $user = CAdmin::Model::User->new; - - my @columns = map { $_->name } $user->columns; - #warn "# columns = ",dump( @columns ); - - foreach my $attr ( $entry->attributes ) { - if ( grep(/^\Q$attr\E$/, @columns ) ) { - $data->{$attr} = $entry->get_value( $attr ); - } else { - warn "model ",ref($user)," doesn't have column $attr\n"; - } - } - - warn dump( $data ); +my $ldap = A3C::LDAP->new; - $user->load_or_create( %$data ); +foreach my $model ( qw/Organization User/ ) { + my $collection = $ldap->collection( $model, $limit ); + Jifty->log->info( "found ", $collection->count, " entries for $model" ); }