mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-08-26 12:46:08 +00:00
bind: Replace config in setup
This commit is contained in:
parent
e0abdbd0e9
commit
d4b0809db0
56
actions/bind
56
actions/bind
@ -27,12 +27,41 @@ from plinth import action_utils
|
|||||||
|
|
||||||
|
|
||||||
CONFIG_FILE = '/etc/bind/named.conf.options'
|
CONFIG_FILE = '/etc/bind/named.conf.options'
|
||||||
|
default_file = '\n'+\
|
||||||
value1 = 'acl goodclients { \n localnets;\n};\n'
|
'acl goodclients {\n'+\
|
||||||
value2 = ' recursion yes;\n allow-query { goodclients; };\n\n'
|
' localnets;\n'+\
|
||||||
value3 = ' // 8.8.8.8; 8.8.4.4;\n'
|
'};\n'+\
|
||||||
value4 = ' //forward first;\n'
|
'options {\n'+\
|
||||||
value5 = ' //dnssec-enable yes;\n'
|
'directory "/var/cache/bind";\n'+\
|
||||||
|
'\n'+\
|
||||||
|
'recursion yes;\n'+\
|
||||||
|
'allow-query { goodclients; };\n'+\
|
||||||
|
'\n'+\
|
||||||
|
'// If there is a firewall between you and nameservers you want\n'+\
|
||||||
|
'// to talk to, you may need to fix the firewall to allow multiple\n'+\
|
||||||
|
'// ports to talk. See http://www.kb.cert.org/vuls/id/800113\n'+\
|
||||||
|
'\n'+\
|
||||||
|
'// If your ISP provided one or more IP addresses for stable\n'+\
|
||||||
|
'// nameservers, you probably want to use them as forwarders.\n'+\
|
||||||
|
'// Uncomment the following block, and insert the addresses replacing\n'+\
|
||||||
|
"// the all-0's placeholder.\n"+\
|
||||||
|
'\n'+\
|
||||||
|
'forwarders {\n'+\
|
||||||
|
'8.8.8.8; 8.8.4.4;\n'+\
|
||||||
|
'};\n'+\
|
||||||
|
'forward first;\n'+\
|
||||||
|
'\n'+\
|
||||||
|
'dnssec-enable yes;\n'+\
|
||||||
|
'//========================================================================\n'+\
|
||||||
|
'// If BIND logs error messages about the root key being expired,\n'+\
|
||||||
|
'// you will need to update your keys. See https://www.isc.org/bind-keys\n'+\
|
||||||
|
'//========================================================================\n'+\
|
||||||
|
'dnssec-validation auto;\n'+\
|
||||||
|
'\n'+\
|
||||||
|
'auth-nxdomain no; # conform to RFC1035\n'+\
|
||||||
|
'listen-on-v6 { any; };\n'+\
|
||||||
|
'};\n'+\
|
||||||
|
'\n'
|
||||||
|
|
||||||
def parse_arguments():
|
def parse_arguments():
|
||||||
"""Return parsed command line arguments as dictionary"""
|
"""Return parsed command line arguments as dictionary"""
|
||||||
@ -54,22 +83,9 @@ def parse_arguments():
|
|||||||
|
|
||||||
def subcommand_setup(_):
|
def subcommand_setup(_):
|
||||||
"""Setup BIND configuration."""
|
"""Setup BIND configuration."""
|
||||||
f = open(CONFIG_FILE, "r")
|
|
||||||
contents = f.readlines()
|
|
||||||
f.close()
|
|
||||||
|
|
||||||
contents.insert(0, value1)
|
|
||||||
contents.insert(4, value2)
|
|
||||||
contents.insert(15, value3)
|
|
||||||
contents.insert(18, value4)
|
|
||||||
contents.insert(20, value5)
|
|
||||||
|
|
||||||
f = open(CONFIG_FILE, "w")
|
f = open(CONFIG_FILE, "w")
|
||||||
contents = "".join(contents)
|
f.write(default_file)
|
||||||
f.write(contents)
|
|
||||||
f.close()
|
f.close()
|
||||||
set_forwarding(True)
|
|
||||||
enable_dnssec(True)
|
|
||||||
action_utils.service_restart('bind9')
|
action_utils.service_restart('bind9')
|
||||||
|
|
||||||
def subcommand_dns(arguments):
|
def subcommand_dns(arguments):
|
||||||
|
|||||||
@ -136,9 +136,9 @@ def get_default():
|
|||||||
|
|
||||||
if flag == 1:
|
if flag == 1:
|
||||||
if '//' in line:
|
if '//' in line:
|
||||||
dns_set = ''
|
forwarders = ''
|
||||||
else:
|
else:
|
||||||
dns_set = re.sub('[;]', '', line)
|
forwarders = re.sub('[;]', '', line)
|
||||||
flag = 0
|
flag = 0
|
||||||
if 'forwarders {' in line:
|
if 'forwarders {' in line:
|
||||||
flag = 1
|
flag = 1
|
||||||
@ -146,7 +146,7 @@ def get_default():
|
|||||||
conf = {
|
conf = {
|
||||||
'set_forwarding': set_forwarding,
|
'set_forwarding': set_forwarding,
|
||||||
'enable_dnssec': enable_dnssec,
|
'enable_dnssec': enable_dnssec,
|
||||||
'dns_set': dns_set
|
'forwarders': forwarders
|
||||||
}
|
}
|
||||||
return conf
|
return conf
|
||||||
|
|
||||||
|
|||||||
@ -39,7 +39,6 @@ class BindForm(ServiceForm):
|
|||||||
required=False,
|
required=False,
|
||||||
help_text=_('Enable Domain Name System Security Extensions'))
|
help_text=_('Enable Domain Name System Security Extensions'))
|
||||||
|
|
||||||
dns_set = forms.CharField(
|
forwarders = forms.CharField(
|
||||||
label=_('Set DNS server'),
|
|
||||||
required=False,
|
required=False,
|
||||||
help_text=_('Set new DNS server'))
|
help_text=_('Set new DNS server'))
|
||||||
|
|||||||
@ -67,17 +67,17 @@ class BindServiceView(ServiceView): # pylint: disable=too-many-ancestors
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
if old_config['dns_set'] != data['dns_set'] and old_config['dns_set'] is not '':
|
if old_config['forwarders'] != data['forwarders'] and old_config['forwarders'] is not '':
|
||||||
if validate(data['dns_set']) is True:
|
if validate(data['forwarders']) is True:
|
||||||
actions.superuser_run(
|
actions.superuser_run(
|
||||||
'bind',
|
'bind',
|
||||||
['dns', '--set', data['dns_set']])
|
['dns', '--set', data['forwarders']])
|
||||||
messages.success(self.request,
|
messages.success(self.request,
|
||||||
_('DNS server configuration updated'))
|
_('DNS server configuration updated'))
|
||||||
else:
|
else:
|
||||||
messages.error(self.request,
|
messages.error(self.request,
|
||||||
_('Enter a valid IPv4 or IPv6 address.'))
|
_('Enter a valid IPv4 or IPv6 address.'))
|
||||||
elif old_config['dns_set'] is '' and old_config['dns_set'] != data['dns_set']:
|
elif old_config['forwarders'] is '' and old_config['forwarders'] != data['forwarders']:
|
||||||
messages.error(self.request,
|
messages.error(self.request,
|
||||||
_('Enable forwarding to set forwarding DNS servers'))
|
_('Enable forwarding to set forwarding DNS servers'))
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user