LDAPget application module for the Asterisk PBX

©2004,2005,2006,2007 Sven Slezak <sunny at mezzo.net>

LDAPget is an Asterisk application for data retrieval from LDAP
directories (e.g. OpenLDAP or ActiveDirectory).
LDAPget does not require you to use a specific LDAP schema.
If the requested data is found in the directory it is assigned
to a given variable an the priority is increased by 101.

Configuration:

The syntax for LDAPget in extensions.conf is as follows:

LDAPget(VARIABLE=config-file-section[/lookup-key1,lookup-key2,...])

Example:
If you would like to lookup the caller-id's name you could
configure your extensions.conf like this:

exten => 1234,1,LDAPget(CALLERID(name)=cidname)
exten => 1234,2,Dial(Zap/11/${EXTEN},15)
Then you have to configure the corresponding section in your
ldap.conf file. (an example file is included in this package)
Because we called the config-file-section 'cidname' we have to add a section
'cidname' to our ldap.conf file:

[cidname]
  host = ldap.mydomain.com; (default: localhost)
  port = 3389; (default: 389)
  timeout = 5; (default: 10 sec)
  version = 3; (default: 2)
  user = cn=root,ou=People,o=mydomain.com
  pass = secret
  base = ou=Addressbook,o=mydomain.com
  filter = (&(objectClass=person)(|(telephoneNumber=${CALLERID(num)})(mobile=${CALLERID(num)})(homePhone=${CALLERID(num)})(fax=${CALLERID(num)})))
  attribute = displayName; (default: commonName)
  convert = UTF-8,ISO-8859-1
note: the variable names in Asterisk 1.2 were CALLERIDNUM and CALLERIDNAME

LDAPget will connect to ldap.mydomain.com on port 3389 (which you can change with 'port = <port>')
and bind as user 'cn=root,ou=People,o=mydomain.com' with password 'secret'.
(if you ommit user and pass LDAPget will bind anonymously to the LDAP server.)

After successful bind it executes an LDAP search with a subdirectory scope
from base 'ou=Addressbook,o=mydomain.com' with the default filter
(&(objectClass=person)(telephoneNumber=<lookup-key>))
You can change this with 'filter = <ldap filter>' where you have to use '%s' as place holders for the lookup-keys.
Example: If you need to match the phone number from right to left you can change
the filter to (note the *): (&(objectClass=person)(telephoneNumber=*%s))

When an object is found, LDAPget sets the given VARIABLE to the text found
in the displayName attribute. (you can change the attribute to use with 'attribute = <ldap attribute>').

And at last: If the charset which is used by your directory server is not supported by
your handset (like mine) you can have LDAPget convert the text into the required charset.
There is also a seperate application module for character conversion: Iconv.

Another Example for LDAPGet usage can be found in the
O'REILLY® Book Switching to VoIP Chapter 14




Compile:

You will need the openldap client libraries and header files included in openldap-devel rpm
and the iconv library and header file included in glibc-headers rpm;
and Asterisk of course.

Download (see below) and unpack the package:
tar -xzf app_ldap-release.tgz
in the app_ldap directory run:
make install
Restart Asterisk or load the application module with:
load app_ldap.so
done!
show application LDAPget
should print the description.



Changes and Download:

Mac version included in Asterisk PBX for Mac OS X
2.0rc1 - new version for Asterisk 1.4
1.0rc6 - bug fix: handle base=null. thanks to John Todd
1.0rc5 - fix for asterisk 1.2
1.0rc4 - fixed setting of CIDNAME in CVS. thanks to Stefan Lang, OrgaNet GmbH.
1.0rc3 - CVS support.
1.0rc2 - some debugging output removed.
1.0rc1 - added configuration for ldap version. thanks to Renan Prates Lopes de Campos

0.9.9.2 - fixed another memory leak. thanks to Craig Guy, zettaserve.com
0.9.9 - fixed memory leak and CVS_HEAD support. thanks to Alexander Litvin, goldentele.com
0.9.6 - added asterisk variables support in filter and base parameter
0.9.5 - added timeout configuration
0.9.3 - fixed allocation for filter. thanks to John B Dunning, Wayne State College
0.9.2 - fixed memory allocation for character conversion.
0.9.1 - asterisk api changed: chan->callerid to chan->cid.cid_num
0.9 - added ldap_unbind for unsuccessful searches. thanks to Hugh Blandford, Island Internet.
    - added support for multiple keys in search filter.
0.8 - initial release

	 \ | /
	- :-) -
	 / | \