From 0649895cb560759aec652b14941f5f4ebca4a247 Mon Sep 17 00:00:00 2001 From: SBCrumb Date: Wed, 22 Oct 2025 17:25:33 -0400 Subject: [PATCH] fix: dashboard status --- api/web_routes.py | 25 +++++++++++++++---------- nfoguard-web/static/js/app.js | 30 ++++++++++++++++++++++++------ 2 files changed, 39 insertions(+), 16 deletions(-) diff --git a/api/web_routes.py b/api/web_routes.py index 930194c..6395b55 100644 --- a/api/web_routes.py +++ b/api/web_routes.py @@ -1364,29 +1364,34 @@ def register_web_routes(app, dependencies): @app.get("/api/scan/status") async def api_scan_status(): - """Proxy scan status requests to core container""" + """Check scan status by looking at core container logs""" import urllib.request import urllib.error import json import os import socket + import time - # Get core container URL + # Get core container URL to check if it's responsive 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" + # For now, implement basic status tracking based on recent activity + # This is a simple implementation - ideally the core would track this try: - # Create request with timeout - req = urllib.request.Request(core_url) + # Try to reach core container to see if it's active + health_url = f"http://{core_host}:{core_port}/health" + req = urllib.request.Request(health_url) - # Make request with timeout - with urllib.request.urlopen(req, timeout=10) as response: - response_data = response.read().decode('utf-8') - return json.loads(response_data) + with urllib.request.urlopen(req, timeout=5) as response: + # Core is responsive, return basic status + # TODO: Core container should implement proper scan status tracking + return { + "scanning": False, + "message": "Scan status tracking not fully implemented - check core container logs" + } except (urllib.error.URLError, socket.timeout): - # 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 13dbd9e..56c884a 100644 --- a/nfoguard-web/static/js/app.js +++ b/nfoguard-web/static/js/app.js @@ -118,8 +118,8 @@ async function loadDashboard() { updateDashboardStats(); updateDashboardCharts(); - // Check if there's an ongoing scan when dashboard loads - await checkScanStatus(); + // Note: Scan status tracking not implemented yet + // Real-time scan status would require core container modifications } catch (error) { console.error('Failed to load dashboard:', error); } @@ -1443,8 +1443,13 @@ async function handleManualScan(event) { showToast(`✅ Manual scan initiated: ${result.message}`, 'success'); - // Start polling for scan status - startScanStatusPolling(); + // Show scan status banner temporarily + updateScanStatus('Manual scan started - check core container logs for progress', true); + + // Hide banner after 10 seconds since we don't have real-time tracking yet + setTimeout(() => { + updateScanStatus('Scan status tracking not available - check core container logs', false); + }, 10000); } catch (error) { console.error('Manual scan failed:', error); @@ -1486,8 +1491,13 @@ async function handleCustomScan(event) { showToast(`✅ Custom scan initiated: ${result.message}`, 'success'); - // Start polling for scan status - startScanStatusPolling(); + // Show scan status banner temporarily + updateScanStatus('Custom directory scan started - check core container logs for progress', true); + + // Hide banner after 10 seconds since we don't have real-time tracking yet + setTimeout(() => { + updateScanStatus('Scan status tracking not available - check core container logs', false); + }, 10000); } catch (error) { console.error('Custom scan failed:', error); @@ -1528,6 +1538,8 @@ function updateScanStatus(message, isActive = false) { const statusBanner = document.getElementById('dashboard-scan-status'); const statusText = document.getElementById('dashboard-scan-text'); + console.log('updateScanStatus called:', { message, isActive, statusBanner: !!statusBanner, statusText: !!statusText }); + if (!statusBanner || !statusText) { console.log('Scan status elements not found, skipping update'); return; @@ -1538,12 +1550,15 @@ function updateScanStatus(message, isActive = false) { if (isActive) { statusBanner.className = 'scan-status-banner active'; statusBanner.style.display = 'block'; + console.log('Scan status banner activated:', message); } else { statusBanner.className = 'scan-status-banner'; + console.log('Scan status banner deactivated:', message); // Don't hide completely, just mark as inactive setTimeout(() => { if (statusBanner.className === 'scan-status-banner') { statusBanner.style.display = 'none'; + console.log('Scan status banner hidden after timeout'); } }, 3000); } @@ -1551,13 +1566,16 @@ function updateScanStatus(message, isActive = false) { async function checkScanStatus() { try { + console.log('Checking scan status...'); const status = await apiCall('/api/scan/status'); + console.log('Scan status response:', status); if (status.scanning) { updateScanStatus(status.message || 'Scan in progress...', true); // Start polling if not already polling if (!scanStatusInterval) { + console.log('Starting scan status polling from checkScanStatus'); startScanStatusPolling(); } return true; // Continue polling