format with prettier

This commit is contained in:
Elijah R 2024-06-23 18:45:14 -04:00
parent 5fd343c87b
commit c0e1f9c830
4 changed files with 728 additions and 653 deletions

1
.prettierrc Normal file
View file

@ -0,0 +1 @@
{}

102
client.js
View file

@ -1,5 +1,5 @@
// Small single-file CollabVM client library, in semi-modern Javascript // Small single-file CollabVM client library, in semi-modern Javascript
import * as ws from 'ws'; import * as ws from "ws";
const guacutils = { const guacutils = {
parse: (string) => { parse: (string) => {
@ -7,49 +7,49 @@ const guacutils = {
let sections = []; let sections = [];
for (;;) { for (;;) {
let len=string.indexOf('.', pos + 1); let len = string.indexOf(".", pos + 1);
if(len === -1) if (len === -1) break;
break;
pos=parseInt(string.slice(pos + 1, len)) + len + 1 pos = parseInt(string.slice(pos + 1, len)) + len + 1;
sections.push(string.slice(len + 1, pos) sections.push(
string
.slice(len + 1, pos)
.replace(/'/g, "'") .replace(/'/g, "'")
.replace(/"/g, '"') .replace(/"/g, '"')
.replace(///g, '/') .replace(///g, "/")
.replace(/&lt;/g, '<') .replace(/&lt;/g, "<")
.replace(/&gt;/g, '>') .replace(/&gt;/g, ">")
.replace(/&amp;/g, '&') .replace(/&amp;/g, "&"),
); );
if(string.slice(pos, pos + 1) === ';') if (string.slice(pos, pos + 1) === ";") break;
break;
} }
return sections; return sections;
}, },
encode: (cypher) => { encode: (cypher) => {
let command = ''; let command = "";
for (var i = 0; i < cypher.length; i++) { for (var i = 0; i < cypher.length; i++) {
let current = cypher[i]; let current = cypher[i];
command += current.length + '.' + current; command += current.length + "." + current;
command += ( i < cypher.length - 1 ? ',' : ';'); command += i < cypher.length - 1 ? "," : ";";
} }
return command; return command;
} },
}; };
const ConnectionState = Object.freeze({ const ConnectionState = Object.freeze({
CLOSED: 0, CLOSED: 0,
CONNECTING: 1, CONNECTING: 1,
CONNECTED: 2 CONNECTED: 2,
}); });
// System chat messages have a nil username. // System chat messages have a nil username.
function IsSystemChatInstruction(inst) { function IsSystemChatInstruction(inst) {
return inst[1] == ''; return inst[1] == "";
} }
class UserData { class UserData {
@ -61,28 +61,35 @@ class UserData {
this._rank = rank; this._rank = rank;
} }
GetName() { return this._name; } GetName() {
GetRank() { return this._rank; } return this._name;
}
GetRank() {
return this._rank;
}
UpdateRank(new_rank) { this._rank = new_rank; } UpdateRank(new_rank) {
this._rank = new_rank;
}
} }
export default class CollabVMClient { export default class CollabVMClient {
constructor() { constructor() {
this._state = ConnectionState.CLOSED; this._state = ConnectionState.CLOSED;
this._users = []; this._users = [];
} }
GetState() { return this._state; } GetState() {
return this._state;
}
Connect(uri) { Connect(uri) {
this._ws = new ws.WebSocket(uri, 'guacamole', { this._ws = new ws.WebSocket(uri, "guacamole", {
origin: "https://computernewb.com" origin: "https://computernewb.com",
}); });
this._ws.onopen = this.OnWebSocketOpen.bind(this); this._ws.onopen = this.OnWebSocketOpen.bind(this);
this._ws.onclose = this.OnWebSocketClose.bind(this); this._ws.onclose = this.OnWebSocketClose.bind(this);
this._ws.onerror = this.OnWebSocketError.bind(this) this._ws.onerror = this.OnWebSocketError.bind(this);
this._ws.onmessage = this.OnWebSocketMessage.bind(this); this._ws.onmessage = this.OnWebSocketMessage.bind(this);
this._state = ConnectionState.CONNECTING; this._state = ConnectionState.CONNECTING;
} }
@ -110,12 +117,10 @@ export default class CollabVMClient {
OnWebSocketMessage(ev) { OnWebSocketMessage(ev) {
// cvm server should never send binary data // cvm server should never send binary data
if(typeof(ev.data) !== "string") if (typeof ev.data !== "string") return;
return;
let message = guacutils.parse(ev.data); let message = guacutils.parse(ev.data);
if(message.length === 0) if (message.length === 0) return;
return;
// Hardcoded, we need to keep this to be alive // Hardcoded, we need to keep this to be alive
if (message[0] === "nop") { if (message[0] === "nop") {
@ -128,7 +133,11 @@ export default class CollabVMClient {
// console.log(`FUCK (${message.length}) ${message[1]} ${message[2]}`) // console.log(`FUCK (${message.length}) ${message[1]} ${message[2]}`)
//} //}
if(message[0] === "chat" && message.length === 3 && !IsSystemChatInstruction(message)) { if (
message[0] === "chat" &&
message.length === 3 &&
!IsSystemChatInstruction(message)
) {
if (message[1] != this._username) { if (message[1] != this._username) {
//console.log(`FUCK 2 (${message.length}) ${message[1]} ${message[2]}`) //console.log(`FUCK 2 (${message.length}) ${message[1]} ${message[2]}`)
this.OnChat(message[1], message[2]); this.OnChat(message[1], message[2]);
@ -147,7 +156,7 @@ export default class CollabVMClient {
// Handle renames // Handle renames
if (message[0] === "rename") { if (message[0] === "rename") {
if (message.length === 5) { if (message.length === 5) {
if(message[1] == '1') { if (message[1] == "1") {
this._username = message[3]; this._username = message[3];
} }
} }
@ -164,7 +173,7 @@ export default class CollabVMClient {
//console.log(`[${this.GetVM()}] user ${name} rank ${rank}`) //console.log(`[${this.GetVM()}] user ${name} rank ${rank}`)
let existingUser = this._users.find(elem => elem.GetName() == name); let existingUser = this._users.find((elem) => elem.GetName() == name);
if (existingUser === undefined) { if (existingUser === undefined) {
//console.log(`[${this.GetVM()}] New user ${name} rank ${rank}`) //console.log(`[${this.GetVM()}] New user ${name} rank ${rank}`)
this._users.push(new UserData(name, rank)); this._users.push(new UserData(name, rank));
@ -182,7 +191,7 @@ export default class CollabVMClient {
OnRemUser(users, count) { OnRemUser(users, count) {
for (var i = 0; i < count; i++) { for (var i = 0; i < count; i++) {
let saveUserTemp = this.GetUser(users[i]); let saveUserTemp = this.GetUser(users[i]);
this._users = this._users.filter(user => user.GetName() != users[i]); this._users = this._users.filter((user) => user.GetName() != users[i]);
} }
this.OnRemUser_Bot(this.GetUserCount()); this.OnRemUser_Bot(this.GetUserCount());
@ -195,7 +204,7 @@ export default class CollabVMClient {
//"General Darian" //"General Darian"
// logger bots // logger bots
"Specialized Egg", "Specialized Egg",
"Emperor Kevin" "Emperor Kevin",
]; ];
var len = this._users.length; var len = this._users.length;
@ -203,11 +212,10 @@ export default class CollabVMClient {
// subtract known bots // subtract known bots
for (var i = len - 1; i != 0; --i) { for (var i = len - 1; i != 0; --i) {
// ? // ?
if(this._users[i] === undefined) if (this._users[i] === undefined) return;
return;
var name = this._users[i].GetName(); var name = this._users[i].GetName();
if(KnownBots.find(elem => name == elem) !== undefined) { if (KnownBots.find((elem) => name == elem) !== undefined) {
//console.log("found blacklisted username", name) //console.log("found blacklisted username", name)
len--; len--;
} }
@ -216,7 +224,6 @@ export default class CollabVMClient {
return len; return len;
} }
GetUserCountFull() { GetUserCountFull() {
return this._users.length; return this._users.length;
} }
@ -226,23 +233,26 @@ export default class CollabVMClient {
} }
GetUser(username) { GetUser(username) {
let existingUser = this._users.find(elem => elem.GetName() == username); let existingUser = this._users.find((elem) => elem.GetName() == username);
// Apparently this can fail somehow..? // Apparently this can fail somehow..?
if(existingUser === undefined) if (existingUser === undefined) return null;
return null;
return existingUser; return existingUser;
} }
GetUsername() { return this._username; } GetUsername() {
return this._username;
}
Rename(name) { Rename(name) {
this._username = name; this._username = name;
this.SendGuacamoleMessage("rename", name); this.SendGuacamoleMessage("rename", name);
} }
GetVM() { return this._vm; } GetVM() {
return this._vm;
}
ConnectToVM(vm) { ConnectToVM(vm) {
this._vm = vm; this._vm = vm;
@ -250,10 +260,8 @@ export default class CollabVMClient {
} }
SendGuacamoleMessage() { SendGuacamoleMessage() {
if(this._state !== ConnectionState.CONNECTED) if (this._state !== ConnectionState.CONNECTED) return;
return;
this._ws.send(guacutils.encode(Array.prototype.slice.call(arguments))); this._ws.send(guacutils.encode(Array.prototype.slice.call(arguments)));
} }
} }

375
index.js
View file

@ -1,12 +1,19 @@
import CollabVMClient from './client.js'; import CollabVMClient from "./client.js";
import {BANNED_ISO, ISO_DIRECTORIES, INSTALLBOT_VMS, BOT_PREFIX, ADMIN_TOKEN, kGeneralLimitBaseSeconds, kRebootLimitBaseSeconds} from './config.js'; import {
BANNED_ISO,
ISO_DIRECTORIES,
INSTALLBOT_VMS,
BOT_PREFIX,
ADMIN_TOKEN,
kGeneralLimitBaseSeconds,
kRebootLimitBaseSeconds,
} from "./config.js";
function Log() { function Log() {
// console.log(`[AnyOSBot] [${new Date()}]`, [...arguments].join(' ')) // console.log(`[AnyOSBot] [${new Date()}]`, [...arguments].join(' '))
console.log('[AnyOSBot]', [...arguments].join(' ')) console.log("[AnyOSBot]", [...arguments].join(" "));
} }
// you people SUCK man (dynamic edition, with less bugs!) // you people SUCK man (dynamic edition, with less bugs!)
// and it actually probably works without hanging or negative seconds this time. // and it actually probably works without hanging or negative seconds this time.
class RateLimit { class RateLimit {
@ -27,26 +34,20 @@ class RateLimit {
} }
GetMs() { GetMs() {
let ret = Math.floor( let ret = Math.floor(this._n * (1 / 5) * this._timeBase * this._factor);
((this._n * (1/5)) * this._timeBase) * this._factor
);
// Make sure it's at least time base // Make sure it's at least time base
if(ret < 1000) if (ret < 1000) ret = this._timeBase;
ret = this._timeBase;
// Clean out fractional milliseconds // Clean out fractional milliseconds
if((ret % 1000) != 0) if (ret % 1000 != 0) ret -= ret % 1000;
ret -= (ret % 1000);
//Log(`Debug: Ratelimit returns ${ret} (where N = ${this._n})`); //Log(`Debug: Ratelimit returns ${ret} (where N = ${this._n})`);
return ret; return ret;
} }
SetUserCount(count) { SetUserCount(count) {
if(count == 0) if (count == 0) count = 1;
count = 1;
this._n = count; this._n = count;
//Log(`Debug: Ratelimit \"${this._ident}\" count set to ${count}, algo says time will be: ${this.GetMs()} (${this.GetMs() / 1000} seconds)`); //Log(`Debug: Ratelimit \"${this._ident}\" count set to ${count}, algo says time will be: ${this.GetMs()} (${this.GetMs() / 1000} seconds)`);
@ -54,18 +55,19 @@ class RateLimit {
StartLimit() { StartLimit() {
// TODO: this might work for the dyna ratelimit? // TODO: this might work for the dyna ratelimit?
if(this._limited) if (this._limited) return;
return;
let self = this; let self = this;
self._msUntil = this.GetMs(); self._msUntil = this.GetMs();
Log(`Ratelimit \"${this._ident}\" started, will be done in ${self._msUntil} ms (${self._msUntil / 1000} seconds)`); Log(
`Ratelimit \"${this._ident}\" started, will be done in ${self._msUntil} ms (${self._msUntil / 1000} seconds)`,
);
self._limited = true; self._limited = true;
this._siHandle = setInterval(() => { this._siHandle = setInterval(() => {
self._msUntil -= 1000; self._msUntil -= 1000;
if (self._msUntil <= 0) { if (self._msUntil <= 0) {
Log(`Ratelimit \"${self._ident}\" is done.`) Log(`Ratelimit \"${self._ident}\" is done.`);
clearInterval(self._siHandle); clearInterval(self._siHandle);
self._limited = false; self._limited = false;
return; return;
@ -76,15 +78,13 @@ class RateLimit {
ToString() { ToString() {
const time = Math.floor(this.GetTime() / 1000); const time = Math.floor(this.GetTime() / 1000);
let second_or_seconds = () => { let second_or_seconds = () => {
if(time > 1 || time === 0) if (time > 1 || time === 0) return "seconds";
return "seconds";
return "second"; return "second";
}; };
return `${time} ${second_or_seconds()}`; return `${time} ${second_or_seconds()}`;
} }
} }
class HelperBot extends CollabVMClient { class HelperBot extends CollabVMClient {
constructor(wsUri, vmId, ide2, floppy) { constructor(wsUri, vmId, ide2, floppy) {
super(); super();
@ -93,7 +93,6 @@ class HelperBot extends CollabVMClient {
this._vmId = vmId; this._vmId = vmId;
this._ide2 = ide2; this._ide2 = ide2;
this._hasFloppy = floppy; this._hasFloppy = floppy;
} }
DoConn() { DoConn() {
@ -124,7 +123,6 @@ class HelperBot extends CollabVMClient {
}, 1000 * 5) }, 1000 * 5)
*/ */
Log(`[${this._vmId}]`, `Connection closed, exiting process`); Log(`[${this._vmId}]`, `Connection closed, exiting process`);
process.exit(0); process.exit(0);
@ -135,7 +133,6 @@ class HelperBot extends CollabVMClient {
this.SendGuacamoleMessage("chat", message); this.SendGuacamoleMessage("chat", message);
} }
OnAddUser_Bot(count) { OnAddUser_Bot(count) {
this.GeneralCmdLimit.SetUserCount(count); this.GeneralCmdLimit.SetUserCount(count);
this.RebootLimit.SetUserCount(count); this.RebootLimit.SetUserCount(count);
@ -150,14 +147,12 @@ class HelperBot extends CollabVMClient {
let existingUser = this.GetUser(username); let existingUser = this.GetUser(username);
// Apparently this can fail somehow..? // Apparently this can fail somehow..?
if(existingUser == null) if (existingUser == null) return false;
return false;
let rank = existingUser.GetRank(); let rank = existingUser.GetRank();
return rank == 2 || rank == 3; return rank == 2 || rank == 3;
} }
SendMonitorCommand(cmd) { SendMonitorCommand(cmd) {
this.SendGuacamoleMessage("admin", "5", this.GetVM(), cmd); this.SendGuacamoleMessage("admin", "5", this.GetVM(), cmd);
} }
@ -183,22 +178,17 @@ class HelperBot extends CollabVMClient {
} }
QemuEjectCd() { QemuEjectCd() {
if(this._ide2) if (this._ide2) this.QemuEjectDevice("ide2-cd0");
this.QemuEjectDevice("ide2-cd0"); else this.QemuEjectDevice("vm.cd");
else
this.QemuEjectDevice("vm.cd");
} }
QemuEjectFloppy() { QemuEjectFloppy() {
if(this._hasFloppy) if (this._hasFloppy) this.QemuEjectDevice("vm.floppy");
this.QemuEjectDevice("vm.floppy");
} }
QemuChangeCd(source, opts) { QemuChangeCd(source, opts) {
if(this._ide2) if (this._ide2) this.QemuChangeDevice("ide2-cd0", source, opts);
this.QemuChangeDevice("ide2-cd0", source, opts); else this.QemuChangeDevice("vm.cd", source, opts);
else
this.QemuChangeDevice("vm.cd", source, opts);
} }
QemuChangeFloppy(source) { QemuChangeFloppy(source) {
@ -206,12 +196,10 @@ class HelperBot extends CollabVMClient {
this.QemuChangeDevice("vm.floppy", source, "raw read-only"); this.QemuChangeDevice("vm.floppy", source, "raw read-only");
} }
OnChat(username, message) { OnChat(username, message) {
//console.log(`${username}> ${message}`); //console.log(`${username}> ${message}`);
if(username == this.GetUsername()) if (username == this.GetUsername()) return;
return;
if (message[0] === BOT_PREFIX) { if (message[0] === BOT_PREFIX) {
this.HandleCommands(username, message); this.HandleCommands(username, message);
@ -239,11 +227,12 @@ class HelperBot extends CollabVMClient {
const DoLimit = (limit) => { const DoLimit = (limit) => {
//console.log(`[AnyOSBot] [${this._vmId}] ${this.GetUserCount()} users online (${this.GetUserCountFull()} actual)`) //console.log(`[AnyOSBot] [${this._vmId}] ${this.GetUserCount()} users online (${this.GetUserCountFull()} actual)`)
//if(this._vmId !== 'vm0b0t') { //if(this._vmId !== 'vm0b0t') {
// //
if (limit.IsLimited() && !this.UserCanBypass(username)) { if (limit.IsLimited() && !this.UserCanBypass(username)) {
this.Chat(`You may not use commands yet. Please wait ${limit.ToString()}.`); this.Chat(
`You may not use commands yet. Please wait ${limit.ToString()}.`,
);
return false; return false;
} }
//} //}
@ -257,20 +246,19 @@ class HelperBot extends CollabVMClient {
limit.StartLimit(); limit.StartLimit();
} }
return true; return true;
} };
// generate a help HTML string for the help // generate a help HTML string for the help
const generateHelp = (arr) => { const generateHelp = (arr) => {
let str = "<h4>AnyOSInstallBot Help:</h4><ul>"; let str = "<h4>AnyOSInstallBot Help:</h4><ul>";
for (var cmd of arr) { for (var cmd of arr) {
// remove commands which depend on the floppy on a VM without floppy // remove commands which depend on the floppy on a VM without floppy
if(cmd.usesFloppy && !this._hasFloppy) if (cmd.usesFloppy && !this._hasFloppy) continue;
continue;
str += `<li><b>${BOT_PREFIX}${cmd.command}</b> - ${cmd.help}</li>`; str += `<li><b>${BOT_PREFIX}${cmd.command}</b> - ${cmd.help}</li>`;
} }
str += "</ul>"; str += "</ul>";
return str; return str;
} };
const generateList = (title, arr) => { const generateList = (title, arr) => {
let str = `<h4>${title}</h4><ul>`; let str = `<h4>${title}</h4><ul>`;
@ -279,58 +267,96 @@ class HelperBot extends CollabVMClient {
} }
str += "</ul>"; str += "</ul>";
return str; return str;
} };
let command = "";
if (message.indexOf(" ") !== -1)
command = message.slice(1, message.indexOf(" "));
let command = ''; else command = message.slice(1);
if(message.indexOf(' ') !== -1)
command = message.slice(1, message.indexOf(' '));
else
command = message.slice(1);
switch (command) { switch (command) {
case 'help': case "help":
if(!DoLimit(this.GeneralCmdLimit)) if (!DoLimit(this.GeneralCmdLimit)) return;
return; this.SendGuacamoleMessage(
this.SendGuacamoleMessage("admin", "21", generateHelp([ "admin",
{ command: "certerror", help: "Provides information on the CollabNet SSL certificate" }, "21",
generateHelp([
{
command: "certerror",
help: "Provides information on the CollabNet SSL certificate",
},
{ command: "network", help: "Provides network driver information" }, { command: "network", help: "Provides network driver information" },
{ command: "cd [path]", help: "Change CD image to Computernewb ISO image (see computernewb.com/isos)" }, {
{ command: "lilycd [path]", help: "Change CD image to Lily ISO image (see computernewb.com/~lily/ISOs)" }, command: "cd [path]",
{ command: "crustycd [path]", help: "Change CD image to CrustyWindows ISO image (see crustywindo.ws/collection)" }, help: "Change CD image to Computernewb ISO image (see computernewb.com/isos)",
{ command: "flp [path]", help: "Change Floppy image to Dartz IMG/flp image", usesFloppy: true }, },
{ command: "lilyflp [path]", help: "Change Floppy image to Lily IMG/flp image", usesFloppy: true }, {
{ command: "httpcd [URL]", help: "Change CD image to HTTP server ISO file. Whitelisted domains only (see computernewb.com/CHOCOLATEMAN/domains.txt for a list)" }, command: "lilycd [path]",
{ command: "eject [cd/flp]", help: "Ejects media from the specified drive." }, help: "Change CD image to Lily ISO image (see computernewb.com/~lily/ISOs)",
{ command: "reboot", help: "Reboot the VM. Has a larger cooldown, so don't be a retard with it." }, },
{ command: "bootset [string of c,a,d,n]", help: "Change the VM's boot order" }, {
])); command: "crustycd [path]",
help: "Change CD image to CrustyWindows ISO image (see crustywindo.ws/collection)",
},
{
command: "flp [path]",
help: "Change Floppy image to Dartz IMG/flp image",
usesFloppy: true,
},
{
command: "lilyflp [path]",
help: "Change Floppy image to Lily IMG/flp image",
usesFloppy: true,
},
{
command: "httpcd [URL]",
help: "Change CD image to HTTP server ISO file. Whitelisted domains only (see computernewb.com/CHOCOLATEMAN/domains.txt for a list)",
},
{
command: "eject [cd/flp]",
help: "Ejects media from the specified drive.",
},
{
command: "reboot",
help: "Reboot the VM. Has a larger cooldown, so don't be a retard with it.",
},
{
command: "bootset [string of c,a,d,n]",
help: "Change the VM's boot order",
},
]),
);
return; return;
break; break;
case 'network': case "network":
if(!DoLimit(this.GeneralCmdLimit)) if (!DoLimit(this.GeneralCmdLimit)) return;
return;
switch (this._vmId) { switch (this._vmId) {
case "vm7": case "vm7":
this.SendGuacamoleMessage("admin", "21", generateList("VirtIO Network Setup Instructions (Windows):", [ this.SendGuacamoleMessage(
"Run \"!cd driver/virtio-win-0.1.225.iso\" to insert the VirtIO driver CD into the VM.", "admin",
"Run \"devmgmt.msc\" in the VM, look for the \"Ethernet Controller\" device, and update its driver.", "21",
generateList("VirtIO Network Setup Instructions (Windows):", [
'Run "!cd driver/virtio-win-0.1.225.iso" to insert the VirtIO driver CD into the VM.',
'Run "devmgmt.msc" in the VM, look for the "Ethernet Controller" device, and update its driver.',
"When asked for a path, put in D:\\NetKVM\\{OS}\\x86 (or on a 64-bit OS, D:\\NetKVM\\{OS}\\amd64)", "When asked for a path, put in D:\\NetKVM\\{OS}\\x86 (or on a 64-bit OS, D:\\NetKVM\\{OS}\\amd64)",
"After that, see the !certerror command." "After that, see the !certerror command.",
])); ]),
);
break; break;
case "vm8": case "vm8":
this.SendGuacamoleMessage("admin", "21", generateList("RTL8139 Network Setup Instructions (Windows):", [ this.SendGuacamoleMessage(
"Run \"!cd Driver/VM8 Network Drivers.iso\" to insert the RTL8139 network driver CD into the VM.", "admin",
"Run \"devmgmt.msc\" in the VM, look for the \"Ethernet Controller\" device, and update its driver.", "21",
generateList("RTL8139 Network Setup Instructions (Windows):", [
'Run "!cd Driver/VM8 Network Drivers.iso" to insert the RTL8139 network driver CD into the VM.',
'Run "devmgmt.msc" in the VM, look for the "Ethernet Controller" device, and update its driver.',
"When asked for a path, put in D:\\(name of OS)\\. For example, on Windows NT 4, put in D:\\WINNT4\\ (click browse and select the OS if you can't figure it out)", "When asked for a path, put in D:\\(name of OS)\\. For example, on Windows NT 4, put in D:\\WINNT4\\ (click browse and select the OS if you can't figure it out)",
"After that, you should be online. This step should NOT be required on Windows 2000, XP, Vista, or 7. This step should not be required on ANY Linux distro unless its really shit." "After that, you should be online. This step should NOT be required on Windows 2000, XP, Vista, or 7. This step should not be required on ANY Linux distro unless its really shit.",
])); ]),
);
break; break;
default: default:
this.chat("This VM should already have internet."); this.chat("This VM should already have internet.");
@ -339,35 +365,37 @@ class HelperBot extends CollabVMClient {
break; break;
case 'certerror': case "certerror":
if(!DoLimit(this.GeneralCmdLimit)) if (!DoLimit(this.GeneralCmdLimit)) return;
return;
//if(this._vmId == 'vm0b0t') { //if(this._vmId == 'vm0b0t') {
// this.SendGuacamoleMessage("admin", "21", "<h1>fuck off retard why are you trying to get collabnet on vm0</h1>"); // this.SendGuacamoleMessage("admin", "21", "<h1>fuck off retard why are you trying to get collabnet on vm0</h1>");
// return; // return;
//} //}
this.SendGuacamoleMessage("admin", "21", generateList("CollabNet Setup Instructions:", [ this.SendGuacamoleMessage(
"Follow the instructions on http://192.168.1.1 to install the certificate." "admin",
])); "21",
generateList("CollabNet Setup Instructions:", [
"Follow the instructions on http://192.168.1.1 to install the certificate.",
]),
);
break; break;
// this is gigantic holy fuck // this is gigantic holy fuck
case 'cd': case "cd":
case 'lilycd': case "lilycd":
case 'crustycd': case "crustycd":
case 'flp': case "flp":
case 'lilyflp': case "lilyflp":
case 'httpcd': case "httpcd":
case 'httpflp': { case "httpflp":
if(!DoLimit(this.GeneralCmdLimit)) {
return; if (!DoLimit(this.GeneralCmdLimit)) return;
let arg = message.slice(message.indexOf(' ')+1); let arg = message.slice(message.indexOf(" ") + 1);
let ext = arg.slice(arg.lastIndexOf('.') + 1); let ext = arg.slice(arg.lastIndexOf(".") + 1);
if(arg.indexOf('..') !== -1) if (arg.indexOf("..") !== -1) return;
return;
for (var ii = 0; ii < BANNED_ISO.length; ii++) { for (var ii = 0; ii < BANNED_ISO.length; ii++) {
if (BANNED_ISO[ii].test(arg)) { if (BANNED_ISO[ii].test(arg)) {
this.Chat("That ISO is currently blacklisted."); this.Chat("That ISO is currently blacklisted.");
@ -376,35 +404,42 @@ class HelperBot extends CollabVMClient {
} }
switch (command) { switch (command) {
case 'cd': case "cd":
case 'lilycd': case "lilycd":
case 'crustycd': case "crustycd":
if(arg.indexOf('http://') !== -1 || arg.indexOf('https://') != -1) { if (
this.Chat("Use the http versions of these commands, if the iso is locally hosted you can try !command Path/iso.iso (case-sensitive)") arg.indexOf("http://") !== -1 ||
arg.indexOf("https://") != -1
) {
this.Chat(
"Use the http versions of these commands, if the iso is locally hosted you can try !command Path/iso.iso (case-sensitive)",
);
return; return;
} }
if (ext.toLowerCase() === "iso") { if (ext.toLowerCase() === "iso") {
// repetitive but whatever it works // repetitive but whatever it works
if(command === 'lilycd') if (command === "lilycd")
this.QemuChangeCd(this.ConcatPath('lily', arg), ""); this.QemuChangeCd(this.ConcatPath("lily", arg), "");
else if (command == 'crustycd') else if (command == "crustycd")
this.QemuChangeCd(this.ConcatPath('crustywin', arg), ""); this.QemuChangeCd(this.ConcatPath("crustywin", arg), "");
else if (command == 'cd') else if (command == "cd")
this.QemuChangeCd(this.ConcatPath('computernewb', arg), ""); this.QemuChangeCd(this.ConcatPath("computernewb", arg), "");
//this.QemuChangeCd(this.ConcatPath(command === 'lilycd' && 'lily' || command === "crustycd" && 'crustywin' || 'computernewb', arg), ""); //this.QemuChangeCd(this.ConcatPath(command === 'lilycd' && 'lily' || command === "crustycd" && 'crustywin' || 'computernewb', arg), "");
} }
break; break;
case 'flp': case "flp":
case 'lilyflp': case "lilyflp":
if(arg.indexOf('http://') !== -1 || arg.indexOf('https://') != -1) { if (
this.Chat("Use the http versions of these commands") arg.indexOf("http://") !== -1 ||
arg.indexOf("https://") != -1
) {
this.Chat("Use the http versions of these commands");
return; return;
} }
if (!this._hasFloppy) { if (!this._hasFloppy) {
this.Chat("This VM does not have a floppy drive."); this.Chat("This VM does not have a floppy drive.");
return; return;
@ -416,19 +451,33 @@ class HelperBot extends CollabVMClient {
} }
if (ext.toLowerCase() === "img" || ext.toLowerCase() === "ima") { if (ext.toLowerCase() === "img" || ext.toLowerCase() === "ima") {
this.QemuChangeFloppy(this.ConcatPath(command === 'lilyflp' ? 'lily' : 'computernewb', arg)); this.QemuChangeFloppy(
this.ConcatPath(
command === "lilyflp" ? "lily" : "computernewb",
arg,
),
);
} }
break; break;
case 'httpcd': case "httpcd":
//this.Chat("Disabled due to retards, sorry! Try !cd, !lilycd or !crustycd for some local isos."); //this.Chat("Disabled due to retards, sorry! Try !cd, !lilycd or !crustycd for some local isos.");
//return; //return;
// whitelisted domains // whitelisted domains
const whitelist = ['http://kernel.org', 'https://kernel.org', 'http://distro.ibiblio.org', const whitelist = [
'https://distro.ibiblio.org', 'https://dl.collabsysos.xyz', 'https://egg.l5.ca', "http://kernel.org",
'https://download.manjaro.org', 'https://ubuntu.osuosl.org/', 'https://mirror.kku.ac.th/', "https://kernel.org",
'https://cdimage.debian.org', 'https://archive.elijahr.dev/Games/pcgc.iso' ]; "http://distro.ibiblio.org",
"https://distro.ibiblio.org",
"https://dl.collabsysos.xyz",
"https://egg.l5.ca",
"https://download.manjaro.org",
"https://ubuntu.osuosl.org/",
"https://mirror.kku.ac.th/",
"https://cdimage.debian.org",
"https://archive.elijahr.dev/Games/pcgc.iso",
];
/*var is_founded = false; // this might not be elegant sorry - Hilda /*var is_founded = false; // this might not be elegant sorry - Hilda
for (var piss in whitelist) { for (var piss in whitelist) {
@ -440,9 +489,9 @@ class HelperBot extends CollabVMClient {
}*/ }*/
// Yeah I knew it, thanks modeco! - Hilda // Yeah I knew it, thanks modeco! - Hilda
let is_founded = (() => whitelist.find(e => arg.startsWith(e)) !== undefined)(); let is_founded = (() =>
if(is_founded === false) whitelist.find((e) => arg.startsWith(e)) !== undefined)();
{ if (is_founded === false) {
//this.Chat("This is sparta!"); //this.Chat("This is sparta!");
return; return;
} }
@ -459,16 +508,20 @@ class HelperBot extends CollabVMClient {
return; return;
}*/ // wait im retarded whitelist }*/ // wait im retarded whitelist
if(ext.toLowerCase() === "iso") if (ext.toLowerCase() === "iso") this.QemuChangeCd(arg, "");
this.QemuChangeCd(arg, "");
break; break;
case 'httpflp': case "httpflp":
//this.Chat("Disabled due to retards; sorry!"); //this.Chat("Disabled due to retards; sorry!");
//return; //return;
if(arg.indexOf('~dartz/isos') !== -1 || arg.indexOf('~lily/ISOs') !== -1) { if (
this.Chat('Use the non-http versions of these commands for local images, please.'); arg.indexOf("~dartz/isos") !== -1 ||
arg.indexOf("~lily/ISOs") !== -1
) {
this.Chat(
"Use the non-http versions of these commands for local images, please.",
);
return; return;
} }
@ -483,44 +536,45 @@ class HelperBot extends CollabVMClient {
} }
// bleh // bleh
this.Chat("Tried to put media into specified device."); this.Chat("Tried to put media into specified device.");
} break; }
break;
case 'eject': { case "eject":
if(!DoLimit(this.GeneralCmdLimit)) {
return; if (!DoLimit(this.GeneralCmdLimit)) return;
let arg = message.slice(message.indexOf(' ')+1); let arg = message.slice(message.indexOf(" ") + 1);
//this.Chat("sorry, severe autism not allowed right now"); //this.Chat("sorry, severe autism not allowed right now");
//return; //return;
switch (arg) { switch (arg) {
case 'cd': case "cd":
this.QemuEjectCd(); this.QemuEjectCd();
break; break;
case 'flp': case "flp":
this.QemuEjectFloppy(); this.QemuEjectFloppy();
break; break;
} }
} break; }
break;
case "reboot":
case 'reboot': if (!DoLimit(this.RebootLimit)) return;
if(!DoLimit(this.RebootLimit))
return;
// this.Chat("hold on fellas"); // this.Chat("hold on fellas");
// return; // return;
this.SendMonitorCommand("system_reset"); this.SendMonitorCommand("system_reset");
break; break;
case 'bootset': case "bootset":
if(!DoLimit(this.GeneralCmdLimit)) if (!DoLimit(this.GeneralCmdLimit)) return;
return;
//this.Chat("sorry, severe autism not allowed right now"); //this.Chat("sorry, severe autism not allowed right now");
//return; //return;
this.SendMonitorCommand(`boot_set ${message.slice(message.indexOf(' ')+1)}`); this.SendMonitorCommand(
`boot_set ${message.slice(message.indexOf(" ") + 1)}`,
);
break; break;
default: default:
@ -536,15 +590,23 @@ class HelperBot extends CollabVMClient {
//if (vmId == 'vm0b0t') //if (vmId == 'vm0b0t')
// this.GeneralCmdLimit = new RateLimit(25 * 1000); // this.GeneralCmdLimit = new RateLimit(25 * 1000);
//else //else
this.GeneralCmdLimit = new RateLimit(kGeneralLimitBaseSeconds * 1000, 2, `General commands/${this._vmId}`); this.GeneralCmdLimit = new RateLimit(
kGeneralLimitBaseSeconds * 1000,
2,
`General commands/${this._vmId}`,
);
//this.EjectLimit = new RateLimit(30 * 1000); //this.EjectLimit = new RateLimit(30 * 1000);
this.RebootLimit = new RateLimit(kRebootLimitBaseSeconds * 1000, 3, `!reboot/${this._vmId}`); this.RebootLimit = new RateLimit(
kRebootLimitBaseSeconds * 1000,
3,
`!reboot/${this._vmId}`,
);
} }
OnGuacamoleMessage(message) { OnGuacamoleMessage(message) {
if (message[0] == "connect") { if (message[0] == "connect") {
if(message[1] == '0') { if (message[1] == "0") {
Log(`[${this._vmId}]`, `Failed to connect to VM`); Log(`[${this._vmId}]`, `Failed to connect to VM`);
this.Close(); this.Close();
return; return;
@ -553,7 +615,6 @@ class HelperBot extends CollabVMClient {
//console.log(message); //console.log(message);
Log(`[${this._vmId}]`, `Connected to VM`); Log(`[${this._vmId}]`, `Connected to VM`);
// I'm fucking lazy // I'm fucking lazy
this.SendGuacamoleMessage("login", ADMIN_TOKEN); this.SendGuacamoleMessage("login", ADMIN_TOKEN);
this.CreateRateLimits(); this.CreateRateLimits();
@ -562,10 +623,11 @@ class HelperBot extends CollabVMClient {
// 5.admin,1.2,44.unknown command: &#x27;aaaaa&#x27;&#13;&#10;; // 5.admin,1.2,44.unknown command: &#x27;aaaaa&#x27;&#13;&#10;;
if (message[0] == "admin" && message[1] == "2") { if (message[0] == "admin" && message[1] == "2") {
if (message[2].indexOf("Could not open") !== -1) { if (message[2].indexOf("Could not open") !== -1) {
this.Chat("Could not open selected CD or floppy image. Please check the filename"); this.Chat(
"Could not open selected CD or floppy image. Please check the filename",
);
} }
if (message[2].indexOf("boot device list now set to") !== -1) { if (message[2].indexOf("boot device list now set to") !== -1) {
this.Chat("Successfully set boot order."); this.Chat("Successfully set boot order.");
} }
@ -574,10 +636,7 @@ class HelperBot extends CollabVMClient {
} }
} }
for (let vm of INSTALLBOT_VMS) { for (let vm of INSTALLBOT_VMS) {
// initalize this bot instance // initalize this bot instance
new HelperBot(vm.uri, vm.id, vm.usesIde2, vm.hasFloppy) new HelperBot(vm.uri, vm.id, vm.usesIde2, vm.hasFloppy).DoConn();
.DoConn();
} }

View file

@ -1,5 +1,5 @@
{ {
"name": "AnyOSInstallBot", "name": "anyosinstallbot",
"version": "1.0.0", "version": "1.0.0",
"description": "Helper bot to insert media into AnyOS VMs", "description": "Helper bot to insert media into AnyOS VMs",
"main": "index.js", "main": "index.js",
@ -8,5 +8,12 @@
"type": "module", "type": "module",
"dependencies": { "dependencies": {
"ws": "^8.3.0" "ws": "^8.3.0"
},
"packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e",
"scripts": {
"format": "prettier *.js -w"
},
"devDependencies": {
"prettier": "^3.3.2"
} }
} }