Esempio n. 1
0
File: Db.php Progetto: rootzig/SNEP
 /**
  * Retorna uma instância já existente ou nova instância do banco de dados.
  *
  * @return Zend_Db_Adapter_Abstract $instance
  */
 public static function getInstance()
 {
     if (self::$instance === null) {
         $config = Snep_Config::getConfig()->ambiente->db->toArray();
         $adapter = array_shift($config);
         if (strtoupper($adapter) == "PDO_MYSQL") {
             $config["driver_options"] = array(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => true);
         }
         self::$instance = self::factory($adapter, $config);
         Zend_Db_Table_Abstract::setDefaultAdapter(self::$instance);
         require_once "Zend/Registry.php";
         Zend_Registry::set("db", self::$instance);
     }
     return self::$instance;
 }
Esempio n. 2
0
 *
 *  You should have received a copy of the GNU General Public License
 *  along with SNEP.  If not, see <http://www.gnu.org/licenses/>.
 */
// Define path to application directory
defined('APPLICATION_PATH') || define('APPLICATION_PATH', realpath(dirname(__FILE__)));
// Add standard library to the include path
set_include_path(implode(PATH_SEPARATOR, array(APPLICATION_PATH . '/lib', get_include_path())));
// Initializing Snep Config
require_once "Snep/Config.php";
Snep_Config::setConfigFile(APPLICATION_PATH . '/includes/setup.conf');
$config = Snep_Config::getConfig();
defined('SNEP_VENDOR') || define('SNEP_VENDOR', $config->ambiente->emp_nome);
defined('SNEP_VERSION') || define('SNEP_VERSION', trim(file_get_contents(APPLICATION_PATH . "/configs/snep_version")));
// Define application environment
$snep_env = Snep_Config::getConfig()->system->debug ? "development" : "production";
defined('APPLICATION_ENV') || define('APPLICATION_ENV', getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : $snep_env);
if (APPLICATION_ENV === "development") {
    require_once "Zend/Debug.php";
}
// Adds the modules directory to the snep module system
require_once "Snep/Modules.php";
Snep_Modules::getInstance()->addPath(APPLICATION_PATH . "/modules");
/** Zend_Application */
require_once 'Zend/Application.php';
require_once 'Zend/Config/Ini.php';
// Create application, bootstrap, and run
$application = new Zend_Application(APPLICATION_ENV, APPLICATION_PATH . '/application.ini');
// Adding standard lib autoloader capabilities to keep old code running
$application->setAutoloaderNamespaces(array("Asterisk_", "PBX_", "Snep_"));
// Keeping old links to avoid rework in too much stuff.
Esempio n. 3
0
 /**
  * Parses recursively the resources xml into Snep_Acl
  *
  * @param SimpleXMLElement $resources
  */
 protected function loadResources(SimpleXMLElement $resources, $parent = null, $menu_parent = null)
 {
     $acl = Snep_Acl::getInstance();
     $menu = Snep_Menu::getMasterInstance();
     $baseUrl = Snep_Config::getConfig()->system->path->web;
     $menu_parent = $menu_parent === null ? $parent : $menu_parent;
     foreach ($resources as $element) {
         $id = (string) $element->attributes()->id;
         if ($id === null) {
             throw new Exception("Resource object must contain id attribute.");
         }
         if ($element->getName() == "resource") {
             $resname = $parent . "_" . $id;
             $acl->addResource($resname, $parent);
             if ($element->attributes()->order == "allow") {
                 $acl->allow(null, $resname);
             }
         } else {
             $resname = $parent;
         }
         if ($element->attributes()->label !== null) {
             $menu_id = $menu_parent . "_" . $id;
             $menu_object = new Snep_Menu($menu_id);
             $menu_object->setLabel((string) $element->attributes()->label);
             $menu_object->setUri($baseUrl . "/index.php/" . str_replace("_", "/", $resname));
             $menu_parent_obj = $menu->getChildById($menu_parent);
             if ($menu_parent_obj === null) {
                 $menu_parent_obj = $menu;
             }
             $menu_parent_obj->addChild($menu_object);
         } else {
             $menu_id = $menu_parent;
         }
         if (count($element) > 0) {
             $this->loadResources($element, $resname, $menu_id);
         }
     }
 }
Esempio n. 4
0
 public function __construct()
 {
     $config = Snep_Config::getConfig();
     $locale = $this->locale = $config->system->locale;
     $language = $this->language = $config->system->language;
     $timezone = $this->timezone = $config->system->timezone;
     if (!Zend_Locale::isLocale($locale)) {
         throw new Exception("Fatal: '{$locale}' is not a valid locale", 500);
     }
     setlocale(LC_COLLATE, $locale . ".utf8");
     Zend_Locale::setDefault($locale);
     $this->zendLocale = $zendLocale = new Zend_Locale($locale);
     Zend_Registry::set('Zend_Locale', $zendLocale);
     Zend_Locale_Format::setOptions(array("locale" => $locale));
     if (!Zend_Locale::isLocale($language)) {
         throw new Exception("Fatal: '{$language}' is not a valid language locale", 500);
     }
     if (!self::isTimezone($timezone)) {
         throw new Exception("Fatal: '{$timezone}' is not a valid timezone", 500);
     }
     date_default_timezone_set($timezone);
     $language_alt = substr($language, 0, strpos($language, "_"));
     if (file_exists(TRANSLATIONS_PATH . DIRECTORY_SEPARATOR . "{$language}.mo")) {
         $translate = new Zend_Translate('gettext', TRANSLATIONS_PATH . DIRECTORY_SEPARATOR . "{$language}.mo", $language);
     } else {
         if (file_exists(TRANSLATIONS_PATH . DIRECTORY_SEPARATOR . "{$language_alt}.mo")) {
             $translate = new Zend_Translate('gettext', TRANSLATIONS_PATH . DIRECTORY_SEPARATOR . "{$language_alt}.mo", $language);
         } else {
             $translate = new Zend_Translate('gettext', null, $language);
         }
     }
     $this->zendTranslate = $translate;
     Zend_Registry::set("Zend_Translate", $translate);
     $lang_dirs = scandir(TRANSLATIONS_PATH . "/Zend_Validate/");
     if (in_array($language, $lang_dirs)) {
         $validate_locale = $language;
     } else {
         if (in_array($language_alt, $lang_dirs)) {
             $validate_locale = $language_alt;
         } else {
             $validate_locale = "us";
         }
     }
     $zend_validate_translator = new Zend_Translate_Adapter_Array(TRANSLATIONS_PATH . "/Zend_Validate/{$validate_locale}/Zend_Validate.php", $language);
     Zend_Validate_Abstract::setDefaultTranslator($zend_validate_translator);
 }
Esempio n. 5
0
 *  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/>.
 */
// Controle da exibição de erros
error_reporting(E_ALL | E_STRICT);
ini_set('display_startup_errors', 1);
ini_set('display_errors', 1);
require_once "Bootstrap.php";
new Bootstrap();
require_once "Snep/Config.php";
require_once "Snep/Logger.php";
require_once "PBX/Asterisk/AGI.php";
require_once "Zend/Console/Getopt.php";
$config = Snep_Config::getConfig();
$log = Snep_Logger::getInstance();
$asterisk = PBX_Asterisk_AGI::getInstance();
// Configuração das opções da linha de comando
try {
    $opts = new Zend_Console_Getopt(array('version|v' => 'Prints version.', 'outgoing_number|o=s' => 'Define a outgoing number', 'xfer|x=s' => 'Replace the channel used for source identification.'));
    $opts->parse();
} catch (Zend_Console_Getopt_Exception $e) {
    $log->err($e->getMessage());
    $log->err($e->getUsageMessage());
    exit;
}
if ($opts->version) {
    echo "SNEP Version " . Zend_Registry::get('snep_version') . "\n";
    exit;
}
Esempio n. 6
0
 protected function startLogger()
 {
     $asterisk = PBX_Asterisk_AGI::getInstance();
     $config = Snep_Config::getConfig();
     $log = Snep_Logger::getInstance();
     Zend_Registry::set("log", $log);
     // Log em arquivo
     $writer = new Zend_Log_Writer_Stream($config->system->path->log . '/agi.log');
     $format = sprintf("%%timestamp%% - %s -> %s - %%priorityName%% (%%priority%%):%%message%%", $asterisk->request['agi_callerid'], $asterisk->request['agi_extension']) . PHP_EOL;
     $formatter = new Zend_Log_Formatter_Simple($format);
     $writer->setFormatter($formatter);
     $log->addWriter($writer);
     // Log no console do Asterisk
     $console_writer = new PBX_Asterisk_Log_Writer($asterisk);
     $format = sprintf("%s -> %s %%priorityName%% (%%priority%%):%%message%%", $asterisk->request['agi_callerid'], $asterisk->request['agi_extension']) . PHP_EOL;
     $console_formatter = new Zend_Log_Formatter_Simple($format . PHP_EOL);
     $console_writer->setFormatter($console_formatter);
     $log->addWriter($console_writer);
     if (!$config->system->debug) {
         $writer->addFilter(new Zend_Log_Filter_Priority(Zend_Log::NOTICE));
         $console_writer->addFilter(new Zend_Log_Filter_Priority(Zend_Log::INFO));
     }
 }
Esempio n. 7
0
 protected function _initLogger()
 {
     $log = Snep_Logger::getInstance();
     $config = Snep_Config::getConfig();
     $writer = new Zend_Log_Writer_Stream($config->system->path->log . '/ui.log');
     // Filtramos a 'sujeira' dos logs se não estamos em debug mode.
     if (!$config->system->debug) {
         $filter = new Zend_Log_Filter_Priority(Zend_Log::WARN);
         $writer->addFilter($filter);
     }
     $log->addWriter($writer);
 }