mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-05-20 10:34:30 +00:00
bind: Rework getting and changing config
Signed-off-by: James Valleroy <jvalleroy@mailbox.org> Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
This commit is contained in:
parent
3cb95fcbbd
commit
3e66e57c0f
@ -37,16 +37,12 @@ service = None
|
|||||||
|
|
||||||
managed_services = ['bind9']
|
managed_services = ['bind9']
|
||||||
|
|
||||||
managed_packages = ['bind9', 'bind9utils', 'bind9-doc']
|
managed_packages = ['bind9']
|
||||||
|
|
||||||
description = [
|
description = [
|
||||||
_('BIND is open source software that enables you to publish your Domain '
|
_('BIND enables you to publish your Domain Name System (DNS) information '
|
||||||
'Name System (DNS) information on the Internet, and to resolve '
|
'on the Internet, and to resolve DNS queries for your user devices on '
|
||||||
'DNS queries for your users.'),
|
'your network.')
|
||||||
_('BIND is by far the most widely used DNS software on the Internet, '
|
|
||||||
'providing a robust and stable platform on top of which organizations'
|
|
||||||
' can build distributed computing systems with the knowledge that those '
|
|
||||||
'systems are fully compliant with published DNS standards.')
|
|
||||||
]
|
]
|
||||||
|
|
||||||
CONFIG_FILE = '/etc/bind/named.conf.options'
|
CONFIG_FILE = '/etc/bind/named.conf.options'
|
||||||
@ -96,7 +92,7 @@ def setup(helper, old_version=None):
|
|||||||
ports=['dns'], is_external=True,
|
ports=['dns'], is_external=True,
|
||||||
enable=enable, disable=disable)
|
enable=enable, disable=disable)
|
||||||
helper.call('post', service.notify_enabled, None, True)
|
helper.call('post', service.notify_enabled, None, True)
|
||||||
helper.call('post', default_config)
|
helper.call('post', actions.superuser_run, 'bind', ['setup'])
|
||||||
|
|
||||||
|
|
||||||
def enable():
|
def enable():
|
||||||
@ -121,38 +117,27 @@ def diagnose():
|
|||||||
return results
|
return results
|
||||||
|
|
||||||
|
|
||||||
def default_config():
|
|
||||||
"""Setp BIND configuration"""
|
|
||||||
actions.superuser_run('bind', ['setup'])
|
|
||||||
|
|
||||||
|
|
||||||
def get_config():
|
def get_config():
|
||||||
"""Get initial value for forwarding"""
|
"""Get current configuration"""
|
||||||
data = [line.strip() for line in open(CONFIG_FILE, 'r')]
|
data = [line.strip() for line in open(CONFIG_FILE, 'r')]
|
||||||
if '// forwarders {' in data:
|
|
||||||
set_forwarding = False
|
|
||||||
else:
|
|
||||||
set_forwarding = True
|
|
||||||
if '// dnssec-enable yes;' in data or '//dnssec-enable yes;' in data:
|
|
||||||
enable_dnssec = False
|
|
||||||
else:
|
|
||||||
enable_dnssec = True
|
|
||||||
|
|
||||||
flag = 0
|
forwarding_enabled = False
|
||||||
|
dnssec_enabled = False
|
||||||
|
forwarders = ''
|
||||||
|
flag = False
|
||||||
for line in data:
|
for line in data:
|
||||||
|
if re.match(r'^\s*forwarders\s+{', line):
|
||||||
if flag == 1:
|
forwarding_enabled = True
|
||||||
if '//' in line:
|
flag = True
|
||||||
forwarders = ''
|
elif re.match(r'^\s*dnssec-enable\s+yes;', line):
|
||||||
else:
|
dnssec_enabled = True
|
||||||
forwarders = re.sub('[;]', '', line)
|
elif flag and '//' not in line:
|
||||||
flag = 0
|
forwarders = re.sub('[;]', '', line)
|
||||||
if 'forwarders {' in line:
|
flag = False
|
||||||
flag = 1
|
|
||||||
|
|
||||||
conf = {
|
conf = {
|
||||||
'set_forwarding': set_forwarding,
|
'set_forwarding': forwarding_enabled,
|
||||||
'enable_dnssec': enable_dnssec,
|
'enable_dnssec': dnssec_enabled,
|
||||||
'forwarders': forwarders
|
'forwarders': forwarders
|
||||||
}
|
}
|
||||||
return conf
|
return conf
|
||||||
@ -163,54 +148,48 @@ def set_forwarding(choice):
|
|||||||
data = [line.strip() for line in open(CONFIG_FILE, 'r')]
|
data = [line.strip() for line in open(CONFIG_FILE, 'r')]
|
||||||
flag = 0
|
flag = 0
|
||||||
if choice == "false":
|
if choice == "false":
|
||||||
if 'forwarders {' in data and '// forwarders {' not in data:
|
conf_file = open(CONFIG_FILE, 'w')
|
||||||
conf_file = open(CONFIG_FILE, 'w')
|
for line in data:
|
||||||
for line in data:
|
if re.match(r'^\s*forwarders\s+{', line):
|
||||||
if 'forwarders {' in line and '// forwarders {' not in line:
|
flag = 1
|
||||||
flag = 1
|
if flag == 1:
|
||||||
if flag == 1:
|
line = '// ' + line
|
||||||
line = ' // ' + line
|
if re.match(r'forward\s+first', line):
|
||||||
if 'forward first' in line:
|
flag = 0
|
||||||
flag = 0
|
conf_file.write(line + '\n')
|
||||||
if "0.0.0.0" not in line:
|
conf_file.close()
|
||||||
conf_file.write(line + '\n')
|
|
||||||
conf_file.close()
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
if '// forwarders {' in data:
|
conf_file = open(CONFIG_FILE, 'w')
|
||||||
conf_file = open(CONFIG_FILE, 'w')
|
for line in data:
|
||||||
for line in data:
|
if re.match(r'//\s*forwarders\s+{', line):
|
||||||
if '// forwarders {' in line:
|
flag = 1
|
||||||
flag = 1
|
if flag == 1:
|
||||||
if flag == 1:
|
line = line.lstrip('/')
|
||||||
line = line[2:]
|
if re.match(r'forward\s+first', line):
|
||||||
if 'forward first' in line:
|
flag = 0
|
||||||
flag = 0
|
conf_file.write(line + '\n')
|
||||||
if "0.0.0.0" not in line:
|
conf_file.close()
|
||||||
conf_file.write(line + '\n')
|
|
||||||
conf_file.close()
|
|
||||||
|
|
||||||
|
|
||||||
def enable_dnssec(choice):
|
def enable_dnssec(choice):
|
||||||
"""Enable or disable DNSSEC."""
|
"""Enable or disable DNSSEC."""
|
||||||
data = [line.strip() for line in open(CONFIG_FILE, 'r')]
|
data = [line.strip() for line in open(CONFIG_FILE, 'r')]
|
||||||
if choice == "false":
|
if choice == "false":
|
||||||
if '//dnssec-enable yes;' not in data:
|
conf_file = open(CONFIG_FILE, 'w')
|
||||||
conf_file = open(CONFIG_FILE, 'w')
|
for line in data:
|
||||||
for line in data:
|
if re.match(r'^\s*dnssec-enable\s+yes;', line):
|
||||||
if 'dnssec-enable yes;' in line:
|
line = '//' + line
|
||||||
line = '//' + line
|
conf_file.write(line + '\n')
|
||||||
conf_file.write(line + '\n')
|
conf_file.close()
|
||||||
conf_file.close()
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
if '//dnssec-enable yes;' in data:
|
conf_file = open(CONFIG_FILE, 'w')
|
||||||
conf_file = open(CONFIG_FILE, 'w')
|
for line in data:
|
||||||
for line in data:
|
if re.match(r'//\s*dnssec-enable\s+yes;', line):
|
||||||
if '//dnssec-enable yes;' in line:
|
line = line.lstrip('/')
|
||||||
line = line[2:]
|
conf_file.write(line + '\n')
|
||||||
conf_file.write(line + '\n')
|
conf_file.close()
|
||||||
conf_file.close()
|
|
||||||
|
|
||||||
|
|
||||||
def set_forwarders(forwarders):
|
def set_forwarders(forwarders):
|
||||||
@ -219,7 +198,7 @@ def set_forwarders(forwarders):
|
|||||||
data = [line.strip() for line in open(CONFIG_FILE, 'r')]
|
data = [line.strip() for line in open(CONFIG_FILE, 'r')]
|
||||||
conf_file = open(CONFIG_FILE, 'w')
|
conf_file = open(CONFIG_FILE, 'w')
|
||||||
for line in data:
|
for line in data:
|
||||||
if 'forwarders {' in line:
|
if re.match(r'^\s*forwarders\s+{', line):
|
||||||
conf_file.write(line + '\n')
|
conf_file.write(line + '\n')
|
||||||
for dns in forwarders.split():
|
for dns in forwarders.split():
|
||||||
conf_file.write(dns + '; ')
|
conf_file.write(dns + '; ')
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user