/** * Construtor do objeto */ public function AsteriskInfo() { global $SETUP, $LANG; // Verificando se já existe alguma conex�o if (!isset(self::$asterisk)) { // Criando a primeira instancia da conexão self::$asterisk = PBX_Asterisk_AMI::getInstance(); } }
/** * Método que retorna a instancia da classe PBX_Asterisk_AMI. Se esta não estiver * disponível é instanciada. * * Conexão automática usando as variáveis para conexão com o asterisk * fornecidas na configuração do snep. * * @return Asterisk_AMI */ public static function getInstance() { if (!isset(self::$instance)) { $config = Zend_Registry::get('config'); $args = array("server" => $config->ambiente->ip_sock, "username" => $config->ambiente->user_sock, "secret" => $config->ambiente->pass_sock); $asterisk = new Asterisk_AMI(null, $args); $asterisk->connect(); self::$instance = $asterisk; } return self::$instance; }
public function __construct() { $this->asterisk = PBX_Asterisk_AMI::getInstance(); }
public static function loadConfFromDb() { $view = new Zend_View(); $db = Snep_Db::getInstance(); // TODO - buscar informações da tabela extensions foreach (array("sip", "iax2") as $tech) { $config = Zend_Registry::get('config'); $asteriskDirectory = $config->system->path->asterisk->conf; $extenFileConf = "{$asteriskDirectory}/snep/snep-{$tech}.conf"; $trunkFileConf = "{$asteriskDirectory}/snep/snep-{$tech}-trunks.conf"; if (!is_writable($extenFileConf)) { throw new PBX_Exception_IO($view->translate("Failed to open file %s with write permission.", $extenFileConf)); } if (!is_writable($trunkFileConf)) { throw new PBX_Exception_IO($view->translate("Failed to open file %s with write permission.", $trunkFileConf)); } /* clean snep-sip.conf file */ file_put_contents($extenFileConf, ''); /* Register header on output string of the file */ $todayDate = date("d/m/Y H:m:s"); $header = ";------------------------------------------------------------------------------------\n"; $header .= "; Arquivo: snep-{$tech}.conf - Cadastro de ramais \n"; $header .= "; \n"; $header .= "; Atualizado em: {$todayDate} \n"; $header .= "; Copyright(c) 2008 Opens Tecnologia \n"; $header .= ";------------------------------------------------------------------------------------\n"; $header .= "; Os registros a Seguir sao gerados pelo Software SNEP. \n"; $header .= "; Este Arquivo NAO DEVE ser editado Manualmente sob riscos de \n"; $header .= "; causar mau funcionamento do Asterisk \n"; $header .= ";------------------------------------------------------------------------------------\n"; /* query that gets information of the peers on the DB */ $sql = "SELECT * FROM peers WHERE name != 'admin' AND canal like '" . strtoupper($tech) . "%'"; $peer_data = $db->query($sql)->fetchAll(); $peers = "\n"; $trunk_config = "\n"; if (count($peer_data) > 0) { foreach ($peer_data as $peer) { $sipallow = explode(";", $peer['allow']); $allow = ''; foreach ($sipallow as $siper) { if ($siper != '') { $allow .= $siper . ","; } } $allow = substr($allow, 0, strlen($allow) - 1); if ($peer['peer_type'] == 'T') { $select = $db->select()->from('trunks')->where("name = {$peer['name']}")->limit(1); $trunk = $db->query($select)->fetchObject(); if ($trunk->type == "SNEPSIP") { /* Assemble trunk entries */ $peers .= '[' . $peer['username'] . "]\n"; $peers .= 'type=' . $peer['type'] . "\n"; $peers .= 'context=' . $peer['context'] . "\n"; $peers .= 'canreinvite=' . $peer['canreinvite'] . "\n"; $peers .= 'dtmfmode=' . ($peer['dtmfmode'] ? $peer['dtmfmode'] : "rfc2833") . "\n"; $peers .= 'host=' . $peer['host'] . "\n"; $peers .= 'qualify=' . ($peer['qualify'] == "no" ? "no" : "yes") . "\n"; $peers .= 'nat=' . $peer['nat'] . "\n"; $peers .= 'disallow=' . $peer['disallow'] . "\n"; $peers .= 'allow=' . $allow . "\n"; $peers .= "\n"; } else { if ($trunk->type == "SNEPIAX2") { /* Assemble Extension entries */ $peers .= '[' . $peer['username'] . "]\n"; $peers .= 'type=' . $peer['type'] . "\n"; $peers .= 'username='******'username'] . "\n"; $peers .= 'secret=' . $peer['username'] . "\n"; $peers .= 'context=' . $peer['context'] . "\n"; $peers .= 'canreinvite=' . $peer['canreinvite'] . "\n"; $peers .= 'dtmfmode=' . ($peer['dtmfmode'] ? $peer['dtmfmode'] : "rfc2833") . "\n"; $peers .= 'host=' . $peer['host'] . "\n"; $peers .= 'qualify=' . ($peer['qualify'] == "no" ? "no" : "yes") . "\n"; $peers .= 'nat=' . $peer['nat'] . "\n"; $peers .= 'disallow=' . $peer['disallow'] . "\n"; $peers .= 'allow=' . $allow . "\n"; $peers .= "\n"; } else { if ($trunk->dialmethod != "NOAUTH") { /* Assemble trunk entries */ $peers .= '[' . $peer['username'] . "]\n"; $peers .= 'type=' . $peer['type'] . "\n"; $peers .= 'context=' . $peer['context'] . "\n"; $peers .= $peer['fromdomain'] != "" ? 'fromdomain=' . $peer['fromdomain'] . "\n" : ""; $peers .= $peer['fromuser'] != "" ? 'fromuser='******'fromuser'] . "\n" : ""; $peers .= 'canreinvite=' . $peer['canreinvite'] . "\n"; $peers .= 'dtmfmode=' . ($peer['dtmfmode'] ? $peer['dtmfmode'] : "rfc2833") . "\n"; $peers .= 'host=' . $peer['host'] . "\n"; $peers .= 'qualify=' . $peer['qualify'] . "\n"; $peers .= 'nat=' . $peer['nat'] . "\n"; $peers .= 'disallow=' . $peer['disallow'] . "\n"; $peers .= 'allow=' . $allow . "\n"; if ($peer['port'] != "") { $peers .= 'port=' . $peer['port'] . "\n"; } if ($peer['call-limit'] != "" && $trunk->type == "SIP") { $peers .= 'call-limit=' . $peer['call-limit'] . "\n"; } if ($trunk->insecure != "") { $peers .= 'insecure=' . $trunk->insecure . "\n"; } if ($trunk->domain != "" && $trunk->type == "SIP") { $peers .= 'domain=' . $trunk->domain . "\n"; } if ($trunk->type == "IAX2") { $peers .= 'trunk=' . $peer['trunk'] . "\n"; } if ($trunk->reverse_auth) { $peers .= 'username='******'username'] . "\n"; $peers .= 'secret=' . $peer['secret'] . "\n"; } $peers .= "\n"; } } } $trunk_config .= $trunk->dialmethod != "NOAUTH" && !preg_match("/SNEP/", $trunk->type) ? "register => " . $peer['username'] . ":" . $peer['secret'] . "@" . $peer['host'] . "\n" : ""; } else { /* Assemble Extension entries */ $peers .= '[' . $peer['name'] . "]\n"; $peers .= 'type=' . $peer['type'] . "\n"; $peers .= 'context=' . $peer['context'] . "\n"; $peers .= 'host=' . $peer['host'] . "\n"; # dinamyc $peers .= 'secret=' . $peer['secret'] . "\n"; $peers .= 'callerid=' . $peer['callerid'] . "\n"; $peers .= 'canreinvite=' . $peer['canreinvite'] . "\n"; $peers .= 'dtmfmode=' . ($peer['dtmfmode'] ? $peer['dtmfmode'] : "rfc2833") . "\n"; $peers .= 'nat=' . $peer['nat'] . "\n"; $peers .= 'qualify=' . $peer['qualify'] . "\n"; $peers .= 'disallow=' . $peer['disallow'] . "\n"; $peers .= 'allow=' . $allow . "\n"; $peers .= 'username='******'name'] . "\n"; $peers .= 'fromuser='******'name'] . "\n"; $peers .= 'call-limit=' . $peer['call-limit'] . "\n"; $peers .= "\n"; } } } $trunkcont = str_replace(".conf", "-trunks.conf", $header) . $trunk_config; file_put_contents($trunkFileConf, $trunkcont); $content = $header . $peers; file_put_contents($extenFileConf, $content); } // Forcing asterisk to reload the configs $asteriskAmi = PBX_Asterisk_AMI::getInstance(); $asteriskAmi->Command("sip reload"); $asteriskAmi->Command("iax2 reload"); }