Update: The code below does not work in Asterisk 2.0b4 or newer. I will update with instructions on how to get it to work in those versions. Thanks to Dan for pointing this out.
Update: I have changed the code to the removed part. It now requires a key press to accept the number to delete.
I have added a blacklist function to my Asterisk@Home server and thought that I’d share it here if someone is interested. There are two ways to add a number to the blacklist. The easiest is to dial *32. Then you get a voice telling you the number of the last incoming call. To add it to the blacklist, press 1. Great use against pesky telemarketers and If you want to add it manually, press *30. Then you can enter the phone number directly on your telephone. To remove an entry from the blacklist, press *31 and enter the phone number. If you don’t like the codes I use, change them.
Here’s How You Add A Black-list Function In Asterisk
Add the code below at the end of extensions_custom.conf. You can edit it from the web interface, go under Maintenance and Config Edit and select extensions_custom.conf. You have to add it to the _custom file because AMP changes the _additional.conf file every time you update something.
[custom-blacklist-add] exten => s,1,Playback(enter-num-blacklist); exten => s,2,DigitTimeout(5) exten => s,2,ResponseTimeout(60) exten => s,3,Read(blacknr,then-press-pound) exten => s,4,SayDigits(${blacknr}) exten => s,5,Playback(if-correct-press) exten => s,6,Playback(digits/1) exten => 1,1,DBput(blacklist/${blacknr}=1) exten => 1,2,Playback(num-was-successfully) exten => 1,3,Playback(added) exten => 1,4,Wait(1) exten => 1,5,Hangup exten=_X.,3,Playback(num-was-successfully) exten=_X.,4,Playback(added) exten=_X.,5,Hangup [custom-blacklist-remove] exten => s,1,Playback(entr-num-rmv-blklist) exten => s,2,ResponseTimeout(60) exten => s,3,Read(blacknr,then-press-pound) exten => s,4,SayDigits(${blacknr}) exten => s,5,Playback(if-correct-press) exten => s,6,Playback(digits/1) exten => 1,1,DBdel(blacklist/${blacknr}) exten => 1,2,SayDigits($blacklist) exten => 1,3,Playback(num-was-successfully) exten => 1,4,Playback(removed) exten => 1,5,Hangup [custom-blacklisted] exten=s,1,Answer exten=s,2,Wait(1) exten=s,3,Playback(nbdy-avail-to-take-call) exten=s,4,Playback(carried-away-by-monkeys) exten=s,5,Playback(lots-o-monkeys) exten=s,6,Hangup [custom-blacklist-last] exten => s,1,Answer exten => s,2,Wait(1) exten => s,3,DBget(number=CALLTRACE/${CALLERIDNUM}); goto 104 if no last caller exten => s,4,GotoIf($"${number}" = ""?104,1) ; also if it's blank (caller id blocked) exten =>s,5,Playback(privacy-to-blacklist-last-caller) exten => s,6,Playback(telephone-number) exten => s,7,SayDigits(${number}) exten => s,8,Wait,1 exten => s,9,Playback(if-correct-press) exten => s,10,Playback(digits/1) exten => 1,1,DBput(blacklist/${number}=1) exten => 1,2,Playback(privacy-blacklisted) exten => 1,3,Wait,1 exten => 1,4,Hangup exten => s,104,Playback(unidentified-no-callback) exten => s,106,Hangup
You also need to add a custom function to the from-PSTN context, a function that gets called before the normal incoming call handler. So it checks if the incoming number is on the blacklist. If so, give a weird message (or maybe just congestion?)
Add the following at the beginning of extensions_custom.conf. Make sure there’s not a declaration for that context already. If so, add the lines there.
[cc][from-pstn-custom]
exten => s,1,LookupBlacklist ; If CID blacklisted, goto 102
exten => s,102,Goto(custom-blacklisted,s,1)[/cc]
And then the last change. Add the following lines in extensions_custom.conf in the [from-internal-custom] context. There are already some lines there, but add the following after that.
[cc]exten => *30,1,Goto(custom-blacklist-add,s,1)
exten => *31,1,Goto(custom-blacklist-remove,s,1)
exten => *32,1,Goto(custom-blacklist-last,s,1)[/cc]
You’ll probably like to change the [custom-blacklisted] to do something like congestion or hang up instead of the weird message my version does.
dstroot says
Has anyone pointed out the following three lines are repeated
at the bottom of the [custom-blacklist-add] code? Is this a typo?
exten=_X.,3,Playback(num-was-successfully)
exten=_X.,4,Playback(added)
exten=_X.,5,Hangup
Also in [from-pstn-custom] – where does the LookupBlacklist function come from? Is this a script or function already on the box somewhere?
exten => s,1,LookupBlacklist ; If CID blacklisted, goto 102
Jacken says
Yes, you are correct, it’s a typ0. Have removed them now. Thanks!
The LookupBlacklist is a built in function.
dstroot says
FYI – The “LookupBlacklist” function is not in Asterisk@Home 2.0 Beta 4 – I’m working on a way to add it
Kevan says
When using DID routes in AMP or AAH to send calls directly to an extension bypassing the Incoming call settings the [from-pstn-custom] statements don’t work. If you change the statements to the following it will allow to work either way:
[from-pstn-custom]
exten => _NXXNXXXXXX,1,LookupBlacklist ; If CID blacklisted, goto 102
exten => _NXXNXXXXXX,102,Goto(custom-blacklisted,s,1)
exten => _1NXXNXXXXXX,1,LookupBlacklist ; If CID blacklisted, goto 102
exten => _1NXXNXXXXXX,102,Goto(custom-blacklisted,s,1)
Jacken says
I’m guessing that there is a way to call the blacklist function before an incoming DID call. I’ll try to find a way later on.
Stefan says
Thanks for the information.
However it would be nice to
use your soundfiles used in your example.
I’m suspecting one of them contains the sound
of a bunch of screaming chimps… 🙂
Can you post them or a link?
Regards
//Stefan
Jacken says
All the files are already included with Asterisk@Home. So the examples should work directly.
Daniel Nylander says
Sweeet 🙂
gbutters says
For AAH 2.0 I had to change [custom-blacklist-last]
exten => s,4,GotoIf($”${number}” = “”?104,1) ; also if it’s blank (caller id blocked)
to
exten => s,4,GotoIf($[${number} = “”]?104,1) ; also if it’s blank (caller id blocked)
to get it to work. Before I made the change it just gave me a busy signal.
Anonymous says
Okay all, we have been seeing a problem with the “lookupblacklist” command in Asterisk @home v2.2. After banging my head against the wall trying to work with the command I gave up and wrote my own script to handle the function. I have implemented this on my *@home server (2.2) and it works flawlessly.
First let me explain a little about my setup so you can understand why I did it this way. I have 4 DID’s on an IAX pipe from my provider. I do not use POTS or SIP trunks on my * server. I have 2 local and 2 toll free DID’s. One of each are public which go stright to an auto attendant so I don’t care who calls those numbers. The other 2 are private and are for family/friends only. These 2 DID’s actually ring through to the phones, so I want to control who can ring through on these DID’s. I wanted my blacklist lookup to apply ONLY to these 2 DID’s.
I applied the code to the “extensions_additional.conf” file so I could control which DID’s the code applied to. The code needs to go in the [ext-did] context, appeneded before the already populated code for each DID you want this to apply to.
[ext-did]
include => ext-did-custom
;private number
exten => NPANXXXXXX,1,SetGlobalVar(blkstat=9) ; added by Joel
exten => NPANXXXXXX,2,DBget(blkstat=blacklist/${CALLERIDNUM}) ; added by Joel
exten => NPANXXXXXX,3,GotoIf($[“${blkstat}” = “1”]?custom-blacklisted,s,1) ; added by Joel
exten => NPANXXXXXX,4,SetVar(FROM_DID=NPANXXXXXX) ; from AMP
exten => NPANXXXXXX,5,SetVar(FAX_RX=disabled) ; from AMP
exten => NPANXXXXXX,6,Goto(ext-local,221,1) ; from AMP
First in line 1, we declare a variable. I did not want to use the pre-defined system variables. I set the initial value to “9” as this value is not used in the blacklist database so there should be no conflict.
Next in line 2, we check the database for the “blacklist” family looking to see if the current caller is in the database. If the number exists a value of 1 will be set into the “blkstat” variable.
Last in line 3, we check the value of the “blkstat” variable. If it is “1” (the number has been blacklisted) then the caller is sent off to the [custom-blacklisted] script. If not, then the caller gets passed through to the remaining script as gerenated by AMP.
In hindsight this MAY have worked if put into the [ext-did-custom] context, but I just couldn’t be bothered to mess with it once I had it working.
Joel says
An update to my last post on the blacklist lookup.
Although it did work flawlessly I realized after posting that if you make any changes in AMP it will over-write the “extensions-additional.conf” file, delelting the custom code.
Here is how to correct my previous mistake.
For whichever DID you want to check the blacklist, set the inbound routing in AMP for the DID to go to a custom application: I used “custom-check-private,s,1” in the field for the app name.
Then I added the following to the “extensions-custom.conf” file at the bottom
[custom-check-private]
exten => s,1,SetGlobalVar(blkstat=9) ; added by Joel
exten => s,2,DBGet(blkstat=blacklist/${CALLERIDNUM}) ; added by Joel
exten => s,3,GotoIf($[“${blkstat}”=”1”]?custom-blacklisted,s,1) ; added by Joel
exten => s,4,Goto(ext-local,221,1)
You will need to manually change line 4 to Goto whatever function you previously has the inbound route goto. Mine was extension 221.
CHRISTOPHER says
Note: On asterisk 1.2+ you must add (j) to the end, in order for it to actually make the priority jump. Like such:
exten => s,1,LookupBlacklist(j)
ever zalazar says
HI, I need to know about extensions-additional.conf
Lets say that i need to configure the language for each user when go to read their message. The menu of voicemail has to be in the language that the user choose. That users are not in sip.conf, they come directly from a S.E.R.server, and check the email. HOw can I configure them the language?
thanks
ryanczak says
I had to update this a bit to get it to work with Asterisk 1.4.2 (I don’t use Asterisk@home but it should work anyways).
First I had to replace calltrace as it does not seem to be available in asterisk 1.4.2. I did this by adding the following to the inbound call context:
Set(DB(lastcallerid/number)=${CALLERID(num)})
My inbound context looks like this:
exten => s,1,LookupBlacklist(j) ; If CID blacklisted, goto 102
exten => s,2,Set(DB(lastcallerid/number)=${CALLERID(num)})
exten => s,3,Dial(SIP/100,30,tr)
exten => s,4,Voicemail(u100)
exten => s,5,Hangup
exten => s,102,Goto(custom-blacklisted,s,1)
The rest is pretty straight forward. I added autofallthrough=no to the [general] context because yes is now the default value. It needs to be no for this to work properly. I replaced the DBput and DBget calls with the appropriate Set syntax (DBput and DBget have been depreciated). I changed the gotoif in [custom-blacklist-last] because it would not work as written above. Lastly I changed the ResponseTimeout(60) to Set(TIMEOUT(response)=60). Here are the changed blacklist contexts:
[custom-blacklist-add]
exten => s,1,Playback(enter-num-blacklist)
exten => s,2,Set(TIMEOUT(response)=60)
exten => s,3,Read(blacknr,then-press-pound)
exten => s,4,SayDigits(${blacknr})
exten => s,5,Playback(if-correct-press)
exten => s,6,Playback(digits/1)
;exten => 1,1,DBput(blacklist/${blacknr}=1)
exten => 1,1,Set(DB(blacklist/${blacknr})=1)
exten => 1,2,Playback(num-was-successfully)
exten => 1,3,Playback(added)
exten => 1,4,Wait(1)
exten => 1,5,Hangup
exten=_X.,3,Playback(num-was-successfully)
exten=_X.,4,Playback(added)
exten=_X.,5,Hangup
[custom-blacklist-remove]
exten => s,1,Playback(entr-num-rmv-blklist)
exten => s,2,Set(TIMEOUT(response)=60)
exten => s,3,Read(blacknr,then-press-pound)
exten => s,4,SayDigits(${blacknr})
exten => s,5,Playback(if-correct-press)
exten => s,6,Playback(digits/1)
exten => 1,1,DBdel(blacklist/${blacknr})
exten => 1,2,SayDigits($blacklist)
exten => 1,3,Playback(num-was-successfully)
exten => 1,4,Playback(removed)
exten => 1,5,Hangup
[custom-blacklisted]
exten=s,1,Answer
exten=s,2,Wait(1)
exten=s,3,Playback(nbdy-avail-to-take-call)
exten=s,4,Playback(carried-away-by-monkeys)
exten=s,5,Playback(lots-o-monkeys)
exten=s,6,Hangup
[custom-blacklist-last]
exten => s,1,Answer
exten => s,2,Wait(1)
exten => s,3,Set(number=${DB(lastcallerid/number)})
exten => s,4,GotoIf($[“${number}” = “”]?104) ; also if it’s blank (caller id blocked)
exten => s,5,Playback(privacy-to-blacklist-last-caller)
exten => s,6,Playback(telephone-number)
exten => s,7,SayDigits(${number})
exten => s,8,Playback(press)
exten => s,9,Playback(digits/1)
exten => 1,1,Set(DB(blacklist/${number})=1)
exten => 1,2,Playback(privacy-blacklisted)
exten => 1,3,Wait,1
exten => 1,4,Hangup
exten => s,104,Playback(unidentified-no-callback)
exten => s,106,Hangup
joey says
hey guys I am sorry I am an amateur here
I have developed a asterisk server and used the xlite softphones as my client. Now i need to find a way to detect voice spam using this setup.may be using blacklisting please help me on how to move forward from here.I have the initial setup ready
Anonymous says
I have the need to deploy a blacklist feature for multiple customers, who use the same asterisk server. The problem with blacklist is it only validates on the callerID. I need a way to validate on if the number is calling a particular DID, which has decided to blacklist them. Anyone have a dial plan for that?
Jake says
With LookupBlaclist being deprecated has any updated these dialplan applications to use just Blacklist() ?
Sven says
here is the dialplan in 1.4 for individual blacklist:
in the incoming contexts, add:
::CODECOLORERCOMMENT1::
in your features place:
::CODECOLORERCOMMENT2::
Sven says
here is the dialplan in 1.4 for individual blacklist:
in the incoming contexts, add:
in your features place:
Herman says
This is allfor professionalsnot learners like me please send a simple way of setting this blaclist on elastix easier