From 8c0d8e9db204ee4feafc85f496e161fa0542a5aa Mon Sep 17 00:00:00 2001 From: mridulnagpal Date: Sat, 31 Dec 2016 05:58:17 +0530 Subject: [PATCH] bind: forwarding works fine now --- actions/bind | 13 ++++++++++--- plinth/modules/bind/__init__.py | 18 ++++++------------ plinth/modules/bind/forms.py | 3 ++- plinth/modules/bind/urls.py | 4 ++-- plinth/modules/bind/views.py | 2 +- 5 files changed, 21 insertions(+), 19 deletions(-) diff --git a/actions/bind b/actions/bind index dc4f847a5..b56bb8f89 100755 --- a/actions/bind +++ b/actions/bind @@ -28,6 +28,11 @@ from plinth import action_utils 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' + def parse_arguments(): """Return parsed command line arguments as dictionary""" parser = argparse.ArgumentParser() @@ -52,11 +57,13 @@ def subcommand_setup(_): contents.insert(0, value1) contents.insert(4, value2) contents.insert(15, value3) + contents.insert(18, value4) f = open(CONFIG_FILE, "w") contents = "".join(contents) f.write(contents) f.close() + action_utils.service_restart('bind9') def subcommand_configure(arguments): """Configure BIND.""" @@ -68,7 +75,7 @@ def subcommand_configure(arguments): def set_forwarding(choice): - if choice == False: + if choice == "false": flag = 0 data = [line.strip() for line in open(CONFIG_FILE, 'r')] if 'forwarders {' in data and not '// forwarders {' in data: @@ -77,7 +84,7 @@ def set_forwarding(choice): if 'forwarders {' in line and not '// forwarders {' in line: flag = 1 if flag == 1: - line = ' //'+line + line = ' // '+line if 'forward only' in line: flag = 0 f.write(line+'\n') @@ -85,7 +92,7 @@ def set_forwarding(choice): - if choice == True: + else: flag = 0 data = [line.strip() for line in open(CONFIG_FILE, 'r')] if '// forwarders {' in data: diff --git a/plinth/modules/bind/__init__.py b/plinth/modules/bind/__init__.py index 9ab4ee83d..0184f0380 100644 --- a/plinth/modules/bind/__init__.py +++ b/plinth/modules/bind/__init__.py @@ -32,7 +32,7 @@ from plinth.views import ServiceView version = 1 -depends = ['apps'] +depends = ['system'] title = _('Domain Name Server \n (BIND)') @@ -55,10 +55,6 @@ description = [ 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' - def init(): """Intialize the BIND module.""" @@ -96,13 +92,11 @@ def setup(helper, old_version=None): def enable(): """Enable the module.""" actions.superuser_run('service', ['enable', managed_services[0]]) - add_shortcut() def disable(): """Disable the module.""" actions.superuser_run('service', ['disable', managed_services[0]]) - frontpage.remove_shortcut('bind') def diagnose(): @@ -113,20 +107,20 @@ def diagnose(): results.append(action_utils.diagnose_port_listening(53, 'udp6')) return results - + def default_config(): """Setp BIND configuration""" actions.superuser_run('bind', ['setup']) - + def get_default(): """Get initial value for forwarding""" - f = open(CONFIG_FILE, "r") - contents = f.readlines() - if '// forwarders {' in contents: + data = [line.strip() for line in open(CONFIG_FILE, 'r')] + if '// forwarders {' in data: conf = { 'set_forwarding': False} else: conf = { 'set_forwarding': True} + return conf diff --git a/plinth/modules/bind/forms.py b/plinth/modules/bind/forms.py index 8e04b1761..cb36a5217 100644 --- a/plinth/modules/bind/forms.py +++ b/plinth/modules/bind/forms.py @@ -29,4 +29,5 @@ class BindForm(ServiceForm): """BIND configuration form""" set_forwarding = forms.BooleanField( label=_('Enable forwarding'), - required=False) + required=False, + help_text=_('Enable forwarding on your BIND server')) diff --git a/plinth/modules/bind/urls.py b/plinth/modules/bind/urls.py index 298ea0c88..adbaf0676 100644 --- a/plinth/modules/bind/urls.py +++ b/plinth/modules/bind/urls.py @@ -21,9 +21,9 @@ URLs for the BIND module from django.conf.urls import url -from plinth.modules.bind import BindServiceView +from plinth.modules.bind.views import BindServiceView urlpatterns = [ - url(r'^apps/bind/$', BindServiceView.as_view(), name='index'), + url(r'^sys/bind/$', BindServiceView.as_view(), name='index'), ] diff --git a/plinth/modules/bind/views.py b/plinth/modules/bind/views.py index 499969515..2de927241 100644 --- a/plinth/modules/bind/views.py +++ b/plinth/modules/bind/views.py @@ -53,7 +53,7 @@ class BindServiceView(ServiceView): # pylint: disable=too-many-ancestors value = 'true' if data['set_forwarding'] else 'false' actions.superuser_run( 'bind', - ['configure', '--set_forwarding', value]) + ['configure', '--set-forwarding', value]) messages.success(self.request, _('Set forwarding configuration updated'))