#!/bin/sh #Lookup phone number via Domino LDAP and return name for callerid #v.3 #Configurable variables ldaphostname="" #enter ldap server name ldapusername="" #enter username ldappassword="" #enter password tempfile=/tmp/file.txt #process incoming variables from Asterisk AGI declare -a array while read -e ARG && [ "$ARG" ] ; do array=(` echo $ARG | sed -e 's/://'`) #echo $ARG >> $tempfile export ${array[0]}=${array[1]} done num=$agi_callerid len=${#num} #Check for number of digits in callerid #I think from Asterisk it should always be 10. #However script will handle it if it passes 12 in the following format #xxx-xxx-xxxx if [ $len -eq 10 ] then #We have a 10 digit callerid. Add 2 dashes for the 12 digit version num10=$num num12=${num:0:3}-${num:3:3}-${num:6:4} elif [ $len -eq 12 ]; then #We have a 12 digit callerid. Remove 2 dashes for 10 digit version num10=${num:0:3}${num:4:3}${num:8:4} num12=$num else #If callerid is not 10 or 12 digits do not attempt a lookup and exit script. exit 0; fi #build LDAP search filter searchstr="(|(mobile=$num10)(mobile=$num12)(phonenumber=$num10)(phonenumber=$num12)(telephonenumber=$num10)(telephonenumber=$num12))" #perform ldap search /usr/bin/ldapsearch -h $ldaphostname -D "$ldapusername" -w "$ldappassword" -x -LLL "$searchstr" givenname sn >> $tempfile #Currently the script writes the output to a file, greps the file and deletes it #I would like to change this to keeping it in a variable #I currently don't know how to keep multi-line text in variable without losing caridge returns #parse out last name and first name lastname=`grep sn $tempfile | cut -d ":" -f 2 | sed 's/^ //'` firstname=`grep givenname $tempfile | cut -d ":" -f 2 | sed 's/^ //'` rm $tempfile #check that lastname is more than 1 char long #if true, then exit so we don't override callerid if [ ${#lastname} -lt 2 ] then exit 0; fi CIDNAME="$lastname, $firstname" #return new callerid to Asterisk echo "SET CALLERID \"$CIDNAME\"<$agi_callerid>" exit 0;