From 077efbbd4554076afd5619fdfc8162c5b40716fb Mon Sep 17 00:00:00 2001 From: Matthew R Date: Sun, 29 Mar 2020 01:55:31 -0400 Subject: [PATCH 01/19] syntax fixes --- src/static/nginx.conf | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/static/nginx.conf b/src/static/nginx.conf index 327a416..4312ac5 100644 --- a/src/static/nginx.conf +++ b/src/static/nginx.conf @@ -24,19 +24,19 @@ server { limit_req zone=one burst=15; location / { - proxy_set_header Host $host; + proxy_set_header Host $host; - proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_set_header X-Forwarded-Proto $scheme; + proxy_set_header X-Forwarded-Proto $scheme; - proxy_pass http://localhost:[PORT]; + proxy_pass http://localhost:[PORT]; - proxy_read_timeout 90; + proxy_read_timeout 90; - proxy_redirect http://localhost:[PORT] https://[DOMAIN]; + proxy_redirect http://localhost:[PORT] https://[DOMAIN]; } } From efc8dc8f02b25beab6ac284c8b8483f6fa477e3b Mon Sep 17 00:00:00 2001 From: Matthew R Date: Sun, 29 Mar 2020 04:32:17 -0400 Subject: [PATCH 02/19] create a support key on account creation --- src/class/AccountUtil.ts | 10 +++++++--- src/class/Util.ts | 4 ++-- src/commands/createaccount.ts | 14 +++++++------- src/commands/whois.ts | 1 + src/models/Account.ts | 4 +++- 5 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/class/AccountUtil.ts b/src/class/AccountUtil.ts index cac764a..87cba9a 100644 --- a/src/class/AccountUtil.ts +++ b/src/class/AccountUtil.ts @@ -1,3 +1,4 @@ +import { randomBytes } from 'crypto'; import { AccountInterface } from '../models'; import { Client } from '..'; @@ -22,20 +23,22 @@ export default class AccountUtil { let passHash = await this.client.util.createHash(tempPass); passHash = passHash.replace(/[$]/g, '\\$').replace('\n', ''); const acctName = this.client.users.get(data.userID).username.replace(/[!@#$%^&*(),.?":{}|<>]/g, '-').replace(/\s/g, '-'); const etcPasswd = `${acctName},${data.userID},,`; + const code = randomBytes(3).toString('hex').toUpperCase(); - const accountInterface = await this.client.util.createAccount(passHash, etcPasswd, data.username, data.userID, data.emailAddress, moderator); + const accountInterface = await this.client.util.createAccount(passHash, etcPasswd, data.username, data.userID, data.emailAddress, moderator, code); await this.client.util.createModerationLog(data.userID, moderatorMember, 0); this.client.util.transport.sendMail({ to: data.emailAddress, from: 'Library of Code sp-us | Cloud Services ', - subject: 'Your account has been created', + subject: 'Your account has been created!', html: `

Library of Code | Cloud Services

Your Cloud Account has been created, welcome! Please see below for some details regarding your account and our services

Username: ${data.username}

+

Support Key: ${code} || You may be asked for this support key when contacting Library of Code, please keep the code in a safe area.

SSH Login:

ssh ${data.username}@cloud.libraryofcode.org

Useful information

How to log in:

@@ -67,7 +70,8 @@ export default class AccountUtil { + `You will be asked to change your password, \`(current) UNIX password\` is \`${tempPass}\`, then create a password that is at least 12 characters long, with at least one number, special character, and an uppercase letter\n` + 'Bear in mind that when you enter your password, it will be blank, so be careful not to type in your password incorrectly.\n' + 'You may now return to Modmail, and continue setting up your account from there.\n\n' - + 'An email containing some useful information has also been sent').catch(); + + 'An email containing some useful information has also been sent.\n' + + `Your support key is \`${code}\`. Pin this message, you may need this key to contact Library of Code in the future.`).catch(); return { account: accountInterface, tempPass }; } } diff --git a/src/class/Util.ts b/src/class/Util.ts index 28cb962..fb093d2 100644 --- a/src/class/Util.ts +++ b/src/class/Util.ts @@ -147,12 +147,12 @@ export default class Util { return tempPass; } - public async createAccount(hash: string, etcPasswd: string, username: string, userID: string, emailAddress: string, moderatorID: string): Promise { + public async createAccount(hash: string, etcPasswd: string, username: string, userID: string, emailAddress: string, moderatorID: string, code: string): Promise { await this.exec(`useradd -m -p ${hash} -c ${etcPasswd} -s /bin/bash ${username}`); await this.exec(`chage -d0 ${username}`); const account = new this.client.db.Account({ - username, userID, emailAddress, createdBy: moderatorID, createdAt: new Date(), locked: false, tier: 1, ssInit: false, homepath: `/home/${username}`, + username, userID, emailAddress, createdBy: moderatorID, createdAt: new Date(), locked: false, tier: 1, supportKey: code, ssInit: false, homepath: `/home/${username}`, }); return account.save(); } diff --git a/src/commands/createaccount.ts b/src/commands/createaccount.ts index c345066..15c04b5 100644 --- a/src/commands/createaccount.ts +++ b/src/commands/createaccount.ts @@ -24,17 +24,17 @@ export default class CreateAccount extends Command { try { if (message.channel instanceof PrivateChannel || message.channel instanceof GroupChannel) return message; // Stop TS being gay if (!args[2]) return this.client.commands.get('help').run(message, [this.name]); - if (!message.channel.guild.members.has(args[0])) return message.channel.createMessage(`${this.client.stores.emojis.error} ***User not found***`); - if (message.channel.guild.members.get(args[0]).bot) return message.channel.createMessage(`${this.client.stores.emojis.error} ***I cannot create accounts for bots***`); + if (!message.channel.guild.members.has(args[0])) return message.channel.createMessage(`${this.client.stores.emojis.error} ***User not found.***`); + if (message.channel.guild.members.get(args[0]).bot) return message.channel.createMessage(`${this.client.stores.emojis.error} ***I cannot create accounts for bots.***`); const checkUser = await this.client.db.Account.findOne({ userID: args[0] }); - if (checkUser) return message.channel.createMessage(`${this.client.stores.emojis.error} ***<@${args[0]}> already has an account***`); + if (checkUser) return message.channel.createMessage(`${this.client.stores.emojis.error} ***<@${args[0]}> already has an account.***`); const checkEmail = await this.client.db.Account.findOne({ emailAddress: args[1] }); - if (checkEmail) return message.channel.createMessage(`${this.client.stores.emojis.error} ***Account already exists with this email address***`); + if (checkEmail) return message.channel.createMessage(`${this.client.stores.emojis.error} ***Account already exists with this email address.***`); const checkAccount = await this.client.db.Account.findOne({ username: args[2] }); - if (checkAccount) return message.channel.createMessage(`${this.client.stores.emojis.error} ***Account already exists with this username***`); + if (checkAccount) return message.channel.createMessage(`${this.client.stores.emojis.error} ***Account already exists with this username.***`); - if (!this.client.util.isValidEmail(args[1])) return message.channel.createMessage(`${this.client.stores.emojis.error} ***Invalid email address supplied***`); - if (!/^[a-z][-a-z0-9]*$/.test(args[2])) return message.channel.createMessage(`${this.client.stores.emojis.error} ***Invalid username supplied***`); + if (!this.client.util.isValidEmail(args[1])) return message.channel.createMessage(`${this.client.stores.emojis.error} ***Invalid email address supplied.***`); + if (!/^[a-z][-a-z0-9]*$/.test(args[2])) return message.channel.createMessage(`${this.client.stores.emojis.error} ***Invalid username supplied.***`); const confirmation = await message.channel.createMessage(`${this.client.stores.emojis.loading} ***Creating account...***`); const data = await this.client.util.accounts.createAccount({ userID: args[0], username: args[2], emailAddress: args[1] }, message.author.id); diff --git a/src/commands/whois.ts b/src/commands/whois.ts index 38109bf..48465a7 100644 --- a/src/commands/whois.ts +++ b/src/commands/whois.ts @@ -39,6 +39,7 @@ export default class Whois extends Command { embed.addField('ID', account.userID, true); embed.addField('Email Address', account.emailAddress, true); embed.addField('Tier', String(account.tier), true); + embed.addField('Support Key', account.supportKey, true); embed.addField('Created By', `<@${this.client.users.get(account.createdBy).id}>`, true); embed.addField('Created At', moment(account.createdAt).format('dddd, MMMM Do YYYY, h:mm:ss A'), true); const cpuUsage = await this.client.util.exec(`top -b -n 1 -u ${account.username} | awk 'NR>7 { sum += $9; } END { print sum; }'`); diff --git a/src/models/Account.ts b/src/models/Account.ts index 3f10dc2..7ba490b 100644 --- a/src/models/Account.ts +++ b/src/models/Account.ts @@ -8,7 +8,8 @@ export interface AccountInterface extends Document { createdBy: string, createdAt: Date, locked: boolean, - tier: number; + tier: number, + supportKey: string, permissions: { staff: boolean, sheriff: boolean, @@ -29,6 +30,7 @@ const Account: Schema = new Schema({ createdAt: Date, locked: Boolean, tier: Number, + supportKey: String, permissions: { staff: Boolean, sheriff: Boolean, From 2159845d467bc56be64065328332f59cf5fafc1f Mon Sep 17 00:00:00 2001 From: Matthew R Date: Sun, 29 Mar 2020 04:32:27 -0400 Subject: [PATCH 03/19] command to change tier --- src/commands/tier.ts | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/commands/tier.ts diff --git a/src/commands/tier.ts b/src/commands/tier.ts new file mode 100644 index 0000000..a86d2e6 --- /dev/null +++ b/src/commands/tier.ts @@ -0,0 +1,41 @@ +/* eslint-disable consistent-return */ +import { Message } from 'eris'; +import { Client } from '..'; +import { Command, RichEmbed } from '../class'; + +export default class Tier extends Command { + constructor(client: Client) { + super(client); + this.name = 'tier'; + this.description = 'Changes the tier level for an account.'; + this.usage = `${this.client.config.prefix}tier <1 | 2 | 3>`; + this.permissions = { roles: ['446104438969466890'] }; + this.enabled = true; + } + + public async run(message: Message, args: string[]) { + try { + if (!args.length) return this.client.commands.get('help').run(message, [this.name]); + const edit = await message.channel.createMessage(`***${this.client.stores.emojis.loading} Editing tier...***`); + const account = await this.client.db.Account.findOne({ $or: [{ username: args[0] }, { userID: args[0].replace(/[<@!>]/gi, '') }] }); + if (!account) return edit.edit(`***${this.client.stores.emojis.error} Cannot find user.***`); + if (account.root) return edit.edit(`***${this.client.stores.emojis.error} Permission denied.***`); + if (Number.isNaN(Number(args[1]))) return edit.edit(`***${this.client.stores.emojis.error} The tier you provided is not a valid number. It should be between 1 and 3.***`); + if (Number(args[1]) > 3 || Number(args[1]) < 1) return edit.edit(`***${this.client.stores.emojis.error} You can only choose a Tier between 1 and 3.***`); + message.delete(); + await account.updateOne({ $set: { tier: Number(args[1]) } }); + message.channel.createMessage(`***${this.client.stores.emojis.success} Tier for ${account.username} has been changed to ${args[1]}.***`); + const embed = new RichEmbed(); + embed.setTitle('Cloud Account | Tier Change'); + embed.setColor('#0099ff'); + embed.addField('User', `${account.username} | <@${account.userID}>`, true); + embed.addField('Moderator', `<@${message.author.id}>`, true); + embed.addField('Old Tier -> New Tier', `${account.tier} -> ${args[1]}`, true); + embed.setFooter(this.client.user.username, this.client.user.avatarURL); + embed.setTimestamp(); + this.client.createMessage('580950455581147146', { embed }); this.client.getDMChannel(account.userID).then((channel) => channel.createMessage({ embed })).catch(); + } catch (error) { + await this.client.util.handleError(error, message, this); + } + } +} From 09de117cbd0632833b96441604a59c644aa4792b Mon Sep 17 00:00:00 2001 From: Matthew R Date: Sun, 29 Mar 2020 04:32:38 -0400 Subject: [PATCH 04/19] command for email verification --- src/commands/emailcode.ts | 43 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 src/commands/emailcode.ts diff --git a/src/commands/emailcode.ts b/src/commands/emailcode.ts new file mode 100644 index 0000000..ad203c1 --- /dev/null +++ b/src/commands/emailcode.ts @@ -0,0 +1,43 @@ +/* eslint-disable consistent-return */ +import { randomBytes } from 'crypto'; +import { Message } from 'eris'; +import { Client } from '..'; +import { Command, RichEmbed } from '../class'; + +export default class EmailCode extends Command { + constructor(client: Client) { + super(client); + this.name = 'emailcode'; + this.description = 'Sends a code to an email address to use for address verification.'; + this.usage = `${this.client.config.prefix}emailcode `; + this.permissions = { roles: ['446104438969466890'] }; + this.aliases = ['code']; + this.enabled = true; + } + + public async run(message: Message, args: string[]) { + try { + const code = randomBytes(5).toString('hex'); + if (!this.client.util.isValidEmail(args[0])) return message.channel.createMessage(`${this.client.stores.emojis.error} ***Invalid email address supplied.***`); + this.client.util.transport.sendMail({ + to: args[0], + from: 'Library of Code sp-us | Cloud Services ', + subject: 'Email Verification Code', + html: ` + + +

Library of Code | Cloud Services

+

Please provide the code provided below to the Staff member working with you on account creation.

+

${code}

+

Want to support us?

+

You can support us on Patreon! Head to our Patreon page and feel free to donate as much or as little as you want!
Donating $5 or more will grant you Tier 3, which means we will manage your account at your request, longer certificates, increased Tier limits as well as some roles in the server!

+ Library of Code sp-us | Support Team + + `, + }); + message.channel.createMessage(`***${this.client.stores.emojis.success} Code: \`${code}\` | Email Address: ${args[0]}***`); + } catch (error) { + await this.client.util.handleError(error, message, this); + } + } +} From a9c1e79d296d19f82468e87276d0a67992c21e2e Mon Sep 17 00:00:00 2001 From: Matthew R Date: Sun, 29 Mar 2020 04:37:12 -0400 Subject: [PATCH 05/19] tsconfig changes --- tsconfig.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tsconfig.json b/tsconfig.json index 10493bf..febdc18 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -2,7 +2,7 @@ "compilerOptions": { /* Basic Options */ // "incremental": true, /* Enable incremental compilation */ - "target": "ES2020", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */ + "target": "ES2017", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */ "module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */ "lib": ["ES2019.Object", "ES2020.Promise"], /* Specify library files to be included in the compilation. */ // "allowJs": true, /* Allow javascript files to be compiled. */ From 53774752dda3313eb199573ee3f182a42f97db12 Mon Sep 17 00:00:00 2001 From: Matthew R Date: Sun, 29 Mar 2020 04:45:59 -0400 Subject: [PATCH 06/19] fix issue in automatic perm checks --- src/intervals/checkStaffStatus.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/intervals/checkStaffStatus.ts b/src/intervals/checkStaffStatus.ts index bfff788..48f7c0e 100644 --- a/src/intervals/checkStaffStatus.ts +++ b/src/intervals/checkStaffStatus.ts @@ -26,7 +26,7 @@ export default function checkStaffStatus(client: Client) { await client.db.Account.updateOne({ username: acc.username }, { $set: { 'permissions.staff': false } }); } - if (acc.permissions.staff && acc.tier > 3) { + if (acc.permissions.staff && acc.tier < 3) { await client.db.Account.updateOne({ username: acc.username }, { $set: { tier: 3 } }); client.getDMChannel(acc.userID).then((chan) => { chan.createMessage('***Your account has automatically been upgraded to Tier 3 since you are a Staff member.***'); From f38bf2587272b9f63a110fe7e8a6d2b0f25baa1a Mon Sep 17 00:00:00 2001 From: Matthew R Date: Sun, 29 Mar 2020 04:58:29 -0400 Subject: [PATCH 07/19] add new commands --- src/commands/index.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/commands/index.ts b/src/commands/index.ts index f9d20aa..0abb76d 100644 --- a/src/commands/index.ts +++ b/src/commands/index.ts @@ -4,6 +4,7 @@ export { default as createaccount } from './createaccount'; export { default as cwg } from './cwg'; export { default as deleteaccount } from './deleteaccount'; export { default as disk } from './disk'; +export { default as emailcode } from './emailcode'; export { default as eval } from './eval'; export { default as exec } from './exec'; export { default as help } from './help'; @@ -19,6 +20,7 @@ export { default as resetpassword } from './resetpassword'; export { default as restart } from './restart'; export { default as securesign } from './securesign'; export { default as sysinfo } from './sysinfo'; +export { default as tier } from './tier'; export { default as unban } from './unban'; export { default as unlock } from './unlock'; export { default as warn } from './warn'; From 2b8772dbfbf49079508c48f0f1fad4bbf4a90331 Mon Sep 17 00:00:00 2001 From: Matthew R Date: Sun, 29 Mar 2020 05:22:22 -0400 Subject: [PATCH 08/19] fix memory checking issue --- src/intervals/memory.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/intervals/memory.ts b/src/intervals/memory.ts index 87c5d60..d285e3b 100644 --- a/src/intervals/memory.ts +++ b/src/intervals/memory.ts @@ -34,7 +34,8 @@ export default function memory(client: Client) { /* if the user has exceeded their soft memory limit, which is the one described in the resource limit guidelines, we'll inform staff. */ - if (acc.tier === 1 && memoryConversion >= userLimits.soft) { + if (memoryConversion >= userLimits.soft) { + client.signale.info(`RAM Soft Limit Reached | ${acc.username} | ${memoryConversion}/${userLimits.soft} MB`); const embed = new RichEmbed(); if (client.users.get(acc.userID)) embed.setThumbnail(client.users.get(acc.userID).avatarURL); embed.addField('User', `${acc.username} | <@${acc.userID}> | ${acc.userID}`, true); @@ -46,6 +47,7 @@ export default function memory(client: Client) { // if they exceed the hard limit, we'll kill all of their processes. if (memoryConversion >= userLimits.hard) { + client.signale.info(`RAM Hard Limit Reached | ${acc.username} | ${memoryConversion}/${userLimits.hard} MB`); client.util.exec(`killall -9 -u ${acc.username}`); embed.setTitle('Resource Enforcement Notification'); embed.setDescription('Someone has reached the (hard) resource limit for their tier on RAM. The system has automatically killed all of their processes.'); From 344926c74246a7863361c72b799a2a613359548d Mon Sep 17 00:00:00 2001 From: Matthew R Date: Sun, 29 Mar 2020 05:23:11 -0400 Subject: [PATCH 09/19] fix memory checking issue --- src/intervals/memory.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/intervals/memory.ts b/src/intervals/memory.ts index d285e3b..f0806f8 100644 --- a/src/intervals/memory.ts +++ b/src/intervals/memory.ts @@ -73,5 +73,5 @@ export default function memory(client: Client) { client.createMessage(channelID, { embed }); } } - }, 300000); + }, 60000); } From 4ca2e9b1886571b7e666a0ec8f84b13e715a5cb0 Mon Sep 17 00:00:00 2001 From: Matthew R Date: Sun, 29 Mar 2020 05:28:40 -0400 Subject: [PATCH 10/19] fix memory checking issue --- src/intervals/memory.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/intervals/memory.ts b/src/intervals/memory.ts index f0806f8..04fabe5 100644 --- a/src/intervals/memory.ts +++ b/src/intervals/memory.ts @@ -16,7 +16,9 @@ export const memoryLimits = { export default function memory(client: Client) { setInterval(async () => { const accounts = await client.db.Account.find(); + console.log(accounts); for (const acc of accounts) { + console.log(acc); if (acc.root) return; // memory in bytes const mem = Number(await client.util.exec(`memory ${acc.username}`)) * 1000; @@ -34,6 +36,7 @@ export default function memory(client: Client) { /* if the user has exceeded their soft memory limit, which is the one described in the resource limit guidelines, we'll inform staff. */ + console.log(memoryConversion, userLimits.soft, userLimits.hard); if (memoryConversion >= userLimits.soft) { client.signale.info(`RAM Soft Limit Reached | ${acc.username} | ${memoryConversion}/${userLimits.soft} MB`); const embed = new RichEmbed(); From 271cfe1959e47706beb3ca9befead850a4e4eddd Mon Sep 17 00:00:00 2001 From: Matthew R Date: Sun, 29 Mar 2020 05:33:43 -0400 Subject: [PATCH 11/19] fix memory checking issue --- src/intervals/memory.ts | 122 +++++++++++++++++++++------------------- 1 file changed, 64 insertions(+), 58 deletions(-) diff --git a/src/intervals/memory.ts b/src/intervals/memory.ts index 04fabe5..334d9b6 100644 --- a/src/intervals/memory.ts +++ b/src/intervals/memory.ts @@ -15,66 +15,72 @@ export const memoryLimits = { export default function memory(client: Client) { setInterval(async () => { - const accounts = await client.db.Account.find(); - console.log(accounts); - for (const acc of accounts) { - console.log(acc); - if (acc.root) return; - // memory in bytes - const mem = Number(await client.util.exec(`memory ${acc.username}`)) * 1000; - // memory in megabytes - const memoryConversion = mem / 1024 / 1024; - let userLimits: { soft: number, hard: number }; - if (acc.tier === 1) { - userLimits = { soft: memoryLimits.TIER_1_SOFT, hard: memoryLimits.TIER_1_HARD }; - } else if (acc.tier === 2) { - userLimits = { soft: memoryLimits.TIER_2_SOFT, hard: memoryLimits.TIER_2_HARD }; - } else if (acc.tier === 3) { - userLimits = { soft: memoryLimits.TIER_3_SOFT, hard: memoryLimits.TIER_3_HARD }; - } - - /* if the user has exceeded their soft memory limit, which is the one described in the - resource limit guidelines, we'll inform staff. - */ - console.log(memoryConversion, userLimits.soft, userLimits.hard); - if (memoryConversion >= userLimits.soft) { - client.signale.info(`RAM Soft Limit Reached | ${acc.username} | ${memoryConversion}/${userLimits.soft} MB`); - const embed = new RichEmbed(); - if (client.users.get(acc.userID)) embed.setThumbnail(client.users.get(acc.userID).avatarURL); - embed.addField('User', `${acc.username} | <@${acc.userID}> | ${acc.userID}`, true); - embed.addField('Tier', String(acc.tier), true); - embed.addField('Memory Usage', `${String(memoryConversion)} MB`, true); - embed.addField('Memory Limit', `${String(userLimits.soft)} MB`, true); - embed.setFooter(client.user.username, client.user.avatarURL); - embed.setTimestamp(); - - // if they exceed the hard limit, we'll kill all of their processes. - if (memoryConversion >= userLimits.hard) { - client.signale.info(`RAM Hard Limit Reached | ${acc.username} | ${memoryConversion}/${userLimits.hard} MB`); - client.util.exec(`killall -9 -u ${acc.username}`); - embed.setTitle('Resource Enforcement Notification'); - embed.setDescription('Someone has reached the (hard) resource limit for their tier on RAM. The system has automatically killed all of their processes.'); - client.util.createModerationLog(acc.userID, client.guilds.get('446067825673633794').members.get(client.user.id), 1, '[AUTO] Exceeded resource limit for RAM.'); - client.util.transport.sendMail({ - to: acc.emailAddress, - from: 'Library of Code sp-us | Cloud Services ', - subject: 'Your account has been warned', - html: ` -

Library of Code sp-us | Cloud Services

-

Your account has received an official warning from a Moderator. Please get the underlying issue resolved to avoid possible moderative action.

-

Reason: [AUTO] Exceeded resource limit for RAM.

-

Moderator: ${client.user.username}

- - Library of Code sp-us | Support Team - `, - }); - } else { - embed.setTitle('Resource Limit Notification'); - embed.setDescription('Someone has reached the (soft) resource limit for their tier on RAM.'); + try { + const accounts = await client.db.Account.find(); + console.log(accounts); + for (const acc of accounts) { + console.log(acc); + if (acc.root === true) return; + // memory in bytes + const mem = Number(await client.util.exec(`memory ${acc.username}`)) * 1000; + console.log(mem); + // memory in megabytes + const memoryConversion = mem / 1024 / 1024; + console.log(memoryConversion); + let userLimits: { soft: number, hard: number }; + if (acc.tier === 1) { + userLimits = { soft: memoryLimits.TIER_1_SOFT, hard: memoryLimits.TIER_1_HARD }; + } else if (acc.tier === 2) { + userLimits = { soft: memoryLimits.TIER_2_SOFT, hard: memoryLimits.TIER_2_HARD }; + } else if (acc.tier === 3) { + userLimits = { soft: memoryLimits.TIER_3_SOFT, hard: memoryLimits.TIER_3_HARD }; + } + + /* if the user has exceeded their soft memory limit, which is the one described in the + resource limit guidelines, we'll inform staff. + */ + console.log(memoryConversion, userLimits.soft, userLimits.hard); + if (memoryConversion >= userLimits.soft) { + client.signale.info(`RAM Soft Limit Reached | ${acc.username} | ${memoryConversion}/${userLimits.soft} MB`); + const embed = new RichEmbed(); + if (client.users.get(acc.userID)) embed.setThumbnail(client.users.get(acc.userID).avatarURL); + embed.addField('User', `${acc.username} | <@${acc.userID}> | ${acc.userID}`, true); + embed.addField('Tier', String(acc.tier), true); + embed.addField('Memory Usage', `${String(memoryConversion)} MB`, true); + embed.addField('Memory Limit', `${String(userLimits.soft)} MB`, true); + embed.setFooter(client.user.username, client.user.avatarURL); + embed.setTimestamp(); + + // if they exceed the hard limit, we'll kill all of their processes. + if (memoryConversion >= userLimits.hard) { + client.signale.info(`RAM Hard Limit Reached | ${acc.username} | ${memoryConversion}/${userLimits.hard} MB`); + client.util.exec(`killall -9 -u ${acc.username}`); + embed.setTitle('Resource Enforcement Notification'); + embed.setDescription('Someone has reached the (hard) resource limit for their tier on RAM. The system has automatically killed all of their processes.'); + client.util.createModerationLog(acc.userID, client.guilds.get('446067825673633794').members.get(client.user.id), 1, '[AUTO] Exceeded resource limit for RAM.'); + client.util.transport.sendMail({ + to: acc.emailAddress, + from: 'Library of Code sp-us | Cloud Services ', + subject: 'Your account has been warned', + html: ` +

Library of Code sp-us | Cloud Services

+

Your account has received an official warning from a Moderator. Please get the underlying issue resolved to avoid possible moderative action.

+

Reason: [AUTO] Exceeded resource limit for RAM.

+

Moderator: ${client.user.username}

+ + Library of Code sp-us | Support Team + `, + }); + } else { + embed.setTitle('Resource Limit Notification'); + embed.setDescription('Someone has reached the (soft) resource limit for their tier on RAM.'); + } + // @ts-ignore + client.createMessage(channelID, { embed }); } - // @ts-ignore - client.createMessage(channelID, { embed }); } + } catch (err) { + client.util.handleError(err); } }, 60000); } From 0b08700140e348a63005918d5e7c6d50817cb83a Mon Sep 17 00:00:00 2001 From: Matthew R Date: Sun, 29 Mar 2020 05:37:14 -0400 Subject: [PATCH 12/19] fix memory checking issue --- src/intervals/memory.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/intervals/memory.ts b/src/intervals/memory.ts index 334d9b6..fef3803 100644 --- a/src/intervals/memory.ts +++ b/src/intervals/memory.ts @@ -19,7 +19,8 @@ export default function memory(client: Client) { const accounts = await client.db.Account.find(); console.log(accounts); for (const acc of accounts) { - console.log(acc); + console.log(acc.username); + console.log(acc.root); if (acc.root === true) return; // memory in bytes const mem = Number(await client.util.exec(`memory ${acc.username}`)) * 1000; From 2cec8a45ae05b171c60233e5416985e78c2b82bb Mon Sep 17 00:00:00 2001 From: Matthew R Date: Sun, 29 Mar 2020 05:43:40 -0400 Subject: [PATCH 13/19] fix memory checking issue --- src/intervals/memory.ts | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/intervals/memory.ts b/src/intervals/memory.ts index fef3803..70f08b4 100644 --- a/src/intervals/memory.ts +++ b/src/intervals/memory.ts @@ -1,3 +1,4 @@ +/* eslint-disable no-continue */ /* eslint-disable no-await-in-loop */ import { Client } from '..'; import { RichEmbed } from '../class'; @@ -17,17 +18,12 @@ export default function memory(client: Client) { setInterval(async () => { try { const accounts = await client.db.Account.find(); - console.log(accounts); for (const acc of accounts) { - console.log(acc.username); - console.log(acc.root); - if (acc.root === true) return; + if (acc.root === true) continue; // memory in bytes const mem = Number(await client.util.exec(`memory ${acc.username}`)) * 1000; - console.log(mem); // memory in megabytes const memoryConversion = mem / 1024 / 1024; - console.log(memoryConversion); let userLimits: { soft: number, hard: number }; if (acc.tier === 1) { userLimits = { soft: memoryLimits.TIER_1_SOFT, hard: memoryLimits.TIER_1_HARD }; @@ -40,7 +36,6 @@ export default function memory(client: Client) { /* if the user has exceeded their soft memory limit, which is the one described in the resource limit guidelines, we'll inform staff. */ - console.log(memoryConversion, userLimits.soft, userLimits.hard); if (memoryConversion >= userLimits.soft) { client.signale.info(`RAM Soft Limit Reached | ${acc.username} | ${memoryConversion}/${userLimits.soft} MB`); const embed = new RichEmbed(); From 4f6233548b78f7fd6a61beb3fdd1718e67ecc49c Mon Sep 17 00:00:00 2001 From: Matthew R Date: Sun, 29 Mar 2020 05:47:42 -0400 Subject: [PATCH 14/19] fix memory checking issue --- src/intervals/memory.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/intervals/memory.ts b/src/intervals/memory.ts index 70f08b4..6492524 100644 --- a/src/intervals/memory.ts +++ b/src/intervals/memory.ts @@ -5,7 +5,7 @@ import { RichEmbed } from '../class'; const channelID = '691824484230889546'; -export const memoryLimits = { +const memoryLimits = { TIER_1_SOFT: 200, TIER_1_HARD: 350, TIER_2_SOFT: 350, @@ -24,6 +24,7 @@ export default function memory(client: Client) { const mem = Number(await client.util.exec(`memory ${acc.username}`)) * 1000; // memory in megabytes const memoryConversion = mem / 1024 / 1024; + console.log(memoryLimits); let userLimits: { soft: number, hard: number }; if (acc.tier === 1) { userLimits = { soft: memoryLimits.TIER_1_SOFT, hard: memoryLimits.TIER_1_HARD }; @@ -32,6 +33,7 @@ export default function memory(client: Client) { } else if (acc.tier === 3) { userLimits = { soft: memoryLimits.TIER_3_SOFT, hard: memoryLimits.TIER_3_HARD }; } + console.log(userLimits); /* if the user has exceeded their soft memory limit, which is the one described in the resource limit guidelines, we'll inform staff. From 6ebddbf9e0110d339359496718d67bfa21e392ad Mon Sep 17 00:00:00 2001 From: Matthew R Date: Sun, 29 Mar 2020 05:47:53 -0400 Subject: [PATCH 15/19] fix memory checking issue --- src/intervals/memory.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/intervals/memory.ts b/src/intervals/memory.ts index 6492524..5677bc9 100644 --- a/src/intervals/memory.ts +++ b/src/intervals/memory.ts @@ -80,5 +80,5 @@ export default function memory(client: Client) { } catch (err) { client.util.handleError(err); } - }, 60000); + }, 30000); } From c5ddad81c743ad93b57aeb6cf79d2502ef906e0e Mon Sep 17 00:00:00 2001 From: Matthew R Date: Sun, 29 Mar 2020 05:53:15 -0400 Subject: [PATCH 16/19] fix memory checking issue --- src/intervals/memory.ts | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/intervals/memory.ts b/src/intervals/memory.ts index 5677bc9..369ae19 100644 --- a/src/intervals/memory.ts +++ b/src/intervals/memory.ts @@ -25,13 +25,22 @@ export default function memory(client: Client) { // memory in megabytes const memoryConversion = mem / 1024 / 1024; console.log(memoryLimits); - let userLimits: { soft: number, hard: number }; - if (acc.tier === 1) { - userLimits = { soft: memoryLimits.TIER_1_SOFT, hard: memoryLimits.TIER_1_HARD }; - } else if (acc.tier === 2) { - userLimits = { soft: memoryLimits.TIER_2_SOFT, hard: memoryLimits.TIER_2_HARD }; - } else if (acc.tier === 3) { - userLimits = { soft: memoryLimits.TIER_3_SOFT, hard: memoryLimits.TIER_3_HARD }; + const userLimits: { soft?: number, hard?: number } = {}; + switch (acc.tier) { + case 1: + userLimits.soft = memoryLimits.TIER_1_SOFT; + userLimits.hard = memoryLimits.TIER_1_HARD; + break; + case 2: + userLimits.soft = memoryLimits.TIER_2_SOFT; + userLimits.hard = memoryLimits.TIER_2_HARD; + break; + case 3: + userLimits.soft = memoryLimits.TIER_3_SOFT; + userLimits.hard = memoryLimits.TIER_3_HARD; + break; + default: + break; } console.log(userLimits); @@ -80,5 +89,5 @@ export default function memory(client: Client) { } catch (err) { client.util.handleError(err); } - }, 30000); + }, 60000); } From c4541b7ec09bccf2a677f1801d0b585152a3d4e5 Mon Sep 17 00:00:00 2001 From: Matthew R Date: Sun, 29 Mar 2020 05:59:57 -0400 Subject: [PATCH 17/19] fix memory checking issue --- src/intervals/memory.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/intervals/memory.ts b/src/intervals/memory.ts index 369ae19..b61451f 100644 --- a/src/intervals/memory.ts +++ b/src/intervals/memory.ts @@ -24,7 +24,6 @@ export default function memory(client: Client) { const mem = Number(await client.util.exec(`memory ${acc.username}`)) * 1000; // memory in megabytes const memoryConversion = mem / 1024 / 1024; - console.log(memoryLimits); const userLimits: { soft?: number, hard?: number } = {}; switch (acc.tier) { case 1: @@ -42,7 +41,6 @@ export default function memory(client: Client) { default: break; } - console.log(userLimits); /* if the user has exceeded their soft memory limit, which is the one described in the resource limit guidelines, we'll inform staff. From 682d067f67def5ea05ec3151bebfea3101350ed7 Mon Sep 17 00:00:00 2001 From: Matthew R Date: Sun, 29 Mar 2020 06:19:32 -0400 Subject: [PATCH 18/19] add role on account creation --- src/class/AccountUtil.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/class/AccountUtil.ts b/src/class/AccountUtil.ts index 87cba9a..339f48d 100644 --- a/src/class/AccountUtil.ts +++ b/src/class/AccountUtil.ts @@ -64,6 +64,7 @@ export default class AccountUtil { `, }); + this.client.guilds.get('446067825673633794').members.get(data.userID).addRole('546457886440685578'); const dmChannel = await this.client.getDMChannel(data.userID).catch(); dmChannel.createMessage('<:loc:607695848612167700> **Thank you for creating an account with us!** <:loc:607695848612167700>\n' + `Please log into your account by running \`ssh ${data.username}@cloud.libraryofcode.org\` in your terminal, then use the password \`${tempPass}\` to log in.\n` From 363917895297f1eedd3344f1f82bf2ace28ef051 Mon Sep 17 00:00:00 2001 From: Matthew R Date: Sun, 29 Mar 2020 06:48:20 -0400 Subject: [PATCH 19/19] notifs --- src/intervals/checkStaffStatus.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/intervals/checkStaffStatus.ts b/src/intervals/checkStaffStatus.ts index 48f7c0e..0d318de 100644 --- a/src/intervals/checkStaffStatus.ts +++ b/src/intervals/checkStaffStatus.ts @@ -1,5 +1,6 @@ /* eslint-disable no-await-in-loop */ import { Client } from '..'; +import { RichEmbed } from '../class'; export default function checkStaffStatus(client: Client) { setInterval(async () => { @@ -28,6 +29,15 @@ export default function checkStaffStatus(client: Client) { if (acc.permissions.staff && acc.tier < 3) { await client.db.Account.updateOne({ username: acc.username }, { $set: { tier: 3 } }); + const embed = new RichEmbed(); + embed.setTitle('Cloud Account | Tier Change'); + embed.setColor('#0099ff'); + embed.addField('User', `${acc.username} | <@${acc.userID}>`, true); + embed.addField('Moderator', `<@${client.user.id}>`, true); + embed.addField('Old Tier -> New Tier', `${acc.tier} -> 3`, true); + embed.setFooter(this.client.user.username, this.client.user.avatarURL); + embed.setTimestamp(); + this.client.createMessage('580950455581147146', { embed }); client.getDMChannel(acc.userID).then((chan) => { chan.createMessage('***Your account has automatically been upgraded to Tier 3 since you are a Staff member.***'); });