Servers and the agent, dashboard (2.1.0): servers, installs, updates, jobs, ports, download page

- Servers: add with a one-time join command, each server's CPU / RAM
  charts (24 h, 7 days, 90 days, spikes over 85% marked, table view),
  configuration, PM2 processes, sites, jobs and alerts.
- Installs: New install (server chooser with free RAM, CPU and sites),
  Link existing, FastPanel steps and Proxy done, schedule / emergency
  update, adopt, uninstall (2FA and the short name).
- Updates: one release to many installs (a batch), planned jobs.
- Jobs with their reports; Ports & defaults; the public download page
  that decrypts an export in the browser.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-17 13:18:20 +02:00
co-authored by Claude Opus 5.5
parent 041461f2b5
commit c8359c77e9
13 changed files with 1075 additions and 4 deletions
@@ -0,0 +1,90 @@
"use client";
import React, { useCallback, useEffect, useMemo, useState } from "react";
import Link from "next/link";
import { api, errorText } from "@/lib/api";
import { fmtDate } from "@/lib/format";
import { Loading, Message, PageTitle } from "@/components/ui";
import { ServersNav, StatusPill, toInput, fromInput, type Deployment, type Job } from "@/components/servers";
type Msg = { type: "ok" | "err"; text: string } | null;
const H = 60 * 60 * 1000;
/**
* Updates (§8): one release to several installs at one time with one notice. They run one at a
* time, and the batch stops at the first failure (the rest are told it's postponed).
*/
export default function UpdatesPage() {
const [deployments, setDeployments] = useState<Deployment[] | null>(null);
const [upcoming, setUpcoming] = useState<Job[]>([]);
const [chosen, setChosen] = useState<string[]>([]);
const [form, setForm] = useState({ version: "", at: toInput(new Date(Date.now() + 5 * H)), emergency: false, reason: "", totp: "" });
const [msg, setMsg] = useState<Msg>(null);
const load = useCallback(() => {
api<{ deployments: Deployment[] }>("/api/admin/deployments?status=live").then(r => setDeployments(r.deployments)).catch(e => setMsg({ type: "err", text: errorText(e) }));
api<{ jobs: Job[] }>("/api/admin/jobs?upcoming=true").then(r => setUpcoming(r.jobs)).catch(() => {});
}, []);
useEffect(() => { load(); }, [load]);
const byVersion = useMemo(() => [...new Set((deployments || []).map(d => d.install?.version || d.version || "?"))].sort(), [deployments]);
const submit = async (e: React.FormEvent) => {
e.preventDefault();
setMsg(null);
try {
const r = await api<{ jobs: Job[]; warnings: string[] }>("/api/admin/updates", { method: "POST", body: { deploymentIds: chosen, version: form.version || undefined, at: fromInput(form.at), emergency: form.emergency, reason: form.reason || null, totp: form.totp || null } });
setMsg({ type: "ok", text: `Planned for ${r.jobs.length} install(s); each church was emailed and sees a banner.${r.warnings.length ? ` Note: ${r.warnings.join(" ")}` : ""}` });
setChosen([]);
load();
} catch (err) { setMsg({ type: "err", text: errorText(err) }); }
};
return (
<div className="space-y-6">
<div>
<PageTitle title="Updates" subtitle="Plan a release for one or more installs. Churches get an email and a banner now, and a reminder an hour before." />
<ServersNav active="/servers/updates" />
<Message msg={msg} />
</div>
{!deployments ? <Loading /> : (
<form className="card space-y-4" onSubmit={submit}>
<div className="flex flex-wrap items-center gap-2 text-sm">
<span className="text-slate-500">Select:</span>
<button type="button" className="btn-secondary px-2 py-1 text-xs" onClick={() => setChosen(deployments.map(d => d.id))}>All live ({deployments.length})</button>
{byVersion.map(v => <button key={v} type="button" className="btn-secondary px-2 py-1 text-xs" onClick={() => setChosen(deployments.filter(d => (d.install?.version || d.version || "?") === v).map(d => d.id))}>On {v}</button>)}
<button type="button" className="btn-secondary px-2 py-1 text-xs" onClick={() => setChosen([])}>None</button>
</div>
<div className="max-h-72 space-y-1 overflow-y-auto rounded-lg border border-slate-200 p-3">
{deployments.map(d => (
<label key={d.id} className="flex items-center gap-2 text-sm">
<input type="checkbox" checked={chosen.includes(d.id)} onChange={() => setChosen(chosen.includes(d.id) ? chosen.filter(x => x !== d.id) : [...chosen, d.id])} />
<span className="font-medium">{d.customer?.name}</span><span className="text-slate-500">{d.domain} · {d.install?.version || d.version || "?"} · {d.server?.name}</span>
</label>
))}
{!deployments.length && <p className="text-sm text-slate-500">No live installs on servers.</p>}
</div>
<div className="grid gap-3 md:grid-cols-2">
<div><label className="label" htmlFor="b-v">Release</label><input id="b-v" className="input" placeholder="latest" value={form.version} onChange={e => setForm({ ...form, version: e.target.value })} /></div>
<div><label className="label" htmlFor="b-at">When</label><input id="b-at" type="datetime-local" className="input" value={form.at} onChange={e => setForm({ ...form, at: e.target.value })} /><p className="mt-1 text-xs text-slate-500">At least {form.emergency ? "15 minutes" : "4 hours"} away. They run one at a time from then.</p></div>
<label className="flex items-center gap-2 text-sm md:col-span-2"><input type="checkbox" checked={form.emergency} onChange={e => setForm({ ...form, emergency: e.target.checked })} /> Emergency: 15 minutes&apos; notice, with a reason and your two-factor code</label>
{form.emergency && <>
<div><label className="label" htmlFor="b-r">Reason (shown to the churches)</label><input id="b-r" className="input" required value={form.reason} onChange={e => setForm({ ...form, reason: e.target.value })} /></div>
<div><label className="label" htmlFor="b-t">Two-factor code</label><input id="b-t" className="input" inputMode="numeric" autoComplete="one-time-code" required value={form.totp} onChange={e => setForm({ ...form, totp: e.target.value })} /></div>
</>}
</div>
<button className="btn-primary" disabled={!chosen.length}>Plan the update for {chosen.length} install(s)</button>
</form>
)}
<div className="card overflow-x-auto">
<h2 className="font-medium">Planned and running</h2>
<table className="mt-3 w-full text-sm">
<thead><tr className="text-left text-xs text-slate-500"><th className="py-1">Job</th><th>Install</th><th>When</th><th>Status</th></tr></thead>
<tbody>{upcoming.map(j => <tr key={j.id} className="border-t"><td className="py-1.5"><Link className="text-indigo-700 hover:underline" href={`/jobs/${j.id}`}>{j.type}</Link>{j.batchId && <span className="ml-1 text-xs text-slate-500">batch</span>}{j.emergency && <span className="ml-1 text-xs text-red-700">emergency</span>}</td><td>{j.deployment?.shortName || "–"}</td><td>{fmtDate(j.notBefore)}</td><td><StatusPill status={j.status} /></td></tr>)}</tbody>
</table>
{!upcoming.length && <p className="mt-2 text-sm text-slate-500">Nothing planned.</p>}
</div>
</div>
);
}