mirror of
https://github.com/mail-in-a-box/mailinabox.git
synced 2025-04-04 00:17:06 +00:00
dns: ensure _caldavs._tcp and _carddavs._tcp SRV records point to the remote nextcloud
This commit is contained in:
parent
36bdb836ae
commit
e5eb7680ae
@ -17,6 +17,7 @@ import sys, os, os.path, urllib.parse, datetime, re, hashlib, base64
|
|||||||
import ipaddress
|
import ipaddress
|
||||||
import rtyaml
|
import rtyaml
|
||||||
import dns.resolver
|
import dns.resolver
|
||||||
|
import hooks
|
||||||
|
|
||||||
from utils import shell, load_env_vars_from_file, safe_domain_name, sort_domains
|
from utils import shell, load_env_vars_from_file, safe_domain_name, sort_domains
|
||||||
from ssl_certificates import get_ssl_certificates, check_certificate
|
from ssl_certificates import get_ssl_certificates, check_certificate
|
||||||
@ -390,6 +391,12 @@ def build_zone(domain, domain_properties, additional_records, env, is_zone=True)
|
|||||||
# Sort the records. The None records *must* go first in the nsd zone file. Otherwise it doesn't matter.
|
# Sort the records. The None records *must* go first in the nsd zone file. Otherwise it doesn't matter.
|
||||||
records.sort(key = lambda rec : list(reversed(rec[0].split(".")) if rec[0] is not None else ""))
|
records.sort(key = lambda rec : list(reversed(rec[0].split(".")) if rec[0] is not None else ""))
|
||||||
|
|
||||||
|
# execute hooks
|
||||||
|
hooks.exec_hooks('dns_update', {
|
||||||
|
'op':'build_zone_end',
|
||||||
|
'records':records
|
||||||
|
})
|
||||||
|
|
||||||
return records
|
return records
|
||||||
|
|
||||||
def is_domain_cert_signed_and_valid(domain, env):
|
def is_domain_cert_signed_and_valid(domain, env):
|
||||||
|
@ -27,30 +27,59 @@ log = logging.getLogger(__name__)
|
|||||||
|
|
||||||
|
|
||||||
def do_hook(hook_name, hook_data, mods_env):
|
def do_hook(hook_name, hook_data, mods_env):
|
||||||
if hook_name != 'web_update':
|
|
||||||
# we only care about hooking web_update
|
|
||||||
log.debug('hook - ignoring hook %s', hook_name)
|
|
||||||
return False
|
|
||||||
|
|
||||||
if hook_data['op'] != 'pre-save':
|
|
||||||
log.debug('hook - ignoring hook op %s:%s', hook_name, hook_data['op'])
|
|
||||||
return False
|
|
||||||
|
|
||||||
if 'NC_HOST' not in mods_env or mods_env['NC_HOST'].strip() == '':
|
if 'NC_HOST' not in mods_env or mods_env['NC_HOST'].strip() == '':
|
||||||
# not configured for a remote nextcloud
|
# not configured for a remote nextcloud
|
||||||
log.debug('hook - not configured for a remote nextcloud')
|
log.debug('hook - not configured for a remote nextcloud')
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# get the remote nextcloud url and ensure no tailing /
|
if hook_name == 'web_update':
|
||||||
|
return do_hook_web_update(hook_name, hook_data, mods_env)
|
||||||
|
|
||||||
|
elif hook_name == 'dns_update':
|
||||||
|
return do_hook_dns_update(hook_name, hook_data, mods_env)
|
||||||
|
|
||||||
|
else:
|
||||||
|
log.debug('hook - ignoring hook %s', hook_name)
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def do_hook_dns_update(hook_name, hook_data, mods_env):
|
||||||
|
if hook_data['op'] != 'build_zone_end':
|
||||||
|
log.debug('hook - ignoring hook op %s:%s', hook_name, hook_data['op'])
|
||||||
|
return False
|
||||||
|
changed = False
|
||||||
|
records = hook_data['records']
|
||||||
|
for idx in range(len(records)):
|
||||||
|
# record format (name, record-type, record-value, "help-text" or False)
|
||||||
|
record = records[idx]
|
||||||
|
rname = record[0]
|
||||||
|
rtype = record[1]
|
||||||
|
if rtype=='SRV' and rname in ('_caldavs._tcp', '_carddavs._tcp'):
|
||||||
|
newrec = list(record)
|
||||||
|
newrec[2] = '10 10 443 %s.' % mods_env['NC_HOST']
|
||||||
|
records[idx] = tuple(newrec)
|
||||||
|
changed = True
|
||||||
|
return changed
|
||||||
|
|
||||||
|
|
||||||
|
def get_nc_url(mods_env):
|
||||||
|
# return the remote nextcloud url - ensures no tailing /
|
||||||
nc_url = "%s://%s:%s%s" % (
|
nc_url = "%s://%s:%s%s" % (
|
||||||
mods_env['NC_PROTO'],
|
mods_env['NC_PROTO'],
|
||||||
mods_env['NC_HOST'],
|
mods_env['NC_HOST'],
|
||||||
mods_env['NC_PORT'],
|
mods_env['NC_PORT'],
|
||||||
mods_env['NC_PREFIX'][0:-1] if mods_env['NC_PREFIX'].endswith('/') else mods_env['NC_PREFIX']
|
mods_env['NC_PREFIX'][0:-1] if mods_env['NC_PREFIX'].endswith('/') else mods_env['NC_PREFIX']
|
||||||
)
|
)
|
||||||
|
return nc_url
|
||||||
|
|
||||||
|
|
||||||
|
def do_hook_web_update(hook_name, hook_data, mods_env):
|
||||||
|
if hook_data['op'] != 'pre-save':
|
||||||
|
log.debug('hook - ignoring hook op %s:%s', hook_name, hook_data['op'])
|
||||||
|
return False
|
||||||
|
|
||||||
|
nc_url = get_nc_url(mods_env)
|
||||||
|
|
||||||
# find start and end of Nextcloud configuration section
|
# find start and end of Nextcloud configuration section
|
||||||
|
|
||||||
str = hook_data['nginx_conf']
|
str = hook_data['nginx_conf']
|
||||||
|
Loading…
Reference in New Issue
Block a user