diff --git a/php/public/index.php b/php/public/index.php index 29c467d4..a1a8c189 100644 --- a/php/public/index.php +++ b/php/public/index.php @@ -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); diff --git a/php/src/Controller/LoginController.php b/php/src/Controller/LoginController.php index c917115c..aaab2952 100644 --- a/php/src/Controller/LoginController.php +++ b/php/src/Controller/LoginController.php @@ -12,12 +12,17 @@ use Psr\Http\Message\ServerRequestInterface as Request; class LoginController { private AuthManager $authManager; + private DockerActionManager $dockerActionManager; - public function __construct(AuthManager $authManager) { + public function __construct(AuthManager $authManager, DockerActionManager $dockerActionManager) { $this->authManager = $authManager; + $this->dockerActionManager = $dockerActionManager; } public function TryLogin(Request $request, Response $response, $args) : Response { + if (!$this->dockerActionManager->isLoginAllowed()) { + return $response->withHeader('Location', '/')->withStatus(302); + } $password = $request->getParsedBody()['password']; if($this->authManager->CheckCredentials($password)) { $this->authManager->SetAuthState(true); diff --git a/php/src/Docker/DockerActionManager.php b/php/src/Docker/DockerActionManager.php index bc1b01f9..2b180310 100644 --- a/php/src/Docker/DockerActionManager.php +++ b/php/src/Docker/DockerActionManager.php @@ -517,4 +517,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; + } } diff --git a/php/templates/login.twig b/php/templates/login.twig index 06b875ea..f9f7564a 100644 --- a/php/templates/login.twig +++ b/php/templates/login.twig @@ -5,13 +5,18 @@

Nextcloud AIO Login

-

Log in using your Nextcloud AIO password. If you don't have it, you can also use the automatic login from your Nextcloud.

-
- - - - -
+ {% if is_login_allowed == true %} +

Log in using your Nextcloud AIO password.

+
+ + + + +
+ {% else %} +

The login is blocked since Nextcloud is running. Please use the automatic login from your Nextcloud.

+ You can unblock the login by running 'sudo docker stop nextcloud-aio-apache'.

+ {% endif %}
{% endblock %}