Asterisk 101 : How to get rid of your mother-in-law …

… or anyone else really, with a little trick to implement a black list and filter unwanted callers.

1. The BLACKLIST function

Asterisk implements a BLACKLIST function which can be used to check whether a callerID is blacklisted or not, here is the synopsis (which you can get by connecting to thee asterisk server by issuing the asterisk -v command and then core show function BLACKLIST) :

spaghetti*CLI> core show function BLACKLIST

  -= Info about function 'BLACKLIST' =- 

[Synopsis]
Check if the callerid is on the blacklist. 

[Description]
Uses astdb to check if the Caller*ID is in family 'blacklist'. Returns '1'
or '0'.

[Syntax]
BLACKLIST()

[Arguments]
Not available

[See Also]
DB
spaghetti*CLI> 

This is what we’re going to use for this example.

2. Managing the blacklist

You can add callerIDs to the blacklist with the following command :

spaghetti*CLI> database put blacklist 03001125000 "Mother-in-law from hell"
Updated database successfully
spaghetti*CLI> database put blacklist 03001125150 "FAX machine harassing me"
Updated database successfully

If later on you wish to remove an item from the blacklist (maybe the fax is not that bad after all !), use the following :

spaghetti*CLI> database del blacklist 03001125150 
Database entry removed.

And of course you can list the content of the current blacklist like that :

spaghetti*CLI> database show blacklist
/blacklist/03001125000                             : Mother-in-law from hell
1 results found.
spaghetti*CLI> 

Use those commands to tailor the blacklist according to your needs.

3. Altering the dialplan to filter out the blacklisted numbers

Next you’ve got to update your incoming context to deal with blacklisted callerIDs. My incoming context is named “incoming-calls” but you might have to adjust that :

[incoming-calls] ; on declare le contexte de reception d'appels depuis freephonie
exten => s,1,GotoIf($["${CALLERID(NUM)}" = "anonymous"] ? 10) 
exten => s,2,GotoIf(${BLACKLIST()} ? 10)
exten => s,3,Dial(SIP/phone1&SIP/phone2,10)
exten => s,4,Congestion()
exten => s,5,Hangup()
exten => s,10,Answer
exten => s,11,Wait(1)
exten => s,12,MusicOnHold(default)
exten => s,13,Hangup

So here, the rules 1 and 2 are to send both anonymous callers (mostly telemarketers over here) and blacklisted callers to an infinite holding music (starting at line 10). The rules 3,4,5 are to deal with other calls and direct them to 2 SIP phones.

That’s it ! Feel free to ask if you need more details about this set up.

One thought on “Asterisk 101 : How to get rid of your mother-in-law …”

Comments are closed.