mirror of
https://github.com/netinvent/npbackup.git
synced 2025-10-23 11:57:57 +08:00
GUI: Allow manager password disabling
This commit is contained in:
parent
cc3b67ea7d
commit
870e188e6d
2 changed files with 29 additions and 6 deletions
|
@ -545,7 +545,14 @@ def inject_permissions_into_full_config(full_config: dict) -> Tuple[bool, dict]:
|
||||||
f"{object_type}.{object_name}.new_permissions"
|
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(
|
full_config.s(
|
||||||
f"{object_type}.{object_name}.repo_uri",
|
f"{object_type}.{object_name}.repo_uri",
|
||||||
(repo_uri, new_permissions, new_manager_password),
|
(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)
|
full_config.s(f"{object_type}.{object_name}.is_protected", True)
|
||||||
logger.debug(f"Permissions exist for {object_type} {object_name}")
|
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
|
# Don't keep decrypted manager password and permissions bare in config file
|
||||||
# They should be injected in repo_uri tuple
|
# They should be injected in repo_uri tuple
|
||||||
|
|
|
@ -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.Text(_t("config_gui.set_manager_password"), size=(40, 1)),
|
||||||
sg.Input(
|
sg.Input(
|
||||||
manager_password,
|
None,
|
||||||
key="-MANAGER-PASSWORD-",
|
key="-MANAGER-PASSWORD-",
|
||||||
size=(50, 1),
|
size=(50, 1),
|
||||||
password_char="*",
|
password_char="*",
|
||||||
|
@ -872,12 +872,28 @@ def config_gui(full_config: dict, config_file: str):
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
sg.Push(),
|
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.cancel"), key="--CANCEL--"),
|
||||||
sg.Button(_t("generic.accept"), key="--ACCEPT--"),
|
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 = 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:
|
while True:
|
||||||
event, values = window.read()
|
event, values = window.read()
|
||||||
if event in (sg.WIN_CLOSED, sg.WIN_X_EVENT, "--CANCEL--"):
|
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",
|
f"{object_type}.{object_name}.new_manager_password",
|
||||||
values["-MANAGER-PASSWORD-"],
|
values["-MANAGER-PASSWORD-"],
|
||||||
)
|
)
|
||||||
|
break
|
||||||
|
if event == "--SUPPRESS-PASSWORD--":
|
||||||
|
full_config.s(f"{object_type}.{object_name}.new_permissions", "full")
|
||||||
full_config.s(
|
full_config.s(
|
||||||
f"{object_type}.{object_name}.current_manager_password",
|
f"{object_type}.{object_name}.new_manager_password", False
|
||||||
full_config.g(f"{object_type}.{object_name}.manager_password"),
|
|
||||||
)
|
)
|
||||||
break
|
break
|
||||||
window.close()
|
window.close()
|
||||||
|
|
Loading…
Add table
Reference in a new issue