From c8854ab1e3ba1c895fc6952d3217b17c1e64e2ad Mon Sep 17 00:00:00 2001 From: szaimen Date: Tue, 8 Mar 2022 21:16:33 +0100 Subject: [PATCH] allow to change the password Signed-off-by: szaimen --- .../Controller/ConfigurationController.php | 6 ++ php/src/Data/ConfigurationManager.php | 28 +++++++++ php/templates/containers.twig | 60 +++++++++++-------- 3 files changed, 69 insertions(+), 25 deletions(-) diff --git a/php/src/Controller/ConfigurationController.php b/php/src/Controller/ConfigurationController.php index 61f22f27..e43a380f 100644 --- a/php/src/Controller/ConfigurationController.php +++ b/php/src/Controller/ConfigurationController.php @@ -25,6 +25,12 @@ class ConfigurationController $this->configurationManager->SetDomain($request->getParsedBody()['domain']); } + if (isset($request->getParsedBody()['current-master-password']) || isset($request->getParsedBody()['new-master-password'])) { + $currentMasterPassword = $request->getParsedBody()['current-master-password'] ?? ''; + $newMasterPassword = $request->getParsedBody()['new-master-password'] ?? ''; + $this->configurationManager->ChangeMasterPassword($currentMasterPassword, $newMasterPassword); + } + if (isset($request->getParsedBody()['borg_backup_host_location'])) { $this->configurationManager->SetBorgBackupHostLocation($request->getParsedBody()['borg_backup_host_location']); } diff --git a/php/src/Data/ConfigurationManager.php b/php/src/Data/ConfigurationManager.php index f98cab2b..d4eab72f 100644 --- a/php/src/Data/ConfigurationManager.php +++ b/php/src/Data/ConfigurationManager.php @@ -236,6 +236,34 @@ class ConfigurationManager $this->WriteConfig($config); } + /** + * @throws InvalidSettingConfigurationException + */ + public function ChangeMasterPassword(string $currentPassword, string $newPassword) : void { + if ($currentPassword === '') { + throw new InvalidSettingConfigurationException("Please enter your current password."); + } + + if ($currentPassword !== $this->GetPassword()) { + throw new InvalidSettingConfigurationException("The entered current password is not correct."); + } + + if ($newPassword === '') { + throw new InvalidSettingConfigurationException("Please enter a new password."); + } + + if (strlen($newPassword) < 24) { + throw new InvalidSettingConfigurationException("New passwords must be >= 24 digits."); + } + + if (!preg_match("#^[a-zA-Z0-9 ]+$#", $newPassword)) { + throw new InvalidSettingConfigurationException('Not allowed characters in the new password.'); + } + + // All checks pass so set the password + $this->SetPassword($newPassword); + } + public function GetApachePort() : string { $port = getenv('APACHE_PORT'); if ($port === false) { diff --git a/php/templates/containers.twig b/php/templates/containers.twig index 3875d266..bbaf8fb3 100644 --- a/php/templates/containers.twig +++ b/php/templates/containers.twig @@ -19,8 +19,6 @@

Nextcloud AIO Beta v0.6.0

This is beta software and not production ready.

- You are currently running the {{ current_channel }} channel.

- {% set isAnyRunning = false %} {% set isWatchtowerRunning = false %} {% set isBackupContainerRunning = false %} @@ -79,6 +77,7 @@ {% if isAnyRunning == true %} {% if isApacheStarting != true %} + Your initial Nextcloud credentials:

Initial Nextcloud username: admin
Initial Nextcloud password: {{ nextcloud_password }}

Open your Nextcloud ↗
@@ -161,31 +160,42 @@ {% endif %} {% endif %} - {% if is_mastercontainer_update_available == true %} - {% if isBackupOrRestoreRunning == false %} -

Mastercontainer update

- {% if isAnyRunning == false %} - ⚠ A mastercontainer update is available. Please click on the button below to update it.

-
- - - -
- {% else %} - ⚠ A mastercontainer update is available. Please stop your containers in order to be able to update the mastercontainer.

- {% endif %} - {% if current_channel starts with 'latest' %} - You can find the changelog here

- {% elseif current_channel starts with 'beta' %} - You can find the changelog here

- {% elseif current_channel starts with 'develop' %} - You can find all changes here

- {% endif %} - {% endif %} - {% endif %} - {% if was_start_button_clicked == true %} + {% if isBackupOrRestoreRunning == false %} +

Mastercontainer

+ You are currently running the {{ current_channel }} channel.

+ + {% if is_mastercontainer_update_available == true %} + {% if isAnyRunning == false %} + ⚠ A mastercontainer update is available. Please click on the button below to update it.

+
+ + + +
+ {% else %} + ⚠ A mastercontainer update is available. Please stop your containers in order to be able to update the mastercontainer.

+ {% endif %} + {% if current_channel starts with 'latest' %} + You can find the changelog here

+ {% elseif current_channel starts with 'beta' %} + You can find the changelog here

+ {% elseif current_channel starts with 'develop' %} + You can find all changes here

+ {% endif %} + {% endif %} + + You can change your AIO password below:

+
+ + + + + +
+ The new password needs to be at least 24 characters long. Allowed characters are the latin characters 'a-z', 'A-Z', '0-9' and spaces.

+ {% endif %} {% if isBackupOrRestoreRunning == false and borg_backup_host_location == "" and isApacheStarting != true %}

Backup and restore