diff --git a/actions/bind b/actions/bind index 2023929ad..14244bda1 100755 --- a/actions/bind +++ b/actions/bind @@ -30,7 +30,7 @@ CONFIG_FILE = '/etc/bind/named.conf.options' value1 = 'acl goodclients { \n localnets;\n};\n' value2 = ' recursion yes;\n allow-query { goodclients; };\n\n' -value3 = ' // 8.8.8.8 8.8.4.4;\n' +value3 = ' // 8.8.8.8; 8.8.4.4;\n' value4 = ' //forward first;\n' value5 = ' //dnssec-enable yes;\n' @@ -104,7 +104,7 @@ def set_forwarding(choice): flag = 1 if flag == 1: line = ' // '+line - if 'forward only' in line: + if 'forward first' in line: flag = 0 if "0.0.0.0" not in line: f.write(line+'\n') @@ -153,7 +153,9 @@ def set(DNS): for line in data: if 'forwarders {' in line : f.write(line+'\n') - f.write(DNS+';\n') + for dns in DNS.split(): + f.write(dns+'; ') + f.write('\n') flag = 1 elif '};' and flag == 1: flag = 0 diff --git a/plinth/modules/bind/__init__.py b/plinth/modules/bind/__init__.py index bec5e2321..769697fc4 100644 --- a/plinth/modules/bind/__init__.py +++ b/plinth/modules/bind/__init__.py @@ -19,8 +19,11 @@ Plinth module to configure BIND server """ +import re + from django.urls import reverse_lazy from django.utils.translation import ugettext_lazy as _ +from django.core.validators import validate_ipv46_address from plinth import actions from plinth import action_utils @@ -123,7 +126,7 @@ def get_default(): set_forwarding = False else: set_forwarding = True - if '//dnssec-enable yes;' in data: + if '// dnssec-enable yes;' in data or '//dnssec-enable yes;' in data: enable_dnssec = False else: enable_dnssec = True @@ -132,7 +135,10 @@ def get_default(): for line in data: if flag == 1: - dns_set = line[:len(line)-1] + if '//' in line: + dns_set = '' + else: + dns_set = re.sub('[;]', '', line) flag = 0 if 'forwarders {' in line: flag = 1 @@ -143,3 +149,12 @@ def get_default(): 'dns_set': dns_set } return conf + + +def validate(IP): + for ip in IP.split(): + try : + validate_ipv46_address(ip) + except: + return False + return True diff --git a/plinth/modules/bind/views.py b/plinth/modules/bind/views.py index fc1e3ce04..503293510 100644 --- a/plinth/modules/bind/views.py +++ b/plinth/modules/bind/views.py @@ -26,7 +26,7 @@ from plinth import actions from plinth.views import ServiceView -from . import description, managed_services, get_default +from . import description, managed_services, get_default, validate from .forms import BindForm @@ -65,11 +65,20 @@ class BindServiceView(ServiceView): # pylint: disable=too-many-ancestors messages.success(self.request, _('Enable DNSSEC configuration updated')) - if old_config['dns_set'] != data['dns_set']: - actions.superuser_run( - 'bind', - ['dns', '--set', data['dns_set']]) - messages.success(self.request, - _('DNS server configuration updated')) + + + if old_config['dns_set'] != data['dns_set'] and old_config['dns_set'] is not '': + if validate(data['dns_set']) is True: + actions.superuser_run( + 'bind', + ['dns', '--set', data['dns_set']]) + messages.success(self.request, + _('DNS server configuration updated')) + else: + messages.error(self.request, + _('Enter a valid IPv4 or IPv6 address.')) + elif old_config['dns_set'] is '' and old_config['dns_set'] != data['dns_set']: + messages.error(self.request, + _('Enable forwarding to set forwarding DNS servers')) return super().form_valid(form)