Share the excluded-ranges filter with IP Addresses; add Admin Links page
IP Addresses (IPAM) now reads the same excluded-ranges setting the Consistency page manages, so "not interesting" addresses - a Docker bridge network repeating on every host, say - can be hidden there too. Adds a "Hide excluded addresses" toggle (on by default, with a live count), an inline ranges editor matching Consistency's, an "excluded" badge on rows shown anyway, and a per-row "Exclude..." shortcut that suggests a /24 (or /64 for IPv6) around that address. Editing ranges from either page updates both, since it's one shared setting. Also adds Operations > Admin Links: a single page summarizing every admin bookmark added across all servers (Dockge, Webmin, Cockpit, etc, previously only visible per-server on each server's own detail page), sortable and searchable, with the same add/edit/delete capability - adding one here just asks which server it belongs to. Verified both with real HTTP-level tests: a genuine Express app, a scratch SQLite DB, and forged sessions, covering the exclusion matching, the shared-setting round trip, the links aggregation and join, and role enforcement - the real dev DB was confirmed untouched throughout. Both packages build clean. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
236b1da0dc
commit
1ff1c6550c
9 files changed
+435
-9
No files matched your search
+114
-4
@@ -17,6 +17,11 @@ function isIpv6(ip: string) {
|
||||
export default function Ipam({ user }: { user: CurrentUser }) {
|
||||
const canEdit = user.role === "admin" || user.role === "operator";
|
||||
const [entries, setEntries] = useState<IpamEntry[] | null>(null);
|
||||
const [excludedRanges, setExcludedRanges] = useState<string[]>([]);
|
||||
const [hideExcluded, setHideExcluded] = useState(true);
|
||||
const [showRanges, setShowRanges] = useState(false);
|
||||
const [newRange, setNewRange] = useState("");
|
||||
const [savingRanges, setSavingRanges] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [searchParams] = useSearchParams();
|
||||
const [search, setSearch] = useState(() => searchParams.get("q") ?? "");
|
||||
@@ -34,6 +39,7 @@ export default function Ipam({ user }: { user: CurrentUser }) {
|
||||
.list()
|
||||
.then((res) => {
|
||||
setEntries(res.entries);
|
||||
setExcludedRanges(res.excludedRanges);
|
||||
// Deep-link from global search (?editId=) — jump straight to that entry's edit form.
|
||||
const editId = Number(searchParams.get("editId"));
|
||||
const target = res.entries.find((e) => e.id === editId);
|
||||
@@ -44,14 +50,49 @@ export default function Ipam({ user }: { user: CurrentUser }) {
|
||||
|
||||
useEffect(load, []);
|
||||
|
||||
/** Saves the whole list (the server validates and normalises it) and reloads — shared with the Consistency page. */
|
||||
async function saveRanges(ranges: string[]): Promise<boolean> {
|
||||
setSavingRanges(true);
|
||||
setError(null);
|
||||
try {
|
||||
await api.consistency.setExcludedRanges(ranges);
|
||||
load();
|
||||
return true;
|
||||
} catch (err) {
|
||||
setError(err instanceof Error ? err.message : String(err));
|
||||
return false;
|
||||
} finally {
|
||||
setSavingRanges(false);
|
||||
}
|
||||
}
|
||||
|
||||
async function addRange(e: React.FormEvent) {
|
||||
e.preventDefault();
|
||||
if (!newRange.trim()) return;
|
||||
if (await saveRanges([...excludedRanges, newRange.trim()])) setNewRange("");
|
||||
}
|
||||
|
||||
async function excludeAround(entry: IpamEntry) {
|
||||
const suggestion = isIpv6(entry.ipAddress) ? `${entry.ipAddress}/64` : `${entry.ipAddress.split(".").slice(0, 3).join(".")}.0/24`;
|
||||
const range = window.prompt(
|
||||
`Hide this range from IP Addresses and the Consistency report — every address in it, not just this one:`,
|
||||
suggestion,
|
||||
);
|
||||
if (range === null || !range.trim()) return;
|
||||
await saveRanges([...excludedRanges, range.trim()]);
|
||||
}
|
||||
|
||||
const excludedCount = useMemo(() => entries?.filter((e) => e.excluded).length ?? 0, [entries]);
|
||||
|
||||
const filtered = useMemo(() => {
|
||||
if (!entries) return [];
|
||||
const base = hideExcluded ? entries.filter((e) => !e.excluded) : entries;
|
||||
const q = search.trim().toLowerCase();
|
||||
if (!q) return entries;
|
||||
return entries.filter((e) =>
|
||||
if (!q) return base;
|
||||
return base.filter((e) =>
|
||||
[e.ipAddress, e.label, e.vendor, e.location].some((v) => (v ?? "").toLowerCase().includes(q)),
|
||||
);
|
||||
}, [entries, search]);
|
||||
}, [entries, hideExcluded, search]);
|
||||
|
||||
function startAdd() {
|
||||
setAdding(true);
|
||||
@@ -176,6 +217,67 @@ export default function Ipam({ user }: { user: CurrentUser }) {
|
||||
{error && <div className="alert alert-danger">{error}</div>}
|
||||
{syncResult && <div className="alert alert-success">Synced from {syncResult}</div>}
|
||||
|
||||
<div className="card mb-3">
|
||||
<div className="card-body">
|
||||
<div className="d-flex flex-wrap align-items-center gap-2">
|
||||
<label className="form-check mb-0">
|
||||
<input
|
||||
type="checkbox"
|
||||
className="form-check-input"
|
||||
checked={hideExcluded}
|
||||
onChange={(e) => setHideExcluded(e.target.checked)}
|
||||
/>
|
||||
<span className="form-check-label">
|
||||
Hide excluded addresses{excludedCount > 0 && ` (${excludedCount})`}
|
||||
</span>
|
||||
</label>
|
||||
<button type="button" className="btn btn-link btn-sm p-0 ms-2" onClick={() => setShowRanges((s) => !s)}>
|
||||
{showRanges ? "Hide" : "Manage"} excluded ranges
|
||||
</button>
|
||||
</div>
|
||||
{showRanges && (
|
||||
<div className="mt-2">
|
||||
<div className="text-secondary small mb-2">
|
||||
Addresses in these ranges are left out here and on the Consistency report — the same setting either
|
||||
page manages. Meant for networks that aren't part of your LAN, like Docker's, which repeat the same
|
||||
subnet on many hosts.
|
||||
</div>
|
||||
<div className="d-flex flex-wrap gap-1 mb-2">
|
||||
{excludedRanges.length === 0 && <span className="text-secondary small">Nothing excluded.</span>}
|
||||
{excludedRanges.map((r) => (
|
||||
<span key={r} className="badge bg-secondary-lt text-secondary d-inline-flex align-items-center">
|
||||
<code className="bg-transparent p-0">{r}</code>
|
||||
{canEdit && (
|
||||
<button
|
||||
type="button"
|
||||
className="btn-close ms-1"
|
||||
style={{ fontSize: "0.5rem" }}
|
||||
aria-label={`Stop excluding ${r}`}
|
||||
disabled={savingRanges}
|
||||
onClick={() => void saveRanges(excludedRanges.filter((x) => x !== r))}
|
||||
/>
|
||||
)}
|
||||
</span>
|
||||
))}
|
||||
</div>
|
||||
{canEdit && (
|
||||
<form onSubmit={addRange} className="d-flex gap-2" style={{ maxWidth: 460 }}>
|
||||
<input
|
||||
className="form-control form-control-sm"
|
||||
placeholder="e.g. 172.17.0.0/16 or 10.1.2.3"
|
||||
value={newRange}
|
||||
onChange={(e) => setNewRange(e.target.value)}
|
||||
/>
|
||||
<button type="submit" className="btn btn-sm btn-primary" disabled={savingRanges || !newRange.trim()}>
|
||||
Exclude
|
||||
</button>
|
||||
</form>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{canEdit && showForm && (
|
||||
<div className="card mb-3">
|
||||
<div className="card-header">
|
||||
@@ -327,6 +429,7 @@ export default function Ipam({ user }: { user: CurrentUser }) {
|
||||
{isIpv6(entry.ipAddress) ? "IPv6" : "IPv4"}
|
||||
</span>
|
||||
{entry.ipAddress}
|
||||
{entry.excluded && <span className="badge bg-secondary-lt text-secondary ms-2">excluded</span>}
|
||||
</td>
|
||||
<td>{entry.label ?? "—"}</td>
|
||||
<td>
|
||||
@@ -343,6 +446,11 @@ export default function Ipam({ user }: { user: CurrentUser }) {
|
||||
<button className="btn btn-sm" onClick={() => startEdit(entry)}>
|
||||
Edit
|
||||
</button>
|
||||
{!entry.excluded && (
|
||||
<button className="btn btn-sm" onClick={() => excludeAround(entry)} title="Hide this and every address in the same range">
|
||||
Exclude…
|
||||
</button>
|
||||
)}
|
||||
<button className="btn btn-sm btn-outline-danger" onClick={() => remove(entry)}>
|
||||
Delete
|
||||
</button>
|
||||
@@ -354,7 +462,9 @@ export default function Ipam({ user }: { user: CurrentUser }) {
|
||||
{(sorted ?? []).length === 0 && (
|
||||
<tr>
|
||||
<td colSpan={canEdit ? 7 : 5} className="text-secondary text-center">
|
||||
No IP addresses tracked yet.
|
||||
{entries && entries.length > 0
|
||||
? "Every tracked address is currently excluded or filtered out — turn off “Hide excluded addresses”, or adjust your search, to see them."
|
||||
: "No IP addresses tracked yet."}
|
||||
</td>
|
||||
</tr>
|
||||
)}
|
||||
|
||||
Reference in new issue
Block a user