Skip to content

Commit

Permalink
Store www only domains in settings.yaml instead of a file under /etc
Browse files Browse the repository at this point in the history
  • Loading branch information
kiekerjan committed Jan 3, 2025
1 parent 9666b73 commit c4e61fc
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 21 deletions.
8 changes: 5 additions & 3 deletions management/dns_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions management/web_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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']:
Expand Down
29 changes: 14 additions & 15 deletions management/wwwconfig.py
Original file line number Diff line number Diff line change
@@ -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)


Expand Down

0 comments on commit c4e61fc

Please sign in to comment.