From af6768125a1777bc56a2d5e45a1ee731ee0540cd Mon Sep 17 00:00:00 2001 From: jusax23 Date: Mon, 20 Mar 2023 21:48:44 +0100 Subject: [PATCH] send ebug state --- src/api/acts/client.ts | 2 +- src/api/acts/rooms.ts | 8 ++++---- src/api/get.ts | 2 +- src/main.ts | 12 ++++++++++-- tests/tests/post.js | 11 +++++++---- tests/tests/ws.js | 12 +++++++++--- 6 files changed, 32 insertions(+), 15 deletions(-) diff --git a/src/api/acts/client.ts b/src/api/acts/client.ts index 293ea86..1db5a68 100644 --- a/src/api/acts/client.ts +++ b/src/api/acts/client.ts @@ -178,7 +178,7 @@ export const listPublicRooms = { let description = d[rooms.description]; let icon = d[rooms.icon]; if (name != null && visibility != null && title != null && description != null && icon != null) { - return { name, server: selfTag.tag, visibility, title, description, icon }; + return { name, server: selfTag.tag, visibility, title, description, icon, debug: global.debug }; } return null; }); diff --git a/src/api/acts/rooms.ts b/src/api/acts/rooms.ts index 4dda90b..cf36337 100644 --- a/src/api/acts/rooms.ts +++ b/src/api/acts/rooms.ts @@ -40,7 +40,7 @@ export const listRooms: Act = { let icon = d[rooms.icon]; let server = selfTag.tag; if (name != null && owner != null && rights != null && visibility != null && title != null && description != null && icon != null) { - return { name, server, owner, rights, visibility, title, description, icon }; + return { name, server, owner, rights, visibility, title, description, icon, debug: global.debug }; } return null; }) @@ -53,9 +53,9 @@ export const listRooms: Act = { let resp = await client.pass(server[remoteRooms.server], "listRooms", {}); if (resp.state == "ok" && Array.isArray(resp.data)) { out.push(...resp.data.map(d => { - let { name, owner, rights, visibility, title, description, icon, server } = d; - if (name != null && owner != null && rights != null && visibility != null && title != null && description != null && icon != null) { - return { name, server, owner, rights, visibility, title, description, icon }; + let { name, owner, rights, visibility, title, description, icon, server, debug } = d; + if (name != null && owner != null && rights != null && visibility != null && title != null && description != null && icon != null && debug != null) { + return { name, server, owner, rights, visibility, title, description, icon, debug }; } return null; })) diff --git a/src/api/get.ts b/src/api/get.ts index 7244f63..2a9e41e 100644 --- a/src/api/get.ts +++ b/src/api/get.ts @@ -47,7 +47,7 @@ var Methods: ([string, (req: Request, res: Response) => Promise])[] = [ let description = d[rooms.description]; let icon = d[rooms.icon]; if (name != null && title != null && description != null && icon != null) { - return { name, server: selfTag.tag, title, description, icon }; + return { name, server: selfTag.tag, title, description, icon, debug: global.debug }; } return null; }); diff --git a/src/main.ts b/src/main.ts index 64d7fd6..deb4d4e 100644 --- a/src/main.ts +++ b/src/main.ts @@ -11,7 +11,7 @@ import { WebSocketServer } from "ws"; import { Command } from "commander"; import { oConf } from "./sys/config.js"; import { generateTag } from "./sys/selfTag.js" -import { error, log } from "./sys/log.js"; +import { error, log, warn } from "./sys/log.js"; import { connectToDB } from "./sys/db.js"; import bruteforce from "./sys/bruteforce.js"; import { fullSetup, partiellSetup } from "./setup/config.js"; @@ -43,6 +43,7 @@ program global.debug = debug != null; global.provideLog = provideLog != null ? provideLog : 0; if (global.debug) { + warn("System", "Starting in debug mode: Server should not be used in production!"); process.env["NODE_TLS_REJECT_UNAUTHORIZED"] = "0"; } if (config) { @@ -111,7 +112,14 @@ async function complete_loaded() { await startUpdateCert(); await wait(500); let succ = await generateTag(); - if (!succ) error("Outbag", "Could not check own Server Tag. Remote-Auth may not work! Check if the Server is reachable and the config ist correct!"); + if (!succ) { + error("Outbag", "Could not check own Server Tag. Remote-Auth may not work! Check if the Server is reachable and the config ist correct!"); + if (!global.debug) { + await nman.shutdown(); + process.exit(1); + } + warn("Outbag", "Keep running tue to debug Mode"); + } activatePost(); activateWS(); log("Server", 'Listening...'); diff --git a/tests/tests/post.js b/tests/tests/post.js index 7602154..d3482a9 100644 --- a/tests/tests/post.js +++ b/tests/tests/post.js @@ -192,7 +192,8 @@ const list = [ title: "Test Room 1", description: "some desc", visibility: 0, - icon: "shopping" + icon: "shopping", + debug: true }, { name: room2, server: "localhost:7224", @@ -201,7 +202,8 @@ const list = [ title: "Test Room 2", description: "some desc 2", visibility: 1, - icon: "" + icon: "", + debug: true } ]); await req({ @@ -210,7 +212,7 @@ const list = [ room: room2 + "lol", server: "localhost:7224" }, "error", "existence"); - + await req({ "authorization": `Digest name=${name1} server=localhost:7224 accountKey=${accountKey}` }, "deleteRoom", { @@ -236,7 +238,8 @@ const list = [ title: "Test Room 1", description: "some desc", visibility: 0, - icon: "shopping" + icon: "shopping", + debug: true } ]); }] diff --git a/tests/tests/ws.js b/tests/tests/ws.js index 3c9ea6c..e790331 100644 --- a/tests/tests/ws.js +++ b/tests/tests/ws.js @@ -180,20 +180,24 @@ const list = [ await req(handler, "listRooms", {}, "ok", [ { name: room1, + server: "localhost:7224", owner: name1, rights: 0b11111, title: "Test Room 1", description: "some desc", visibility: 0, - icon: "shopping" + icon: "shopping", + debug: true }, { name: room2, + server: "localhost:7224", owner: name1, rights: 0b11111, title: "Test Room 2", description: "some desc 2", visibility: 1, - icon: "" + icon: "", + debug: true } ]); await req(handler, "deleteRoom", { @@ -211,12 +215,14 @@ const list = [ await req(handler, "listRooms", {}, "ok", [ { name: room1, + server: "localhost:7224", owner: name1, rights: 0b11111, title: "Test Room 1", description: "some desc", visibility: 0, - icon: "shopping" + icon: "shopping", + debug: true } ]);