[WholesaleDirect-Ncid] ; Used for bypassing a2billing for large clients. Uses fraction of server resorces. looks in cc_route_nCid table exten => _X.,1,Set(Strheader=${SIP_HEADER(TO):5}) ;remove first 5 Characters from sip header, to help clean up destination number string. exten => _X.,2,Set(DNID=${CUT(Strheader,@,1)}) ;remove the @ and Characters after destinatoin number. This cleans up the sip header given us an clean 11 digit number. exten => _X.,3,Set(DNID=${DNID:0:7}) ;get the NPANXX of destination number. 10 digit dialing only. exten => _X.,4,MYSQL(Connect connid 209.40.000.00 a2billinguser password a2b) ;connect to database ;connects to database exten => _X.,5,MYSQL(Query resultid ${connid} SELECT\ username\,credit\,creditlimit\,activated\,lastuse\,nbused\ FROM\ cc_card\ WHERE\ username=\${CDR(accountcode)}\ and\ credit + creditlimit>\0\ and\ activated=\"t"\) ; Checks to make sure client account code matches username in cc_card table and client as founds or have not maxed out his credit limit. exten => _X.,6,MYSQL(Fetch fetchid ${resultid} strusername strcredit strcreditlimit stractivated strlastuse strnbused) ;get fields returned by the database and puts them into variables to be used later. exten => _X.,7,MYSQL(Clear ${resultid}) exten => _X.,8,GotoIf($[${strusername}=${CDR(accountcode)}]?9:h,23) ;checks if exist username returned by query. If not it means client is not in database and is bared from calling. Also checks credit and creditlimit fields. If credit + creditlimit is less than 0 calls are refused. exten => _X.,9,MYSQL(Query resultid ${connid} SELECT\ provider\,npanxx\,Price\,Prefix\,spoofCid\ FROM\ cc_route_nCid\ WHERE\ npanxx=\${DNID}\) ;checks database for npanxx of number being dialed. Returns 0 if not found. exten => _X.,10,MYSQL(Fetch fetchid ${resultid} Provider Npanxx Price Prefix spoofCid) ;get the fields we want in variable to use later exten => _X.,11,MYSQL(Clear ${resultid}) ;clear results Id exten => _X.,12,MYSQL(Disconnect ${connid}) ;closes database connection but not realy needed here as its closed later on in the code. exten => _X.,13,GotoIf($[${Npanxx} = ${DNID}]?14:18) ;checks to see if NPANXX of number dialed is in database. If not Logs calls and exits exten => _X.,14,Set(StrspoofCid=${LEN(${spoofCid})}) ; Get number of charactors in spoofCid field matching the NPANXX found exten => _X.,15,GotoIf($[${StrspoofCid}<5]?17:16) ;checks to see if there is a cli that should be spoofed. If so changes extensions to new CLI, CLI must be 5 digits or more to be spoofed exten => _X.,16,Set(CALLERID(number)=${spoofCid}) ; changes Cli number to number in database exten => _X.,17,Dial(SIP/${Prefix}${EXTEN}@${Provider}||g) ; dial destination number including any tech prefix (from database) using provider or trunk asigned to the NPANXXXX exten => _X.,18,Hangup() ;end call or refuse call. H extensions will finish processing CDRs loggin declined calls unless account code not now be varified.. exten => h,1,GotoIf($[${strusername}=${CDR(accountcode)}]?2:23) ;will refuse caller and send to hang up if accountcode does not match user name in a2billing table cc_card, Call will not be logged. exten => h,2,Set(StrSessionid=${CDR(dcontext)}) ;set variable for updating CDRs exten => h,3,Set(StrUniqueid=${CDR(uniqueid)}) ;set variable for updating CDRs exten => h,4,Set(Strusername=${CDR(accountcode)}) ;set variable for updating CDRs exten => h,5,Set(StrStarttime=${CDR(start)}) ;set variable for updating CDRs exten => h,6,Set(StrStoptime=${CDR(end)}) ;set variable for updating CDRs exten => h,7,Set(StrSessiontime=${CDR(billsec)}) ;set variable for updating CDRs exten => h,8,Set(StrCalledstation=${CDR(dst)}) ;set variable for updating CDRs exten => h,9,Set(StrStartdelay=${CDR(duration)}) ;set variable for updating CDRs exten => h,10,Set(StrTerminatecause=${CDR(disposition)}) ;set variable for updating CDRs exten => h,11,Set(StrCalledprovider=${provider}) ;set variable for updating CDRs exten => h,12,Set(StrCalledrate=${Price}) ;set variable for updating CDRs exten => h,13,set(StrSessionbill=${MATH(${StrSessiontime}*${Price})}) ;set variable StrSessionbill= number of billable seconds multiplied by price from table exten => h,14,set(StrSessionbill=${MATH(${StrSessionbill}/60)}) ; set variable: since the seconds were charged at the perminute rate the charge for the call is 60X to much so we devide it by 60. exten => h,15,Set(StrBeforebal=${strcredit}) ;set variable for updating CDRs exten => h,16,Set(StrSrc=${spoofCid}) ;set variable for updating CDRs exten => h,17,Set(Stroriginating_cid=${CDR(clid}) ;set variable for updating CDRs exten => h,18,MYSQL(Connect connid 209.40.226.00 a2billinguser password a2b) ;connect to database ;connects to database exten => h,19,MYSQL(Query resultid ${connid} INSERT\ INTO\ cc_call\ SET\ sessionid=\'${StrSessionid}\'\,uniqueid=\'${StrUniqueid}\'\,username=\'${Strusername}\'\,Starttime=\'${StrStarttime}\'\,Stoptime=\'${StrStoptime}\'\,Sessiontime=\'${StrSessiontime}\'\,Calledstation=\'${StrCalledstation}\'\,Startdelay=\'${StrStartdelay}\'\,Terminatecause=\'${StrTerminatecause}\'\,Calledprovider=\'${StrCalledprovider}\'\,Calledrate=\'${StrCalledrate}\'\,Sessionbill=\'${StrSessionbill}\'\,Beforebal=\(SELECT credit from cc_card where username = 6625866)\,Src=\'${StrSrc}\'\,originating_cid=\'${Stroriginating_cid}\'\) ;appends records to CDRs exten => h,20,MYSQL(Query resultid ${connid} UPDATE\ cc_card\ SET\ lastuse=\'${StrStoptime}\'\,credit=credit-\${StrSessionbill}\,nbused=nbused+1\ WHERE\ username=\${CDR(accountcode)}\) exten => h,21,MYSQL(Disconnect ${connid}) ;closes database connection very important exten => h,22,Noop(${CDR(billsec)}) exten => h,23,Hangup ; I am not sure what error code is sent if this is invoked because client's calls does not begin with a NPANXX in table.