Adding SIP clients to Asterisk

SIP clients in Asterisk are specified in the sip.conf file, so open it for example in the nano text editor (Ctrl+X to exit the editor, y or n to save or discard changes):

sudo nano /etc/asterisk/sip.conf

First we specify the following parameter, forbidding anonymous calls:

allowguest=no

Now at the very end of the file, add the client:

[6000]
type=friend
secret=PASSWORD
nat=no
host=dynamic
dtmfmode=rfc2833
disallow=all
allow=ulaw
context=sip-dialout
callerid=6000
deny=0.0.0.0/0
permit=192.168.0.10/32

Briefly describe the parameters that I indicated:
type – type of client, can be user (authentication by password), peer (identification by host address), fried (either by password or by host).
secret – user password.
nat=no – indicates that the client may be behind NAT, see my article about this – Solution to the Asterisk problem – no sound when calling via NAT.
host=dynamic – there is no client binding to the host address.
dtmfmode=rfc2833 – method of transmitting dtmf dialing tones.
disallow=all – ban all codecs.
allow=ulaw – Let’s solve only the ulaw codec.
context=sip-dialout — the name of the dialplan (it is described in extensions.conf)
callerid=6000 – customer’s internal phone number.
deny=0.0.0.0/0 – we forbid connection from all IP addresses.
permit=192.168.0.10/32 – we only allow connection from the specified IP address.

After adding the client, we will connect to Asterisk and update the sip configuration:

sudo asterisk -r
sip reload

To see the list of clients you can use the command:

sip show users

To exit the Asterisk console, type:

quit

Now it is already possible to connect the added client to the Asterisk server using for example the X-Lite, Zoiper or VoIP phone program, but there is nowhere to call, so we will add the second client to sip.conf for the test:

[6001]
type=friend
secret=PASSWORD
nat=no
host=dynamic 
dtmfmode=rfc2833
disallow=all
allow=ulaw
context=sip-dialout
callerid=6001
deny=0.0.0.0/0
permit=192.168.0.10/32

Open the extensions.conf file in the editor:

sudo nano /etc/asterisk/extensions.conf

And we will indicate the following lines at the end of it, so that users can call each other:

[sip-dialout]
exten => 6000,1,Dial(SIP/6000)
exten => 6001,1,Dial(SIP/6001)

Restart Asterisk to apply the changes:

sudo service asterisk restart

Done, we added two users and they can call each other.

See also:
Adding a SIP client to FreePBX

Adding a SIP client to FreePBX

To add a SIP client to FreePBX, open the menu “Applications” – “Extensions“, choose for example “Generic CHAN SIP Device” and we indicate the main parameters:

User Extension: 6000 (SIP number)
Display Name: Operator (any name to display)
Secret: PASSWORD
and click “Submit“.

Done, SIP is added, it can already be registered at the specified number and password.

How to add SIP in the configuration file I described in this article – Adding SIP clients to Asterisk

Installing the Digium Asterisk GUI

Digium Asterisk GUI – web-management interface Asterisk.

Today I’ll sculpt it to Asterisk 11 on Ubuntu Server 14.04 LTS.
Switch directly to the root user:

sudo -i

Download it:

apt-get install subversion
mkdir -p ~/asterisk-gui
cd ~/asterisk-gui
svn checkout http://svn.digium.com/svn/asterisk-gui/branches/2.0/

We compile and install:

cd 2.0
./configure
make
make install

Just in case, we’ll make a copy of the Asterisk configuration files:

cp -r /etc/asterisk /etc/asterisk.original

Open the configuration file manager.conf for example in the editor nano (Ctrl+X to exit the editor, y/n to save or cancel changes):

nano /etc/asterisk/manager.conf

The main parameters that must be configured in the manager.conf configuration file are:

[general]
enabled = yes
webenabled = yes
bindaddr = 0.0.0.0
[USERNAME]
secret = PASSWORD
read = system,call,log,verbose,command,agent,user,config
write = system,call,log,verbose,command,agent,user,config

At the very end of the file, replace the symbol # with; otherwise you can not enter under the login and password specified above.

Now edit http.conf:

nano /etc/asterisk/http.conf

In it we will specify the following parameters of the web server:

enabled=yes
enablestatic=yes
bindaddr=0.0.0.0
prefix=asterisk

Let’s check the settings:

make checkconfig

Delete the empty folder and specify a link to the real one with the files of the web server:

rmdir /usr/share/asterisk/static-http/
ln -s /var/lib/asterisk/static-http/ /usr/share/asterisk/

Restarting Asterisk:

/etc/init.d/asterisk restart

Now Digium Asterisk GUI should open by link http://192.168.56.102:8088/asterisk/static/config/index.html, where 192.168.56.102 this is the IP or Server domain with Asterisk.

To log in, we’ll specify the username and password you wrote earlier in the manager.conf file

Done.

Solution to the Asterisk problem – no sound when calling via NAT

I noticed recently that there is no sound when calling from IP-phone to another IP-phone which were both behind the same NAT (router).

Therefore, in the sip.conf configuration for these accounts, you need to specify that they are behind NAT, specifying the parameter:

nat=force_rport,comedia

I want to note that the value of “yes” for nat is already obsolete since version Asterisk 11, so it will be correct as mentioned above.

And also point at no to the directmedia parameter, so that Asterisk does not send packets to the same port from which it was received (which in my case happened, both phones connected to Asterisk from the same IP, with the same ports):

directmedia=no

Done.

Asterisk Error Solution “Context ‘local’ tries to include nonexistent context ‘parkedcalls'”

I screwed the DAHDI board somehow and noticed the following error when I dialed the call from the analog line:

WARNING[7238]: pbx.c:12314 ast_context_verify_includes: Context ‘local’ tries to include nonexistent context ‘parkedcalls’

The error occurred because the res_parking module was not loaded to load it, open the asterisk console and execute the command:

sudo asterisk -vvr
module load res_parking

To automatically load it when starting Asterisk, in the file /etc/asterisk/modules.conf, in the [modules] block, add the line:

load => res_parking.so

Configuring Asterisk CDR and Asterisk CDR Viewer

CDR (Call Data Record), allows you to keep statistics on call activity in the MySQL database.

On the test, I set up the Asterisk CDR and the Asterisk CDR Viewer in Ubuntu Server.
Suppose that Asterisk is already installed.

First we will install the necessary components:

sudo apt-get install mysql-server php5-mysql apache2 git
sudo service apache2 restart

Let’s start creating a database in which records of calls will be saved.
Connect to MySQL:

mysql -u root -p

Create a database:

CREATE DATABASE asteriskcdrdb;

Create asteriskcdr user:

GRANT ALL PRIVILEGES ON asteriskcdrdb.* TO  asteriskcdr@localhost  IDENTIFIED BY 'PASSWORD';
flush privileges;

Switch to the base asteriskcdrdb:

use asteriskcdrdb;

And create the table:

CREATE TABLE cdr (
   calldate datetime NOT NULL default '0000-00-00 00:00:00',
   clid varchar(80) NOT NULL default '',
   src varchar(80) NOT NULL default '',
   dst varchar(80) NOT NULL default '',
   dcontext varchar(80) NOT NULL default '',
   channel varchar(80) NOT NULL default '',
   dstchannel varchar(80) NOT NULL default '',
   lastapp varchar(80) NOT NULL default '',
   lastdata varchar(80) NOT NULL default '',
   duration int(11) NOT NULL default '0',
   billsec int(11) NOT NULL default '0',
   disposition varchar(45) NOT NULL default '',
   amaflags int(11) NOT NULL default '0',
   accountcode varchar(20) NOT NULL default '',
   uniqueid varchar(32) NOT NULL default '',
   userfield varchar(255) NOT NULL default '',
   did varchar(50) NOT NULL default '',
   recordingfile varchar(255) NOT NULL default '',
   KEY `calldate` (`calldate`),
   KEY `dst` (`dst`),
   KEY `accountcode` (`accountcode`),
   KEY `uniqueid` (`uniqueid`)
);

This completes the creation of the database, now we proceed to configure the configuration file /etc/asterisk/cdr_mysql.conf, as standard, all the lines in it are commented out.
Uncomment and specify the parameters for connecting to the mysql database in the [global] section:

[global]
hostname=localhost
dbname=asteriskcdrdb
table=cdr
password=PASSWORD
user=asteriskcdr

In the configuration file of the modules /etc/asterisk/modules.conf, the module cdr_mysql.so must be registered for the load:

load => cdr_mysql.so

Manually it can be loaded from the asterisk console like this:

sudo asterisk -rvv
module load cdr_mysql.so
module show like cdr_mysql.so

After the module is loaded, when receiving calls, the data should be entered into the database, let’s see if there is something:

mysql -u root -p
use asteriskcdrdb;
select * from cdr;

In fact, now you can use data from the database in any convenient way, for example, to add to any billing script statistics and graphs.
We’ll set up the finished Asterisk CDR Viewer.
Download the files and move them to the web server directory:

cd /tmp/
git clone https://github.com/g613/asterisk-cdr-viewer/
cd asterisk-cdr-viewer
tar -xzvf asterisk-cdr-viewer-latest.tgz
mv asterisk-cdr-viewer /var/www/asterisk-cdr-viewer
chown -R www-data:www-data /var/www/

The Russian version can be found here https://github.com/prog-it/Asterisk-CDR-Viewer-Mod

Copy the file with the web configuration to the directory with the web server apache2:

cp /var/www/asterisk-cdr-viewer/contrib/httpd/asterisk-cdr-viewer.conf /etc/apache2/conf-enabled/asterisk-cdr-viewer.conf
service apache2 restart

Specify the connection settings for the database for the Asterisk-CDR-viewer in the file /var/www/asterisk-cdr-viewer/include/config.inc.php

After that you will be able to view the statistics by opening in the browser http://SERVER/acdr

In version 1.0.9, I noticed a typo in the code, because of which a white screen was displayed and there was an error in the logs:

PHP Parse error: syntax error, unexpected ‘[‘ in /var/www/asterisk-cdr-viewer/index.php on line 23

To fix this, open the file index.php and at the end of the 23 line we will see the missing $:

$startmonth = is_blank($_REQUEST['startmonth']) ? date('m') : printf('%02d',_REQUEST['startmonth']);

It should be like this:

$startmonth = is_blank($_REQUEST['startmonth']) ? date('m') : printf('%02d',$_REQUEST['startmonth']);

Done.

The solution of the error “Unable to create channel of type ‘SIP’ (cause 20 – Subscriber absent)”

I noticed one time when I received a call from the Asterisk console:

dial_exec_full: Unable to create channel of type ‘SIP’ (cause 20 – Subscriber absent)

In the context of the dialplan, I make a call simultaneously to two phones:

exten => s,5,DIAL(SIP/204&SIP/203,19)

Sometimes one of the IP phones is turned off, which is why this error occurs, informing that there is no subscriber.
To solve it, you just need to turn on the IP phone.

You can see information about SIP in the Asterisk console:

asterisk -rvv
sip show peers
sip show peer NUMBER
quit

If the client’s IP address is null and expire is -1, the SIP client is not online:

Expire: -1
Addr->IP: (null)

Solving the error in Asterisk “File vm-newn does not exist in any format”

When I called a voicemail number, I noticed the following errors in the Asterisk console:

[Apr 10 17:08:01] WARNING[19135][C-00001cf4]: file.c:701 ast_openstream_full: File digits/1n does not exist in any format
[Apr 10 17:08:01] WARNING[19135][C-00001cf4]: file.c:1017 ast_streamfile: Unable to open digits/1n (format (ulaw)): No such file or directory
[Apr 10 17:08:01] WARNING[19135][C-00001cf4]: file.c:701 ast_openstream_full: File vm-newn does not exist in any format
[Apr 10 17:08:01] WARNING[19135][C-00001cf4]: file.c:1017 ast_streamfile: Unable to open vm-newn (format (ulaw)): No such file or directory

Errors are caused by the lack of sound files, for example, in my case in the voice mail one message and when I try to say “you have one (1n.ulaw) new (vm-newn) message, an error occurs and the handset lies down.

Archive with a set of necessary files is enough to simply download from the official site http://downloads.asterisk.org/pub/telephony/sounds/releases/ and unpack to the directory /usr/share/asterisk/sounds
After this, the error should not be.

How to remove “New User” in Asterisk CallerID

I noticed once that when incoming calls from the Goip4 gateway on SIP phones, not only the caller’s number is displayed, but the name “New User” flashes alternately with the phone number, which is obviously superfluous and hinders.

After viewing the Asterisk configuration files, I noticed some standard values in the /etc/asterisk/users.conf file in the general section, namely:

[general]
fullname = New User

Which need to comment out:

;fullname = New User

And restart Asterisk to apply the changes:

sudo service asterisk restart

Done, now with incoming calls only the phone number will be displayed.