diff --git a/data/actionsmap/yunohost.yml b/data/actionsmap/yunohost.yml index bff87d4e8..fd206603d 100644 --- a/data/actionsmap/yunohost.yml +++ b/data/actionsmap/yunohost.yml @@ -1168,7 +1168,7 @@ dyndns: default: "dyndns.yunohost.org" -d: full: --domain - help: Full domain to subscribe with + help: Full domain to update extra: pattern: *pattern_domain -k: diff --git a/debian/changelog b/debian/changelog index 03539feba..81124e12b 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,15 @@ +moulinette-yunohost (2.2.4) stable; urgency=low + + [ Jérôme Lebleu ] + * [fix] Update first registered domain with DynDNS instead of current_host + * [fix] Set found private key and don't validate it in dyndns_update + * [fix] Use dyndns.yunohost.org instead of dynhost.yunohost.org + + [ opi ] + * [fix] Catch ConnectionError from requests package + + -- Jérôme Lebleu Sun, 27 Mar 2016 16:30:42 +0200 + yunohost (2.3.11.2) testing; urgency=low * [fix] Don't fail dnsmasq regen if IPv4/6 cannot be retrieved @@ -383,12 +395,6 @@ moulinette-yunohost (2.3.0) testing; urgency=low -- Jérôme Lebleu Tue, 08 Sep 2015 14:19:28 +0200 -moulinette-yunohost (2.2.3-1) stable; urgency=low - - * [fix] Catch ConnectionError from requests package - - -- opi Sun, 06 Mar 2016 21:51:06 +0100 - moulinette-yunohost (2.2.3) stable; urgency=low * [fix] Catch proper exception in backup_list (fix #65) diff --git a/locales/en.json b/locales/en.json index 5859a10f2..10c056d9b 100644 --- a/locales/en.json +++ b/locales/en.json @@ -69,6 +69,8 @@ "no_ipv6_connectivity": "IPv6 connectivity is not available", "dyndns_key_generating" : "DNS key is being generated, it may take a while...", + "dyndns_key_not_found" : "DNS key not found for the domain", + "dyndns_no_domain_registered": "No domain has been registered with DynDNS", "dyndns_unavailable" : "Unavailable DynDNS subdomain", "dyndns_registration_failed" : "Unable to register DynDNS domain: {error:s}", "dyndns_registered" : "DynDNS domain successfully registered", diff --git a/src/yunohost/dyndns.py b/src/yunohost/dyndns.py index 4d95ebeab..878bc577e 100644 --- a/src/yunohost/dyndns.py +++ b/src/yunohost/dyndns.py @@ -24,12 +24,12 @@ Subscribe and Update DynDNS Hosts """ import os -import requests import re import json import glob import base64 import errno +import requests import subprocess from moulinette.core import MoulinetteError @@ -62,6 +62,10 @@ class IPRouteLine(object): for k, v in self.m.groupdict().items(): setattr(self, k, v) +re_dyndns_private_key = re.compile( + r'.*/K(?P[^\s\+]+)\.\+157.+\.private$' +) + def dyndns_subscribe(subscribe_host="dyndns.yunohost.org", domain=None, key=None): """ @@ -120,17 +124,13 @@ def dyndns_update(dyn_host="dyndns.yunohost.org", domain=None, key=None, Update IP on DynDNS platform Keyword argument: - domain -- Full domain to subscribe with + domain -- Full domain to update dyn_host -- Dynette DNS server to inform key -- Public DNS key ipv4 -- IP address to send ipv6 -- IPv6 address to send """ - if domain is None: - with open('/etc/yunohost/current_host', 'r') as f: - domain = f.readline().rstrip() - # IPv4 if ipv4 is None: ipv4 = get_public_ip() @@ -168,6 +168,37 @@ def dyndns_update(dyn_host="dyndns.yunohost.org", domain=None, key=None, old_ipv6 = '0000:0000:0000:0000:0000:0000:0000:0000' if old_ip != ipv4 or old_ipv6 != ipv6: + if domain is None: + # Retrieve the first registered domain + for path in glob.iglob('/etc/yunohost/dyndns/K*.private'): + match = re_dyndns_private_key.match(path) + if not match: + continue + _domain = match.group('domain') + try: + # Check if domain is registered + if requests.get('https://{0}/test/{1}'.format( + dyn_host, _domain)).status_code == 200: + continue + except requests.ConnectionError: + raise MoulinetteError(errno.ENETUNREACH, + m18n.n('no_internet_connection')) + domain = _domain + key = path + break + if not domain: + raise MoulinetteError(errno.EINVAL, + m18n.n('dyndns_no_domain_registered')) + + if key is None: + keys = glob.glob( + '/etc/yunohost/dyndns/K{0}.+*.private'.format(domain)) + if len(keys) > 0: + key = keys[0] + if not key: + raise MoulinetteError(errno.EIO, + m18n.n('dyndns_key_not_found')) + host = domain.split('.')[1:] host = '.'.join(host) lines = [ @@ -209,11 +240,7 @@ def dyndns_update(dyn_host="dyndns.yunohost.org", domain=None, key=None, for line in lines: zone.write(line + '\n') - if key is None: - private_key_file = glob.glob('/etc/yunohost/dyndns/*.private')[0] - else: - private_key_file = key - if os.system('/usr/bin/nsupdate -k %s /etc/yunohost/dyndns/zone' % private_key_file) == 0: + if os.system('/usr/bin/nsupdate -k %s /etc/yunohost/dyndns/zone' % key) == 0: logger.success(m18n.n('dyndns_ip_updated')) with open('/etc/yunohost/dyndns/old_ip', 'w') as f: f.write(ipv4)