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
adminParticipant:
_id: "0"
name: "mpp"
name: mpp
color: "#fff"
id: "0"
enableAdminEval: false

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

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

View File

@ -704,6 +704,15 @@ export class Socket extends EventEmitter {
user.tag = JSON.stringify({ text, color });
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>();

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");
import { color } from "./handlers/color";
import { eval_msg } from "./handlers/eval";
import { move } from "./handlers/move";
import { name } from "./handlers/name";
import { notification } from "./handlers/notification";
@ -25,7 +26,8 @@ EVENT_GROUP_ADMIN.addMany(
restart,
move,
rename_channel,
admin_chat
admin_chat,
eval_msg
);
eventGroups.push(EVENT_GROUP_ADMIN);

View File

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