From 014a53890d4edf97ab0f010629cc516e67f53a92 Mon Sep 17 00:00:00 2001 From: Matthew R Date: Fri, 1 Nov 2019 17:46:23 -0400 Subject: [PATCH 01/21] rm check for ports --- src/commands/cwg_create.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/commands/cwg_create.ts b/src/commands/cwg_create.ts index 02a758f..11ebfd4 100644 --- a/src/commands/cwg_create.ts +++ b/src/commands/cwg_create.ts @@ -33,7 +33,7 @@ export default class CWG_Create extends Command { if (args[3] && !args[4]) return edit.edit(`${this.client.stores.emojis.error} x509 Certificate key required`); let certs: { cert?: string, key?: string }; if (args[4]) certs = { cert: args[3], key: args[4] }; if (await this.client.db.Domain.exists({ domain: args[1] })) return edit.edit(`***${this.client.stores.emojis.error} This domain already exists.***`); - if (await this.client.db.Domain.exists({ port: Number(args[2]) })) return edit.edit(`***${this.client.stores.emojis.error} This port is already binded to a domain.***`); + if (await this.client.db.Domain.exists({ port: Number(args[2]) })) return message.channel.createMessage('***WARNING: This port is already binded to another domain.***'); const domain = await this.createDomain(account, args[1], Number(args[2]), certs); const embed = new RichEmbed(); embed.setTitle('Domain Creation'); @@ -98,7 +98,7 @@ export default class CWG_Create extends Command { public async createDomain(account: AccountInterface, domain: string, port: number, x509Certificate: { cert?: string, key?: string } = { cert: '/etc/nginx/ssl/cloud-org.chain.crt', key: '/etc/nginx/ssl/cloud-org.key.pem' }) { try { if (port <= 1024 || port >= 65535) throw new RangeError(`Port range must be between 1024 and 65535, received ${port}.`); - if (await this.client.db.Domain.exists({ port })) throw new Error(`Port ${port} already exists in the database.`); + // if (await this.client.db.Domain.exists({ port })) throw new Error(`Port ${port} already exists in the database.`); if (await this.client.db.Domain.exists({ domain })) throw new Error(`Domain ${domain} already exists in the database.`); if (!await this.client.db.Account.exists({ userID: account.userID })) throw new Error(`Cannot find account ${account.userID}.`); await fs.access(x509Certificate.cert, fs.constants.R_OK); From 8959dd5315f84829c76ab6ced486772c62809cc4 Mon Sep 17 00:00:00 2001 From: Matthew R Date: Fri, 8 Nov 2019 20:05:47 -0500 Subject: [PATCH 02/21] send dm to log and user on delete cwg --- src/commands/cwg_delete.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/commands/cwg_delete.ts b/src/commands/cwg_delete.ts index 3998fab..cf58e16 100644 --- a/src/commands/cwg_delete.ts +++ b/src/commands/cwg_delete.ts @@ -53,7 +53,9 @@ export default class CWG_Delete extends Command { await this.client.util.exec('systemctl reload nginx'); edit.edit(`***${this.client.stores.emojis.success} Domain ${domain.domain} with port ${domain.port} has been successfully deleted.***`); // @ts-ignore - return message.channel.createMessage({ embed }); + this.client.createMessage('580950455581147146', { embed }); + // @ts-ignore + return this.client.getDMChannel(domain.account.userID).then((channel) => channel.createMessage({ embed })).catch(() => {}); } catch (error) { return this.client.util.handleError(error, message, this); } From 8a23d7dbe43296ca7b67ecae93ad16690e5e921c Mon Sep 17 00:00:00 2001 From: Matthew R Date: Sat, 9 Nov 2019 23:05:01 -0500 Subject: [PATCH 03/21] bind intervals on startup and add redis --- src/Client.ts | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/Client.ts b/src/Client.ts index 11a09d6..8a0c400 100644 --- a/src/Client.ts +++ b/src/Client.ts @@ -1,8 +1,8 @@ import Eris from 'eris'; +import Redis from 'ioredis'; import mongoose from 'mongoose'; import signale from 'signale'; import fs from 'fs-extra'; -import path from 'path'; import config from './config.json'; import { Account, AccountInterface, Moderation, ModerationInterface, Domain, DomainInterface } from './models'; import { emojis } from './stores'; @@ -19,6 +19,8 @@ export default class Client extends Eris.Client { public db: { Account: mongoose.Model; Domain: mongoose.Model; Moderation: mongoose.Model; }; + public redis: Redis.Redis; + public stores: { emojis: { success: string, loading: string, error: string }; }; public signale: signale.Signale; @@ -31,6 +33,7 @@ export default class Client extends Eris.Client { this.util = new Util(this); this.commands = new Collection(); this.db = { Account, Domain, Moderation }; + this.redis = new Redis(); this.stores = { emojis }; this.signale = signale; this.signale.config({ @@ -80,15 +83,15 @@ export default class Client extends Eris.Client { } public async init() { + const intervals = await fs.readdir('./intervals'); + intervals.forEach((interval) => { + // eslint-disable-next-line + if (interval === 'index.js') return; + require(`./intervals/${interval}`).default(this); + this.signale.complete(`Loaded interval ${interval.split('.')[0]}`); + }); const evtFiles = await fs.readdir('./events/'); Object.values(commands).forEach((c: Function) => this.loadCommand(c)); - /* - const commands = await fs.readdir(path.join(__dirname, './commands/')); - commands.forEach((command) => { - if (command === 'index.js') return; - this.loadCommand(`./commands/${command}`); - }); - */ evtFiles.forEach((file) => { const eventName = file.split('.')[0]; From b6f37d072c9652b1b1eed5d188b9c333456551a4 Mon Sep 17 00:00:00 2001 From: Matthew R Date: Sat, 9 Nov 2019 23:05:17 -0500 Subject: [PATCH 04/21] add cpu usage, memory, and storage to whois --- src/commands/whois.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/commands/whois.ts b/src/commands/whois.ts index e109a95..115b2bc 100644 --- a/src/commands/whois.ts +++ b/src/commands/whois.ts @@ -3,6 +3,7 @@ import moment from 'moment'; import { Message } from 'eris'; import { Client } from '..'; import { Command, RichEmbed } from '../class'; +import { dataConversion } from '../functions'; export default class Whois extends Command { constructor(client: Client) { @@ -30,6 +31,10 @@ export default class Whois extends Command { embed.addField('Email Address', account.emailAddress, 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); + embed.addField('CPU Usage', `${await this.client.util.exec(`top -b -n 1 -u ${account.username} | awk 'NR>7 { sum += $9; } END { print sum; }'`)}%`, true); + embed.addField('Memory', dataConversion(Number(this.client.util.exec(`memory ${account.username}`))), true); + const data = await this.client.redis.get(`storage-${account.username}`) ? dataConversion(Number(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.engineer) details += 'This account belongs to an Engineer.\n'; From 2febbdbba4a457268913b37c64db24a51346354f Mon Sep 17 00:00:00 2001 From: Matthew R Date: Sat, 9 Nov 2019 23:05:22 -0500 Subject: [PATCH 05/21] v1.2.0 --- package.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 707e959..3eefffc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cloudservices-rewrite", - "version": "1.1.0", + "version": "1.2.0", "description": "The official LOC Cloud Services system, this is a rewrite of the original version. ", "main": "dist/Client.js", "scripts": { @@ -16,6 +16,7 @@ "eris": "^0.10.1", "eris-pagination": "bsian03/eris-pagination", "fs-extra": "^8.1.0", + "ioredis": "^4.14.1", "moment": "^2.24.0", "moment-precise-range-plugin": "^1.3.0", "mongoose": "^5.7.4", @@ -25,6 +26,7 @@ }, "devDependencies": { "@types/fs-extra": "^8.0.0", + "@types/ioredis": "^4.0.18", "@types/mongoose": "^5.5.20", "@types/nodemailer": "^6.2.1", "@types/signale": "^1.2.1", From 615cc76904b855e332a670798c3b1396ea0f1cc5 Mon Sep 17 00:00:00 2001 From: Matthew R Date: Sat, 9 Nov 2019 23:05:34 -0500 Subject: [PATCH 06/21] Add storage interval --- src/intervals/storage.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 src/intervals/storage.ts diff --git a/src/intervals/storage.ts b/src/intervals/storage.ts new file mode 100644 index 0000000..68bc6c8 --- /dev/null +++ b/src/intervals/storage.ts @@ -0,0 +1,19 @@ +/* eslint-disable no-await-in-loop */ +import fs from 'fs-extra'; +import { Client } from '..'; + +export default function storage(client: Client) { + setInterval(async () => { + const accounts = await client.db.Account.find(); + for (const account of accounts) { + let bytes = Number(await client.util.exec(`du -bs /home/${account.username}`)); + try { + await fs.access(`/var/mail/${account.username}`, fs.constants.F_OK); + bytes += Number(await client.util.exec(`du -bs /var/mail/${account.username}`)); + } catch { + bytes += 0; + } + await client.redis.set(`storage-${account.username}`, bytes); + } + }, 300000); +} From cbeb964b218e676b204e799b13962d86dc28ea7f Mon Sep 17 00:00:00 2001 From: Matthew R Date: Sat, 9 Nov 2019 23:13:49 -0500 Subject: [PATCH 07/21] change interval timing on storage --- src/intervals/storage.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/intervals/storage.ts b/src/intervals/storage.ts index 68bc6c8..799a14c 100644 --- a/src/intervals/storage.ts +++ b/src/intervals/storage.ts @@ -3,7 +3,7 @@ import fs from 'fs-extra'; import { Client } from '..'; export default function storage(client: Client) { - setInterval(async () => { + const main = async () => { const accounts = await client.db.Account.find(); for (const account of accounts) { let bytes = Number(await client.util.exec(`du -bs /home/${account.username}`)); @@ -15,5 +15,8 @@ export default function storage(client: Client) { } await client.redis.set(`storage-${account.username}`, bytes); } + }; + setInterval(async () => { + await main(); }, 300000); } From d7a19e1b4ea6e3a9fba4fee06976f5064bcc0452 Mon Sep 17 00:00:00 2001 From: Matthew R Date: Sat, 9 Nov 2019 23:14:02 -0500 Subject: [PATCH 08/21] move bindings --- src/Client.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Client.ts b/src/Client.ts index 8a0c400..9d3317e 100644 --- a/src/Client.ts +++ b/src/Client.ts @@ -83,13 +83,6 @@ export default class Client extends Eris.Client { } public async init() { - const intervals = await fs.readdir('./intervals'); - intervals.forEach((interval) => { - // eslint-disable-next-line - if (interval === 'index.js') return; - require(`./intervals/${interval}`).default(this); - this.signale.complete(`Loaded interval ${interval.split('.')[0]}`); - }); const evtFiles = await fs.readdir('./events/'); Object.values(commands).forEach((c: Function) => this.loadCommand(c)); @@ -108,6 +101,13 @@ export default class Client extends Eris.Client { this.on('ready', () => { this.signale.info(`Connected to Discord as ${this.user.username}#${this.user.discriminator}`); }); + const intervals = await fs.readdir('./intervals'); + intervals.forEach((interval) => { + // eslint-disable-next-line + if (interval === 'index.js') return; + require(`./intervals/${interval}`).default(this); + this.signale.complete(`Loaded interval ${interval.split('.')[0]}`); + }); } } From 990cb8be2333f958faea3111a4f7565c421cbe98 Mon Sep 17 00:00:00 2001 From: Matthew R Date: Sat, 9 Nov 2019 23:14:14 -0500 Subject: [PATCH 09/21] change mark issues --- src/commands/whois.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/commands/whois.ts b/src/commands/whois.ts index 115b2bc..9519c3b 100644 --- a/src/commands/whois.ts +++ b/src/commands/whois.ts @@ -31,8 +31,9 @@ export default class Whois extends Command { embed.addField('Email Address', account.emailAddress, 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); - embed.addField('CPU Usage', `${await this.client.util.exec(`top -b -n 1 -u ${account.username} | awk 'NR>7 { sum += $9; } END { print sum; }'`)}%`, true); - embed.addField('Memory', dataConversion(Number(this.client.util.exec(`memory ${account.username}`))), 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], true); + embed.addField('Memory', dataConversion(Number(await this.client.util.exec(`memory ${account.username}`))), true); const data = await this.client.redis.get(`storage-${account.username}`) ? dataConversion(Number(this.client.redis.get(`storage-${account.username}`))) : 'N/A'; embed.addField('Storage', data, true); let details = ''; From b924e08cede166d54a3931ed1a3ab8422d05fd7d Mon Sep 17 00:00:00 2001 From: Matthew R Date: Sat, 9 Nov 2019 23:16:04 -0500 Subject: [PATCH 10/21] change mark issues --- src/commands/whois.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/commands/whois.ts b/src/commands/whois.ts index 9519c3b..d4b2982 100644 --- a/src/commands/whois.ts +++ b/src/commands/whois.ts @@ -32,7 +32,7 @@ export default class Whois extends Command { 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], true); + embed.addField('CPU Usage', `${cpuUsage.split('\n')[0]}%`, true); embed.addField('Memory', dataConversion(Number(await this.client.util.exec(`memory ${account.username}`))), true); const data = await this.client.redis.get(`storage-${account.username}`) ? dataConversion(Number(this.client.redis.get(`storage-${account.username}`))) : 'N/A'; embed.addField('Storage', data, true); From e40d8fe47f63db3c01caf8ffdc0eda93bbff94c3 Mon Sep 17 00:00:00 2001 From: Matthew R Date: Sat, 9 Nov 2019 23:23:26 -0500 Subject: [PATCH 11/21] fix issue with storage --- src/intervals/storage.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/intervals/storage.ts b/src/intervals/storage.ts index 799a14c..19f08e4 100644 --- a/src/intervals/storage.ts +++ b/src/intervals/storage.ts @@ -6,10 +6,11 @@ export default function storage(client: Client) { const main = async () => { const accounts = await client.db.Account.find(); for (const account of accounts) { - let bytes = Number(await client.util.exec(`du -bs /home/${account.username}`)); + const res = await client.util.exec(`du -bs /home/${account.username}`); + let bytes = Number(res.split('/')[0].replace('\t', '')); try { await fs.access(`/var/mail/${account.username}`, fs.constants.F_OK); - bytes += Number(await client.util.exec(`du -bs /var/mail/${account.username}`)); + bytes += Number(res.split('/')[0].replace('\t', '')); } catch { bytes += 0; } From 0c553035056fe605de8e73626f5629a0a17c7607 Mon Sep 17 00:00:00 2001 From: Matthew R Date: Sat, 9 Nov 2019 23:34:19 -0500 Subject: [PATCH 12/21] fix await issue in whois --- src/commands/whois.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/commands/whois.ts b/src/commands/whois.ts index d4b2982..b6e9a90 100644 --- a/src/commands/whois.ts +++ b/src/commands/whois.ts @@ -34,7 +34,7 @@ export default class Whois extends Command { 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]}%`, true); embed.addField('Memory', dataConversion(Number(await this.client.util.exec(`memory ${account.username}`))), true); - const data = await this.client.redis.get(`storage-${account.username}`) ? dataConversion(Number(this.client.redis.get(`storage-${account.username}`))) : 'N/A'; + 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'; From 166ba54c4b2fbd2c28a65b518ede9c9d9d7f6fd2 Mon Sep 17 00:00:00 2001 From: Matthew R Date: Sat, 9 Nov 2019 23:34:36 -0500 Subject: [PATCH 13/21] change to 0 KB if bytes == 0 --- src/functions/dataConversion.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/functions/dataConversion.ts b/src/functions/dataConversion.ts index e38337d..f72a611 100644 --- a/src/functions/dataConversion.ts +++ b/src/functions/dataConversion.ts @@ -1,5 +1,8 @@ -export default function dataConversion(bytes: number) { +export default function dataConversion(bytes) { const i = Math.floor(Math.log(bytes) / Math.log(1024)); const sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']; + if (bytes === 0) { + return '0 KB'; + } return `${(bytes / 1024 ** i).toFixed(2)} ${sizes[i]}`; } From a62d10caa5a8f08d7bbb445aeefcbc96420c3788 Mon Sep 17 00:00:00 2001 From: Matthew R Date: Sat, 9 Nov 2019 23:34:48 -0500 Subject: [PATCH 14/21] run every 15 minutes --- src/intervals/storage.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/intervals/storage.ts b/src/intervals/storage.ts index 19f08e4..3d822ed 100644 --- a/src/intervals/storage.ts +++ b/src/intervals/storage.ts @@ -19,5 +19,5 @@ export default function storage(client: Client) { }; setInterval(async () => { await main(); - }, 300000); + }, 900000); } From adf12401167d750661e450bf1e78ed2df4fda94e Mon Sep 17 00:00:00 2001 From: Matthew R Date: Sat, 9 Nov 2019 23:38:11 -0500 Subject: [PATCH 15/21] fix int issue --- src/intervals/storage.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/intervals/storage.ts b/src/intervals/storage.ts index 3d822ed..b15ca9e 100644 --- a/src/intervals/storage.ts +++ b/src/intervals/storage.ts @@ -10,7 +10,8 @@ export default function storage(client: Client) { let bytes = Number(res.split('/')[0].replace('\t', '')); try { await fs.access(`/var/mail/${account.username}`, fs.constants.F_OK); - bytes += Number(res.split('/')[0].replace('\t', '')); + const res2 = await client.util.exec(`du -bs /var/mail/${account.username}`); + bytes += Number(res2.split('/')[0].replace('\t', '')); } catch { bytes += 0; } From 6af603b96b6030a5d7bb079e7539696d287288f4 Mon Sep 17 00:00:00 2001 From: Matthew R Date: Sat, 9 Nov 2019 23:46:21 -0500 Subject: [PATCH 16/21] factor --- src/commands/whois.ts | 2 +- src/intervals/storage.ts | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/commands/whois.ts b/src/commands/whois.ts index b6e9a90..2b54488 100644 --- a/src/commands/whois.ts +++ b/src/commands/whois.ts @@ -32,7 +32,7 @@ export default class Whois extends Command { 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]}%`, true); + embed.addField('CPU Usage', cpuUsage ? `${cpuUsage.split('\n')[0]}%` : '0%', true); embed.addField('Memory', dataConversion(Number(await this.client.util.exec(`memory ${account.username}`))), 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); diff --git a/src/intervals/storage.ts b/src/intervals/storage.ts index b15ca9e..939edf4 100644 --- a/src/intervals/storage.ts +++ b/src/intervals/storage.ts @@ -2,7 +2,7 @@ import fs from 'fs-extra'; import { Client } from '..'; -export default function storage(client: Client) { +export default async function storage(client: Client) { const main = async () => { const accounts = await client.db.Account.find(); for (const account of accounts) { @@ -18,6 +18,7 @@ export default function storage(client: Client) { await client.redis.set(`storage-${account.username}`, bytes); } }; + await main(); setInterval(async () => { await main(); }, 900000); From 564623bc536773b80411892b7bd46909122100b2 Mon Sep 17 00:00:00 2001 From: Matthew R Date: Sat, 9 Nov 2019 23:50:28 -0500 Subject: [PATCH 17/21] factor --- src/commands/whois.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/commands/whois.ts b/src/commands/whois.ts index 2b54488..53297d1 100644 --- a/src/commands/whois.ts +++ b/src/commands/whois.ts @@ -32,7 +32,7 @@ export default class Whois extends Command { 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 ? `${cpuUsage.split('\n')[0]}%` : '0%', true); + 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}`))), 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); From 3964c77a40c2f18cd3c086a75d7eff97379382ca Mon Sep 17 00:00:00 2001 From: Matthew R Date: Sun, 10 Nov 2019 00:03:35 -0500 Subject: [PATCH 18/21] memory is wrong, fix --- src/commands/whois.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/commands/whois.ts b/src/commands/whois.ts index 53297d1..0799ca3 100644 --- a/src/commands/whois.ts +++ b/src/commands/whois.ts @@ -33,7 +33,7 @@ export default class Whois extends Command { 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}`))), 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 = ''; From 9412ee87c99732c3e2e284bdf84c09d0711c9ac1 Mon Sep 17 00:00:00 2001 From: Matthew R Date: Mon, 11 Nov 2019 20:15:46 -0500 Subject: [PATCH 19/21] permission changes --- src/commands/announce.ts | 2 +- src/commands/deleteaccount.ts | 2 +- src/commands/disk.ts | 2 +- src/commands/lock.ts | 2 +- src/commands/unlock.ts | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/commands/announce.ts b/src/commands/announce.ts index de33fb3..f0b271f 100644 --- a/src/commands/announce.ts +++ b/src/commands/announce.ts @@ -9,7 +9,7 @@ export default class Announce extends Command { this.description = 'Sends an announcement to all active terminals'; this.usage = `${this.client.config.prefix}announce Hi there! | ${this.client.config.prefix}announce -e EMERGENCY!`; this.aliases = ['ann']; - this.permissions = { roles: ['608095934399643649', '521312697896271873'] }; + this.permissions = { roles: ['475817826251440128', '525441307037007902'] }; this.enabled = true; } diff --git a/src/commands/deleteaccount.ts b/src/commands/deleteaccount.ts index 3480f74..eb58625 100644 --- a/src/commands/deleteaccount.ts +++ b/src/commands/deleteaccount.ts @@ -1,6 +1,6 @@ import { Message, PrivateChannel } from 'eris'; import uuid from 'uuid/v4'; -import { Command, RichEmbed } from '../class'; +import { Command } from '../class'; import { Client } from '..'; export default class DeleteAccount extends Command { diff --git a/src/commands/disk.ts b/src/commands/disk.ts index 0dd9afd..052cc03 100644 --- a/src/commands/disk.ts +++ b/src/commands/disk.ts @@ -13,7 +13,7 @@ export default class Disk extends Command { this.description = 'Checks the used disk space by a user'; this.usage = `${this.client.config.prefix}disk [Username/User ID/Email]`; this.permissions = { roles: ['446104438969466890'] }; - this.enabled = true; + this.enabled = false; } async run(message: Message, args: string[]) { diff --git a/src/commands/lock.ts b/src/commands/lock.ts index 1f367c3..18ae3ee 100644 --- a/src/commands/lock.ts +++ b/src/commands/lock.ts @@ -8,7 +8,7 @@ export default class Lock extends Command { super(client); this.name = 'lock'; this.description = 'Locks an account.'; - this.permissions = { roles: ['608095934399643649', '521312697896271873'] }; + this.permissions = { roles: ['455972169449734144', '643619219988152321'] }; this.enabled = true; } diff --git a/src/commands/unlock.ts b/src/commands/unlock.ts index 11be5f8..1d04afb 100644 --- a/src/commands/unlock.ts +++ b/src/commands/unlock.ts @@ -8,7 +8,7 @@ export default class Unlock extends Command { super(client); this.name = 'unlock'; this.description = 'Unlocks an account.'; - this.permissions = { roles: ['608095934399643649', '521312697896271873'] }; + this.permissions = { roles: ['455972169449734144', '643619219988152321'] }; this.enabled = true; } From ba3fd31c8efca6d9d1cb0b9641cb4a29ba29de8c Mon Sep 17 00:00:00 2001 From: Matthew R Date: Mon, 11 Nov 2019 20:52:42 -0500 Subject: [PATCH 20/21] update archetypes --- src/class/Util.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/class/Util.ts b/src/class/Util.ts index b1b9b99..2d3cf4b 100644 --- a/src/class/Util.ts +++ b/src/class/Util.ts @@ -232,11 +232,11 @@ export default class Util { let color: string; let archType: string; switch (type) { - default: archType = 'Moderator'; embedTitle = 'Cloud Account | Generic'; color = '0892e1'; break; + default: archType = 'Staff'; embedTitle = 'Cloud Account | Generic'; color = '0892e1'; break; case 0: archType = 'Administrator'; embedTitle = 'Cloud Account | Create'; color = '00ff00'; break; - case 1: archType = 'Moderator'; embedTitle = 'Account Warning | Warn'; color = 'ffff00'; break; - case 2: archType = 'Supervisor'; embedTitle = 'Account Infraction | Lock'; color = 'ff6600'; break; - case 3: archType = 'Supervisor'; embedTitle = 'Account Reclaim | Unlock'; color = '0099ff'; break; + case 1: archType = 'Staff'; embedTitle = 'Account Warning | Warn'; color = 'ffff00'; break; + case 2: archType = 'Moderator'; embedTitle = 'Account Infraction | Lock'; color = 'ff6600'; break; + case 3: archType = 'Moderator'; embedTitle = 'Account Reclaim | Unlock'; color = '0099ff'; break; case 4: archType = 'Administrator'; embedTitle = 'Cloud Account | Delete'; color = 'ff0000'; break; } const embed = new RichEmbed() From 7c4ca745acafeb576342d30334cb2ca7f1e3fbf5 Mon Sep 17 00:00:00 2001 From: Matthew R Date: Mon, 11 Nov 2019 21:00:41 -0500 Subject: [PATCH 21/21] error handling for ENOENT in parse --- src/commands/parse.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/commands/parse.ts b/src/commands/parse.ts index 1e8c1d7..ef2fef0 100644 --- a/src/commands/parse.ts +++ b/src/commands/parse.ts @@ -18,7 +18,13 @@ export default class Parse extends Command { if (!args.length) 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].replace(/[<@!>]/gi, '') }] }); if (!account) return message.channel.createMessage(`***${this.client.stores.emojis.error} Cannot find user.***`); - const dir = await fs.readdir(`/home/${account.username}/Validation`); + let dir: string[]; + try { + dir = await fs.readdir(`/home/${account.username}/Validation`); + } catch (err) { + return message.channel.createMessage(`***${this.client.stores.emojis.error} Cannot locate Validation directory.***`); + } + if (!dir.length) return message.channel.createMessage(`***${this.client.stores.emojis.error} Cannot locate certificate.***`); const cert = parseCert(`/home/${account.username}/Validation/${dir[0]}`); const subjectCommonName = cert.subject.commonName ? cert.subject.commonName : 'Not Specified'; const subjectEmailAddress = cert.subject.emailAddress ? cert.subject.emailAddress : 'Not Specified';