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

View file

@ -134,12 +134,12 @@ def send_update(force=False):
(current_time - last_send_time).total_seconds() < CHECK_INTERVAL): (current_time - last_send_time).total_seconds() < CHECK_INTERVAL):
return return
# Create the data payload # Always include the server name in data payload
data = { data = {
"server": SERVER_NAME, "server": SERVER_NAME, # Always include this
"entries": current_data, "entries": current_data,
"timestamp": current_time.isoformat(), "timestamp": current_time.isoformat(),
"type": SERVER_TYPE # Add the server type "type": SERVER_TYPE
} }
# Create authentication token # Create authentication token
@ -158,8 +158,8 @@ def send_update(force=False):
DASHBOARD_URL, DASHBOARD_URL,
json=data, json=data,
headers=headers, headers=headers,
timeout=10, # Set a reasonable timeout timeout=10,
verify=VERIFY_SSL # Control SSL verification verify=VERIFY_SSL
) )
if response.status_code == 200: if response.status_code == 200:

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 CADDYFILE_PATH = "/app/Caddyfile" # Fixed internal path
NGINX_CONFIG_PATH = os.getenv('NGINX_CONFIG_PATH', '/app/nginx/conf.d') # Path to nginx config directory 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 # Get server name from env variable for local configurations only
SERVER_NAME = os.getenv('SERVER_NAME', 'Local Server') # Get server name from env variable LOCAL_SERVER_NAME = os.getenv('SERVER_NAME', 'Local Server')
# Setup logging # Setup logging
logging.basicConfig( logging.basicConfig(
@ -212,7 +212,15 @@ def update_proxies():
if not data or not isinstance(data, dict): if not data or not isinstance(data, dict):
return jsonify({"status": "error", "message": "Invalid data format"}), 400 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", {}) entries = data.get("entries", {})
server_type = data.get("type", "caddy").lower() # Default to caddy if not specified server_type = data.get("type", "caddy").lower() # Default to caddy if not specified
@ -262,15 +270,15 @@ def delete_server():
if USE_LOCAL_CADDYFILE: if USE_LOCAL_CADDYFILE:
entries = parse_local_caddyfile() entries = parse_local_caddyfile()
if entries: if entries:
caddy_proxies[SERVER_NAME] = entries caddy_proxies[LOCAL_SERVER_NAME] = entries # Use LOCAL_SERVER_NAME for local configs
timestamps[SERVER_NAME] = datetime.now().strftime("%Y-%m-%d %H:%M:%S") timestamps[LOCAL_SERVER_NAME] = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
logger.info(f"Loaded {len(entries)} entries from local Caddyfile") logger.info(f"Loaded {len(entries)} entries from local Caddyfile")
if USE_LOCAL_NGINX: if USE_LOCAL_NGINX:
entries = parse_nginx_configs() entries = parse_nginx_configs()
if entries: if entries:
nginx_proxies[f"{SERVER_NAME} Nginx"] = entries nginx_proxies[f"{LOCAL_SERVER_NAME} Nginx"] = entries # Use LOCAL_SERVER_NAME for Nginx too
timestamps[f"{SERVER_NAME} Nginx"] = datetime.now().strftime("%Y-%m-%d %H:%M:%S") 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") logger.info(f"Loaded {len(entries)} entries from local Nginx configs")
def signal_handler(sig, frame): def signal_handler(sig, frame):
@ -286,8 +294,8 @@ if __name__ == '__main__':
# Load it initially # Load it initially
local_data = parse_local_caddyfile() local_data = parse_local_caddyfile()
if local_data: if local_data:
caddy_proxies[SERVER_NAME] = local_data caddy_proxies[LOCAL_SERVER_NAME] = local_data
timestamps[SERVER_NAME] = datetime.now().strftime("%Y-%m-%d %H:%M:%S") timestamps[LOCAL_SERVER_NAME] = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
if not API_KEY: if not API_KEY:
logger.warning("API_KEY not set - running without authentication!") logger.warning("API_KEY not set - running without authentication!")