diff options
| author | 2021-01-02 21:20:19 +0100 | |
|---|---|---|
| committer | 2021-01-02 21:20:19 +0100 | |
| commit | 9c6682e7edf8cbad828088cbeeef66c7ecefdd9a (patch) | |
| tree | c8c8a6ba34d49d22497a14ddaf18ae97d8cd5bb1 /p/api | |
| 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 'p/api')
| -rw-r--r-- | p/api/fever.php | 9 | ||||
| -rw-r--r-- | p/api/greader.php | 29 | ||||
| -rw-r--r-- | p/api/index.php | 2 | ||||
| -rw-r--r-- | p/api/pshb.php | 16 |
4 files changed, 17 insertions, 39 deletions
diff --git a/p/api/fever.php b/p/api/fever.php index 64e6dfd65..ae9e45084 100644 --- a/p/api/fever.php +++ b/p/api/fever.php @@ -14,10 +14,9 @@ // BOOTSTRAP FreshRSS require(__DIR__ . '/../../constants.php'); require(LIB_PATH . '/lib_rss.php'); //Includes class autoloader -Minz_Configuration::register('system', DATA_PATH . '/config.php', FRESHRSS_PATH . '/config.default.php'); +FreshRSS_Context::initSystem(); // check if API is enabled globally -FreshRSS_Context::$system_conf = Minz_Configuration::get('system'); if (!FreshRSS_Context::$system_conf->api_enabled) { Minz_Log::warning('Fever API: serviceUnavailable() ' . debugInfo(), API_LOG); header('HTTP/1.1 503 Service Unavailable'); @@ -159,10 +158,8 @@ class FeverAPI $username = @file_get_contents(DATA_PATH . '/fever/.key-' . sha1(FreshRSS_Context::$system_conf->salt) . '-' . $feverKey . '.txt', false); if ($username != false) { $username = trim($username); - Minz_Session::_param('currentUser', $username); - $user_conf = get_user_configuration($username); - if ($user_conf != null && $feverKey === $user_conf->feverKey && $user_conf->enabled) { - FreshRSS_Context::$user_conf = $user_conf; + FreshRSS_Context::initUser($username); + if (FreshRSS_Context::$user_conf != null && $feverKey === FreshRSS_Context::$user_conf->feverKey && FreshRSS_Context::$user_conf->enabled) { Minz_Translate::init(FreshRSS_Context::$user_conf->language); $this->entryDAO = FreshRSS_Factory::createEntryDao(); $this->feedDAO = FreshRSS_Factory::createFeedDao(); diff --git a/p/api/greader.php b/p/api/greader.php index 55097cc9f..ad7a322bd 100644 --- a/p/api/greader.php +++ b/p/api/greader.php @@ -153,7 +153,7 @@ function authorizationToUser() { if (count($headerAuthX) === 2) { $user = $headerAuthX[0]; if (FreshRSS_user_Controller::checkUsername($user)) { - FreshRSS_Context::$user_conf = get_user_configuration($user); + FreshRSS_Context::initUser($user); if (FreshRSS_Context::$user_conf == null) { Minz_Log::warning('Invalid API user ' . $user . ': configuration cannot be found.'); unauthorized(); @@ -179,7 +179,7 @@ function authorizationToUser() { function clientLogin($email, $pass) { //http://web.archive.org/web/20130604091042/http://undoc.in/clientLogin.html if (FreshRSS_user_Controller::checkUsername($email)) { - FreshRSS_Context::$user_conf = get_user_configuration($email); + FreshRSS_Context::initUser($email); if (FreshRSS_Context::$user_conf == null) { Minz_Log::warning('Invalid API user ' . $email . ': configuration cannot be found.'); unauthorized(); @@ -922,10 +922,7 @@ if (count($pathInfos) < 3) { badRequest(); } -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_Log::debug('----------------------------------------------------------------', API_LOG); //Minz_Log::debug(debugInfo(), API_LOG); @@ -938,29 +935,23 @@ if (!FreshRSS_Context::$system_conf->api_enabled) { Minz_Session::init('FreshRSS', true); -$user = $pathInfos[1] === 'accounts' ? '' : authorizationToUser(); -FreshRSS_Context::$user_conf = null; -if ($user !== '') { - FreshRSS_Context::$user_conf = get_user_configuration($user); +if ($pathInfos[1] !== 'accounts') { + authorizationToUser(); +} +if (FreshRSS_Context::$user_conf != null) { + Minz_Translate::init(FreshRSS_Context::$user_conf->language); Minz_ExtensionManager::init(); - if (FreshRSS_Context::$user_conf != null) { - Minz_Translate::init(FreshRSS_Context::$user_conf->language); - Minz_ExtensionManager::enableByList(FreshRSS_Context::$user_conf->extensions_enabled); - } else { - Minz_Translate::init(); - } + Minz_ExtensionManager::enableByList(FreshRSS_Context::$user_conf->extensions_enabled); } else { Minz_Translate::init(); } -Minz_Session::_param('currentUser', $user); - if ($pathInfos[1] === 'accounts') { if (($pathInfos[2] === 'ClientLogin') && isset($_REQUEST['Email']) && isset($_REQUEST['Passwd'])) { clientLogin($_REQUEST['Email'], $_REQUEST['Passwd']); } } elseif ($pathInfos[1] === 'reader' && $pathInfos[2] === 'api' && isset($pathInfos[3]) && $pathInfos[3] === '0' && isset($pathInfos[4])) { - if ($user == '') { + if (Minz_Session::param('currentUser', '') == '') { unauthorized(); } $timestamp = isset($_GET['ck']) ? intval($_GET['ck']) : 0; //ck=[unix timestamp] : Use the current Unix time here, helps Google with caching. diff --git a/p/api/index.php b/p/api/index.php index d441099d7..6ca7e1b6d 100644 --- a/p/api/index.php +++ b/p/api/index.php @@ -10,7 +10,7 @@ <?php require(__DIR__ . '/../../constants.php'); require(LIB_PATH . '/lib_rss.php'); //Includes class autoloader -Minz_Configuration::register('system', DATA_PATH . '/config.php', FRESHRSS_PATH . '/config.default.php'); +FreshRSS_Context::initSystem(); echo json_encode(array( 'greader' => Minz_Url::display('/api/greader.php', 'php', true), 'fever' => Minz_Url::display('/api/fever.php', 'php', true), diff --git a/p/api/pshb.php b/p/api/pshb.php index 1e07c0f80..c2436d0ff 100644 --- a/p/api/pshb.php +++ b/p/api/pshb.php @@ -9,9 +9,8 @@ header('X-Content-Type-Options: nosniff'); $ORIGINAL_INPUT = file_get_contents('php://input', false, null, 0, MAX_PAYLOAD); -Minz_Configuration::register('system', DATA_PATH . '/config.php', FRESHRSS_PATH . '/config.default.php'); -$system_conf = Minz_Configuration::get('system'); -$system_conf->auth_type = 'none'; // avoid necessity to be logged in (not saved!) +FreshRSS_Context::initSystem(); +FreshRSS_Context::$system_conf->auth_type = 'none'; // avoid necessity to be logged in (not saved!) //Minz_Log::debug(print_r(array('_SERVER' => $_SERVER, '_GET' => $_GET, '_POST' => $_POST, 'INPUT' => $ORIGINAL_INPUT), true), PSHB_LOG); @@ -58,10 +57,6 @@ if (empty($users)) { $url = base64url_decode($canonical64); Minz_Log::warning('Warning: Nobody subscribes to this feed anymore!: ' . $url, PSHB_LOG); unlink('../../keys/' . $key . '.txt'); - Minz_Configuration::register('system', - DATA_PATH . '/config.php', - FRESHRSS_PATH . '/config.default.php'); - FreshRSS_Context::$system_conf = Minz_Configuration::get('system'); $feed = new FreshRSS_Feed($url); $feed->pubSubHubbubSubscribe(false); unlink('!hub.json'); @@ -129,12 +124,7 @@ foreach ($users as $userFilename) { } try { - Minz_Session::_param('currentUser', $username); - Minz_Configuration::register('user', - join_path(USERS_PATH, $username, 'config.php'), - join_path(FRESHRSS_PATH, 'config-user.default.php')); - new Minz_ModelPdo($username); //TODO: FIXME: Quick-fix while waiting for a better FreshRSS() constructor/init - FreshRSS_Context::init(); + FreshRSS_Context::initUser($username); if (FreshRSS_Context::$user_conf != null) { Minz_ExtensionManager::enableByList(FreshRSS_Context::$user_conf->extensions_enabled); Minz_Translate::reset(FreshRSS_Context::$user_conf->language); |
