예제 #1
0
파일: Request.php 프로젝트: rootzig/SNEP
 /**
  * Construtor da requisição.
  *
  * Para identificar o objeto de origem estamos considerando seu callerid
  * como número de ramal. Isso, obviamente, irá identificar somente ramais.
  * Importante ressaltar que a "falsidade ideológica" entre os canais é mais
  * fácil de ser praticada nesse sistema.
  *
  * @param int $origem
  * @param string $destino
  * @param string $contexto
  */
 public function __construct($agi_request)
 {
     parent::__construct($agi_request);
     $log = Snep_Logger::getInstance();
     // Descobrindo se esse canal criado pertence a alguma entidade
     // cadastrada no snep.
     $channel = $this->request['channel'];
     // removendo o hash de controle do asterisk
     // de TECH/ID-HASH para TECH/ID
     $channel = strpos($channel, '-') ? substr($channel, 0, strpos($channel, '-')) : $channel;
     $object = PBX_Interfaces::getChannelOwner($channel);
     if ($object instanceof Snep_Trunk && $object->allowExtensionMapping()) {
         try {
             $exten = PBX_Usuarios::get($this->origem);
             if ($exten->getInterface() instanceof PBX_Asterisk_Interface_VIRTUAL) {
                 $object = $exten;
             }
         } catch (PBX_Exception_NotFound $ex) {
             // Ignore
         }
     }
     $this->setSrcObj($object);
     if (is_object($object)) {
         $classname = get_class($this->getSrcObj());
         $log->info("Identified source: {$this->getSrcObj()} ({$classname})");
     }
 }
 /**
  * Executa a ação. É chamado dentro de uma instancia usando AGI.
  *
  * @param Asterisk_AGI $asterisk
  * @param Asterisk_AGI_Request $request
  */
 public function execute($asterisk, $request)
 {
     $log = Zend_Registry::get('log');
     $tronco = PBX_Trunks::get($this->config['tronco']);
     // Montando as Flags para limite na ligação
     $flags = $this->config['dial_flags'];
     if (isset($this->config['dial_limit']) && $this->config['dial_limit'] > 0) {
         $flags .= "L(" . $this->config['dial_limit'];
         // play_warning_value
         if (isset($this->defaultConfig['play_warning']) && $this->defaultConfig['play_warning'] > 0) {
             $flags .= ":" . $this->defaultConfig['play_warning'];
             // warning_freq
             if (isset($this->defaultConfig['warning_freq']) && $this->defaultConfig['warning_freq'] > 0) {
                 $flags .= ":" . $this->defaultConfig['warning_freq'];
             }
         }
         $flags .= ")";
         if (isset($this->defaultConfig['warning_sound'])) {
             $warning_sound = $this->defaultConfig['warning_sound'] != "" ? $this->defaultConfig['warning_sound'] : "beep";
             $asterisk->set_variable("LIMIT_WARNING_FILE", $warning_sound);
         }
     }
     if ($tronco->getDtmfDialMode()) {
         $dst_number = $tronco->getDtmfDialNumber();
         $flags .= "D({$request->destino})";
     } else {
         $dst_number = $request->destino;
     }
     if ($tronco->getInterface() instanceof PBX_Asterisk_Interface_SIP_NoAuth || $tronco->getInterface() instanceof PBX_Asterisk_Interface_IAX2_NoAuth) {
         $destiny = $tronco->getInterface()->getTech() . "/" . $dst_number . "@" . $tronco->getInterface()->getHost();
     } else {
         $postfix = isset($this->config['omit_kgsm']) && $this->config['omit_kgsm'] == "true" ? "/orig=restricted" : "";
         $destiny = $tronco->getInterface()->getCanal() . "/" . $dst_number . $postfix;
     }
     $flags .= "A({$this->config['announce']})";
     $log->info("Discando para {$request->destino} atraves do tronco {$tronco->getName()}({$destiny})");
     $dialstatus = $asterisk->get_variable("DIALSTATUS");
     $lastdialstatus = $dialstatus['data'];
     if (Zend_Registry::get('outgoingNumber') !== "") {
         $asterisk->set_variable("CALLERID(num)", Zend_Registry::get('outgoingNumber'));
     }
     $log->debug("Dial({$destiny}, {$this->config['dial_timeout']}, {$flags}");
     // ==== DIAL ====
     $asterisk->exec_dial($destiny, $this->config['dial_timeout'], $flags);
     $dialstatus = $asterisk->get_variable("DIALSTATUS");
     $log->debug("DIALSTATUS: " . $dialstatus['data']);
     // Enviar email de alerta.
     if (isset($this->config['alertEmail']) && $this->config['alertEmail'] != "") {
         $informations = array('Regra' => $this->getRule(), 'Hora da chamada' => date('H:i'), 'Data da chamada' => date('d/m/Y'), 'Origem Original' => $request->getOriginalCallerid(), 'Destino original' => $request->getOriginalExtension(), 'Origem' => $request->origem, 'Destino' => $request->destino, 'Status da Ligação' => $dialstatus['data']);
         if ($lastdialstatus != "") {
             $lastdialaction = null;
             foreach ($this->getRule()->getAcoes() as $action) {
                 if ($action == $this) {
                     break;
                 }
                 $cfg = $action->getConfigArray();
                 if ($action instanceof FaxOutAction) {
                     $lastdialaction = PBX_Trunks::get($cfg['tronco']);
                 } else {
                     if ($action instanceof PBX_Rule_Action_DiscarRamal) {
                         $lastdialaction = $cfg['ramal'];
                     }
                 }
             }
             $informations["\nHouve uma tentativa de ligação anterior"] = "";
             $informations["Ultima ligação para"] = $lastdialaction;
             $informations["Estado da ultima ligação"] = $lastdialstatus;
         }
         $this->sendMailAlert(explode(",", $this->config['alertEmail']), $informations);
     }
     switch ($dialstatus['data']) {
         case 'ANSWER':
         case 'CANCEL':
         case 'NOANSWER':
         case 'BUSY':
             throw new PBX_Rule_Action_Exception_StopExecution("Fim da ligacao");
             break;
         default:
             $log->err($dialstatus['data'] . " ao discar para {$request->destino} pelo tronco {$tronco}");
     }
 }
예제 #3
0
파일: DialTrunk.php 프로젝트: rootzig/SNEP
 /**
  * Executa a ação. É chamado dentro de uma instancia usando AGI.
  *
  * @param Asterisk_AGI $asterisk
  * @param Asterisk_AGI_Request $request
  */
 public function execute($asterisk, $request)
 {
     $log = Zend_Registry::get('log');
     $trs = $this->i18n;
     $tronco = PBX_Trunks::get($this->config['tronco']);
     // Montando as Flags para limite na ligação
     $flags = $this->config['dial_flags'];
     if (isset($this->config['dial_limit']) && $this->config['dial_limit'] > 0) {
         $flags .= "L(" . $this->config['dial_limit'];
         // play_warning_value
         if (isset($this->defaultConfig['play_warning']) && $this->defaultConfig['play_warning'] > 0) {
             $flags .= ":" . $this->defaultConfig['play_warning'];
             // warning_freq
             if (isset($this->defaultConfig['warning_freq']) && $this->defaultConfig['warning_freq'] > 0) {
                 $flags .= ":" . $this->defaultConfig['warning_freq'];
             }
         }
         $flags .= ")";
         if (isset($this->defaultConfig['warning_sound'])) {
             $warning_sound = $this->defaultConfig['warning_sound'] != "" ? $this->defaultConfig['warning_sound'] : "beep";
             $asterisk->set_variable("LIMIT_WARNING_FILE", $warning_sound);
         }
     }
     if ($tronco->getDtmfDialMode()) {
         $dst_number = $tronco->getDtmfDialNumber();
         $flags .= "D({$request->destino})";
     } else {
         $dst_number = $request->destino;
     }
     if ($tronco->getInterface() instanceof PBX_Asterisk_Interface_SIP_NoAuth || $tronco->getInterface() instanceof PBX_Asterisk_Interface_IAX2_NoAuth) {
         $destiny = $tronco->getInterface()->getTech() . "/" . $dst_number . "@" . $tronco->getInterface()->getHost();
     } else {
         $postfix = isset($this->config['omit_kgsm']) && $this->config['omit_kgsm'] == "true" ? "/orig=restricted" : "";
         $destiny = $tronco->getInterface()->getCanal() . "/" . $dst_number . $postfix;
     }
     $log->info("Dialing to {$request->destino} through trunk {$tronco->getName()}({$destiny})");
     $dialstatus = $asterisk->get_variable("DIALSTATUS");
     $lastdialstatus = $dialstatus['data'];
     if (Zend_Registry::get('outgoingNumber') !== "") {
         $asterisk->set_variable("CALLERID(num)", Zend_Registry::get('outgoingNumber'));
     }
     $log->debug("Dial({$destiny}, {$this->config['dial_timeout']}, {$flags})");
     // ==== DIAL ====
     $asterisk->exec_dial($destiny, $this->config['dial_timeout'], $flags);
     $dialstatus = $asterisk->get_variable("DIALSTATUS");
     $log->debug("DIALSTATUS: " . $dialstatus['data']);
     // Enviar email de alerta.
     if (isset($this->config['alertEmail']) && $this->config['alertEmail'] != "") {
         $informations = array($trs->translate('Rule') => $this->getRule(), $trs->translate('Call Time') => date('H:i'), $trs->translate('Call Date') => date('d/m/Y'), $trs->translate('Original Source') => $request->getOriginalCallerid(), $trs->translate('Original Destination') => $request->getOriginalExtension(), $trs->translate('Source') => $request->origem, $trs->translate('Destination') => $request->destino, $trs->translate('Call status') => $dialstatus['data']);
         if ($lastdialstatus != "") {
             $lastdialaction = null;
             foreach ($this->getRule()->getAcoes() as $action) {
                 if ($action == $this) {
                     break;
                 }
                 $cfg = $action->getConfigArray();
                 if ($action instanceof DiscarTronco) {
                     $lastdialaction = PBX_Trunks::get($cfg['tronco']);
                 } else {
                     if ($action instanceof DiscarRamal) {
                         $lastdialaction = $cfg['ramal'];
                     }
                 }
             }
             $informations[$trs->translate("\nThere were a previous call attempt")] = "";
             $informations[$trs->translate("Last call to")] = $lastdialaction;
             $informations[$trs->translate("Status of last call")] = $lastdialstatus;
         }
         $this->sendMailAlert(explode(",", $this->config['alertEmail']), $informations);
     }
     switch ($dialstatus['data']) {
         case 'ANSWER':
         case 'CANCEL':
         case 'NOANSWER':
         case 'BUSY':
             throw new PBX_Rule_Action_Exception_StopExecution("Call end");
             break;
         default:
             $log->err($dialstatus['data'] . " dialing to {$request->destino} through trunk {$tronco}");
     }
 }