From 93fd3789e2fd2fcfa0883cea360f9a8e33db17a8 Mon Sep 17 00:00:00 2001 From: SBCrumb Date: Wed, 22 Oct 2025 17:08:20 -0400 Subject: [PATCH] web: fix to run from web --- api/web_routes.py | 52 ++++++++++++++++++++++++++++++++++- nfoguard-web/static/js/app.js | 4 +-- 2 files changed, 53 insertions(+), 3 deletions(-) diff --git a/api/web_routes.py b/api/web_routes.py index 93df4d6..816aa4b 100644 --- a/api/web_routes.py +++ b/api/web_routes.py @@ -1321,4 +1321,54 @@ def register_web_routes(app, dependencies): session_manager.delete_session(session_token) response.delete_cookie("nfoguard_session") - return {"status": "logged_out", "message": "Session cleared"} \ No newline at end of file + return {"status": "logged_out", "message": "Session cleared"} + + # Manual scan endpoints (proxy to core container) + @app.post("/manual/scan") + async def api_manual_scan(request: Request): + """Proxy manual scan requests to core container""" + import httpx + import os + + # Get request body + try: + body = await request.json() + except: + body = {} + + # Get core container URL + core_host = os.environ.get("CORE_API_HOST", "nfoguard-core") + core_port = os.environ.get("CORE_API_PORT", "8080") + core_url = f"http://{core_host}:{core_port}/manual/scan" + + try: + async with httpx.AsyncClient(timeout=30.0) as client: + response = await client.post(core_url, json=body) + return response.json() + except httpx.TimeoutException: + raise HTTPException(status_code=504, detail="Core container request timed out") + except httpx.RequestError as e: + raise HTTPException(status_code=503, detail=f"Could not connect to core container: {str(e)}") + except Exception as e: + raise HTTPException(status_code=500, detail=f"Manual scan request failed: {str(e)}") + + @app.get("/api/scan/status") + async def api_scan_status(): + """Proxy scan status requests to core container""" + import httpx + import os + + # Get core container URL + core_host = os.environ.get("CORE_API_HOST", "nfoguard-core") + core_port = os.environ.get("CORE_API_PORT", "8080") + core_url = f"http://{core_host}:{core_port}/api/scan/status" + + try: + async with httpx.AsyncClient(timeout=10.0) as client: + response = await client.get(core_url) + return response.json() + except httpx.RequestError: + # If core is unreachable, return default status + return {"scanning": False, "message": "Core container unavailable"} + except Exception: + return {"scanning": False, "message": "Unable to check scan status"} \ No newline at end of file diff --git a/nfoguard-web/static/js/app.js b/nfoguard-web/static/js/app.js index 414a4d9..9793612 100644 --- a/nfoguard-web/static/js/app.js +++ b/nfoguard-web/static/js/app.js @@ -1517,8 +1517,8 @@ function handleDirectoryFormatting(event) { let scanStatusInterval = null; function updateScanStatus(message, isActive = false) { - const statusBanner = document.getElementById('scan-status-banner'); - const statusText = document.getElementById('scan-status-text'); + const statusBanner = document.getElementById('dashboard-scan-status'); + const statusText = document.getElementById('dashboard-scan-text'); if (!statusBanner || !statusText) { console.log('Scan status elements not found, skipping update');