mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
[enh] Add and remove only one domain and catch creation error
This commit is contained in:
parent
81215f7f12
commit
b932844459
4 changed files with 78 additions and 89 deletions
|
@ -243,9 +243,8 @@ domain:
|
||||||
configuration:
|
configuration:
|
||||||
authenticate: all
|
authenticate: all
|
||||||
arguments:
|
arguments:
|
||||||
domains:
|
domain:
|
||||||
help: Domain name to add
|
help: Domain name to add
|
||||||
nargs: '+'
|
|
||||||
extra:
|
extra:
|
||||||
pattern:
|
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])*)$'
|
- '^([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])*)$'
|
||||||
|
@ -266,9 +265,8 @@ domain:
|
||||||
configuration:
|
configuration:
|
||||||
authenticate: all
|
authenticate: all
|
||||||
arguments:
|
arguments:
|
||||||
domains:
|
domain:
|
||||||
help: Domain(s) to delete
|
help: Domain to delete
|
||||||
nargs: "+"
|
|
||||||
extra:
|
extra:
|
||||||
pattern:
|
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])*)$'
|
- '^([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])*)$'
|
||||||
|
|
63
domain.py
63
domain.py
|
@ -64,12 +64,12 @@ def domain_list(auth, filter=None, limit=None, offset=None):
|
||||||
return { 'domains': result_list }
|
return { 'domains': result_list }
|
||||||
|
|
||||||
|
|
||||||
def domain_add(auth, domains, main=False, dyndns=False):
|
def domain_add(auth, domain, main=False, dyndns=False):
|
||||||
"""
|
"""
|
||||||
Create a custom domain
|
Create a custom domain
|
||||||
|
|
||||||
Keyword argument:
|
Keyword argument:
|
||||||
domains -- Domain name to add
|
domain -- Domain name to add
|
||||||
main -- Is the main domain
|
main -- Is the main domain
|
||||||
dyndns -- Subscribe to DynDNS
|
dyndns -- Subscribe to DynDNS
|
||||||
|
|
||||||
|
@ -81,14 +81,9 @@ def domain_add(auth, domains, main=False, dyndns=False):
|
||||||
ip = "127.0.0.1"
|
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 = []
|
|
||||||
|
|
||||||
if not isinstance(domains, list):
|
|
||||||
domains = [ domains ]
|
|
||||||
|
|
||||||
for domain in domains:
|
|
||||||
if domain in domain_list(auth)['domains']:
|
if domain in domain_list(auth)['domains']:
|
||||||
continue
|
raise MoulinetteError(errno.EEXIST, m18n.n('domain_exists'))
|
||||||
|
|
||||||
# DynDNS domain
|
# DynDNS domain
|
||||||
if dyndns:
|
if dyndns:
|
||||||
|
@ -113,6 +108,7 @@ def domain_add(auth, domains, main=False, dyndns=False):
|
||||||
raise MoulinetteError(errno.EINVAL,
|
raise MoulinetteError(errno.EINVAL,
|
||||||
m18n.n('domain_dyndns_root_unknown'))
|
m18n.n('domain_dyndns_root_unknown'))
|
||||||
|
|
||||||
|
try:
|
||||||
# Commands
|
# 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/%s' % domain
|
ssl_domain_path = '/etc/yunohost/certs/%s' % domain
|
||||||
|
@ -236,35 +232,28 @@ def domain_add(auth, domains, main=False, dyndns=False):
|
||||||
os.system('sed -i s/yunohost.org/%s/g /etc/nginx/conf.d/%s.conf' % (domain, domain))
|
os.system('sed -i s/yunohost.org/%s/g /etc/nginx/conf.d/%s.conf' % (domain, domain))
|
||||||
os.system('service nginx reload')
|
os.system('service nginx reload')
|
||||||
|
|
||||||
if auth.add('virtualdomain=%s,ou=domains' % domain, attr_dict):
|
if not auth.add('virtualdomain=%s,ou=domains' % domain, attr_dict):
|
||||||
result.append(domain)
|
|
||||||
continue
|
|
||||||
else:
|
|
||||||
raise MoulinetteError(errno.EIO, m18n.n('domain_creation_failed'))
|
raise MoulinetteError(errno.EIO, m18n.n('domain_creation_failed'))
|
||||||
|
|
||||||
|
|
||||||
os.system('yunohost app ssowatconf > /dev/null 2>&1')
|
os.system('yunohost app ssowatconf > /dev/null 2>&1')
|
||||||
|
except:
|
||||||
|
# Force domain removal
|
||||||
|
domain_remove(auth, domain, True)
|
||||||
|
raise
|
||||||
|
|
||||||
msignals.display(m18n.n('domain_created'), 'success')
|
msignals.display(m18n.n('domain_created'), 'success')
|
||||||
return { 'domains': result }
|
|
||||||
|
|
||||||
|
|
||||||
def domain_remove(auth, domains):
|
def domain_remove(auth, domain, force=False):
|
||||||
"""
|
"""
|
||||||
Delete domains
|
Delete domains
|
||||||
|
|
||||||
Keyword argument:
|
Keyword argument:
|
||||||
domains -- Domain(s) to delete
|
domain -- Domain to delete
|
||||||
|
force -- Force the domain removal
|
||||||
|
|
||||||
"""
|
"""
|
||||||
result = []
|
if not force and domain not in domain_list(auth)['domains']:
|
||||||
domains_list = domain_list(auth)['domains']
|
|
||||||
|
|
||||||
if not isinstance(domains, list):
|
|
||||||
domains = [ domains ]
|
|
||||||
|
|
||||||
for domain in domains:
|
|
||||||
if domain not in domains_list:
|
|
||||||
raise MoulinetteError(errno.EINVAL, m18n.n('domain_unknown'))
|
raise MoulinetteError(errno.EINVAL, m18n.n('domain_unknown'))
|
||||||
|
|
||||||
# Check if apps are installed on the domain
|
# Check if apps are installed on the domain
|
||||||
|
@ -279,16 +268,19 @@ def domain_remove(auth, domains):
|
||||||
raise MoulinetteError(errno.EPERM,
|
raise MoulinetteError(errno.EPERM,
|
||||||
m18n.n('domain_uninstall_app_first'))
|
m18n.n('domain_uninstall_app_first'))
|
||||||
|
|
||||||
if auth.remove('virtualdomain=' + domain + ',ou=domains'):
|
if auth.remove('virtualdomain=' + domain + ',ou=domains') or force:
|
||||||
try:
|
command_list = [
|
||||||
shutil.rmtree('/etc/yunohost/certs/%s' % domain)
|
'rm -rf /etc/yunohost/certs/%s' % domain,
|
||||||
os.remove('/var/lib/bind/%s.zone' % domain)
|
'rm -f /var/lib/bind/%s.zone' % domain,
|
||||||
shutil.rmtree('/var/lib/metronome/%s' % domain.replace('.', '%2e'))
|
'rm -rf /var/lib/metronome/%s' % domain.replace('.', '%2e'),
|
||||||
os.remove('/etc/metronome/conf.d/%s.cfg.lua' % domain)
|
'rm -f /etc/metronome/conf.d/%s.cfg.lua' % domain,
|
||||||
shutil.rmtree('/etc/nginx/conf.d/%s.d' % domain)
|
'rm -rf /etc/nginx/conf.d/%s.d' % domain,
|
||||||
os.remove('/etc/nginx/conf.d/%s.conf' % domain)
|
'rm -f /etc/nginx/conf.d/%s.conf' % domain,
|
||||||
except:
|
]
|
||||||
pass
|
for command in command_list:
|
||||||
|
if os.system(command) != 0:
|
||||||
|
msignals.display(m18n.n('path_removal_failed', command[7:]),
|
||||||
|
'warning')
|
||||||
with open('/etc/bind/named.conf.local', 'r') as conf:
|
with open('/etc/bind/named.conf.local', 'r') as conf:
|
||||||
conf_lines = conf.readlines()
|
conf_lines = conf.readlines()
|
||||||
with open('/etc/bind/named.conf.local', 'w') as conf:
|
with open('/etc/bind/named.conf.local', 'w') as conf:
|
||||||
|
@ -301,8 +293,6 @@ def domain_remove(auth, domains):
|
||||||
in_block = False
|
in_block = False
|
||||||
else:
|
else:
|
||||||
conf.write(line)
|
conf.write(line)
|
||||||
result.append(domain)
|
|
||||||
continue
|
|
||||||
else:
|
else:
|
||||||
raise MoulinetteError(errno.EIO, m18n.n('domain_deletion_failed'))
|
raise MoulinetteError(errno.EIO, m18n.n('domain_deletion_failed'))
|
||||||
|
|
||||||
|
@ -312,4 +302,3 @@ def domain_remove(auth, domains):
|
||||||
os.system('service metronome restart')
|
os.system('service metronome restart')
|
||||||
|
|
||||||
msignals.display(m18n.n('domain_deleted'), 'success')
|
msignals.display(m18n.n('domain_deleted'), 'success')
|
||||||
return { 'domains': result }
|
|
||||||
|
|
|
@ -38,6 +38,7 @@
|
||||||
"executing_script": "Executing script...",
|
"executing_script": "Executing script...",
|
||||||
"done" : "Done.",
|
"done" : "Done.",
|
||||||
|
|
||||||
|
"path_removal_failed" : "Unable to remove path {:s}",
|
||||||
"domain_unknown" : "Unknown domain",
|
"domain_unknown" : "Unknown domain",
|
||||||
"domain_dyndns_invalid" : "Invalid domain to use with DynDNS",
|
"domain_dyndns_invalid" : "Invalid domain to use with DynDNS",
|
||||||
"domain_dyndns_already_subscribed" : "You already have subscribed to a DynDNS domain",
|
"domain_dyndns_already_subscribed" : "You already have subscribed to a DynDNS domain",
|
||||||
|
|
|
@ -38,6 +38,7 @@
|
||||||
"executing_script": "Exécution du script...",
|
"executing_script": "Exécution du script...",
|
||||||
"done" : "Terminé.",
|
"done" : "Terminé.",
|
||||||
|
|
||||||
|
"path_removal_failed" : "Impossible de supprimer le chemin {:s}",
|
||||||
"domain_unknown" : "Domaine inconnu",
|
"domain_unknown" : "Domaine inconnu",
|
||||||
"domain_dyndns_invalid" : "Domaine incorrect pour un usage avec DynDNS",
|
"domain_dyndns_invalid" : "Domaine incorrect pour un usage avec DynDNS",
|
||||||
"domain_dyndns_already_subscribed" : "Vous avez déjà souscris à un domaine DynDNS",
|
"domain_dyndns_already_subscribed" : "Vous avez déjà souscris à un domaine DynDNS",
|
||||||
|
|
Loading…
Add table
Reference in a new issue