From f977f0f0b2bf6160f4afd8256869f683fec055db Mon Sep 17 00:00:00 2001 From: Matthew R Date: Mon, 29 Jun 2020 02:34:29 -0400 Subject: [PATCH] add resource/account api endpoints --- src/api/routes/Account.ts | 16 +++++- src/commands/securesign.ts | 29 ---------- src/commands/securesign_account.ts | 46 --------------- src/commands/securesign_activatekey.ts | 46 --------------- src/commands/securesign_alliance.ts | 78 -------------------------- src/commands/securesign_build.ts | 35 ------------ src/commands/securesign_createcrt.ts | 64 --------------------- src/commands/securesign_init.ts | 55 ------------------ src/commands/whoisold.ts | 71 ----------------------- src/commands/whoisold_user.ts | 61 -------------------- src/functions/checkLock.ts | 31 ---------- src/functions/checkSS.ts | 49 ---------------- src/functions/existingLimitsSetup.ts | 2 +- 13 files changed, 14 insertions(+), 569 deletions(-) delete mode 100644 src/commands/securesign.ts delete mode 100644 src/commands/securesign_account.ts delete mode 100644 src/commands/securesign_activatekey.ts delete mode 100644 src/commands/securesign_alliance.ts delete mode 100644 src/commands/securesign_build.ts delete mode 100644 src/commands/securesign_createcrt.ts delete mode 100644 src/commands/securesign_init.ts delete mode 100644 src/commands/whoisold.ts delete mode 100644 src/commands/whoisold_user.ts delete mode 100644 src/functions/checkLock.ts delete mode 100644 src/functions/checkSS.ts diff --git a/src/api/routes/Account.ts b/src/api/routes/Account.ts index 6f7920c..40b1685 100644 --- a/src/api/routes/Account.ts +++ b/src/api/routes/Account.ts @@ -47,10 +47,20 @@ export default class Account extends Route { } }); - this.router.get('/storage', async (req: Req, res) => { + this.router.get('/resources', async (req: Req, res) => { try { - const data = await this.server.client.redis.get(`storage-${req.account.username}`) ? Number(await this.server.client.redis.get(`storage-${req.account.username}`)) : null; - res.status(200).json({ code: this.constants.codes.SUCCESS, message: data }); + const [cpuUsage, ramUsage, diskUsage] = await Promise.all([ + this.server.client.util.exec(`top -b -n 1 -u ${req.account.username} | awk 'NR>7 { sum += $9; } END { print sum; }'`), + this.server.client.util.exec(`memory ${req.account.username}`), + this.server.client.redis.get(`storage-${req.account.username}`), + ]); + res.status(200).json({ code: this.constants.codes.SUCCESS, + message: { + cpu: Number(`${cpuUsage.split('\n')[0] || '0'}`), + ram: (Number(ramUsage) * 1000) / 1024 / 1024, + disk: Number(diskUsage) / 1024 / 1024, + }, + }); } catch (error) { this.handleError(error, res); this.server.client.util.handleError(error); diff --git a/src/commands/securesign.ts b/src/commands/securesign.ts deleted file mode 100644 index a0bbfc7..0000000 --- a/src/commands/securesign.ts +++ /dev/null @@ -1,29 +0,0 @@ -import { Message } from 'eris'; -import { Command } from '../class'; -import { Client } from '..'; -import Build from './securesign_build'; -import Init from './securesign_init'; -import Account from './securesign_account'; -import ActivateKey from './securesign_activatekey'; -import CreateCrt from './securesign_createcrt'; -import Alliace from './securesign_alliance'; - -export default class SecureSign extends Command { - constructor(client: Client) { - super(client); - this.name = 'securesign'; - this.description = 'Runs SecureSign CLI commands'; - this.usage = `Run ${this.client.config.prefix}${this.name} [subcommand] for usage information`; - this.aliases = ['ss']; - this.subcmds = [Build, Init, Account, ActivateKey, CreateCrt, Alliace]; - this.enabled = false; - } - - public async run(message: Message) { - try { - return this.client.commands.get('help').run(message, [this.name]); - } catch (error) { - return this.client.util.handleError(error, message, this); - } - } -} diff --git a/src/commands/securesign_account.ts b/src/commands/securesign_account.ts deleted file mode 100644 index e520df2..0000000 --- a/src/commands/securesign_account.ts +++ /dev/null @@ -1,46 +0,0 @@ -import { Message, PrivateChannel } from 'eris'; -import { Client } from '..'; -import { Command, RichEmbed } from '../class'; -import { AccountInterface } from '../models'; - -export default class SecureSign_Account extends Command { - constructor(client: Client) { - super(client); - this.name = 'account'; - this.description = 'Provides SecureSign account details for currently logged in user'; - this.usage = `${this.client.config.prefix}securesign account`; - this.enabled = false; - this.guildOnly = false; - } - - public async run(message: Message, args: string[]) { - try { - const user = await this.client.db.Account.findOne({ userID: message.author.id }); - if (!user || (!user.permissions.staff && !(message.channel instanceof PrivateChannel))) return message.channel.createMessage(`${this.client.stores.emojis.error} ***Run this command in your DMs!***`); - - let account: AccountInterface; - if (!args[0] || !user.permissions.staff) account = user; - else account = await this.client.db.Account.findOne({ $or: [{ userID: args[0] }, { username: args[0] }, { emailAddress: args[0] }] }); - - if (!account) return message.channel.createMessage(`${this.client.stores.emojis.error} ***Account not found***`); - if (!account.hash) return message.channel.createMessage(`${this.client.stores.emojis.error} ***Account not initialized***`); - const msg = await message.channel.createMessage(`${this.client.stores.emojis.loading} ***Loading account details...***`); - - const details = await this.client.util.exec(`sudo -H -u ${account.username} bash -c 'securesign-canary account'`); - const info = details.replace(/^\s+|\s+$/g, '').replace(/\n/g, '\n**').replace(/: /g, ':** ').split('\n'); - const title = info.shift(); - const description = info.join('\n'); - const content = ''; - - const embed = new RichEmbed(); - embed.setTitle(title); - embed.setDescription(description); - embed.setAuthor(this.client.user.username, this.client.user.avatarURL); - embed.setFooter(`Requested by ${message.author.username}#${message.author.discriminator}`, message.author.avatarURL); - - return msg.edit({ content, embed }); - } catch (error) { - return this.client.util.handleError(error, message, this); - } - } -} diff --git a/src/commands/securesign_activatekey.ts b/src/commands/securesign_activatekey.ts deleted file mode 100644 index 2d1bcd0..0000000 --- a/src/commands/securesign_activatekey.ts +++ /dev/null @@ -1,46 +0,0 @@ -import { Message } from 'eris'; -import axios from 'axios'; -import { Client } from '..'; -import { Command } from '../class'; - -export default class SecureSign_ActivateKey extends Command { - constructor(client: Client) { - super(client); - this.name = 'activatekey'; - this.description = 'Claims an Activation Key'; - this.usage = `${this.client.config.prefix}securesign activatekey [key]`; - this.enabled = false; - } - - public async run(message: Message, args: string[]) { - try { - if (!args[0]) return this.client.commands.get('help').run(message, ['securesign', this.name]); - const account = await this.client.db.Account.findOne({ userID: message.author.id }); - if (!account) return message.channel.createMessage(`${this.client.stores.emojis.error} ***Account not found***`); - if (!account.hash) return message.channel.createMessage(`${this.client.stores.emojis.error} ***Account not initialized***`); - const msg = await message.channel.createMessage(`${this.client.stores.emojis.loading} ***Activating key...***`); - const hash = this.client.util.getAcctHash(account.homepath); - try { - await axios({ - method: 'POST', - url: 'https://api.securesign.org/account/keys/activation', - headers: { Authorization: hash, 'Content-Type': 'application/json' }, - data: JSON.stringify({ key: args[0] }), - }); - } catch (error) { - const { code } = error.response.data; - if (code === 1001) { - await this.client.db.Account.updateOne({ userID: account.userID }, { $set: { hash: false } }); - this.client.getDMChannel(account.userID).then((channel) => channel.createMessage('Your SecureSign password has been reset - please reinitialize your SecureSign account')).catch(); - return msg.edit(`${this.client.stores.emojis.error} ***Authentication failed***`); - } - if (code === 1002) return msg.edit(`${this.client.stores.emojis.error} ***Invalid Activation Key***`); - if (code === 1003) return msg.edit(`${this.client.stores.emojis.error} ***${error.response.data.message}***`); - throw error; - } - return msg.edit(`${this.client.stores.emojis.success} ***Activation Key Accepted***`); - } catch (error) { - return this.client.util.handleError(error, message, this); - } - } -} diff --git a/src/commands/securesign_alliance.ts b/src/commands/securesign_alliance.ts deleted file mode 100644 index ca509c5..0000000 --- a/src/commands/securesign_alliance.ts +++ /dev/null @@ -1,78 +0,0 @@ -import { Message } from 'eris'; -import axios from 'axios'; -import fs from 'fs-extra'; -import { Client } from '..'; -import { Command } from '../class'; - -export default class SecureSign_Alliance extends Command { - constructor(client: Client) { - super(client); - this.name = 'alliance'; - this.description = 'Claims an alliance/promo key'; - this.usage = `${this.client.config.prefix}securesign alliance [key]`; - this.enabled = false; - this.guildOnly = false; - } - - public async run(message: Message, args: string[]) { - try { - const account = await this.client.db.Account.findOne({ userID: message.author.id }); - if (!account) return message.channel.createMessage(`${this.client.stores.emojis.error} ***Account not found***`); - if (!account.hash) return message.channel.createMessage(`${this.client.stores.emojis.error} ***Account not initialized***`); - - const promocode = args[0]; - const splitPromo = promocode.split('-'); - if (splitPromo.length !== 5 || splitPromo.some((code) => code.length < 4 || code.length > 6)) return message.channel.createMessage(`${this.client.stores.emojis.error} ***Invalid promotion code***`); - - const msg = await message.channel.createMessage(`${this.client.stores.emojis.loading} ***Activating key...***`); - const Authorization = this.client.util.getAcctHash(account.homepath); - - // Check if they can activate promos - try { - const { data } = await axios({ - method: 'GET', - url: 'https://api.securesign.org/account/details', - headers: { Authorization, 'Content-Type': 'application/json' }, - }); - - const { promo } = data.message; - if (!promo) return msg.edit(`${this.client.stores.emojis.error} ***Please ask a member of staff to generate an activation key with promotions allowed***`); - } catch (error) { - const { code } = error.response.data; - if (code === 1001) { - await this.client.db.Account.updateOne({ userID: account.userID }, { $set: { hash: false } }); - this.client.getDMChannel(account.userID).then((channel) => channel.createMessage('Your SecureSign password has been reset - please reinitialize your SecureSign account')).catch(); - return msg.edit(`${this.client.stores.emojis.error} ***Authentication failed***`); - } - throw error; - } - - let data: { URL: string }; - try { - const request = await axios({ - method: 'POST', - url: 'https://api.securesign.org/certificates/alliance/client', - headers: { Authorization }, - }); - data = request.data; - } catch (error) { - const { code } = error.response.data; - if (code === 1001) { - await this.client.db.Account.updateOne({ userID: account.userID }, { $set: { hash: false } }); - this.client.getDMChannel(account.userID).then((channel) => channel.createMessage('Your SecureSign password has been reset - please reinitialize your SecureSign account')).catch(); - return msg.edit(`${this.client.stores.emojis.error} ***Authentication failed***`); - } - if (code === 1002) return msg.edit(`${this.client.stores.emojis.error} ***Server responded with ${error.message}`); - throw error; - } - - const certificate = await axios({ method: 'GET', url: data.URL }); - if (!fs.existsSync(`${account.homepath}/Validation/`)) await fs.mkdir(`${account.homepath}/Validation/`); - await fs.writeFile(`${account.homepath}/Validation/${account.username}.crt`, certificate.data, { encoding: 'utf8' }); - - return msg.edit(`${this.client.stores.emojis.success} ***Successfully activated key and created and saved certificate***`); - } catch (error) { - return this.client.util.handleError(error, message, this); - } - } -} diff --git a/src/commands/securesign_build.ts b/src/commands/securesign_build.ts deleted file mode 100644 index fd8665b..0000000 --- a/src/commands/securesign_build.ts +++ /dev/null @@ -1,35 +0,0 @@ -import { Message } from 'eris'; -import { Client } from '..'; -import { Command, RichEmbed } from '../class'; - -export default class SecureSign_Build extends Command { - constructor(client: Client) { - super(client); - this.name = 'build'; - this.description = 'Shows information about the current build of the CLI'; - this.usage = `${this.client.config.prefix}securesign build`; - this.enabled = false; - } - - public async run(message: Message, args: string[]) { - try { - const msg = await message.channel.createMessage(`${this.client.stores.emojis.loading} ***Loading build information...***`); - - const build = await this.client.util.exec("sudo -H -u root bash -c 'securesign-canary build'"); - const info = build.replace(/^\s+|\s+$/g, '').replace(/\n/g, '\n**').replace(/: /g, ':** ').split('\n'); - const title = info.shift(); - const description = info.join('\n'); - const content = ''; - - const embed = new RichEmbed(); - embed.setTitle(title); - embed.setDescription(description); - embed.setAuthor(this.client.user.username, this.client.user.avatarURL); - embed.setFooter(`Requested by ${message.member.username}#${message.member.discriminator}`, message.member.avatarURL); - - msg.edit({ content, embed }); - } catch (error) { - this.client.util.handleError(error, message, this); - } - } -} diff --git a/src/commands/securesign_createcrt.ts b/src/commands/securesign_createcrt.ts deleted file mode 100644 index 655921b..0000000 --- a/src/commands/securesign_createcrt.ts +++ /dev/null @@ -1,64 +0,0 @@ -import { Message, PrivateChannel, TextChannel } from 'eris'; -import axios from 'axios'; -import { Client } from '..'; -import { Command } from '../class'; - -export default class SecureSign_Init extends Command { - constructor(client: Client) { - super(client); - this.name = 'createcrt'; - this.description = 'Creates a new certificate'; - this.usage = `${this.client.config.prefix}securesign createcrt [-s sign] [-c class] [-m digest]\n\`sign\`: Sign type (ecc/rsa)\n\`class\`: Certificate Class (1/2/3)\n\`digest\`: SHA Digest (256/384/512)`; - this.enabled = false; - this.guildOnly = false; - } - - public async run(message: Message, args: string[]) { - try { - const account = await this.client.db.Account.findOne({ userID: message.author.id }); - if (!account) return message.channel.createMessage(`${this.client.stores.emojis.error} ***Account not found***`); - if (!account.hash) return message.channel.createMessage(`${this.client.stores.emojis.error} ***Account not initialized***`); - - const options: { s?: string, c?: string, m?: string } = args.length ? Object.fromEntries(` ${args.join(' ')}`.split(' -').filter((a) => a).map((a) => a.split(/ (.+)/)).filter((a) => a.length > 1)) : {}; - if (options.s && options.s.toLowerCase() !== 'ecc' && options.s.toLowerCase() !== 'rsa') return message.channel.createMessage(`${this.client.stores.emojis.error} ***Invalid signing type, choose between \`ecc\` or \`rsa\``); - if (options.c && (!Number(options.c) || Number(options.c) < 1 || Number(options.c) > 3)) return message.channel.createMessage(`${this.client.stores.emojis.error} ***Invalid class selected, choose between Class \`1\`, \`2\` or \`3\``); - if (options.m && (!Number(options.m) || (options.m !== '256' && options.m !== '384' && options.m !== '512'))) return message.channel.createMessage(`${this.client.stores.emojis.error} ***Invalid SHA Digest selected, choose between \`256\`, \`384\` or \`512\``); - if (Number(options.c) === 3 && (!options.s || options.s.toLowerCase() === 'ecc')) return message.channel.createMessage(`${this.client.stores.emojis.error} ***Class 3 ECC certificates are not supported, please use the \`-s rsa\` option instead***`); - - const msg = await message.channel.createMessage(`${this.client.stores.emojis.loading} ***Creating certificate...***`); - if (options.s) options.s = options.s.toLowerCase(); - const hash = this.client.util.getAcctHash(account.homepath); - - // Check if they can generate certificate - try { - const { data } = await axios({ - method: 'GET', - url: 'https://api.securesign.org/account/details', - headers: { Authorization: hash, 'Content-Type': 'application/json' }, - }); - - const { total, allowed } = data.message; - if (total >= allowed) return msg.edit(`${this.client.stores.emojis.error} ***Not enough certificate allowances - please ask a member of staff to increase this limit from ${total}***`); - if (Number(options.c) > data.message.class) return msg.edit(`${this.client.stores.emojis.error} ***Class too low, you are on a class ${data.message.class} account***`); - } catch (error) { - const { code } = error.response.data; - if (code === 1001) { - await this.client.db.Account.updateOne({ userID: account.userID }, { $set: { hash: false } }); - this.client.getDMChannel(account.userID).then((channel) => channel.createMessage('Your SecureSign password has been reset - please reinitialize your SecureSign account')).catch(); - return msg.edit(`${this.client.stores.emojis.error} ***Authentication failed***`); - } - throw error; - } - - const execoptions = `${options.s ? ` -s ${options.s}` : ''}${options.c ? ` -c ${options.c}` : ''}${options.m ? ` -m ${options.m}` : ''}`; - const cmd = `sudo -H -u ${account.username} bash -c 'securesign-canary createcrt${execoptions}'`; - - const exec = await this.client.util.exec(cmd); - if (!exec.replace(/^\s+|\s+$/g, '').endsWith('Successfully wrote certificate.')) throw new Error(`Certificate generation did not complete successfully:\n${cmd}`); - - return msg.edit(`${this.client.stores.emojis.success} ***Successfully created certificate***`); - } catch (error) { - return this.client.util.handleError(error, message, this); - } - } -} diff --git a/src/commands/securesign_init.ts b/src/commands/securesign_init.ts deleted file mode 100644 index 199acf3..0000000 --- a/src/commands/securesign_init.ts +++ /dev/null @@ -1,55 +0,0 @@ -import { Message, PrivateChannel, TextChannel } from 'eris'; -import axios, { AxiosResponse } from 'axios'; -import { Client } from '..'; -import { Command } from '../class'; - -export default class SecureSign_Init extends Command { - constructor(client: Client) { - super(client); - this.name = 'init'; - this.description = 'Inits configuration files and environment variables (DM only)'; - this.usage = `${this.client.config.prefix}securesign init [hash]`; - this.enabled = false; - this.guildOnly = false; - } - - public async run(message: Message, args: string[]) { - try { - if (!args[0]) return this.client.commands.get('help').run(message, ['securesign', this.name]); - if (!(message.channel instanceof PrivateChannel)) { - message.delete(); - return message.channel.createMessage(`${this.client.stores.emojis.error} ***Run this command in your DMs!***`); - } - const account = await this.client.db.Account.findOne({ userID: message.author.id }); - if (!account) return message.channel.createMessage(`${this.client.stores.emojis.error} ***Account not registered***`); - if (account.locked) return message.channel.createMessage(`${this.client.stores.emojis.error} ***Your account is locked***`); - const msg = await message.channel.createMessage(`${this.client.stores.emojis.loading} ***Initializing account...***`); - let verify: AxiosResponse; - try { - verify = await axios({ - method: 'get', - url: 'https://api.securesign.org/account/details', - headers: { Authorization: args[0] }, - }); - } catch (error) { - const { status } = error.response; - if (status === 400 || status === 401 || status === 403 || status === 404) return msg.edit(`${this.client.stores.emojis.error} ***Credentials incorrect***`); - throw error; - } - const { id } = verify.data.message; - if (id !== message.author.id && !account.root) { - const channel = this.client.guilds.get('446067825673633794').channels.get('501089664040697858') as TextChannel; - channel.createMessage(`**__UNAUTHORIZED ACCESS ALERT__**\n${message.author.mention} tried to initialize their account using <@${id}>'s SecureSign credentials.\nTheir account has been locked under Section 5.2 of the EULA.`); - const tasks = [this.client.util.exec(`lock ${account.username}`), account.updateOne({ locked: true }), this.client.util.createModerationLog(account.userID, this.client.user, 2, 'Violation of Section 5.2 of the EULA')]; - await Promise.all(tasks); - return msg.edit(`${this.client.stores.emojis.error} ***Credentials incorrect***`); - } - const init = await this.client.util.exec(`sudo -H -u ${account.username} bash -c 'securesign-canary init -a ${args[0]}'`); - if (!init.replace(/^\s+|\s+$/g, '').endsWith('Initialization sequence completed.')) throw new Error(`Account initialization did not complete successfully:\n${init}`); - await this.client.db.Account.updateOne({ userID: message.author.id }, { $set: { hash: true } }); - return msg.edit(`${this.client.stores.emojis.success} ***Account initialized***`); - } catch (error) { - return this.client.util.handleError(error, message, this); - } - } -} diff --git a/src/commands/whoisold.ts b/src/commands/whoisold.ts deleted file mode 100644 index f9dfe8e..0000000 --- a/src/commands/whoisold.ts +++ /dev/null @@ -1,71 +0,0 @@ -import moment from 'moment'; -import { Message } from 'eris'; -import { Client } from '..'; -import { Command, RichEmbed } from '../class'; -import { dataConversion } from '../functions'; -import User from './whoisold_user'; - -export default class WhoisOld extends Command { - constructor(client: Client) { - super(client); - this.name = 'whoisold'; - this.description = 'Views information for a cloud account.'; - this.aliases = ['accountold', 'userold']; - this.usage = `${this.client.config.prefix}accountold [User Name | User ID | Email Address]`; - this.permissions = { roles: ['662163685439045632', '701454780828221450'] }; - this.subcmds = [User]; - this.enabled = true; - } - - public async run(message: Message, args: string[]) { - try { - message.channel.createMessage('This command is being deprecated. Please use `=whois` instead.'); - if (!args[0]) return this.client.commands.get('help').run(message, [this.name]); - const account = await this.client.db.Account.findOne({ $or: [{ username: args[0] }, { userID: args[0] }, { emailAddress: args[0] }, { supportKey: args[0].toUpperCase() }] }); - if (!account) return message.channel.createMessage(`${this.client.stores.emojis.error} ***Account not found.***`); - const embed = new RichEmbed(); - embed.setTitle('Account Information'); - if (this.client.users.get(account.userID)) embed.setThumbnail(this.client.users.get(account.userID).avatarURL); - embed.setColor(0x36393f); - let fingerInformation = await this.client.util.exec(`finger ${account.username}`); - if (message.member && !message.member.roles.includes('662163685439045632')) { - fingerInformation = fingerInformation.replace(/((^\s*((([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]))\s*$)|(^\s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(%.+)?\s*$))/g, '[MASKED IP ADDRESS]'); - } - embed.setDescription(`${fingerInformation}\n${await this.client.util.exec(`chage -l ${account.username}`)}`); - embed.addField('Username', `${account.username} | <@${account.userID}>`, true); - 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; }'`); - embed.addField('CPU Usage', cpuUsage.split('\n')[0] ? `${cpuUsage.split('\n')[0]}%` : '0%', true); - embed.addField('Memory', dataConversion(Number(await this.client.util.exec(`memory ${account.username}`)) * 1000), true); - const data = await this.client.redis.get(`storage-${account.username}`) ? dataConversion(Number(await this.client.redis.get(`storage-${account.username}`))) : 'N/A'; - embed.addField('Storage', data, true); - let details = ''; - if (account.locked) details += '__This account is currently locked.__\n'; - if (account.permissions.director) { - details += 'This account belongs to a Director.\n'; - const roleColor = this.client.guilds.get('446067825673633794').roles.get('662163685439045632').color; - embed.setColor(roleColor); - } else if (account.permissions.technician) { - details += 'This account belongs to a Technician.\n'; - const roleColor = this.client.guilds.get('446067825673633794').roles.get('701454780828221450').color; - embed.setColor(roleColor); - } else if (account.permissions.staff) { - details += 'This account belongs to a Staff member.\n'; - const roleColor = this.client.guilds.get('446067825673633794').roles.get('453689940140883988').color; - embed.setColor(roleColor); - } else embed.setColor(0x36393f); - if (account.root) details += '**This account has root/administrative privileges.**\n'; - if (details) embed.addField('Additional Details', details, true); - embed.setFooter(this.client.user.username, this.client.user.avatarURL); - embed.setTimestamp(); - return message.channel.createMessage({ embed }); - } catch (error) { - return this.client.util.handleError(error, message, this); - } - } -} diff --git a/src/commands/whoisold_user.ts b/src/commands/whoisold_user.ts deleted file mode 100644 index 67dd7cb..0000000 --- a/src/commands/whoisold_user.ts +++ /dev/null @@ -1,61 +0,0 @@ -import moment from 'moment'; -import { Message } from 'eris'; -import { Client } from '..'; -import { Command, RichEmbed } from '../class'; -import { dataConversion } from '../functions'; -import { AccountInterface } from '../models'; - -export default class WhoisOld_User extends Command { - constructor(client: Client) { - super(client); - this.name = 'user'; - this.description = 'Gets information about your account.'; - this.usage = `${this.client.config.prefix}whoisold user `; - this.enabled = true; - } - - public async run(message: Message, args: string[]) { - try { - message.channel.createMessage('This command is being deprecated. Please use `=whois` instead.'); - let account: AccountInterface; - if (!args[0]) account = await this.client.db.Account.findOne({ userID: message.author.id }); - else account = await this.client.db.Account.findOne({ $or: [{ username: args[0] }, { userID: args[0] }] }); - if (!account) return message.channel.createMessage(`***${this.client.stores.emojis.error} You don't have an account.***`); - const embed = new RichEmbed(); - embed.setTitle('Account Information'); - if (this.client.users.get(account.userID)) embed.setThumbnail(this.client.users.get(account.userID).avatarURL); - embed.addField('Username', `${account.username} | <@${account.userID}>`, true); - embed.addField('ID', account.userID, true); - embed.addField('Tier', String(account.tier), 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; }'`); - embed.addField('CPU Usage', cpuUsage.split('\n')[0] ? `${cpuUsage.split('\n')[0]}%` : '0%', true); - embed.addField('Memory', dataConversion(Number(await this.client.util.exec(`memory ${account.username}`)) * 1000), true); - const data = await this.client.redis.get(`storage-${account.username}`) ? dataConversion(Number(await this.client.redis.get(`storage-${account.username}`))) : 'N/A'; - embed.addField('Storage', data, true); - let details = ''; - if (account.locked) details += '__This account is currently locked.__\n'; - if (account.permissions.director) { - details += 'This account belongs to a Director.\n'; - const roleColor = this.client.guilds.get('446067825673633794').roles.get('662163685439045632').color; - embed.setColor(roleColor); - } else if (account.permissions.technician) { - details += 'This account belongs to a Technician.\n'; - const roleColor = this.client.guilds.get('446067825673633794').roles.get('701454780828221450').color; - embed.setColor(roleColor); - } else if (account.permissions.staff) { - details += 'This account belongs to a Staff member.\n'; - const roleColor = this.client.guilds.get('446067825673633794').roles.get('453689940140883988').color; - embed.setColor(roleColor); - } else embed.setColor(0x36393f); - if (account.root) details += '**This account has root/administrative privileges.**\n'; - if (details) embed.addField('Additional Details', details, true); - embed.setFooter(this.client.user.username, this.client.user.avatarURL); - embed.setTimestamp(); - return message.channel.createMessage({ embed }); - } catch (error) { - return this.client.util.handleError(error, message, this); - } - } -} diff --git a/src/functions/checkLock.ts b/src/functions/checkLock.ts deleted file mode 100644 index da8d33f..0000000 --- a/src/functions/checkLock.ts +++ /dev/null @@ -1,31 +0,0 @@ -import { Client } from '..'; - -let interval: NodeJS.Timeout; - -export default function checkLock(client: Client) { - interval = setInterval(async () => { - try { - const moderations = await client.db.Moderation.find(); - moderations.forEach(async (moderation) => { - if (!moderation.expiration) return; - if (moderation.expiration.processed) return; - if (new Date() > moderation.expiration.date) { - const account = await client.db.Account.findOne({ username: moderation.username }); - if (!account) return; - await client.util.exec(`unlock ${account.username}`); - await moderation.updateOne({ 'expiration.processed': true }); - await account.updateOne({ locked: false }); - await client.util.createModerationLog(account.userID, client.user, 3, 'Auto'); - client.signale.complete(`Unlocked account ${account.username} | Queue date at ${moderation.expiration.date.toLocaleString('en-us')}`); - } - }); - } catch (error) { - await client.util.handleError(error); - } - }, 10000); - return interval; -} - -export function clear() { - clearInterval(interval); -} diff --git a/src/functions/checkSS.ts b/src/functions/checkSS.ts deleted file mode 100644 index 39cee9d..0000000 --- a/src/functions/checkSS.ts +++ /dev/null @@ -1,49 +0,0 @@ -/* eslint-disable consistent-return */ -/* eslint-disable no-unreachable */ -/* eslint-disable no-await-in-loop */ -import axios from 'axios'; -import { inspect } from 'util'; -import { Client } from '..'; - -let interval: NodeJS.Timeout; -export default function checkSS(client: Client) { - return; - interval = setInterval(async () => { - try { - const accounts = await client.db.Account.find(); - for (const { userID, homepath, hash } of accounts) { - try { - const Authorization = client.util.getAcctHash(homepath); - if (hash === null) throw new Error('Unable to locate auth file, homepath is probably incorrect'); - await axios({ - method: 'get', - url: 'https://api.securesign.org/account/details', - headers: { Authorization }, - }); - if (!hash) { - await client.db.Account.updateOne({ userID }, { $set: { hash: true } }); - client.getDMChannel(userID).then((channel) => channel.createMessage('Your SecureSign account has been automatically initialized via the SecureSign CLI.')).catch(); - } - } catch (error) { - if (!hash) return; - try { - const { status } = error.response; - if (status === 400 || status === 401 || status === 403 || status === 404) { - await client.db.Account.updateOne({ userID }, { $set: { hash: false } }); - client.getDMChannel(userID).then((channel) => channel.createMessage('Your SecureSign password has been reset - please reinitialize your SecureSign account. Run `=securesign init` for more information')).catch(); - } - } catch (e) { - throw error; - } - } - } - } catch (error) { - client.util.handleError(error); - } - }, 60000); - return interval; -} - -export function clear() { - clearTimeout(interval); -} diff --git a/src/functions/existingLimitsSetup.ts b/src/functions/existingLimitsSetup.ts index 08040ee..fb2e918 100644 --- a/src/functions/existingLimitsSetup.ts +++ b/src/functions/existingLimitsSetup.ts @@ -4,7 +4,7 @@ import { Client } from '..'; export default async function existingLimitsSetup(client: Client): Promise { const tier1 = await client.db.Tier.findOne({ id: 1 }); const tier2 = await client.db.Tier.findOne({ id: 2 }); - const tier3 = await await client.db.Tier.findOne({ id: 3 }); + const tier3 = await client.db.Tier.findOne({ id: 3 }); const accounts = await client.db.Account.find(); let numOfAccountsUpdated = 0;