mirror of
https://github.com/eduardogsilva/wireguard_webadmin.git
synced 2026-11-21 04:23:15 +01:00
Each application host now selects how its TLS certificate is issued: self-signed, ACME HTTP challenge, or ACME DNS challenge using a stored DNS credential. ACME modes fall back to the internal CA when issuance fails, so hosts stay reachable with a browser warning instead of a TLS error. - Add DnsChallengeCredential model and provider registry (Cloudflare) - Add certificate_type and dns_credential to ApplicationHost - Sync WireGuard WebAdmin hosts from .env into the reserved application - Export per-host TLS settings to tls.json, read only by Caddy - Group hosts by certificate settings into separate Caddy site blocks - Build Caddy with the Cloudflare DNS module using xcaddy - Regenerate the Caddyfile without DNS challenge if validation fails
42 lines
1.3 KiB
Bash
42 lines
1.3 KiB
Bash
#!/bin/bash
|
|
|
|
set -eu
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
|
PYTHON="python3"
|
|
JSON_DIR="${JSON_DIR:-/caddy_json_export}"
|
|
CADDYFILE_PATH="${CADDYFILE_PATH:-/etc/caddy/Caddyfile}"
|
|
|
|
echo "==> Generating wireguard_webadmin.json..."
|
|
"$PYTHON" "${SCRIPT_DIR}/export_wireguard_webadmin_config.py"
|
|
|
|
generate_caddyfile() {
|
|
"$PYTHON" "${SCRIPT_DIR}/process_config.py"
|
|
# Validation output is not printed because provider errors may include credentials
|
|
if ! caddy validate --config "$CADDYFILE_PATH" --adapter caddyfile >/dev/null 2>&1; then
|
|
echo "Warning: generated Caddyfile is invalid, regenerating with DNS challenge disabled. Check the DNS credentials."
|
|
DISABLE_DNS_CHALLENGE=1 "$PYTHON" "${SCRIPT_DIR}/process_config.py"
|
|
fi
|
|
}
|
|
|
|
echo "==> Processing config files..."
|
|
generate_caddyfile
|
|
|
|
echo "==> Starting Caddy..."
|
|
caddy run --config "$CADDYFILE_PATH" --adapter caddyfile &
|
|
CADDY_PID=$!
|
|
|
|
sleep 2
|
|
|
|
echo "==> Watching ${JSON_DIR} for config changes..."
|
|
while true; do
|
|
inotifywait -qq -e close_write,moved_to,create "${JSON_DIR}/" --include '.*\.json$' 2>/dev/null || true
|
|
sleep 1
|
|
|
|
echo "==> Config change detected, reprocessing..."
|
|
generate_caddyfile
|
|
|
|
echo "==> Reloading Caddy..."
|
|
caddy reload --config "$CADDYFILE_PATH" --adapter caddyfile 2>/dev/null || echo "Warning: Caddy reload failed, will retry on next change."
|
|
done
|