Asterisk to Voiceflex - an example on the NSLU2
I have had numerous comments and requests regarding Asterisk configuration for Voiceflex. I have neglected my blog somewhat lately, but when I googled for “BCM50 SIP” the other day, I was suprised to see my own blog high up the listings! I have decided to revisit this, as it has obviously generated a lot of interest.
I have a bash script that I used on the Linksys NSLU2 (“the SLUG”) in order to quickly configure Asterisk to act as a gateway between a Nortel BCM50 and Voiceflex’s SIP trunks. Although there is no longer a need to use the NSLU2 in this fashion, as Voiceflex can dispense with SIP authentication when the BCM50 is on a static IP, I will post the scripts, as well as the relevant Asterisk config files, as they may be useful for anybody that wants to configure Asterisk with SIP trunks.
Firstly, the Asterisk configs: obviously, do not use these as-is, you will need to change the details to suit!
sip.conf
[general] context=default bindport=5060 bindaddr=0.0.0.0 srvlookup=yes domain=asterisk disallow=all allow=alaw,g729,g723 language=en relaxdtmf=yes trustrpid=no useragent=Asterisk PBX promiscredir=yes canreinvite=yes domain=146.101.248.200,incoming-voiceflex domain=192.168.40.6,incoming-voiceflex domain=10.10.10.10,incoming-bcm domain=10.10.11.11,default #include /etc/asterisk/sip_nat.conf #include /etc/asterisk/sip_accounts.conf [sip-bcm] type=peer host=10.10.10.10 context=incoming-bcm #include /etc/asterisk/sip_og_context.conf ; sip ext for xlite, for testing [200] type=friend regexten=200 secret=donttell context=default host=10.10.10.10 canreinvite=no insecure=port,invitesip_nat.conf
externip=11.11.11.11 localnet=192.168.192.0/24 nat=yessip_accounts.conf
;sip_accounts.conf generated by autoasterflex register => 12345678:shhhsecret@sip.voiceflex.com registertimeout=20 registerattempts=0 [authentication] auth=12345678:shhhsecret@146.101.248.200 auth=12345678:shhhsecret@voiceflex auth=12345678:shhhsecret@sip.voiceflex.comsip_og_context.conf
[voiceflex] type=friend callerid=01234567890 fromuser=01234567890 defaultuser=12345678@voiceflex disallow=all allow=alaw,ulaw,g729 fromdomain=voiceflex secret=shhhsecret host=sip.voiceflex.com insecure=invite,port context=incoming-voiceflexextensions_incoming_voiceflex.conf
[incoming-voiceflex] exten => s,1,Dial(SIP/666666@sip-bcm,,r); exten => 666666,1,Dial(SIP/666666@sip-bcm,,r);extensions.conf
; extensions.conf - asterisk dialplan
[general]
static=yes
writeprotect=no
autofallthrough=yes
clearglobalvars=no
priorityjumping=no
[globals]
[incoming-bcm]
exten => 200,1,Dial(SIP/200,,r);
exten => _9.,1,Dial(SIP/${EXTEN:1}@voiceflex,,r);
exten => _8.,1,SIPDtmfMode(inband);
exten => _8.,2,Dial(SIP/${EXTEN:1}@voiceflex,,r);
;this context must be absent prior to running autoasterflex
;[incoming-voiceflex]
;exten => s,1,Dial(SIP/234567@sip-bcm,,r);
;exten => 234567,1,Dial(SIP/234567@sip-bcm,,r);
[default]
exten => _9.,1,Dial(SIP/${EXTEN:1}@voiceflex,,r);
exten => 300,1,Dial(SIP/234567@sip-bcm,,r);
exten => 234567,1,Dial(SIP/234567@sip-bcm,,r);
#include /etc/asterisk/extensions_incoming_voiceflex.conf
Finally, here is a little shell script that I was using, in order to configure an NSLU2 with Asterisk already installed, to configure the SIP trunks. USE WITH CAUTION - answering "y" to "Change IP & DNS settings (y/n) ?" will re-write the network interface config (/etc/network/interfaces) and DNS client config (/etc/resolf.conf) on the machine that you run it on (if it is Linux based.) I would advise anybody using the script to exercise care doing this, and only to do so if you have read and understand the script.
autoasterflex.sh
#!/bin/bash
#autoasterflex
echo "Caller ID of incoming SIP Trunk?"
read CALLERID
echo "SIP Account number?"
read SIPACCT
echo "SIP Account password?"
read SIPPASS
echo "PBX IP Address?"
read BCMIP
echo "WAN IP Address?"
read EXTERNIP
echo "Local network? (eg 192.168.0.1/24)"
read LOCALNET
echo "Digits to send to pbx as received digits?"
read DDI
echo "Change IP & DNS settings (y/n) ?"
read CHANGEIP
if [ "$CHANGEIP" == "y" ]; then
echo "Slug IP?"
read SLUGIP
echo "Slug Netmask?"
read SLUGSN
echo "Slug Default Gateway?"
read SLUGDGW
echo "DNS Server?"
read SLUGDNS
fi
# modify existing sip_og_context.conf
sed -i "s/callerid=.*/callerid=${CALLERID}/" /etc/asterisk/sip_og_context.conf
sed -i "s/fromuser=.*/fromuser=${CALLERID}/" /etc/asterisk/sip_og_context.conf
sed -i "s/defaultuser=.*/defaultuser=${SIPACCT}@voiceflex/" /etc/asterisk/sip_og_context.conf
sed -i "s/secret=.*/secret=${SIPPASS}/" /etc/asterisk/sip_og_context.conf
# delete existing si_accounts.conf, create a new one
rm -f /etc/asterisk/sip_accounts.conf
echo ";sip_accounts.conf generated by autoasterflex" >> /etc/asterisk/sip_accounts.conf
echo "register => ${SIPACCT}:${SIPPASS}@sip.voiceflex.com" >> /etc/asterisk/sip_accounts.conf
echo "" >> /etc/asterisk/sip_accounts.conf
echo "registertimeout=20" >> /etc/asterisk/sip_accounts.conf
echo "registerattempts=0" >> /etc/asterisk/sip_accounts.conf
echo "" >> /etc/asterisk/sip_accounts.conf
echo "[authentication]" >> /etc/asterisk/sip_accounts.conf
echo "auth=${SIPACCT}:${SIPPASS}@146.101.248.200" >> /etc/asterisk/sip_accounts.conf
echo "auth=${SIPACCT}:${SIPPASS}@voiceflex" >> /etc/asterisk/sip_accounts.conf
echo "auth=${SIPACCT}:${SIPPASS}@sip.voiceflex.com" >> /etc/asterisk/sip_accounts.conf
#delete existing sip_nat.conf, create a new one
rm -f /etc/asterisk/sip_nat.conf
echo "externip=${EXTERNIP}" >> /etc/asterisk/sip_nat.conf
echo "localnet=${LOCALNET}" >> /etc/asterisk/sip_nat.conf
echo "nat=yes" >> /etc/asterisk/sip_nat.conf
#check extensions.conf has #include /etc/asterisk/extensions_incoming_voiceflex.conf, append if absent
INCVFLEXCONFPRESENT=`grep '/etc/asterisk/extensions_incoming_voiceflex.conf' /etc/asterisk/extensions.conf`
if [ "" == "$INCVFLEXCONFPRESENT" ]; then
echo "" >> /etc/asterisk/extensions.conf
echo "#include /etc/asterisk/extensions_incoming_voiceflex.conf" >> /etc/asterisk/extensions.conf
fi
#delete existing extensions_incoming_voiceflex.conf, recreate
rm -f /etc/asterisk/extensions_incoming_voiceflex.conf
echo "[incoming-voiceflex]" >> /etc/asterisk/extensions_incoming_voiceflex.conf
echo "exten => s,1,Dial(SIP/${DDI}@sip-bcm,,r);" >> /etc/asterisk/extensions_incoming_voiceflex.conf
echo "exten => ${DDI},1,Dial(SIP/${DDI}@sip-bcm,,r);" >> /etc/asterisk/extensions_incoming_voiceflex.conf
# modify sip.conf
sed -i "s/domain=.*,incoming-bcm/domain=${BCMIP},incoming-bcm/" /etc/asterisk/sip.conf
sed -i "s/host=.*/host=${BCMIP}/" /etc/asterisk/sip.conf
if [ "$CHANGEIP" == "y" ]; then
#recreate /etc/network/interfaces
rm -f /etc/network/interfaces
echo "# /etc/network/interfaces" >> /etc/network/interfaces
echo "# recreated by autoasterflex" >> /etc/network/interfaces
echo "#" >> /etc/network/interfaces
echo "# the loopback interface" >> /etc/network/interfaces
echo "auto lo" >> /etc/network/interfaces
echo "iface lo inet loopback" >> /etc/network/interfaces
echo "#" >> /etc/network/interfaces
echo "# the interface used by default during boot" >> /etc/network/interfaces
echo "auto eth0" >> /etc/network/interfaces
echo "#" >> /etc/network/interfaces
echo "# static entry for eth0" >> /etc/network/interfaces
echo "iface eth0 inet static" >> /etc/network/interfaces
echo " address ${SLUGIP}" >> /etc/network/interfaces
echo " netmask ${SLUGSN}" >> /etc/network/interfaces
echo " gateway ${SLUGDGW}" >> /etc/network/interfaces
#recreate /etc/resolf.conf
rm -f /etc/resolv.conf
echo "search workgroup" >> /etc/resolf.conf
echo "nameserver ${SLUGDNS}" >> /etc/resolv.conf
fi
#done
echo "Changes done. execute shutdown -r now to restart with new settings."
I hope this helps.