📜 ⬆️ ⬇️

Web interface for listening to call recordings Asterisk


Search engines give a huge amount of results of different usefulness to the request made in the title.
I did not find such an article on Habrahabr, which means you need to write it!
I took the asterisk cdr viewer project as a basis.
Translated the language of the web interface to the great mighty and “voiced” it, i.e. added the ability to listen to the recordings of conversations in the browser, as well as download them.
The number of filter fields is reduced to a minimum, leaving only the most necessary.
Screenshots, samples and a detailed description of the installation are comfortably located under the screen.

UPDATE_2016
Ready new interface.
A small video guide:

Read more here.


Web interface screenshots

The logo and link to donat developers remained in their places.
All fields are translated, if you need to display any field as in the original, just uncomment it in templates / form.tpl.php

')
And this is the result of the search by filter.
Each conversation can be downloaded, or listen through the flash player.


Cooking MySQL

The CDRs of our Asterisk should be written to the MySQL database, how to set it up can be read here for example;).
At the end of the cdr_mysql.conf file, in the [columns] section, add
alias realdst => realdst alias filename => filename 

The name of the conversation recording file is written in the file field of the CDR table.
Add it:
 mysql -uroot -p -e "alter table `cdr` add column `filename` varchar(120) after `userfield`;" asterisk 


Dialplan

To configure Asterisk dialplan, I use extensions.ael.
extensions.ael
 globals { WAV=/records/wav; //   WAV MP3=/records/mp3; //  mp3  RECORDING=1; // , 1 - . }; macro recording (calling,called) { if ("${RECORDING}" = "1"){ Set(fname=${UNIQUEID}-${STRFTIME(${EPOCH},,%Y-%m-%d-%H_%M)}-${calling}-${called}); Set(monopt=nice -n 19 /usr/bin/lame -b 32 --silent "${WAV}/${fname}.wav" "${MP3}/${fname}.mp3" && rm -f "${WAV}/${fname}.wav" && chmod o+r "${MP3}/${fname}.mp3"); Set(CDR(filename)=${fname}.mp3); Set(CDR(realdst)=${called}); MixMonitor(${WAV}/${fname}.wav,b,${monopt}); }; }; _XXXXXX => { &recording(${CALLERID(number)},${EXTEN}); Dial(SIP/rtk/${EXTEN}); Hangup(); } 


Global variables define the paths to the files, as well as allow you to turn on / off the recording of the conversation.
The recording macro accepts the caller's number and the number where the call is made as parameters. If the recording is enabled, a temporary wav file is written, recoded into mp3, and in MySQL the name of the CDR drops the name of the file.
The file name consists of the uniqueid-date_time-FromChodCall-ToCall, for example:
 1392597899.17572-2014-02-17-07_44-83843ZZZ-32ZZ.mp3 

The current day mp3 files are added to / records / mp3 /
Every night, the script in the crown distributes the recordings of conversations in the appropriate date folders
 1 0 * * * /root/sh/mvrecords.sh 

 #!/bin/bash PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin y=`date +%Y -d "-1 day"` ym=`date +%Y-%m -d "-1 day"` ymd=`date +%Y-%m-%d -d "-1 day"` mkdir -p /records/$y/$ym/$ymd/ mv /records/mp3/*$ymd* /records/mp3/$y/$ym/$ymd/ 


In the folder where the web interface files are located, you need to create a symlink to the folder / records / mp3 /
 /var/www# ls -l total 60 -rw-r--r-- 1 fessae fessae 182 Nov 19 2011 callrates.csv drwxr-xr-x 3 fessae fessae 4096 Sep 26 2012 contrib -rw-r--r-- 1 fessae fessae 1986 Dec 22 2012 download.php -rw-r--r-- 1 fessae fessae 246 Sep 6 2013 downloads.php drwxr-xr-x 4 fessae fessae 4096 Apr 15 20:48 include -rw-r--r-- 1 fessae fessae 30384 Dec 2 20:21 index.php lrwxrwxrwx 1 root root 13 Apr 15 20:48 records -> /records/mp3/ drwxr-xr-x 2 fessae fessae 4096 Feb 13 2013 style drwxr-xr-x 3 fessae fessae 4096 Feb 18 21:07 templates 

Screenshots of the folder structure.




Php

In the file include / functions.php spelled out the logic of the output buttons "download the file with the conversation" and flash player in the field "File".
part include / functions.php
  $recorded_file = $row['filename']; $mycalldate = substr("$calldate",0,10); $mycalldate_ym = substr("$calldate",0,7); $mydate = date("Ymd"); if ($mycalldate<$mydate){ if (file_exists("records/$mycalldate_ym/$mycalldate/$recorded_file")) { echo " <td class=\"record_col\"><a href=\"downloads.php?audio=records/$mycalldate_ym/$mycalldate/$recorded_file\" title=\"   \"><img src=\"templates/images/sound.png\"</a> <object type=\"application/x-shockwave-flash\" data=\"include/player_mp3_maxi.swf\" width=\"150\" height=\"20\"> <param movie=include/player_mp3_maxi.swf/> <param name=FlashVars value=mp3=records/$mycalldate_ym/$mycalldate/$recorded_file /> </td>\n"; } else {echo " <td class=\"record_col\"> </td>\n"; } } else { if (file_exists("records/$recorded_file")) { echo " <td class=\"record_col\"><a href=\"downloads.php?audio=records/$recorded_file\" title=\"   \"><img src=\"templates/images/sound.png\"</a> <object type=\"application/x-shockwave-flash\" data=\"include/player_mp3_maxi.swf\" width=\"150\" height=\"20\"> <param movie=include/player_mp3_maxi.swf/> <param name=FlashVars value=mp3=records/$recorded_file /> </td>\n"; } else {echo " <td class=\"record_col\"> </td>\n";} } } 


In this code, it is determined in which folder to search for the conversation recording file.
For the current day we search in / records / mp3, and for previous in / records / mp3 / YEAR-MONTH / YEAR-MONTH-DAY /
If the file was not found, we will see "no record" in the "File" field.

Just do not forget to specify the connection details to MySQL in include/config.inc.php

A curtain

That's all!
I would be glad if my work will be useful.

ps
Sorts are available at links 1 and 2

UPD
If there is no account on Habré, I can help on the forum - sysadminz.ru/index.php?topic=6592.0
UPD 2
A small glitch was found, if the recording in any direction is disabled (that is, the file is not being written and the filename field is not filled in the database), then the flash player is still displayed as if the file is there.
To correct it, you need to make changes to the CDR table, set the default value for the filename field:
 mysql -p mysql> alter table cdr alter filename set default 'none'; mysql> describe cdr; +-------------+-----------------+------+-----+---------------------+----------------+ | Field | Type | Null | Key | Default | Extra | +-------------+-----------------+------+-----+---------------------+----------------+ | id | int(9) unsigned | NO | PRI | NULL | auto_increment | | calldate | datetime | NO | MUL | 0000-00-00 00:00:00 | | | clid | varchar(80) | NO | | | | | src | varchar(80) | NO | MUL | | | | dst | varchar(80) | NO | MUL | | | | dcontext | varchar(80) | NO | | | | | channel | varchar(80) | NO | | | | | dstchannel | varchar(80) | NO | | | | | lastapp | varchar(80) | NO | | | | | lastdata | varchar(80) | NO | | | | | duration | int(11) | NO | | 0 | | | billsec | int(11) | NO | | 0 | | | disposition | varchar(45) | NO | | | | | amaflags | int(11) | NO | | 0 | | | accountcode | varchar(20) | NO | MUL | | | | uniqueid | varchar(32) | NO | MUL | | | | userfield | varchar(255) | NO | | | | | filename | varchar(120) | YES | | none | | +-------------+-----------------+------+-----+---------------------+----------------+ 18 rows in set (0.00 sec) mysql> \q Bye 

UPD 3 (from the post header)
Comrade profiton (aka prog-it) essentially finished the topic.
Screenshots:
image
image
image
image

Features:
Key Features
Fully Russian interface
Updated design
Tooltips
Correct export of records to a CSV file
The correct calculation of the cost of calls (plugin)
View the cost of each call (plugin)
The ability to specify a non-chargeable interval for the correct calculation of the cost
Ability to specify additional. rate. For example: The cost of the first minute is 1 rub., Then 10 kopecks each. (extra rate)
The file name of the call record is stored in the database
Ability to listen to the recording of the call through the web interface
You can click on the phone number and get information about it.
The player to listen to the call is loaded via javascript, so nothing slows down
If call records are archived, you will be prompted to download a record.
If you receive a fax, you can also download it.
Files for download are given by the script with the ability to resume
The folder for storing records can be located in any directory of your server.
And much more ...


Link - prog-it.imtqy.com/Asterisk-CDR-Viewer-Mod

Source: https://habr.com/ru/post/212815/


All Articles