New debug option

This commit is contained in:
Pierre Rudloff 2019-11-27 21:22:23 +01:00
parent 89c1538d0f
commit 0b1ce90f47
4 changed files with 27 additions and 13 deletions

View File

@ -34,5 +34,5 @@ FileETag None
Header set X-Content-Type-Options nosniff Header set X-Content-Type-Options nosniff
Header set X-XSS-Protection "1; mode=block" Header set X-XSS-Protection "1; mode=block"
Header set Referrer-Policy no-referrer Header set Referrer-Policy no-referrer
Header set Content-Security-Policy "default-src 'self'; object-src 'none'; script-src 'none'; img-src http:" Header set Content-Security-Policy "default-src 'self'; object-src 'none'; script-src 'none'; style-src 'self' 'unsafe-inline'; img-src http:"
</ifmodule> </ifmodule>

View File

@ -135,6 +135,8 @@ class Config
*/ */
public $genericFormats = []; public $genericFormats = [];
public $debug = false;
/** /**
* Config constructor. * Config constructor.
* *

View File

@ -16,6 +16,7 @@ use Slim\Container;
use Slim\Http\Request; use Slim\Http\Request;
use Slim\Http\Response; use Slim\Http\Response;
use Slim\Views\Smarty; use Slim\Views\Smarty;
use Symfony\Component\Debug\ExceptionHandler;
/** /**
* Main controller. * Main controller.
@ -233,18 +234,23 @@ class FrontController extends BaseController
*/ */
public function error(Request $request, Response $response, Exception $exception) public function error(Request $request, Response $response, Exception $exception)
{ {
$this->view->render( if ($this->config->debug) {
$response, $handler = new ExceptionHandler();
'error.tpl', $handler->handle($exception);
[ } else {
'config' => $this->config, $this->view->render(
'errors' => $exception->getMessage(), $response,
'class' => 'video', 'error.tpl',
'title' => _('Error'), [
'canonical' => $this->getCanonicalUrl($request), 'config' => $this->config,
'locale' => $this->localeManager->getLocale(), 'errors' => $exception->getMessage(),
] 'class' => 'video',
); 'title' => _('Error'),
'canonical' => $this->getCanonicalUrl($request),
'locale' => $this->localeManager->getLocale(),
]
);
}
return $response->withStatus(500); return $response->withStatus(500);
} }

View File

@ -10,6 +10,7 @@ use Alltube\LocaleMiddleware;
use Alltube\UglyRouter; use Alltube\UglyRouter;
use Alltube\ViewFactory; use Alltube\ViewFactory;
use Slim\App; use Slim\App;
use Symfony\Component\Debug\Debug;
if (isset($_SERVER['REQUEST_URI']) && strpos($_SERVER['REQUEST_URI'], '/index.php') !== false) { if (isset($_SERVER['REQUEST_URI']) && strpos($_SERVER['REQUEST_URI'], '/index.php') !== false) {
header('Location: ' . str_ireplace('/index.php', '/', $_SERVER['REQUEST_URI'])); header('Location: ' . str_ireplace('/index.php', '/', $_SERVER['REQUEST_URI']));
@ -26,6 +27,11 @@ $config = Config::getInstance();
if ($config->uglyUrls) { if ($config->uglyUrls) {
$container['router'] = new UglyRouter(); $container['router'] = new UglyRouter();
} }
if ($config->debug) {
Debug::enable();
}
$container['view'] = ViewFactory::create($container); $container['view'] = ViewFactory::create($container);
if (!class_exists('Locale')) { if (!class_exists('Locale')) {