8 |
use Jifty; |
use Jifty; |
9 |
use Net::LDAP; |
use Net::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 $limit = 0; |
16 |
|
GetOptions( |
17 |
|
'limit=i', => \$limit, |
18 |
|
); |
19 |
|
|
20 |
my $ldap_config = Jifty->config->app('LDAP'); |
my $ldap_config = Jifty->config->app('LDAP'); |
21 |
Jifty->log->debug( "config->app(LDAP) = ",dump( $ldap_config ) ); |
Jifty->log->debug( "config->app(LDAP) = ",dump( $ldap_config ) ); |
22 |
|
|
24 |
|
|
25 |
# an anonymous bind |
# an anonymous bind |
26 |
#my $mesg = $ldap->bind; |
#my $mesg = $ldap->bind; |
27 |
my $mesg = $ldap->bind( |
my $mesg = $ldap->bind( $ldap_config->{DN}, password => $ldap_config->{Password} ); |
|
DN => $ldap_config->{DN}, |
|
|
password => $ldap_config->{Password}, |
|
|
); |
|
28 |
|
|
29 |
Jifty->log->info("Connected to ", $ldap_config->{Server}, " with DN ", $ldap_config->{DN}); |
Jifty->log->info("Connected to ", $ldap_config->{Server}, " with DN ", $ldap_config->{DN}); |
30 |
|
|
33 |
base => "dc=skole,dc=hr", |
base => "dc=skole,dc=hr", |
34 |
# filter => "(&(sn=Barr) (o=Texas Instruments))", |
# filter => "(&(sn=Barr) (o=Texas Instruments))", |
35 |
filter => "(objectClass=hrEduPerson)", |
filter => "(objectClass=hrEduPerson)", |
36 |
sizelimit => 100, # 0 = off |
sizelimit => $limit, # 0 = off |
37 |
); |
); |
38 |
|
|
39 |
if ( $mesg->code ) { |
if ( $mesg->code ) { |
40 |
warn $mesg->code, ": ", $mesg->error, "\n"; |
Jifty->log->error( $mesg->code, ": ", $mesg->error ); |
41 |
} |
} |
42 |
|
|
43 |
Jifty->log->info( "found ", $mesg->count, " entries" ); |
Jifty->log->info( "found ", $mesg->count, " entries" ); |
44 |
|
|
45 |
foreach my $entry ( $mesg->entries ) { |
foreach my $entry ( $mesg->entries ) { |
46 |
|
|
47 |
$entry->dump; |
# $entry->dump; |
48 |
|
|
49 |
my $data; |
my $data; |
50 |
my $user = A3C::Model::User->new; |
my $user = A3C::Model::User->new; |
64 |
|
|
65 |
my ( $id, $message ) = $user->load_or_create( %$data ); |
my ( $id, $message ) = $user->load_or_create( %$data ); |
66 |
|
|
67 |
Jifty->log->error( $message ) if ! $id; |
if ( $id ) { |
68 |
|
Jifty->log->info("added $id ", $data->{uid}); |
69 |
|
} else { |
70 |
|
Jifty->log->error( $message ); |
71 |
|
} |
72 |
} |
} |
73 |
|
|