Rewrite all AIO interface paths to be relative

Signed-off-by: Lorenzo Moscati <lorenzo@moscati.page>
This commit is contained in:
Lorenzo Moscati 2025-08-23 01:30:20 +02:00
parent 4581cf7649
commit 21fbb58c96
No known key found for this signature in database
14 changed files with 96 additions and 79 deletions

View file

@ -161,7 +161,7 @@ readonly class ConfigurationController {
$this->configurationManager->DeleteBorgBackupLocationVars();
}
return $response->withStatus(201)->withHeader('Location', '/');
return $response->withStatus(201)->withHeader('Location', '.');
} catch (InvalidSettingConfigurationException $ex) {
$response->getBody()->write($ex->getMessage());
return $response->withStatus(422);

View file

@ -85,7 +85,7 @@ readonly class DockerController {
public function StartBackupContainerBackup(Request $request, Response $response, array $args) : Response {
$forceStopNextcloud = true;
$this->startBackup($forceStopNextcloud);
return $response->withStatus(201)->withHeader('Location', '/');
return $response->withStatus(201)->withHeader('Location', '.');
}
public function startBackup(bool $forceStopNextcloud = false) : void {
@ -102,7 +102,7 @@ readonly class DockerController {
public function StartBackupContainerCheck(Request $request, Response $response, array $args) : Response {
$this->checkBackup();
return $response->withStatus(201)->withHeader('Location', '/');
return $response->withStatus(201)->withHeader('Location', '.');
}
public function checkBackup() : void {
@ -132,7 +132,7 @@ readonly class DockerController {
$id = 'nextcloud-aio-borgbackup';
$this->PerformRecursiveContainerStart($id);
return $response->withStatus(201)->withHeader('Location', '/');
return $response->withStatus(201)->withHeader('Location', '.');
}
public function StartBackupContainerCheckRepair(Request $request, Response $response, array $args) : Response {
@ -148,7 +148,7 @@ readonly class DockerController {
$config['backup-mode'] = 'check';
$this->configurationManager->WriteConfig($config);
return $response->withStatus(201)->withHeader('Location', '/');
return $response->withStatus(201)->withHeader('Location', '.');
}
public function StartBackupContainerTest(Request $request, Response $response, array $args) : Response {
@ -163,7 +163,7 @@ readonly class DockerController {
$id = 'nextcloud-aio-borgbackup';
$this->PerformRecursiveContainerStart($id);
return $response->withStatus(201)->withHeader('Location', '/');
return $response->withStatus(201)->withHeader('Location', '.');
}
public function StartContainer(Request $request, Response $response, array $args) : Response
@ -171,6 +171,7 @@ readonly class DockerController {
$uri = $request->getUri();
$host = $uri->getHost();
$port = $uri->getPort();
$path = $request->getParsedBody()['base_path'];
if ($port === 8000) {
error_log('The AIO_URL-port was discovered to be 8000 which is not expected. It is now set to 443.');
$port = 443;
@ -184,7 +185,7 @@ readonly class DockerController {
$config = $this->configurationManager->GetConfig();
// set AIO_URL
$config['AIO_URL'] = $host . ':' . $port;
$config['AIO_URL'] = $host . ':' . $port . $path;
// set wasStartButtonClicked
$config['wasStartButtonClicked'] = 1;
// set install_latest_major
@ -204,7 +205,7 @@ readonly class DockerController {
// Temporarily disabled as it leads much faster to docker rate limits
// apcu_clear_cache();
return $response->withStatus(201)->withHeader('Location', '/');
return $response->withStatus(201)->withHeader('Location', '.');
}
public function startTopContainer(bool $pullImage) : void {
@ -223,7 +224,7 @@ readonly class DockerController {
public function StartWatchtowerContainer(Request $request, Response $response, array $args) : Response {
$this->startWatchtower();
return $response->withStatus(201)->withHeader('Location', '/');
return $response->withStatus(201)->withHeader('Location', '.');
}
public function startWatchtower() : void {
@ -261,7 +262,7 @@ readonly class DockerController {
$forceStopNextcloud = true;
$this->PerformRecursiveContainerStop($id, $forceStopNextcloud);
return $response->withStatus(201)->withHeader('Location', '/');
return $response->withStatus(201)->withHeader('Location', '.');
}
public function stopTopContainer() : void {

View file

@ -19,33 +19,33 @@ readonly class LoginController {
public function TryLogin(Request $request, Response $response, array $args) : Response {
if (!$this->dockerActionManager->isLoginAllowed()) {
$response->getBody()->write("The login is blocked since Nextcloud is running.");
return $response->withHeader('Location', '/')->withStatus(422);
return $response->withHeader('Location', '.')->withStatus(422);
}
$password = $request->getParsedBody()['password'] ?? '';
if($this->authManager->CheckCredentials($password)) {
$this->authManager->SetAuthState(true);
return $response->withHeader('Location', '/')->withStatus(201);
return $response->withHeader('Location', '.')->withStatus(201);
}
$response->getBody()->write("The password is incorrect.");
return $response->withHeader('Location', '/')->withStatus(422);
return $response->withHeader('Location', '.')->withStatus(422);
}
public function GetTryLogin(Request $request, Response $response, array $args) : Response {
$token = $request->getQueryParams()['token'] ?? '';
if($this->authManager->CheckToken($token)) {
$this->authManager->SetAuthState(true);
return $response->withHeader('Location', '/')->withStatus(302);
return $response->withHeader('Location', '../..')->withStatus(302);
}
return $response->withHeader('Location', '/')->withStatus(302);
return $response->withHeader('Location', '../..')->withStatus(302);
}
public function Logout(Request $request, Response $response, array $args) : Response
{
$this->authManager->SetAuthState(false);
return $response
->withHeader('Location', '/')
->withHeader('Location', '.')
->withStatus(302);
}
}

View file

@ -27,7 +27,15 @@ readonly class AuthMiddleware {
if(!in_array($request->getUri()->getPath(), $publicRoutes)) {
if(!$this->authManager->IsAuthenticated()) {
$status = 302;
$headers = ['Location' => '/'];
if(count(explode('/', $request->getUri()->getPath())) > 2) {
$location = '..';
for($i = 0; $i < count(explode('/', $request->getUri()->getPath())) - 3; $i++) {
$location = $location . '/..';
}
} else {
$location = '.';
}
$headers = ['Location' => $location];
$response = new Response($status, $headers);
return $response;
}