From a6623b7b2fa3f026a0ea30e49b1a221f7a4a8e55 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Wed, 2 Jan 2019 21:36:33 +0100 Subject: Apache performance (#2202) * Apache performance API: Use SetEnvIf if available and fallback to RewriteRule Docker: Disable unused modules. Docker: Hard-include .htaccess to avoid having to scan for changes in that file. Docker: Disable security check of symlinks, which we do not use ayway. * Apache readme * Docker/Apache tuning Run cron job with correct www-data user instead of root Remove PHP GMP module uneeded for 64-bit Docker image Add option to mount custom .htaccess for HTTP authentication Re-add Apache module for HTTP authentication Move Alpine-specific instructions to Docker file (instead of Apache conf) to make it easier to have other base images than Alpine --- p/api/.htaccess | 11 ++++++++--- p/i/.gitignore | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) (limited to 'p') diff --git a/p/api/.htaccess b/p/api/.htaccess index 41b653d96..937983ec9 100644 --- a/p/api/.htaccess +++ b/p/api/.htaccess @@ -1,4 +1,9 @@ - - RewriteEngine on - RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] + + SetEnvIf "^Authorization$" "(.*)" HTTP_AUTHORIZATION=$1 + + + + RewriteEngine on + RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] + diff --git a/p/i/.gitignore b/p/i/.gitignore index 03c88fd7a..b76d11b5a 100644 --- a/p/i/.gitignore +++ b/p/i/.gitignore @@ -1 +1 @@ -.htaccess +.ht* -- cgit v1.2.3 From 20223b8b01f47fba0858d854c5744fad5900b9cc Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Sat, 5 Jan 2019 12:33:18 +0100 Subject: Automatic API test (#2207) * Automatic API test Easier for end-user, smarter, and the guess testing of greader authorization token was not reliable. * Travis + minor --- p/api/greader.php | 21 ++++++++----------- p/api/index.php | 27 ++++++++++++++---------- p/scripts/api.js | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 87 insertions(+), 23 deletions(-) create mode 100644 p/scripts/api.js (limited to 'p') diff --git a/p/api/greader.php b/p/api/greader.php index 7cd312f2c..d41430d3c 100644 --- a/p/api/greader.php +++ b/p/api/greader.php @@ -143,14 +143,11 @@ function 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!'); + die('FAIL 64-bit or GMP extension! Wrong PHP configuration.'); } - if ((!array_key_exists('HTTP_AUTHORIZATION', $_SERVER)) && //Apache mod_rewrite trick should be fine - (!array_key_exists('REDIRECT_HTTP_AUTHORIZATION', $_SERVER)) && //Apache mod_rewrite with FCGI - (empty($_SERVER['SERVER_SOFTWARE']) || (stripos($_SERVER['SERVER_SOFTWARE'], 'nginx') === false)) && //nginx should be fine - (empty($_SERVER['SERVER_SOFTWARE']) || (stripos($_SERVER['SERVER_SOFTWARE'], 'lighttpd') === false)) && //lighttpd should be fine - ((!function_exists('getallheaders')) || (stripos(php_sapi_name(), 'cgi') !== false))) { //Main problem is Apache/CGI mode - die('FAIL getallheaders! (probably)'); + $headerAuth = headerVariable('Authorization', 'GoogleLogin_auth'); + if ($headerAuth == '') { + die('FAIL get HTTP Authorization header! Wrong Web server configuration.'); } echo 'PASS'; exit(); @@ -913,6 +910,10 @@ FreshRSS_Context::$system_conf = Minz_Configuration::get('system'); if (!FreshRSS_Context::$system_conf->api_enabled) { serviceUnavailable(); +} elseif (count($pathInfos) < 3) { + badRequest(); +} elseif ($pathInfos[1] === 'check' && $pathInfos[2] === 'compatibility') { + checkCompatibility(); } ini_set('session.use_cookies', '0'); @@ -927,9 +928,7 @@ if ($user !== '') { Minz_Session::_param('currentUser', $user); -if (count($pathInfos) < 3) { - badRequest(); -} elseif ($pathInfos[1] === 'accounts') { +if ($pathInfos[1] === 'accounts') { if (($pathInfos[2] === 'ClientLogin') && isset($_REQUEST['Email']) && isset($_REQUEST['Passwd'])) { clientLogin($_REQUEST['Email'], $_REQUEST['Passwd']); } @@ -1088,8 +1087,6 @@ if (count($pathInfos) < 3) { userInfo(); break; } -} elseif ($pathInfos[1] === 'check' && $pathInfos[2] === 'compatibility') { - checkCompatibility(); } badRequest(); diff --git a/p/api/index.php b/p/api/index.php index ee37b794b..d441099d7 100644 --- a/p/api/index.php +++ b/p/api/index.php @@ -5,6 +5,18 @@ FreshRSS API endpoints + + @@ -14,17 +26,11 @@
Your API address:
+
Google Reader API configuration test:
+
?
-

Fever compatible API

@@ -32,10 +38,9 @@ configuration (without %2F support)
+
Fever API configuration test:
+
?
- diff --git a/p/scripts/api.js b/p/scripts/api.js new file mode 100644 index 000000000..841b16a6a --- /dev/null +++ b/p/scripts/api.js @@ -0,0 +1,62 @@ +"use strict"; +/* jshint esversion:6, strict:global */ + +function check(url, next) { + if (!url || !next) { + return; + } + const req = new XMLHttpRequest(); + req.open('GET', url, true); + req.setRequestHeader('Authorization', 'GoogleLogin auth=test/1'); + req.onerror = function (e) { + next('FAIL: HTTP ' + e); + }; + req.onload = function () { + if (this.status == 200) { + next(this.response); + } else { + next('FAIL: HTTP error ' + this.status + ' ' + this.statusText); + } + }; + req.send(); +} + +const jsonVars = JSON.parse(document.getElementById('jsonVars').innerHTML); + +check(jsonVars.greader + '/check/compatibility', function next(result1) { + const greaderOutput = document.getElementById('greaderOutput'); + if (result1 === 'PASS') { + greaderOutput.innerHTML = '✔️ ' + result1; + } else { + check(jsonVars.greader + '/check%2Fcompatibility', function next(result2) { + if (result2 === 'PASS') { + greaderOutput.innerHTML = '⚠️ WARN: no %2F support, so some clients will not work!'; + } else { + check('./greader.php/check/compatibility', function next(result3) { + if (result3 === 'PASS') { + greaderOutput.innerHTML = '⚠️ WARN: Probable invalid base URL in ./data/config.php'; + } else { + greaderOutput.innerHTML = '❌ ' + result1; + } + }); + } + }); + } + }); + +check(jsonVars.fever + '?api', function next(result1) { + const feverOutput = document.getElementById('feverOutput'); + try { + JSON.parse(result1); + feverOutput.innerHTML = '✔️ PASS'; + } catch (ex) { + check('./fever.php?api', function next(result2) { + try { + JSON.parse(result2); + feverOutput.innerHTML = '⚠️ WARN: Probable invalid base URL in ./data/config.php'; + } catch (ex) { + feverOutput.innerHTML = '❌ ' + result1; + } + }); + } + }); -- cgit v1.2.3 From 802c264574902ea44c2c76ae098a6f58911fe114 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Sun, 6 Jan 2019 00:46:48 +0100 Subject: Copy syslog to STDERR (#2208) * Use openlog before syslog In order to have a copy on stderr when syslog is not available. * Take advantage of syslog for actualization Pipe cron job STDERR and syslog to Docker log Cf. https://github.com/FreshRSS/FreshRSS/pull/2202/commits/00bd467655b7c060cdae388519b2413d12d8cb0f --- Docker/Dockerfile | 11 +++++------ app/Models/Entry.php | 1 + app/actualize_script.php | 8 ++++++-- cli/_cli.php | 2 +- lib/favicons.php | 1 + lib/lib_install.php | 1 + lib/lib_rss.php | 7 +++++++ p/i/index.php | 2 ++ 8 files changed, 24 insertions(+), 9 deletions(-) (limited to 'p') diff --git a/Docker/Dockerfile b/Docker/Dockerfile index 2a25e567d..db034ff61 100644 --- a/Docker/Dockerfile +++ b/Docker/Dockerfile @@ -6,11 +6,10 @@ RUN apk add --no-cache \ php7-ctype php7-dom php7-fileinfo php7-iconv php7-json php7-session php7-simplexml php7-xmlreader php7-zlib \ php7-pdo_sqlite php7-pdo_mysql php7-pdo_pgsql -ENV FRESHRSS_ROOT /var/www/FreshRSS -RUN mkdir -p ${FRESHRSS_ROOT} /run/apache2/ -WORKDIR ${FRESHRSS_ROOT} +RUN mkdir -p /var/www/FreshRSS /run/apache2/ +WORKDIR /var/www/FreshRSS -COPY . ${FRESHRSS_ROOT} +COPY . /var/www/FreshRSS COPY ./Docker/*.Apache.conf /etc/apache2/conf.d/ RUN rm -f /etc/apache2/conf.d/languages.conf /etc/apache2/conf.d/info.conf \ @@ -21,8 +20,8 @@ RUN rm -f /etc/apache2/conf.d/languages.conf /etc/apache2/conf.d/info.conf \ /etc/apache2/httpd.conf && \ sed -r -i "/^\s*(CustomLog|ErrorLog|Listen) /s/^/#/" \ /etc/apache2/httpd.conf && \ - echo "17,37 * * * * php ${FRESHRSS_ROOT}/app/actualize_script.php 2>&1 | tee /tmp/FreshRSS.log" >> \ - /var/spool/cron/crontabs/www-data + echo "17,37 * * * * su apache -s /bin/sh -c 'php /var/www/FreshRSS/app/actualize_script.php' 2>> /proc/1/fd/2 > /tmp/FreshRSS.log" >> \ + /var/spool/cron/crontabs/root ENV CRON_MIN '' ENTRYPOINT ["./Docker/entrypoint.sh"] diff --git a/app/Models/Entry.php b/app/Models/Entry.php index 985276734..f2f3d08fe 100644 --- a/app/Models/Entry.php +++ b/app/Models/Entry.php @@ -209,6 +209,7 @@ class FreshRSS_Entry extends Minz_Model { $feed_timeout = empty($attributes['timeout']) ? 0 : intval($attributes['timeout']); if ($system_conf->simplepie_syslog_enabled) { + prepareSyslog(); syslog(LOG_INFO, 'FreshRSS GET ' . SimplePie_Misc::url_remove_credentials($url)); } diff --git a/app/actualize_script.php b/app/actualize_script.php index ba9660a14..f1dec5640 100755 --- a/app/actualize_script.php +++ b/app/actualize_script.php @@ -12,6 +12,9 @@ if (defined('STDOUT')) { fwrite(STDOUT, 'Starting feed actualization at ' . $begin_date->format('c') . "\n"); //Unbuffered } +prepareSyslog(); +syslog(LOG_INFO, 'FreshRSS Start feeds actualization...'); + // Set the header params ($_GET) to call the FRSS application. $_GET['c'] = 'feed'; $_GET['a'] = 'actualize'; @@ -64,7 +67,7 @@ foreach ($users as $user) { if (!invalidateHttpCache()) { 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"); + fwrite(STDERR, 'FreshRSS write access problem in ' . join_path(USERS_PATH, $user, 'log.txt') . "\n"); } } } @@ -75,7 +78,8 @@ if (defined('STDOUT')) { $end_date = date_create('now'); $duration = date_diff($end_date, $begin_date); fwrite(STDOUT, 'Ending feed actualization at ' . $end_date->format('c') . "\n"); //Unbuffered - fwrite(STDOUT, 'Feed actualizations took ' . $duration->format('%a day(s), %h hour(s), %i minute(s) and %s seconds') . ' for ' . count($users) . " users\n"); //Unbuffered + fwrite(STDOUT, 'Feed actualizations took ' . $duration->format('%a day(s), %h hour(s), %i minute(s) and %s seconds') . ' for ' . count($users) . " users\n"); //Unbuffered } echo 'End.', "\n"; ob_end_flush(); +syslog(LOG_INFO, 'FreshRSS feeds actualization done.'); diff --git a/cli/_cli.php b/cli/_cli.php index 72629171c..e8fb6ae42 100644 --- a/cli/_cli.php +++ b/cli/_cli.php @@ -4,7 +4,7 @@ if (php_sapi_name() !== 'cli') { } require(__DIR__ . '/../constants.php'); -require(LIB_PATH . '/lib_rss.php'); +require(LIB_PATH . '/lib_rss.php'); //Includes class autoloader require(LIB_PATH . '/lib_install.php'); Minz_Configuration::register('system', diff --git a/lib/favicons.php b/lib/favicons.php index fe2e65f1f..7a2d1187e 100644 --- a/lib/favicons.php +++ b/lib/favicons.php @@ -22,6 +22,7 @@ function isImgMime($content) { } function downloadHttp(&$url, $curlOptions = array()) { + prepareSyslog(); syslog(LOG_INFO, 'FreshRSS Favicon GET ' . $url); if (substr($url, 0, 2) === '//') { $url = 'https:' . $url; diff --git a/lib/lib_install.php b/lib/lib_install.php index d51a37e58..6e4df4e9c 100644 --- a/lib/lib_install.php +++ b/lib/lib_install.php @@ -81,6 +81,7 @@ function generateSalt() { function checkDb(&$dbOptions) { $dsn = ''; $driver_options = null; + prepareSyslog(); try { switch ($dbOptions['type']) { case 'mysql': diff --git a/lib/lib_rss.php b/lib/lib_rss.php index 168309563..738ccf641 100644 --- a/lib/lib_rss.php +++ b/lib/lib_rss.php @@ -202,12 +202,19 @@ function html_only_entity_decode($text) { return strtr($text, $htmlEntitiesOnly); } +function prepareSyslog() { + return openlog("FreshRSS", LOG_PERROR | LOG_PID, LOG_USER); +} + function customSimplePie($attributes = array()) { $system_conf = Minz_Configuration::get('system'); $limits = $system_conf->limits; $simplePie = new SimplePie(); $simplePie->set_useragent(FRESHRSS_USERAGENT); $simplePie->set_syslog($system_conf->simplepie_syslog_enabled); + if ($system_conf->simplepie_syslog_enabled) { + prepareSyslog(); + } $simplePie->set_cache_location(CACHE_PATH); $simplePie->set_cache_duration($limits['cache_duration']); diff --git a/p/i/index.php b/p/i/index.php index 5bc9c0d76..8a4f529d4 100755 --- a/p/i/index.php +++ b/p/i/index.php @@ -50,5 +50,7 @@ if (file_exists(DATA_PATH . '/do-install.txt')) { echo '### Fatal error! ###
', "\n"; Minz_Log::error($e->getMessage()); echo 'See logs files.'; + prepareSyslog(); + syslog(LOG_INFO, 'FreshRSS Fatal error! ' . $e->getMessage()); } } -- cgit v1.2.3 From 9214eeecff363883d3d396490e8f1c7adf523c05 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Tue, 15 Jan 2019 18:51:13 +0100 Subject: Comment about Gecko scrollbar bug in Firefox 64 https://bugzilla.mozilla.org/show_bug.cgi?id=1514498 --- p/scripts/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'p') diff --git a/p/scripts/main.js b/p/scripts/main.js index 4ba329dc1..b12b3cf26 100644 --- a/p/scripts/main.js +++ b/p/scripts/main.js @@ -543,7 +543,7 @@ function init_column_categories() { } }); $(this).parent().next(".tree-folder-items").slideToggle(300, function () { - //Workaround for Gecko bug in Firefox 64-65(+?): + //Workaround for Gecko bug 1514498 in Firefox 64 var sidebar = document.getElementById('sidebar'); if (sidebar && sidebar.scrollHeight > sidebar.clientHeight && //if needs scrollbar sidebar.scrollWidth >= sidebar.offsetWidth) { //but no scrollbar -- cgit v1.2.3 From da4a80b88a64855bd62d996baabaaf25497c5f42 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Thu, 24 Jan 2019 19:43:28 +0100 Subject: Add a JavaScript event when opening an article (#2222) * Add a JavaScript event when opening an article https://framagit.org/nicofrand/xextension-threepanesview/issues/4 ```javascript document.body.addEventListener('freshrss:openArticle', function (e) { console.log('freshrss:openArticle'); console.log(e.target); }); ``` --- CHANGELOG.md | 2 ++ p/scripts/main.js | 10 ++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) (limited to 'p') diff --git a/CHANGELOG.md b/CHANGELOG.md index badc66e79..3a0188431 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,8 @@ * New `TZ` timezone environment variable [#2153](https://github.com/FreshRSS/FreshRSS/issues/2153) * Run Docker cron job with Apache user instead of root [#2208](https://github.com/FreshRSS/FreshRSS/pull/2208) * Accept HTTP header `X-WebAuth-User` for delegated HTTP Authentication [#2204](https://github.com/FreshRSS/FreshRSS/pull/2204) +* Extensions + * Trigger a `freshrss:openArticle` JavaScript event [#2222](https://github.com/FreshRSS/FreshRSS/pull/2222) * API * Automatic test of API configuration [#2207](https://github.com/FreshRSS/FreshRSS/pull/2207) * Performance + compatibility: Use Apache `SetEnvIf` module if available and fall-back to `RewriteRule` [#2202](https://github.com/FreshRSS/FreshRSS/pull/2202) diff --git a/p/scripts/main.js b/p/scripts/main.js index b12b3cf26..6cab2e55a 100644 --- a/p/scripts/main.js +++ b/p/scripts/main.js @@ -237,6 +237,9 @@ function mark_favorite(active) { }); } +var freshrssOpenArticleEvent = document.createEvent('Event'); +freshrssOpenArticleEvent.initEvent('freshrss:openArticle', true, true); + function toggleContent(new_active, old_active, skipping) { // If skipping, move current without activating or marking as read if (new_active.length === 0) { @@ -299,8 +302,11 @@ function toggleContent(new_active, old_active, skipping) { } } - if (context.auto_mark_article && new_active.hasClass('active') && !skipping) { - mark_read(new_active, true); + if (new_active.hasClass('active') && !skipping) { + if (context.auto_mark_article) { + mark_read(new_active, true); + } + new_active[0].dispatchEvent(freshrssOpenArticleEvent); } } -- cgit v1.2.3