diff --git a/frontend/src/components/servers/LevelIllustrations.jsx b/frontend/src/components/servers/LevelIllustrations.jsx new file mode 100644 index 00000000..bb8671d3 --- /dev/null +++ b/frontend/src/components/servers/LevelIllustrations.jsx @@ -0,0 +1,49 @@ +// Small inline illustrations for the permission-level cards. They use +// currentColor plus the panel accent variables, so they follow the theme. +const common = { + viewBox: '0 0 96 56', + height: 56, + 'aria-hidden': true, + focusable: 'false', + fill: 'none', + stroke: 'currentColor', + strokeWidth: 2, + strokeLinecap: 'round', + strokeLinejoin: 'round', +}; + +const Monitor = () => ( + + + + + +); + +const Protect = () => ( + + + + + +); + +const Full = () => ( + + + + + + + + +); + +const ILLUSTRATIONS = { monitor: Monitor, protect: Protect, full: Full }; + +const LevelIllustration = ({ level }) => { + const Svg = ILLUSTRATIONS[level] || Monitor; + return ; +}; + +export default LevelIllustration; diff --git a/frontend/src/i18n/locales/en.json b/frontend/src/i18n/locales/en.json index 02a7c335..a519601d 100644 --- a/frontend/src/i18n/locales/en.json +++ b/frontend/src/i18n/locales/en.json @@ -5670,6 +5670,8 @@ "agentFound": "Agent found", "agentPairedSuccessfully": "Agent paired", "autoDetectedFromAgentOptional": "Auto-detected from agent (optional)", + "capAllowed": "allowed", + "capBlocked": "blocked", "clearSelection": "Clear selection", "confirmThisFingerprintMatchesTheOne": "Confirm this fingerprint matches the one shown by the agent before continuing.", "connectionString": "Connection string", @@ -5704,10 +5706,11 @@ "lastSeen": "Last seen", "leaveBlankToUseTheAgent": "Leave blank to use the agent's hostname.", "levelColumn": "Level", - "levelEnforcedByAgent": "The level is enforced by the agent and can only be changed on the server itself, with", + "levelEnforcedShort": "Enforced on the server by the agent. Change with", "levelFull": "Full", "levelFullCan": "Everything the agent supports: Docker, files, terminal, packages, services and more.", "levelFullCannot": "No restrictions. Choose this only for servers you want this panel to fully manage.", + "levelInfo": "What can {{level}} do?", "levelMonitor": "Monitor", "levelMonitorCan": "Reports CPU, memory, disk and service health (web server, PHP-FPM, database) to this panel.", "levelMonitorCannot": "Cannot run commands, open a terminal or change anything. The panel cannot send it any instructions.", diff --git a/frontend/src/pages/Servers.jsx b/frontend/src/pages/Servers.jsx index 99088d97..485af69b 100644 --- a/frontend/src/pages/Servers.jsx +++ b/frontend/src/pages/Servers.jsx @@ -1,6 +1,8 @@ import { useState, useEffect, useCallback, useMemo, useId } from 'react'; import { useNavigate } from 'react-router-dom'; -import { ChevronRight, Folder, Plus, RefreshCw, Server as ServerLucideIcon, X } from 'lucide-react'; +import { Ban, ChevronRight, Container, Cpu, Database, Flame, Folder, HardDrive, Info, Lock, MemoryStick, Plus, RefreshCw, Server as ServerLucideIcon, Terminal, X } from 'lucide-react'; +import { Tooltip, TooltipTrigger, TooltipContent } from '@/components/ui/tooltip'; +import LevelIllustration from '../components/servers/LevelIllustrations'; import api from '../services/api'; import { useToast } from '../contexts/useToast.js'; import EmptyState from '../components/EmptyState'; @@ -30,7 +32,7 @@ import { t } from '../i18n/t'; import { toastError } from '@/utils/errorMessage'; import { formatDate } from '@/utils/intl'; import { - DEFAULT_LEVEL, PERMISSION_LEVELS, buildInstallCommands, levelKind, serverHealth, + DEFAULT_LEVEL, PERMISSION_LEVELS, buildInstallCommands, levelAllows, levelKind, serverHealth, } from '@/utils/agentPermissionLevel'; // Radix Select items cannot use '' — stands in for "no group". @@ -820,6 +822,19 @@ const healthLabel = (code) => { } }; +const CAPABILITY_ICONS = { + cpu: [Cpu, 'CPU'], + memory: [MemoryStick, 'Memory'], + disk: [HardDrive, 'Disk'], + services: [ServerLucideIcon, 'Web server and PHP'], + database: [Database, 'Database'], + firewall: [Flame, 'Firewall'], + ban: [Ban, 'Ban (fail2ban, CrowdSec)'], + terminal: [Terminal, 'Terminal'], + docker: [Container, 'Docker'], + files: [Folder, 'Files'], +}; + const LevelPicker = ({ value, onChange }) => { const { t } = useTranslation(); const copy = { @@ -836,24 +851,59 @@ const LevelPicker = ({ value, onChange }) => { cannot: t('app.servers.levelFullCannot', 'No restrictions. Choose this only for servers you want this panel to fully manage.'), }, }; + const onKeyDown = (e, level) => { + if (e.key === ' ' || e.key === 'Enter') { + e.preventDefault(); + onChange(level); + } + }; return (
{t('app.servers.permissionLevel', 'Permission level')}
{PERMISSION_LEVELS.map((level) => ( - +
+
onChange(level)} + onKeyDown={(e) => onKeyDown(e, level)} + > + + {levelLabel(level)} + + {Object.entries(CAPABILITY_ICONS).map(([cap, [Icon, label]]) => { + const allowed = levelAllows(level, cap); + const text = `${label}: ${allowed ? t('app.servers.capAllowed', 'allowed') : t('app.servers.capBlocked', 'blocked')}`; + return ( + + + ); + })} + +
+ + + + + + {copy[level].can} + {copy[level].cannot} + + +
))}
- - {t('app.servers.levelEnforcedByAgent', 'The level is enforced by the agent and can only be changed on the server itself, with')} + +
diff --git a/frontend/src/styles/pages/_servers.scss b/frontend/src/styles/pages/_servers.scss index f45ce5d1..86532642 100644 --- a/frontend/src/styles/pages/_servers.scss +++ b/frontend/src/styles/pages/_servers.scss @@ -2584,42 +2584,124 @@ // Permission-level picker in the Add Server drawer .level-picker { display: grid; - grid-template-columns: repeat(3, 1fr); + grid-template-columns: repeat(3, minmax(0, 1fr)); gap: $space-2; + @media (max-width: 560px) { + grid-template-columns: 1fr; + } + + // The (i) button is a sibling of the radio card, not nested in it. + &__cell { + position: relative; + display: flex; + } + &__opt { + flex: 1; display: flex; flex-direction: column; - align-items: flex-start; - gap: $space-1; + align-items: center; + gap: $space-2; padding: $space-3; - text-align: start; + text-align: center; + color: $text-tertiary; background: $bg-card; border: 1px solid $border-subtle; border-radius: $radius-control; cursor: pointer; - transition: border-color $transition-fast, background $transition-fast; + transition: border-color $transition-fast, background $transition-fast, box-shadow $transition-fast; &:hover { border-color: $border-active; + background: $bg-elevated; + } + + &:focus-visible { + outline: 2px solid var(--accent-dim); + outline-offset: 2px; } &.is-active { + color: var(--accent); border-color: var(--accent-dim); background: var(--accent-bg); } } + &__art svg { + display: block; + width: auto; + max-width: 100%; + height: 56px; + } + &__head { - font-size: $text-xs; + font-size: $text-sm; font-weight: $font-weight-semibold; color: $text-primary; } - &__desc { - font-size: $text-xs; + &__caps { + display: flex; + flex-wrap: wrap; + justify-content: center; + gap: $space-1; + } + + &__cap { + position: relative; + display: inline-flex; + color: $text-secondary; + + .is-active & { + color: var(--accent); + } + + &.is-blocked { + color: $text-tertiary; + opacity: .5; + + &::after { + content: ''; + position: absolute; + inset: 50% -2px auto; + height: 1.5px; + background: currentColor; + transform: rotate(-45deg); + } + } + } + + &__info { + position: absolute; + top: $space-1; + inset-inline-end: $space-1; + display: inline-flex; + padding: $space-1; color: $text-tertiary; - line-height: 1.45; + background: none; + border: 0; + border-radius: 50%; + cursor: pointer; + + &:hover, + &:focus-visible { + color: $text-primary; + } + } + + &__tip { + flex-direction: column; + align-items: flex-start; + max-width: 260px; white-space: normal; } + + &__note { + display: flex; + flex-wrap: wrap; + align-items: center; + gap: $space-1; + } } diff --git a/frontend/src/utils/__tests__/agentPermissionLevel.test.mjs b/frontend/src/utils/__tests__/agentPermissionLevel.test.mjs index 68e5d4f9..5b5e7a3a 100644 --- a/frontend/src/utils/__tests__/agentPermissionLevel.test.mjs +++ b/frontend/src/utils/__tests__/agentPermissionLevel.test.mjs @@ -1,6 +1,6 @@ import assert from 'node:assert/strict'; import test from 'node:test'; -import { buildInstallCommands, normalizeLevel, serverHealth } from '../agentPermissionLevel.js'; +import { buildInstallCommands, CAPABILITIES, levelAllows, normalizeLevel, serverHealth } from '../agentPermissionLevel.js'; const NOW = Date.parse('2026-01-01T12:00:00Z'); const ago = (s) => new Date(NOW - s * 1000).toISOString(); @@ -26,3 +26,13 @@ test('health combines status, report age and checks', () => { assert.equal(serverHealth({ ...base, status: 'offline' }, NOW).kind, 'red'); assert.equal(serverHealth({ status: 'pending' }, NOW).code, 'pending'); }); + +test('capability matrix per level', () => { + const blocked = (level) => CAPABILITIES.filter((c) => !levelAllows(level, c)); + assert.deepEqual(blocked('monitor'), ['firewall', 'ban', 'terminal', 'docker', 'files']); + assert.deepEqual(blocked('protect'), ['terminal', 'docker', 'files']); + assert.deepEqual(blocked('full'), []); + assert.equal(levelAllows('protect', 'firewall'), true); + assert.equal(levelAllows('protect', 'ban'), true); + assert.equal(levelAllows('bogus', 'terminal'), false); +}); diff --git a/frontend/src/utils/agentPermissionLevel.js b/frontend/src/utils/agentPermissionLevel.js index 056fbf6c..4d914e82 100644 --- a/frontend/src/utils/agentPermissionLevel.js +++ b/frontend/src/utils/agentPermissionLevel.js @@ -51,3 +51,21 @@ export function serverHealth(server, now = Date.now()) { if (degraded.length) return { kind: 'amber', code: 'degraded', failing, degraded }; return { kind: 'green', code: 'healthy', failing, degraded }; } + +// What each level lets the panel do on a server. Mirrors +// backend/app/services/permission_levels.py: monitor is report-only, protect +// adds the PROTECT_ACTIONS (firewall, fail2ban/CrowdSec, Cloudflare origin +// lock), full is everything. +export const CAPABILITIES = ['cpu', 'memory', 'disk', 'services', 'database', 'firewall', 'ban', 'terminal', 'docker', 'files']; +const HEALTH = ['cpu', 'memory', 'disk', 'services', 'database']; +const PROTECT = [...HEALTH, 'firewall', 'ban']; + +export const LEVEL_CAPABILITIES = { + monitor: HEALTH, + protect: PROTECT, + full: CAPABILITIES, +}; + +export function levelAllows(level, capability) { + return (LEVEL_CAPABILITIES[normalizeLevel(level) || DEFAULT_LEVEL] || []).includes(capability); +}