-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathbindZoneMaker.py
50 lines (40 loc) · 1.39 KB
/
bindZoneMaker.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/bin/python3
# -*- coding: utf-8 -*-
#
#Copyright (c) 2019 WAHED Shah Mohsin
#This code is under MIT licence, you can find the complete file here: https://github.com/shahwahed/BindZoneMaker/blob/master/LICENSE
import yaml
import json
import sys
import datetime
import getopt
from jinja2 import Environment, FileSystemLoader
def main(argv):
_zonefile = ''
try:
opts, args = getopt.getopt(argv, "z:", ["zonefile="])
except getopt.GetoptError:
print('bindZoneMaker.py -z <zonefile.json>')
sys.exit(2)
for opt, arg in opts:
if opt == '-h':
print('bindZoneMaker.py -z <zonefile.json>')
sys.exit()
elif opt in ("-z", "--zonefile"):
_zonefile = arg
try:
#dnszonejson = json.loads(open('dns_reverse_example.json').read())
dnszonejson = json.loads(open(_zonefile).read())
#create Jinja2 environment object and refer to templates directory
env = Environment(loader=FileSystemLoader('.'))
template = env.get_template('zone.j2')
template.globals['now'] = datetime.datetime.utcnow().replace(tzinfo=datetime.timezone.utc).isoformat()
#print(dnszonejson)
print(template.render(dnszonejson))
except (OSError) as ex:
print(ex)
except:
print("An unexpected error occurred")
raise
if __name__ == "__main__":
main(sys.argv[1:])