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:

   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:


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

load =>

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

sudo asterisk -rvv
module load
module show like

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
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

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/

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']);


Configuring FreeRADIUS DHCP for ABillS

Suppose you installed FreeRADIUS 2 as written in this article – Installation and configuration of the ABillS billing system
Now copy the dhcp.conf file into the FreeRADIUS configuration:

sudo cp /usr/abills/misc/freeradius/v2/dhcp.conf /usr/local/freeradius/etc/raddb/sites-enabled/

Continue reading “Configuring FreeRADIUS DHCP for ABillS”

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

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

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

Linux disk test for errors and broken sectors

Switch directly to the root user:

sudo -i

Let’s see the list of disks:

fdisk -l
df -h

You can see the information and model of the disk as follows:

hdparm -i /dev/sda

If SMART is supported, install the utilities and see the SMART statistics:

apt-get install smartmontools
smartctl -a /dev/sda
smartctl -a /dev/sda|grep -i reallocated

Run SMART tests and view information (smartctl -X to stop the long test):

smartctl -H /dev/sda
smartctl --test=long /dev/sda
smartctl -l selftest /dev/sda

Now we will perform a disk check on the broken sectors (-s will display information about scanning, -v more detailed mode):

badblocks -sv /dev/sda1

You can save the result to a file:

badblocks -sv /dev/sda1 > ~/badblocks.list

You may need to unmount the disk to check:

umount /dev/sda1

You can run the test using e2fsck like this:

e2fsck /dev/sda1

See also:
Description of SMART attributes
Diagnostics HDD using smartmontools

Installing and using iotop

iotop – a console program that displays statistics on the use of disk space.

You can install Debian, Ubuntu, Mint with the command:

sudo apt-get install iotop

In Red Hat, Fedora, CentOS:

yum install iotop

Normal startup:


Running with the option:

iotop OPTION

I’ll describe the possible startup options:
–version (view version)
-h (view help)
-o (display only active processes or threads that read or write, instead of displaying all)
-b (inclusion of non-interactive mode, convenient for example to output information to a file)
-t (display time in each line, for non-interactive mode -b)
-n NUMBER (the number of iterations after which the output will be executed, if not specified, then the output is not standardized)
-d NUMBER (the delay between iterations in seconds, you can specify not an integer, a standard value of 1)
-p PID (display statistics only for the specified processes / threads, standard for all)
-u USER (display statistics only for specified users, standard for all)
-P (display only processes)
-a (accumulation of statistics from the start of the launch of iotop)
-k (statistics in kilobytes)
-q (shortened view, some header lines are removed, when used with the -b option. There are more abbreviated, for example -qq without title names and -qqq without a general summary)

Using the acct utility

The acct utility allows you to see statistics of user activity in the system.

Installation in Ubuntu:

sudo apt-get install acct

Removed in Ubuntu with the following command:

sudo apt-get remove acct

Installation in Fedora:

su -c 'yum install psacct'

Running in Ubuntu:

/etc/init.d/acct start

Running in Fedora:

su -c 'service acct start'

I will list and describe several commands of the acct utility:
ac – statistics on the time spent by users in the system
ac -d (per day)
ac -y (in a year)
ac -p (individual statistics)
ac –version (display version of the utility)
man ac (help on the team)

sa – information about executed commands and running applications
sa -c (statistics in percent)
man sa (help on the command)

lastcomm – last executed commands
sudo accton on/off – on and off collection of information

Disabling ecryptfs encryption at home directory

It took one day to disable the ecryptfs encryption of the home directory, which was once set up when installing the system.

First of all, we make a copy of the home directory of the right user:

sudo cp -rp /home/user /home/user_backup

Get the mount point in the directory:

PRIVATE=`cat ~/.ecryptfs/Private.mnt 2>/dev/null || echo $HOME/Private`

Unmount the directory:


Install the rights to the directory:

chmod 750 $PRIVATE

Delete the directory and directories ~/.Private, ~/.ecryptfs:

rm -rf $PRIVATE ~/.Private ~/.ecryptfs

And also in the made copy:

rm -rf /home/user_backup/.Private /home/user_backup/.ecryptfs

If ecryptfs is no longer used in the system, then we will delete the utilities:

sudo apt-get remove ecryptfs-utils libecryptfs0

Install the right user directory:

sudo chmod 750 /home/user
sudo chown user:user -R /home/user

Copy the necessary files from the backup copy of the home directory.


You can see the built-in statement with the command:

ecryptfs-setup-private --undo

See also:
The solution to the error “Could not chdir to home directory /home/user: Permission denied”

The solution to the error “Could not chdir to home directory /home/user: Permission denied”

Moved once the system to another disk and when connected via SSH saw the following errors:

Could not chdir to home directory /home/user: Permission denied
-bash: /home/user/.bash_profile: Access denied

As it turned out, the errors were caused by incorrect permissions to the /home directory, namely, there were no rights to execute from the group and other users.

To solve the problem, first see what rights are installed on the home directory (must be drwxr-xr-x):

ls -l /
ls -l /home

We will expose the correct:

sudo chmod +x /home

If necessary, we set permissions for the directory of the user you want:

sudo chmod 750 /home/user
sudo chown user:user /home/user

Done, in my case the error has disappeared.