diff options
Diffstat (limited to 'index.php')
-rw-r--r-- | index.php | 31 |
1 files changed, 26 insertions, 5 deletions
@@ -25,9 +25,12 @@ require_once 'application/Utils.php'; | |||
25 | 25 | ||
26 | require_once __DIR__ . '/init.php'; | 26 | require_once __DIR__ . '/init.php'; |
27 | 27 | ||
28 | use Katzgrau\KLogger\Logger; | ||
29 | use Psr\Log\LogLevel; | ||
28 | use Shaarli\Config\ConfigManager; | 30 | use Shaarli\Config\ConfigManager; |
29 | use Shaarli\Container\ContainerBuilder; | 31 | use Shaarli\Container\ContainerBuilder; |
30 | use Shaarli\Languages; | 32 | use Shaarli\Languages; |
33 | use Shaarli\Security\BanManager; | ||
31 | use Shaarli\Security\CookieManager; | 34 | use Shaarli\Security\CookieManager; |
32 | use Shaarli\Security\LoginManager; | 35 | use Shaarli\Security\LoginManager; |
33 | use Shaarli\Security\SessionManager; | 36 | use Shaarli\Security\SessionManager; |
@@ -48,10 +51,22 @@ if ($conf->get('dev.debug', false)) { | |||
48 | }); | 51 | }); |
49 | } | 52 | } |
50 | 53 | ||
54 | $logger = new Logger( | ||
55 | dirname($conf->get('resource.log')), | ||
56 | !$conf->get('dev.debug') ? LogLevel::INFO : LogLevel::DEBUG, | ||
57 | ['filename' => basename($conf->get('resource.log'))] | ||
58 | ); | ||
51 | $sessionManager = new SessionManager($_SESSION, $conf, session_save_path()); | 59 | $sessionManager = new SessionManager($_SESSION, $conf, session_save_path()); |
52 | $sessionManager->initialize(); | 60 | $sessionManager->initialize(); |
53 | $cookieManager = new CookieManager($_COOKIE); | 61 | $cookieManager = new CookieManager($_COOKIE); |
54 | $loginManager = new LoginManager($conf, $sessionManager, $cookieManager); | 62 | $banManager = new BanManager( |
63 | $conf->get('security.trusted_proxies', []), | ||
64 | $conf->get('security.ban_after'), | ||
65 | $conf->get('security.ban_duration'), | ||
66 | $conf->get('resource.ban_file', 'data/ipbans.php'), | ||
67 | $logger | ||
68 | ); | ||
69 | $loginManager = new LoginManager($conf, $sessionManager, $cookieManager, $banManager, $logger); | ||
55 | $loginManager->generateStaySignedInToken($_SERVER['REMOTE_ADDR']); | 70 | $loginManager->generateStaySignedInToken($_SERVER['REMOTE_ADDR']); |
56 | 71 | ||
57 | // Sniff browser language and set date format accordingly. | 72 | // Sniff browser language and set date format accordingly. |
@@ -71,7 +86,7 @@ date_default_timezone_set($conf->get('general.timezone', 'UTC')); | |||
71 | 86 | ||
72 | $loginManager->checkLoginState(client_ip_id($_SERVER)); | 87 | $loginManager->checkLoginState(client_ip_id($_SERVER)); |
73 | 88 | ||
74 | $containerBuilder = new ContainerBuilder($conf, $sessionManager, $cookieManager, $loginManager); | 89 | $containerBuilder = new ContainerBuilder($conf, $sessionManager, $cookieManager, $loginManager, $logger); |
75 | $container = $containerBuilder->build(); | 90 | $container = $containerBuilder->build(); |
76 | $app = new App($container); | 91 | $app = new App($container); |
77 | 92 | ||
@@ -153,6 +168,12 @@ $app->group('/api/v1', function () { | |||
153 | $this->get('/history', '\Shaarli\Api\Controllers\HistoryController:getHistory')->setName('getHistory'); | 168 | $this->get('/history', '\Shaarli\Api\Controllers\HistoryController:getHistory')->setName('getHistory'); |
154 | })->add('\Shaarli\Api\ApiMiddleware'); | 169 | })->add('\Shaarli\Api\ApiMiddleware'); |
155 | 170 | ||
156 | $response = $app->run(true); | 171 | try { |
157 | 172 | $response = $app->run(true); | |
158 | $app->respond($response); | 173 | $app->respond($response); |
174 | } catch (Throwable $e) { | ||
175 | die(nl2br( | ||
176 | 'An unexpected error happened, and the error template could not be displayed.' . PHP_EOL . PHP_EOL . | ||
177 | exception2text($e) | ||
178 | )); | ||
179 | } | ||