UniFi: servers plugged into switches; server page in sections; My work; settings search and undo
UniFi: the controller's client list is matched to servers by IP address, so a server is connected through a switch or access point (and port). That is a dependency made by itself, shown on the server page, the Network devices page and the Connections map. IP Addresses can sync the devices' addresses. A server's page is split into Overview, Health, Network, History, Tasks and Settings, by ?view=; alerts link to the section they are about. My work lists what has your name on it: alerts you have, maintenance you started (extend, end with undo) and update runs you started, with a badge. Settings has a search box (and the command palette lists every setting). Removing a dependency, admin link, runbook, hand-made IP address, port opening or restore test is undone from the message instead of asked about first. Two backup tests used a fixed date and failed as days passed; they follow the real clock now. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
396e074108
commit
5e26e77340
45 files changed
+6224
-194
No files matched your search
+45
-11
@@ -1,3 +1,5 @@
|
||||
import { toast } from "../utils/toast";
|
||||
import { removeWithUndo } from "../utils/undoable";
|
||||
import { useEffect, useMemo, useState } from "react";
|
||||
import { useSearchParams } from "react-router-dom";
|
||||
import { api, type CurrentUser, type IpamEntry, type IpamInput } from "../api/client";
|
||||
@@ -33,7 +35,7 @@ export default function Ipam({ user }: { user: CurrentUser }) {
|
||||
const [adding, setAdding] = useState(false);
|
||||
const [form, setForm] = useState<IpamInput>(emptyForm);
|
||||
const [saving, setSaving] = useState(false);
|
||||
const [syncing, setSyncing] = useState<"tailscale" | "proxmox" | "phpipam" | null>(null);
|
||||
const [syncing, setSyncing] = useState<"tailscale" | "proxmox" | "phpipam" | "unifi" | null>(null);
|
||||
const [syncResult, setSyncResult] = useState<string | null>(null);
|
||||
const selection = useSelection<number>();
|
||||
const [bulkDeleting, setBulkDeleting] = useState(false);
|
||||
@@ -146,47 +148,76 @@ export default function Ipam({ user }: { user: CurrentUser }) {
|
||||
}
|
||||
}
|
||||
|
||||
/** What is needed to make an entry again; one that a sync made would come back as a hand-made one, so those are still asked about. */
|
||||
const asInput = (e: IpamEntry): IpamInput => ({ ipAddress: e.ipAddress, label: e.label ?? undefined, vendor: e.vendor ?? undefined, location: e.location ?? undefined, notes: e.notes ?? undefined });
|
||||
|
||||
async function remove(entry: IpamEntry) {
|
||||
if (!(await confirmDialog({ title: "Delete IP address", message: `Delete IP address "${entry.ipAddress}"?`, confirmLabel: "Delete", danger: true }))) return;
|
||||
setError(null);
|
||||
try {
|
||||
await api.ipam.remove(entry.id);
|
||||
load();
|
||||
} catch (err) {
|
||||
setError(err instanceof Error ? err.message : String(err));
|
||||
if (entry.source) {
|
||||
if (!(await confirmDialog({ title: "Delete IP address", message: `Delete IP address "${entry.ipAddress}"? A sync can bring it back.`, confirmLabel: "Delete", danger: true }))) return;
|
||||
try {
|
||||
await api.ipam.remove(entry.id);
|
||||
load();
|
||||
} catch (err) {
|
||||
setError(err instanceof Error ? err.message : String(err));
|
||||
}
|
||||
return;
|
||||
}
|
||||
await removeWithUndo({
|
||||
remove: () => api.ipam.remove(entry.id),
|
||||
restore: () => api.ipam.create(asInput(entry)),
|
||||
message: `Deleted ${entry.ipAddress}.`,
|
||||
reload: load,
|
||||
onError: setError,
|
||||
});
|
||||
}
|
||||
|
||||
async function bulkDelete() {
|
||||
const ids = Array.from(selection.selected);
|
||||
if (ids.length === 0) return;
|
||||
if (!(await confirmDialog({ title: "Delete IP addresses", message: `Delete ${ids.length} IP address${ids.length !== 1 ? "es" : ""}?`, confirmLabel: "Delete", danger: true }))) return;
|
||||
const picked = (entries ?? []).filter((e) => ids.includes(e.id));
|
||||
const plain = picked.length === ids.length && picked.every((e) => !e.source);
|
||||
if (!plain && !(await confirmDialog({ title: "Delete IP addresses", message: `Delete ${ids.length} IP address${ids.length !== 1 ? "es" : ""}? Those a sync made can be brought back by it.`, confirmLabel: "Delete", danger: true }))) return;
|
||||
setError(null);
|
||||
setBulkDeleting(true);
|
||||
try {
|
||||
const results = await Promise.allSettled(ids.map((id) => api.ipam.remove(id)));
|
||||
const failed = results.filter((r) => r.status === "rejected").length;
|
||||
if (failed > 0) setError(`${failed} of ${ids.length} deletions failed.`);
|
||||
const gone = picked.filter((_, i) => results[ids.indexOf(picked[i].id)]?.status === "fulfilled");
|
||||
selection.clear();
|
||||
load();
|
||||
if (plain && gone.length > 0) {
|
||||
toast.success(`Deleted ${gone.length} IP address${gone.length !== 1 ? "es" : ""}.`, {
|
||||
label: "Undo",
|
||||
onClick: async () => {
|
||||
const back = await Promise.allSettled(gone.map((e) => api.ipam.create(asInput(e))));
|
||||
const lost = back.filter((r) => r.status === "rejected").length;
|
||||
if (lost > 0) toast.error(`${lost} could not be put back.`);
|
||||
else toast.info("Put back.");
|
||||
load();
|
||||
},
|
||||
});
|
||||
}
|
||||
} finally {
|
||||
setBulkDeleting(false);
|
||||
}
|
||||
}
|
||||
|
||||
const SYNC_LABELS: Record<"tailscale" | "proxmox" | "phpipam", string> = {
|
||||
const SYNC_LABELS: Record<"tailscale" | "proxmox" | "phpipam" | "unifi", string> = {
|
||||
tailscale: "Tailscale",
|
||||
proxmox: "Proxmox",
|
||||
phpipam: "phpIPAM",
|
||||
unifi: "UniFi",
|
||||
};
|
||||
|
||||
async function runSync(source: "tailscale" | "proxmox" | "phpipam") {
|
||||
async function runSync(source: "tailscale" | "proxmox" | "phpipam" | "unifi") {
|
||||
setError(null);
|
||||
setSyncResult(null);
|
||||
setSyncing(source);
|
||||
try {
|
||||
const res =
|
||||
source === "tailscale" ? await api.ipam.syncTailscale() : source === "proxmox" ? await api.ipam.syncProxmox() : await api.ipam.syncPhpIpam();
|
||||
source === "tailscale" ? await api.ipam.syncTailscale() : source === "proxmox" ? await api.ipam.syncProxmox() : source === "unifi" ? await api.ipam.syncUnifi() : await api.ipam.syncPhpIpam();
|
||||
const parts = [`${res.added} added`, `${res.updated} updated`];
|
||||
if (res.skipped > 0) parts.push(`${res.skipped} skipped (already tracked manually)`);
|
||||
setSyncResult(`${SYNC_LABELS[source]}: ${parts.join(", ")}`);
|
||||
@@ -378,6 +409,9 @@ export default function Ipam({ user }: { user: CurrentUser }) {
|
||||
<button className="btn btn-sm btn-outline-secondary" onClick={() => runSync("phpipam")} disabled={!!syncing}>
|
||||
{syncing === "phpipam" ? "Syncing…" : "Sync from phpIPAM"}
|
||||
</button>
|
||||
<button className="btn btn-sm btn-outline-secondary" onClick={() => runSync("unifi")} disabled={!!syncing}>
|
||||
{syncing === "unifi" ? "Syncing…" : "Sync from UniFi"}
|
||||
</button>
|
||||
</>
|
||||
)}
|
||||
</>
|
||||
|
||||
Reference in new issue
Block a user