From 04c661035db7ecb3601e399069f1c934cf3dabdc Mon Sep 17 00:00:00 2001 From: Knut Ahlers Date: Mon, 5 Feb 2018 08:37:55 +0100 Subject: [PATCH] Update serial for replacement, allow caching of zones Signed-off-by: Knut Ahlers --- Dockerfile | 2 ++ generateZonefiles.py | 21 +++++++++++++++------ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index 8bd9859..62974cf 100644 --- a/Dockerfile +++ b/Dockerfile @@ -24,5 +24,7 @@ WORKDIR /src EXPOSE 53/udp 53 +VOLUME ["/src/zones"] + ENTRYPOINT ["/usr/local/bin/coredns"] CMD ["--"] diff --git a/generateZonefiles.py b/generateZonefiles.py index 1cc1f03..5918096 100644 --- a/generateZonefiles.py +++ b/generateZonefiles.py @@ -6,6 +6,7 @@ import hashlib import os import os.path import sys +import time # Third-party imports import dns.resolver @@ -13,7 +14,6 @@ import dns.rdatatype import jinja2 import yaml -BLOCKSIZE = 65536 DEFAULT_TTL = 3600 @@ -42,14 +42,21 @@ def hash_file(filename): return "" hasher = hashlib.sha1() - with open(filename, 'rb') as afile: - buf = afile.read(BLOCKSIZE) - while len(buf) > 0: - hasher.update(buf) - buf = afile.read(BLOCKSIZE) + with open(filename, 'r') as afile: + lines = afile.readlines() + + lines = map(replace_soa_line, lines) + + hasher.update(''.join(lines).encode('utf-8')) return hasher.hexdigest() +def replace_soa_line(line): + if 'SOA' in line: + return '; SOA line replaced' + return line + + def resolve_alias(entry): result = [] @@ -96,6 +103,8 @@ def sanitize(entry): def write_zone(zone, ttl, soa, nameserver, mailserver, entries): + soa['serial'] = int(time.time()) - 946681200 # 2000-01-01 + tpl = jinja2.Template(open("zone_template.j2").read()) zone_content = tpl.render({ "zone": zone,