diff options
author | yude <yudesleepy@gmail.com> | 2021-01-04 18:51:10 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-04 18:51:10 +0900 |
commit | e6754f2154a79abd8e5e64bd923f6984aa9ad44b (patch) | |
tree | f074119530bb59ef155938ea367f719f1e4b70f1 /application/front/controller/admin/ServerController.php | |
parent | 5256b4287021342a9f8868967b2a77e481314331 (diff) | |
parent | ed4ee8f0297941ac83300389b7de6a293312d20e (diff) | |
download | Shaarli-e6754f2154a79abd8e5e64bd923f6984aa9ad44b.tar.gz Shaarli-e6754f2154a79abd8e5e64bd923f6984aa9ad44b.tar.zst Shaarli-e6754f2154a79abd8e5e64bd923f6984aa9ad44b.zip |
Merge pull request #2 from shaarli/master
Merge fork source
Diffstat (limited to 'application/front/controller/admin/ServerController.php')
-rw-r--r-- | application/front/controller/admin/ServerController.php | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/application/front/controller/admin/ServerController.php b/application/front/controller/admin/ServerController.php new file mode 100644 index 00000000..4b74f4a9 --- /dev/null +++ b/application/front/controller/admin/ServerController.php | |||
@@ -0,0 +1,101 @@ | |||
1 | <?php | ||
2 | |||
3 | declare(strict_types=1); | ||
4 | |||
5 | namespace Shaarli\Front\Controller\Admin; | ||
6 | |||
7 | use Shaarli\Helper\ApplicationUtils; | ||
8 | use Shaarli\Helper\FileUtils; | ||
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 | { | ||
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 | |||
38 | $currentVersion = ApplicationUtils::getVersion('./shaarli_version.php'); | ||
39 | $currentVersion = $currentVersion === 'dev' ? $currentVersion : 'v' . $currentVersion; | ||
40 | $phpEol = new \DateTimeImmutable(ApplicationUtils::getPhpEol(PHP_VERSION)); | ||
41 | |||
42 | $permissions = array_merge( | ||
43 | ApplicationUtils::checkResourcePermissions($this->container->conf), | ||
44 | ApplicationUtils::checkDatastoreMutex() | ||
45 | ); | ||
46 | |||
47 | $this->assignView('php_version', PHP_VERSION); | ||
48 | $this->assignView('php_eol', format_date($phpEol, false)); | ||
49 | $this->assignView('php_has_reached_eol', $phpEol < new \DateTimeImmutable()); | ||
50 | $this->assignView('php_extensions', ApplicationUtils::getPhpExtensionsRequirement()); | ||
51 | $this->assignView('permissions', $permissions); | ||
52 | $this->assignView('release_url', $releaseUrl); | ||
53 | $this->assignView('latest_version', $latestVersion); | ||
54 | $this->assignView('current_version', $currentVersion); | ||
55 | $this->assignView('thumbnails_mode', $this->container->conf->get('thumbnails.mode')); | ||
56 | $this->assignView('index_url', index_url($this->container->environment)); | ||
57 | $this->assignView('client_ip', client_ip_id($this->container->environment)); | ||
58 | $this->assignView('trusted_proxies', $this->container->conf->get('security.trusted_proxies', [])); | ||
59 | |||
60 | $this->assignView( | ||
61 | 'pagetitle', | ||
62 | t('Server administration') . ' - ' . $this->container->conf->get('general.title', 'Shaarli') | ||
63 | ); | ||
64 | |||
65 | return $response->write($this->render('server')); | ||
66 | } | ||
67 | |||
68 | /** | ||
69 | * GET /admin/clear-cache?type={$type} - Action to trigger cache folder clearing (either main or thumbnails). | ||
70 | */ | ||
71 | public function clearCache(Request $request, Response $response): Response | ||
72 | { | ||
73 | $exclude = ['.htaccess']; | ||
74 | |||
75 | if ($request->getQueryParam('type') === static::CACHE_THUMB) { | ||
76 | $folders = [$this->container->conf->get('resource.thumbnails_cache')]; | ||
77 | |||
78 | $this->saveWarningMessage( | ||
79 | t('Thumbnails cache has been cleared.') . ' ' . | ||
80 | '<a href="' . $this->container->basePath . '/admin/thumbnails">' . | ||
81 | t('Please synchronize them.') . | ||
82 | '</a>' | ||
83 | ); | ||
84 | } else { | ||
85 | $folders = [ | ||
86 | $this->container->conf->get('resource.page_cache'), | ||
87 | $this->container->conf->get('resource.raintpl_tmp'), | ||
88 | ]; | ||
89 | |||
90 | $this->saveSuccessMessage(t('Shaarli\'s cache folder has been cleared!')); | ||
91 | } | ||
92 | |||
93 | // Make sure that we don't delete root cache folder | ||
94 | $folders = array_map('realpath', array_values(array_filter(array_map('trim', $folders)))); | ||
95 | foreach ($folders as $folder) { | ||
96 | FileUtils::clearFolder($folder, false, $exclude); | ||
97 | } | ||
98 | |||
99 | return $this->redirect($response, '/admin/server'); | ||
100 | } | ||
101 | } | ||