larxius commited on
Commit
25de298
·
verified ·
1 Parent(s): 3d8aa06

Update frontend/src/pages/LogsAndThreats.jsx

Browse files
Files changed (1) hide show
  1. frontend/src/pages/LogsAndThreats.jsx +35 -13
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(10);
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(100);
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
- const interval = setInterval(() => fetchStats(false), 15000);
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
- setSearchQuery(initialSearch);
 
 
 
 
 
 
 
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 filteredAllLogs = allLogs.filter(log => {
 
 
347
  if (searchQuery) {
348
- const q = searchQuery.toLowerCase();
349
- const matchQuery = (
350
- (log.action && log.action.toLowerCase().includes(q)) ||
351
- (log.user_email && log.user_email.toLowerCase().includes(q)) ||
352
- (log.target_name && log.target_name.toLowerCase().includes(q)) ||
353
- (log.target_id && log.target_id.toLowerCase().includes(q))
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