forked from engineering/cloudservices
Improvements
parent
a9cd35b21a
commit
da29adac49
|
@ -3,6 +3,7 @@ import { parseCert } from '@ghaiklor/x509';
|
|||
import { Message } from 'eris';
|
||||
import { Client } from '..';
|
||||
import { Command, RichEmbed } from '../class';
|
||||
import { parseCertificate } from '../functions';
|
||||
|
||||
export default class Parse extends Command {
|
||||
constructor(client: Client) {
|
||||
|
@ -25,18 +26,19 @@ export default class Parse extends Command {
|
|||
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(`${account.homepath}/Validation/${dir[0]}`);
|
||||
const subjectCommonName = cert.subject.commonName ? cert.subject.commonName : 'Not Specified';
|
||||
const subjectEmailAddress = cert.subject.emailAddress ? cert.subject.emailAddress : 'Not Specified';
|
||||
const subjectOrganization = cert.subject.organizationName ? cert.subject.organizationName : 'Not Specified';
|
||||
const subjectOrganizationalUnit = cert.subject.organizationalUnitName ? cert.subject.organizationalUnitName : 'Not Specified';
|
||||
const subjectCountry = cert.subject.countryName ? cert.subject.countryName : 'Not Specified';
|
||||
const issuerCommonName = cert.issuer.commonName ? cert.issuer.commonName : 'Not Specified';
|
||||
const issuerEmailAddress = cert.issuer.emailAddress ? cert.issuer.emailAddress : 'Not Specified';
|
||||
const issuerOrganization = cert.issuer.organizationName ? cert.issuer.organizationName : 'Not Specified';
|
||||
const issuerOrganizationalUnit = cert.issuer.organizationalUnitName ? cert.issuer.organizationalUnitName : 'Not Specified';
|
||||
const issuerCountry = cert.issuer.countryName ? cert.issuer.countryName : 'Not Specified';
|
||||
const user = this.client.users.get(account.userID) ? this.client.users.get(account.userID) : await this.client.getRESTUser(account.userID);
|
||||
const cert = await parseCertificate(this.client, dir[0]);
|
||||
// const cert = parseCert(`${account.homepath}/Validation/${dir[0]}`);
|
||||
const subjectCommonName = cert.subject.commonName || 'Not Specified';
|
||||
const subjectEmailAddress = cert.subject.emailAddress || 'Not Specified';
|
||||
const subjectOrganization = cert.subject.organizationName || 'Not Specified';
|
||||
const subjectOrganizationalUnit = cert.subject.organizationalUnitName || 'Not Specified';
|
||||
const subjectCountry = cert.subject.countryName || 'Not Specified';
|
||||
const issuerCommonName = cert.issuer.commonName || 'Not Specified';
|
||||
const issuerEmailAddress = cert.issuer.emailAddress || 'Not Specified';
|
||||
const issuerOrganization = cert.issuer.organizationName || 'Not Specified';
|
||||
const issuerOrganizationalUnit = cert.issuer.organizationalUnitName || 'Not Specified';
|
||||
const issuerCountry = cert.issuer.countryName || 'Not Specified';
|
||||
const user = this.client.users.get(account.userID) || await this.client.getRESTUser(account.userID);
|
||||
const embed = new RichEmbed();
|
||||
embed.setTitle('Parse x509 Certificate');
|
||||
embed.setDescription(`${account.homepath}/Validation/${dir[0]} | ${account.username} <@${user.id}>`);
|
||||
|
@ -46,10 +48,10 @@ export default class Parse extends Command {
|
|||
embed.addField('Serial Number', cert.serial, true);
|
||||
embed.addField('Fingerprint', cert.fingerPrint, true);
|
||||
embed.addField('Signature Algorithm', cert.signatureAlgorithm, true);
|
||||
embed.addField('Public Key Algorithm', cert.publicKey.algorithm, true);
|
||||
embed.addField('Public Key Algorithm', cert.publicKeyAlgorithm, true);
|
||||
embed.addField('Key Usage', cert.extensions.keyUsage, true);
|
||||
embed.addField('Extended Key Usage', cert.extensions.extendedKeyUsage, true);
|
||||
embed.addField('Policies', cert.extensions.certificatePolicies, true);
|
||||
embed.addField('Extended Key Usage', cert.extensions.extendedKeyUsage.join(', '), true);
|
||||
embed.addField('Policies', cert.extensions.certificatePolicies.join(', '), true);
|
||||
embed.addField('Issued On', new Date(cert.notBefore).toLocaleString('en-us'), true);
|
||||
embed.addField('Expires On', new Date(cert.notAfter).toLocaleString('en-us'), true);
|
||||
embed.setFooter(this.client.user.username, this.client.user.avatarURL);
|
||||
|
|
|
@ -24,20 +24,28 @@ export default class Parseall extends Command {
|
|||
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.homepath);
|
||||
const accounts = search;
|
||||
const final: string[] = [];
|
||||
|
||||
accounts.forEach(async (a) => {
|
||||
try {
|
||||
const certFile = readdirSync(`${a}/Validation`)[0];
|
||||
const { notAfter } = parseCert(`${a}/Validation/${certFile}`);
|
||||
const certFile = readdirSync(`${a.homepath}/Validation`)[0];
|
||||
const { notAfter } = parseCert(`${a.homepath}/Validation/${certFile}`);
|
||||
// @ts-ignore
|
||||
const time = moment.preciseDiff(new Date(), notAfter);
|
||||
const timeObject: {years: number, months: number, days: number, hours: number, minutes: number, seconds: number, firstDateWasLater: boolean} = moment.preciseDiff(new Date(), notAfter, true);
|
||||
const precise: [number, string][] = [];
|
||||
// @ts-ignore
|
||||
const timeArray: number[] = Object.values(timeObject).filter((v) => !isNaN(v)).forEach((t: number) => { // eslint-disable-line
|
||||
const index = timeArray.indexOf(t);
|
||||
const measurements = ['yr', 'mo', 'd', 'h', 'm', 's'];
|
||||
precise.push([t, measurements[index]]);
|
||||
});
|
||||
const time = precise.map(((v) => v.join(''))).join(', ');
|
||||
|
||||
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}`);
|
||||
if (notAfter < new Date()) final.push(`${this.client.stores.emojis.error} **${a.username}** Certificate expired ${time} ago`);
|
||||
else final.push(`${this.client.stores.emojis.success} **${a.username}** Certificate expires in ${time}`);
|
||||
} catch (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`);
|
||||
if (error.message.includes('no such file or directory') || error.message.includes('File doesn\'t exist.')) final.push(`${this.client.stores.emojis.error} **${a.username}** Unable to locate certificate`);
|
||||
else throw error;
|
||||
}
|
||||
});
|
||||
|
|
|
@ -1,2 +1,4 @@
|
|||
export { default as checkLock } from './checkLock';
|
||||
export { default as dataConversion } from './dataConversion';
|
||||
export { default as checkSS } from './checkSS';
|
||||
export { default as parseCertificate } from './parseCertificate';
|
||||
|
|
Loading…
Reference in New Issue