X-Git-Url: https://git.deb.at/w?a=blobdiff_plain;f=contrib%2Fldap-abook%2Fldap2abook;fp=contrib%2Fldap-abook%2Fldap2abook;h=58b793624ce7b5cec11740431d75e17dde712717;hb=9d28f71348269e7075d0ff5c0b7ae4e05f358304;hp=0000000000000000000000000000000000000000;hpb=c0b0c6c7a0971525558239e544212589fbbac58b;p=pkg%2Fabook.git diff --git a/contrib/ldap-abook/ldap2abook b/contrib/ldap-abook/ldap2abook new file mode 100644 index 0000000..58b7936 --- /dev/null +++ b/contrib/ldap-abook/ldap2abook @@ -0,0 +1,95 @@ +#!/usr/bin/perl +# +# This is very simple method to get data from LDAP and +# converts it to abook readable format. +# Script get only first email of any person. This is, probably, +# primary address. +# If you have better/simpler method - send me, please. +# +# You MUST have ldap-utils installed on your system to +# use this script. Without ldapsearch script does not work! +# +# Author: Mariusz Balewski +# 03.06.2004 +# 29.08.2005 Tried to fix insecure tempfile handling (untested) +# +# GPL licensed +# Feel free to send me your comments +# +# I'm not programmer, so REMEMBER: +# YOU USE THIS SCRIPT ON YOUR OWN RISK!!! +# + +# Change this section to your local settings + # Your LDAP host + $HOST="ldaphost.com"; + + # Base dn to search + $BASEDN="\"-b ou=example,dc=com\""; + + # dn which contains email addresses + $FINDDN="mail"; + + # for example "-D \"cn=admin,dc=com\"" (if needed) + $AUTHDN=""; + + # ldap password (if needed), or -w to force script + # to password prompting + $PASS=""; + + # use -x if your ldaphost accept simple authentication + # or leave empty + $SIMPLEAUTH=""; + + # Where you want to put results? + # In this example results will be putted to + # your home directory, to abookFromLDAP file. + # If you wish to use abook with this file, simply run: + # abook --datafile $HOME/abookFromLDAP + $DESTFILE="$ENV{'HOME'}/abookFromLDAP"; + + # If you wish to see communiats in english or polish + # link comms.pl-en to comms.pl to english or + # comms.pl-pl to polish + +# End of configuration +############################### +############################### + +use File::Temp qw/ :mktemp /; +$file = mktemp("/tmp/tmpfileXXXXXXX"); + + +require 'comms.pl'; + +system("ldapsearch -h $HOST $SIMPLEAUTH $AUTHDN $PASS \"$FINDDN=*\" $BASEDN -LLL > $file"); + +$i=0; +open(F1,"<$file") || die "$TMPERR"; +open(F2,">$DESTFILE") || die "$DESTFILEERR"; + flock(F1,8); + flock(F2,8); + while(){ + if ($_ =~ m/^gecos/g){ + s/^ //g; + s/^gecos: /name=/g; + print F2 "[$i]\n"; + print F2 $_; + $i++; + } + elsif ($_ =~ m/^mail/g){ + s/^mail: /email=/g; + print F2 "$_\n"; + } + } + flock(F2,2); + flock(F1,2); +close(F2); +close(F1); + +unlink($file); + +print "\n$i "; +print "$REPORT\n\n"; + +#== END