mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-05-20 10:34:30 +00:00
bind: Add validator
This commit is contained in:
parent
0312c41415
commit
e0abdbd0e9
@ -30,7 +30,7 @@ CONFIG_FILE = '/etc/bind/named.conf.options'
|
|||||||
|
|
||||||
value1 = 'acl goodclients { \n localnets;\n};\n'
|
value1 = 'acl goodclients { \n localnets;\n};\n'
|
||||||
value2 = ' recursion yes;\n allow-query { goodclients; };\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'
|
value4 = ' //forward first;\n'
|
||||||
value5 = ' //dnssec-enable yes;\n'
|
value5 = ' //dnssec-enable yes;\n'
|
||||||
|
|
||||||
@ -104,7 +104,7 @@ def set_forwarding(choice):
|
|||||||
flag = 1
|
flag = 1
|
||||||
if flag == 1:
|
if flag == 1:
|
||||||
line = ' // '+line
|
line = ' // '+line
|
||||||
if 'forward only' in line:
|
if 'forward first' in line:
|
||||||
flag = 0
|
flag = 0
|
||||||
if "0.0.0.0" not in line:
|
if "0.0.0.0" not in line:
|
||||||
f.write(line+'\n')
|
f.write(line+'\n')
|
||||||
@ -153,7 +153,9 @@ def set(DNS):
|
|||||||
for line in data:
|
for line in data:
|
||||||
if 'forwarders {' in line :
|
if 'forwarders {' in line :
|
||||||
f.write(line+'\n')
|
f.write(line+'\n')
|
||||||
f.write(DNS+';\n')
|
for dns in DNS.split():
|
||||||
|
f.write(dns+'; ')
|
||||||
|
f.write('\n')
|
||||||
flag = 1
|
flag = 1
|
||||||
elif '};' and flag == 1:
|
elif '};' and flag == 1:
|
||||||
flag = 0
|
flag = 0
|
||||||
|
|||||||
@ -19,8 +19,11 @@
|
|||||||
Plinth module to configure BIND server
|
Plinth module to configure BIND server
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import re
|
||||||
|
|
||||||
from django.urls import reverse_lazy
|
from django.urls import reverse_lazy
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
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
|
||||||
@ -123,7 +126,7 @@ def get_default():
|
|||||||
set_forwarding = False
|
set_forwarding = False
|
||||||
else:
|
else:
|
||||||
set_forwarding = True
|
set_forwarding = True
|
||||||
if '//dnssec-enable yes;' in data:
|
if '// dnssec-enable yes;' in data or '//dnssec-enable yes;' in data:
|
||||||
enable_dnssec = False
|
enable_dnssec = False
|
||||||
else:
|
else:
|
||||||
enable_dnssec = True
|
enable_dnssec = True
|
||||||
@ -132,7 +135,10 @@ def get_default():
|
|||||||
for line in data:
|
for line in data:
|
||||||
|
|
||||||
if flag == 1:
|
if flag == 1:
|
||||||
dns_set = line[:len(line)-1]
|
if '//' in line:
|
||||||
|
dns_set = ''
|
||||||
|
else:
|
||||||
|
dns_set = re.sub('[;]', '', line)
|
||||||
flag = 0
|
flag = 0
|
||||||
if 'forwarders {' in line:
|
if 'forwarders {' in line:
|
||||||
flag = 1
|
flag = 1
|
||||||
@ -143,3 +149,12 @@ def get_default():
|
|||||||
'dns_set': dns_set
|
'dns_set': dns_set
|
||||||
}
|
}
|
||||||
return conf
|
return conf
|
||||||
|
|
||||||
|
|
||||||
|
def validate(IP):
|
||||||
|
for ip in IP.split():
|
||||||
|
try :
|
||||||
|
validate_ipv46_address(ip)
|
||||||
|
except:
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|||||||
@ -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
|
from . import description, managed_services, get_default, validate
|
||||||
from .forms import BindForm
|
from .forms import BindForm
|
||||||
|
|
||||||
|
|
||||||
@ -65,11 +65,20 @@ class BindServiceView(ServiceView): # pylint: disable=too-many-ancestors
|
|||||||
messages.success(self.request,
|
messages.success(self.request,
|
||||||
_('Enable DNSSEC configuration updated'))
|
_('Enable DNSSEC configuration updated'))
|
||||||
|
|
||||||
if old_config['dns_set'] != data['dns_set']:
|
|
||||||
|
|
||||||
|
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(
|
actions.superuser_run(
|
||||||
'bind',
|
'bind',
|
||||||
['dns', '--set', data['dns_set']])
|
['dns', '--set', data['dns_set']])
|
||||||
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['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)
|
return super().form_valid(form)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user