forked from engineering/cloudservices
Added and changed stuff
parent
6f0741b03b
commit
8c35748aee
|
@ -0,0 +1,47 @@
|
||||||
|
import { Message, PrivateChannel } from 'eris';
|
||||||
|
import { Client } from '..';
|
||||||
|
import { Command, RichEmbed } from '../class';
|
||||||
|
import { AccountInterface } from '../models';
|
||||||
|
|
||||||
|
export default class SecureSign_Account extends Command {
|
||||||
|
constructor(client: Client) {
|
||||||
|
super(client);
|
||||||
|
this.name = 'account';
|
||||||
|
this.description = 'Provides SecureSign account details for currently logged in user';
|
||||||
|
this.usage = `${this.client.config.prefix}securesign account`;
|
||||||
|
this.enabled = true;
|
||||||
|
this.guildOnly = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async run(message: Message, args: string[]) {
|
||||||
|
try {
|
||||||
|
const user = await this.client.db.Account.findOne({ userID: message.author.id });
|
||||||
|
if (!user || (user.permissions.staff && !(message.channel instanceof PrivateChannel))) return message.channel.createMessage(`${this.client.stores.emojis.error} ***Run this command in your DMs!***`);
|
||||||
|
|
||||||
|
let account: AccountInterface;
|
||||||
|
if (!args[0] || !user.permissions.staff) account = user;
|
||||||
|
else account = await this.client.db.Account.findOne({ $or: [{ userID: args[0] }, { username: args[0] }, { emailAddress: args[0] }] });
|
||||||
|
|
||||||
|
if (!account) return message.channel.createMessage(`${this.client.stores.emojis.error} ***Account not found***`);
|
||||||
|
if (!account.hash) return message.channel.createMessage(`${this.client.stores.emojis.error} ***Account not initialized***`);
|
||||||
|
const msg = await message.channel.createMessage(`${this.client.stores.emojis.loading} ***Loading account details...***`);
|
||||||
|
|
||||||
|
const details = await this.client.util.exec(`sudo -H -u ${account.username} bash -c 'securesign-canary account'`);
|
||||||
|
const info = details.replace(/^\s+|\s+$/g, '').replace(/\n/g, '\n**').replace(/: /g, ':** ').split('\n');
|
||||||
|
const title = info.shift();
|
||||||
|
const description = info.join('\n');
|
||||||
|
const content = '';
|
||||||
|
|
||||||
|
const embed = new RichEmbed();
|
||||||
|
embed.setTitle(title);
|
||||||
|
embed.setDescription(description);
|
||||||
|
embed.setAuthor(this.client.user.username, this.client.user.avatarURL);
|
||||||
|
embed.setFooter(`Requested by ${message.member.username}#${message.member.discriminator}`, message.member.avatarURL);
|
||||||
|
|
||||||
|
// @ts-ignore
|
||||||
|
return msg.edit({ content, embed });
|
||||||
|
} catch (error) {
|
||||||
|
return this.client.util.handleError(error, message, this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -47,6 +47,7 @@ export default class SecureSign_Init extends Command {
|
||||||
}
|
}
|
||||||
const init = await this.client.util.exec(`sudo -H -u ${account.username} bash -c 'securesign-canary init -a ${args[0]}'`);
|
const init = await this.client.util.exec(`sudo -H -u ${account.username} bash -c 'securesign-canary init -a ${args[0]}'`);
|
||||||
if (!init.replace(/^\s+|\s+$/g, '').endsWith('Initialization sequence completed.')) throw new Error(`Account initialization did not complete successfully:\n${init}`);
|
if (!init.replace(/^\s+|\s+$/g, '').endsWith('Initialization sequence completed.')) throw new Error(`Account initialization did not complete successfully:\n${init}`);
|
||||||
|
await this.client.db.Account.updateOne({ userID: message.author.id }, { $set: { hash: args[0] } });
|
||||||
return msg.edit(`${this.client.stores.emojis.success} ***Account initialized***`);
|
return msg.edit(`${this.client.stores.emojis.success} ***Account initialized***`);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return this.client.util.handleError(error, message, this);
|
return this.client.util.handleError(error, message, this);
|
||||||
|
|
|
@ -0,0 +1,25 @@
|
||||||
|
/* eslint-disable no-await-in-loop */
|
||||||
|
import axios from 'axios';
|
||||||
|
import { Client } from '..';
|
||||||
|
|
||||||
|
export default function checkSS(client: Client) {
|
||||||
|
setInterval(async () => {
|
||||||
|
const accounts = await client.db.Account.find();
|
||||||
|
const hashes = accounts.filter((h) => h.hash);
|
||||||
|
for (const { hash, userID } of hashes) {
|
||||||
|
try {
|
||||||
|
await axios({
|
||||||
|
method: 'get',
|
||||||
|
url: 'https://api.securesign.org/account/details',
|
||||||
|
headers: { Authorization: hash },
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
const { status } = error.response;
|
||||||
|
if (status === 400 || status === 401 || status === 403 || status === 404) {
|
||||||
|
client.db.Account.updateOne({ hash }, { $set: { hash: null } });
|
||||||
|
client.getDMChannel(userID).then((channel) => channel.createMessage('Your SecureSign password has been reset - please reinitialize your SecureSign account')).catch();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, 60000);
|
||||||
|
}
|
Loading…
Reference in New Issue