Beispiel #1
0
 /**
  * Executa a ação.
  * @param Asterisk_AGI $asterisk
  * @param PBX_Asterisk_AGI_Request $request
  */
 public function execute($asterisk, $request)
 {
     $log = Zend_Registry::get('log');
     if (isset($this->ask_peer) && $this->ask_peer === true) {
         $asterisk->answer();
         $asterisk->exec("READ", "RAMAL|agent-user|10|||4");
         $ramal = $asterisk->get_variable("RAMAL");
         try {
             $ramal = PBX_Usuarios::get($ramal['data']);
         } catch (PBX_Exception_NotFound $ex) {
             throw new PBX_Exception_AuthFail("Ivalid Extension");
         }
         $request->setSrcObj($ramal);
         $request->origem = $ramal->getNumero();
         $asterisk->set_variable("CALLERID(all)", $ramal->getNumero());
     }
     $senha = "";
     if ((!isset($this->config['senha']) || isset($this->config['senha']) && $this->config['senha'] == "") && $request->getSrcObj() instanceof Snep_Usuario) {
         $senha = $request->getSrcObj()->getPassword();
     } else {
         if (isset($this->config['senha']) && $this->config['senha'] != "") {
             $senha = $this->config['senha'];
         } else {
             return;
         }
     }
     $auth = $asterisk->exec('AUTHENTICATE', array($senha, '', strlen((string) $senha)));
     if ($auth['result'] == -1) {
         throw new PBX_Exception_AuthFail();
     }
 }
Beispiel #2
0
 public function indexAction()
 {
     $this->view->breadcrumb = Snep_Breadcrumb::renderPath(array($this->view->translate("Routing"), $this->view->translate("Routes"), $this->view->translate("Simulator")));
     $trunks = array();
     foreach (PBX_Trunks::getAll() as $value) {
         $trunks[$value->getId()] = $value->getId() . " - " . $value->getName();
     }
     $this->view->trunks = $trunks;
     if ($this->_request->getPost()) {
         $formData = $this->_request->getParams();
         $extension = isset($formData['dst']) && $formData['dst'] != "" ? $formData['dst'] : 's';
         $srcType = isset($formData['srcType']) ? $formData['srcType'] : NULL;
         $trunk = isset($formData['trunk']) ? $formData['trunk'] : NULL;
         $caller = isset($formData['caller']) && $formData['caller'] != "" ? $formData['caller'] : "unknown";
         $time = isset($formData['time']) ? $formData['time'] : NULL;
         $dialplan = new PBX_Dialplan_Verbose();
         if ($srcType == "exten") {
             try {
                 $srcObj = PBX_Usuarios::get($caller);
             } catch (PBX_Exception_NotFound $ex) {
                 $this->view->error = $this->view->translate($ex->getMessage());
                 $this->view->back = $this->view->translate("Back");
                 $this->renderScript('simulator/error.phtml');
                 return;
             }
             $channel = $srcObj->getInterface()->getCanal();
         } else {
             if ($srcType == "trunk") {
                 $srcObj = PBX_Trunks::get($trunk);
                 $channel = $srcObj->getInterface()->getCanal();
             } else {
                 $srcObj = null;
                 $channel = "unknown";
             }
         }
         $request = new PBX_Asterisk_AGI_Request(array("agi_callerid" => $caller, "agi_extension" => $extension, "agi_channel" => $channel));
         $request->setSrcObj($srcObj);
         $dialplan->setRequest($request);
         if ($time) {
             if (preg_match("/^[0-9]:([0-9]{2})\$/", $time)) {
                 $time = "0" . $time;
             }
             $dialplan->setTime($time);
         }
         try {
             $dialplan->parse();
         } catch (PBX_Exception_NotFound $ex) {
             $this->view->error = $this->view->translate("No rule found.");
             $this->view->back = $this->view->translate("Back");
             $this->renderScript('simulator/error.phtml');
             return;
         }
         if (count($dialplan->getMatches()) > 0) {
             $found = false;
             foreach ($dialplan->getMatches() as $index => $rule) {
                 if ($rule->getId() == $dialplan->getLastRule()->getId()) {
                     $state = "torun";
                     $found = true;
                 } else {
                     if ($found) {
                         $state = "ignored";
                     } else {
                         $state = "outdated";
                     }
                 }
                 $actions = array();
                 foreach ($rule->getAcoes() as $action) {
                     $config = $action->getConfigArray();
                     if ($action instanceof CCustos) {
                         $actions[] = $this->view->translate("Define Cost Center to ") . $config['ccustos'];
                     } else {
                         if ($action instanceof DiscarTronco) {
                             $tronco = PBX_Trunks::get($config['tronco']);
                             $actions[] = $this->view->translate("Dial through Trunk ") . $tronco->getName();
                         } else {
                             if ($action instanceof DiscarRamal) {
                                 if (isset($config['ramal']) && $config['ramal'] != "") {
                                     $peer = $config['ramal'];
                                 } else {
                                     $peer = $extension;
                                 }
                                 try {
                                     $ramal = PBX_Usuarios::get($peer);
                                     $actions[] = $this->view->translate("Dial to extension %s", $ramal->getCallerid());
                                 } catch (PBX_Exception_NotFound $ex) {
                                     $actions[] = "<strong style='color:red'>" . $this->view->translate("Failure on trial to dial extension %: non existent extension", $extension) . "</strong>";
                                 }
                             } else {
                                 if ($action instanceof Queue) {
                                     $actions[] = $this->view->translate("Direct to queue %s", $config['queue']);
                                 } else {
                                     if ($action instanceof Cadeado) {
                                         $actions[] = $this->view->translate("Request password");
                                     } else {
                                         if ($action instanceof Context) {
                                             $actions[] = $this->view->translate("Redirect to context %s", $config['context']);
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
                 $srcs = array();
                 foreach ($rule->getSrcList() as $src) {
                     $srcs[] = trim(implode(":", $src), ':');
                 }
                 $srcs = implode(",", $srcs);
                 $dsts = array();
                 foreach ($rule->getDstList() as $dst) {
                     $dsts[] = trim(implode(":", $dst), ':');
                 }
                 $dsts = implode(",", $dsts);
                 $result[$index] = array("id" => $rule->getId(), "state" => $state, "caller" => $srcs, "dst" => $dsts, "desc" => $rule->getDesc(), "valid" => join(";", $rule->getValidTimeList()), "actions" => $actions);
             }
             $input = array("caller" => $caller, "dst" => $extension, "time" => $dialplan->getLastExecutionTime());
             $this->view->input = $input;
             $this->view->result = $result;
         }
     }
 }