mirror of
https://github.com/Termix-SSH/Termix.git
synced 2026-07-15 04:43:36 +00:00
47 lines
1.0 KiB
TypeScript
47 lines
1.0 KiB
TypeScript
import type { NextFunction, Request, Response } from "express";
|
|
import type { AuthenticatedRequest } from "../../../types/index.js";
|
|
import { SimpleDBOps } from "../../utils/simple-db-ops.js";
|
|
|
|
export function applyHostEnrollmentDefaults(
|
|
hostData: Record<string, unknown>,
|
|
): Record<string, unknown> {
|
|
return {
|
|
connectionType: "ssh",
|
|
port: 22,
|
|
authType: "none",
|
|
enableTerminal: true,
|
|
enableSsh: true,
|
|
...hostData,
|
|
};
|
|
}
|
|
|
|
export function requireHostEnrollmentAccessForPath(
|
|
req: Request,
|
|
res: Response,
|
|
next: NextFunction,
|
|
): void {
|
|
if (req.path !== "/enroll") {
|
|
next();
|
|
return;
|
|
}
|
|
|
|
const authReq = req as AuthenticatedRequest;
|
|
if (!authReq.apiKeyId) {
|
|
res.status(401).json({
|
|
error: "Host enrollment requires an API key",
|
|
code: "API_KEY_REQUIRED",
|
|
});
|
|
return;
|
|
}
|
|
|
|
if (!SimpleDBOps.isUserDataUnlocked(authReq.userId)) {
|
|
res.status(423).json({
|
|
error: "User data is locked. Sign in before enrolling hosts.",
|
|
code: "DATA_LOCKED",
|
|
});
|
|
return;
|
|
}
|
|
|
|
next();
|
|
}
|