mirror of
https://github.com/Luzifer/dns.git
synced 2024-12-23 03:11:20 +00:00
Update serial for replacement, allow caching of zones
Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
parent
75386be0ba
commit
04c661035d
2 changed files with 17 additions and 6 deletions
|
@ -24,5 +24,7 @@ WORKDIR /src
|
||||||
|
|
||||||
EXPOSE 53/udp 53
|
EXPOSE 53/udp 53
|
||||||
|
|
||||||
|
VOLUME ["/src/zones"]
|
||||||
|
|
||||||
ENTRYPOINT ["/usr/local/bin/coredns"]
|
ENTRYPOINT ["/usr/local/bin/coredns"]
|
||||||
CMD ["--"]
|
CMD ["--"]
|
||||||
|
|
|
@ -6,6 +6,7 @@ import hashlib
|
||||||
import os
|
import os
|
||||||
import os.path
|
import os.path
|
||||||
import sys
|
import sys
|
||||||
|
import time
|
||||||
|
|
||||||
# Third-party imports
|
# Third-party imports
|
||||||
import dns.resolver
|
import dns.resolver
|
||||||
|
@ -13,7 +14,6 @@ import dns.rdatatype
|
||||||
import jinja2
|
import jinja2
|
||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
BLOCKSIZE = 65536
|
|
||||||
DEFAULT_TTL = 3600
|
DEFAULT_TTL = 3600
|
||||||
|
|
||||||
|
|
||||||
|
@ -42,14 +42,21 @@ def hash_file(filename):
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
hasher = hashlib.sha1()
|
hasher = hashlib.sha1()
|
||||||
with open(filename, 'rb') as afile:
|
with open(filename, 'r') as afile:
|
||||||
buf = afile.read(BLOCKSIZE)
|
lines = afile.readlines()
|
||||||
while len(buf) > 0:
|
|
||||||
hasher.update(buf)
|
lines = map(replace_soa_line, lines)
|
||||||
buf = afile.read(BLOCKSIZE)
|
|
||||||
|
hasher.update(''.join(lines).encode('utf-8'))
|
||||||
return hasher.hexdigest()
|
return hasher.hexdigest()
|
||||||
|
|
||||||
|
|
||||||
|
def replace_soa_line(line):
|
||||||
|
if 'SOA' in line:
|
||||||
|
return '; SOA line replaced'
|
||||||
|
return line
|
||||||
|
|
||||||
|
|
||||||
def resolve_alias(entry):
|
def resolve_alias(entry):
|
||||||
result = []
|
result = []
|
||||||
|
|
||||||
|
@ -96,6 +103,8 @@ def sanitize(entry):
|
||||||
|
|
||||||
|
|
||||||
def write_zone(zone, ttl, soa, nameserver, mailserver, entries):
|
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())
|
tpl = jinja2.Template(open("zone_template.j2").read())
|
||||||
zone_content = tpl.render({
|
zone_content = tpl.render({
|
||||||
"zone": zone,
|
"zone": zone,
|
||||||
|
|
Loading…
Reference in a new issue