Skip to content

Commit

Permalink
allow to change the password
Browse files Browse the repository at this point in the history
Signed-off-by: szaimen <szaimen@e.mail.de>
  • Loading branch information
szaimen committed Mar 8, 2022
1 parent b929d57 commit 5758d22
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 24 deletions.
6 changes: 6 additions & 0 deletions php/src/Controller/ConfigurationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ public function SetConfig(Request $request, Response $response, $args) : Respons
$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']);
}
Expand Down
28 changes: 28 additions & 0 deletions php/src/Data/ConfigurationManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,34 @@ public function SetBorgBackupHostLocation(string $location) : void {
$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.');
}

// Sll checks pass so set the password
$this->SetPassword($newPassword);
}

public function GetApachePort() : string {
$port = getenv('APACHE_PORT');
if ($port === false) {
Expand Down
58 changes: 34 additions & 24 deletions php/templates/containers.twig
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
<h1>Nextcloud AIO Beta v0.6.0</h1>
This is beta software and not production ready.<br><br>

You are currently running the {{ current_channel }} channel.<br><br>

{% set isAnyRunning = false %}
{% set isWatchtowerRunning = false %}
{% set isBackupContainerRunning = false %}
Expand Down Expand Up @@ -79,6 +77,7 @@

{% if isAnyRunning == true %}
{% if isApacheStarting != true %}
Your initial Nextcloud credentials:<br><br />
Initial Nextcloud username: admin<br />
Initial Nextcloud password: {{ nextcloud_password }}<br /><br/>
<a href="https://{{ domain }}" class="button" target="_blank" rel="noopener">Open your Nextcloud ↗</a><br/>
Expand Down Expand Up @@ -161,31 +160,42 @@
{% endif %}
{% endif %}

{% if is_mastercontainer_update_available == true %}
{% if was_start_button_clicked == true %}

{% if isBackupOrRestoreRunning == false %}
<h2>Mastercontainer update</h2>
{% if isAnyRunning == false %}
⚠ A mastercontainer update is available. Please click on the button below to update it.<br><br>
<form method="POST" action="/api/docker/watchtower" class="xhr">
<input type="hidden" name="{{csrf.keys.name}}" value="{{csrf.name}}">
<input type="hidden" name="{{csrf.keys.value}}" value="{{csrf.value}}">
<input class="button" type="submit" value="Update mastercontainer" />
</form>
{% else %}
⚠ A mastercontainer update is available. Please stop your containers in order to be able to update the mastercontainer.<br><br>
{% endif %}
{% if current_channel starts with 'latest' %}
You can find the changelog <a href="https://github.com/nextcloud/all-in-one/releases/latest">here</a><br><br>
{% elseif current_channel starts with 'beta' %}
You can find the changelog <a href="https://github.com/nextcloud/all-in-one/releases">here</a><br><br>
{% elseif current_channel starts with 'develop' %}
You can find all changes <a href="https://github.com/nextcloud-releases/all-in-one/commits/main">here</a><br><br>
<h2>Mastercontainer</h2>
You are currently running the {{ current_channel }} channel.<br><br>

{% if is_mastercontainer_update_available == true %}
{% if isAnyRunning == false %}
⚠ A mastercontainer update is available. Please click on the button below to update it.<br><br>
<form method="POST" action="/api/docker/watchtower" class="xhr">
<input type="hidden" name="{{csrf.keys.name}}" value="{{csrf.name}}">
<input type="hidden" name="{{csrf.keys.value}}" value="{{csrf.value}}">
<input class="button" type="submit" value="Update mastercontainer" />
</form>
{% else %}
⚠ A mastercontainer update is available. Please stop your containers in order to be able to update the mastercontainer.<br><br>
{% endif %}
{% if current_channel starts with 'latest' %}
You can find the changelog <a href="https://github.com/nextcloud/all-in-one/releases/latest">here</a><br><br>
{% elseif current_channel starts with 'beta' %}
You can find the changelog <a href="https://github.com/nextcloud/all-in-one/releases">here</a><br><br>
{% elseif current_channel starts with 'develop' %}
You can find all changes <a href="https://github.com/nextcloud-releases/all-in-one/commits/main">here</a><br><br>
{% endif %}
{% endif %}
{% endif %}
{% endif %}

{% if was_start_button_clicked == true %}

You can change your AIO password below:<br><br />
<form method="POST" action="/api/configuration" class="xhr">
<input type="text" autocomplete="current-password" name="current-master-password" placeholder="your current aio password"/>
<input type="text" autocomplete="new-password" name="new-master-password" placeholder="your new aio password"/>
<input type="hidden" name="{{csrf.keys.name}}" value="{{csrf.name}}">
<input type="hidden" name="{{csrf.keys.value}}" value="{{csrf.value}}">
<input class="button" type="submit" value="Submit" />
</form>
The new password needs to be at least 24 characters long. Allowed characters are the <a href="https://en.wikipedia.org/wiki/Latin_alphabet#/media/File:Abecedarium.png">latin characters</a> 'a-z', 'A-Z', '0-9' and spaces.<br><br>
{% endif %}

{% if isBackupOrRestoreRunning == false and borg_backup_host_location == "" and isApacheStarting != true %}
<h2>Backup and restore</h2>
Expand Down

0 comments on commit 5758d22

Please sign in to comment.