bind: Added DNS servers setting

This commit is contained in:
mridulnagpal authored and James Valleroy committed 2017-01-06 18:17:25 -05:00
1 parent d986d58250
commit 0312c41415
4 files changed
+56 -6

No files matched your search

+30 -4
View File
@@ -28,9 +28,9 @@ from plinth import action_utils
CONFIG_FILE = '/etc/bind/named.conf.options'
value1 = 'acl goodclients { \n localhost;\n};\n'
value1 = 'acl goodclients { \n localnets;\n};\n'
value2 = ' recursion yes;\n allow-query { goodclients; };\n\n'
value3 = ' // 8.8.8.8;\n // 8.8.4.4;\n'
value3 = ' // 8.8.8.8 8.8.4.4;\n'
value4 = ' //forward first;\n'
value5 = ' //dnssec-enable yes;\n'
@@ -46,6 +46,9 @@ def parse_arguments():
configure.add_argument('--enable-dnssec', choices=['true', 'false'],
help='Set DNSSEC true/false')
dns = subparsers.add_parser('dns', help='Set up DNS server')
dns.add_argument('--set', help='Set DNS server')
return parser.parse_args()
@@ -69,6 +72,15 @@ def subcommand_setup(_):
enable_dnssec(True)
action_utils.service_restart('bind9')
def subcommand_dns(arguments):
"""Setting DNS servers"""
if arguments.set:
set(arguments.set)
action_utils.service_restart('bind9')
def subcommand_configure(arguments):
"""Configure BIND."""
@@ -98,8 +110,6 @@ def set_forwarding(choice):
f.write(line+'\n')
f.close()
else:
if '// forwarders {' in data:
f = open(CONFIG_FILE, 'w')
@@ -136,6 +146,22 @@ def enable_dnssec(choice):
f.close()
def set(DNS):
flag = 0
data = [line.strip() for line in open(CONFIG_FILE, 'r')]
f = open(CONFIG_FILE, 'w')
for line in data:
if 'forwarders {' in line :
f.write(line+'\n')
f.write(DNS+';\n')
flag = 1
elif '};' and flag == 1:
flag = 0
elif flag == 0:
f.write(line+'\n')
f.close()
def main():
"""Parse arguments and perform all duties"""
arguments = parse_arguments()