diff --git a/.env.example b/.env.example index e2c2ed6..5985048 100644 --- a/.env.example +++ b/.env.example @@ -6,6 +6,16 @@ DEBUG_MODE=False # Choose a timezone from https://en.wikipedia.org/wiki/List_of_tz_database_time_zones TIMEZONE=America/Sao_Paulo +# WireGuard status caching settings +# This improves performance by reducing the number of calls to `wg` command and storing recent results. +# WIREGUARD_STATUS_CACHE_ENABLED=True +# +# How many cached WireGuard status snapshots should be preloaded on page load. +# This allows traffic charts to be displayed already populated instead of starting empty. +# Lower this value if the initial peer list feels slow. +# 0 = disable preload, 9 = fully prefill traffic charts.# +# WIREGUARD_STATUS_CACHE_WEB_LOAD_PREVIOUS_COUNT=9 + # If you need additional hosts to be allowed, you can specify them here. # The SERVER_ADDRESS will always be allowed. # Example: EXTRA_ALLOWED_HOSTS=app1.example.com,app2.example.com:8443,app3.example.com diff --git a/docker-compose-no-nginx-dev.yml b/docker-compose-no-nginx-dev.yml index 9763eb3..c177c95 100644 --- a/docker-compose-no-nginx-dev.yml +++ b/docker-compose-no-nginx-dev.yml @@ -12,6 +12,8 @@ services: - COMPOSE_VERSION=03r - TZ=${TIMEZONE} - EXTRA_ALLOWED_HOSTS=${EXTRA_ALLOWED_HOSTS} + - WIREGUARD_STATUS_CACHE_ENABLED=${WIREGUARD_STATUS_CACHE_ENABLED} + - WIREGUARD_STATUS_CACHE_WEB_LOAD_PREVIOUS_COUNT=${WIREGUARD_STATUS_CACHE_WEB_LOAD_PREVIOUS_COUNT} volumes: - wireguard:/etc/wireguard - static_volume:/app_static_files/ diff --git a/docker-compose-no-nginx.yml b/docker-compose-no-nginx.yml index fd45e5a..e1a37d9 100644 --- a/docker-compose-no-nginx.yml +++ b/docker-compose-no-nginx.yml @@ -10,6 +10,8 @@ services: - COMPOSE_VERSION=03r - TZ=${TIMEZONE} - EXTRA_ALLOWED_HOSTS=${EXTRA_ALLOWED_HOSTS} + - WIREGUARD_STATUS_CACHE_ENABLED=${WIREGUARD_STATUS_CACHE_ENABLED} + - WIREGUARD_STATUS_CACHE_WEB_LOAD_PREVIOUS_COUNT=${WIREGUARD_STATUS_CACHE_WEB_LOAD_PREVIOUS_COUNT} volumes: - wireguard:/etc/wireguard - static_volume:/app_static_files/ diff --git a/docker-compose.yml b/docker-compose.yml index 67636e7..56c29ee 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -10,6 +10,8 @@ services: - COMPOSE_VERSION=03r - TZ=${TIMEZONE} - EXTRA_ALLOWED_HOSTS=${EXTRA_ALLOWED_HOSTS} + - WIREGUARD_STATUS_CACHE_ENABLED=${WIREGUARD_STATUS_CACHE_ENABLED} + - WIREGUARD_STATUS_CACHE_WEB_LOAD_PREVIOUS_COUNT=${WIREGUARD_STATUS_CACHE_WEB_LOAD_PREVIOUS_COUNT} volumes: - wireguard:/etc/wireguard - static_volume:/app_static_files/ diff --git a/entrypoint.sh b/entrypoint.sh index 1b0e5de..a75f3f5 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -39,10 +39,17 @@ CSRF_TRUSTED_ORIGINS = ['http://wireguard-webadmin', 'https://$SERVER_ADDRESS'${ SECRET_KEY = '$(openssl rand -base64 32)' EOL -if [ -n "$TZ" ]; then - echo "TIME_ZONE = '$TZ'" >> /app/wireguard_webadmin/production_settings.py +if [ -n "${TZ:-}" ]; then + echo "TIME_ZONE = '${TZ}'" >> /app/wireguard_webadmin/production_settings.py fi +if [[ "${WIREGUARD_STATUS_CACHE_ENABLED,,}" == "false" ]]; then + echo "WIREGUARD_STATUS_CACHE_ENABLED = False" >> /app/wireguard_webadmin/production_settings.py +fi + +if [ -n "${WIREGUARD_STATUS_CACHE_WEB_LOAD_PREVIOUS_COUNT:-}" ]; then + echo "WIREGUARD_STATUS_CACHE_WEB_LOAD_PREVIOUS_COUNT = ${WIREGUARD_STATUS_CACHE_WEB_LOAD_PREVIOUS_COUNT}" >> /app/wireguard_webadmin/production_settings.py +fi if [[ "${DEV_MODE,,}" != "true" ]]; then sed -i "/^ path('admin\/', admin.site.urls),/s/^ / # /" /app/wireguard_webadmin/urls.py diff --git a/templates/wireguard/wireguard_peer_list.html b/templates/wireguard/wireguard_peer_list.html index 3aa1449..a878785 100644 --- a/templates/wireguard/wireguard_peer_list.html +++ b/templates/wireguard/wireguard_peer_list.html @@ -379,6 +379,7 @@