From f632a346269100d6a93bef318ffa66c97f16f6fa Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Thu, 12 Oct 2017 20:11:06 +0200 Subject: CLI optimize database (#1663) CLI optimize database https://github.com/FreshRSS/FreshRSS/issues/1583 And VACUUM in SQLite https://github.com/FreshRSS/FreshRSS/issues/918 Add VACUUM for PostgreSQL (Not tested yet) --- app/Controllers/configureController.php | 6 ++++-- app/Controllers/entryController.php | 4 ++-- app/Controllers/userController.php | 4 +++- 3 files changed, 9 insertions(+), 5 deletions(-) (limited to 'app/Controllers') diff --git a/app/Controllers/configureController.php b/app/Controllers/configureController.php index 155221d19..9d2ee450c 100755 --- a/app/Controllers/configureController.php +++ b/app/Controllers/configureController.php @@ -225,10 +225,12 @@ class FreshRSS_configure_Controller extends Minz_ActionController { $entryDAO = FreshRSS_Factory::createEntryDao(); $this->view->nb_total = $entryDAO->count(); - $this->view->size_user = $entryDAO->size(); + + $databaseDAO = FreshRSS_Factory::createDatabaseDAO(); + $this->view->size_user = $databaseDAO->size(); if (FreshRSS_Auth::hasAccess('admin')) { - $this->view->size_total = $entryDAO->size(true); + $this->view->size_total = $databaseDAO->size(true); } } diff --git a/app/Controllers/entryController.php b/app/Controllers/entryController.php index c40588105..bd8b65b2b 100755 --- a/app/Controllers/entryController.php +++ b/app/Controllers/entryController.php @@ -147,8 +147,8 @@ class FreshRSS_entry_Controller extends Minz_ActionController { @set_time_limit(300); - $entryDAO = FreshRSS_Factory::createEntryDao(); - $entryDAO->optimizeTable(); + $databaseDAO = FreshRSS_Factory::createDatabaseDAO(); + $databaseDAO->optimize(); $feedDAO = FreshRSS_Factory::createFeedDao(); $feedDAO->updateCachedValues(); diff --git a/app/Controllers/userController.php b/app/Controllers/userController.php index a58501186..2a1d43d9e 100644 --- a/app/Controllers/userController.php +++ b/app/Controllers/userController.php @@ -120,7 +120,9 @@ class FreshRSS_user_Controller extends Minz_ActionController { // Get information about the current user. $entryDAO = FreshRSS_Factory::createEntryDao($this->view->current_user); $this->view->nb_articles = $entryDAO->count(); - $this->view->size_user = $entryDAO->size(); + + $databaseDAO = FreshRSS_Factory::createDatabaseDAO(); + $this->view->size_user = $databaseDAO->size(); } public static function createUser($new_user_name, $passwordPlain, $apiPasswordPlain, $userConfig = array(), $insertDefaultFeeds = true) { -- cgit v1.2.3 From 8abfe1cf28b9ca4b1b53073dbb1ec24953855777 Mon Sep 17 00:00:00 2001 From: Kevin Papst Date: Sat, 2 Dec 2017 13:45:26 +0100 Subject: Update panel shows latest version message as success (#1701) show latest version message as success, FIXES #1586 --- app/Controllers/updateController.php | 4 ++-- app/views/update/index.phtml | 16 +++++++++++++++- 2 files changed, 17 insertions(+), 3 deletions(-) (limited to 'app/Controllers') diff --git a/app/Controllers/updateController.php b/app/Controllers/updateController.php index 7a8a3d6c0..c67b358bb 100644 --- a/app/Controllers/updateController.php +++ b/app/Controllers/updateController.php @@ -102,7 +102,7 @@ class FreshRSS_update_Controller extends Minz_ActionController { $version = 'git'; } else { $this->view->message = array( - 'status' => 'bad', + 'status' => 'latest', 'title' => _t('gen.short.damn'), 'body' => _t('feedback.update.none') ); @@ -138,7 +138,7 @@ class FreshRSS_update_Controller extends Minz_ActionController { $status = $res_array[0]; if (strpos($status, 'UPDATE') !== 0) { $this->view->message = array( - 'status' => 'bad', + 'status' => 'latest', 'title' => _t('gen.short.damn'), 'body' => _t('feedback.update.none') ); diff --git a/app/views/update/index.phtml b/app/views/update/index.phtml index da1bc7ef5..0599d5b0d 100644 --- a/app/views/update/index.phtml +++ b/app/views/update/index.phtml @@ -14,7 +14,21 @@

message)) { ?> -

+ message['status']) { + case 'bad': + $class = 'alert-error'; + break; + case 'latest': + $class = 'alert-success'; + break; + default: + $class = 'alert-warn'; + break; + } + ?> +

message['title']; ?> message['body']; ?>

-- cgit v1.2.3 From 3902d3f43330504945e78627b4c49e67ae88aea9 Mon Sep 17 00:00:00 2001 From: Kevin Papst Date: Wed, 6 Dec 2017 21:04:45 +0100 Subject: Show existing extensions in admin panel (#1708) * first draft * display installed extension state * fixed whitespace vs tabs * added translation in all languages * added error checks and log messages * fixed tabs vs whitespace * another try in fixing whitespaces * another try in fixing whitespaces * improved extension list translations * using JSON from official extension repo * improved version compare * updated translations * French translation --- app/Controllers/extensionController.php | 37 +++++++++++++++++++++++++++++++++ app/i18n/cz/admin.php | 7 +++++++ app/i18n/de/admin.php | 7 +++++++ app/i18n/en/admin.php | 7 +++++++ app/i18n/es/admin.php | 7 +++++++ app/i18n/fr/admin.php | 13 +++++++++--- app/i18n/it/admin.php | 7 +++++++ app/i18n/kr/admin.php | 7 +++++++ app/i18n/nl/admin.php | 7 +++++++ app/i18n/pt-br/admin.php | 7 +++++++ app/i18n/ru/admin.php | 7 +++++++ app/i18n/tr/admin.php | 7 +++++++ app/i18n/zh-cn/admin.php | 7 +++++++ app/views/extension/index.phtml | 37 +++++++++++++++++++++++++++++++-- 14 files changed, 159 insertions(+), 5 deletions(-) (limited to 'app/Controllers') diff --git a/app/Controllers/extensionController.php b/app/Controllers/extensionController.php index b6d2d3fe4..bb846e921 100644 --- a/app/Controllers/extensionController.php +++ b/app/Controllers/extensionController.php @@ -25,10 +25,47 @@ class FreshRSS_extension_Controller extends Minz_ActionController { 'user' => array(), ); + $this->view->extensions_installed = array(); + $extensions = Minz_ExtensionManager::listExtensions(); foreach ($extensions as $ext) { $this->view->extension_list[$ext->getType()][] = $ext; + $this->view->extensions_installed[$ext->getEntrypoint()] = $ext->getVersion(); + } + + $availableExtensions = $this->getAvailableExtensionList(); + $this->view->available_extensions = $availableExtensions; + } + + /** + * fetch extension list from GitHub + */ + protected function getAvailableExtensionList() { + $extensionListUrl = 'https://raw.githubusercontent.com/FreshRSS/Extensions/master/extensions.json'; + $json = file_get_contents($extensionListUrl); + + // we ran into problems, simply ignore them + if ($json === false) { + Minz_Log::error('Could not fetch available extension from GitHub'); + return array(); + } + + // fetch the list as an array + $list = json_decode($json, true); + if (empty($list)) { + Minz_Log::warning('Failed to convert extension file list'); + return array(); } + + // we could use that for comparing and caching later + $version = $list['version']; + + // By now, all the needed data is kept in the main extension file. + // In the future we could fetch detail information from the extensions metadata.json, but I tend to stick with + // the current implementation for now, unless it becomes too much effort maintain the extension list manually + $extensions = $list['extensions']; + + return $extensions; } /** diff --git a/app/i18n/cz/admin.php b/app/i18n/cz/admin.php index 63cee3cca..dbfebd4c9 100644 --- a/app/i18n/cz/admin.php +++ b/app/i18n/cz/admin.php @@ -155,6 +155,13 @@ return array( 'help' => '0 znamená žádná omezení účtu', 'number' => 'Maximální počet účtů', ), + 'community' => 'Available community extensions', // @todo translate + 'name' => 'Name', // @todo translate + 'version' => 'Version', // @todo translate + 'description' => 'Description', // @todo translate + 'author' => 'Author', // @todo translate + 'latest' => 'Installed', // @todo translate + 'update' => 'Update available', // @todo translate ), 'update' => array( '_' => 'Aktualizace systému', diff --git a/app/i18n/de/admin.php b/app/i18n/de/admin.php index b5deea989..bb2c9352d 100644 --- a/app/i18n/de/admin.php +++ b/app/i18n/de/admin.php @@ -112,6 +112,13 @@ return array( ), 'title' => 'Erweiterungen', 'user' => 'Benutzer-Erweiterungen', + 'community' => 'Verfügbare Community Erweiterungen', + 'name' => 'Name', + 'version' => 'Version', + 'description' => 'Beschreibungen', + 'author' => 'Autor', + 'latest' => 'Installiert', + 'update' => 'Update verfügbar', ), 'stats' => array( '_' => 'Statistiken', diff --git a/app/i18n/en/admin.php b/app/i18n/en/admin.php index 707627782..d92a016af 100644 --- a/app/i18n/en/admin.php +++ b/app/i18n/en/admin.php @@ -112,6 +112,13 @@ return array( ), 'title' => 'Extensions', 'user' => 'User extensions', + 'community' => 'Available community extensions', + 'name' => 'Name', + 'version' => 'Version', + 'description' => 'Description', + 'author' => 'Author', + 'latest' => 'Installed', + 'update' => 'Update available' ), 'stats' => array( '_' => 'Statistics', diff --git a/app/i18n/es/admin.php b/app/i18n/es/admin.php index c9d9368eb..93b1e6e5c 100755 --- a/app/i18n/es/admin.php +++ b/app/i18n/es/admin.php @@ -112,6 +112,13 @@ return array( ), 'title' => 'Extensiones', 'user' => 'Extensiones de usuario', + 'community' => 'Available community extensions', // @todo translate + 'name' => 'Name', // @todo translate + 'version' => 'Version', // @todo translate + 'description' => 'Description', // @todo translate + 'author' => 'Author', // @todo translate + 'latest' => 'Installed', // @todo translate + 'update' => 'Update available', // @todo translate ), 'stats' => array( '_' => 'Estadísticas', diff --git a/app/i18n/fr/admin.php b/app/i18n/fr/admin.php index 9a13ecc21..b2bc48209 100644 --- a/app/i18n/fr/admin.php +++ b/app/i18n/fr/admin.php @@ -103,15 +103,22 @@ return array( ), 'extensions' => array( 'disabled' => 'Désactivée', - 'empty_list' => 'Il n’y a aucune extension installée.', + 'empty_list' => 'Aucune extension installée', 'enabled' => 'Activée', - 'no_configure_view' => 'Cette extension ne peut pas être configurée.', + 'no_configure_view' => 'Cette extension n’a pas à être configurée', 'system' => array( '_' => 'Extensions système', - 'no_rights' => 'Extension système (vous n’avez aucun droit dessus)', + 'no_rights' => 'Extensions système (contrôlées par l’administrateur)', ), 'title' => 'Extensions', 'user' => 'Extensions utilisateur', + 'community' => 'Extensions utilisateur disponibles', + 'name' => 'Nom', + 'version' => 'Version', + 'description' => 'Description', + 'author' => 'Auteur', + 'latest' => 'Installée', + 'update' => 'Mise à jour disponible', ), 'stats' => array( '_' => 'Statistiques', diff --git a/app/i18n/it/admin.php b/app/i18n/it/admin.php index ae46818ae..0248d9317 100644 --- a/app/i18n/it/admin.php +++ b/app/i18n/it/admin.php @@ -112,6 +112,13 @@ return array( ), 'title' => 'Estensioni', 'user' => 'Estensioni utente', + 'community' => 'Available community extensions', // @todo translate + 'name' => 'Name', // @todo translate + 'version' => 'Version', // @todo translate + 'description' => 'Description', // @todo translate + 'author' => 'Author', // @todo translate + 'latest' => 'Installed', // @todo translate + 'update' => 'Update available', // @todo translate ), 'stats' => array( '_' => 'Statistiche', diff --git a/app/i18n/kr/admin.php b/app/i18n/kr/admin.php index 13f4695e1..9781fb640 100644 --- a/app/i18n/kr/admin.php +++ b/app/i18n/kr/admin.php @@ -112,6 +112,13 @@ return array( ), 'title' => '확장 기능', 'user' => '사용자 확장 기능', + 'community' => 'Available community extensions', // @todo translate + 'name' => 'Name', // @todo translate + 'version' => 'Version', // @todo translate + 'description' => 'Description', // @todo translate + 'author' => 'Author', // @todo translate + 'latest' => 'Installed', // @todo translate + 'update' => 'Update available', // @todo translate ), 'stats' => array( '_' => '통계', diff --git a/app/i18n/nl/admin.php b/app/i18n/nl/admin.php index fdfe6e3bc..384242b4d 100644 --- a/app/i18n/nl/admin.php +++ b/app/i18n/nl/admin.php @@ -112,6 +112,13 @@ return array( ), 'title' => 'Uitbreidingen', 'user' => 'Gebruikersuitbreidingen', + 'community' => 'Gebruikersuitbreidingen beschikbaar', + 'name' => 'Naam', + 'version' => 'Versie', + 'description' => 'Beschrijving', + 'author' => 'Auteur', + 'latest' => 'Geïnstalleerd', + 'update' => 'Update beschikbaar', ), 'stats' => array( '_' => 'Statistieken', diff --git a/app/i18n/pt-br/admin.php b/app/i18n/pt-br/admin.php index 1076534b2..e62718e80 100644 --- a/app/i18n/pt-br/admin.php +++ b/app/i18n/pt-br/admin.php @@ -112,6 +112,13 @@ return array( ), 'title' => 'Extensões', 'user' => 'Extensões do usuário', + 'community' => 'Available community extensions', // @todo translate + 'name' => 'Name', // @todo translate + 'version' => 'Version', // @todo translate + 'description' => 'Description', // @todo translate + 'author' => 'Author', // @todo translate + 'latest' => 'Installed', // @todo translate + 'update' => 'Update available', // @todo translate ), 'stats' => array( '_' => 'Estatísticas', diff --git a/app/i18n/ru/admin.php b/app/i18n/ru/admin.php index f5da97371..d877c5006 100644 --- a/app/i18n/ru/admin.php +++ b/app/i18n/ru/admin.php @@ -112,6 +112,13 @@ return array( ), 'title' => 'Расширения', 'user' => 'Расширения пользователя', + 'community' => 'Available community extensions', // @todo translate + 'name' => 'Name', // @todo translate + 'version' => 'Version', // @todo translate + 'description' => 'Description', // @todo translate + 'author' => 'Author', // @todo translate + 'latest' => 'Installed', // @todo translate + 'update' => 'Update available', // @todo translate ), 'stats' => array( '_' => 'Статистика', diff --git a/app/i18n/tr/admin.php b/app/i18n/tr/admin.php index 9d10ef9dd..aa3aad7b7 100644 --- a/app/i18n/tr/admin.php +++ b/app/i18n/tr/admin.php @@ -112,6 +112,13 @@ return array( ), 'title' => 'Eklentiler', 'user' => 'Kullanıcı eklentileri', + 'community' => 'Available community extensions', // @todo translate + 'name' => 'Name', // @todo translate + 'version' => 'Version', // @todo translate + 'description' => 'Description', // @todo translate + 'author' => 'Author', // @todo translate + 'latest' => 'Installed', // @todo translate + 'update' => 'Update available', // @todo translate ), 'stats' => array( '_' => 'İstatistikler', diff --git a/app/i18n/zh-cn/admin.php b/app/i18n/zh-cn/admin.php index 4ecc52e64..ca18bf63d 100644 --- a/app/i18n/zh-cn/admin.php +++ b/app/i18n/zh-cn/admin.php @@ -112,6 +112,13 @@ return array( ), 'title' => '扩展', 'user' => '用户扩展', + 'community' => 'Available community extensions', // @todo translate + 'name' => 'Name', // @todo translate + 'version' => 'Version', // @todo translate + 'description' => 'Description', // @todo translate + 'author' => 'Author', // @todo translate + 'latest' => 'Installed', // @todo translate + 'update' => 'Update available', // @todo translate ), 'stats' => array( '_' => '统计', diff --git a/app/views/extension/index.phtml b/app/views/extension/index.phtml index 7cb16bfff..6439a0333 100644 --- a/app/views/extension/index.phtml +++ b/app/views/extension/index.phtml @@ -26,13 +26,46 @@ } ?> extension_list['system']) && empty($this->extension_list['user'])) { + if (empty($this->extension_list['system']) && empty($this->extension_list['user'])) { ?>

+ + available_extensions)) { ?> +

+ + + + + + + + available_extensions as $ext) { ?> + + + + + + + +
+ + extensions_installed[$ext['name']])) { ?> + extensions_installed[$ext['name']], $ext['version']) >= 0) { ?> + + + + extensions_installed[$ext['name']] != $ext['version']) { ?> + + + + + +
+ extension) ? ' class="active"' : ''; ?> -- cgit v1.2.3 From b1c317a253445a6458f1263c1b622a788cc7cd0e Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Sun, 10 Dec 2017 21:31:41 +0100 Subject: Log rotation, use Minz_Log, new log constants ADMIN_LOG, API_LOG, PSHB_LOG --- app/Controllers/feedController.php | 4 ++-- app/Models/Feed.php | 14 +++++------- app/Models/LogDAO.php | 6 ++--- app/actualize_script.php | 13 ++++------- constants.php | 7 ++++-- lib/Minz/Log.php | 22 ++++++++++++++---- p/api/greader.php | 47 +++++++++----------------------------- p/api/pshb.php | 40 +++++++++++++++----------------- 8 files changed, 66 insertions(+), 87 deletions(-) (limited to 'app/Controllers') diff --git a/app/Controllers/feedController.php b/app/Controllers/feedController.php index 45cba9e98..883f7af05 100755 --- a/app/Controllers/feedController.php +++ b/app/Controllers/feedController.php @@ -263,7 +263,7 @@ class FreshRSS_feed_Controller extends Minz_ActionController { if ((!$simplePiePush) && (!$feed_id) && $pubSubHubbubEnabled && ($feed->lastUpdate() > $pshbMinAge)) { //$text = 'Skip pull of feed using PubSubHubbub: ' . $url; //Minz_Log::debug($text); - //file_put_contents(USERS_PATH . '/_/log_pshb.txt', date('c') . "\t" . $text . "\n", FILE_APPEND); + //Minz_Log::debug($text, PSHB_LOG); continue; //When PubSubHubbub is used, do not pull refresh so often } @@ -371,7 +371,7 @@ class FreshRSS_feed_Controller extends Minz_ActionController { if ($pubSubHubbubEnabled && !$simplePiePush) { //We use push, but have discovered an article by pull! $text = 'An article was discovered by pull although we use PubSubHubbub!: Feed ' . $url . ' GUID ' . $entry->guid(); - file_put_contents(USERS_PATH . '/_/log_pshb.txt', date('c') . "\t" . $text . "\n", FILE_APPEND); + Minz_Log::warning($text, PSHB_LOG); Minz_Log::warning($text); $pubSubHubbubEnabled = false; $feed->pubSubHubbubError(true); diff --git a/app/Models/Feed.php b/app/Models/Feed.php index 85273d3f7..75d9f6d6f 100644 --- a/app/Models/Feed.php +++ b/app/Models/Feed.php @@ -403,8 +403,7 @@ class FreshRSS_Feed extends Minz_Model { if (!isset($hubJson['error']) || $hubJson['error'] !== (bool)$error) { $hubJson['error'] = (bool)$error; file_put_contents($hubFilename, json_encode($hubJson)); - file_put_contents(USERS_PATH . '/_/log_pshb.txt', date('c') . "\t" - . 'Set error to ' . ($error ? 1 : 0) . ' for ' . $url . "\n", FILE_APPEND); + Minz_Log::warning('Set error to ' . ($error ? 1 : 0) . ' for ' . $url, PSHB_LOG); } return false; } @@ -419,7 +418,7 @@ class FreshRSS_Feed extends Minz_Model { if (!$hubJson || empty($hubJson['key']) || !ctype_xdigit($hubJson['key'])) { $text = 'Invalid JSON for PubSubHubbub: ' . $this->url; Minz_Log::warning($text); - file_put_contents(USERS_PATH . '/_/log_pshb.txt', date('c') . "\t" . $text . "\n", FILE_APPEND); + Minz_Log::warning($text, PSHB_LOG); return false; } if ((!empty($hubJson['lease_end'])) && ($hubJson['lease_end'] < (time() + (3600 * 23)))) { //TODO: Make a better policy @@ -427,7 +426,7 @@ class FreshRSS_Feed extends Minz_Model { . date('c', empty($hubJson['lease_end']) ? time() : $hubJson['lease_end']) . ' and needs renewal: ' . $this->url; Minz_Log::warning($text); - file_put_contents(USERS_PATH . '/_/log_pshb.txt', date('c') . "\t" . $text . "\n", FILE_APPEND); + Minz_Log::warning($text, PSHB_LOG); $key = $hubJson['key']; //To renew our lease } elseif (((!empty($hubJson['error'])) || empty($hubJson['lease_end'])) && (empty($hubJson['lease_start']) || $hubJson['lease_start'] < time() - (3600 * 23))) { //Do not renew too often @@ -445,7 +444,7 @@ class FreshRSS_Feed extends Minz_Model { file_put_contents(PSHB_PATH . '/keys/' . $key . '.txt', base64url_encode($this->selfUrl)); $text = 'PubSubHubbub prepared for ' . $this->url; Minz_Log::debug($text); - file_put_contents(USERS_PATH . '/_/log_pshb.txt', date('c') . "\t" . $text . "\n", FILE_APPEND); + Minz_Log::debug($text, PSHB_LOG); } $currentUser = Minz_Session::param('currentUser'); if (FreshRSS_user_Controller::checkUsername($currentUser) && !file_exists($path . '/' . $currentUser . '.txt')) { @@ -499,9 +498,8 @@ class FreshRSS_Feed extends Minz_Model { $response = curl_exec($ch); $info = curl_getinfo($ch); - file_put_contents(USERS_PATH . '/_/log_pshb.txt', date('c') . "\t" . - 'PubSubHubbub ' . ($state ? 'subscribe' : 'unsubscribe') . ' to ' . $url . - ' with callback ' . $callbackUrl . ': ' . $info['http_code'] . ' ' . $response . "\n", FILE_APPEND); + Minz_Log::warning('PubSubHubbub ' . ($state ? 'subscribe' : 'unsubscribe') . ' to ' . $url . + ' with callback ' . $callbackUrl . ': ' . $info['http_code'] . ' ' . $response, PSHB_LOG); if (substr($info['http_code'], 0, 1) == '2') { return true; diff --git a/app/Models/LogDAO.php b/app/Models/LogDAO.php index ab258cd58..5bce466d5 100644 --- a/app/Models/LogDAO.php +++ b/app/Models/LogDAO.php @@ -22,9 +22,9 @@ class FreshRSS_LogDAO { public static function truncate() { file_put_contents(join_path(DATA_PATH, 'users', Minz_Session::param('currentUser', '_'), 'log.txt'), ''); if (FreshRSS_Auth::hasAccess('admin')) { - file_put_contents(join_path(DATA_PATH, 'users', '_', 'log.txt'), ''); - file_put_contents(join_path(DATA_PATH, 'users', '_', 'log_api.txt'), ''); - file_put_contents(join_path(DATA_PATH, 'users', '_', 'log_pshb.txt'), ''); + file_put_contents(ADMIN_LOG, ''); + file_put_contents(API_LOG, ''); + file_put_contents(PSHB_LOG, ''); } } } diff --git a/app/actualize_script.php b/app/actualize_script.php index deaa1bf7c..d4908d3ea 100755 --- a/app/actualize_script.php +++ b/app/actualize_script.php @@ -20,10 +20,6 @@ $_GET['ajax'] = 1; $_GET['force'] = true; $_SERVER['HTTP_HOST'] = ''; - -$log_file = join_path(USERS_PATH, '_', 'log.txt'); - - $app = new FreshRSS(); $system_conf = Minz_Configuration::get('system'); @@ -45,13 +41,13 @@ $min_last_activity = time() - $limits['max_inactivity']; foreach ($users as $user) { if (($user !== $system_conf->default_user) && (FreshRSS_UserDAO::mtime($user) < $min_last_activity)) { - Minz_Log::notice('FreshRSS skip inactive user ' . $user, $log_file); + Minz_Log::notice('FreshRSS skip inactive user ' . $user, ADMIN_LOG); if (defined('STDOUT')) { fwrite(STDOUT, 'FreshRSS skip inactive user ' . $user . "\n"); //Unbuffered } continue; } - Minz_Log::notice('FreshRSS actualize ' . $user, $log_file); + Minz_Log::notice('FreshRSS actualize ' . $user, ADMIN_LOG); if (defined('STDOUT')) { fwrite(STDOUT, 'Actualize ' . $user . "...\n"); //Unbuffered } @@ -66,8 +62,7 @@ foreach ($users as $user) { if (!invalidateHttpCache()) { - Minz_Log::notice('FreshRSS write access problem in ' . join_path(USERS_PATH, $user, 'log.txt'), - $log_file); + Minz_Log::warning('FreshRSS write access problem in ' . join_path(USERS_PATH, $user, 'log.txt'), ADMIN_LOG); if (defined('STDERR')) { fwrite(STDERR, 'Write access problem in ' . join_path(USERS_PATH, $user, 'log.txt') . "\n"); } @@ -75,7 +70,7 @@ foreach ($users as $user) { } -Minz_Log::notice('FreshRSS actualize done.', $log_file); +Minz_Log::notice('FreshRSS actualize done.', ADMIN_LOG); if (defined('STDOUT')) { fwrite(STDOUT, 'Done.' . "\n"); $end_date = date_create('now'); diff --git a/constants.php b/constants.php index b48c1be96..576be09b9 100644 --- a/constants.php +++ b/constants.php @@ -8,8 +8,8 @@ define('FRESHRSS_USERAGENT', 'FreshRSS/' . FRESHRSS_VERSION . ' (' . PHP_OS . '; // PHP text output compression http://php.net/ob_gzhandler (better to do it at Web server level) define('PHP_COMPRESSION', false); -// maximum log file size, before it will be purged (defaults to 512000 = 500kB) -define('MAX_LOG_SIZE', 512000); +// Maximum log file size in Bytes, before it will be divided by two +define('MAX_LOG_SIZE', 1048576); // Constantes de chemins define('FRESHRSS_PATH', dirname(__FILE__)); @@ -22,7 +22,10 @@ define('FRESHRSS_PATH', dirname(__FILE__)); define('DATA_PATH', FRESHRSS_PATH . '/data'); define('UPDATE_FILENAME', DATA_PATH . '/update.php'); define('USERS_PATH', DATA_PATH . '/users'); + define('ADMIN_LOG', USERS_PATH . '/_/log.txt'); + define('API_LOG', USERS_PATH . '/_/log_api.txt'); define('CACHE_PATH', DATA_PATH . '/cache'); + define('PSHB_LOG', USERS_PATH . '/_/log_pshb.txt'); define('PSHB_PATH', DATA_PATH . '/PubSubHubbub'); define('LIB_PATH', FRESHRSS_PATH . '/lib'); diff --git a/lib/Minz/Log.php b/lib/Minz/Log.php index 6231754fa..5e7831cdb 100644 --- a/lib/Minz/Log.php +++ b/lib/Minz/Log.php @@ -71,7 +71,7 @@ class Minz_Log { . ' [' . $level_label . ']' . ' --- ' . $information . "\n"; - self::checkLogfileSize($file_name); + self::ensureMaxLogSize($file_name); if (file_put_contents($file_name, $log, FILE_APPEND | LOCK_EX) === false) { throw new Minz_PermissionDeniedException($file_name, Minz_Exception::ERROR); @@ -88,12 +88,24 @@ class Minz_Log { * @param $file_name * @throws Minz_PermissionDeniedException */ - protected static function checkLogfileSize($file_name) { - $maxSize = defined('MAX_LOG_SIZE') ? MAX_LOG_SIZE : 512000; - if (@filesize($file_name) > $maxSize) { - if (file_put_contents($file_name, '') === false) { + protected static function ensureMaxLogSize($file_name) { + $maxSize = defined('MAX_LOG_SIZE') ? MAX_LOG_SIZE : 1048576; + if ($maxSize > 0 && @filesize($file_name) > $maxSize) { + $fp = fopen($file_name, 'c+'); + if ($fp && flock($fp, LOCK_EX)) { + fseek($fp, -intval($maxSize / 2), SEEK_END); + $content = fread($fp, $maxSize); + rewind($fp); + ftruncate($fp, 0); + fwrite($fp, $content ? $content : ''); + fflush($fp); + flock($fp, LOCK_UN); + } else { throw new Minz_PermissionDeniedException($file_name, Minz_Exception::ERROR); } + if ($fp) { + fclose($fp); + } } } diff --git a/p/api/greader.php b/p/api/greader.php index f086ee442..b27f5bd43 100644 --- a/p/api/greader.php +++ b/p/api/greader.php @@ -78,10 +78,6 @@ class MyPDO extends Minz_ModelPdo { } } -function logMe($text) { - file_put_contents(join_path(USERS_PATH, '_', 'log_api.txt'), date('c') . "\t" . $text . "\n", FILE_APPEND); -} - function debugInfo() { if (function_exists('getallheaders')) { $ALL_HEADERS = getallheaders(); @@ -107,16 +103,14 @@ function debugInfo() { } function badRequest() { - logMe("badRequest()"); - logMe(debugInfo()); + Minz_Log::warning('badRequest() ' . debugInfo(), API_LOG); header('HTTP/1.1 400 Bad Request'); header('Content-Type: text/plain; charset=UTF-8'); die('Bad Request!'); } function unauthorized() { - logMe("unauthorized()"); - logMe(debugInfo()); + Minz_Log::warning('unauthorized() ' . debugInfo(), API_LOG); header('HTTP/1.1 401 Unauthorized'); header('Content-Type: text/plain; charset=UTF-8'); header('Google-Bad-Token: true'); @@ -124,22 +118,21 @@ function unauthorized() { } function notImplemented() { - logMe("notImplemented()"); - logMe(debugInfo()); + Minz_Log::warning('notImplemented() ' . debugInfo(), API_LOG); header('HTTP/1.1 501 Not Implemented'); header('Content-Type: text/plain; charset=UTF-8'); die('Not Implemented!'); } function serviceUnavailable() { - logMe("serviceUnavailable()"); + Minz_Log::warning('serviceUnavailable() ' . debugInfo(), API_LOG); header('HTTP/1.1 503 Service Unavailable'); header('Content-Type: text/plain; charset=UTF-8'); die('Service Unavailable!'); } function checkCompatibility() { - logMe("checkCompatibility()"); + Minz_Log::warning('checkCompatibility() ' . debugInfo(), API_LOG); header('Content-Type: text/plain; charset=UTF-8'); if (PHP_INT_SIZE < 8 && !function_exists('gmp_init')) { die('FAIL 64-bit or GMP extension!'); @@ -170,7 +163,7 @@ function authorizationToUser() { if ($headerAuthX[1] === sha1(FreshRSS_Context::$system_conf->salt . $user . FreshRSS_Context::$user_conf->apiPasswordHash)) { return $user; } else { - logMe('Invalid API authorisation for user ' . $user . ': ' . $headerAuthX[1]); + Minz_Log::warning('Invalid API authorisation for user ' . $user . ': ' . $headerAuthX[1], API_LOG); Minz_Log::warning('Invalid API authorisation for user ' . $user . ': ' . $headerAuthX[1]); unauthorized(); } @@ -183,7 +176,6 @@ function authorizationToUser() { } function clientLogin($email, $pass) { //http://web.archive.org/web/20130604091042/http://undoc.in/clientLogin.html - //logMe('clientLogin(' . $email . ")"); if (ctype_alnum($email)) { if (!function_exists('password_verify')) { include_once(LIB_PATH . '/password_compat.php'); @@ -215,7 +207,7 @@ function token($conf) { //http://blog.martindoms.com/2009/08/15/using-the-google-reader-api-part-1/ //https://github.com/ericmann/gReader-Library/blob/master/greader.class.php $user = Minz_Session::param('currentUser', '_'); - //logMe('token('. $user . ")"); //TODO: Implement real token that expires + //Minz_Log::debug('token('. $user . ')', API_LOG); //TODO: Implement real token that expires $token = str_pad(sha1(FreshRSS_Context::$system_conf->salt . $user . $conf->apiPasswordHash), 57, 'Z'); //Must have 57 characters echo $token, "\n"; exit(); @@ -224,7 +216,6 @@ function token($conf) { function checkToken($conf, $token) { //http://code.google.com/p/google-reader-api/wiki/ActionToken $user = Minz_Session::param('currentUser', '_'); - //logMe('checkToken(' . $token . ")"); if ($token === str_pad(sha1(FreshRSS_Context::$system_conf->salt . $user . $conf->apiPasswordHash), 57, 'Z')) { return true; } @@ -232,7 +223,6 @@ function checkToken($conf, $token) { } function userInfo() { //https://github.com/theoldreader/api#user-info - //logMe("userInfo()"); $user = Minz_Session::param('currentUser', '_'); exit(json_encode(array( 'userId' => $user, @@ -243,7 +233,6 @@ function userInfo() { //https://github.com/theoldreader/api#user-info } function tagList() { - //logMe("tagList()"); header('Content-Type: application/json; charset=UTF-8'); $pdo = new MyPDO(); @@ -268,7 +257,6 @@ function tagList() { } function subscriptionList() { - //logMe("subscriptionList()"); header('Content-Type: application/json; charset=UTF-8'); $pdo = new MyPDO(); @@ -303,7 +291,6 @@ function subscriptionList() { } function subscriptionEdit($streamNames, $titles, $action, $add = '', $remove = '') { - //logMe("subscriptionEdit()"); //https://github.com/mihaip/google-reader-api/blob/master/wiki/ApiSubscriptionEdit.wiki switch ($action) { case 'subscribe': @@ -360,7 +347,7 @@ function subscriptionEdit($streamNames, $titles, $action, $add = '', $remove = ' $feed = FreshRSS_feed_Controller::addFeed($streamName, $title, $addCatId, $c_name, $http_auth); continue; } catch (Exception $e) { - logMe("subscriptionEdit error subscribe: " . $e->getMessage()); + Minz_Log::error('subscriptionEdit error subscribe: ' . $e->getMessage(), API_LOG); } } badRequest(); @@ -389,7 +376,6 @@ function subscriptionEdit($streamNames, $titles, $action, $add = '', $remove = ' } function quickadd($url) { - //logMe("quickadd($url)"); try { $feed = FreshRSS_feed_Controller::addFeed($url); exit(json_encode(array( @@ -397,7 +383,7 @@ function quickadd($url) { 'streamId' => $feed->id(), ))); } catch (Exception $e) { - logMe("subscriptionEdit error subscribe: " . $e->getMessage()); + Minz_Log::error('quickadd error: ' . $e->getMessage(), API_LOG); die(json_encode(array( 'numResults' => 0, 'error' => $e->getMessage(), @@ -406,7 +392,6 @@ function quickadd($url) { } function unreadCount() { //http://blog.martindoms.com/2009/10/16/using-the-google-reader-api-part-2/#unread-count - //logMe("unreadCount()"); header('Content-Type: application/json; charset=UTF-8'); $totalUnreads = 0; @@ -453,7 +438,6 @@ function unreadCount() { //http://blog.martindoms.com/2009/10/16/using-the-googl function streamContents($path, $include_target, $start_time, $count, $order, $exclude_target, $continuation) { //http://code.google.com/p/pyrfeed/wiki/GoogleReaderAPI //http://blog.martindoms.com/2009/10/16/using-the-google-reader-api-part-2/#feed - //logMe("streamContents($path, $include_target, $start_time, $count, $order, $exclude_target, $continuation)"); header('Content-Type: application/json; charset=UTF-8'); $feedDAO = FreshRSS_Factory::createFeedDao(); @@ -562,8 +546,6 @@ function streamContentsItemsIds($streamId, $start_time, $count, $order, $exclude //http://code.google.com/p/google-reader-api/wiki/ApiStreamItemsIds //http://code.google.com/p/pyrfeed/wiki/GoogleReaderAPI //http://blog.martindoms.com/2009/10/16/using-the-google-reader-api-part-2/#feed - //logMe("streamContentsItemsIds($streamId, $start_time, $count, $order, $exclude_target)"); - $type = 'A'; $id = ''; if ($streamId === 'user/-/state/com.google/reading-list') { @@ -610,8 +592,6 @@ function streamContentsItemsIds($streamId, $start_time, $count, $order, $exclude } function editTag($e_ids, $a, $r) { - //logMe("editTag()"); - foreach ($e_ids as $i => $e_id) { $e_ids[$i] = hex2dec(basename($e_id)); //Strip prefix 'tag:google.com,2005:reader/item/' } @@ -645,7 +625,6 @@ function editTag($e_ids, $a, $r) { } function renameTag($s, $dest) { - //logMe("renameTag()"); if ($s != '' && strpos($s, 'user/-/label/') === 0 && $dest != '' && strpos($dest, 'user/-/label/') === 0) { $s = substr($s, 13); @@ -661,7 +640,6 @@ function renameTag($s, $dest) { } function disableTag($s) { - //logMe("disableTag($s)"); if ($s != '' && strpos($s, 'user/-/label/') === 0) { $s = substr($s, 13); $categoryDAO = new FreshRSS_CategoryDAO(); @@ -679,7 +657,6 @@ function disableTag($s) { } function markAllAsRead($streamId, $olderThanId) { - //logMe("markAllAsRead($streamId, $olderThanId)"); $entryDAO = FreshRSS_Factory::createEntryDao(); if (strpos($streamId, 'feed/') === 0) { $f_id = basename($streamId); @@ -696,8 +673,8 @@ function markAllAsRead($streamId, $olderThanId) { exit('OK'); } -//logMe('----------------------------------------------------------------'); -//logMe(debugInfo()); +//Minz_Log::debug('----------------------------------------------------------------', API_LOG); +//Minz_Log::debug(debugInfo(), API_LOG); $pathInfo = empty($_SERVER['PATH_INFO']) ? '/Error' : urldecode($_SERVER['PATH_INFO']); $pathInfos = explode('/', $pathInfo); @@ -718,8 +695,6 @@ if ($user !== '') { FreshRSS_Context::$user_conf = get_user_configuration($user); } -//logMe('User => ' . $user); - Minz_Session::_param('currentUser', $user); if (count($pathInfos) < 3) { diff --git a/p/api/pshb.php b/p/api/pshb.php index ed8326cf5..578681cc4 100644 --- a/p/api/pshb.php +++ b/p/api/pshb.php @@ -2,18 +2,18 @@ require('../../constants.php'); require(LIB_PATH . '/lib_rss.php'); //Includes class autoloader -define('MAX_PAYLOAD', 3145728); +const MAX_PAYLOAD = 3145728; header('Content-Type: text/plain; charset=UTF-8'); header('X-Content-Type-Options: nosniff'); -function logMe($text) { - file_put_contents(USERS_PATH . '/_/log_pshb.txt', date('c') . "\t" . $text . "\n", FILE_APPEND); -} - $ORIGINAL_INPUT = file_get_contents('php://input', false, null, 0, MAX_PAYLOAD); -//logMe(print_r(array('_SERVER' => $_SERVER, '_GET' => $_GET, '_POST' => $_POST, 'INPUT' => $ORIGINAL_INPUT), true)); +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!) + +//Minz_Log::debug(print_r(array('_SERVER' => $_SERVER, '_GET' => $_GET, '_POST' => $_POST, 'INPUT' => $ORIGINAL_INPUT), true), PSHB_LOG); $key = isset($_GET['k']) ? substr($_GET['k'], 0, 128) : ''; if (!ctype_xdigit($key)) { @@ -24,31 +24,31 @@ chdir(PSHB_PATH); $canonical64 = @file_get_contents('keys/' . $key . '.txt'); if ($canonical64 === false) { if (!empty($_REQUEST['hub_mode']) && $_REQUEST['hub_mode'] === 'unsubscribe') { - logMe('Warning: Accept unknown unsubscribe'); + Minz_Log::warning('Warning: Accept unknown unsubscribe', PSHB_LOG); header('Connection: close'); exit(isset($_REQUEST['hub_challenge']) ? $_REQUEST['hub_challenge'] : ''); } header('HTTP/1.1 404 Not Found'); - logMe('Warning: Feed key not found!: ' . $key); + Minz_Log::warning('Warning: Feed key not found!: ' . $key, PSHB_LOG); die('Feed key not found!'); } $canonical64 = trim($canonical64); if (!preg_match('/^[A-Za-z0-9_-]+$/D', $canonical64)) { header('HTTP/1.1 500 Internal Server Error'); - logMe('Error: Invalid key reference!: ' . $canonical64); + Minz_Log::error('Error: Invalid key reference!: ' . $canonical64, PSHB_LOG); die('Invalid key reference!'); } $hubFile = @file_get_contents('feeds/' . $canonical64 . '/!hub.json'); if ($hubFile === false) { header('HTTP/1.1 404 Not Found'); unlink('keys/' . $key . '.txt'); - logMe('Error: Feed info not found!: ' . $canonical64); + Minz_Log::error('Error: Feed info not found!: ' . $canonical64, PSHB_LOG); die('Feed info not found!'); } $hubJson = json_decode($hubFile, true); if (!$hubJson || empty($hubJson['key']) || $hubJson['key'] !== $key) { header('HTTP/1.1 500 Internal Server Error'); - logMe('Error: Invalid key cross-check!: ' . $key); + Minz_Log::error('Error: Invalid key cross-check!: ' . $key, PSHB_LOG); die('Invalid key cross-check!'); } chdir('feeds/' . $canonical64); @@ -56,7 +56,7 @@ $users = glob('*.txt', GLOB_NOSORT); if (empty($users)) { header('HTTP/1.1 410 Gone'); $url = base64url_decode($canonical64); - logMe('Warning: Nobody subscribes to this feed anymore!: ' . $url); + 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', @@ -101,10 +101,6 @@ if ($ORIGINAL_INPUT == '') { die('Missing XML 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!) - $simplePie = customSimplePie(); $simplePie->set_raw_data($ORIGINAL_INPUT); $simplePie->init(); @@ -115,7 +111,7 @@ $self = isset($links[0]) ? $links[0] : null; if ($self !== base64url_decode($canonical64)) { //header('HTTP/1.1 422 Unprocessable Entity'); - logMe('Warning: Self URL [' . $self . '] does not match registered canonical URL!: ' . base64url_decode($canonical64)); + Minz_Log::warning('Warning: Self URL [' . $self . '] does not match registered canonical URL!: ' . base64url_decode($canonical64), PSHB_LOG); //die('Self URL does not match registered canonical URL!'); $self = base64url_decode($canonical64); } @@ -124,7 +120,7 @@ $nb = 0; foreach ($users as $userFilename) { $username = basename($userFilename, '.txt'); if (!file_exists(USERS_PATH . '/' . $username . '/config.php')) { - logMe('Warning: Removing broken user link: ' . $username . ' for ' . $self); + Minz_Log::warning('Warning: Removing broken user link: ' . $username . ' for ' . $self, PSHB_LOG); unlink($userFilename); continue; } @@ -140,11 +136,11 @@ foreach ($users as $userFilename) { if ($updated_feeds > 0 || $feed != false) { $nb++; } else { - logMe('Warning: User ' . $username . ' does not subscribe anymore to ' . $self); + Minz_Log::warning('Warning: User ' . $username . ' does not subscribe anymore to ' . $self, PSHB_LOG); unlink($userFilename); } } catch (Exception $e) { - logMe('Error: ' . $e->getMessage() . ' for user ' . $username . ' and feed ' . $self); + Minz_Log::error('Error: ' . $e->getMessage() . ' for user ' . $username . ' and feed ' . $self, PSHB_LOG); } } @@ -153,12 +149,12 @@ unset($simplePie); if ($nb === 0) { header('HTTP/1.1 410 Gone'); - logMe('Warning: Nobody subscribes to this feed anymore after all!: ' . $self); + Minz_Log::warning('Warning: Nobody subscribes to this feed anymore after all!: ' . $self, PSHB_LOG); die('Nobody subscribes to this feed anymore after all!'); } elseif (!empty($hubJson['error'])) { $hubJson['error'] = false; file_put_contents('./!hub.json', json_encode($hubJson)); } -logMe('PubSubHubbub ' . $self . ' done: ' . $nb); +Minz_Log::notice('PubSubHubbub ' . $self . ' done: ' . $nb, PSHB_LOG); exit('Done: ' . $nb . "\n"); -- cgit v1.2.3 From 62e9db55b21034f92b0f4603512c3e788e0351f1 Mon Sep 17 00:00:00 2001 From: Kevin Papst Date: Sun, 17 Dec 2017 16:36:48 +0100 Subject: fixed bug when adding a category and feed at the same time (#1731) fixed bug when adding a category and feed at the same time --- app/Controllers/feedController.php | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) (limited to 'app/Controllers') diff --git a/app/Controllers/feedController.php b/app/Controllers/feedController.php index 883f7af05..fff20f798 100755 --- a/app/Controllers/feedController.php +++ b/app/Controllers/feedController.php @@ -26,6 +26,18 @@ class FreshRSS_feed_Controller extends Minz_ActionController { } } + /** + * @param $url + * @param string $title + * @param int $cat_id + * @param string $new_cat_name + * @param string $http_auth + * @return FreshRSS_Feed|the + * @throws FreshRSS_AlreadySubscribed_Exception + * @throws FreshRSS_FeedNotAdded_Exception + * @throws FreshRSS_Feed_Exception + * @throws Minz_FileNotExistException + */ public static function addFeed($url, $title = '', $cat_id = 0, $new_cat_name = '', $http_auth = '') { FreshRSS_UserDAO::touch(); @set_time_limit(300); @@ -33,12 +45,13 @@ class FreshRSS_feed_Controller extends Minz_ActionController { $catDAO = new FreshRSS_CategoryDAO(); $cat = null; + if ($new_cat_name != '') { + $new_cat_id = $catDAO->addCategory(array('name' => $new_cat_name)); + $cat_id = $new_cat_id > 0 ? $new_cat_id : $cat_id; + } if ($cat_id > 0) { $cat = $catDAO->searchById($cat_id); } - if ($cat == null && $new_cat_name != '') { - $cat = $catDAO->addCategory(array('name' => $new_cat_name)); - } if ($cat == null) { $catDAO->checkDefault(); } @@ -54,7 +67,7 @@ class FreshRSS_feed_Controller extends Minz_ActionController { throw new FreshRSS_AlreadySubscribed_Exception($url, $feed->name()); } - // Call the extension hook + /** @var FreshRSS_Feed $feed */ $feed = Minz_ExtensionManager::callHook('feed_before_insert', $feed); if ($feed === null) { throw new FreshRSS_FeedNotAdded_Exception($url, $feed->name()); @@ -136,7 +149,7 @@ class FreshRSS_feed_Controller extends Minz_ActionController { // User want to create a new category, new_category parameter // must exist $new_cat = Minz_Request::param('new_category'); - $new_cat_name = isset($new_cat['name']) ? $new_cat['name'] : ''; + $new_cat_name = isset($new_cat['name']) ? trim($new_cat['name']) : ''; } // HTTP information are useful if feed is protected behind a -- cgit v1.2.3