From 437eec0f83bdb963d699e8b6770eebf9cb380b62 Mon Sep 17 00:00:00 2001 From: Eduardo Silva Date: Thu, 1 Jan 2026 15:29:59 -0300 Subject: [PATCH] refactor cluster settings handling and update DNS version logic --- .env.cluster_example | 6 +----- cluster/views.py | 7 ++++--- dns/functions.py | 10 ++++++---- docker-compose-no-nginx-dev.yml | 2 +- 4 files changed, 12 insertions(+), 13 deletions(-) diff --git a/.env.cluster_example b/.env.cluster_example index 9e3cf0d..aa5837a 100644 --- a/.env.cluster_example +++ b/.env.cluster_example @@ -1,6 +1,6 @@ # Example configuration for Cluster Node # Rename this file to .env before starting -COMPOSE_PROJECT_NAME=wireguard_webadmin_cluster_node +COMPOSE_PROJECT_NAME=wireguard_webadmin_cluster_node_test2 # Master Server Address (where the API is hosting) # Example: https://wireguard.example.com MASTER_SERVER_ADDRESS=https://wireguard.example.com @@ -14,8 +14,4 @@ TOKEN= # Debug Mode (optional, default False) DEBUG_MODE=False -# Compose Version (Do not change) -COMPOSE_VERSION=03r - -# Timezone (duplicate for compatibility if needed, but TZ is standard) TIMEZONE=America/Sao_Paulo diff --git a/cluster/views.py b/cluster/views.py index 2b8a357..fc029e0 100644 --- a/cluster/views.py +++ b/cluster/views.py @@ -110,10 +110,11 @@ def cluster_settings(request): if form.is_valid(): form.save() messages.success(request, _('Cluster settings updated successfully.')) + if cluster_settings.enabled: + if cluster_settings.config_version == 0: + cluster_settings.config_version += 1 + cluster_settings.save() compress_dnsmasq_config() - if cluster_settings.enabled and cluster_settings.config_version == 0: - cluster_settings.config_version += 1 - cluster_settings.save() return redirect('/cluster/') else: form = ClusterSettingsForm(instance=cluster_settings) diff --git a/dns/functions.py b/dns/functions.py index b3df1d8..542c391 100644 --- a/dns/functions.py +++ b/dns/functions.py @@ -9,10 +9,7 @@ def compress_dnsmasq_config(): output_file = "/etc/dnsmasq/dnsmasq_config.tar.gz" base_dir = "/etc/dnsmasq" cluster_settings = ClusterSettings.objects.filter(enabled=True, name='cluster_settings').first() - if cluster_settings: - cluster_settings.dns_version += 1 - cluster_settings.save() - else: + if not cluster_settings: if os.path.exists(output_file): os.remove(output_file) return None @@ -36,9 +33,14 @@ def compress_dnsmasq_config(): if newest_conf_mtime <= tar_mtime: return output_file + # If we reach here, we need to increment DNS version and recompile the tar.gz + cluster_settings.dns_version += 1 + cluster_settings.save() dns_version_file = os.path.join(base_dir, "config_version.conf") with open(dns_version_file, "w", encoding="utf-8") as f: f.write(f"DNS_VERSION={cluster_settings.dns_version}\n") + if "config_version.conf" not in conf_files: + conf_files.append("config_version.conf") # Create tar.gz tmp_output = output_file + ".tmp" diff --git a/docker-compose-no-nginx-dev.yml b/docker-compose-no-nginx-dev.yml index af75fd1..83dffc7 100644 --- a/docker-compose-no-nginx-dev.yml +++ b/docker-compose-no-nginx-dev.yml @@ -24,7 +24,7 @@ services: - "8000:8000" # Warning: Docker will have a hard time handling large amount of ports. Expose only the ports that you need. # Ports for multiple WireGuard instances. (Probably, you just need one) - - "51820-51839:51820-51839/udp" + #- "51820-51839:51820-51839/udp" # Ports for port forwarding rules. Add your own ports here if you need them. - "8080-8089:8080-8089/tcp"