One reason why I wanted to deploy my own home PBX was that I get incredibly annoyed by telemarketers. The other day I was having a nice afternoon snooze when I was woken up by one. But I have an Asterisk system, so let's block these guys!
I'll provide the complete new extensions.conf below (for the impatient, like me).
Step 1Backup extensions.conf and add replace the [answer] context with this new [answer] context:
[answer]
exten => s,1,GotoIf(${BLACKLIST()}?blacklisted,s,1)
exten => s,n,NoOp(CURRENT CALLER ID= ${CALLERID(num)})
exten => s,n,Macro(stdexten,6002,SIP/6002)
Now in extensions.conf add the following context:
[blacklisted]
exten => s,1,Answer
exten => s,n,Wait(1)
exten => s,n,Zapateller
exten => s,n,Playback(ss-noservice)
exten => s,n,Hangup
And finally add the [blacklisted] context to [default]:
[default]
include => answer
include => blacklisted
include => app-system-blacklist
include => pstn-outgoing
include => numberplan-custom-1
exten => 6000,1,VoiceMailMain
Step 2
To add a caller to the blacklist fire up the Asterisk CLI and type:
database put blacklist XXXXXXXXXX 1
The trailing 1 after the phone number is necessary. To remove the number type:
database del blacklist XXXXXXXXXX
A few points:
Zapateller plays a Session Information Tone (SIT) that apparently will help remove you from the nasty telemarketer's database.
This code:
GotoIf(${BLACKLIST()}?blacklisted,s,1)
Replaces the older Asterisk 1.2 LookupBlacklist function. There's some interesting discussion about this over at
voip-info.org, but I couldn't get any of the examples offered to work!
Step 3Having to go to the CLI to add a blacklist number is a bit of a drag, so let's do this right from the phone. I couldn't find too many script examples in my Internet searching, but it was surprisingly easier than trying to get Step 2 done. The best example I found was here:
How to blacklist unwanted calleridWe have to modify this because we don't have perl and we want to use Asterisk 1.4 database calls. Here's what I did:
[app-system-blacklist]
; 33 1 - Add to blacklist
; 33 - Delete from blacklist
exten => _33XXXXXXXXXX.,1,Answer
exten => _33XXXXXXXXXX.,n,Set(DB(blacklist/${EXTEN:2:10})=${EXTEN:13})
exten => _33XXXXXXXXXX.,n,Wait(2)
exten => _33XXXXXXXXXX.,n,SayDigits(${EXTEN:2:10})
exten => _33XXXXXXXXXX.,n,Playback(added)
exten => _33XXXXXXXXXX.,n,Hangup
exten => _33XXXXXXXXXX,1,Answer
exten => _33XXXXXXXXXX,n,DBdel(blacklist/${EXTEN:2:10})
exten => _33XXXXXXXXXX,n,Wait(2)
exten => _33XXXXXXXXXX,n,SayDigits(digits/${EXTEN:2:10})
exten => _33XXXXXXXXXX,n,Playback(removed)
exten => _33XXXXXXXXXX,n,Hangup
Add [app-system-blacklist] to your [default] context and you should be good to go.
I had to remove * from my example (the above link has *96 as the prefix) because one of my Linksys phones got cranky and I'm too lazy to figure out why. I believe it has something to do with the phone's vertical service activation codes. (Don't you just love telco speak!). My other Linksys phone was happy with * so your YMMV!
To add a blacklisted number pickup the phone and dial:
33XXXXXXXXXX1
To remove the number dial:
33XXXXXXXXXX
Note: This is good for 10 digit local calls. If you get an 11 digit long distance call (prefixed by "1" for example) make a new blacklist app and include it in your default context. Alternatively, if you receive 7 digit calls make the appropriate changes by removing Xs and adjusting {EXTEN} for the new values.
FinallyHere's the latest incarnation of extensions.conf. I've cleaned it up a bit as I'm learning more:
;!
;! Automatically generated configuration file
;! Filename: extensions.conf (/opt/etc/asterisk/extensions.conf)
;! Generator: Manager
;! Creation Date: Fri Dec 28 02:25:23 2007
;!
[general]
;
; If static is set to no, or omitted, then the pbx_config will rewrite
; this file when extensions are modified. Remember that all comments
; made in the file will be lost when that happens.
;
; XXX Not yet implemented XXX
;
static = yes
;
;
; if stati=yes and writeprotect=no, you can save dialplan by
; CLI command 'save dialplan' too
;
writeprotect = yes
[globals]
PHONE1 = SIP/2203
; These variables are to avoid the irritating problem
; with inability to use regexp's on strings that have
; not been defined.
;
CALLFILENAME = foo
FOO = foo
trunk_1 = SIP/trunk_1
trunk_2 = IAX2/trunk_2
[macro-trunkdial]
;
; Standard trunk dial macro (hangs up on a dialstatus that should
; terminate call)
; ${ARG1} - What to dial
;
exten => s,1,Dial(${ARG1})
exten => s,n,Goto(s-${DIALSTATUS},1)
exten => s-NOANSWER,1,Hangup
exten => s-BUSY,1,Hangup
exten => _s-.,1,NoOp
[macro-stdexten];
;
; Standard extension macro:
; ${ARG1} - Extension (we could have used ${MACRO_EXTEN} here as well
; ${ARG2} - Device(s) to ring
;
exten => s,1,Dial(${ARG2},20) ; Ring the interface, 20 seconds maximum
exten => s,2,Goto(s-${DIALSTATUS},1) ; Jump based on status (NOANSWER,BUSY,CHAN
exten => s-NOANSWER,1,Voicemail(${ARG1},u) ; If unavailable, send to voicemail
exten => s-BUSY,2,Goto(default,s,1) ; If they press #, return to start
exten => _s-.,1,Goto(s-NOANSWER,1) ; Treat anything else as no answer
exten => a,1,VoicemailMain(${ARG1}) ; If they press *, send the user in
[macro-failann]
; Failure announcement playback macro:
; ${ARG1} - Status of the call, one of:
; (CHANUNAVAIL | CONGESTION | BUSY | NOANSWER |
; ANSWER | CANCEL | DONTCALL | TORTURE)
;
exten => s,1,Goto(s-${ARG1},1)
exten => s-CHANUNAVAIL,1,Playback(all-circuits-busy-now)
exten => s-CHANUNAVAIL,2,Playback(pls-try-call-later)
exten => s-CHANUNAVAIL,3,Hangup
exten => s-CONGESTION,1,Playback(cannot-complete-temp-error)
exten => s-CONGESTION,2,Playback(pls-try-call-later)
exten => s-BUSY,1,Playback(the-party-you-are-calling)
exten => s-BUSY,2,Playback(is-curntly-busy)
exten => s-BUSY,3,Hangup
exten => s-NOANSWER,1,Playback(the-party-you-are-calling)
exten => s-NOANSWER,2,Playback(is-curntly-unavail)
exten => s-NOANSWER,3,Hangup
exten => s-ANSWER,1,Hangup
exten => _s-.,1,Playback(cannot-complete-network-error)
exten => _s-.,2,Playback(pls-try-call-later)
exten => _s-.,3,Hangup
[pstn-outgoing]
exten => 911,1,Dial(SIP/${EXTEN}@LinksysFXO,,T)
exten => 911,2,Macro(failann,${DIALSTATUS})
exten => _604NXXXXXX,1,Dial(SIP/${EXTEN}@LinksysFXO,60,T)
exten => _604NXXXXXX,2,Macro(failann,${DIALSTATUS})
exten => _1250NXXXXXX,1,Dial(SIP/${EXTEN}@LinksysFXO,60,T)
exten => _1250NXXXXXX,2,Macro(failann,${DIALSTATUS})
exten => _778NXXXXXX,1,Dial(SIP/${EXTEN}@LinksysFXO,60,T)
exten => _778NXXXXXX,2,Macro(failann,${DIALSTATUS})
exten => _18XXNXXXXXX,1,Dial(SIP/${EXTEN}@LinksysFXO,60,T)
exten => _18XXNXXXXXX,2,Macro(failann,${DIALSTATUS})
[answer]
exten => s,1,GotoIf(${BLACKLIST()}?blacklisted,s,1)
exten => s,n,NoOp(CURRENT CALLER ID= ${CALLERID(num)})
exten => s,n,Macro(stdexten,6002,SIP/6002)
[blacklisted]
exten => s,1,Answer
exten => s,n,Wait(1)
exten => s,n,Zapateller
exten => s,n,Playback(ss-noservice)
exten => s,n,Hangup
[app-system-blacklist]
; 33 1 - Add to blacklist
; 33 - Delete from blacklist
exten => _33XXXXXXXXXX.,1,Answer
exten => _33XXXXXXXXXX.,n,Set(DB(blacklist/${EXTEN:2:10})=${EXTEN:13})
exten => _33XXXXXXXXXX.,n,Wait(2)
exten => _33XXXXXXXXXX.,n,SayDigits(${EXTEN:2:10})
exten => _33XXXXXXXXXX.,n,Playback(added)
exten => _33XXXXXXXXXX.,n,Hangup
exten => _33XXXXXXXXXX,1,Answer
exten => _33XXXXXXXXXX,n,DBdel(blacklist/${EXTEN:2:10})
exten => _33XXXXXXXXXX,n,Wait(2)
exten => _33XXXXXXXXXX,n,SayDigits(digits/${EXTEN:2:10})
exten => _33XXXXXXXXXX,n,Playback(removed)
exten => _33XXXXXXXXXX,n,Hangup
[default]
include => answer
include => blacklisted
include => app-system-blacklist
include => pstn-outgoing
include => numberplan-custom-1
exten => 6000,1,VoiceMailMain
[asterisk_guitools]
exten = executecommand,1,System(${command})
exten = executecommand,n,Hangup()
exten = record_vmenu,1,Answer
exten = record_vmenu,n,Playback(vm-intro)
exten = record_vmenu,n,Record(${var1})
exten = record_vmenu,n,Playback(vm-saved)
exten = record_vmenu,n,Playback(vm-goodbye)
exten = record_vmenu,n,Hangup
exten = play_file,1,Answer
exten = play_file,n,Playback(${var1})
exten = play_file,n,Hangup
hasbeensetup = Y
[DID_trunk_1]
include = default
exten = _X.,1,Goto(default|6003|1)
exten = s,1,Goto(default|6003|1)
[numberplan-custom-1]
plancomment = DialPlan1
include = default
include = parkedcalls
exten = _8XXX!,1,Macro(trunkdial,${trunk_1}/${EXTEN:1})
comment = _8XXX!,1,FWD_SIP_Rule,standard