public function indexAction() { $exten = $this->getRequest()->getParam("exten"); if ($exten === null) { throw new Zend_Controller_Action_Exception('Page not found.', 404); } try { PBX_Usuarios::get($exten); } catch (PBX_Exception_NotFound $ex) { throw new Zend_Controller_Action_Exception($this->view->translate("Extension %s does not exists.", $exten), 404); } $this->view->exten = $exten; $this->view->breadcrumb = Snep_Breadcrumb::renderPath(array("Manage", "Extensions", "Permissions")); $resources = array(); foreach (Snep_Acl::getInstance()->getResources() as $resource) { $res_tree = explode("_", $resource); $resource = array(); while ($element = array_pop($res_tree)) { $resource = array($element => $resource); } $resources = array_merge_recursive($resources, $resource); } $this->view->resources = $resources; }
/** * Defined by Zend_Validate_Interface * * Returns true if and only if $value contains only alphabetic and digit characters * * @param string $value * @return boolean */ public function isValid($value) { $valueString = (string) $value; $this->_setValue($valueString); if ('' === $valueString && !$this->getAllowEmpty()) { $this->_error(self::STRING_EMPTY); return false; } try { PBX_Usuarios::get($value); } catch (PBX_Exception_NotFound $ex) { $this->_error(self::NOT_EXTEN); return false; } return true; }
/** * Procura o dono de uma interface baseado em canal. * * @param string $channel Canal da interface * @return object Objeto que representa o dono da interface (se houver) */ public static function getChannelOwner($channel) { $db = Snep_Db::getInstance(); $select = $db->select()->from('trunks'); $trunk_ifaces = $db->query($select)->fetchAll(); foreach ($trunk_ifaces as $interface) { if (preg_match("#^{$interface['id_regex']}\$#i", $channel)) { return PBX_Trunks::get($interface['id']); } } $select = $db->select()->from('peers')->where("name != 'admin' AND peer_type='R'"); $interfaces = $db->query($select)->fetchAll(); foreach ($interfaces as $interface) { if (preg_match("#^{$interface['canal']}\$#i", $channel)) { return PBX_Usuarios::get($interface['name']); } } return null; }
* SNEP is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * SNEP is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with SNEP. If not, see <http://www.gnu.org/licenses/>. */ require_once "agi_base.php"; if ($argc != 2) { $asterisk->verbose("This agi script requires one extension as parameter."); exit(1); } $sigame = ""; try { $ramal = PBX_Usuarios::get($argv[1]); if ($ramal->getFollowMe() != "") { $ramal2 = PBX_Usuarios::get($ramal->getFollowMe()); $sigame = $ramal2->getInterface()->getCanal(); } } catch (Exception $e) { $asterisk->verbose("[{$requestid}] Failure to resolv extension: " . $e->getMessage(), 1); exit(1); } $asterisk->set_variable("DND", $ramal->isDNDActive() ? "1" : "0"); $asterisk->set_variable("SIGAME", "\"{$sigame}\"");
* * SNEP is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * SNEP is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with SNEP. If not, see <http://www.gnu.org/licenses/>. */ require_once 'agi_base.php'; $ramal = PBX_Usuarios::get($request->callerid); if (!$ramal->isLocked()) { $db->update('peers', array("authenticate" => true), "name='{$ramal->getNumero()}'"); $asterisk->answer(); $asterisk->stream_file('activated'); } else { if ($ramal->isLocked()) { $auth = $asterisk->exec('AUTHENTICATE', array($ramal->getPassword(), '', strlen((string) $ramal->getPassword()))); if ($auth['result'] == -1) { $log->info("Wrong password to lock extension {$ramal}"); } else { $db->update('peers', array("authenticate" => false), "name='{$ramal->getNumero()}'"); $asterisk->answer(); $asterisk->stream_file('de-activated'); } }
/** * 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}"); } } } }
/** * Verifica se um destino é válido para essa regra. * * @param string $extension * @return boolean validity */ public function isValidDst($extension) { foreach ($this->getDstList() as $dst) { if ($dst['type'] == 'G') { try { $peer = PBX_Usuarios::get($extension); } catch (PBX_Exception_NotFound $ex) { $peer = false; } if ($peer instanceof Snep_Usuario && PBX_Usuarios::hasGroupInheritance($dst['value'], $peer->getGroup())) { return true; } } else { if ($this->checkExpr($dst['type'], $dst['value'], $extension)) { return true; } } } return false; }
/** * 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(); } }
/** * 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})"); } }
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; } } }
* * SNEP is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * SNEP is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with SNEP. If not, see <http://www.gnu.org/licenses/>. */ require_once "agi_base.php"; if ($argc != 3) { $asterisk->verbose("This script requires one extension and a variable name as parameter"); exit(1); } // Procurando no banco pelo canal do peer try { $ramal = PBX_Usuarios::get($argv[1]); } catch (Exception $e) { $asterisk->verbose("[{$requestid}] Failure to resolv interface: " . $e->getMessage(), 1); exit(1); } $channel = $ramal->getInterface()->getCanal(); if (substr($channel, 0, 1) == "k" || substr($channel, 0, 1) == "K") { $channel = "Khomp/" . strtoupper(substr($channel, strpos($channel, '/') + 1)); } $asterisk->set_variable($argv[2], $channel);