mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-01-21 07:55:00 +00:00
bind: Use django's form validation
This commit is contained in:
parent
8f8d0e8901
commit
24943ebe15
@ -8,6 +8,7 @@ All notable changes to this project will be documented in this file.
|
||||
list those modules.
|
||||
- Added JS license web labels for LibreJS.
|
||||
- Added basic configuration form for Minetest server.
|
||||
- Added Domain Name Server (BIND) module.
|
||||
|
||||
### Changed
|
||||
- frontpage: Show app logos instead of generic icons.
|
||||
|
||||
@ -22,8 +22,6 @@ Plinth module to configure BIND server
|
||||
import re
|
||||
|
||||
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
|
||||
@ -141,13 +139,3 @@ def get_default():
|
||||
'forwarders': forwarders
|
||||
}
|
||||
return conf
|
||||
|
||||
|
||||
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
|
||||
|
||||
@ -20,11 +20,18 @@ Forms for BIND module.
|
||||
"""
|
||||
|
||||
from django import forms
|
||||
from django.core.validators import validate_ipv46_address
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from plinth.forms import ServiceForm
|
||||
|
||||
|
||||
def validate_ips(ips):
|
||||
"""Validate that ips is a list of IP addresses, separated by space."""
|
||||
for ip_addr in ips.split():
|
||||
validate_ipv46_address(ip_addr)
|
||||
|
||||
|
||||
class BindForm(ServiceForm):
|
||||
"""BIND configuration form"""
|
||||
set_forwarding = forms.BooleanField(
|
||||
@ -39,4 +46,5 @@ class BindForm(ServiceForm):
|
||||
|
||||
forwarders = forms.CharField(
|
||||
required=False,
|
||||
validators=[validate_ips],
|
||||
help_text=_('A list of IP addresses, separated by space'))
|
||||
|
||||
@ -26,7 +26,7 @@ from plinth import actions
|
||||
from plinth.views import ServiceView
|
||||
|
||||
|
||||
from . import description, managed_services, get_default, validate
|
||||
from . import description, managed_services, get_default
|
||||
from .forms import BindForm
|
||||
|
||||
|
||||
@ -67,15 +67,11 @@ class BindServiceView(ServiceView): # pylint: disable=too-many-ancestors
|
||||
|
||||
if old_config['forwarders'] != data['forwarders'] \
|
||||
and old_config['forwarders'] is not '':
|
||||
if validate(data['forwarders']) is True:
|
||||
actions.superuser_run(
|
||||
'bind',
|
||||
['dns', '--set', data['forwarders']])
|
||||
messages.success(self.request,
|
||||
_('DNS server configuration updated'))
|
||||
else:
|
||||
messages.error(self.request,
|
||||
_('Enter a valid IPv4 or IPv6 address.'))
|
||||
actions.superuser_run(
|
||||
'bind',
|
||||
['dns', '--set', data['forwarders']])
|
||||
messages.success(self.request,
|
||||
_('DNS server configuration updated'))
|
||||
elif old_config['forwarders'] is '' \
|
||||
and old_config['forwarders'] != data['forwarders']:
|
||||
messages.error(
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user