1
0
Fork 0

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

refactor/models
Matthew 2019-11-21 21:22:25 -05:00
commit 3a99c9efa4
No known key found for this signature in database
GPG Key ID: 766BE43AE75F7559
5 changed files with 73 additions and 29 deletions

View File

@ -27,6 +27,7 @@ export default class Account extends Route {
res.status(200).json({ code: this.constants.codes.SUCCESS, message: acc }); res.status(200).json({ code: this.constants.codes.SUCCESS, message: acc });
} catch (error) { } catch (error) {
this.handleError(error, res); this.handleError(error, res);
this.server.client.util.handleError(error);
} }
}); });
@ -42,6 +43,7 @@ export default class Account extends Route {
} }
} catch (error) { } catch (error) {
this.handleError(error, res); this.handleError(error, res);
this.server.client.util.handleError(error);
} }
}); });
@ -51,6 +53,7 @@ export default class Account extends Route {
res.status(200).json({ code: this.constants.codes.SUCCESS, message: data }); res.status(200).json({ code: this.constants.codes.SUCCESS, message: data });
} catch (error) { } catch (error) {
this.handleError(error, res); this.handleError(error, res);
this.server.client.util.handleError(error);
} }
}); });
} }

View File

@ -35,6 +35,7 @@ export default class Root extends Route {
res.status(200).json({ code: this.constants.codes.SUCCESS, message: response }); res.status(200).json({ code: this.constants.codes.SUCCESS, message: response });
} catch (error) { } catch (error) {
this.handleError(error, res); this.handleError(error, res);
this.server.client.util.handleError(error);
} }
}); });
} }

View File

@ -17,6 +17,7 @@ export { default as Pull } from './pull';
export { default as Restart } from './restart'; export { default as Restart } from './restart';
export { default as SecureSign } from './securesign'; export { default as SecureSign } from './securesign';
export { default as Sysinfo } from './sysinfo'; export { default as Sysinfo } from './sysinfo';
export { default as Unban } from './unban';
export { default as Unlock } from './unlock'; export { default as Unlock } from './unlock';
export { default as Warn } from './warn'; export { default as Warn } from './warn';
export { default as Whois } from './whois'; export { default as Whois } from './whois';

35
src/commands/unban.ts Normal file
View File

@ -0,0 +1,35 @@
import { Message } from 'eris';
import { Client } from '..';
import { Command } from '../class';
export default class Unban extends Command {
constructor(client: Client) {
super(client);
this.name = 'unban';
this.description = 'Unban an IP from Cloud/NGINX';
this.aliases = ['unbanip'];
this.usage = `${this.client.config.prefix}unban [service] [ip]`;
this.permissions = { roles: ['455972169449734144', '643619219988152321'] };
this.enabled = true;
}
public async run(message: Message, args: string[]) {
try {
if (!args[1]) return this.client.commands.get('help').run(message, [this.name]);
const msg = await message.channel.createMessage(`${this.client.stores.emojis.loading} ***Unbanning IP...***`);
try {
await this.client.util.exec(`sudo fail2ban-client set ${args[0]} unbanip ${args[1]}`);
} catch (error) {
if (error.message.includes('is not banned')) return msg.edit(`${this.client.stores.emojis.error} ***IP address not banned***`);
if (error.message.includes(`'${args[0]}'`)) return msg.edit(`${this.client.stores.emojis.error} ***Invalid service***`);
throw error;
}
message.delete();
return msg.edit(`${this.client.stores.emojis.success} ***IP address ${args[1]} unbanned from ${args[0].toUpperCase()}***`);
} catch (error) {
return this.client.util.handleError(error, message, this);
}
}
}

View File

@ -16,34 +16,38 @@ export default class Whois_User extends Command {
} }
public async run(message: Message, args: string[]) { public async run(message: Message, args: string[]) {
let account: AccountInterface; try {
if (!args[0]) account = await this.client.db.Account.findOne({ userID: message.author.id }); let account: AccountInterface;
else account = await this.client.db.Account.findOne({ $or: [{ username: args[0] }, { userID: args[0] }] }); if (!args[0]) account = await this.client.db.Account.findOne({ userID: message.author.id });
if (!account) return message.channel.createMessage(`***${this.client.stores.emojis.error} You don't have an account.***`); else account = await this.client.db.Account.findOne({ $or: [{ username: args[0] }, { userID: args[0] }] });
const embed = new RichEmbed(); if (!account) return message.channel.createMessage(`***${this.client.stores.emojis.error} You don't have an account.***`);
embed.setTitle('Account Information'); const embed = new RichEmbed();
if (this.client.users.get(account.userID)) embed.setThumbnail(this.client.users.get(account.userID).avatarURL); embed.setTitle('Account Information');
embed.setColor(0x36393f); if (this.client.users.get(account.userID)) embed.setThumbnail(this.client.users.get(account.userID).avatarURL);
embed.addField('Username', `${account.username} | <@${account.userID}>`, true); embed.setColor(0x36393f);
embed.addField('ID', account.userID, true); embed.addField('Username', `${account.username} | <@${account.userID}>`, true);
embed.addField('Created By', `<@${this.client.users.get(account.createdBy).id}>`, true); embed.addField('ID', account.userID, true);
embed.addField('Created At', moment(account.createdAt).format('dddd, MMMM Do YYYY, h:mm:ss A'), true); embed.addField('Created By', `<@${this.client.users.get(account.createdBy).id}>`, true);
const cpuUsage = await this.client.util.exec(`top -b -n 1 -u ${account.username} | awk 'NR>7 { sum += $9; } END { print sum; }'`); embed.addField('Created At', moment(account.createdAt).format('dddd, MMMM Do YYYY, h:mm:ss A'), true);
embed.addField('CPU Usage', cpuUsage.split('\n')[0] ? `${cpuUsage.split('\n')[0]}%` : '0%', true); const cpuUsage = await this.client.util.exec(`top -b -n 1 -u ${account.username} | awk 'NR>7 { sum += $9; } END { print sum; }'`);
embed.addField('Memory', dataConversion(Number(await this.client.util.exec(`memory ${account.username}`)) * 1000), true); embed.addField('CPU Usage', cpuUsage.split('\n')[0] ? `${cpuUsage.split('\n')[0]}%` : '0%', true);
const data = await this.client.redis.get(`storage-${account.username}`) ? dataConversion(Number(await this.client.redis.get(`storage-${account.username}`))) : 'N/A'; embed.addField('Memory', dataConversion(Number(await this.client.util.exec(`memory ${account.username}`)) * 1000), true);
embed.addField('Storage', data, true); const data = await this.client.redis.get(`storage-${account.username}`) ? dataConversion(Number(await this.client.redis.get(`storage-${account.username}`))) : 'N/A';
let details = ''; embed.addField('Storage', data, true);
if (account.locked) details += 'This account is currently locked.\n'; let details = '';
if (account.permissions.engineer) details += 'This account belongs to an Engineer.\n'; if (account.locked) details += 'This account is currently locked.\n';
else if (account.permissions.communityManager) details += 'This account belongs to a Community Manager.\n'; if (account.permissions.engineer) details += 'This account belongs to an Engineer.\n';
else if (account.permissions.supervisor) details += 'This account belongs to a Supervisor.\n'; else if (account.permissions.communityManager) details += 'This account belongs to a Community Manager.\n';
else if (account.permissions.staff) details += 'This account belongs to a Staff member.\n'; else if (account.permissions.supervisor) details += 'This account belongs to a Supervisor.\n';
if (account.root) details += 'This account has root/administrative privileges.\n'; else if (account.permissions.staff) details += 'This account belongs to a Staff member.\n';
if (details) embed.addField('Additional Details', details, true); if (account.root) details += 'This account has root/administrative privileges.\n';
embed.setFooter(this.client.user.username, this.client.user.avatarURL); if (details) embed.addField('Additional Details', details, true);
embed.setTimestamp(); embed.setFooter(this.client.user.username, this.client.user.avatarURL);
// @ts-ignore embed.setTimestamp();
message.channel.createMessage({ embed }); // @ts-ignore
message.channel.createMessage({ embed });
} catch (error) {
this.client.util.handleError(error, message, this);
}
} }
} }