From 72ddf7a3ee2e8aea21b1d139585042527b78c649 Mon Sep 17 00:00:00 2001 From: pika Date: Mon, 24 Mar 2025 18:30:47 +0100 Subject: [PATCH] wip --- .env.example | 3 ++- agent.py | 20 ++++++++++++++++++-- compose.yml | 9 +++++++++ 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/.env.example b/.env.example index 7aecd36..b0427d5 100644 --- a/.env.example +++ b/.env.example @@ -9,4 +9,5 @@ DASHBOARD_URL=https://dashboard.example.com/api/update # Agent mode configurations # only if you want to change the internal path of the Caddyfile # SERVER_NAME=my-caddy-server # Optional - defaults to hostname -CHECK_INTERVAL=60 # Seconds between checks \ No newline at end of file +CHECK_INTERVAL=60 # Seconds between checks +VERIFY_SSL=true # Set to false to disable SSL certificate verification (insecure but useful for testing) \ No newline at end of file diff --git a/agent.py b/agent.py index 75b3b52..a8f5780 100644 --- a/agent.py +++ b/agent.py @@ -13,16 +13,18 @@ from datetime import datetime, timedelta from watchdog.observers import Observer from watchdog.events import FileSystemEventHandler from dotenv import load_dotenv +import urllib3 # Load environment variables load_dotenv() # Fixed configuration CADDYFILE_PATH = "/app/Caddyfile" # Fixed internal path -DASHBOARD_URL = os.getenv('DASHBOARD_URL') +DASHBOARD_URL = os.getenv('DASHBOARD_URL', 'http://caddydb-server:5000/api/update') SERVER_NAME = os.getenv('SERVER_NAME', socket.gethostname()) API_KEY = os.getenv('API_KEY') CHECK_INTERVAL = int(os.getenv('CHECK_INTERVAL', '60')) +VERIFY_SSL = os.getenv('VERIFY_SSL', 'true').lower() == 'true' # Setup logging logging.basicConfig( @@ -31,6 +33,19 @@ logging.basicConfig( ) logger = logging.getLogger('caddy-agent') +# Debug configuration +logger.info(f"Starting Caddy agent with configuration:") +logger.info(f"- DASHBOARD_URL: {DASHBOARD_URL}") +logger.info(f"- SERVER_NAME: {SERVER_NAME}") +logger.info(f"- CADDYFILE_PATH: {CADDYFILE_PATH}") +logger.info(f"- VERIFY_SSL: {VERIFY_SSL}") +logger.info(f"- API_KEY set: {'Yes' if API_KEY else 'No'}") + +# Disable SSL warnings if verification is disabled +if not VERIFY_SSL: + urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) + logger.warning("SSL verification is disabled - this is insecure!") + # Validate required configuration if not os.path.exists(CADDYFILE_PATH): logger.error(f"Caddyfile not found at {CADDYFILE_PATH}") @@ -128,7 +143,8 @@ def send_update(force=False): DASHBOARD_URL, json=data, headers=headers, - timeout=10 # Set a reasonable timeout + timeout=10, # Set a reasonable timeout + verify=VERIFY_SSL # Control SSL verification ) if response.status_code == 200: diff --git a/compose.yml b/compose.yml index 2218f86..9632621 100644 --- a/compose.yml +++ b/compose.yml @@ -11,6 +11,8 @@ services: - ./Caddyfile:/app/Caddyfile:ro command: server restart: unless-stopped + networks: + - caddy-network # Agent mode (example) caddydb-agent: @@ -22,5 +24,12 @@ services: - DASHBOARD_URL=http://caddydb-server:5000/api/update - SERVER_NAME=caddy-server-1 - CHECK_INTERVAL=60 + - VERIFY_SSL=false # Set to false if using self-signed certificates command: agent restart: unless-stopped + networks: + - caddy-network + +networks: + caddy-network: + driver: bridge