WWW.DUMAISNET.CA

Asterisk Filter ApplicationLast edited on Feb 25, 2012

Filter application

I use this application to manage a blacklist of telemarketers. Althought this could be easily done with a perl script, I'd rather have a real application for it. This application will allow you to define several groups. In each group, you add a list of callerID, an optional greeting message and a context/extension pair to jump to. If the callerID of an incomming call matches a callerID defined in a group, the group's greeting message will be played and the dialplan will jump to the context/extension defined for that group. If no greeting is defined, none will be played. If no context/extension pair is defined, dialplan execution will continue normaly.

Compiling and Installing

After downloading app_filter.c, copy the file in your asterisk source three and compile it. In my example, I am assuming that your asterisk source code is in /usr/src/asterisk-1.4.21.1/apps/ and that your modules are located in /usr/lib/asterisk/modules/.

cp app_filter.c /usr/src/asterisk-1.4.21.1/apps/
cd /usr/src/asterisk-1.4.21.1
make apps
cp apps/app_filter.so /usr/lib/asterisk/modules/

next, go into the asterisk CLI and load the module using "module load app_filter.so". Of course it is also possible to have the module loaded automatically using /etc/asterisk/modules.conf. Now you are ready to use the module

Configuration

You must first create /etc/asterisk/filter.conf. Add the following:

[general]
dbtype => 0

"dbtype" must be set to 0 if the same configuration file is going to be used for defining filter groups. Set dbtype to 1 if you prefer mysql. If you are going to be using mysql, you can skip to the next section. Otherwise, here's how to do it. Note that the configuration file is read each time that Filter() is called

You can several sections, in the file. In each section, add as many callerIDs as you want using the "cid:" directive. Define an optional greeting with "greeting", context with "context" and extension to "exten" Complete example:

[general]
dbtype => 0

[test1]
cid => 1001234567
cid => 1001234566
greeting => greeting1 ; do not add the extension. This file must be present in /var/lib/asterisk/sounds

[test2]
cid => 1001234565
cid => 1001234564
greeting => not-welcome
context => telemarketer-torture
exten => s

In this example, caller with callerID 100-123-4565 will hear the "not-welcome.wav" greeting message and will be redirected to extension "s" in the "telemarketer-torture" context

Configuration with mysql

mysql support is not implemented yet

Dialplan

Here is how you should use it in the dialplan:

exten => s,1,Answer()
exten => s,2,Filter()

Download

The source code can be found here: app_filter.c