2019-11-01 20:53:34 -04:00
|
|
|
import fs from 'fs';
|
2019-10-31 19:17:34 -04:00
|
|
|
import moment from 'moment';
|
|
|
|
import x509 from '@ghaiklor/x509';
|
2019-11-01 19:53:21 -04:00
|
|
|
import { createPaginationEmbed } from 'eris-pagination';
|
2019-10-31 19:17:34 -04:00
|
|
|
import { Message } from 'eris';
|
2019-11-01 20:53:34 -04:00
|
|
|
import { promisify } from 'util';
|
2019-10-31 19:17:34 -04:00
|
|
|
import { Command, RichEmbed } from '../class';
|
|
|
|
import { Client } from '..';
|
|
|
|
|
|
|
|
export default class CWG_Data extends Command {
|
|
|
|
constructor(client: Client) {
|
|
|
|
super(client);
|
|
|
|
this.name = 'data';
|
|
|
|
this.description = 'Check CWG data';
|
|
|
|
this.usage = `${this.client.config.prefix}cwg data [Domain | Port]`;
|
|
|
|
this.permissions = { roles: ['446104438969466890'] };
|
|
|
|
this.enabled = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public async run(message: Message, args: string[]) {
|
|
|
|
try {
|
2019-10-31 19:47:36 -04:00
|
|
|
if (!args[0]) return this.client.commands.get('help').run(message, ['cwg', this.name]);
|
2019-11-01 19:53:21 -04:00
|
|
|
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.***`);
|
2019-11-01 20:53:34 -04:00
|
|
|
// const embeds: RichEmbed[] = [];
|
|
|
|
const embeds = dom.map(async (domain) => {
|
|
|
|
const cert = fs.readFileSync(domain.x509.cert, { encoding: 'utf8' });
|
2019-11-01 19:53:21 -04:00
|
|
|
const embed = new RichEmbed();
|
|
|
|
embed.setTitle('Domain Information');
|
|
|
|
embed.addField('Account Username', domain.account.username, true);
|
|
|
|
embed.addField('Account ID', domain.account.userID, true);
|
|
|
|
embed.addField('Domain', domain.domain, true);
|
|
|
|
embed.addField('Port', String(domain.port), true);
|
2019-11-01 20:15:22 -04:00
|
|
|
embed.addField('Certificate Issuer', x509.getIssuer(cert).organizationName, true);
|
|
|
|
embed.addField('Certificate Subject', x509.getSubject(cert).commonName, true);
|
|
|
|
embed.addField('Certificate Expiration Date', moment(x509.parseCert(cert).notAfter).format('dddd, MMMM Do YYYY, h:mm:ss A'), true);
|
2019-11-01 19:53:21 -04:00
|
|
|
embed.setFooter(this.client.user.username, this.client.user.avatarURL);
|
|
|
|
embed.setTimestamp();
|
2019-11-01 20:53:34 -04:00
|
|
|
return embed;
|
|
|
|
});
|
2019-11-01 20:06:14 -04:00
|
|
|
this.client.signale.log(embeds);
|
2019-10-31 19:17:34 -04:00
|
|
|
// @ts-ignore
|
2019-11-01 19:53:21 -04:00
|
|
|
if (embeds.length === 1) return message.channel.createMessage({ embed: embeds[0] });
|
|
|
|
return createPaginationEmbed(message, this.client, embeds, {});
|
2019-10-31 19:17:34 -04:00
|
|
|
} catch (error) {
|
|
|
|
return this.client.util.handleError(error, message, this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|