diff --git a/actions/bind b/actions/bind index c5f9f1dee..ac4bb01bb 100755 --- a/actions/bind +++ b/actions/bind @@ -27,7 +27,6 @@ from plinth import action_utils CONFIG_FILE = '/etc/bind/named.conf.options' -CONFIG_FILE_2 = '/etc/bind/named_temp.conf.options' def parse_arguments(): """Return parsed command line arguments as dictionary""" @@ -53,41 +52,38 @@ def subcommand_configure(arguments): def set_forwarding(choice): - """Sets forwarding true/false""" + actions.superuser_run('bind', ['setup']) if choice == False: flag = 0 - f = open(CONFIG_FILE, 'r') - w = open(CONFIG_FILE_2, 'w+') - for line in f: - if 'forwarders {' in line and not '// forwarders {' in line: - flag = 1 - if flag == 1: - line = ' //'+line - print(line) - if 'forward only' in line: - flag = 0 - w.write(line) - f.close() - w.close() - os.rename('named.conf_temp.options', 'named.conf.options') + 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: + if 'forwarders {' in line and not '// forwarders {' in line: + flag = 1 + if flag == 1: + line = ' //'+line + if 'forward only' in line: + flag = 0 + f.write(line+'\n') + f.close() + + if choice == True: flag = 0 - f = open(CONFIG_FILE, 'r') - w = open(CONFIG_FILE_2, 'w+') - for line in f: - if '// forwarders {' in line: - print("yesy") - flag = 1 - if flag == 1: - line = line[3:] - print(line) - if 'forward only' in line: - flag = 0 - w.write(line) - f.close() - w.close() - os.rename('named.conf_temp.options', 'named.conf.options') + data = [line.strip() for line in open(CONFIG_FILE, 'r')] + if '// forwarders {' in data: + f = open(CONFIG_FILE, 'w') + for line in data: + if '// forwarders {' in line: + flag = 1 + if flag == 1: + line = line[2:] + if 'forward only' in line: + flag = 0 + f.write(line+'\n') + f.close() def main(): diff --git a/plinth/modules/bind/__init__.py b/plinth/modules/bind/__init__.py index b441a0295..78174ec5a 100644 --- a/plinth/modules/bind/__init__.py +++ b/plinth/modules/bind/__init__.py @@ -116,6 +116,7 @@ def diagnose(): def default_config(): """Initialize config file for BIND""" + actions.superuser_run('bind', ['setup']) f = open(CONFIG_FILE, "r") contents = f.readlines() f.close() diff --git a/plinth/modules/bind/views.py b/plinth/modules/bind/views.py index de9232dc3..80e582866 100644 --- a/plinth/modules/bind/views.py +++ b/plinth/modules/bind/views.py @@ -30,7 +30,7 @@ from . import description, managed_services, get_default from .forms import BindForm -class MinetestServiceView(ServiceView): # pylint: disable=too-many-ancestors +class BindServiceView(ServiceView): # pylint: disable=too-many-ancestors """A specialized view for configuring minetest.""" service_id = managed_services[0] diagnostics_module_name = "bind"