This commit is contained in:
pika 2025-03-30 13:40:12 +02:00
parent 9e295a6f18
commit fcc5f2eb35
2 changed files with 22 additions and 14 deletions

26
app.py
View file

@ -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!")