web: fix to run from web
This commit is contained in:
@@ -1322,3 +1322,53 @@ def register_web_routes(app, dependencies):
|
|||||||
|
|
||||||
response.delete_cookie("nfoguard_session")
|
response.delete_cookie("nfoguard_session")
|
||||||
return {"status": "logged_out", "message": "Session cleared"}
|
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"}
|
||||||
@@ -1517,8 +1517,8 @@ function handleDirectoryFormatting(event) {
|
|||||||
let scanStatusInterval = null;
|
let scanStatusInterval = null;
|
||||||
|
|
||||||
function updateScanStatus(message, isActive = false) {
|
function updateScanStatus(message, isActive = false) {
|
||||||
const statusBanner = document.getElementById('scan-status-banner');
|
const statusBanner = document.getElementById('dashboard-scan-status');
|
||||||
const statusText = document.getElementById('scan-status-text');
|
const statusText = document.getElementById('dashboard-scan-text');
|
||||||
|
|
||||||
if (!statusBanner || !statusText) {
|
if (!statusBanner || !statusText) {
|
||||||
console.log('Scan status elements not found, skipping update');
|
console.log('Scan status elements not found, skipping update');
|
||||||
|
|||||||
Reference in New Issue
Block a user