diff options
| author | 2021-01-02 21:20:19 +0100 | |
|---|---|---|
| committer | 2021-01-02 21:20:19 +0100 | |
| commit | 9c6682e7edf8cbad828088cbeeef66c7ecefdd9a (patch) | |
| tree | c8c8a6ba34d49d22497a14ddaf18ae97d8cd5bb1 /app | |
| parent | 7bc2cc5825547f5b5cf15005fda937e06065b45d (diff) | |
Avoid manual initialisations of system or user configuration (#3070)
* Avoid manual intialisations of system or user configuration
More consistent use of Context
* Simplify FreshRSS_Context::initUser
* Remove a few manual get_user_configuration
* A bit of debugging
* Fix context user init
* Fix install
* Fix concurrency
Concurrent requests could lead to bad race condition
* Fix actualize cron
Fix case when system i initialised several times
Diffstat (limited to 'app')
| -rw-r--r-- | app/Controllers/authController.php | 25 | ||||
| -rw-r--r-- | app/Controllers/errorController.php | 2 | ||||
| -rwxr-xr-x | app/Controllers/javascriptController.php | 5 | ||||
| -rw-r--r-- | app/FreshRSS.php | 33 | ||||
| -rw-r--r-- | app/Models/Auth.php | 39 | ||||
| -rw-r--r-- | app/Models/Context.php | 60 | ||||
| -rw-r--r-- | app/Models/Entry.php | 7 | ||||
| -rw-r--r-- | app/Models/Factory.php | 18 | ||||
| -rw-r--r-- | app/Models/FormAuth.php | 12 | ||||
| -rwxr-xr-x | app/actualize_script.php | 29 | ||||
| -rw-r--r-- | app/install.php | 44 |
11 files changed, 146 insertions, 128 deletions
diff --git a/app/Controllers/authController.php b/app/Controllers/authController.php index 342c577e2..403c92790 100644 --- a/app/Controllers/authController.php +++ b/app/Controllers/authController.php @@ -112,8 +112,7 @@ class FreshRSS_auth_Controller extends Minz_ActionController { Minz_View::prependTitle(_t('gen.auth.login') . ' ยท '); Minz_View::appendScript(Minz_Url::display('/scripts/bcrypt.min.js?' . @filemtime(PUBLIC_PATH . '/scripts/bcrypt.min.js'))); - $conf = Minz_Configuration::get('system'); - $limits = $conf->limits; + $limits = FreshRSS_Context::$system_conf->limits; $this->view->cookie_days = round($limits['cookie_duration'] / 86400, 1); $isPOST = Minz_Request::isPost() && !Minz_Session::param('POST_to_GET'); @@ -124,38 +123,38 @@ class FreshRSS_auth_Controller extends Minz_ActionController { $username = Minz_Request::param('username', ''); $challenge = Minz_Request::param('challenge', ''); - $conf = get_user_configuration($username); - if ($conf == null) { + FreshRSS_Context::initUser($username); + if (FreshRSS_Context::$user_conf == null) { //We do not test here whether the user exists, so most likely an internal error. Minz_Error::error(403, array(_t('feedback.auth.login.invalid')), false); return; } - if (!$conf->enabled) { + if (!FreshRSS_Context::$user_conf->enabled) { Minz_Error::error(403, array(_t('feedback.auth.login.invalid')), false); return; } $ok = FreshRSS_FormAuth::checkCredentials( - $username, $conf->passwordHash, $nonce, $challenge + $username, FreshRSS_Context::$user_conf->passwordHash, $nonce, $challenge ); if ($ok) { // Set session parameter to give access to the user. Minz_Session::_params([ 'currentUser' => $username, - 'passwordHash' => $conf->passwordHash, + 'passwordHash' => FreshRSS_Context::$user_conf->passwordHash, 'csrf' => false, ]); FreshRSS_Auth::giveAccess(); // Set cookie parameter if nedded. if (Minz_Request::param('keep_logged_in')) { - FreshRSS_FormAuth::makeCookie($username, $conf->passwordHash); + FreshRSS_FormAuth::makeCookie($username, FreshRSS_Context::$user_conf->passwordHash); } else { FreshRSS_FormAuth::deleteCookie(); } - Minz_Translate::init($conf->language); + Minz_Translate::init(FreshRSS_Context::$user_conf->language); // All is good, go back to the index. Minz_Request::good(_t('feedback.auth.login.success'), @@ -183,12 +182,12 @@ class FreshRSS_auth_Controller extends Minz_ActionController { FreshRSS_FormAuth::deleteCookie(); - $conf = get_user_configuration($username); - if ($conf == null) { + FreshRSS_Context::initUser($username); + if (FreshRSS_Context::$user_conf == null) { return; } - $s = $conf->passwordHash; + $s = FreshRSS_Context::$user_conf->passwordHash; $ok = password_verify($password, $s); unset($password); if ($ok) { @@ -199,7 +198,7 @@ class FreshRSS_auth_Controller extends Minz_ActionController { ]); FreshRSS_Auth::giveAccess(); - Minz_Translate::init($conf->language); + Minz_Translate::init(FreshRSS_Context::$user_conf->language); Minz_Request::good(_t('feedback.auth.login.success'), array('c' => 'index', 'a' => 'index')); diff --git a/app/Controllers/errorController.php b/app/Controllers/errorController.php index a5f901fd4..ce6024406 100644 --- a/app/Controllers/errorController.php +++ b/app/Controllers/errorController.php @@ -33,10 +33,12 @@ class FreshRSS_error_Controller extends Minz_ActionController { case 500: header('HTTP/1.1 500 Internal Server Error'); $this->view->code = 'Error 500 - Internal Server Error'; + $this->view->errorMessage = 'Error 500 - Internal Server Error'; break; case 503: header('HTTP/1.1 503 Service Unavailable'); $this->view->code = 'Error 503 - Service Unavailable'; + $this->view->errorMessage = 'Error 503 - Service Unavailable'; break; case 404: default: diff --git a/app/Controllers/javascriptController.php b/app/Controllers/javascriptController.php index b22e2c127..40f0fc19a 100755 --- a/app/Controllers/javascriptController.php +++ b/app/Controllers/javascriptController.php @@ -29,11 +29,10 @@ class FreshRSS_javascript_Controller extends Minz_ActionController { header('Pragma: no-cache'); $user = isset($_GET['user']) ? $_GET['user'] : ''; - if (FreshRSS_user_Controller::checkUsername($user)) { + if (FreshRSS_Context::initUser($user)) { try { $salt = FreshRSS_Context::$system_conf->salt; - $conf = get_user_configuration($user); - $s = $conf->passwordHash; + $s = FreshRSS_Context::$user_conf->passwordHash; if (strlen($s) >= 60) { $this->view->salt1 = substr($s, 0, 29); //CRYPT_BLOWFISH Salt: "$2a$", a two digit cost parameter, "$", and 22 characters from the alphabet "./0-9A-Za-z". $this->view->nonce = sha1($salt . uniqid(mt_rand(), true)); diff --git a/app/FreshRSS.php b/app/FreshRSS.php index 5bf0011d0..fe55427c0 100644 --- a/app/FreshRSS.php +++ b/app/FreshRSS.php @@ -24,10 +24,12 @@ class FreshRSS extends Minz_FrontController { Minz_Session::init('FreshRSS'); } - // Register the configuration setter for the system configuration - $configuration_setter = new FreshRSS_ConfigurationSetter(); - $system_conf = Minz_Configuration::get('system'); - $system_conf->_configurationSetter($configuration_setter); + FreshRSS_Context::initSystem(); + if (FreshRSS_Context::$system_conf == null) { + $message = 'Error during context system init!'; + Minz_Error::error(500, [$message], false); + die($message); + } // Load list of extensions and enable the "system" ones. Minz_ExtensionManager::init(); @@ -35,26 +37,25 @@ class FreshRSS extends Minz_FrontController { // Auth has to be initialized before using currentUser session parameter // because it's this part which create this parameter. self::initAuth(); + if (FreshRSS_Context::$user_conf == null) { + FreshRSS_Context::initUser(); + } + if (FreshRSS_Context::$user_conf == null) { + $message = 'Error during context user init!'; + Minz_Error::error(500, [$message], false); + die($message); + } - // Then, register the user configuration and use the configuration setter - // created above. - $current_user = Minz_Session::param('currentUser', '_'); - Minz_Configuration::register('user', - join_path(USERS_PATH, $current_user, 'config.php'), - join_path(FRESHRSS_PATH, 'config-user.default.php'), - $configuration_setter); - - // Finish to initialize the other FreshRSS / Minz components. - FreshRSS_Context::init(); + // Complete initialization of the other FreshRSS / Minz components. self::initI18n(); self::loadNotifications(); // Enable extensions for the current (logged) user. - if (FreshRSS_Auth::hasAccess() || $system_conf->allow_anonymous) { + if (FreshRSS_Auth::hasAccess() || FreshRSS_Context::$system_conf->allow_anonymous) { $ext_list = FreshRSS_Context::$user_conf->extensions_enabled; Minz_ExtensionManager::enableByList($ext_list); } - if ($system_conf->force_email_validation && !FreshRSS_Auth::hasAccess('admin')) { + if (FreshRSS_Context::$system_conf->force_email_validation && !FreshRSS_Auth::hasAccess('admin')) { self::checkEmailValidated(); } diff --git a/app/Models/Auth.php b/app/Models/Auth.php index 9b18b8259..709a80f84 100644 --- a/app/Models/Auth.php +++ b/app/Models/Auth.php @@ -22,9 +22,8 @@ class FreshRSS_Auth { self::$login_ok = Minz_Session::param('loginOk', false); $current_user = Minz_Session::param('currentUser', ''); - if ($current_user === '') { - $conf = Minz_Configuration::get('system'); - $current_user = $conf->default_user; + if ($current_user == '') { + $current_user = FreshRSS_Context::$system_conf->default_user; Minz_Session::_params([ 'currentUser' => $current_user, 'csrf' => false, @@ -51,7 +50,6 @@ class FreshRSS_Auth { * @return boolean true if user can be connected, false else. */ private static function accessControl() { - FreshRSS_Context::$system_conf = Minz_Configuration::get('system'); $auth_type = FreshRSS_Context::$system_conf->auth_type; switch ($auth_type) { case 'form': @@ -103,19 +101,18 @@ class FreshRSS_Auth { * Gives access to the current user. */ public static function giveAccess() { - $current_user = Minz_Session::param('currentUser'); - $user_conf = get_user_configuration($current_user); - if ($user_conf == null) { + FreshRSS_Context::initUser(); + if (FreshRSS_Context::$user_conf == null) { self::$login_ok = false; return false; } - $system_conf = Minz_Configuration::get('system'); - switch ($system_conf->auth_type) { + switch (FreshRSS_Context::$system_conf->auth_type) { case 'form': - self::$login_ok = Minz_Session::param('passwordHash') === $user_conf->passwordHash; + self::$login_ok = Minz_Session::param('passwordHash') === FreshRSS_Context::$user_conf->passwordHash; break; case 'http_auth': + $current_user = Minz_Session::param('currentUser'); self::$login_ok = strcasecmp($current_user, httpAuthUser()) === 0; break; case 'none': @@ -140,11 +137,12 @@ class FreshRSS_Auth { * @return boolean true if user has corresponding access, false else. */ public static function hasAccess($scope = 'general') { - $systemConfiguration = Minz_Configuration::get('system'); + if (FreshRSS_Context::$user_conf == null) { + return false; + } $currentUser = Minz_Session::param('currentUser'); - $userConfiguration = get_user_configuration($currentUser); - $isAdmin = $userConfiguration && $userConfiguration->is_admin; - $default_user = $systemConfiguration->default_user; + $isAdmin = FreshRSS_Context::$user_conf->is_admin; + $default_user = FreshRSS_Context::$system_conf->default_user; $ok = self::$login_ok; switch ($scope) { case 'general': @@ -168,7 +166,6 @@ class FreshRSS_Auth { 'csrf' => false, 'REMOTE_USER' => false, ]); - $system_conf = Minz_Configuration::get('system'); $username = ''; $token_param = Minz_Request::param('token', ''); @@ -182,11 +179,11 @@ class FreshRSS_Auth { } } if ($username == '') { - $username = $system_conf->default_user; + $username = FreshRSS_Context::$system_conf->default_user; } Minz_Session::_param('currentUser', $username); - switch ($system_conf->auth_type) { + switch (FreshRSS_Context::$system_conf->auth_type) { case 'form': Minz_Session::_param('passwordHash'); FreshRSS_FormAuth::deleteCookie(); @@ -204,18 +201,14 @@ class FreshRSS_Auth { * Return if authentication is enabled on this instance of FRSS. */ public static function accessNeedsLogin() { - $conf = Minz_Configuration::get('system'); - $auth_type = $conf->auth_type; - return $auth_type !== 'none'; + return FreshRSS_Context::$system_conf->auth_type !== 'none'; } /** * Return if authentication requires a PHP action. */ public static function accessNeedsAction() { - $conf = Minz_Configuration::get('system'); - $auth_type = $conf->auth_type; - return $auth_type === 'form'; + return FreshRSS_Context::$system_conf->auth_type === 'form'; } public static function csrfToken() { diff --git a/app/Models/Context.php b/app/Models/Context.php index 8be73f407..1ca99a26d 100644 --- a/app/Models/Context.php +++ b/app/Models/Context.php @@ -43,14 +43,58 @@ class FreshRSS_Context { public static $isCli = false; /** - * Initialize the context. - * - * Set the correct configurations and $categories variables. + * Initialize the context for the global system. */ - public static function init() { - // Init configuration. - self::$system_conf = Minz_Configuration::get('system'); - self::$user_conf = Minz_Configuration::get('user'); + public static function initSystem($reload = false) { + if ($reload || FreshRSS_Context::$system_conf == null) { + //TODO: Keep in session what we need instead of always reloading from disk + Minz_Configuration::register('system', DATA_PATH . '/config.php', FRESHRSS_PATH . '/config.default.php'); + FreshRSS_Context::$system_conf = Minz_Configuration::get('system'); + // Register the configuration setter for the system configuration + $configurationSetter = new FreshRSS_ConfigurationSetter(); + FreshRSS_Context::$system_conf->_configurationSetter($configurationSetter); + } + return FreshRSS_Context::$system_conf; + } + + /** + * Initialize the context for the current user. + */ + public static function initUser($username = '') { + FreshRSS_Context::$user_conf = null; + if (!isset($_SESSION)) { + Minz_Session::init('FreshRSS'); + } + + Minz_Session::lock(); + if ($username == '') { + $username = Minz_Session::param('currentUser', ''); + } + if ($username === '_' || FreshRSS_user_Controller::checkUsername($username)) { + try { + //TODO: Keep in session what we need instead of always reloading from disk + Minz_Configuration::register('user', + USERS_PATH . '/' . $username . '/config.php', + FRESHRSS_PATH . '/config-user.default.php', + FreshRSS_Context::$system_conf->configurationSetter()); + + Minz_Session::_param('currentUser', $username); + FreshRSS_Context::$user_conf = Minz_Configuration::get('user'); + } catch (Exception $ex) { + Minz_Log::warning($ex->getMessage(), USERS_PATH . '/_/log.txt'); + } + } + if (FreshRSS_Context::$user_conf == null) { + Minz_Session::_params([ + 'loginOk' => false, + 'currentUser' => false, + ]); + } + Minz_Session::unlock(); + + if (FreshRSS_Context::$user_conf == null) { + return false; + } //Legacy $oldEntries = (int)FreshRSS_Context::$user_conf->param('old_entries', 0); @@ -74,6 +118,8 @@ class FreshRSS_Context { if (!in_array(FreshRSS_Context::$user_conf->display_categories, [ 'active', 'remember', 'all', 'none' ], true)) { FreshRSS_Context::$user_conf->display_categories = FreshRSS_Context::$user_conf->display_categories === true ? 'all' : 'active'; } + + return FreshRSS_Context::$user_conf; } /** diff --git a/app/Models/Entry.php b/app/Models/Entry.php index ed0c1245c..96e1cf3a6 100644 --- a/app/Models/Entry.php +++ b/app/Models/Entry.php @@ -355,11 +355,10 @@ class FreshRSS_Entry extends Minz_Model { } public static function getContentByParsing($url, $path, $attributes = array(), $maxRedirs = 3) { - $system_conf = Minz_Configuration::get('system'); - $limits = $system_conf->limits; + $limits = FreshRSS_Context::$system_conf->limits; $feed_timeout = empty($attributes['timeout']) ? 0 : intval($attributes['timeout']); - if ($system_conf->simplepie_syslog_enabled) { + if (FreshRSS_Context::$system_conf->simplepie_syslog_enabled) { syslog(LOG_INFO, 'FreshRSS GET ' . SimplePie_Misc::url_remove_credentials($url)); } @@ -377,7 +376,7 @@ class FreshRSS_Entry extends Minz_Model { CURLOPT_FOLLOWLOCATION => true, CURLOPT_ENCODING => '', //Enable all encodings ]); - curl_setopt_array($ch, $system_conf->curl_options); + curl_setopt_array($ch, FreshRSS_Context::$system_conf->curl_options); if (isset($attributes['ssl_verify'])) { curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, $attributes['ssl_verify'] ? 2 : 0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $attributes['ssl_verify'] ? true : false); diff --git a/app/Models/Factory.php b/app/Models/Factory.php index 69885c205..308ff2864 100644 --- a/app/Models/Factory.php +++ b/app/Models/Factory.php @@ -7,8 +7,7 @@ class FreshRSS_Factory { } public static function createCategoryDao($username = null) { - $conf = Minz_Configuration::get('system'); - switch ($conf->db['type']) { + switch (FreshRSS_Context::$system_conf->db['type']) { case 'sqlite': return new FreshRSS_CategoryDAOSQLite($username); default: @@ -17,8 +16,7 @@ class FreshRSS_Factory { } public static function createFeedDao($username = null) { - $conf = Minz_Configuration::get('system'); - switch ($conf->db['type']) { + switch (FreshRSS_Context::$system_conf->db['type']) { case 'sqlite': return new FreshRSS_FeedDAOSQLite($username); default: @@ -27,8 +25,7 @@ class FreshRSS_Factory { } public static function createEntryDao($username = null) { - $conf = Minz_Configuration::get('system'); - switch ($conf->db['type']) { + switch (FreshRSS_Context::$system_conf->db['type']) { case 'sqlite': return new FreshRSS_EntryDAOSQLite($username); case 'pgsql': @@ -39,8 +36,7 @@ class FreshRSS_Factory { } public static function createTagDao($username = null) { - $conf = Minz_Configuration::get('system'); - switch ($conf->db['type']) { + switch (FreshRSS_Context::$system_conf->db['type']) { case 'sqlite': return new FreshRSS_TagDAOSQLite($username); case 'pgsql': @@ -51,8 +47,7 @@ class FreshRSS_Factory { } public static function createStatsDAO($username = null) { - $conf = Minz_Configuration::get('system'); - switch ($conf->db['type']) { + switch (FreshRSS_Context::$system_conf->db['type']) { case 'sqlite': return new FreshRSS_StatsDAOSQLite($username); case 'pgsql': @@ -63,8 +58,7 @@ class FreshRSS_Factory { } public static function createDatabaseDAO($username = null) { - $conf = Minz_Configuration::get('system'); - switch ($conf->db['type']) { + switch (FreshRSS_Context::$system_conf->db['type']) { case 'sqlite': return new FreshRSS_DatabaseDAOSQLite($username); case 'pgsql': diff --git a/app/Models/FormAuth.php b/app/Models/FormAuth.php index 86742e2f2..1aca7c3d1 100644 --- a/app/Models/FormAuth.php +++ b/app/Models/FormAuth.php @@ -24,8 +24,7 @@ class FreshRSS_FormAuth { $token_file = DATA_PATH . '/tokens/' . $token . '.txt'; $mtime = @filemtime($token_file); - $conf = Minz_Configuration::get('system'); - $limits = $conf->limits; + $limits = FreshRSS_Context::$system_conf->limits; $cookie_duration = empty($limits['cookie_duration']) ? FreshRSS_Auth::DEFAULT_COOKIE_DURATION : $limits['cookie_duration']; if ($mtime + $cookie_duration < time()) { // Token has expired (> cookie_duration) or does not exist. @@ -43,8 +42,7 @@ class FreshRSS_FormAuth { private static function renewCookie($token) { $token_file = DATA_PATH . '/tokens/' . $token . '.txt'; if (touch($token_file)) { - $conf = Minz_Configuration::get('system'); - $limits = $conf->limits; + $limits = FreshRSS_Context::$system_conf->limits; $cookie_duration = empty($limits['cookie_duration']) ? FreshRSS_Auth::DEFAULT_COOKIE_DURATION : $limits['cookie_duration']; $expire = time() + $cookie_duration; Minz_Session::setLongTermCookie('FreshRSS_login', $token, $expire); @@ -54,9 +52,8 @@ class FreshRSS_FormAuth { } public static function makeCookie($username, $password_hash) { - $conf = Minz_Configuration::get('system'); do { - $token = sha1($conf->salt . $username . uniqid(mt_rand(), true)); + $token = sha1(FreshRSS_Context::$system_conf->salt . $username . uniqid(mt_rand(), true)); $token_file = DATA_PATH . '/tokens/' . $token . '.txt'; } while (file_exists($token_file)); @@ -80,8 +77,7 @@ class FreshRSS_FormAuth { } public static function purgeTokens() { - $conf = Minz_Configuration::get('system'); - $limits = $conf->limits; + $limits = FreshRSS_Context::$system_conf->limits; $cookie_duration = empty($limits['cookie_duration']) ? FreshRSS_Auth::DEFAULT_COOKIE_DURATION : $limits['cookie_duration']; $oldest = time() - $cookie_duration; foreach (new DirectoryIterator(DATA_PATH . '/tokens/') as $file_info) { diff --git a/app/actualize_script.php b/app/actualize_script.php index 18b7f99f8..8bbc45e41 100755 --- a/app/actualize_script.php +++ b/app/actualize_script.php @@ -32,39 +32,42 @@ $_SERVER['HTTP_HOST'] = ''; $app = new FreshRSS(); -$system_conf = Minz_Configuration::get('system'); -$system_conf->auth_type = 'none'; // avoid necessity to be logged in (not saved!) -define('SIMPLEPIE_SYSLOG_ENABLED', $system_conf->simplepie_syslog_enabled); +FreshRSS_Context::initSystem(); +FreshRSS_Context::$system_conf->auth_type = 'none'; // avoid necessity to be logged in (not saved!) +define('SIMPLEPIE_SYSLOG_ENABLED', FreshRSS_Context::$system_conf->simplepie_syslog_enabled); notice('FreshRSS starting feeds actualization at ' . $begin_date->format('c')); // make sure the PHP setup of the CLI environment is compatible with FreshRSS as well -performRequirementCheck($system_conf->db['type']); +performRequirementCheck(FreshRSS_Context::$system_conf->db['type']); // Create the list of users to actualize. // Users are processed in a random order but always start with default user $users = listUsers(); shuffle($users); -if ($system_conf->default_user !== '') { - array_unshift($users, $system_conf->default_user); +if (FreshRSS_Context::$system_conf->default_user !== '') { + array_unshift($users, FreshRSS_Context::$system_conf->default_user); $users = array_unique($users); } -$limits = $system_conf->limits; +$limits = FreshRSS_Context::$system_conf->limits; $min_last_activity = time() - $limits['max_inactivity']; foreach ($users as $user) { - if (!get_user_configuration($user)->enabled) { + FreshRSS_Context::initUser($user); + if (FreshRSS_Context::$user_conf == null) { + notice('Invalid user ' . $user); + continue; + } + if (!FreshRSS_Context::$user_conf->enabled) { notice('FreshRSS skip disabled user ' . $user); continue; } - if (($user !== $system_conf->default_user) && + if (($user !== FreshRSS_Context::$system_conf->default_user) && (FreshRSS_UserDAO::mtime($user) < $min_last_activity)) { notice('FreshRSS skip inactive user ' . $user); continue; } - Minz_Session::_param('currentUser', $user); - new Minz_ModelPdo($user); //TODO: FIXME: Quick-fix while waiting for a better FreshRSS() constructor/init FreshRSS_Auth::giveAccess(); $app->init(); notice('FreshRSS actualize ' . $user . '...'); @@ -78,10 +81,6 @@ foreach ($users as $user) { } } - Minz_Session::_params([ - 'currentUser' => '_', - 'loginOk' => false, - ]); gc_collect_cycles(); } diff --git a/app/install.php b/app/install.php index 418c72eba..bb7d9de9d 100644 --- a/app/install.php +++ b/app/install.php @@ -69,29 +69,21 @@ function saveStep1() { // with values from the previous installation // First, we try to get previous configurations - Minz_Configuration::register('system', - join_path(DATA_PATH, 'config.php'), - join_path(FRESHRSS_PATH, 'config.default.php')); - $system_conf = Minz_Configuration::get('system'); - - $current_user = $system_conf->default_user; - Minz_Configuration::register('user', - join_path(USERS_PATH, $current_user, 'config.php'), - join_path(FRESHRSS_PATH, 'config-user.default.php')); - $user_conf = Minz_Configuration::get('user'); + FreshRSS_Context::initSystem(); + FreshRSS_Context::initUser(FreshRSS_Context::$system_conf->default_user); // Then, we set $_SESSION vars Minz_Session::_params([ - 'title' => $system_conf->title, - 'auth_type' => $system_conf->auth_type, - 'default_user' => $current_user, - 'passwordHash' => $user_conf->passwordHash, - 'bd_type' => $system_conf->db['type'], - 'bd_host' => $system_conf->db['host'], - 'bd_user' => $system_conf->db['user'], - 'bd_password' => $system_conf->db['password'], - 'bd_base' => $system_conf->db['base'], - 'bd_prefix' => $system_conf->db['prefix'], + 'title' => FreshRSS_Context::$system_conf->title, + 'auth_type' => FreshRSS_Context::$system_conf->auth_type, + 'default_user' => Minz_Session::param('currentUser'), + 'passwordHash' => FreshRSS_Context::$user_conf->passwordHash, + 'bd_type' => FreshRSS_Context::$system_conf->db['type'], + 'bd_host' => FreshRSS_Context::$system_conf->db['host'], + 'bd_user' => FreshRSS_Context::$system_conf->db['user'], + 'bd_password' => FreshRSS_Context::$system_conf->db['password'], + 'bd_base' => FreshRSS_Context::$system_conf->db['base'], + 'bd_prefix' => FreshRSS_Context::$system_conf->db['prefix'], 'bd_error' => false, ]); @@ -159,8 +151,7 @@ function saveStep2() { opcache_reset(); } - Minz_Configuration::register('system', DATA_PATH . '/config.php', FRESHRSS_PATH . '/config.default.php'); - FreshRSS_Context::$system_conf = Minz_Configuration::get('system'); + FreshRSS_Context::initSystem(); $ok = false; try { @@ -211,13 +202,9 @@ function saveStep3() { return false; } - Minz_Configuration::register('system', DATA_PATH . '/config.php', FRESHRSS_PATH . '/config.default.php'); - FreshRSS_Context::$system_conf = Minz_Configuration::get('system'); + FreshRSS_Context::initSystem(); Minz_Translate::init(Minz_Session::param('language')); - FreshRSS_Context::$system_conf->default_user = Minz_Session::param('default_user'); - FreshRSS_Context::$system_conf->save(); - // Create default user files but first, we delete previous data to // avoid access right problems. recursive_unlink(USERS_PATH . '/' . Minz_Session::param('default_user')); @@ -242,6 +229,9 @@ function saveStep3() { return false; } + FreshRSS_Context::$system_conf->default_user = Minz_Session::param('default_user'); + FreshRSS_Context::$system_conf->save(); + header('Location: index.php?step=4'); } } |
