1
0
Fork 0

Merge branch 'master' of gitlab.libraryofcode.org:engineering/cloudservices-rewrite

refactor/models
Matthew 2019-11-16 14:19:47 -05:00
commit 17572da752
No known key found for this signature in database
GPG Key ID: 766BE43AE75F7559
5 changed files with 63 additions and 4 deletions

View File

@ -22,7 +22,6 @@ export default class CWG_Data extends Command {
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) return message.channel.createMessage(`***${this.client.stores.emojis.error} The domain or port you provided could not be found.***`);
// const embeds: RichEmbed[] = [];
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();

View File

@ -18,6 +18,7 @@ export default class Disk extends Command {
async run(message: Message, args: string[]) { async run(message: Message, args: string[]) {
try { try {
if (!args[0]) return this.client.commands.get('help').run(message, [this.name]);
const account = await this.client.db.Account.findOne({ $or: [{ username: args[0] }, { userID: args[0] }, { emailAddress: args[0] }] }); const account = await this.client.db.Account.findOne({ $or: [{ username: args[0] }, { userID: args[0] }, { emailAddress: args[0] }] });
if (!account) return message.channel.createMessage(`${this.client.stores.emojis.error} ***Account not found***`); if (!account) return message.channel.createMessage(`${this.client.stores.emojis.error} ***Account not found***`);
if (account.root || args[0].includes('./')) return message.channel.createMessage(`${this.client.stores.emojis.error} ***Permission denied***`); if (account.root || args[0].includes('./')) return message.channel.createMessage(`${this.client.stores.emojis.error} ***Permission denied***`);
@ -30,8 +31,8 @@ export default class Disk extends Command {
const embed = new RichEmbed(); const embed = new RichEmbed();
embed.setTitle('Disk Usage'); embed.setTitle('Disk Usage');
embed.setColor('ff0000'); embed.setColor('ff0000');
embed.setDescription(`/home/${account.username}`); embed.setDescription(result.split(/ +/g)[1]);
embed.addField('Result', dataConversion(Number(result)), true); embed.addField('Result', dataConversion(Number(result.split(/ +/g)[0])), true);
embed.addField('Time taken', totalTime, true); embed.addField('Time taken', totalTime, true);
embed.setFooter(`Requested by ${message.author.username}#${message.author.discriminator}`, message.author.avatarURL); embed.setFooter(`Requested by ${message.author.username}#${message.author.discriminator}`, message.author.avatarURL);
embed.setTimestamp(); embed.setTimestamp();

View File

@ -10,6 +10,7 @@ export { default as Lock } from './lock';
export { default as Modlogs } from './modlogs'; export { default as Modlogs } from './modlogs';
export { default as Notify } from './notify'; export { default as Notify } from './notify';
export { default as Parse } from './parse'; export { default as Parse } from './parse';
export { default as Parseall } from './parseall';
export { default as Ping } from './ping'; export { default as Ping } from './ping';
export { default as Pull } from './pull'; export { default as Pull } from './pull';
export { default as Sysinfo } from './sysinfo'; export { default as Sysinfo } from './sysinfo';

View File

@ -21,7 +21,8 @@ export default class Modlogs extends Command {
const query = await this.client.db.Moderation.find({ $or: [{ username: args.join(' ') }, { userID: args.filter((a) => a)[0].replace(/[<@!>]/g, '') }] }); const query = await this.client.db.Moderation.find({ $or: [{ username: args.join(' ') }, { userID: args.filter((a) => a)[0].replace(/[<@!>]/g, '') }] });
if (!query.length) return msg.edit(`***${this.client.stores.emojis.error} Cannot locate modlogs for ${args.join(' ')}***`); if (!query.length) return msg.edit(`***${this.client.stores.emojis.error} Cannot locate modlogs for ${args.join(' ')}***`);
const formatted = query.map((log) => { // @ts-ignore
const formatted = query.sort((a, b) => a.date - b.date).map((log) => {
const { username, moderatorID, reason, type, date } = log; const { username, moderatorID, reason, type, date } = log;
let name: string; let name: string;
switch (type) { switch (type) {

57
src/commands/parseall.ts Normal file
View File

@ -0,0 +1,57 @@
import { parseCert } from '@ghaiklor/x509';
import { Message } from 'eris';
import { readdirSync } from 'fs';
import moment from 'moment';
import { Client } from '..';
import { Command, RichEmbed } from '../class';
export default class Parseall extends Command {
constructor(client: Client) {
super(client);
this.name = 'parseall';
this.description = 'Displays certificate validation for all accounts';
this.usage = `${this.client.config.prefix}parseall`;
this.permissions = { roles: ['446104438969466890'] };
this.aliases = ['checkcerts', 'verifyall', 'verifycerts'];
}
public async run(message: Message, args: string[]) {
try {
const embed = new RichEmbed();
embed.setTitle('Certificate Validation');
embed.setAuthor(this.client.user.username, this.client.user.avatarURL);
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.username);
const final: string[] = [];
accounts.forEach(async (a) => {
try {
const certFile = readdirSync(`/home/${a}/Validation`)[0];
const { notAfter } = parseCert(`/home/${a}/Validation/${certFile}`);
// @ts-ignore
const time = moment.preciseDiff(new Date(), notAfter);
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}`);
} 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`);
else throw error;
}
});
if (final.join('\n').length < 2048) embed.setDescription(final.join('\n'));
else {
const split = this.client.util.splitString(final.join('\n'), 1024);
split.forEach((s) => embed.addField('\u200B', s));
}
// @ts-ignore
return await message.channel.createMessage({ embed });
} catch (error) {
return this.client.util.handleError(error, message, this);
}
}
}