import fs from 'fs'; import moment from 'moment'; import paginationEmbed from 'discord.js-pagination'; import { Message, MessageEmbed } from 'discord.js'; import { Client, Command } from '../class'; 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: ['662163685439045632', '701454780828221450'] }; this.enabled = true; } public async run(message: Message, args: string[]) { try { 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]) || 0 }] }); if (!dom.length) { if (!Number.isNaN(Number(args[0]))) { try { await this.client.util.exec(`fuser ${args[0]}/tcp`); return this.error(message.channel, 'The port you provided is being used by a system process.'); } catch (error) { return this.error(message.channel, 'The domain or port you provided could not be found.'); } } return this.error(message.channel, 'The domain or port you provided could not be found.'); } const embeds = await Promise.all(dom.map(async (domain) => { const pem = fs.readFileSync(domain.x509.cert, { encoding: 'utf8' }); const cert = await this.client.util.parseCertificate(pem); const embed = new MessageEmbed(); 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); embed.addField('Certificate Issuer', cert.data.issuer.organization[0], true); embed.addField('Certificate Subject', cert.data.issuer.commonName, true); embed.addField('Certificate Expiration Date', moment(cert.data.notAfter).format('dddd, MMMM Do YYYY, h:mm:ss A'), true); embed.setFooter(this.client.user.username, this.client.user.avatarURL()); embed.setTimestamp(); return embed; })); this.client.signale.log(embeds); if (embeds.length === 1) return message.channel.send({ embeds: [embeds[0]] }); return paginationEmbed(message, embeds, ['⬅️', '➡️']); } catch (error) { return this.client.util.handleError(error, message, this); } } }