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