From: Marcin Haba Date: Tue, 5 Jan 2016 03:15:11 +0000 (+0100) Subject: baculum: Tweak comments and variables naming X-Git-Tag: Release-7.4.0~38 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=7e78ae764ffee2191dfc3922667388312087cf00;p=bacula%2Fbacula baculum: Tweak comments and variables naming --- diff --git a/gui/baculum/protected/Class/API.php b/gui/baculum/protected/Class/API.php index 9f631fd1f0..bab030c679 100644 --- a/gui/baculum/protected/Class/API.php +++ b/gui/baculum/protected/Class/API.php @@ -3,7 +3,7 @@ * Bacula(R) - The Network Backup Solution * Baculum - Bacula web interface * - * Copyright (C) 2013-2015 Marcin Haba + * Copyright (C) 2013-2016 Marcin Haba * * The main author of Baculum is Marcin Haba. * The original author of Bacula is Kern Sibbald, with contributions @@ -36,16 +36,18 @@ class API extends TModule { /** * Store configuration data from settings file + * * @access protected */ - protected $appCfg; + protected $app_cfg; /** * These errors are allowed in API response and they do not cause * disturb application working (no direction to error page) + * * @access private */ - private $allowedErrors = array( + private $allowed_errors = array( GenericError::ERROR_NO_ERRORS, BconsoleError::ERROR_INVALID_COMMAND, PoolError::ERROR_NO_VOLUMES_IN_POOL_TO_UPDATE @@ -54,12 +56,13 @@ class API extends TModule { /** * Get connection request handler. * For data requests is used cURL interface. + * * @access public * @return resource connection handler on success, false on errors */ public function getConnection() { $ch = curl_init(); - $userpwd = sprintf('%s:%s', $this->appCfg['baculum']['login'], $this->appCfg['baculum']['password']); + $userpwd = sprintf('%s:%s', $this->app_cfg['baculum']['login'], $this->app_cfg['baculum']['password']); curl_setopt($ch, CURLOPT_USERPWD, $userpwd); curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); @@ -71,6 +74,7 @@ class API extends TModule { /** * Get API specific headers used in HTTP requests. + * * @access private * @return API specific headers */ @@ -86,16 +90,18 @@ class API extends TModule { /** * Initializes API module (framework module constructor) + * * @access public * @param TXmlElement $config API module configuration */ public function init($config) { $this->initSessionCache(); - $this->appCfg = $this->Application->getModule('configuration')->getApplicationConfig(); + $this->app_cfg = $this->Application->getModule('configuration')->getApplicationConfig(); } /** * Get URL to use by internal API client's request. + * * @access private * @return string URL to internal API server */ @@ -113,6 +119,7 @@ class API extends TModule { /** * Set URL parameters and prepare URL to request send. + * * @access private * @param string &$url reference to URL string variable */ @@ -134,6 +141,7 @@ class API extends TModule { /** * Internal API GET request. + * * @access public * @param array $params GET params to send in request * @param bool $use_cache if true then try to use session cache, if false then always use fresh data @@ -165,6 +173,7 @@ class API extends TModule { /** * Internal API SET request. + * * @access public * @param array $params GET params to send in request * @param array $options POST params to send in request @@ -190,6 +199,7 @@ class API extends TModule { /** * Internal API CREATE request. + * * @access public * @param array $params GET params to send in request * @param array $options POST params to send in request @@ -211,6 +221,7 @@ class API extends TModule { /** * Internal API REMOVE request. + * * @access public * @param array $params GET params to send in request * @return object stdClass with request result as two properties: 'output' and 'error' @@ -230,6 +241,7 @@ class API extends TModule { /** * Initially parse and prepare every Internal API response. * If a error occurs then redirect to appropriate error page. + * * @access private * @param string $result response output as JSON string (not object yet) * @return object stdClass parsed response with two top level properties 'output' and 'error' @@ -250,7 +262,7 @@ class API extends TModule { $error = null; if(is_object($resource) && property_exists($resource, 'error')) { - if(!in_array($resource->error, $this->allowedErrors)) { + if(!in_array($resource->error, $this->allowed_errors)) { $error = $resource->error; } } else { @@ -280,12 +292,26 @@ class API extends TModule { return $resource; } + /** + * Initialize session cache. + * + * @access public + * @param bool $force if true then cache is force initialized + * @return none + */ public function initSessionCache($force = false) { if (!isset($_SESSION) || !array_key_exists('cache', $_SESSION) || !is_array($_SESSION['cache']) || $force === true) { $_SESSION['cache'] = array(); } } + /** + * Get session cache value by params. + * + * @access private + * @param array $params command parameters as numeric array + * @return mixed if cache exists then returned is cached data, otherwise null + */ private function getSessionCache(array $params) { $cached = null; $key = $this->getSessionKey($params); @@ -295,17 +321,39 @@ class API extends TModule { return $cached; } + /** + * Save data to session cache. + * + * @access private + * @param array $params command parameters as numeric array + * @param mixed $value value to save in cache + * @return none + */ private function setSessionCache(array $params, $value) { $key = $this->getSessionKey($params); $_SESSION['cache'][$key] = $value; } + /** + * Get session key by command parameters. + * + * @access private + * @param array $params command parameters as numeric array + * @return string session key for given command + */ private function getSessionKey(array $params) { $key = implode(';', $params); $key = base64_encode($key); return $key; } + /** + * Check if session key exists in session cache. + * + * @access private + * @param string $key session key + * @return bool true if session key exists, otherwise false + */ private function isSessionValue($key) { $is_value = array_key_exists($key, $_SESSION['cache']); return $is_value; diff --git a/gui/baculum/protected/Class/ConfigurationManager.php b/gui/baculum/protected/Class/ConfigurationManager.php index 7995754a58..73608a6933 100644 --- a/gui/baculum/protected/Class/ConfigurationManager.php +++ b/gui/baculum/protected/Class/ConfigurationManager.php @@ -84,12 +84,12 @@ class ConfigurationManager extends TModule public function getDbNameByType($type) { $type = (string) $type; switch($type) { - case self::PGSQL: $dbName = self::PGSQL_NAME; break; - case self::MYSQL: $dbName = self::MYSQL_NAME; break; - case self::SQLITE: $dbName = self::SQLITE_NAME; break; - default: $dbName = null; break; + case self::PGSQL: $db_name = self::PGSQL_NAME; break; + case self::MYSQL: $db_name = self::MYSQL_NAME; break; + case self::SQLITE: $db_name = self::SQLITE_NAME; break; + default: $db_name = null; break; } - return $dbName; + return $db_name; } /** @@ -151,8 +151,8 @@ class ConfigurationManager extends TModule * @return boolean true if config save is successfully, false if config save is failure */ public function setApplicationConfig(array $config) { - $cfgFile = Prado::getPathOfNamespace(self::CONFIG_FILE, '.conf'); - return ($this->Application->getModule('misc')->writeINIFile($cfgFile, $config) != false); + $cfg_file = Prado::getPathOfNamespace(self::CONFIG_FILE, '.conf'); + return ($this->Application->getModule('misc')->writeINIFile($cfg_file, $config) != false); } /** @@ -162,8 +162,8 @@ class ConfigurationManager extends TModule * @return array application configuration */ public static function getApplicationConfig() { - $cfgFile = Prado::getPathOfNamespace(self::CONFIG_FILE, '.conf'); - return Miscellaneous::parseINIFile($cfgFile); + $cfg_file = Prado::getPathOfNamespace(self::CONFIG_FILE, '.conf'); + return Miscellaneous::parseINIFile($cfg_file); } /** @@ -204,39 +204,39 @@ class ConfigurationManager extends TModule * @access public * @param string $user username * @param string $password user's password - * @param boolean $firstUsage determine if it is first saved user during first Baculum run - * @param mixed $oldUser previous username before change + * @param boolean $first_usage determine if it is first saved user during first Baculum run + * @param mixed $old_user previous username before change * @return boolean true if user saved successfully, otherwise false */ - public function setUsersConfig($user, $password, $firstUsage = false, $oldUser = null) { - if ($firstUsage === true) { + public function setUsersConfig($user, $password, $first_usage = false, $old_user = null) { + if ($first_usage === true) { $this->clearUsersConfig(); } - $allUsers = $this->getAllUsers(); + $all_users = $this->getAllUsers(); $password = $this->getCryptedPassword($password); - $userExists = array_key_exists($user, $allUsers); + $userExists = array_key_exists($user, $all_users); if ($userExists === true) { // update user password; - $allUsers[$user] = $password; + $all_users[$user] = $password; } - if (!is_null($oldUser) && $oldUser !== $user) { + if (!is_null($old_user) && $old_user !== $user) { // delete old username with password from configuration file - if (array_key_exists($oldUser, $allUsers)) { - unset($allUsers[$oldUser]); + if (array_key_exists($old_user, $all_users)) { + unset($all_users[$old_user]); } } // add new user if does not exist if ($userExists === false) { - $allUsers[$user] = $password; + $all_users[$user] = $password; } - $result = $this->saveUserConfig($allUsers); + $result = $this->saveUserConfig($all_users); return $result; } @@ -249,18 +249,18 @@ class ConfigurationManager extends TModule * @return array users/passwords list */ public function getAllUsers() { - $allUsers = array(); + $all_users = array(); if ($this->isUsersConfig() === true) { - $usersFile = Prado::getPathOfNamespace(self::USERS_FILE, '.users'); - $users = file($usersFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); + $users_file = Prado::getPathOfNamespace(self::USERS_FILE, '.users'); + $users = file($users_file, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); for($i = 0; $i < count($users); $i++) { if (preg_match("/^(?P\S+)\:(?P\S+)$/", $users[$i], $match) === 1) { - $allUsers[$match['user']] = $match['hash']; + $all_users[$match['user']] = $match['hash']; } } } - return $allUsers; + return $all_users; } /** @@ -269,19 +269,19 @@ class ConfigurationManager extends TModule * and encrypted passwords as values. * * @access public - * @param array $allUsers users/passwords list + * @param array $all_users users/passwords list * @return boolean true if users file saved successfully, otherwise false */ - public function saveUserConfig($allUsers) { + public function saveUserConfig($all_users) { $users = array(); - foreach ($allUsers as $user => $pwd) { + foreach ($all_users as $user => $pwd) { $users[] = "$user:$pwd"; } - $usersFile = Prado::getPathOfNamespace(self::USERS_FILE, '.users'); + $users_file = Prado::getPathOfNamespace(self::USERS_FILE, '.users'); $usersToFile = implode("\n", $users); $old_umask = umask(0); umask(0077); - $result = file_put_contents($usersFile, $usersToFile) !== false; + $result = file_put_contents($users_file, $usersToFile) !== false; umask($old_umask); return $result; } @@ -297,10 +297,10 @@ class ConfigurationManager extends TModule */ public function removeUser($username) { $result = false; - $allUsers = $this->getAllUsers(); - if (array_key_exists($username, $allUsers)) { - unset($allUsers[$username]); - $result = $this->saveUserConfig($allUsers); + $all_users = $this->getAllUsers(); + if (array_key_exists($username, $all_users)) { + unset($all_users[$username]); + $result = $this->saveUserConfig($all_users); } return $result; } @@ -322,8 +322,8 @@ class ConfigurationManager extends TModule * @return boolean true if file cleared successfully, otherwise false */ public function clearUsersConfig() { - $usersFile = Prado::getPathOfNamespace(self::USERS_FILE, '.users'); - $result = file_put_contents($usersFile, '') !== false; + $users_file = Prado::getPathOfNamespace(self::USERS_FILE, '.users'); + $result = file_put_contents($users_file, '') !== false; return $result; } @@ -343,9 +343,9 @@ class ConfigurationManager extends TModule * @return none */ public function switchToUser($http_protocol, $host, $port, $user, $password) { - $urlPrefix = $this->Application->getModule('friendly-url')->getUrlPrefix(); - $location = sprintf("%s://%s:%s@%s:%d%s", $http_protocol, $user, $password, $host, $port, $urlPrefix); - $refresh_url = sprintf("%s://%s:%d%s", $http_protocol, $host, $port, $urlPrefix); + $url_prefix = $this->Application->getModule('friendly-url')->getUrlPrefix(); + $location = sprintf("%s://%s:%s@%s:%d%s", $http_protocol, $user, $password, $host, $port, $url_prefix); + $refresh_url = sprintf("%s://%s:%d%s", $http_protocol, $host, $port, $url_prefix); /** * Refresh page is required due to lack of auth data in $_SERVER superglobal array