mirror of
https://github.com/eduardogsilva/wireguard_webadmin.git
synced 2026-04-04 06:26:20 +00:00
Add export_configs management command for WireGuard and Caddy configurations
This commit is contained in:
16
init.sh
16
init.sh
@@ -4,6 +4,13 @@ set -e
|
|||||||
# Lets wait for the DNS container to start
|
# Lets wait for the DNS container to start
|
||||||
sleep 5
|
sleep 5
|
||||||
|
|
||||||
|
# Django startup
|
||||||
|
python manage.py migrate --noinput
|
||||||
|
python manage.py collectstatic --noinput
|
||||||
|
|
||||||
|
# Export WireGuard, firewall and Caddy configs before bringing up interfaces
|
||||||
|
python manage.py export_configs
|
||||||
|
|
||||||
# Starts each WireGuard configuration file found in /etc/wireguard
|
# Starts each WireGuard configuration file found in /etc/wireguard
|
||||||
shopt -s nullglob
|
shopt -s nullglob
|
||||||
config_files=(/etc/wireguard/*.conf)
|
config_files=(/etc/wireguard/*.conf)
|
||||||
@@ -12,15 +19,6 @@ if [ ${#config_files[@]} -gt 0 ]; then
|
|||||||
wg-quick up "$(basename "${f}" .conf)"
|
wg-quick up "$(basename "${f}" .conf)"
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Django startup
|
|
||||||
python manage.py migrate --noinput
|
|
||||||
python manage.py collectstatic --noinput
|
|
||||||
|
|
||||||
if [[ "${CADDY_ENABLED,,}" == "true" ]]; then
|
|
||||||
echo "Exporting Caddy configuration (auth_policies.json, applications.json, routes.json)..."
|
|
||||||
python manage.py shell -c "from app_gateway.caddy_config_export import export_caddy_config; export_caddy_config('/caddy_json_export')" || echo "Failed to export Caddy configuration."
|
|
||||||
fi
|
|
||||||
if [[ "${DEV_MODE,,}" == "true" ]]; then
|
if [[ "${DEV_MODE,,}" == "true" ]]; then
|
||||||
echo ""
|
echo ""
|
||||||
echo ""
|
echo ""
|
||||||
|
|||||||
0
wireguard_tools/management/__init__.py
Normal file
0
wireguard_tools/management/__init__.py
Normal file
0
wireguard_tools/management/commands/__init__.py
Normal file
0
wireguard_tools/management/commands/__init__.py
Normal file
32
wireguard_tools/management/commands/export_configs.py
Normal file
32
wireguard_tools/management/commands/export_configs.py
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
import os
|
||||||
|
|
||||||
|
from django.conf import settings
|
||||||
|
from django.core.management.base import BaseCommand
|
||||||
|
|
||||||
|
from wireguard_tools.views import export_firewall_configuration, export_wireguard_configuration
|
||||||
|
|
||||||
|
|
||||||
|
class Command(BaseCommand):
|
||||||
|
help = 'Export WireGuard, firewall and Caddy configuration files'
|
||||||
|
|
||||||
|
def handle(self, *args, **options):
|
||||||
|
self.stdout.write('Exporting WireGuard configuration...')
|
||||||
|
export_wireguard_configuration()
|
||||||
|
self.stdout.write(self.style.SUCCESS('WireGuard configuration exported.'))
|
||||||
|
|
||||||
|
self.stdout.write('Exporting firewall configuration...')
|
||||||
|
export_firewall_configuration()
|
||||||
|
self.stdout.write(self.style.SUCCESS('Firewall configuration exported.'))
|
||||||
|
|
||||||
|
if settings.CADDY_ENABLED:
|
||||||
|
self.stdout.write('Exporting Caddy configuration...')
|
||||||
|
try:
|
||||||
|
from app_gateway.caddy_config_export import export_caddy_config
|
||||||
|
export_caddy_config('/caddy_json_export/')
|
||||||
|
if settings.DEBUG:
|
||||||
|
export_caddy_config(os.path.join(settings.BASE_DIR, 'containers', 'caddy', 'config_files'))
|
||||||
|
self.stdout.write(self.style.SUCCESS('Caddy configuration exported.'))
|
||||||
|
except Exception as e:
|
||||||
|
self.stdout.write(self.style.WARNING(f'Failed to export Caddy configuration: {e}'))
|
||||||
|
else:
|
||||||
|
self.stdout.write('Skipping Caddy configuration export (CADDY_ENABLED is not set).')
|
||||||
Reference in New Issue
Block a user