A free, self-hostable news aggregator…
Merge branch 'dev'
Marien Fressinauda97bbd9bd54c
diff --cc app/Controllers/indexController.phpindex d3b299f4e,c53d3223e..ddcf0b4e4--- a/app/Controllers/indexController.php+++ b/app/Controllers/indexController.php@@@ -148,352 -56,182 +56,181 @@@ class FreshRSS_index_Controller extend$this->view->entries = $entries;} catch (FreshRSS_EntriesGetter_Exception $e) {- Minz_Log::record ($e->getMessage (), Minz_Log::NOTICE);- Minz_Error::error (- 404,- array ('error' => array (Minz_Translate::t ('page_not_found')))- );+ Minz_Log::notice($e->getMessage());+ Minz_Error::error(404);}- }- /*- * Vérifie que la catégorie / flux sélectionné existe- * + Initialise correctement les variables de vue get_c et get_f- * + Met à jour la variable $this->nb_not_read_cat- */- private function checkAndProcessType ($getType, $getId) {- switch ($getType) {- case 'a':- $this->view->currentName = Minz_Translate::t ('your_rss_feeds');- $this->nb_not_read_cat = $this->view->nb_not_read;- $this->view->get_c = $getType;- return true;- case 's':- $this->view->currentName = Minz_Translate::t ('your_favorites');- $this->nb_not_read_cat = $this->view->nb_favorites['unread'];- $this->view->get_c = $getType;- return true;- case 'c':- $cat = isset($this->view->cat_aside[$getId]) ? $this->view->cat_aside[$getId] : null;- if ($cat === null) {- $catDAO = new FreshRSS_CategoryDAO();- $cat = $catDAO->searchById($getId);- }- if ($cat) {- $this->view->currentName = $cat->name ();- $this->nb_not_read_cat = $cat->nbNotRead ();- $this->view->get_c = $getId;- return true;- } else {- return false;- }- case 'f':- $feed = FreshRSS_CategoryDAO::findFeed($this->view->cat_aside, $getId);- if (empty($feed)) {- $feedDAO = FreshRSS_Factory::createFeedDao();- $feed = $feedDAO->searchById($getId);- }- if ($feed) {- $this->view->currentName = $feed->name ();- $this->nb_not_read_cat = $feed->nbNotRead ();- $this->view->get_f = $getId;- $this->view->get_c = $feed->category ();- return true;- } else {- return false;- }- default:- return false;+ $this->view->categories = FreshRSS_Context::$categories;++ $this->view->rss_title = FreshRSS_Context::$name . ' | ' . Minz_View::title();+ $title = FreshRSS_Context::$name;+ if (FreshRSS_Context::$get_unread > 0) {+ $title = '(' . FreshRSS_Context::$get_unread . ') ' . $title;}+ Minz_View::prependTitle($title . ' · ');}-- public function aboutAction () {- Minz_View::prependTitle (Minz_Translate::t ('about') . ' · ');++ /**+ * This action displays the reader view of FreshRSS.+ *+ * @todo: change this view into specific CSS rules?+ */+ public function readerAction() {+ $this->normalAction();}- public function logsAction () {- if (!$this->view->loginOk) {- Minz_Error::error (- 403,- array ('error' => array (Minz_Translate::t ('access_denied')))- );+ /**+ * This action displays the global view of FreshRSS.+ */+ public function globalAction() {+ $allow_anonymous = FreshRSS_Context::$system_conf->allow_anonymous;+ if (!FreshRSS_Auth::hasAccess() && !$allow_anonymous) {+ Minz_Request::forward(array('c' => 'auth', 'a' => 'login'));+ return;}- Minz_View::prependTitle (Minz_Translate::t ('logs') . ' · ');+ Minz_View::appendScript(Minz_Url::display('/scripts/global_view.js?' . @filemtime(PUBLIC_PATH . '/scripts/global_view.js')));- if (Minz_Request::isPost ()) {- FreshRSS_LogDAO::truncate();+ try {+ $this->updateContext();+ } catch (FreshRSS_Context_Exception $e) {+ Minz_Error::error(404);}- $logs = FreshRSS_LogDAO::lines(); //TODO: ask only the necessary lines+ $this->view->categories = FreshRSS_Context::$categories;- //gestion pagination- $page = Minz_Request::param ('page', 1);- $this->view->logsPaginator = new Minz_Paginator ($logs);- $this->view->logsPaginator->_nbItemsPerPage (50);- $this->view->logsPaginator->_currentPage ($page);+ $this->view->rss_title = FreshRSS_Context::$name . ' | ' . Minz_View::title();+ $title = _t('index.feed.title_global');+ if (FreshRSS_Context::$get_unread > 0) {+ $title = '(' . FreshRSS_Context::$get_unread . ') ' . $title;+ }+ Minz_View::prependTitle($title . ' · ');}- public function loginAction () {- $this->view->_useLayout (false);-- $url = 'https://verifier.login.persona.org/verify';- $assert = Minz_Request::param ('assertion');- $params = 'assertion=' . $assert . '&audience=' .- urlencode (Minz_Url::display (null, 'php', true));- $ch = curl_init ();- $options = array (- CURLOPT_URL => $url,- CURLOPT_RETURNTRANSFER => TRUE,- CURLOPT_POST => 2,- CURLOPT_POSTFIELDS => $params- );- curl_setopt_array ($ch, $options);- $result = curl_exec ($ch);- curl_close ($ch);-- $res = json_decode ($result, true);-- $loginOk = false;- $reason = '';- if ($res['status'] === 'okay') {- $email = filter_var($res['email'], FILTER_VALIDATE_EMAIL);- if ($email != '') {- $personaFile = DATA_PATH . '/persona/' . $email . '.txt';- if (($currentUser = @file_get_contents($personaFile)) !== false) {- $currentUser = trim($currentUser);- if (ctype_alnum($currentUser)) {- try {- $this->conf = new FreshRSS_Configuration($currentUser);- $loginOk = strcasecmp($email, $this->conf->mail_login) === 0;- } catch (Minz_Exception $e) {- $reason = 'Invalid configuration for user [' . $currentUser . ']! ' . $e->getMessage(); //Permission denied or conf file does not exist- }- } else {- $reason = 'Invalid username format [' . $currentUser . ']!';- }- }- } else {- $reason = 'Invalid email format [' . $res['email'] . ']!';- }+ /**+ * This action displays the RSS feed of FreshRSS.+ */+ public function rssAction() {+ $allow_anonymous = FreshRSS_Context::$system_conf->allow_anonymous;+ $token = FreshRSS_Context::$user_conf->token;+ $token_param = Minz_Request::param('token', '');+ $token_is_ok = ($token != '' && $token === $token_param);++ // Check if user has access.+ if (!FreshRSS_Auth::hasAccess() &&+ !$allow_anonymous &&+ !$token_is_ok) {+ Minz_Error::error(403);}- if ($loginOk) {- Minz_Session::_param('currentUser', $currentUser);- Minz_Session::_param ('mail', $email);- $this->view->loginOk = true;- invalidateHttpCache();- } else {- $res = array ();- $res['status'] = 'failure';- $res['reason'] = $reason == '' ? Minz_Translate::t ('invalid_login') : $reason;- Minz_Log::record ('Persona: ' . $res['reason'], Minz_Log::WARNING);++ try {+ $this->updateContext();+ } catch (FreshRSS_Context_Exception $e) {+ Minz_Error::error(404);}- header('Content-Type: application/json; charset=UTF-8');- $this->view->res = json_encode ($res);- }+ try {+ $this->view->entries = $this->listEntriesByContext();+ } catch (FreshRSS_EntriesGetter_Exception $e) {+ Minz_Log::notice($e->getMessage());+ Minz_Error::error(404);+ }- public function logoutAction () {+ // No layout for RSS output.+ $this->view->rss_title = FreshRSS_Context::$name . ' | ' . Minz_View::title();$this->view->_useLayout(false);- invalidateHttpCache();- Minz_Session::_param('currentUser');- Minz_Session::_param('mail');- Minz_Session::_param('passwordHash');+ header('Content-Type: application/rss+xml; charset=utf-8');}- private static function makeLongTermCookie($username, $passwordHash) {- do {- $token = sha1(Minz_Configuration::salt() . $username . uniqid(mt_rand(), true));- $tokenFile = DATA_PATH . '/tokens/' . $token . '.txt';- } while (file_exists($tokenFile));- if (@file_put_contents($tokenFile, $username . "\t" . $passwordHash) === false) {- return false;- }- $expire = time() + 2629744; //1 month //TODO: Use a configuration instead- Minz_Session::setLongTermCookie('FreshRSS_login', $token, $expire);- Minz_Session::_param('token', $token);- return $token;- }+ /**+ * This action updates the Context object by using request parameters.+ *+ * Parameters are:+ * - state (default: conf->default_view)+ * - search (default: empty string)+ * - order (default: conf->sort_order)+ * - nb (default: conf->posts_per_page)+ * - next (default: empty string)+ */+ private function updateContext() {+ // Update number of read / unread variables.+ $entryDAO = FreshRSS_Factory::createEntryDao();+ FreshRSS_Context::$total_starred = $entryDAO->countUnreadReadFavorites();+ FreshRSS_Context::$total_unread = FreshRSS_CategoryDAO::CountUnreads(+ FreshRSS_Context::$categories, 1+ );- private static function deleteLongTermCookie() {- Minz_Session::deleteLongTermCookie('FreshRSS_login');- $token = Minz_Session::param('token', null);- if (ctype_alnum($token)) {- @unlink(DATA_PATH . '/tokens/' . $token . '.txt');- }- Minz_Session::_param('token');- if (rand(0, 10) === 1) {- self::purgeTokens();+ FreshRSS_Context::_get(Minz_Request::param('get', 'a'));-+ FreshRSS_Context::$state = Minz_Request::param(+ 'state', FreshRSS_Context::$user_conf->default_state+ );+ $state_forced_by_user = Minz_Request::param('state', false) !== false;+ if (FreshRSS_Context::$user_conf->default_view === 'adaptive' &&+ FreshRSS_Context::$get_unread <= 0 &&+ !FreshRSS_Context::isStateEnabled(FreshRSS_Entry::STATE_READ) &&+ !$state_forced_by_user) {+ FreshRSS_Context::$state |= FreshRSS_Entry::STATE_READ;}- }- private static function purgeTokens() {- $oldest = time() - 2629744; //1 month //TODO: Use a configuration instead- foreach (new DirectoryIterator(DATA_PATH . '/tokens/') as $fileInfo) {- $extension = pathinfo($fileInfo->getFilename(), PATHINFO_EXTENSION);- if ($extension === 'txt' && $fileInfo->getMTime() < $oldest) {- @unlink($fileInfo->getPathname());- }- }+ FreshRSS_Context::$search = Minz_Request::param('search', '');+ FreshRSS_Context::$order = Minz_Request::param(+ 'order', FreshRSS_Context::$user_conf->sort_order+ );+ FreshRSS_Context::$number = Minz_Request::param(+ 'nb', FreshRSS_Context::$user_conf->posts_per_page+ );+ FreshRSS_Context::$first_id = Minz_Request::param('next', '');}- public function formLoginAction () {- if ($this->view->loginOk) {- Minz_Request::forward(array('c' => 'index', 'a' => 'index'), true);- }+ /**+ * This method returns a list of entries based on the Context object.+ */+ private function listEntriesByContext() {+ $entryDAO = FreshRSS_Factory::createEntryDao();- if (Minz_Request::isPost()) {- $ok = false;- $nonce = Minz_Session::param('nonce');- $username = Minz_Request::param('username', '');- $c = Minz_Request::param('challenge', '');- if (ctype_alnum($username) && ctype_graph($c) && ctype_alnum($nonce)) {- if (!function_exists('password_verify')) {- include_once(LIB_PATH . '/password_compat.php');- }- try {- $conf = new FreshRSS_Configuration($username);- $s = $conf->passwordHash;- $ok = password_verify($nonce . $s, $c);- if ($ok) {- Minz_Session::_param('currentUser', $username);- Minz_Session::_param('passwordHash', $s);- if (Minz_Request::param('keep_logged_in', false)) {- self::makeLongTermCookie($username, $s);- } else {- self::deleteLongTermCookie();- }- } else {- Minz_Log::record('Password mismatch for user ' . $username . ', nonce=' . $nonce . ', c=' . $c, Minz_Log::WARNING);- }- } catch (Minz_Exception $me) {- Minz_Log::record('Login failure: ' . $me->getMessage(), Minz_Log::WARNING);- }- } else {- Minz_Log::record('Invalid credential parameters: user=' . $username . ' challenge=' . $c . ' nonce=' . $nonce, Minz_Log::DEBUG);- }- if (!$ok) {- $notif = array(- 'type' => 'bad',- 'content' => Minz_Translate::t('invalid_login')- );- Minz_Session::_param('notification', $notif);- }- $this->view->_useLayout(false);- Minz_Request::forward(array('c' => 'index', 'a' => 'index'), true);- } elseif (Minz_Configuration::unsafeAutologinEnabled() && isset($_GET['u']) && isset($_GET['p'])) {- Minz_Session::_param('currentUser');- Minz_Session::_param('mail');- Minz_Session::_param('passwordHash');- $username = ctype_alnum($_GET['u']) ? $_GET['u'] : '';- $passwordPlain = $_GET['p'];- Minz_Request::_param('p'); //Discard plain-text password ASAP- $_GET['p'] = '';- if (!function_exists('password_verify')) {- include_once(LIB_PATH . '/password_compat.php');- }- try {- $conf = new FreshRSS_Configuration($username);- $s = $conf->passwordHash;- $ok = password_verify($passwordPlain, $s);- unset($passwordPlain);- if ($ok) {- Minz_Session::_param('currentUser', $username);- Minz_Session::_param('passwordHash', $s);- } else {- Minz_Log::record('Unsafe password mismatch for user ' . $username, Minz_Log::WARNING);- }- } catch (Minz_Exception $me) {- Minz_Log::record('Unsafe login failure: ' . $me->getMessage(), Minz_Log::WARNING);- }- Minz_Request::forward(array('c' => 'index', 'a' => 'index'), true);- } elseif (!Minz_Configuration::canLogIn()) {- Minz_Error::error (- 403,- array ('error' => array (Minz_Translate::t ('access_denied')))- );+ $get = FreshRSS_Context::currentGet(true);+ if (count($get) > 1) {+ $type = $get[0];+ $id = $get[1];+ } else {+ $type = $get;+ $id = '';}- invalidateHttpCache();- }- public function formLogoutAction () {- $this->view->_useLayout(false);- invalidateHttpCache();- Minz_Session::_param('currentUser');- Minz_Session::_param('mail');- Minz_Session::_param('passwordHash');- self::deleteLongTermCookie();- Minz_Request::forward(array('c' => 'index', 'a' => 'index'), true);+ return $entryDAO->listWhere(+ $type, $id, FreshRSS_Context::$state, FreshRSS_Context::$order,+ FreshRSS_Context::$number + 1, FreshRSS_Context::$first_id,+ FreshRSS_Context::$search+ );}- public function resetAuthAction() {- Minz_View::prependTitle(_t('auth_reset') . ' · ');- Minz_View::appendScript(Minz_Url::display(- '/scripts/bcrypt.min.js?' . @filemtime(PUBLIC_PATH . '/scripts/bcrypt.min.js')- ));-- $this->view->no_form = false;- // Enable changement of auth only if Persona!- if (Minz_Configuration::authType() != 'persona') {- $this->view->message = array(- 'status' => 'bad',- 'title' => _t('damn'),- 'body' => _t('auth_not_persona')- );- $this->view->no_form = true;- return;- }+ /**+ * This action displays the about page of FreshRSS.+ */+ public function aboutAction() {+ Minz_View::prependTitle(_t('index.about.title') . ' · ');+ }- $conf = new FreshRSS_Configuration(Minz_Configuration::defaultUser());- // Admin user must have set its master password.- if (!$conf->passwordHash) {- $this->view->message = array(- 'status' => 'bad',- 'title' => _t('damn'),- 'body' => _t('auth_no_password_set')- );- $this->view->no_form = true;- return;+ /**+ * This action displays logs of FreshRSS for the current user.+ */+ public function logsAction() {+ if (!FreshRSS_Auth::hasAccess()) {+ Minz_Error::error(403);}- invalidateHttpCache();+ Minz_View::prependTitle(_t('index.log.title') . ' · ');if (Minz_Request::isPost()) {- $nonce = Minz_Session::param('nonce');- $username = Minz_Request::param('username', '');- $c = Minz_Request::param('challenge', '');- if (!(ctype_alnum($username) && ctype_graph($c) && ctype_alnum($nonce))) {- Minz_Log::debug('Invalid credential parameters:' .- ' user=' . $username .- ' challenge=' . $c .- ' nonce=' . $nonce);- Minz_Request::bad(_t('invalid_login'),- array('c' => 'index', 'a' => 'resetAuth'));- }-- if (!function_exists('password_verify')) {- include_once(LIB_PATH . '/password_compat.php');- }+ FreshRSS_LogDAO::truncate();+ }- $s = $conf->passwordHash;- $ok = password_verify($nonce . $s, $c);- if ($ok) {- Minz_Configuration::_authType('form');- $ok = Minz_Configuration::writeFile();-- if ($ok) {- Minz_Request::good(_t('auth_form_set'));- } else {- Minz_Request::bad(_t('auth_form_not_set'),- array('c' => 'index', 'a' => 'resetAuth'));- }- } else {- Minz_Log::debug('Password mismatch for user ' . $username .- ', nonce=' . $nonce . ', c=' . $c);+ $logs = FreshRSS_LogDAO::lines(); //TODO: ask only the necessary lines- Minz_Request::bad(_t('invalid_login'),- array('c' => 'index', 'a' => 'resetAuth'));- }- }+ //gestion pagination+ $page = Minz_Request::param('page', 1);+ $this->view->logsPaginator = new Minz_Paginator($logs);+ $this->view->logsPaginator->_nbItemsPerPage(50);+ $this->view->logsPaginator->_currentPage($page);}}diff --cc constants.phpindex adc965244,8136afc85..4ee93700b--- a/constants.php+++ b/constants.php@@@ -1,5 -1,5 +1,5 @@@<?php- define('FRESHRSS_VERSION', '0.8.1');-define('FRESHRSS_VERSION', '0.10-dev');++define('FRESHRSS_VERSION', '1.0.0');define('FRESHRSS_WEBSITE', 'http://freshrss.org');define('FRESHRSS_UPDATE_WEBSITE', 'https://update.freshrss.org?v=' . FRESHRSS_VERSION);define('FRESHRSS_WIKI', 'http://doc.freshrss.org');