From c5b5f2eb35e0d7e41de49fee6db2f33609683808 Mon Sep 17 00:00:00 2001 From: Irina LAMBLA Date: Mon, 27 Aug 2018 20:03:08 +0200 Subject: [PATCH 1/4] [fix] 'dyndns update' should check the upstream dns record fix #1063 --- src/yunohost/dyndns.py | 61 +++++++++++++++++++----------------------- 1 file changed, 27 insertions(+), 34 deletions(-) diff --git a/src/yunohost/dyndns.py b/src/yunohost/dyndns.py index 785b0dd34..e9542ed95 100644 --- a/src/yunohost/dyndns.py +++ b/src/yunohost/dyndns.py @@ -37,14 +37,14 @@ from moulinette.core import MoulinetteError from moulinette.utils.log import getActionLogger from moulinette.utils.filesystem import read_file, write_to_file, rm from moulinette.utils.network import download_json +from moulinette.utils.process import check_output + from yunohost.domain import _get_maindomain, _build_dns_conf from yunohost.utils.network import get_public_ip logger = getActionLogger('yunohost.dyndns') -OLD_IPV4_FILE = '/etc/yunohost/dyndns/old_ip' -OLD_IPV6_FILE = '/etc/yunohost/dyndns/old_ipv6' DYNDNS_ZONE = '/etc/yunohost/dyndns/zone' RE_DYNDNS_PRIVATE_KEY_MD5 = re.compile( @@ -95,7 +95,7 @@ def _dyndns_available(provider, domain): domain -- The full domain that you'd like.. e.g. "foo.nohost.me" Returns: - True if the domain is avaible, False otherwise. + True if the domain is available, False otherwise. """ logger.debug("Checking if domain %s is available on %s ..." % (domain, provider)) @@ -187,32 +187,6 @@ def dyndns_update(dyn_host="dyndns.yunohost.org", domain=None, key=None, old_ipv4, old_ipv6 = (None, None) # (default values) - if os.path.isfile(OLD_IPV4_FILE): - old_ipv4 = read_file(OLD_IPV4_FILE).rstrip() - - if os.path.isfile(OLD_IPV6_FILE): - old_ipv6 = read_file(OLD_IPV6_FILE).rstrip() - - # Get current IPv4 and IPv6 - ipv4_ = get_public_ip() - ipv6_ = get_public_ip(6) - - if ipv4 is None: - ipv4 = ipv4_ - - if ipv6 is None: - ipv6 = ipv6_ - - logger.debug("Old IPv4/v6 are (%s, %s)" % (old_ipv4, old_ipv6)) - logger.debug("Requested IPv4/v6 are (%s, %s)" % (ipv4, ipv6)) - - # no need to update - if old_ipv4 == ipv4 and old_ipv6 == ipv6: - logger.info("No updated needed.") - return - else: - logger.info("Updated needed, going on...") - # If domain is not given, try to guess it from keys available... if domain is None: (domain, key) = _guess_current_dyndns_domain(dyn_host) @@ -252,6 +226,30 @@ def dyndns_update(dyn_host="dyndns.yunohost.org", domain=None, key=None, 'zone %s' % host, ] + + old_ipv4 = check_output("dig @91.224.148.92 +short %s" % domain).strip() + old_ipv6 = check_output("dig @91.224.148.92 +short aaaa %s" % domain).strip() + + # Get current IPv4 and IPv6 + ipv4_ = get_public_ip() + ipv6_ = get_public_ip(6) + + if ipv4 is None: + ipv4 = ipv4_ + + if ipv6 is None: + ipv6 = ipv6_ + + logger.debug("Old IPv4/v6 are (%s, %s)" % (old_ipv4, old_ipv6)) + logger.debug("Requested IPv4/v6 are (%s, %s)" % (ipv4, ipv6)) + + # no need to update + if old_ipv4 == ipv4 and old_ipv6 == ipv6: + logger.info("No updated needed.") + return + else: + logger.info("Updated needed, going on...") + dns_conf = _build_dns_conf(domain) # Delete the old records for all domain/subdomains @@ -301,11 +299,6 @@ def dyndns_update(dyn_host="dyndns.yunohost.org", domain=None, key=None, logger.success(m18n.n('dyndns_ip_updated')) - if ipv4 is not None: - write_to_file(OLD_IPV4_FILE, ipv4) - if ipv6 is not None: - write_to_file(OLD_IPV6_FILE, ipv6) - def dyndns_installcron(): """ From 6883784fdb99b7122bfe9d60ba620408d1d0018d Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Wed, 24 Oct 2018 15:45:41 +0000 Subject: [PATCH 2/4] Using dyndns host for dns resolution instead of hardcoded ip --- src/yunohost/dyndns.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/yunohost/dyndns.py b/src/yunohost/dyndns.py index e9542ed95..bb6a626fc 100644 --- a/src/yunohost/dyndns.py +++ b/src/yunohost/dyndns.py @@ -227,8 +227,8 @@ def dyndns_update(dyn_host="dyndns.yunohost.org", domain=None, key=None, ] - old_ipv4 = check_output("dig @91.224.148.92 +short %s" % domain).strip() - old_ipv6 = check_output("dig @91.224.148.92 +short aaaa %s" % domain).strip() + old_ipv4 = check_output("dig @%s +short %s" % (dyn_host, domain)).strip() + old_ipv6 = check_output("dig @%s +short aaaa %s" % (dyn_host, domain)).strip() # Get current IPv4 and IPv6 ipv4_ = get_public_ip() From d42ac39c11bd8045ff693ba4d69d92afe5f60522 Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Wed, 24 Oct 2018 15:55:20 +0000 Subject: [PATCH 3/4] Fallback to 'None' if no ip was resolved --- src/yunohost/dyndns.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/yunohost/dyndns.py b/src/yunohost/dyndns.py index bb6a626fc..5edf77ccd 100644 --- a/src/yunohost/dyndns.py +++ b/src/yunohost/dyndns.py @@ -227,8 +227,8 @@ def dyndns_update(dyn_host="dyndns.yunohost.org", domain=None, key=None, ] - old_ipv4 = check_output("dig @%s +short %s" % (dyn_host, domain)).strip() - old_ipv6 = check_output("dig @%s +short aaaa %s" % (dyn_host, domain)).strip() + old_ipv4 = check_output("dig @%s +short %s" % (dyn_host, domain)).strip() or None + old_ipv6 = check_output("dig @%s +short aaaa %s" % (dyn_host, domain)).strip() or None # Get current IPv4 and IPv6 ipv4_ = get_public_ip() From d1d660b2cf373440937bda5919a89b5092ee6f51 Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Wed, 24 Oct 2018 18:08:56 +0200 Subject: [PATCH 4/4] Those files don't exist anymoar --- src/yunohost/dyndns.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/yunohost/dyndns.py b/src/yunohost/dyndns.py index 5edf77ccd..a1e6cd60a 100644 --- a/src/yunohost/dyndns.py +++ b/src/yunohost/dyndns.py @@ -292,8 +292,6 @@ def dyndns_update(dyn_host="dyndns.yunohost.org", domain=None, key=None, command = ["/usr/bin/nsupdate", "-k", key, DYNDNS_ZONE] subprocess.check_call(command) except subprocess.CalledProcessError: - rm(OLD_IPV4_FILE, force=True) # Remove file (ignore if non-existent) - rm(OLD_IPV6_FILE, force=True) # Remove file (ignore if non-existent) raise MoulinetteError(errno.EPERM, m18n.n('dyndns_ip_update_failed'))