From d66a46a8de2f11bee34cc2faf0ebf42f87fd7899 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Lebleu?= Date: Sat, 26 Mar 2016 00:27:25 +0100 Subject: [PATCH 1/4] [fix] Update first registered domain with DynDNS instead of current_host --- data/actionsmap/yunohost.yml | 2 +- lib/yunohost/dyndns.py | 47 ++++++++++++++++++++++++++++-------- locales/en.json | 2 ++ 3 files changed, 40 insertions(+), 11 deletions(-) diff --git a/data/actionsmap/yunohost.yml b/data/actionsmap/yunohost.yml index 7f3ae9483..190104238 100644 --- a/data/actionsmap/yunohost.yml +++ b/data/actionsmap/yunohost.yml @@ -1026,7 +1026,7 @@ dyndns: default: "dynhost.yunohost.org" -d: full: --domain - help: Full domain to subscribe with + help: Full domain to update extra: pattern: *pattern_domain -k: diff --git a/lib/yunohost/dyndns.py b/lib/yunohost/dyndns.py index 27650ad99..6276849a3 100644 --- a/lib/yunohost/dyndns.py +++ b/lib/yunohost/dyndns.py @@ -24,6 +24,7 @@ Subscribe and Update DynDNS Hosts """ import os +import re import sys import requests import json @@ -33,6 +34,10 @@ import errno from moulinette.core import MoulinetteError +re_dyndns_private_key = re.compile( + r'.*/K(?P[^\s\+]+)\.\+157.+\.private$' +) + def dyndns_subscribe(subscribe_host="dyndns.yunohost.org", domain=None, key=None): """ @@ -90,16 +95,12 @@ def dyndns_update(dyn_host="dynhost.yunohost.org", domain=None, key=None, ip=Non 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 ip -- IP address to send """ - if domain is None: - with open('/etc/yunohost/current_host', 'r') as f: - domain = f.readline().rstrip() - if ip is None: try: new_ip = requests.get('http://ip.yunohost.org').text @@ -151,6 +152,36 @@ def dyndns_update(dyn_host="dynhost.yunohost.org", domain=None, key=None, ip=Non new_ipv6 = '0000:0000:0000:0000:0000:0000:0000:0000' if old_ip != new_ip or old_ipv6 != new_ipv6 and new_ipv6 is not None: + 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 + 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 or not os.path.isfile(key): + raise MoulinetteError(errno.EIO, + m18n.n('dyndns_key_not_found')) + host = domain.split('.')[1:] host = '.'.join(host) lines = [ @@ -184,11 +215,7 @@ def dyndns_update(dyn_host="dynhost.yunohost.org", domain=None, key=None, ip=Non 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: msignals.display(m18n.n('dyndns_ip_updated'), 'success') with open('/etc/yunohost/dyndns/old_ip', 'w') as f: f.write(new_ip) diff --git a/locales/en.json b/locales/en.json index 64cfd7b4e..6fad9a9f7 100644 --- a/locales/en.json +++ b/locales/en.json @@ -58,6 +58,8 @@ "no_internet_connection": "Server not connected to the Internet", "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: {:s}", "dyndns_registered" : "DynDNS domain successfully registered", From 39f4eb2aadfbb15185c3934fdabaf583c5762311 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Lebleu?= Date: Sat, 26 Mar 2016 10:29:52 +0100 Subject: [PATCH 2/4] [fix] Set found private key and don't validate it in dyndns_update --- lib/yunohost/dyndns.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/yunohost/dyndns.py b/lib/yunohost/dyndns.py index 6276849a3..231954b84 100644 --- a/lib/yunohost/dyndns.py +++ b/lib/yunohost/dyndns.py @@ -168,6 +168,7 @@ def dyndns_update(dyn_host="dynhost.yunohost.org", domain=None, key=None, ip=Non raise MoulinetteError(errno.ENETUNREACH, m18n.n('no_internet_connection')) domain = _domain + key = path break if not domain: raise MoulinetteError(errno.EINVAL, @@ -178,7 +179,7 @@ def dyndns_update(dyn_host="dynhost.yunohost.org", domain=None, key=None, ip=Non '/etc/yunohost/dyndns/K{0}.+*.private'.format(domain)) if len(keys) > 0: key = keys[0] - if not key or not os.path.isfile(key): + if not key: raise MoulinetteError(errno.EIO, m18n.n('dyndns_key_not_found')) From 0d9b8d9b3d4680473b56fd95a3b9d4b1a80db55d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Lebleu?= Date: Sat, 26 Mar 2016 14:15:49 +0100 Subject: [PATCH 3/4] [fix] Use dyndns.yunohost.org instead of dynhost.yunohost.org --- data/actionsmap/yunohost.yml | 2 +- lib/yunohost/dyndns.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/data/actionsmap/yunohost.yml b/data/actionsmap/yunohost.yml index 190104238..f14973497 100644 --- a/data/actionsmap/yunohost.yml +++ b/data/actionsmap/yunohost.yml @@ -1023,7 +1023,7 @@ dyndns: arguments: --dyn-host: help: Dynette DNS server to inform - default: "dynhost.yunohost.org" + default: "dyndns.yunohost.org" -d: full: --domain help: Full domain to update diff --git a/lib/yunohost/dyndns.py b/lib/yunohost/dyndns.py index 231954b84..b12d50484 100644 --- a/lib/yunohost/dyndns.py +++ b/lib/yunohost/dyndns.py @@ -90,7 +90,7 @@ def dyndns_subscribe(subscribe_host="dyndns.yunohost.org", domain=None, key=None dyndns_installcron() -def dyndns_update(dyn_host="dynhost.yunohost.org", domain=None, key=None, ip=None): +def dyndns_update(dyn_host="dyndns.yunohost.org", domain=None, key=None, ip=None): """ Update IP on DynDNS platform From 5d21b8deb718a9cdea5ad90773e5c437f572f03a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Lebleu?= Date: Sun, 27 Mar 2016 16:30:52 +0200 Subject: [PATCH 4/4] Update changelog for 2.2.4 release --- debian/changelog | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/debian/changelog b/debian/changelog index 6fe87139b..2923a67dc 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,8 +1,14 @@ -moulinette-yunohost (2.2.3-1) stable; urgency=low +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 - -- opi Sun, 06 Mar 2016 21:51:06 +0100 + -- Jérôme Lebleu Sun, 27 Mar 2016 16:30:42 +0200 moulinette-yunohost (2.2.3) stable; urgency=low