mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
[fix] Update first registered domain with DynDNS instead of current_host
This commit is contained in:
parent
6f572f419f
commit
d66a46a8de
3 changed files with 40 additions and 11 deletions
|
@ -1026,7 +1026,7 @@ dyndns:
|
||||||
default: "dynhost.yunohost.org"
|
default: "dynhost.yunohost.org"
|
||||||
-d:
|
-d:
|
||||||
full: --domain
|
full: --domain
|
||||||
help: Full domain to subscribe with
|
help: Full domain to update
|
||||||
extra:
|
extra:
|
||||||
pattern: *pattern_domain
|
pattern: *pattern_domain
|
||||||
-k:
|
-k:
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
Subscribe and Update DynDNS Hosts
|
Subscribe and Update DynDNS Hosts
|
||||||
"""
|
"""
|
||||||
import os
|
import os
|
||||||
|
import re
|
||||||
import sys
|
import sys
|
||||||
import requests
|
import requests
|
||||||
import json
|
import json
|
||||||
|
@ -33,6 +34,10 @@ import errno
|
||||||
|
|
||||||
from moulinette.core import MoulinetteError
|
from moulinette.core import MoulinetteError
|
||||||
|
|
||||||
|
re_dyndns_private_key = re.compile(
|
||||||
|
r'.*/K(?P<domain>[^\s\+]+)\.\+157.+\.private$'
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def dyndns_subscribe(subscribe_host="dyndns.yunohost.org", domain=None, key=None):
|
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
|
Update IP on DynDNS platform
|
||||||
|
|
||||||
Keyword argument:
|
Keyword argument:
|
||||||
domain -- Full domain to subscribe with
|
domain -- Full domain to update
|
||||||
dyn_host -- Dynette DNS server to inform
|
dyn_host -- Dynette DNS server to inform
|
||||||
key -- Public DNS key
|
key -- Public DNS key
|
||||||
ip -- IP address to send
|
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:
|
if ip is None:
|
||||||
try:
|
try:
|
||||||
new_ip = requests.get('http://ip.yunohost.org').text
|
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'
|
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 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 = domain.split('.')[1:]
|
||||||
host = '.'.join(host)
|
host = '.'.join(host)
|
||||||
lines = [
|
lines = [
|
||||||
|
@ -184,11 +215,7 @@ def dyndns_update(dyn_host="dynhost.yunohost.org", domain=None, key=None, ip=Non
|
||||||
for line in lines:
|
for line in lines:
|
||||||
zone.write(line + '\n')
|
zone.write(line + '\n')
|
||||||
|
|
||||||
if key is None:
|
if os.system('/usr/bin/nsupdate -k %s /etc/yunohost/dyndns/zone' % key) == 0:
|
||||||
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:
|
|
||||||
msignals.display(m18n.n('dyndns_ip_updated'), 'success')
|
msignals.display(m18n.n('dyndns_ip_updated'), 'success')
|
||||||
with open('/etc/yunohost/dyndns/old_ip', 'w') as f:
|
with open('/etc/yunohost/dyndns/old_ip', 'w') as f:
|
||||||
f.write(new_ip)
|
f.write(new_ip)
|
||||||
|
|
|
@ -58,6 +58,8 @@
|
||||||
"no_internet_connection": "Server not connected to the Internet",
|
"no_internet_connection": "Server not connected to the Internet",
|
||||||
|
|
||||||
"dyndns_key_generating" : "DNS key is being generated, it may take a while...",
|
"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_unavailable" : "Unavailable DynDNS subdomain",
|
||||||
"dyndns_registration_failed" : "Unable to register DynDNS domain: {:s}",
|
"dyndns_registration_failed" : "Unable to register DynDNS domain: {:s}",
|
||||||
"dyndns_registered" : "DynDNS domain successfully registered",
|
"dyndns_registered" : "DynDNS domain successfully registered",
|
||||||
|
|
Loading…
Add table
Reference in a new issue