#include ext-radius.conf [general] static=yes autofallthrough=yes [forbidden] exten => _[0-9a-zA-Z*+#]!,1,NoOp(-- No context for host ${CHANNEL(recvip)} --) same => n,Log(NOTICE,UC from ${CALLERID(name)} ${CALLERID(num)}@${CHANNEL(recvip)} to ${EXTEN}) same => n,Hangup(21) exten => h,1,Hangup(21) [h323-id] exten => _[#+*0-9]!,1,NoOp(-- H323 ID --) same => n,Set(ID=${SIP_HEADER(h323-conf-id)}) same => n,ExecIf($[ "${ID}" = "" ]?Set(ID=${RAND(300000000,2000000000)}-${RAND(300000000,2000000000)}-${RAND(300000000,2000000000)}-${RAND(300000000,2000000000)})) same => n,Set(H323_ID=${ID}) same => n,Set(H323_ID_HEX=${MATH(${CUT(ID,,1)}+0,hex)} ${MATH(${CUT(ID,,2)}+0,hex)} ${MATH(${CUT(ID,,3)}+0,hex)} ${MATH(${CUT(ID,,4)}+0,hex)}) same => n,SIPAddHeader(h323-conf-id: ${H323_ID}) same => n,Set(CDR(h323id)=${H323_ID_HEX}) same => n,Return() [fromhost] exten => _[*0-9]!,1,NoOp(-- Inbound Authentication for customer IP --) same => n,Set(CDR(CustomerType)=IpAuth) same => n,Set(CDR(accountcode)=${CHANNEL(recvip)}) same => n,Gosub(h323-id,${EXTEN},1) same => n,Set(MYCALLID=${SIPCALLID}) same => n,AGI(/var/lib/asterisk/agi-bin/agi-rad-auth.pl,Routing=SIP&AuthorizeBy=Account&Password=cisco&H323_ID=${H323_ID}&CustomerType=IpAuth&H323_RADDR=${CHANNEL(recvip)}) same => n,Set(CDR(disconnect-reason)=${h323-return-code}) same => n,Goto(rad-auth,${VERIFIED_EXTEN},1) [fromnode] exten => _[*0-9]!,1,NoOp(-- Inbound Authentication --) same => n,Set(CDR(CustomerType)=PeerAuth) same => n,Set(CDR(accountcode)=${CHANNEL(recvip)}) same => n,Gosub(h323-id,${EXTEN},1) same => n,Set(MYCALLID=${SIPCALLID}) same => n,AGI(/var/lib/asterisk/agi-bin/agi-rad-auth.pl,Routing=SIP&AuthorizeBy=Account&Password=cisco&H323_ID=${H323_ID}&CustomerType=PeerAuth&H323_RADDR=${CHANNEL(recvip)}) same => n,Set(CDR(disconnect-reason)=${h323-return-code}) same => n,Goto(rad-auth,${VERIFIED_EXTEN},1) [fromaccount] exten => _[#+*0-9]!,1,NoOp(-- SIP Authentication --) same => n,Set(CDR(CustomerType)=SipAuth) same => n,Set(CDR(accountcode)=${SIP_Username}) same => n,Gosub(h323-id,${EXTEN},1) same => n,Set(SIP_Authorization=${SIP_HEADER(Proxy-Authorization)}) same => n,Execif($[ "${SIP_Authorization}" = "" ]?Set(SIP_Authorization=${SIP_HEADER(Authorization)})) same => n,AGI(/var/lib/asterisk/agi-bin/agi-rad-auth.pl,Routing=SIP&AuthorizeBy=SIP&IfFailed=DoNotHangup&H323_ID=${H323_ID}&CustomerType=SipAuth&H323_RADDR=${CHANNEL(recvip)}) same => n,Goto(rad-auth,${VERIFIED_EXTEN},1) [rad-auth] exten => _[*0-9]!,1,NoOp() same => n,Set(RECVIP=${CHANNEL(recvip)}) same => n,Set(PBCLD=${PBCLD}) same => n,Set(CDR(disconnect-reason)=${h323-return-code}) same => n,GotoIf($[ "${h323-return-code}" = "1" ]?invalid_account,${EXTEN},1) same => n,GotoIf($[ "${h323-return-code}" = "2" ]?wrong_passwd,${EXTEN},1) same => n,GotoIf($[ "${h323-return-code}" = "3" ]?in_use,${EXTEN},1) same => n,GotoIf($[ "${h323-return-code}" = "4" ]?zero_balance,${EXTEN},1) same => n,GotoIf($[ "${h323-return-code}" = "5" ]?account_expired,${EXTEN},1) same => n,GotoIf($[ "${h323-return-code}" = "6" ]?credit_limit,${EXTEN},1) same => n,GotoIf($[ "${h323-return-code}" = "7" ]?user_denied,${EXTEN},1) same => n,GotoIf($[ "${h323-return-code}" = "8" ]?not_avail,${EXTEN},1) same => n,GotoIf($[ "${h323-return-code}" = "9" ]?no-route-exists-to-dest,${EXTEN},1) same => n,GotoIf($[ "${h323-return-code}" = "10" ]?retries,${EXTEN},1) same => n,GotoIf($[ "${h323-return-code}" = "12" ]?insufficient_balance,${EXTEN},1) same => n,GotoIf($[ "${h323-return-code}" = "14" ]?Not-Found-2,${EXTEN},1) same => n,GotoIf($[ "${h323-return-code}" = "0" | "${h323-return-code}" = "13" ]?welcome-msg,${EXTEN},1) same => n,Goto(cannot-complete-temp-error,${EXTEN},1) [welcome-msg] exten => _[*0-9]!,1,NoOp() same => n,Set(User_Agent=${SIP_HEADER(User-Agent)}) same => n,Set(CDR(User-Agent)=User-Agent:${User_Agent}) same => n,Progress same => n,ExecIf($[ "${h323-return-code}" = "13" & "${CDR(CustomerType)}" = "SipAuth" ]?Playback(free-calls,noanswer):Playback(beep,noanswer)) same => n,Goto(routing,${EXTEN},1) [MyRoute] exten => _[*0-9]!,1,NoOp() same => n,ExecIf($[ "${ActivePrivacy}" = "1" ]?SetCallerPres(prohib_not_screened)) ; this might not be needed --- needs further testing same => n,GotoIf($["${connid}" = ""]?MyRoute-error,${EXTEN},1) same => n,MYSQL(Query resultid ${connid} CALL set_route('${VDNID}','${CHANNEL(recvip)}','${multipleUA}')) same => n,MYSQL(Query resultid ${connid} SELECT get_route('${VDNID}')) same => n,MYSQL(Fetch fetchid ${resultid} myROUTE) same => n,GotoIf($[ "${myROUTE}"="NULL" | "${myROUTE}"="" ]?MyRoute-error,${EXTEN},1) same => n,MYSQL(Clear ${resultid}) same => n,MYSQL(Disconnect ${connid}) same => n,Set(VDNID=${PBCLD}) same => n,Set(ROUTEIP=${NAS_IP_Address}) same => n,ExecIf($[ "${TARGET_EXPIRE}" = "" ]?Set(TARGET_EXPIRE=30) same => n,Dial(${myROUTE},${TARGET_EXPIRE},${CALL_LIMIT}) same => n,Goto(routing,${EXTEN},failed) [MyRoute-error] exten => _[*0-9]!,1,NoOp() same => n,Dial(SIP/${PBCLD},30,${CALL_LIMIT}) same => n,Hangup(${HANGUPCAUSE}) same => n,Set(CDR(Hangupcause)=Hangupcause:${HANGUPCAUSE}) [check_ua] exten => _[*0-9]!,1,NoOp() same => n,MYSQL(Connect connid localhost ${dbuser} ${dbpass} ${dbname}) same => n,GotoIf($["${connid}" = ""]?error) same => n,GotoIf($["${CDR(CustomerType)}" = "PeerAuth"]?localmua:allmua) same => n(localmua),MYSQL(Query resultid ${connid} SELECT IF ((SELECT count(*) FROM multiple_ua WHERE username='${VDNID}' AND domain='${NAS_IP_Address}')>1,2,0)as a) same => n,MYSQL(Fetch fetchid ${resultid} multipleUA) same => n,Goto(setvar) same => n(allmua),MYSQL(Query resultid ${connid} SELECT IF ((SELECT count(*) FROM multiple_ua WHERE username='${VDNID}')>1,1,0)as a) same => n,MYSQL(Fetch fetchid ${resultid} multipleUA) same => n(setvar),ExecIf($[ "${multipleUA}"="NULL" | "${multipleUA}"="" ]?Set(multipleUA=0)) same => n,MYSQL(Clear ${resultid}) same => n,ExecIf($[ "${multipleUA}" = "0" ]?MYSQL(Disconnect ${connid})) same => n(error),Return() [routing] exten => _[*0-9]!,1,NoOp() same => n,ExecIf($[ "${CALLERID(name)}" = "Anonymous" | "${CALLERID(name)}" = "anonymous"]?Set(ActivePrivacy=1)) same => n(loop),NoOp() ;same => n,ExecIf($[ ${II} > 1 ]?Playback(the-next,noanswer) same => n,Set(KK=0) same => n,Set(SUM_ROUTE=${XSUM_${II}}) same => n(loop1),NoOp() same => n,Set(CDR(RouteNum)=${II}_${KK}) same => n,Set(TARGET_ROUTE=${XROUTE_${II}_${KK}}) same => n,GotoIf($[ "${TARGET_ROUTE}"="" ]?defaultroute:varroute) same => n(defaultroute),Set(TARGET_ROUTE=SIP/${DNID}@${NAS_IP_Address}) same => n,Set(TARGET_EXPIRE=30) same => n,Set(TARGET_CLI=${CALLERID(num)}) same => n,Goto(routeset) same => n(varroute),Set(TARGET_EXPIRE=${XEXP_${II}_${KK}}) same => n,Set(TARGET_CLI=${XCLI_${II}_${KK}}) same => n,Set(CALLERID(all)=${XCLI_${II}_${KK}} <${XCLI_${II}_${KK}}>) same => n(routeset),Set(MYDNID=${CUT(TARGET_ROUTE,@,1)}) same => n,Set(VDNID=${CUT(MYDNID,/,2)}) same => n,Set(ROUTEIP=${CUT(TARGET_ROUTE,@,2)}) same => n,GotoIf($[ "${ROUTEIP}" = "" ]?not_avail,${EXTEN},1) same => n,GotoIf($[ "${ActivePrivacy}" != "1" ]?noprivacy) same => n,GotoIf($[ "${ROUTEIP}" != "${NAS_IP_Address}" ]?extprivacy) same => n,SetCallerPres(prohib_not_screened) ; this might not be needed --- needs further testing same => n,Goto(noprivacy) same => n(extprivacy),SIPAddHeader(Remote-Party-ID:"${CALLERID(num)}" \;privacy=full\;screen=yes) same => n(noprivacy),ExecIf($[ ${multipleUA} = 0 ]?Gosub(check_ua,${EXTEN},1) same => n,GotoIf($[ ${XTOT} < 1 & "${multipleUA}" = "0" ]?telephone-number-temp-disconnected,${EXTEN},1) same => n,GotoIf($[ "${multipleUA}" = "1" | "${multipleUA}" = "2" ]?MyRoute,${EXTEN},1) same => n,Dial(${IF($[ "${ROUTEIP}" = "${NAS_IP_Address}" | $[ "${CDR(CustomerType)}" = "PeerAuth"] ]?${MYDNID}:${TARGET_ROUTE})},${TARGET_EXPIRE},${CALL_LIMIT}) same => n(failed),Set(multipleUA=0) same => n,Set(HANGUPCAUSE2=${HANGUPCAUSE}) same => n,Execif($[ "${ROUTEIP}" = "${NAS_IP_Address}" & "${HANGUPCAUSE2}" = "20"]?Set(HANGUPCAUSE2=126)) same => n,Set(CDR(Hangupcause)=Hangupcause:${HANGUPCAUSE2}) same => n,GotoIf($[ "${DIALSTATUS}" = "BUSY" | "${DIALSTATUS}" = "NOANSWER" | "${DIALSTATUS}" = "CANCEL" ]?end1) same => n,Set(KK=$[${KK}+1]) same => n,GotoIf($[${KK} < ${SUM_ROUTE} ]?loop1:end1) same => n(end1),NoOp() same => n,Set(II=$[${II}+1]) same => n,GotoIf($[${II} <= ${XTOT} ]?loop:end) same => n(end),NoOp() same => n,Goto(Error-Info,${EXTEN},1) [Error-Info] exten => _[*0-9]!,1,NoOp() same => n,GotoIf($[ ${XTOT} > 1 ]?Ter) same => n,GotoIf($[ "${HANGUPCAUSE2}" = "17" ]?currentlybusy,${EXTEN},1) same => n,GotoIf($[ "${HANGUPCAUSE2}" = "126" ]?not_avail,${EXTEN},1) same => n,GotoIf($[ "${HANGUPCAUSE2}" = "28" ]?ISUP28,${EXTEN},1) same => n,GotoIf($[ "${HANGUPCAUSE2}" = "1" | "${HANGUPCAUSE2}" = "3" | "${HANGUPCAUSE2}" = "27" | "${HANGUPCAUSE2}" = "31" | "${HANGUPCAUSE2}" = "88" | "${HANGUPCAUSE2}" = "95" | "${HANGUPCAUSE2}" = "111" ]?Not-Found,${EXTEN},1) same => n,GotoIf($[ ${HANGUPCAUSE2} >= 90 ]?cannot-complete-temp-error,${EXTEN},1) same => n,GotoIf($[ "${DIALSTATUS}" = "CANCEL" ]?cancelled,${EXTEN},1) same => n,GotoIf($[ "${HANGUPCAUSE2}" = "34" | "${HANGUPCAUSE2}" = "38" | "${HANGUPCAUSE2}" = "41" | "${HANGUPCAUSE2}" = "42" | "${HANGUPCAUSE2}" = "47" ]?all-outgoing-lines-unavailable,${EXTEN},1) same => n,GotoIf($[ "${DIALSTATUS}" = "CHANUNAVAIL" ]?an-error-has-occured,${EXTEN},1) same => n,GotoIf($[ "${DIALSTATUS}" = "CONGESTION" ]?cannot-complete-otherend-error,${EXTEN},1) same => n(Ter),Hangup(${HANGUPCAUSE2}) [ISUP28] exten => _[*0-9]!,1,SET(error_message="incomplete-num") same => n,Gosub(playerror,${EXTEN},1) same => n,Hangup(${HANGUPCAUSE2}) [currentlybusy] exten => _[*0-9]!,1,SET(error_message="the-number-u-dialed&is-curntly-busy") same => n,Gosub(playerror,${EXTEN},1) same => n,Hangup(${HANGUPCAUSE2}) [user_denied] exten => _[*0-9]!,1,SET(error_message="user_denied") same => n,Gosub(playerror,${EXTEN},1) same => n,Hangup(${HANGUPCAUSE2}) [cannot-complete-otherend-error] exten => _[*0-9]!,1,SET(error_message="cannot-complete-otherend-error") same => n,Gosub(playerror,${EXTEN},1) same => n,Hangup(${HANGUPCAUSE2}) [cancelled] exten => _[*0-9]!,1,SET(error_message="cancelled") same => n,Gosub(playerror,${EXTEN},1) same => n,Hangup(${HANGUPCAUSE2}) [not_avail] exten => _[*0-9]!,1,SET(error_message="not_avail") same => n,Gosub(playerror,${EXTEN},1) same => n,Hangup(${HANGUPCAUSE2}) [invalid_account] exten => _[*0-9]!,1,SET(error_message="invalid_account") same => n,Gosub(playerror,${EXTEN},1) same => n,Hangup(${HANGUPCAUSE2}) [wrong_passwd] exten => _[*0-9]!,1,SET(error_message="wrong_passwd") same => n,Gosub(playerror,${EXTEN},1) same => n,Hangup(${HANGUPCAUSE2}) [account_expired] exten => _[*0-9]!,1,SET(error_message="account_expired") same => n,Gosub(playerror,${EXTEN},1) same => n,Hangup(${HANGUPCAUSE2}) [credit_limit] exten => _[*0-9]!,1,SET(error_message="credit_limit") same => n,Gosub(playerror,${EXTEN},1) same => n,Hangup(${HANGUPCAUSE2}) [zero_balance] exten => _[*0-9]!,1,SET(error_message="zero_balance") same => n,Gosub(playerror,${EXTEN},1) same => n,Hangup(${HANGUPCAUSE2}) [in_use] exten => _[*0-9]!,1,SET(error_message="simul-call-limit-reached") same => n,Gosub(playerror,${EXTEN},1) same => n,Hangup(${HANGUPCAUSE2}) [insufficient_balance] exten => _[*0-9]!,1,SET(error_message="insufficient_balance") same => n,Gosub(playerror,${EXTEN},1) same => n,Hangup(${HANGUPCAUSE2}) [retries] exten => _[*0-9]!,1,SET(error_message="retries") same => n,Gosub(playerror,${EXTEN},1) same => n,Hangup(${HANGUPCAUSE2}) [cannot-complete-temp-error] exten => _[*0-9]!,1,SET(error_message="cannot-complete-temp-error") same => n,Gosub(playerror,${EXTEN},1) same => n,Hangup(${HANGUPCAUSE2}) [no-route-exists-to-dest] exten => _[*0-9]!,1,SET(error_message="no-route-exists-to-dest") same => n,Gosub(playerror,${EXTEN},1) same => n,Hangup(${HANGUPCAUSE2}) [Not-Found] exten => _[*0-9]!,1,NoOp() same => n,Set(NotFoundContext=Not-Found-${IF($[ ${CUT(TARGET_ROUTE,@,2)} = ${NAS_IP_Address}]?1:2)}) same => n,Goto(${NotFoundContext},${EXTEN},1) [Not-Found-1] exten => _[*0-9]!,1,SET(error_message="not-found") same => n,Gosub(playerror,${EXTEN},1) same => n,Hangup(${HANGUPCAUSE2}) [Not-Found-2] exten => _[*0-9]!,1,SET(error_message="you-dialed-wrong-number") same => n,Gosub(playerror,${EXTEN},1) same => n,Hangup(${HANGUPCAUSE2}) [telephone-number-temp-disconnected] exten => _[*0-9]!,1,SET(error_message="the-number-u-dialed&temp-disconnected") same => n,Gosub(playerror,${EXTEN},1) same => n,Hangup(${HANGUPCAUSE2}) [all-outgoing-lines-unavailable] exten => _[*0-9]!,1,SET(error_message="all-outgoing-lines-unavailable") same => n,Gosub(playerror,${EXTEN},1) same => n,Hangup(${HANGUPCAUSE2}) [an-error-has-occured] exten => _[*0-9]!,1,SET(error_message="an-error-has-occured") same => n,Gosub(playerror,${EXTEN},1) same => n,Hangup(${HANGUPCAUSE2}) [playerror] exten => _[*0-9]!,1,Set(COUNTER=0) same => n,Progress() same => n,Wait(0.5) same => n(loop),Wait(1) same => n,Playback(beeperr,noanswer) same => n,Playback(${error_message},noanswer) same => n,Set(COUNTER=$[${COUNTER} + 1]) same => n,GotoIf($[${COUNTER}<=5]?loop) same => n,Return