mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
[fix] Update DNS zone files on main domain change
This commit is contained in:
parent
4d2c6bfb64
commit
9ec3e29edb
5 changed files with 35 additions and 15 deletions
|
@ -249,10 +249,6 @@ domain:
|
||||||
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])*)$'
|
||||||
- pattern_domain
|
- pattern_domain
|
||||||
-m:
|
|
||||||
full: --main
|
|
||||||
help: Is the main domain
|
|
||||||
action: store_true
|
|
||||||
-d:
|
-d:
|
||||||
full: --dyndns
|
full: --dyndns
|
||||||
help: Subscribe to the DynDNS service
|
help: Subscribe to the DynDNS service
|
||||||
|
|
|
@ -64,13 +64,12 @@ def domain_list(auth, filter=None, limit=None, offset=None):
|
||||||
return { 'domains': result_list }
|
return { 'domains': result_list }
|
||||||
|
|
||||||
|
|
||||||
def domain_add(auth, domain, main=False, dyndns=False):
|
def domain_add(auth, domain, dyndns=False):
|
||||||
"""
|
"""
|
||||||
Create a custom domain
|
Create a custom domain
|
||||||
|
|
||||||
Keyword argument:
|
Keyword argument:
|
||||||
domain -- Domain name to add
|
domain -- Domain name to add
|
||||||
main -- Is the main domain
|
|
||||||
dyndns -- Subscribe to DynDNS
|
dyndns -- Subscribe to DynDNS
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
@ -163,12 +162,6 @@ def domain_add(auth, domain, main=False, dyndns=False):
|
||||||
'_xmpp-server._tcp.%s. IN SRV 0 5 5269 %s.' % (domain, domain),
|
'_xmpp-server._tcp.%s. IN SRV 0 5 5269 %s.' % (domain, domain),
|
||||||
'_jabber._tcp.%s. IN SRV 0 5 5269 %s.' % (domain, domain),
|
'_jabber._tcp.%s. IN SRV 0 5 5269 %s.' % (domain, domain),
|
||||||
]
|
]
|
||||||
if main:
|
|
||||||
zone_lines.extend([
|
|
||||||
'pubsub.%s. IN A %s' % (domain, ip),
|
|
||||||
'muc.%s. IN A %s' % (domain, ip),
|
|
||||||
'vjud.%s. IN A %s' % (domain, ip)
|
|
||||||
])
|
|
||||||
with open('/var/lib/bind/%s.zone' % domain, 'w') as zone:
|
with open('/var/lib/bind/%s.zone' % domain, 'w') as zone:
|
||||||
for line in zone_lines:
|
for line in zone_lines:
|
||||||
zone.write(line + '\n')
|
zone.write(line + '\n')
|
||||||
|
|
|
@ -46,7 +46,8 @@
|
||||||
"domain_dyndns_root_unknown" : "Unknown DynDNS root domain",
|
"domain_dyndns_root_unknown" : "Unknown DynDNS root domain",
|
||||||
"domain_cert_gen_failed" : "Unable to generate certificate",
|
"domain_cert_gen_failed" : "Unable to generate certificate",
|
||||||
"domain_exists" : "Domain already exists",
|
"domain_exists" : "Domain already exists",
|
||||||
"domain_zone_exists" : "Zone file already exists",
|
"domain_zone_exists" : "DNS zone file already exists",
|
||||||
|
"domain_zone_not_found" : "DNS zone file not found for domain {:s}",
|
||||||
"domain_creation_failed" : "Unable to create domain",
|
"domain_creation_failed" : "Unable to create domain",
|
||||||
"domain_created" : "Domain successfully created",
|
"domain_created" : "Domain successfully created",
|
||||||
"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.",
|
||||||
|
|
|
@ -46,7 +46,8 @@
|
||||||
"domain_dyndns_root_unknown" : "Domaine DynDNS principal inconnu",
|
"domain_dyndns_root_unknown" : "Domaine DynDNS principal inconnu",
|
||||||
"domain_cert_gen_failed" : "Impossible de générer le certificat",
|
"domain_cert_gen_failed" : "Impossible de générer le certificat",
|
||||||
"domain_exists" : "Le domaine existe déjà",
|
"domain_exists" : "Le domaine existe déjà",
|
||||||
"domain_zone_exists" : "Le fichier de zone existe déjà",
|
"domain_zone_exists" : "Le fichier de zone DNS existe déjà",
|
||||||
|
"domain_zone_not_found" : "Fichier de zone DNS introuvable pour le domaine {:s}",
|
||||||
"domain_creation_failed" : "Impossible de créer le domaine",
|
"domain_creation_failed" : "Impossible de créer le domaine",
|
||||||
"domain_created" : "Domaine créé avec succès",
|
"domain_created" : "Domaine créé avec succès",
|
||||||
"domain_uninstall_app_first" : "Une ou plusieurs applications sont installées sur ce domaine. Veuillez d'abord les désinstaller avant de supprimer ce domaine.",
|
"domain_uninstall_app_first" : "Une ou plusieurs applications sont installées sur ce domaine. Veuillez d'abord les désinstaller avant de supprimer ce domaine.",
|
||||||
|
|
31
tools.py
31
tools.py
|
@ -120,7 +120,7 @@ def tools_maindomain(auth, old_domain=None, new_domain=None, dyndns=False):
|
||||||
if not new_domain:
|
if not new_domain:
|
||||||
raise MoulinetteError(errno.EINVAL, m18n.n('new_domain_required'))
|
raise MoulinetteError(errno.EINVAL, m18n.n('new_domain_required'))
|
||||||
if new_domain not in domain_list(auth)['domains']:
|
if new_domain not in domain_list(auth)['domains']:
|
||||||
domain_add(auth, new_domain, main=True)
|
domain_add(auth, new_domain)
|
||||||
|
|
||||||
config_files = [
|
config_files = [
|
||||||
'/etc/postfix/main.cf',
|
'/etc/postfix/main.cf',
|
||||||
|
@ -145,6 +145,35 @@ def tools_maindomain(auth, old_domain=None, new_domain=None, dyndns=False):
|
||||||
for line in lines:
|
for line in lines:
|
||||||
sources.write(re.sub(r''+ old_domain +'', new_domain, line))
|
sources.write(re.sub(r''+ old_domain +'', new_domain, line))
|
||||||
|
|
||||||
|
## Update DNS zone file for old and new domains
|
||||||
|
main_subdomains = ['pubsub', 'muc', 'vjud']
|
||||||
|
try:
|
||||||
|
with open('/var/lib/bind/%s.zone' % old_domain, 'r') as f:
|
||||||
|
old_zone = f.read()
|
||||||
|
except IOError:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
# Remove unneeded subdomains entries
|
||||||
|
for sub in main_subdomains:
|
||||||
|
old_zone = re.sub(
|
||||||
|
r'^({sub}.{domain}.|{sub})[\ \t]+(IN).*$[\n]?'.format(
|
||||||
|
sub=sub, domain=old_domain),
|
||||||
|
'', old_zone, 1, re.MULTILINE)
|
||||||
|
with open('/var/lib/bind/%s.zone' % old_domain, 'w') as f:
|
||||||
|
f.write(old_zone)
|
||||||
|
try:
|
||||||
|
with open('/var/lib/bind/%s.zone' % new_domain, 'r') as f:
|
||||||
|
new_zone = f.read()
|
||||||
|
except IOError:
|
||||||
|
msignals.display(m18n.n('domain_zone_not_found', new_domain), 'warning')
|
||||||
|
else:
|
||||||
|
# Add main subdomains entries
|
||||||
|
for sub in main_subdomains:
|
||||||
|
new_zone += '{sub} IN CNAME {domain}.\n'.format(
|
||||||
|
sub=sub, domain=new_domain)
|
||||||
|
with open('/var/lib/bind/%s.zone' % new_domain, 'w') as f:
|
||||||
|
f.write(new_zone)
|
||||||
|
|
||||||
os.system('rm /etc/ssl/private/yunohost_key.pem')
|
os.system('rm /etc/ssl/private/yunohost_key.pem')
|
||||||
os.system('rm /etc/ssl/certs/yunohost_crt.pem')
|
os.system('rm /etc/ssl/certs/yunohost_crt.pem')
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue