Пример #1
0
 public function indexAction()
 {
     $this->view->breadcrumb = Snep_Breadcrumb::renderPath(array($this->view->translate("Routing"), $this->view->translate("Expression Alias")));
     $aliases = PBX_ExpressionAliases::getInstance();
     $this->view->aliases = $aliases->getAll();
     $this->view->filter = array(array("url" => $this->getFrontController()->getBaseUrl() . '/' . $this->getRequest()->getControllerName() . '/add', "display" => $this->view->translate("Add Expression Alias"), "css" => "include"));
 }
Пример #2
0
 /**
  * Executa a ação
  *
  * @param Asterisk_AGI $asterisk
  * @param Asterisk_AGI_Request $request
  */
 public function execute($asterisk, $request)
 {
     $log = Zend_Registry::get('log');
     $i18n = $this->i18n;
     $num = isset($this->config['type']) && $this->config['type'] == 'src' ? $request->origem : $request->destino;
     // Cortando numero
     if (isset($this->config['cut']) && $this->config['cut'] == 'pipecut') {
         if (!is_null($this->getRule())) {
             $expr = $this->config['type'] == 'src' ? $this->getRule()->getValidSrcExpr($num) : $this->getRule()->getValidDstExpr($num);
             if ($expr['type'] == 'RX') {
                 // Removendo da contagem caracteres de controle e instrução
                 $normalized_string = str_replace("_", "", $expr['value']);
                 // Normalizando [123-8] e similares para um unico caractere
                 $normalized_string = preg_replace("/\\[[0-9\\-]*\\]/", "#", $normalized_string);
                 /* Nesse ponto uma expressão:
                  * _0XX|[2-9]XX[23].
                  * Deve ser:
                  * 0XX|#XX#.
                  */
                 $cut_point = strpos($normalized_string, "|");
                 if ($cut_point > 0) {
                     // caso haja algo para cortar
                     // Cortando
                     $num = substr($num, $cut_point);
                 }
             } else {
                 if ($expr['type'] == "AL") {
                     $aliases = PBX_ExpressionAliases::getInstance();
                     $expression = $aliases->get((int) $expr['value']);
                     $regular_expression = new PBX_Asterisk_Expression();
                     $found = null;
                     foreach ($expression["expressions"] as $expr_value) {
                         $regular_expression->setExpression($expr_value);
                         if ($regular_expression->match($num)) {
                             $found = $expr_value;
                             break;
                         }
                     }
                     // Removendo da contagem caracteres de controle e instrução
                     $normalized_string = str_replace("_", "", $found);
                     // Normalizando [123-8] e similares para um unico caractere
                     $normalized_string = preg_replace("/\\[[0-9\\-]*\\]/", "#", $normalized_string);
                     /* Nesse ponto uma expressão:
                      * _0XX|[2-9]XX[23].
                      * Deve ser:
                      * 0XX|#XX#.
                      */
                     $cut_point = strpos($normalized_string, "|");
                     if ($cut_point > 0) {
                         // caso haja algo para cortar
                         // Cortando
                         $num = substr($num, $cut_point);
                     }
                 }
             }
         }
     }
     // Adicionando prefixo
     if (isset($this->config['prefix'])) {
         $num = $this->config['prefix'] . $num;
     }
     // Adicionando suffixo
     if (isset($this->config['suffix'])) {
         $num .= $this->config['suffix'];
     }
     // Reescrevendo numero
     if (isset($this->config['replace']) && $this->config['replace'] != '') {
         $num = $this->config['replace'];
     }
     // Aplicando modificações no callerid/extension do asterisk
     if (isset($this->config['type']) && $this->config['type'] == 'src') {
         $log->info(sprintf($i18n->translate("Rewriting source to %s"), $num));
         $request->origem = $num;
         $asterisk->set_callerid($num);
     } else {
         $log->info(sprintf($i18n->translate("Rewriting destination to %s"), $num));
         $request->destino = $num;
         $asterisk->set_extension($request->destino);
     }
 }
Пример #3
0
 /**
  * Generate the form for routes
  *
  * @return Zend_Form
  */
 protected function getForm()
 {
     if ($this->form === Null) {
         $form_xml = new Zend_Config_Xml(Zend_Registry::get("config")->system->path->base . "/modules/default/forms/route.xml");
         $form = new Snep_Form($form_xml);
         $actions = PBX_Rule_Actions::getInstance();
         $installed_actions = array();
         foreach ($actions->getInstalledActions() as $action) {
             $action_instance = new $action();
             $installed_actions[$action] = $action_instance->getName();
         }
         asort($installed_actions);
         $this->view->actions = $installed_actions;
         $src = new Snep_Form_Element_Html("route/elements/src.phtml", "src", false);
         $src->setLabel($this->view->translate("Source"));
         $src->setOrder(1);
         $form->addElement($src);
         $dst = new Snep_Form_Element_Html("route/elements/dst.phtml", "dst", false);
         $dst->setLabel($this->view->translate("Destiny"));
         $dst->setOrder(2);
         $form->addElement($dst);
         $time = new Snep_Form_Element_Html("route/elements/time.phtml", "time", false);
         $time->setOrder(4);
         $time->setLabel($this->view->translate("Valid times"));
         $form->addElement($time);
         $form->addElement(new Snep_Form_Element_Html("route/elements/actions.phtml", "actions"));
         $this->form = $form;
         $groups = new Snep_GruposRamais();
         $groups = $groups->getAll();
         $group_list = "";
         foreach ($groups as $group) {
             $group_list .= "[\"{$group['name']}\", \"{$group['name']}\"],";
         }
         $group_list = "[" . trim($group_list, ",") . "]";
         $this->view->group_list = $group_list;
         $alias_list = "";
         foreach (PBX_ExpressionAliases::getInstance()->getAll() as $alias) {
             $alias_list .= "[\"{$alias['id']}\", \"{$alias['name']}\"],";
         }
         $alias_list = "[" . trim($alias_list, ",") . "]";
         $this->view->alias_list = $alias_list;
         $trunks = "";
         foreach (PBX_Trunks::getAll() as $trunk) {
             $trunks .= "[\"{$trunk->getId()}\", \"{$trunk->getName()}\"],";
         }
         $trunks = "[" . trim($trunks, ",") . "]";
         $this->view->trunk_list = $trunks;
         $cgroup_list = "";
         $cgroup_manager = new Snep_ContactGroups_Manager();
         foreach ($cgroup_manager->getAll() as $cgroup) {
             $cgroup_list .= "[\"{$cgroup['id']}\", \"{$cgroup['name']}\"],";
         }
         $cgroup_list = "[" . trim($cgroup_list, ",") . "]";
         $this->view->contact_groups_list = $cgroup_list;
     }
     return $this->form;
 }
Пример #4
0
 /**
  * Checa se uma origem/destino casa com um numero
  *
  * @param string $type Tipo de origem/destino
  * @param string $expr Expressão do tipo, se houver
  * @param string $value Valor a ser confrontado com a expressão
  * @return boolean Resultado da checagem
  */
 private function checkExpr($type, $expr, $value)
 {
     switch ($type) {
         case 'RX':
             // Expressão Regular
             return preg_match("/{$this->astrule2regex($expr)}/", $value);
             break;
         case 'G':
             if ($this->request->getSrcObj() instanceof Snep_Usuario) {
                 return PBX_Usuarios::hasGroupInheritance($expr, $this->request->getSrcObj()->getGroup());
             } else {
                 return false;
             }
             break;
         case 'R':
             // Vinda de um Ramal específico
             return $value == $expr ? true : false;
             break;
         case 'S':
             // Sem destino - Válido somente para destinos (duh!).
             return $value == 's' ? true : false;
             break;
         case 'T':
             // Troncos
             $log = Snep_Logger::getInstance();
             if ($this->request->getSrcObj() instanceof Snep_Trunk && $this->request->getSrcObj()->getId() == $expr) {
                 return true;
             } else {
                 return false;
             }
             break;
         case 'X':
             // Qualquer origem/destino
             return true;
             break;
         case 'CG':
             $db = Zend_Registry::get('db');
             $select = $db->select()->from('contacts_names')->where("`group` = '{$expr}' AND (phone_1 = '{$value}' OR cell_1 = '{$value}')");
             $stmt = $db->query($select);
             $groups = $stmt->fetchAll();
             if (count($groups) > 0) {
                 return true;
             } else {
                 return false;
             }
             break;
         case "AL":
             $aliases = PBX_ExpressionAliases::getInstance();
             $expression = $aliases->get((int) $expr);
             $found = false;
             foreach ($expression["expressions"] as $expr_value) {
                 if (preg_match("/{$this->astrule2regex($expr_value)}/", $value)) {
                     $found = true;
                     break;
                 }
             }
             return $found;
             break;
         default:
             throw new PBX_Exception_BadArg("Tipo de expressao invalido '{$type}' para checagem de origem/destino, cheque a regra de negocio {$this->parsingRuleId}");
     }
 }