Asterisk open source PBX applications
This is a collection of applications that I've done for Asterisk. These were only tested on Asterisk 1.4.21
1 - Filter application
1.1 - Compiling and Installing
1.2 - Configuration
1.3 - Configuration with mysql
1.4 - Dialplan
1.5 - Download
2 - Phonebook Application
2.1 - Compiling and Installing
2.2 - Configuration
2.3 - Download
3 - Sound injection Application
3.1 - Compiling and Installing
3.2 - Configuration
3.3 - Download
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
Phonebook Application
This application lets you enter the name of a contact with your phone keypad (2 = a,b or c ...) and retrieves
its phone number from a mysql database. Let's say you have a contact named "André l'heureux",
you would enter 2637354387389. You don't need to enter all the letters, just enough so that only one match is found.
After completing, the application will set a channel variable "SEARCHRETURN" with the following values:
0: Match found
1: Too many matches found
2: No match found
3: General error
Compiling and Installing
First, get a copy of the source code. Untar in any folder you like. With this one, the source code doesn't need to reside in the asterisk source tree, but you will need the asterisk sources on your computer. You might need to change the Makefile since the folders in there are good for my installation, but might not be good for yours. It's a one-line change anyway. Next, just type "make" to build the app, or "make load" to automatically build,install and load the module into asterisk. so basically:
wget http://www.dumaisnet.ca/files/app_phonebook.tar tar -xf app_phonebook.tar # you might need to modify the ASTMODULES and INCLUDES paths in Makefile make load
Configuration
There is no configuration to do for the module itself. All you need to do is to call the application in your
dialplan. You have to execute Answer() first in the dialplan. The application takes 6 parameters:
1- dbname: The database name
2- username: The database user name
3- password: The password
4- tablename: The table which contains your phonebook
5- namefield: The name of the field that holds the name of your contacts
6- phonefield: The name of the field that holds the phone number of your contacts
The application assumes that the database resides on the local computer. If this is not the case for you, you can change the mysql_real_connect line in the source file. Let's say I have a table defined as follow:
PhoneBook( ID INT NOT NULL AUTO_INCREMENT, phone VARCHAR(12), name VARCHAR(25), );
I would do this in my dialplan:
exten => *6,1,Answer() exten => *6,2,Playback(enternameofcontact) exten => *6,3,Phonebook(contactdatabase,username,password,PhoneBook,name,phone) exten => *6,4,Hangup()
Download
Sound injection Application
This application, while not very usefull, is quite funny. I use it to inject sounds on an arbitrary channel, part of an active call, and will not be heard by the other peer. This will act a bit like ChanSpy, except that when pressing on a digit on your keypad, a sound file will be played on the specified channel. For example, let's say that ipphone1 is currently talking talking to ipphone2. With ipphone3, you call an extention that executes Inject(SIP/ipphone2). This will allow you to hear the conversation between ipphone1 and ipphone2. Now you would like to inject a sample that says "What is your name?" (a sound file recorded with the voice of the user using ipphone1). This can now be done by pressing a digit on your keypad. Not only they will not hear you on the other end, but the sound file that you have just injected will be heard by ipphone2 only. This could create a lot of confusion for both users.
Compiling and Installing
First, get a copy of the source code. Untar in any folder you like. With this one, the source code doesn't need to reside in the asterisk source tree, but you will need the asterisk sources on your computer. You might need to change the Makefile since the folders in there are good for my installation, but might not be good for yours. It's a one-line change anyway. Next, just type "make" to build the app, or "make load" to automatically build,install and load the module into asterisk. so basically:
wget http://www.dumaisnet.ca/files/app_inject.tar tar -xf app_inject.tar # you might need to modify the ASTMODULES and INCLUDES paths in Makefile make load
Configuration
No configuration files are needed. The only thing you need to setup is the dialplan. You only need to call Inject(CHANNEL). No need to answer first, the application will take care of it.
exten => *7,1,Inject(SIP/ipphone) exten => *7,2,Hangup()
You will need to provide sound files for when you will press digits to play the different sounds that you need. You need to copy 10 sound files in your sound folder (usualy /var/lib/asterisk/sounds). They MUST follow the name scheme "injection0.gsm", "injection1.gsm", ... "injection9.gsm". Of course, you could use .wav or .gsm. As you guessed it, pressing on "5" will play injection5.gsm. It is not necessary to provide all sound files.