Export CSV on every table, edit recurring maintenance, runs-on nothing, and run package checks outside the agent sandbox
- Export CSV for the small tables that had none (reads the table as shown) - Servers page shows a skeleton while loading instead of "No servers registered yet" - Recurring maintenance schedules can be edited (PUT /schedules/:id) - A server can be set to run on nothing (servers.no_parent, migration 0028) - Linux agent v3: package-manager question runs in ExecStartPre=-+ outside the sandbox, with --prepare-updates and --check-updates modes - Docs: README, DATABASE, AGENT_UPDATE Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
c17e9aa140
commit
540ab704b7
32 files changed
+3003
-66
No files matched your search
@@ -309,23 +309,32 @@ maintenanceRouter.get("/schedules", asyncHandler(async (_req, res) => {
|
||||
res.json({ schedules: out });
|
||||
}));
|
||||
|
||||
maintenanceRouter.post("/schedules", requireRole("operator"), asyncHandler(async (req, res) => {
|
||||
const parsed = scheduleSchema.safeParse(req.body);
|
||||
type ScheduleBody = z.infer<typeof scheduleSchema>;
|
||||
|
||||
/** Checks a schedule's fields the same way for making one and for changing one: the shape, the time zone, and that what it covers exists (once each). */
|
||||
async function checkScheduleBody(body: unknown): Promise<{ data: ScheduleBody; targets: ScheduleBody["targets"] } | { status: number; json: object }> {
|
||||
const parsed = scheduleSchema.safeParse(body);
|
||||
if (!parsed.success) {
|
||||
return res.status(400).json({ error: "invalid_body", message: "Name it, choose what it covers, the days, a start time and how long.", details: parsed.error.flatten() });
|
||||
return { status: 400, json: { error: "invalid_body", message: "Name it, choose what it covers, the days, a start time and how long.", details: parsed.error.flatten() } };
|
||||
}
|
||||
const data = parsed.data;
|
||||
if (!isValidTimeZone(data.timezone)) return res.status(400).json({ error: "invalid_timezone", message: "That isn't a time zone this server knows." });
|
||||
// Only things that exist, once each.
|
||||
if (!isValidTimeZone(data.timezone)) return { status: 400, json: { error: "invalid_timezone", message: "That isn't a time zone this server knows." } };
|
||||
const seen = new Set<string>();
|
||||
const targets = [];
|
||||
const targets: ScheduleBody["targets"] = [];
|
||||
for (const t of data.targets) {
|
||||
const key = `${t.type}:${t.id}`;
|
||||
if (seen.has(key)) continue;
|
||||
seen.add(key);
|
||||
if (!(await describeTarget(t.type, t.id))) return res.status(400).json({ error: "unknown_target", message: "One of the things chosen doesn't exist any more." });
|
||||
if (!(await describeTarget(t.type, t.id))) return { status: 400, json: { error: "unknown_target", message: "One of the things chosen doesn't exist any more." } };
|
||||
targets.push(t);
|
||||
}
|
||||
return { data, targets };
|
||||
}
|
||||
|
||||
maintenanceRouter.post("/schedules", requireRole("operator"), asyncHandler(async (req, res) => {
|
||||
const checked = await checkScheduleBody(req.body);
|
||||
if ("status" in checked) return res.status(checked.status).json(checked.json);
|
||||
const { data, targets } = checked;
|
||||
const actor = req.currentUser!;
|
||||
const [created] = await db
|
||||
.insert(maintenanceSchedules)
|
||||
@@ -345,6 +354,36 @@ maintenanceRouter.post("/schedules", requireRole("operator"), asyncHandler(async
|
||||
res.status(201).json({ id: created.id, windowsMade: made });
|
||||
}));
|
||||
|
||||
/**
|
||||
* Changes a schedule's name, days, time, length or what it covers. Windows it made that haven't begun are taken back and made again from the
|
||||
* new settings; one already under way keeps the times it started with, and ends on its own.
|
||||
*/
|
||||
maintenanceRouter.put("/schedules/:id", requireRole("operator"), asyncHandler(async (req, res) => {
|
||||
const id = Number(req.params.id);
|
||||
if (!Number.isInteger(id)) return res.status(400).json({ error: "invalid_id" });
|
||||
const [row] = await db.select().from(maintenanceSchedules).where(eq(maintenanceSchedules.id, id)).limit(1);
|
||||
if (!row) return res.status(404).json({ error: "not_found" });
|
||||
const checked = await checkScheduleBody(req.body);
|
||||
if ("status" in checked) return res.status(checked.status).json(checked.json);
|
||||
const { data, targets } = checked;
|
||||
await db
|
||||
.update(maintenanceSchedules)
|
||||
.set({
|
||||
name: data.name,
|
||||
reason: data.reason || null,
|
||||
targets: JSON.stringify(targets),
|
||||
days: JSON.stringify([...new Set(data.days)].sort()),
|
||||
startTime: data.startTime,
|
||||
durationMinutes: data.durationMinutes,
|
||||
timezone: data.timezone,
|
||||
})
|
||||
.where(eq(maintenanceSchedules.id, id));
|
||||
await removeFutureWindows(id);
|
||||
const made = row.enabled ? await materializeSchedules(new Date(), undefined, id) : 0;
|
||||
await recordAudit({ actor: req.currentUser!, category: "maintenance", action: "update_schedule", targetType: "maintenance_schedule", targetId: id, detail: { name: data.name, targets: targets.length, days: data.days, startTime: data.startTime, durationMinutes: data.durationMinutes } });
|
||||
res.json({ windowsMade: made });
|
||||
}));
|
||||
|
||||
maintenanceRouter.patch("/schedules/:id", requireRole("operator"), asyncHandler(async (req, res) => {
|
||||
const id = Number(req.params.id);
|
||||
const parsed = z.object({ enabled: z.boolean() }).safeParse(req.body);
|
||||
|
||||
@@ -120,6 +120,8 @@ const updateServerSchema = z
|
||||
hideProxmoxLink: z.boolean().optional(),
|
||||
// The server this one runs on. Null goes back to working it out from the Proxmox node.
|
||||
parentServerId: z.number().int().nullable().optional(),
|
||||
// True says it runs on nothing, which also stops the Proxmox-node guess. Choosing a server, or null, turns it off again.
|
||||
noParent: z.boolean().optional(),
|
||||
})
|
||||
.refine(
|
||||
(data) => {
|
||||
@@ -166,7 +168,10 @@ serversRouter.patch("/:id", requireRole("admin"), asyncHandler(async (req, res)
|
||||
}
|
||||
}
|
||||
|
||||
const [updated] = await db.update(servers).set(parsed.data).where(eq(servers.id, id)).returning();
|
||||
const changes: typeof parsed.data = { ...parsed.data };
|
||||
if (changes.noParent === true) changes.parentServerId = null;
|
||||
else if (changes.parentServerId !== undefined) changes.noParent = false;
|
||||
const [updated] = await db.update(servers).set(changes).where(eq(servers.id, id)).returning();
|
||||
|
||||
await recordAudit({
|
||||
actor: req.currentUser!,
|
||||
@@ -174,7 +179,7 @@ serversRouter.patch("/:id", requireRole("admin"), asyncHandler(async (req, res)
|
||||
action: "update",
|
||||
targetType: "server",
|
||||
targetId: id,
|
||||
detail: { name: updated.name, ...(parsed.data.parentServerId !== undefined ? { parentServerId: parsed.data.parentServerId } : {}) },
|
||||
detail: { name: updated.name, ...(parsed.data.parentServerId !== undefined ? { parentServerId: parsed.data.parentServerId } : {}), ...(parsed.data.noParent !== undefined ? { noParent: parsed.data.noParent } : {}) },
|
||||
});
|
||||
|
||||
const serverOut = publicServer(updated);
|
||||
|
||||
Reference in new issue
Block a user