add option for specific OS's in scripts.

change view in script editor to match the block view (looks much nicer and much more organized).
This commit is contained in:
KingKDot
2026-03-17 13:27:44 -05:00
parent 0564bbd1ea
commit 7ee22bb004
6 changed files with 217 additions and 279 deletions
@@ -28,6 +28,13 @@ export function dispatchAutoScriptsForConnection(
}
for (const script of scripts) {
if (script.osFilter.length > 0) {
const clientOs = (info.os || "").toLowerCase();
if (!script.osFilter.includes(clientOs)) {
continue;
}
}
if (script.trigger === "on_connect_once") {
if (hasAutoScriptRun(script.id, info.id)) {
continue;
@@ -7,7 +7,7 @@ import {
updateAutoScript,
} from "../../db";
import { requirePermission } from "../../rbac";
import { AUTO_SCRIPT_TRIGGERS, ALLOWED_SCRIPT_TYPES } from "../validation-constants";
import { AUTO_SCRIPT_TRIGGERS, ALLOWED_SCRIPT_TYPES, ALLOWED_OS_FILTERS } from "../validation-constants";
import { v4 as uuidv4 } from "uuid";
export async function handleAutoScriptsRoutes(
@@ -59,6 +59,8 @@ export async function handleAutoScriptsRoutes(
const script = String(body?.script || "");
const scriptTypeRaw = String(body?.scriptType || "powershell").trim();
const enabled = typeof body?.enabled === "boolean" ? body.enabled : true;
const osFilterRaw = Array.isArray(body?.osFilter) ? body.osFilter : [];
const osFilter = osFilterRaw.filter((v: unknown) => typeof v === "string" && ALLOWED_OS_FILTERS.has(v));
if (!name) {
return Response.json({ error: "Name is required" }, { status: 400 });
@@ -81,6 +83,7 @@ export async function handleAutoScriptsRoutes(
script,
scriptType,
enabled,
osFilter,
});
return Response.json({ ok: true, item });
@@ -121,12 +124,18 @@ export async function handleAutoScriptsRoutes(
: "powershell"
: undefined;
const osFilterRaw = Array.isArray(body?.osFilter) ? body.osFilter : undefined;
const osFilter = osFilterRaw
? osFilterRaw.filter((v: unknown) => typeof v === "string" && ALLOWED_OS_FILTERS.has(v))
: undefined;
const updated = updateAutoScript(autoScriptMatch[1], {
name: body?.name ? String(body.name).trim() : undefined,
trigger: triggerRaw as AutoScriptTrigger | undefined,
script: body?.script ? String(body.script) : undefined,
scriptType,
enabled: typeof body?.enabled === "boolean" ? body.enabled : undefined,
osFilter,
});
if (!updated) {
@@ -29,3 +29,11 @@ export const ALLOWED_PLATFORMS = new Set([
"android-amd64",
"android-armv7",
]);
export const ALLOWED_OS_FILTERS = new Set([
"windows",
"linux",
"darwin",
"android",
"freebsd",
]);