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
@@ -0,0 +1,122 @@
|
||||
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(" · ");
|
||||
}
|
||||
|
||||
/** The raw audit table — the "Raw audit log" side of the Change log page. */
|
||||
export default function AuditLogView() {
|
||||
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">
|
||||
<div className="text-secondary">The table behind the change log: every change made in the app, every sign-in and sign-out, with who did it and from where.</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<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>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,193 @@
|
||||
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 DependencyEditor({ 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 (
|
||||
<>
|
||||
<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>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,210 @@
|
||||
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;
|
||||
|
||||
/** Every call made to an integration or DNS provider — the "Call log" side of the Integrations page. */
|
||||
export default function DiagLogView() {
|
||||
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 className="text-secondary">
|
||||
Every call this app makes to a DNS provider or integration — the last 500 calls are kept. Use this to troubleshoot connectivity issues.
|
||||
</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>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,174 @@
|
||||
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}`;
|
||||
}
|
||||
|
||||
/** Everyone who is signed in right now, on every device — the "Signed in now" side of the Users page. */
|
||||
export default function SessionsView() {
|
||||
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 className="text-secondary">Everyone currently signed in, across every device. Ending a session signs that device out at once.</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>
|
||||
</>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user