aboutsummaryrefslogtreecommitdiffhomepage
path: root/index.php
diff options
context:
space:
mode:
Diffstat (limited to 'index.php')
-rw-r--r--index.php57
1 files changed, 42 insertions, 15 deletions
diff --git a/index.php b/index.php
index b10397dd..1eb7659a 100644
--- a/index.php
+++ b/index.php
@@ -1,4 +1,5 @@
1<?php 1<?php
2
2/** 3/**
3 * Shaarli - The personal, minimalist, super-fast, database free, bookmarking service. 4 * Shaarli - The personal, minimalist, super-fast, database free, bookmarking service.
4 * 5 *
@@ -25,9 +26,12 @@ require_once 'application/Utils.php';
25 26
26require_once __DIR__ . '/init.php'; 27require_once __DIR__ . '/init.php';
27 28
29use Katzgrau\KLogger\Logger;
30use Psr\Log\LogLevel;
28use Shaarli\Config\ConfigManager; 31use Shaarli\Config\ConfigManager;
29use Shaarli\Container\ContainerBuilder; 32use Shaarli\Container\ContainerBuilder;
30use Shaarli\Languages; 33use Shaarli\Languages;
34use Shaarli\Security\BanManager;
31use Shaarli\Security\CookieManager; 35use Shaarli\Security\CookieManager;
32use Shaarli\Security\LoginManager; 36use Shaarli\Security\LoginManager;
33use Shaarli\Security\SessionManager; 37use Shaarli\Security\SessionManager;
@@ -48,10 +52,22 @@ if ($conf->get('dev.debug', false)) {
48 }); 52 });
49} 53}
50 54
55$logger = new Logger(
56 dirname($conf->get('resource.log')),
57 !$conf->get('dev.debug') ? LogLevel::INFO : LogLevel::DEBUG,
58 ['filename' => basename($conf->get('resource.log'))]
59);
51$sessionManager = new SessionManager($_SESSION, $conf, session_save_path()); 60$sessionManager = new SessionManager($_SESSION, $conf, session_save_path());
52$sessionManager->initialize(); 61$sessionManager->initialize();
53$cookieManager = new CookieManager($_COOKIE); 62$cookieManager = new CookieManager($_COOKIE);
54$loginManager = new LoginManager($conf, $sessionManager, $cookieManager); 63$banManager = new BanManager(
64 $conf->get('security.trusted_proxies', []),
65 $conf->get('security.ban_after'),
66 $conf->get('security.ban_duration'),
67 $conf->get('resource.ban_file', 'data/ipbans.php'),
68 $logger
69);
70$loginManager = new LoginManager($conf, $sessionManager, $cookieManager, $banManager, $logger);
55$loginManager->generateStaySignedInToken($_SERVER['REMOTE_ADDR']); 71$loginManager->generateStaySignedInToken($_SERVER['REMOTE_ADDR']);
56 72
57// Sniff browser language and set date format accordingly. 73// Sniff browser language and set date format accordingly.
@@ -62,16 +78,16 @@ if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
62new Languages(setlocale(LC_MESSAGES, 0), $conf); 78new Languages(setlocale(LC_MESSAGES, 0), $conf);
63 79
64$conf->setEmpty('general.timezone', date_default_timezone_get()); 80$conf->setEmpty('general.timezone', date_default_timezone_get());
65$conf->setEmpty('general.title', t('Shared bookmarks on '). escape(index_url($_SERVER))); 81$conf->setEmpty('general.title', t('Shared bookmarks on ') . escape(index_url($_SERVER)));
66 82
67RainTPL::$tpl_dir = $conf->get('resource.raintpl_tpl').'/'.$conf->get('resource.theme').'/'; // template directory 83RainTPL::$tpl_dir = $conf->get('resource.raintpl_tpl') . '/' . $conf->get('resource.theme') . '/'; // template directory
68RainTPL::$cache_dir = $conf->get('resource.raintpl_tmp'); // cache directory 84RainTPL::$cache_dir = $conf->get('resource.raintpl_tmp'); // cache directory
69 85
70date_default_timezone_set($conf->get('general.timezone', 'UTC')); 86date_default_timezone_set($conf->get('general.timezone', 'UTC'));
71 87
72$loginManager->checkLoginState(client_ip_id($_SERVER)); 88$loginManager->checkLoginState(client_ip_id($_SERVER));
73 89
74$containerBuilder = new ContainerBuilder($conf, $sessionManager, $cookieManager, $loginManager); 90$containerBuilder = new ContainerBuilder($conf, $sessionManager, $cookieManager, $loginManager, $logger);
75$container = $containerBuilder->build(); 91$container = $containerBuilder->build();
76$app = new App($container); 92$app = new App($container);
77 93
@@ -110,13 +126,16 @@ $app->group('/admin', function () {
110 $this->post('/configure', '\Shaarli\Front\Controller\Admin\ConfigureController:save'); 126 $this->post('/configure', '\Shaarli\Front\Controller\Admin\ConfigureController:save');
111 $this->get('/tags', '\Shaarli\Front\Controller\Admin\ManageTagController:index'); 127 $this->get('/tags', '\Shaarli\Front\Controller\Admin\ManageTagController:index');
112 $this->post('/tags', '\Shaarli\Front\Controller\Admin\ManageTagController:save'); 128 $this->post('/tags', '\Shaarli\Front\Controller\Admin\ManageTagController:save');
113 $this->get('/add-shaare', '\Shaarli\Front\Controller\Admin\ManageShaareController:addShaare'); 129 $this->post('/tags/change-separator', '\Shaarli\Front\Controller\Admin\ManageTagController:changeSeparator');
114 $this->get('/shaare', '\Shaarli\Front\Controller\Admin\ManageShaareController:displayCreateForm'); 130 $this->get('/add-shaare', '\Shaarli\Front\Controller\Admin\ShaareAddController:addShaare');
115 $this->get('/shaare/{id:[0-9]+}', '\Shaarli\Front\Controller\Admin\ManageShaareController:displayEditForm'); 131 $this->get('/shaare', '\Shaarli\Front\Controller\Admin\ShaarePublishController:displayCreateForm');
116 $this->post('/shaare', '\Shaarli\Front\Controller\Admin\ManageShaareController:save'); 132 $this->get('/shaare/{id:[0-9]+}', '\Shaarli\Front\Controller\Admin\ShaarePublishController:displayEditForm');
117 $this->get('/shaare/delete', '\Shaarli\Front\Controller\Admin\ManageShaareController:deleteBookmark'); 133 $this->get('/shaare/private/{hash}', '\Shaarli\Front\Controller\Admin\ShaareManageController:sharePrivate');
118 $this->get('/shaare/visibility', '\Shaarli\Front\Controller\Admin\ManageShaareController:changeVisibility'); 134 $this->post('/shaare-batch', '\Shaarli\Front\Controller\Admin\ShaarePublishController:displayCreateBatchForms');
119 $this->get('/shaare/{id:[0-9]+}/pin', '\Shaarli\Front\Controller\Admin\ManageShaareController:pinBookmark'); 135 $this->post('/shaare', '\Shaarli\Front\Controller\Admin\ShaarePublishController:save');
136 $this->get('/shaare/delete', '\Shaarli\Front\Controller\Admin\ShaareManageController:deleteBookmark');
137 $this->get('/shaare/visibility', '\Shaarli\Front\Controller\Admin\ShaareManageController:changeVisibility');
138 $this->get('/shaare/{id:[0-9]+}/pin', '\Shaarli\Front\Controller\Admin\ShaareManageController:pinBookmark');
120 $this->patch( 139 $this->patch(
121 '/shaare/{id:[0-9]+}/update-thumbnail', 140 '/shaare/{id:[0-9]+}/update-thumbnail',
122 '\Shaarli\Front\Controller\Admin\ThumbnailsController:ajaxUpdate' 141 '\Shaarli\Front\Controller\Admin\ThumbnailsController:ajaxUpdate'
@@ -128,8 +147,10 @@ $app->group('/admin', function () {
128 $this->get('/plugins', '\Shaarli\Front\Controller\Admin\PluginsController:index'); 147 $this->get('/plugins', '\Shaarli\Front\Controller\Admin\PluginsController:index');
129 $this->post('/plugins', '\Shaarli\Front\Controller\Admin\PluginsController:save'); 148 $this->post('/plugins', '\Shaarli\Front\Controller\Admin\PluginsController:save');
130 $this->get('/token', '\Shaarli\Front\Controller\Admin\TokenController:getToken'); 149 $this->get('/token', '\Shaarli\Front\Controller\Admin\TokenController:getToken');
150 $this->get('/server', '\Shaarli\Front\Controller\Admin\ServerController:index');
151 $this->get('/clear-cache', '\Shaarli\Front\Controller\Admin\ServerController:clearCache');
131 $this->get('/thumbnails', '\Shaarli\Front\Controller\Admin\ThumbnailsController:index'); 152 $this->get('/thumbnails', '\Shaarli\Front\Controller\Admin\ThumbnailsController:index');
132 153 $this->get('/metadata', '\Shaarli\Front\Controller\Admin\MetadataController:ajaxRetrieveTitle');
133 $this->get('/visibility/{visibility}', '\Shaarli\Front\Controller\Admin\SessionFilterController:visibility'); 154 $this->get('/visibility/{visibility}', '\Shaarli\Front\Controller\Admin\SessionFilterController:visibility');
134})->add('\Shaarli\Front\ShaarliAdminMiddleware'); 155})->add('\Shaarli\Front\ShaarliAdminMiddleware');
135 156
@@ -151,6 +172,12 @@ $app->group('/api/v1', function () {
151 $this->get('/history', '\Shaarli\Api\Controllers\HistoryController:getHistory')->setName('getHistory'); 172 $this->get('/history', '\Shaarli\Api\Controllers\HistoryController:getHistory')->setName('getHistory');
152})->add('\Shaarli\Api\ApiMiddleware'); 173})->add('\Shaarli\Api\ApiMiddleware');
153 174
154$response = $app->run(true); 175try {
155 176 $response = $app->run(true);
156$app->respond($response); 177 $app->respond($response);
178} catch (Throwable $e) {
179 die(nl2br(
180 'An unexpected error happened, and the error template could not be displayed.' . PHP_EOL . PHP_EOL .
181 exception2text($e)
182 ));
183}