From 888a4ef01cdfb838abf710da8164c9de5da3dfa5 Mon Sep 17 00:00:00 2001 From: Elijah R Date: Thu, 1 Aug 2024 00:26:08 -0400 Subject: [PATCH] re-add support for servers without auth --- config.example.json | 1 + src/config.ts | 3 ++- src/index.ts | 16 +++++++++++++--- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/config.example.json b/config.example.json index 50ccf4a..ff16ed5 100644 --- a/config.example.json +++ b/config.example.json @@ -23,6 +23,7 @@ ], "BOT_PREFIX": "!", "ADMIN_TOKEN": "get_your_own_bot_token", + "ADMIN_PASSWORD": "yourPasswordGoesHere", "kGeneralLimitBaseSeconds": 6, "kRebootLimitBaseSeconds": 25 } diff --git a/src/config.ts b/src/config.ts index bd73c53..dc0c949 100644 --- a/src/config.ts +++ b/src/config.ts @@ -9,7 +9,8 @@ export default interface Config { hasUsb: boolean; }[]; BOT_PREFIX: string; - ADMIN_TOKEN: string; + ADMIN_TOKEN: string | undefined; + ADMIN_PASSWORD: string | undefined; kGeneralLimitBaseSeconds: number; kRebootLimitBaseSeconds: number; } diff --git a/src/index.ts b/src/index.ts index f569f0c..99ddd6b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -6,6 +6,11 @@ import Config from "./config.js"; let config: Config = JSON.parse(fs.readFileSync("config.json", "utf-8")); +if (!config.ADMIN_PASSWORD && !config.ADMIN_TOKEN) { + console.error("Either ADMIN_PASSWORD or ADMIN_TOKEN must be defined in config.json"); + process.exit(1); +} + const blankflp = Buffer.alloc(1440000); if (!fs.existsSync("media/flp/")) fs.mkdirSync("media/flp/", { recursive: true }); @@ -241,7 +246,8 @@ class HelperBot extends CollabVMClient { // This should disallow unregistered users, // please don't fuck the rank up to where I can't do this - if (!(user.GetRank() >= 1)) { + // hack lol + if (config.ADMIN_TOKEN && user.GetRank() === 0) { return; } } @@ -616,8 +622,12 @@ class HelperBot extends CollabVMClient { } Log(`[${this._vmId}]`, `Connected to VM`); - // I'm fucking lazy - this.SendGuacamoleMessage("login", config.ADMIN_TOKEN); + if (config.ADMIN_PASSWORD) { + this.SendGuacamoleMessage("admin", "2", config.ADMIN_PASSWORD); + } else if (config.ADMIN_TOKEN) { + this.SendGuacamoleMessage("login", config.ADMIN_TOKEN); + } + this.CreateRateLimits(); }