示例#1
0
文件: AMI.php 项目: rootzig/SNEP
 /**
  * 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;
 }
示例#2
0
 public function configureAction()
 {
     $objInspector = new Snep_Inspector('Permissions');
     $inspect = $objInspector->getInspects();
     $this->view->error = $inspect['Permissions'];
     $this->view->hideMenu = true;
     $this->view->breadcrumb = $this->view->translate("Installer » Configuration");
     $form_config = new Zend_Config_Xml("./modules/default/formsinstaller.xml");
     $form = new Snep_Form();
     $form->setAction($this->getFrontController()->getBaseUrl() . '/installer/configure');
     $asterisk_form = new Snep_Form_SubForm($this->view->translate("Asterisk Configuration"), $form_config->asterisk);
     $database_form = new Snep_Form_SubForm($this->view->translate("Database Configuration"), $form_config->database);
     $snep_form = new Snep_Form_SubForm($this->view->translate("Admin Password"), $form_config->snep);
     $form->addSubForm($database_form, "database");
     $form->addSubForm($asterisk_form, "asterisk");
     $form->addSubForm($snep_form, "snep");
     $submit_button = $form->getElement('submit');
     if ($this->view->error['error']) {
         $submit_button->setAttrib('disabled', true);
     }
     if ($this->getRequest()->isPost()) {
         $form_isValid = $form->isValid($_POST);
         $snep_data = $form->getValue("snep");
         if ($snep_data['password'] !== $snep_data['confirmpassword']) {
             $snep_form->getElement('confirmpassword')->addError($this->view->translate("The password confirmation is different from the original"));
             $form_isValid = false;
         }
         if (!$asterisk_form->isErrors()) {
             $asterisk_data = $form->getValue("asterisk");
             $asterisk = new Asterisk_AMI(null, $asterisk_data);
             try {
                 $asterisk->connect();
             } catch (Asterisk_Exception_Auth $ex) {
                 $asterisk_form->getElement('secret')->addError($this->view->translate("User and/or password rejected by Asterisk"));
                 $form_isValid = false;
             } catch (Asterisk_Exception_CantConnect $ex) {
                 $asterisk_form->getElement('server')->addError($this->view->translate("Unable to connect: %s", $ex->getMessage()));
                 $form_isValid = false;
             }
         }
         if (!$database_form->isErrors()) {
             $database_data = $form->getValue('database');
             $db = Zend_Db::factory('Pdo_Mysql', $database_data);
             try {
                 $db->getConnection();
             } catch (Zend_Db_Exception $ex) {
                 $database_form->getElement('hostname')->addError($this->view->translate("Unable to connect: %s", $ex->getMessage()));
                 $form_isValid = false;
             }
         }
         if ($form_isValid) {
             try {
                 $this->install($db);
             } catch (Exception $ex) {
                 $this->view->message = $ex->getMessage();
                 $this->renderScript("installer/error.phtml");
             }
             // Setando usuário do admin.
             $db->update("peers", array('password' => $snep_data['password']), "id = 1");
             // Gravando alterações no arquivo de configuração.
             $config_file = "./includes/setup.conf";
             $config = new Zend_Config_Ini($config_file, null, true);
             $config->ambiente->ip_sock = $_POST['asterisk']['server'];
             $config->ambiente->user_sock = $_POST['asterisk']['username'];
             $config->ambiente->pass_sock = $_POST['asterisk']['secret'];
             $config->ambiente->db->host = $_POST['database']['hostname'];
             $config->ambiente->db->username = $_POST['database']['username'];
             $config->ambiente->db->password = $_POST['database']['password'];
             $config->ambiente->db->dbname = $_POST['database']['dbname'];
             $writer = new Zend_Config_Writer_Ini(array('config' => $config, 'filename' => $config_file));
             // Grava arquivo.
             $writer->write();
             $this->_redirect("installer/installed");
         }
     }
     $this->view->form = $form;
 }