From bc3521fd0452295378177033496976f6d1813cda Mon Sep 17 00:00:00 2001 From: "theo@manjaro" Date: Wed, 6 Jul 2022 09:30:00 +0200 Subject: [PATCH] `yunohost tools postinstall` auto-detect DynDNS domains and asks for a --subscribe or --no-subscribe option --- share/actionsmap.yml | 14 ++++++++++++-- src/tools.py | 18 ++++++++---------- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/share/actionsmap.yml b/share/actionsmap.yml index eb24de49f..d69a35f1f 100644 --- a/share/actionsmap.yml +++ b/share/actionsmap.yml @@ -1574,9 +1574,19 @@ tools: pattern: *pattern_password required: True comment: good_practices_about_admin_password - --ignore-dyndns: - help: Do not subscribe domain to a DynDNS service + -n: + full: --no-subscribe + help: If adding a DynDNS domain, only add the domain, without subscribing to the DynDNS service action: store_true + -s: + full: --subscribe + metavar: PASSWORD + nargs: "?" + const: 0 + help: If adding a DynDNS domain, subscribe to the DynDNS service with a password, used to later delete the domain + extra: + pattern: *pattern_password + comment: dyndns_added_password --force-password: help: Use this if you really want to set a weak password action: store_true diff --git a/src/tools.py b/src/tools.py index bb7ded03a..543f835e6 100644 --- a/src/tools.py +++ b/src/tools.py @@ -186,6 +186,8 @@ def tools_postinstall( domain, password, ignore_dyndns=False, + subscribe=None, + no_subscribe=False, force_password=False, force_diskspace=False, ): @@ -230,10 +232,13 @@ def tools_postinstall( assert_password_is_strong_enough("admin", password) # If this is a nohost.me/noho.st, actually check for availability - if not ignore_dyndns and is_yunohost_dyndns_domain(domain): + if is_yunohost_dyndns_domain(domain): + if ((subscribe==None) == (no_subscribe==False)): + raise YunohostValidationError("domain_dyndns_instruction_unclear") + # Check if the domain is available... try: - available = _dyndns_available(domain) + _dyndns_available(domain) # If an exception is thrown, most likely we don't have internet # connectivity or something. Assume that this domain isn't manageable # and inform the user that we could not contact the dyndns host server. @@ -241,14 +246,7 @@ def tools_postinstall( logger.warning( m18n.n("dyndns_provider_unreachable", provider="dyndns.yunohost.org") ) - - if available: - dyndns = True - # If not, abort the postinstall - else: raise YunohostValidationError("dyndns_unavailable", domain=domain) - else: - dyndns = False if os.system("iptables -V >/dev/null 2>/dev/null") != 0: raise YunohostValidationError( @@ -260,7 +258,7 @@ def tools_postinstall( logger.info(m18n.n("yunohost_installing")) # New domain config - domain_add(domain, dyndns) + domain_add(domain, subscribe=subscribe,no_subscribe=no_subscribe) domain_main_domain(domain) # Update LDAP admin and create home dir