[smartroute-1]
include => smartroute-1-custom
exten => i,1,Noop(Smartroute invalid DID handler - FIX EXTENSION VAR)
exten => i,n,Set(FIX_EXTEN=${INVALID_EXTEN})
exten => i,n,Set(TMP=0)
exten => i,n,Set(ANS=)
exten => i,n,Set(END=${LEN(${FIX_EXTEN})})
exten => i,n(clean_ext_loop_top),GotoIf($["${TMP}" = "${END}"]?clean_ext_done)
exten => i,n,Set(TCH=${FIX_EXTEN:${TMP}:1})
exten => i,n,GotoIf($["${TCH}" < "0"]?clean_ext_ignore_char)
exten => i,n,GotoIf($["${TCH}" > "9"]?clean_ext_ignore_char)
exten => i,n,Set(ANS=${ANS}${TCH})
exten => i,n(clean_ext_ignore_char),Set(TMP=$[${TMP}+1])
exten => i,n,Goto(clean_ext_loop_top)
exten => i,n(clean_ext_done),Set(FIX_EXTEN=${ANS})
exten => i,n,Goto(smartroute-1,${FIX_EXTEN},1)
exten => s,1,Noop(Smartroute passed generic extension s handler - FIX EXTENSION VAR)
exten => s,n,GotoIf($["${CATCHALL_DID}" != "s" & "${CATCHALL_DID}empty" != "empty"]?smartroute-1,${CATCHALL_DID},1)
exten => s,n,GotoIf($["${FROM_DID}" != "s" & "${FROM_DID}empty" != "empty"]?smartroute-1,${FROM_DID},1)
exten => s,n,Goto(smartroute-1,${CALLERID(dnid)},1)
exten => _X.,1,Noop(Smartroute: Start Standard Processing - DB Routing)
exten => _X.,n,ExecIf($[ "${FROM_DID}" = "" | "${FROM_DID}" = "s"] ?Set(__FROM_DID=${EXTEN}))
exten => _X.,n,ExecIf($[ "${FROM_DID}" = "" | "${FROM_DID}" = "s"] ?Set(__FROM_DID=${CATCHALL_DID}))
exten => _X.,n,ExecIf($[ "${FROM_DID}" = "" | "${FROM_DID}" = "s"] ?Set(__FROM_DID=${CALLERID(dnid)}))
exten => _X.,n,ExecIf($[ "${FROM_DID}" = "" ] ?Set(__FROM_DID=${EXTEN}))
exten => _X.,n,ExecIf($[ "${CALLERID(name)}" = "" ] ?Set(CALLERID(name)=${CALLERID(num)}))
exten => _X.,n,Set(__CALLINGPRES_SV=${CALLERPRES()})
exten => _X.,n,Set(CALLERPRES()=allowed_not_screened)
exten => _X.,n,Set(FAX_DEST=)
exten => _X.,n,Noop(Smartroute: test)
exten => _X.,n,MYSQL(Connect connid localhost asteriskuser PASSWORD asteriskcdrdb)
exten => _X.,n,MYSQL(Query resultid ${connid} SELECT dst FROM lastcalls WHERE src = '${CALLERID(num)}')
exten => _X.,n,MYSQL(Fetch fetchid ${resultid} DBRESULT)
exten => _X.,n,MYSQL(Clear ${resultid})
exten => _X.,n,MYSQL(Disconnect ${connid})
exten => _X.,n,ExecIf($[${fetchid} = 0]?Set(DBRESULT=))
exten => _X.,n,GotoIf($[${fetchid} = 0]?no_match_found)
exten => _X.,n,GotoIf($["${DBRESULT}" = "950"]?destination0)
exten => _X.,n,GotoIf($["${DBRESULT}" = "953"]?destination1)
exten => _X.,n(no_match_found),Noop(No Smartroute Match: Goto Default Destination)
exten => _X.,n,Goto(ext-queues,123,1)
exten => _X.,n,Hangup
exten => _X.,n(destination0),Set(SR_PRIMARY_DEST=from-did-direct^950^1)
exten => _X.,n,Set(SR_FAILOVER_DEST=ext-queues^123^1)
exten => _X.,n,Set(SR_OR_EXTVAR=)
exten => _X.,n,Set(SR_MACRO=)
exten => _X.,n,Set(SR_MACRO_TRUNK=)
exten => _X.,n,Goto(process_match_found)
exten => _X.,n(destination1),Set(SR_PRIMARY_DEST=from-did-direct^953^1)
exten => _X.,n,Set(SR_FAILOVER_DEST=ext-queues^123^1)
exten => _X.,n,Set(SR_OR_EXTVAR=)
exten => _X.,n,Set(SR_MACRO=)
exten => _X.,n,Set(SR_MACRO_TRUNK=)
exten => _X.,n,Goto(process_match_found)
exten => _X.,n,Noop(Smartroute Error - should never get here.)
exten => _X.,n,Hangup
exten => _X.,n(process_match_found),Noop(Process Match Found)
exten => _X.,n,GotoIf($["${SR_MACRO}empty" != "empty"]?process_macrotrunk)
exten => _X.,n,Goto(${CUT(SR_PRIMARY_DEST,^,1)},${CUT(SR_PRIMARY_DEST,^,2)},${CUT(SR_PRIMARY_DEST,^,3)})
exten => _X.,n,Goto(${CUT(SR_FAILOVER_DEST,^,1)},${CUT(SR_FAILOVER_DEST,^,2)},${CUT(SR_FAILOVER_DEST,^,3)})
exten => _X.,n,Hangup
exten => _X.,n(process_macrotrunk),Noop(Process Trunk Destination with Failover)
exten => _X.,n,Set(INTRACOMPANYROUTE=YES)
exten => _X.,n,Set(KEEPCID=TRUE)
exten => _X.,n,Set(OUTDISABLE_${SR_MACRO_TRUNK}=off)
exten => _X.,n,Set(SAVECID=${CALLERID(number)})
exten => _X.,n,ExecIf($["${SR_OR_EXTVAR}empty" = "empty"]?Set(SR_OR_EXTVAR=${FROM_DID}))
exten => _X.,n,Macro(dialout-trunk,${SR_MACRO_TRUNK},${SR_OR_EXTVAR},)
exten => _X.,n,Set(CALLERID(number)=${SAVECID})
exten => _X.,n,Goto(${CUT(SR_FAILOVER_DEST,^,1)},${CUT(SR_FAILOVER_DEST,^,2)},${CUT(SR_FAILOVER_DEST,^,3)})
exten => _X.,n,Hangup
exten => h,1,Macro(hangupcall,)
;--== end of [smartroute-1] ==--;