Merge branch 'master' of gitlab.libraryofcode.org:engineering/cloudservices
commit
3a99c9efa4
|
@ -27,6 +27,7 @@ export default class Account extends Route {
|
|||
res.status(200).json({ code: this.constants.codes.SUCCESS, message: acc });
|
||||
} catch (error) {
|
||||
this.handleError(error, res);
|
||||
this.server.client.util.handleError(error);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -42,6 +43,7 @@ export default class Account extends Route {
|
|||
}
|
||||
} catch (error) {
|
||||
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 });
|
||||
} catch (error) {
|
||||
this.handleError(error, res);
|
||||
this.server.client.util.handleError(error);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -35,6 +35,7 @@ export default class Root extends Route {
|
|||
res.status(200).json({ code: this.constants.codes.SUCCESS, message: response });
|
||||
} catch (error) {
|
||||
this.handleError(error, res);
|
||||
this.server.client.util.handleError(error);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@ export { default as Pull } from './pull';
|
|||
export { default as Restart } from './restart';
|
||||
export { default as SecureSign } from './securesign';
|
||||
export { default as Sysinfo } from './sysinfo';
|
||||
export { default as Unban } from './unban';
|
||||
export { default as Unlock } from './unlock';
|
||||
export { default as Warn } from './warn';
|
||||
export { default as Whois } from './whois';
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -16,34 +16,38 @@ export default class Whois_User extends Command {
|
|||
}
|
||||
|
||||
public async run(message: Message, args: string[]) {
|
||||
let account: AccountInterface;
|
||||
if (!args[0]) account = await this.client.db.Account.findOne({ userID: message.author.id });
|
||||
else account = await this.client.db.Account.findOne({ $or: [{ username: args[0] }, { userID: args[0] }] });
|
||||
if (!account) return message.channel.createMessage(`***${this.client.stores.emojis.error} You don't have an account.***`);
|
||||
const embed = new RichEmbed();
|
||||
embed.setTitle('Account Information');
|
||||
if (this.client.users.get(account.userID)) embed.setThumbnail(this.client.users.get(account.userID).avatarURL);
|
||||
embed.setColor(0x36393f);
|
||||
embed.addField('Username', `${account.username} | <@${account.userID}>`, true);
|
||||
embed.addField('ID', account.userID, true);
|
||||
embed.addField('Created By', `<@${this.client.users.get(account.createdBy).id}>`, true);
|
||||
embed.addField('Created At', moment(account.createdAt).format('dddd, MMMM Do YYYY, h:mm:ss A'), 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('CPU Usage', cpuUsage.split('\n')[0] ? `${cpuUsage.split('\n')[0]}%` : '0%', true);
|
||||
embed.addField('Memory', dataConversion(Number(await this.client.util.exec(`memory ${account.username}`)) * 1000), 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('Storage', data, true);
|
||||
let details = '';
|
||||
if (account.locked) details += 'This account is currently locked.\n';
|
||||
if (account.permissions.engineer) details += 'This account belongs to an Engineer.\n';
|
||||
else if (account.permissions.communityManager) details += 'This account belongs to a Community Manager.\n';
|
||||
else if (account.permissions.supervisor) details += 'This account belongs to a Supervisor.\n';
|
||||
else if (account.permissions.staff) details += 'This account belongs to a Staff member.\n';
|
||||
if (account.root) details += 'This account has root/administrative privileges.\n';
|
||||
if (details) embed.addField('Additional Details', details, true);
|
||||
embed.setFooter(this.client.user.username, this.client.user.avatarURL);
|
||||
embed.setTimestamp();
|
||||
// @ts-ignore
|
||||
message.channel.createMessage({ embed });
|
||||
try {
|
||||
let account: AccountInterface;
|
||||
if (!args[0]) account = await this.client.db.Account.findOne({ userID: message.author.id });
|
||||
else account = await this.client.db.Account.findOne({ $or: [{ username: args[0] }, { userID: args[0] }] });
|
||||
if (!account) return message.channel.createMessage(`***${this.client.stores.emojis.error} You don't have an account.***`);
|
||||
const embed = new RichEmbed();
|
||||
embed.setTitle('Account Information');
|
||||
if (this.client.users.get(account.userID)) embed.setThumbnail(this.client.users.get(account.userID).avatarURL);
|
||||
embed.setColor(0x36393f);
|
||||
embed.addField('Username', `${account.username} | <@${account.userID}>`, true);
|
||||
embed.addField('ID', account.userID, true);
|
||||
embed.addField('Created By', `<@${this.client.users.get(account.createdBy).id}>`, true);
|
||||
embed.addField('Created At', moment(account.createdAt).format('dddd, MMMM Do YYYY, h:mm:ss A'), 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('CPU Usage', cpuUsage.split('\n')[0] ? `${cpuUsage.split('\n')[0]}%` : '0%', true);
|
||||
embed.addField('Memory', dataConversion(Number(await this.client.util.exec(`memory ${account.username}`)) * 1000), 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('Storage', data, true);
|
||||
let details = '';
|
||||
if (account.locked) details += 'This account is currently locked.\n';
|
||||
if (account.permissions.engineer) details += 'This account belongs to an Engineer.\n';
|
||||
else if (account.permissions.communityManager) details += 'This account belongs to a Community Manager.\n';
|
||||
else if (account.permissions.supervisor) details += 'This account belongs to a Supervisor.\n';
|
||||
else if (account.permissions.staff) details += 'This account belongs to a Staff member.\n';
|
||||
if (account.root) details += 'This account has root/administrative privileges.\n';
|
||||
if (details) embed.addField('Additional Details', details, true);
|
||||
embed.setFooter(this.client.user.username, this.client.user.avatarURL);
|
||||
embed.setTimestamp();
|
||||
// @ts-ignore
|
||||
message.channel.createMessage({ embed });
|
||||
} catch (error) {
|
||||
this.client.util.handleError(error, message, this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue