mirror of
https://github.com/YunoHost/moulinette.git
synced 2024-09-03 20:06:31 +02:00
Subscribe to DynDNS after postinstall (fixes #38)
This commit is contained in:
parent
6ac40404f8
commit
8d66b6f831
3 changed files with 30 additions and 5 deletions
|
@ -180,6 +180,14 @@ domain:
|
||||||
help: Domain name to add
|
help: Domain name to add
|
||||||
nargs: '+'
|
nargs: '+'
|
||||||
pattern: '^([a-zA-Z0-9]{1}([a-zA-Z0-9\-]*[a-zA-Z0-9])*)(\.[a-zA-Z0-9]{1}([a-zA-Z0-9\-]*[a-zA-Z0-9])*)*(\.[a-zA-Z]{1}([a-zA-Z0-9\-]*[a-zA-Z0-9])*)$'
|
pattern: '^([a-zA-Z0-9]{1}([a-zA-Z0-9\-]*[a-zA-Z0-9])*)(\.[a-zA-Z0-9]{1}([a-zA-Z0-9\-]*[a-zA-Z0-9])*)*(\.[a-zA-Z]{1}([a-zA-Z0-9\-]*[a-zA-Z0-9])*)$'
|
||||||
|
-m:
|
||||||
|
full: --main
|
||||||
|
help: Is the main domain
|
||||||
|
action: store_true
|
||||||
|
-d:
|
||||||
|
full: --dyndns
|
||||||
|
help: Subscribe to the DynDNS service
|
||||||
|
action: store_true
|
||||||
|
|
||||||
### domain_remove()
|
### domain_remove()
|
||||||
remove:
|
remove:
|
||||||
|
|
|
@ -30,8 +30,10 @@ import re
|
||||||
import shutil
|
import shutil
|
||||||
import json
|
import json
|
||||||
import yaml
|
import yaml
|
||||||
|
import requests
|
||||||
from urllib import urlopen
|
from urllib import urlopen
|
||||||
from yunohost import YunoHostError, YunoHostLDAP, win_msg, colorize, validate, get_required_args
|
from yunohost import YunoHostError, YunoHostLDAP, win_msg, colorize, validate, get_required_args
|
||||||
|
from yunohost_dyndns import dyndns_subscribe
|
||||||
|
|
||||||
|
|
||||||
def domain_list(filter=None, limit=None, offset=None):
|
def domain_list(filter=None, limit=None, offset=None):
|
||||||
|
@ -66,12 +68,14 @@ def domain_list(filter=None, limit=None, offset=None):
|
||||||
return { 'Domains': result_list }
|
return { 'Domains': result_list }
|
||||||
|
|
||||||
|
|
||||||
def domain_add(domains, main=False):
|
def domain_add(domains, main=False, dyndns=False):
|
||||||
"""
|
"""
|
||||||
Create a custom domain
|
Create a custom domain
|
||||||
|
|
||||||
Keyword argument:
|
Keyword argument:
|
||||||
domains -- Domain name to add
|
domains -- Domain name to add
|
||||||
|
main -- Is the main domain
|
||||||
|
dyndns -- Subscribe to DynDNS
|
||||||
|
|
||||||
"""
|
"""
|
||||||
with YunoHostLDAP() as yldap:
|
with YunoHostLDAP() as yldap:
|
||||||
|
@ -88,6 +92,19 @@ def domain_add(domains, main=False):
|
||||||
try:
|
try:
|
||||||
if domain in domain_list()['Domains']: continue
|
if domain in domain_list()['Domains']: continue
|
||||||
except YunoHostError: pass
|
except YunoHostError: pass
|
||||||
|
|
||||||
|
# DynDNS domain
|
||||||
|
if dyndns and len(domain.split('.')) >= 3:
|
||||||
|
r = requests.get('http://dyndns.yunohost.org/domains')
|
||||||
|
dyndomains = json.loads(r.text)
|
||||||
|
dyndomain = '.'.join(domain.split('.')[1:])
|
||||||
|
if dyndomain in dyndomains:
|
||||||
|
if os.path.exists('/etc/cron.d/yunohost-dyndns'):
|
||||||
|
raise YunoHostError(22, _("You already have a DynDNS domain"))
|
||||||
|
else:
|
||||||
|
dyndns_subscribe(domain=domain)
|
||||||
|
|
||||||
|
# Commands
|
||||||
ssl_dir = '/usr/share/yunohost/yunohost-config/ssl/yunoCA'
|
ssl_dir = '/usr/share/yunohost/yunohost-config/ssl/yunoCA'
|
||||||
ssl_domain_path = '/etc/yunohost/certs/'+ domain
|
ssl_domain_path = '/etc/yunohost/certs/'+ domain
|
||||||
with open(ssl_dir +'/serial', 'r') as f:
|
with open(ssl_dir +'/serial', 'r') as f:
|
||||||
|
|
|
@ -45,6 +45,10 @@ def dyndns_subscribe(subscribe_host="dyndns.yunohost.org", domain=None, key=None
|
||||||
with open('/etc/yunohost/current_host', 'r') as f:
|
with open('/etc/yunohost/current_host', 'r') as f:
|
||||||
domain = f.readline().rstrip()
|
domain = f.readline().rstrip()
|
||||||
|
|
||||||
|
# Verify if domain is available
|
||||||
|
if requests.get('http://'+ subscribe_host +'/test/'+ domain).status_code != 200:
|
||||||
|
raise YunoHostError(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')
|
||||||
|
@ -56,10 +60,6 @@ def dyndns_subscribe(subscribe_host="dyndns.yunohost.org", domain=None, key=None
|
||||||
with open(key_file) as f:
|
with open(key_file) as f:
|
||||||
key = f.readline().strip().split(' ')[-1]
|
key = f.readline().strip().split(' ')[-1]
|
||||||
|
|
||||||
# Verify if domain is available
|
|
||||||
if requests.get('http://'+ subscribe_host +'/test/'+ domain).status_code != 200:
|
|
||||||
raise YunoHostError(17, _("Domain is already taken"))
|
|
||||||
|
|
||||||
# Send subscription
|
# Send subscription
|
||||||
r = requests.post('http://'+ subscribe_host +'/key/'+ base64.b64encode(key), data={ 'subdomain': domain })
|
r = requests.post('http://'+ subscribe_host +'/key/'+ base64.b64encode(key), data={ 'subdomain': domain })
|
||||||
if r.status_code != 201:
|
if r.status_code != 201:
|
||||||
|
|
Loading…
Add table
Reference in a new issue