This repository has been archived on 2025-12-04. You can view files and clone it, but cannot push or open issues or pull requests.
Files
wilcon-agent/wilcon.py
2025-06-29 08:33:19 +02:00

50 lines
1.6 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# wilcon.py
# Version 0.3.4 – mit API-Key-Schutz + CORS für 192.168.13.0/24
import os
from fastapi import FastAPI, Header, HTTPException, Depends
from fastapi.middleware.cors import CORSMiddleware
from sysinfo import get_hardware_info, set_debug_mode as set_sysinfo_debug_mode
from netinf import get_network_info, set_debug_mode as set_netinf_debug_mode
from proginfo import get_process_info, set_debug_mode as set_proginfo_debug_mode
app = FastAPI(
title="Wilcon Client Agent",
description="API für Client-System-, Netzwerk- und Prozessinformationen.",
version="0.3.4"
)
# --- API-Key-Schutz ---
API_KEY = os.getenv("WILCON_API_KEY", "test123") # In .env oder als Umgebungsvariable setzen
def verify_api_key(x_api_key: str = Header(...)):
if x_api_key != API_KEY:
raise HTTPException(status_code=403, detail="Zugriff verweigert")
# --- CORS-Konfiguration für gesamtes 192.168.13.0/24-Netzwerk ---
app.add_middleware(
CORSMiddleware,
allow_origin_regex=r"http://192\.168\.13\.\d{1,3}(:\d+)?",
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
# --- Endpunkte ---
@app.get("/sysinfo")
async def get_sysinfo_endpoint(_: str = Depends(verify_api_key)):
return get_hardware_info()
@app.get("/netinfo")
async def get_netinfo_endpoint(_: str = Depends(verify_api_key)):
return get_network_info()
@app.get("/procinfo")
async def get_procinfo_endpoint(_: str = Depends(verify_api_key)):
return get_process_info()
# Optional Debug-Modus einschalten
# set_sysinfo_debug_mode(True)
# set_netinf_debug_mode(True)
# set_proginfo_debug_mode(True)