dyndns: Misc semantic tweaks...

This commit is contained in:
Alexandre Aubin 2023-04-11 15:17:41 +02:00
parent d67e231678
commit 81360723cc
5 changed files with 37 additions and 39 deletions

View file

@ -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_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_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_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": "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 --no-unsubscribe", "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_exists": "The domain already exists",
"domain_hostname_failed": "Unable to set new hostname. This might cause an issue later (it might be fine).", "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}.", "domain_registrar_is_not_configured": "The registrar is not yet configured for domain {domain}.",

View file

@ -506,8 +506,7 @@ domain:
help: Domain name to add help: Domain name to add
extra: extra:
pattern: *pattern_domain pattern: *pattern_domain
-n: --ignore-dyndns:
full: --no-subscribe
help: If adding a DynDNS domain, only add the domain, without subscribing to the DynDNS service help: If adding a DynDNS domain, only add the domain, without subscribing to the DynDNS service
action: store_true action: store_true
--dyndns-recovery-password: --dyndns-recovery-password:
@ -536,8 +535,7 @@ domain:
full: --force full: --force
help: Do not ask confirmation to remove apps help: Do not ask confirmation to remove apps
action: store_true action: store_true
-n: --ignore-dyndns:
full: --no-unsubscribe
help: If removing a DynDNS domain, only remove the domain, without unsubscribing from the DynDNS service help: If removing a DynDNS domain, only remove the domain, without unsubscribing from the DynDNS service
action: store_true action: store_true
--dyndns-recovery-password: --dyndns-recovery-password:
@ -662,7 +660,7 @@ domain:
extra: extra:
pattern: *pattern_domain pattern: *pattern_domain
-p: -p:
full: --password full: --recovery-password
nargs: "?" nargs: "?"
const: 0 const: 0
help: Password used to later delete the domain help: Password used to later delete the domain
@ -681,7 +679,7 @@ domain:
pattern: *pattern_domain pattern: *pattern_domain
required: True required: True
-p: -p:
full: --password full: --recovery-password
nargs: "?" nargs: "?"
const: 0 const: 0
help: Password used to delete the domain help: Password used to delete the domain
@ -1688,8 +1686,7 @@ tools:
pattern: *pattern_password pattern: *pattern_password
required: True required: True
comment: good_practices_about_admin_password comment: good_practices_about_admin_password
-n: --ingnore-dyndns:
full: --no-subscribe
help: If adding a DynDNS domain, only add the domain, without subscribing to the DynDNS service help: If adding a DynDNS domain, only add the domain, without subscribing to the DynDNS service
action: store_true action: store_true
--dyndns-recovery-password: --dyndns-recovery-password:

View file

@ -214,7 +214,7 @@ def _get_parent_domain_of(domain, return_self=False, topest=False):
@is_unit_operation(exclude=["dyndns_recovery_password"]) @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 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 domain -- Domain name to add
dyndns -- Subscribe to DynDNS dyndns -- Subscribe to DynDNS
dyndns_recovery_password -- Password used to later unsubscribe from 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.hook import hook_callback
from yunohost.app import app_ssowatconf 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 ) # 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 dyndns = is_yunohost_dyndns_domain(domain) and len(domain.split(".")) == 3
if dyndns: 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": if Moulinette.interface.type == "api":
raise YunohostValidationError("domain_dyndns_missing_password") raise YunohostValidationError("domain_dyndns_missing_password")
else: else:
@ -267,7 +267,7 @@ def domain_add(operation_logger, domain, dyndns_recovery_password=None, no_subsc
# Ensure sufficiently complex password # Ensure sufficiently complex password
assert_password_is_strong_enough("admin", dyndns_recovery_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") raise YunohostValidationError("domain_dyndns_instruction_unclear")
from yunohost.dyndns import is_subscribing_allowed 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") raise YunohostValidationError("domain_dyndns_already_subscribed")
operation_logger.start() operation_logger.start()
if not dyndns and (dyndns_recovery_password is not None or no_subscribe): 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 --no-subscribe option") 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 # Actually subscribe
domain_dyndns_subscribe(domain=domain, password=dyndns_recovery_password) 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"]) @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 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 force -- Force the domain removal and don't not ask confirmation to
remove apps if remove_apps is specified remove apps if remove_apps is specified
dyndns_recovery_password -- Recovery password used at the creation of the DynDNS domain 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.hook import hook_callback
from yunohost.app import app_ssowatconf, app_info, app_remove 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 ) # 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 dyndns = is_yunohost_dyndns_domain(domain) and len(domain.split(".")) == 3
if dyndns: 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") raise YunohostValidationError("domain_dyndns_instruction_unclear_unsubscribe")
operation_logger.start() operation_logger.start()
if not dyndns and ((dyndns_recovery_password is not None) or (no_unsubscribe is not False)): 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 --no-unsubscribe option") logger.warning("This domain is not a DynDNS one, no need for the --dyndns_recovery_password or --ignore-dyndns option")
ldap = _get_ldap_interface() ldap = _get_ldap_interface()
try: try:
@ -467,7 +467,7 @@ def domain_remove(operation_logger, domain, remove_apps=False, force=False, dynd
hook_callback("post_domain_remove", args=[domain]) hook_callback("post_domain_remove", args=[domain])
# If a password is provided, delete the DynDNS record # If a password is provided, delete the DynDNS record
if dyndns and not no_unsubscribe: if dyndns and not ignore_dyndns:
# Actually unsubscribe # Actually unsubscribe
domain_dyndns_unsubscribe(domain=domain, password=dyndns_recovery_password) domain_dyndns_unsubscribe(domain=domain, password=dyndns_recovery_password)

View file

@ -79,27 +79,27 @@ def _dyndns_available(domain):
@is_unit_operation() @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 Subscribe to a DynDNS service
Keyword argument: Keyword argument:
domain -- Full domain to subscribe with 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')) logger.warning(m18n.n('dyndns_no_recovery_password'))
else: else:
from yunohost.utils.password import assert_password_is_strong_enough from yunohost.utils.password import assert_password_is_strong_enough
# Ensure sufficiently complex password # Ensure sufficiently complex password
if Moulinette.interface.type == "cli" and password == 0: if Moulinette.interface.type == "cli" and recovery_password == 0:
password = Moulinette.prompt( recovery_password = Moulinette.prompt(
m18n.n("ask_password"), m18n.n("ask_password"),
is_password=True, is_password=True,
confirm=True confirm=True
) )
assert_password_is_strong_enough("admin", password) assert_password_is_strong_enough("admin", recovery_password)
if not is_subscribing_allowed(): if not is_subscribing_allowed():
raise YunohostValidationError("domain_dyndns_already_subscribed") 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() b64encoded_key = base64.b64encode(secret.encode()).decode()
data = {"subdomain": domain} data = {"subdomain": domain}
if password is not None: 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( r = requests.post(
f"https://{DYNDNS_PROVIDER}/key/{b64encoded_key}?key_algo=hmac-sha512", f"https://{DYNDNS_PROVIDER}/key/{b64encoded_key}?key_algo=hmac-sha512",
data=data, data=data,
@ -193,24 +193,24 @@ def dyndns_subscribe(operation_logger, domain=None, password=None):
@is_unit_operation() @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 Unsubscribe from a DynDNS service
Keyword argument: Keyword argument:
domain -- Full domain to unsubscribe with 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 from yunohost.utils.password import assert_password_is_strong_enough
# Ensure sufficiently complex password # Ensure sufficiently complex password
if Moulinette.interface.type == "cli" and not password: if Moulinette.interface.type == "cli" and not recovery_password:
password = Moulinette.prompt( recovery_password = Moulinette.prompt(
m18n.n("ask_password"), m18n.n("ask_password"),
is_password=True is_password=True
) )
assert_password_is_strong_enough("admin", password) assert_password_is_strong_enough("admin", recovery_password)
operation_logger.start() operation_logger.start()
@ -222,7 +222,7 @@ def dyndns_unsubscribe(operation_logger, domain, password=None):
# Send delete request # Send delete request
try: try:
secret = str(domain) + ":" + str(password).strip() secret = str(domain) + ":" + str(recovery_password).strip()
r = requests.delete( r = requests.delete(
f"https://{DYNDNS_PROVIDER}/domains/{domain}", f"https://{DYNDNS_PROVIDER}/domains/{domain}",
data={"recovery_password": hashlib.sha256(secret.encode('utf-8')).hexdigest()}, data={"recovery_password": hashlib.sha256(secret.encode('utf-8')).hexdigest()},

View file

@ -152,7 +152,7 @@ def tools_postinstall(
fullname, fullname,
password, password,
dyndns_recovery_password=None, dyndns_recovery_password=None,
no_subscribe=False, ignore_dyndns=False,
force_diskspace=False, force_diskspace=False,
): ):
@ -194,7 +194,8 @@ def tools_postinstall(
# If this is a nohost.me/noho.st, actually check for availability # If this is a nohost.me/noho.st, actually check for availability
if is_yunohost_dyndns_domain(domain): 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") raise YunohostValidationError("domain_dyndns_instruction_unclear")
# Check if the domain is available... # Check if the domain is available...
@ -219,7 +220,7 @@ def tools_postinstall(
logger.info(m18n.n("yunohost_installing")) logger.info(m18n.n("yunohost_installing"))
# New domain config # 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) domain_main_domain(domain)
user_create(username, domain, password, admin=True, fullname=fullname) user_create(username, domain, password, admin=True, fullname=fullname)