mirror of
https://github.com/jhd3197/ServerKit.git
synced 2026-12-04 22:21:21 +09:00
Add diagnostic setup logging and Windows-friendly error UI, plus a large refactor of security frontend components. - Agent: introduce openSetupDebugLog, write diagnostics during runSetup, LockOSThread for Windows WebView2, and catch panics to surface failures. Add platform-specific showFatalError implementations (MessageBox on Windows, stderr elsewhere). Update setup UI Run behavior to create the native WebView2 window synchronously and fall back to the browser. - Frontend: replace raw HTML buttons/badges/inputs/selects/textareas across many security-related components with shared UI primitives (Button, Badge, Input, Label, Select, Textarea) and update modal forms to use them. - Misc: add /agent/packaging to .gitignore. These changes improve diagnostics for the setup wizard (especially when launched without a console), provide clearer error surfacing on Windows, and standardize the security UI on the new component library.
100 lines
4.4 KiB
React
100 lines
4.4 KiB
React
import React, { useState, useEffect } from 'react';
|
|
import api from '../../services/api';
|
|
import { Button } from '@/components/ui/button';
|
|
|
|
const EventsTab = () => {
|
|
const [events, setEvents] = useState([]);
|
|
const [failedLogins, setFailedLogins] = useState(null);
|
|
const [loading, setLoading] = useState(true);
|
|
|
|
useEffect(() => {
|
|
loadEvents();
|
|
loadFailedLogins();
|
|
}, []);
|
|
|
|
async function loadEvents() {
|
|
try {
|
|
const data = await api.getSecurityEvents(50);
|
|
setEvents(data.events || []);
|
|
} catch (err) {
|
|
console.error('Failed to load security events:', err);
|
|
} finally {
|
|
setLoading(false);
|
|
}
|
|
}
|
|
|
|
async function loadFailedLogins() {
|
|
try {
|
|
const data = await api.getFailedLogins(24);
|
|
setFailedLogins(data);
|
|
} catch (err) {
|
|
console.error('Failed to load failed logins:', err);
|
|
}
|
|
}
|
|
|
|
function getEventIcon(type) {
|
|
if (type.includes('malware')) {
|
|
return <svg viewBox="0 0 24 24" width="16" height="16" stroke="currentColor" fill="none" strokeWidth="2"><path d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"/></svg>;
|
|
}
|
|
if (type.includes('integrity')) {
|
|
return <svg viewBox="0 0 24 24" width="16" height="16" stroke="currentColor" fill="none" strokeWidth="2"><path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"/><polyline points="14 2 14 8 20 8"/></svg>;
|
|
}
|
|
return <svg viewBox="0 0 24 24" width="16" height="16" stroke="currentColor" fill="none" strokeWidth="2"><path d="M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z"/></svg>;
|
|
}
|
|
|
|
return (
|
|
<div className="events-tab">
|
|
{failedLogins && (
|
|
<div className={`card ${failedLogins.alert_triggered ? 'card-warning' : ''}`}>
|
|
<div className="card-header">
|
|
<h3>Failed Login Attempts (24h)</h3>
|
|
<Button variant="outline" size="sm" onClick={loadFailedLogins}>Refresh</Button>
|
|
</div>
|
|
<div className="card-body">
|
|
<div className="failed-login-summary">
|
|
<span className={`count ${failedLogins.alert_triggered ? 'danger' : ''}`}>
|
|
{failedLogins.failed_attempts}
|
|
</span>
|
|
<span className="label">failed attempts (threshold: {failedLogins.threshold})</span>
|
|
</div>
|
|
{failedLogins.recent_failures?.length > 0 && (
|
|
<details className="recent-failures">
|
|
<summary>View recent failures</summary>
|
|
<pre>{failedLogins.recent_failures.join('\n')}</pre>
|
|
</details>
|
|
)}
|
|
</div>
|
|
</div>
|
|
)}
|
|
|
|
<div className="card">
|
|
<div className="card-header">
|
|
<h3>Security Events</h3>
|
|
<Button variant="outline" size="sm" onClick={loadEvents}>Refresh</Button>
|
|
</div>
|
|
<div className="card-body">
|
|
{loading ? (
|
|
<div className="loading-sm">Loading...</div>
|
|
) : events.length === 0 ? (
|
|
<p className="text-muted">No security events recorded.</p>
|
|
) : (
|
|
<div className="events-list">
|
|
{events.map((event, index) => (
|
|
<div key={index} className={`event-item ${event.type}`}>
|
|
<div className="event-icon">{getEventIcon(event.type)}</div>
|
|
<div className="event-content">
|
|
<span className="event-message">{event.message}</span>
|
|
<span className="event-time">{new Date(event.timestamp).toLocaleString()}</span>
|
|
</div>
|
|
</div>
|
|
))}
|
|
</div>
|
|
)}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
);
|
|
};
|
|
|
|
export default EventsTab;
|