mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-04-29 10:10:19 +00:00
bind: Added DNS servers setting
This commit is contained in:
parent
d986d58250
commit
0312c41415
34
actions/bind
34
actions/bind
@ -28,9 +28,9 @@ from plinth import action_utils
|
|||||||
|
|
||||||
CONFIG_FILE = '/etc/bind/named.conf.options'
|
CONFIG_FILE = '/etc/bind/named.conf.options'
|
||||||
|
|
||||||
value1 = 'acl goodclients { \n localhost;\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;\n // 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'
|
||||||
|
|
||||||
@ -46,6 +46,9 @@ def parse_arguments():
|
|||||||
configure.add_argument('--enable-dnssec', choices=['true', 'false'],
|
configure.add_argument('--enable-dnssec', choices=['true', 'false'],
|
||||||
help='Set DNSSEC true/false')
|
help='Set DNSSEC true/false')
|
||||||
|
|
||||||
|
dns = subparsers.add_parser('dns', help='Set up DNS server')
|
||||||
|
dns.add_argument('--set', help='Set DNS server')
|
||||||
|
|
||||||
return parser.parse_args()
|
return parser.parse_args()
|
||||||
|
|
||||||
|
|
||||||
@ -69,6 +72,15 @@ def subcommand_setup(_):
|
|||||||
enable_dnssec(True)
|
enable_dnssec(True)
|
||||||
action_utils.service_restart('bind9')
|
action_utils.service_restart('bind9')
|
||||||
|
|
||||||
|
def subcommand_dns(arguments):
|
||||||
|
"""Setting DNS servers"""
|
||||||
|
|
||||||
|
if arguments.set:
|
||||||
|
set(arguments.set)
|
||||||
|
|
||||||
|
action_utils.service_restart('bind9')
|
||||||
|
|
||||||
|
|
||||||
def subcommand_configure(arguments):
|
def subcommand_configure(arguments):
|
||||||
"""Configure BIND."""
|
"""Configure BIND."""
|
||||||
|
|
||||||
@ -98,8 +110,6 @@ def set_forwarding(choice):
|
|||||||
f.write(line+'\n')
|
f.write(line+'\n')
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
if '// forwarders {' in data:
|
if '// forwarders {' in data:
|
||||||
f = open(CONFIG_FILE, 'w')
|
f = open(CONFIG_FILE, 'w')
|
||||||
@ -136,6 +146,22 @@ def enable_dnssec(choice):
|
|||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
|
|
||||||
|
def set(DNS):
|
||||||
|
flag = 0
|
||||||
|
data = [line.strip() for line in open(CONFIG_FILE, 'r')]
|
||||||
|
f = open(CONFIG_FILE, 'w')
|
||||||
|
for line in data:
|
||||||
|
if 'forwarders {' in line :
|
||||||
|
f.write(line+'\n')
|
||||||
|
f.write(DNS+';\n')
|
||||||
|
flag = 1
|
||||||
|
elif '};' and flag == 1:
|
||||||
|
flag = 0
|
||||||
|
elif flag == 0:
|
||||||
|
f.write(line+'\n')
|
||||||
|
f.close()
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
"""Parse arguments and perform all duties"""
|
"""Parse arguments and perform all duties"""
|
||||||
arguments = parse_arguments()
|
arguments = parse_arguments()
|
||||||
|
|||||||
@ -65,7 +65,7 @@ def init():
|
|||||||
setup_helper = globals()['setup_helper']
|
setup_helper = globals()['setup_helper']
|
||||||
if setup_helper.get_state() != 'needs-setup':
|
if setup_helper.get_state() != 'needs-setup':
|
||||||
service = service_module.Service(
|
service = service_module.Service(
|
||||||
managed_services[0], title, ports=['bind-plinth'],
|
managed_services[0], title, ports=['dns'],
|
||||||
is_external=False,
|
is_external=False,
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -127,8 +127,19 @@ def get_default():
|
|||||||
enable_dnssec = False
|
enable_dnssec = False
|
||||||
else:
|
else:
|
||||||
enable_dnssec = True
|
enable_dnssec = True
|
||||||
|
|
||||||
|
flag = 0
|
||||||
|
for line in data:
|
||||||
|
|
||||||
|
if flag == 1:
|
||||||
|
dns_set = line[:len(line)-1]
|
||||||
|
flag = 0
|
||||||
|
if 'forwarders {' in line:
|
||||||
|
flag = 1
|
||||||
|
|
||||||
conf = {
|
conf = {
|
||||||
'set_forwarding': set_forwarding,
|
'set_forwarding': set_forwarding,
|
||||||
'enable_dnssec': enable_dnssec
|
'enable_dnssec': enable_dnssec,
|
||||||
|
'dns_set': dns_set
|
||||||
}
|
}
|
||||||
return conf
|
return conf
|
||||||
|
|||||||
@ -24,6 +24,8 @@ from django.utils.translation import ugettext_lazy as _
|
|||||||
|
|
||||||
from plinth.forms import ServiceForm
|
from plinth.forms import ServiceForm
|
||||||
|
|
||||||
|
from . import get_default
|
||||||
|
|
||||||
|
|
||||||
class BindForm(ServiceForm):
|
class BindForm(ServiceForm):
|
||||||
"""BIND configuration form"""
|
"""BIND configuration form"""
|
||||||
@ -36,3 +38,8 @@ class BindForm(ServiceForm):
|
|||||||
label=_('Enable DNSSEC'),
|
label=_('Enable DNSSEC'),
|
||||||
required=False,
|
required=False,
|
||||||
help_text=_('Enable Domain Name System Security Extensions'))
|
help_text=_('Enable Domain Name System Security Extensions'))
|
||||||
|
|
||||||
|
dns_set = forms.CharField(
|
||||||
|
label=_('Set DNS server'),
|
||||||
|
required=False,
|
||||||
|
help_text=_('Set new DNS server'))
|
||||||
|
|||||||
@ -65,5 +65,11 @@ 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']:
|
||||||
|
actions.superuser_run(
|
||||||
|
'bind',
|
||||||
|
['dns', '--set', data['dns_set']])
|
||||||
|
messages.success(self.request,
|
||||||
|
_('DNS server configuration updated'))
|
||||||
|
|
||||||
return super().form_valid(form)
|
return super().form_valid(form)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user