bind: Add enable DNSSEC

This commit is contained in:
mridulnagpal authored and James Valleroy committed 2017-01-06 18:17:22 -05:00
1 parent 8c0d8e9db2
commit d986d58250
4 files changed
+65 -15

No files matched your search

+37 -9
View File
@@ -31,7 +31,8 @@ CONFIG_FILE = '/etc/bind/named.conf.options'
value1 = 'acl goodclients { \n localhost;\n};\n'
value2 = ' recursion yes;\n allow-query { goodclients; };\n\n'
value3 = ' // 8.8.8.8;\n // 8.8.4.4;\n'
value4 = ' //forward only;\n'
value4 = ' //forward first;\n'
value5 = ' //dnssec-enable yes;\n'
def parse_arguments():
"""Return parsed command line arguments as dictionary"""
@@ -39,10 +40,10 @@ def parse_arguments():
subparsers = parser.add_subparsers(dest='subcommand', help='Sub command')
subparsers.add_parser('setup', help='Setup for BIND')
configure = subparsers.add_parser('configure', help='Configure Minetest')
configure = subparsers.add_parser('configure', help='Configure BIND')
configure.add_argument('--set-forwarding', choices=['true', 'false'],
help='Set forwarding true/false')
configure.add_argument('--dnssec', choices=['true', 'false'],
configure.add_argument('--enable-dnssec', choices=['true', 'false'],
help='Set DNSSEC true/false')
return parser.parse_args()
@@ -58,11 +59,14 @@ def subcommand_setup(_):
contents.insert(4, value2)
contents.insert(15, value3)
contents.insert(18, value4)
contents.insert(20, value5)
f = open(CONFIG_FILE, "w")
contents = "".join(contents)
f.write(contents)
f.close()
set_forwarding(True)
enable_dnssec(True)
action_utils.service_restart('bind9')
def subcommand_configure(arguments):
@@ -71,13 +75,16 @@ def subcommand_configure(arguments):
if arguments.set_forwarding:
set_forwarding(arguments.set_forwarding)
if arguments.enable_dnssec:
enable_dnssec(arguments.enable_dnssec)
action_utils.service_restart('bind9')
def set_forwarding(choice):
data = [line.strip() for line in open(CONFIG_FILE, 'r')]
flag = 0
if choice == "false":
flag = 0
data = [line.strip() for line in open(CONFIG_FILE, 'r')]
if 'forwarders {' in data and not '// forwarders {' in data:
f = open(CONFIG_FILE, 'w')
for line in data:
@@ -87,14 +94,13 @@ def set_forwarding(choice):
line = ' // '+line
if 'forward only' in line:
flag = 0
f.write(line+'\n')
if "0.0.0.0" not in line:
f.write(line+'\n')
f.close()
else:
flag = 0
data = [line.strip() for line in open(CONFIG_FILE, 'r')]
if '// forwarders {' in data:
f = open(CONFIG_FILE, 'w')
for line in data:
@@ -102,8 +108,30 @@ def set_forwarding(choice):
flag = 1
if flag == 1:
line = line[2:]
if 'forward only' in line:
if 'forward first' in line:
flag = 0
if "0.0.0.0" not in line:
f.write(line+'\n')
f.close()
def enable_dnssec(choice):
data = [line.strip() for line in open(CONFIG_FILE, 'r')]
if choice == "false":
if '//dnssec-enable yes;' not in data:
f = open(CONFIG_FILE, 'w')
for line in data:
if 'dnssec-enable yes;' in line:
line = '//' + line
f.write(line+'\n')
f.close()
else:
if '//dnssec-enable yes;' in data:
f = open(CONFIG_FILE, 'w')
for line in data:
if '//dnssec-enable yes;' in line:
line = line[2:]
f.write(line+'\n')
f.close()