mirror of
https://github.com/eduardogsilva/wireguard_webadmin.git
synced 2025-08-26 21:31:14 +00:00
DNS Container and docker compose
This commit is contained in:
@@ -21,6 +21,7 @@ class DNSSettingsForm(forms.ModelForm):
|
||||
self.helper = FormHelper()
|
||||
self.fields['dns_primary'].label = 'Primary Resolver'
|
||||
self.fields['dns_secondary'].label = 'Secondary Resolver'
|
||||
self.fields['dns_primary'].required = True
|
||||
self.helper.form_method = 'post'
|
||||
self.helper.layout = Layout(
|
||||
Fieldset(
|
||||
|
@@ -25,9 +25,51 @@ server:
|
||||
local-zone: "local." static
|
||||
do-not-query-localhost: {do_not_query_localhost}
|
||||
verbosity: 1
|
||||
recursion: yes
|
||||
'''
|
||||
unbound_config += forward_zone
|
||||
for static_host in static_hosts:
|
||||
unbound_config += f'local-data: "{static_host.hostname}. IN A {static_host.ip_address}"\n'
|
||||
|
||||
if static_hosts:
|
||||
unbound_config += '\nlocal-zone: "." transparent\n'
|
||||
for static_host in static_hosts:
|
||||
unbound_config += f' local-data: "{static_host.hostname}. IN A {static_host.ip_address}"\n'
|
||||
return unbound_config
|
||||
|
||||
|
||||
def generate_dnsdist_config():
|
||||
dns_settings = DNSSettings.objects.get(name='dns_settings')
|
||||
static_hosts = StaticHost.objects.all()
|
||||
dnsdist_config = "setLocal('0.0.0.0:53')\n"
|
||||
dnsdist_config += "setACL('0.0.0.0/0')\n"
|
||||
|
||||
if dns_settings.dns_primary:
|
||||
dnsdist_config += f"newServer({{address='{dns_settings.dns_primary}', pool='upstreams'}})\n"
|
||||
if dns_settings.dns_secondary:
|
||||
dnsdist_config += f"newServer({{address='{dns_settings.dns_secondary}', pool='upstreams'}})\n"
|
||||
|
||||
if static_hosts:
|
||||
dnsdist_config += "addAction(makeRule(''), PoolAction('staticHosts'))\n"
|
||||
for static_host in static_hosts:
|
||||
dnsdist_config += f"addLocal('{static_host.hostname}', '{static_host.ip_address}')\n"
|
||||
|
||||
return dnsdist_config
|
||||
|
||||
|
||||
def generate_dnsmasq_config():
|
||||
dns_settings = DNSSettings.objects.get(name='dns_settings')
|
||||
static_hosts = StaticHost.objects.all()
|
||||
dnsmasq_config = f'''
|
||||
no-dhcp-interface=
|
||||
listen-address=0.0.0.0
|
||||
bind-interfaces
|
||||
|
||||
'''
|
||||
if dns_settings.dns_primary:
|
||||
dnsmasq_config += f'server={dns_settings.dns_primary}\n'
|
||||
if dns_settings.dns_secondary:
|
||||
dnsmasq_config += f'server={dns_settings.dns_secondary}\n'
|
||||
|
||||
if static_hosts:
|
||||
dnsmasq_config += '\n'
|
||||
for static_host in static_hosts:
|
||||
dnsmasq_config += f'address=/{static_host.hostname}/{static_host.ip_address}\n'
|
||||
return dnsmasq_config
|
||||
|
15
dns/views.py
15
dns/views.py
@@ -4,7 +4,7 @@ from django.contrib import messages
|
||||
from user_manager.models import UserAcl
|
||||
from .models import DNSSettings, StaticHost
|
||||
from .forms import StaticHostForm, DNSSettingsForm
|
||||
from .functions import generate_unbound_config
|
||||
from .functions import generate_dnsmasq_config
|
||||
from django.conf import settings
|
||||
|
||||
|
||||
@@ -13,9 +13,9 @@ def view_apply_dns_config(request):
|
||||
dns_settings, _ = DNSSettings.objects.get_or_create(name='dns_settings')
|
||||
dns_settings.pending_changes = False
|
||||
dns_settings.save()
|
||||
unbound_config = generate_unbound_config()
|
||||
with open(settings.UNBOUND_CONFIG, 'w') as f:
|
||||
f.write(unbound_config)
|
||||
dnsmasq_config = generate_dnsmasq_config()
|
||||
with open(settings.DNS_CONFIG_FILE, 'w') as f:
|
||||
f.write(dnsmasq_config)
|
||||
messages.success(request, 'DNS settings applied successfully')
|
||||
return redirect('/dns/')
|
||||
|
||||
@@ -48,12 +48,7 @@ def view_manage_dns_settings(request):
|
||||
<p>
|
||||
All DNS queries will be forwarded to the primary resolver. If the primary resolver is not available, the secondary resolver will be used.
|
||||
</p>
|
||||
<strong>
|
||||
Local DNS Resolution
|
||||
</strong>
|
||||
<p>
|
||||
If no forwarders are specified, the system will locally resolve DNS queries. This can lead to slower DNS resolution times, but can be useful in certain scenarios.
|
||||
</p>
|
||||
|
||||
'''
|
||||
|
||||
context = {
|
||||
|
Reference in New Issue
Block a user