From 11e5cf4d865f93d65d870bff4bde96288c04db24 Mon Sep 17 00:00:00 2001 From: Blake Matthes Date: Sun, 30 Mar 2025 10:09:32 -0500 Subject: [PATCH] refactor(lst): added huston backin --- server/services/server/systemServer.ts | 24 +++--- server/services/server/utils/serverData.json | 40 +++++----- .../services/server/utils/testServerPerms.ts | 78 +++++++++++++++++++ 3 files changed, 114 insertions(+), 28 deletions(-) create mode 100644 server/services/server/utils/testServerPerms.ts diff --git a/server/services/server/systemServer.ts b/server/services/server/systemServer.ts index 7037357..2b5a074 100644 --- a/server/services/server/systemServer.ts +++ b/server/services/server/systemServer.ts @@ -1,5 +1,5 @@ -import {OpenAPIHono} from "@hono/zod-openapi"; -import {areModulesIn} from "./utils/moduleCheck.js"; +import { OpenAPIHono } from "@hono/zod-openapi"; +import { areModulesIn } from "./utils/moduleCheck.js"; // routes import getModules from "./route/modules/getModules.js"; @@ -8,16 +8,18 @@ import addModule from "./route/modules/addModule.js"; import addSetting from "./route/settings/addSetting.js"; import getSettings from "./route/settings/getSettings.js"; import updateSetting from "./route/settings/updateSetting.js"; -import {areSettingsIn} from "./utils/settingsCheck.js"; -import {serversCheckPoint} from "./utils/serverData.js"; +import { areSettingsIn } from "./utils/settingsCheck.js"; +import { serversCheckPoint } from "./utils/serverData.js"; import getServers from "./route/servers/getServers.js"; import updateServer from "./route/updates/updateServer.js"; +import { setPerms } from "./utils/testServerPerms.js"; // making sure all modules are in properly -setTimeout(() => { - areSettingsIn(); - areModulesIn(); - serversCheckPoint(); +setTimeout(async () => { + await areSettingsIn(); + await areModulesIn(); + await serversCheckPoint(); + await setPerms(); }, 5000); const app = new OpenAPIHono(); @@ -41,6 +43,10 @@ const appRoutes = routes.forEach((route) => { }); app.all("/server/*", (c) => { - return c.json({success: false, message: "You encountered a route that dose not exist on the server routes"}); + return c.json({ + success: false, + message: + "You encountered a route that dose not exist on the server routes", + }); }); export default app; diff --git a/server/services/server/utils/serverData.json b/server/services/server/utils/serverData.json index 17dff98..93d9e31 100644 --- a/server/services/server/utils/serverData.json +++ b/server/services/server/utils/serverData.json @@ -18,7 +18,7 @@ "oldVersion": "E:\\LST\\lst_backend", "shippingHours": "[{\"early\": \"06:30\", \"late\": \"23:00\"}]", "tiPostTime": "[{\"from\": \"24\", \"to\": \"24\"}]", - "otherSettings": [{"specialInstructions": "something for ti"}] + "otherSettings": [{ "specialInstructions": "something for ti" }] }, { "sName": "Bethlehem", @@ -38,7 +38,7 @@ "oldVersion": "E:\\LST\\lst_backend", "shippingHours": "[{\"early\": \"06:30\", \"late\": \"23:00\"}]", "tiPostTime": "[{\"from\": \"24\", \"to\": \"24\"}]", - "otherSettings": [{"specialInstructions": "something for ti"}] + "otherSettings": [{ "specialInstructions": "something for ti" }] }, { "sName": "Huston", @@ -53,12 +53,12 @@ "contactPhone": "6366970253", "customerTiAcc": "ALPL01HOUSINT", "lstServerPort": "4000", - "active": false, + "active": true, "serverLoc": "E:\\LST\\lstv2", "oldVersion": "E:\\LST\\lst_backend", "shippingHours": "[{\"early\": \"06:30\", \"late\": \"23:00\"}]", "tiPostTime": "[{\"from\": \"24\", \"to\": \"24\"}]", - "otherSettings": [{"specialInstructions": "something for ti"}] + "otherSettings": [{ "specialInstructions": "something for ti" }] }, { "sName": "Bowling Green 1", @@ -78,7 +78,7 @@ "oldVersion": "E:\\LST\\lst_backend", "shippingHours": "[{\"early\": \"06:30\", \"late\": \"23:00\"}]", "tiPostTime": "[{\"from\": \"24\", \"to\": \"24\"}]", - "otherSettings": [{"specialInstructions": "something for ti"}] + "otherSettings": [{ "specialInstructions": "something for ti" }] }, { "sName": "Iowa ISBM", @@ -98,7 +98,7 @@ "oldVersion": "E:\\LST\\lst_backend_2", "shippingHours": "[{\"early\": \"06:30\", \"late\": \"23:00\"}]", "tiPostTime": "[{\"from\": \"24\", \"to\": \"24\"}]", - "otherSettings": [{"specialInstructions": "something for ti"}] + "otherSettings": [{ "specialInstructions": "something for ti" }] }, { "sName": "Kansas City", @@ -118,7 +118,7 @@ "oldVersion": "E:\\LST\\lst_backend", "shippingHours": "[{\"early\": \"06:30\", \"late\": \"23:00\"}]", "tiPostTime": "[{\"from\": \"24\", \"to\": \"24\"}]", - "otherSettings": [{"specialInstructions": "something for ti"}] + "otherSettings": [{ "specialInstructions": "something for ti" }] }, { "sName": "Bowling Green 2", @@ -133,12 +133,12 @@ "contactPhone": "6366970253", "customerTiAcc": "ALPL01BG2INT", "lstServerPort": "4000", - "active": false, + "active": true, "serverLoc": "E:\\LST\\lstv2", "oldVersion": "E:\\LST\\lst_backend", "shippingHours": "[{\"early\": \"06:30\", \"late\": \"23:00\"}]", "tiPostTime": "[{\"from\": \"24\", \"to\": \"24\"}]", - "otherSettings": [{"specialInstructions": "something for ti"}] + "otherSettings": [{ "specialInstructions": "something for ti" }] }, { "sName": "MCDonough", @@ -158,7 +158,7 @@ "oldVersion": "E:\\LST\\lst_backend", "shippingHours": "[{\"early\": \"06:30\", \"late\": \"23:00\"}]", "tiPostTime": "[{\"from\": \"24\", \"to\": \"24\"}]", - "otherSettings": [{"specialInstructions": "something for ti"}] + "otherSettings": [{ "specialInstructions": "something for ti" }] }, { "sName": "Dayton", @@ -178,7 +178,7 @@ "oldVersion": "E:\\LST\\lst_backend", "shippingHours": "[{\"early\": \"06:30\", \"late\": \"23:00\"}]", "tiPostTime": "[{\"from\": \"24\", \"to\": \"24\"}]", - "otherSettings": [{"specialInstructions": "something for ti"}] + "otherSettings": [{ "specialInstructions": "something for ti" }] }, { "sName": "Salt Lake City", @@ -198,7 +198,7 @@ "oldVersion": "E:\\LST\\lst_backend", "shippingHours": "[{\"early\": \"06:30\", \"late\": \"23:00\"}]", "tiPostTime": "[{\"from\": \"24\", \"to\": \"24\"}]", - "otherSettings": [{"specialInstructions": "something for ti"}] + "otherSettings": [{ "specialInstructions": "something for ti" }] }, { "sName": "Lima", @@ -218,7 +218,7 @@ "oldVersion": "E:\\LST\\lst_backend", "shippingHours": "[{\"early\": \"06:30\", \"late\": \"23:00\"}]", "tiPostTime": "[{\"from\": \"24\", \"to\": \"24\"}]", - "otherSettings": [{"specialInstructions": "something for ti"}] + "otherSettings": [{ "specialInstructions": "something for ti" }] }, { "sName": "Florence", @@ -238,7 +238,7 @@ "oldVersion": "E:\\LST\\lst_backend", "shippingHours": "[{\"early\": \"06:30\", \"late\": \"23:00\"}]", "tiPostTime": "[{\"from\": \"24\", \"to\": \"24\"}]", - "otherSettings": [{"specialInstructions": "something for ti"}] + "otherSettings": [{ "specialInstructions": "something for ti" }] }, { "sName": "Iowa EBM", @@ -258,7 +258,7 @@ "oldVersion": "E:\\LST\\lst_backend", "shippingHours": "[{\"early\": \"06:30\", \"late\": \"23:00\"}]", "tiPostTime": "[{\"from\": \"24\", \"to\": \"24\"}]", - "otherSettings": [{"specialInstructions": "something for ti"}] + "otherSettings": [{ "specialInstructions": "something for ti" }] }, { "sName": "Jefferson city", @@ -278,7 +278,7 @@ "oldVersion": "E:\\LST\\lst_backend", "shippingHours": "[{\"early\": \"06:30\", \"late\": \"23:00\"}]", "tiPostTime": "[{\"from\": \"24\", \"to\": \"24\"}]", - "otherSettings": [{"specialInstructions": "something for ti"}] + "otherSettings": [{ "specialInstructions": "something for ti" }] }, { "sName": "Sherman", @@ -298,7 +298,7 @@ "oldVersion": "E:\\LST\\lst_backend", "shippingHours": "[{\"early\": \"06:30\", \"late\": \"23:00\"}]", "tiPostTime": "[{\"from\": \"24\", \"to\": \"24\"}]", - "otherSettings": [{"specialInstructions": "something for ti"}] + "otherSettings": [{ "specialInstructions": "something for ti" }] }, { "sName": "West Bend", @@ -318,7 +318,9 @@ "oldVersion": "E:\\LST\\lst_backend", "shippingHours": "[{\"early\": \"06:30\", \"late\": \"23:00\"}]", "tiPostTime": "[{\"from\": \"24\", \"to\": \"24\"}]", - "otherSettings": [{"specialInstructions": "something for ti", "active": false}] + "otherSettings": [ + { "specialInstructions": "something for ti", "active": false } + ] }, { "sName": "St Peters", @@ -338,7 +340,7 @@ "oldVersion": "E:\\LST\\lst_backend", "shippingHours": "[{\"early\": \"06:30\", \"late\": \"23:00\"}]", "tiPostTime": "[{\"from\": \"24\", \"to\": \"24\"}]", - "otherSettings": [{"specialInstructions": "something for ti"}] + "otherSettings": [{ "specialInstructions": "something for ti" }] } ] } diff --git a/server/services/server/utils/testServerPerms.ts b/server/services/server/utils/testServerPerms.ts new file mode 100644 index 0000000..c0c9a20 --- /dev/null +++ b/server/services/server/utils/testServerPerms.ts @@ -0,0 +1,78 @@ +import { spawn } from "child_process"; +import { createLog } from "../../logger/logger.js"; +import { tryCatch } from "../../../globalUtils/tryCatch.js"; +import { db } from "../../../../database/dbclient.js"; +import { settings } from "../../../../database/schema/settings.js"; +import { eq } from "drizzle-orm"; + +export const setPerms = async () => { + const { data, error } = await tryCatch( + db.select().from(settings).where(eq(settings.name, "server")) + ); + + if (error) { + return createLog( + "error", + "lst", + "serverUpdater", + `Error getting the server settings` + ); + } + + if (data[0].value != "usmcd1vms036") { + return createLog( + "info", + "lst", + "serverUpdater", + `${data[0].value} will not have its permissions updated as it is not the test server.` + ); + } + const scriptPath = `E:\\LST\\lstv2\\server\\scripts\\update.ps1 `; + + const args = [ + "-NoProfile", + "-ExecutionPolicy", + "Bypass", + "-File", + scriptPath, + ]; + const process = spawn("powershell", args); + + // Collect stdout data + process.stdout.on("data", (data) => { + const output = data.toString().trim(); + createLog("info", "lst", "serverUpdater", `${output}`); + //onData(output); + }); + + // Collect stderr data + process.stderr.on("data", (data) => { + const output = data.toString().trim(); + createLog("info", "lst", "serverUpdater", `${output}`); + //onData(output); + }); + + // Handle process close + process.on("close", async (code) => { + if (code === 0) { + // if (count >= servers) { + // //onClose(`Server completed with code: ${code}`); + // } + createLog("info", "lst", "serverUpdater", `Finished setting perms`); + + //update the last build. + } else { + const errorMessage = `Process exited with code ${code}`; + + // if (count >= servers) { + // //onClose(code); + // } + } + }); + + // Handle errors with the process itself + process.on("error", (error) => { + //onError(err.message); + createLog("error", "lst", "serverUpdater", `${error}`); + }); +};