From 870e188e6da84a8faa3c99694017ae7c506a82ce Mon Sep 17 00:00:00 2001 From: deajan Date: Fri, 14 Feb 2025 13:30:03 +0100 Subject: [PATCH] GUI: Allow manager password disabling --- npbackup/configuration.py | 11 ++++++++--- npbackup/gui/config.py | 24 +++++++++++++++++++++--- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/npbackup/configuration.py b/npbackup/configuration.py index 583fea6..8f08229 100644 --- a/npbackup/configuration.py +++ b/npbackup/configuration.py @@ -545,7 +545,14 @@ def inject_permissions_into_full_config(full_config: dict) -> Tuple[bool, dict]: f"{object_type}.{object_name}.new_permissions" ) - if new_manager_password and current_manager_password == manager_password: + # Always first consider there is no protection + full_config.s(f"{object_type}.{object_name}.is_protected", False) + + # We may set new_password_manager to false to explicitly disabling password manager + if ( + new_manager_password is not None + and current_manager_password == manager_password + ): full_config.s( f"{object_type}.{object_name}.repo_uri", (repo_uri, new_permissions, new_manager_password), @@ -563,8 +570,6 @@ def inject_permissions_into_full_config(full_config: dict) -> Tuple[bool, dict]: ) full_config.s(f"{object_type}.{object_name}.is_protected", True) logger.debug(f"Permissions exist for {object_type} {object_name}") - else: - full_config.s(f"{object_type}.{object_name}.is_protected", False) # Don't keep decrypted manager password and permissions bare in config file # They should be injected in repo_uri tuple diff --git a/npbackup/gui/config.py b/npbackup/gui/config.py index 9310203..8517f08 100644 --- a/npbackup/gui/config.py +++ b/npbackup/gui/config.py @@ -864,7 +864,7 @@ def config_gui(full_config: dict, config_file: str): [ sg.Text(_t("config_gui.set_manager_password"), size=(40, 1)), sg.Input( - manager_password, + None, key="-MANAGER-PASSWORD-", size=(50, 1), password_char="*", @@ -872,12 +872,28 @@ def config_gui(full_config: dict, config_file: str): ], [ sg.Push(), + sg.Button( + _t("config_gui.remove_password"), + key="--SUPPRESS-PASSWORD--", + button_color="red", + ), sg.Button(_t("generic.cancel"), key="--CANCEL--"), sg.Button(_t("generic.accept"), key="--ACCEPT--"), ], ] + # We need to set current_manager_password variable to make sure we have sufficient permissions to modifiy settings + full_config.s( + f"{object_type}.{object_name}.current_manager_password", + full_config.g(f"{object_type}.{object_name}.manager_password"), + ) + window = sg.Window(_t("config_gui.permissions"), layout, keep_on_top=True) + window.finalize() + # Stupid fix because using window update method will fill input with "0" if False is given + window["-MANAGER-PASSWORD-"].Update( + manager_password if manager_password else "" + ) while True: event, values = window.read() if event in (sg.WIN_CLOSED, sg.WIN_X_EVENT, "--CANCEL--"): @@ -912,9 +928,11 @@ def config_gui(full_config: dict, config_file: str): f"{object_type}.{object_name}.new_manager_password", values["-MANAGER-PASSWORD-"], ) + break + if event == "--SUPPRESS-PASSWORD--": + full_config.s(f"{object_type}.{object_name}.new_permissions", "full") full_config.s( - f"{object_type}.{object_name}.current_manager_password", - full_config.g(f"{object_type}.{object_name}.manager_password"), + f"{object_type}.{object_name}.new_manager_password", False ) break window.close()