disable login if Nextcloud is running

Signed-off-by: szaimen <szaimen@e.mail.de>
This commit is contained in:
szaimen 2021-12-30 14:57:49 +01:00
parent 892590275f
commit 0010a6cfa3
3 changed files with 27 additions and 9 deletions

View file

@ -89,9 +89,13 @@ $app->get('/containers', function ($request, $response, $args) use ($container)
'last_backup_time' => $configurationManager->GetLastBackupTime(),
]);
})->setName('profile');
$app->get('/login', function ($request, $response, $args) {
$app->get('/login', function ($request, $response, $args) use ($container) {
$view = Twig::fromRequest($request);
return $view->render($response, 'login.twig');
/** @var \AIO\Docker\DockerActionManager $dockerActionManger */
$dockerActionManger = $container->get(\AIO\Docker\DockerActionManager::class);
return $view->render($response, 'login.twig', [
'is_login_allowed' => $dockerActionManger->isLoginAllowed(),
]);
});
$app->get('/setup', function ($request, $response, $args) use ($container) {
$view = Twig::fromRequest($request);

View file

@ -507,4 +507,13 @@ class DockerActionManager
return -1;
}
}
public function isLoginAllowed() : bool {
$id = 'nextcloud-aio-apache';
$apacheContainer = $this->containerDefinitionFetcher->GetContainerById($id);
if ($this->GetContainerStartingState($apacheContainer) instanceof RunningState) {
return false;
}
return true;
}
}

View file

@ -5,13 +5,18 @@
<div class="login">
<img src="/img/logo-blue.svg" style="margin-left: auto;margin-right: auto;display: block;">
<h1>Nextcloud AIO Login</h1>
<p>Log in using your Nextcloud AIO password. If you don't have it, you can also use the automatic login from your Nextcloud.</p>
{% if is_login_allowed == true %}
<p>Log in using your Nextcloud AIO password.</p>
<form method="POST" action="/api/auth/login">
<input type="text" name="password" placeholder="Password" />
<input type="hidden" name="{{csrf.keys.name}}" value="{{csrf.name}}">
<input type="hidden" name="{{csrf.keys.value}}" value="{{csrf.value}}">
<input type="submit" class="button" value="Login" />
</form>
{% else %}
<p>The login is blocked since Nextcloud is running. Please use the automatic login from your Nextcloud.<br><br>
You can unblock the login by running 'sudo docker stop nextcloud-aio-apache'.</p>
{% endif %}
</div>
</div>
{% endblock %}