Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion update-zonefile.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,17 @@
regex_domain = '^(127|0)\\.0\\.0\\.(0|1)[\\s\\t]+(?P<domain>([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
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)):
Expand Down