function __construct($filename, $default_filename = '', $upgrade = true) { if (!file_exists($filename)) { if (file_exists($default_filename)) { copy($default_filename, $filename); } else { trigger_error("The INI settings file is missing: {$filename}"); die; } } $this->_ini_file = $filename; $this->load(); // check for updated ini settings if necessary // IF cong/upgrade exists! if ($upgrade && file_exists(APP_PATH . 'conf/upgrade')) { $new_ini = new Ini($default_filename, '', false); $new_ini->load(); foreach ($new_ini as $key => $value) { if ($this->item($key) === null) { $this->item($key, $value); } } $this->save(); unset($new_ini); unlink(APP_PATH . 'conf/upgrade'); } }
function get_switch($filename, $username) { $switches = array(); $ini = new Ini(); $ini->load($filename); foreach ($ini->sections() as $host) { if ($ini->get($host, "context") == $username) { $switch["host"] = $ini->get($host, "host"); $switch["call-limit"] = $ini->get($host, "call-limit"); $switches[] = $switch; } } return $switches; }
/** * apply curry.ini settings * * @return boolean */ public function applyConfig() { Loader::load('Ini', 'core'); Loader::load('Db', 'db'); $ini = false; if ($this->_appEnv == null) { // Default section is "product" $ini = Ini::load('database.ini', 'product'); } else { $ini = Ini::load('database.ini', $this->_appEnv); } if ($ini === false) { // For the compatibility of a old version. $ini = Ini::load('database.ini', 'connection'); } if ($ini !== false) { Db::setConfig($ini); } $ini = Ini::load('curry.ini'); if ($ini === false) { return false; } if (array_key_exists('dispatch', $ini)) { $values = $ini['dispatch']; $key = 'plugin_enabled'; if (array_key_exists($key, $values)) { if (is_numeric($values[$key]) && $values[$key] == 1) { $this->dispatcher->enablePlugin(true); } } $key = 'is_send_404'; if (array_key_exists($key, $values)) { if (is_numeric($values[$key]) && $values[$key] != 1) { $this->dispatcher->isSend404(false); } } $key = 'sub_controller_enabled'; if (array_key_exists($key, $values)) { if (is_numeric($values[$key]) && $values[$key] == 1) { $this->router->enableSubController(true); } } $key = 'is_rewrite'; if (array_key_exists($key, $values)) { if (is_numeric($values[$key]) && $values[$key] != 1) { $this->router->isRewrite(false); } } $key = 'default_controller'; if (array_key_exists($key, $values)) { $this->router->setDefaultController($values[$key]); } $key = 'default_action'; if (array_key_exists($key, $values)) { $this->router->setDefaultAction($values[$key]); } $key = 'controller_query_key'; if (array_key_exists($key, $values)) { $this->router->setControllerQueryKey($values[$key]); } $key = 'action_query_key'; if (array_key_exists($key, $values)) { $this->router->setActionQueryKey($values[$key]); } $key = 'controller_suffix'; if (array_key_exists($key, $values)) { NameManager::setControllerSuffix($values[$key]); } $key = 'action_suffix'; if (array_key_exists($key, $values)) { NameManager::setActionSuffix($values[$key]); } } if (array_key_exists('view', $ini)) { $values = $ini['view']; $key = 'class_name'; if (array_key_exists($key, $values)) { $this->dispatcher->setViewClass($values[$key]); } $key = 'layout_enabled'; if (array_key_exists($key, $values)) { if (is_numeric($values[$key]) && $values[$key] != 1) { ViewAbstract::setDefaultLayoutEnabled(false); } } $key = 'template_extension'; if (array_key_exists($key, $values)) { NameManager::setTemplateExtension($values[$key]); } } if (array_key_exists('request', $ini)) { $values = $ini['request']; $key = 'auto_trim'; if (array_key_exists($key, $values)) { if (is_numeric($values[$key]) && $values[$key] == 1) { Request::setAutoTrim(true); } } } if (array_key_exists('database', $ini)) { $values = $ini['database']; $key = 'is_singleton'; if (array_key_exists($key, $values)) { if (is_numeric($values[$key]) && $values[$key] == 0) { Db::setIsSingleton(false); } } } if (array_key_exists('logger', $ini)) { Loader::load('Logger', 'utility'); $values = $ini['logger']; $key = 'system_log'; if (array_key_exists($key, $values)) { Logger::setLogName($values[$key]); } $key = 'query_log'; if (array_key_exists($key, $values)) { Logger::setLogName($values[$key], 'query'); Db::enableLogging('query'); } $key = 'output_level'; if (array_key_exists($key, $values)) { $val = strtolower(trim($values[$key])); if (is_numeric($val) == false) { $levels = array('debug' => LogLevel::DEBUG, 'info' => LogLevel::INFO, 'warn' => LogLevel::WARN, 'error' => LogLevel::ERROR, 'except' => LogLevel::EXCEPT); if (array_key_exists($val, $levels)) { $val = $levels[$val]; } else { $val = LogLevel::NO_OUTPUT; } } Logger::setOutputLevel($val, 'query'); } $key = 'max_line'; if (array_key_exists($key, $values)) { Logger::setMaxLine($values[$key]); } $key = 'max_generation'; if (array_key_exists($key, $values)) { Logger::setGeneration($values[$key]); } } if (array_key_exists('loader', $ini)) { $values = $ini['loader']; $key = 'autoload_dirs'; if (array_key_exists($key, $values)) { $dirs = explode(',', $values[$key]); Loader::addAutoloadDirectory($dirs); } } return true; }
* Export the configurations by MAC address and file type */ $access_role = "reader"; require_once "access.php"; require_once "lib/validate.php"; Header("Content-Type: text/plain; charset=UTF-8"); if ($_GET["type"] == "sig") { echo "voipconf\n"; exit(0); } if (($mac = valid_mac($_GET["mac"])) === false) { exit(1); } require_once "lib/ini.php"; $chan = new Ini(); $chan->load($g_chan_sync); foreach ($chan->sections() as $user) { if ($chan->get($user, "mac") == $mac) { $username = $user; break; } } if (!isset($username)) { exit(1); } switch ($_GET["type"]) { case "sbo": ?> [<?php echo $username; ?>
/** * Initialize validator * * @return void */ public function initValidator() { $ini = Ini::load('validate.ini', 'error_message'); if ($ini !== false) { Validator::setDefaultErrorMessage($ini); } if (array_key_exists($this->action, $this->validateRules)) { $this->validator->setRules($this->validateRules[$this->action]); } }
$usr->add($model["username"], $gateway); } $ael = new ExtAel(); $ael->load($g_ext_ael); if (isset($old_user)) { $ael->delete($old_user); } $ael->add($model["username"]); $chan->dump($g_chan_sync); $sip->dump($g_sip); $usr->dump($g_ext_usr); $ael->dump($g_ext_ael); reload_all($g_vpn); header("Location: " . dirname($_SERVER["PHP_SELF"]) . "/list.php"); exit; } // load generic info by mac $ini = new Ini(); $ini->load($g_chan_sync); foreach ($ini->sections() as $user) { if ($ini->get($user, "mac") == $model["mac"]) { $model["username"] = $ini->get($user, "authname"); $model["password"] = $ini->get($user, "secret"); break; } } // load switch info by username $model["switch"] = get_switch($g_sip, $model["username"]); // load gateway info by username $model["gateway"] = get_gateway($g_ext_usr, $model["username"]); render("Edit", "edit", $model);
/** * Get params as url path separated by "/" when mod rewrite enabled * * @param string $basePath * @return void */ protected function _getParamsRewrite($basePath) { // get path from url $paramStr = trim($_SERVER['REQUEST_URI'], '/'); $paramStr = str_replace(trim($basePath, '/'), '', $paramStr); $paramStr = str_replace('index.php', '', $paramStr); $paramStr = preg_replace('/\\?.*/', '', $paramStr); $paramStr = trim($paramStr, '/'); $controller = ''; $action = ''; // read routing setting by "routing.ini", if exists. Loader::load('Ini', 'core'); $ini = Ini::load('routing.ini'); if ($ini !== false) { foreach ($ini as $setting) { if (!isset($setting['request'])) { continue; } // Check request path matching $match = false; $requests = explode(',', $setting['request']); foreach ($requests as $request) { $req = trim(trim($request), '/'); if ($req == '*') { $match = true; } else { if ($req == '') { if ($paramStr == '') { $match = true; } } else { // Segment match $req = str_replace('*/', '[^/]+/', $req); // Forward match $req = preg_replace('|/\\*$|', '/.*', $req); // If setting of "request" section is contained in url, enable setting of correspond section of routing.ini if (preg_match('|^' . $req . '$|', $paramStr)) { $match = true; } } } } // Get setting of route when a request path matches if ($match) { foreach ($setting as $key => $val) { if ($key == 'default_controller') { $this->_controller = $val; } else { if ($key == 'default_action') { $this->_action = $val; } else { if ($key == 'controller') { $controller = $val; } else { if ($key == 'action') { $action = $val; } else { if ($key == 'route') { $this->_routingPath = trim($val, '/'); } else { $this->_params[$key] = $val; } } } } } } break; } } } // Explode "route" setting by "/" $this->_routingPath = preg_replace('/dir\\//', '', $this->_routingPath); $routingParams = explode('/', $this->_routingPath); // Explode url parameter by "/" $params = array(); if ($paramStr !== '') { $params = explode('/', $paramStr); } if ($this->_subControllerEnabled) { $params = $this->_getSubdirRemovedParams($params); } $i = 0; foreach ($params as $idx => $param) { if (array_key_exists($idx, $routingParams)) { $key = $routingParams[$idx]; if ($key == 'dir') { continue; } else { if ($key == 'controller') { if ($controller == '') { $controller = $param; } } else { if ($key == 'action') { if ($action == '') { $action = $param; } } else { if (!isset($this->_params[$key]) || ($this->_params[$key] = '')) { $this->_params[$key] = $param; $i++; } } } } } else { $key = $i; $val = $param; if (strpos($param, '=')) { $splited = explode('=', $param); $key = $splited[0]; $val = $splited[1]; } $this->_params[$key] = $val; $i++; } } if ($controller != '') { $this->_controller = $controller; } if ($action != '') { $this->_action = $action; } }
/** * Execute authorization by the authorization file "auth.ini" * * @param boolean $crypt * @return boolean */ public function file($crypt = false) { if ($this->_inputedUserId == null) { self::_showInput(); } $conf = Ini::load('auth.ini', 'basic_auth'); if ($conf === false) { self::_deny(); } foreach ($conf as $userId => $password) { $res = false; if ($crypt) { $res = $this->crypt($userId, $password); } else { $res = $this->plain($userId, $password); } if ($res === true) { break; } } return true; }