[enh] Allow local installation

This commit is contained in:
Kload 2014-05-27 14:42:40 +02:00
parent 0db7cb0dd7
commit 42745c0daf
4 changed files with 53 additions and 28 deletions

View file

@ -75,7 +75,10 @@ def domain_add(auth, domains, main=False, dyndns=False):
""" """
attr_dict = { 'objectClass' : ['mailDomain', 'top'] } attr_dict = { 'objectClass' : ['mailDomain', 'top'] }
try:
ip = str(urlopen('http://ip.yunohost.org').read()) ip = str(urlopen('http://ip.yunohost.org').read())
except IOError:
ip = "127.0.0.1"
now = datetime.datetime.now() now = datetime.datetime.now()
timestamp = str(now.year) + str(now.month) + str(now.day) timestamp = str(now.year) + str(now.month) + str(now.day)
result = [] result = []
@ -94,7 +97,11 @@ def domain_add(auth, domains, main=False, dyndns=False):
import requests import requests
from yunohost.dyndns import dyndns_subscribe from yunohost.dyndns import dyndns_subscribe
try:
r = requests.get('http://dyndns.yunohost.org/domains') r = requests.get('http://dyndns.yunohost.org/domains')
except ConnectionError:
pass
else:
dyndomains = json.loads(r.text) dyndomains = json.loads(r.text)
dyndomain = '.'.join(domain.split('.')[1:]) dyndomain = '.'.join(domain.split('.')[1:])
if dyndomain in dyndomains: if dyndomain in dyndomains:

View file

@ -49,8 +49,11 @@ 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
try:
if requests.get('http://%s/test/%s' % (subscribe_host, domain)).status_code != 200: if requests.get('http://%s/test/%s' % (subscribe_host, domain)).status_code != 200:
raise MoulinetteError(errno.EEXIST, m18n.n('dyndns_unavailable')) raise MoulinetteError(errno.EEXIST, m18n.n('dyndns_unavailable'))
except ConnectionError:
raise MoulinetteError(errno.ENETUNREACH, m18n.n('no_internet_connection'))
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:
@ -64,7 +67,10 @@ 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
try:
r = requests.post('http://%s/key/%s' % (subscribe_host, base64.b64encode(key)), data={ 'subdomain': domain }) r = requests.post('http://%s/key/%s' % (subscribe_host, base64.b64encode(key)), data={ 'subdomain': domain })
except ConnectionError:
raise MoulinetteError(errno.ENETUNREACH, m18n.n('no_internet_connection'))
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"
@ -92,7 +98,10 @@ def dyndns_update(dyn_host="dynhost.yunohost.org", domain=None, key=None, ip=Non
domain = f.readline().rstrip() domain = f.readline().rstrip()
if ip is None: if ip is None:
try:
new_ip = requests.get('http://ip.yunohost.org').text new_ip = requests.get('http://ip.yunohost.org').text
except ConnectionError:
raise MoulinetteError(errno.ENETUNREACH, m18n.n('no_internet_connection'))
else: else:
new_ip = ip new_ip = ip

View file

@ -49,6 +49,7 @@
"domain_uninstall_app_first" : "One or more apps are installed on this domain. Please uninstall them before proceed to domain removal.", "domain_uninstall_app_first" : "One or more apps are installed on this domain. Please uninstall them before proceed to domain removal.",
"domain_deletion_failed" : "Unable to delete domain", "domain_deletion_failed" : "Unable to delete domain",
"domain_deleted" : "Domain successfully deleted", "domain_deleted" : "Domain successfully deleted",
"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_unavailable" : "Unavailable DynDNS subdomain", "dyndns_unavailable" : "Unavailable DynDNS subdomain",

View file

@ -163,7 +163,11 @@ def tools_maindomain(auth, old_domain=None, new_domain=None, dyndns=False):
if dyndns: dyndns_subscribe(domain=new_domain) if dyndns: dyndns_subscribe(domain=new_domain)
elif len(new_domain.split('.')) >= 3: elif len(new_domain.split('.')) >= 3:
try:
r = requests.get('http://dyndns.yunohost.org/domains') r = requests.get('http://dyndns.yunohost.org/domains')
except ConnectionError:
pass
else:
dyndomains = json.loads(r.text) dyndomains = json.loads(r.text)
dyndomain = '.'.join(new_domain.split('.')[1:]) dyndomain = '.'.join(new_domain.split('.')[1:])
if dyndomain in dyndomains: if dyndomain in dyndomains:
@ -196,7 +200,11 @@ def tools_postinstall(domain, password, dyndns=False):
raise MoulinetteError(errno.EPERM, m18n.n('yunohost_already_installed')) raise MoulinetteError(errno.EPERM, m18n.n('yunohost_already_installed'))
if len(domain.split('.')) >= 3: if len(domain.split('.')) >= 3:
try:
r = requests.get('http://dyndns.yunohost.org/domains') r = requests.get('http://dyndns.yunohost.org/domains')
except ConnectionError:
pass
else:
dyndomains = json.loads(r.text) dyndomains = json.loads(r.text)
dyndomain = '.'.join(domain.split('.')[1:]) dyndomain = '.'.join(domain.split('.')[1:])
if dyndomain in dyndomains: if dyndomain in dyndomains: