Skip to content

ServerKit is a lightweight, modern server control panel for managing web applications, databases, and services on your VPS or dedicated server. Built with Python/Flask backend and React frontend.

refactor(ui): security page + overview adopt shared cards

Juan Denis53f440abb0fc
diff --git a/frontend/src/components/security/OverviewTab.jsx b/frontend/src/components/security/OverviewTab.jsx
index 654d146f..4a72b6e8 100644
--- a/frontend/src/components/security/OverviewTab.jsx
+++ b/frontend/src/components/security/OverviewTab.jsx
@@ -1,4 +1,4 @@
-import React, { useState, useEffect } from 'react';
+import React, { useState } from 'react';
import api from '../../services/api';
import { InfoList, InfoItem } from '../InfoList';
import { Button } from '@/components/ui/button';
@@ -31,87 +31,17 @@ const InstallClamAVButton = ({ onInstalled }) => {
);
};
-const OverviewTab = ({ status, onRefresh }) => {
- const [clamavStatus, setClamavStatus] = useState(null);
- const [loading, setLoading] = useState(true);
-
- useEffect(() => {
- loadClamavStatus();
- }, []);
-
- async function loadClamavStatus() {
- try {
- const data = await api.getClamAVStatus();
- setClamavStatus(data);
- } catch (err) {
- console.error('Failed to load ClamAV status:', err);
- } finally {
- setLoading(false);
- }
- }
-
+const OverviewTab = ({ status, clamavStatus, clamavLoading, onRefreshClamav }) => {
const alerts = status?.recent_alerts || {};
+ const loading = clamavLoading;
return (
<div className="security-overview">
- <div className="stats-grid">
- <div className={`stat-card ${alerts.total > 0 ? 'warning' : 'success'}`}>
- <div className="stat-icon">
- <svg viewBox="0 0 24 24" width="24" height="24" stroke="currentColor" fill="none" strokeWidth="2">
- <path d="M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z"/>
- </svg>
- </div>
- <div className="stat-content">
- <span className="stat-value">{alerts.total || 0}</span>
- <span className="stat-label">Alerts (24h)</span>
- </div>
- </div>
-
- <div className={`stat-card ${alerts.malware_detections > 0 ? 'danger' : 'success'}`}>
- <div className="stat-icon">
- <svg viewBox="0 0 24 24" width="24" height="24" 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>
- </div>
- <div className="stat-content">
- <span className="stat-value">{alerts.malware_detections || 0}</span>
- <span className="stat-label">Malware Detected</span>
- </div>
- </div>
-
- <div className={`stat-card ${clamavStatus?.installed ? 'success' : 'warning'}`}>
- <div className="stat-icon">
- <svg viewBox="0 0 24 24" width="24" height="24" stroke="currentColor" fill="none" strokeWidth="2">
- <circle cx="12" cy="12" r="10"/>
- {clamavStatus?.installed && <polyline points="9 12 12 15 16 10"/>}
- {!clamavStatus?.installed && <line x1="15" y1="9" x2="9" y2="15"/>}
- </svg>
- </div>
- <div className="stat-content">
- <span className="stat-value">{clamavStatus?.installed ? 'Active' : 'Not Installed'}</span>
- <span className="stat-label">ClamAV Status</span>
- </div>
- </div>
-
- <div className={`stat-card ${status?.scan_status === 'running' ? 'info' : 'default'}`}>
- <div className="stat-icon">
- <svg viewBox="0 0 24 24" width="24" height="24" stroke="currentColor" fill="none" strokeWidth="2">
- <circle cx="11" cy="11" r="8"/>
- <line x1="21" y1="21" x2="16.65" y2="16.65"/>
- </svg>
- </div>
- <div className="stat-content">
- <span className="stat-value" style={{ textTransform: 'capitalize' }}>{status?.scan_status || 'Idle'}</span>
- <span className="stat-label">Scan Status</span>
- </div>
- </div>
- </div>
-
<div className="security-grid">
<div className="card">
<div className="card-header">
<h3>ClamAV Antivirus</h3>
- <Button variant="outline" size="sm" onClick={loadClamavStatus}>Refresh</Button>
+ <Button variant="outline" size="sm" onClick={onRefreshClamav}>Refresh</Button>
</div>
<div className="card-body">
{loading ? (
@@ -132,7 +62,7 @@ const OverviewTab = ({ status, onRefresh }) => {
) : (
<div className="not-installed">
<p>ClamAV is not installed on this server.</p>
- <InstallClamAVButton onInstalled={loadClamavStatus} />
+ <InstallClamAVButton onInstalled={onRefreshClamav} />
</div>
)}
</div>
diff --git a/frontend/src/pages/Security.jsx b/frontend/src/pages/Security.jsx
index d8b03070..27e889a1 100644
--- a/frontend/src/pages/Security.jsx
+++ b/frontend/src/pages/Security.jsx
@@ -19,17 +19,23 @@ import {
} from '../components/security';
import { Tabs, TabsList, TabsTrigger, TabsContent } from '@/components/ui/tabs';
import EmptyState from '../components/EmptyState';
+import { StatStrip, Stat } from '../components/StatCard';
const VALID_TABS = ['overview', 'firewall', 'fail2ban', 'ssh-keys', 'ip-lists', 'scanner', 'quarantine', 'integrity', 'audit', 'vulnerability', 'updates', 'events', 'settings'];
+const capitalize = (s) => (s ? s.charAt(0).toUpperCase() + s.slice(1) : s);
+
const Security = () => {
const { isAdmin } = useAuth();
const [activeTab, setActiveTab] = useTabParam('/security', VALID_TABS);
const [status, setStatus] = useState(null);
+ const [clamav, setClamav] = useState(null);
+ const [clamavLoading, setClamavLoading] = useState(true);
const [loading, setLoading] = useState(true);
useEffect(() => {
loadStatus();
+ loadClamav();
}, []);
async function loadStatus() {
@@ -43,10 +49,24 @@ const Security = () => {
}
}
+ async function loadClamav() {
+ try {
+ const data = await api.getClamAVStatus();
+ setClamav(data);
+ } catch (err) {
+ console.error('Failed to load ClamAV status:', err);
+ } finally {
+ setClamavLoading(false);
+ }
+ }
+
if (loading) {
return <EmptyState loading title="Loading security status..." />;
}
+ const alerts = status?.recent_alerts || {};
+ const scanRunning = status?.scan_status === 'running';
+
return (
<div className="page-container security-page">
<div className="page-header">
@@ -56,6 +76,29 @@ const Security = () => {
</div>
</div>
+ <StatStrip ariaLabel="Security overview">
+ <Stat
+ label="Alerts (24h)"
+ value={alerts.total || 0}
+ state={alerts.total > 0 ? 'warning' : 'success'}
+ />
+ <Stat
+ label="Malware Detected"
+ value={alerts.malware_detections || 0}
+ state={alerts.malware_detections > 0 ? 'danger' : 'success'}
+ />
+ <Stat
+ label="ClamAV"
+ value={clamav?.installed ? 'Active' : 'Not installed'}
+ state={clamav?.installed ? 'success' : 'warning'}
+ />
+ <Stat
+ label="Scan Status"
+ value={capitalize(status?.scan_status) || 'Idle'}
+ state={scanRunning ? 'info' : undefined}
+ />
+ </StatStrip>
+
<Tabs value={activeTab} onValueChange={setActiveTab}>
<TabsList>
<TabsTrigger value="overview">Overview</TabsTrigger>
@@ -74,7 +117,7 @@ const Security = () => {
</TabsList>
<div className="tab-content">
- <TabsContent value="overview"><OverviewTab status={status} onRefresh={loadStatus} /></TabsContent>
+ <TabsContent value="overview"><OverviewTab status={status} clamavStatus={clamav} clamavLoading={clamavLoading} onRefreshClamav={loadClamav} /></TabsContent>
<TabsContent value="firewall"><FirewallTab /></TabsContent>
<TabsContent value="fail2ban"><Fail2banTab /></TabsContent>
<TabsContent value="ssh-keys"><SSHKeysTab /></TabsContent>
diff --git a/frontend/src/styles/pages/_security.scss b/frontend/src/styles/pages/_security.scss
index bffa947f..2df90e9e 100644
--- a/frontend/src/styles/pages/_security.scss
+++ b/frontend/src/styles/pages/_security.scss
@@ -36,69 +36,6 @@
// Overview Tab
.security-overview {
- .stats-grid {
- display: grid;
- grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
- gap: $space-4;
- margin-bottom: $space-6;
- }
-
- .stat-card {
- display: flex;
- align-items: center;
- gap: $space-4;
- padding: $space-6;
- background: $bg-card;
- border-radius: $radius-lg;
- border: 1px solid $border-subtle;
-
- &.success {
- border-color: fade($success, 30%);
- .stat-icon { color: $success; background: fade($success, 15%); }
- }
-
- &.warning {
- border-color: fade($warning, 30%);
- .stat-icon { color: $warning; background: fade($warning, 15%); }
- }
-
- &.danger {
- border-color: fade($danger, 30%);
- .stat-icon { color: $danger; background: fade($danger, 15%); }
- }
-
- &.info {
- border-color: fade($accent-primary-raw, 30%);
- .stat-icon { color: $accent-primary; background: fade($accent-primary-raw, 15%); }
- }
- }
-
- .stat-icon {
- width: 48px;
- height: 48px;
- display: flex;
- align-items: center;
- justify-content: center;
- background: $bg-hover;
- border-radius: $radius-md;
- flex-shrink: 0;
- }
-
- .stat-content {
- display: flex;
- flex-direction: column;
-
- .stat-value {
- font-size: $font-size-xl;
- font-weight: 700;
- }
-
- .stat-label {
- color: $text-secondary;
- font-size: $font-size-sm;
- }
- }
-
.security-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));