first commit
This commit is contained in:
1 parent
abb09fbea8
commit
72f6d49818
355 files changed
+121239
-3
No files matched your search
@@ -0,0 +1,87 @@
|
||||
import { AlertTriangle, Boxes, CircleDashed } from "lucide-react";
|
||||
import type { DockerRuntimeStatus } from "@/lib/api";
|
||||
|
||||
interface DockerBadgeProps {
|
||||
docker?: DockerRuntimeStatus | null;
|
||||
error?: string | null;
|
||||
loading?: boolean;
|
||||
}
|
||||
|
||||
export default function DockerBadge({
|
||||
docker,
|
||||
error,
|
||||
loading,
|
||||
}: DockerBadgeProps) {
|
||||
if (loading) {
|
||||
return (
|
||||
<span
|
||||
className="ui-badge badge-info"
|
||||
style={{
|
||||
gap: 5,
|
||||
}}
|
||||
>
|
||||
<CircleDashed size={10} className="animate-spin" />
|
||||
Checking Docker
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
if (docker?.available) {
|
||||
return (
|
||||
<span
|
||||
className="ui-badge badge-online"
|
||||
title={docker.version ? `Docker ${docker.version}` : "Docker ready"}
|
||||
style={{
|
||||
gap: 5,
|
||||
}}
|
||||
>
|
||||
<Boxes size={10} />
|
||||
Docker Ready
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
if (docker?.probeFailed) {
|
||||
return (
|
||||
<span
|
||||
className="ui-badge badge-warning"
|
||||
title={docker.reason || "Docker status check failed"}
|
||||
style={{
|
||||
gap: 5,
|
||||
}}
|
||||
>
|
||||
<AlertTriangle size={10} />
|
||||
Check Failed
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
if (error) {
|
||||
return (
|
||||
<span
|
||||
className="ui-badge badge-warning"
|
||||
title={error}
|
||||
style={{
|
||||
gap: 5,
|
||||
}}
|
||||
>
|
||||
<AlertTriangle size={10} />
|
||||
Status Unavailable
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<span
|
||||
className="ui-badge badge-offline"
|
||||
title={docker?.reason || "Docker is not ready on this server"}
|
||||
style={{
|
||||
gap: 5,
|
||||
}}
|
||||
>
|
||||
<AlertTriangle size={10} />
|
||||
{/* Fresh Vps / No Docker */}
|
||||
No Docker Installed
|
||||
</span>
|
||||
);
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,434 @@
|
||||
"use client";
|
||||
|
||||
import { Eye, EyeOff, Loader2, RocketIcon, X } from "lucide-react";
|
||||
import { useState } from "react";
|
||||
import { servers as serversApi, Server as ServerType } from "@/lib/api";
|
||||
|
||||
function createServerFormState(server?: ServerType) {
|
||||
return {
|
||||
name: server?.name ?? "",
|
||||
ip: server?.ip ?? "",
|
||||
sshPort: server?.sshPort ?? 22,
|
||||
username: server?.username ?? "root",
|
||||
authType: (server?.authType ?? "PASSWORD") as "PASSWORD" | "SSH_KEY",
|
||||
password: "",
|
||||
sshKey: "",
|
||||
location: server?.location ?? "",
|
||||
tags: server?.tags.join(", ") ?? "",
|
||||
};
|
||||
}
|
||||
|
||||
interface ServerFormModalProps {
|
||||
server?: ServerType;
|
||||
onClose: () => void;
|
||||
onSaved: (message: string) => void;
|
||||
}
|
||||
|
||||
export default function ServerFormModal({
|
||||
server,
|
||||
onClose,
|
||||
onSaved,
|
||||
}: ServerFormModalProps) {
|
||||
const isEdit = Boolean(server);
|
||||
const [form, setForm] = useState(() => createServerFormState(server));
|
||||
const [showPw, setShowPw] = useState(false);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [error, setError] = useState("");
|
||||
|
||||
const submit = async (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
setError("");
|
||||
setLoading(true);
|
||||
try {
|
||||
const payload = {
|
||||
name: form.name,
|
||||
ip: form.ip,
|
||||
sshPort: form.sshPort,
|
||||
username: form.username,
|
||||
authType: form.authType,
|
||||
password:
|
||||
form.authType === "PASSWORD" && form.password.trim()
|
||||
? form.password
|
||||
: undefined,
|
||||
sshKey:
|
||||
form.authType === "SSH_KEY" && form.sshKey.trim()
|
||||
? form.sshKey
|
||||
: undefined,
|
||||
location: form.location || undefined,
|
||||
tags: form.tags
|
||||
? form.tags
|
||||
.split(",")
|
||||
.map((t: string) => t.trim())
|
||||
.filter(Boolean)
|
||||
: undefined,
|
||||
};
|
||||
|
||||
if (!isEdit && form.authType === "PASSWORD" && !form.password.trim()) {
|
||||
throw new Error("Password is required for PASSWORD auth type");
|
||||
}
|
||||
|
||||
if (!isEdit && form.authType === "SSH_KEY" && !form.sshKey.trim()) {
|
||||
throw new Error("SSH key is required for SSH_KEY auth type");
|
||||
}
|
||||
|
||||
if (server) {
|
||||
await serversApi.update(server.id, payload);
|
||||
onSaved(`Server \"${form.name}\" updated successfully`);
|
||||
} else {
|
||||
await serversApi.create(payload);
|
||||
onSaved(`Server \"${form.name}\" added successfully`);
|
||||
}
|
||||
onClose();
|
||||
} catch (err: unknown) {
|
||||
setError(
|
||||
err instanceof Error
|
||||
? err.message
|
||||
: `Failed to ${isEdit ? "update" : "add"} server`,
|
||||
);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="modal-overlay">
|
||||
<div
|
||||
className="modal animate-slide-in"
|
||||
style={{
|
||||
width: "100%",
|
||||
maxWidth: 520,
|
||||
padding: 28,
|
||||
}}
|
||||
>
|
||||
<div
|
||||
style={{
|
||||
display: "flex",
|
||||
justifyContent: "space-between",
|
||||
alignItems: "center",
|
||||
marginBottom: 20,
|
||||
}}
|
||||
>
|
||||
<h3
|
||||
style={{
|
||||
color: "var(--text-primary)",
|
||||
fontWeight: 700,
|
||||
fontSize: 16,
|
||||
}}
|
||||
>
|
||||
{isEdit ? "Edit Server" : "Add Server"}
|
||||
</h3>
|
||||
<button
|
||||
type="button"
|
||||
onClick={onClose}
|
||||
style={{
|
||||
background: "none",
|
||||
border: "none",
|
||||
cursor: "pointer",
|
||||
color: "var(--text-muted)",
|
||||
}}
|
||||
>
|
||||
<X size={18} />
|
||||
</button>
|
||||
</div>
|
||||
{error && (
|
||||
<div
|
||||
style={{
|
||||
background: "rgba(239,68,68,0.1)",
|
||||
border: "1px solid rgba(239,68,68,0.3)",
|
||||
borderRadius: 8,
|
||||
padding: "10px 14px",
|
||||
marginBottom: 14,
|
||||
fontSize: 13,
|
||||
color: "#ef4444",
|
||||
}}
|
||||
>
|
||||
{error}
|
||||
</div>
|
||||
)}
|
||||
<form
|
||||
onSubmit={submit}
|
||||
style={{ display: "flex", flexDirection: "column", gap: 14 }}
|
||||
>
|
||||
<div
|
||||
style={{ display: "grid", gridTemplateColumns: "1fr 1fr", gap: 12 }}
|
||||
>
|
||||
<div>
|
||||
<label
|
||||
style={{
|
||||
fontSize: 12,
|
||||
color: "var(--text-muted)",
|
||||
display: "block",
|
||||
marginBottom: 5,
|
||||
}}
|
||||
>
|
||||
Name *
|
||||
</label>
|
||||
<input
|
||||
className="input"
|
||||
value={form.name}
|
||||
onChange={(e) => setForm({ ...form, name: e.target.value })}
|
||||
placeholder="prod-01"
|
||||
required
|
||||
style={{ width: "100%" }}
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label
|
||||
style={{
|
||||
fontSize: 12,
|
||||
color: "var(--text-muted)",
|
||||
display: "block",
|
||||
marginBottom: 5,
|
||||
}}
|
||||
>
|
||||
IP Address *
|
||||
</label>
|
||||
<input
|
||||
className="input"
|
||||
value={form.ip}
|
||||
onChange={(e) => setForm({ ...form, ip: e.target.value })}
|
||||
placeholder="192.168.1.10"
|
||||
required
|
||||
style={{ width: "100%" }}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
style={{ display: "grid", gridTemplateColumns: "1fr 1fr", gap: 12 }}
|
||||
>
|
||||
<div>
|
||||
<label
|
||||
style={{
|
||||
fontSize: 12,
|
||||
color: "var(--text-muted)",
|
||||
display: "block",
|
||||
marginBottom: 5,
|
||||
}}
|
||||
>
|
||||
SSH Port *
|
||||
</label>
|
||||
<input
|
||||
className="input"
|
||||
type="number"
|
||||
value={form.sshPort}
|
||||
onChange={(e) =>
|
||||
setForm({ ...form, sshPort: parseInt(e.target.value) })
|
||||
}
|
||||
min={1}
|
||||
max={65535}
|
||||
style={{ width: "100%" }}
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label
|
||||
style={{
|
||||
fontSize: 12,
|
||||
color: "var(--text-muted)",
|
||||
display: "block",
|
||||
marginBottom: 5,
|
||||
}}
|
||||
>
|
||||
Username *
|
||||
</label>
|
||||
<input
|
||||
className="input"
|
||||
value={form.username}
|
||||
onChange={(e) => setForm({ ...form, username: e.target.value })}
|
||||
placeholder="root"
|
||||
style={{ width: "100%" }}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<label
|
||||
style={{
|
||||
fontSize: 12,
|
||||
color: "var(--text-muted)",
|
||||
display: "block",
|
||||
marginBottom: 5,
|
||||
}}
|
||||
>
|
||||
Auth Type *
|
||||
</label>
|
||||
<div style={{ display: "flex", gap: 8 }}>
|
||||
{(["PASSWORD", "SSH_KEY"] as const).map((t) => (
|
||||
<button
|
||||
type="button"
|
||||
key={t}
|
||||
onClick={() => setForm({ ...form, authType: t })}
|
||||
style={{
|
||||
flex: 1,
|
||||
padding: "8px 0",
|
||||
borderRadius: 8,
|
||||
border: `1px solid ${form.authType === t ? "var(--accent)" : "var(--border)"}`,
|
||||
background:
|
||||
form.authType === t
|
||||
? "rgba(59,130,246,0.1)"
|
||||
: "var(--bg-input)",
|
||||
color:
|
||||
form.authType === t
|
||||
? "var(--accent)"
|
||||
: "var(--text-muted)",
|
||||
cursor: "pointer",
|
||||
fontSize: 12,
|
||||
fontWeight: 600,
|
||||
}}
|
||||
>
|
||||
{t === "PASSWORD" ? "Password" : "SSH Key"}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
{form.authType === "PASSWORD" && (
|
||||
<div>
|
||||
<label
|
||||
style={{
|
||||
fontSize: 12,
|
||||
color: "var(--text-muted)",
|
||||
display: "block",
|
||||
marginBottom: 5,
|
||||
}}
|
||||
>
|
||||
Password {isEdit ? "(leave blank to keep current)" : "*"}
|
||||
</label>
|
||||
<div style={{ position: "relative" }}>
|
||||
<input
|
||||
className="input"
|
||||
type={showPw ? "text" : "password"}
|
||||
value={form.password}
|
||||
onChange={(e) =>
|
||||
setForm({ ...form, password: e.target.value })
|
||||
}
|
||||
required={!isEdit}
|
||||
style={{ width: "100%", paddingRight: 36 }}
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setShowPw(!showPw)}
|
||||
style={{
|
||||
position: "absolute",
|
||||
right: 10,
|
||||
top: "50%",
|
||||
transform: "translateY(-50%)",
|
||||
background: "none",
|
||||
border: "none",
|
||||
cursor: "pointer",
|
||||
color: "var(--text-muted)",
|
||||
}}
|
||||
>
|
||||
{showPw ? <EyeOff size={14} /> : <Eye size={14} />}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
{form.authType === "SSH_KEY" && (
|
||||
<div>
|
||||
<label
|
||||
style={{
|
||||
fontSize: 12,
|
||||
color: "var(--text-muted)",
|
||||
display: "block",
|
||||
marginBottom: 5,
|
||||
}}
|
||||
>
|
||||
SSH Private Key {isEdit ? "(leave blank to keep current)" : "*"}
|
||||
</label>
|
||||
<textarea
|
||||
className="input"
|
||||
value={form.sshKey}
|
||||
onChange={(e) => setForm({ ...form, sshKey: e.target.value })}
|
||||
required={!isEdit}
|
||||
rows={6}
|
||||
placeholder="-----BEGIN OPENSSH PRIVATE KEY-----\n...\n-----END OPENSSH PRIVATE KEY-----"
|
||||
style={{
|
||||
width: "100%",
|
||||
fontFamily: "monospace",
|
||||
fontSize: 11,
|
||||
resize: "vertical",
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
<div
|
||||
style={{ display: "grid", gridTemplateColumns: "1fr 1fr", gap: 12 }}
|
||||
>
|
||||
<div>
|
||||
<label
|
||||
style={{
|
||||
fontSize: 12,
|
||||
color: "var(--text-muted)",
|
||||
display: "block",
|
||||
marginBottom: 5,
|
||||
}}
|
||||
>
|
||||
Location
|
||||
</label>
|
||||
<input
|
||||
className="input"
|
||||
value={form.location}
|
||||
onChange={(e) => setForm({ ...form, location: e.target.value })}
|
||||
placeholder="Singapore"
|
||||
list="location-suggestions"
|
||||
style={{ width: "100%" }}
|
||||
/>
|
||||
<datalist id="location-suggestions">
|
||||
<option value="Indonesia" />
|
||||
<option value="Malaysia" />
|
||||
<option value="Singapore" />
|
||||
<option value="India" />
|
||||
<option value="Japan" />
|
||||
<option value="Germany" />
|
||||
<option value="United States" />
|
||||
</datalist>
|
||||
</div>
|
||||
<div>
|
||||
<label
|
||||
style={{
|
||||
fontSize: 12,
|
||||
color: "var(--text-muted)",
|
||||
display: "block",
|
||||
marginBottom: 5,
|
||||
}}
|
||||
>
|
||||
Tags (comma-separated)
|
||||
</label>
|
||||
<input
|
||||
className="input"
|
||||
value={form.tags}
|
||||
onChange={(e) => setForm({ ...form, tags: e.target.value })}
|
||||
placeholder="production, web"
|
||||
style={{ width: "100%" }}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div style={{ display: "flex", gap: 10, marginTop: 4 }}>
|
||||
<button
|
||||
type="button"
|
||||
onClick={onClose}
|
||||
className="btn"
|
||||
style={{ flex: 1 }}
|
||||
>
|
||||
Cancel
|
||||
</button>
|
||||
<button
|
||||
type="submit"
|
||||
className="btn btn-primary"
|
||||
disabled={loading}
|
||||
style={{
|
||||
flex: 2,
|
||||
display: "flex",
|
||||
alignItems: "center",
|
||||
justifyContent: "center",
|
||||
gap: 8,
|
||||
}}
|
||||
>
|
||||
{loading && <Loader2 size={14} className="animate-spin" />}
|
||||
<RocketIcon size={14} />
|
||||
{isEdit ? "Save Changes" : "Add Server"}
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,510 @@
|
||||
import type { Server as ServerType, ServerMetric } from "@/lib/api";
|
||||
import { Activity, Cpu, HardDrive, Server, Wifi } from "lucide-react";
|
||||
import {
|
||||
Area,
|
||||
AreaChart,
|
||||
CartesianGrid,
|
||||
ResponsiveContainer,
|
||||
Tooltip,
|
||||
XAxis,
|
||||
YAxis,
|
||||
} from "recharts";
|
||||
import {
|
||||
formatBytes,
|
||||
formatDateTime,
|
||||
formatLastUpdated,
|
||||
formatUptime,
|
||||
} from "./server-utils";
|
||||
|
||||
type MetricWithNetwork = ServerMetric & {
|
||||
networkMbps?: number | string | null;
|
||||
networkMbit?: number | string | null;
|
||||
networkRxBps?: number | string | null;
|
||||
networkTxBps?: number | string | null;
|
||||
networkIn?: number | string | null;
|
||||
networkOut?: number | string | null;
|
||||
};
|
||||
|
||||
interface ServerMetricsPanelProps {
|
||||
server: ServerType;
|
||||
history: ServerMetric[];
|
||||
loading: boolean;
|
||||
error?: string | null;
|
||||
}
|
||||
|
||||
interface ChartPoint {
|
||||
label: string;
|
||||
timestamp: string;
|
||||
cpu: number;
|
||||
ram: number;
|
||||
disk: number;
|
||||
network: number | null;
|
||||
}
|
||||
|
||||
function toFiniteNumber(
|
||||
value: number | string | null | undefined,
|
||||
): number | null {
|
||||
if (value === null || value === undefined || value === "") {
|
||||
return null;
|
||||
}
|
||||
|
||||
const parsed = Number(value);
|
||||
return Number.isFinite(parsed) ? parsed : null;
|
||||
}
|
||||
|
||||
function extractNetworkMbps(metric: ServerMetric): number | null {
|
||||
const candidate = metric as MetricWithNetwork;
|
||||
const directValue =
|
||||
toFiniteNumber(candidate.networkMbps) ??
|
||||
toFiniteNumber(candidate.networkMbit);
|
||||
|
||||
if (directValue !== null) {
|
||||
return directValue;
|
||||
}
|
||||
|
||||
const rxBps =
|
||||
toFiniteNumber(candidate.networkRxBps) ??
|
||||
toFiniteNumber(candidate.networkIn);
|
||||
const txBps =
|
||||
toFiniteNumber(candidate.networkTxBps) ??
|
||||
toFiniteNumber(candidate.networkOut);
|
||||
|
||||
if (rxBps === null && txBps === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const totalBps = Math.max(0, (rxBps ?? 0) + (txBps ?? 0));
|
||||
return totalBps / 125000;
|
||||
}
|
||||
|
||||
function formatChartTime(value: string): string {
|
||||
const date = new Date(value);
|
||||
if (Number.isNaN(date.getTime())) {
|
||||
return "--:--";
|
||||
}
|
||||
|
||||
return date.toLocaleTimeString([], {
|
||||
hour: "2-digit",
|
||||
minute: "2-digit",
|
||||
});
|
||||
}
|
||||
|
||||
function ResourceCard({
|
||||
icon,
|
||||
label,
|
||||
accent,
|
||||
value,
|
||||
helper,
|
||||
}: {
|
||||
icon: React.ReactNode;
|
||||
label: string;
|
||||
accent: string;
|
||||
value: string;
|
||||
helper: string;
|
||||
}) {
|
||||
return (
|
||||
<div
|
||||
style={{
|
||||
border: "1px solid var(--metrics-border)",
|
||||
background: "var(--metrics-surface-strong)",
|
||||
borderRadius: 14,
|
||||
padding: 16,
|
||||
minHeight: 106,
|
||||
display: "grid",
|
||||
gap: 8,
|
||||
}}
|
||||
>
|
||||
<div
|
||||
style={{
|
||||
display: "flex",
|
||||
alignItems: "center",
|
||||
justifyContent: "space-between",
|
||||
gap: 12,
|
||||
}}
|
||||
>
|
||||
<span
|
||||
style={{
|
||||
display: "inline-flex",
|
||||
alignItems: "center",
|
||||
gap: 8,
|
||||
fontSize: 12,
|
||||
color: "var(--text-secondary)",
|
||||
fontWeight: 600,
|
||||
letterSpacing: "0.04em",
|
||||
textTransform: "uppercase",
|
||||
}}
|
||||
>
|
||||
<span
|
||||
style={{
|
||||
width: 28,
|
||||
height: 28,
|
||||
borderRadius: 10,
|
||||
display: "grid",
|
||||
placeItems: "center",
|
||||
background: `${accent}22`,
|
||||
color: accent,
|
||||
}}
|
||||
>
|
||||
{icon}
|
||||
</span>
|
||||
{label}
|
||||
</span>
|
||||
</div>
|
||||
<strong
|
||||
style={{
|
||||
color: "var(--text-primary)",
|
||||
fontSize: 22,
|
||||
lineHeight: 1.1,
|
||||
}}
|
||||
>
|
||||
{value}
|
||||
</strong>
|
||||
<span style={{ color: "var(--text-muted)", fontSize: 12 }}>{helper}</span>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function MetricChart({
|
||||
title,
|
||||
color,
|
||||
suffix,
|
||||
dataKey,
|
||||
data,
|
||||
}: {
|
||||
title: string;
|
||||
color: string;
|
||||
suffix: string;
|
||||
dataKey: keyof ChartPoint;
|
||||
data: ChartPoint[];
|
||||
}) {
|
||||
return (
|
||||
<div
|
||||
style={{
|
||||
border: "1px solid var(--metrics-border)",
|
||||
background: "var(--metrics-surface)",
|
||||
borderRadius: 14,
|
||||
padding: 16,
|
||||
minHeight: 220,
|
||||
}}
|
||||
>
|
||||
<div
|
||||
style={{
|
||||
display: "flex",
|
||||
justifyContent: "space-between",
|
||||
marginBottom: 12,
|
||||
}}
|
||||
>
|
||||
<div>
|
||||
<p
|
||||
style={{
|
||||
color: "var(--text-secondary)",
|
||||
fontSize: 12,
|
||||
fontWeight: 600,
|
||||
textTransform: "uppercase",
|
||||
letterSpacing: "0.08em",
|
||||
}}
|
||||
>
|
||||
{title}
|
||||
</p>
|
||||
<p style={{ color: "var(--text-muted)", fontSize: 12 }}>
|
||||
Last {data.length} samples
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<div style={{ width: "100%", minWidth: 0, height: 150, minHeight: 150 }}>
|
||||
<ResponsiveContainer width="100%" height="100%">
|
||||
<AreaChart data={data}>
|
||||
<defs>
|
||||
<linearGradient
|
||||
id={`gradient-${String(dataKey)}`}
|
||||
x1="0"
|
||||
y1="0"
|
||||
x2="0"
|
||||
y2="1"
|
||||
>
|
||||
<stop offset="5%" stopColor={color} stopOpacity={0.35} />
|
||||
<stop offset="95%" stopColor={color} stopOpacity={0.04} />
|
||||
</linearGradient>
|
||||
</defs>
|
||||
<CartesianGrid stroke="var(--metrics-grid)" vertical={false} />
|
||||
<XAxis
|
||||
dataKey="label"
|
||||
tick={{ fill: "var(--metrics-axis)", fontSize: 11 }}
|
||||
axisLine={false}
|
||||
tickLine={false}
|
||||
/>
|
||||
<YAxis
|
||||
tick={{ fill: "var(--metrics-axis)", fontSize: 11 }}
|
||||
axisLine={false}
|
||||
tickLine={false}
|
||||
width={42}
|
||||
tickFormatter={(value: number) => `${value}${suffix}`}
|
||||
/>
|
||||
<Tooltip
|
||||
contentStyle={{
|
||||
background: "var(--metrics-tooltip-bg)",
|
||||
border: "1px solid var(--metrics-border-muted)",
|
||||
borderRadius: 12,
|
||||
color: "var(--metrics-tooltip-text)",
|
||||
}}
|
||||
labelStyle={{ color: "var(--metrics-tooltip-label)" }}
|
||||
formatter={(value) => [`${value ?? 0}${suffix}`, title]}
|
||||
labelFormatter={(_, payload) => {
|
||||
const point = payload?.[0]?.payload as ChartPoint | undefined;
|
||||
return point ? formatDateTime(point.timestamp) : "";
|
||||
}}
|
||||
/>
|
||||
<Area
|
||||
type="monotone"
|
||||
dataKey={dataKey}
|
||||
stroke={color}
|
||||
strokeWidth={2}
|
||||
fill={`url(#gradient-${String(dataKey)})`}
|
||||
dot={false}
|
||||
activeDot={{ r: 4 }}
|
||||
connectNulls
|
||||
/>
|
||||
</AreaChart>
|
||||
</ResponsiveContainer>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default function ServerMetricsPanel({
|
||||
server,
|
||||
history,
|
||||
loading,
|
||||
error,
|
||||
}: ServerMetricsPanelProps) {
|
||||
const samples =
|
||||
history.length > 0 ? history : server.metrics ? [server.metrics] : [];
|
||||
const latest = samples.at(-1) ?? server.metrics ?? null;
|
||||
const chartData: ChartPoint[] = samples.map((metric) => ({
|
||||
label: formatChartTime(metric.recordedAt),
|
||||
timestamp: metric.recordedAt,
|
||||
cpu: Number(metric.cpuPct.toFixed(1)),
|
||||
ram: Number(metric.ramPct.toFixed(1)),
|
||||
disk: Number(metric.diskPct.toFixed(1)),
|
||||
network: extractNetworkMbps(metric),
|
||||
}));
|
||||
const hasNetworkData = chartData.some((item) => item.network !== null);
|
||||
const latestNetwork =
|
||||
[...chartData].reverse().find((item) => item.network !== null)?.network ??
|
||||
null;
|
||||
|
||||
if (loading) {
|
||||
return (
|
||||
<div
|
||||
style={{
|
||||
padding: 20,
|
||||
display: "flex",
|
||||
alignItems: "center",
|
||||
gap: 10,
|
||||
color: "var(--text-muted)",
|
||||
}}
|
||||
>
|
||||
<Activity size={16} className="animate-spin" />
|
||||
Loading metrics history for {server.name}...
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (error) {
|
||||
return (
|
||||
<div
|
||||
style={{
|
||||
padding: 20,
|
||||
color: "var(--metrics-error-text)",
|
||||
fontSize: 13,
|
||||
borderRadius: 12,
|
||||
border: "1px solid var(--metrics-error-border)",
|
||||
background: "var(--metrics-error-bg)",
|
||||
}}
|
||||
>
|
||||
Failed to load metrics history: {error}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (!latest) {
|
||||
return (
|
||||
<div
|
||||
style={{
|
||||
padding: 20,
|
||||
color: "var(--text-muted)",
|
||||
fontSize: 13,
|
||||
}}
|
||||
>
|
||||
Metrics are not available for this server yet. Run Refresh Metrics to
|
||||
collect the first sample.
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div style={{ display: "grid", gap: 18 }}>
|
||||
<div
|
||||
style={{
|
||||
display: "flex",
|
||||
justifyContent: "space-between",
|
||||
alignItems: "flex-start",
|
||||
gap: 16,
|
||||
flexWrap: "wrap",
|
||||
}}
|
||||
>
|
||||
<div style={{ display: "grid", gap: 4 }}>
|
||||
<div style={{ display: "flex", alignItems: "center", gap: 10 }}>
|
||||
<span
|
||||
style={{
|
||||
width: 34,
|
||||
height: 34,
|
||||
borderRadius: 12,
|
||||
display: "grid",
|
||||
placeItems: "center",
|
||||
background: "rgba(59, 130, 246, 0.12)",
|
||||
color: "var(--metrics-server-accent)",
|
||||
}}
|
||||
>
|
||||
<Server size={16} />
|
||||
</span>
|
||||
<div>
|
||||
<strong style={{ color: "var(--text-primary)", fontSize: 16 }}>
|
||||
{server.name}
|
||||
</strong>
|
||||
<p style={{ color: "var(--text-muted)", fontSize: 12 }}>
|
||||
{server.ip}:{server.sshPort}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<p style={{ color: "var(--text-secondary)", fontSize: 13 }}>
|
||||
Latest sample {formatLastUpdated(latest.recordedAt)} with{" "}
|
||||
{samples.length} point history.
|
||||
</p>
|
||||
</div>
|
||||
<div
|
||||
style={{
|
||||
padding: "10px 12px",
|
||||
borderRadius: 12,
|
||||
border: "1px solid var(--metrics-border)",
|
||||
background: "var(--metrics-surface)",
|
||||
fontSize: 12,
|
||||
color: "var(--text-secondary)",
|
||||
}}
|
||||
>
|
||||
Uptime {formatUptime(latest.uptimeSec)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div
|
||||
style={{
|
||||
display: "grid",
|
||||
gridTemplateColumns: "repeat(auto-fit, minmax(190px, 1fr))",
|
||||
gap: 14,
|
||||
}}
|
||||
>
|
||||
<ResourceCard
|
||||
icon={<Cpu size={15} />}
|
||||
label="CPU"
|
||||
accent="#3b82f6"
|
||||
value={`${latest.cpuPct.toFixed(1)}%`}
|
||||
helper={`Updated ${formatLastUpdated(latest.recordedAt)}`}
|
||||
/>
|
||||
<ResourceCard
|
||||
icon={<Activity size={15} />}
|
||||
label="RAM"
|
||||
accent="#8b5cf6"
|
||||
value={`${latest.ramPct.toFixed(1)}%`}
|
||||
helper={`${formatBytes(latest.ramUsed)} / ${formatBytes(latest.ramTotal)}`}
|
||||
/>
|
||||
<ResourceCard
|
||||
icon={<HardDrive size={15} />}
|
||||
label="Disk"
|
||||
accent="#f59e0b"
|
||||
value={`${latest.diskPct.toFixed(1)}%`}
|
||||
helper={`${formatBytes(latest.diskUsed)} / ${formatBytes(latest.diskTotal)}`}
|
||||
/>
|
||||
<ResourceCard
|
||||
icon={<Wifi size={15} />}
|
||||
label="Network I/O"
|
||||
accent="#06b6d4"
|
||||
value={
|
||||
latestNetwork !== null
|
||||
? `${latestNetwork.toFixed(2)} Mbit/s`
|
||||
: "No data"
|
||||
}
|
||||
helper={
|
||||
latestNetwork !== null
|
||||
? "Live Rx + Tx throughput sample"
|
||||
: "No network sample stored for this point"
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div
|
||||
style={{
|
||||
display: "grid",
|
||||
gridTemplateColumns: "repeat(auto-fit, minmax(260px, 1fr))",
|
||||
gap: 14,
|
||||
}}
|
||||
>
|
||||
<MetricChart
|
||||
title="CPU"
|
||||
color="#3b82f6"
|
||||
suffix="%"
|
||||
dataKey="cpu"
|
||||
data={chartData}
|
||||
/>
|
||||
<MetricChart
|
||||
title="RAM"
|
||||
color="#8b5cf6"
|
||||
suffix="%"
|
||||
dataKey="ram"
|
||||
data={chartData}
|
||||
/>
|
||||
<MetricChart
|
||||
title="Disk"
|
||||
color="#f59e0b"
|
||||
suffix="%"
|
||||
dataKey="disk"
|
||||
data={chartData}
|
||||
/>
|
||||
{hasNetworkData ? (
|
||||
<MetricChart
|
||||
title="Network I/O"
|
||||
color="#06b6d4"
|
||||
suffix=" Mbit/s"
|
||||
dataKey="network"
|
||||
data={chartData}
|
||||
/>
|
||||
) : (
|
||||
<div
|
||||
style={{
|
||||
border: "1px dashed var(--metrics-border-muted)",
|
||||
borderRadius: 14,
|
||||
padding: 18,
|
||||
minHeight: 220,
|
||||
display: "grid",
|
||||
alignContent: "center",
|
||||
justifyItems: "center",
|
||||
gap: 8,
|
||||
color: "var(--text-muted)",
|
||||
background: "var(--metrics-surface-soft)",
|
||||
textAlign: "center",
|
||||
}}
|
||||
>
|
||||
<Wifi size={18} />
|
||||
<strong style={{ color: "var(--text-secondary)", fontSize: 14 }}>
|
||||
Network metrics not available yet
|
||||
</strong>
|
||||
<p style={{ maxWidth: 260, fontSize: 12 }}>
|
||||
No historical network throughput has been stored for this server
|
||||
yet. Run Refresh Metrics or wait for the next polling cycle to
|
||||
collect the first sample.
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
import { Activity, CheckCircle, Server, XCircle } from "lucide-react";
|
||||
|
||||
interface ServersSummaryProps {
|
||||
counts: {
|
||||
total: number;
|
||||
online: number;
|
||||
offline: number;
|
||||
containers: number;
|
||||
};
|
||||
}
|
||||
|
||||
export default function ServersSummary({ counts }: ServersSummaryProps) {
|
||||
const items = [
|
||||
{
|
||||
label: "Total Servers",
|
||||
value: counts.total,
|
||||
color: "#3b82f6",
|
||||
icon: Server,
|
||||
},
|
||||
{
|
||||
label: "Online",
|
||||
value: counts.online,
|
||||
color: "#10b981",
|
||||
icon: CheckCircle,
|
||||
},
|
||||
{
|
||||
label: "Offline",
|
||||
value: counts.offline,
|
||||
color: "#ef4444",
|
||||
icon: XCircle,
|
||||
},
|
||||
{
|
||||
label: "Total Containers",
|
||||
value: counts.containers,
|
||||
color: "#8b5cf6",
|
||||
icon: Activity,
|
||||
},
|
||||
];
|
||||
|
||||
return (
|
||||
<div
|
||||
style={{
|
||||
display: "grid",
|
||||
gridTemplateColumns: "repeat(auto-fit, minmax(120px, 1fr))",
|
||||
gap: 12,
|
||||
}}
|
||||
>
|
||||
{items.map((item) => {
|
||||
const Icon = item.icon;
|
||||
return (
|
||||
<div
|
||||
key={item.label}
|
||||
className="card"
|
||||
style={{
|
||||
padding: 16,
|
||||
display: "flex",
|
||||
alignItems: "center",
|
||||
gap: 14,
|
||||
}}
|
||||
>
|
||||
<div
|
||||
style={{
|
||||
width: 42,
|
||||
height: 42,
|
||||
borderRadius: 10,
|
||||
background: `${item.color}15`,
|
||||
border: `1px solid ${item.color}25`,
|
||||
display: "flex",
|
||||
alignItems: "center",
|
||||
justifyContent: "center",
|
||||
flexShrink: 0,
|
||||
}}
|
||||
>
|
||||
<Icon size={18} style={{ color: item.color }} />
|
||||
</div>
|
||||
<div>
|
||||
<p
|
||||
style={{
|
||||
fontSize: 22,
|
||||
fontWeight: 700,
|
||||
color: "var(--text-primary)",
|
||||
lineHeight: 1,
|
||||
}}
|
||||
>
|
||||
{item.value}
|
||||
</p>
|
||||
<p
|
||||
style={{
|
||||
fontSize: 11,
|
||||
color: "var(--text-muted)",
|
||||
marginTop: 3,
|
||||
}}
|
||||
>
|
||||
{item.label}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,558 @@
|
||||
import TablePagination from "@/components/TablePagination";
|
||||
import type {
|
||||
DockerRuntimeStatus,
|
||||
Server as ServerType,
|
||||
ServerMetric,
|
||||
} from "@/lib/api";
|
||||
import { Fragment, useCallback, useState } from "react";
|
||||
import {
|
||||
Activity,
|
||||
Boxes,
|
||||
Loader2,
|
||||
MoreVertical,
|
||||
Settings2,
|
||||
Pencil,
|
||||
RefreshCw,
|
||||
Server,
|
||||
Terminal,
|
||||
Trash2,
|
||||
Wifi,
|
||||
} from "lucide-react";
|
||||
import DockerBadge from "./DockerBadge";
|
||||
import ServerMetricsPanel from "./ServerMetricsPanel";
|
||||
import StatusBadge from "./StatusBadge";
|
||||
import { formatBytes, formatLastUpdated, formatUptime } from "./server-utils";
|
||||
|
||||
interface ServersTableProps {
|
||||
loading: boolean;
|
||||
items: ServerType[];
|
||||
currentPage: number;
|
||||
totalPages: number;
|
||||
totalItems: number;
|
||||
startItem: number;
|
||||
endItem: number;
|
||||
dockerStates: Record<string, DockerRuntimeStatus | null>;
|
||||
dockerErrors: Record<string, string | null>;
|
||||
dockerLoading: Record<string, boolean>;
|
||||
refreshing: Record<string, boolean>;
|
||||
installingDocker: Record<string, boolean>;
|
||||
deleting: string | null;
|
||||
openMenuId: string | null;
|
||||
expandedMetricsId: string | null;
|
||||
metricsHistory: Record<string, ServerMetric[]>;
|
||||
metricsHistoryLoading: Record<string, boolean>;
|
||||
metricsHistoryError: Record<string, string | null>;
|
||||
onPageChange: (page: number) => void;
|
||||
onRefreshMetrics: (serverId: string) => void | Promise<void>;
|
||||
onTestConnection: (serverId: string) => void | Promise<void>;
|
||||
onOpenTerminal: (server: ServerType) => void;
|
||||
onInstallDocker: (server: ServerType) => void | Promise<void>;
|
||||
onToggleMenu: (serverId: string) => void;
|
||||
onOpenConfig: (server: ServerType) => void;
|
||||
onToggleMetrics: (server: ServerType) => void | Promise<void>;
|
||||
onEdit: (server: ServerType) => void;
|
||||
onDelete: (serverId: string) => void | Promise<void>;
|
||||
}
|
||||
|
||||
export default function ServersTable({
|
||||
loading,
|
||||
items,
|
||||
currentPage,
|
||||
totalPages,
|
||||
totalItems,
|
||||
startItem,
|
||||
endItem,
|
||||
dockerStates,
|
||||
dockerErrors,
|
||||
dockerLoading,
|
||||
refreshing,
|
||||
installingDocker,
|
||||
deleting,
|
||||
openMenuId,
|
||||
expandedMetricsId,
|
||||
metricsHistory,
|
||||
metricsHistoryLoading,
|
||||
metricsHistoryError,
|
||||
onPageChange,
|
||||
onRefreshMetrics,
|
||||
onTestConnection,
|
||||
onOpenTerminal,
|
||||
onInstallDocker,
|
||||
onToggleMenu,
|
||||
onOpenConfig,
|
||||
onToggleMetrics,
|
||||
onEdit,
|
||||
onDelete,
|
||||
}: ServersTableProps) {
|
||||
const [menuPosition, setMenuPosition] = useState<{
|
||||
top: number;
|
||||
left: number;
|
||||
} | null>(null);
|
||||
|
||||
const handleMenuToggle = useCallback(
|
||||
(event: React.MouseEvent<HTMLButtonElement>, serverId: string) => {
|
||||
event.stopPropagation();
|
||||
|
||||
const rect = event.currentTarget.getBoundingClientRect();
|
||||
const menuWidth = 176;
|
||||
const menuHeight = 174;
|
||||
const nextLeft = Math.min(
|
||||
window.innerWidth - menuWidth - 12,
|
||||
Math.max(12, rect.right - menuWidth + rect.width),
|
||||
);
|
||||
const nextTop = Math.min(
|
||||
window.innerHeight - menuHeight - 12,
|
||||
rect.bottom + 6,
|
||||
);
|
||||
|
||||
setMenuPosition({ top: Math.max(12, nextTop), left: nextLeft });
|
||||
onToggleMenu(serverId);
|
||||
},
|
||||
[onToggleMenu],
|
||||
);
|
||||
|
||||
return (
|
||||
<div className="card" style={{ overflow: "visible" }}>
|
||||
{loading ? (
|
||||
<div style={{ padding: 48, textAlign: "center" }}>
|
||||
<Loader2
|
||||
size={28}
|
||||
className="animate-spin"
|
||||
style={{ color: "var(--accent)", margin: "0 auto 12px" }}
|
||||
/>
|
||||
<p style={{ color: "var(--text-muted)", fontSize: 14 }}>
|
||||
Loading servers...
|
||||
</p>
|
||||
</div>
|
||||
) : items.length === 0 ? (
|
||||
<div style={{ padding: 48, textAlign: "center" }}>
|
||||
<Server
|
||||
size={36}
|
||||
style={{
|
||||
color: "var(--text-muted)",
|
||||
margin: "0 auto 12px",
|
||||
opacity: 0.4,
|
||||
}}
|
||||
/>
|
||||
<p style={{ color: "var(--text-muted)", fontSize: 14 }}>
|
||||
No servers found. Add your first server above.
|
||||
</p>
|
||||
</div>
|
||||
) : (
|
||||
<>
|
||||
<div style={{ overflowX: "auto" }}>
|
||||
<table className="data-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Server</th>
|
||||
<th>Status</th>
|
||||
<th>Docker</th>
|
||||
<th>CPU</th>
|
||||
<th>RAM</th>
|
||||
<th>Disk</th>
|
||||
<th>Containers</th>
|
||||
<th>Uptime</th>
|
||||
<th>Last Updated</th>
|
||||
<th>Location</th>
|
||||
<th style={{ textAlign: "right" }}>Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{items.map((server) => {
|
||||
const metrics = server.metrics;
|
||||
const docker = dockerStates[server.id];
|
||||
const canInstallDocker =
|
||||
!dockerLoading[server.id] &&
|
||||
!!docker &&
|
||||
!docker.available &&
|
||||
docker.canInstall;
|
||||
const isMetricsOpen = expandedMetricsId === server.id;
|
||||
|
||||
return (
|
||||
<Fragment key={server.id}>
|
||||
<tr>
|
||||
<td>
|
||||
<div
|
||||
style={{
|
||||
display: "flex",
|
||||
alignItems: "center",
|
||||
gap: 10,
|
||||
}}
|
||||
>
|
||||
<div
|
||||
style={{
|
||||
width: 34,
|
||||
height: 34,
|
||||
borderRadius: 8,
|
||||
background: "var(--bg-input)",
|
||||
border: "1px solid var(--border)",
|
||||
display: "flex",
|
||||
alignItems: "center",
|
||||
justifyContent: "center",
|
||||
}}
|
||||
>
|
||||
<Server size={14} style={{ color: "#3b82f6" }} />
|
||||
</div>
|
||||
<div>
|
||||
<p
|
||||
style={{
|
||||
color: "var(--text-primary)",
|
||||
fontWeight: 600,
|
||||
fontSize: 13,
|
||||
}}
|
||||
>
|
||||
{server.name}
|
||||
</p>
|
||||
<p
|
||||
style={{
|
||||
color: "var(--text-muted)",
|
||||
fontSize: 11,
|
||||
fontFamily: "monospace",
|
||||
}}
|
||||
>
|
||||
{server.ip}:{server.sshPort}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
<StatusBadge status={server.status} />
|
||||
</td>
|
||||
<td>
|
||||
<DockerBadge
|
||||
docker={dockerStates[server.id]}
|
||||
error={dockerErrors[server.id]}
|
||||
loading={dockerLoading[server.id]}
|
||||
/>
|
||||
</td>
|
||||
<td>
|
||||
<div>
|
||||
<span
|
||||
style={{
|
||||
fontSize: 12,
|
||||
color:
|
||||
(metrics?.cpuPct ?? 0) > 80
|
||||
? "#ef4444"
|
||||
: "var(--text-secondary)",
|
||||
fontWeight: 500,
|
||||
}}
|
||||
>
|
||||
{(metrics?.cpuPct ?? 0).toFixed(1)}%
|
||||
</span>
|
||||
<div
|
||||
className="progress-bar"
|
||||
style={{ width: 80, marginTop: 4 }}
|
||||
>
|
||||
<div
|
||||
className="progress-fill"
|
||||
style={{
|
||||
width: `${metrics?.cpuPct ?? 0}%`,
|
||||
background:
|
||||
(metrics?.cpuPct ?? 0) > 80
|
||||
? "#ef4444"
|
||||
: "#3b82f6",
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
<div>
|
||||
<span
|
||||
style={{
|
||||
fontSize: 12,
|
||||
color:
|
||||
(metrics?.ramPct ?? 0) > 80
|
||||
? "#ef4444"
|
||||
: "var(--text-secondary)",
|
||||
fontWeight: 500,
|
||||
}}
|
||||
>
|
||||
{(metrics?.ramPct ?? 0).toFixed(1)}%
|
||||
</span>
|
||||
<div
|
||||
className="progress-bar"
|
||||
style={{ width: 80, marginTop: 4 }}
|
||||
>
|
||||
<div
|
||||
className="progress-fill"
|
||||
style={{
|
||||
width: `${metrics?.ramPct ?? 0}%`,
|
||||
background: "#8b5cf6",
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
{metrics ? (
|
||||
<p
|
||||
style={{
|
||||
fontSize: 10,
|
||||
color: "var(--text-muted)",
|
||||
marginTop: 2,
|
||||
}}
|
||||
>
|
||||
{formatBytes(metrics.ramUsed)}/
|
||||
{formatBytes(metrics.ramTotal)}
|
||||
</p>
|
||||
) : null}
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
<div>
|
||||
<span
|
||||
style={{
|
||||
fontSize: 12,
|
||||
color:
|
||||
(metrics?.diskPct ?? 0) > 80
|
||||
? "#ef4444"
|
||||
: "var(--text-secondary)",
|
||||
fontWeight: 500,
|
||||
}}
|
||||
>
|
||||
{(metrics?.diskPct ?? 0).toFixed(1)}%
|
||||
</span>
|
||||
<div
|
||||
className="progress-bar"
|
||||
style={{ width: 80, marginTop: 4 }}
|
||||
>
|
||||
<div
|
||||
className="progress-fill"
|
||||
style={{
|
||||
width: `${metrics?.diskPct ?? 0}%`,
|
||||
background: "#f59e0b",
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
<span
|
||||
style={{
|
||||
background: "rgba(59,130,246,0.1)",
|
||||
color: "#3b82f6",
|
||||
padding: "2px 8px",
|
||||
borderRadius: 6,
|
||||
fontSize: 12,
|
||||
fontWeight: 600,
|
||||
}}
|
||||
>
|
||||
{server.containers}
|
||||
</span>
|
||||
</td>
|
||||
<td
|
||||
style={{
|
||||
fontFamily: "monospace",
|
||||
fontSize: 11,
|
||||
color: "var(--text-secondary)",
|
||||
}}
|
||||
>
|
||||
{formatUptime(metrics?.uptimeSec)}
|
||||
</td>
|
||||
<td
|
||||
style={{
|
||||
fontSize: 11,
|
||||
color: "var(--text-muted)",
|
||||
whiteSpace: "nowrap",
|
||||
}}
|
||||
>
|
||||
{formatLastUpdated(
|
||||
metrics?.recordedAt ?? server.lastHealth,
|
||||
)}
|
||||
</td>
|
||||
<td
|
||||
style={{ fontSize: 12, color: "var(--text-muted)" }}
|
||||
>
|
||||
{server.location ?? "—"}
|
||||
</td>
|
||||
<td>
|
||||
<div
|
||||
style={{
|
||||
display: "flex",
|
||||
gap: 6,
|
||||
justifyContent: "flex-end",
|
||||
alignItems: "center",
|
||||
}}
|
||||
>
|
||||
<button
|
||||
title="Refresh metrics"
|
||||
onClick={() => void onRefreshMetrics(server.id)}
|
||||
className="btn btn-ghost"
|
||||
style={{ padding: "4px 8px", fontSize: 11 }}
|
||||
disabled={refreshing[server.id]}
|
||||
>
|
||||
{refreshing[server.id] ? (
|
||||
<Loader2 size={12} className="animate-spin" />
|
||||
) : (
|
||||
<RefreshCw size={12} />
|
||||
)}
|
||||
</button>
|
||||
<button
|
||||
title="Test SSH"
|
||||
onClick={() => void onTestConnection(server.id)}
|
||||
className="btn btn-ghost"
|
||||
style={{ padding: "4px 8px", fontSize: 11 }}
|
||||
disabled={refreshing[`test_${server.id}`]}
|
||||
>
|
||||
{refreshing[`test_${server.id}`] ? (
|
||||
<Loader2 size={12} className="animate-spin" />
|
||||
) : (
|
||||
<Wifi size={12} />
|
||||
)}
|
||||
</button>
|
||||
<button
|
||||
title="Terminal"
|
||||
onClick={() => onOpenTerminal(server)}
|
||||
className="btn btn-ghost"
|
||||
style={{ padding: "4px 8px", fontSize: 11 }}
|
||||
>
|
||||
<Terminal size={12} />
|
||||
</button>
|
||||
{canInstallDocker ? (
|
||||
<button
|
||||
title="Install Docker"
|
||||
onClick={() => void onInstallDocker(server)}
|
||||
className="btn btn-ghost"
|
||||
style={{
|
||||
padding: "4px 8px",
|
||||
fontSize: 11,
|
||||
color: "#10b981",
|
||||
}}
|
||||
disabled={installingDocker[server.id]}
|
||||
>
|
||||
{installingDocker[server.id] ? (
|
||||
<Loader2 size={12} className="animate-spin" />
|
||||
) : (
|
||||
<Boxes size={12} />
|
||||
)}
|
||||
</button>
|
||||
) : null}
|
||||
<button
|
||||
title="More actions"
|
||||
onClick={(event) =>
|
||||
handleMenuToggle(event, server.id)
|
||||
}
|
||||
className="btn btn-ghost"
|
||||
style={{ padding: "4px 8px", fontSize: 11 }}
|
||||
>
|
||||
<MoreVertical size={12} />
|
||||
</button>
|
||||
{openMenuId === server.id && menuPosition ? (
|
||||
<div
|
||||
className="card"
|
||||
onClick={(event) => event.stopPropagation()}
|
||||
style={{
|
||||
position: "fixed",
|
||||
top: menuPosition.top,
|
||||
left: menuPosition.left,
|
||||
minWidth: 176,
|
||||
padding: 6,
|
||||
display: "flex",
|
||||
flexDirection: "column",
|
||||
gap: 4,
|
||||
zIndex: 160,
|
||||
boxShadow: "0 18px 40px rgba(2, 6, 23, 0.42)",
|
||||
}}
|
||||
>
|
||||
<button
|
||||
onClick={() => onOpenConfig(server)}
|
||||
className="btn btn-ghost"
|
||||
style={{
|
||||
fontSize: 12,
|
||||
justifyContent: "flex-start",
|
||||
}}
|
||||
>
|
||||
<Settings2 size={12} /> Config Server
|
||||
</button>
|
||||
<button
|
||||
onClick={() => void onToggleMetrics(server)}
|
||||
className="btn btn-ghost"
|
||||
style={{
|
||||
fontSize: 12,
|
||||
justifyContent: "flex-start",
|
||||
color: isMetricsOpen
|
||||
? "var(--text-primary)"
|
||||
: "var(--text-secondary)",
|
||||
}}
|
||||
>
|
||||
<Activity size={12} />
|
||||
{isMetricsOpen
|
||||
? "Hide Monitor"
|
||||
: "Resource Monitor"}
|
||||
</button>
|
||||
<button
|
||||
onClick={() => onEdit(server)}
|
||||
className="btn btn-ghost"
|
||||
style={{
|
||||
fontSize: 12,
|
||||
justifyContent: "flex-start",
|
||||
}}
|
||||
>
|
||||
<Pencil size={12} /> Edit Server
|
||||
</button>
|
||||
<button
|
||||
onClick={() => void onDelete(server.id)}
|
||||
className="btn btn-ghost"
|
||||
style={{
|
||||
fontSize: 12,
|
||||
justifyContent: "flex-start",
|
||||
color: "#ef4444",
|
||||
}}
|
||||
disabled={deleting === server.id}
|
||||
>
|
||||
{deleting === server.id ? (
|
||||
<Loader2
|
||||
size={12}
|
||||
className="animate-spin"
|
||||
/>
|
||||
) : (
|
||||
<Trash2 size={12} />
|
||||
)}
|
||||
Remove Server
|
||||
</button>
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
{isMetricsOpen ? (
|
||||
<tr>
|
||||
<td colSpan={11} style={{ padding: "0 16px 16px" }}>
|
||||
<div
|
||||
style={{
|
||||
borderRadius: 16,
|
||||
border: "1px solid var(--metrics-border)",
|
||||
background: "var(--metrics-shell)",
|
||||
padding: 18,
|
||||
}}
|
||||
>
|
||||
<ServerMetricsPanel
|
||||
server={server}
|
||||
history={metricsHistory[server.id] ?? []}
|
||||
loading={
|
||||
metricsHistoryLoading[server.id] ?? false
|
||||
}
|
||||
error={metricsHistoryError[server.id] ?? null}
|
||||
/>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
) : null}
|
||||
</Fragment>
|
||||
);
|
||||
})}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<TablePagination
|
||||
currentPage={currentPage}
|
||||
totalPages={totalPages}
|
||||
totalItems={totalItems}
|
||||
startItem={startItem}
|
||||
endItem={endItem}
|
||||
itemLabel="servers"
|
||||
onPageChange={onPageChange}
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
import SearchField from "@/components/SearchField";
|
||||
import { Plus, RefreshCw } from "lucide-react";
|
||||
|
||||
interface ServersToolbarProps {
|
||||
search: string;
|
||||
filter: string;
|
||||
totalCount: number;
|
||||
onSearchChange: (value: string) => void;
|
||||
onFilterChange: (value: string) => void;
|
||||
onRefresh: () => void | Promise<void>;
|
||||
onAddServer: () => void;
|
||||
}
|
||||
|
||||
export default function ServersToolbar({
|
||||
search,
|
||||
filter,
|
||||
totalCount,
|
||||
onSearchChange,
|
||||
onFilterChange,
|
||||
onRefresh,
|
||||
onAddServer,
|
||||
}: ServersToolbarProps) {
|
||||
return (
|
||||
<div
|
||||
className="card ui-responsive-toolbar"
|
||||
style={{
|
||||
padding: "12px 16px",
|
||||
}}
|
||||
>
|
||||
<SearchField
|
||||
placeholder="Search servers..."
|
||||
value={search}
|
||||
onChange={(event) => onSearchChange(event.target.value)}
|
||||
containerStyle={{ flex: "1 1 360px", minWidth: 240 }}
|
||||
/>
|
||||
<div className="ui-pill-switch no-scrollbar" style={{}}>
|
||||
{["ALL", "ONLINE", "WARNING", "OFFLINE"].map((item) => (
|
||||
<button
|
||||
key={item}
|
||||
type="button"
|
||||
onClick={() => onFilterChange(item)}
|
||||
style={{
|
||||
padding: "5px 14px",
|
||||
borderRadius: 6,
|
||||
border: "none",
|
||||
cursor: "pointer",
|
||||
fontSize: 12,
|
||||
fontWeight: 500,
|
||||
background: filter === item ? "var(--bg-card)" : "transparent",
|
||||
color:
|
||||
filter === item ? "var(--text-primary)" : "var(--text-muted)",
|
||||
transition: "all 0.15s",
|
||||
}}
|
||||
>
|
||||
{item === "ALL"
|
||||
? `All (${totalCount})`
|
||||
: item.charAt(0) + item.slice(1).toLowerCase()}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
<div className="ui-toolbar-actions" style={{}}>
|
||||
<button
|
||||
className="btn btn-ghost"
|
||||
style={{ fontSize: 12 }}
|
||||
onClick={() => void onRefresh()}
|
||||
>
|
||||
<RefreshCw size={12} /> Refresh
|
||||
</button>
|
||||
<button
|
||||
className="btn btn-primary"
|
||||
style={{ fontSize: 12 }}
|
||||
onClick={onAddServer}
|
||||
>
|
||||
<Plus size={12} /> Add Server
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
import { AlertTriangle, CheckCircle, XCircle } from "lucide-react";
|
||||
|
||||
interface StatusBadgeProps {
|
||||
status: string;
|
||||
}
|
||||
|
||||
export default function StatusBadge({ status }: StatusBadgeProps) {
|
||||
const cfg: Record<
|
||||
string,
|
||||
{
|
||||
className: string;
|
||||
icon: React.ReactNode;
|
||||
label: string;
|
||||
}
|
||||
> = {
|
||||
ONLINE: {
|
||||
className: "badge-online",
|
||||
icon: <CheckCircle size={10} />,
|
||||
label: "Online",
|
||||
},
|
||||
WARNING: {
|
||||
className: "badge-warning",
|
||||
icon: <AlertTriangle size={10} />,
|
||||
label: "Warning",
|
||||
},
|
||||
OFFLINE: {
|
||||
className: "badge-offline",
|
||||
icon: <XCircle size={10} />,
|
||||
label: "Offline",
|
||||
},
|
||||
UNKNOWN: {
|
||||
className: "",
|
||||
icon: <XCircle size={10} />,
|
||||
label: "Unknown",
|
||||
},
|
||||
};
|
||||
const current = cfg[status] || cfg.UNKNOWN;
|
||||
|
||||
return (
|
||||
<span
|
||||
className={`ui-badge ${current.className}`}
|
||||
style={{
|
||||
gap: 5,
|
||||
}}
|
||||
>
|
||||
{status === "ONLINE" ? (
|
||||
<span
|
||||
style={{
|
||||
width: 5,
|
||||
height: 5,
|
||||
borderRadius: "50%",
|
||||
background: "currentColor",
|
||||
display: "inline-block",
|
||||
}}
|
||||
className="animate-pulse-dot"
|
||||
/>
|
||||
) : (
|
||||
current.icon
|
||||
)}
|
||||
{current.label}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,455 @@
|
||||
import type {
|
||||
Server as ServerType,
|
||||
ServerConfigSnapshot,
|
||||
WebStackAction,
|
||||
WebStackComponentKey,
|
||||
WebStackComponentStatus,
|
||||
} from "@/lib/api";
|
||||
|
||||
export type ServerConfigTab =
|
||||
| "overview"
|
||||
| "users"
|
||||
| "services"
|
||||
| "web-server"
|
||||
| "mounts"
|
||||
| "actions";
|
||||
|
||||
export type UserBadgeTone =
|
||||
| "danger"
|
||||
| "success"
|
||||
| "neutral"
|
||||
| "warning"
|
||||
| "info";
|
||||
|
||||
export type ServerConfigNotice = {
|
||||
tab: ServerConfigTab;
|
||||
tone: "success" | "error" | "info";
|
||||
title: string;
|
||||
summary: string;
|
||||
details?: string[];
|
||||
detailText?: string;
|
||||
};
|
||||
|
||||
export type ServerPendingConfirm =
|
||||
| {
|
||||
kind: "server";
|
||||
action: "restart-nginx" | "reboot" | "prune-docker";
|
||||
title: string;
|
||||
description: string;
|
||||
confirmLabel: string;
|
||||
tone: "danger" | "warning" | "info";
|
||||
pruneOptions?: {
|
||||
images: boolean;
|
||||
containers: boolean;
|
||||
networks: boolean;
|
||||
volumes: boolean;
|
||||
buildCache: boolean;
|
||||
};
|
||||
}
|
||||
| {
|
||||
kind: "docker";
|
||||
action: "install" | "uninstall" | "reinstall";
|
||||
title: string;
|
||||
description: string;
|
||||
confirmLabel: string;
|
||||
tone: "danger" | "warning" | "info";
|
||||
}
|
||||
| {
|
||||
kind: "service";
|
||||
serviceName: string;
|
||||
title: string;
|
||||
description: string;
|
||||
confirmLabel: string;
|
||||
tone: "danger" | "warning" | "info";
|
||||
}
|
||||
| {
|
||||
kind: "web-stack";
|
||||
component: WebStackComponentKey;
|
||||
action: WebStackAction;
|
||||
title: string;
|
||||
description: string;
|
||||
confirmLabel: string;
|
||||
tone: "danger" | "warning" | "info";
|
||||
};
|
||||
|
||||
export function canRestartService(serviceName: string): boolean {
|
||||
return [
|
||||
"docker",
|
||||
"fail2ban",
|
||||
"caddy",
|
||||
"nginx",
|
||||
"apache2",
|
||||
"httpd",
|
||||
"ssh",
|
||||
"sshd",
|
||||
"ufw",
|
||||
].includes(serviceName.toLowerCase());
|
||||
}
|
||||
|
||||
export function getWebStackActionLabel(action: WebStackAction): string {
|
||||
switch (action) {
|
||||
case "install":
|
||||
return "Install";
|
||||
case "upgrade":
|
||||
return "Upgrade";
|
||||
case "reinstall":
|
||||
return "Reinstall";
|
||||
case "remove":
|
||||
return "Remove";
|
||||
}
|
||||
}
|
||||
|
||||
export function getDockerActionLabel(
|
||||
action: "install" | "uninstall" | "reinstall",
|
||||
): string {
|
||||
switch (action) {
|
||||
case "install":
|
||||
return "Install Docker";
|
||||
case "uninstall":
|
||||
return "Remove Docker";
|
||||
case "reinstall":
|
||||
return "Reinstall Docker";
|
||||
}
|
||||
}
|
||||
|
||||
export function getWebStackActionStyle(action: WebStackAction) {
|
||||
if (action === "remove") {
|
||||
return {
|
||||
color: "#ef4444",
|
||||
border: "1px solid rgba(239,68,68,0.18)",
|
||||
background: "rgba(239,68,68,0.08)",
|
||||
};
|
||||
}
|
||||
|
||||
if (action === "upgrade") {
|
||||
return {
|
||||
color: "#f59e0b",
|
||||
border: "1px solid rgba(245,158,11,0.18)",
|
||||
background: "rgba(245,158,11,0.08)",
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
color: "#3b82f6",
|
||||
border: "1px solid rgba(59,130,246,0.18)",
|
||||
background: "rgba(59,130,246,0.08)",
|
||||
};
|
||||
}
|
||||
|
||||
export function getWebStackComponentLabel(
|
||||
component: WebStackComponentKey,
|
||||
): string {
|
||||
switch (component) {
|
||||
case "nginx":
|
||||
return "Nginx";
|
||||
case "apache":
|
||||
return "Apache";
|
||||
case "caddy":
|
||||
return "Caddy";
|
||||
case "php":
|
||||
return "PHP + FPM";
|
||||
case "nodejs":
|
||||
return "Node.js";
|
||||
case "pm2":
|
||||
return "PM2";
|
||||
case "mysql":
|
||||
return "MariaDB / MySQL";
|
||||
case "redis":
|
||||
return "Redis";
|
||||
case "postgresql":
|
||||
return "PostgreSQL";
|
||||
case "composer":
|
||||
return "Composer";
|
||||
case "certbot":
|
||||
return "Certbot";
|
||||
}
|
||||
}
|
||||
|
||||
export function getWebStackActionTone(
|
||||
action: WebStackAction,
|
||||
): "danger" | "warning" | "info" {
|
||||
if (action === "remove") {
|
||||
return "danger";
|
||||
}
|
||||
|
||||
if (action === "reinstall") {
|
||||
return "warning";
|
||||
}
|
||||
|
||||
return "info";
|
||||
}
|
||||
|
||||
export function getDockerActionTone(
|
||||
action: "install" | "uninstall" | "reinstall",
|
||||
): "danger" | "warning" | "info" {
|
||||
if (action === "uninstall") {
|
||||
return "danger";
|
||||
}
|
||||
|
||||
if (action === "reinstall") {
|
||||
return "warning";
|
||||
}
|
||||
|
||||
return "info";
|
||||
}
|
||||
|
||||
export function getServiceRestartTone(
|
||||
serviceName: string,
|
||||
): "danger" | "warning" | "info" {
|
||||
const normalizedName = serviceName.toLowerCase();
|
||||
|
||||
if (["ssh", "sshd", "docker"].includes(normalizedName)) {
|
||||
return "danger";
|
||||
}
|
||||
|
||||
return "warning";
|
||||
}
|
||||
|
||||
export function getWebStackActionDescription(
|
||||
componentLabel: string,
|
||||
action: WebStackAction,
|
||||
): string {
|
||||
switch (action) {
|
||||
case "install":
|
||||
return `This will install ${componentLabel} on the host and may pull new packages or enable related services.`;
|
||||
case "upgrade":
|
||||
return `This will upgrade ${componentLabel} packages on the host and may restart related services if the package manager requires it.`;
|
||||
case "reinstall":
|
||||
return `This will reinstall ${componentLabel} to repair the current setup. Existing configuration or active workloads may be affected during the process.`;
|
||||
case "remove":
|
||||
return `This will remove ${componentLabel} from the host. Sites, apps, queues, databases, or caches that depend on it may stop working immediately.`;
|
||||
}
|
||||
}
|
||||
|
||||
export function getDockerActionDescription(
|
||||
serverName: string,
|
||||
action: "install" | "uninstall" | "reinstall",
|
||||
): string {
|
||||
switch (action) {
|
||||
case "install":
|
||||
return `This will install Docker on ${serverName} and may add packages, services, and system groups on the host.`;
|
||||
case "uninstall":
|
||||
return `This will remove the Docker runtime from ${serverName}. Existing containers, images, and dependent workloads may stop working immediately.`;
|
||||
case "reinstall":
|
||||
return `This will remove and reinstall Docker on ${serverName} to repair the runtime. Containers and related workloads may restart or become unavailable during the process.`;
|
||||
}
|
||||
}
|
||||
|
||||
export function getServiceRestartDescription(serviceName: string): string {
|
||||
const normalizedName = serviceName.toLowerCase();
|
||||
|
||||
if (["ssh", "sshd"].includes(normalizedName)) {
|
||||
return `This will restart the ${serviceName} service. Your SSH session may reconnect briefly while the daemon comes back.`;
|
||||
}
|
||||
|
||||
if (normalizedName === "docker") {
|
||||
return "This will restart the Docker daemon. Running containers may pause, reconnect, or briefly become unavailable while the runtime is restarting.";
|
||||
}
|
||||
|
||||
return `This will restart the ${serviceName} service on the host. Active requests or background work that depend on it may reconnect briefly.`;
|
||||
}
|
||||
|
||||
export function getDockerPruneSummary(options: {
|
||||
images: boolean;
|
||||
containers: boolean;
|
||||
networks: boolean;
|
||||
volumes: boolean;
|
||||
buildCache: boolean;
|
||||
}): string {
|
||||
const labels = [
|
||||
options.images ? "images" : null,
|
||||
options.containers ? "stopped containers" : null,
|
||||
options.networks ? "unused networks" : null,
|
||||
options.volumes ? "unused volumes" : null,
|
||||
options.buildCache ? "build cache" : null,
|
||||
].filter((value): value is string => Boolean(value));
|
||||
|
||||
if (labels.length === 0) {
|
||||
return "Select at least one Docker artifact to prune.";
|
||||
}
|
||||
|
||||
if (labels.length === 1) {
|
||||
return `This will remove unused ${labels[0]} only. Active containers will remain untouched.`;
|
||||
}
|
||||
|
||||
const lastLabel = labels[labels.length - 1];
|
||||
return `This will remove unused ${labels.slice(0, -1).join(", ")} and ${lastLabel}. Active containers will remain untouched.`;
|
||||
}
|
||||
|
||||
function getFallbackWebStackComponentCategory(
|
||||
component: WebStackComponentKey,
|
||||
): WebStackComponentStatus["category"] {
|
||||
switch (component) {
|
||||
case "nginx":
|
||||
case "apache":
|
||||
case "caddy":
|
||||
return "web-server";
|
||||
case "php":
|
||||
case "nodejs":
|
||||
return "runtime";
|
||||
case "pm2":
|
||||
return "process-manager";
|
||||
case "mysql":
|
||||
case "postgresql":
|
||||
return "database";
|
||||
case "redis":
|
||||
return "cache";
|
||||
case "composer":
|
||||
case "certbot":
|
||||
return "tooling";
|
||||
}
|
||||
}
|
||||
|
||||
function getFallbackWebStackComponentDescription(
|
||||
component: WebStackComponentKey,
|
||||
): string {
|
||||
switch (component) {
|
||||
case "nginx":
|
||||
return "Reverse proxy and static web server commonly used for PHP and Node.js deployments.";
|
||||
case "apache":
|
||||
return "Alternative web server for PHP apps, legacy virtual hosts, and .htaccess-based setups.";
|
||||
case "caddy":
|
||||
return "Modern web server with automatic HTTPS and simplified reverse proxy configuration.";
|
||||
case "php":
|
||||
return "PHP runtime and FPM process manager for Laravel, WordPress, and similar applications.";
|
||||
case "nodejs":
|
||||
return "JavaScript runtime for Next.js, Express, and other Node-based applications.";
|
||||
case "pm2":
|
||||
return "Process manager for long-running Node.js apps and background workers.";
|
||||
case "mysql":
|
||||
return "MariaDB or MySQL relational database runtime for application data storage.";
|
||||
case "redis":
|
||||
return "In-memory cache and queue backend for sessions, jobs, and fast key-value access.";
|
||||
case "postgresql":
|
||||
return "PostgreSQL relational database runtime for transactional application workloads.";
|
||||
case "composer":
|
||||
return "PHP dependency manager used to install and update application packages.";
|
||||
case "certbot":
|
||||
return "Let's Encrypt client used to issue and renew TLS certificates on the host.";
|
||||
}
|
||||
}
|
||||
|
||||
function getFallbackWebStackRecommendedFor(
|
||||
component: WebStackComponentKey,
|
||||
): string[] {
|
||||
switch (component) {
|
||||
case "nginx":
|
||||
return ["Static Sites", "PHP Apps", "Node.js Apps"];
|
||||
case "apache":
|
||||
return ["PHP Apps", "Legacy Apps"];
|
||||
case "caddy":
|
||||
return ["Static Sites", "HTTPS Automation", "Node.js Apps"];
|
||||
case "php":
|
||||
return ["Laravel", "WordPress", "PHP Apps"];
|
||||
case "nodejs":
|
||||
return ["Next.js", "Express", "JavaScript Apps"];
|
||||
case "pm2":
|
||||
return ["Node.js Apps", "Background Jobs"];
|
||||
case "mysql":
|
||||
return ["PHP Apps", "CMS", "SQL Workloads"];
|
||||
case "redis":
|
||||
return ["Cache", "Queues", "Sessions"];
|
||||
case "postgresql":
|
||||
return ["SQL Workloads", "Node.js Apps", "Analytics"];
|
||||
case "composer":
|
||||
return ["PHP Apps", "Laravel", "WordPress"];
|
||||
case "certbot":
|
||||
return ["HTTPS Automation", "TLS Certificates"];
|
||||
}
|
||||
}
|
||||
|
||||
function createFallbackWebStackComponents(
|
||||
loadError: string,
|
||||
): WebStackComponentStatus[] {
|
||||
const componentKeys: WebStackComponentKey[] = [
|
||||
"nginx",
|
||||
"apache",
|
||||
"caddy",
|
||||
"php",
|
||||
"nodejs",
|
||||
"pm2",
|
||||
"mysql",
|
||||
"redis",
|
||||
"postgresql",
|
||||
"composer",
|
||||
"certbot",
|
||||
];
|
||||
|
||||
return componentKeys.map((component) => ({
|
||||
key: component,
|
||||
label: getWebStackComponentLabel(component),
|
||||
category: getFallbackWebStackComponentCategory(component),
|
||||
description: getFallbackWebStackComponentDescription(component),
|
||||
installed: false,
|
||||
version: null,
|
||||
serviceName: null,
|
||||
active: null,
|
||||
enabled: null,
|
||||
availableActions: [],
|
||||
recommendedFor: getFallbackWebStackRecommendedFor(component),
|
||||
notes: [
|
||||
"Live package status is unavailable until the server snapshot can be refreshed.",
|
||||
loadError,
|
||||
],
|
||||
}));
|
||||
}
|
||||
|
||||
export function createUnavailableServerConfigSnapshot(
|
||||
server: ServerType,
|
||||
loadError: string,
|
||||
): ServerConfigSnapshot {
|
||||
return {
|
||||
hostname: server.name,
|
||||
os: server.os,
|
||||
kernel: null,
|
||||
currentUser: server.username,
|
||||
serverUser: server.username,
|
||||
users: [],
|
||||
rootUser: null,
|
||||
nonRootUsers: [],
|
||||
hasRootUser: false,
|
||||
sudoNonInteractive: false,
|
||||
docker: {
|
||||
installed: false,
|
||||
daemonRunning: false,
|
||||
available: false,
|
||||
version: null,
|
||||
reason: loadError,
|
||||
canInstall: true,
|
||||
probeFailed: true,
|
||||
platform: {
|
||||
distro: server.os,
|
||||
packageManager: null,
|
||||
sudoNonInteractive: false,
|
||||
supportedForFail2banInstall: false,
|
||||
},
|
||||
},
|
||||
services: [],
|
||||
webServer: {
|
||||
ready: false,
|
||||
summary:
|
||||
"Live web stack inventory is unavailable. The host may be offline, SSH may be failing, or the snapshot request may have timed out.",
|
||||
notes: [
|
||||
loadError,
|
||||
"Action buttons in the Actions tab remain available so you can try host recovery steps.",
|
||||
"Refresh this modal after the server becomes reachable again to load package, service, and mount details.",
|
||||
],
|
||||
packageManager: null,
|
||||
canManage: false,
|
||||
primaryWebServer: null,
|
||||
support: {
|
||||
staticSites: false,
|
||||
phpApps: false,
|
||||
javascriptApps: false,
|
||||
sslAutomation: false,
|
||||
processManager: false,
|
||||
relationalDatabase: false,
|
||||
cache: false,
|
||||
},
|
||||
components: createFallbackWebStackComponents(loadError),
|
||||
},
|
||||
diskMounts: [],
|
||||
lastBoot: null,
|
||||
fetchedAt: new Date().toISOString(),
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,423 @@
|
||||
"use client";
|
||||
|
||||
import type { Dispatch, SetStateAction } from "react";
|
||||
import { Boxes, Loader2, Power, RefreshCw, Trash2 } from "lucide-react";
|
||||
import type { Server as ServerType, ServerConfigSnapshot } from "@/lib/api";
|
||||
import { ConfigInfoRow } from "@/app/servers/components/server-config/ServerConfigPrimitives";
|
||||
|
||||
interface ServerConfigActionsPanelProps {
|
||||
server: ServerType;
|
||||
snapshot: ServerConfigSnapshot;
|
||||
snapshotLoadError?: string | null;
|
||||
resetConfirmation: string;
|
||||
setResetConfirmation: Dispatch<SetStateAction<string>>;
|
||||
confirmResetStep: boolean;
|
||||
setConfirmResetStep: Dispatch<SetStateAction<boolean>>;
|
||||
deleteConfirmed: boolean;
|
||||
isActionRunning: (actionKey: string) => boolean;
|
||||
getServerActionKey: (
|
||||
action: "reboot" | "restart-nginx" | "prune-docker",
|
||||
) => string;
|
||||
getDockerActionKey: (action: "install" | "uninstall" | "reinstall") => string;
|
||||
onRequestServerActionConfirm: (
|
||||
action: "reboot" | "restart-nginx" | "prune-docker",
|
||||
) => void;
|
||||
onRequestDockerActionConfirm: (
|
||||
action: "install" | "uninstall" | "reinstall",
|
||||
) => void;
|
||||
onReset: () => Promise<void>;
|
||||
setError: Dispatch<SetStateAction<string>>;
|
||||
}
|
||||
|
||||
export default function ServerConfigActionsPanel({
|
||||
server,
|
||||
snapshot,
|
||||
snapshotLoadError,
|
||||
resetConfirmation,
|
||||
setResetConfirmation,
|
||||
confirmResetStep,
|
||||
setConfirmResetStep,
|
||||
deleteConfirmed,
|
||||
isActionRunning,
|
||||
getServerActionKey,
|
||||
getDockerActionKey,
|
||||
onRequestServerActionConfirm,
|
||||
onRequestDockerActionConfirm,
|
||||
onReset,
|
||||
setError,
|
||||
}: ServerConfigActionsPanelProps) {
|
||||
const dockerStatusUnavailable = Boolean(
|
||||
snapshotLoadError || snapshot.docker.probeFailed,
|
||||
);
|
||||
const showInstallDocker =
|
||||
dockerStatusUnavailable || !snapshot.docker.installed;
|
||||
const showRuntimeMaintenance =
|
||||
dockerStatusUnavailable || snapshot.docker.installed;
|
||||
|
||||
return (
|
||||
<div
|
||||
style={{
|
||||
display: "grid",
|
||||
gridTemplateColumns: "repeat(auto-fit, minmax(280px, 1fr))",
|
||||
gap: 16,
|
||||
}}
|
||||
>
|
||||
<div style={{ display: "grid", gap: 16 }}>
|
||||
{snapshotLoadError ? (
|
||||
<div
|
||||
className="card"
|
||||
style={{
|
||||
padding: 18,
|
||||
display: "grid",
|
||||
gap: 8,
|
||||
border: "1px solid rgba(245,158,11,0.24)",
|
||||
background: "rgba(245,158,11,0.08)",
|
||||
}}
|
||||
hidden={snapshotLoadError != null}
|
||||
>
|
||||
<strong style={{ color: "#f59e0b", fontSize: 14 }}>
|
||||
Recovery mode
|
||||
</strong>
|
||||
<p
|
||||
style={{
|
||||
color: "var(--text-primary)",
|
||||
fontSize: 13,
|
||||
lineHeight: 1.6,
|
||||
}}
|
||||
>
|
||||
Live runtime status could not be loaded, but host-level actions
|
||||
are still available so you can try rebooting the server,
|
||||
restarting the web server, or repairing Docker.
|
||||
</p>
|
||||
<p style={{ color: "#fbbf24", fontSize: 12 }}>
|
||||
{snapshotLoadError}
|
||||
</p>
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
<div className="card" style={{ padding: 18, display: "grid", gap: 14 }}>
|
||||
<div style={{ display: "flex", alignItems: "center", gap: 8 }}>
|
||||
<Power size={15} style={{ color: "#10b981" }} />
|
||||
<strong style={{ color: "var(--text-primary)", fontSize: 14 }}>
|
||||
Server Controls
|
||||
</strong>
|
||||
</div>
|
||||
<p
|
||||
style={{
|
||||
color: "var(--text-muted)",
|
||||
fontSize: 13,
|
||||
lineHeight: 1.6,
|
||||
}}
|
||||
>
|
||||
Trigger common maintenance actions for the host and web stack.
|
||||
</p>
|
||||
<div style={{ display: "flex", gap: 10, flexWrap: "wrap" }}>
|
||||
<button
|
||||
className="btn btn-sm"
|
||||
onClick={() => onRequestServerActionConfirm("restart-nginx")}
|
||||
disabled={isActionRunning(getServerActionKey("restart-nginx"))}
|
||||
style={{
|
||||
background: "rgba(16,185,129,0.12)",
|
||||
color: "#10b981",
|
||||
border: "1px solid rgba(16,185,129,0.22)",
|
||||
}}
|
||||
>
|
||||
{isActionRunning(getServerActionKey("restart-nginx")) ? (
|
||||
<Loader2 size={14} className="animate-spin" />
|
||||
) : (
|
||||
<RefreshCw size={14} />
|
||||
)}
|
||||
Restart Nginx
|
||||
</button>
|
||||
<button
|
||||
className="btn btn-sm"
|
||||
onClick={() => onRequestServerActionConfirm("reboot")}
|
||||
disabled={isActionRunning(getServerActionKey("reboot"))}
|
||||
style={{
|
||||
background: "rgba(239,68,68,0.12)",
|
||||
color: "#ef4444",
|
||||
border: "1px solid rgba(239,68,68,0.22)",
|
||||
}}
|
||||
>
|
||||
{isActionRunning(getServerActionKey("reboot")) ? (
|
||||
<Loader2 size={14} className="animate-spin" />
|
||||
) : (
|
||||
<Power size={14} />
|
||||
)}
|
||||
Reboot Server
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="card" style={{ padding: 18, display: "grid", gap: 14 }}>
|
||||
<div style={{ display: "flex", alignItems: "center", gap: 8 }}>
|
||||
<Boxes size={15} style={{ color: "#3b82f6" }} />
|
||||
<strong style={{ color: "var(--text-primary)", fontSize: 14 }}>
|
||||
Docker Maintenance
|
||||
</strong>
|
||||
</div>
|
||||
<p
|
||||
style={{
|
||||
color: "var(--text-muted)",
|
||||
fontSize: 13,
|
||||
lineHeight: 1.6,
|
||||
}}
|
||||
>
|
||||
Install Docker when it is missing, or remove and reinstall it when
|
||||
the runtime needs a clean recovery.
|
||||
</p>
|
||||
<div style={{ display: "flex", gap: 10, flexWrap: "wrap" }}>
|
||||
{showInstallDocker ? (
|
||||
<button
|
||||
className="btn btn-sm"
|
||||
onClick={() => onRequestDockerActionConfirm("install")}
|
||||
disabled={
|
||||
(!dockerStatusUnavailable &&
|
||||
isActionRunning(getDockerActionKey("install"))) ||
|
||||
(!dockerStatusUnavailable && !snapshot.docker.canInstall)
|
||||
}
|
||||
style={{
|
||||
background: "rgba(59,130,246,0.12)",
|
||||
color: "#3b82f6",
|
||||
border: "1px solid rgba(59,130,246,0.22)",
|
||||
}}
|
||||
>
|
||||
{isActionRunning(getDockerActionKey("install")) ? (
|
||||
<Loader2 size={14} className="animate-spin" />
|
||||
) : (
|
||||
<Boxes size={14} />
|
||||
)}
|
||||
Install Docker
|
||||
</button>
|
||||
) : null}
|
||||
|
||||
{showRuntimeMaintenance ? (
|
||||
<>
|
||||
<button
|
||||
className="btn btn-sm"
|
||||
onClick={() => onRequestDockerActionConfirm("reinstall")}
|
||||
disabled={isActionRunning(getDockerActionKey("reinstall"))}
|
||||
style={{
|
||||
background: "rgba(59,130,246,0.12)",
|
||||
color: "#3b82f6",
|
||||
border: "1px solid rgba(59,130,246,0.22)",
|
||||
}}
|
||||
>
|
||||
{isActionRunning(getDockerActionKey("reinstall")) ? (
|
||||
<Loader2 size={14} className="animate-spin" />
|
||||
) : (
|
||||
<RefreshCw size={14} />
|
||||
)}
|
||||
Reinstall
|
||||
</button>
|
||||
<button
|
||||
className="btn btn-sm"
|
||||
onClick={() => onRequestDockerActionConfirm("uninstall")}
|
||||
disabled={isActionRunning(getDockerActionKey("uninstall"))}
|
||||
style={{
|
||||
background: "rgba(245,158,11,0.12)",
|
||||
color: "#f59e0b",
|
||||
border: "1px solid rgba(245,158,11,0.22)",
|
||||
}}
|
||||
>
|
||||
{isActionRunning(getDockerActionKey("uninstall")) ? (
|
||||
<Loader2 size={14} className="animate-spin" />
|
||||
) : (
|
||||
<Trash2 size={14} />
|
||||
)}
|
||||
Remove
|
||||
</button>
|
||||
<button
|
||||
className="btn btn-sm"
|
||||
onClick={() => onRequestServerActionConfirm("prune-docker")}
|
||||
disabled={isActionRunning(getServerActionKey("prune-docker"))}
|
||||
style={{
|
||||
background: "rgba(239,68,68,0.12)",
|
||||
color: "#ef4444",
|
||||
border: "1px solid rgba(239,68,68,0.22)",
|
||||
}}
|
||||
>
|
||||
{isActionRunning(getServerActionKey("prune-docker")) ? (
|
||||
<Loader2 size={14} className="animate-spin" />
|
||||
) : (
|
||||
<Trash2 size={14} />
|
||||
)}
|
||||
Prune Garbage
|
||||
</button>
|
||||
</>
|
||||
) : null}
|
||||
</div>
|
||||
{!dockerStatusUnavailable &&
|
||||
!snapshot.docker.canInstall &&
|
||||
!snapshot.docker.installed ? (
|
||||
<div
|
||||
style={{
|
||||
borderRadius: 10,
|
||||
border: "1px solid rgba(245,158,11,0.25)",
|
||||
background: "rgba(245,158,11,0.08)",
|
||||
padding: "12px 14px",
|
||||
color: "#b45309",
|
||||
fontSize: 12,
|
||||
}}
|
||||
>
|
||||
Docker install requires root access or non-interactive sudo on
|
||||
this server.
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
|
||||
<div className="card" style={{ padding: 18, display: "grid", gap: 14 }}>
|
||||
<div style={{ display: "flex", alignItems: "center", gap: 8 }}>
|
||||
<Power size={15} style={{ color: "#ef4444" }} />
|
||||
<strong style={{ color: "var(--text-primary)", fontSize: 14 }}>
|
||||
Reset Server
|
||||
</strong>
|
||||
</div>
|
||||
<p
|
||||
style={{
|
||||
color: "var(--text-muted)",
|
||||
fontSize: 13,
|
||||
lineHeight: 1.6,
|
||||
}}
|
||||
>
|
||||
Type DELETE to unlock the final reset confirmation. This action
|
||||
interrupts SSH access and monitoring until the machine is back
|
||||
online.
|
||||
</p>
|
||||
<input
|
||||
className="input"
|
||||
placeholder="Type DELETE to confirm"
|
||||
value={resetConfirmation}
|
||||
onChange={(event) => {
|
||||
const nextValue = event.target.value;
|
||||
setResetConfirmation(nextValue);
|
||||
if (nextValue.trim() !== "DELETE") {
|
||||
setConfirmResetStep(false);
|
||||
}
|
||||
}}
|
||||
style={{ width: "100%" }}
|
||||
/>
|
||||
{!confirmResetStep ? (
|
||||
<div>
|
||||
<button
|
||||
className="btn btn-sm"
|
||||
onClick={() => {
|
||||
if (!deleteConfirmed) {
|
||||
setError('Type "DELETE" before continuing.');
|
||||
return;
|
||||
}
|
||||
setError("");
|
||||
setConfirmResetStep(true);
|
||||
}}
|
||||
disabled={!deleteConfirmed}
|
||||
style={{
|
||||
background: "rgba(239,68,68,0.12)",
|
||||
color: "#ef4444",
|
||||
border: "1px solid rgba(239,68,68,0.22)",
|
||||
}}
|
||||
>
|
||||
<Power size={14} /> Continue
|
||||
</button>
|
||||
</div>
|
||||
) : (
|
||||
<div
|
||||
style={{
|
||||
display: "grid",
|
||||
gap: 12,
|
||||
borderRadius: 12,
|
||||
border: "1px solid rgba(239,68,68,0.22)",
|
||||
background: "rgba(239,68,68,0.06)",
|
||||
padding: 14,
|
||||
}}
|
||||
>
|
||||
<div
|
||||
style={{
|
||||
color: "var(--text-primary)",
|
||||
fontSize: 13,
|
||||
fontWeight: 600,
|
||||
}}
|
||||
>
|
||||
Final confirmation
|
||||
</div>
|
||||
<div
|
||||
style={{
|
||||
color: "var(--text-muted)",
|
||||
fontSize: 12,
|
||||
lineHeight: 1.6,
|
||||
}}
|
||||
>
|
||||
Resetting {server.name} will interrupt SSH access and monitoring
|
||||
until the machine boots again.
|
||||
</div>
|
||||
<div style={{ display: "flex", gap: 10, flexWrap: "wrap" }}>
|
||||
<button
|
||||
className="btn btn-sm"
|
||||
onClick={() => setConfirmResetStep(false)}
|
||||
>
|
||||
Cancel
|
||||
</button>
|
||||
<button
|
||||
className="btn btn-sm"
|
||||
onClick={() => void onReset()}
|
||||
disabled={isActionRunning("server:reset") || !deleteConfirmed}
|
||||
style={{
|
||||
background: "rgba(239,68,68,0.12)",
|
||||
color: "#ef4444",
|
||||
border: "1px solid rgba(239,68,68,0.22)",
|
||||
}}
|
||||
>
|
||||
{isActionRunning("server:reset") ? (
|
||||
<Loader2 size={14} className="animate-spin" />
|
||||
) : (
|
||||
<Power size={14} />
|
||||
)}
|
||||
Confirm Reset
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
className="card"
|
||||
style={{ padding: 18, display: "grid", gap: 10, alignContent: "start" }}
|
||||
hidden
|
||||
>
|
||||
<strong style={{ color: "var(--text-primary)", fontSize: 14 }}>
|
||||
Quick Facts
|
||||
</strong>
|
||||
<ConfigInfoRow label="Server" value={server.name} />
|
||||
<ConfigInfoRow label="IP" value={server.ip} />
|
||||
<ConfigInfoRow label="SSH User" value={snapshot.serverUser} />
|
||||
<ConfigInfoRow
|
||||
label="Users"
|
||||
value={`${snapshot.users.length} accounts`}
|
||||
/>
|
||||
<ConfigInfoRow
|
||||
label="Docker"
|
||||
value={
|
||||
dockerStatusUnavailable
|
||||
? `Status unavailable${snapshot.docker.reason ? ` • ${snapshot.docker.reason}` : ""}`
|
||||
: snapshot.docker.installed
|
||||
? snapshot.docker.available
|
||||
? `Installed • ${snapshot.docker.version ?? "ready"}`
|
||||
: (snapshot.docker.reason ?? "Installed but unavailable")
|
||||
: "Not installed"
|
||||
}
|
||||
/>
|
||||
<ConfigInfoRow
|
||||
label="Services"
|
||||
value={`${snapshot.services.length} tracked`}
|
||||
/>
|
||||
<ConfigInfoRow
|
||||
label="Web Stack"
|
||||
value={snapshot.webServer.ready ? "Ready" : "Needs setup"}
|
||||
/>
|
||||
<ConfigInfoRow
|
||||
label="Mounts"
|
||||
value={`${snapshot.diskMounts.length} detected`}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
"use client";
|
||||
|
||||
import type { ServerConfigSnapshot } from "@/lib/api";
|
||||
import { UserBadge } from "@/app/servers/components/server-config/ServerConfigPrimitives";
|
||||
|
||||
interface ServerConfigMountsPanelProps {
|
||||
snapshot: ServerConfigSnapshot;
|
||||
snapshotLoadError?: string | null;
|
||||
}
|
||||
|
||||
export default function ServerConfigMountsPanel({
|
||||
snapshot,
|
||||
snapshotLoadError,
|
||||
}: ServerConfigMountsPanelProps) {
|
||||
const hasMounts = snapshot.diskMounts.length > 0;
|
||||
|
||||
return (
|
||||
<div style={{ display: "grid", gap: 16 }}>
|
||||
<div className="card" style={{ padding: 18 }}>
|
||||
<div
|
||||
style={{
|
||||
display: "flex",
|
||||
justifyContent: "space-between",
|
||||
alignItems: "center",
|
||||
gap: 12,
|
||||
flexWrap: "wrap",
|
||||
}}
|
||||
>
|
||||
<div>
|
||||
<strong style={{ color: "var(--text-primary)", fontSize: 14 }}>
|
||||
Disk Mount Inventory
|
||||
</strong>
|
||||
<p
|
||||
style={{ marginTop: 6, color: "var(--text-muted)", fontSize: 13 }}
|
||||
>
|
||||
Filesystems reported by df excluding temporary mounts.
|
||||
</p>
|
||||
</div>
|
||||
<UserBadge
|
||||
label={`${snapshot.diskMounts.length} mounts`}
|
||||
tone="info"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
{hasMounts ? (
|
||||
<div className="card" style={{ overflow: "hidden" }}>
|
||||
<div style={{ overflowX: "auto" }}>
|
||||
<table className="data-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Filesystem</th>
|
||||
<th>Type</th>
|
||||
<th>Size</th>
|
||||
<th>Used</th>
|
||||
<th>Available</th>
|
||||
<th>Use%</th>
|
||||
<th>Mount Point</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{snapshot.diskMounts.map((mount) => (
|
||||
<tr key={`${mount.filesystem}-${mount.mountPoint}`}>
|
||||
<td>{mount.filesystem}</td>
|
||||
<td>{mount.type}</td>
|
||||
<td>{mount.size}</td>
|
||||
<td>{mount.used}</td>
|
||||
<td>{mount.available}</td>
|
||||
<td>{mount.usedPercent}</td>
|
||||
<td>{mount.mountPoint}</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<div
|
||||
className="card"
|
||||
style={{ padding: 20, color: "var(--text-muted)", fontSize: 13 }}
|
||||
>
|
||||
{snapshotLoadError
|
||||
? `Disk mount information is unavailable because the live server snapshot could not be fetched: ${snapshotLoadError}`
|
||||
: "No disk mounts were returned by the server snapshot."}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,152 @@
|
||||
"use client";
|
||||
|
||||
import { Settings2, Shield } from "lucide-react";
|
||||
import type { Server as ServerType, ServerConfigSnapshot } from "@/lib/api";
|
||||
import { formatDateTime } from "@/app/servers/components/server-utils";
|
||||
import { ConfigInfoRow } from "@/app/servers/components/server-config/ServerConfigPrimitives";
|
||||
|
||||
interface ServerConfigOverviewPanelProps {
|
||||
server: ServerType;
|
||||
snapshot: ServerConfigSnapshot;
|
||||
snapshotLoadError?: string | null;
|
||||
}
|
||||
|
||||
export default function ServerConfigOverviewPanel({
|
||||
server,
|
||||
snapshot,
|
||||
snapshotLoadError,
|
||||
}: ServerConfigOverviewPanelProps) {
|
||||
return (
|
||||
<div
|
||||
style={{
|
||||
display: "grid",
|
||||
gridTemplateColumns: "repeat(auto-fit, minmax(250px, 2fr))",
|
||||
gap: 16,
|
||||
}}
|
||||
>
|
||||
{snapshotLoadError ? (
|
||||
<div
|
||||
hidden
|
||||
className="card"
|
||||
style={{
|
||||
padding: 18,
|
||||
display: "grid",
|
||||
gap: 8,
|
||||
gridColumn: "1 / -1",
|
||||
border: "1px solid rgba(245,158,11,0.24)",
|
||||
background: "rgba(245,158,11,0.08)",
|
||||
}}
|
||||
>
|
||||
<strong style={{ color: "#f59e0b", fontSize: 14 }}>
|
||||
Runtime data unavailable
|
||||
</strong>
|
||||
<p
|
||||
style={{
|
||||
color: "var(--text-primary)",
|
||||
fontSize: 13,
|
||||
lineHeight: 1.6,
|
||||
}}
|
||||
>
|
||||
The server is not returning a live configuration snapshot right now.
|
||||
Basic host identity is still shown below, and recovery actions
|
||||
remain available in the Actions tab.
|
||||
</p>
|
||||
<p style={{ color: "#fbbf24", fontSize: 12 }}>{snapshotLoadError}</p>
|
||||
</div>
|
||||
) : null}
|
||||
<div
|
||||
className="card"
|
||||
style={{ padding: 18, display: "grid", gap: 12 }}
|
||||
hidden={snapshotLoadError != null}
|
||||
>
|
||||
<div style={{ display: "flex", alignItems: "center", gap: 8 }}>
|
||||
<Settings2 size={15} style={{ color: "#3b82f6" }} />
|
||||
<strong style={{ color: "var(--text-primary)", fontSize: 14 }}>
|
||||
Server Overview
|
||||
</strong>
|
||||
</div>
|
||||
<ConfigInfoRow
|
||||
label="Hostname"
|
||||
value={snapshot.hostname ?? server.name}
|
||||
/>
|
||||
<ConfigInfoRow label="Operating System" value={snapshot.os ?? "—"} />
|
||||
<ConfigInfoRow label="Kernel" value={snapshot.kernel ?? "—"} />
|
||||
<ConfigInfoRow label="SSH User" value={snapshot.serverUser} />
|
||||
<ConfigInfoRow
|
||||
label="Detected User"
|
||||
value={snapshot.currentUser ?? "—"}
|
||||
/>
|
||||
<ConfigInfoRow
|
||||
label="Last Boot"
|
||||
value={formatDateTime(snapshot.lastBoot)}
|
||||
/>
|
||||
<ConfigInfoRow
|
||||
label="Fetched At"
|
||||
value={formatDateTime(snapshot.fetchedAt)}
|
||||
/>
|
||||
</div>
|
||||
<div
|
||||
style={{ display: "grid", gap: 16 }}
|
||||
hidden={snapshotLoadError != null}
|
||||
>
|
||||
<div className="card" style={{ padding: 18, display: "grid", gap: 10 }}>
|
||||
<div style={{ display: "flex", alignItems: "center", gap: 8 }}>
|
||||
<Shield size={15} style={{ color: "#10b981" }} />
|
||||
<strong style={{ color: "var(--text-primary)", fontSize: 14 }}>
|
||||
Access & Runtime
|
||||
</strong>
|
||||
</div>
|
||||
<ConfigInfoRow
|
||||
label="Sudo"
|
||||
value={
|
||||
snapshot.sudoNonInteractive
|
||||
? "Non-interactive sudo ready"
|
||||
: "Requires root or interactive sudo"
|
||||
}
|
||||
/>
|
||||
<ConfigInfoRow
|
||||
label="Docker"
|
||||
value={
|
||||
snapshot.docker.probeFailed
|
||||
? `Status check failed${snapshot.docker.reason ? ` • ${snapshot.docker.reason}` : ""}`
|
||||
: snapshot.docker.available
|
||||
? `Ready${snapshot.docker.version ? ` • ${snapshot.docker.version}` : ""}`
|
||||
: (snapshot.docker.reason ?? "Not ready")
|
||||
}
|
||||
/>
|
||||
<ConfigInfoRow
|
||||
label="Package Manager"
|
||||
value={snapshot.docker.platform.packageManager ?? "—"}
|
||||
/>
|
||||
<ConfigInfoRow
|
||||
label="Tracked Users"
|
||||
value={`${snapshot.users.length} account(s)`}
|
||||
/>
|
||||
</div>
|
||||
<div
|
||||
className="card"
|
||||
style={{
|
||||
padding: 18,
|
||||
background:
|
||||
"linear-gradient(135deg, rgba(59,130,246,0.08), rgba(16,185,129,0.05))",
|
||||
}}
|
||||
>
|
||||
<p
|
||||
style={{
|
||||
color: "var(--text-primary)",
|
||||
fontSize: 14,
|
||||
fontWeight: 700,
|
||||
}}
|
||||
>
|
||||
Root visibility
|
||||
</p>
|
||||
<p style={{ color: "var(--text-muted)", fontSize: 13, marginTop: 8 }}>
|
||||
{snapshot.rootUser
|
||||
? `Root account detected with groups: ${snapshot.rootUser.groups.join(", ") || "none"}.`
|
||||
: "No root account was detected from the current /etc/passwd snapshot."}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,160 @@
|
||||
"use client";
|
||||
|
||||
import { KeyRound } from "lucide-react";
|
||||
import type { ServerSystemUser } from "@/lib/api";
|
||||
import type { UserBadgeTone } from "@/app/servers/components/server-config-utils";
|
||||
|
||||
export function ConfigInfoRow({
|
||||
label,
|
||||
value,
|
||||
}: {
|
||||
label: string;
|
||||
value: string;
|
||||
}) {
|
||||
return (
|
||||
<div
|
||||
style={{
|
||||
display: "grid",
|
||||
gridTemplateColumns: "140px 1fr",
|
||||
gap: 10,
|
||||
alignItems: "start",
|
||||
}}
|
||||
>
|
||||
<span style={{ fontSize: 12, color: "var(--text-muted)" }}>{label}</span>
|
||||
<span
|
||||
style={{
|
||||
fontSize: 13,
|
||||
color: "var(--text-primary)",
|
||||
wordBreak: "break-word",
|
||||
}}
|
||||
>
|
||||
{value}
|
||||
</span>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export function UserBadge({
|
||||
label,
|
||||
tone,
|
||||
}: {
|
||||
label: string;
|
||||
tone: UserBadgeTone;
|
||||
}) {
|
||||
const palette = {
|
||||
danger: {
|
||||
color: "#ef4444",
|
||||
background: "rgba(239,68,68,0.08)",
|
||||
border: "rgba(239,68,68,0.2)",
|
||||
},
|
||||
success: {
|
||||
color: "#10b981",
|
||||
background: "rgba(16,185,129,0.08)",
|
||||
border: "rgba(16,185,129,0.2)",
|
||||
},
|
||||
neutral: {
|
||||
color: "var(--text-secondary)",
|
||||
background: "var(--bg-input)",
|
||||
border: "var(--border)",
|
||||
},
|
||||
warning: {
|
||||
color: "#f59e0b",
|
||||
background: "rgba(245,158,11,0.08)",
|
||||
border: "rgba(245,158,11,0.2)",
|
||||
},
|
||||
info: {
|
||||
color: "#3b82f6",
|
||||
background: "rgba(59,130,246,0.08)",
|
||||
border: "rgba(59,130,246,0.2)",
|
||||
},
|
||||
} as const;
|
||||
const style = palette[tone];
|
||||
|
||||
return (
|
||||
<span
|
||||
className="ui-badge"
|
||||
style={{
|
||||
color: style.color,
|
||||
background: style.background,
|
||||
border: `1px solid ${style.border}`,
|
||||
}}
|
||||
>
|
||||
{label}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
export function ServiceStatusBadge({ state }: { state: string }) {
|
||||
const normalized = state.toLowerCase();
|
||||
const tone =
|
||||
normalized === "active"
|
||||
? "success"
|
||||
: normalized === "enabled"
|
||||
? "info"
|
||||
: normalized === "inactive"
|
||||
? "danger"
|
||||
: "warning";
|
||||
|
||||
return <UserBadge label={state} tone={tone} />;
|
||||
}
|
||||
|
||||
export function ServerUserCard({ user }: { user: ServerSystemUser }) {
|
||||
const accountLabel = user.isRoot ? "root" : "non-root";
|
||||
const accountTone = user.isRoot ? "danger" : "info";
|
||||
|
||||
return (
|
||||
<div
|
||||
className="card"
|
||||
style={{
|
||||
padding: 16,
|
||||
display: "flex",
|
||||
flexDirection: "column",
|
||||
gap: 12,
|
||||
}}
|
||||
>
|
||||
<div
|
||||
style={{
|
||||
display: "flex",
|
||||
justifyContent: "space-between",
|
||||
alignItems: "flex-start",
|
||||
gap: 12,
|
||||
flexWrap: "wrap",
|
||||
}}
|
||||
>
|
||||
<div>
|
||||
<div
|
||||
style={{
|
||||
display: "flex",
|
||||
alignItems: "center",
|
||||
gap: 10,
|
||||
flexWrap: "wrap",
|
||||
}}
|
||||
>
|
||||
<strong style={{ color: "var(--text-primary)", fontSize: 14 }}>
|
||||
{user.username}
|
||||
</strong>
|
||||
<UserBadge label={accountLabel} tone={accountTone} />
|
||||
{user.isSshUser ? (
|
||||
<UserBadge label="SSH LOGIN" tone="neutral" />
|
||||
) : null}
|
||||
</div>
|
||||
<p style={{ marginTop: 6, fontSize: 12, color: "var(--text-muted)" }}>
|
||||
UID {user.uid ?? "—"} • GID {user.gid ?? "—"}
|
||||
</p>
|
||||
</div>
|
||||
<KeyRound
|
||||
size={16}
|
||||
style={{ color: user.isRoot ? "#ef4444" : "#3b82f6" }}
|
||||
/>
|
||||
</div>
|
||||
<div style={{ display: "grid", gap: 8 }}>
|
||||
<ConfigInfoRow label="Home" value={user.home ?? "—"} />
|
||||
<ConfigInfoRow label="Shell" value={user.shell ?? "—"} />
|
||||
<ConfigInfoRow
|
||||
label="Groups"
|
||||
value={user.groups.length > 0 ? user.groups.join(", ") : "—"}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,146 @@
|
||||
"use client";
|
||||
|
||||
import { Loader2, RefreshCw } from "lucide-react";
|
||||
import type { ServerConfigSnapshot } from "@/lib/api";
|
||||
import {
|
||||
ServiceStatusBadge,
|
||||
UserBadge,
|
||||
} from "@/app/servers/components/server-config/ServerConfigPrimitives";
|
||||
import { canRestartService } from "@/app/servers/components/server-config-utils";
|
||||
|
||||
interface ServerConfigServicesPanelProps {
|
||||
snapshot: ServerConfigSnapshot;
|
||||
snapshotLoadError?: string | null;
|
||||
isActionRunning: (actionKey: string) => boolean;
|
||||
getServiceActionKey: (serviceName: string) => string;
|
||||
onRequestServiceRestartConfirm: (serviceName: string) => void;
|
||||
}
|
||||
|
||||
export default function ServerConfigServicesPanel({
|
||||
snapshot,
|
||||
snapshotLoadError,
|
||||
isActionRunning,
|
||||
getServiceActionKey,
|
||||
onRequestServiceRestartConfirm,
|
||||
}: ServerConfigServicesPanelProps) {
|
||||
return (
|
||||
<div
|
||||
style={{ display: "grid", gap: 16 }}
|
||||
hidden={snapshotLoadError != null}
|
||||
>
|
||||
<div className="card" style={{ padding: 18 }}>
|
||||
<div
|
||||
style={{
|
||||
display: "flex",
|
||||
justifyContent: "space-between",
|
||||
alignItems: "center",
|
||||
gap: 12,
|
||||
flexWrap: "wrap",
|
||||
}}
|
||||
>
|
||||
<div>
|
||||
<strong style={{ color: "var(--text-primary)", fontSize: 14 }}>
|
||||
Service Snapshot
|
||||
</strong>
|
||||
<p
|
||||
style={{ marginTop: 6, color: "var(--text-muted)", fontSize: 13 }}
|
||||
>
|
||||
Runtime status for common services detected on the server.
|
||||
</p>
|
||||
</div>
|
||||
<UserBadge
|
||||
label={`${snapshot.services.length} services`}
|
||||
tone="info"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
{snapshot.services.length > 0 ? (
|
||||
<div
|
||||
style={{
|
||||
display: "grid",
|
||||
gridTemplateColumns:
|
||||
"repeat(auto-fill, minmax(min(380px, 100%), 1fr))",
|
||||
gap: 16,
|
||||
}}
|
||||
>
|
||||
{snapshot.services.map((service, index) => (
|
||||
<div
|
||||
key={`${service.name}-${service.active}-${service.enabled}-${index}`}
|
||||
className="card"
|
||||
style={{
|
||||
display: "grid",
|
||||
gridTemplateColumns: "repeat(auto-fit, minmax(250px, 1fr))",
|
||||
gap: 16,
|
||||
padding: 18,
|
||||
}}
|
||||
>
|
||||
<div
|
||||
style={{
|
||||
display: "flex",
|
||||
justifyContent: "space-between",
|
||||
gap: 12,
|
||||
alignItems: "flex-start",
|
||||
}}
|
||||
>
|
||||
<div>
|
||||
<strong
|
||||
style={{
|
||||
color: "var(--text-primary)",
|
||||
fontSize: 14,
|
||||
textTransform: "capitalize",
|
||||
}}
|
||||
>
|
||||
{service.name}
|
||||
</strong>
|
||||
<p
|
||||
style={{
|
||||
marginTop: 6,
|
||||
fontSize: 12,
|
||||
color: "var(--text-muted)",
|
||||
}}
|
||||
>
|
||||
{service.description ?? "No description available"}
|
||||
</p>
|
||||
</div>
|
||||
{canRestartService(service.name) ? (
|
||||
<button
|
||||
className="btn btn-ghost btn-sm"
|
||||
onClick={() => onRequestServiceRestartConfirm(service.name)}
|
||||
disabled={isActionRunning(
|
||||
getServiceActionKey(service.name),
|
||||
)}
|
||||
style={{
|
||||
color: "#3b82f6",
|
||||
border: "1px solid rgba(59,130,246,0.18)",
|
||||
background: "rgba(59,130,246,0.08)",
|
||||
whiteSpace: "nowrap",
|
||||
}}
|
||||
>
|
||||
{isActionRunning(getServiceActionKey(service.name)) ? (
|
||||
<Loader2 size={12} className="animate-spin" />
|
||||
) : (
|
||||
<RefreshCw size={12} />
|
||||
)}
|
||||
</button>
|
||||
) : null}
|
||||
</div>
|
||||
<div style={{ display: "flex", gap: 8, flexWrap: "wrap" }}>
|
||||
<ServiceStatusBadge state={service.active} />
|
||||
<ServiceStatusBadge state={service.enabled} />
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
) : (
|
||||
<div
|
||||
className="card"
|
||||
style={{ padding: 20, color: "var(--text-muted)", fontSize: 13 }}
|
||||
>
|
||||
{snapshotLoadError
|
||||
? "Service inventory could not be loaded because the live server snapshot is unavailable."
|
||||
: "No supported services were detected from the current snapshot."}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
"use client";
|
||||
|
||||
import type { ServerConfigSnapshot } from "@/lib/api";
|
||||
import {
|
||||
ServerUserCard,
|
||||
UserBadge,
|
||||
} from "@/app/servers/components/server-config/ServerConfigPrimitives";
|
||||
|
||||
interface ServerConfigUsersPanelProps {
|
||||
snapshot: ServerConfigSnapshot;
|
||||
snapshotLoadError?: string | null;
|
||||
}
|
||||
|
||||
export default function ServerConfigUsersPanel({
|
||||
snapshot,
|
||||
snapshotLoadError,
|
||||
}: ServerConfigUsersPanelProps) {
|
||||
return (
|
||||
<div
|
||||
style={{ display: "grid", gap: 16 }}
|
||||
hidden={snapshotLoadError != null}
|
||||
>
|
||||
<div className="card" style={{ padding: 18 }}>
|
||||
<div
|
||||
style={{
|
||||
display: "flex",
|
||||
justifyContent: "space-between",
|
||||
gap: 12,
|
||||
flexWrap: "wrap",
|
||||
}}
|
||||
>
|
||||
<div>
|
||||
<strong style={{ color: "var(--text-primary)", fontSize: 14 }}>
|
||||
User Inventory
|
||||
</strong>
|
||||
<p
|
||||
style={{ marginTop: 6, color: "var(--text-muted)", fontSize: 13 }}
|
||||
>
|
||||
Showing root and non-root accounts together with their detected
|
||||
groups.
|
||||
</p>
|
||||
</div>
|
||||
<div
|
||||
style={{
|
||||
display: "flex",
|
||||
gap: 8,
|
||||
height: "10px",
|
||||
flexWrap: "wrap",
|
||||
}}
|
||||
>
|
||||
<UserBadge
|
||||
label={`${snapshot.hasRootUser ? 1 : 0} root`}
|
||||
tone="danger"
|
||||
/>
|
||||
<UserBadge
|
||||
label={`${snapshot.nonRootUsers.length} non-root`}
|
||||
tone="info"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{snapshot.rootUser ? <ServerUserCard user={snapshot.rootUser} /> : null}
|
||||
{snapshot.nonRootUsers.length > 0 ? (
|
||||
<div
|
||||
style={{
|
||||
display: "grid",
|
||||
gridTemplateColumns: "repeat(auto-fit, minmax(260px, 1fr))",
|
||||
gap: 16,
|
||||
}}
|
||||
>
|
||||
{snapshot.nonRootUsers.map((user) => (
|
||||
<ServerUserCard key={user.username} user={user} />
|
||||
))}
|
||||
</div>
|
||||
) : (
|
||||
<div
|
||||
className="card"
|
||||
style={{ padding: 20, color: "var(--text-muted)", fontSize: 13 }}
|
||||
>
|
||||
{snapshotLoadError
|
||||
? "User inventory could not be fetched because the live server snapshot is unavailable."
|
||||
: "No non-root users were included in the current snapshot."}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,451 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import { Loader2, Plus, RefreshCw, Trash2 } from "lucide-react";
|
||||
import type {
|
||||
WebStackComponentStatus,
|
||||
ServerConfigSnapshot,
|
||||
WebStackAction,
|
||||
WebStackComponentKey,
|
||||
} from "@/lib/api";
|
||||
import {
|
||||
ServiceStatusBadge,
|
||||
UserBadge,
|
||||
} from "@/app/servers/components/server-config/ServerConfigPrimitives";
|
||||
import {
|
||||
getWebStackActionLabel,
|
||||
getWebStackActionStyle,
|
||||
} from "@/app/servers/components/server-config-utils";
|
||||
|
||||
interface ServerConfigWebServerPanelProps {
|
||||
snapshot: ServerConfigSnapshot;
|
||||
isActionRunning: (actionKey: string) => boolean;
|
||||
getWebStackActionKey: (
|
||||
component: WebStackComponentKey,
|
||||
action: WebStackAction,
|
||||
) => string;
|
||||
onRequestWebStackActionConfirm: (
|
||||
component: WebStackComponentKey,
|
||||
action: WebStackAction,
|
||||
) => void;
|
||||
}
|
||||
|
||||
export default function ServerConfigWebServerPanel({
|
||||
snapshot,
|
||||
isActionRunning,
|
||||
getWebStackActionKey,
|
||||
onRequestWebStackActionConfirm,
|
||||
}: ServerConfigWebServerPanelProps) {
|
||||
const [activeGroup, setActiveGroup] = useState<
|
||||
"infrastructure" | "runtime-tools"
|
||||
>("infrastructure");
|
||||
|
||||
const infrastructureComponents = snapshot.webServer.components.filter(
|
||||
(component) =>
|
||||
component.category === "web-server" || component.key === "certbot",
|
||||
);
|
||||
const runtimeToolComponents = snapshot.webServer.components.filter(
|
||||
(component) =>
|
||||
component.category !== "web-server" && component.key !== "certbot",
|
||||
);
|
||||
|
||||
const visibleComponents =
|
||||
activeGroup === "infrastructure"
|
||||
? infrastructureComponents
|
||||
: runtimeToolComponents;
|
||||
|
||||
const renderComponentCard = (component: WebStackComponentStatus) => (
|
||||
<div
|
||||
key={component.key}
|
||||
className="card"
|
||||
style={{ padding: 16, display: "grid", gap: 14 }}
|
||||
>
|
||||
<div
|
||||
style={{
|
||||
display: "flex",
|
||||
justifyContent: "space-between",
|
||||
alignItems: "flex-start",
|
||||
gap: 12,
|
||||
}}
|
||||
>
|
||||
<div>
|
||||
<strong style={{ color: "var(--text-primary)", fontSize: 14 }}>
|
||||
{component.label}
|
||||
</strong>
|
||||
<p
|
||||
style={{
|
||||
marginTop: 6,
|
||||
fontSize: 12,
|
||||
color: "var(--text-muted)",
|
||||
lineHeight: 1.6,
|
||||
}}
|
||||
>
|
||||
{component.description}
|
||||
</p>
|
||||
</div>
|
||||
<UserBadge
|
||||
label={component.installed ? "Installed" : "Not Installed"}
|
||||
tone={component.installed ? "success" : "warning"}
|
||||
/>
|
||||
</div>
|
||||
<hr style={{ borderColor: "var(--border)" }} />
|
||||
|
||||
<div
|
||||
style={{ display: "flex", gap: 8, maxHeight: "20px", flexWrap: "wrap" }}
|
||||
>
|
||||
<UserBadge label={component.category} tone="neutral" />
|
||||
{component.version ? (
|
||||
<UserBadge label={component.version} tone="neutral" />
|
||||
) : null}
|
||||
{component.serviceName ? (
|
||||
<UserBadge label={component.serviceName} tone="neutral" />
|
||||
) : null}
|
||||
{component.active ? (
|
||||
<ServiceStatusBadge state={component.active} />
|
||||
) : null}
|
||||
{component.enabled ? (
|
||||
<ServiceStatusBadge state={component.enabled} />
|
||||
) : null}
|
||||
</div>
|
||||
|
||||
<div
|
||||
style={{ display: "flex", gap: 8, maxHeight: "20px", flexWrap: "wrap" }}
|
||||
>
|
||||
{component.recommendedFor.map((target) => (
|
||||
<UserBadge key={target} label={target} tone="neutral" />
|
||||
))}
|
||||
</div>
|
||||
|
||||
{component.notes.length > 0 ? (
|
||||
<div
|
||||
style={{
|
||||
display: "grid",
|
||||
gap: 6,
|
||||
lineHeight: 1.4,
|
||||
padding: 12,
|
||||
borderRadius: 12,
|
||||
background: "rgba(248, 113, 113, 0.15)",
|
||||
border: "1px solid rgba(248, 113, 113, 0.3)",
|
||||
}}
|
||||
>
|
||||
{component.notes.map((note) => (
|
||||
<div
|
||||
key={note}
|
||||
style={{ color: "var(--text-danger)", fontSize: 12 }}
|
||||
>
|
||||
{note}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
<hr style={{ borderColor: "var(--border)" }} />
|
||||
|
||||
<div
|
||||
style={{
|
||||
display: "flex",
|
||||
gap: 6,
|
||||
maxHeight: "20px",
|
||||
padding: "0 0 24px 0",
|
||||
flexWrap: "wrap",
|
||||
}}
|
||||
>
|
||||
{component.availableActions.length > 0 ? (
|
||||
component.availableActions.map((action) => {
|
||||
const actionStyle = getWebStackActionStyle(action);
|
||||
return (
|
||||
<button
|
||||
key={`${component.key}-${action}`}
|
||||
className="btn btn-ghost btn-sm"
|
||||
onClick={() =>
|
||||
onRequestWebStackActionConfirm(component.key, action)
|
||||
}
|
||||
disabled={isActionRunning(
|
||||
getWebStackActionKey(component.key, action),
|
||||
)}
|
||||
style={{ whiteSpace: "nowrap", ...actionStyle }}
|
||||
>
|
||||
{isActionRunning(
|
||||
getWebStackActionKey(component.key, action),
|
||||
) ? (
|
||||
<Loader2 size={12} className="animate-spin" />
|
||||
) : action === "remove" ? (
|
||||
<Trash2 size={12} />
|
||||
) : action === "install" ? (
|
||||
<Plus size={12} />
|
||||
) : (
|
||||
<RefreshCw size={12} />
|
||||
)}
|
||||
{getWebStackActionLabel(action)}
|
||||
</button>
|
||||
);
|
||||
})
|
||||
) : (
|
||||
<div style={{ color: "var(--text-muted)", fontSize: 12 }}>
|
||||
Package management is unavailable for this SSH user on the current
|
||||
server.
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
return (
|
||||
<div style={{ display: "grid", gap: 16 }}>
|
||||
<div className="card" style={{ padding: 18, display: "grid", gap: 14 }}>
|
||||
<div
|
||||
style={{
|
||||
display: "flex",
|
||||
justifyContent: "space-between",
|
||||
alignItems: "flex-start",
|
||||
gap: 12,
|
||||
flexWrap: "wrap",
|
||||
}}
|
||||
>
|
||||
<div>
|
||||
<strong style={{ color: "var(--text-primary)", fontSize: 14 }}>
|
||||
Web Server Readiness
|
||||
</strong>
|
||||
<p
|
||||
style={{
|
||||
marginTop: 6,
|
||||
color: "var(--text-muted)",
|
||||
fontSize: 13,
|
||||
lineHeight: 1.6,
|
||||
}}
|
||||
>
|
||||
{snapshot.webServer.summary}
|
||||
</p>
|
||||
</div>
|
||||
<div style={{ display: "flex", gap: 8, flexWrap: "wrap" }}>
|
||||
<UserBadge
|
||||
label={snapshot.webServer.ready ? "Ready" : "Needs Setup"}
|
||||
tone={snapshot.webServer.ready ? "success" : "warning"}
|
||||
/>
|
||||
<UserBadge
|
||||
label={`Pkg: ${snapshot.webServer.packageManager ?? "none"}`}
|
||||
tone="neutral"
|
||||
/>
|
||||
{snapshot.webServer.primaryWebServer ? (
|
||||
<UserBadge
|
||||
label={snapshot.webServer.primaryWebServer}
|
||||
tone="info"
|
||||
/>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
<div style={{ display: "flex", gap: 8, flexWrap: "wrap" }}>
|
||||
<UserBadge
|
||||
label={
|
||||
snapshot.webServer.support.staticSites
|
||||
? "Static Sites Ready"
|
||||
: "Static Sites Missing"
|
||||
}
|
||||
tone={
|
||||
snapshot.webServer.support.staticSites ? "success" : "warning"
|
||||
}
|
||||
/>
|
||||
<UserBadge
|
||||
label={
|
||||
snapshot.webServer.support.phpApps
|
||||
? "PHP Apps Ready"
|
||||
: "PHP Apps Missing"
|
||||
}
|
||||
tone={snapshot.webServer.support.phpApps ? "success" : "warning"}
|
||||
/>
|
||||
<UserBadge
|
||||
label={
|
||||
snapshot.webServer.support.javascriptApps
|
||||
? "JavaScript Apps Ready"
|
||||
: "JavaScript Apps Missing"
|
||||
}
|
||||
tone={
|
||||
snapshot.webServer.support.javascriptApps ? "success" : "warning"
|
||||
}
|
||||
/>
|
||||
<UserBadge
|
||||
label={
|
||||
snapshot.webServer.support.sslAutomation
|
||||
? "HTTPS Automation Ready"
|
||||
: "HTTPS Automation Missing"
|
||||
}
|
||||
tone={
|
||||
snapshot.webServer.support.sslAutomation ? "success" : "warning"
|
||||
}
|
||||
/>
|
||||
<UserBadge
|
||||
label={
|
||||
snapshot.webServer.support.processManager
|
||||
? "Process Manager Ready"
|
||||
: "Process Manager Missing"
|
||||
}
|
||||
tone={
|
||||
snapshot.webServer.support.processManager ? "success" : "warning"
|
||||
}
|
||||
/>
|
||||
<UserBadge
|
||||
label={
|
||||
snapshot.webServer.support.relationalDatabase
|
||||
? "SQL Ready"
|
||||
: "SQL Missing"
|
||||
}
|
||||
tone={
|
||||
snapshot.webServer.support.relationalDatabase
|
||||
? "success"
|
||||
: "warning"
|
||||
}
|
||||
/>
|
||||
<UserBadge
|
||||
label={
|
||||
snapshot.webServer.support.cache ? "Cache Ready" : "Cache Missing"
|
||||
}
|
||||
tone={snapshot.webServer.support.cache ? "success" : "warning"}
|
||||
/>
|
||||
</div>
|
||||
{snapshot.webServer.notes.length > 0 ? (
|
||||
<div
|
||||
style={{
|
||||
display: "grid",
|
||||
gap: 6,
|
||||
padding: 12,
|
||||
borderRadius: 12,
|
||||
background: "rgba(15,23,42,0.18)",
|
||||
border: "1px solid rgba(148,163,184,0.14)",
|
||||
}}
|
||||
>
|
||||
{snapshot.webServer.notes.map((note) => (
|
||||
<div
|
||||
key={note}
|
||||
style={{ color: "var(--text-muted)", fontSize: 12 }}
|
||||
>
|
||||
{note}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
|
||||
<div className="card" style={{ padding: 18, display: "grid", gap: 14 }}>
|
||||
<div
|
||||
style={{
|
||||
display: "flex",
|
||||
justifyContent: "space-between",
|
||||
alignItems: "flex-start",
|
||||
gap: 12,
|
||||
flexWrap: "wrap",
|
||||
}}
|
||||
>
|
||||
<div>
|
||||
<strong style={{ color: "var(--text-primary)", fontSize: 14 }}>
|
||||
Component Groups
|
||||
</strong>
|
||||
<p
|
||||
style={{
|
||||
marginTop: 6,
|
||||
color: "var(--text-muted)",
|
||||
fontSize: 13,
|
||||
lineHeight: 1.6,
|
||||
}}
|
||||
>
|
||||
Switch between core host infrastructure and runtime packages that
|
||||
support native deployments on the server.
|
||||
</p>
|
||||
</div>
|
||||
<div style={{ display: "flex", gap: 8, flexWrap: "wrap" }}>
|
||||
<button
|
||||
className="btn btn-ghost btn-sm"
|
||||
onClick={() => setActiveGroup("infrastructure")}
|
||||
style={{
|
||||
borderColor:
|
||||
activeGroup === "infrastructure"
|
||||
? "rgba(59,130,246,0.35)"
|
||||
: "var(--border)",
|
||||
background:
|
||||
activeGroup === "infrastructure"
|
||||
? "rgba(59,130,246,0.12)"
|
||||
: "var(--bg-input)",
|
||||
color:
|
||||
activeGroup === "infrastructure"
|
||||
? "#3b82f6"
|
||||
: "var(--text-secondary)",
|
||||
}}
|
||||
>
|
||||
Infrastructure
|
||||
</button>
|
||||
<button
|
||||
className="btn btn-ghost btn-sm"
|
||||
onClick={() => setActiveGroup("runtime-tools")}
|
||||
style={{
|
||||
borderColor:
|
||||
activeGroup === "runtime-tools"
|
||||
? "rgba(59,130,246,0.35)"
|
||||
: "var(--border)",
|
||||
background:
|
||||
activeGroup === "runtime-tools"
|
||||
? "rgba(59,130,246,0.12)"
|
||||
: "var(--bg-input)",
|
||||
color:
|
||||
activeGroup === "runtime-tools"
|
||||
? "#3b82f6"
|
||||
: "var(--text-secondary)",
|
||||
}}
|
||||
>
|
||||
Runtime Tools
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div
|
||||
style={{
|
||||
display: "flex",
|
||||
justifyContent: "space-between",
|
||||
alignItems: "center",
|
||||
gap: 12,
|
||||
flexWrap: "wrap",
|
||||
}}
|
||||
>
|
||||
<div>
|
||||
<strong style={{ color: "var(--text-primary)", fontSize: 13 }}>
|
||||
{activeGroup === "infrastructure"
|
||||
? "Infrastructure"
|
||||
: "Runtime Tools"}
|
||||
</strong>
|
||||
<p
|
||||
style={{
|
||||
marginTop: 4,
|
||||
color: "var(--text-muted)",
|
||||
fontSize: 12,
|
||||
lineHeight: 1.6,
|
||||
}}
|
||||
>
|
||||
{activeGroup === "infrastructure"
|
||||
? "Core host services for reverse proxy, site delivery, and HTTPS automation."
|
||||
: "Optional native host deployment packages for app runtimes, databases, queues, and supporting tools."}
|
||||
</p>
|
||||
</div>
|
||||
<hr style={{ borderColor: "var(--border)", width: "100%" }} />
|
||||
|
||||
<div style={{ display: "flex", gap: 8, flexWrap: "wrap" }}>
|
||||
<UserBadge
|
||||
label={`${visibleComponents.length} components`}
|
||||
tone="neutral"
|
||||
/>
|
||||
{activeGroup === "runtime-tools" ? (
|
||||
<UserBadge label="Native Host Deployment" tone="info" />
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div
|
||||
style={{
|
||||
display: "grid",
|
||||
gridTemplateColumns: "repeat(auto-fit, minmax(280px, 1fr))",
|
||||
gap: 16,
|
||||
}}
|
||||
>
|
||||
{visibleComponents.map((component) => renderComponentCard(component))}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
export function formatUptime(sec: string | null | undefined): string {
|
||||
if (!sec) return "—";
|
||||
const seconds = Number(sec);
|
||||
const days = Math.floor(seconds / 86400);
|
||||
const hours = Math.floor((seconds % 86400) / 3600);
|
||||
const minutes = Math.floor((seconds % 3600) / 60);
|
||||
if (days > 0) return `${days}d ${hours}h`;
|
||||
if (hours > 0) return `${hours}h ${minutes}m`;
|
||||
return `${minutes}m`;
|
||||
}
|
||||
|
||||
export function formatBytes(bytes: string | null | undefined): string {
|
||||
if (!bytes) return "—";
|
||||
const value = Number(bytes);
|
||||
if (value >= 1e9) return `${(value / 1e9).toFixed(1)} GB`;
|
||||
if (value >= 1e6) return `${(value / 1e6).toFixed(0)} MB`;
|
||||
return `${(value / 1e3).toFixed(0)} KB`;
|
||||
}
|
||||
|
||||
export function formatLastUpdated(value: string | null | undefined): string {
|
||||
if (!value) return "—";
|
||||
|
||||
const date = new Date(value);
|
||||
if (Number.isNaN(date.getTime())) return "—";
|
||||
|
||||
const diffSeconds = Math.max(
|
||||
0,
|
||||
Math.floor((Date.now() - date.getTime()) / 1000),
|
||||
);
|
||||
if (diffSeconds < 60) return `${diffSeconds}s ago`;
|
||||
if (diffSeconds < 3600) return `${Math.floor(diffSeconds / 60)}m ago`;
|
||||
if (diffSeconds < 86400) return `${Math.floor(diffSeconds / 3600)}h ago`;
|
||||
return date.toLocaleString();
|
||||
}
|
||||
|
||||
export function formatDateTime(value: string | null | undefined): string {
|
||||
if (!value) return "—";
|
||||
|
||||
const date = new Date(value);
|
||||
if (Number.isNaN(date.getTime())) return value;
|
||||
|
||||
return date.toLocaleString();
|
||||
}
|
||||
Reference in new issue
Block a user