]>
Commit | Line | Data |
---|---|---|
0cf76ccb A |
1 | <?php |
2 | ||
3 | declare(strict_types=1); | |
4 | ||
5 | namespace Shaarli\Front\Controller\Admin; | |
6 | ||
54afb1d6 A |
7 | use Shaarli\Helper\ApplicationUtils; |
8 | use Shaarli\Helper\FileUtils; | |
0cf76ccb A |
9 | use Slim\Http\Request; |
10 | use Slim\Http\Response; | |
11 | ||
12 | /** | |
13 | * Slim controller used to handle Server administration page, and actions. | |
14 | */ | |
15 | class ServerController extends ShaarliAdminController | |
16 | { | |
17 | /** @var string Cache type - main - by default pagecache/ and tmp/ */ | |
18 | protected const CACHE_MAIN = 'main'; | |
19 | ||
20 | /** @var string Cache type - thumbnails - by default cache/ */ | |
21 | protected const CACHE_THUMB = 'thumbnails'; | |
22 | ||
23 | /** | |
24 | * GET /admin/server - Display page Server administration | |
25 | */ | |
26 | public function index(Request $request, Response $response): Response | |
27 | { | |
80c8889b A |
28 | $releaseUrl = ApplicationUtils::$GITHUB_URL . '/releases/'; |
29 | if ($this->container->conf->get('updates.check_updates', true)) { | |
30 | $latestVersion = 'v' . ApplicationUtils::getVersion( | |
31 | ApplicationUtils::$GIT_RAW_URL . '/latest/' . ApplicationUtils::$VERSION_FILE | |
32 | ); | |
33 | $releaseUrl .= 'tag/' . $latestVersion; | |
34 | } else { | |
35 | $latestVersion = t('Check disabled'); | |
36 | } | |
37 | ||
0cf76ccb A |
38 | $currentVersion = ApplicationUtils::getVersion('./shaarli_version.php'); |
39 | $currentVersion = $currentVersion === 'dev' ? $currentVersion : 'v' . $currentVersion; | |
40 | $phpEol = new \DateTimeImmutable(ApplicationUtils::getPhpEol(PHP_VERSION)); | |
41 | ||
42 | $this->assignView('php_version', PHP_VERSION); | |
43 | $this->assignView('php_eol', format_date($phpEol, false)); | |
44 | $this->assignView('php_has_reached_eol', $phpEol < new \DateTimeImmutable()); | |
45 | $this->assignView('php_extensions', ApplicationUtils::getPhpExtensionsRequirement()); | |
46 | $this->assignView('permissions', ApplicationUtils::checkResourcePermissions($this->container->conf)); | |
80c8889b | 47 | $this->assignView('release_url', $releaseUrl); |
0cf76ccb A |
48 | $this->assignView('latest_version', $latestVersion); |
49 | $this->assignView('current_version', $currentVersion); | |
50 | $this->assignView('thumbnails_mode', $this->container->conf->get('thumbnails.mode')); | |
51 | $this->assignView('index_url', index_url($this->container->environment)); | |
52 | $this->assignView('client_ip', client_ip_id($this->container->environment)); | |
53 | $this->assignView('trusted_proxies', $this->container->conf->get('security.trusted_proxies', [])); | |
54 | ||
55 | $this->assignView( | |
56 | 'pagetitle', | |
57 | t('Server administration') . ' - ' . $this->container->conf->get('general.title', 'Shaarli') | |
58 | ); | |
59 | ||
60 | return $response->write($this->render('server')); | |
61 | } | |
62 | ||
63 | /** | |
64 | * GET /admin/clear-cache?type={$type} - Action to trigger cache folder clearing (either main or thumbnails). | |
65 | */ | |
66 | public function clearCache(Request $request, Response $response): Response | |
67 | { | |
68 | $exclude = ['.htaccess']; | |
69 | ||
70 | if ($request->getQueryParam('type') === static::CACHE_THUMB) { | |
71 | $folders = [$this->container->conf->get('resource.thumbnails_cache')]; | |
72 | ||
73 | $this->saveWarningMessage( | |
74 | t('Thumbnails cache has been cleared.') . ' ' . | |
75 | '<a href="'. $this->container->basePath .'/admin/thumbnails">' . t('Please synchronize them.') .'</a>' | |
76 | ); | |
77 | } else { | |
78 | $folders = [ | |
79 | $this->container->conf->get('resource.page_cache'), | |
80 | $this->container->conf->get('resource.raintpl_tmp'), | |
81 | ]; | |
82 | ||
83 | $this->saveSuccessMessage(t('Shaarli\'s cache folder has been cleared!')); | |
84 | } | |
85 | ||
86 | // Make sure that we don't delete root cache folder | |
87 | $folders = array_map('realpath', array_values(array_filter(array_map('trim', $folders)))); | |
88 | foreach ($folders as $folder) { | |
89 | FileUtils::clearFolder($folder, false, $exclude); | |
90 | } | |
91 | ||
92 | return $this->redirect($response, '/admin/server'); | |
93 | } | |
94 | } |