Exemplo n.º 1
0
 /**
  * Executa a ação.
  * @param Asterisk_AGI $asterisk
  * @param Asterisk_AGI_Request $request
  */
 public function execute($asterisk, $request)
 {
     $log = Zend_Registry::get('log');
     try {
         if (!$this->ramal instanceof Snep_Exten) {
             $ramal = PBX_Usuarios::get($request->destino);
         } else {
             $ramal = $this->ramal;
         }
     } catch (PBX_Exception_NotFound $ex) {
         $log->info($ex->getMessage());
         return;
     }
     if ($ramal->isDNDActive()) {
         $log->info("Extension {$ramal} have do not disturb enabled.");
     } else {
         if ($ramal->getFollowMe() != null) {
             $log->info("Follow-me, trying to find: " . $ramal->getFollowMe());
             $fake_request = $asterisk->request;
             $fake_request['agi_callerid'] = $ramal->getNumero();
             $fake_request['agi_extension'] = $ramal->getFollowMe();
             $request = new PBX_Asterisk_AGI_Request($fake_request);
             $dialplan = new PBX_Dialplan();
             $dialplan->setRequest($request);
             $dialplan->parse();
             $regra = $dialplan->getLastRule();
             $original_request = $asterisk->requestObj;
             $asterisk->requestObj = $request;
             $regra->setAsteriskInterface($asterisk);
             $regra->execute();
             $asterisk->requestObj = $original_request;
             $dialstatus = $asterisk->get_variable("DIALSTATUS");
             $log->debug("DIALSTATUS: " . $dialstatus['data']);
             switch ($dialstatus['data']) {
                 case 'ANSWER':
                 case 'CANCEL':
                     throw new PBX_Rule_Action_Exception_StopExecution("End of call detected");
                     break;
                 case 'CHANUNAVAIL':
                     $log->warn($dialstatus['data'] . " dialing to extension {$ramal}");
             }
         } else {
             $canal = $ramal->getInterface()->getCanal();
             if ($this->diff_ring) {
                 if ($ramal->getInterface()->getTech() == "SIP") {
                     $asterisk->exec('SIPAddHeader', 'Alert-Info: Bellcore-r3');
                 } else {
                     if ($ramal->getInterface()->getTech() == "KHOMP") {
                         $canal .= "/ring=400.200:ring_ext=400.2000";
                     }
                 }
             }
             if ($ramal->getPickupGroup() != null) {
                 $asterisk->set_variable('__PICKUPMARK', $ramal->getPickupGroup());
             }
             $log->info("Discando para ramal {$ramal} no canal {$canal}.");
             $asterisk->exec_dial($canal, $this->dial_timeout, $this->dial_flags);
             $dialstatus = $asterisk->get_variable("DIALSTATUS");
             $log->debug("DIALSTATUS: " . $dialstatus['data']);
             if ($dialstatus['data'] != "ANSWER" && $dialstatus['data'] != "CANCEL" && $this->allow_voicemail && $ramal->hasVoiceMail()) {
                 $log->info("Executing voicemail to extension {$ramal} due to {$dialstatus['data']}");
                 $vm_params = array($ramal->getMailBox(), "u");
                 $asterisk->exec('voicemail', $vm_params);
                 throw new PBX_Rule_Action_Exception_StopExecution("End of call");
             }
             switch ($dialstatus['data']) {
                 case 'ANSWER':
                 case 'CANCEL':
                     throw new PBX_Rule_Action_Exception_StopExecution("End of call");
                     break;
                 case 'NOANSWER':
                 case 'BUSY':
                     if ($this->dont_overflow) {
                         throw new PBX_Rule_Action_Exception_StopExecution("End of call");
                     }
                     break;
                 default:
                     $log->err($dialstatus['data'] . " ao discar para {$request->destino}");
             }
         }
     }
 }
Exemplo n.º 2
0
}
if ($opts->xfer) {
    $asterisk->request['agi_channel'] = $opts->xfer;
    $request = new PBX_Asterisk_AGI_Request($asterisk->request);
    $asterisk->requestObj = $request;
}
if ($opts->outgoing_number) {
    Zend_Registry::set("outgoingNumber", $opts->outgoing_number);
} else {
    Zend_Registry::set("outgoingNumber", "");
}
$log = Zend_Registry::get('log');
$request = $asterisk->requestObj;
$log->info("Call from {$request->origem} ({$request->channel}) to {$request->destino}");
try {
    $dialplan = new PBX_Dialplan();
    $dialplan->setRequest($asterisk->requestObj);
    $dialplan->parse();
    $regra = $dialplan->getLastRule();
} catch (PBX_Exception_NotFound $ex) {
    $log->info("No valid rule for this request: " . $ex->getMessage());
    if (!$opts->xfer) {
        $asterisk->answer();
        $asterisk->stream_file('invalid');
        $asterisk->hangup();
    }
    exit;
} catch (Exception $ex) {
    $log->crit("Oops! Exception resolving routing rule.");
    $log->crit($ex);
    die;