From 263ce00b3c9b5f8165e1da79d9f18e2ef4270104 Mon Sep 17 00:00:00 2001 From: Miro <200482516+Mirochill@users.noreply.github.com> Date: Mon, 25 May 2026 21:34:37 +0200 Subject: [PATCH] Preserve zone TTL directive Signed-off-by: Miro <200482516+Mirochill@users.noreply.github.com> --- update-zonefile.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/update-zonefile.py b/update-zonefile.py index f2094fb..778d851 100755 --- a/update-zonefile.py +++ b/update-zonefile.py @@ -60,6 +60,17 @@ regex_domain = '^(127|0)\\.0\\.0\\.(0|1)[\\s\\t]+(?P([a-z0-9\\-_]+\\.)+[a-z][a-z0-9_-]*)$' regex_no_comment = '^#.*|^$' regex_no_comment_in_line = '^([^#]+)' +default_zone_ttl = 3600 + + +def add_default_ttl(zonefile): + path = Path(zonefile) + zone_text = path.read_text() + + if zone_text.startswith('$TTL'): + return + + path.write_text('$TTL {}\n{}'.format(default_zone_ttl, zone_text)) def download_list(url): headers = None @@ -170,7 +181,10 @@ def load_zone(zonefile, origin, raw): if not path.exists(): with tmpPath.open('w') as f: - f.write('@ 3600 IN SOA @ admin.{}. 0 86400 7200 2592000 86400\n@ 3600 IN NS LOCALHOST.'.format(origin)) + f.write( + '$TTL {}\n' + '@ 3600 IN SOA @ admin.{}. 0 86400 7200 2592000 86400\n' + '@ 3600 IN NS LOCALHOST.'.format(default_zone_ttl, origin)) save_zone(tmpPath, zonefile, origin, raw) @@ -290,6 +304,7 @@ def append_domain_to_zonefile(file, domain): tmpzonefile = Path(config['cache'], 'tempzone') zone.to_file(str(tmpzonefile)) + add_default_ttl(tmpzonefile) with tmpzonefile.open('a') as f: for d in (sorted(domains)):