Spaces:
Running on CPU Upgrade
Running on CPU Upgrade
Update frontend/src/pages/LogsAndThreats.jsx
Browse files
frontend/src/pages/LogsAndThreats.jsx
CHANGED
|
@@ -83,7 +83,7 @@ const LogsAndThreats = () => {
|
|
| 83 |
const [threatSortCol, setThreatSortCol] = useState('severity');
|
| 84 |
const [threatSortDir, setThreatSortDir] = useState('desc');
|
| 85 |
const [fullThreatsPage, setFullThreatsPage] = useState(1);
|
| 86 |
-
const [fullThreatsPageSize, setFullThreatsPageSize] = useState(
|
| 87 |
|
| 88 |
// Full Page Audit Logs View State
|
| 89 |
const [isFullLogsView, setIsFullLogsView] = useState(false);
|
|
@@ -93,7 +93,7 @@ const LogsAndThreats = () => {
|
|
| 93 |
const [actionCategory, setActionCategory] = useState('all');
|
| 94 |
const [dateFilter, setDateFilter] = useState('all');
|
| 95 |
const [currentPage, setCurrentPage] = useState(1);
|
| 96 |
-
const [pageSize, setPageSize] = useState(
|
| 97 |
const [sortLogCol, setSortLogCol] = useState('Timestamp');
|
| 98 |
const [sortLogDir, setSortLogDir] = useState('desc');
|
| 99 |
|
|
@@ -144,8 +144,7 @@ const LogsAndThreats = () => {
|
|
| 144 |
|
| 145 |
useEffect(() => {
|
| 146 |
fetchStats(true);
|
| 147 |
-
|
| 148 |
-
return () => clearInterval(interval);
|
| 149 |
}, []);
|
| 150 |
|
| 151 |
useEffect(() => {
|
|
@@ -157,9 +156,21 @@ const LogsAndThreats = () => {
|
|
| 157 |
}, [threatSearch, threatSeverityFilter, threatCategoryFilter, threatOwaspFilter, threatSortCol, threatSortDir]);
|
| 158 |
|
| 159 |
const openFullLogsView = (initialSearch = '') => {
|
|
|
|
| 160 |
if (initialSearch) {
|
| 161 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 162 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 163 |
setIsFullThreatsView(false);
|
| 164 |
setIsFullLogsView(true);
|
| 165 |
fetchAllAuditLogs();
|
|
@@ -343,15 +354,26 @@ const LogsAndThreats = () => {
|
|
| 343 |
const paginatedFullThreats = filteredFullThreats.slice(startFullThreatIdx, endFullThreatIdx);
|
| 344 |
|
| 345 |
// Filtered Audit Logs Calculation
|
| 346 |
-
const
|
|
|
|
|
|
|
| 347 |
if (searchQuery) {
|
| 348 |
-
const q = searchQuery.toLowerCase();
|
| 349 |
-
const
|
| 350 |
-
|
| 351 |
-
|
| 352 |
-
|
| 353 |
-
|
| 354 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 355 |
if (!matchQuery) return false;
|
| 356 |
}
|
| 357 |
|
|
|
|
| 83 |
const [threatSortCol, setThreatSortCol] = useState('severity');
|
| 84 |
const [threatSortDir, setThreatSortDir] = useState('desc');
|
| 85 |
const [fullThreatsPage, setFullThreatsPage] = useState(1);
|
| 86 |
+
const [fullThreatsPageSize, setFullThreatsPageSize] = useState(5);
|
| 87 |
|
| 88 |
// Full Page Audit Logs View State
|
| 89 |
const [isFullLogsView, setIsFullLogsView] = useState(false);
|
|
|
|
| 93 |
const [actionCategory, setActionCategory] = useState('all');
|
| 94 |
const [dateFilter, setDateFilter] = useState('all');
|
| 95 |
const [currentPage, setCurrentPage] = useState(1);
|
| 96 |
+
const [pageSize, setPageSize] = useState(8);
|
| 97 |
const [sortLogCol, setSortLogCol] = useState('Timestamp');
|
| 98 |
const [sortLogDir, setSortLogDir] = useState('desc');
|
| 99 |
|
|
|
|
| 144 |
|
| 145 |
useEffect(() => {
|
| 146 |
fetchStats(true);
|
| 147 |
+
fetchAllAuditLogs();
|
|
|
|
| 148 |
}, []);
|
| 149 |
|
| 150 |
useEffect(() => {
|
|
|
|
| 156 |
}, [threatSearch, threatSeverityFilter, threatCategoryFilter, threatOwaspFilter, threatSortCol, threatSortDir]);
|
| 157 |
|
| 158 |
const openFullLogsView = (initialSearch = '') => {
|
| 159 |
+
let cleanQuery = '';
|
| 160 |
if (initialSearch) {
|
| 161 |
+
if (initialSearch.includes('CVE-')) {
|
| 162 |
+
const match = initialSearch.match(/CVE-\d{4}-\d+/i);
|
| 163 |
+
cleanQuery = match ? match[0] : initialSearch;
|
| 164 |
+
} else if (initialSearch.includes(':')) {
|
| 165 |
+
cleanQuery = initialSearch.split(':')[0].trim();
|
| 166 |
+
} else {
|
| 167 |
+
cleanQuery = initialSearch.trim();
|
| 168 |
+
}
|
| 169 |
}
|
| 170 |
+
setSearchQuery(cleanQuery);
|
| 171 |
+
setActionCategory('all');
|
| 172 |
+
setDateFilter('all');
|
| 173 |
+
setCurrentPage(1);
|
| 174 |
setIsFullThreatsView(false);
|
| 175 |
setIsFullLogsView(true);
|
| 176 |
fetchAllAuditLogs();
|
|
|
|
| 354 |
const paginatedFullThreats = filteredFullThreats.slice(startFullThreatIdx, endFullThreatIdx);
|
| 355 |
|
| 356 |
// Filtered Audit Logs Calculation
|
| 357 |
+
const logsToFilter = (allLogs && allLogs.length > 0) ? allLogs : auditLogs;
|
| 358 |
+
|
| 359 |
+
const filteredAllLogs = logsToFilter.filter(log => {
|
| 360 |
if (searchQuery) {
|
| 361 |
+
const q = searchQuery.toLowerCase().trim();
|
| 362 |
+
const searchableText = [
|
| 363 |
+
log.action,
|
| 364 |
+
log.user_email,
|
| 365 |
+
log.admin_id,
|
| 366 |
+
log.target_name,
|
| 367 |
+
log.target_id,
|
| 368 |
+
log.details,
|
| 369 |
+
log.threat_name,
|
| 370 |
+
log.severity,
|
| 371 |
+
log.category,
|
| 372 |
+
log.owasp
|
| 373 |
+
].filter(Boolean).join(' ').toLowerCase();
|
| 374 |
+
|
| 375 |
+
const words = q.split(/\s+/).filter(w => w.length >= 2);
|
| 376 |
+
const matchQuery = searchableText.includes(q) || (words.length > 0 && words.some(w => searchableText.includes(w)));
|
| 377 |
if (!matchQuery) return false;
|
| 378 |
}
|
| 379 |
|