mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-04-29 10:10:19 +00:00
bind: forwarding works fine now
This commit is contained in:
parent
95265426a9
commit
8c0d8e9db2
13
actions/bind
13
actions/bind
@ -28,6 +28,11 @@ 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'
|
||||||
|
value2 = ' recursion yes;\n allow-query { goodclients; };\n\n'
|
||||||
|
value3 = ' // 8.8.8.8;\n // 8.8.4.4;\n'
|
||||||
|
value4 = ' //forward only;\n'
|
||||||
|
|
||||||
def parse_arguments():
|
def parse_arguments():
|
||||||
"""Return parsed command line arguments as dictionary"""
|
"""Return parsed command line arguments as dictionary"""
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
@ -52,11 +57,13 @@ def subcommand_setup(_):
|
|||||||
contents.insert(0, value1)
|
contents.insert(0, value1)
|
||||||
contents.insert(4, value2)
|
contents.insert(4, value2)
|
||||||
contents.insert(15, value3)
|
contents.insert(15, value3)
|
||||||
|
contents.insert(18, value4)
|
||||||
|
|
||||||
f = open(CONFIG_FILE, "w")
|
f = open(CONFIG_FILE, "w")
|
||||||
contents = "".join(contents)
|
contents = "".join(contents)
|
||||||
f.write(contents)
|
f.write(contents)
|
||||||
f.close()
|
f.close()
|
||||||
|
action_utils.service_restart('bind9')
|
||||||
|
|
||||||
def subcommand_configure(arguments):
|
def subcommand_configure(arguments):
|
||||||
"""Configure BIND."""
|
"""Configure BIND."""
|
||||||
@ -68,7 +75,7 @@ def subcommand_configure(arguments):
|
|||||||
|
|
||||||
|
|
||||||
def set_forwarding(choice):
|
def set_forwarding(choice):
|
||||||
if choice == False:
|
if choice == "false":
|
||||||
flag = 0
|
flag = 0
|
||||||
data = [line.strip() for line in open(CONFIG_FILE, 'r')]
|
data = [line.strip() for line in open(CONFIG_FILE, 'r')]
|
||||||
if 'forwarders {' in data and not '// forwarders {' in data:
|
if 'forwarders {' in data and not '// forwarders {' in data:
|
||||||
@ -77,7 +84,7 @@ def set_forwarding(choice):
|
|||||||
if 'forwarders {' in line and not '// forwarders {' in line:
|
if 'forwarders {' in line and not '// forwarders {' in line:
|
||||||
flag = 1
|
flag = 1
|
||||||
if flag == 1:
|
if flag == 1:
|
||||||
line = ' //'+line
|
line = ' // '+line
|
||||||
if 'forward only' in line:
|
if 'forward only' in line:
|
||||||
flag = 0
|
flag = 0
|
||||||
f.write(line+'\n')
|
f.write(line+'\n')
|
||||||
@ -85,7 +92,7 @@ def set_forwarding(choice):
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
if choice == True:
|
else:
|
||||||
flag = 0
|
flag = 0
|
||||||
data = [line.strip() for line in open(CONFIG_FILE, 'r')]
|
data = [line.strip() for line in open(CONFIG_FILE, 'r')]
|
||||||
if '// forwarders {' in data:
|
if '// forwarders {' in data:
|
||||||
|
|||||||
@ -32,7 +32,7 @@ from plinth.views import ServiceView
|
|||||||
|
|
||||||
version = 1
|
version = 1
|
||||||
|
|
||||||
depends = ['apps']
|
depends = ['system']
|
||||||
|
|
||||||
title = _('Domain Name Server \n (BIND)')
|
title = _('Domain Name Server \n (BIND)')
|
||||||
|
|
||||||
@ -55,10 +55,6 @@ description = [
|
|||||||
|
|
||||||
CONFIG_FILE = '/etc/bind/named.conf.options'
|
CONFIG_FILE = '/etc/bind/named.conf.options'
|
||||||
|
|
||||||
value1 = 'acl goodclients { \n localhost;\n};\n'
|
|
||||||
value2 = ' recursion yes;\n allow-query { goodclients; };\n\n'
|
|
||||||
value3 = ' // 8.8.8.8;\n // 8.8.4.4;\n'
|
|
||||||
|
|
||||||
|
|
||||||
def init():
|
def init():
|
||||||
"""Intialize the BIND module."""
|
"""Intialize the BIND module."""
|
||||||
@ -96,13 +92,11 @@ def setup(helper, old_version=None):
|
|||||||
def enable():
|
def enable():
|
||||||
"""Enable the module."""
|
"""Enable the module."""
|
||||||
actions.superuser_run('service', ['enable', managed_services[0]])
|
actions.superuser_run('service', ['enable', managed_services[0]])
|
||||||
add_shortcut()
|
|
||||||
|
|
||||||
|
|
||||||
def disable():
|
def disable():
|
||||||
"""Disable the module."""
|
"""Disable the module."""
|
||||||
actions.superuser_run('service', ['disable', managed_services[0]])
|
actions.superuser_run('service', ['disable', managed_services[0]])
|
||||||
frontpage.remove_shortcut('bind')
|
|
||||||
|
|
||||||
|
|
||||||
def diagnose():
|
def diagnose():
|
||||||
@ -113,20 +107,20 @@ def diagnose():
|
|||||||
results.append(action_utils.diagnose_port_listening(53, 'udp6'))
|
results.append(action_utils.diagnose_port_listening(53, 'udp6'))
|
||||||
|
|
||||||
return results
|
return results
|
||||||
|
|
||||||
|
|
||||||
def default_config():
|
def default_config():
|
||||||
"""Setp BIND configuration"""
|
"""Setp BIND configuration"""
|
||||||
actions.superuser_run('bind', ['setup'])
|
actions.superuser_run('bind', ['setup'])
|
||||||
|
|
||||||
|
|
||||||
def get_default():
|
def get_default():
|
||||||
"""Get initial value for forwarding"""
|
"""Get initial value for forwarding"""
|
||||||
f = open(CONFIG_FILE, "r")
|
data = [line.strip() for line in open(CONFIG_FILE, 'r')]
|
||||||
contents = f.readlines()
|
if '// forwarders {' in data:
|
||||||
if '// forwarders {' in contents:
|
|
||||||
conf = {
|
conf = {
|
||||||
'set_forwarding': False}
|
'set_forwarding': False}
|
||||||
else:
|
else:
|
||||||
conf = {
|
conf = {
|
||||||
'set_forwarding': True}
|
'set_forwarding': True}
|
||||||
|
return conf
|
||||||
|
|||||||
@ -29,4 +29,5 @@ class BindForm(ServiceForm):
|
|||||||
"""BIND configuration form"""
|
"""BIND configuration form"""
|
||||||
set_forwarding = forms.BooleanField(
|
set_forwarding = forms.BooleanField(
|
||||||
label=_('Enable forwarding'),
|
label=_('Enable forwarding'),
|
||||||
required=False)
|
required=False,
|
||||||
|
help_text=_('Enable forwarding on your BIND server'))
|
||||||
|
|||||||
@ -21,9 +21,9 @@ URLs for the BIND module
|
|||||||
|
|
||||||
from django.conf.urls import url
|
from django.conf.urls import url
|
||||||
|
|
||||||
from plinth.modules.bind import BindServiceView
|
from plinth.modules.bind.views import BindServiceView
|
||||||
|
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url(r'^apps/bind/$', BindServiceView.as_view(), name='index'),
|
url(r'^sys/bind/$', BindServiceView.as_view(), name='index'),
|
||||||
]
|
]
|
||||||
|
|||||||
@ -53,7 +53,7 @@ class BindServiceView(ServiceView): # pylint: disable=too-many-ancestors
|
|||||||
value = 'true' if data['set_forwarding'] else 'false'
|
value = 'true' if data['set_forwarding'] else 'false'
|
||||||
actions.superuser_run(
|
actions.superuser_run(
|
||||||
'bind',
|
'bind',
|
||||||
['configure', '--set_forwarding', value])
|
['configure', '--set-forwarding', value])
|
||||||
messages.success(self.request,
|
messages.success(self.request,
|
||||||
_('Set forwarding configuration updated'))
|
_('Set forwarding configuration updated'))
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user