From a55c3193e002cfd78f6c000e2cdf4fb5441d6c11 Mon Sep 17 00:00:00 2001 From: KingKDot Date: Sun, 29 Mar 2026 14:03:05 -0500 Subject: [PATCH] fix auto plugins not working if someone was allowed in through purgatory --- Overlord-Server/src/main-server.ts | 23 +++++++++++++++++-- .../src/server/routes/enrollment-routes.ts | 15 +++++++++++- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/Overlord-Server/src/main-server.ts b/Overlord-Server/src/main-server.ts index 5ca114e..0d97e10 100644 --- a/Overlord-Server/src/main-server.ts +++ b/Overlord-Server/src/main-server.ts @@ -17,7 +17,7 @@ import { metrics } from "./metrics"; import { ensureDataDir } from "./paths"; import { handleAuthRoutes } from "./server/routes/auth-routes"; import { handleAutoScriptsRoutes } from "./server/routes/auto-scripts-routes"; -import { handleEnrollmentRoutes } from "./server/routes/enrollment-routes"; +import { handleEnrollmentRoutes, setPostApproveHook } from "./server/routes/enrollment-routes"; import { handleBuildRoutes } from "./server/routes/build-routes"; import { handleAssetsRoutes } from "./server/routes/assets-routes"; import { handleDeployRoutes } from "./server/routes/deploy-routes"; @@ -297,6 +297,23 @@ const pendingCommandReplies = new Map(); async function startServer() { await loadPluginState(); + + setPostApproveHook((clientId: string) => { + const client = clientManager.getClient(clientId); + if (!client) return; + dispatchAutoLoadPlugins( + client, + pluginState, + notificationPluginHandlers.isPluginLoaded, + notificationPluginHandlers.isPluginLoading, + notificationPluginHandlers.markPluginLoading, + notificationPluginHandlers.enqueuePluginEvent, + loadPluginBundle, + ).catch((err) => { + logger.warn(`[enrollment] failed to dispatch auto-load plugins for ${clientId}: ${(err as Error).message}`); + }); + }); + await cleanupFileTransferTempFiles(DATA_DIR); logger.info("[filebrowser] cleaned stale transfer temp files on startup"); let tls: @@ -468,7 +485,9 @@ async function startServer() { notificationPluginHandlers.markPluginLoading, notificationPluginHandlers.enqueuePluginEvent, loadPluginBundle, - ); + ).catch((err) => { + logger.warn(`[plugin-autoload] dispatch error for ${info.id}: ${(err as Error).message}`); + }); }, takePendingNotificationScreenshot: takePendingNotificationScreenshotForClient, storeNotificationScreenshot: storeNotificationScreenshotForPending, diff --git a/Overlord-Server/src/server/routes/enrollment-routes.ts b/Overlord-Server/src/server/routes/enrollment-routes.ts index d520725..db1e07a 100644 --- a/Overlord-Server/src/server/routes/enrollment-routes.ts +++ b/Overlord-Server/src/server/routes/enrollment-routes.ts @@ -15,6 +15,12 @@ import { logAudit, AuditAction } from "../../auditLog"; import * as clientManager from "../../clientManager"; import { setOnlineState } from "../../db"; +let _postApproveHook: ((clientId: string) => void) | undefined; + +export function setPostApproveHook(hook: (clientId: string) => void): void { + _postApproveHook = hook; +} + export async function handleEnrollmentRoutes( req: Request, url: URL, @@ -62,6 +68,8 @@ export async function handleEnrollmentRoutes( setClientEnrollmentStatus(clientId, "approved", user.username); + _postApproveHook?.(clientId); + logAudit({ timestamp: Date.now(), username: user.username, @@ -175,7 +183,12 @@ export async function handleEnrollmentRoutes( status as "approved" | "denied" | "pending", action === "approve" ? user.username : undefined, ); - if (ok) updated++; + if (ok) { + updated++; + if (action === "approve") { + _postApproveHook?.(id); + } + } } logAudit({