3 # This is very simple method to get data from LDAP and
4 # converts it to abook readable format.
5 # Script get only first email of any person. This is, probably,
7 # If you have better/simpler method - send me, please.
9 # You MUST have ldap-utils installed on your system to
10 # use this script. Without ldapsearch script does not work!
12 # Author: Mariusz Balewski <M.Balewski@wp.pl>
14 # 29.08.2005 Tried to fix insecure tempfile handling (untested)
17 # Feel free to send me your comments
19 # I'm not programmer, so REMEMBER:
20 # YOU USE THIS SCRIPT ON YOUR OWN RISK!!!
23 # Change this section to your local settings
28 $BASEDN="\"-b ou=example,dc=com\"";
30 # dn which contains email addresses
33 # for example "-D \"cn=admin,dc=com\"" (if needed)
36 # ldap password (if needed), or -w to force script
37 # to password prompting
40 # use -x if your ldaphost accept simple authentication
44 # Where you want to put results?
45 # In this example results will be putted to
46 # your home directory, to abookFromLDAP file.
47 # If you wish to use abook with this file, simply run:
48 # abook --datafile $HOME/abookFromLDAP
49 $DESTFILE="$ENV{'HOME'}/abookFromLDAP";
51 # If you wish to see communiats in english or polish
52 # link comms.pl-en to comms.pl to english or
53 # comms.pl-pl to polish
55 # End of configuration
56 ###############################
57 ###############################
59 use File::Temp qw/ :mktemp /;
60 $file = mktemp("/tmp/tmpfileXXXXXXX");
65 system("ldapsearch -h $HOST $SIMPLEAUTH $AUTHDN $PASS \"$FINDDN=*\" $BASEDN -LLL > $file");
68 open(F1,"<$file") || die "$TMPERR";
69 open(F2,">$DESTFILE") || die "$DESTFILEERR";
73 if ($_ =~ m/^gecos/g){
80 elsif ($_ =~ m/^mail/g){