📜 ⬆️ ⬇️

Asternic CDR Reports. Listening to calls in FreePBX with access restrictions

Software Versions


FreePBX 2.11.0.41
Asternic CDR Reports 1.5.1

Introduction


Task: it is necessary to give a person the opportunity to listen to recordings of conversations, but strictly on a certain range of internal extensions. We are trying to create a new administrator and even assign the Extension Range to it, hoping in this way to give him limited access to listening.


')
But then, going under the created account and going to the call reports, we understand that it was a fiasco - CDR Reports ignores the specified Extension Range and displays information on all numbers.

Scratching the back of the head, we are looking for an alternative module of reports - and, lo and behold, we find it: Asternic CDR Reports. It is wonderful and works only with those numbers whose range is limited for the authorized administrator.



But what is it? No listening to calls? Does the Listen column show voice mail? No, that won't do ...

Fix


Information on calls to Asterisk is stored in Mysql in the “asteriskcdrdb” database, table cdr. This is evident from the following code taken from the page.cdr.php file of the regular CDR Reports

$resultscdr = $dbcdr->getAll($query, DB_FETCHMODE_ASSOC); ... foreach($resultscdr as $row) ...       if ($row['recordingfile']) {          $rec_parts = explode('-',$row['recordingfile']);          $fyear = substr($rec_parts[3],0,4);          $fmonth = substr($rec_parts[3],4,2);          $fday = substr($rec_parts[3],6,2);          $monitor_base = $amp_conf['MIXMON_DIR'] ? $amp_conf['MIXMON_DIR'] : $amp_conf['ASTSPOOLDIR'] . '/monitor';          $recordingfile = "$monitor_base/$fyear/$fmonth/$fday/" . $row['recordingfile'];          if (!file_exists($recordingfile)) {             $recordingfile = '';          }       } else {          $recordingfile = '';       } 

So, all we need is to read the value of the recordingfile cell where the string “filename.wav” is stored and add the full path to this file to it, which is taken, by the way, from the very name of the file (year, month, day).

Open the file /var/www/html/admin/modules/asternic_cdr/functions.inc.php module Asternic.

Looking for line 154

 $query.= "billsec,duration,duration-billsec as ringtime,src,"; 

and replace with

 $query.= "billsec,duration,duration-billsec as ringtime,src,recordingfile,"; 

So in the query to the database, we added the field recordingfile, the value of which, respectively, will now be in the resulting array, from which we will take it later to form a link to the file.

Looking for line 208

 $detail[$row['chan1']].= "\n<td>"; $uni = $row['uniqueid']; $uni = str_replace(".","",$uni); if($row['userfield']<>"") { $detail[$row['chan1']].="<a href=\"javascript:void(0);\" onclick='javascript:playVmail(\"".$row['userfield']."\",\"play".$uni."\");'>"; $detail[$row['chan1']].="<div class='playicon' title='Play' id='play".$uni."' style='float:left;'>"; $detail[$row['chan1']].="<img src='images/blank.gif' alt='pixel' height='16' width='16' border='0'>"; $detail[$row['chan1']].="</div></a>"; $detail[$row['chan1']].="<a href=\"javascript:void(0); return false;\" onclick='javascript:downloadVmail(\"".$row['userfield']."\",\"play".$uni."\",\"$ftype\",\"$fdisplay\",\"$ftab\"); return false;'>"; $detail[$row['chan1']].="<div class='downicon' title='Download' id='dload".$uni."' style='float:left;'>"; $detail[$row['chan1']].="<img src='images/blank.gif' alt='pixel' height='16' width='16' border='0'>"; $detail[$row['chan1']].="</div></a>"; } else { $detail[$row['chan1']].= " "; } $detail[$row['chan1']].= "</td>\n"; 


replace with

 if ($row['recordingfile']) {         $rec_parts = explode('-',$row['recordingfile']);         $fyear = substr($rec_parts[3],0,4);         $fmonth = substr($rec_parts[3],4,2);         $fday = substr($rec_parts[3],6,2);         $monitor_base = $amp_conf['MIXMON_DIR'] ? $amp_conf['MIXMON_DIR'] : $amp_conf['ASTSPOOLDIR'] . '/monitor';         $recordingfile = "$monitor_base/$fyear/$fmonth/$fday/" . $row['recordingfile'];         if (!file_exists($recordingfile)) {            $recordingfile = '';            $detail[$row['chan1']].= "\n<td>";         }         else {         $detail[$row['chan1']].= "\n<td style='text-align: center;' title=\"$row[recordingfile]\"><a href=\"".$PHP_SELF."?getRec=".base64_encode($recordingfile)."\" target=\"_blank\"><img src=\"images/asternic_playicon.png\" alt=\"Call recording\" /></a>";         }      } else {         $recordingfile = '';         $detail[$row['chan1']].= "\n<td>";      }         $detail[$row['chan1']].= "</td>\n"; 

Thus, in the table cell, instead of outputting voice mail, we checked for the recording of this call and, if found, output a small Play icon with a link encoded in base64 to the audio recording file itself.



The attentive reader noticed that in the link being formed there is a GET request variable called getRec. Since the web server does not have access to the directory with audio recordings, we give the file via php, and for this at the end of the functions.inc.php file we check for the getRec variable, in the case of which we refer to the function giving the file

Add the code to the very end of the file, up to, of course, the closing php-tag "?>"

 function recordfile_uri($path) {   $size = filesize($path);   $name = basename($path);   $extension = strtolower(substr(strrchr($name,"."),1));   // This will set the Content-Type to the appropriate setting for the file   $ctype ='';   switch( $extension ) {      case "WAV":         $ctype="audio/x-wav";         break;      case "wav":         $ctype="audio/x-wav";         break;      case "ulaw":         $ctype="audio/basic";         break;      case "alaw":         $ctype="audio/x-alaw-basic";         break;      case "sln":         $ctype="audio/x-wav";         break;      case "gsm":         $ctype="audio/x-gsm";         break;      case "g729":         $ctype="audio/x-g729";         break;      default: //not downloadable         // echo ("<b>404 File not found! foo</b>");         // TODO: what to do if none of the above work?      break ;   } $fp=fopen($path, "rb"); if ($size && $ctype && $fp) {   header("Pragma: public");   header("Expires: 0");   header("Cache-Control: must-revalidate, post-check=0, pre-check=0");   header("Cache-Control: public");   header("Content-Description: audio file");   header("Content-Type: " . $ctype);   header("Content-Disposition: attachment; filename=" . $name);   header("Content-Transfer-Encoding: binary");   header("Content-length: " . $size);   $chunksize = 1*(1024*1024);   while (!feof($fp)) {       $buffer = fread($fp, $chunksize);       echo $buffer;       ob_flush();       flush();   }   fclose($fp); } } if(isset($_GET['getRec'])){   recordfile_uri(base64_decode($_GET['getRec']));   die(); } 


Done!


Everyone is happy and happy - because now you can easily download the recording of the conversation and listen to it locally in the audio player.

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


All Articles