From 9e295a6f188afffdade7ef79f6de721646ce5fe6 Mon Sep 17 00:00:00 2001 From: pika Date: Mon, 24 Mar 2025 20:05:14 +0100 Subject: [PATCH] wip --- app.py | 21 ++++++++------ templates/dashboard.html | 61 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 73 insertions(+), 9 deletions(-) diff --git a/app.py b/app.py index 9272587..34bf5c3 100644 --- a/app.py +++ b/app.py @@ -20,6 +20,9 @@ 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 + # Setup logging logging.basicConfig( level=logging.DEBUG if DEBUG_MODE else logging.INFO, @@ -181,7 +184,9 @@ def index(): caddy_count=stats['caddy_servers'], nginx_count=stats['nginx_servers'], domain_count=stats['total_domains'], - last_update=stats['last_update']) + last_update=stats['last_update'], + caddy_proxies=caddy_proxies, # Pass all proxies data + nginx_proxies=nginx_proxies) # Pass all proxies data @app.route('/caddy') def caddy_dashboard(): @@ -207,7 +212,7 @@ 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", "Local Server") # Default to 'Local Server' if not provided + server_name = data.get("server", SERVER_NAME) # Default to SERVER_NAME if not provided entries = data.get("entries", {}) server_type = data.get("type", "caddy").lower() # Default to caddy if not specified @@ -257,15 +262,15 @@ def delete_server(): if USE_LOCAL_CADDYFILE: entries = parse_local_caddyfile() if entries: - caddy_proxies["Local Server"] = entries - timestamps["Local Server"] = datetime.now().strftime("%Y-%m-%d %H:%M:%S") + caddy_proxies[SERVER_NAME] = entries + timestamps[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["Local Nginx"] = entries - timestamps["Local Nginx"] = datetime.now().strftime("%Y-%m-%d %H:%M:%S") + nginx_proxies[f"{SERVER_NAME} Nginx"] = entries + timestamps[f"{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): @@ -281,8 +286,8 @@ if __name__ == '__main__': # Load it initially local_data = parse_local_caddyfile() if local_data: - caddy_proxies["Local Server"] = local_data - timestamps["Local Server"] = datetime.now().strftime("%Y-%m-%d %H:%M:%S") + caddy_proxies[SERVER_NAME] = local_data + timestamps[SERVER_NAME] = datetime.now().strftime("%Y-%m-%d %H:%M:%S") if not API_KEY: logger.warning("API_KEY not set - running without authentication!") diff --git a/templates/dashboard.html b/templates/dashboard.html index ecadceb..5e633cb 100644 --- a/templates/dashboard.html +++ b/templates/dashboard.html @@ -104,7 +104,7 @@ -
+
+ + +
+
+

Active Domains

+

All configured domains across servers

+
+ +
+ {% set domain_list = [] %} + {% for server_type, servers in [('caddy', caddy_proxies), ('nginx', nginx_proxies)] %} + {% for server, domains in servers.items() %} + {% for domain, target in domains.items() %} + {% do domain_list.append((domain, target, server, server_type)) %} + {% endfor %} + {% endfor %} + {% endfor %} + + {% for domain, target, server, server_type in domain_list[:20] %} +
+
+
+ +
+
+ + {{ domain }} + +

{{ server }}

+
+
+
+ {{ target }} + + {{ server_type }} + +
+
+ {% endfor %} + + {% if domain_list|length == 0 %} +
+

No domains configured yet

+
+ {% endif %} +
+ + {% if domain_list|length > 20 %} + + {% endif %} +