TUTORIAL FOP2-managed Call Recordings

Noxee

New Member
Joined
Oct 20, 2016
Messages
6
Reaction score
1
I have a client with particular call recording needs that I've been trying to meet for quite some time now.
They wanted their calls to be automatically recorded (easily done through Incredible PBX GUI) but also wanted employees to be able to search through their recorded calls and download them (easily done through UCP). The problem was, they also wanted to be able to delete individual call recordings. I couldn't find a way to do this other than by configuring a chronjob that deleted calls every x amount of days. They wanted something more user friendly.

They use FOP2 which provides an easy way to record calls, listen to, download and delete them. Unfortunately, it doesn't allow for automatic call recording.

What I've done, with some much appreciated guidance from Nicolás Gudiño (creator of FOP2), is written a post recording script that allows users to manage (listen, download and delete) their recordings from the FOP2 GUI.

Here's how:

For starters, I created a file in /var/lib/asterisk/bin/ and called it postrecording.sh. This file needs proper permissions to function chmod 755 postrecording.sh.

The script:

#!/bin/bash

#Post recording

mysql -u username -ppassword <<EOF

use mysql

####VARIABLES

SET @path := (SELECT DATE_FORMAT(CURDATE(),'/var/spool/asterisk/monitor/%Y/%m/%d/'));

####MAIN

INSERT IGNORE INTO asterisk.fop2recordings
(uniqueid, datetime, ownerextension, targetextension, filename, duration, context)
SELECT uniqueid, calldate, cnum, dst, CONCAT(@path,recordingfile), duration, dcontext
FROM asteriskcdrdb.cdr
WHERE recordingfile LIKE '%wav%'
ORDER BY calldate DESC
LIMIT 10
EOF

What it does:


When FreePBX finishes a recording, it is stored in a mysql table asteriskcdrdb.cdr.
The script takes certain important values and writes them to FOP2's recording table asterisk.fop2recordings.
The @path variable allows us to save the recorded file as /var/spool/asterisk/monitor/year/day/filename.wav in asterisk.fop2recordings. This is important because without the path, you can't listen to or download the recordings.

If you want to see recordings of incoming calls and not just outbound calls, there are a few extra needed steps.
You'll need to modify:
/var/www/html/fop2/recordings.php
If you scroll down, you'll get to a section that starts with // Sanitize Input. A little bit further, you'll find this line:
$grid->set_condition("(ownerextension='$extension' OR $admin=1)");
change it to:
$grid->set_condition("(ownerextension='$extension' OR $admin=1 OR targetextension='$extension')");

One last step is needed. For the script to be automatically run after recorded calls are completed, you need to go to settings, advanced settings, in the Incredible PBX GUI. Change Display Readonly Settings and Override Readonly Settings to true and click apply. Next insert /var/lib/asterisk/bin/postrecording.sh under the Post Call Recording Script section.

There you have it, an easy way for users to retrieve and delete their calls through FOP2.

*NOTE
Default Incredible PBX credentials for MYSQL are
username: root
password: passw0rd

If you see any weaknesses in my script please let me know. This is my first time writing a script.
 
Last edited:

Noxee

New Member
Joined
Oct 20, 2016
Messages
6
Reaction score
1
I made some modifications to the program.

Users weren't able to listen to their recordings this week and I found out that the script names the recording path incorrectly. Instead of /var/spool/asterisk/monitor/2016/11/01/ it was looking in /var/spool/asterisk/monitor/2016/11/1/ . The new code is much simpler.

#!/bin/bash

#Post recording

mysql -u username -ppassword <<EOF

use mysql

####VARIABLES

SET @path := (SELECT DATE_FORMAT(CURDATE(),'/var/spool/asterisk/monitor/%Y/%m/%d/'));

####MAIN

INSERT IGNORE INTO asterisk.fop2recordings
(uniqueid, datetime, ownerextension, targetextension, filename, duration, context)
SELECT uniqueid, calldate, cnum, dst, CONCAT(@path,recordingfile), duration, dcontext
FROM asteriskcdrdb.cdr
WHERE recordingfile LIKE '%wav%'
ORDER BY calldate DESC
LIMIT 10;

EOF

Also, I realized that users could only listen to and download outgoing calls, not incoming calls. To fix this, I made a modification to


/var/www/html/fop2/recordings.php

If you scroll down, you'll get to a section that starts with // Sanitize Input. A little bit further, you'll find this line:
$grid->set_condition("(ownerextension='$extension' OR $admin=1)");
change it to:
$grid->set_condition("(ownerextension='$extension' OR $admin=1 OR targetextension='$extension')");

Enjoy!
 
Get 3CX - Absolutely Free!

Link up your team and customers Phone System Live Chat Video Conferencing

Hosted or Self-managed. Up to 10 users free forever. No credit card. Try risk free.

3CX
A 3CX Account with that email already exists. You will be redirected to the Customer Portal to sign in or reset your password if you've forgotten it.
Top