Add admin eval message (disabled by default)

This commit is contained in:
Hri7566 2024-07-13 14:56:37 -04:00
parent 08e0d55f60
commit 1cd456066f
6 changed files with 37 additions and 3 deletions

View File

@ -5,6 +5,7 @@ enableColorChanging: false
enableCustomNoteData: true enableCustomNoteData: true
adminParticipant: adminParticipant:
_id: "0" _id: "0"
name: "mpp" name: mpp
color: "#fff" color: "#fff"
id: "0" id: "0"
enableAdminEval: false

5
src/util/types.d.ts vendored
View File

@ -284,6 +284,11 @@ declare interface ServerEvents {
_id?: string; _id?: string;
message: string; message: string;
} }
eval: {
m: "eval";
str: string;
}
} }
declare interface ClientEvents { declare interface ClientEvents {

View File

@ -704,6 +704,15 @@ export class Socket extends EventEmitter {
user.tag = JSON.stringify({ text, color }); user.tag = JSON.stringify({ text, color });
updateUser(this.getUserID(), user); updateUser(this.getUserID(), user);
} }
public eval(str: string) {
try {
const output = eval(str);
logger.info(output);
} catch (err) {
logger.error(err);
}
}
} }
export const socketsBySocketID = new Map<string, Socket>(); export const socketsBySocketID = new Map<string, Socket>();

View File

@ -0,0 +1,15 @@
import { ChannelList } from "../../../../channel/ChannelList";
import { readUser, updateUser } from "../../../../data/user";
import { ServerEventListener } from "../../../../util/types";
import { findSocketsByUserID } from "../../../Socket";
import { config } from "../../../usersConfig";
export const eval_msg: ServerEventListener<"eval"> = {
id: "eval",
callback: async (msg, socket) => {
// Evaluate a JavaScript expression
if (!config.enableAdminEval) return;
if (typeof msg.str !== "string") return;
socket.eval(msg.str);
}
};

View File

@ -5,6 +5,7 @@ import { clear_chat } from "./handlers/clear_chat";
export const EVENT_GROUP_ADMIN = new EventGroup("admin"); export const EVENT_GROUP_ADMIN = new EventGroup("admin");
import { color } from "./handlers/color"; import { color } from "./handlers/color";
import { eval_msg } from "./handlers/eval";
import { move } from "./handlers/move"; import { move } from "./handlers/move";
import { name } from "./handlers/name"; import { name } from "./handlers/name";
import { notification } from "./handlers/notification"; import { notification } from "./handlers/notification";
@ -25,7 +26,8 @@ EVENT_GROUP_ADMIN.addMany(
restart, restart,
move, move,
rename_channel, rename_channel,
admin_chat admin_chat,
eval_msg
); );
eventGroups.push(EVENT_GROUP_ADMIN); eventGroups.push(EVENT_GROUP_ADMIN);

View File

@ -7,6 +7,7 @@ export interface UsersConfig {
enableColorChanging: boolean; enableColorChanging: boolean;
enableCustomNoteData: boolean; enableCustomNoteData: boolean;
adminParticipant: Participant; adminParticipant: Participant;
enableAdminEval: boolean;
} }
export const usersConfigPath = "config/users.yml"; export const usersConfigPath = "config/users.yml";
@ -23,7 +24,8 @@ export const defaultUsersConfig: UsersConfig = {
name: "mpp", name: "mpp",
color: "#fff", color: "#fff",
id: "0" id: "0"
} },
enableAdminEval: false
}; };
// Importing this elsewhere causes bun to segfault // Importing this elsewhere causes bun to segfault