Added suggested changes

Signed-off-by: Lorenzo Moscati <lorenzo@moscati.page>
This commit is contained in:
Lorenzo Moscati 2025-10-14 15:59:28 +02:00
parent 3bb9cdf31d
commit 10529a597c
No known key found for this signature in database
3 changed files with 20 additions and 7 deletions

View file

@ -1,3 +1,7 @@
document.addEventListener("DOMContentLoaded", function(event) {
document.getElementById("base_path") && (document.getElementById("base_path").value = window.location.pathname.slice(0, -11));
document.addEventListener("DOMContentLoaded", function() {
basePath = document.getElementById("base_path")
if (basePath) {
// Remove '/containers' from the end of the path, to get the base path only
basePath.value = window.location.pathname.slice(0, -11);
}
});

View file

@ -45,7 +45,7 @@ readonly class LoginController {
{
$this->authManager->SetAuthState(false);
return $response
->withHeader('Location', '.')
->withHeader('Location', '../..')
->withStatus(302);
}
}

View file

@ -27,14 +27,23 @@ readonly class AuthMiddleware {
if(!in_array($request->getUri()->getPath(), $publicRoutes)) {
if(!$this->authManager->IsAuthenticated()) {
$status = 302;
if(count(explode('/', $request->getUri()->getPath())) > 2) {
// Check the url of the request: split the string by '/' and count the number of elements
// Note that the path that gets to this middleware is not aware of any base path managed by a reverse proxy, so if the url is 'https://example.com/AIO/somepage', the path will be 'https://mastercontainer/somepage'
if (count(explode('/', $request->getUri()->getPath())) < 2) {
// If there are less than 2 elements it means we are somewhere in the root folder (no '/', so no subfolder), so we redirect to the same folder level to offload the redirection to the appropriate page to 'index.php' (specifically, once in the root level the login page will be loaded since we are not authenticated)
$location = '.';
} else {
// If there are 2 or more elements it means we are in a subfolder, so we need to go back to the root folder
// In the best case we need to go back by 1 level only
$location = '..';
for($i = 0; $i < count(explode('/', $request->getUri()->getPath())) - 3; $i++) {
// In the worst case we need to go back by n levels, where n is the number of elements - 2 (the first element is not a folder, the second element is already accounted for by the initial '..')
for ($i = 1; $i < count(explode('/', $request->getUri()->getPath())) - 2; $i++) {
// For each extra level we need to go back by another level
$location = $location . '/..';
}
} else {
$location = '.';
}
$headers = ['Location' => $location];
$response = new Response($status, $headers);
return $response;