From e7bab80282213f27971fc5ab5872013fc36fd4d0 Mon Sep 17 00:00:00 2001 From: Bsian Date: Sat, 2 Nov 2019 13:22:49 +0000 Subject: [PATCH 1/8] k --- src/commands/cwg_data.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/commands/cwg_data.ts b/src/commands/cwg_data.ts index 36f3801..bee8f2f 100644 --- a/src/commands/cwg_data.ts +++ b/src/commands/cwg_data.ts @@ -22,7 +22,6 @@ export default class CWG_Data extends Command { if (!args[0]) return this.client.commands.get('help').run(message, ['cwg', this.name]); const dom = await this.client.db.Domain.find({ $or: [{ domain: args[0] }, { port: Number(args[0]) || '' }] }); if (!dom.length) return message.channel.createMessage(`***${this.client.stores.emojis.error} The domain or port you provided could not be found.***`); - // const embeds: RichEmbed[] = []; const embeds = dom.map((domain) => { const cert = fs.readFileSync(domain.x509.cert, { encoding: 'utf8' }); const embed = new RichEmbed(); From e9110c3180b650d9d6d0886f34fca496e47558b4 Mon Sep 17 00:00:00 2001 From: Bsian Date: Sat, 2 Nov 2019 13:24:04 +0000 Subject: [PATCH 2/8] show help info --- src/commands/disk.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/commands/disk.ts b/src/commands/disk.ts index 3379c24..3f2ae98 100644 --- a/src/commands/disk.ts +++ b/src/commands/disk.ts @@ -17,6 +17,7 @@ export default class Disk extends Command { async run(message: Message, args: string[]) { try { + 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] }] }); if (!account) return message.channel.createMessage(`${this.client.stores.emojis.error} ***Account not found***`); if (account.root || args[0].includes('./')) return message.channel.createMessage(`${this.client.stores.emojis.error} ***Permission denied***`); From 8e59238c5d387a8cc14799348894de61fae14ba6 Mon Sep 17 00:00:00 2001 From: Bsian Date: Sat, 2 Nov 2019 13:26:45 +0000 Subject: [PATCH 3/8] Fixed result --- src/commands/disk.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/commands/disk.ts b/src/commands/disk.ts index 3f2ae98..51788ed 100644 --- a/src/commands/disk.ts +++ b/src/commands/disk.ts @@ -31,7 +31,7 @@ export default class Disk extends Command { embed.setTitle('Disk Usage'); embed.setColor('ff0000'); embed.setDescription(`/home/${account.username}`); - embed.addField('Result', dataConversion(Number(result)), true); + embed.addField('Result', dataConversion(Number(result.split(/ +/g)[0])), true); embed.addField('Time taken', totalTime, true); embed.setFooter(`Requested by ${message.author.username}#${message.author.discriminator}`, message.author.avatarURL); embed.setTimestamp(); From af6ba645f80053f834b94b239b1c58bc638ed838 Mon Sep 17 00:00:00 2001 From: Bsian Date: Sat, 2 Nov 2019 13:28:20 +0000 Subject: [PATCH 4/8] use result path --- src/commands/disk.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/commands/disk.ts b/src/commands/disk.ts index 51788ed..fe656c5 100644 --- a/src/commands/disk.ts +++ b/src/commands/disk.ts @@ -30,7 +30,7 @@ export default class Disk extends Command { const embed = new RichEmbed(); embed.setTitle('Disk Usage'); embed.setColor('ff0000'); - embed.setDescription(`/home/${account.username}`); + embed.setDescription(result.split(/ +/g)[1]); embed.addField('Result', dataConversion(Number(result.split(/ +/g)[0])), true); embed.addField('Time taken', totalTime, true); embed.setFooter(`Requested by ${message.author.username}#${message.author.discriminator}`, message.author.avatarURL); From 8b47fba0ba7d19ad740b2cdf072d4c40bb82b5e8 Mon Sep 17 00:00:00 2001 From: Bsian Date: Sat, 2 Nov 2019 16:17:55 +0000 Subject: [PATCH 5/8] Sort by date --- src/commands/modlogs.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/commands/modlogs.ts b/src/commands/modlogs.ts index ee5ea30..aeb2e21 100644 --- a/src/commands/modlogs.ts +++ b/src/commands/modlogs.ts @@ -21,7 +21,8 @@ export default class Modlogs extends Command { const query = await this.client.db.Moderation.find({ $or: [{ username: args.join(' ') }, { userID: args.filter((a) => a)[0].replace(/[<@!>]/g, '') }] }); if (!query.length) return msg.edit(`***${this.client.stores.emojis.error} Cannot locate modlogs for ${args.join(' ')}***`); - const formatted = query.map((log) => { + // @ts-ignore + const formatted = query.sort((a, b) => a.date - b.date).map((log) => { const { username, moderatorID, reason, type, date } = log; let name: string; switch (type) { From 56d1ce3e30ff33268b74c3dfbf8d413d42aeec56 Mon Sep 17 00:00:00 2001 From: Bsian Date: Thu, 14 Nov 2019 21:56:58 +0000 Subject: [PATCH 6/8] added command --- src/commands/parseall.ts | 56 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 src/commands/parseall.ts diff --git a/src/commands/parseall.ts b/src/commands/parseall.ts new file mode 100644 index 0000000..9ff0c47 --- /dev/null +++ b/src/commands/parseall.ts @@ -0,0 +1,56 @@ +import { parseCert } from '@ghaiklor/x509'; +import { Message } from 'eris'; +import { readdirSync } from 'fs'; +import moment from 'moment'; +import { Client } from '..'; +import { Command, RichEmbed } from '../class'; + +export default class Parseall extends Command { + constructor(client: Client) { + super(client); + + this.name = 'parseall'; + this.description = 'Displays certificate validation for all accounts'; + this.usage = `${this.client.config.prefix}parseall`; + this.permissions = { roles: ['446104438969466890'] }; + this.aliases = ['checkcerts', 'verifyall', 'verifycerts']; + } + + public async run(message: Message, args: string[]) { + try { + const embed = new RichEmbed(); + embed.setTitle('Certificate Validation'); + embed.setAuthor(this.client.user.username, this.client.user.avatarURL); + embed.setFooter(`Requested by ${message.member.username}#${message.member.discriminator}`, message.member.avatarURL); + const search = await this.client.db.Account.find(); + const accounts = search.map((acc) => acc.username); + const initial = accounts.map((acc) => `${this.client.stores.emojis.loading} **${acc}** Loading...`); + embed.setDescription(initial.join('\n')); + // @ts-ignore + const msg = await message.channel.createMessage({ embed }); + + accounts.forEach(async (a) => { + try { + const certFile = readdirSync(`/home/${a}/Validation`)[0]; + const { notAfter } = parseCert(`/home/${a}/Validation/${certFile}`); + // @ts-ignore + const time = moment.preciseDiff(new Date(), notAfter); + + if (notAfter < new Date()) initial[accounts.findIndex((acc) => acc === a)] = `${this.client.stores.emojis.error} **${a}** Certificate expired ${time} ago`; + else initial[accounts.findIndex((acc) => acc === a)] = `${this.client.stores.emojis.success} **${a}** Certificate expires in ${time}`; + + embed.setDescription(initial.join('\n')); + await msg.edit({ embed }); + } catch (error) { + if (error.message.includes('no such file or directory') || error.message.includes('File doesn\'t exist.')) { + initial[accounts.findIndex((acc) => acc === a)] = `${this.client.stores.emojis.error} **${a}** Unable to locate certificate`; + embed.setDescription(initial.join('\n')); + await msg.edit({ embed }); + } else throw error; + } + }); + } catch (error) { + this.client.util.handleError(error, message, this); + } + } +} From 43943fce5d95e2eeca224e12b7ad0fb8322a9aa2 Mon Sep 17 00:00:00 2001 From: Bsian Date: Thu, 14 Nov 2019 22:12:12 +0000 Subject: [PATCH 7/8] Register command --- src/commands/index.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/commands/index.ts b/src/commands/index.ts index 80123f3..f0fb9b3 100644 --- a/src/commands/index.ts +++ b/src/commands/index.ts @@ -10,6 +10,7 @@ export { default as Lock } from './lock'; export { default as Modlogs } from './modlogs'; export { default as Notify } from './notify'; export { default as Parse } from './parse'; +export { default as Parseall } from './parseall'; export { default as Ping } from './ping'; export { default as Pull } from './pull'; export { default as Sysinfo } from './sysinfo'; From 259c5d15c8eb61ae7f75c6ae3fe930bde3f51bd5 Mon Sep 17 00:00:00 2001 From: Bsian Date: Thu, 14 Nov 2019 23:13:52 +0000 Subject: [PATCH 8/8] Workaround for embed limits --- src/commands/parseall.ts | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/src/commands/parseall.ts b/src/commands/parseall.ts index 9ff0c47..0ac535e 100644 --- a/src/commands/parseall.ts +++ b/src/commands/parseall.ts @@ -22,12 +22,10 @@ export default class Parseall extends Command { embed.setTitle('Certificate Validation'); embed.setAuthor(this.client.user.username, this.client.user.avatarURL); embed.setFooter(`Requested by ${message.member.username}#${message.member.discriminator}`, message.member.avatarURL); + embed.setTimestamp(); const search = await this.client.db.Account.find(); const accounts = search.map((acc) => acc.username); - const initial = accounts.map((acc) => `${this.client.stores.emojis.loading} **${acc}** Loading...`); - embed.setDescription(initial.join('\n')); - // @ts-ignore - const msg = await message.channel.createMessage({ embed }); + const final: string[] = []; accounts.forEach(async (a) => { try { @@ -36,21 +34,24 @@ export default class Parseall extends Command { // @ts-ignore const time = moment.preciseDiff(new Date(), notAfter); - if (notAfter < new Date()) initial[accounts.findIndex((acc) => acc === a)] = `${this.client.stores.emojis.error} **${a}** Certificate expired ${time} ago`; - else initial[accounts.findIndex((acc) => acc === a)] = `${this.client.stores.emojis.success} **${a}** Certificate expires in ${time}`; - - embed.setDescription(initial.join('\n')); - await msg.edit({ embed }); + if (notAfter < new Date()) final.push(`${this.client.stores.emojis.error} **${a}** Certificate expired ${time} ago`); + else final.push(`${this.client.stores.emojis.success} **${a}** Certificate expires in ${time}`); } catch (error) { - if (error.message.includes('no such file or directory') || error.message.includes('File doesn\'t exist.')) { - initial[accounts.findIndex((acc) => acc === a)] = `${this.client.stores.emojis.error} **${a}** Unable to locate certificate`; - embed.setDescription(initial.join('\n')); - await msg.edit({ embed }); - } else throw error; + if (error.message.includes('no such file or directory') || error.message.includes('File doesn\'t exist.')) final.push(`${this.client.stores.emojis.error} **${a}** Unable to locate certificate`); + else throw error; } }); + + if (final.join('\n').length < 2048) embed.setDescription(final.join('\n')); + else { + const split = this.client.util.splitString(final.join('\n'), 1024); + split.forEach((s) => embed.addField('\u200B', s)); + } + + // @ts-ignore + return await message.channel.createMessage({ embed }); } catch (error) { - this.client.util.handleError(error, message, this); + return this.client.util.handleError(error, message, this); } } }