Spaces:
Running on CPU Upgrade
Running on CPU Upgrade
Update frontend/src/pages/OrganizationPage.jsx
Browse files- frontend/src/pages/OrganizationPage.jsx +378 -373
frontend/src/pages/OrganizationPage.jsx
CHANGED
|
@@ -1,373 +1,378 @@
|
|
| 1 |
-
import React, { useState, useEffect, useCallback } from 'react';
|
| 2 |
-
import { useAuth } from '../components/AuthContext';
|
| 3 |
-
import { Shield, Activity, Users, Globe, Lock, ShieldAlert, ArrowLeft, BarChart3, PieChart as PieChartIcon } from 'lucide-react';
|
| 4 |
-
import { useNavigate } from 'react-router-dom';
|
| 5 |
-
import { BarChart, Bar, XAxis, YAxis, CartesianGrid, Tooltip as RechartsTooltip, ResponsiveContainer, LineChart, Line, PieChart, Pie, Cell, Legend, LabelList, ComposedChart } from 'recharts';
|
| 6 |
-
|
| 7 |
-
const SEVERITY_COLORS = ['#EF4444', '#F97316', '#EAB308', '#3B82F6']; // Critical, High, Medium, Low
|
| 8 |
-
const SCAN_TYPE_COLORS = ['#3B82F6', '#8B5CF6', '#10B981', '#F59E0B'];
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
//
|
| 79 |
-
const
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
//
|
| 120 |
-
const
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
});
|
| 148 |
-
const
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
<
|
| 171 |
-
<
|
| 172 |
-
|
| 173 |
-
<
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
<
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
{
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
<
|
| 190 |
-
<
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
>
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
<
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
|
| 240 |
-
|
| 241 |
-
|
| 242 |
-
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
<
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
|
| 251 |
-
|
| 252 |
-
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
|
| 256 |
-
|
| 257 |
-
|
| 258 |
-
|
| 259 |
-
|
| 260 |
-
|
| 261 |
-
|
| 262 |
-
<
|
| 263 |
-
|
| 264 |
-
|
| 265 |
-
|
| 266 |
-
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
|
| 283 |
-
|
| 284 |
-
|
| 285 |
-
|
| 286 |
-
|
| 287 |
-
|
| 288 |
-
<
|
| 289 |
-
|
| 290 |
-
|
| 291 |
-
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
|
| 296 |
-
|
| 297 |
-
|
| 298 |
-
|
| 299 |
-
|
| 300 |
-
|
| 301 |
-
|
| 302 |
-
|
| 303 |
-
|
| 304 |
-
|
| 305 |
-
|
| 306 |
-
|
| 307 |
-
|
| 308 |
-
|
| 309 |
-
|
| 310 |
-
|
| 311 |
-
|
| 312 |
-
|
| 313 |
-
<
|
| 314 |
-
|
| 315 |
-
|
| 316 |
-
|
| 317 |
-
|
| 318 |
-
|
| 319 |
-
|
| 320 |
-
|
| 321 |
-
|
| 322 |
-
|
| 323 |
-
|
| 324 |
-
|
| 325 |
-
|
| 326 |
-
|
| 327 |
-
|
| 328 |
-
|
| 329 |
-
|
| 330 |
-
|
| 331 |
-
</
|
| 332 |
-
<
|
| 333 |
-
|
| 334 |
-
</
|
| 335 |
-
|
| 336 |
-
|
| 337 |
-
|
| 338 |
-
|
| 339 |
-
|
| 340 |
-
|
| 341 |
-
|
| 342 |
-
|
| 343 |
-
|
| 344 |
-
|
| 345 |
-
|
| 346 |
-
|
| 347 |
-
|
| 348 |
-
|
| 349 |
-
|
| 350 |
-
|
| 351 |
-
|
| 352 |
-
|
| 353 |
-
|
| 354 |
-
|
| 355 |
-
|
| 356 |
-
|
| 357 |
-
|
| 358 |
-
|
| 359 |
-
|
| 360 |
-
|
| 361 |
-
</
|
| 362 |
-
|
| 363 |
-
|
| 364 |
-
|
| 365 |
-
|
| 366 |
-
|
| 367 |
-
|
| 368 |
-
|
| 369 |
-
|
| 370 |
-
|
| 371 |
-
|
| 372 |
-
|
| 373 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import React, { useState, useEffect, useCallback } from 'react';
|
| 2 |
+
import { useAuth } from '../components/AuthContext';
|
| 3 |
+
import { Shield, Activity, Users, Globe, Lock, ShieldAlert, ArrowLeft, BarChart3, PieChart as PieChartIcon } from 'lucide-react';
|
| 4 |
+
import { useNavigate } from 'react-router-dom';
|
| 5 |
+
import { BarChart, Bar, XAxis, YAxis, CartesianGrid, Tooltip as RechartsTooltip, ResponsiveContainer, LineChart, Line, PieChart, Pie, Cell, Legend, LabelList, ComposedChart } from 'recharts';
|
| 6 |
+
|
| 7 |
+
const SEVERITY_COLORS = ['#EF4444', '#F97316', '#EAB308', '#3B82F6']; // Critical, High, Medium, Low
|
| 8 |
+
const SCAN_TYPE_COLORS = ['#3B82F6', '#8B5CF6', '#10B981', '#F59E0B'];
|
| 9 |
+
|
| 10 |
+
const CustomChartTooltip = ({ active, payload, label }) => {
|
| 11 |
+
if (active && payload && payload.length) {
|
| 12 |
+
return (
|
| 13 |
+
<div className="bg-[#0f172a] border border-[#334155] rounded-lg px-3 py-1.5 shadow-xl text-left pointer-events-none">
|
| 14 |
+
{label && <div className="text-[12px] font-bold text-sky-400 leading-tight mb-1">{label}</div>}
|
| 15 |
+
{payload.map((item, index) => (
|
| 16 |
+
<div key={index} className="text-[12px] font-medium text-slate-200 leading-tight">
|
| 17 |
+
<span style={{ color: item.color || '#38bdf8' }}>{item.name || item.dataKey}</span> : <span className="font-bold text-white">{item.value}</span>
|
| 18 |
+
</div>
|
| 19 |
+
))}
|
| 20 |
+
</div>
|
| 21 |
+
);
|
| 22 |
+
}
|
| 23 |
+
return null;
|
| 24 |
+
};
|
| 25 |
+
|
| 26 |
+
export const OrganizationPage = () => {
|
| 27 |
+
const { user, token } = useAuth();
|
| 28 |
+
const navigate = useNavigate();
|
| 29 |
+
const [loading, setLoading] = useState(true);
|
| 30 |
+
|
| 31 |
+
const [summaryData, setSummaryData] = useState(null);
|
| 32 |
+
const [scanHistory, setScanHistory] = useState([]);
|
| 33 |
+
const [filterOrg, setFilterOrg] = useState('All');
|
| 34 |
+
const [filterWebsite, setFilterWebsite] = useState('All');
|
| 35 |
+
|
| 36 |
+
const getToken = useCallback(() => localStorage.getItem('wss_token') || localStorage.getItem('wss_token') || token, [token]);
|
| 37 |
+
|
| 38 |
+
const fetchData = useCallback(async () => {
|
| 39 |
+
try {
|
| 40 |
+
const activeToken = getToken();
|
| 41 |
+
const [summaryRes, historyRes] = await Promise.all([
|
| 42 |
+
fetch('/api/vulnerabilities/summary?global=true', { headers: { 'Authorization': `Bearer ${activeToken}` } }),
|
| 43 |
+
fetch('/api/scans/history?global=true&limit=100', { headers: { 'Authorization': `Bearer ${activeToken}` } })
|
| 44 |
+
]);
|
| 45 |
+
|
| 46 |
+
if (!summaryRes.ok || !historyRes.ok) return;
|
| 47 |
+
|
| 48 |
+
const summaryJson = await summaryRes.json();
|
| 49 |
+
const historyJson = await historyRes.json();
|
| 50 |
+
|
| 51 |
+
setSummaryData(summaryJson.summary);
|
| 52 |
+
setScanHistory(historyJson.scans || []);
|
| 53 |
+
} catch (err) {
|
| 54 |
+
console.error("Failed to fetch organization data:", err);
|
| 55 |
+
} finally {
|
| 56 |
+
setLoading(false);
|
| 57 |
+
}
|
| 58 |
+
}, [getToken]);
|
| 59 |
+
|
| 60 |
+
useEffect(() => {
|
| 61 |
+
fetchData();
|
| 62 |
+
const interval = setInterval(fetchData, 5000); // Polling real-time data every 5s
|
| 63 |
+
return () => clearInterval(interval);
|
| 64 |
+
}, [fetchData]);
|
| 65 |
+
|
| 66 |
+
if (loading) {
|
| 67 |
+
return (
|
| 68 |
+
<div className="flex h-[80vh] items-center justify-center">
|
| 69 |
+
<div className="animate-spin rounded-full h-12 w-12 border-b-2 border-primary"></div>
|
| 70 |
+
</div>
|
| 71 |
+
);
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
// Extract Unique Orgs & Websites for filters
|
| 75 |
+
const uniqueOrgs = [...new Set(scanHistory.map(s => s.org_name).filter(Boolean))];
|
| 76 |
+
const uniqueWebsites = [...new Set(scanHistory.map(s => s.target_url).filter(Boolean))];
|
| 77 |
+
|
| 78 |
+
// Apply Filters
|
| 79 |
+
const filteredScans = scanHistory
|
| 80 |
+
.filter(scan => filterOrg === 'All' || scan.org_name === filterOrg)
|
| 81 |
+
.filter(scan => filterWebsite === 'All' || scan.target_url === filterWebsite);
|
| 82 |
+
|
| 83 |
+
// Derive metrics dynamically from filteredScans
|
| 84 |
+
const completedScans = filteredScans.filter(s => s.status === 'completed' && s.security_score !== null);
|
| 85 |
+
const score = completedScans.length > 0
|
| 86 |
+
? Math.round(completedScans.reduce((sum, s) => sum + s.security_score, 0) / completedScans.length)
|
| 87 |
+
: 100;
|
| 88 |
+
|
| 89 |
+
const totalVulnerabilities = filteredScans.reduce((sum, s) => {
|
| 90 |
+
const vc = s.vulnerabilities_count;
|
| 91 |
+
return sum + (vc ? (vc.critical + vc.high + vc.medium + vc.low) : (s.total_vulnerabilities || 0));
|
| 92 |
+
}, 0);
|
| 93 |
+
|
| 94 |
+
// Active Assets (unique target URLs)
|
| 95 |
+
const activeAssets = new Set(filteredScans.map(s => s.target_url).filter(Boolean)).size;
|
| 96 |
+
|
| 97 |
+
// Vulnerability Distribution Pie Chart Data
|
| 98 |
+
const vulnCounts = filteredScans.reduce((acc, s) => {
|
| 99 |
+
if (s.vulnerabilities_count) {
|
| 100 |
+
acc.critical += s.vulnerabilities_count.critical || 0;
|
| 101 |
+
acc.high += s.vulnerabilities_count.high || 0;
|
| 102 |
+
acc.medium += s.vulnerabilities_count.medium || 0;
|
| 103 |
+
acc.low += s.vulnerabilities_count.low || 0;
|
| 104 |
+
}
|
| 105 |
+
return acc;
|
| 106 |
+
}, { critical: 0, high: 0, medium: 0, low: 0 });
|
| 107 |
+
|
| 108 |
+
const vulnerabilityTypes = [
|
| 109 |
+
{ name: 'Critical', value: vulnCounts.critical },
|
| 110 |
+
{ name: 'High', value: vulnCounts.high },
|
| 111 |
+
{ name: 'Medium', value: vulnCounts.medium },
|
| 112 |
+
{ name: 'Low', value: vulnCounts.low },
|
| 113 |
+
].filter(v => v.value > 0);
|
| 114 |
+
|
| 115 |
+
if (vulnerabilityTypes.length === 0) {
|
| 116 |
+
vulnerabilityTypes.push({ name: 'Clean / No Risks', value: 1 });
|
| 117 |
+
}
|
| 118 |
+
|
| 119 |
+
// Risk Score Trend (Last 10 Scans)
|
| 120 |
+
const riskTrendData = [...filteredScans]
|
| 121 |
+
.filter(s => s.started_at)
|
| 122 |
+
.sort((a, b) => new Date(a.started_at) - new Date(b.started_at))
|
| 123 |
+
.slice(-10)
|
| 124 |
+
.map((scan, index) => {
|
| 125 |
+
const totalVulns = scan.vulnerabilities_count
|
| 126 |
+
? (scan.vulnerabilities_count.critical + scan.vulnerabilities_count.high + scan.vulnerabilities_count.medium + scan.vulnerabilities_count.low)
|
| 127 |
+
: (scan.total_vulnerabilities || 0);
|
| 128 |
+
return {
|
| 129 |
+
name: scan.target_url ? scan.target_url.replace('https://', '').replace('http://', '').replace(/\/$/, '') : `Scan ${index + 1}`,
|
| 130 |
+
securityScore: Math.round(scan.security_score ?? 100),
|
| 131 |
+
vulnerabilities: totalVulns
|
| 132 |
+
};
|
| 133 |
+
});
|
| 134 |
+
|
| 135 |
+
// Group Scans by Month for Bar Chart
|
| 136 |
+
const monthsData = {};
|
| 137 |
+
filteredScans.forEach(scan => {
|
| 138 |
+
const d = new Date(scan.started_at || scan.created_at);
|
| 139 |
+
if (isNaN(d.getTime())) return;
|
| 140 |
+
const month = d.toLocaleString('en-US', { month: 'short', year: 'numeric' });
|
| 141 |
+
if (!monthsData[month]) monthsData[month] = { month, scans: 0, issues: 0 };
|
| 142 |
+
monthsData[month].scans += 1;
|
| 143 |
+
const totalVulns = scan.vulnerabilities_count
|
| 144 |
+
? (scan.vulnerabilities_count.critical + scan.vulnerabilities_count.high + scan.vulnerabilities_count.medium + scan.vulnerabilities_count.low)
|
| 145 |
+
: (scan.total_vulnerabilities || 0);
|
| 146 |
+
monthsData[month].issues += totalVulns;
|
| 147 |
+
});
|
| 148 |
+
const scanHistoryChartData = Object.values(monthsData);
|
| 149 |
+
|
| 150 |
+
// Top Vulnerability Categories Chart Data
|
| 151 |
+
const categoriesData = Object.entries(summaryData?.by_category || {})
|
| 152 |
+
.map(([cat, count]) => ({ category: cat || 'General Security', count }))
|
| 153 |
+
.sort((a, b) => b.count - a.count)
|
| 154 |
+
.slice(0, 6);
|
| 155 |
+
|
| 156 |
+
// Extract Unique Orgs & Websites for filters is moved up.
|
| 157 |
+
|
| 158 |
+
// Scan Types Breakdown Chart Data (Filtered)
|
| 159 |
+
const scanTypeCounts = {};
|
| 160 |
+
filteredScans.forEach(scan => {
|
| 161 |
+
const type = scan.scan_type ? (scan.scan_type.charAt(0).toUpperCase() + scan.scan_type.slice(1)) + ' Scan' : 'Advanced Scan';
|
| 162 |
+
scanTypeCounts[type] = (scanTypeCounts[type] || 0) + 1;
|
| 163 |
+
});
|
| 164 |
+
const scanTypeChartData = Object.entries(scanTypeCounts).map(([name, value]) => ({ name, value }));
|
| 165 |
+
|
| 166 |
+
return (
|
| 167 |
+
<div className="w-full text-on-surface animate-fade-in pb-xl">
|
| 168 |
+
<div className="flex flex-col md:flex-row md:items-center justify-between mb-xl gap-sm">
|
| 169 |
+
<div>
|
| 170 |
+
<h1 className="text-[28px] font-extrabold font-display tracking-tight brand-gradient flex items-center gap-2">
|
| 171 |
+
<Globe className="w-8 h-8 text-primary" />
|
| 172 |
+
LarShield Global Management
|
| 173 |
+
</h1>
|
| 174 |
+
<p className="text-on-surface-variant text-[14px] mt-1">Centralized oversight for all client organizations, scans, and security nodes.</p>
|
| 175 |
+
</div>
|
| 176 |
+
<div className="flex gap-sm flex-wrap">
|
| 177 |
+
<button onClick={fetchData} className="flex items-center px-md py-sm bg-surface-container border border-outline-variant text-on-surface rounded-lg hover:bg-surface-container-high transition-colors font-bold text-[13.5px] cursor-pointer">
|
| 178 |
+
<Activity className={`w-4 h-4 mr-2 text-primary ${loading ? 'animate-spin' : ''}`} /> Sync Metrics
|
| 179 |
+
</button>
|
| 180 |
+
<button onClick={() => navigate('/super-admin')} className="flex items-center px-md py-sm bg-surface-container border border-outline-variant text-on-surface rounded-lg hover:bg-surface-container-high transition-colors font-bold text-[13.5px] cursor-pointer">
|
| 181 |
+
<Lock className="w-4 h-4 mr-2 text-primary" /> Manage Pricing
|
| 182 |
+
</button>
|
| 183 |
+
<button onClick={() => navigate('/organization')} className="flex items-center px-md py-sm bg-surface-container border border-outline-variant text-on-surface rounded-lg hover:bg-surface-container-high transition-colors font-bold text-[13.5px] cursor-pointer">
|
| 184 |
+
<Activity className="w-4 h-4 mr-2 text-primary" /> Org Dashboard
|
| 185 |
+
</button>
|
| 186 |
+
<button onClick={() => navigate('/super-admin/logs')} className="flex items-center px-md py-sm bg-surface-container border border-outline-variant text-on-surface rounded-lg hover:bg-surface-container-high transition-colors font-bold text-[13.5px] cursor-pointer">
|
| 187 |
+
<ShieldAlert className="w-4 h-4 mr-2 text-primary" /> Logs & Threats
|
| 188 |
+
</button>
|
| 189 |
+
<button onClick={() => navigate(-1)} className="flex items-center px-md py-sm bg-primary text-white rounded-lg hover:brightness-110 transition-all font-bold text-[13.5px] border-0 cursor-pointer shadow-md shadow-primary/20">
|
| 190 |
+
<ArrowLeft className="w-4 h-4 mr-2" /> Back
|
| 191 |
+
</button>
|
| 192 |
+
</div>
|
| 193 |
+
</div>
|
| 194 |
+
|
| 195 |
+
|
| 196 |
+
|
| 197 |
+
{/* Top Metrics Grid */}
|
| 198 |
+
<div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-md mb-xl">
|
| 199 |
+
{[
|
| 200 |
+
{ title: 'Security Score', value: `${score}/100`, icon: Shield, color: score > 80 ? 'text-green-500' : score > 50 ? 'text-orange-500' : 'text-error', bg: score > 80 ? 'bg-green-500/10' : score > 50 ? 'bg-orange-500/10' : 'bg-error/10', border: score > 80 ? 'border-green-500/20' : score > 50 ? 'border-orange-500/20' : 'border-error/20' },
|
| 201 |
+
{ title: 'Active Assets', value: activeAssets.toString(), icon: Globe, color: 'text-blue-500', bg: 'bg-blue-500/10', border: 'border-blue-500/20' },
|
| 202 |
+
{ title: 'Total Scans', value: filteredScans.length.toString(), icon: Activity, color: 'text-purple-500', bg: 'bg-purple-500/10', border: 'border-purple-500/20' },
|
| 203 |
+
{ title: 'Open Risks', value: totalVulnerabilities.toString(), icon: ShieldAlert, color: totalVulnerabilities > 0 ? 'text-orange-500' : 'text-green-500', bg: totalVulnerabilities > 0 ? 'bg-orange-500/10' : 'bg-green-500/10', border: totalVulnerabilities > 0 ? 'border-orange-500/20' : 'border-green-500/20' }
|
| 204 |
+
].map((metric, i) => (
|
| 205 |
+
<div key={i} className="bg-surface-container-lowest border border-outline-variant p-md rounded-2xl shadow-sm hover:shadow-md transition-all group">
|
| 206 |
+
<div className="flex justify-between items-start">
|
| 207 |
+
<div>
|
| 208 |
+
<p className="text-on-surface-variant font-bold text-[12px] uppercase tracking-wider mb-1">{metric.title}</p>
|
| 209 |
+
<h3 className="text-[32px] font-extrabold tracking-tight text-on-surface">{metric.value}</h3>
|
| 210 |
+
</div>
|
| 211 |
+
<div className={`${metric.bg} ${metric.border} p-2.5 rounded-xl border group-hover:scale-110 transition-transform`}>
|
| 212 |
+
<metric.icon className={`${metric.color} w-6 h-6`} />
|
| 213 |
+
</div>
|
| 214 |
+
</div>
|
| 215 |
+
</div>
|
| 216 |
+
))}
|
| 217 |
+
</div>
|
| 218 |
+
|
| 219 |
+
{/* Scan Engine Distribution */}
|
| 220 |
+
{scanTypeChartData.length > 0 && (
|
| 221 |
+
<div className="bg-surface-container-lowest border border-outline-variant p-lg rounded-2xl shadow-sm mb-xl">
|
| 222 |
+
<div className="flex flex-col md:flex-row justify-between items-start md:items-center mb-6 gap-4">
|
| 223 |
+
<h2 className="font-headline-sm font-bold text-on-surface text-[18px] flex items-center gap-2">
|
| 224 |
+
<PieChartIcon className="w-5 h-5 text-purple-400" />
|
| 225 |
+
Scan Mode Distribution
|
| 226 |
+
</h2>
|
| 227 |
+
<div className="flex gap-sm">
|
| 228 |
+
<select
|
| 229 |
+
value={filterOrg}
|
| 230 |
+
onChange={e => setFilterOrg(e.target.value)}
|
| 231 |
+
className="bg-surface-container border border-outline-variant text-on-surface rounded-lg px-3 py-1.5 text-sm font-bold outline-none"
|
| 232 |
+
>
|
| 233 |
+
<option value="All">All Organizations</option>
|
| 234 |
+
{uniqueOrgs.map(org => <option key={org} value={org}>{org}</option>)}
|
| 235 |
+
</select>
|
| 236 |
+
<select
|
| 237 |
+
value={filterWebsite}
|
| 238 |
+
onChange={e => setFilterWebsite(e.target.value)}
|
| 239 |
+
className="bg-surface-container border border-outline-variant text-on-surface rounded-lg px-3 py-1.5 text-sm font-bold outline-none"
|
| 240 |
+
>
|
| 241 |
+
<option value="All">All Websites</option>
|
| 242 |
+
{uniqueWebsites.map(web => <option key={web} value={web}>{web.replace(/^https?:\/\//, '')}</option>)}
|
| 243 |
+
</select>
|
| 244 |
+
</div>
|
| 245 |
+
</div>
|
| 246 |
+
<div className="h-[250px] w-full">
|
| 247 |
+
<ResponsiveContainer width="100%" height="100%">
|
| 248 |
+
<PieChart>
|
| 249 |
+
<Pie
|
| 250 |
+
data={scanTypeChartData}
|
| 251 |
+
cx="50%"
|
| 252 |
+
cy="50%"
|
| 253 |
+
outerRadius={85}
|
| 254 |
+
dataKey="value"
|
| 255 |
+
label={({ name, percent }) => `${name} ${(percent * 100).toFixed(0)}%`}
|
| 256 |
+
>
|
| 257 |
+
{scanTypeChartData.map((entry, index) => (
|
| 258 |
+
<Cell key={`scan-cell-${index}`} fill={SCAN_TYPE_COLORS[index % SCAN_TYPE_COLORS.length]} />
|
| 259 |
+
))}
|
| 260 |
+
</Pie>
|
| 261 |
+
<RechartsTooltip content={<CustomChartTooltip />} />
|
| 262 |
+
</PieChart>
|
| 263 |
+
</ResponsiveContainer>
|
| 264 |
+
</div>
|
| 265 |
+
</div>
|
| 266 |
+
)}
|
| 267 |
+
|
| 268 |
+
{/* Row 1: Charts Grid */}
|
| 269 |
+
<div className="grid grid-cols-1 lg:grid-cols-2 gap-lg mb-xl">
|
| 270 |
+
{/* Risk Trend Line Chart */}
|
| 271 |
+
<div className="bg-surface-container-lowest border border-outline-variant p-lg rounded-2xl shadow-sm">
|
| 272 |
+
<h2 className="font-headline-sm font-bold text-on-surface mb-6 text-[18px] flex items-center gap-2">
|
| 273 |
+
<Activity className="w-5 h-5 text-primary" />
|
| 274 |
+
Security Score Trend (Recent {riskTrendData.length} Scans)
|
| 275 |
+
</h2>
|
| 276 |
+
<div className="h-[300px] w-full">
|
| 277 |
+
{riskTrendData.length > 0 ? (
|
| 278 |
+
<ResponsiveContainer width="100%" height="100%">
|
| 279 |
+
<LineChart data={riskTrendData}>
|
| 280 |
+
<CartesianGrid strokeDasharray="3 3" stroke="#374151" vertical={false} />
|
| 281 |
+
<XAxis dataKey="name" stroke="#9CA3AF" tick={{ fill: '#9CA3AF', fontSize: 11 }} />
|
| 282 |
+
<YAxis stroke="#9CA3AF" tick={{ fill: '#9CA3AF', fontSize: 12 }} domain={[0, 100]} />
|
| 283 |
+
<RechartsTooltip content={<CustomChartTooltip />} />
|
| 284 |
+
<Line type="monotone" dataKey="securityScore" name="Security Score" stroke="#3B82F6" strokeWidth={3} dot={{ r: 4, fill: '#3B82F6', strokeWidth: 2 }} activeDot={{ r: 6 }} />
|
| 285 |
+
</LineChart>
|
| 286 |
+
</ResponsiveContainer>
|
| 287 |
+
) : (
|
| 288 |
+
<div className="flex h-full items-center justify-center text-on-surface-variant">No scan history available.</div>
|
| 289 |
+
)}
|
| 290 |
+
</div>
|
| 291 |
+
</div>
|
| 292 |
+
|
| 293 |
+
{/* Vulnerability Distribution Bar Chart */}
|
| 294 |
+
<div className="bg-surface-container-lowest border border-outline-variant p-lg rounded-2xl shadow-sm">
|
| 295 |
+
<h2 className="font-headline-sm font-bold text-on-surface mb-6 text-[18px] flex items-center gap-2">
|
| 296 |
+
<BarChart3 className="w-5 h-5 text-primary" />
|
| 297 |
+
Severity Level Breakdown
|
| 298 |
+
</h2>
|
| 299 |
+
<div className="h-[300px] w-full">
|
| 300 |
+
<ResponsiveContainer width="100%" height="100%">
|
| 301 |
+
<BarChart data={vulnerabilityTypes} margin={{ top: 20, right: 30, left: 0, bottom: 5 }}>
|
| 302 |
+
<CartesianGrid strokeDasharray="3 3" stroke="#374151" vertical={false} />
|
| 303 |
+
<XAxis dataKey="name" stroke="#9CA3AF" tick={{ fill: '#9CA3AF', fontSize: 12 }} />
|
| 304 |
+
<YAxis stroke="#9CA3AF" tick={{ fill: '#9CA3AF', fontSize: 12 }} />
|
| 305 |
+
<RechartsTooltip content={<CustomChartTooltip />} />
|
| 306 |
+
<Bar dataKey="value" name="Risks" radius={[4, 4, 0, 0]}>
|
| 307 |
+
<LabelList dataKey="value" position="top" fill="#9CA3AF" fontSize={12} fontWeight="bold" />
|
| 308 |
+
{vulnerabilityTypes.map((entry, index) => (
|
| 309 |
+
<Cell key={`cell-${index}`} fill={entry.name.includes('Clean') ? '#10B981' : SEVERITY_COLORS[index % SEVERITY_COLORS.length]} />
|
| 310 |
+
))}
|
| 311 |
+
</Bar>
|
| 312 |
+
</BarChart>
|
| 313 |
+
</ResponsiveContainer>
|
| 314 |
+
</div>
|
| 315 |
+
</div>
|
| 316 |
+
</div>
|
| 317 |
+
|
| 318 |
+
{/* Row 2: Secondary Charts Grid */}
|
| 319 |
+
<div className="grid grid-cols-1 lg:grid-cols-2 gap-lg mb-xl">
|
| 320 |
+
{/* Scan Frequency vs Issues Found */}
|
| 321 |
+
<div className="bg-surface-container-lowest border border-outline-variant p-lg rounded-2xl shadow-sm">
|
| 322 |
+
<h2 className="font-headline-sm font-bold text-on-surface mb-6 text-[18px] flex items-center gap-2">
|
| 323 |
+
<BarChart3 className="w-5 h-5 text-primary" />
|
| 324 |
+
Monthly Scans vs Issues Found
|
| 325 |
+
</h2>
|
| 326 |
+
<div className="h-[300px] w-full">
|
| 327 |
+
{scanHistoryChartData.length > 0 ? (
|
| 328 |
+
<ResponsiveContainer width="100%" height="100%">
|
| 329 |
+
<ComposedChart data={scanHistoryChartData} margin={{ top: 20, right: 30, left: 0, bottom: 5 }}>
|
| 330 |
+
<CartesianGrid strokeDasharray="3 3" stroke="#374151" vertical={false} />
|
| 331 |
+
<XAxis dataKey="month" stroke="#9CA3AF" tick={{ fill: '#9CA3AF', fontSize: 12 }} />
|
| 332 |
+
<YAxis yAxisId="left" orientation="left" stroke="#9CA3AF" tick={{ fill: '#9CA3AF', fontSize: 12 }} />
|
| 333 |
+
<YAxis yAxisId="right" orientation="right" stroke="#9CA3AF" tick={{ fill: '#9CA3AF', fontSize: 12 }} />
|
| 334 |
+
<RechartsTooltip content={<CustomChartTooltip />} />
|
| 335 |
+
<Legend wrapperStyle={{ fontSize: '12px' }} />
|
| 336 |
+
<Bar yAxisId="left" dataKey="scans" name="Total Scans" fill="#3B82F6" radius={[4, 4, 0, 0]} maxBarSize={40}>
|
| 337 |
+
<LabelList dataKey="scans" position="insideTop" fill="#ffffff" fontSize={11} fontWeight="bold" offset={10} />
|
| 338 |
+
</Bar>
|
| 339 |
+
<Line yAxisId="right" type="monotone" dataKey="issues" name="Issues Found" stroke="#EF4444" strokeWidth={3} dot={{ r: 4, fill: '#EF4444', strokeWidth: 2 }} activeDot={{ r: 6 }}>
|
| 340 |
+
<LabelList dataKey="issues" position="top" fill="#EF4444" fontSize={12} fontWeight="bold" offset={10} />
|
| 341 |
+
</Line>
|
| 342 |
+
</ComposedChart>
|
| 343 |
+
</ResponsiveContainer>
|
| 344 |
+
) : (
|
| 345 |
+
<div className="flex h-full items-center justify-center text-on-surface-variant">No scan history available.</div>
|
| 346 |
+
)}
|
| 347 |
+
</div>
|
| 348 |
+
</div>
|
| 349 |
+
|
| 350 |
+
{/* Top Vulnerability Categories */}
|
| 351 |
+
<div className="bg-surface-container-lowest border border-outline-variant p-lg rounded-2xl shadow-sm">
|
| 352 |
+
<h2 className="font-headline-sm font-bold text-on-surface mb-6 text-[18px] flex items-center gap-2">
|
| 353 |
+
<ShieldAlert className="w-5 h-5 text-orange-500" />
|
| 354 |
+
Top Vulnerability Categories (OWASP)
|
| 355 |
+
</h2>
|
| 356 |
+
<div className="h-[300px] w-full">
|
| 357 |
+
{categoriesData.length > 0 ? (
|
| 358 |
+
<ResponsiveContainer width="100%" height="100%">
|
| 359 |
+
<BarChart data={categoriesData} layout="vertical" margin={{ top: 10, right: 30, left: 40, bottom: 5 }}>
|
| 360 |
+
<CartesianGrid strokeDasharray="3 3" stroke="#374151" horizontal={false} />
|
| 361 |
+
<XAxis type="number" stroke="#9CA3AF" tick={{ fill: '#9CA3AF', fontSize: 12 }} />
|
| 362 |
+
<YAxis dataKey="category" type="category" stroke="#9CA3AF" tick={{ fill: '#9CA3AF', fontSize: 11 }} width={110} />
|
| 363 |
+
<RechartsTooltip content={<CustomChartTooltip />} />
|
| 364 |
+
<Bar dataKey="count" name="Detections" fill="#F97316" radius={[0, 4, 4, 0]}>
|
| 365 |
+
<LabelList dataKey="count" position="right" fill="#9CA3AF" fontSize={11} fontWeight="bold" />
|
| 366 |
+
</Bar>
|
| 367 |
+
</BarChart>
|
| 368 |
+
</ResponsiveContainer>
|
| 369 |
+
) : (
|
| 370 |
+
<div className="flex h-full items-center justify-center text-on-surface-variant">No category breakdown available.</div>
|
| 371 |
+
)}
|
| 372 |
+
</div>
|
| 373 |
+
</div>
|
| 374 |
+
</div>
|
| 375 |
+
|
| 376 |
+
</div>
|
| 377 |
+
);
|
| 378 |
+
};
|