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.
Python astracloudflarecontrol-panelcyberpaneldnsfablehosting-control-panelhosting-panelkimi-k3server-managementserverkitubuntu-web-panelwebserver
Enhance Server detail UI, token flow & metrics
Juan Denis2f618b983f32
diff --git a/Dockerfile b/Dockerfileindex 42e60131..eb2faa23 100644--- a/Dockerfile+++ b/Dockerfile@@ -62,8 +62,8 @@ RUN apt-get update && apt-get install -y --no-install-recommends \RUN groupadd -r serverkit && useradd -r -g serverkit serverkit# Create necessary directories-RUN mkdir -p /etc/serverkit /var/log/serverkit /var/quarantine \- && chown -R serverkit:serverkit /etc/serverkit /var/log/serverkit /var/quarantine+RUN mkdir -p /etc/serverkit /var/log/serverkit /var/quarantine /var/backups/serverkit \+ && chown -R serverkit:serverkit /etc/serverkit /var/log/serverkit /var/quarantine /var/backups/serverkit# Set working directoryWORKDIR /appdiff --git a/backend/Dockerfile b/backend/Dockerfileindex 38668676..fc3339a4 100644--- a/backend/Dockerfile+++ b/backend/Dockerfile@@ -30,7 +30,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \&& apt-get clean# Create directories for ServerKit-RUN mkdir -p /etc/serverkit /app/logs /var/quarantine /app/instance+RUN mkdir -p /etc/serverkit /app/logs /var/quarantine /app/instance /var/backups/serverkit# Copy requirements first for cachingCOPY requirements.txt .@@ -47,7 +47,8 @@ RUN useradd --create-home appuser \&& chown -R appuser:appuser /app \&& chown -R appuser:appuser /app/instance \&& chown -R appuser:appuser /etc/serverkit \- && chown -R appuser:appuser /var/quarantine+ && chown -R appuser:appuser /var/quarantine \+ && chown -R appuser:appuser /var/backups/serverkitUSER appuserdiff --git a/frontend/src/App.jsx b/frontend/src/App.jsxindex 85ed8ef0..511f0e23 100644--- a/frontend/src/App.jsx+++ b/frontend/src/App.jsx@@ -173,7 +173,7 @@ function AppRoutes() {<Route path="docker" element={<Docker />} /><Route path="servers" element={<Servers />} /><Route path="servers/:id" element={<ServerDetail />} />- <Route path="servers/:id/docker" element={<ServerDetail />} />+ <Route path="servers/:id/:tab" element={<ServerDetail />} /><Route path="downloads" element={<Downloads />} /><Route path="firewall" element={<Navigate to="/security" replace />} /><Route path="git" element={<Git />} />diff --git a/frontend/src/components/MetricsGraph.jsx b/frontend/src/components/MetricsGraph.jsxindex f2beceba..a23ba3c0 100644--- a/frontend/src/components/MetricsGraph.jsx+++ b/frontend/src/components/MetricsGraph.jsx@@ -13,7 +13,7 @@ const CHART_COLORS = {disk: '#f59e0b' // Amber/Orange (Disk)};-const MetricsGraph = ({ compact = false, timezone }) => {+const MetricsGraph = ({ compact = false, timezone, serverId }) => {const [data, setData] = useState(null);const [period, setPeriod] = useState('1h');const [loading, setLoading] = useState(true);@@ -35,12 +35,14 @@ const MetricsGraph = ({ compact = false, timezone }) => {useEffect(() => {loadHistory();- }, [period]);+ }, [period, serverId]);async function loadHistory() {try {setLoading(true);- const response = await api.getMetricsHistory(period);+ const response = serverId+ ? await api.getServerMetricsHistory(serverId, period)+ : await api.getMetricsHistory(period);setData(response);setError(null);} catch (err) {@@ -64,9 +66,9 @@ const MetricsGraph = ({ compact = false, timezone }) => {const chartData = data?.data?.map(point => ({time: formatTimestamp(point.timestamp),- cpu: point.cpu.percent,- memory: point.memory.percent,- disk: point.disk.percent+ cpu: point.cpu?.percent ?? point.cpu_percent ?? 0,+ memory: point.memory?.percent ?? point.memory_percent ?? 0,+ disk: point.disk?.percent ?? point.disk_percent ?? 0})) || [];// Auto-zoom: compute Y-axis ceiling from visible metricsdiff --git a/frontend/src/pages/Docker.jsx b/frontend/src/pages/Docker.jsxindex 88142784..7d4ae1a4 100644--- a/frontend/src/pages/Docker.jsx+++ b/frontend/src/pages/Docker.jsx@@ -30,7 +30,7 @@ const Docker = () => {async function loadServers() {try {const data = await api.getAvailableServers();- setServers(data.servers || []);+ setServers(Array.isArray(data) ? data : []);} catch (err) {console.error('Failed to load servers:', err);// Default to just localdiff --git a/frontend/src/pages/ServerDetail.jsx b/frontend/src/pages/ServerDetail.jsxindex de76541f..60ecffb8 100644--- a/frontend/src/pages/ServerDetail.jsx+++ b/frontend/src/pages/ServerDetail.jsx@@ -2,22 +2,26 @@ import React, { useState, useEffect, useCallback } from 'react';import { useParams, Link, useNavigate } from 'react-router-dom';import api from '../services/api';import { useToast } from '../contexts/ToastContext';+import MetricsGraph from '../components/MetricsGraph';const ServerDetail = () => {- const { id } = useParams();+ const { id, tab } = useParams();const navigate = useNavigate();const [server, setServer] = useState(null);const [metrics, setMetrics] = useState(null);const [systemInfo, setSystemInfo] = useState(null);- const [activeTab, setActiveTab] = useState('overview');const [loading, setLoading] = useState(true);const [error, setError] = useState(null);+ const [showTokenModal, setShowTokenModal] = useState(false);const toast = useToast();+ const validTabs = ['overview', 'docker', 'metrics', 'settings'];+ const activeTab = validTabs.includes(tab) ? tab : 'overview';+const loadServer = useCallback(async () => {try {const data = await api.getServer(id);- setServer(data.server);+ setServer(data);setError(null);} catch (err) {setError(err.message);@@ -95,7 +99,25 @@ const ServerDetail = () => {try {const result = await api.generateRegistrationToken(id);toast.success('New registration token generated');- setServer(prev => ({ ...prev, registration_token: result.token }));+ setServer(prev => ({+ ...prev,+ registration_token: result.registration_token,+ registration_expires: result.registration_expires+ }));+ } catch (err) {+ toast.error(err.message || 'Failed to generate token');+ }+ }++ async function handleGenerateToken() {+ try {+ const result = await api.generateRegistrationToken(id);+ setServer(prev => ({+ ...prev,+ registration_token: result.registration_token,+ registration_expires: result.registration_expires+ }));+ setShowTokenModal(true);} catch (err) {toast.error(err.message || 'Failed to generate token');}@@ -165,20 +187,20 @@ const ServerDetail = () => {<button className="btn btn-secondary" onClick={handlePingServer}><RefreshIcon /> Ping</button>- <button className="btn btn-danger" onClick={handleDeleteServer}>- <TrashIcon /> Remove+ <button className="btn btn-primary" onClick={handleGenerateToken}>+ <KeyIcon /> Generate Token</button></div></div><div className="server-detail-tabs">- {tabs.map(tab => (+ {tabs.map(t => (<button- key={tab.id}- className={`tab-btn ${activeTab === tab.id ? 'active' : ''}`}- onClick={() => setActiveTab(tab.id)}+ key={t.id}+ className={`tab-btn ${activeTab === t.id ? 'active' : ''}`}+ onClick={() => navigate(t.id === 'overview' ? `/servers/${id}` : `/servers/${id}/${t.id}`, { replace: true })}>- {tab.label}+ {t.label}</button>))}</div>@@ -202,9 +224,17 @@ const ServerDetail = () => {server={server}onUpdate={loadServer}onRegenerateToken={handleRegenerateToken}+ onDelete={handleDeleteServer}/>)}</div>++ {showTokenModal && server && (+ <TokenModal+ server={server}+ onClose={() => setShowTokenModal(false)}+ />+ )}</div>);};@@ -559,127 +589,131 @@ const DockerTab = ({ serverId, serverStatus }) => {};const MetricsTab = ({ serverId, metrics }) => {- if (!metrics) {- return (- <div className="offline-notice">- <OfflineIcon />- <h4>No Metrics Available</h4>- <p>Metrics are only available when the server is online.</p>- </div>- );- }+ const formatBytes = (bytes) => {+ if (!bytes) return 'N/A';+ const sizes = ['B', 'KB', 'MB', 'GB', 'TB'];+ const i = Math.floor(Math.log(bytes) / Math.log(1024));+ return `${(bytes / Math.pow(1024, i)).toFixed(1)} ${sizes[i]}`;+ };return (<div className="metrics-tab">- <div className="metrics-grid">- <div className="metric-card large">- <h3>CPU Usage</h3>- <div className="metric-gauge">- <CircularGauge value={metrics.cpu_percent || 0} color="#6366F1" />- </div>- <div className="metric-details">- <div className="detail-item">- <span>Load Average</span>- <span>{metrics.load_avg?.join(', ') || 'N/A'}</span>+ <MetricsGraph serverId={serverId} />++ {metrics && (+ <div className="metrics-live-stats">+ <div className="live-stat-card">+ <h4>Current Snapshot</h4>+ <div className="live-stats-grid">+ <div className="live-stat">+ <span className="live-stat-label">CPU</span>+ <span className="live-stat-value">{(metrics.cpu_percent || 0).toFixed(1)}%</span>+ </div>+ <div className="live-stat">+ <span className="live-stat-label">Memory</span>+ <span className="live-stat-value">{(metrics.memory_percent || 0).toFixed(1)}%</span>+ </div>+ <div className="live-stat">+ <span className="live-stat-label">Disk</span>+ <span className="live-stat-value">{(metrics.disk_percent || 0).toFixed(1)}%</span>+ </div>+ <div className="live-stat">+ <span className="live-stat-label">Net TX</span>+ <span className="live-stat-value">{formatBytes(metrics.network_sent)}/s</span>+ </div>+ <div className="live-stat">+ <span className="live-stat-label">Net RX</span>+ <span className="live-stat-value">{formatBytes(metrics.network_recv)}/s</span>+ </div>+ <div className="live-stat">+ <span className="live-stat-label">Containers</span>+ <span className="live-stat-value">{metrics.container_running || 0} / {metrics.container_count || 0}</span>+ </div></div></div></div>+ )}+ </div>+ );+};- <div className="metric-card large">- <h3>Memory Usage</h3>- <div className="metric-gauge">- <CircularGauge value={metrics.memory_percent || 0} color="#10B981" />- </div>- <div className="metric-details">- <div className="detail-item">- <span>Used</span>- <span>{formatBytes(metrics.memory_used)}</span>- </div>- <div className="detail-item">- <span>Total</span>- <span>{formatBytes(metrics.memory_total)}</span>- </div>- </div>- </div>- <div className="metric-card large">- <h3>Disk Usage</h3>- <div className="metric-gauge">- <CircularGauge value={metrics.disk_percent || 0} color="#F59E0B" />- </div>- <div className="metric-details">- <div className="detail-item">- <span>Used</span>- <span>{formatBytes(metrics.disk_used)}</span>- </div>- <div className="detail-item">- <span>Total</span>- <span>{formatBytes(metrics.disk_total)}</span>- </div>+const AgentRegistrationSection = ({ server, onRegenerateToken }) => {+ const [copied, setCopied] = useState(false);+ const toast = useToast();++ const token = server.registration_token;+ const expires = server.registration_expires;+ const isExpired = expires && new Date(expires) < new Date();++ const linuxScript = token ? `curl -fsSL ${window.location.origin}/api/v1/servers/install.sh | sudo bash -s -- \\+ --server "${window.location.origin}" \\+ --token "${token}"` : '';++ const windowsScript = token ? `irm ${window.location.origin}/api/v1/servers/install.ps1 | iex+Install-ServerKitAgent -Server "${window.location.origin}" -Token "${token}"` : '';++ function copyToClipboard(text) {+ navigator.clipboard.writeText(text);+ setCopied(true);+ toast.success('Copied to clipboard');+ setTimeout(() => setCopied(false), 2000);+ }++ return (+ <div className="form-section">+ <h3>Agent Installation</h3>++ {token && !isExpired ? (+ <div className="install-active">+ <div className="token-status">+ <span className="token-status-dot active" />+ <span>Token active — expires {new Date(expires).toLocaleString()}</span></div>- </div>- <div className="metric-card">- <h3>Network I/O</h3>- <div className="network-stats">- <div className="net-stat">- <UploadIcon />- <span>Upload</span>- <span className="value">{formatBytes(metrics.network_sent)}/s</span>- </div>- <div className="net-stat">- <DownloadIcon />- <span>Download</span>- <span className="value">{formatBytes(metrics.network_recv)}/s</span>+ <div className="install-script-block">+ <div className="install-script-header">+ <TerminalIcon />+ <span>Linux / macOS</span>+ <button className="btn btn-sm btn-secondary" onClick={() => copyToClipboard(linuxScript)}>+ <CopyIcon /> Copy+ </button></div>+ <pre className="install-script-code">{linuxScript}</pre></div>- </div>- <div className="metric-card">- <h3>Docker</h3>- <div className="docker-stats">- <div className="docker-stat">- <span>Containers</span>- <span className="value">{metrics.container_count || 0}</span>- </div>- <div className="docker-stat">- <span>Running</span>- <span className="value">{metrics.container_running || 0}</span>+ <div className="install-script-block">+ <div className="install-script-header">+ <WindowsIcon />+ <span>Windows (PowerShell)</span>+ <button className="btn btn-sm btn-secondary" onClick={() => copyToClipboard(windowsScript)}>+ <CopyIcon /> Copy+ </button></div>+ <pre className="install-script-code">{windowsScript}</pre></div>++ <button className="btn btn-secondary" onClick={onRegenerateToken}>+ <RefreshIcon /> Regenerate Token+ </button></div>- </div>+ ) : (+ <div className="install-inactive">+ <p className="section-description">+ {isExpired+ ? 'The registration token has expired. Generate a new one to install or reinstall the agent.'+ : 'Generate a registration token to install the agent on your server.'}+ </p>+ <button className="btn btn-primary" onClick={onRegenerateToken}>+ <KeyIcon /> Generate Token+ </button>+ </div>+ )}</div>);};-const CircularGauge = ({ value, color }) => {- const safeValue = Math.min(Math.max(value || 0, 0), 100);- const circumference = 2 * Math.PI * 45;- const offset = circumference - (safeValue / 100) * circumference;-- return (- <svg className="circular-gauge" viewBox="0 0 100 100">- <circle className="gauge-bg" cx="50" cy="50" r="45" />- <circle- className="gauge-fill"- cx="50"- cy="50"- r="45"- style={{- strokeDasharray: circumference,- strokeDashoffset: offset,- stroke: safeValue > 80 ? '#EF4444' : color- }}- />- <text x="50" y="50" className="gauge-text">- {safeValue.toFixed(0)}%- </text>- </svg>- );-};--const SettingsTab = ({ server, onUpdate, onRegenerateToken }) => {+const SettingsTab = ({ server, onUpdate, onRegenerateToken, onDelete }) => {const [formData, setFormData] = useState({name: server.name || '',description: server.description || '',@@ -704,7 +738,7 @@ const SettingsTab = ({ server, onUpdate, onRegenerateToken }) => {async function loadGroups() {try {const data = await api.getServerGroups();- setGroups(data.groups || []);+ setGroups(Array.isArray(data) ? data : []);} catch (err) {console.error('Failed to load groups:', err);}@@ -808,215 +842,216 @@ const SettingsTab = ({ server, onUpdate, onRegenerateToken }) => {return (<div className="settings-tab">- <form onSubmit={handleSubmit} className="settings-form">- <div className="form-section">- <h3>Basic Information</h3>-- <div className="form-group">- <label>Server Name</label>- <input- type="text"- name="name"- value={formData.name}- onChange={handleChange}- required- />- </div>-- <div className="form-group">- <label>Description</label>- <textarea- name="description"- value={formData.description}- onChange={handleChange}- rows={3}- />- </div>+ <div className="settings-grid">+ <form onSubmit={handleSubmit} className="settings-form">+ <div className="form-section">+ <h3>Basic Information</h3>- <div className="form-row"><div className="form-group">- <label>Hostname</label>+ <label>Server Name</label><inputtype="text"- name="hostname"- value={formData.hostname}+ name="name"+ value={formData.name}onChange={handleChange}+ required/></div>+<div className="form-group">- <label>IP Address</label>- <input- type="text"- name="ip_address"- value={formData.ip_address}+ <label>Description</label>+ <textarea+ name="description"+ value={formData.description}onChange={handleChange}+ rows={3}/></div>- </div>- <div className="form-group">- <label>Group</label>- <select name="group_id" value={formData.group_id} onChange={handleChange}>- <option value="">No Group</option>- {groups.map(group => (- <option key={group.id} value={group.id}>{group.name}</option>- ))}- </select>- </div>+ <div className="form-row">+ <div className="form-group">+ <label>Hostname</label>+ <input+ type="text"+ name="hostname"+ value={formData.hostname}+ onChange={handleChange}+ />+ </div>+ <div className="form-group">+ <label>IP Address</label>+ <input+ type="text"+ name="ip_address"+ value={formData.ip_address}+ onChange={handleChange}+ />+ </div>+ </div>- <button type="submit" className="btn btn-primary" disabled={loading}>- {loading ? 'Saving...' : 'Save Changes'}- </button>- </div>- </form>+ <div className="form-group">+ <label>Group</label>+ <select name="group_id" value={formData.group_id} onChange={handleChange}>+ <option value="">No Group</option>+ {groups.map(group => (+ <option key={group.id} value={group.id}>{group.name}</option>+ ))}+ </select>+ </div>- <div className="form-section">- <h3>Agent Registration</h3>- <p className="section-description">- If you need to reinstall the agent or connect from a different machine,- generate a new registration token.- </p>- <button className="btn btn-secondary" onClick={onRegenerateToken}>- <RefreshIcon /> Generate New Token- </button>+ <button type="submit" className="btn btn-primary" disabled={loading}>+ {loading ? 'Saving...' : 'Save Changes'}+ </button>+ </div>+ </form>++ <AgentRegistrationSection+ server={server}+ onRegenerateToken={onRegenerateToken}+ /></div>- <div className="form-section">- <h3>Security</h3>+ <div className="security-grid">+ <div className="form-section">+ <h3>Connection & IP Allowlist</h3>++ {connectionInfo && (+ <div className="security-info-bar">+ <div className="security-info-item">+ <span className="security-info-label">Connection IP</span>+ <span className="security-info-value">+ <code>{connectionInfo.ip_address || 'Not connected'}</code>+ </span>+ </div>+ {connectionInfo.connected_since && (+ <div className="security-info-item">+ <span className="security-info-label">Connected Since</span>+ <span className="security-info-value">{new Date(connectionInfo.connected_since).toLocaleString()}</span>+ </div>+ )}+ </div>+ )}++ <div className="subsection">+ <p className="section-description">+ Restrict which IPs can connect. Supports single IPs, CIDR notation, and wildcards.+ </p>- {/* Connection Info */}- {connectionInfo && (- <div className="security-info">- <div className="info-item">- <span className="label">Current Connection IP:</span>- <span className="value">{connectionInfo.ip_address || 'Not connected'}</span>+ <div className="ip-list">+ {allowedIPs.length === 0 ? (+ <div className="ip-empty">No IP restrictions (all IPs allowed)</div>+ ) : (+ allowedIPs.map((ip, idx) => (+ <div key={idx} className="ip-item">+ <code>{ip}</code>+ {connectionInfo?.ip_address === ip && (+ <span className="badge badge-success">Current</span>+ )}+ <button+ className="btn-icon danger"+ onClick={() => handleRemoveIP(ip)}+ title="Remove"+ >+ <TrashIcon />+ </button>+ </div>+ ))+ )}</div>- {connectionInfo.connected_since && (- <div className="info-item">- <span className="label">Connected Since:</span>- <span className="value">{new Date(connectionInfo.connected_since).toLocaleString()}</span>- </div>- )}- </div>- )}- {/* IP Allowlist */}- <div className="subsection">- <h4>IP Allowlist</h4>- <p className="section-description">- Restrict which IP addresses can connect to this server. Leave empty to allow all IPs.- Supports single IPs, CIDR notation (192.168.1.0/24), and wildcards (192.168.1.*).- </p>+ <div className="ip-add-form">+ <input+ type="text"+ placeholder="IP address or CIDR (e.g., 192.168.1.0/24)"+ value={newIP}+ onChange={(e) => setNewIP(e.target.value)}+ onKeyPress={(e) => e.key === 'Enter' && (e.preventDefault(), handleAddIP())}+ />+ <button className="btn btn-secondary" onClick={handleAddIP}>+ Add+ </button>+ </div>- <div className="ip-list">- {allowedIPs.length === 0 ? (- <p className="empty-state">No IP restrictions (all IPs allowed)</p>- ) : (- allowedIPs.map((ip, idx) => (- <div key={idx} className="ip-item">- <code>{ip}</code>- {connectionInfo?.ip_address === ip && (- <span className="badge badge-success">Current</span>- )}- <button- className="btn btn-icon btn-danger-subtle"- onClick={() => handleRemoveIP(ip)}- title="Remove"- >- <TrashIcon />- </button>- </div>- ))+ {connectionInfo?.ip_address && allowedIPs.length > 0 && !allowedIPs.some(ip => {+ return ip === connectionInfo.ip_address || ip.includes('*') || ip.includes('/');+ }) && (+ <div className="security-warning">+ Current connection IP ({connectionInfo.ip_address}) may be blocked by these rules.+ </div>)}</div>-- <div className="ip-add-form">- <input- type="text"- placeholder="Add IP address or CIDR (e.g., 192.168.1.0/24)"- value={newIP}- onChange={(e) => setNewIP(e.target.value)}- onKeyPress={(e) => e.key === 'Enter' && (e.preventDefault(), handleAddIP())}- />- <button className="btn btn-secondary" onClick={handleAddIP}>- Add IP- </button>- </div>-- {connectionInfo?.ip_address && allowedIPs.length > 0 && !allowedIPs.some(ip => {- // Simple check - full validation is server-side- return ip === connectionInfo.ip_address || ip.includes('*') || ip.includes('/');- }) && (- <p className="warning">- Warning: Current connection IP ({connectionInfo.ip_address}) may be blocked!- </p>- )}</div>- {/* API Key Rotation */}- <div className="subsection">- <h4>API Key Rotation</h4>+ <div className="form-section">+ <h3>API Key Rotation</h3><p className="section-description">Rotate the API credentials used by the agent. The agent must be online to receive new credentials.</p>- <button- className="btn btn-secondary"- onClick={handleRotateKey}- disabled={rotatingKey || server.status !== 'online'}- >- <KeyIcon /> {rotatingKey ? 'Rotating...' : 'Rotate API Key'}- </button>- {server.api_key_last_rotated && (- <p className="hint">Last rotated: {new Date(server.api_key_last_rotated).toLocaleString()}</p>+ <div className="key-rotation-actions">+ <button+ className="btn btn-secondary"+ onClick={handleRotateKey}+ disabled={rotatingKey || server.status !== 'online'}+ >+ <KeyIcon /> {rotatingKey ? 'Rotating...' : 'Rotate API Key'}+ </button>+ {server.api_key_last_rotated && (+ <span className="key-rotation-hint">Last rotated: {new Date(server.api_key_last_rotated).toLocaleString()}</span>+ )}+ </div>++ {server.status !== 'online' && (+ <div className="security-notice">+ Server must be online to rotate credentials.+ </div>)}</div>+ </div>- {/* Security Alerts */}- {securityAlerts.length > 0 && (- <div className="subsection">- <h4>Security Alerts</h4>- <div className="alerts-list">- {securityAlerts.map(alert => (- <div key={alert.id} className={`alert-item severity-${alert.severity}`}>- <div className="alert-header">- <span className={`severity-badge ${alert.severity}`}>{alert.severity}</span>- <span className="alert-type">{alert.alert_type.replace('_', ' ')}</span>- <span className="alert-time">{new Date(alert.created_at).toLocaleString()}</span>- </div>- <div className="alert-details">- {alert.source_ip && <span>IP: {alert.source_ip}</span>}- {alert.details?.message && <span>{alert.details.message}</span>}- {alert.details?.attempts && <span>Attempts: {alert.details.attempts}</span>}- </div>- <div className="alert-actions">- {alert.status === 'open' && (- <button- className="btn btn-sm btn-secondary"- onClick={() => handleAcknowledgeAlert(alert.id)}- >- Acknowledge- </button>- )}+ {securityAlerts.length > 0 && (+ <div className="form-section">+ <h3>Security Alerts</h3>+ <div className="alerts-list">+ {securityAlerts.map(alert => (+ <div key={alert.id} className={`alert-item severity-${alert.severity}`}>+ <div className="alert-item-header">+ <span className={`severity-badge ${alert.severity}`}>{alert.severity}</span>+ <span className="alert-type">{alert.alert_type.replace('_', ' ')}</span>+ <span className="alert-time">{new Date(alert.created_at).toLocaleString()}</span>+ </div>+ <div className="alert-item-details">+ {alert.source_ip && <span>IP: {alert.source_ip}</span>}+ {alert.details?.message && <span>{alert.details.message}</span>}+ {alert.details?.attempts && <span>Attempts: {alert.details.attempts}</span>}+ </div>+ <div className="alert-item-actions">+ {alert.status === 'open' && (<button- className="btn btn-sm btn-success"- onClick={() => handleResolveAlert(alert.id)}+ className="btn btn-sm btn-secondary"+ onClick={() => handleAcknowledgeAlert(alert.id)}>- Resolve+ Acknowledge</button>- </div>+ )}+ <button+ className="btn btn-sm btn-success"+ onClick={() => handleResolveAlert(alert.id)}+ >+ Resolve+ </button></div>- ))}- </div>+ </div>+ ))}</div>- )}- </div>+ </div>+ )}<div className="form-section danger-zone"><h3>Danger Zone</h3><p className="section-description">Removing this server will disconnect the agent and delete all associated data.</p>- <button className="btn btn-danger">+ <button className="btn btn-danger" onClick={onDelete}><TrashIcon /> Remove Server</button></div>@@ -1024,13 +1059,87 @@ const SettingsTab = ({ server, onUpdate, onRegenerateToken }) => {);};-// Helper function-function formatBytes(bytes) {- if (!bytes) return 'N/A';- const sizes = ['B', 'KB', 'MB', 'GB', 'TB'];- const i = Math.floor(Math.log(bytes) / Math.log(1024));- return `${(bytes / Math.pow(1024, i)).toFixed(1)} ${sizes[i]}`;-}++const TokenModal = ({ server, onClose }) => {+ const toast = useToast();+ const token = server.registration_token;+ const expires = server.registration_expires;++ const linuxScript = token ? `curl -fsSL ${window.location.origin}/api/v1/servers/install.sh | sudo bash -s -- \\+ --server "${window.location.origin}" \\+ --token "${token}"` : '';++ const windowsScript = token ? `irm ${window.location.origin}/api/v1/servers/install.ps1 | iex+Install-ServerKitAgent -Server "${window.location.origin}" -Token "${token}"` : '';++ function copyToClipboard(text) {+ navigator.clipboard.writeText(text);+ toast.success('Copied to clipboard');+ }++ return (+ <div className="modal-overlay" onClick={onClose}>+ <div className="modal modal-lg" onClick={e => e.stopPropagation()}>+ <div className="modal-header">+ <h2>Agent Installation Token</h2>+ <button className="modal-close" onClick={onClose}>×</button>+ </div>+ <div className="install-instructions">+ <div className="token-status">+ <span className="token-status-dot active" />+ <span>Token active — expires {new Date(expires).toLocaleString()}</span>+ </div>++ <div className="install-tabs">+ <div className="install-tab">+ <div className="install-tab-header">+ <TerminalIcon />+ <div className="install-tab-title">+ <span>Linux / macOS</span>+ <span className="install-tab-description">Ubuntu, Debian, CentOS, Fedora, Arch, macOS — requires curl and sudo</span>+ </div>+ <button className="btn btn-sm btn-secondary" onClick={() => copyToClipboard(linuxScript)}>+ <CopyIcon /> Copy+ </button>+ </div>+ <pre className="install-script">{linuxScript}</pre>+ </div>++ <div className="install-tab">+ <div className="install-tab-header">+ <WindowsIcon />+ <div className="install-tab-title">+ <span>Windows (PowerShell)</span>+ <span className="install-tab-description">Run as Administrator</span>+ </div>+ <button className="btn btn-sm btn-secondary" onClick={() => copyToClipboard(windowsScript)}>+ <CopyIcon /> Copy+ </button>+ </div>+ <pre className="install-script">{windowsScript}</pre>+ </div>+ </div>++ <div className="install-info">+ <h4>What happens next?</h4>+ <ol>+ <li>Copy and run the install script on your server</li>+ <li>The agent downloads, installs, and registers automatically</li>+ <li>Your server will appear as <strong>"Pending"</strong> until the agent connects, then switch to <strong>"Online"</strong></li>+ </ol>+ <p className="text-muted">+ The registration token expires in 24 hours. You can regenerate it from the server settings page.+ </p>+ </div>++ <div className="modal-actions">+ <button className="btn btn-primary" onClick={onClose}>Close</button>+ </div>+ </div>+ </div>+ </div>+ );+};// Iconsconst RefreshIcon = () => (@@ -1077,17 +1186,23 @@ const PlayIcon = () => (</svg>);-const UploadIcon = () => (+const TerminalIcon = () => (<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">- <polyline points="17 11 12 6 7 11"/>- <line x1="12" y1="6" x2="12" y2="18"/>+ <polyline points="4 17 10 11 4 5"/>+ <line x1="12" y1="19" x2="20" y2="19"/></svg>);-const DownloadIcon = () => (- <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">- <polyline points="7 13 12 18 17 13"/>- <line x1="12" y1="18" x2="12" y2="6"/>+const CopyIcon = () => (+ <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">+ <rect x="9" y="9" width="13" height="13" rx="2" ry="2"/>+ <path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/>+ </svg>+);++const WindowsIcon = () => (+ <svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor">+ <path d="M0 3.449L9.75 2.1v9.451H0m10.949-9.602L24 0v11.4H10.949M0 12.6h9.75v9.451L0 20.699M10.949 12.6H24V24l-12.9-1.801"/></svg>);diff --git a/frontend/src/pages/Servers.jsx b/frontend/src/pages/Servers.jsxindex 31030716..685baee5 100644--- a/frontend/src/pages/Servers.jsx+++ b/frontend/src/pages/Servers.jsx@@ -24,8 +24,8 @@ const Servers = () => {api.getServers(),api.getServerGroups()]);- setServers(serversData.servers || []);- setGroups(groupsData.groups || []);+ setServers(Array.isArray(serversData) ? serversData : []);+ setGroups(Array.isArray(groupsData) ? groupsData : []);} catch (err) {console.error('Failed to load servers:', err);toast.error('Failed to load servers');@@ -34,18 +34,6 @@ const Servers = () => {}}- async function handleDeleteServer(serverId) {- if (!confirm('Are you sure you want to remove this server?')) return;-- try {- await api.deleteServer(serverId);- toast.success('Server removed successfully');- loadData();- } catch (err) {- toast.error(err.message || 'Failed to remove server');- }- }-async function handlePingServer(serverId) {try {const result = await api.pingServer(serverId);@@ -180,7 +168,6 @@ const Servers = () => {<ServerCardkey={server.id}server={server}- onDelete={() => handleDeleteServer(server.id)}onPing={() => handlePingServer(server.id)}/>))}@@ -209,7 +196,7 @@ const Servers = () => {);};-const ServerCard = ({ server, onDelete, onPing }) => {+const ServerCard = ({ server, onPing }) => {const statusColors = {online: '#10B981',offline: '#EF4444',@@ -237,11 +224,6 @@ const ServerCard = ({ server, onDelete, onPing }) => {<h3 className="server-name">{server.name}</h3><span className="server-hostname">{server.hostname || server.ip_address}</span></div>- <div className="server-actions-dropdown">- <button className="btn-icon" title="Actions">- <MoreIcon />- </button>- </div></div><div className="server-card-body">@@ -477,18 +459,23 @@ Install-ServerKitAgent -Server "${window.location.origin}" -Token "${registratio<div className="install-instructions"><div className="success-banner"><CheckCircleIcon />- <span>Server created! Install the agent to connect.</span>+ <div>+ <strong>Server registered successfully</strong>+ <p className="success-subtitle">Run the install script on your target machine to connect the agent.</p>+ </div></div><div className="install-tabs"><InstallTabtitle="Linux / macOS"+ description="Ubuntu, Debian, CentOS, Fedora, Arch, macOS — requires curl and sudo"icon={<TerminalIcon />}script={linuxInstallScript}onCopy={() => copyToClipboard(linuxInstallScript)}/><InstallTabtitle="Windows (PowerShell)"+ description="Run as Administrator"icon={<WindowsIcon />}script={windowsInstallScript}onCopy={() => copyToClipboard(windowsInstallScript)}@@ -498,18 +485,18 @@ Install-ServerKitAgent -Server "${window.location.origin}" -Token "${registratio<div className="install-info"><h4>What happens next?</h4><ol>- <li>Run the install script on your server</li>- <li>The agent will download and configure automatically</li>- <li>Once connected, the server will appear as "Online"</li>+ <li>Copy and run the install script on your server</li>+ <li>The agent downloads, installs, and registers automatically</li>+ <li>Your server will appear as <strong>"Pending"</strong> until the agent connects, then switch to <strong>"Online"</strong></li></ol><p className="text-muted">- The registration token expires in 24 hours. After that, you'll need to generate a new one.+ The registration token expires in 24 hours. You can regenerate it from the server details page.</p></div><div className="modal-actions"><button className="btn btn-primary" onClick={onCreated}>- Done+ Close</button></div></div>@@ -519,12 +506,15 @@ Install-ServerKitAgent -Server "${window.location.origin}" -Token "${registratio);};-const InstallTab = ({ title, icon, script, onCopy }) => {+const InstallTab = ({ title, description, icon, script, onCopy }) => {return (<div className="install-tab"><div className="install-tab-header">{icon}- <span>{title}</span>+ <div className="install-tab-title">+ <span>{title}</span>+ {description && <span className="install-tab-description">{description}</span>}+ </div><button className="btn btn-sm btn-secondary" onClick={onCopy}><CopyIcon /> Copy</button>@@ -552,7 +542,7 @@ const ManageGroupsModal = ({ groups, onClose, onUpdated }) => {toast.success('Group created');onUpdated();const data = await api.getServerGroups();- setGroupList(data.groups || []);+ setGroupList(Array.isArray(data) ? data : []);} catch (err) {toast.error(err.message || 'Failed to create group');} finally {@@ -567,7 +557,7 @@ const ManageGroupsModal = ({ groups, onClose, onUpdated }) => {setEditingGroup(null);onUpdated();const data = await api.getServerGroups();- setGroupList(data.groups || []);+ setGroupList(Array.isArray(data) ? data : []);} catch (err) {toast.error(err.message || 'Failed to update group');}@@ -581,7 +571,7 @@ const ManageGroupsModal = ({ groups, onClose, onUpdated }) => {toast.success('Group deleted');onUpdated();const data = await api.getServerGroups();- setGroupList(data.groups || []);+ setGroupList(Array.isArray(data) ? data : []);} catch (err) {toast.error(err.message || 'Failed to delete group');}@@ -715,14 +705,6 @@ const RefreshIcon = () => (</svg>);-const MoreIcon = () => (- <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">- <circle cx="12" cy="12" r="1"/>- <circle cx="19" cy="12" r="1"/>- <circle cx="5" cy="12" r="1"/>- </svg>-);-const EyeIcon = () => (<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2"><path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"/>diff --git a/frontend/src/services/api.js b/frontend/src/services/api.jsindex ccb69790..b036febe 100644--- a/frontend/src/services/api.js+++ b/frontend/src/services/api.js@@ -2600,7 +2600,7 @@ class ApiService {// Server Registrationasync generateRegistrationToken(serverId) {- return this.request(`/servers/${serverId}/registration-token`, {+ return this.request(`/servers/${serverId}/regenerate-token`, {method: 'POST'});}diff --git a/frontend/src/styles/pages/_servers.less b/frontend/src/styles/pages/_servers.lessindex 425899d5..65ad2eb4 100644--- a/frontend/src/styles/pages/_servers.less+++ b/frontend/src/styles/pages/_servers.less@@ -208,22 +208,6 @@}}-.server-actions-dropdown {- .btn-icon {- background: transparent;- border: none;- color: @text-tertiary;- cursor: pointer;- padding: @space-2;- border-radius: @radius-sm;-- &:hover {- color: @text-primary;- background: @bg-hover;- }- }-}-.server-card-body {padding: @space-4;}@@ -791,6 +775,59 @@padding: 0;}+.metrics-live-stats {+ margin-top: @space-6;+}++.live-stat-card {+ background: @bg-card;+ border: 1px solid @border-subtle;+ border-radius: @radius-lg;+ padding: @space-5;++ h4 {+ font-size: @font-size-xs;+ font-weight: @font-weight-semibold;+ color: @text-tertiary;+ text-transform: uppercase;+ letter-spacing: 0.05em;+ margin: 0 0 @space-4;+ }+}++.live-stats-grid {+ display: grid;+ grid-template-columns: repeat(6, 1fr);+ gap: @space-4;++ @media (max-width: @breakpoint-lg) {+ grid-template-columns: repeat(3, 1fr);+ }++ @media (max-width: @breakpoint-sm) {+ grid-template-columns: repeat(2, 1fr);+ }+}++.live-stat {+ text-align: center;++ .live-stat-label {+ display: block;+ font-size: @font-size-xs;+ color: @text-tertiary;+ margin-bottom: @space-1;+ }++ .live-stat-value {+ display: block;+ font-size: @font-size-md;+ font-weight: @font-weight-semibold;+ font-family: @font-mono;+ color: @text-primary;+ }+}+.metrics-grid {display: grid;grid-template-columns: repeat(3, 1fr);@@ -919,11 +956,250 @@// Settings Tab.settings-tab {- max-width: 600px;+ max-width: none;+}++.settings-grid {+ display: grid;+ grid-template-columns: 1fr 1fr;+ gap: @space-6;+ margin-bottom: @space-6;+ align-items: start;++ @media (max-width: @breakpoint-lg) {+ grid-template-columns: 1fr;+ }++ .form-section {+ margin-bottom: 0;+ }}.settings-form {- margin-bottom: @space-8;+ margin-bottom: 0;+ background: transparent;+ border: none;+ border-radius: 0;+ padding: 0;++ .form-section .btn[type="submit"] {+ margin-top: @space-4;+ }+}++.security-grid {+ display: grid;+ grid-template-columns: 1fr 1fr;+ gap: @space-6;+ margin-bottom: @space-6;+ align-items: start;++ @media (max-width: @breakpoint-lg) {+ grid-template-columns: 1fr;+ }++ .form-section {+ margin-bottom: 0;+ }+}++// Security section styles+.security-info-bar {+ display: flex;+ gap: @space-6;+ padding: @space-4;+ background: @bg-elevated;+ border: 1px solid @border-subtle;+ border-radius: @radius-lg;+ margin-bottom: @space-5;+}++.security-info-item {+ .security-info-label {+ display: block;+ font-size: @font-size-xs;+ color: @text-tertiary;+ margin-bottom: @space-1;+ }++ .security-info-value {+ font-size: @font-size-sm;+ color: @text-primary;++ code {+ font-family: @font-mono;+ background: @bg-body;+ padding: 2px @space-2;+ border-radius: @radius-sm;+ font-size: @font-size-xs;+ }+ }+}++.subsection {+ h4 {+ font-size: @font-size-sm;+ font-weight: @font-weight-semibold;+ color: @text-primary;+ margin: 0 0 @space-2;+ }+}++.ip-list {+ margin-bottom: @space-3;+}++.ip-empty {+ font-size: @font-size-sm;+ color: @text-tertiary;+ padding: @space-4;+ text-align: center;+ background: @bg-elevated;+ border: 1px dashed @border-subtle;+ border-radius: @radius-md;+}++.ip-item {+ display: flex;+ align-items: center;+ gap: @space-3;+ padding: @space-2 @space-3;+ background: @bg-elevated;+ border: 1px solid @border-subtle;+ border-radius: @radius-md;+ margin-bottom: @space-2;++ code {+ flex: 1;+ font-family: @font-mono;+ font-size: @font-size-sm;+ color: @text-primary;+ }++ .badge-success {+ font-size: @font-size-xs;+ padding: 2px @space-2;+ background: @success-bg;+ color: @success;+ border-radius: @radius-sm;+ }+}++.ip-add-form {+ display: flex;+ gap: @space-2;++ input {+ flex: 1;+ background: @bg-elevated;+ border: 1px solid @border-subtle;+ border-radius: @radius-md;+ padding: @space-2 @space-3;+ color: @text-primary;+ font-size: @font-size-sm;++ &::placeholder {+ color: @text-tertiary;+ }++ &:focus {+ border-color: @accent-primary;+ outline: none;+ }+ }+}++.security-warning {+ margin-top: @space-3;+ padding: @space-3 @space-4;+ background: fade(@warning, 10%);+ border: 1px solid fade(@warning, 25%);+ border-radius: @radius-md;+ font-size: @font-size-xs;+ color: @warning;+}++.security-notice {+ margin-top: @space-3;+ font-size: @font-size-xs;+ color: @text-tertiary;+}++.key-rotation-actions {+ display: flex;+ align-items: center;+ gap: @space-4;+}++.key-rotation-hint {+ font-size: @font-size-xs;+ color: @text-tertiary;+}++// Security Alerts+.alerts-list {+ display: flex;+ flex-direction: column;+ gap: @space-3;+}++.alert-item {+ padding: @space-4;+ background: @bg-elevated;+ border: 1px solid @border-subtle;+ border-radius: @radius-lg;+ border-left: 3px solid @text-tertiary;++ &.severity-critical { border-left-color: @danger; }+ &.severity-high { border-left-color: @warning; }+ &.severity-medium { border-left-color: @accent-primary; }+ &.severity-low { border-left-color: @text-tertiary; }+}++.alert-item-header {+ display: flex;+ align-items: center;+ gap: @space-3;+ margin-bottom: @space-2;++ .alert-type {+ flex: 1;+ font-size: @font-size-sm;+ font-weight: @font-weight-medium;+ color: @text-primary;+ text-transform: capitalize;+ }++ .alert-time {+ font-size: @font-size-xs;+ color: @text-tertiary;+ }+}++.severity-badge {+ font-size: @font-size-xs;+ font-weight: @font-weight-semibold;+ text-transform: uppercase;+ padding: 2px @space-2;+ border-radius: @radius-sm;++ &.critical { background: fade(@danger, 15%); color: @danger; }+ &.high { background: fade(@warning, 15%); color: @warning; }+ &.medium { background: fade(@accent-primary, 15%); color: @accent-primary; }+ &.low { background: @bg-hover; color: @text-tertiary; }+}++.alert-item-details {+ display: flex;+ gap: @space-4;+ font-size: @font-size-xs;+ color: @text-secondary;+ margin-bottom: @space-3;+}++.alert-item-actions {+ display: flex;+ gap: @space-2;}.form-section {@@ -965,6 +1241,84 @@}}+// ============================================+// AGENT REGISTRATION SECTION+// ============================================++.token-status {+ display: flex;+ align-items: center;+ gap: @space-2;+ font-size: @font-size-sm;+ color: @text-secondary;+ margin-bottom: @space-5;+}++.token-status-dot {+ width: 8px;+ height: 8px;+ border-radius: @radius-full;+ flex-shrink: 0;++ &.active {+ background: @success;+ box-shadow: 0 0 6px fade(@success, 40%);+ }+}++.install-active {+ display: flex;+ flex-direction: column;+ gap: @space-4;+}++.install-script-block {+ background: @bg-elevated;+ border: 1px solid @border-subtle;+ border-radius: @radius-lg;+ overflow: hidden;+}++.install-script-header {+ display: flex;+ align-items: center;+ gap: @space-3;+ padding: @space-3 @space-4;+ background: @bg-hover;+ border-bottom: 1px solid @border-subtle;++ > svg {+ color: @text-tertiary;+ flex-shrink: 0;+ }++ > span {+ flex: 1;+ font-size: @font-size-sm;+ font-weight: @font-weight-medium;+ color: @text-primary;+ }+}++.install-script-code {+ padding: @space-4 @space-5;+ margin: 0;+ font-family: @font-mono;+ font-size: @font-size-xs;+ line-height: @line-height-relaxed;+ color: @text-secondary;+ background: @bg-body;+ overflow-x: auto;+ white-space: pre-wrap;+ word-break: break-all;+}++.install-inactive {+ .section-description {+ margin-bottom: @space-4;+ }+}+// ============================================// ADD SERVER MODAL// ============================================@@ -999,21 +1353,39 @@}.install-instructions {- padding: @space-4 0;+ padding: @space-6;}.success-banner {display: flex;- align-items: center;- gap: @space-3;+ align-items: flex-start;+ gap: @space-4;background: @success-bg;+ border: 1px solid @success-border;color: @success;- padding: @space-4;- border-radius: @radius-md;+ padding: @space-5;+ border-radius: @radius-lg;margin-bottom: @space-6;svg {flex-shrink: 0;+ width: 22px;+ height: 22px;+ margin-top: 1px;+ }++ strong {+ display: block;+ font-size: @font-size-sm;+ font-weight: @font-weight-semibold;+ margin-bottom: @space-1;+ }++ .success-subtitle {+ font-size: @font-size-xs;+ color: @text-secondary;+ margin: 0;+ line-height: @line-height-normal;}}@@ -1026,7 +1398,7 @@.install-tab {background: @bg-elevated;border: 1px solid @border-subtle;- border-radius: @radius-md;+ border-radius: @radius-lg;overflow: hidden;}@@ -1038,23 +1410,38 @@background: @bg-hover;border-bottom: 1px solid @border-subtle;- svg {+ > svg {color: @text-tertiary;+ flex-shrink: 0;}+}- span {- flex: 1;+.install-tab-title {+ flex: 1;+ min-width: 0;++ > span:first-child {+ display: block;font-size: @font-size-sm;font-weight: @font-weight-medium;color: @text-primary;}}+.install-tab-description {+ display: block;+ font-size: @font-size-xs;+ color: @text-tertiary;+ font-weight: @font-weight-normal;+ margin-top: 1px;+}+.install-script {- padding: @space-4;+ padding: @space-4 @space-5;margin: 0;font-family: @font-mono;font-size: @font-size-xs;+ line-height: @line-height-relaxed;color: @text-secondary;background: @bg-body;overflow-x: auto;@@ -1064,8 +1451,10 @@.install-info {margin-top: @space-6;- padding-top: @space-6;- border-top: 1px solid @border-subtle;+ padding: @space-5;+ background: @bg-elevated;+ border: 1px solid @border-subtle;+ border-radius: @radius-lg;h4 {font-size: @font-size-sm;@@ -1079,6 +1468,7 @@padding-left: @space-5;color: @text-secondary;font-size: @font-size-sm;+ line-height: @line-height-relaxed;}li {