/[A3C]/bin/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/ldap.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 7 - (show annotations)
Thu Mar 13 13:12:46 2008 UTC (11 years, 10 months ago) by dpavlin
File MIME type: text/plain
File size: 1015 byte(s)
first try at script which imports data from ldap

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
12 BEGIN { Jifty->new; };
13
14 my $ldap = Net::LDAP->new( 'ldap1.skole.local' ) or die "$@";
15
16 # an anonymous bind
17 my $mesg = $ldap->bind;
18
19 # perform a search
20 $mesg = $ldap->search(
21 base => "dc=skole,dc=hr",
22 # filter => "(&(sn=Barr) (o=Texas Instruments))",
23 filter => "(objectClass=hrEduPerson)",
24 sizelimit => 100, # off
25 );
26
27 if ( $mesg->code ) {
28 warn $mesg->code, ": ", $mesg->error, "\n";
29 }
30
31 warn "# found ", $mesg->count, " entries\n";
32
33 foreach my $entry ( $mesg->entries ) {
34
35 $entry->dump;
36
37 my $data;
38 my $user = CAdmin::Model::User->new;
39
40 my @columns = map { $_->name } $user->columns;
41 #warn "# columns = ",dump( @columns );
42
43 foreach my $attr ( $entry->attributes ) {
44 if ( grep(/^\Q$attr\E$/, @columns ) ) {
45 $data->{$attr} = $entry->get_value( $attr );
46 } else {
47 warn "model ",ref($user)," doesn't have column $attr\n";
48 }
49 }
50
51 warn dump( $data );
52
53 $user->load_or_create( %$data );
54 }
55

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26