LDAP for SER
Alan Crosswell <alan@columbia.edu> (November 26, 2003)
Columbia is using the SIP Express Router from iptel.org. Adding
the LDAP lookup was easy. Right after SER looks in the user location
database for a registered user agent and fails to find it, we added a
call to an external script via the exec_dset() module:
# native SIP destinations are handled using our USRLOC DB if
(!lookup("location")) { if (!exec_dset("/etc/ser/sipldap")) {
sl_send_reply("404", "Not Found"); break; } else { log(1," sipldap
call"); }; }; #!lookup
This script simply does an LDAP query for mail=user@columbia.edu
or uni=uni and returns the telephonenumber attribute, rewritten as a
sip uri that incorporates our various local tieline hacks:
#!/bin/sh
echo "$*" >/tmp/sipldap.log
m=`echo $1 | sed -e 's/^sip://'`
u=`echo $m | sed -e 's/@columbia.edu$//'`
f="(|(mail=$m)(uni=$u))"
num=`ldapsearch -LLL -b "" -P 2 -x -h ldap.cc.columbia.edu $f telephonenumber \
| grep '^telephonenumber' | sed -e 's/^telephonenumber: //'`
if [ -z "$num" ]
then
echo "$*"
exit 1
fi
num=`echo $num | sed -e 's/^+1 212-85\([1347]\)-\(....\)/\1\2/' \
-e 's/^+1 212-30\(5\)-\(....\)/51\1\2/' \
-e 's/^+1 845-365-\(....\)/95\1/' \
-e 's/^+1 212-678-\(....\)/94\1/' \
-e 's/^+1 212-870-\(....\)/80\1/' \
-e 's/^+\(1\) \(...\)-\(...\)-\(....\)/93\1\2\3\4/'`
echo $num >>/tmp/sipldap.log
echo sip:$num@columbia.edu
exit 0
|