Ticket #2966: recordingcheck.diff

File recordingcheck.diff, 12.7 kB (added by errr, 3 months ago)
  • recordingcheck

    old new  
    2020/* --------WARNING--------- 
    2121 *  
    2222 * This script is auto-copied from an included module and will get overwritten. 
    23  * If you modify it, you must change it to write only, in the agi-bin directory, 
     23 * If you modify it, you must change it to read only, in the agi-bin directory, 
    2424 * to keep it from getting changed. 
    2525 */ 
    2626 
     27/** 
     28 * Major changes made to this script on 2008-08-20 
     29 * By: Michael Rice aka errr michael@michaelrice.org 
     30 */ 
    2731 
    2832include("phpagi.php"); 
    29  
    30  
    31 /**********************************************************************************************************************/ 
    32  
    3333$agi = new AGI(); 
    34  
     34// Asterisk generated time stamp: ${STRFTIME(${EPOCH},,%Y%m%d-%H%M%S)} 
    3535$timestamp = $argv[1]; 
     36// Chan variable from asterisk: ${UNIQUEID} 
    3637$uniqueid = $argv[2]; 
     38// Set to TRUE for more verbose output 
     39$debug = FALSE; 
     40/** 
     41 * $type String value 
     42 * When called from [ext-grop] value will be Group 
     43 * When calling from exten -> exten it will be IN and only for the exten 
     44 * being called 100 calls 101 it will be IN for 101 
     45 * The only time it is OUT is if you are dialing an outside line 
     46 */ 
    3747$type = $agi->get_variable("ARG2"); 
    3848 
    39 switch($type['data']) { 
    40         case "Group": 
    41          
    42                 $r = $agi->get_variable("ARG1"); 
    43                 if ($r["result"] == 0) { 
    44                         $agi->verbose("Extension List not set -- nothing to do"); 
    45                         exit(1); 
    46                 } 
    47                 $extenlist = $r["data"]; 
    48                  
    49                 $agi->set_variable("RecEnable", "DISABLED"); //disable by default 
    50                  
    51                 $list = explode("-",$extenlist); 
    52                 if(!empty($list)) { 
    53                         foreach($list as $exten) { 
    54                                 $setting = $agi->database_get("AMPUSER",$exten."/recording"); 
    55                                 if ($setting["result"] == 0) { 
    56                                         $agi->verbose("No DB Entry AMPUSER/$exten/recording - Not Recording for $exten, checking for others"); 
    57                                         continue; 
    58                                 } 
    59                                 //explode recording vars 
    60                                 $recording = explode("|",$setting["data"]); 
    61                                 $recout = substr($recording[0],4); 
    62                                 $recin = substr($recording[1],3); 
    63                                 if ($recin == "Always") { 
    64                                         $agi->verbose("Recording enable for ".$exten); 
    65                                         $agi->verbose("CALLFILENAME=g{$exten}-{$timestamp}-{$uniqueid}"); 
    66                                         $agi->set_variable("CALLFILENAME","g{$exten}-{$timestamp}-{$uniqueid}"); 
    67                                         $agi->set_priority(999); 
    68                                         exit(0); 
    69                                 } 
    70                         } 
    71                 } else { 
    72                         $agi->verbose("Extension List is empty -- nothing to do"); 
    73                         exit(1);                 
    74                 } 
    75          
    76         break; 
    77         case "OUT": 
    78                 $exten = $agi->get_variable("ARG1"); 
    79                  
    80                 $options = $agi->database_get("AMPUSER","{$exten['data']}/recording"); 
    81                  
    82                 if ($options["result"] == "0") { 
    83                         $agi->verbose("No AMPUSER db entry for ".$exten["data"].". Not recording"); 
    84                         exit(1);                 
    85                 } 
    86  
    87                 //explode recording vars 
    88                 $recording = explode("|",$options["data"]); 
    89                 $recout = substr($recording[0],4); 
    90                 $recin = substr($recording[1],3); 
    91          
    92                 if($recout == "Always") { 
    93                         $agi->verbose("Outbound recording enabled."); 
    94                         $agi->verbose("CALLFILENAME=OUT{$exten['data']}-{$timestamp}-{$uniqueid}"); 
    95                         $agi->set_variable("CALLFILENAME","OUT{$exten['data']}-{$timestamp}-{$uniqueid}"); 
    96                         $agi->set_priority(999); 
    97                         exit(0); 
    98                 } else { 
    99                         $agi->verbose("Outbound recording not enabled"); 
    100                         exit(1);                 
    101                 } 
    102         break; 
    103         case "IN": 
    104                 $exten = $agi->get_variable("ARG1");     
    105                 $options = $agi->database_get("AMPUSER","{$exten['data']}/recording"); 
    106                  
    107                 if ($options["result"] == "0") { 
    108                         $agi->verbose("No AMPUSER db entry for ".$exten["data"].". Not recording"); 
    109                         exit(1);                 
    110                 } 
    111                 //explode recording vars 
    112                 $recording = explode("|",$options["data"]); 
    113                 $recout = substr($recording[0],4); 
    114                 $recin = substr($recording[1],3); 
    115                  
    116                 if($recin == "Always")  { 
    117                         $agi->verbose("Inbound recording enabled."); 
    118                         $agi->verbose("CALLFILENAME={$timestamp}-{$uniqueid}"); 
    119                         $agi->set_variable("CALLFILENAME","{$timestamp}-{$uniqueid}"); 
    120                         $agi->set_priority(999); 
    121                         exit(0);         
    122                 } else { 
    123                         $agi->verbose("Inbound recording not enabled"); 
    124                         exit(1);                 
    125                 } 
    126         break; 
     49// Should note that $agi->get_variable("ARG1"); is ${AMPUSER} 
     50// unless recordmethod = Group in which case it will be ${DB(AMPUSER/7001/followme/grplist)} 
     51// which will be a list dash seperated: 100-101-102-110  
     52 
     53/** 
     54 * Set the filename for outbound recordings 
     55 * @param object $agicon Connection to AGI 
     56 * @param string $exten Extension of who is making call 
     57 * @param string $ts Asterisk generated time stamp: ${STRFTIME(${EPOCH},,%Y%m%d-%H%M%S)} 
     58 * @param string $uid Chan variable from asterisk: ${UNIQUEID} 
     59 */ 
     60function setOutFileName($agicon,$exten,$ts,$uid) { 
     61    $agicon->verbose("Outbound recording enabled. for {$exten}"); 
     62    $agicon->verbose("CALLFILENAMEOUT=OUT{$exten}-{$ts}-{$uid}"); 
     63    $agicon->set_variable("CALLFILENAMEOUT","OUT{$exten}-{$ts}-{$uid}"); 
     64    return; 
     65
     66 /** 
     67  * Set the filename for outbound recordings 
     68  * @param object $agicon Connection to AGI 
     69  * @param string $exten Extension of who is making call 
     70  * @param string $ts Asterisk generated time stamp: ${STRFTIME(${EPOCH},,%Y%m%d-%H%M%S)} 
     71  * @param string $uid Chan variable from asterisk: ${UNIQUEID} 
     72  */ 
     73function setInFileName($agicon,$exten,$ts,$uid) { 
     74    $agicon->verbose("Inbound recording enabled for {$exten}"); 
     75    $agicon->verbose("CALLFILENAMEIN=IN{$exten}-{$ts}-{$uid}"); 
     76    $agicon->set_variable("CALLFILENAMEIN","IN{$exten}-{$ts}-{$uid}"); 
     77    return; 
    12778} 
    12879 
     80/** 
     81 * Check status of recording for extension 
     82 * @param object $agicon Connection to AGI 
     83 * @param string $ext Extension of who to check 
     84 */ 
     85function recordEnabled($agicon,$ext) { 
     86    $recSetting = $agicon->database_get("AMPUSER",$ext."/recording"); 
     87    if ($recSetting["result"] == 0) { 
     88        return false; 
     89    } 
     90    $recSetting = splitRecData($agicon,$ext); 
     91    if($recSetting['in'] == "Always" || $recSetting['out'] == "Always" ) { 
     92        return true; 
     93    } 
     94    else { 
     95        return false; 
     96    } 
     97} 
     98 
     99/** 
     100 * Fetch the recording setting for extension 
     101 * Split data and return as an array 
     102 * @param object $agicon Connection to AGI  
     103 * @param string $ext Exten to look up data for 
     104 * @return array, ['in'] holds value for incoming call setting ['out'] holds outgoing info 
     105 */ 
     106function splitRecData($agicon,$ext) { 
     107    $options = $agicon->database_get("AMPUSER",$ext."/recording"); 
     108    $recording = explode("|",$options["data"]); 
     109    $rec['out'] = substr($recording[0],4); 
     110    $rec['in']  = substr($recording[1],3); 
     111    return $rec; 
     112} 
     113 
     114switch($type['data']) { 
     115    case "Group": 
     116        $r = $agi->get_variable("ARG1"); 
     117        if ($r["result"] == 0) { 
     118            $agi->verbose("Extension List not set -- nothing to do"); 
     119            exit(1); 
     120        } 
     121        $extenlist = $r["data"]; 
     122        $list = explode("-",$extenlist); 
     123        if(!empty($list)) { 
     124            foreach($list as $exten) { 
     125                $setting = $agi->database_get("AMPUSER",$exten."/recording"); 
     126                if(!recordEnabled($agi,$exten)) { 
     127                    $agi->verbose("No DB Entry AMPUSER/$exten/recording - Not Recording for $exten, checking for others"); 
     128                    continue; 
     129                } 
     130                $rec = splitRecData($agi,$exten); 
     131                if ($rec['in'] == "Always") { 
     132                    $agi->verbose("Recording enable for ".$exten); 
     133                    $agi->verbose("CALLFILENAMEIN=g{$exten}-{$timestamp}-{$uniqueid}"); 
     134                    $agi->set_variable("CALLFILENAMEIN","g{$exten}-{$timestamp}-{$uniqueid}"); 
     135                    $agi->set_priority(999); 
     136                    exit(0); 
     137                } 
     138            } 
     139        }  
     140        else { 
     141            $agi->verbose("Extension List is empty -- nothing to do"); 
     142            exit(1);             
     143        } 
     144    break; 
     145    // this is only used if its an outbound call not out via exten to exten 
     146    case "OUT": 
     147        $exten = $agi->get_variable("ARG1"); 
     148        $exten = $exten['data']; 
     149        if(!recordEnabled($agi,$exten)) { 
     150            $agi->verbose("No AMPUSER db entry for ".$exten.". Not recording"); 
     151            exit(1);             
     152        } 
     153        $rec = splitRecData($agi,$exten); 
     154        if($rec['out'] == "Always") { 
     155            setOutFileName($agi,$exten,$timestamp,$uniqueid); 
     156            $agi->set_priority(555); 
     157            exit(0); 
     158        }  
     159        else { 
     160            $agi->verbose("Outbound recording not enabled for {$exten}"); 
     161            exit(1); 
     162        } 
     163    break; 
     164     
     165    case "IN": 
     166        $exten = $agi->get_variable("ARG1");     
     167        $exten = $exten['data'];  
     168        // need to check if this is a local to local (internal) call 
     169        $callerNum = $agi->request['agi_callerid']; 
     170        $callerOpts = $agi->database_get("AMPUSER","{$callerNum}/recording"); 
     171        $calledOptions = $agi->database_get("AMPUSER","{$exten}/recording"); 
     172        // must check recording status of callerid incase local, and set file names 
     173        // before moving on to checking exten incase they dont have it enabled 
     174        // then no recording will happen 
     175        if($debug) { 
     176            $agi->verbose("IN, testing inbound: {$exten} and who called: {$callerNum} for recording settings"); 
     177            //$agi->verbose(" ".print_r($callerOpts)." "); 
     178            $agi->verbose("callerOpts: {$callerOpts['data']}"); 
     179        } 
     180        // here we wanna test if the caller needs a file if not skip on 
     181        // this only runs if its internal calls not from the outside 
     182        // as the caller would not have settings unless their callerid num 
     183        // matches an extension. 
     184        if(recordEnabled($agi,$callerNum)) { 
     185            if($debug) { 
     186                $agi->verbose("results: {$callerOpts['data']}"); 
     187            } 
     188            // Person making call 
     189            $callerRecOpts = splitRecData($agi,$callerNum); 
     190            // Person recieving call 
     191            $calledRecOpts = splitRecData( $agi,$exten ); 
     192            if($debug) { 
     193                $agi->verbose("Checking what caller: {$callerRecOpts['out']} && called: {$calledRecOpts['in']} equal"); 
     194            } 
     195            // here we have an internal call where both parties should get a copy of this recording 
     196            // *working* 
     197            if($callerRecOpts['out'] == "Always" && $calledRecOpts['in'] == "Always" ) { 
     198                setOutFileName($agi,$callerNum,$timestamp,$uniqueid); 
     199                setInFileName($agi,$exten,$timestamp,$uniqueid);  
     200                $agi->set_priority(555); 
     201                exit(0); 
     202            } 
     203            // here we have internal call where caller wants a recording but callee doesnt care 
     204            // *working* 
     205            if($callerRecOpts['out'] == "Always" && $calledRecOpts['in'] == "Adhoc" ) { 
     206                setOutFileName($agi,$callerNum,$timestamp,$uniqueid); 
     207                $agi->verbose("Inbound recording not enabled for {$exten}"); 
     208                $agi->set_priority(555); 
     209                exit(0); 
     210            } 
     211            /* 
     212              Im not sure how to handle this right now because even if its set to Never 
     213              for the incoming caller I can hit *1 and do it auto 
     214            // here we have internal call where caller wants recording but callee does not 
     215            // want the call recorded, and the admin has not set up an override allowing 
     216            // callers setting to over ride 
     217            if($callerRecOpts['out'] == "Always" && $calledRecOpts['in'] == "Never") { 
     218                $agi->verbose("Caller wants a file but callee doesnt want the call being recorded"); 
     219                $agi->verbose("For this file to be recorded the admin will have to allow it"); 
     220                exit(0); 
     221            } 
     222             */ 
     223 
     224            /** 
     225             * @todo Need to finish this and make it work  
     226             * // here caller wants it, callee dosent, admin says caller is recording this call 
     227             * if($outrecout == "Always" && $recin == "Never" && $adminOverRideIn == "1") { 
     228             * } 
     229             */ 
     230            if($debug) { 
     231               $agi->verbose("Out of things to test, Im outtie!!"); 
     232            }                 
     233        } 
     234        if($debug) { 
     235            $agi->verbose("Nothing for internal exten to exten where caller wants recording"); 
     236            $agi->verbose("Moving on to testing {$exten}"); 
     237        } 
     238        if(!recordEnabled($agi,$exten)) { 
     239            if($debug) { 
     240                $agi->verbose("No soup for you!!"); 
     241            } 
     242            $agi->verbose("No AMPUSER db entry for ".$exten.". Not recording"); 
     243            exit(1);             
     244        }   
     245        // incoming call from outside 
     246        $rec = splitRecData($agi,$exten); 
     247        if($rec['in'] == "Always")  { 
     248            setInFileName($agi,$exten,$timestamp,$uniqueid); 
     249            $agi->set_priority(999); 
     250            exit(0); 
     251        } 
     252        else { 
     253            $agi->verbose("Inbound recording not enabled"); 
     254            exit(1);             
     255        } 
     256    break; 
     257} 
    129258// we just exit with no changes to the variable. 
    130259exit(1); 
    131  
    132260?> 
Donate



Support
Download
Develop
Forums
News
Documentation
Paid Support
About

Paid Ads