Posts Tagged ‘asterisk’

Asterisk: round-robin dial out through trunks

Thursday, March 27th, 2014

Imagine that we have 3 trunks for dial out and we must balance outgoing calls in random order. This could be done with the RAND function. Module func_rand.so must be compiled and loaded.

sip.conf:

[trunk1](trunk_preset)
host=10.10.10.11

[trunk2](trunk_preset)
host=10.10.10.12

[trunk3](trunk_preset)
host=10.10.10.13

extensions.conf:

exten => _79XXXXXXXXX,1,NoCDR()
    same => n,Dial(SIP/trunk${RAND(1,3)}/${EXTEN})
    same => n(hang),Hangup()

You may say – well, OK, but what if my trunks are named not like [trunk1], [trunk2], [trunkN] and I can not substitute the last symbol in Dial application?
In this case we can write a list of trunk names (which you configured already in sip.conf) in txt file, for example rrtrunks.txt:

teliasonera-out
deutschetelekom-out
level3-out

Ensure that a ‘sort’ command is available in your *NIX system. Usually it’s a part of coreutils. Older versions don’t suit us, because they don’t have the ‘-R’ flag which means sort randomly. Newer versions have.

Then load func_shell.so and use it in your dialplan. It can execute a shell command and use its output in dialplan.

exten => _79XXXXXXXXX,1,NoCDR()
    same => n,Dial(SIP/${SHELL(sort -R /etc/asterisk/rrtrunks.txt | head -1)}/${EXTEN},20)
    same => n,Hangup()

It means that we sort randomly our list of trunks and get the first one each time.

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

Friday, January 31st, 2014

One number :

    73522123456 =>
    {
        if(${CALLERID(num)} = 74995008119)
            {
            Hangup;
            }
        Dial(IAX2/iaxpeer/somedevice);
    }

Several numbers:

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

         case 74957805170:
            NoOp(Block call from Susan);
            Hangup();
            break;

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

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

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

        default:
            Set(CDR(accountcode)=some-accountcode);
            Dial(SIP/somepeer/tomsphone01,,r);
        }
    }

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

https://wiki.asterisk.org/wiki/display/AST/AEL+Conditionals

Asterisk AMI

Monday, October 28th, 2013

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

[general]
enabled = yes
webenabled = no

port = 5038
bindaddr = 10.190.52.14

[support]
secret = supportpass
deny=0.0.0.0/0.0.0.0
permit=10.190.52.0/255.255.255.0
permit=10.190.51.4/255.255.255.255

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

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

';
}
fclose($socket);
}
?>

Asterisk run user

Friday, September 27th, 2013

When installing Asterisk from source, you need to create an unprivileged user manually.
Add to /etc/group something like:
asterisk:x:110:
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)

Wednesday, July 10th, 2013

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

Asterisk 1.8, Debian package, no app_meetme.so

Thursday, May 30th, 2013

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

Thursday, May 23rd, 2013

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:

contactdeny=0.0.0.0/0.0.0.0
contactpermit=10.145.13.0/255.255.255.0
contactpermit=10.145.14.0/255.255.255.0

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

Tuesday, January 22nd, 2013

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 OUTPUT ACCEPT
iptables -P INPUT DROP

Asterisk modules

Tuesday, January 22nd, 2013

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: запись продиктованного в телефон

Friday, January 11th, 2013

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

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), когда сказали всё, что хотели, нажимаем # , после чего через секунду нам проиграют надиктованный голос.