Skip to content

Commit 88fe7dc

Browse files
committed
refactor: migrated admin session keepalive to controller (#3257)
1 parent 0175d46 commit 88fe7dc

File tree

8 files changed

+70
-109
lines changed

8 files changed

+70
-109
lines changed

nginx.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ server {
129129
rewrite admin/api/(.*) /admin/api/index.php last;
130130

131131
# Administration pages
132-
rewrite admin/(attachments|backup|backup/export|backup/restore|configuration|elasticsearch|instance/edit|instance/update|instances|stopwords|system|update) /admin/front.php last;
132+
rewrite admin/(attachments|backup|backup/export|backup/restore|configuration|elasticsearch|instance/edit|instance/update|instances|session-keep-alive|stopwords|system|update) /admin/front.php last;
133133

134134
# REST API v3.0 and v3.1
135135
rewrite ^api/v3\.[01]/(.*) /api/index.php last;

phpmyfaq/.htaccess

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ Header set Access-Control-Allow-Headers "Content-Type, Authorization"
143143
# Administration API
144144
RewriteRule ^admin/api/(.*) admin/api/index.php [L,QSA]
145145
# Administration pages
146-
RewriteRule ^admin/(attachments|backup|backup/export|backup/restore|configuration|elasticsearch|instance/edit|instance/update|instances|stopwords|system|update) admin/front.php [L,QSA]
146+
RewriteRule ^admin/(attachments|backup|backup/export|backup/restore|configuration|elasticsearch|instance/edit|instance/update|instances|session-keep-alive|stopwords|system|update) admin/front.php [L,QSA]
147147
# Private APIs
148148
RewriteRule ^api/(autocomplete|bookmark/delete|bookmark/create|user/data/update|user/password/update|user/request-removal|user/remove-twofactor|contact|voting|register|captcha|share|comment/create|faq/create|question/create|webauthn/prepare|webauthn/register|webauthn/prepare-login|webauthn/login) api/index.php [L,QSA]
149149
# Setup APIs

phpmyfaq/admin/session.keepalive.php

Lines changed: 0 additions & 104 deletions
This file was deleted.

phpmyfaq/assets/templates/admin/footer.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@
8686
</div>
8787

8888
{% if isUserLoggedIn %}
89-
<iframe id="keepPMFSessionAlive" src="./session.keepalive.php?lang={{ currentLanguage }}" width="0" height="0"
89+
<iframe id="keepPMFSessionAlive" src="./session-keep-alive?lang={{ currentLanguage }}" width="0" height="0"
9090
style="display: none;" name="keep-phpmyfaq-session-alive"></iframe>
9191
{% endif %}
9292

phpmyfaq/assets/templates/admin/index.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@
312312
</div>
313313

314314
{% if isUserLoggedIn %}
315-
<iframe id="keepPMFSessionAlive" src="./session.keepalive.php?lang={{ currentLanguage }}" width="0" height="0"
315+
<iframe id="keepPMFSessionAlive" src="./session-keep-alive?lang={{ currentLanguage }}" width="0" height="0"
316316
style="display: none;" name="keep-phpmyfaq-session-alive"></iframe>
317317
{% endif %}
318318

phpmyfaq/assets/templates/admin/session-keepalive.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!DOCTYPE html>
2-
<html lang="{{ metaLanguage }}" class="no-js">
2+
<html lang="{{ metaLanguage }}">
33
<head>
44
<meta charset="utf-8">
55

phpmyfaq/src/admin-routes.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use phpMyFAQ\Controller\Administration\ConfigurationController;
2121
use phpMyFAQ\Controller\Administration\ElasticsearchController;
2222
use phpMyFAQ\Controller\Administration\InstanceController;
23+
use phpMyFAQ\Controller\Administration\SessionKeepAliveController;
2324
use phpMyFAQ\Controller\Administration\StopWordsController;
2425
use phpMyFAQ\Controller\Administration\SystemInformationController;
2526
use phpMyFAQ\Controller\Administration\UpdateController;
@@ -74,6 +75,11 @@
7475
'controller' => [InstanceController::class, 'index'],
7576
'methods' => 'GET'
7677
],
78+
'admin.session.keepalive' => [
79+
'path' => '/session-keep-alive',
80+
'controller' => [SessionKeepAliveController::class, 'index'],
81+
'methods' => 'GET'
82+
],
7783
'admin.stopwords' => [
7884
'path' => '/stopwords',
7985
'controller' => [StopwordsController::class, 'index'],
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
3+
/**
4+
* The Session Keepalive Controller
5+
*
6+
* This Source Code Form is subject to the terms of the Mozilla Public License,
7+
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
8+
* obtain one at https://mozilla.org/MPL/2.0/.
9+
*
10+
* @package phpMyFAQ
11+
* @author Thorsten Rinne <[email protected]>
12+
* @copyright 2024 phpMyFAQ Team
13+
* @license https://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0
14+
* @link https://www.phpmyfaq.de
15+
* @since 2024-11-23
16+
*/
17+
18+
declare(strict_types=1);
19+
20+
namespace phpMyFAQ\Controller\Administration;
21+
22+
use phpMyFAQ\Core\Exception;
23+
use phpMyFAQ\Filter;
24+
use phpMyFAQ\Session\Token;
25+
use phpMyFAQ\System;
26+
use phpMyFAQ\Translation;
27+
use Symfony\Component\HttpFoundation\Request;
28+
use Symfony\Component\HttpFoundation\Response;
29+
use Symfony\Component\Routing\Attribute\Route;
30+
use Twig\Error\LoaderError;
31+
32+
class SessionKeepAliveController extends AbstractAdministrationController
33+
{
34+
/**
35+
* @throws Exception
36+
* @throws LoaderError
37+
* @throws \Exception
38+
*/
39+
#[Route('/session-keep-alive', name: 'admin.session.keepalive', methods: ['GET'])]
40+
public function index(Request $request): Response
41+
{
42+
$language = Filter::filterVar($request->query->get('lang', 'en'), FILTER_SANITIZE_SPECIAL_CHARS);
43+
$refreshTime = (PMF_AUTH_TIMEOUT - PMF_AUTH_TIMEOUT_WARNING) * 60;
44+
45+
return $this->render(
46+
'@admin/session-keepalive.twig',
47+
[
48+
'metaLanguage' => $language,
49+
'phpMyFAQVersion' => System::getVersion(),
50+
'currentYear' => date('Y'),
51+
'isUserLoggedIn' => $this->currentUser->isLoggedIn(),
52+
'csrfToken' => Token::getInstance($this->container->get('session'))->getTokenString('admin-logout'),
53+
'msgConfirm' => sprintf(Translation::get('ad_session_expiring'), PMF_AUTH_TIMEOUT_WARNING),
54+
'sessionTimeout' => PMF_AUTH_TIMEOUT,
55+
'refreshTime' => $refreshTime,
56+
]
57+
);
58+
}
59+
}

0 commit comments

Comments
 (0)