From 07a241ebe3f33096bfe00a9351d30d740e0676ba Mon Sep 17 00:00:00 2001 From: Bsian Date: Mon, 23 Dec 2019 14:18:17 +0000 Subject: [PATCH 01/16] Removed unnecessary usage --- src/commands/deleteaccount.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/commands/deleteaccount.ts b/src/commands/deleteaccount.ts index e620d3e..d6565b2 100644 --- a/src/commands/deleteaccount.ts +++ b/src/commands/deleteaccount.ts @@ -8,7 +8,7 @@ export default class DeleteAccount extends Command { super(client); this.name = 'deleteaccount'; this.description = 'Delete an account on the Cloud VM'; - this.usage = `${this.client.config.prefix}deleteaccount [User Name | User ID | Email Address] [Reason] | ${this.client.config.prefix}deleteaccount [Username] [Reason] | ${this.client.config.prefix}deleteaccount [Email] [Reason]`; + this.usage = `${this.client.config.prefix}deleteaccount [User Name | User ID | Email Address] [Reason]`; this.aliases = ['deleteacc', 'dacc', 'daccount', 'delete']; this.permissions = { roles: ['475817826251440128', '525441307037007902'] }; this.guildOnly = true; From d445108a9819a95939c14fd818b8c3b29cfc20e1 Mon Sep 17 00:00:00 2001 From: Bsian Date: Mon, 23 Dec 2019 14:42:24 +0000 Subject: [PATCH 02/16] Promise rejections --- src/class/Util.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/class/Util.ts b/src/class/Util.ts index 8e5aaed..03e702d 100644 --- a/src/class/Util.ts +++ b/src/class/Util.ts @@ -167,11 +167,11 @@ export default class Util { public async messageCollector(message: Message, question: string, timeout: number, shouldDelete = false, choices: string[] = null, filter = (msg: Message): boolean|void => {}): Promise { const msg = await message.channel.createMessage(question); return new Promise((res, rej) => { - setTimeout(() => { if (shouldDelete) msg.delete(); rej(new Error('Did not supply a valid input in time')); }, timeout); + setTimeout(() => { if (shouldDelete) msg.delete().catch(); rej(new Error('Did not supply a valid input in time')); }, timeout); this.client.on('messageCreate', (Msg) => { if (filter(Msg) === false) return; const verif = choices ? choices.includes(Msg.content) : Msg.content; - if (verif) { if (shouldDelete) msg.delete(); res(Msg); } + if (verif) { if (shouldDelete) msg.delete().catch(); res(Msg); } }); }); } From 11ac39dc19a5eca7be21a6ba09aef1ff1db97301 Mon Sep 17 00:00:00 2001 From: Bsian Date: Mon, 23 Dec 2019 15:24:46 +0000 Subject: [PATCH 03/16] Stop erroring if user isn't in server --- src/class/Util.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/class/Util.ts b/src/class/Util.ts index 03e702d..f967e24 100644 --- a/src/class/Util.ts +++ b/src/class/Util.ts @@ -156,7 +156,7 @@ export default class Util { this.exec(`lock ${username}`); const tasks = [ this.exec(`deluser ${username} --remove-home --backup-to /management/Archives && rm -rf -R /home/${username}`), - this.client.removeGuildMemberRole('446067825673633794', account.userID, '546457886440685578', 'Cloud Account Deleted'), + this.client.removeGuildMemberRole('446067825673633794', account.userID, '546457886440685578', 'Cloud Account Deleted').catch(), this.client.db.Account.deleteOne({ username }), this.exec(`groupdel ${username}`), ]; From bbaf9f55dbcf3e129f07a2ae67ec4f9f17fdad71 Mon Sep 17 00:00:00 2001 From: Bsian Date: Mon, 23 Dec 2019 16:11:45 +0000 Subject: [PATCH 04/16] Stop erroring if user isn't in server --- src/class/Util.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/class/Util.ts b/src/class/Util.ts index f967e24..76ca6a0 100644 --- a/src/class/Util.ts +++ b/src/class/Util.ts @@ -156,10 +156,10 @@ export default class Util { this.exec(`lock ${username}`); const tasks = [ this.exec(`deluser ${username} --remove-home --backup-to /management/Archives && rm -rf -R /home/${username}`), - this.client.removeGuildMemberRole('446067825673633794', account.userID, '546457886440685578', 'Cloud Account Deleted').catch(), this.client.db.Account.deleteOne({ username }), this.exec(`groupdel ${username}`), ]; + this.client.removeGuildMemberRole('446067825673633794', account.userID, '546457886440685578', 'Cloud Account Deleted').catch(); // @ts-ignore await Promise.all(tasks); } From 82b3148fd3c4898ce07bb1a15eed987b56bed3d4 Mon Sep 17 00:00:00 2001 From: Bsian Date: Mon, 23 Dec 2019 16:55:10 +0000 Subject: [PATCH 05/16] Move group delete to after folder delete --- src/class/Util.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/class/Util.ts b/src/class/Util.ts index 76ca6a0..8f85dd6 100644 --- a/src/class/Util.ts +++ b/src/class/Util.ts @@ -155,9 +155,8 @@ export default class Util { if (!account) throw new Error('Account not found'); this.exec(`lock ${username}`); const tasks = [ - this.exec(`deluser ${username} --remove-home --backup-to /management/Archives && rm -rf -R /home/${username}`), + this.exec(`deluser ${username} --remove-home --backup-to /management/Archives && rm -rf -R /home/${username} && groupdel ${username}`), this.client.db.Account.deleteOne({ username }), - this.exec(`groupdel ${username}`), ]; this.client.removeGuildMemberRole('446067825673633794', account.userID, '546457886440685578', 'Cloud Account Deleted').catch(); // @ts-ignore From 612d527986cf9b4fa0b5e5dd0690a897d444c436 Mon Sep 17 00:00:00 2001 From: Bsian Date: Mon, 23 Dec 2019 17:08:42 +0000 Subject: [PATCH 06/16] Add home path --- src/class/Util.ts | 4 ++-- src/commands/deleteaccount.ts | 2 +- src/commands/disk.ts | 2 +- src/commands/parse.ts | 6 +++--- src/commands/parseall.ts | 6 +++--- src/commands/securesign_activatekey.ts | 2 +- src/commands/securesign_createcrt.ts | 2 +- src/models/Account.ts | 2 ++ 8 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/class/Util.ts b/src/class/Util.ts index 8f85dd6..cdd27c2 100644 --- a/src/class/Util.ts +++ b/src/class/Util.ts @@ -155,7 +155,7 @@ export default class Util { if (!account) throw new Error('Account not found'); this.exec(`lock ${username}`); const tasks = [ - this.exec(`deluser ${username} --remove-home --backup-to /management/Archives && rm -rf -R /home/${username} && groupdel ${username}`), + this.exec(`deluser ${username} --remove-home --backup-to /management/Archives && rm -rf -R ${account.homepath} && groupdel ${account.homepath.replace('/home/', '')}`), this.client.db.Account.deleteOne({ username }), ]; this.client.removeGuildMemberRole('446067825673633794', account.userID, '546457886440685578', 'Cloud Account Deleted').catch(); @@ -240,7 +240,7 @@ export default class Util { public getAcctHash(username: string) { try { - return fs.readFileSync(`/home/${username}/.securesign/auth`).toString(); + return fs.readFileSync(`${username}/.securesign/auth`).toString(); } catch (error) { return null; } diff --git a/src/commands/deleteaccount.ts b/src/commands/deleteaccount.ts index d6565b2..32dc9aa 100644 --- a/src/commands/deleteaccount.ts +++ b/src/commands/deleteaccount.ts @@ -20,7 +20,7 @@ export default class DeleteAccount extends Command { if (!args[1]) 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] }] }); if (!account) return message.channel.createMessage(`${this.client.stores.emojis.error} ***Account not found.***`); - const { root, username, userID, emailAddress } = account; + const { root, username, userID, emailAddress, homepath } = account; if (root) return message.channel.createMessage(`${this.client.stores.emojis.error} ***Permission denied.***`); const pad = (number: number, amount: number): string => '0'.repeat(amount - number.toString().length) + number; diff --git a/src/commands/disk.ts b/src/commands/disk.ts index 2db92e4..b1ac0d6 100644 --- a/src/commands/disk.ts +++ b/src/commands/disk.ts @@ -24,7 +24,7 @@ export default class Disk extends Command { if (account.root || args[0].includes('./')) return message.channel.createMessage(`${this.client.stores.emojis.error} ***Permission denied***`); const diskReply = await message.channel.createMessage(`${this.client.stores.emojis.loading} ***Fetching total disk size may up to 10 minutes. This message will edit when the disk size has been located.***`); const start = Date.now(); - const result = await this.client.util.exec(`du -s /home/${account.username}`); + const result = await this.client.util.exec(`du -s ${account.homepath}`); const end = Date.now(); // @ts-ignore const totalTime: string = moment.preciseDiff(start, end); diff --git a/src/commands/parse.ts b/src/commands/parse.ts index ef2fef0..acd293f 100644 --- a/src/commands/parse.ts +++ b/src/commands/parse.ts @@ -20,12 +20,12 @@ export default class Parse extends Command { if (!account) return message.channel.createMessage(`***${this.client.stores.emojis.error} Cannot find user.***`); let dir: string[]; try { - dir = await fs.readdir(`/home/${account.username}/Validation`); + dir = await fs.readdir(`${account.homepath}/Validation`); } catch (err) { return message.channel.createMessage(`***${this.client.stores.emojis.error} Cannot locate Validation directory.***`); } if (!dir.length) return message.channel.createMessage(`***${this.client.stores.emojis.error} Cannot locate certificate.***`); - const cert = parseCert(`/home/${account.username}/Validation/${dir[0]}`); + const cert = parseCert(`${account.homepath}/Validation/${dir[0]}`); const subjectCommonName = cert.subject.commonName ? cert.subject.commonName : 'Not Specified'; const subjectEmailAddress = cert.subject.emailAddress ? cert.subject.emailAddress : 'Not Specified'; const subjectOrganization = cert.subject.organizationName ? cert.subject.organizationName : 'Not Specified'; @@ -39,7 +39,7 @@ export default class Parse extends Command { const user = this.client.users.get(account.userID) ? this.client.users.get(account.userID) : await this.client.getRESTUser(account.userID); const embed = new RichEmbed(); embed.setTitle('Parse x509 Certificate'); - embed.setDescription(`/home/${account.username}/Validation/${dir[0]} | ${account.username} <@${user.id}>`); + embed.setDescription(`${account.homepath}/Validation/${dir[0]} | ${account.username} <@${user.id}>`); embed.setColor(3447003); embed.addField('Subject', `**Common Name:** ${subjectCommonName}\n**Email Address:** ${subjectEmailAddress}\n**Organization:** ${subjectOrganization}\n**Organizational Unit:** ${subjectOrganizationalUnit}\n**Country:** ${subjectCountry}`, true); embed.addField('Issuer', `**Common Name:** ${issuerCommonName}\n**Email Address:** ${issuerEmailAddress}\n**Organization:** ${issuerOrganization}\n**Organizational Unit:** ${issuerOrganizationalUnit}\n**Country:** ${issuerCountry}`, true); diff --git a/src/commands/parseall.ts b/src/commands/parseall.ts index 0ac535e..9d9d246 100644 --- a/src/commands/parseall.ts +++ b/src/commands/parseall.ts @@ -24,13 +24,13 @@ export default class Parseall extends Command { 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 accounts = search.map((acc) => acc.homepath); const final: string[] = []; accounts.forEach(async (a) => { try { - const certFile = readdirSync(`/home/${a}/Validation`)[0]; - const { notAfter } = parseCert(`/home/${a}/Validation/${certFile}`); + const certFile = readdirSync(`${a}/Validation`)[0]; + const { notAfter } = parseCert(`${a}/Validation/${certFile}`); // @ts-ignore const time = moment.preciseDiff(new Date(), notAfter); diff --git a/src/commands/securesign_activatekey.ts b/src/commands/securesign_activatekey.ts index 7c7d74a..fc99504 100644 --- a/src/commands/securesign_activatekey.ts +++ b/src/commands/securesign_activatekey.ts @@ -19,7 +19,7 @@ export default class SecureSign_ActivateKey extends Command { 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} ***Activating key...***`); - const hash = this.client.util.getAcctHash(account.username); + const hash = this.client.util.getAcctHash(account.homepath); try { await axios({ method: 'POST', diff --git a/src/commands/securesign_createcrt.ts b/src/commands/securesign_createcrt.ts index df8f26f..05d9937 100644 --- a/src/commands/securesign_createcrt.ts +++ b/src/commands/securesign_createcrt.ts @@ -26,7 +26,7 @@ export default class SecureSign_Init extends Command { if (options.m && (!Number(options.m) || (options.m !== '256' && options.m !== '384' && options.m !== '512'))) return message.channel.createMessage(`${this.client.stores.emojis.error} ***Invalid SHA Digest selected, choose between \`256\`, \`384\` or \`512\``); const msg = await message.channel.createMessage(`${this.client.stores.emojis.loading} ***Creating certificate...***`); - const hash = this.client.util.getAcctHash(account.username); + const hash = this.client.util.getAcctHash(account.homepath); // Check if they can generate certificate try { diff --git a/src/models/Account.ts b/src/models/Account.ts index cadec7a..812fa4a 100644 --- a/src/models/Account.ts +++ b/src/models/Account.ts @@ -3,6 +3,7 @@ import { Document, Schema, model } from 'mongoose'; export interface AccountInterface extends Document { username: string, userID: string, + homepath: string emailAddress: string, createdBy: string, createdAt: Date, @@ -23,6 +24,7 @@ export interface AccountInterface extends Document { const Account: Schema = new Schema({ username: String, userID: String, + homepath: String, emailAddress: String, createdBy: String, createdAt: Date, From 72b89b2f7822f7b21a5a7432b4d1ad8de79eb08c Mon Sep 17 00:00:00 2001 From: Bsian Date: Mon, 23 Dec 2019 17:15:24 +0000 Subject: [PATCH 07/16] Added DB to reload --- src/commands/load.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/commands/load.ts b/src/commands/load.ts index 8f55fe5..172b28a 100644 --- a/src/commands/load.ts +++ b/src/commands/load.ts @@ -15,7 +15,7 @@ export default class Load extends Command { public async run(message: Message, args: string[]) { try { if (!args[0]) return this.client.commands.get('help').run(message, [this.name]); - const allowed = ['config', 'util', 'command']; + const allowed = ['config', 'util', 'command', 'db']; const type = args[0].toLowerCase(); if (!allowed.includes(type)) return message.channel.createMessage(`${this.client.stores.emojis.error} ***Invalid type to (re)load***`); @@ -27,6 +27,19 @@ export default class Load extends Command { const Util = require(`${corepath}/class/Util`).default; this.client.util = new Util(this.client); delete require.cache[`${corepath}/class/Util.js`]; + } else if (type === 'db') { + try { + const dbIndex = require('../models'); + let Db = dbIndex[args[1]]; + if (!Db) return message.channel.createMessage(`${this.client.stores.emojis.error} ***Could not find file***`); + delete require.cache[`${corepath}/models/index.js`]; + delete require.cache[`${corepath}/models/${args[1]}.js`]; + Db = require(`${corepath}/commands/${args[1]}`).default; + this.client.db = require('../models'); + } catch (error) { + if (error.message.includes('Cannot find module')) return message.channel.createMessage(`${this.client.stores.emojis} ***Cannot find file***`); + throw error; + } } else { try { const cmdIndex = require('../commands'); From bc4e351a0ae503b7a74b39ae839d3ac09f40a907 Mon Sep 17 00:00:00 2001 From: Bsian Date: Mon, 23 Dec 2019 17:43:42 +0000 Subject: [PATCH 08/16] Mongoose is a useless pile of shit, bye bye db reloader --- src/commands/load.ts | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/src/commands/load.ts b/src/commands/load.ts index 172b28a..8f55fe5 100644 --- a/src/commands/load.ts +++ b/src/commands/load.ts @@ -15,7 +15,7 @@ export default class Load extends Command { public async run(message: Message, args: string[]) { try { if (!args[0]) return this.client.commands.get('help').run(message, [this.name]); - const allowed = ['config', 'util', 'command', 'db']; + const allowed = ['config', 'util', 'command']; const type = args[0].toLowerCase(); if (!allowed.includes(type)) return message.channel.createMessage(`${this.client.stores.emojis.error} ***Invalid type to (re)load***`); @@ -27,19 +27,6 @@ export default class Load extends Command { const Util = require(`${corepath}/class/Util`).default; this.client.util = new Util(this.client); delete require.cache[`${corepath}/class/Util.js`]; - } else if (type === 'db') { - try { - const dbIndex = require('../models'); - let Db = dbIndex[args[1]]; - if (!Db) return message.channel.createMessage(`${this.client.stores.emojis.error} ***Could not find file***`); - delete require.cache[`${corepath}/models/index.js`]; - delete require.cache[`${corepath}/models/${args[1]}.js`]; - Db = require(`${corepath}/commands/${args[1]}`).default; - this.client.db = require('../models'); - } catch (error) { - if (error.message.includes('Cannot find module')) return message.channel.createMessage(`${this.client.stores.emojis} ***Cannot find file***`); - throw error; - } } else { try { const cmdIndex = require('../commands'); From 1fba4a3f06eb203eaee3dbea649e87a88d387d51 Mon Sep 17 00:00:00 2001 From: Bsian Date: Mon, 23 Dec 2019 18:14:42 +0000 Subject: [PATCH 09/16] Stop un initing --- src/class/Util.ts | 4 ++-- src/functions/checkSS.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/class/Util.ts b/src/class/Util.ts index cdd27c2..6e24fae 100644 --- a/src/class/Util.ts +++ b/src/class/Util.ts @@ -238,9 +238,9 @@ export default class Util { return Promise.resolve(log); } - public getAcctHash(username: string) { + public getAcctHash(userpath: string) { try { - return fs.readFileSync(`${username}/.securesign/auth`).toString(); + return fs.readFileSync(`${userpath}/.securesign/auth`).toString(); } catch (error) { return null; } diff --git a/src/functions/checkSS.ts b/src/functions/checkSS.ts index 29e7b55..5a6070e 100644 --- a/src/functions/checkSS.ts +++ b/src/functions/checkSS.ts @@ -7,9 +7,9 @@ export default function checkSS(client: Client) { try { const accounts = await client.db.Account.find(); const hashes = accounts.filter((h) => h.hash); - for (const { userID, username } of hashes) { + for (const { userID, homepath } of hashes) { try { - const hash = client.util.getAcctHash(username); + const hash = client.util.getAcctHash(homepath); await axios({ method: 'get', url: 'https://api.securesign.org/account/details', From 692b4af059dfc72d621bcc56556f42d6ec3bb275 Mon Sep 17 00:00:00 2001 From: Bsian Date: Mon, 23 Dec 2019 23:10:04 +0000 Subject: [PATCH 10/16] Added password reset command --- src/commands/index.ts | 1 + src/commands/resetpassword.ts | 42 +++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 src/commands/resetpassword.ts diff --git a/src/commands/index.ts b/src/commands/index.ts index 7312475..f8e4bf7 100644 --- a/src/commands/index.ts +++ b/src/commands/index.ts @@ -15,6 +15,7 @@ export { default as parse } from './parse'; export { default as parseall } from './parseall'; export { default as ping } from './ping'; export { default as pull } from './pull'; +export { default as resetpassword } from './resetpassword'; export { default as restart } from './restart'; export { default as securesign } from './securesign'; export { default as sysinfo } from './sysinfo'; diff --git a/src/commands/resetpassword.ts b/src/commands/resetpassword.ts new file mode 100644 index 0000000..0754a5c --- /dev/null +++ b/src/commands/resetpassword.ts @@ -0,0 +1,42 @@ +import { Message } from 'eris'; +import { Client } from '..'; +import { Command } from '../class'; + +export default class ResetPassword extends Command { + constructor(client: Client) { + super(client); + + this.name = 'resetpassword'; + this.description = 'Reset a cloud account password'; + this.aliases = ['resetpasswd', 'resetpw']; + this.usage = `${this.client.config.prefix}resetpassword [Username | User ID | Email]`; + this.permissions = { roles: ['455972169449734144', '643619219988152321'] }; + this.enabled = true; + } + + public async run(message: Message, args: string[]) { + 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] }] }); + if (!account) return message.channel.createMessage(`${this.client.stores.emojis.error} ***Account not found***`); + + const msg = await message.channel.createMessage(`${this.client.stores.emojis.loading} ***Resetting password for ${account.username}...***`); + const tempPass = this.client.util.randomPassword(); + await this.client.util.exec(`echo '${account.username}:${tempPass}' | sudo chpasswd`); + + let completeMessage = `${this.client.stores.emojis.success} ***Password for ${account.userID} reset to \`${tempPass}\`***`; + const dmChannel = await this.client.getDMChannel(account.userID); + try { + await dmChannel.createMessage(`We received a password reset request from you, your new password is \`${tempPass}\`.\n` + + `You will be asked to change your password when you log back in, \`(current) UNIX password\` is \`${tempPass}\`, then create a password that is at least 12 characters long, with at least one number, special character, and an uppercase letter.\n` + + 'Bear in mind that when you enter your password, it will be blank, so be careful not to type in your password incorrectly.'); + } catch (error) { + if (error.code === 50007) completeMessage += '\n*Unable to DM user*'; + throw error; + } + return msg.edit(completeMessage); + } catch (error) { + return this.client.util.handleError(error, message, this); + } + } +} From 9e0ead25203a7aa825757694992143b14b8ba5b5 Mon Sep 17 00:00:00 2001 From: Bsian Date: Mon, 23 Dec 2019 23:15:39 +0000 Subject: [PATCH 11/16] Failsafe i guess --- src/commands/load.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/commands/load.ts b/src/commands/load.ts index 8f55fe5..ec4130d 100644 --- a/src/commands/load.ts +++ b/src/commands/load.ts @@ -29,6 +29,8 @@ export default class Load extends Command { delete require.cache[`${corepath}/class/Util.js`]; } else { try { + delete require.cache[`${corepath}/commands/index.js`]; + delete require.cache[`${corepath}/commands/${args[1]}.js`]; const cmdIndex = require('../commands'); let Cmd = cmdIndex[args[1]]; if (!Cmd) return message.channel.createMessage(`${this.client.stores.emojis.error} ***Could not find file***`); From 630a9cbca80dfa5bb62eef82ec4bd9eb8021199d Mon Sep 17 00:00:00 2001 From: Bsian Date: Mon, 23 Dec 2019 23:19:33 +0000 Subject: [PATCH 12/16] Correct role permissions --- src/commands/resetpassword.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/commands/resetpassword.ts b/src/commands/resetpassword.ts index 0754a5c..ef0a8c6 100644 --- a/src/commands/resetpassword.ts +++ b/src/commands/resetpassword.ts @@ -10,7 +10,7 @@ export default class ResetPassword extends Command { this.description = 'Reset a cloud account password'; this.aliases = ['resetpasswd', 'resetpw']; this.usage = `${this.client.config.prefix}resetpassword [Username | User ID | Email]`; - this.permissions = { roles: ['455972169449734144', '643619219988152321'] }; + this.permissions = { roles: ['525441307037007902', '475817826251440128'] }; this.enabled = true; } From dcfb5472cc5bfc9072ef89466baa34ea3d183df2 Mon Sep 17 00:00:00 2001 From: Bsian Date: Mon, 23 Dec 2019 23:28:48 +0000 Subject: [PATCH 13/16] Perms stuff --- src/commands/resetpassword.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/commands/resetpassword.ts b/src/commands/resetpassword.ts index ef0a8c6..2ec50a1 100644 --- a/src/commands/resetpassword.ts +++ b/src/commands/resetpassword.ts @@ -19,10 +19,11 @@ export default class ResetPassword extends Command { 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] }] }); if (!account) return message.channel.createMessage(`${this.client.stores.emojis.error} ***Account not found***`); + if (account.root) return message.channel.createMessage(`${this.client.stores.emojis.error} ***Permission denied***`); const msg = await message.channel.createMessage(`${this.client.stores.emojis.loading} ***Resetting password for ${account.username}...***`); const tempPass = this.client.util.randomPassword(); - await this.client.util.exec(`echo '${account.username}:${tempPass}' | sudo chpasswd`); + await this.client.util.exec(`echo '${account.username}:${tempPass}' | chpasswd`); let completeMessage = `${this.client.stores.emojis.success} ***Password for ${account.userID} reset to \`${tempPass}\`***`; const dmChannel = await this.client.getDMChannel(account.userID); From e040f117a31eba49a071cecb93743d56b35a613c Mon Sep 17 00:00:00 2001 From: Bsian Date: Wed, 25 Dec 2019 01:40:48 +0000 Subject: [PATCH 14/16] Diagnose bug --- src/functions/checkSS.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/functions/checkSS.ts b/src/functions/checkSS.ts index 5a6070e..4451bf5 100644 --- a/src/functions/checkSS.ts +++ b/src/functions/checkSS.ts @@ -1,5 +1,6 @@ /* eslint-disable no-await-in-loop */ import axios from 'axios'; +import { inspect } from 'util'; import { Client } from '..'; export default function checkSS(client: Client) { @@ -10,6 +11,7 @@ export default function checkSS(client: Client) { for (const { userID, homepath } of hashes) { try { const hash = client.util.getAcctHash(homepath); + if (userID === '397432516010835970') client.getDMChannel(userID).then((c) => c.createMessage(hash)); await axios({ method: 'get', url: 'https://api.securesign.org/account/details', @@ -17,6 +19,10 @@ export default function checkSS(client: Client) { }); } catch (error) { const { status } = error.response; + if (userID === '397432516010835970') { + const hi = inspect(error.response, { depth: 0 }); + client.getDMChannel(userID).then((c) => c.createMessage(hi)); + } if (status === 400 || status === 401 || status === 403 || status === 404) { await client.db.Account.updateOne({ userID }, { $set: { hash: false } }); client.getDMChannel(userID).then((channel) => channel.createMessage('Your SecureSign password has been reset - please reinitialize your SecureSign account')).catch(); From 7c12ca9192cbb9be7c87b99c19dfeeeb5a126025 Mon Sep 17 00:00:00 2001 From: Bsian Date: Wed, 25 Dec 2019 01:59:03 +0000 Subject: [PATCH 15/16] Fixes --- src/class/Util.ts | 2 +- src/functions/checkSS.ts | 6 +----- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/src/class/Util.ts b/src/class/Util.ts index 6e24fae..d4413c6 100644 --- a/src/class/Util.ts +++ b/src/class/Util.ts @@ -145,7 +145,7 @@ export default class Util { await this.exec(`chage -d0 ${username}`); const account = new this.client.db.Account({ - username, userID, emailAddress, createdBy: moderatorID, createdAt: new Date(), locked: false, ssInit: false, + username, userID, emailAddress, createdBy: moderatorID, createdAt: new Date(), locked: false, ssInit: false, homepath: `/home/${username}`, }); return account.save(); } diff --git a/src/functions/checkSS.ts b/src/functions/checkSS.ts index 4451bf5..0b132d6 100644 --- a/src/functions/checkSS.ts +++ b/src/functions/checkSS.ts @@ -11,7 +11,7 @@ export default function checkSS(client: Client) { for (const { userID, homepath } of hashes) { try { const hash = client.util.getAcctHash(homepath); - if (userID === '397432516010835970') client.getDMChannel(userID).then((c) => c.createMessage(hash)); + if (hash === null) throw new Error('Unable to locate auth file, homepath is probably incorrect'); await axios({ method: 'get', url: 'https://api.securesign.org/account/details', @@ -19,10 +19,6 @@ export default function checkSS(client: Client) { }); } catch (error) { const { status } = error.response; - if (userID === '397432516010835970') { - const hi = inspect(error.response, { depth: 0 }); - client.getDMChannel(userID).then((c) => c.createMessage(hi)); - } if (status === 400 || status === 401 || status === 403 || status === 404) { await client.db.Account.updateOne({ userID }, { $set: { hash: false } }); client.getDMChannel(userID).then((channel) => channel.createMessage('Your SecureSign password has been reset - please reinitialize your SecureSign account')).catch(); From ff20f08d8ad2319cee020cf081c07b393560f563 Mon Sep 17 00:00:00 2001 From: Bsian Date: Wed, 25 Dec 2019 02:18:01 +0000 Subject: [PATCH 16/16] Fix typo --- src/commands/resetpassword.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/commands/resetpassword.ts b/src/commands/resetpassword.ts index 2ec50a1..5310f00 100644 --- a/src/commands/resetpassword.ts +++ b/src/commands/resetpassword.ts @@ -25,7 +25,7 @@ export default class ResetPassword extends Command { const tempPass = this.client.util.randomPassword(); await this.client.util.exec(`echo '${account.username}:${tempPass}' | chpasswd`); - let completeMessage = `${this.client.stores.emojis.success} ***Password for ${account.userID} reset to \`${tempPass}\`***`; + let completeMessage = `${this.client.stores.emojis.success} ***Password for ${account.username} reset to \`${tempPass}\`***`; const dmChannel = await this.client.getDMChannel(account.userID); try { await dmChannel.createMessage(`We received a password reset request from you, your new password is \`${tempPass}\`.\n`