Fold four pages into the pages they belong to; add a Backups menu group
Dependencies become a view of the Map (graph with the editor under it), Sessions the 'Signed in now' tab of Users, the Audit Log the 'Raw audit log' tab of the Change log, and the Diagnostic Log the 'Call log' tab of Integrations (admins). Backup coverage and Proxmox Backup move to a new Backups group. Old addresses redirect; a shared ViewTabs component does the tabs. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
4e0c6927b2
commit
1432b148e9
19 files changed
+177
-102
No files matched your search
+12
-18
@@ -19,6 +19,7 @@ import { useAlertsReport } from "../hooks/useAlertsReport";
|
||||
import { summariseAlerts } from "../utils/alertSummary";
|
||||
import { EmptyRow } from "../components/EmptyState";
|
||||
import IncidentHistory, { incidentPath } from "../components/IncidentHistory";
|
||||
import ViewTabs from "../components/ViewTabs";
|
||||
|
||||
const SEVERITY: Record<AlertSeverity, { label: string; badge: string; rank: number }> = {
|
||||
critical: { label: "Critical", badge: "bg-red-lt text-red", rank: 0 },
|
||||
@@ -42,22 +43,15 @@ const CATEGORY_LABELS: Record<AlertCategory, string> = {
|
||||
type Row = AlertItem & { rank: number };
|
||||
|
||||
/** Now and History: what is wrong right now, and every time something was raised and went away. The same page, switched by `?view=history`. */
|
||||
function ViewTabs({ view }: { view: "now" | "history" }) {
|
||||
return (
|
||||
<ul className="nav nav-tabs mb-3" aria-label="Alerts view">
|
||||
<li className="nav-item">
|
||||
<Link to="/alerts" className={`nav-link ${view === "now" ? "active" : ""}`} aria-current={view === "now" ? "page" : undefined}>
|
||||
Now
|
||||
</Link>
|
||||
</li>
|
||||
<li className="nav-item">
|
||||
<Link to="/alerts?view=history" className={`nav-link ${view === "history" ? "active" : ""}`} aria-current={view === "history" ? "page" : undefined}>
|
||||
History
|
||||
</Link>
|
||||
</li>
|
||||
</ul>
|
||||
);
|
||||
}
|
||||
const alertTabs = (view: "now" | "history") => (
|
||||
<ViewTabs
|
||||
label="Alerts view"
|
||||
tabs={[
|
||||
{ to: "/alerts", label: "Now", active: view === "now" },
|
||||
{ to: "/alerts?view=history", label: "History", active: view === "history" },
|
||||
]}
|
||||
/>
|
||||
);
|
||||
|
||||
export default function Alerts({ user }: { user: CurrentUser }) {
|
||||
const [params] = useSearchParams();
|
||||
@@ -67,12 +61,12 @@ export default function Alerts({ user }: { user: CurrentUser }) {
|
||||
<div className="d-flex align-items-center mb-2">
|
||||
<h2 className="page-title mb-0">Alerts</h2>
|
||||
</div>
|
||||
<ViewTabs view="history" />
|
||||
{alertTabs("history")}
|
||||
<IncidentHistory />
|
||||
</>
|
||||
);
|
||||
}
|
||||
return <AlertsNow user={user} tabs={<ViewTabs view="now" />} />;
|
||||
return <AlertsNow user={user} tabs={alertTabs("now")} />;
|
||||
}
|
||||
|
||||
function AlertsNow({ user, tabs }: { user: CurrentUser; tabs: React.ReactNode }) {
|
||||
|
||||
@@ -1,121 +0,0 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { api, type AuditLogEntry } from "../api/client";
|
||||
import { formatDateTime, parseDbTimestamp } from "../utils/date";
|
||||
import { useSortable } from "../hooks/useSortable";
|
||||
import SortableTh from "../components/SortableTh";
|
||||
import { usePagination } from "../hooks/usePagination";
|
||||
import Pagination from "../components/Pagination";
|
||||
import { downloadCsv } from "../utils/csv";
|
||||
import { ErrorNotice } from "../components/Notice";
|
||||
import { SearchBox } from "../components/TableToolbar";
|
||||
import { useTableSearch } from "../hooks/useTableSearch";
|
||||
import { EmptyRow, LoadingRow } from "../components/EmptyState";
|
||||
|
||||
function targetLabel(e: AuditLogEntry): string {
|
||||
if (!e.targetType) return "—";
|
||||
let detail: Record<string, unknown> | null = null;
|
||||
if (e.detail) {
|
||||
try {
|
||||
detail = JSON.parse(e.detail);
|
||||
} catch {
|
||||
detail = null;
|
||||
}
|
||||
}
|
||||
const name = detail?.name ?? detail?.targetLabel ?? detail?.ipAddress;
|
||||
const typeLabel = e.targetType.replace(/_/g, " ");
|
||||
if (typeof name === "string" && name) return `${typeLabel} "${name}"`;
|
||||
return `${typeLabel}${e.targetId ? ` #${e.targetId}` : ""}`;
|
||||
}
|
||||
|
||||
/** What was done, beyond the target — the link's label and URL, a scan's address and range, and so on. The name is already in the Target column. */
|
||||
function detailSummary(e: AuditLogEntry): string {
|
||||
if (!e.detail) return "";
|
||||
let parsed: unknown;
|
||||
try {
|
||||
parsed = JSON.parse(e.detail);
|
||||
} catch {
|
||||
return e.detail;
|
||||
}
|
||||
if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) return String(parsed);
|
||||
return Object.entries(parsed as Record<string, unknown>)
|
||||
.filter(([key, value]) => key !== "name" && value !== null && value !== undefined && value !== "" && !(Array.isArray(value) && value.length === 0))
|
||||
.map(([key, value]) => `${key}: ${typeof value === "object" ? JSON.stringify(value) : String(value)}`)
|
||||
.join(" · ");
|
||||
}
|
||||
|
||||
export default function AuditLog() {
|
||||
const [entries, setEntries] = useState<AuditLogEntry[] | null>(null);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
api.auditLog
|
||||
.list()
|
||||
.then((res) => setEntries(res.entries))
|
||||
.catch((err) => setError(String(err)));
|
||||
}, []);
|
||||
|
||||
const tableSearch = useTableSearch(entries);
|
||||
const { sorted, sortKey, sortDir, requestSort } = useSortable(tableSearch.filtered, "createdAt", "desc", { url: true });
|
||||
const { pageItems, page, setPage, pageCount, totalCount } = usePagination(sorted);
|
||||
|
||||
function exportCsv() {
|
||||
if (!sorted) return;
|
||||
downloadCsv(
|
||||
"audit-log.csv",
|
||||
["When", "Actor", "Category", "Action", "Target", "Details"],
|
||||
sorted.map((e) => [formatDateTime(parseDbTimestamp(e.createdAt)), e.actorLabel ?? "", e.category, e.action, targetLabel(e), detailSummary(e)]),
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="d-flex align-items-center mb-3">
|
||||
<h2 className="page-title mb-0">Audit Log</h2>
|
||||
<button className="btn btn-outline-secondary ms-auto" onClick={exportCsv} disabled={!sorted || sorted.length === 0}>
|
||||
Export CSV
|
||||
</button>
|
||||
</div>
|
||||
<ErrorNotice error={error} />
|
||||
<div className="card">
|
||||
<div className="card-header">
|
||||
<SearchBox value={tableSearch.query} onChange={tableSearch.setQuery} />
|
||||
</div>
|
||||
<div className="table-responsive">
|
||||
<table className="table table-vcenter card-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<SortableTh<AuditLogEntry> label="When" sortKeyName="createdAt" activeKey={sortKey} direction={sortDir} onSort={requestSort} />
|
||||
<SortableTh<AuditLogEntry> label="Actor" sortKeyName="actorLabel" activeKey={sortKey} direction={sortDir} onSort={requestSort} />
|
||||
<SortableTh<AuditLogEntry> label="Category" sortKeyName="category" activeKey={sortKey} direction={sortDir} onSort={requestSort} />
|
||||
<SortableTh<AuditLogEntry> label="Action" sortKeyName="action" activeKey={sortKey} direction={sortDir} onSort={requestSort} />
|
||||
<SortableTh<AuditLogEntry> label="Target" sortKeyName="targetType" activeKey={sortKey} direction={sortDir} onSort={requestSort} />
|
||||
<th>Details</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{pageItems?.map((e) => (
|
||||
<tr key={e.id}>
|
||||
<td>{formatDateTime(parseDbTimestamp(e.createdAt))}</td>
|
||||
<td>{e.actorLabel ?? "—"}</td>
|
||||
<td>
|
||||
<span className="badge bg-blue-lt">{e.category}</span>
|
||||
</td>
|
||||
<td>{e.action}</td>
|
||||
<td>{targetLabel(e)}</td>
|
||||
<td className="text-secondary small text-break" style={{ maxWidth: 420 }}>
|
||||
{detailSummary(e) || "—"}
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
{entries === null && <LoadingRow colSpan={6} />}
|
||||
{sorted?.length === 0 && (
|
||||
<EmptyRow colSpan={6} title="Nothing recorded yet" hint="Changes people make in the app, sign-ins and the app's own housekeeping are written here as they happen." filtered={tableSearch.active ? () => tableSearch.setQuery("") : undefined} />
|
||||
)}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<Pagination page={page} pageCount={pageCount} totalCount={totalCount} onPageChange={setPage} />
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -1,7 +1,9 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { useEffect, useState, type ReactNode } from "react";
|
||||
import { Link, useSearchParams } from "react-router-dom";
|
||||
import { api, type ChangeEntry, type ChangeKind } from "../api/client";
|
||||
import { ErrorNotice } from "../components/Notice";
|
||||
import ViewTabs from "../components/ViewTabs";
|
||||
import AuditLogView from "../views/AuditLogView";
|
||||
import { BlockSkeleton } from "../components/Skeleton";
|
||||
import EmptyState from "../components/EmptyState";
|
||||
import { downloadCsv } from "../utils/csv";
|
||||
@@ -24,7 +26,33 @@ const PAGE = 100;
|
||||
* What has changed, in one list: agents updated, settings changed, maintenance started, dependencies edited, alerts raised and cleared — each as a
|
||||
* sentence, newest first, grouped by day. Narrow it to a kind of change, a server, a stretch of time or a word. The Audit Log is the raw table behind it.
|
||||
*/
|
||||
const changeTabs = (view: "changes" | "audit") => (
|
||||
<ViewTabs
|
||||
label="Change log view"
|
||||
tabs={[
|
||||
{ to: "/changes", label: "Readable", active: view === "changes" },
|
||||
{ to: "/changes?view=audit", label: "Raw audit log", active: view === "audit" },
|
||||
]}
|
||||
/>
|
||||
);
|
||||
|
||||
export default function ChangeLog() {
|
||||
const [params] = useSearchParams();
|
||||
if (params.get("view") === "audit") {
|
||||
return (
|
||||
<>
|
||||
<div className="d-flex align-items-center mb-2">
|
||||
<h2 className="page-title mb-0">Change log</h2>
|
||||
</div>
|
||||
{changeTabs("audit")}
|
||||
<AuditLogView />
|
||||
</>
|
||||
);
|
||||
}
|
||||
return <ReadableChanges tabs={changeTabs("changes")} />;
|
||||
}
|
||||
|
||||
function ReadableChanges({ tabs }: { tabs: ReactNode }) {
|
||||
const [params, setParams] = useSearchParams();
|
||||
const days = RANGES.some((r) => r.days === Number(params.get("days"))) ? Number(params.get("days")) : 7;
|
||||
const kind = params.get("kind") ?? "";
|
||||
@@ -121,8 +149,9 @@ export default function ChangeLog() {
|
||||
Export CSV
|
||||
</button>
|
||||
</div>
|
||||
{tabs}
|
||||
<p className="text-secondary">
|
||||
What changed and when: agents updated, settings changed, maintenance started and ended, dependencies edited, alerts raised and cleared. The <Link to="/audit-log">Audit Log</Link> is the raw table behind it.
|
||||
What changed and when: agents updated, settings changed, maintenance started and ended, dependencies edited, alerts raised and cleared. The raw table behind it is the other tab.
|
||||
</p>
|
||||
<ErrorNotice error={error} />
|
||||
|
||||
|
||||
@@ -1,196 +0,0 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { Link } from "react-router-dom";
|
||||
import { api, type CurrentUser, type DependenciesResponse, type DependencyNode } from "../api/client";
|
||||
import { ErrorNotice } from "../components/Notice";
|
||||
import { BlockSkeleton } from "../components/Skeleton";
|
||||
import { confirmDialog } from "../utils/dialogs";
|
||||
import { readableError } from "../utils/errors";
|
||||
import { toast } from "../utils/toast";
|
||||
import { EmptyRow } from "../components/EmptyState";
|
||||
|
||||
const TYPE_LABELS = { server: "Server", integration: "Integration" } as const;
|
||||
|
||||
const linkTo = (type: string, id: number) => (type === "server" ? `/servers/${id}` : "/integrations");
|
||||
|
||||
/** The options of a node picker, grouped by what they are. */
|
||||
function NodeSelect({ id, label, nodes, value, onChange }: { id: string; label: string; nodes: DependencyNode[]; value: string; onChange: (key: string) => void }) {
|
||||
return (
|
||||
<>
|
||||
<label className="form-label" htmlFor={id}>
|
||||
{label}
|
||||
</label>
|
||||
<select id={id} className="form-select" value={value} onChange={(e) => onChange(e.target.value)}>
|
||||
<option value="">— choose —</option>
|
||||
{(["server", "integration"] as const).map((type) => (
|
||||
<optgroup key={type} label={`${TYPE_LABELS[type]}s`}>
|
||||
{nodes
|
||||
.filter((n) => n.type === type)
|
||||
.map((n) => (
|
||||
<option key={n.key} value={n.key}>
|
||||
{n.name}
|
||||
</option>
|
||||
))}
|
||||
</optgroup>
|
||||
))}
|
||||
</select>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* What needs what. When something is down, whatever depends on it is down too, and only the one that matters should raise the alarm — so the
|
||||
* alerts of the things that need it are folded under it, like a guest under its host.
|
||||
*/
|
||||
export default function Dependencies({ user }: { user: CurrentUser }) {
|
||||
const canEdit = user.role === "admin" || user.role === "operator";
|
||||
const [data, setData] = useState<DependenciesResponse | null>(null);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [from, setFrom] = useState("");
|
||||
const [to, setTo] = useState("");
|
||||
const [busy, setBusy] = useState(false);
|
||||
|
||||
function load() {
|
||||
api.dependencies
|
||||
.list()
|
||||
.then(setData)
|
||||
.catch((err) => setError(readableError(err)));
|
||||
}
|
||||
useEffect(load, []);
|
||||
|
||||
const parse = (key: string) => {
|
||||
const [type, id] = key.split(":");
|
||||
return { type: type as "server" | "integration", id: Number(id) };
|
||||
};
|
||||
|
||||
async function add(e: React.FormEvent) {
|
||||
e.preventDefault();
|
||||
if (!from || !to) return;
|
||||
setBusy(true);
|
||||
setError(null);
|
||||
try {
|
||||
const f = parse(from);
|
||||
const t = parse(to);
|
||||
await api.dependencies.create({ fromType: f.type, fromId: f.id, toType: t.type, toId: t.id });
|
||||
toast.success("Saved.");
|
||||
setFrom("");
|
||||
setTo("");
|
||||
load();
|
||||
} catch (err) {
|
||||
setError(readableError(err));
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
}
|
||||
|
||||
async function remove(d: DependenciesResponse["dependencies"][number]) {
|
||||
if (!(await confirmDialog({ title: "Remove a dependency", message: `${d.from.name} no longer needs ${d.to.name}?`, confirmLabel: "Remove", danger: true }))) return;
|
||||
try {
|
||||
await api.dependencies.remove(d.id);
|
||||
load();
|
||||
} catch (err) {
|
||||
setError(readableError(err));
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="d-flex align-items-center mb-3">
|
||||
<h2 className="page-title mb-0">Dependencies</h2>
|
||||
</div>
|
||||
<p className="text-secondary">
|
||||
Say what needs what: Gitea needs the server it is installed on; a Proxmox guest needs the Proxmox it runs on. When the thing that is needed is down, what needs it is down too — and its alert is
|
||||
held back under the first one on the Alerts page instead of adding to the noise. A service that was down for its own reasons still alerts once what it needs is back.
|
||||
</p>
|
||||
<ErrorNotice error={error} />
|
||||
|
||||
{canEdit && (
|
||||
<form className="card mb-3" onSubmit={add}>
|
||||
<div className="card-header">
|
||||
<h3 className="card-title">Add a dependency</h3>
|
||||
</div>
|
||||
<div className="card-body row g-3 align-items-end">
|
||||
<div className="col-md-5">
|
||||
<NodeSelect id="dep-from" label="This…" nodes={data?.nodes ?? []} value={from} onChange={setFrom} />
|
||||
</div>
|
||||
<div className="col-md-5">
|
||||
<NodeSelect id="dep-to" label="…needs this" nodes={(data?.nodes ?? []).filter((n) => n.key !== from)} value={to} onChange={setTo} />
|
||||
</div>
|
||||
<div className="col-md-2">
|
||||
<button type="submit" className="btn btn-primary w-100" disabled={busy || !from || !to}>
|
||||
{busy ? "Saving…" : "Add"}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
)}
|
||||
|
||||
<div className="card mb-3">
|
||||
<div className="card-header">
|
||||
<h3 className="card-title">Written here</h3>
|
||||
</div>
|
||||
<div className="table-responsive">
|
||||
<table className="table table-vcenter card-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>This</th>
|
||||
<th>needs</th>
|
||||
{canEdit && <th className="w-1">Actions</th>}
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{data === null && !error && (
|
||||
<tr>
|
||||
<td colSpan={canEdit ? 3 : 2}>
|
||||
<BlockSkeleton lines={2} />
|
||||
</td>
|
||||
</tr>
|
||||
)}
|
||||
{data?.dependencies.map((d) => (
|
||||
<tr key={d.id}>
|
||||
<td>
|
||||
<Link to={linkTo(d.from.type, d.from.id)}>{d.from.name}</Link> <span className="text-secondary small">{TYPE_LABELS[d.from.type].toLowerCase()}</span>
|
||||
</td>
|
||||
<td>
|
||||
<Link to={linkTo(d.to.type, d.to.id)}>{d.to.name}</Link> <span className="text-secondary small">{TYPE_LABELS[d.to.type].toLowerCase()}</span>
|
||||
</td>
|
||||
{canEdit && (
|
||||
<td>
|
||||
<button className="btn btn-sm btn-outline-danger" onClick={() => void remove(d)}>
|
||||
Remove
|
||||
</button>
|
||||
</td>
|
||||
)}
|
||||
</tr>
|
||||
))}
|
||||
{data && data.dependencies.length === 0 && (
|
||||
<EmptyRow colSpan={canEdit ? 3 : 2} title="Nothing depends on anything yet" hint="Say what needs what — Gitea needs the server it is installed on — and when that one is down, the other's alert is held back under it instead of adding to the noise." />
|
||||
)}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{data && data.runsOn.length > 0 && (
|
||||
<div className="card">
|
||||
<div className="card-header">
|
||||
<h3 className="card-title">Servers that run on servers</h3>
|
||||
</div>
|
||||
<div className="card-body text-secondary small pb-0">These are set on each server (“runs on”), or worked out from the Proxmox node it is a guest of. They count here too.</div>
|
||||
<div className="table-responsive">
|
||||
<table className="table table-vcenter card-table">
|
||||
<tbody>
|
||||
{data.runsOn.map((r) => (
|
||||
<tr key={`${r.from.key}>${r.to.key}`}>
|
||||
<td>{r.from.name}</td>
|
||||
<td className="text-secondary">runs on</td>
|
||||
<td>{r.to.name}</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -1,213 +0,0 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { api, type DiagLogEntry } from "../api/client";
|
||||
import { formatDateTime, parseDbTimestamp } from "../utils/date";
|
||||
import { useSortable } from "../hooks/useSortable";
|
||||
import SortableTh from "../components/SortableTh";
|
||||
import { downloadCsv } from "../utils/csv";
|
||||
import { confirmDialog } from "../utils/dialogs";
|
||||
import { ErrorNotice } from "../components/Notice";
|
||||
import { EmptyRow, LoadingRow } from "../components/EmptyState";
|
||||
|
||||
const SOURCE_LABELS: Record<string, string> = {
|
||||
cloudflare: "Cloudflare",
|
||||
loopia: "Loopia",
|
||||
pihole: "Pi-hole",
|
||||
azure: "Azure DNS",
|
||||
cpanel: "cPanel",
|
||||
technitium: "Technitium",
|
||||
tailscale: "Tailscale",
|
||||
proxmox: "Proxmox",
|
||||
synology: "Synology",
|
||||
semaphore: "Semaphore",
|
||||
gitea: "Gitea",
|
||||
dockhand: "Dockhand",
|
||||
};
|
||||
|
||||
const PAGE_SIZE = 100;
|
||||
|
||||
export default function DiagLog() {
|
||||
const [entries, setEntries] = useState<DiagLogEntry[] | null>(null);
|
||||
const [total, setTotal] = useState(0);
|
||||
const [page, setPage] = useState(0);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [filterSource, setFilterSource] = useState("");
|
||||
const [filterOk, setFilterOk] = useState("");
|
||||
const [clearing, setClearing] = useState(false);
|
||||
|
||||
function load(pg: number) {
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
api.diagLog
|
||||
.list({
|
||||
source: filterSource || undefined,
|
||||
ok: filterOk === "" ? undefined : filterOk === "true",
|
||||
limit: PAGE_SIZE,
|
||||
offset: pg * PAGE_SIZE,
|
||||
})
|
||||
.then((res) => {
|
||||
setEntries(res.entries);
|
||||
setTotal(res.total);
|
||||
})
|
||||
.catch((err) => setError(err instanceof Error ? err.message : String(err)))
|
||||
.finally(() => setLoading(false));
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
setPage(0);
|
||||
load(0);
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [filterSource, filterOk]);
|
||||
|
||||
function goToPage(pg: number) {
|
||||
setPage(pg);
|
||||
load(pg);
|
||||
}
|
||||
|
||||
async function handleClear() {
|
||||
if (!(await confirmDialog({ title: "Clear diagnostic log", message: "Clear the entire diagnostic log? This cannot be undone.", confirmLabel: "Clear log", danger: true }))) return;
|
||||
setClearing(true);
|
||||
try {
|
||||
await api.diagLog.clear();
|
||||
setEntries([]);
|
||||
setTotal(0);
|
||||
} catch (err) {
|
||||
setError(err instanceof Error ? err.message : String(err));
|
||||
} finally {
|
||||
setClearing(false);
|
||||
}
|
||||
}
|
||||
|
||||
const { sorted, sortKey, sortDir, requestSort } = useSortable(entries, "createdAt", "desc");
|
||||
const totalPages = Math.ceil(total / PAGE_SIZE);
|
||||
const errorCount = entries?.filter((e) => !e.ok).length ?? 0;
|
||||
|
||||
function exportCsv() {
|
||||
if (!sorted) return;
|
||||
downloadCsv(
|
||||
"diagnostic-log.csv",
|
||||
["Time", "Source", "Operation", "OK", "Latency (ms)", "Error"],
|
||||
sorted.map((e) => [formatDateTime(parseDbTimestamp(e.createdAt)), e.source, e.operation, e.ok ? "yes" : "no", e.latencyMs, e.error ?? ""]),
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="d-flex align-items-center mb-3">
|
||||
<div>
|
||||
<h2 className="page-title mb-0">Diagnostic Log</h2>
|
||||
<div className="text-secondary small mt-1">
|
||||
Every call this app makes to a DNS provider or integration — the last 500 calls are kept. Use this to
|
||||
troubleshoot connectivity issues.
|
||||
</div>
|
||||
</div>
|
||||
<button className="btn btn-outline-danger ms-auto" onClick={handleClear} disabled={clearing || total === 0}>
|
||||
{clearing ? "Clearing…" : "Clear log"}
|
||||
</button>
|
||||
</div>
|
||||
<ErrorNotice error={error} />
|
||||
|
||||
<div className="card mb-3">
|
||||
<div className="card-body">
|
||||
<div className="row g-2 align-items-end">
|
||||
<div className="col-md-3">
|
||||
<label className="form-label">Source</label>
|
||||
<select className="form-select" value={filterSource} onChange={(e) => setFilterSource(e.target.value)}>
|
||||
<option value="">All sources</option>
|
||||
{Object.entries(SOURCE_LABELS).map(([value, label]) => (
|
||||
<option key={value} value={value}>
|
||||
{label}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
<div className="col-md-3">
|
||||
<label className="form-label">Result</label>
|
||||
<select className="form-select" value={filterOk} onChange={(e) => setFilterOk(e.target.value)}>
|
||||
<option value="">All results</option>
|
||||
<option value="false">Errors only</option>
|
||||
<option value="true">Success only</option>
|
||||
</select>
|
||||
</div>
|
||||
<div className="col-md-6 d-flex justify-content-end gap-2">
|
||||
<button className="btn btn-outline-secondary" onClick={() => load(page)} disabled={loading}>
|
||||
{loading ? "Refreshing…" : "Refresh"}
|
||||
</button>
|
||||
<button className="btn btn-outline-secondary" onClick={exportCsv} disabled={!sorted || sorted.length === 0}>
|
||||
Export CSV
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="card">
|
||||
<div className="card-header">
|
||||
<h3 className="card-title">
|
||||
{total} entries
|
||||
{errorCount > 0 && <span className="text-red fw-normal ms-2">{errorCount} errors on this page</span>}
|
||||
</h3>
|
||||
</div>
|
||||
<div className="table-responsive">
|
||||
<table className="table table-vcenter card-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<SortableTh<DiagLogEntry> label="Time" sortKeyName="createdAt" activeKey={sortKey} direction={sortDir} onSort={requestSort} />
|
||||
<SortableTh<DiagLogEntry> label="Source" sortKeyName="source" activeKey={sortKey} direction={sortDir} onSort={requestSort} />
|
||||
<SortableTh<DiagLogEntry> label="Operation" sortKeyName="operation" activeKey={sortKey} direction={sortDir} onSort={requestSort} />
|
||||
<SortableTh<DiagLogEntry> label="Result" sortKeyName="ok" activeKey={sortKey} direction={sortDir} onSort={requestSort} />
|
||||
<SortableTh<DiagLogEntry>
|
||||
label="Latency"
|
||||
sortKeyName="latencyMs"
|
||||
activeKey={sortKey}
|
||||
direction={sortDir}
|
||||
onSort={requestSort}
|
||||
/>
|
||||
<th>Error</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{sorted?.map((e) => (
|
||||
<tr key={e.id}>
|
||||
<td className="text-secondary" style={{ whiteSpace: "nowrap" }}>
|
||||
{formatDateTime(parseDbTimestamp(e.createdAt))}
|
||||
</td>
|
||||
<td>{SOURCE_LABELS[e.source] ?? e.source}</td>
|
||||
<td className="text-secondary">{e.operation}</td>
|
||||
<td>
|
||||
{e.ok ? (
|
||||
<span className="badge bg-green-lt text-green">OK</span>
|
||||
) : (
|
||||
<span className="badge bg-red-lt text-red">Error</span>
|
||||
)}
|
||||
</td>
|
||||
<td className={`text-secondary ${e.latencyMs > 2000 ? "text-yellow" : ""}`}>{e.latencyMs}ms</td>
|
||||
<td className="text-red small" title={e.error ?? ""} style={{ maxWidth: 320, overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" }}>
|
||||
{e.error ?? ""}
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
{entries === null && <LoadingRow colSpan={6} />}
|
||||
{sorted?.length === 0 && (
|
||||
<EmptyRow colSpan={6} {...(filterSource || filterOk ? { filtered: () => { setFilterSource(""); setFilterOk(""); } } : { title: "No diagnostic entries yet", hint: "Every call the app makes to an integration or a DNS provider is logged here, with how long it took and whether it worked." })} />
|
||||
)}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
{totalPages > 1 && (
|
||||
<div className="card-footer d-flex align-items-center justify-content-between">
|
||||
<button className="btn btn-outline-secondary" onClick={() => goToPage(page - 1)} disabled={page === 0}>
|
||||
← Prev
|
||||
</button>
|
||||
<span className="text-secondary">
|
||||
Page {page + 1} of {totalPages}
|
||||
</span>
|
||||
<button className="btn btn-outline-secondary" onClick={() => goToPage(page + 1)} disabled={page >= totalPages - 1}>
|
||||
Next →
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -1,7 +1,9 @@
|
||||
import { useEffect, useState, type CSSProperties } from "react";
|
||||
import { useEffect, useState, type CSSProperties, type ReactNode } from "react";
|
||||
import { Link, useSearchParams } from "react-router-dom";
|
||||
import { api, type CurrentUser, type IntegrationSummary, type IntegrationType } from "../api/client";
|
||||
import IntegrationForm from "../components/IntegrationForm";
|
||||
import ViewTabs from "../components/ViewTabs";
|
||||
import DiagLogView from "../views/DiagLogView";
|
||||
import IntegrationEditForm from "../components/IntegrationEditForm";
|
||||
import TableToolbar from "../components/TableToolbar";
|
||||
import { useTableSearch } from "../hooks/useTableSearch";
|
||||
@@ -73,7 +75,35 @@ function typeBadgeStyle(colors: Record<string, string>, type: IntegrationType):
|
||||
return { backgroundColor: `${color}22`, color, border: `1px solid ${color}55` };
|
||||
}
|
||||
|
||||
const integrationTabs = (view: "list" | "calls") => (
|
||||
<ViewTabs
|
||||
label="Integrations view"
|
||||
tabs={[
|
||||
{ to: "/integrations", label: "Integrations", active: view === "list" },
|
||||
{ to: "/integrations?view=calls", label: "Call log", active: view === "calls" },
|
||||
]}
|
||||
/>
|
||||
);
|
||||
|
||||
/** The integrations, and — for administrators — the log of every call made to them (`?view=calls`), where a connection is troubleshot. */
|
||||
export default function Integrations({ user }: { user: CurrentUser }) {
|
||||
const [params] = useSearchParams();
|
||||
const isAdmin = user.role === "admin";
|
||||
if (isAdmin && params.get("view") === "calls") {
|
||||
return (
|
||||
<>
|
||||
<div className="d-flex align-items-center mb-2">
|
||||
<h2 className="page-title mb-0">Integrations</h2>
|
||||
</div>
|
||||
{integrationTabs("calls")}
|
||||
<DiagLogView />
|
||||
</>
|
||||
);
|
||||
}
|
||||
return <IntegrationsList user={user} tabs={isAdmin ? integrationTabs("list") : null} />;
|
||||
}
|
||||
|
||||
function IntegrationsList({ user, tabs }: { user: CurrentUser; tabs: ReactNode }) {
|
||||
const isAdmin = user.role === "admin";
|
||||
const isOperator = user.role === "admin" || user.role === "operator";
|
||||
const [searchParams, setSearchParams] = useSearchParams();
|
||||
@@ -171,6 +201,7 @@ export default function Integrations({ user }: { user: CurrentUser }) {
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
{tabs}
|
||||
<ErrorNotice error={error} />
|
||||
|
||||
{editingIntegration ? (
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import { useEffect, useMemo, useState } from "react";
|
||||
import { Link, useSearchParams } from "react-router-dom";
|
||||
import DependencyMap from "../components/DependencyMap";
|
||||
import DependencyEditor from "../views/DependencyEditor";
|
||||
import type { CurrentUser } from "../api/client";
|
||||
import { api, type MapData, type MapNode } from "../api/client";
|
||||
import { ErrorNotice } from "../components/Notice";
|
||||
import { PageSkeleton } from "../components/Skeleton";
|
||||
@@ -75,7 +77,7 @@ function layout(data: MapData): { placed: Map<string, Placed>; width: number; he
|
||||
}
|
||||
|
||||
/** The picture: how the servers, their Proxmox hosts, DNS names and monitors connect. Hover or tab to a box to light up its connections. */
|
||||
export default function MapPage() {
|
||||
export default function MapPage({ user }: { user: CurrentUser }) {
|
||||
const [params, setParams] = useSearchParams();
|
||||
const view = params.get("view") === "dependencies" ? "dependencies" : "connections";
|
||||
const choose = (v: "connections" | "dependencies") =>
|
||||
@@ -107,10 +109,11 @@ export default function MapPage() {
|
||||
) : (
|
||||
<>
|
||||
<p className="text-secondary">
|
||||
What needs what: a server that runs on another, a service that needs the server it is installed on. Pick a box to see what would go down with it before you reboot it.{" "}
|
||||
<Link to="/dependencies">Edit dependencies</Link>
|
||||
A server that runs on another, a service that needs the server it is installed on. Pick a box to see what would go down with it before you reboot it.
|
||||
</p>
|
||||
<DependencyMap />
|
||||
<h3 className="mt-4 mb-2">Say what needs what</h3>
|
||||
<DependencyEditor user={user} />
|
||||
</>
|
||||
)}
|
||||
</>
|
||||
|
||||
@@ -334,7 +334,7 @@ export default function Privacy() {
|
||||
<div className="card-body">
|
||||
<ul className="mb-0">
|
||||
<li className="mb-2">
|
||||
<strong>Sign out</strong> to end your session now. Administrators can also end anyone's on the <Link to="/sessions">Sessions</Link> page.
|
||||
<strong>Sign out</strong> to end your session now. Administrators can also end anyone's on the <Link to="/users?view=sessions">Users → Signed in now</Link> page.
|
||||
</li>
|
||||
<li className="mb-2">
|
||||
<strong>Audit and diagnostic logs</strong> can be deleted automatically after a set number of days under Settings → Logs
|
||||
|
||||
@@ -1,176 +0,0 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import TimeAgo from "../components/TimeAgo";
|
||||
import { api, type SessionSummary } from "../api/client";
|
||||
import { formatDateTime } from "../utils/date";
|
||||
import { useSortable } from "../hooks/useSortable";
|
||||
import SortableTh from "../components/SortableTh";
|
||||
import { downloadCsv } from "../utils/csv";
|
||||
import { confirmDialog } from "../utils/dialogs";
|
||||
import { ErrorNotice } from "../components/Notice";
|
||||
import { SearchBox } from "../components/TableToolbar";
|
||||
import { useTableSearch } from "../hooks/useTableSearch";
|
||||
import { EmptyRow, LoadingRow } from "../components/EmptyState";
|
||||
|
||||
function friendlyUserAgent(ua: string | null): string {
|
||||
if (!ua) return "—";
|
||||
const os = /Windows/.test(ua)
|
||||
? "Windows"
|
||||
: /Mac OS X/.test(ua)
|
||||
? "macOS"
|
||||
: /Android/.test(ua)
|
||||
? "Android"
|
||||
: /iPhone|iPad/.test(ua)
|
||||
? "iOS"
|
||||
: /Linux/.test(ua)
|
||||
? "Linux"
|
||||
: "unknown OS";
|
||||
const browser = /Edg\//.test(ua)
|
||||
? "Edge"
|
||||
: /Chrome\//.test(ua)
|
||||
? "Chrome"
|
||||
: /Firefox\//.test(ua)
|
||||
? "Firefox"
|
||||
: /Safari\//.test(ua)
|
||||
? "Safari"
|
||||
: "unknown browser";
|
||||
return `${browser} on ${os}`;
|
||||
}
|
||||
|
||||
export default function Sessions() {
|
||||
const [sessions, setSessions] = useState<SessionSummary[] | null>(null);
|
||||
const [currentSessionId, setCurrentSessionId] = useState<string | null>(null);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [revokingId, setRevokingId] = useState<string | null>(null);
|
||||
|
||||
function load() {
|
||||
api.sessions
|
||||
.list()
|
||||
.then((res) => {
|
||||
setSessions(res.sessions);
|
||||
setCurrentSessionId(res.currentSessionId);
|
||||
})
|
||||
.catch((err) => setError(String(err)));
|
||||
}
|
||||
|
||||
useEffect(load, []);
|
||||
|
||||
async function revoke(s: SessionSummary) {
|
||||
const isSelf = s.id === currentSessionId;
|
||||
const label = s.name ?? s.email ?? s.sub;
|
||||
const confirmMsg = isSelf
|
||||
? `This is your current session — revoking it will sign you out immediately. Continue?`
|
||||
: `Revoke ${label}'s session? They'll be signed out immediately.`;
|
||||
if (!(await confirmDialog({ title: isSelf ? "Sign out of this session" : "End session", message: confirmMsg, confirmLabel: isSelf ? "Sign me out" : "Revoke session", danger: true }))) return;
|
||||
setError(null);
|
||||
setRevokingId(s.id);
|
||||
try {
|
||||
await api.sessions.revoke(s.id);
|
||||
if (isSelf) {
|
||||
window.location.href = "/";
|
||||
return;
|
||||
}
|
||||
load();
|
||||
} catch (err) {
|
||||
setError(err instanceof Error ? err.message : String(err));
|
||||
} finally {
|
||||
setRevokingId(null);
|
||||
}
|
||||
}
|
||||
|
||||
const tableSearch = useTableSearch(sessions);
|
||||
const { sorted, sortKey, sortDir, requestSort } = useSortable(tableSearch.filtered, undefined, "asc", { url: true });
|
||||
|
||||
function exportCsv() {
|
||||
if (!sorted) return;
|
||||
downloadCsv(
|
||||
"sessions.csv",
|
||||
["Name", "Email", "Role", "IP", "Device", "Last active", "Expires"],
|
||||
sorted.map((s) => [
|
||||
s.name ?? "",
|
||||
s.email ?? "",
|
||||
s.role ?? "",
|
||||
s.ip ?? "",
|
||||
friendlyUserAgent(s.userAgent),
|
||||
formatDateTime(new Date(s.lastAccess)),
|
||||
s.expiresAt ? formatDateTime(new Date(s.expiresAt)) : "",
|
||||
]),
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="d-flex align-items-center mb-3">
|
||||
<div>
|
||||
<h2 className="page-title mb-0">Sessions</h2>
|
||||
<div className="text-secondary small mt-1">Everyone currently signed in, across every device.</div>
|
||||
</div>
|
||||
<button className="btn btn-outline-secondary ms-auto" onClick={exportCsv} disabled={!sorted || sorted.length === 0}>
|
||||
Export CSV
|
||||
</button>
|
||||
</div>
|
||||
<ErrorNotice error={error} />
|
||||
<div className="card">
|
||||
<div className="card-header">
|
||||
<SearchBox value={tableSearch.query} onChange={tableSearch.setQuery} />
|
||||
</div>
|
||||
<div className="table-responsive">
|
||||
<table className="table table-vcenter card-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<SortableTh<SessionSummary> label="Name" sortKeyName="name" activeKey={sortKey} direction={sortDir} onSort={requestSort} />
|
||||
<SortableTh<SessionSummary> label="Email" sortKeyName="email" activeKey={sortKey} direction={sortDir} onSort={requestSort} />
|
||||
<SortableTh<SessionSummary> label="Role" sortKeyName="role" activeKey={sortKey} direction={sortDir} onSort={requestSort} />
|
||||
<SortableTh<SessionSummary> label="IP" sortKeyName="ip" activeKey={sortKey} direction={sortDir} onSort={requestSort} />
|
||||
<th>Device</th>
|
||||
<SortableTh<SessionSummary>
|
||||
label="Last active"
|
||||
sortKeyName="lastAccess"
|
||||
activeKey={sortKey}
|
||||
direction={sortDir}
|
||||
onSort={requestSort}
|
||||
/>
|
||||
<SortableTh<SessionSummary>
|
||||
label="Expires"
|
||||
sortKeyName="expiresAt"
|
||||
activeKey={sortKey}
|
||||
direction={sortDir}
|
||||
onSort={requestSort}
|
||||
/>
|
||||
<th className="w-1">Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{sorted?.map((s) => (
|
||||
<tr key={s.id}>
|
||||
<td>
|
||||
{s.name ?? "—"}
|
||||
{s.id === currentSessionId && <span className="badge bg-blue-lt text-blue ms-2">This device</span>}
|
||||
</td>
|
||||
<td>{s.email ?? "—"}</td>
|
||||
<td>{s.role ?? <span className="text-secondary">unknown user</span>}</td>
|
||||
<td>{s.ip ?? "—"}</td>
|
||||
<td className="text-secondary">{friendlyUserAgent(s.userAgent)}</td>
|
||||
<td><TimeAgo value={s.lastAccess} /></td>
|
||||
<td>{s.expiresAt ? formatDateTime(new Date(s.expiresAt)) : "—"}</td>
|
||||
<td>
|
||||
<button
|
||||
className="btn btn-sm btn-outline-danger"
|
||||
onClick={() => revoke(s)}
|
||||
disabled={revokingId === s.id}
|
||||
>
|
||||
{revokingId === s.id ? "Revoking…" : "Revoke"}
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
{sessions === null && <LoadingRow colSpan={8} />}
|
||||
{sorted?.length === 0 && (
|
||||
<EmptyRow colSpan={8} title="No active sessions" hint="Everyone who is signed in appears here, with where from and until when." filtered={tableSearch.active ? () => tableSearch.setQuery("") : undefined} />
|
||||
)}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
+32
-2
@@ -1,5 +1,7 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { Link } from "react-router-dom";
|
||||
import { useEffect, useState, type ReactNode } from "react";
|
||||
import { Link, useSearchParams } from "react-router-dom";
|
||||
import ViewTabs from "../components/ViewTabs";
|
||||
import SessionsView from "../views/SessionsView";
|
||||
import { api, type UserRecord, type UserRole } from "../api/client";
|
||||
import { formatDateTime } from "../utils/date";
|
||||
import { useSortable } from "../hooks/useSortable";
|
||||
@@ -13,7 +15,34 @@ import Avatar from "../components/Avatar";
|
||||
|
||||
const ROLES: UserRole[] = ["viewer", "operator", "admin"];
|
||||
|
||||
/** People and Signed in now: who has an account and what they may do, and who is signed in at this moment. Switched by `?view=sessions`. */
|
||||
const userTabs = (view: "people" | "sessions") => (
|
||||
<ViewTabs
|
||||
label="Users view"
|
||||
tabs={[
|
||||
{ to: "/users", label: "People", active: view === "people" },
|
||||
{ to: "/users?view=sessions", label: "Signed in now", active: view === "sessions" },
|
||||
]}
|
||||
/>
|
||||
);
|
||||
|
||||
export default function Users() {
|
||||
const [params] = useSearchParams();
|
||||
if (params.get("view") === "sessions") {
|
||||
return (
|
||||
<>
|
||||
<div className="d-flex align-items-center mb-2">
|
||||
<h2 className="page-title mb-0">Users</h2>
|
||||
</div>
|
||||
{userTabs("sessions")}
|
||||
<SessionsView />
|
||||
</>
|
||||
);
|
||||
}
|
||||
return <People tabs={userTabs("people")} />;
|
||||
}
|
||||
|
||||
function People({ tabs }: { tabs: ReactNode }) {
|
||||
const [users, setUsers] = useState<UserRecord[] | null>(null);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [savingId, setSavingId] = useState<number | null>(null);
|
||||
@@ -65,6 +94,7 @@ export default function Users() {
|
||||
Export CSV
|
||||
</button>
|
||||
</div>
|
||||
{tabs}
|
||||
<ErrorNotice error={error} />
|
||||
{followGroups && (
|
||||
<div className="alert alert-info">
|
||||
|
||||
Reference in new issue
Block a user