From 4214954ea169e6cf6b9a7b2927dce892463c851c Mon Sep 17 00:00:00 2001 From: maTh Date: Sun, 21 Aug 2022 22:44:03 +0200 Subject: Improved: error page (#4465) * error page: true HTML page * error page: http500 erorr * error page: add CSP header * 'log.txt' replaced by LOG_FILENAME * use ADMIN_LOG * log.txt => LOG_FILENAME * error message: add * Docs created * delete: documentation on error message page * line break added * added: new line at the end * typo fixed * Update lib/lib_rss.php Co-authored-by: Alexandre Alapetite <alexandre@alapetite.fr> * Update lib/lib_rss.php Co-authored-by: Alexandre Alapetite <alexandre@alapetite.fr> * Minz HTTP 500 Co-authored-by: Alexandre Alapetite <alexandre@alapetite.fr> --- lib/Minz/FrontController.php | 17 +++++++++-------- lib/Minz/Log.php | 2 +- lib/lib_rss.php | 31 +++++++++++-------------------- 3 files changed, 21 insertions(+), 29 deletions(-) (limited to 'lib') diff --git a/lib/Minz/FrontController.php b/lib/Minz/FrontController.php index dea818a91..80fa5ce96 100644 --- a/lib/Minz/FrontController.php +++ b/lib/Minz/FrontController.php @@ -44,7 +44,7 @@ class Minz_FrontController { Minz_Request::forward ($url); } catch (Minz_Exception $e) { Minz_Log::error($e->getMessage()); - $this->killApp ($e->getMessage()); + self::killApp($e->getMessage()); } $this->dispatcher = Minz_Dispatcher::getInstance(); @@ -78,7 +78,7 @@ class Minz_FrontController { try { Minz_Log::error($e->getMessage()); } catch (Minz_PermissionDeniedException $e) { - $this->killApp ($e->getMessage ()); + self::killApp($e->getMessage()); } if ($e instanceof Minz_FileNotExistException || @@ -91,20 +91,21 @@ class Minz_FrontController { true ); } else { - $this->killApp($e->getMessage()); + self::killApp($e->getMessage()); } } } /** - * Permet d'arrĂȘter le programme en urgence - */ - private function killApp ($txt = '') { + * Kills the programme + */ + public static function killApp($txt = '') { + header('HTTP 1.1 500 Internal Server Error', true, 500); if (function_exists('errorMessageInfo')) { //If the application has defined a custom error message function - exit(errorMessageInfo('Application problem', $txt)); + die(errorMessageInfo('Application problem', $txt)); } - exit('### Application problem ###<br />' . "\n" . $txt); + die('### Application problem ###<br />' . "\n" . $txt); } private function setReporting() { diff --git a/lib/Minz/Log.php b/lib/Minz/Log.php index 80b93a097..43f3c9d6d 100644 --- a/lib/Minz/Log.php +++ b/lib/Minz/Log.php @@ -36,7 +36,7 @@ class Minz_Log { $username = '_'; } if ($file_name == null) { - $file_name = join_path(USERS_PATH, $username, 'log.txt'); + $file_name = join_path(USERS_PATH, $username, LOG_FILENAME); } else { $username = '_'; } diff --git a/lib/lib_rss.php b/lib/lib_rss.php index b485d379b..743aa7840 100644 --- a/lib/lib_rss.php +++ b/lib/lib_rss.php @@ -508,7 +508,7 @@ function invalidateHttpCache($username = '') { Minz_Session::_param('touch', uTimeString()); $username = Minz_Session::param('currentUser', '_'); } - $ok = @touch(DATA_PATH . '/users/' . $username . '/log.txt'); + $ok = @touch(DATA_PATH . '/users/' . $username . '/' . LOG_FILENAME); //if (!$ok) { //TODO: Display notification error on front-end //} @@ -569,9 +569,9 @@ function get_user_configuration($username) { FRESHRSS_PATH . '/config-user.default.php'); } catch (Minz_ConfigurationNamespaceException $e) { // namespace already exists, do nothing. - Minz_Log::warning($e->getMessage(), USERS_PATH . '/_/log.txt'); + Minz_Log::warning($e->getMessage(), ADMIN_LOG); } catch (Minz_FileNotExistException $e) { - Minz_Log::warning($e->getMessage(), USERS_PATH . '/_/log.txt'); + Minz_Log::warning($e->getMessage(), ADMIN_LOG); return null; } @@ -823,25 +823,16 @@ function errorMessageInfo($errorTitle, $error = '') { $details = "<pre>{$details}</pre>"; } + header("Content-Security-Policy: default-src 'self'"); + return <<<MSG - <h1>{$errorTitle}</h1> + <!DOCTYPE html><html><header><title>HTTP 500: {$errorTitle} +

HTTP 500: {$errorTitle}

{$message} {$details} -

Check the logs

-

FreshRSS logs are located in ./FreshRSS/data/users/*/log*.txt

-

N.B.: A typical problem is wrong file permissions in the ./FreshRSS/data/ folder - so make sure the Web server can write there and in sub-directories.

-

Common locations for additional logs

-

N.B.: Adapt names and paths according to your local setup.

- -

More logs can be generated by enabling 'environment' => 'development', in ./FreshRSS/data/config.php

-

Running the feed update script (with the same user and PHP version as your Web server) might provide other hints, e.g.: - sudo -u www-data /usr/bin/php ./FreshRSS/app/actualize_script.php

+
+ For help see the documentation: + https://freshrss.github.io/FreshRSS/en/admins/logs_and_errors.html + MSG; } -- cgit v1.2.3