1
0
mirror of https://github.com/mail-in-a-box/mailinabox.git synced 2026-03-12 17:07:23 +01:00

dns: ensure _caldavs._tcp and _carddavs._tcp SRV records point to the remote nextcloud

This commit is contained in:
downtownallday
2022-11-13 12:45:38 -05:00
parent 36bdb836ae
commit e5eb7680ae
2 changed files with 48 additions and 12 deletions

View File

@@ -27,30 +27,59 @@ log = logging.getLogger(__name__)
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() == '':
# not configured for a remote nextcloud
log.debug('hook - not configured for a remote nextcloud')
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" % (
mods_env['NC_PROTO'],
mods_env['NC_HOST'],
mods_env['NC_PORT'],
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
str = hook_data['nginx_conf']