Scaffold Homelab Manager foundation
Monorepo (Express+TS+Drizzle/libSQL server, React+Vite+Tabler web) matching the stack used by ScheduleTaskManager and Sloth Manager. Includes Authentik OIDC login with local admin/operator/viewer roles (first user becomes admin), a generalized audit log, encrypted-at-rest storage for future integration API tokens, the DB schema for all planned modules, and the Tabler-styled app shell/nav. Also ports the Secrets (expiry tracker) and IP Addresses (IPAM) modules from Sloth Manager onto the new stack. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
commit
6bd2ed52c1
52 files changed
+8103
No files matched your search
@@ -0,0 +1,283 @@
|
||||
import { useEffect, useMemo, useState } from "react";
|
||||
import { api, type CurrentUser, type SecretInput, type SecretRecord, type SecretStatus } from "../api/client";
|
||||
import { downloadCsv } from "../utils/csv";
|
||||
|
||||
const TYPE_LABELS: Record<SecretRecord["type"], string> = {
|
||||
api_token: "API Token",
|
||||
ssl_certificate: "SSL Certificate",
|
||||
password: "Password",
|
||||
generic: "Generic",
|
||||
};
|
||||
|
||||
const STATUS_BADGE: Record<SecretStatus, string> = {
|
||||
ok: "bg-green-lt text-green",
|
||||
expiring: "bg-yellow-lt text-yellow",
|
||||
expired: "bg-red-lt text-red",
|
||||
};
|
||||
|
||||
const emptyForm: SecretInput = {
|
||||
name: "",
|
||||
type: "generic",
|
||||
description: "",
|
||||
expiryDate: "",
|
||||
warnDays: 30,
|
||||
notes: "",
|
||||
};
|
||||
|
||||
export default function Secrets({ user }: { user: CurrentUser }) {
|
||||
const canEdit = user.role === "admin" || user.role === "operator";
|
||||
const [secrets, setSecrets] = useState<SecretRecord[] | null>(null);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [search, setSearch] = useState("");
|
||||
const [statusFilter, setStatusFilter] = useState<"all" | SecretStatus>("all");
|
||||
const [editingId, setEditingId] = useState<number | null>(null);
|
||||
const [form, setForm] = useState<SecretInput>(emptyForm);
|
||||
const [saving, setSaving] = useState(false);
|
||||
|
||||
function load() {
|
||||
api.secrets
|
||||
.list()
|
||||
.then((res) => setSecrets(res.secrets))
|
||||
.catch((err) => setError(String(err)));
|
||||
}
|
||||
|
||||
useEffect(load, []);
|
||||
|
||||
const filtered = useMemo(() => {
|
||||
if (!secrets) return [];
|
||||
return secrets.filter((s) => {
|
||||
if (statusFilter !== "all" && s.status !== statusFilter) return false;
|
||||
const q = search.trim().toLowerCase();
|
||||
if (!q) return true;
|
||||
return s.name.toLowerCase().includes(q) || (s.description ?? "").toLowerCase().includes(q);
|
||||
});
|
||||
}, [secrets, search, statusFilter]);
|
||||
|
||||
function startEdit(s: SecretRecord) {
|
||||
setEditingId(s.id);
|
||||
setForm({
|
||||
name: s.name,
|
||||
type: s.type,
|
||||
description: s.description ?? "",
|
||||
expiryDate: s.expiryDate,
|
||||
warnDays: s.warnDays,
|
||||
notes: s.notes ?? "",
|
||||
});
|
||||
}
|
||||
|
||||
function cancelEdit() {
|
||||
setEditingId(null);
|
||||
setForm(emptyForm);
|
||||
}
|
||||
|
||||
async function submit(e: React.FormEvent) {
|
||||
e.preventDefault();
|
||||
setError(null);
|
||||
setSaving(true);
|
||||
try {
|
||||
if (editingId) {
|
||||
await api.secrets.update(editingId, form);
|
||||
} else {
|
||||
await api.secrets.create(form);
|
||||
}
|
||||
cancelEdit();
|
||||
load();
|
||||
} catch (err) {
|
||||
setError(err instanceof Error ? err.message : String(err));
|
||||
} finally {
|
||||
setSaving(false);
|
||||
}
|
||||
}
|
||||
|
||||
async function remove(s: SecretRecord) {
|
||||
if (!confirm(`Delete secret "${s.name}"?`)) return;
|
||||
setError(null);
|
||||
try {
|
||||
await api.secrets.remove(s.id);
|
||||
load();
|
||||
} catch (err) {
|
||||
setError(err instanceof Error ? err.message : String(err));
|
||||
}
|
||||
}
|
||||
|
||||
function exportCsv() {
|
||||
downloadCsv(
|
||||
"secrets.csv",
|
||||
["Name", "Type", "Description", "Expiry Date", "Warn Days", "Status", "Days Left", "Notes"],
|
||||
filtered.map((s) => [
|
||||
s.name,
|
||||
TYPE_LABELS[s.type],
|
||||
s.description ?? "",
|
||||
s.expiryDate,
|
||||
s.warnDays,
|
||||
s.status,
|
||||
s.daysLeft,
|
||||
s.notes ?? "",
|
||||
]),
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<h2 className="page-title mb-3">Secrets</h2>
|
||||
{error && <div className="alert alert-danger">{error}</div>}
|
||||
|
||||
{canEdit && (
|
||||
<div className="card mb-3">
|
||||
<div className="card-header">
|
||||
<h3 className="card-title">{editingId ? "Edit secret" : "Add a secret"}</h3>
|
||||
</div>
|
||||
<form onSubmit={submit}>
|
||||
<div className="card-body row g-3">
|
||||
<div className="col-md-4">
|
||||
<label className="form-label">Name</label>
|
||||
<input
|
||||
className="form-control"
|
||||
required
|
||||
value={form.name}
|
||||
onChange={(e) => setForm({ ...form, name: e.target.value })}
|
||||
/>
|
||||
</div>
|
||||
<div className="col-md-3">
|
||||
<label className="form-label">Type</label>
|
||||
<select
|
||||
className="form-select"
|
||||
value={form.type}
|
||||
onChange={(e) => setForm({ ...form, type: e.target.value as SecretInput["type"] })}
|
||||
>
|
||||
{Object.entries(TYPE_LABELS).map(([value, label]) => (
|
||||
<option key={value} value={value}>
|
||||
{label}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
<div className="col-md-2">
|
||||
<label className="form-label">Expiry date</label>
|
||||
<input
|
||||
type="date"
|
||||
className="form-control"
|
||||
required
|
||||
value={form.expiryDate}
|
||||
onChange={(e) => setForm({ ...form, expiryDate: e.target.value })}
|
||||
/>
|
||||
</div>
|
||||
<div className="col-md-3">
|
||||
<label className="form-label">Warn (days before)</label>
|
||||
<input
|
||||
type="number"
|
||||
min={0}
|
||||
className="form-control"
|
||||
value={form.warnDays}
|
||||
onChange={(e) => setForm({ ...form, warnDays: Number(e.target.value) })}
|
||||
/>
|
||||
</div>
|
||||
<div className="col-md-6">
|
||||
<label className="form-label">Description</label>
|
||||
<input
|
||||
className="form-control"
|
||||
value={form.description}
|
||||
onChange={(e) => setForm({ ...form, description: e.target.value })}
|
||||
/>
|
||||
</div>
|
||||
<div className="col-md-6">
|
||||
<label className="form-label">Notes</label>
|
||||
<input
|
||||
className="form-control"
|
||||
value={form.notes}
|
||||
onChange={(e) => setForm({ ...form, notes: e.target.value })}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div className="card-footer d-flex gap-2">
|
||||
<button type="submit" className="btn btn-primary" disabled={saving}>
|
||||
{editingId ? "Save changes" : "Add secret"}
|
||||
</button>
|
||||
{editingId && (
|
||||
<button type="button" className="btn" onClick={cancelEdit}>
|
||||
Cancel
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="card">
|
||||
<div className="card-header">
|
||||
<div className="d-flex flex-wrap gap-2 align-items-center w-100">
|
||||
<input
|
||||
className="form-control"
|
||||
style={{ maxWidth: 260 }}
|
||||
placeholder="Search name or description…"
|
||||
value={search}
|
||||
onChange={(e) => setSearch(e.target.value)}
|
||||
/>
|
||||
<select
|
||||
className="form-select"
|
||||
style={{ maxWidth: 160 }}
|
||||
value={statusFilter}
|
||||
onChange={(e) => setStatusFilter(e.target.value as typeof statusFilter)}
|
||||
>
|
||||
<option value="all">All statuses</option>
|
||||
<option value="ok">OK</option>
|
||||
<option value="expiring">Expiring</option>
|
||||
<option value="expired">Expired</option>
|
||||
</select>
|
||||
<button className="btn btn-outline-secondary ms-auto" onClick={exportCsv}>
|
||||
Export CSV
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div className="table-responsive">
|
||||
<table className="table table-vcenter card-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Type</th>
|
||||
<th>Expiry</th>
|
||||
<th>Days left</th>
|
||||
<th>Status</th>
|
||||
<th>Description</th>
|
||||
{canEdit && <th className="w-1">Actions</th>}
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{filtered.map((s) => (
|
||||
<tr key={s.id}>
|
||||
<td>{s.name}</td>
|
||||
<td>{TYPE_LABELS[s.type]}</td>
|
||||
<td>{s.expiryDate}</td>
|
||||
<td>{s.daysLeft < 0 ? `${Math.abs(s.daysLeft)}d ago` : `${s.daysLeft}d`}</td>
|
||||
<td>
|
||||
<span className={`badge ${STATUS_BADGE[s.status]}`}>{s.status}</span>
|
||||
</td>
|
||||
<td className="text-secondary">{s.description ?? "—"}</td>
|
||||
{canEdit && (
|
||||
<td>
|
||||
<div className="btn-list flex-nowrap">
|
||||
<button className="btn btn-sm" onClick={() => startEdit(s)}>
|
||||
Edit
|
||||
</button>
|
||||
<button className="btn btn-sm btn-outline-danger" onClick={() => remove(s)}>
|
||||
Delete
|
||||
</button>
|
||||
</div>
|
||||
</td>
|
||||
)}
|
||||
</tr>
|
||||
))}
|
||||
{filtered.length === 0 && (
|
||||
<tr>
|
||||
<td colSpan={canEdit ? 7 : 6} className="text-secondary text-center">
|
||||
No secrets tracked yet.
|
||||
</td>
|
||||
</tr>
|
||||
)}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user