From c569b80b4a96adb099d033c81753f9270b1d31a1 Mon Sep 17 00:00:00 2001 From: OniriCorpe Date: Wed, 3 Jan 2024 22:41:43 +0100 Subject: [PATCH] add a new password tool in the config panel --- config_panel.toml | 5 +++++ doc/PRE_UPGRADE.d/0.107.43~ynh4 | 2 ++ scripts/config | 10 ++++++++++ scripts/install | 2 ++ scripts/upgrade | 4 ++++ 5 files changed, 23 insertions(+) diff --git a/config_panel.toml b/config_panel.toml index d9f67bc..6b7d9af 100644 --- a/config_panel.toml +++ b/config_panel.toml @@ -19,3 +19,8 @@ type = "boolean" yes = "true" bind = "tls>enabled:__INSTALL_DIR__/AdGuardHome.yaml" help = "If so, anyone who knows your adguard address can make a doh request to https://adguardomain.tld/dns-query It also may be used to perform amplification attacks. Read the admin doc to secure your server using allowlist." + +[main.extra.new_password] +ask = "Set a new admin password" +type = "string" +help = "With this tool, you can easily change the password of your AdGuard Home. Just put the desired password in the text input." diff --git a/doc/PRE_UPGRADE.d/0.107.43~ynh4 b/doc/PRE_UPGRADE.d/0.107.43~ynh4 index 727cee3..ecddd6d 100644 --- a/doc/PRE_UPGRADE.d/0.107.43~ynh4 +++ b/doc/PRE_UPGRADE.d/0.107.43~ynh4 @@ -10,6 +10,8 @@ Applications → AdGuard Home → AdGuard Home configuration It's really important to use the configuration panel to activate or deactivate the DNS-over-HTTPS/QUIC setting, and **NOT** the built-in setting in the AdGuardHome interface. This is because YunoHost needs to perform actions such as automatically opening or closing the server's ports and refresh the IP to provide to AdGuard Home, which cannot be done without going through the configuration panel. +A new password tool has been added in the config panel too, to make it easier to change the administration password of AdGuard Home + This update is at risk of crashing AdGuard Home, so: - If any trouble or question, please refer to [the package's admin docs](https://github.com/YunoHost-Apps/adguardhome_ynh/blob/master/doc/ADMIN.md)! In any case, we recommend reading it! ^w^ - If needed and a similar issue does not already exist, please [open an issue on the GitHub's package page](https://github.com/YunoHost-Apps/adguardhome_ynh/issues)! diff --git a/scripts/config b/scripts/config index f84f174..e75daaf 100644 --- a/scripts/config +++ b/scripts/config @@ -88,6 +88,16 @@ set__dns_over_https() { ynh_app_setting_set --app="$app" --key=dns_over_https --value="$dns_over_https" } +set__new_password() { + + # user's password encryption + password=$(python3 -c "import bcrypt; print(bcrypt.hashpw(b\"$new_password\", bcrypt.gensalt(rounds=10)).decode())") + ynh_app_setting_set --app="$app" --key=password --value="$password" + + # save the new setting in the AGH config file + ynh_write_var_in_file --file="$install_dir/AdGuardHome.yaml" --key="password" --value="$password" +} + #================================================= # GENERIC FINALIZATION #================================================= diff --git a/scripts/install b/scripts/install index a6fc925..5d73a8c 100644 --- a/scripts/install +++ b/scripts/install @@ -44,6 +44,8 @@ fi ynh_app_setting_set --app="$app" --key=expose_port_53 --value="$expose_port_53" +ynh_app_setting_set --app="$app" --key=new_password --value="" + #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index 0a3d6ed..be9d0a6 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -86,6 +86,10 @@ fi # remove setting no longer required ynh_app_setting_delete --app="$app" --key=port_adguard +if [ -z "${new_password:-}" ]; then + ynh_app_setting_set --app="$app" --key=new_password --value="" +fi + #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #=================================================