mirror of
https://github.com/YunoHost/moulinette.git
synced 2024-09-03 20:06:31 +02:00
[ref] Adapt yunohost_dyndns
This commit is contained in:
parent
906a416f59
commit
9cfde30899
2 changed files with 28 additions and 24 deletions
|
@ -947,6 +947,9 @@ tools:
|
||||||
postinstall:
|
postinstall:
|
||||||
action_help: YunoHost post-install
|
action_help: YunoHost post-install
|
||||||
api: POST /postinstall
|
api: POST /postinstall
|
||||||
|
configuration:
|
||||||
|
authenticate: all
|
||||||
|
lock: false
|
||||||
arguments:
|
arguments:
|
||||||
-d:
|
-d:
|
||||||
full: --domain
|
full: --domain
|
||||||
|
|
|
@ -48,14 +48,14 @@ def dyndns_subscribe(subscribe_host="dyndns.yunohost.org", domain=None, key=None
|
||||||
domain = f.readline().rstrip()
|
domain = f.readline().rstrip()
|
||||||
|
|
||||||
# Verify if domain is available
|
# Verify if domain is available
|
||||||
if requests.get('http://'+ subscribe_host +'/test/'+ domain).status_code != 200:
|
if requests.get('http://%s/test/%s' % (subscribe_host, domain)).status_code != 200:
|
||||||
raise MoulinetteError(17, _("DynDNS domain is already taken"))
|
raise MoulinetteError(17, _("DynDNS domain is already taken"))
|
||||||
|
|
||||||
if key is None:
|
if key is None:
|
||||||
if len(glob.glob('/etc/yunohost/dyndns/*.key')) == 0:
|
if len(glob.glob('/etc/yunohost/dyndns/*.key')) == 0:
|
||||||
os.makedirs('/etc/yunohost/dyndns')
|
os.makedirs('/etc/yunohost/dyndns')
|
||||||
print(_("DNS key is being generated, it may take a while..."))
|
print(_("DNS key is being generated, it may take a while..."))
|
||||||
os.system('cd /etc/yunohost/dyndns && dnssec-keygen -a hmac-md5 -b 128 -n USER '+ domain)
|
os.system('cd /etc/yunohost/dyndns && dnssec-keygen -a hmac-md5 -b 128 -n USER %s' % domain)
|
||||||
os.system('chmod 600 /etc/yunohost/dyndns/*.key /etc/yunohost/dyndns/*.private')
|
os.system('chmod 600 /etc/yunohost/dyndns/*.key /etc/yunohost/dyndns/*.private')
|
||||||
|
|
||||||
key_file = glob.glob('/etc/yunohost/dyndns/*.key')[0]
|
key_file = glob.glob('/etc/yunohost/dyndns/*.key')[0]
|
||||||
|
@ -63,7 +63,7 @@ def dyndns_subscribe(subscribe_host="dyndns.yunohost.org", domain=None, key=None
|
||||||
key = f.readline().strip().split(' ')[-1]
|
key = f.readline().strip().split(' ')[-1]
|
||||||
|
|
||||||
# Send subscription
|
# Send subscription
|
||||||
r = requests.post('http://'+ subscribe_host +'/key/'+ base64.b64encode(key), data={ 'subdomain': domain })
|
r = requests.post('http://%s/key/%s' % (subscribe_host, base64.b64encode(key)), data={ 'subdomain': domain })
|
||||||
if r.status_code != 201:
|
if r.status_code != 201:
|
||||||
try: error = json.loads(r.text)['error']
|
try: error = json.loads(r.text)['error']
|
||||||
except: error = "Server error"
|
except: error = "Server error"
|
||||||
|
@ -104,24 +104,24 @@ def dyndns_update(dyn_host="dynhost.yunohost.org", domain=None, key=None, ip=Non
|
||||||
host = domain.split('.')[1:]
|
host = domain.split('.')[1:]
|
||||||
host = '.'.join(host)
|
host = '.'.join(host)
|
||||||
lines = [
|
lines = [
|
||||||
'server '+ dyn_host,
|
'server %s' % dyn_host,
|
||||||
'zone '+ host,
|
'zone %s' % host,
|
||||||
'update delete '+ domain +'. A',
|
'update delete %s. A' % domain,
|
||||||
'update delete '+ domain +'. MX',
|
'update delete %s. MX' % domain,
|
||||||
'update delete '+ domain +'. TXT',
|
'update delete %s. TXT' % domain,
|
||||||
'update delete pubsub.'+ domain +'. A',
|
'update delete pubsub.%s. A' % domain,
|
||||||
'update delete muc.'+ domain +'. A',
|
'update delete muc.%s. A' % domain,
|
||||||
'update delete vjud.'+ domain +'. A',
|
'update delete vjud.%s. A' % domain,
|
||||||
'update delete _xmpp-client._tcp.'+ domain +'. SRV',
|
'update delete _xmpp-client._tcp.%s. SRV' % domain,
|
||||||
'update delete _xmpp-server._tcp.'+ domain +'. SRV',
|
'update delete _xmpp-server._tcp.%s. SRV' % domain,
|
||||||
'update add '+ domain +'. 1800 A '+ new_ip,
|
'update add %s. 1800 A %s' % (domain, new_ip),
|
||||||
'update add '+ domain +'. 14400 MX 5 '+ domain +'.',
|
'update add %s. 14400 MX 5 %s.' % (domain, domain),
|
||||||
'update add '+ domain +'. 14400 TXT "v=spf1 a mx -all"',
|
'update add %s. 14400 TXT "v=spf1 a mx -all"' % domain,
|
||||||
'update add pubsub.'+ domain +'. 1800 A '+ new_ip,
|
'update add pubsub.%s. 1800 A %s' % (domain, new_ip),
|
||||||
'update add muc.'+ domain +'. 1800 A '+ new_ip,
|
'update add muc.%s. 1800 A %s' % (domain, new_ip),
|
||||||
'update add vjud.'+ domain +'. 1800 A '+ new_ip,
|
'update add vjud.%s. 1800 A %s' % (domain, new_ip),
|
||||||
'update add _xmpp-client._tcp.'+ domain +'. 14400 SRV 0 5 5222 '+ domain +'.',
|
'update add _xmpp-client._tcp.%s. 14400 SRV 0 5 5222 %s.' % (domain, domain),
|
||||||
'update add _xmpp-server._tcp.'+ domain +'. 14400 SRV 0 5 5269 '+ domain +'.',
|
'update add _xmpp-server._tcp.%s. 14400 SRV 0 5 5269 %s.' % (domain, domain),
|
||||||
'show',
|
'show',
|
||||||
'send'
|
'send'
|
||||||
]
|
]
|
||||||
|
@ -133,7 +133,7 @@ def dyndns_update(dyn_host="dynhost.yunohost.org", domain=None, key=None, ip=Non
|
||||||
private_key_file = glob.glob('/etc/yunohost/dyndns/*.private')[0]
|
private_key_file = glob.glob('/etc/yunohost/dyndns/*.private')[0]
|
||||||
else:
|
else:
|
||||||
private_key_file = key
|
private_key_file = key
|
||||||
if os.system('/usr/bin/nsupdate -k '+ private_key_file +' /etc/yunohost/dyndns/zone') == 0:
|
if os.system('/usr/bin/nsupdate -k %s /etc/yunohost/dyndns/zone' % private_key_file) == 0:
|
||||||
msignals.display(_("IP successfully updated."), 'success')
|
msignals.display(_("IP successfully 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)
|
||||||
|
@ -148,8 +148,9 @@ def dyndns_installcron():
|
||||||
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
os.system("touch /etc/cron.d/yunohost-dyndns")
|
with open('/etc/cron.d/yunohost-dyndns', 'w+') as f:
|
||||||
os.system("echo '*/2 * * * * root yunohost dyndns update --no-ldap >> /dev/null' >/etc/cron.d/yunohost-dyndns")
|
f.write('*/2 * * * * root yunohost dyndns update >> /dev/null')
|
||||||
|
|
||||||
msignals.display(_("DynDNS cron installed."), 'success')
|
msignals.display(_("DynDNS cron installed."), 'success')
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue