6 |
use lib 'lib'; |
use lib 'lib'; |
7 |
|
|
8 |
use Jifty; |
use Jifty; |
9 |
use Net::LDAP; |
use A3C::LDAP; |
10 |
use Data::Dump qw/dump/; |
use Data::Dump qw/dump/; |
11 |
|
use Getopt::Long; |
12 |
|
|
13 |
BEGIN { Jifty->new; }; |
BEGIN { Jifty->new; }; |
14 |
|
|
15 |
my $ldap = Net::LDAP->new( 'ldap1.skole.local' ) or die "$@"; |
my $limit = 0; |
16 |
|
my @models; |
17 |
# an anonymous bind |
GetOptions( |
18 |
my $mesg = $ldap->bind; |
'limit=i', => \$limit, |
19 |
|
'model=s', => \@models, |
|
# perform a search |
|
|
$mesg = $ldap->search( |
|
|
base => "dc=skole,dc=hr", |
|
|
# filter => "(&(sn=Barr) (o=Texas Instruments))", |
|
|
filter => "(objectClass=hrEduPerson)", |
|
|
sizelimit => 100, # off |
|
20 |
); |
); |
21 |
|
|
22 |
if ( $mesg->code ) { |
@models = ( 'Organization' ) unless @models; |
|
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 ); |
|
23 |
|
|
24 |
foreach my $attr ( $entry->attributes ) { |
my $ldap = A3C::LDAP->new; |
|
if ( grep(/^\Q$attr\E$/, @columns ) ) { |
|
|
$data->{$attr} = $entry->get_value( $attr ); |
|
|
} else { |
|
|
warn "model ",ref($user)," doesn't have column $attr\n"; |
|
|
} |
|
|
} |
|
25 |
|
|
26 |
warn dump( $data ); |
Jifty->log->info( 'syncing: ', join(',', @models) ); |
27 |
|
|
28 |
$user->load_or_create( %$data ); |
foreach my $model ( @models ) { |
29 |
|
my $collection = $ldap->collection( $model, limit => $limit ); |
30 |
|
Jifty->log->info( "found ", $collection->count, " entries for $model" ); |
31 |
} |
} |
32 |
|
|