mirror of
https://github.com/eduardogsilva/wireguard_webadmin.git
synced 2026-01-01 14:16:18 +00:00
add function to compress dnsmasq configuration
This commit is contained in:
@@ -3,6 +3,7 @@ from django.contrib.auth.decorators import login_required
|
||||
from django.shortcuts import get_object_or_404, redirect, render
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from dns.functions import compress_dnsmasq_config
|
||||
from user_manager.models import UserAcl
|
||||
from .forms import WorkerForm, ClusterSettingsForm
|
||||
from .models import ClusterSettings, Worker
|
||||
@@ -109,6 +110,7 @@ def cluster_settings(request):
|
||||
if form.is_valid():
|
||||
form.save()
|
||||
messages.success(request, _('Cluster settings updated successfully.'))
|
||||
compress_dnsmasq_config()
|
||||
return redirect('/cluster/')
|
||||
else:
|
||||
form = ClusterSettingsForm(instance=cluster_settings)
|
||||
|
||||
@@ -1,8 +1,28 @@
|
||||
import os
|
||||
import tarfile
|
||||
|
||||
from cluster.models import ClusterSettings
|
||||
from .models import DNSSettings, StaticHost, DNSFilterList
|
||||
|
||||
|
||||
def compress_dnsmasq_config():
|
||||
output_file = "/etc/dnsmasq/dnsmasq_config.tar.gz"
|
||||
base_dir = "/etc/dnsmasq"
|
||||
|
||||
if not ClusterSettings.objects.filter(enabled=True, name='cluster_settings').exists():
|
||||
if os.path.exists(output_file):
|
||||
os.remove(output_file)
|
||||
return None
|
||||
|
||||
with tarfile.open(output_file, "w:gz") as tar:
|
||||
for filename in os.listdir(base_dir):
|
||||
if filename.endswith(".conf"):
|
||||
fullpath = os.path.join(base_dir, filename)
|
||||
tar.add(fullpath, arcname=filename)
|
||||
|
||||
return output_file
|
||||
|
||||
|
||||
def generate_unbound_config():
|
||||
dns_settings = DNSSettings.objects.get(name='dns_settings')
|
||||
static_hosts = StaticHost.objects.all()
|
||||
@@ -82,3 +102,4 @@ bind-interfaces
|
||||
file_path = os.path.join("/etc/dnsmasq/", f"{dns_list.uuid}.conf")
|
||||
dnsmasq_config += f'addn-hosts={file_path}\n'
|
||||
return dnsmasq_config
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ from django.utils.translation import gettext_lazy as _
|
||||
from user_manager.models import UserAcl
|
||||
from .forms import DNSFilterListForm
|
||||
from .forms import DNSSettingsForm, StaticHostForm
|
||||
from .functions import generate_dnsmasq_config
|
||||
from .functions import generate_dnsmasq_config, compress_dnsmasq_config
|
||||
from .models import DNSFilterList, DNSSettings
|
||||
from .models import StaticHost
|
||||
|
||||
@@ -24,6 +24,7 @@ def export_dns_configuration():
|
||||
dnsmasq_config = generate_dnsmasq_config()
|
||||
with open(settings.DNS_CONFIG_FILE, 'w') as f:
|
||||
f.write(dnsmasq_config)
|
||||
compress_dnsmasq_config()
|
||||
return
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user