Tag Archive for 'asterisk'

Page 2 of 3

Asterisk: block inbound call by CALLERID(num) (AEL syntax)

One number :

    73522123456 =>
        if(${CALLERID(num)} = 74995008119)

Several numbers:

    73522123456 =>
    switch (${CALLERID(num)}) {

         case 74957805170:
            NoOp(Block call from Susan);

        pattern [78]4957805174:
            NoOp(Block call from Anna);

        pattern [78]4957805061:
            NoOp(Block call from Lily );

        pattern [78]495780508X:
            NoOp(Block call from Samantha);


pattern – here you may use constructions like [167] and/or 123X.
case – is exact sequence of symbols.


Asterisk AMI

Let your first-line support do ‘sip reload’ neither with knowing Asterisk, nor with a priveleged account in the system.
Set up manager.conf:

enabled = yes
webenabled = no

port = 5038
bindaddr =

secret = supportpass

displayconnects = yes
read = system,command
write = system,command

Create a php page on some host with Apache and PHP configured:


Asterisk run user

When installing Asterisk from source, you need to create an unprivileged user manually.
Add to /etc/group something like:
and to /etc/passwd:
asterisk:x:107:110:Asterisk PBX daemon,,,:/var/lib/asterisk:/bin/false
Just set unused GID and UID.

Then change permissions:
chown -R asterisk:asterisk /var/lib/asterisk/
chown -R asterisk:asterisk /var/spool/asterisk/
chown -R asterisk:asterisk /var/log/asterisk/
chown -R asterisk:asterisk /var/run/asterisk/

And finally, set the running user in asterisk.conf.

It is not mentioned in the Book, but I think chown‘ing /etc/asterisk/ with the -R option is also worth doing; changing config files (not directories, if exist) permissions in /etc/asterisk to 640 either.

Digium Certified Asterisk Administrator (dCAA)

Now I am a Digium Certified Asterisk Administrator (dCAA).

Asterisk 1.8, Debian package, no app_meetme.so

If you’ve installed Asterisk 1.8 from Debian repository and do not have app_meetme, install the asterisk-dahdi package.

Asterisk: contactpermit and contactdeny

We can control in the [general] section of the sip.conf from which IP-addresses the device can register against our Asterisk server. This could be achieved with the ‘contactpermit‘ and ‘contactdeny‘ parameters:


The example above denies to register from any IP address and allows registration for devices which have 10.145.13.x or 10.145.14.x address.

Note, that these are separate options, besides ‘deny=x.x.x.x/x.x.x.x’ and ‘permit=x.x.x.x/x.x.x.x’, which are set in your SIP peers sections.

Asterisk & IPtables

A good starting place is a set of rules similar to this one:

iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A INPUT -p tcp --dport 22 -j ACCEPT
iptables -A INPUT -p udp --dport 5060 -j ACCEPT
iptables -A INPUT -p udp --dport 10000:20000 -j ACCEPT
iptables -A INPUT -i lo -j ACCEPT
iptables -P FORWARD DROP
iptables -P INPUT DROP

Asterisk modules

My practice of manual loading of needed modules only.
Change ‘autoload=yes‘ to ‘autoload=no‘ in /etc/asterisk/modules.conf .
Restart Asterisk – Asterisk CLI> core restart now (remember that it will cancel all active calls).

Login into Asterisk console (root# asterisk -rvvvvvvv). Then load modules manually:
Asterisk CLI> module load app_dial.so
Asterisk CLI> module load app_playback.so
Asterisk CLI> module load chan_sip.so
Asterisk CLI> module load codec_alaw.so
Asterisk CLI> module load codec_gsm.so
Asterisk CLI> module load res_rtp_asterisk.so
Asterisk CLI> module load res_musiconhold.so
Asterisk CLI> module load func_dialplan.so
Asterisk CLI> module load pbx_config.so
Asterisk CLI> module load format_sln.so
Asterisk CLI> module load format_wav.so
Asterisk CLI> module load format_gsm.so
Asterisk CLI> module load app_record.so

A nice help for modules being used is ‘Asterisk CLI> module show‘ . This is mine:

Asterisk CLI> module show 
Module                         Description                              Use Count 
res_musiconhold.so             Music On Hold Resource                   0         
app_dial.so                    Dialing Application                      0         
app_playback.so                Sound File Playback Application          0         
chan_sip.so                    Session Initiation Protocol (SIP)        0         
codec_alaw.so                  A-law Coder/Decoder                      0         
codec_gsm.so                   GSM Coder/Decoder                        0         
res_rtp_asterisk.so            Asterisk RTP Stack                       0         
func_dialplan.so               Dialplan Context/Extension/Priority Chec 0         
pbx_config.so                  Text Extension Configuration             0         
format_sln.so                  Raw Signed Linear Audio support (SLN)    0         
app_record.so                  Trivial Record Application               0         
format_wav.so                  Microsoft WAV/WAV16 format (8kHz/16kHz S 0         
format_gsm.so                  Raw GSM data                             0         
13 modules loaded
Asterisk CLI> 

If you need AEL, you have to load 2 modules (in shown sequence):

Asterisk CLI> module load res_ael_share.so
Asterisk CLI> module load pbx_ael.so

The best practice is to configure /etc/asterisk/modules.conf according to its syntax, to prevent manual loading of modules each time your Asterisk PBX starts.

Your installation may need other modules as well.

Asterisk: запись продиктованного в телефон

Добавляем в диалплан

exten => *98,1,Answer()
exten => *98,n,Wait(2)
exten => *98,n,Record(/tmp/myrecord%d:wav)
exten => *98,n,Wait(1)
exten => *98,n,Playback(${RECORDED_FILE})
exten => *98,n,Wait(1)
exten => *98,n,Hangup()

Начинаем надиктовывать после сигнала (услышите его, набрав *98), когда сказали всё, что хотели, нажимаем # , после чего через секунду нам проиграют надиктованный голос.

Asterisk: конвертируем файлы для MOH

Вариантов много, подробности тут http://www.voip-info.org/wiki/view/Convert+WAV+audio+files+for+use+in+Asterisk

Я сначала конвертировал .mp3 в .wav, но Asterisk ругался, поэтому пришлось .wav конвертировать в .sln, он очень хорош для Asterisk’a.

mpg123 -w foo-out.wav foo-in.mp3
sox foo-in.wav -t raw -r 8000 -s -2 -c 1 foo-out.sln

По ссылке выше написано, что можно сразу из .mp3 в .sln, но у меня не получилось.