From 84a539c65a78da859bcb70fe1c9fe0751094761a Mon Sep 17 00:00:00 2001 From: Matthew R Date: Sat, 16 Jul 2022 03:01:39 -0400 Subject: [PATCH] fix bug with cwg_data --- src/commands/cwg_data.ts | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/commands/cwg_data.ts b/src/commands/cwg_data.ts index e0cca7f..82d00bb 100644 --- a/src/commands/cwg_data.ts +++ b/src/commands/cwg_data.ts @@ -8,7 +8,7 @@ export default class CWG_Data extends Command { super(client); this.name = 'data'; this.description = 'Check CWG data'; - this.usage = `${this.client.config.prefix}cwg data [Domain | Port]`; + this.usage = `${this.client.config.prefix}cwg data `; this.permissions = { roles: ['662163685439045632', '701454780828221450'] }; this.enabled = true; } @@ -29,7 +29,13 @@ export default class CWG_Data extends Command { 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' }); + let pem: string; + try { + pem = fs.readFileSync(domain.x509.cert, { encoding: 'utf8' }); + } catch { + pem = fs.readFileSync('/etc/ssl/private/cloud-libraryofcode-org.chain.crt', { encoding: 'utf8' }); + } + const cert = await this.client.util.parseCertificate(pem); const embed = new MessageEmbed(); embed.setTitle('Domain Information'); @@ -37,9 +43,9 @@ export default class CWG_Data extends Command { 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.issuer.organization[0], true); - embed.addField('Certificate Subject', cert.issuer.commonName, true); - embed.addField('Certificate Expiration Date', moment(cert.notAfter).format('dddd, MMMM Do YYYY, h:mm:ss A'), true); + embed.addField('Certificate Issuer', `${cert.issuer.organization[0]} (${cert.issuer.commonName})` || 'N/A', true); + embed.addField('Certificate Subject', cert.subject.commonName || 'N/A', true); + embed.addField('Certificate Expiration Date', cert.notAfter ? moment(cert.notAfter).format('dddd, MMMM Do YYYY, h:mm:ss A') || 'N/A' : 'N/A', true); embed.setFooter(this.client.user.username, this.client.user.avatarURL()); embed.setTimestamp(); return embed;