From 81360723cc6284fa61e3668a844d412346322c23 Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Tue, 11 Apr 2023 15:17:41 +0200 Subject: [PATCH] dyndns: Misc semantic tweaks... --- locales/en.json | 4 ++-- share/actionsmap.yml | 13 +++++-------- src/domain.py | 26 +++++++++++++------------- src/dyndns.py | 26 +++++++++++++------------- src/tools.py | 7 ++++--- 5 files changed, 37 insertions(+), 39 deletions(-) diff --git a/locales/en.json b/locales/en.json index 21ffdfdc2..8c6636322 100644 --- a/locales/en.json +++ b/locales/en.json @@ -375,8 +375,8 @@ "domain_dns_registrar_supported": "YunoHost automatically detected that this domain is handled by the registrar **{registrar}**. If you want, YunoHost will automatically configure this DNS zone, if you provide it with the appropriate API credentials. You can find documentation on how to obtain your API credentials on this page: https://yunohost.org/registar_api_{registrar}. (You can also manually configure your DNS records following the documentation at https://yunohost.org/dns )", "domain_dns_registrar_yunohost": "This domain is a nohost.me / nohost.st / ynh.fr and its DNS configuration is therefore automatically handled by YunoHost without any further configuration. (see the 'yunohost domain dns push DOMAIN' command)", "domain_dyndns_already_subscribed": "You have already subscribed to a DynDNS domain", - "domain_dyndns_instruction_unclear": "You must choose exactly one of the following options : --subscribe or --no-subscribe", - "domain_dyndns_instruction_unclear_unsubscribe": "You must choose exactly one of the following options : --unsubscribe or --no-unsubscribe", + "domain_dyndns_instruction_unclear": "You must choose exactly one of the following options : --subscribe or --ignore-dyndns", + "domain_dyndns_instruction_unclear_unsubscribe": "You must choose exactly one of the following options : --unsubscribe or --ignore-dyndns", "domain_exists": "The domain already exists", "domain_hostname_failed": "Unable to set new hostname. This might cause an issue later (it might be fine).", "domain_registrar_is_not_configured": "The registrar is not yet configured for domain {domain}.", diff --git a/share/actionsmap.yml b/share/actionsmap.yml index 294d00881..3124f3105 100644 --- a/share/actionsmap.yml +++ b/share/actionsmap.yml @@ -506,8 +506,7 @@ domain: help: Domain name to add extra: pattern: *pattern_domain - -n: - full: --no-subscribe + --ignore-dyndns: help: If adding a DynDNS domain, only add the domain, without subscribing to the DynDNS service action: store_true --dyndns-recovery-password: @@ -536,8 +535,7 @@ domain: full: --force help: Do not ask confirmation to remove apps action: store_true - -n: - full: --no-unsubscribe + --ignore-dyndns: help: If removing a DynDNS domain, only remove the domain, without unsubscribing from the DynDNS service action: store_true --dyndns-recovery-password: @@ -662,7 +660,7 @@ domain: extra: pattern: *pattern_domain -p: - full: --password + full: --recovery-password nargs: "?" const: 0 help: Password used to later delete the domain @@ -681,7 +679,7 @@ domain: pattern: *pattern_domain required: True -p: - full: --password + full: --recovery-password nargs: "?" const: 0 help: Password used to delete the domain @@ -1688,8 +1686,7 @@ tools: pattern: *pattern_password required: True comment: good_practices_about_admin_password - -n: - full: --no-subscribe + --ingnore-dyndns: help: If adding a DynDNS domain, only add the domain, without subscribing to the DynDNS service action: store_true --dyndns-recovery-password: diff --git a/src/domain.py b/src/domain.py index 4301f9ab1..020a707c7 100644 --- a/src/domain.py +++ b/src/domain.py @@ -214,7 +214,7 @@ def _get_parent_domain_of(domain, return_self=False, topest=False): @is_unit_operation(exclude=["dyndns_recovery_password"]) -def domain_add(operation_logger, domain, dyndns_recovery_password=None, no_subscribe=False): +def domain_add(operation_logger, domain, dyndns_recovery_password=None, ignore_dyndns=False): """ Create a custom domain @@ -222,7 +222,7 @@ def domain_add(operation_logger, domain, dyndns_recovery_password=None, no_subsc domain -- Domain name to add dyndns -- Subscribe to DynDNS dyndns_recovery_password -- Password used to later unsubscribe from DynDNS - no_unsubscribe -- If we want to just add the DynDNS domain to the list, without subscribing + ignore_dyndns -- If we want to just add the DynDNS domain to the list, without subscribing """ from yunohost.hook import hook_callback from yunohost.app import app_ssowatconf @@ -256,7 +256,7 @@ def domain_add(operation_logger, domain, dyndns_recovery_password=None, no_subsc # Detect if this is a DynDNS domain ( and not a subdomain of a DynDNS domain ) dyndns = is_yunohost_dyndns_domain(domain) and len(domain.split(".")) == 3 if dyndns: - if not no_subscribe and not dyndns_recovery_password: + if not ignore_dyndns and not dyndns_recovery_password: if Moulinette.interface.type == "api": raise YunohostValidationError("domain_dyndns_missing_password") else: @@ -267,7 +267,7 @@ def domain_add(operation_logger, domain, dyndns_recovery_password=None, no_subsc # Ensure sufficiently complex password assert_password_is_strong_enough("admin", dyndns_recovery_password) - if ((dyndns_recovery_password is None) == (no_subscribe is False)): + if ((dyndns_recovery_password is None) == (ignore_dyndns is False)): raise YunohostValidationError("domain_dyndns_instruction_unclear") from yunohost.dyndns import is_subscribing_allowed @@ -277,10 +277,10 @@ def domain_add(operation_logger, domain, dyndns_recovery_password=None, no_subsc raise YunohostValidationError("domain_dyndns_already_subscribed") operation_logger.start() - if not dyndns and (dyndns_recovery_password is not None or no_subscribe): - logger.warning("This domain is not a DynDNS one, no need for the --dyndns-recovery-password or --no-subscribe option") + if not dyndns and (dyndns_recovery_password is not None or ignore_dyndns): + logger.warning("This domain is not a DynDNS one, no need for the --dyndns-recovery-password or --ignore-dyndns option") - if dyndns and not no_subscribe: + if dyndns and not ignore_dyndns: # Actually subscribe domain_dyndns_subscribe(domain=domain, password=dyndns_recovery_password) @@ -332,7 +332,7 @@ def domain_add(operation_logger, domain, dyndns_recovery_password=None, no_subsc @is_unit_operation(exclude=["dyndns_recovery_password"]) -def domain_remove(operation_logger, domain, remove_apps=False, force=False, dyndns_recovery_password=None, no_unsubscribe=False): +def domain_remove(operation_logger, domain, remove_apps=False, force=False, dyndns_recovery_password=None, ignore_dyndns=False): """ Delete domains @@ -342,7 +342,7 @@ def domain_remove(operation_logger, domain, remove_apps=False, force=False, dynd force -- Force the domain removal and don't not ask confirmation to remove apps if remove_apps is specified dyndns_recovery_password -- Recovery password used at the creation of the DynDNS domain - no_unsubscribe -- If we just remove the DynDNS domain, without unsubscribing + ignore_dyndns -- If we just remove the DynDNS domain, without unsubscribing """ from yunohost.hook import hook_callback from yunohost.app import app_ssowatconf, app_info, app_remove @@ -414,13 +414,13 @@ def domain_remove(operation_logger, domain, remove_apps=False, force=False, dynd # Detect if this is a DynDNS domain ( and not a subdomain of a DynDNS domain ) dyndns = is_yunohost_dyndns_domain(domain) and len(domain.split(".")) == 3 if dyndns: - if ((dyndns_recovery_password is None) == (no_unsubscribe is False)): + if ((dyndns_recovery_password is None) == (ignore_dyndns is False)): raise YunohostValidationError("domain_dyndns_instruction_unclear_unsubscribe") operation_logger.start() - if not dyndns and ((dyndns_recovery_password is not None) or (no_unsubscribe is not False)): - logger.warning("This domain is not a DynDNS one, no need for the --dyndns_recovery_password or --no-unsubscribe option") + if not dyndns and ((dyndns_recovery_password is not None) or (ignore_dyndns is not False)): + logger.warning("This domain is not a DynDNS one, no need for the --dyndns_recovery_password or --ignore-dyndns option") ldap = _get_ldap_interface() try: @@ -467,7 +467,7 @@ def domain_remove(operation_logger, domain, remove_apps=False, force=False, dynd hook_callback("post_domain_remove", args=[domain]) # If a password is provided, delete the DynDNS record - if dyndns and not no_unsubscribe: + if dyndns and not ignore_dyndns: # Actually unsubscribe domain_dyndns_unsubscribe(domain=domain, password=dyndns_recovery_password) diff --git a/src/dyndns.py b/src/dyndns.py index d1049e756..caeef9459 100644 --- a/src/dyndns.py +++ b/src/dyndns.py @@ -79,27 +79,27 @@ def _dyndns_available(domain): @is_unit_operation() -def dyndns_subscribe(operation_logger, domain=None, password=None): +def dyndns_subscribe(operation_logger, domain=None, recovery_password=None): """ Subscribe to a DynDNS service Keyword argument: domain -- Full domain to subscribe with - password -- Password that will be used to delete the domain + recovery_password -- Password that will be used to delete the domain """ - if password is None: + if recovery_password is None: logger.warning(m18n.n('dyndns_no_recovery_password')) else: from yunohost.utils.password import assert_password_is_strong_enough # Ensure sufficiently complex password - if Moulinette.interface.type == "cli" and password == 0: - password = Moulinette.prompt( + if Moulinette.interface.type == "cli" and recovery_password == 0: + recovery_password = Moulinette.prompt( m18n.n("ask_password"), is_password=True, confirm=True ) - assert_password_is_strong_enough("admin", password) + assert_password_is_strong_enough("admin", recovery_password) if not is_subscribing_allowed(): raise YunohostValidationError("domain_dyndns_already_subscribed") @@ -155,7 +155,7 @@ def dyndns_subscribe(operation_logger, domain=None, password=None): b64encoded_key = base64.b64encode(secret.encode()).decode() data = {"subdomain": domain} if password is not None: - data["recovery_password"] = hashlib.sha256((domain + ":" + password.strip()).encode('utf-8')).hexdigest() + data["recovery_password"] = hashlib.sha256((domain + ":" + recovery_password.strip()).encode('utf-8')).hexdigest() r = requests.post( f"https://{DYNDNS_PROVIDER}/key/{b64encoded_key}?key_algo=hmac-sha512", data=data, @@ -193,24 +193,24 @@ def dyndns_subscribe(operation_logger, domain=None, password=None): @is_unit_operation() -def dyndns_unsubscribe(operation_logger, domain, password=None): +def dyndns_unsubscribe(operation_logger, domain, recovery_password=None): """ Unsubscribe from a DynDNS service Keyword argument: domain -- Full domain to unsubscribe with - password -- Password that is used to delete the domain ( defined when subscribing ) + recovery_password -- Password that is used to delete the domain ( defined when subscribing ) """ from yunohost.utils.password import assert_password_is_strong_enough # Ensure sufficiently complex password - if Moulinette.interface.type == "cli" and not password: - password = Moulinette.prompt( + if Moulinette.interface.type == "cli" and not recovery_password: + recovery_password = Moulinette.prompt( m18n.n("ask_password"), is_password=True ) - assert_password_is_strong_enough("admin", password) + assert_password_is_strong_enough("admin", recovery_password) operation_logger.start() @@ -222,7 +222,7 @@ def dyndns_unsubscribe(operation_logger, domain, password=None): # Send delete request try: - secret = str(domain) + ":" + str(password).strip() + secret = str(domain) + ":" + str(recovery_password).strip() r = requests.delete( f"https://{DYNDNS_PROVIDER}/domains/{domain}", data={"recovery_password": hashlib.sha256(secret.encode('utf-8')).hexdigest()}, diff --git a/src/tools.py b/src/tools.py index 512986ff9..c0da7a37b 100644 --- a/src/tools.py +++ b/src/tools.py @@ -152,7 +152,7 @@ def tools_postinstall( fullname, password, dyndns_recovery_password=None, - no_subscribe=False, + ignore_dyndns=False, force_diskspace=False, ): @@ -194,7 +194,8 @@ def tools_postinstall( # If this is a nohost.me/noho.st, actually check for availability if is_yunohost_dyndns_domain(domain): - if ((dyndns_recovery_password is None) == (no_subscribe is False)): + + if (bool(dyndns_recovery_password), ignore_dyndns) in [(True, True), (False, False)]: raise YunohostValidationError("domain_dyndns_instruction_unclear") # Check if the domain is available... @@ -219,7 +220,7 @@ def tools_postinstall( logger.info(m18n.n("yunohost_installing")) # New domain config - domain_add(domain, dyndns_recovery_password=dyndns_recovery_password, no_subscribe=no_subscribe) + domain_add(domain, dyndns_recovery_password=dyndns_recovery_password, ignore_dyndns=ignore_dyndns) domain_main_domain(domain) user_create(username, domain, password, admin=True, fullname=fullname)