From c4e61fc5a77f33bc1c323e513b78a5e1cc52befd Mon Sep 17 00:00:00 2001 From: KiekerJan Date: Fri, 3 Jan 2025 21:24:18 +0100 Subject: [PATCH] Store www only domains in settings.yaml instead of a file under /etc --- management/dns_update.py | 8 +++++--- management/web_update.py | 6 +++--- management/wwwconfig.py | 29 ++++++++++++++--------------- 3 files changed, 22 insertions(+), 21 deletions(-) diff --git a/management/dns_update.py b/management/dns_update.py index 312b68377..517f42d75 100755 --- a/management/dns_update.py +++ b/management/dns_update.py @@ -31,9 +31,11 @@ def get_dns_domains(env): domains = set() domains |= set(get_mail_domains(env)) domains |= set(get_web_domains(env, include_www_redirects=False)) - # www_domains are hosted here, but DNS is pointed to our box from somewhere else. - # DNS is thus not hosted by us for these domains. - domains -= set(get_www_domains(set())) + # www_domains are hosted here, but DNS might not be. + domains -= set(get_www_domains(set(), env)) + # add other domains for which DNS is hosted here explicitly. + #domains |= set(get_dns_domains)) + domains.add(env['PRIMARY_HOSTNAME']) return domains diff --git a/management/web_update.py b/management/web_update.py index e524db5a3..871004487 100644 --- a/management/web_update.py +++ b/management/web_update.py @@ -20,14 +20,14 @@ def get_web_domains(env, include_www_redirects=True, include_auto=True, exclude_ domains |= get_mail_domains(env) # Add domains for which we only serve www - domains |= get_www_domains(domains) + domains |= get_www_domains(domains, env) if include_www_redirects and include_auto: # Add 'www.' subdomains that we want to provide default redirects # to the main domain for. We'll add 'www.' to any DNS zones, i.e. # the topmost of each domain we serve. domains |= {'www.' + zone for zone, zonefile in get_dns_zones(env)} - domains |= {'www.' + wwwdomain for wwwdomain in get_www_domains(get_mail_domains(env))} + domains |= {'www.' + wwwdomain for wwwdomain in get_www_domains(get_mail_domains(env), env)} if include_auto: # Add Autoconfiguration domains for domains that there are user accounts at: @@ -102,7 +102,7 @@ def read_conf(conf_fn): # Add configuration all other web domains. has_root_proxy_or_redirect = get_web_domains_with_root_overrides(env) web_domains_not_redirect = get_web_domains(env, include_www_redirects=False) - web_only_domains = get_www_domains(get_mail_domains(env)) + web_only_domains = get_www_domains(get_mail_domains(env), env) for domain in get_web_domains(env): if domain == env['PRIMARY_HOSTNAME']: diff --git a/management/wwwconfig.py b/management/wwwconfig.py index 794a4c0e1..1999b93b9 100644 --- a/management/wwwconfig.py +++ b/management/wwwconfig.py @@ -1,24 +1,23 @@ -import os.path, idna, sys, collections +import os.path, idna, sys, collections, logging +from utils import load_settings -def get_www_domains(domains_to_skip): +def get_www_domains(domains_to_skip, env): # Returns the domain names (IDNA-encoded) of all of the domains that are configured to serve www # on the system. domains = [] + + config = load_settings(env) + www_entries = config.get("hostother", {}).get("www", {}) - try: - # read a line from text file - with open("/etc/miabwwwdomains.conf") as file_in: - for line in file_in: - # Valid domain check future extention: use validators module - # Only one dot allowed - if line.count('.') == 1: - www_domain = get_domain(line, as_unicode=False) - if www_domain not in domains_to_skip: - domains.append(www_domain) + try: + if isinstance(www_entries, list) or isinstance(www_entries, dict): + for val in www_entries: + www_domain = get_domain(val, as_unicode=False) + if www_domain not in domains_to_skip: + domains.append(www_domain) except: - # ignore failures - pass - + logging.debug("Error reading hosted www from settings") + return set(domains)