Fragnet game servers: games, addresses, backups, power actions
New integration kind "fragnet" reading Fragnet's Pterodactyl-based panel through the client API (account key). Game servers page under Infrastructure with game, IP:port, state, memory/disk, backups, schedules and databases; alerts for late backups and nearly full disk/memory; operators can start/stop/restart/kill (audited). Metrics, docs and tests included; migration 0071 adds fragnet_state. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
f86661f6c9
commit
9a3d5c466a
29 files changed
+9836
-8
No files matched your search
@@ -20,6 +20,7 @@ import N8n from "./pages/N8n";
|
||||
import NetBox from "./pages/NetBox";
|
||||
import Nextcloud from "./pages/Nextcloud";
|
||||
import Hetzner from "./pages/Hetzner";
|
||||
import GameServers from "./pages/GameServers";
|
||||
import Speedtest from "./pages/Speedtest";
|
||||
import Costs from "./pages/Costs";
|
||||
import ServiceLevels from "./pages/ServiceLevels";
|
||||
@@ -178,6 +179,7 @@ function Shelled({ user }: { user: CurrentUser }) {
|
||||
<Route path="/netbox" element={<NetBox />} />
|
||||
<Route path="/nextcloud" element={<Nextcloud />} />
|
||||
<Route path="/hetzner" element={<Hetzner />} />
|
||||
<Route path="/game-servers" element={<GameServers user={user} />} />
|
||||
<Route path="/speedtest" element={<Speedtest />} />
|
||||
<Route path="/costs" element={<Costs user={user} />} />
|
||||
<Route path="/service-levels" element={<ServiceLevels user={user} />} />
|
||||
|
||||
+57
-1
@@ -1326,6 +1326,57 @@ export interface HetznerForServer {
|
||||
} | null;
|
||||
}
|
||||
|
||||
export interface FragnetServerInfo {
|
||||
/** The short id (8 characters) the game panel uses. */
|
||||
id: string;
|
||||
name: string;
|
||||
description: string | null;
|
||||
node: string | null;
|
||||
/** The game, as the panel names it; null when it did not say. */
|
||||
game: string | null;
|
||||
dockerImage: string | null;
|
||||
panelStatus: string | null;
|
||||
suspended: boolean;
|
||||
installing: boolean;
|
||||
transferring: boolean;
|
||||
owner: boolean;
|
||||
/** running, starting, stopping, offline — or unknown when it could not be read. */
|
||||
state: string;
|
||||
allocations: { ip: string; alias: string | null; port: number; isDefault: boolean; notes: string | null }[];
|
||||
sftp: string | null;
|
||||
/** MB; 0 or null: no limit / not said. */
|
||||
memoryLimitMb: number | null;
|
||||
diskLimitMb: number | null;
|
||||
cpuLimit: number | null;
|
||||
databaseLimit: number | null;
|
||||
backupLimit: number | null;
|
||||
allocationLimit: number | null;
|
||||
usage: { memoryBytes: number; cpu: number; diskBytes: number; rxBytes: number; txBytes: number; uptimeMs: number } | null;
|
||||
/** Newest first; null when they could not be listed. */
|
||||
backups: { uuid: string; name: string | null; bytes: number; createdAt: string | null; completedAt: string | null; successful: boolean; locked: boolean }[] | null;
|
||||
schedules: { id: number; name: string; cron: string; active: boolean; processing: boolean; onlyWhenOnline: boolean; lastRunAt: string | null; nextRunAt: string | null }[] | null;
|
||||
databases: number | null;
|
||||
stateSince: string;
|
||||
firstSeenAt: string;
|
||||
/** The newest backup that worked, and whether a newer one failed; null when the backups could not be listed. */
|
||||
newestBackup: { at: string | null; failedSince: boolean } | null;
|
||||
}
|
||||
|
||||
/** One Fragnet game panel account (an integration of type fragnet), as its page shows it. */
|
||||
export interface FragnetAccount {
|
||||
id: number;
|
||||
name: string;
|
||||
enabled: boolean;
|
||||
panelUrl: string;
|
||||
status: { at: string; ok: boolean; error: string | null } | null;
|
||||
fresh: boolean;
|
||||
options: { backupDays: number; fullPercent: number; ignoreBackups: string[] };
|
||||
state: { servers: FragnetServerInfo[]; updatedAt: string } | null;
|
||||
problems: { key: string; serverId: string; message: string; severity: "warning" | "critical" }[];
|
||||
}
|
||||
|
||||
export type FragnetSignal = "start" | "stop" | "restart" | "kill";
|
||||
|
||||
export interface CostItem {
|
||||
id: number;
|
||||
name: string;
|
||||
@@ -2444,7 +2495,7 @@ export interface ManualTaskInput {
|
||||
enabled?: boolean;
|
||||
}
|
||||
|
||||
export type IntegrationType = "proxmox" | "synology" | "semaphore" | "tailscale" | "gitea" | "dockhand" | "uptimekuma" | "phpipam" | "pbs" | "osticket" | "unifi" | "npm" | "homeassistant" | "ups" | "jellyfin" | "authentik" | "prometheus" | "immich" | "paperless" | "nextcloud" | "netbox" | "n8n" | "hetzner" | "speedtest";
|
||||
export type IntegrationType = "proxmox" | "synology" | "semaphore" | "tailscale" | "gitea" | "dockhand" | "uptimekuma" | "phpipam" | "pbs" | "osticket" | "unifi" | "npm" | "homeassistant" | "ups" | "jellyfin" | "authentik" | "prometheus" | "immich" | "paperless" | "nextcloud" | "netbox" | "n8n" | "hetzner" | "speedtest" | "fragnet";
|
||||
|
||||
export interface IntegrationField {
|
||||
key: string;
|
||||
@@ -3039,6 +3090,11 @@ export const api = {
|
||||
list: () => request<{ speedtests: SpeedtestInfo[] }>("/api/speedtest"),
|
||||
history: (id: number, days: number) => request<SpeedtestHistory>(`/api/speedtest/${id}/history?days=${days}`),
|
||||
},
|
||||
fragnet: {
|
||||
list: () => request<{ accounts: FragnetAccount[] }>("/api/fragnet"),
|
||||
power: (integrationId: number, serverId: string, signal: FragnetSignal) => request<void>(`/api/fragnet/${integrationId}/servers/${serverId}/power`, { method: "POST", body: JSON.stringify({ signal }) }),
|
||||
refresh: (integrationId: number) => request<{ status: { ok: boolean; error: string | null } }>(`/api/fragnet/${integrationId}/refresh`, { method: "POST" }),
|
||||
},
|
||||
hetzner: {
|
||||
list: () => request<{ projects: HetznerProject[] }>("/api/hetzner"),
|
||||
forServer: (serverId: number) => request<HetznerForServer>(`/api/hetzner/for-server/${serverId}`),
|
||||
|
||||
@@ -29,6 +29,7 @@ const TYPE_LABELS: Record<string, string> = {
|
||||
nextcloud: "Nextcloud",
|
||||
hetzner: "Hetzner Cloud",
|
||||
speedtest: "Speedtest Tracker",
|
||||
fragnet: "Fragnet game servers",
|
||||
};
|
||||
|
||||
export type WallLevel = "critical" | "warning" | "ok" | "unsure";
|
||||
|
||||
@@ -19,6 +19,7 @@ import {
|
||||
IconAffiliate,
|
||||
IconCloud,
|
||||
IconBinaryTree,
|
||||
IconDeviceGamepad2,
|
||||
IconServerBolt,
|
||||
IconBolt,
|
||||
IconFileText,
|
||||
@@ -97,6 +98,7 @@ export const NAV: NavEntry[] = [
|
||||
{ to: "/synology", label: "Synology", icon: <IconDatabase size={20} /> },
|
||||
{ to: "/docker", label: "Docker", icon: <IconBrandDocker size={20} /> },
|
||||
{ to: "/hetzner", label: "Hetzner Cloud", icon: <IconServerBolt size={20} /> },
|
||||
{ to: "/game-servers", label: "Game servers", icon: <IconDeviceGamepad2 size={20} /> },
|
||||
{ to: "/tailscale", label: "Tailscale", icon: <IconAffiliate size={20} /> },
|
||||
],
|
||||
},
|
||||
|
||||
@@ -0,0 +1,426 @@
|
||||
import { Fragment, useEffect, useState } from "react";
|
||||
import { Link } from "react-router-dom";
|
||||
import { api, type CurrentUser, type FragnetAccount, type FragnetServerInfo, type FragnetSignal } from "../api/client";
|
||||
import EmptyState from "../components/EmptyState";
|
||||
import TimeAgo from "../components/TimeAgo";
|
||||
import { BlockSkeleton } from "../components/Skeleton";
|
||||
import { ErrorNotice } from "../components/Notice";
|
||||
import { formatBytes } from "./settings/StorageSettings";
|
||||
import { confirmDialog } from "../utils/dialogs";
|
||||
import { readableError } from "../utils/errors";
|
||||
import { toast } from "../utils/toast";
|
||||
|
||||
type Server = FragnetServerInfo;
|
||||
|
||||
const MB = 1024 ** 2;
|
||||
|
||||
function Badge({ a }: { a: FragnetAccount }) {
|
||||
if (!a.enabled) return <span className="badge bg-secondary-lt text-secondary">Off</span>;
|
||||
if (!a.state) return <span className="badge bg-secondary-lt text-secondary">Not read yet</span>;
|
||||
if (!a.fresh) return <span className="badge bg-yellow-lt text-yellow">Can’t be read</span>;
|
||||
if (a.problems.some((x) => x.severity === "critical")) return <span className="badge bg-red-lt text-red">Needs a look</span>;
|
||||
if (a.problems.length > 0) return <span className="badge bg-yellow-lt text-yellow">Needs a look</span>;
|
||||
return <span className="badge bg-green-lt text-green">In order</span>;
|
||||
}
|
||||
|
||||
function StateBadge({ s }: { s: Server }) {
|
||||
if (s.suspended) return <span className="badge bg-red-lt text-red">Suspended</span>;
|
||||
if (s.installing) return <span className="badge bg-blue-lt text-blue">Installing</span>;
|
||||
if (s.panelStatus === "restoring_backup") return <span className="badge bg-blue-lt text-blue">Restoring a backup</span>;
|
||||
if (s.panelStatus === "install_failed" || s.panelStatus === "reinstall_failed") return <span className="badge bg-red-lt text-red">Install failed</span>;
|
||||
if (s.state === "running") return <span className="badge bg-green-lt text-green">Running</span>;
|
||||
if (s.state === "offline") return <span className="badge bg-secondary-lt text-secondary">Stopped</span>;
|
||||
if (s.state === "starting") return <span className="badge bg-blue-lt text-blue">Starting</span>;
|
||||
if (s.state === "stopping") return <span className="badge bg-yellow-lt text-yellow">Stopping</span>;
|
||||
return <span className="badge bg-yellow-lt text-yellow">Unknown</span>;
|
||||
}
|
||||
|
||||
/** What is used of a limit, as a bar that turns yellow at the integration's limit for "nearly full" and red near the top. A limit of 0 (or none) is no limit: only the use is written. */
|
||||
function UseBar({ label, used, limitMb, fullPercent }: { label: string; used: number | null; limitMb: number | null; fullPercent: number }) {
|
||||
if (used === null) return <div className="small text-secondary">{label} —</div>;
|
||||
if (!limitMb || limitMb <= 0) return <div className="small text-secondary">{label} {formatBytes(used)}, no limit</div>;
|
||||
const share = used / (limitMb * MB);
|
||||
return (
|
||||
<div style={{ minWidth: 150 }} className="mb-1">
|
||||
<div className="progress progress-sm">
|
||||
<div className={`progress-bar ${share >= 0.98 ? "bg-red" : share * 100 >= fullPercent ? "bg-yellow" : "bg-green"}`} style={{ width: `${Math.min(100, share * 100)}%` }} />
|
||||
</div>
|
||||
<div className="small text-secondary">
|
||||
{label} {formatBytes(used)} of {formatBytes(limitMb * MB)} ({Math.floor(share * 100)}%)
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const address = (a: Server["allocations"][number]) => `${a.alias ?? a.ip}:${a.port}`;
|
||||
|
||||
function CopyAddress({ a }: { a: Server["allocations"][number] }) {
|
||||
const text = `${a.ip}:${a.port}`;
|
||||
return (
|
||||
<button
|
||||
type="button"
|
||||
className="btn btn-link p-0 text-reset text-decoration-none"
|
||||
title="Copy the address"
|
||||
onClick={() => {
|
||||
void navigator.clipboard?.writeText(text).then(
|
||||
() => toast.success(`Copied ${text}`),
|
||||
() => toast.error("Couldn't copy it."),
|
||||
);
|
||||
}}
|
||||
>
|
||||
<code>{text}</code>
|
||||
</button>
|
||||
);
|
||||
}
|
||||
|
||||
const SIGNAL_TEXT: Record<FragnetSignal, { verb: string; done: string; confirm: string | null; danger: boolean }> = {
|
||||
start: { verb: "Start", done: "start", confirm: null, danger: false },
|
||||
stop: { verb: "Stop", done: "stop", confirm: "Stop {name}? The game is shut down properly, and the players are disconnected.", danger: false },
|
||||
restart: { verb: "Restart", done: "restart", confirm: "Restart {name}? The players are disconnected for a moment.", danger: false },
|
||||
kill: { verb: "Kill", done: "kill", confirm: "Kill {name}? It is stopped at once, without saving — unsaved progress is lost. Use it only when Stop does not work.", danger: true },
|
||||
};
|
||||
|
||||
function Details({ s, panelUrl, canAct, onSignal }: { s: Server; panelUrl: string; canAct: boolean; onSignal: (s: Server, signal: FragnetSignal) => void }) {
|
||||
const backups = s.backups ?? [];
|
||||
return (
|
||||
<div className="row g-3">
|
||||
<div className="col-lg-4">
|
||||
<h5>Addresses</h5>
|
||||
{s.allocations.length === 0 && <div className="text-secondary small">The panel did not list any.</div>}
|
||||
<ul className="list-unstyled mb-2">
|
||||
{s.allocations.map((a) => (
|
||||
<li key={`${a.ip}:${a.port}`}>
|
||||
<CopyAddress a={a} /> {a.isDefault && <span className="badge bg-blue-lt text-blue">main</span>}
|
||||
{a.alias && <span className="text-secondary small"> {a.alias}</span>}
|
||||
{a.notes && <span className="text-secondary small"> — {a.notes}</span>}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
<div className="small text-secondary">
|
||||
{s.sftp && (
|
||||
<div>
|
||||
SFTP: <code>{s.sftp}</code>
|
||||
</div>
|
||||
)}
|
||||
{s.node && <div>Runs on: {s.node}</div>}
|
||||
{s.dockerImage && <div className="text-break">Image: {s.dockerImage}</div>}
|
||||
<div>
|
||||
Plan: {s.memoryLimitMb ? formatBytes(s.memoryLimitMb * MB) : "no limit"} memory, {s.diskLimitMb ? formatBytes(s.diskLimitMb * MB) : "no limit"} disk{s.cpuLimit ? `, ${s.cpuLimit}% CPU` : ""}
|
||||
</div>
|
||||
<div>
|
||||
Room for {s.backupLimit ?? "?"} backups, {s.databaseLimit ?? "?"} databases{s.databases !== null ? ` (${s.databases} made)` : ""}
|
||||
</div>
|
||||
{!s.owner && <div>Shared with this account — not owned by it.</div>}
|
||||
<div>
|
||||
Known here since <TimeAgo value={s.firstSeenAt} />
|
||||
</div>
|
||||
</div>
|
||||
<div className="mt-2 btn-list">
|
||||
<a className="btn btn-sm" href={`${panelUrl.replace(/\/+$/, "")}/server/${s.id}`} target="_blank" rel="noopener noreferrer">
|
||||
Open in the game panel
|
||||
</a>
|
||||
{canAct && !s.suspended && !s.installing && (
|
||||
<button className="btn btn-sm btn-outline-danger" onClick={() => onSignal(s, "kill")}>
|
||||
Kill…
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
<div className="col-lg-4">
|
||||
<h5>Backups{s.backupLimit ? ` (${backups.filter((b) => b.completedAt !== null).length} of ${s.backupLimit})` : ""}</h5>
|
||||
{s.backups === null && <div className="text-secondary small">They could not be listed (the key may not be allowed to).</div>}
|
||||
{s.backups !== null && backups.length === 0 && <div className="text-secondary small">{s.backupLimit ? "None has been made." : "This plan has none."}</div>}
|
||||
<ul className="list-unstyled mb-0">
|
||||
{backups.slice(0, 8).map((b) => (
|
||||
<li key={b.uuid}>
|
||||
{b.completedAt === null ? <span className="badge bg-blue-lt text-blue">being made</span> : b.successful ? <span className="badge bg-green-lt text-green">worked</span> : <span className="badge bg-red-lt text-red">failed</span>}{" "}
|
||||
<TimeAgo value={b.completedAt ?? b.createdAt} />
|
||||
<span className="text-secondary small">
|
||||
{b.successful ? ` · ${formatBytes(b.bytes)}` : ""}
|
||||
{b.locked ? " · locked" : ""}
|
||||
</span>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
{backups.length > 8 && <div className="text-secondary small">and {backups.length - 8} older</div>}
|
||||
</div>
|
||||
<div className="col-lg-4">
|
||||
<h5>Schedules</h5>
|
||||
{s.schedules === null && <div className="text-secondary small">They could not be listed.</div>}
|
||||
{s.schedules !== null && s.schedules.length === 0 && <div className="text-secondary small">None. A restart or a backup on a schedule is set in the game panel.</div>}
|
||||
<ul className="list-unstyled mb-0">
|
||||
{s.schedules?.map((x) => (
|
||||
<li key={x.id}>
|
||||
<strong>{x.name}</strong> {!x.active && <span className="badge bg-secondary-lt text-secondary">off</span>} <code className="small">{x.cron}</code>
|
||||
<div className="small text-secondary">
|
||||
{x.lastRunAt ? (
|
||||
<>
|
||||
ran <TimeAgo value={x.lastRunAt} />
|
||||
</>
|
||||
) : (
|
||||
"has not run"
|
||||
)}
|
||||
{x.active && x.nextRunAt && (
|
||||
<>
|
||||
{" "}
|
||||
· next <TimeAgo value={x.nextRunAt} />
|
||||
</>
|
||||
)}
|
||||
{x.onlyWhenOnline ? " · only while running" : ""}
|
||||
</div>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function ServerRow({ a, s, readAt, canAct, open, onToggle, onSignal, busy }: { a: FragnetAccount; s: Server; readAt: string; canAct: boolean; open: boolean; onToggle: () => void; onSignal: (s: Server, signal: FragnetSignal) => void; busy: boolean }) {
|
||||
const main = s.allocations[0];
|
||||
const problems = a.problems.filter((p) => p.serverId === s.id);
|
||||
const running = s.state === "running" || s.state === "starting" || s.state === "stopping";
|
||||
const movable = canAct && !s.suspended && !s.installing && s.panelStatus !== "restoring_backup" && s.state !== "unknown";
|
||||
const backup = s.newestBackup;
|
||||
return (
|
||||
<Fragment>
|
||||
<tr>
|
||||
<td className="text-break">
|
||||
<button type="button" className="btn btn-link p-0 text-reset text-decoration-none text-start" aria-expanded={open} onClick={onToggle}>
|
||||
<strong>{s.name}</strong> <span className="text-secondary">{open ? "▾" : "▸"}</span>
|
||||
</button>
|
||||
<div className="small text-secondary">{s.game ?? s.dockerImage ?? "game not said"}</div>
|
||||
{s.description && <div className="small text-secondary">{s.description}</div>}
|
||||
{problems.length > 0 && <div className={`small ${problems.some((p) => p.severity === "critical") ? "text-red" : "text-yellow"}`}>{problems.length === 1 ? "needs a look — see above" : `${problems.length} things need a look — see above`}</div>}
|
||||
</td>
|
||||
<td>
|
||||
<StateBadge s={s} />
|
||||
{s.state !== "unknown" && s.state !== "running" && (
|
||||
<div className="text-secondary small">
|
||||
since <TimeAgo value={s.stateSince} />
|
||||
</div>
|
||||
)}
|
||||
{s.usage && s.state === "running" && s.usage.uptimeMs > 0 && (
|
||||
<div className="text-secondary small">
|
||||
started <TimeAgo value={new Date(Date.parse(readAt) - s.usage.uptimeMs)} />
|
||||
</div>
|
||||
)}
|
||||
</td>
|
||||
<td>
|
||||
{main ? <CopyAddress a={main} /> : <span className="text-secondary">—</span>}
|
||||
{main?.alias && <div className="small text-secondary">{address(main)}</div>}
|
||||
{s.allocations.length > 1 && <div className="small text-secondary">+{s.allocations.length - 1} more</div>}
|
||||
</td>
|
||||
<td>
|
||||
<UseBar label="Memory" used={s.state === "running" || s.state === "starting" ? (s.usage?.memoryBytes ?? null) : null} limitMb={s.memoryLimitMb} fullPercent={a.options.fullPercent} />
|
||||
<UseBar label="Disk" used={s.usage?.diskBytes ?? null} limitMb={s.diskLimitMb} fullPercent={a.options.fullPercent} />
|
||||
</td>
|
||||
<td className="text-secondary">
|
||||
{backup === null ? (
|
||||
"—"
|
||||
) : backup.at ? (
|
||||
<>
|
||||
<TimeAgo value={backup.at} />
|
||||
{backup.failedSince && <div className="small text-red">a newer one failed</div>}
|
||||
</>
|
||||
) : (
|
||||
<span className={s.backupLimit ? "text-yellow" : ""}>{s.backupLimit ? "none yet" : "none"}</span>
|
||||
)}
|
||||
{s.backupLimit ? <div className="small">of {s.backupLimit} allowed</div> : null}
|
||||
</td>
|
||||
<td className="text-end">
|
||||
{movable && (
|
||||
<div className="btn-list justify-content-end flex-nowrap">
|
||||
{!running && (
|
||||
<button className="btn btn-sm" disabled={busy} onClick={() => onSignal(s, "start")}>
|
||||
Start
|
||||
</button>
|
||||
)}
|
||||
{running && (
|
||||
<>
|
||||
<button className="btn btn-sm" disabled={busy} onClick={() => onSignal(s, "restart")}>
|
||||
Restart
|
||||
</button>
|
||||
<button className="btn btn-sm" disabled={busy} onClick={() => onSignal(s, "stop")}>
|
||||
Stop
|
||||
</button>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</td>
|
||||
</tr>
|
||||
{open && (
|
||||
<tr>
|
||||
<td colSpan={6} className="bg-body-tertiary">
|
||||
<Details s={s} panelUrl={a.panelUrl} canAct={movable} onSignal={onSignal} />
|
||||
</td>
|
||||
</tr>
|
||||
)}
|
||||
</Fragment>
|
||||
);
|
||||
}
|
||||
|
||||
function Card({ a, canAct, reload }: { a: FragnetAccount; canAct: boolean; reload: () => void }) {
|
||||
const s = a.state;
|
||||
const [open, setOpen] = useState<string | null>(null);
|
||||
const [busy, setBusy] = useState(false);
|
||||
const running = s?.servers.filter((x) => x.state === "running").length ?? 0;
|
||||
const stopped = s?.servers.filter((x) => x.state === "offline" && !x.suspended).length ?? 0;
|
||||
|
||||
async function signal(server: Server, sig: FragnetSignal) {
|
||||
const t = SIGNAL_TEXT[sig];
|
||||
if (t.confirm && !(await confirmDialog({ title: `${t.verb} ${server.name}`, message: t.confirm.replace("{name}", server.name), confirmLabel: t.verb, danger: t.danger }))) return;
|
||||
setBusy(true);
|
||||
try {
|
||||
await api.fragnet.power(a.id, server.id, sig);
|
||||
toast.success(`Asked ${server.name} to ${t.done}.`);
|
||||
// The game takes a few seconds to change; read again then, so the page shows what happened.
|
||||
setTimeout(() => {
|
||||
void api.fragnet
|
||||
.refresh(a.id)
|
||||
.catch(() => undefined)
|
||||
.finally(() => {
|
||||
setBusy(false);
|
||||
reload();
|
||||
});
|
||||
}, 4000);
|
||||
} catch (err) {
|
||||
setBusy(false);
|
||||
toast.error(readableError(err));
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="card mb-3">
|
||||
<div className="card-header">
|
||||
<h3 className="card-title">
|
||||
{a.name} <Badge a={a} />
|
||||
</h3>
|
||||
<div className="card-actions text-secondary small">{a.status ? <>read <TimeAgo value={a.status.at} /></> : "not read yet"}</div>
|
||||
</div>
|
||||
<div className="card-body">
|
||||
{a.status && !a.status.ok && <div className="text-yellow mb-2">The last attempt to read it failed: {a.status.error ?? "no answer"}.</div>}
|
||||
{a.problems.length > 0 && (
|
||||
<ul className="mb-3">
|
||||
{a.problems.map((x) => (
|
||||
<li key={x.key} className={x.severity === "critical" ? "text-red" : ""}>
|
||||
{x.message}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
)}
|
||||
{s && (
|
||||
<>
|
||||
<div className="row g-3 mb-3">
|
||||
<div className="col-6 col-lg-3">
|
||||
<div className="card card-sm h-100">
|
||||
<div className="card-body">
|
||||
<div className="text-secondary small">Game servers</div>
|
||||
<div className="h2 mb-0">{s.servers.length}</div>
|
||||
<div className="text-secondary small">
|
||||
{running} running{stopped > 0 ? `, ${stopped} stopped` : ""}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="col-6 col-lg-3">
|
||||
<div className="card card-sm h-100">
|
||||
<div className="card-body">
|
||||
<div className="text-secondary small">Games</div>
|
||||
<div className="h2 mb-0">{new Set(s.servers.map((x) => x.game ?? x.dockerImage ?? "?")).size}</div>
|
||||
<div className="text-secondary small text-truncate">{[...new Set(s.servers.map((x) => x.game).filter(Boolean))].join(", ") || "not said by the panel"}</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="col-6 col-lg-3">
|
||||
<div className="card card-sm h-100">
|
||||
<div className="card-body">
|
||||
<div className="text-secondary small">Backups</div>
|
||||
<div className="h2 mb-0">{s.servers.reduce((n, x) => n + (x.backups?.filter((b) => b.completedAt !== null && b.successful).length ?? 0), 0)}</div>
|
||||
<div className="text-secondary small">{a.options.backupDays > 0 ? `one is wanted every ${a.options.backupDays} days` : "not judged"}</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="col-6 col-lg-3">
|
||||
<div className="card card-sm h-100">
|
||||
<div className="card-body">
|
||||
<div className="text-secondary small">Addresses</div>
|
||||
<div className="h2 mb-0">{s.servers.reduce((n, x) => n + x.allocations.length, 0)}</div>
|
||||
<div className="text-secondary small">on {new Set(s.servers.flatMap((x) => x.allocations.map((y) => y.ip))).size} IP address(es)</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="table-responsive">
|
||||
<table className="table table-vcenter card-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Server</th>
|
||||
<th>State</th>
|
||||
<th>Address</th>
|
||||
<th>Use</th>
|
||||
<th>Newest backup</th>
|
||||
<th />
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{s.servers.map((x) => (
|
||||
<ServerRow key={x.id} a={a} s={x} readAt={s.updatedAt} canAct={canAct} open={open === x.id} onToggle={() => setOpen(open === x.id ? null : x.id)} onSignal={(sv, sig) => void signal(sv, sig)} busy={busy} />
|
||||
))}
|
||||
{s.servers.length === 0 && (
|
||||
<tr>
|
||||
<td colSpan={6} className="text-secondary">
|
||||
The account has no game servers.
|
||||
</td>
|
||||
</tr>
|
||||
)}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
/** Fragnet: each account's game servers — the game, the addresses, how they are doing and whether they are backed up — with start, stop and restart for operators. */
|
||||
export default function GameServers({ user }: { user: CurrentUser }) {
|
||||
const canAct = user.role === "admin" || user.role === "operator";
|
||||
const [data, setData] = useState<FragnetAccount[] | null>(null);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [tick, setTick] = useState(0);
|
||||
useEffect(() => {
|
||||
const load = () =>
|
||||
api.fragnet
|
||||
.list()
|
||||
.then((r) => {
|
||||
setData(r.accounts);
|
||||
setError(null);
|
||||
})
|
||||
.catch((err) => setError(readableError(err)));
|
||||
void load();
|
||||
const t = setInterval(load, 60_000);
|
||||
return () => clearInterval(t);
|
||||
}, [tick]);
|
||||
return (
|
||||
<>
|
||||
<h2 className="page-title">Game servers</h2>
|
||||
<p className="text-secondary">
|
||||
What Fragnet’s game panel says about your servers, read every few minutes (see <Link to="/integrations">Integrations</Link>). <strong>A backup that is late</strong> and <strong>a disk or memory nearly full</strong> are alerts — see <Link to="/alerts">Alerts</Link>; a server that is stopped is not, since a game server is often stopped on purpose.
|
||||
{canAct ? " Start, stop and restart are sent to the panel when you press them; nothing else is ever changed." : " Operators can start, stop and restart them from here."} What they cost is added by hand under <Link to="/costs">Costs</Link>.
|
||||
</p>
|
||||
<ErrorNotice error={error} />
|
||||
{!data && !error && <BlockSkeleton lines={4} />}
|
||||
{data && data.length === 0 && (
|
||||
<div className="card">
|
||||
<div className="card-body">
|
||||
<EmptyState title="No Fragnet account connected" hint="Add one under Integrations with an API key from the game panel (panel.fragnet.net → your profile → API Credentials; it starts with ptlc_)." />
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
{data?.map((a) => <Card key={a.id} a={a} canAct={canAct} reload={() => setTick((n) => n + 1)} />)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -26,6 +26,7 @@ export const TYPE_LABELS: Record<IntegrationType, string> = {
|
||||
nextcloud: "Nextcloud",
|
||||
hetzner: "Hetzner Cloud",
|
||||
speedtest: "Speedtest Tracker",
|
||||
fragnet: "Fragnet game servers",
|
||||
};
|
||||
|
||||
/** The page each kind of integration gets once it is connected. */
|
||||
@@ -54,11 +55,12 @@ export const TYPE_PAGES: Record<IntegrationType, string> = {
|
||||
nextcloud: "/nextcloud",
|
||||
hetzner: "/hetzner",
|
||||
speedtest: "/speedtest",
|
||||
fragnet: "/game-servers",
|
||||
};
|
||||
|
||||
/** The kinds of integration grouped the way the sidebar groups their pages, in the same order. */
|
||||
export const TYPE_GROUPS: { id: string; label: string; types: IntegrationType[] }[] = [
|
||||
{ id: "infrastructure", label: "Infrastructure", types: ["proxmox", "synology", "dockhand", "hetzner", "tailscale"] },
|
||||
{ id: "infrastructure", label: "Infrastructure", types: ["proxmox", "synology", "dockhand", "hetzner", "fragnet", "tailscale"] },
|
||||
{ id: "apps", label: "Apps", types: ["homeassistant", "jellyfin", "immich", "paperless", "nextcloud", "authentik"] },
|
||||
{ id: "backups", label: "Backups", types: ["pbs"] },
|
||||
{ id: "network", label: "Network", types: ["unifi", "npm", "phpipam", "netbox"] },
|
||||
|
||||
Reference in new issue
Block a user