aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--.docker/nginx.conf7
-rw-r--r--application/Utils.php9
-rw-r--r--application/front/controller/visitor/ErrorController.php5
-rw-r--r--doc/md/Server-configuration.md5
-rw-r--r--index.php12
5 files changed, 30 insertions, 8 deletions
diff --git a/.docker/nginx.conf b/.docker/nginx.conf
index 07fba33f..023f52c1 100644
--- a/.docker/nginx.conf
+++ b/.docker/nginx.conf
@@ -29,7 +29,7 @@ http {
29 log_not_found off; 29 log_not_found off;
30 deny all; 30 deny all;
31 } 31 }
32 32
33 location ~ ~$ { 33 location ~ ~$ {
34 # deny access to temp editor files, e.g. "script.php~" 34 # deny access to temp editor files, e.g. "script.php~"
35 access_log off; 35 access_log off;
@@ -65,6 +65,11 @@ http {
65 include fastcgi.conf; 65 include fastcgi.conf;
66 } 66 }
67 67
68 location ~ /doc/ {
69 default_type "text/html";
70 try_files $uri $uri/ $uri.html =404;
71 }
72
68 location ~ \.php$ { 73 location ~ \.php$ {
69 # deny access to all other PHP scripts 74 # deny access to all other PHP scripts
70 deny all; 75 deny all;
diff --git a/application/Utils.php b/application/Utils.php
index 7a9d2645..bc1c9f5d 100644
--- a/application/Utils.php
+++ b/application/Utils.php
@@ -465,3 +465,12 @@ function t($text, $nText = '', $nb = 1, $domain = 'shaarli')
465{ 465{
466 return dn__($domain, $text, $nText, $nb); 466 return dn__($domain, $text, $nText, $nb);
467} 467}
468
469/**
470 * Converts an exception into a printable stack trace string.
471 */
472function exception2text(Throwable $e): string
473{
474 return $e->getMessage() . PHP_EOL . $e->getFile() . $e->getLine() . PHP_EOL . $e->getTraceAsString();
475}
476
diff --git a/application/front/controller/visitor/ErrorController.php b/application/front/controller/visitor/ErrorController.php
index 10aa84c8..8da11172 100644
--- a/application/front/controller/visitor/ErrorController.php
+++ b/application/front/controller/visitor/ErrorController.php
@@ -28,10 +28,7 @@ class ErrorController extends ShaarliVisitorController
28 // Internal error (any other Throwable) 28 // Internal error (any other Throwable)
29 if ($this->container->conf->get('dev.debug', false)) { 29 if ($this->container->conf->get('dev.debug', false)) {
30 $this->assignView('message', $throwable->getMessage()); 30 $this->assignView('message', $throwable->getMessage());
31 $this->assignView( 31 $this->assignView('stacktrace', exception2text($throwable));
32 'stacktrace',
33 nl2br(get_class($throwable) .': '. PHP_EOL . $throwable->getTraceAsString())
34 );
35 } else { 32 } else {
36 $this->assignView('message', t('An unexpected error occurred.')); 33 $this->assignView('message', t('An unexpected error occurred.'));
37 } 34 }
diff --git a/doc/md/Server-configuration.md b/doc/md/Server-configuration.md
index 8cb39934..4e74d80b 100644
--- a/doc/md/Server-configuration.md
+++ b/doc/md/Server-configuration.md
@@ -325,6 +325,11 @@ server {
325 deny all; 325 deny all;
326 } 326 }
327 327
328 location ~ /doc/ {
329 default_type "text/html";
330 try_files $uri $uri/ $uri.html =404;
331 }
332
328 location = /favicon.ico { 333 location = /favicon.ico {
329 # serve the Shaarli favicon from its custom location 334 # serve the Shaarli favicon from its custom location
330 alias /var/www/shaarli/images/favicon.ico; 335 alias /var/www/shaarli/images/favicon.ico;
diff --git a/index.php b/index.php
index ea6e8501..1b10ee41 100644
--- a/index.php
+++ b/index.php
@@ -166,6 +166,12 @@ $app->group('/api/v1', function () {
166 $this->get('/history', '\Shaarli\Api\Controllers\HistoryController:getHistory')->setName('getHistory'); 166 $this->get('/history', '\Shaarli\Api\Controllers\HistoryController:getHistory')->setName('getHistory');
167})->add('\Shaarli\Api\ApiMiddleware'); 167})->add('\Shaarli\Api\ApiMiddleware');
168 168
169$response = $app->run(true); 169try {
170 170 $response = $app->run(true);
171$app->respond($response); 171 $app->respond($response);
172} catch (Throwable $e) {
173 die(nl2br(
174 'An unexpected error happened, and the error template could not be displayed.' . PHP_EOL . PHP_EOL .
175 exception2text($e)
176 ));
177}