This commit is contained in:
+15
-10
@@ -1364,29 +1364,34 @@ def register_web_routes(app, dependencies):
|
|||||||
|
|
||||||
@app.get("/api/scan/status")
|
@app.get("/api/scan/status")
|
||||||
async def 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.request
|
||||||
import urllib.error
|
import urllib.error
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import socket
|
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_host = os.environ.get("CORE_API_HOST", "nfoguard-core")
|
||||||
core_port = os.environ.get("CORE_API_PORT", "8080")
|
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:
|
try:
|
||||||
# Create request with timeout
|
# Try to reach core container to see if it's active
|
||||||
req = urllib.request.Request(core_url)
|
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=5) as response:
|
||||||
with urllib.request.urlopen(req, timeout=10) as response:
|
# Core is responsive, return basic status
|
||||||
response_data = response.read().decode('utf-8')
|
# TODO: Core container should implement proper scan status tracking
|
||||||
return json.loads(response_data)
|
return {
|
||||||
|
"scanning": False,
|
||||||
|
"message": "Scan status tracking not fully implemented - check core container logs"
|
||||||
|
}
|
||||||
|
|
||||||
except (urllib.error.URLError, socket.timeout):
|
except (urllib.error.URLError, socket.timeout):
|
||||||
# If core is unreachable, return default status
|
|
||||||
return {"scanning": False, "message": "Core container unavailable"}
|
return {"scanning": False, "message": "Core container unavailable"}
|
||||||
except Exception:
|
except Exception:
|
||||||
return {"scanning": False, "message": "Unable to check scan status"}
|
return {"scanning": False, "message": "Unable to check scan status"}
|
||||||
@@ -118,8 +118,8 @@ async function loadDashboard() {
|
|||||||
updateDashboardStats();
|
updateDashboardStats();
|
||||||
updateDashboardCharts();
|
updateDashboardCharts();
|
||||||
|
|
||||||
// Check if there's an ongoing scan when dashboard loads
|
// Note: Scan status tracking not implemented yet
|
||||||
await checkScanStatus();
|
// Real-time scan status would require core container modifications
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed to load dashboard:', error);
|
console.error('Failed to load dashboard:', error);
|
||||||
}
|
}
|
||||||
@@ -1443,8 +1443,13 @@ async function handleManualScan(event) {
|
|||||||
|
|
||||||
showToast(`✅ Manual scan initiated: ${result.message}`, 'success');
|
showToast(`✅ Manual scan initiated: ${result.message}`, 'success');
|
||||||
|
|
||||||
// Start polling for scan status
|
// Show scan status banner temporarily
|
||||||
startScanStatusPolling();
|
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) {
|
} catch (error) {
|
||||||
console.error('Manual scan failed:', error);
|
console.error('Manual scan failed:', error);
|
||||||
@@ -1486,8 +1491,13 @@ async function handleCustomScan(event) {
|
|||||||
|
|
||||||
showToast(`✅ Custom scan initiated: ${result.message}`, 'success');
|
showToast(`✅ Custom scan initiated: ${result.message}`, 'success');
|
||||||
|
|
||||||
// Start polling for scan status
|
// Show scan status banner temporarily
|
||||||
startScanStatusPolling();
|
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) {
|
} catch (error) {
|
||||||
console.error('Custom scan failed:', error);
|
console.error('Custom scan failed:', error);
|
||||||
@@ -1528,6 +1538,8 @@ function updateScanStatus(message, isActive = false) {
|
|||||||
const statusBanner = document.getElementById('dashboard-scan-status');
|
const statusBanner = document.getElementById('dashboard-scan-status');
|
||||||
const statusText = document.getElementById('dashboard-scan-text');
|
const statusText = document.getElementById('dashboard-scan-text');
|
||||||
|
|
||||||
|
console.log('updateScanStatus called:', { message, isActive, statusBanner: !!statusBanner, statusText: !!statusText });
|
||||||
|
|
||||||
if (!statusBanner || !statusText) {
|
if (!statusBanner || !statusText) {
|
||||||
console.log('Scan status elements not found, skipping update');
|
console.log('Scan status elements not found, skipping update');
|
||||||
return;
|
return;
|
||||||
@@ -1538,12 +1550,15 @@ function updateScanStatus(message, isActive = false) {
|
|||||||
if (isActive) {
|
if (isActive) {
|
||||||
statusBanner.className = 'scan-status-banner active';
|
statusBanner.className = 'scan-status-banner active';
|
||||||
statusBanner.style.display = 'block';
|
statusBanner.style.display = 'block';
|
||||||
|
console.log('Scan status banner activated:', message);
|
||||||
} else {
|
} else {
|
||||||
statusBanner.className = 'scan-status-banner';
|
statusBanner.className = 'scan-status-banner';
|
||||||
|
console.log('Scan status banner deactivated:', message);
|
||||||
// Don't hide completely, just mark as inactive
|
// Don't hide completely, just mark as inactive
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
if (statusBanner.className === 'scan-status-banner') {
|
if (statusBanner.className === 'scan-status-banner') {
|
||||||
statusBanner.style.display = 'none';
|
statusBanner.style.display = 'none';
|
||||||
|
console.log('Scan status banner hidden after timeout');
|
||||||
}
|
}
|
||||||
}, 3000);
|
}, 3000);
|
||||||
}
|
}
|
||||||
@@ -1551,13 +1566,16 @@ function updateScanStatus(message, isActive = false) {
|
|||||||
|
|
||||||
async function checkScanStatus() {
|
async function checkScanStatus() {
|
||||||
try {
|
try {
|
||||||
|
console.log('Checking scan status...');
|
||||||
const status = await apiCall('/api/scan/status');
|
const status = await apiCall('/api/scan/status');
|
||||||
|
console.log('Scan status response:', status);
|
||||||
|
|
||||||
if (status.scanning) {
|
if (status.scanning) {
|
||||||
updateScanStatus(status.message || 'Scan in progress...', true);
|
updateScanStatus(status.message || 'Scan in progress...', true);
|
||||||
|
|
||||||
// Start polling if not already polling
|
// Start polling if not already polling
|
||||||
if (!scanStatusInterval) {
|
if (!scanStatusInterval) {
|
||||||
|
console.log('Starting scan status polling from checkScanStatus');
|
||||||
startScanStatusPolling();
|
startScanStatusPolling();
|
||||||
}
|
}
|
||||||
return true; // Continue polling
|
return true; // Continue polling
|
||||||
|
|||||||
Reference in New Issue
Block a user