From fcc5f2eb35c630c1e0b08a4752121187130bd845 Mon Sep 17 00:00:00 2001 From: pika Date: Sun, 30 Mar 2025 13:40:12 +0200 Subject: [PATCH] wip --- agent.py | 10 +++++----- app.py | 26 +++++++++++++++++--------- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/agent.py b/agent.py index b7a9226..6afdffd 100644 --- a/agent.py +++ b/agent.py @@ -134,12 +134,12 @@ def send_update(force=False): (current_time - last_send_time).total_seconds() < CHECK_INTERVAL): return - # Create the data payload + # Always include the server name in data payload data = { - "server": SERVER_NAME, + "server": SERVER_NAME, # Always include this "entries": current_data, "timestamp": current_time.isoformat(), - "type": SERVER_TYPE # Add the server type + "type": SERVER_TYPE } # Create authentication token @@ -158,8 +158,8 @@ def send_update(force=False): DASHBOARD_URL, json=data, headers=headers, - timeout=10, # Set a reasonable timeout - verify=VERIFY_SSL # Control SSL verification + timeout=10, + verify=VERIFY_SSL ) if response.status_code == 200: diff --git a/app.py b/app.py index 34bf5c3..be7a80d 100644 --- a/app.py +++ b/app.py @@ -20,8 +20,8 @@ DEBUG_MODE = os.getenv('DEBUG_MODE', 'false').lower() == 'true' CADDYFILE_PATH = "/app/Caddyfile" # Fixed internal path NGINX_CONFIG_PATH = os.getenv('NGINX_CONFIG_PATH', '/app/nginx/conf.d') # Path to nginx config directory -# Add SERVER_NAME environment variable near the top with other configs -SERVER_NAME = os.getenv('SERVER_NAME', 'Local Server') # Get server name from env variable +# Get server name from env variable for local configurations only +LOCAL_SERVER_NAME = os.getenv('SERVER_NAME', 'Local Server') # Setup logging logging.basicConfig( @@ -212,7 +212,15 @@ def update_proxies(): if not data or not isinstance(data, dict): return jsonify({"status": "error", "message": "Invalid data format"}), 400 - server_name = data.get("server", SERVER_NAME) # Default to SERVER_NAME if not provided + # Use the server name provided by the agent or a default agent name + # Do NOT default to LOCAL_SERVER_NAME which is for local configs only + server_name = data.get("server") + if not server_name: + # Generate a reasonable default name if agent doesn't provide one + agent_ip = request.remote_addr + server_name = f"Agent-{agent_ip}" + logger.warning(f"Agent did not provide server name, using: {server_name}") + entries = data.get("entries", {}) server_type = data.get("type", "caddy").lower() # Default to caddy if not specified @@ -262,15 +270,15 @@ def delete_server(): if USE_LOCAL_CADDYFILE: entries = parse_local_caddyfile() if entries: - caddy_proxies[SERVER_NAME] = entries - timestamps[SERVER_NAME] = datetime.now().strftime("%Y-%m-%d %H:%M:%S") + caddy_proxies[LOCAL_SERVER_NAME] = entries # Use LOCAL_SERVER_NAME for local configs + timestamps[LOCAL_SERVER_NAME] = datetime.now().strftime("%Y-%m-%d %H:%M:%S") logger.info(f"Loaded {len(entries)} entries from local Caddyfile") if USE_LOCAL_NGINX: entries = parse_nginx_configs() if entries: - nginx_proxies[f"{SERVER_NAME} Nginx"] = entries - timestamps[f"{SERVER_NAME} Nginx"] = datetime.now().strftime("%Y-%m-%d %H:%M:%S") + nginx_proxies[f"{LOCAL_SERVER_NAME} Nginx"] = entries # Use LOCAL_SERVER_NAME for Nginx too + timestamps[f"{LOCAL_SERVER_NAME} Nginx"] = datetime.now().strftime("%Y-%m-%d %H:%M:%S") logger.info(f"Loaded {len(entries)} entries from local Nginx configs") def signal_handler(sig, frame): @@ -286,8 +294,8 @@ if __name__ == '__main__': # Load it initially local_data = parse_local_caddyfile() if local_data: - caddy_proxies[SERVER_NAME] = local_data - timestamps[SERVER_NAME] = datetime.now().strftime("%Y-%m-%d %H:%M:%S") + caddy_proxies[LOCAL_SERVER_NAME] = local_data + timestamps[LOCAL_SERVER_NAME] = datetime.now().strftime("%Y-%m-%d %H:%M:%S") if not API_KEY: logger.warning("API_KEY not set - running without authentication!")