Hangup incoming not in MySQL database

Hi Everybody;

I am able to return incoming callers name per the number from MySQL database.

What I want to achieve is to hangup incoming calls that are not in the database, else allow those that are in the database

Thanks in advance

Use ExecIf() with the Hangup() Command.

ExecIf($[${ODBC_LOOKUP(${CALLERID(NUM})=0]?Hangup())

1 Like

Thanks … will try that and revert

HI John, it still didn’t work… incoming calls that are not saved in MySQL database are not hangup.
any other options to look into?
Thank you

Without seeing your SQL query or any console logs it’s impossible for me to make any suggestions.

this is extensions_additional.conf included in the extensions.conf

[cidlookup]
include => cidlookup-custom
exten => cidlookup_2,1,MYSQL(Connect connid localhost root mypass mycontacts)
exten => cidlookup_2,n,MYSQL(Query resultid ${connid} select name from callerid where number like ‘%${CALLERID(num)}%’)
exten => cidlookup_2,n,MYSQL(Fetch fetchid ${resultid} CALLERID(name))
exten => cidlookup_2,n,MYSQL(Clear ${resultid})
exten => cidlookup_2,n,MYSQL(Disconnect ${connid})
exten => cidlookup_2,n,Return()
exten => cidlookup_return,1,Execif($["${DB(cidname/${CALLERID(num)})}" = “”]?Hangup())
;exten => cidlookup_return,1,ExecIf($["${DB(cidname/${CALLERID(num)})}" !=
“”]?Set(CALLERID(name)=${DB(cidname/${CALLERID(num)})}))
exten => cidlookup_return,n,Return()

; end of [cidlookup]

logs:
– Executing [242438050@from-internal:1] Macro(“SIP/.6PBX-000000c8”, “user-callerid,”) in new stack
– Executing [s@macro-user-callerid:1] Set(“SIP/.6PBX-000000c8”, “AMPUSER=209257600”) in new stack
– Executing [s@macro-user-callerid:2] GotoIf(“SIP/.6PBX-000000c8”, “0?report”) in new stack
– Executing [s@macro-user-callerid:3] ExecIf(“SIP/.6PBX-000000c8”, “1?Set(REALCALLERIDNUM=209257600)”) in new stack
– Executing [s@macro-user-callerid:4] Set(“SIP/.6PBX-000000c8”, “AMPUSER=”) in new stack
– Executing [s@macro-user-callerid:5] Set(“SIP/.6PBX-000000c8”, “AMPUSERCIDNAME=”) in new stack
– Executing [s@macro-user-callerid:6] GotoIf(“SIP/.6PBX-000000c8”, “1?report”) in new stack
– Goto (macro-user-callerid,s,10)
– Executing [s@macro-user-callerid:10] GotoIf(“SIP/.6PBX-000000c8”, “0?continue”) in new stack
– Executing [s@macro-user-callerid:11] Set(“SIP/.6PBX-000000c8”, “__TTL=64”) in new stack
– Executing [s@macro-user-callerid:12] GotoIf(“SIP/.6PBX-000000c8”, “1?continue”) in new stack
– Goto (macro-user-callerid,s,19)
– Executing [s@macro-user-callerid:19] Set(“SIP/.6PBX-000000c8”, “CALLERID(number)=209257600”) in new stack
– Executing [s@macro-user-callerid:20] Set(“SIP/.6PBX-000000c8”, “CALLERID(name)=209257600”) in new stack
– Executing [s@macro-user-callerid:21] NoOp(“SIP/.6PBX-000000c8”, “Using CallerID “209257600” <209257600>”) in new stack
– Executing [242438050@from-internal:2] Answer(“SIP/.6PBX-000000c8”, “”) in new stack
– Executing [242438050@from-internal:3] Set(“SIP/.6PBX-000000c8”, “__BLKVM_OVERRIDE=BLKVM/242438050/SIP/.6PBX-000000c8”) in new stack
– Executing [242438050@from-internal:4] Set(“SIP/.6PBX-000000c8”, “__BLKVM_BASE=242438050”) in new stack
– Executing [242438050@from-internal:5] Set(“SIP/.6PBX-000000c8”, “DB(BLKVM/242438050/SIP/.6PBX-000000c8)=TRUE”) in new stack
– Executing [242438050@from-internal:6] ExecIf(“SIP/.6PBX-000000c8”, “1?Set(_DIAL_OPTIONS=trM(auto-blkvm))”) in new stack
– Executing [242438050@from-internal:7] Set(“SIP/.6PBX-000000c8”, “__NODEST=242438050”) in new stack
– Executing [242438050@from-internal:8] Set(“SIP/.6PBX-000000c8”, “MONITOR_FILENAME=/var/spool/asterisk/monitor/q242438050-20180925-092218-1537867338.344”) in new stack
– Executing [242438050@from-internal:9] Queue(“SIP/.6PBX-000000c8”, “242438050,t,custom/AUD-20130327-WA0000,60”) in new stack
– Started music on hold, class ‘default’, on SIP/.6PBX-000000c8
== Using SIP RTP TOS bits 184
== Using SIP RTP CoS mark 5
– SIP/214-000000c9 is ringing
– Stopped music on hold on SIP/.6PBX-000000c8
== Spawn extension (from-internal, 242438050, 9) exited non-zero on ‘SIP/.6PBX-000000c8’
– Executing [h@from-internal:1] Macro(“SIP/.6PBX-000000c8”, “hangupcall”) in new stack
– Executing [s@macro-hangupcall:1] GotoIf(“SIP/.6PBX-000000c8”, “1?endmixmoncheck”) in new stack
– Goto (macro-hangupcall,s,9)
– Executing [s@macro-hangupcall:9] NoOp(“SIP/.6PBX-000000c8”, “End of MIXMON check”) in new stack
– Executing [s@macro-hangupcall:10] GotoIf(“SIP/.6PBX-000000c8”, “1?nomeetmemon”) in new stack
– Goto (macro-hangupcall,s,28)
– Executing [s@macro-hangupcall:28] NoOp(“SIP/.6PBX-000000c8”, “End of MEETME check”) in new stack
– Executing [s@macro-hangupcall:29] GotoIf(“SIP/.6PBX-000000c8”, “1?noautomon”) in new stack
– Goto (macro-hangupcall,s,34)
– Executing [s@macro-hangupcall:34] NoOp(“SIP/.6PBX-000000c8”, “TOUCH_MONITOR_OUTPUT=”) in new stack
– Executing [s@macro-hangupcall:35] GotoIf(“SIP/.6PBX-000000c8”, “0?noautomon2”) in new stack
– Executing [s@macro-hangupcall:36] System(“SIP/.6PBX-000000c8”, “test -e /var/spool/asterisk/monitor/q242438050-20180925-092218-1537867338.344*”) in new stack
– Executing [s@macro-hangupcall:37] NoOp(“SIP/.6PBX-000000c8”, “SYSTEMSTATUS = APPERROR”) in new stack
– Executing [s@macro-hangupcall:38] GotoIf(“SIP/.6PBX-000000c8”, “1?errornoautomon”) in new stack
– Goto (macro-hangupcall,s,40)
– Executing [s@macro-hangupcall:40] NoOp(“SIP/.6PBX-000000c8”, “End of MONITOR QUEUE check”) in new stack
– Executing [s@macro-hangupcall:41] NoOp(“SIP/.6PBX-000000c8”, “MONITOR_FILENAME=/var/spool/asterisk/monitor/q242438050-20180925-092218-1537867338.344”) in new stack
– Executing [s@macro-hangupcall:42] GotoIf(“SIP/.6PBX-000000c8”, “1?skiprg”) in new stack
– Goto (macro-hangupcall,s,45)
– Executing [s@macro-hangupcall:45] GotoIf(“SIP/.6PBX-000000c8”, “0?skipblkvm”) in new stack
– Executing [s@macro-hangupcall:46] NoOp(“SIP/.6PBX-000000c8”, “Cleaning Up Block VM Flag: BLKVM/242438050/SIP/.6PBX-000000c8”) in new stack
– Executing [s@macro-hangupcall:47] NoOp(“SIP/.6PBX-000000c8”, “Deleting: BLKVM/242438050/SIP/.6PBX-000000c8 TRUE”) in new stack
– Executing [s@macro-hangupcall:48] GotoIf(“SIP/.6PBX-000000c8”, “1?theend”) in new stack
– Goto (macro-hangupcall,s,50)
– Executing [s@macro-hangupcall:50] AGI(“SIP/.6PBX-000000c8”, “hangup.agi”) in new stack
– Launched AGI Script /var/lib/asterisk/agi-bin/hangup.agi
– <SIP/.6PBX-000000c8>AGI Script hangup.agi completed, returning 0
– Executing [s@macro-hangupcall:51] Hangup(“SIP/.6PBX-000000c8”, “”) in new stack
== Spawn extension (macro-hangupcall, s, 51) exited non-zero on ‘SIP/.6PBX-000000c8’ in macro ‘hangupcall’
== Spawn extension (from-internal, h, 1) exited non-zero on ‘SIP/.6PBX-000000c8’
– Told SIP/.6PBX-000000c7 in 111 their queue position (which was 1)
– Started music on hold, class ‘default’, on SIP/.6PBX-000000c7
– Remote UNIX connection disconnected

FreePBX is not running anything in your cidlookup context. I assume that means that your problem lies with FreePBX and you need use https://community.freepbx.org/ if you want peer support.

Thanks for your responds David… this logs shows that cidlookup context was executed

log:
– Accepting call from ‘244974301’ to ‘0242438050’ on channel 0/1, span 1
– Executing [0242438050@from-pstn:1] Set(“DAHDI/i1/244974301-3e”, “__FROM_DID=0242438050”) in new stack
– Executing [0242438050@from-pstn:2] Gosub(“DAHDI/i1/244974301-3e”, “app-blacklist-check,s,1”) in new stack
– Executing [s@app-blacklist-check:1] GotoIf(“DAHDI/i1/244974301-3e”, “0?blacklisted”) in new stack
– Executing [s@app-blacklist-check:2] Set(“DAHDI/i1/244974301-3e”, “CALLED_BLACKLIST=1”) in new stack
– Executing [s@app-blacklist-check:3] Return(“DAHDI/i1/244974301-3e”, “”) in new stack
– Executing [0242438050@from-pstn:3] Gosub(“DAHDI/i1/244974301-3e”, “cidlookup,cidlookup_2,1”) in new stack
– Executing [cidlookup_2@cidlookup:1] MYSQL(“DAHDI/i1/244974301-3e”, “Connect connid localhost root mypass mycontacts”) in new stack
– Executing [cidlookup_2@cidlookup:2] MYSQL(“DAHDI/i1/244974301-3e”, “Query resultid 1 select name from callerid where number like ‘%244974301%’”) in new stack
– Executing [cidlookup_2@cidlookup:3] MYSQL(“DAHDI/i1/244974301-3e”, “Fetch fetchid 2 CALLERID(name)”) in new stack
– Executing [cidlookup_2@cidlookup:4] MYSQL(“DAHDI/i1/244974301-3e”, “Clear 2”) in new stack
– Executing [cidlookup_2@cidlookup:5] MYSQL(“DAHDI/i1/244974301-3e”, “Disconnect 1”) in new stack
– Executing [cidlookup_2@cidlookup:6] Return(“DAHDI/i1/244974301-3e”, “”) in new stack
– Executing [0242438050@from-pstn:4] ExecIf(“DAHDI/i1/244974301-3e”, “0 ?Set(CALLERID(name)=244974301)”) in new stack
– Executing [0242438050@from-pstn:5] Set(“DAHDI/i1/244974301-3e”, “__CALLINGPRES_SV=allowed”) in new stack
– Executing [0242438050@from-pstn:6] Set(“DAHDI/i1/244974301-3e”, “CALLERPRES()=allowed_not_screened”) in new stack
– Executing [0242438050@from-pstn:7] Goto(“DAHDI/i1/244974301-3e”, “ext-trunk,4,1”) in new stack
– Goto (ext-trunk,4,1)
– Executing [4@ext-trunk:1] Set(“DAHDI/i1/244974301-3e”, “TDIAL_STRING=SIP/.6PBX”) in new stack
– Executing [4@ext-trunk:2] Set(“DAHDI/i1/244974301-3e”, “DIAL_TRUNK=4”) in new stack
– Executing [4@ext-trunk:3] Goto(“DAHDI/i1/244974301-3e”, “ext-trunk,tdial,1”) in new stack
– Goto (ext-trunk,tdial,1)
– Executing [tdial@ext-trunk:1] Set(“DAHDI/i1/244974301-3e”, “OUTBOUND_GROUP=OUT_4”) in new stack
– Executing [tdial@ext-trunk:2] GotoIf(“DAHDI/i1/244974301-3e”, “1?nomax”) in new stack
– Goto (ext-trunk,tdial,4)
– Executing [tdial@ext-trunk:4] ExecIf(“DAHDI/i1/244974301-3e”, “1?Set(CALLERPRES()=allowed)”) in new stack
– Executing [tdial@ext-trunk:5] Set(“DAHDI/i1/244974301-3e”, “DIAL_NUMBER=0242438050”) in new stack
– Executing [tdial@ext-trunk:6] GosubIf(“DAHDI/i1/244974301-3e”, “0?sub-flp-4,s,1”) in new stack
– Executing [tdial@ext-trunk:7] Set(“DAHDI/i1/244974301-3e”, “OUTNUM=0242438050”) in new stack
– Executing [tdial@ext-trunk:8] Dial(“DAHDI/i1/244974301-3e”, “SIP/.6PBX/0242438050,300,”) in new stack
== Using SIP RTP TOS bits 184
== Using SIP RTP CoS mark 5
– Called SIP/.6PBX/0242438050
– SIP/.6PBX-000000d6 answered DAHDI/i1/244974301-3e

MS SQL Server would require string quotes around a LIKE pattern. I would assume that MYSQL was the same.

it has a single quote…
Can you please walk me through a step by step way of adding another custom file to the extensions.conf with the commands that look through MySQL database and hangup incoming calls that are not in MySQL database
Appreciate your time and patience

I don’t see your code referencing Hangup() anywhere in what is executed.

have hangup command in my context

[cidlookup]
include => cidlookup-custom
exten => cidlookup_2,1,MYSQL(Connect connid localhost root mypass mycontacts)
exten => cidlookup_2,n,MYSQL(Query resultid ${connid} select name from callerid where number like ‘%${CALLERID(num)}%’)
exten => cidlookup_2,n,MYSQL(Fetch fetchid ${resultid} CALLERID(name))
exten => cidlookup_2,n,MYSQL(Clear ${resultid})
exten => cidlookup_2,n,MYSQL(Disconnect ${connid})
exten => cidlookup_2,n,Return()
exten => cidlookup_return,1,Execif($["${DB(cidname/${CALLERID(num)})}" = “”]?Hangup())
;exten => cidlookup_return,1,ExecIf($["${DB(cidname/${CALLERID(num)})}" !=
“”]?Set(CALLERID(name)=${DB(cidname/${CALLERID(num)})}))
exten => cidlookup_return,n,Return()

; end of [cidlookup

Not seeing it, Where is it in this code that is being executed?

Using ExecIf() with the Hangup() Command… i presume the above command hangup calls depending on the condirtion

Look at your logs.

You are executing context cidlookup extension cidlookup_2 priorities 1-6

You are NOT executing context cidlookup extension cidlookup_return priority 1.

Code you don’t call doesn’t do anything.

thanks so much… forgive my ignorance am a newbie in asterisk
can you please walk me through a step by step on how to call it. i will super appreciate it

place your code where it will be called by your dialplan.

If your extension is 0242438050@from-pstn then add the code to

[from-pstn]
exten => 0242438050,1,NoOP()
same => n,ExecIf($[${ODBC_LOOKUP(${CALLERID(NUM})=0]?Hangup())
same => n,Dial(PJSIP/${EXTEN})
same => n,Hangup()

It worked…Thank you for the time and support