bind: Minor fixes and style updates

This commit is contained in:
James Valleroy committed 2017-01-06 18:44:44 -05:00
1 parent d4b0809db0
commit 8f8d0e8901
4 files changed
+81 -97

No files matched your search

+11 -18
View File
@@ -21,16 +21,14 @@ 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.exceptions import ValidationError
from django.core.validators import validate_ipv46_address
from plinth import actions
from plinth import action_utils
from plinth import cfg
from plinth import frontpage
from plinth import service as service_module
from plinth.views import ServiceView
version = 1
@@ -73,12 +71,6 @@ def init():
)
class BindServiceView(ServiceView):
service_id = managed_services[0]
diagnostics_module_name = "bind"
description = description
def setup(helper, old_version=None):
"""Install and configure the module."""
helper.install(managed_packages)
@@ -144,17 +136,18 @@ def get_default():
flag = 1
conf = {
'set_forwarding': set_forwarding,
'enable_dnssec': enable_dnssec,
'forwarders': forwarders
}
'set_forwarding': set_forwarding,
'enable_dnssec': enable_dnssec,
'forwarders': forwarders
}
return conf
def validate(IP):
for ip in IP.split():
try :
validate_ipv46_address(ip)
except:
def validate(ips):
"""Validate that ips is a list of IP addresses, separated by space."""
for ip_addr in ips.split():
try:
validate_ipv46_address(ip_addr)
except ValidationError:
return False
return True
+1 -3
View File
@@ -24,8 +24,6 @@ from django.utils.translation import ugettext_lazy as _
from plinth.forms import ServiceForm
from . import get_default
class BindForm(ServiceForm):
"""BIND configuration form"""
@@ -41,4 +39,4 @@ class BindForm(ServiceForm):
forwarders = forms.CharField(
required=False,
help_text=_('Set new DNS server'))
help_text=_('A list of IP addresses, separated by space'))
+8 -7
View File
@@ -65,9 +65,8 @@ class BindServiceView(ServiceView): # pylint: disable=too-many-ancestors
messages.success(self.request,
_('Enable DNSSEC configuration updated'))
if old_config['forwarders'] != data['forwarders'] and old_config['forwarders'] is not '':
if old_config['forwarders'] != data['forwarders'] \
and old_config['forwarders'] is not '':
if validate(data['forwarders']) is True:
actions.superuser_run(
'bind',
@@ -76,9 +75,11 @@ class BindServiceView(ServiceView): # pylint: disable=too-many-ancestors
_('DNS server configuration updated'))
else:
messages.error(self.request,
_('Enter a valid IPv4 or IPv6 address.'))
elif old_config['forwarders'] is '' and old_config['forwarders'] != data['forwarders']:
messages.error(self.request,
_('Enable forwarding to set forwarding DNS servers'))
_('Enter a valid IPv4 or IPv6 address.'))
elif old_config['forwarders'] is '' \
and old_config['forwarders'] != data['forwarders']:
messages.error(
self.request,
_('Enable forwarding to set forwarding DNS servers'))
return super().form_valid(form)