mirror of
https://github.com/eduardogsilva/wireguard_webadmin.git
synced 2026-01-02 06:36:16 +00:00
add function to compress dnsmasq configuration
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user