feat(lstv2 move): moved lstv2 into this app to keep them combined and easier to maintain
This commit is contained in:
18
lstV2/server/services/server/controller/module/addModule.ts
Normal file
18
lstV2/server/services/server/controller/module/addModule.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import {eq} from "drizzle-orm";
|
||||
import {db} from "../../../../../database/dbclient.js";
|
||||
import {modules} from "../../../../../database/schema/modules.js";
|
||||
import {createLog} from "../../../logger/logger.js";
|
||||
|
||||
export const addModule = async (data: any, user_id: string) => {
|
||||
createLog("info", "lst", "server", "Module being added");
|
||||
let module;
|
||||
|
||||
try {
|
||||
module = await db.insert(modules).values(data).returning({name: modules.name});
|
||||
//.where(sql`${userRole} = ANY(roles)`);
|
||||
} catch (error) {
|
||||
createLog("error", "lst", "server", "There was an error adding the module");
|
||||
throw new Error("There was an error adding the module");
|
||||
}
|
||||
return module;
|
||||
};
|
||||
@@ -0,0 +1,30 @@
|
||||
import {eq} from "drizzle-orm";
|
||||
import {db} from "../../../../../database/dbclient.js";
|
||||
import {modules} from "../../../../../database/schema/modules.js";
|
||||
import {createLog} from "../../../logger/logger.js";
|
||||
|
||||
type Data = {
|
||||
active: boolean;
|
||||
};
|
||||
export const updateModule = async (data: Data, moduleID: string) => {
|
||||
createLog("info", "lst", "server", "Module being updated");
|
||||
let module;
|
||||
|
||||
if (typeof data.active !== "boolean") {
|
||||
createLog("error", "lst", "server", "Invalid data type: 'active' must be a boolean");
|
||||
throw new Error("'active' must be a boolean");
|
||||
}
|
||||
|
||||
try {
|
||||
module = await db
|
||||
.update(modules)
|
||||
.set({active: data.active})
|
||||
.where(eq(modules.module_id, moduleID))
|
||||
.returning({name: modules.name});
|
||||
//.where(sql`${userRole} = ANY(roles)`);
|
||||
} catch (error) {
|
||||
createLog("error", "lst", "server", "There was an error updating the module");
|
||||
throw new Error("There was an error updating the module");
|
||||
}
|
||||
return module;
|
||||
};
|
||||
@@ -0,0 +1,42 @@
|
||||
import { eq } from "drizzle-orm";
|
||||
import { db } from "../../../../../database/dbclient.js";
|
||||
import { createLog } from "../../../logger/logger.js";
|
||||
import { subModules } from "../../../../../database/schema/subModules.js";
|
||||
|
||||
type Data = {
|
||||
active: boolean;
|
||||
};
|
||||
export const updateSubModule = async (data: Data, subModuleID: string) => {
|
||||
createLog("info", "lst", "server", "Module being updated");
|
||||
let module;
|
||||
|
||||
console.log(data);
|
||||
|
||||
if (typeof data.active !== "boolean") {
|
||||
createLog(
|
||||
"error",
|
||||
"lst",
|
||||
"server",
|
||||
"Invalid data type: 'active' must be a boolean"
|
||||
);
|
||||
throw new Error("'active' must be a boolean");
|
||||
}
|
||||
|
||||
try {
|
||||
module = await db
|
||||
.update(subModules)
|
||||
.set({ active: data.active })
|
||||
.where(eq(subModules.submodule_id, subModuleID))
|
||||
.returning({ name: subModules.name });
|
||||
//.where(sql`${userRole} = ANY(roles)`);
|
||||
} catch (error) {
|
||||
createLog(
|
||||
"error",
|
||||
"lst",
|
||||
"server",
|
||||
"There was an error updating the module"
|
||||
);
|
||||
throw new Error("There was an error updating the module");
|
||||
}
|
||||
return module;
|
||||
};
|
||||
101
lstV2/server/services/server/controller/server/serviceControl.ts
Normal file
101
lstV2/server/services/server/controller/server/serviceControl.ts
Normal file
@@ -0,0 +1,101 @@
|
||||
import { spawn } from "child_process";
|
||||
import { eq } from "drizzle-orm";
|
||||
import { tryCatch } from "../../../../globalUtils/tryCatch.js";
|
||||
import { db } from "../../../../../database/dbclient.js";
|
||||
import { createLog } from "../../../logger/logger.js";
|
||||
import { serverData } from "../../../../../database/schema/serverData.js";
|
||||
import os from "os";
|
||||
|
||||
export const serviceControl = async (
|
||||
plantToken: string,
|
||||
processType: string,
|
||||
remote: string | null
|
||||
) => {
|
||||
const { data: serverInfo, error: serverError } = await tryCatch(
|
||||
db
|
||||
.select()
|
||||
.from(serverData)
|
||||
.where(eq(serverData.plantToken, plantToken))
|
||||
);
|
||||
|
||||
if (serverError) {
|
||||
return createLog(
|
||||
"error",
|
||||
"lst",
|
||||
"serverUpdater",
|
||||
`Error getting the server settings`
|
||||
);
|
||||
}
|
||||
|
||||
let scriptPath = `${serverInfo[0].serverLoc}\\dist\\server\\scripts\\services.ps1`;
|
||||
if (os.hostname() != serverInfo[0].serverDNS) {
|
||||
scriptPath = `${process.env.DEVFOLDER}\\dist\\server\\scripts\\services.ps1`;
|
||||
}
|
||||
|
||||
console.log(serverInfo[0].serverDNS);
|
||||
const username = process.env.ADMUSER as string;
|
||||
const password = process.env.ADMPASSWORD as string;
|
||||
|
||||
console.log(username, password);
|
||||
|
||||
const args = [
|
||||
"-NoProfile",
|
||||
"-ExecutionPolicy",
|
||||
"Bypass",
|
||||
"-File",
|
||||
scriptPath,
|
||||
"-serviceName",
|
||||
"LSTV2",
|
||||
"-option",
|
||||
processType,
|
||||
"-appPath",
|
||||
serverInfo[0].serverLoc as string,
|
||||
"-remote",
|
||||
remote ?? "",
|
||||
"-server",
|
||||
serverInfo[0].serverDNS as string,
|
||||
"-username",
|
||||
username,
|
||||
"-admpass",
|
||||
password,
|
||||
];
|
||||
const scriptProcess = spawn("powershell", args);
|
||||
|
||||
// Collect stdout data
|
||||
scriptProcess.stdout.on("data", (data) => {
|
||||
const output = data.toString().trim();
|
||||
createLog("info", "lst", "serverUpdater", `${output}`);
|
||||
//onData(output);
|
||||
});
|
||||
|
||||
// Collect stderr data
|
||||
scriptProcess.stderr.on("data", (data) => {
|
||||
const output = data.toString().trim();
|
||||
createLog("info", "lst", "serverUpdater", `${output}`);
|
||||
//onData(output);
|
||||
});
|
||||
|
||||
// Handle process close
|
||||
scriptProcess.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
|
||||
scriptProcess.on("error", (error) => {
|
||||
//onError(err.message);
|
||||
createLog("error", "lst", "serverUpdater", `${error}`);
|
||||
});
|
||||
};
|
||||
@@ -0,0 +1,36 @@
|
||||
import {and, eq} from "drizzle-orm";
|
||||
import {db} from "../../../../../database/dbclient.js";
|
||||
import {settings} from "../../../../../database/schema/settings.js";
|
||||
import {createLog} from "../../../logger/logger.js";
|
||||
import {userRoles} from "../../../../../database/schema/userRoles.js";
|
||||
import {modules} from "../../../../../database/schema/modules.js";
|
||||
|
||||
export const addSetting = async (data: any, user_id: string) => {
|
||||
createLog("info", "lst", "server", "Adding a new setting");
|
||||
|
||||
// make sure the user is a system admin before moving forward
|
||||
const sysAdmin = await db
|
||||
.select()
|
||||
.from(userRoles)
|
||||
.where(and(eq(userRoles.user_id, user_id), eq(userRoles.role, "systemAdmin")));
|
||||
|
||||
if (sysAdmin) {
|
||||
createLog("info", "lst", "server", `Setting ${data.name} is being added`);
|
||||
try {
|
||||
const moduleId = await db.select().from(modules).where(eq(modules.name, data.module));
|
||||
|
||||
// filter out the module and add in the module id
|
||||
//delete data.module;
|
||||
|
||||
//data.moduleName = moduleId[0].module_id;
|
||||
// console.log(data);
|
||||
const createSetting = await db.insert(settings).values(data);
|
||||
} catch (error) {
|
||||
createLog("error", "lst", "server", "Error adding setting");
|
||||
throw new Error("Error Adding Setting");
|
||||
}
|
||||
} else {
|
||||
createLog("error", "lst", "server", "This user cannot add new roles");
|
||||
throw new Error("The user trying to add a setting dose not have the correct permissions");
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,57 @@
|
||||
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
|
||||
import axios from "axios";
|
||||
import { db } from "../../../../../database/dbclient.js";
|
||||
import { settings } from "../../../../../database/schema/settings.js";
|
||||
import { tryCatch } from "../../../../globalUtils/tryCatch.js";
|
||||
import { createLog } from "../../../logger/logger.js";
|
||||
import type { Settings } from "../../../../types/settings.js";
|
||||
|
||||
export let serverSettings: Settings[];
|
||||
export const getSettings = async () => {
|
||||
const settingsType = process.env.LST_USE_GO;
|
||||
createLog(
|
||||
"info",
|
||||
"lst",
|
||||
"server",
|
||||
`Settings are being grabbed from: ${
|
||||
settingsType === "true" ? "Go backend" : "Localbackend"
|
||||
}`
|
||||
);
|
||||
|
||||
const baseUrl = process.env.LST_BASE_URL;
|
||||
|
||||
if (settingsType === "true") {
|
||||
const { data, error } = (await tryCatch(
|
||||
axios.get(`${baseUrl}/api/v1/settings`)
|
||||
)) as any;
|
||||
|
||||
if (error) {
|
||||
createLog(
|
||||
"error",
|
||||
"lst",
|
||||
"server",
|
||||
"There was an error getting the settings"
|
||||
);
|
||||
throw new Error("There was an error getting the settings");
|
||||
}
|
||||
|
||||
serverSettings = data.data.data;
|
||||
}
|
||||
|
||||
if (settingsType !== "true") {
|
||||
try {
|
||||
serverSettings = (await db.select().from(settings)) as any;
|
||||
//.where(sql`${userRole} = ANY(roles)`);
|
||||
} catch (error) {
|
||||
createLog(
|
||||
"error",
|
||||
"lst",
|
||||
"server",
|
||||
"There was an error getting the settings"
|
||||
);
|
||||
throw new Error("There was an error getting the settings");
|
||||
}
|
||||
}
|
||||
|
||||
return serverSettings;
|
||||
};
|
||||
@@ -0,0 +1,37 @@
|
||||
import {and, eq, sql} from "drizzle-orm";
|
||||
import {db} from "../../../../../database/dbclient.js";
|
||||
import {settings} from "../../../../../database/schema/settings.js";
|
||||
import {createLog} from "../../../logger/logger.js";
|
||||
import {userRoles} from "../../../../../database/schema/userRoles.js";
|
||||
import {users} from "../../../../../database/schema/users.js";
|
||||
|
||||
export const updateSetting = async (data: any, user_id: string) => {
|
||||
createLog("info", "lst", "server", "Adding a new setting");
|
||||
|
||||
// make sure the user is a system admin before moving forward
|
||||
const sysAdmin = await db
|
||||
.select()
|
||||
.from(userRoles)
|
||||
.where(and(eq(userRoles.user_id, user_id), eq(userRoles.role, "systemAdmin")));
|
||||
|
||||
if (sysAdmin) {
|
||||
createLog("info", "lst", "server", `Setting ${data.name} is being updated`);
|
||||
|
||||
//get the username so we can update the correct field
|
||||
const user = await db.select().from(users).where(eq(users.user_id, user_id));
|
||||
try {
|
||||
//const settingID = await db.select().from(settings).where(eq(settings.name, data.module));
|
||||
|
||||
const updateSetting = await db
|
||||
.update(settings)
|
||||
.set({value: data.value, upd_user: user[0].username, upd_date: sql`NOW()`})
|
||||
.where(eq(settings.name, data.name));
|
||||
} catch (error) {
|
||||
createLog("error", "lst", "server", "Error updating setting");
|
||||
throw new Error("Error updating Setting");
|
||||
}
|
||||
} else {
|
||||
createLog("error", "lst", "server", "This user cannot add new roles");
|
||||
throw new Error("The user trying to add a setting dose not have the correct permissions");
|
||||
}
|
||||
};
|
||||
141
lstV2/server/services/server/route/modules/addModule.ts
Normal file
141
lstV2/server/services/server/route/modules/addModule.ts
Normal file
@@ -0,0 +1,141 @@
|
||||
import { z, createRoute, OpenAPIHono } from "@hono/zod-openapi";
|
||||
import type { User } from "../../../../types/users.js";
|
||||
import { verify } from "hono/jwt";
|
||||
import { authMiddleware } from "../../../auth/middleware/authMiddleware.js";
|
||||
import { addModule } from "../../controller/module/addModule.js";
|
||||
import { apiHit } from "../../../../globalUtils/apiHits.js";
|
||||
|
||||
// Define the response schema
|
||||
const responseSchema = z.object({
|
||||
message: z.string().optional(),
|
||||
module_id: z
|
||||
.string()
|
||||
.openapi({ example: "6c922c6c-7de3-4ec4-acb0-f068abdc" })
|
||||
.optional(),
|
||||
name: z.string().openapi({ example: "Production" }).optional(),
|
||||
active: z.boolean().openapi({ example: true }).optional(),
|
||||
roles: z
|
||||
.string()
|
||||
.openapi({ example: `["viewer","technician"]` })
|
||||
.optional(),
|
||||
});
|
||||
|
||||
const app = new OpenAPIHono();
|
||||
|
||||
// const ParamsSchema = z.object({
|
||||
// id: z
|
||||
// .string()
|
||||
// .min(3)
|
||||
// .openapi({
|
||||
// param: {
|
||||
// name: "id",
|
||||
// in: "path",
|
||||
// },
|
||||
// example: "1212121",
|
||||
// }),
|
||||
// });
|
||||
|
||||
const AddModule = z.object({
|
||||
name: z.string().openapi({ example: "production" }),
|
||||
});
|
||||
|
||||
app.openapi(
|
||||
createRoute({
|
||||
tags: ["server"],
|
||||
summary: "Adds a new module",
|
||||
method: "post",
|
||||
path: "/modules",
|
||||
middleware: authMiddleware,
|
||||
request: {
|
||||
body: {
|
||||
content: {
|
||||
"application/json": { schema: AddModule },
|
||||
},
|
||||
},
|
||||
},
|
||||
responses: {
|
||||
200: {
|
||||
content: {
|
||||
"application/json": { schema: responseSchema },
|
||||
},
|
||||
description: "Response message",
|
||||
},
|
||||
400: {
|
||||
content: {
|
||||
"application/json": {
|
||||
schema: z.object({
|
||||
message: z
|
||||
.string()
|
||||
.optional()
|
||||
.openapi({ example: "Internal Server error" }),
|
||||
}),
|
||||
},
|
||||
},
|
||||
description: "Internal Server Error",
|
||||
},
|
||||
401: {
|
||||
content: {
|
||||
"application/json": {
|
||||
schema: z.object({
|
||||
message: z
|
||||
.string()
|
||||
.optional()
|
||||
.openapi({ example: "Unauthenticated" }),
|
||||
}),
|
||||
},
|
||||
},
|
||||
description: "Unauthorized",
|
||||
},
|
||||
500: {
|
||||
content: {
|
||||
"application/json": {
|
||||
schema: z.object({
|
||||
message: z
|
||||
.string()
|
||||
.optional()
|
||||
.openapi({ example: "Internal Server error" }),
|
||||
}),
|
||||
},
|
||||
},
|
||||
description: "Internal Server Error",
|
||||
},
|
||||
},
|
||||
}),
|
||||
async (c) => {
|
||||
//const {id} = c.req.valid("param");
|
||||
|
||||
// make sure we have a vaid user being accessed thats really logged in
|
||||
const authHeader = c.req.header("Authorization");
|
||||
|
||||
const token = authHeader?.split("Bearer ")[1] || "";
|
||||
let user: User;
|
||||
|
||||
try {
|
||||
const payload = await verify(token, process.env.JWT_SECRET!);
|
||||
user = payload.user as User;
|
||||
} catch (error) {
|
||||
return c.json({ message: "Unauthorized" }, 401);
|
||||
}
|
||||
|
||||
// now pass all the data over to update the user info
|
||||
try {
|
||||
const data = await c?.req.json();
|
||||
apiHit(c, { endpoint: `/modules`, lastBody: data });
|
||||
await addModule(data, user.user_id ?? "");
|
||||
return c.json(
|
||||
{ success: true, message: "New setting was added" },
|
||||
200
|
||||
);
|
||||
} catch (error) {
|
||||
return c.json(
|
||||
{
|
||||
message: "Please make sure you are not missing your data.",
|
||||
error,
|
||||
},
|
||||
400
|
||||
);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
export default app;
|
||||
75
lstV2/server/services/server/route/modules/getModules.ts
Normal file
75
lstV2/server/services/server/route/modules/getModules.ts
Normal file
@@ -0,0 +1,75 @@
|
||||
import { z, createRoute, OpenAPIHono } from "@hono/zod-openapi";
|
||||
import { modules } from "../../../../../database/schema/modules.js";
|
||||
import { db } from "../../../../../database/dbclient.js";
|
||||
import { desc } from "drizzle-orm";
|
||||
import { apiHit } from "../../../../globalUtils/apiHits.js";
|
||||
|
||||
// Define the request body schema
|
||||
const requestSchema = z.object({
|
||||
ip: z.string().optional(),
|
||||
endpoint: z.string().optional(),
|
||||
action: z.string().optional(),
|
||||
stats: z.string().optional(),
|
||||
});
|
||||
|
||||
// Define the response schema
|
||||
const responseSchema = z.object({
|
||||
message: z.string().optional(),
|
||||
module_id: z
|
||||
.string()
|
||||
.openapi({ example: "6c922c6c-7de3-4ec4-acb0-f068abdc" })
|
||||
.optional(),
|
||||
name: z.string().openapi({ example: "Production" }).optional(),
|
||||
active: z.boolean().openapi({ example: true }).optional(),
|
||||
roles: z
|
||||
.string()
|
||||
.openapi({ example: `["viewer","technician"]` })
|
||||
.optional(),
|
||||
});
|
||||
|
||||
const app = new OpenAPIHono();
|
||||
|
||||
app.openapi(
|
||||
createRoute({
|
||||
tags: ["server"],
|
||||
summary: "Returns all modules in the server",
|
||||
method: "get",
|
||||
path: "/modules",
|
||||
responses: {
|
||||
200: {
|
||||
content: {
|
||||
"application/json": { schema: responseSchema },
|
||||
},
|
||||
description: "Response message",
|
||||
},
|
||||
},
|
||||
}),
|
||||
async (c) => {
|
||||
//console.log("system modules");
|
||||
apiHit(c, { endpoint: `/getmodules`, action: "just modules" });
|
||||
let module: any = [];
|
||||
try {
|
||||
module = await db.select().from(modules).orderBy(modules.name); // .where(eq(modules.active, true));
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
module = [];
|
||||
}
|
||||
|
||||
// parse the roles
|
||||
const updateModules = module.map((m: any) => {
|
||||
if (m.roles) {
|
||||
return { ...m, roles: m?.roles };
|
||||
}
|
||||
return m;
|
||||
}); //JSON.parse(module[0]?.roles);
|
||||
|
||||
// Return response with the received data
|
||||
|
||||
return c.json({
|
||||
message: `All active modules`,
|
||||
data: module,
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
export default app;
|
||||
78
lstV2/server/services/server/route/modules/getSubModules.ts
Normal file
78
lstV2/server/services/server/route/modules/getSubModules.ts
Normal file
@@ -0,0 +1,78 @@
|
||||
import { z, createRoute, OpenAPIHono } from "@hono/zod-openapi";
|
||||
import { modules } from "../../../../../database/schema/modules.js";
|
||||
import { db } from "../../../../../database/dbclient.js";
|
||||
import { subModules } from "../../../../../database/schema/subModules.js";
|
||||
import { apiHit } from "../../../../globalUtils/apiHits.js";
|
||||
|
||||
// Define the request body schema
|
||||
const requestSchema = z.object({
|
||||
ip: z.string().optional(),
|
||||
endpoint: z.string().optional(),
|
||||
action: z.string().optional(),
|
||||
stats: z.string().optional(),
|
||||
});
|
||||
|
||||
// Define the response schema
|
||||
const responseSchema = z.object({
|
||||
message: z.string().optional(),
|
||||
module_id: z
|
||||
.string()
|
||||
.openapi({ example: "6c922c6c-7de3-4ec4-acb0-f068abdc" })
|
||||
.optional(),
|
||||
name: z.string().openapi({ example: "Production" }).optional(),
|
||||
active: z.boolean().openapi({ example: true }).optional(),
|
||||
roles: z
|
||||
.string()
|
||||
.openapi({ example: `["viewer","technician"]` })
|
||||
.optional(),
|
||||
});
|
||||
|
||||
const app = new OpenAPIHono();
|
||||
|
||||
app.openapi(
|
||||
createRoute({
|
||||
tags: ["server"],
|
||||
summary: "Returns all submodules in the server",
|
||||
method: "get",
|
||||
path: "/submodules",
|
||||
responses: {
|
||||
200: {
|
||||
content: {
|
||||
"application/json": { schema: responseSchema },
|
||||
},
|
||||
description: "Response message",
|
||||
},
|
||||
},
|
||||
}),
|
||||
async (c) => {
|
||||
//console.log("system modules");
|
||||
apiHit(c, { endpoint: `/submodules` });
|
||||
let module: any = [];
|
||||
try {
|
||||
module = await db
|
||||
.select()
|
||||
.from(subModules)
|
||||
.orderBy(subModules.name); // .where(eq(modules.active, true));
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
module = [];
|
||||
}
|
||||
|
||||
// parse the roles
|
||||
const updateModules = module.map((m: any) => {
|
||||
if (m.roles) {
|
||||
return { ...m, roles: m?.roles };
|
||||
}
|
||||
return m;
|
||||
}); //JSON.parse(module[0]?.roles);
|
||||
|
||||
// Return response with the received data
|
||||
|
||||
return c.json({
|
||||
message: `All active submodules`,
|
||||
data: module,
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
export default app;
|
||||
142
lstV2/server/services/server/route/modules/updateModules.ts
Normal file
142
lstV2/server/services/server/route/modules/updateModules.ts
Normal file
@@ -0,0 +1,142 @@
|
||||
import { z, createRoute, OpenAPIHono } from "@hono/zod-openapi";
|
||||
import type { User } from "../../../../types/users.js";
|
||||
import { verify } from "hono/jwt";
|
||||
import { updateModule } from "../../controller/module/updateModule.js";
|
||||
import { authMiddleware } from "../../../auth/middleware/authMiddleware.js";
|
||||
import { apiHit } from "../../../../globalUtils/apiHits.js";
|
||||
|
||||
// Define the response schema
|
||||
const responseSchema = z.object({
|
||||
message: z.string().optional(),
|
||||
module_id: z
|
||||
.string()
|
||||
.openapi({ example: "6c922c6c-7de3-4ec4-acb0-f068abdc" })
|
||||
.optional(),
|
||||
name: z.string().openapi({ example: "Production" }).optional(),
|
||||
active: z.boolean().openapi({ example: true }).optional(),
|
||||
roles: z
|
||||
.string()
|
||||
.openapi({ example: `["viewer","technician"]` })
|
||||
.optional(),
|
||||
});
|
||||
|
||||
const app = new OpenAPIHono();
|
||||
|
||||
const ParamsSchema = z.object({
|
||||
id: z
|
||||
.string()
|
||||
.min(3)
|
||||
.openapi({
|
||||
param: {
|
||||
name: "id",
|
||||
in: "path",
|
||||
},
|
||||
example: "1212121",
|
||||
}),
|
||||
});
|
||||
|
||||
app.openapi(
|
||||
createRoute({
|
||||
tags: ["server"],
|
||||
summary: "Updates module",
|
||||
method: "patch",
|
||||
path: "/modules/{id}",
|
||||
middleware: authMiddleware,
|
||||
request: {
|
||||
params: ParamsSchema,
|
||||
},
|
||||
responses: {
|
||||
200: {
|
||||
content: {
|
||||
"application/json": { schema: responseSchema },
|
||||
},
|
||||
description: "Response message",
|
||||
},
|
||||
400: {
|
||||
content: {
|
||||
"application/json": {
|
||||
schema: z.object({
|
||||
message: z
|
||||
.string()
|
||||
.optional()
|
||||
.openapi({ example: "Internal Server error" }),
|
||||
}),
|
||||
},
|
||||
},
|
||||
description: "Internal Server Error",
|
||||
},
|
||||
401: {
|
||||
content: {
|
||||
"application/json": {
|
||||
schema: z.object({
|
||||
message: z
|
||||
.string()
|
||||
.optional()
|
||||
.openapi({ example: "Unauthenticated" }),
|
||||
}),
|
||||
},
|
||||
},
|
||||
description: "Unauthorized",
|
||||
},
|
||||
500: {
|
||||
content: {
|
||||
"application/json": {
|
||||
schema: z.object({
|
||||
message: z
|
||||
.string()
|
||||
.optional()
|
||||
.openapi({ example: "Internal Server error" }),
|
||||
}),
|
||||
},
|
||||
},
|
||||
description: "Internal Server Error",
|
||||
},
|
||||
},
|
||||
}),
|
||||
async (c) => {
|
||||
const { id } = c.req.valid("param");
|
||||
|
||||
// make sure we have a vaid user being accessed thats really logged in
|
||||
const authHeader = c.req.header("Authorization");
|
||||
|
||||
const token = authHeader?.split("Bearer ")[1] || "";
|
||||
let user: User;
|
||||
|
||||
try {
|
||||
const payload = await verify(token, process.env.JWT_SECRET!);
|
||||
user = payload.user as User;
|
||||
} catch (error) {
|
||||
return c.json({ message: "Unauthorized" }, 401);
|
||||
}
|
||||
|
||||
// now pass all the data over to update the user info
|
||||
try {
|
||||
const data = await c?.req.json();
|
||||
apiHit(c, {
|
||||
endpoint: `/modules/${id}`,
|
||||
action: "just update modules",
|
||||
lastBody: data,
|
||||
});
|
||||
await updateModule(data, id ?? "");
|
||||
return c.json(
|
||||
{ success: true, message: "New setting was added" },
|
||||
200
|
||||
);
|
||||
} catch (error) {
|
||||
return c.json(
|
||||
{
|
||||
message: "Please make sure you are not missing your data.",
|
||||
error,
|
||||
},
|
||||
400
|
||||
);
|
||||
}
|
||||
|
||||
return c.json({
|
||||
message: `Module has been updated`,
|
||||
data: id,
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
export default app;
|
||||
140
lstV2/server/services/server/route/modules/updateSubModules.ts
Normal file
140
lstV2/server/services/server/route/modules/updateSubModules.ts
Normal file
@@ -0,0 +1,140 @@
|
||||
import { z, createRoute, OpenAPIHono } from "@hono/zod-openapi";
|
||||
import type { User } from "../../../../types/users.js";
|
||||
import { verify } from "hono/jwt";
|
||||
|
||||
import { authMiddleware } from "../../../auth/middleware/authMiddleware.js";
|
||||
import { updateSubModule } from "../../controller/module/updateSubModule.js";
|
||||
import { apiHit } from "../../../../globalUtils/apiHits.js";
|
||||
|
||||
// Define the response schema
|
||||
const responseSchema = z.object({
|
||||
message: z.string().optional(),
|
||||
module_id: z
|
||||
.string()
|
||||
.openapi({ example: "6c922c6c-7de3-4ec4-acb0-f068abdc" })
|
||||
.optional(),
|
||||
name: z.string().openapi({ example: "Production" }).optional(),
|
||||
active: z.boolean().openapi({ example: true }).optional(),
|
||||
roles: z
|
||||
.string()
|
||||
.openapi({ example: `["viewer","technician"]` })
|
||||
.optional(),
|
||||
});
|
||||
|
||||
const app = new OpenAPIHono();
|
||||
|
||||
const ParamsSchema = z.object({
|
||||
id: z
|
||||
.string()
|
||||
.min(3)
|
||||
.openapi({
|
||||
param: {
|
||||
name: "id",
|
||||
in: "path",
|
||||
},
|
||||
example: "1212121",
|
||||
}),
|
||||
});
|
||||
|
||||
app.openapi(
|
||||
createRoute({
|
||||
tags: ["server"],
|
||||
summary: "Updates submodule",
|
||||
method: "patch",
|
||||
path: "/submodules/{id}",
|
||||
middleware: authMiddleware,
|
||||
request: {
|
||||
params: ParamsSchema,
|
||||
},
|
||||
responses: {
|
||||
200: {
|
||||
content: {
|
||||
"application/json": { schema: responseSchema },
|
||||
},
|
||||
description: "Response message",
|
||||
},
|
||||
400: {
|
||||
content: {
|
||||
"application/json": {
|
||||
schema: z.object({
|
||||
message: z
|
||||
.string()
|
||||
.optional()
|
||||
.openapi({ example: "Internal Server error" }),
|
||||
}),
|
||||
},
|
||||
},
|
||||
description: "Internal Server Error",
|
||||
},
|
||||
401: {
|
||||
content: {
|
||||
"application/json": {
|
||||
schema: z.object({
|
||||
message: z
|
||||
.string()
|
||||
.optional()
|
||||
.openapi({ example: "Unauthenticated" }),
|
||||
}),
|
||||
},
|
||||
},
|
||||
description: "Unauthorized",
|
||||
},
|
||||
500: {
|
||||
content: {
|
||||
"application/json": {
|
||||
schema: z.object({
|
||||
message: z
|
||||
.string()
|
||||
.optional()
|
||||
.openapi({ example: "Internal Server error" }),
|
||||
}),
|
||||
},
|
||||
},
|
||||
description: "Internal Server Error",
|
||||
},
|
||||
},
|
||||
}),
|
||||
async (c) => {
|
||||
const { id } = c.req.valid("param");
|
||||
|
||||
// make sure we have a vaid user being accessed thats really logged in
|
||||
const authHeader = c.req.header("Authorization");
|
||||
|
||||
const token = authHeader?.split("Bearer ")[1] || "";
|
||||
let user: User;
|
||||
|
||||
try {
|
||||
const payload = await verify(token, process.env.JWT_SECRET!);
|
||||
user = payload.user as User;
|
||||
} catch (error) {
|
||||
return c.json({ message: "Unauthorized" }, 401);
|
||||
}
|
||||
|
||||
// now pass all the data over to update the user info
|
||||
try {
|
||||
const data = await c?.req.json();
|
||||
apiHit(c, {
|
||||
endpoint: `/submodules/${id}`,
|
||||
action: "just updates submodules",
|
||||
lastBody: data,
|
||||
});
|
||||
await updateSubModule(data, id ?? "");
|
||||
return c.json({ success: true, message: "Module Updated" }, 200);
|
||||
} catch (error) {
|
||||
return c.json(
|
||||
{
|
||||
message: "Please make sure you are not missing your data.",
|
||||
error,
|
||||
},
|
||||
400
|
||||
);
|
||||
}
|
||||
|
||||
return c.json({
|
||||
message: `Module has been updated`,
|
||||
data: id,
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
export default app;
|
||||
77
lstV2/server/services/server/route/servers/getServers.ts
Normal file
77
lstV2/server/services/server/route/servers/getServers.ts
Normal file
@@ -0,0 +1,77 @@
|
||||
import { z, createRoute, OpenAPIHono } from "@hono/zod-openapi";
|
||||
import { db } from "../../../../../database/dbclient.js";
|
||||
import { authMiddleware } from "../../../auth/middleware/authMiddleware.js";
|
||||
import { serverData } from "../../../../../database/schema/serverData.js";
|
||||
import { eq } from "drizzle-orm";
|
||||
import { apiHit } from "../../../../globalUtils/apiHits.js";
|
||||
|
||||
// Define the request body schema
|
||||
const requestSchema = z.object({
|
||||
ip: z.string().optional(),
|
||||
endpoint: z.string().optional(),
|
||||
action: z.string().optional(),
|
||||
stats: z.string().optional(),
|
||||
});
|
||||
|
||||
// Define the response schema
|
||||
const responseSchema = z.object({
|
||||
message: z.string().optional(),
|
||||
module_id: z
|
||||
.string()
|
||||
.openapi({ example: "6c922c6c-7de3-4ec4-acb0-f068abdc" })
|
||||
.optional(),
|
||||
name: z.string().openapi({ example: "Production" }).optional(),
|
||||
active: z.boolean().openapi({ example: true }).optional(),
|
||||
roles: z
|
||||
.string()
|
||||
.openapi({ example: `["viewer","technician"]` })
|
||||
.optional(),
|
||||
});
|
||||
|
||||
const app = new OpenAPIHono();
|
||||
|
||||
app.openapi(
|
||||
createRoute({
|
||||
tags: ["server"],
|
||||
summary: "Returns all serverData on the server",
|
||||
method: "get",
|
||||
path: "/servers",
|
||||
middleware: authMiddleware,
|
||||
responses: {
|
||||
200: {
|
||||
content: {
|
||||
"application/json": { schema: responseSchema },
|
||||
},
|
||||
description: "Response message",
|
||||
},
|
||||
},
|
||||
}),
|
||||
async (c) => {
|
||||
//console.log("system modules");
|
||||
apiHit(c, { endpoint: `/servers` });
|
||||
let servers: any = [];
|
||||
try {
|
||||
servers = await db
|
||||
.select()
|
||||
.from(serverData)
|
||||
.where(eq(serverData.active, true));
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
servers = [];
|
||||
}
|
||||
|
||||
// sort the servers by there name
|
||||
servers = servers.sort((a: any, b: any) =>
|
||||
a.sName.localeCompare(b.sName)
|
||||
);
|
||||
|
||||
// Return response with the received data
|
||||
|
||||
return c.json({
|
||||
message: `All active modules`,
|
||||
data: servers,
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
export default app;
|
||||
72
lstV2/server/services/server/route/servers/serverContorl.ts
Normal file
72
lstV2/server/services/server/route/servers/serverContorl.ts
Normal file
@@ -0,0 +1,72 @@
|
||||
import { z, createRoute, OpenAPIHono } from "@hono/zod-openapi";
|
||||
import { authMiddleware } from "../../../auth/middleware/authMiddleware.js";
|
||||
import { responses } from "../../../../globalUtils/routeDefs/responses.js";
|
||||
import { tryCatch } from "../../../../globalUtils/tryCatch.js";
|
||||
import hasCorrectRole from "../../../auth/middleware/roleCheck.js";
|
||||
import { serviceControl } from "../../controller/server/serviceControl.js";
|
||||
import { apiHit } from "../../../../globalUtils/apiHits.js";
|
||||
import { simpleRateLimit } from "../../../../globalUtils/rateLimiter.js";
|
||||
|
||||
// Define the request body schema
|
||||
const requestSchema = z.object({
|
||||
processType: z.string().openapi({ example: "restart" }),
|
||||
plantToken: z.string().openapi({ example: "usday1" }),
|
||||
remote: z.string().optional().openapi({ example: "true" }),
|
||||
});
|
||||
|
||||
const app = new OpenAPIHono();
|
||||
|
||||
app.openapi(
|
||||
createRoute({
|
||||
tags: ["server"],
|
||||
summary: "Starts, Stops, Restarts the server.",
|
||||
method: "post",
|
||||
path: "/serviceprocess",
|
||||
middleware: [
|
||||
authMiddleware,
|
||||
hasCorrectRole(["systemAdmin"], "admin"),
|
||||
simpleRateLimit,
|
||||
],
|
||||
|
||||
request: {
|
||||
body: {
|
||||
content: {
|
||||
"application/json": { schema: requestSchema },
|
||||
},
|
||||
},
|
||||
},
|
||||
responses: responses(),
|
||||
}),
|
||||
async (c) => {
|
||||
const { data, error } = await tryCatch(c.req.json());
|
||||
//apiHit(c, { endpoint: "/bookin", lastBody: data });
|
||||
if (error) {
|
||||
return c.json({
|
||||
success: false,
|
||||
message: "Error with the request body.",
|
||||
});
|
||||
}
|
||||
|
||||
const { data: process, error: processError } = await tryCatch(
|
||||
serviceControl(
|
||||
data.plantToken,
|
||||
data.processType!,
|
||||
data.remote ?? ""
|
||||
)
|
||||
);
|
||||
|
||||
if (processError) {
|
||||
return c.json({
|
||||
success: false,
|
||||
message: "There was an error running the service type",
|
||||
});
|
||||
}
|
||||
|
||||
return c.json({
|
||||
success: true,
|
||||
message: `The service was ${data.processType}`,
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
export default app;
|
||||
72
lstV2/server/services/server/route/settings/addSetting.ts
Normal file
72
lstV2/server/services/server/route/settings/addSetting.ts
Normal file
@@ -0,0 +1,72 @@
|
||||
import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi";
|
||||
import { addSetting } from "../../controller/settings/addSetting.js";
|
||||
|
||||
import { verify } from "hono/jwt";
|
||||
import type { User } from "../../../../types/users.js";
|
||||
import { authMiddleware } from "../../../auth/middleware/authMiddleware.js";
|
||||
import { responses } from "../../../../globalUtils/routeDefs/responses.js";
|
||||
import { apiHit } from "../../../../globalUtils/apiHits.js";
|
||||
|
||||
const app = new OpenAPIHono();
|
||||
|
||||
const AddSetting = z.object({
|
||||
name: z.string().openapi({ example: "server" }),
|
||||
value: z.string().openapi({ example: "localhost" }),
|
||||
description: z
|
||||
.string()
|
||||
.openapi({ example: "The server we are going to connect to" }),
|
||||
roles: z.string().openapi({ example: "admin" }),
|
||||
module: z.string().openapi({ example: "production" }),
|
||||
});
|
||||
|
||||
app.openapi(
|
||||
createRoute({
|
||||
tags: ["server:settings"],
|
||||
summary: "Add Setting",
|
||||
method: "post",
|
||||
path: "/settings",
|
||||
middleware: authMiddleware,
|
||||
request: {
|
||||
body: {
|
||||
content: {
|
||||
"application/json": { schema: AddSetting },
|
||||
},
|
||||
},
|
||||
},
|
||||
responses: responses(),
|
||||
}),
|
||||
async (c) => {
|
||||
// make sure we have a vaid user being accessed thats really logged in
|
||||
const authHeader = c.req.header("Authorization");
|
||||
|
||||
const token = authHeader?.split("Bearer ")[1] || "";
|
||||
let user: User;
|
||||
|
||||
try {
|
||||
const payload = await verify(token, process.env.JWT_SECRET!);
|
||||
user = payload.user as User;
|
||||
} catch (error) {
|
||||
return c.json({ message: "Unauthorized" }, 401);
|
||||
}
|
||||
|
||||
// now pass all the data over to update the user info
|
||||
try {
|
||||
const data = await c?.req.json();
|
||||
apiHit(c, { endpoint: `/addsettings`, lastBody: data });
|
||||
await addSetting(data, user.user_id ?? "");
|
||||
return c.json(
|
||||
{ success: true, message: "New setting was added" },
|
||||
200
|
||||
);
|
||||
} catch (error) {
|
||||
return c.json(
|
||||
{
|
||||
message: "Please make sure you are not missing your data.",
|
||||
error,
|
||||
},
|
||||
400
|
||||
);
|
||||
}
|
||||
}
|
||||
);
|
||||
export default app;
|
||||
29
lstV2/server/services/server/route/settings/deleteSetting.ts
Normal file
29
lstV2/server/services/server/route/settings/deleteSetting.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import {createRoute, OpenAPIHono, z} from "@hono/zod-openapi";
|
||||
|
||||
const app = new OpenAPIHono();
|
||||
|
||||
app.openapi(
|
||||
createRoute({
|
||||
tags: ["server:settings"],
|
||||
summary: "Returns all modules in the server",
|
||||
method: "delete",
|
||||
path: "/settings",
|
||||
responses: {
|
||||
200: {
|
||||
content: {
|
||||
"application/json": {
|
||||
schema: z.object({
|
||||
success: z.boolean().openapi({example: true}),
|
||||
message: z.string().openapi({example: "Starter"}),
|
||||
}),
|
||||
},
|
||||
},
|
||||
description: "Response message",
|
||||
},
|
||||
},
|
||||
}),
|
||||
async (c) => {
|
||||
return c.json({success: true, message: "Example"}, 200);
|
||||
}
|
||||
);
|
||||
export default app;
|
||||
87
lstV2/server/services/server/route/settings/getSettings.ts
Normal file
87
lstV2/server/services/server/route/settings/getSettings.ts
Normal file
@@ -0,0 +1,87 @@
|
||||
import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi";
|
||||
|
||||
import type { User } from "../../../../types/users.js";
|
||||
import { verify } from "hono/jwt";
|
||||
import { getSettings } from "../../controller/settings/getSettings.js";
|
||||
import { apiHit } from "../../../../globalUtils/apiHits.js";
|
||||
|
||||
const app = new OpenAPIHono();
|
||||
|
||||
app.openapi(
|
||||
createRoute({
|
||||
tags: ["server:settings"],
|
||||
summary: "Returns all settings based on your permissions",
|
||||
method: "get",
|
||||
path: "/settings",
|
||||
responses: {
|
||||
200: {
|
||||
content: {
|
||||
"application/json": {
|
||||
schema: z.object({
|
||||
success: z.boolean().openapi({ example: true }),
|
||||
message: z.string().openapi({ example: "Starter" }),
|
||||
}),
|
||||
},
|
||||
},
|
||||
description: "Response message",
|
||||
},
|
||||
400: {
|
||||
content: {
|
||||
"application/json": {
|
||||
schema: z.object({
|
||||
message: z
|
||||
.string()
|
||||
.optional()
|
||||
.openapi({ example: "Internal Server error" }),
|
||||
}),
|
||||
},
|
||||
},
|
||||
description: "Internal Server Error",
|
||||
},
|
||||
401: {
|
||||
content: {
|
||||
"application/json": {
|
||||
schema: z.object({
|
||||
message: z
|
||||
.string()
|
||||
.optional()
|
||||
.openapi({ example: "Unauthenticated" }),
|
||||
}),
|
||||
},
|
||||
},
|
||||
description: "Unauthorized",
|
||||
},
|
||||
500: {
|
||||
content: {
|
||||
"application/json": {
|
||||
schema: z.object({
|
||||
message: z
|
||||
.string()
|
||||
.optional()
|
||||
.openapi({ example: "Internal Server error" }),
|
||||
}),
|
||||
},
|
||||
},
|
||||
description: "Internal Server Error",
|
||||
},
|
||||
},
|
||||
}),
|
||||
async (c) => {
|
||||
// make sure we have a vaid user being accessed thats really logged in
|
||||
apiHit(c, { endpoint: `/settings` });
|
||||
// now pass all the data over to update the user info
|
||||
try {
|
||||
const data = await getSettings();
|
||||
return c.json(
|
||||
{ success: true, message: "All Current Settings", data },
|
||||
200
|
||||
);
|
||||
} catch (error) {
|
||||
return c.json(
|
||||
{ message: "There was an error getting the settings.", error },
|
||||
400
|
||||
);
|
||||
}
|
||||
}
|
||||
);
|
||||
export default app;
|
||||
129
lstV2/server/services/server/route/settings/updateSetting.ts
Normal file
129
lstV2/server/services/server/route/settings/updateSetting.ts
Normal file
@@ -0,0 +1,129 @@
|
||||
import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi";
|
||||
import type { User } from "../../../../types/users.js";
|
||||
import { verify } from "hono/jwt";
|
||||
import { updateSetting } from "../../controller/settings/updateSetting.js";
|
||||
import { apiHit } from "../../../../globalUtils/apiHits.js";
|
||||
|
||||
const app = new OpenAPIHono();
|
||||
|
||||
const UpdateSetting = z.object({
|
||||
name: z.string().openapi({ example: "server" }),
|
||||
value: z.string().openapi({ example: "localhost" }),
|
||||
});
|
||||
|
||||
app.openapi(
|
||||
createRoute({
|
||||
tags: ["server:settings"],
|
||||
summary: "Updates A setting",
|
||||
method: "patch",
|
||||
path: "/settings",
|
||||
request: {
|
||||
body: {
|
||||
content: {
|
||||
"application/json": { schema: UpdateSetting },
|
||||
},
|
||||
},
|
||||
},
|
||||
responses: {
|
||||
200: {
|
||||
content: {
|
||||
"application/json": {
|
||||
schema: z.object({
|
||||
success: z.boolean().openapi({ example: true }),
|
||||
message: z.string().openapi({ example: "Starter" }),
|
||||
}),
|
||||
},
|
||||
},
|
||||
description: "Response message",
|
||||
},
|
||||
400: {
|
||||
content: {
|
||||
"application/json": {
|
||||
schema: z.object({
|
||||
message: z
|
||||
.string()
|
||||
.optional()
|
||||
.openapi({ example: "Internal Server error" }),
|
||||
}),
|
||||
},
|
||||
},
|
||||
description: "Internal Server Error",
|
||||
},
|
||||
401: {
|
||||
content: {
|
||||
"application/json": {
|
||||
schema: z.object({
|
||||
message: z
|
||||
.string()
|
||||
.optional()
|
||||
.openapi({ example: "Unauthenticated" }),
|
||||
}),
|
||||
},
|
||||
},
|
||||
description: "Unauthorized",
|
||||
},
|
||||
500: {
|
||||
content: {
|
||||
"application/json": {
|
||||
schema: z.object({
|
||||
message: z
|
||||
.string()
|
||||
.optional()
|
||||
.openapi({ example: "Internal Server error" }),
|
||||
}),
|
||||
},
|
||||
},
|
||||
description: "Internal Server Error",
|
||||
},
|
||||
},
|
||||
}),
|
||||
async (c) => {
|
||||
// make sure we have a vaid user being accessed thats really logged in
|
||||
const authHeader = c.req.header("Authorization");
|
||||
|
||||
if (authHeader?.includes("Basic")) {
|
||||
return c.json(
|
||||
{
|
||||
message:
|
||||
"You are a Basic user! Please login to get a token",
|
||||
},
|
||||
401
|
||||
);
|
||||
}
|
||||
|
||||
if (!authHeader) {
|
||||
return c.json({ message: "Unauthorized" }, 401);
|
||||
}
|
||||
|
||||
const token = authHeader?.split("Bearer ")[1] || "";
|
||||
let user: User;
|
||||
|
||||
try {
|
||||
const payload = await verify(token, process.env.JWT_SECRET!);
|
||||
user = payload.user as User;
|
||||
} catch (error) {
|
||||
return c.json({ message: "Unauthorized" }, 401);
|
||||
}
|
||||
|
||||
// now pass all the data over to update the user info
|
||||
try {
|
||||
const data = await c?.req.json();
|
||||
apiHit(c, { endpoint: `/updatesettings`, lastBody: data });
|
||||
await updateSetting(data, user.user_id ?? "");
|
||||
return c.json(
|
||||
{
|
||||
success: true,
|
||||
message: "The Setting was just updated",
|
||||
data,
|
||||
},
|
||||
200
|
||||
);
|
||||
} catch (error) {
|
||||
return c.json(
|
||||
{ message: "There was an error updating the settings.", error },
|
||||
400
|
||||
);
|
||||
}
|
||||
}
|
||||
);
|
||||
export default app;
|
||||
112
lstV2/server/services/server/route/updates/updateServer.ts
Normal file
112
lstV2/server/services/server/route/updates/updateServer.ts
Normal file
@@ -0,0 +1,112 @@
|
||||
import { z, createRoute, OpenAPIHono } from "@hono/zod-openapi";
|
||||
import { authMiddleware } from "../../../auth/middleware/authMiddleware.js";
|
||||
import {
|
||||
processAllServers,
|
||||
updateServer,
|
||||
} from "../../../../scripts/updateServers.js";
|
||||
import { apiHit } from "../../../../globalUtils/apiHits.js";
|
||||
|
||||
// Define the request body schema
|
||||
const requestSchema = z.object({
|
||||
ip: z.string().optional(),
|
||||
endpoint: z.string().optional(),
|
||||
action: z.string().optional(),
|
||||
stats: z.string().optional(),
|
||||
});
|
||||
|
||||
// Define the response schema
|
||||
const responseSchema = z.object({
|
||||
message: z.string().optional(),
|
||||
module_id: z
|
||||
.string()
|
||||
.openapi({ example: "6c922c6c-7de3-4ec4-acb0-f068abdc" })
|
||||
.optional(),
|
||||
name: z.string().openapi({ example: "Production" }).optional(),
|
||||
active: z.boolean().openapi({ example: true }).optional(),
|
||||
roles: z
|
||||
.string()
|
||||
.openapi({ example: `["viewer","technician"]` })
|
||||
.optional(),
|
||||
});
|
||||
|
||||
const ParamsSchema = z.object({
|
||||
server: z
|
||||
.string()
|
||||
.min(3)
|
||||
.openapi({
|
||||
param: {
|
||||
name: "server",
|
||||
in: "path",
|
||||
},
|
||||
example: "usbow1",
|
||||
}),
|
||||
});
|
||||
const UpdateServer = z.object({
|
||||
devDir: z.string().openapi({ example: "C:\\something\\Something" }),
|
||||
all: z.boolean().optional().openapi({ example: true }),
|
||||
});
|
||||
|
||||
const app = new OpenAPIHono();
|
||||
|
||||
app.openapi(
|
||||
createRoute({
|
||||
tags: ["server"],
|
||||
summary: "Updates server(s)",
|
||||
method: "post",
|
||||
path: "/update/:server",
|
||||
middleware: authMiddleware,
|
||||
request: {
|
||||
params: ParamsSchema,
|
||||
body: {
|
||||
content: {
|
||||
"application/json": { schema: UpdateServer },
|
||||
},
|
||||
},
|
||||
},
|
||||
responses: {
|
||||
200: {
|
||||
content: {
|
||||
"application/json": { schema: responseSchema },
|
||||
},
|
||||
description: "Response message",
|
||||
},
|
||||
400: {
|
||||
content: {
|
||||
"application/json": { schema: responseSchema },
|
||||
},
|
||||
description: "Response message",
|
||||
},
|
||||
},
|
||||
}),
|
||||
async (c) => {
|
||||
const { server } = c.req.valid("param");
|
||||
const body = await c.req.json();
|
||||
apiHit(c, { endpoint: `/update/${server}`, lastBody: body });
|
||||
// fire off the update we wont make this way
|
||||
if (body.all) {
|
||||
const update = await processAllServers(body.devDir);
|
||||
return c.json({
|
||||
success: update?.success ?? false,
|
||||
message: update?.message,
|
||||
data: [],
|
||||
});
|
||||
}
|
||||
try {
|
||||
const update = await updateServer(body.devDir, server);
|
||||
|
||||
return c.json({
|
||||
success: update?.success ?? false,
|
||||
message: update?.message,
|
||||
data: [],
|
||||
});
|
||||
} catch (error) {
|
||||
return c.json({
|
||||
success: false,
|
||||
message: `${server} Encountered an ${error}`,
|
||||
data: [],
|
||||
});
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
export default app;
|
||||
60
lstV2/server/services/server/systemServer.ts
Normal file
60
lstV2/server/services/server/systemServer.ts
Normal file
@@ -0,0 +1,60 @@
|
||||
import { OpenAPIHono } from "@hono/zod-openapi";
|
||||
import { areModulesIn } from "./utils/moduleCheck.js";
|
||||
|
||||
// routes
|
||||
import getModules from "./route/modules/getModules.js";
|
||||
import updateModule from "./route/modules/updateModules.js";
|
||||
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 getServers from "./route/servers/getServers.js";
|
||||
import updateServer from "./route/updates/updateServer.js";
|
||||
import { setPerms } from "./utils/testServerPerms.js";
|
||||
import serviceControl from "./route/servers/serverContorl.js";
|
||||
import { areSubModulesIn } from "./utils/subModuleCheck.js";
|
||||
import getSubmodules from "./route/modules/getSubModules.js";
|
||||
import updateSubModule from "./route/modules/updateSubModules.js";
|
||||
|
||||
// making sure all modules are in properly
|
||||
setTimeout(async () => {
|
||||
await areSettingsIn();
|
||||
await areModulesIn();
|
||||
await serversCheckPoint();
|
||||
await setPerms();
|
||||
await areSubModulesIn();
|
||||
}, 5000);
|
||||
|
||||
const app = new OpenAPIHono();
|
||||
|
||||
const routes = [
|
||||
getModules,
|
||||
updateModule,
|
||||
addModule,
|
||||
getSubmodules,
|
||||
updateSubModule,
|
||||
// settings
|
||||
addSetting,
|
||||
getSettings,
|
||||
updateSetting,
|
||||
// serverData
|
||||
getServers,
|
||||
updateServer,
|
||||
serviceControl,
|
||||
] as const;
|
||||
|
||||
// app.route("/server", modules);
|
||||
const appRoutes = routes.forEach((route) => {
|
||||
app.route("/server", route);
|
||||
});
|
||||
|
||||
app.all("/server/*", (c) => {
|
||||
return c.json({
|
||||
success: false,
|
||||
message:
|
||||
"You encountered a route that dose not exist on the server routes",
|
||||
});
|
||||
});
|
||||
export default app;
|
||||
71
lstV2/server/services/server/utils/moduleCheck.ts
Normal file
71
lstV2/server/services/server/utils/moduleCheck.ts
Normal file
@@ -0,0 +1,71 @@
|
||||
/**
|
||||
* check if the modules are in and if not add them.
|
||||
* this will only run on a server start up
|
||||
*/
|
||||
|
||||
import { db } from "../../../../database/dbclient.js";
|
||||
import { modules } from "../../../../database/schema/modules.js";
|
||||
import { createLog } from "../../logger/logger.js";
|
||||
// "view", "technician", "supervisor","manager", "admin", "systemAdmin"
|
||||
const newModules: any = [
|
||||
{
|
||||
name: "production",
|
||||
active: true,
|
||||
roles: ["viewer", "tester", "systemAdmin"],
|
||||
},
|
||||
{
|
||||
name: "logistics",
|
||||
active: false,
|
||||
roles: ["viewer", "manager", "supervisor", "tester", "systemAdmin"],
|
||||
},
|
||||
{
|
||||
name: "quality",
|
||||
active: false,
|
||||
roles: ["viewer", "manager", "tester", "systemAdmin"],
|
||||
},
|
||||
{
|
||||
name: "forklift",
|
||||
active: false,
|
||||
roles: ["manager", "admin", "tester", "systemAdmin"],
|
||||
},
|
||||
{
|
||||
name: "eom",
|
||||
active: false,
|
||||
roles: ["manager", "admin", "tester", "systemAdmin"],
|
||||
},
|
||||
{ name: "admin", active: true, roles: ["admin", "systemAdmin"] },
|
||||
{
|
||||
name: "ocp",
|
||||
active: false,
|
||||
roles: ["viewer", "admin", "tester", "systemAdmin"],
|
||||
},
|
||||
];
|
||||
export const areModulesIn = async () => {
|
||||
// get the roles
|
||||
for (let i = 0; i < newModules.length; i++) {
|
||||
try {
|
||||
const newRole = await db
|
||||
.insert(modules)
|
||||
.values(newModules[i])
|
||||
.onConflictDoUpdate({
|
||||
target: modules.name,
|
||||
set: { roles: newModules[i].roles },
|
||||
}) // this will only update the ones that are new :D
|
||||
.returning({ name: modules.name });
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
createLog(
|
||||
"error",
|
||||
"lst",
|
||||
"server",
|
||||
"There was an error adding new modules to the db"
|
||||
);
|
||||
}
|
||||
}
|
||||
createLog(
|
||||
"info",
|
||||
"lst",
|
||||
"server",
|
||||
"Modules were just added due to missing them on server startup"
|
||||
);
|
||||
};
|
||||
381
lstV2/server/services/server/utils/serverData.json
Normal file
381
lstV2/server/services/server/utils/serverData.json
Normal file
@@ -0,0 +1,381 @@
|
||||
{
|
||||
"servers": [
|
||||
{
|
||||
"sName": "Test",
|
||||
"serverDNS": "usmcd1vms036",
|
||||
"plantToken": "test3",
|
||||
"idAdress": "10.193.0.56",
|
||||
"greatPlainsPlantCode": "1",
|
||||
"streetAddress": "289 GA-155 S",
|
||||
"cityState": "McDonough, GA",
|
||||
"zipcode": "30253",
|
||||
"contactEmail": "noreply@alpla.com",
|
||||
"contactPhone": "770-914-1407",
|
||||
"customerTiAcc": "ALPLA01INTGROUP",
|
||||
"lstServerPort": "3000",
|
||||
"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": "" }]
|
||||
},
|
||||
{
|
||||
"sName": "Bethlehem",
|
||||
"serverDNS": "usbet1vms006",
|
||||
"plantToken": "usbet1",
|
||||
"idAddress": "10.204.0.26",
|
||||
"greatPlainsPlantCode": "75",
|
||||
"streetAddress": "2120 Spillman Dr",
|
||||
"cityState": "Bethlehem, PA",
|
||||
"zipcode": "18015",
|
||||
"contactEmail": "ShippingReceivingBethlehem@groups.alpla.com",
|
||||
"contactPhone": "6103902380",
|
||||
"customerTiAcc": "ALPL01BETHINT",
|
||||
"lstServerPort": "3000",
|
||||
"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": "PLEASE CONTACT ShippingReceivingBethlehem@groups.alpla.com WITH ANY QUESTIONS"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"sName": "Huston",
|
||||
"serverDNS": "ushou1vms006",
|
||||
"plantToken": "ushou1",
|
||||
"idAddress": "10.195.0.26",
|
||||
"greatPlainsPlantCode": "20",
|
||||
"streetAddress": "5800 Armour Dr",
|
||||
"cityState": "Houston, TX",
|
||||
"zipcode": "77020",
|
||||
"contactEmail": "blake.matthes@alpla.com",
|
||||
"contactPhone": "6366970253",
|
||||
"customerTiAcc": "ALPL01HOUSINT",
|
||||
"lstServerPort": "3000",
|
||||
"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": "" }]
|
||||
},
|
||||
{
|
||||
"sName": "Bowling Green 1",
|
||||
"serverDNS": "usbow1vms006",
|
||||
"plantToken": "usbow1",
|
||||
"idAddress": "10.25.0.26",
|
||||
"greatPlainsPlantCode": "55",
|
||||
"streetAddress": "215 Technology Way",
|
||||
"cityState": "Bowling Green, KY",
|
||||
"zipcode": "42101",
|
||||
"contactEmail": "ShippingReceivingBowlingGreen1@groups.alpla.com",
|
||||
"contactPhone": "(270) 495-6647",
|
||||
"customerTiAcc": "ALPL01BG1INT",
|
||||
"lstServerPort": "3000",
|
||||
"active": true,
|
||||
"serverLoc": "E:\\LST\\lstv2",
|
||||
"oldVersion": "E:\\LST\\lst_backend",
|
||||
"shippingHours": "[{\"early\": \"00:00\", \"late\": \"23:00\"}]",
|
||||
"tiPostTime": "[{\"from\": \"24\", \"to\": \"24\"}]",
|
||||
"otherSettings": [
|
||||
{
|
||||
"specialInstructions": "Please be sure to schedule a pick up appointment and bring 2 load bars to secure the load."
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"sName": "Iowa ISBM",
|
||||
"serverDNS": "usiow1vms006",
|
||||
"plantToken": "usiow2",
|
||||
"idAddress": "10.75.0.26",
|
||||
"greatPlainsPlantCode": "31",
|
||||
"streetAddress": "2670 INDEPENDENCE RD",
|
||||
"cityState": "Iowa CIty, IA",
|
||||
"zipcode": "52240",
|
||||
"contactEmail": "Dalina.Lacy@alpla.com",
|
||||
"contactPhone": "",
|
||||
"customerTiAcc": "ALPL01IA2INT",
|
||||
"lstServerPort": "3001",
|
||||
"active": true,
|
||||
"serverLoc": "D:\\LST\\lstv2_2",
|
||||
"oldVersion": "D:\\LST\\lst_backend_2",
|
||||
"shippingHours": "[{\"early\": \"06:30\", \"late\": \"23:00\"}]",
|
||||
"tiPostTime": "[{\"from\": \"24\", \"to\": \"24\"}]",
|
||||
"otherSettings": [{ "specialInstructions": "[header]" }]
|
||||
},
|
||||
{
|
||||
"sName": "Kansas City",
|
||||
"serverDNS": "usksc1vms006",
|
||||
"plantToken": "usksc1",
|
||||
"idAddress": "10.42.9.26",
|
||||
"greatPlainsPlantCode": "85",
|
||||
"streetAddress": "1800 E 94th St Suite 300",
|
||||
"cityState": "Kansas City, MO",
|
||||
"zipcode": "64131",
|
||||
"contactEmail": "blake.matthes@alpla.com",
|
||||
"contactPhone": "6366970253",
|
||||
"customerTiAcc": "ALPL01KCINT",
|
||||
"lstServerPort": "3000",
|
||||
"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": "" }]
|
||||
},
|
||||
{
|
||||
"sName": "Bowling Green 2",
|
||||
"serverDNS": "usbow2vms006",
|
||||
"plantToken": "usbow2",
|
||||
"idAddress": "10.106.0.26",
|
||||
"greatPlainsPlantCode": "56",
|
||||
"streetAddress": "377 Southwood Ct",
|
||||
"cityState": "Bowling Green, KY",
|
||||
"zipcode": "42101",
|
||||
"contactEmail": "blake.matthes@alpla.com",
|
||||
"contactPhone": "6366970253",
|
||||
"customerTiAcc": "ALPL01BG2INT",
|
||||
"lstServerPort": "3000",
|
||||
"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": "" }]
|
||||
},
|
||||
{
|
||||
"sName": "MCDonough",
|
||||
"serverDNS": "usmcd1vms006",
|
||||
"plantToken": "usmcd1",
|
||||
"idAddress": "10.193.0.26",
|
||||
"greatPlainsPlantCode": "10",
|
||||
"streetAddress": "289 GA-155 S",
|
||||
"cityState": "McDonough, GA",
|
||||
"zipcode": "30253",
|
||||
"contactEmail": "shippingreceivingmcdonough@groups.alpla.com",
|
||||
"contactPhone": "4049663122",
|
||||
"customerTiAcc": "ALPL01MCDINT",
|
||||
"lstServerPort": "3000",
|
||||
"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": "" }]
|
||||
},
|
||||
{
|
||||
"sName": "Dayton",
|
||||
"serverDNS": "usday1vms006",
|
||||
"plantToken": "usday1",
|
||||
"idAddress": "10.44.0.26",
|
||||
"greatPlainsPlantCode": "80",
|
||||
"streetAddress": "2700 Concorde Dr Suite 200",
|
||||
"cityState": "Vandalia, OH",
|
||||
"zipcode": "45377",
|
||||
"contactEmail": "Daniel.Deshields@alpla.com",
|
||||
"contactPhone": "4846667452",
|
||||
"customerTiAcc": "ALPL01DAYTONINT",
|
||||
"lstServerPort": "3000",
|
||||
"active": true,
|
||||
"serverLoc": "E:\\LST\\lstv2",
|
||||
"oldVersion": "E:\\LST\\lst_backend",
|
||||
"shippingHours": "[{\"early\": \"00:00\", \"late\": \"23:59\"}]",
|
||||
"tiPostTime": "[{\"from\": \"24\", \"to\": \"24\"}]",
|
||||
"otherSettings": [{ "specialInstructions": "" }]
|
||||
},
|
||||
{
|
||||
"sName": "Salt Lake City",
|
||||
"serverDNS": "usslc1vms006",
|
||||
"plantToken": "usslc1",
|
||||
"idAddress": "10.202.0.26",
|
||||
"greatPlainsPlantCode": "70",
|
||||
"streetAddress": "4324 Commercial Way Suite A",
|
||||
"cityState": "Salt Lake City, UT",
|
||||
"zipcode": "84104",
|
||||
"contactEmail": "ShippingReceivingSaltLake@groups.alpla.com",
|
||||
"contactPhone": "801-673-2143",
|
||||
"customerTiAcc": "ALPL01SLCINT",
|
||||
"lstServerPort": "3000",
|
||||
"active": true,
|
||||
"serverLoc": "E:\\LST\\lstv2",
|
||||
"oldVersion": "E:\\LST\\lst_backend",
|
||||
"shippingHours": "[{\"early\": \"07:00\", \"late\": \"17:00\"}]",
|
||||
"tiPostTime": "[{\"from\": \"24\", \"to\": \"24\"}]",
|
||||
"otherSettings": [{ "specialInstructions": "Copy of bol" }]
|
||||
},
|
||||
{
|
||||
"sName": "Lima",
|
||||
"serverDNS": "uslim1vms006",
|
||||
"plantToken": "uslim1",
|
||||
"idAddress": "10.53.0.26",
|
||||
"greatPlainsPlantCode": "50",
|
||||
"streetAddress": "3320 Fort Shawnee Industrial Dr",
|
||||
"cityState": "Lima, OH",
|
||||
"zipcode": "45806",
|
||||
"contactEmail": "shippingreceivinglima@groups.alpla.com",
|
||||
"contactPhone": "",
|
||||
"customerTiAcc": "ALPL01LIMAINT",
|
||||
"lstServerPort": "3000",
|
||||
"active": true,
|
||||
"serverLoc": "E:\\LST\\lstv2",
|
||||
"oldVersion": "E:\\LST\\lst_backend",
|
||||
"shippingHours": "[{\"early\": \"13:00\", \"late\": \"15:00\"}]",
|
||||
"tiPostTime": "[{\"from\": \"24\", \"to\": \"24\"}]",
|
||||
"otherSettings": [{ "specialInstructions": "" }]
|
||||
},
|
||||
{
|
||||
"sName": "Florence",
|
||||
"serverDNS": "usflo1vms006",
|
||||
"plantToken": "usflo1",
|
||||
"idAddress": "10.203.0.26",
|
||||
"greatPlainsPlantCode": "22",
|
||||
"streetAddress": "7080 New Buffington Rd",
|
||||
"cityState": "Florence, KY",
|
||||
"zipcode": "41042",
|
||||
"contactEmail": "blake.matthes@alpla.com",
|
||||
"contactPhone": "6366970253",
|
||||
"customerTiAcc": "ALPL01FLORINT",
|
||||
"lstServerPort": "3000",
|
||||
"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": "" }]
|
||||
},
|
||||
{
|
||||
"sName": "Iowa EBM",
|
||||
"serverDNS": "usiow1vms006",
|
||||
"plantToken": "usiow1",
|
||||
"idAddress": "10.75.0.26",
|
||||
"greatPlainsPlantCode": "30",
|
||||
"streetAddress": "2258 Heinz Rd",
|
||||
"cityState": "Iowa CIty, IA",
|
||||
"zipcode": "52240",
|
||||
"contactEmail": "shippingreceivingiowa1@groups.alpla.com",
|
||||
"contactPhone": "3193378057",
|
||||
"customerTiAcc": "ALPL01IA1INT",
|
||||
"lstServerPort": "3000",
|
||||
"active": true,
|
||||
"serverLoc": "D:\\LST\\lstv2",
|
||||
"oldVersion": "D:\\LST\\lst_backend",
|
||||
"shippingHours": "[{\"early\": \"06:30\", \"late\": \"23:00\"}]",
|
||||
"tiPostTime": "[{\"from\": \"24\", \"to\": \"24\"}]",
|
||||
"otherSettings": [{ "specialInstructions": "" }]
|
||||
},
|
||||
{
|
||||
"sName": "Jefferson city",
|
||||
"serverDNS": "usjci1vms006",
|
||||
"plantToken": "usjci1",
|
||||
"idAddress": "10.167.0.26",
|
||||
"greatPlainsPlantCode": "40",
|
||||
"streetAddress": "2662 Militia Dr",
|
||||
"cityState": "Jefferson City, MO",
|
||||
"zipcode": "65101",
|
||||
"contactEmail": "blake.matthes@alpla.com",
|
||||
"contactPhone": "6366970253",
|
||||
"customerTiAcc": "ALPL01JCINT",
|
||||
"lstServerPort": "3000",
|
||||
"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": "" }]
|
||||
},
|
||||
{
|
||||
"sName": "Sherman",
|
||||
"serverDNS": "usshe1vms006",
|
||||
"plantToken": "usshe1",
|
||||
"idAddress": "10.205.0.26",
|
||||
"greatPlainsPlantCode": "21",
|
||||
"streetAddress": "3000 Howe Dr",
|
||||
"cityState": "Sherman, TX",
|
||||
"zipcode": "75092",
|
||||
"contactEmail": "blake.matthes@alpla.com",
|
||||
"contactPhone": "6366970253",
|
||||
"customerTiAcc": "ALPL01SHERMANINT",
|
||||
"lstServerPort": "3000",
|
||||
"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": "" }]
|
||||
},
|
||||
{
|
||||
"sName": "West Bend",
|
||||
"serverDNS": "usweb1vms006",
|
||||
"plantToken": "usweb1",
|
||||
"idAddress": "10.80.0.26",
|
||||
"greatPlainsPlantCode": "65",
|
||||
"streetAddress": "825 Rail Way",
|
||||
"cityState": "West Bend, WI",
|
||||
"zipcode": "53095",
|
||||
"contactEmail": "shippingreceivingwestbend@groups.alpla.com",
|
||||
"contactPhone": "262-808-4211",
|
||||
"customerTiAcc": "ALPL01WBINT",
|
||||
"lstServerPort": "3000",
|
||||
"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": "This is a FTL load. The driver will need 2 adjustable load locks to secure the load. The driver will not be loaded without them. Please reference ALPLA pickup [header]",
|
||||
"active": false
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"sName": "St Peters",
|
||||
"serverDNS": "usstp1vms006",
|
||||
"plantToken": "usstp1",
|
||||
"idAddress": "10.37.0.26",
|
||||
"greatPlainsPlantCode": "45",
|
||||
"streetAddress": "9 Cermak Blvd",
|
||||
"cityState": "St. Peters, MO",
|
||||
"zipcode": "63376",
|
||||
"contactEmail": "Shippingreceivingstpeters@groups.alpla.com",
|
||||
"contactPhone": "6365771018",
|
||||
"customerTiAcc": "ALPL01STPINT",
|
||||
"lstServerPort": "3000",
|
||||
"active": true,
|
||||
"serverLoc": "D:\\LST\\lstv2",
|
||||
"oldVersion": "E:\\LST\\lst_backend",
|
||||
"shippingHours": "[{\"early\": \"00:01\", \"late\": \"23:59\"}]",
|
||||
"tiPostTime": "[{\"from\": \"24\", \"to\": \"24\"}]",
|
||||
"otherSettings": [
|
||||
{ "specialInstructions": "Loadbars/Straps required." }
|
||||
]
|
||||
},
|
||||
{
|
||||
"sName": "Marked Tree",
|
||||
"serverDNS": "usmar1vms006",
|
||||
"plantToken": "usmar1",
|
||||
"idAddress": "10.206.9.26",
|
||||
"greatPlainsPlantCode": "90",
|
||||
"streetAddress": "301 Industrial St",
|
||||
"cityState": "Marked Tree, AR",
|
||||
"zipcode": "72365",
|
||||
"contactEmail": "Shippingreceivingstpeters@groups.alpla.com",
|
||||
"contactPhone": "6365771018",
|
||||
"customerTiAcc": "ALPL01MARINT",
|
||||
"lstServerPort": "3000",
|
||||
"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": "Loadbars/Straps required." }
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
73
lstV2/server/services/server/utils/serverData.ts
Normal file
73
lstV2/server/services/server/utils/serverData.ts
Normal file
@@ -0,0 +1,73 @@
|
||||
// This will help maintain the server db so when we run an update it will show up here all the time.
|
||||
// kinda bad too but this will help us keep the db identical.
|
||||
|
||||
import { db } from "../../../../database/dbclient.js";
|
||||
import { serverData } from "../../../../database/schema/serverData.js";
|
||||
import { createLog } from "../../logger/logger.js";
|
||||
import fs from "fs";
|
||||
|
||||
export const serversCheckPoint = async () => {
|
||||
let servers: any[] = [];
|
||||
let filePath: string;
|
||||
if (process.env.NODE_ENV === "development") {
|
||||
filePath = "./server/services/server/utils/serverData.json";
|
||||
} else {
|
||||
filePath = "./dist/server/services/server/utils/serverData.json";
|
||||
}
|
||||
|
||||
try {
|
||||
const data = fs.readFileSync(filePath, "utf8");
|
||||
const serverData = JSON.parse(data);
|
||||
servers = serverData.servers;
|
||||
} catch (err) {
|
||||
createLog(
|
||||
"error",
|
||||
"server",
|
||||
"server",
|
||||
`Error reading JSON file: ${JSON.stringify(err)}`
|
||||
);
|
||||
}
|
||||
|
||||
// get the roles
|
||||
|
||||
try {
|
||||
for (let i = 0; i < servers.length; i++) {
|
||||
const serverUpdate = await db
|
||||
.insert(serverData)
|
||||
.values(servers[i])
|
||||
.onConflictDoUpdate({
|
||||
target: serverData.plantToken,
|
||||
set: {
|
||||
sName: servers[i].sName,
|
||||
serverDNS: servers[i].serverDNS,
|
||||
active: servers[i].active,
|
||||
contactEmail: servers[i].contactEmail,
|
||||
contactPhone: servers[i].contactPhone,
|
||||
shippingHours: servers[i].shippingHours,
|
||||
customerTiAcc: servers[i].customerTiAcc,
|
||||
streetAddress: servers[i].streetAddress,
|
||||
cityState: servers[i].cityState,
|
||||
serverLoc: servers[i].serverLoc,
|
||||
lstServerPort: servers[i].lstServerPort,
|
||||
oldVersion: servers[i].oldVersion,
|
||||
tiPostTime: servers[i].tiPostTime,
|
||||
otherSettings: servers[i].otherSettings,
|
||||
},
|
||||
}) // this will only update the ones that are new :D
|
||||
.returning({ name: serverData.sName });
|
||||
}
|
||||
createLog(
|
||||
"info",
|
||||
"lst",
|
||||
"server",
|
||||
"Servers were just added/updated due to server startup"
|
||||
);
|
||||
} catch (error) {
|
||||
createLog(
|
||||
"error",
|
||||
"lst",
|
||||
"server",
|
||||
`There was an error adding/updating serverData to the db, ${error}`
|
||||
);
|
||||
}
|
||||
};
|
||||
315
lstV2/server/services/server/utils/settingsCheck.ts
Normal file
315
lstV2/server/services/server/utils/settingsCheck.ts
Normal file
@@ -0,0 +1,315 @@
|
||||
/**
|
||||
* check if the modules are in and if not add them.
|
||||
* this will only run on a server start up
|
||||
*/
|
||||
|
||||
import { db } from "../../../../database/dbclient.js";
|
||||
import { settings } from "../../../../database/schema/settings.js";
|
||||
|
||||
import { createLog } from "../../logger/logger.js";
|
||||
// "view", "technician", "supervisor","manager", "admin", "systemAdmin"
|
||||
const newSettings = [
|
||||
{
|
||||
name: "server",
|
||||
value: "localhost",
|
||||
description: "Where the app runs at",
|
||||
moduleName: "server",
|
||||
},
|
||||
{
|
||||
name: "serverPort",
|
||||
value: "4400",
|
||||
description: "What are we listening on",
|
||||
moduleName: "server",
|
||||
},
|
||||
{
|
||||
name: "timezone",
|
||||
value: "America/Chicago",
|
||||
description:
|
||||
"What time zone is the server in this is used for cronjobs and some other time stuff",
|
||||
moduleName: "server",
|
||||
},
|
||||
{
|
||||
name: "dbUser",
|
||||
value: "alplaprod",
|
||||
description: "What is the db username",
|
||||
moduleName: "server",
|
||||
},
|
||||
{
|
||||
name: "dbPass",
|
||||
value: "b2JlbGl4",
|
||||
description: "What is the db password",
|
||||
moduleName: "server",
|
||||
},
|
||||
{
|
||||
name: "tcpPort",
|
||||
value: "2222",
|
||||
description:
|
||||
"TCP port for printers to connect send data and the zedra cameras",
|
||||
moduleName: "server",
|
||||
},
|
||||
{
|
||||
name: "prolinkCheck",
|
||||
value: "1",
|
||||
description:
|
||||
"Will prolink be considered to check if matches, maninly used in plants that do not fully utilize prolink + ocp",
|
||||
moduleName: "production",
|
||||
},
|
||||
{
|
||||
name: "bookin",
|
||||
value: "1",
|
||||
description: "do we want to book in after a label is printed",
|
||||
moduleName: "ocp",
|
||||
},
|
||||
{
|
||||
name: "dbServer",
|
||||
value: "usmcd1vms036",
|
||||
description: "What server is the prod db on?",
|
||||
moduleName: "server",
|
||||
},
|
||||
{
|
||||
name: "printDelay",
|
||||
value: "90",
|
||||
description: "How long in seconds between prints",
|
||||
moduleName: "ocp",
|
||||
},
|
||||
{
|
||||
name: "plantToken",
|
||||
value: "test3",
|
||||
description: "What is the plant token",
|
||||
moduleName: "server",
|
||||
},
|
||||
{
|
||||
name: "dualPrinting",
|
||||
value: "0",
|
||||
description: "Dose the plant have 2 machines that go to 1?",
|
||||
moduleName: "ocp",
|
||||
},
|
||||
{
|
||||
name: "ocmeService",
|
||||
value: "0",
|
||||
description:
|
||||
"Is the ocme service enabled. this is gernerally only for Dayton.",
|
||||
moduleName: "ocme",
|
||||
},
|
||||
{
|
||||
name: "fifoCheck",
|
||||
value: "45",
|
||||
description:
|
||||
"How far back do we want to check for fifo default 45, putting 0 will ignore.",
|
||||
moduleName: "ocme",
|
||||
},
|
||||
{
|
||||
name: "dayCheck",
|
||||
value: "3",
|
||||
description: "how many days +/- to check for shipments in alplaprod",
|
||||
moduleName: "ocme",
|
||||
},
|
||||
{
|
||||
name: "maxLotPerTruck",
|
||||
value: "3",
|
||||
description: "How mant lots can we have per truck?",
|
||||
moduleName: "ocme",
|
||||
},
|
||||
{
|
||||
name: "monitorAddress",
|
||||
value: "8",
|
||||
description:
|
||||
"What address is monitored to be limited to the amount of lots that can be added to a truck.",
|
||||
moduleName: "ocme",
|
||||
},
|
||||
{
|
||||
name: "ocmeCycleCount",
|
||||
value: "1",
|
||||
description: "Are we allowing ocme cycle counts?",
|
||||
roles: "admin",
|
||||
module: "ocme",
|
||||
},
|
||||
{
|
||||
name: "devDir",
|
||||
value: "C:\\Users\\matthes01\\Documents\\lstv2",
|
||||
description:
|
||||
"This is the dev dir and strictly only for updating the servers.",
|
||||
moduleName: "server",
|
||||
},
|
||||
{
|
||||
name: "demandMGTActivated",
|
||||
value: "0",
|
||||
description: "Do we allow for new fake edi?",
|
||||
roles: "admin",
|
||||
module: "logistics",
|
||||
},
|
||||
{
|
||||
name: "qualityRequest",
|
||||
value: "0",
|
||||
description: "quality request module?",
|
||||
roles: "admin",
|
||||
module: "logistics",
|
||||
},
|
||||
{
|
||||
name: "ocpLogsCheck",
|
||||
value: "4",
|
||||
description:
|
||||
"How long do we want to allow logs to show that have not been cleared?",
|
||||
roles: "admin",
|
||||
module: "ocp",
|
||||
},
|
||||
{
|
||||
name: "inhouseDelivery",
|
||||
value: "0",
|
||||
description: "Are we doing auto inhouse delivery?",
|
||||
roles: "admin",
|
||||
module: "ocp",
|
||||
},
|
||||
// dyco settings
|
||||
{
|
||||
name: "dycoConnect",
|
||||
value: "0",
|
||||
description: "Are we running the dyco system?",
|
||||
roles: "admin",
|
||||
module: "ocp",
|
||||
},
|
||||
{
|
||||
name: "dycoPrint",
|
||||
value: "0",
|
||||
description: "Are we using the dyco to get the labels or the rfid?",
|
||||
roles: "admin",
|
||||
module: "ocp",
|
||||
},
|
||||
{
|
||||
name: "strapperCheck",
|
||||
value: "1",
|
||||
description: "Are we monitoring the strapper for faults?",
|
||||
roles: "admin",
|
||||
module: "ocp",
|
||||
},
|
||||
{
|
||||
name: "v1SysServer",
|
||||
value: `localhost`,
|
||||
description:
|
||||
"The remaining v1 stuff here until we finish the frontend here.",
|
||||
serviceBelowsTo: "system",
|
||||
roleToChange: "admin",
|
||||
},
|
||||
{
|
||||
name: "v1SysPort",
|
||||
value: `4000`,
|
||||
description:
|
||||
"The remaining v1 stuff here until we finish the frontend here.",
|
||||
serviceBelowsTo: "system",
|
||||
roleToChange: "admin",
|
||||
},
|
||||
{
|
||||
name: "rifd",
|
||||
value: `0`,
|
||||
description: "This is for dayton to be runnning rfid pallet tracking.",
|
||||
serviceBelowsTo: "logistics",
|
||||
roleToChange: "admin",
|
||||
},
|
||||
|
||||
// ocp
|
||||
{
|
||||
name: "ocpActive",
|
||||
value: `1`,
|
||||
description: "Are we pritning on demand?",
|
||||
serviceBelowsTo: "ocp",
|
||||
roleToChange: "admin",
|
||||
},
|
||||
{
|
||||
name: "ocpCycleDelay",
|
||||
value: `10`,
|
||||
description: "How long between printer cycles do we want to monitor.",
|
||||
serviceBelowsTo: "ocp",
|
||||
roleToChange: "admin",
|
||||
},
|
||||
{
|
||||
name: "pNgAddress",
|
||||
value: `139`,
|
||||
description:
|
||||
"What is the address for p&g so we can make sure we have the correct fake edi forcast going in.",
|
||||
serviceBelowsTo: "dm",
|
||||
roleToChange: "admin",
|
||||
},
|
||||
{
|
||||
name: "scannerID",
|
||||
value: `500`,
|
||||
description: "What scanner id will we be using for the app",
|
||||
serviceBelowsTo: "logistics",
|
||||
roleToChange: "admin",
|
||||
},
|
||||
{
|
||||
name: "scannerPort",
|
||||
value: `50002`,
|
||||
description: "What port instance will we be using?",
|
||||
serviceBelowsTo: "logistics",
|
||||
roleToChange: "admin",
|
||||
},
|
||||
{
|
||||
name: "stagingReturnLocations",
|
||||
value: `30125,31523`,
|
||||
description:
|
||||
"What are the staging location IDs we will use to select from. seperated by commas",
|
||||
serviceBelowsTo: "logistics",
|
||||
roleToChange: "admin",
|
||||
},
|
||||
{
|
||||
name: "zechetti",
|
||||
value: `0`,
|
||||
description: "Are we going to be running the Zechetti plcs",
|
||||
serviceBelowsTo: "logistics",
|
||||
roleToChange: "admin",
|
||||
},
|
||||
// temp settings can be deleted at a later date once that code is removed
|
||||
{
|
||||
name: "checkColor",
|
||||
value: `0`,
|
||||
description: "Checks autoconsume and manual consume color",
|
||||
serviceBelowsTo: "admin",
|
||||
roleToChange: "admin",
|
||||
},
|
||||
{
|
||||
name: "checkPKG",
|
||||
value: `0`,
|
||||
description: "Checks checks if we have enough packaging or not",
|
||||
serviceBelowsTo: "admin",
|
||||
roleToChange: "admin",
|
||||
},
|
||||
{
|
||||
name: "siloAdjMigrations",
|
||||
value: `0`,
|
||||
description: "Migrates the old silo adjustments to lst v2.",
|
||||
serviceBelowsTo: "admin",
|
||||
roleToChange: "admin",
|
||||
},
|
||||
];
|
||||
export const areSettingsIn = async () => {
|
||||
// get the roles
|
||||
try {
|
||||
try {
|
||||
const newRole = await db
|
||||
.insert(settings)
|
||||
.values(newSettings)
|
||||
.onConflictDoNothing() // this will only update the ones that are new :D
|
||||
.returning({ name: settings.name });
|
||||
createLog(
|
||||
"info",
|
||||
"lst",
|
||||
"server",
|
||||
"Settings were just added due to missing them on server startup"
|
||||
);
|
||||
} catch (error) {
|
||||
createLog(
|
||||
"error",
|
||||
"lst",
|
||||
"server",
|
||||
"There was an error adding new roles to the db"
|
||||
);
|
||||
}
|
||||
} catch (error) {
|
||||
createLog(
|
||||
"error",
|
||||
"lst",
|
||||
"server",
|
||||
"There was an error getting or adding new Settingss"
|
||||
);
|
||||
}
|
||||
};
|
||||
258
lstV2/server/services/server/utils/subModuleCheck.ts
Normal file
258
lstV2/server/services/server/utils/subModuleCheck.ts
Normal file
@@ -0,0 +1,258 @@
|
||||
/**
|
||||
* check if the modules are in and if not add them.
|
||||
* this will only run on a server start up
|
||||
*/
|
||||
|
||||
import { db } from "../../../../database/dbclient.js";
|
||||
import { subModules } from "../../../../database/schema/subModules.js";
|
||||
import { createLog } from "../../logger/logger.js";
|
||||
// "view", "technician", "supervisor","manager", "admin", "systemAdmin"
|
||||
const newSubModules = [
|
||||
{
|
||||
name: "RFID",
|
||||
moduleName: "prodcution",
|
||||
description: "RFID stuff",
|
||||
link: "/rfid",
|
||||
icon: "Tags",
|
||||
active: true,
|
||||
roles: [
|
||||
"viewer",
|
||||
"technician",
|
||||
"supervisor",
|
||||
"manager",
|
||||
"admin",
|
||||
"systemAdmin",
|
||||
],
|
||||
subSubModule: [],
|
||||
},
|
||||
{
|
||||
name: "Silo Adjustments",
|
||||
moduleName: "logistics",
|
||||
description: "Do a silo adjustmnet",
|
||||
link: "/siloAdjustments",
|
||||
icon: "Cylinder",
|
||||
active: false,
|
||||
roles: ["technician", "supervisor", "manager", "admin", "systemAdmin"],
|
||||
subSubModule: [],
|
||||
},
|
||||
{
|
||||
name: "Demand Management",
|
||||
moduleName: "logistics",
|
||||
description: "Bulk order and Forecast imports",
|
||||
link: "/dm",
|
||||
icon: "Truck",
|
||||
roles: ["technician", "supervisor", "manager", "admin", "systemAdmin"],
|
||||
active: false,
|
||||
subSubModule: [],
|
||||
},
|
||||
{
|
||||
name: "Forecast",
|
||||
moduleName: "logistics",
|
||||
description: "",
|
||||
link: "#",
|
||||
icon: "Truck",
|
||||
roles: ["systemAdmin"],
|
||||
active: false,
|
||||
subSubModule: [],
|
||||
},
|
||||
{
|
||||
name: "Material Helper",
|
||||
moduleName: "logistics",
|
||||
description: "",
|
||||
link: "/materialHelper/consumption",
|
||||
icon: "Package",
|
||||
roles: [
|
||||
"viewer",
|
||||
"technician",
|
||||
"supervisor",
|
||||
"manager",
|
||||
"admin",
|
||||
"systemAdmin",
|
||||
],
|
||||
active: false,
|
||||
subSubModule: [],
|
||||
},
|
||||
{
|
||||
name: "Ocme Cyclecount",
|
||||
moduleName: "logistics",
|
||||
description: "",
|
||||
link: "/cyclecount",
|
||||
icon: "Package",
|
||||
roles: ["technician", "supervisor", "manager", "admin", "systemAdmin"],
|
||||
active: false,
|
||||
subSubModule: [],
|
||||
},
|
||||
{
|
||||
name: "Open Orders",
|
||||
moduleName: "logistics",
|
||||
description: "Open orders",
|
||||
link: "/openOrders",
|
||||
icon: "Truck",
|
||||
roles: [
|
||||
"viewer",
|
||||
"technician",
|
||||
"supervisor",
|
||||
"manager",
|
||||
"admin",
|
||||
"systemAdmin",
|
||||
],
|
||||
active: false,
|
||||
subSubModule: [],
|
||||
},
|
||||
{
|
||||
name: "Barcodes",
|
||||
moduleName: "logistics",
|
||||
description: "Barcodes, lanes and scanable",
|
||||
link: "/barcodegen",
|
||||
icon: "Barcode",
|
||||
roles: [
|
||||
"viewer",
|
||||
"technician",
|
||||
"supervisor",
|
||||
"manager",
|
||||
"admin",
|
||||
"systemAdmin",
|
||||
],
|
||||
active: true,
|
||||
subSubModule: [],
|
||||
},
|
||||
{
|
||||
name: "Helper Commands",
|
||||
moduleName: "logistics",
|
||||
description: "Commands to assist when a scanner is not avalible",
|
||||
link: "/helpercommands",
|
||||
icon: "Command",
|
||||
roles: ["technician", "supervisor", "manager", "admin", "systemAdmin"],
|
||||
active: true,
|
||||
subSubModule: [],
|
||||
},
|
||||
|
||||
// admin module
|
||||
{
|
||||
name: "Servers",
|
||||
moduleName: "admin",
|
||||
description: "Do a silo adjustmnet",
|
||||
link: "/servers",
|
||||
icon: "Server",
|
||||
roles: ["tester", "systemAdmin"],
|
||||
isActive: true,
|
||||
subSubModule: [],
|
||||
},
|
||||
{
|
||||
name: "Admin",
|
||||
moduleName: "admin",
|
||||
description: "Do a silo adjustmnet",
|
||||
link: "#", // when link is # this will mean its a button
|
||||
icon: "ShieldCheck",
|
||||
active: true,
|
||||
roles: ["tester", "admin", "systemAdmin"],
|
||||
subSubModule: [
|
||||
{
|
||||
name: "Settings",
|
||||
link: "/settings",
|
||||
icon: "Settings",
|
||||
newWindow: false,
|
||||
isActive: true,
|
||||
},
|
||||
{
|
||||
name: "Modules",
|
||||
link: "/modules",
|
||||
icon: "Settings",
|
||||
newWindow: false,
|
||||
isActive: true,
|
||||
},
|
||||
{
|
||||
name: "Sub Modules",
|
||||
link: "/subModules",
|
||||
icon: "Settings",
|
||||
newWindow: false,
|
||||
isActive: true,
|
||||
},
|
||||
{
|
||||
name: "Notifcations",
|
||||
link: "notificationMGT",
|
||||
icon: "Webhook",
|
||||
newWindow: false,
|
||||
isActive: true,
|
||||
},
|
||||
{
|
||||
name: "Swagger",
|
||||
link: "#",
|
||||
icon: "Webhook",
|
||||
newWindow: true,
|
||||
isActive: true,
|
||||
},
|
||||
{
|
||||
name: "Logs",
|
||||
link: "#",
|
||||
icon: "Logs",
|
||||
newWindow: false,
|
||||
isActive: false,
|
||||
},
|
||||
{
|
||||
name: "Users",
|
||||
link: "/users",
|
||||
icon: "Users",
|
||||
newWindow: false,
|
||||
isActive: true,
|
||||
},
|
||||
{
|
||||
name: "Prod Perms",
|
||||
link: "/produsers",
|
||||
icon: "Users",
|
||||
newWindow: false,
|
||||
isActive: true,
|
||||
},
|
||||
{
|
||||
name: "UCD",
|
||||
link: "https://ucd.alpla.net:8443/",
|
||||
icon: "Atom",
|
||||
newWindow: false,
|
||||
isActive: true,
|
||||
},
|
||||
{
|
||||
name: "Lst Api",
|
||||
link: "/api/docs",
|
||||
icon: "Webhook",
|
||||
newWindow: false,
|
||||
isActive: true,
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
export const areSubModulesIn = async () => {
|
||||
try {
|
||||
for (let i = 0; i < newSubModules.length; i++) {
|
||||
const subModuleUpdate = await db
|
||||
.insert(subModules)
|
||||
.values(newSubModules[i])
|
||||
.onConflictDoUpdate({
|
||||
target: subModules.name,
|
||||
set: {
|
||||
name: newSubModules[i].name,
|
||||
moduleName: newSubModules[i].moduleName,
|
||||
description: newSubModules[i].description,
|
||||
roles: newSubModules[i].roles,
|
||||
link: newSubModules[i].link,
|
||||
subSubModule: newSubModules[i].subSubModule,
|
||||
icon: newSubModules[i].icon,
|
||||
},
|
||||
}) // this will only update the ones that are new :D
|
||||
.returning({ name: subModules.name });
|
||||
}
|
||||
createLog(
|
||||
"info",
|
||||
"lst",
|
||||
"server",
|
||||
"SubModules were just added due to missing them on server startup"
|
||||
);
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
createLog(
|
||||
"error",
|
||||
"lst",
|
||||
"server",
|
||||
"There was an error adding new subModules to the db"
|
||||
);
|
||||
}
|
||||
};
|
||||
78
lstV2/server/services/server/utils/testServerPerms.ts
Normal file
78
lstV2/server/services/server/utils/testServerPerms.ts
Normal file
@@ -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\\dist\\server\\scripts\\updatePermissions.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}`);
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user