浏览代码

Better error message on failure (#3407)

* bump default logout from 30 to 365 days

* * Change cookie duration to constant
* Change cookie duration to three months

* use class

* use 90 days (otherwise login form says 91.3 days)

* change class

* also this works now

* Better error message

* inconsistent dot with the other message

* Better error message

* add errorMessage()

* fix style

* html escape the error title

* also html escape error message

* remove spaces before parentheses

* rework the error message

* Minz-friendly

* Update message

Do not advise running this script as wrong user

* Update lib/lib_rss.php

Co-authored-by: Martin <spleefer90@gmail.com>

Co-authored-by: Martin Rys <martin@rys.pw>
Co-authored-by: Frans de Jonge <fransdejonge@gmail.com>
Co-authored-by: Alexandre Alapetite <alexandre@alapetite.fr>
Martin 5 年之前
父节点
当前提交
934f032c19
共有 3 个文件被更改,包括 44 次插入19 次删除
  1. 16 15
      lib/Minz/FrontController.php
  2. 27 0
      lib/lib_rss.php
  3. 1 4
      p/i/index.php

+ 16 - 15
lib/Minz/FrontController.php

@@ -43,7 +43,7 @@ class Minz_FrontController {
 			Minz_Request::forward ($url);
 			Minz_Request::forward ($url);
 		} catch (Minz_Exception $e) {
 		} catch (Minz_Exception $e) {
 			Minz_Log::error($e->getMessage());
 			Minz_Log::error($e->getMessage());
-			$this->killApp ($e->getMessage ());
+			$this->killApp ($e->getMessage());
 		}
 		}
 
 
 		$this->dispatcher = Minz_Dispatcher::getInstance();
 		$this->dispatcher = Minz_Dispatcher::getInstance();
@@ -54,21 +54,21 @@ class Minz_FrontController {
 	 * @return tableau représentant l'url
 	 * @return tableau représentant l'url
 	 */
 	 */
 	private function buildUrl() {
 	private function buildUrl() {
-		$url = array ();
+		$url = array();
 
 
-		$url['c'] = Minz_Request::fetchGET (
+		$url['c'] = Minz_Request::fetchGET(
 			'c',
 			'c',
-			Minz_Request::defaultControllerName ()
+			Minz_Request::defaultControllerName()
 		);
 		);
-		$url['a'] = Minz_Request::fetchGET (
+		$url['a'] = Minz_Request::fetchGET(
 			'a',
 			'a',
-			Minz_Request::defaultActionName ()
+			Minz_Request::defaultActionName()
 		);
 		);
-		$url['params'] = Minz_Request::fetchGET ();
+		$url['params'] = Minz_Request::fetchGET();
 
 
 		// post-traitement
 		// post-traitement
-		unset ($url['params']['c']);
-		unset ($url['params']['a']);
+		unset($url['params']['c']);
+		unset($url['params']['a']);
 
 
 		return $url;
 		return $url;
 	}
 	}
@@ -76,7 +76,7 @@ class Minz_FrontController {
 	/**
 	/**
 	 * Démarre l'application (lance le dispatcher et renvoie la réponse)
 	 * Démarre l'application (lance le dispatcher et renvoie la réponse)
 	 */
 	 */
-	public function run () {
+	public function run() {
 		try {
 		try {
 			$this->dispatcher->run();
 			$this->dispatcher->run();
 		} catch (Minz_Exception $e) {
 		} catch (Minz_Exception $e) {
@@ -92,11 +92,11 @@ class Minz_FrontController {
 					$e instanceof Minz_ActionException) {
 					$e instanceof Minz_ActionException) {
 				Minz_Error::error (
 				Minz_Error::error (
 					404,
 					404,
-					array ('error' => array ($e->getMessage ())),
+					array('error' => array ($e->getMessage ())),
 					true
 					true
 				);
 				);
 			} else {
 			} else {
-				$this->killApp ();
+				$this->killApp();
 			}
 			}
 		}
 		}
 	}
 	}
@@ -105,10 +105,11 @@ class Minz_FrontController {
 	* Permet d'arrêter le programme en urgence
 	* Permet d'arrêter le programme en urgence
 	*/
 	*/
 	private function killApp ($txt = '') {
 	private function killApp ($txt = '') {
-		if ($txt == '') {
-			$txt = 'See logs files';
+		if (function_exists('errorMessage')) {
+			//If the application has defined a custom error message function
+			exit(errorMessage('Application problem', $txt));
 		}
 		}
-		exit ('### Application problem ###<br />'."\n".$txt);
+		exit('### Application problem ###<br />' . "\n" . $txt);
 	}
 	}
 
 
 	private function setReporting() {
 	private function setReporting() {

+ 27 - 0
lib/lib_rss.php

@@ -578,3 +578,30 @@ function validateShortcutList($shortcuts) {
 	}
 	}
 	return $shortcuts_ok;
 	return $shortcuts_ok;
 }
 }
+
+function errorMessage($errorTitle, $error = '') {
+	// Prevent empty <h2> tags by checking if error isn't empty first
+	if ('' !== $error) {
+		$error = htmlspecialchars($error, ENT_NOQUOTES, 'UTF-8');
+		$error = "<h2>{$error}</h2>";
+	}
+	$errorTitle = htmlspecialchars($errorTitle, ENT_NOQUOTES, 'UTF-8');
+	return <<<MSG
+	<h1>{$errorTitle}</h1>
+	{$error}
+	<h2>Common problems</h2>
+	<p>A typical problem leading to this message is wrong file permissions in the <code>./FreshRSS/data/</code> folder so make sure the Web server can write there and in sub-directories.</p>
+	<h2>Common locations for additional logs</h2>
+	<p><strong>N.B.:</strong> Adapt names and paths according to your local setup.</p>
+	<ul>
+	<li>If using Docker: <code>docker logs -f freshrss</code></li>
+	<li>To check Web server logs on a Linux system using systemd: <code>journalctl -xeu apache2</code>
+	and if you are using php-fpm: <code>journalctl -xeu php-fpm</code></li>
+	<li>Otherwise, Web server logs are typically located in <code>/var/log/apache2/</code> or similar</li>
+	<li>System logs may also contain relevant information in <code>/var/log/syslog</code>, or if using systemd: <code>sudo journalctl -xe</code></li>
+	</ul>
+	<p>More logs can be generated by enabling <code>'environment' => 'development',</code> in <code>./FreshRSS/data/config.php</code></p>
+	<p>Running the feed update script (with the same user and PHP version as your Web server) might provide other hints, e.g.:
+		<code>sudo -u www-data /usr/bin/php ./FreshRSS/app/actualize_script.php</code></p>
+	MSG;
+}

+ 1 - 4
p/i/index.php

@@ -76,11 +76,8 @@ if (file_exists(DATA_PATH . '/do-install.txt')) {
 	}
 	}
 
 
 	if ($error) {
 	if ($error) {
-		// TODO this should be definitely improved to display a nicer error
-		// page to the users (especially non administrators).
-		echo '### Fatal error! ###<br />', "\n";
 		Minz_Log::error($error);
 		Minz_Log::error($error);
-		echo 'See logs files.';
+		errorMessage('Fatal error');
 		syslog(LOG_INFO, 'FreshRSS Fatal error! ' . $error);
 		syslog(LOG_INFO, 'FreshRSS Fatal error! ' . $error);
 	}
 	}
 }
 }