forked from engineering/cloudservices
Merge branch 'master' of gitlab.libraryofcode.org:engineering/cloudservices
commit
99b905d03a
|
@ -3,7 +3,6 @@ import moment from 'moment';
|
||||||
import x509 from '@ghaiklor/x509';
|
import x509 from '@ghaiklor/x509';
|
||||||
import { createPaginationEmbed } from 'eris-pagination';
|
import { createPaginationEmbed } from 'eris-pagination';
|
||||||
import { Message } from 'eris';
|
import { Message } from 'eris';
|
||||||
import { promisify } from 'util';
|
|
||||||
import { Command, RichEmbed } from '../class';
|
import { Command, RichEmbed } from '../class';
|
||||||
import { Client } from '..';
|
import { Client } from '..';
|
||||||
|
|
||||||
|
@ -21,7 +20,17 @@ export default class CWG_Data extends Command {
|
||||||
try {
|
try {
|
||||||
if (!args[0]) return this.client.commands.get('help').run(message, ['cwg', this.name]);
|
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]) || '' }] });
|
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.***`);
|
if (!dom.length) {
|
||||||
|
if (!Number.isNaN(Number(args[0]))) {
|
||||||
|
try {
|
||||||
|
await this.client.util.exec(`fuser ${args[0]}/tcp`);
|
||||||
|
return message.channel.createMessage(`***${this.client.stores.emojis.error} The port you provided is being used by a system process.***`);
|
||||||
|
} catch (error) {
|
||||||
|
return message.channel.createMessage(`***${this.client.stores.emojis.error} The domain or port you provided could not be found.***`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return message.channel.createMessage(`***${this.client.stores.emojis.error} The domain or port you provided could not be found.***`);
|
||||||
|
}
|
||||||
const embeds = dom.map((domain) => {
|
const embeds = dom.map((domain) => {
|
||||||
const cert = fs.readFileSync(domain.x509.cert, { encoding: 'utf8' });
|
const cert = fs.readFileSync(domain.x509.cert, { encoding: 'utf8' });
|
||||||
const embed = new RichEmbed();
|
const embed = new RichEmbed();
|
||||||
|
|
|
@ -4,7 +4,7 @@ import { readdirSync } from 'fs';
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
import { Client } from '..';
|
import { Client } from '..';
|
||||||
import { Command, RichEmbed } from '../class';
|
import { Command, RichEmbed } from '../class';
|
||||||
import { parseCertificate } from '../functions';
|
import { parseCertificate, Certificate } from '../functions';
|
||||||
|
|
||||||
export default class Parseall extends Command {
|
export default class Parseall extends Command {
|
||||||
constructor(client: Client) {
|
constructor(client: Client) {
|
||||||
|
@ -19,6 +19,7 @@ export default class Parseall extends Command {
|
||||||
|
|
||||||
public async run(message: Message, args: string[]) {
|
public async run(message: Message, args: string[]) {
|
||||||
try {
|
try {
|
||||||
|
const msg = await message.channel.createMessage(`${this.client.stores.emojis.loading} ***Loading...***`);
|
||||||
const embed = new RichEmbed();
|
const embed = new RichEmbed();
|
||||||
embed.setTitle('Certificate Validation');
|
embed.setTitle('Certificate Validation');
|
||||||
embed.setAuthor(this.client.user.username, this.client.user.avatarURL);
|
embed.setAuthor(this.client.user.username, this.client.user.avatarURL);
|
||||||
|
@ -26,41 +27,38 @@ export default class Parseall extends Command {
|
||||||
embed.setTimestamp();
|
embed.setTimestamp();
|
||||||
const search = await this.client.db.Account.find();
|
const search = await this.client.db.Account.find();
|
||||||
|
|
||||||
const certificates = search.map((a) => {
|
const files = search.map((acc) => {
|
||||||
let certFile: string;
|
let certfile: string;
|
||||||
try {
|
try { certfile = readdirSync(`${acc.homepath}/Validation`)[0] } catch (error) { if (error.message.includes('no such file or directory') || error.message.includes('File doesn\'t exist.')) certfile = 'not_found.crt' } // eslint-disable-line
|
||||||
certFile = readdirSync(`${a.homepath}/Validation`)[0]; // eslint-disable-line
|
return `${acc.homepath}/Validation/${certfile}`;
|
||||||
} catch (error) {
|
|
||||||
if (error.message.includes('no such file or directory') || error.message.includes('File doesn\'t exist.')) certFile = 'not_found.crt';
|
|
||||||
else throw error;
|
|
||||||
}
|
|
||||||
return parseCertificate(this.client, `${a.homepath}/Validation/${certFile}`);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const parsed = await Promise.all(certificates);
|
// @ts-ignore
|
||||||
const final = search.map((a) => {
|
const parsed: ({ status: 'fulfilled', value: Certificate } | { status: 'rejected', reason: Error })[] = await Promise.allSettled(files.map((c) => parseCertificate(this.client, c)));
|
||||||
try {
|
|
||||||
const { notAfter } = parsed[search.findIndex((acc) => acc === a)];
|
const final: string[] = await Promise.all(search.map(async (a) => {
|
||||||
// @ts-ignore
|
const result = parsed[search.findIndex((acc) => acc === a)];
|
||||||
const timeObject: {years: number, months: number, days: number, hours: number, minutes: number, seconds: number, firstDateWasLater: boolean} = moment.preciseDiff(new Date(), notAfter, true);
|
if (result.status === 'rejected') {
|
||||||
const precise: [number, string][] = [];
|
if (result.reason.message.includes('no such file or directory') || result.reason.message.includes('File doesn\'t exist.')) return `${this.client.stores.emojis.error} **${a.username}** Unable to locate certificate`;
|
||||||
// @ts-ignore
|
if (result.reason.message.includes('panic: Certificate PEM Encode == nil')) return `${this.client.stores.emojis.error} **${a.username}** Invalid certificate`;
|
||||||
const timeArray: number[] = Object.values(timeObject).filter((v) => typeof v === 'number');
|
throw result.reason;
|
||||||
|
}
|
||||||
|
const { notAfter } = result.value;
|
||||||
|
// @ts-ignore
|
||||||
|
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) => typeof v === 'number');
|
||||||
timeArray.forEach((t) => { // eslint-disable-line
|
timeArray.forEach((t) => { // eslint-disable-line
|
||||||
const index = timeArray.indexOf(t);
|
const index = timeArray.indexOf(t);
|
||||||
const measurements = ['yr', 'mo', 'd', 'h', 'm', 's'];
|
const measurements = ['yr', 'mo', 'd', 'h', 'm', 's'];
|
||||||
precise.push([t, measurements[index]]);
|
precise.push([t, measurements[index]]);
|
||||||
});
|
});
|
||||||
const time = precise.filter((n) => n[0]).map(((v) => v.join(''))).join(', ');
|
const time = precise.filter((n) => n[0]).map(((v) => v.join(''))).join(', ');
|
||||||
|
|
||||||
if (notAfter < new Date()) return `${this.client.stores.emojis.error} **${a.username}** Expired ${time} ago`;
|
if (notAfter < new Date()) return `${this.client.stores.emojis.error} **${a.username}** Expired ${time} ago`;
|
||||||
return `${this.client.stores.emojis.success} **${a.username}** Expires in ${time}`;
|
return `${this.client.stores.emojis.success} **${a.username}** Expires in ${time}`;
|
||||||
} catch (error) {
|
}));
|
||||||
if (error.message.includes('no such file or directory') || error.message.includes('File doesn\'t exist.')) return `${this.client.stores.emojis.error} **${a.username}** Unable to locate certificate`;
|
|
||||||
if (error.message.includes('panic: Certificate PEM Encode == nil')) return `${this.client.stores.emojis.error} ** ${a.username}** Invalid certificate`;
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
if (final.join('\n').length < 2048) embed.setDescription(final.join('\n'));
|
if (final.join('\n').length < 2048) embed.setDescription(final.join('\n'));
|
||||||
else {
|
else {
|
||||||
|
@ -69,7 +67,7 @@ export default class Parseall extends Command {
|
||||||
}
|
}
|
||||||
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
return await message.channel.createMessage({ embed });
|
return await msg.edit({ content: '', embed });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return this.client.util.handleError(error, message, this);
|
return this.client.util.handleError(error, message, this);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue