From 863843a1cf21919a72f286dc875930c0100bcffd Mon Sep 17 00:00:00 2001 From: "theo@manjaro" Date: Fri, 15 Jul 2022 14:26:21 +0200 Subject: [PATCH] The maximum number of subscribed DynDNS domains is configurable --- src/domain.py | 4 +- src/dyndns.py | 107 ++++++++++++++++++++++---------------------------- 2 files changed, 50 insertions(+), 61 deletions(-) diff --git a/src/domain.py b/src/domain.py index b1544d46a..bc04dd523 100644 --- a/src/domain.py +++ b/src/domain.py @@ -182,10 +182,10 @@ def domain_add(operation_logger, domain, subscribe=None, no_subscribe=False): if ((subscribe==None) == (no_subscribe==False)): raise YunohostValidationError("domain_dyndns_instruction_unclear") - from yunohost.dyndns import _guess_current_dyndns_domain + from yunohost.dyndns import is_subscribing_allowed # Do not allow to subscribe to multiple dyndns domains... - if _guess_current_dyndns_domain() != (None, None): + if not is_subscribing_allowed(): raise YunohostValidationError("domain_dyndns_already_subscribed") operation_logger.start() diff --git a/src/dyndns.py b/src/dyndns.py index 0baa1d428..a12ef3355 100644 --- a/src/dyndns.py +++ b/src/dyndns.py @@ -48,6 +48,16 @@ logger = getActionLogger("yunohost.dyndns") DYNDNS_PROVIDER = "dyndns.yunohost.org" DYNDNS_DNS_AUTH = ["ns0.yunohost.org", "ns1.yunohost.org"] +MAX_DYNDNS_DOMAINS = 1 + +def is_subscribing_allowed(): + """ + Check if the limit of subscribed DynDNS domains has been reached + + Returns: + True if the limit is not reached, False otherwise + """ + return len(glob.glob("/etc/yunohost/dyndns/*.key"))[^\s\+]+)\.\+165.+\.key$") - - # Retrieve the first registered domain - paths = list(glob.iglob("/etc/yunohost/dyndns/K*.key")) - for path in paths: - match = DYNDNS_KEY_REGEX.match(path) - if not match: - continue - _domain = match.group("domain") - - # Verify if domain is registered (i.e., if it's available, skip - # current domain beause that's not the one we want to update..) - # If there's only 1 such key found, then avoid doing the request - # for nothing (that's very probably the one we want to find ...) - if len(paths) > 1 and _dyndns_available(_domain): - continue - else: - return (_domain, path) - - return (None, None)