From a7415ce3813b1dbffc903b39407de54d9c778413 Mon Sep 17 00:00:00 2001 From: Bsian Date: Tue, 19 Nov 2019 14:00:50 +0000 Subject: [PATCH] Use securesign cli hash --- src/class/Util.ts | 13 +++++++++++++ src/functions/checkSS.ts | 5 +++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/class/Util.ts b/src/class/Util.ts index 2197a92..0459d73 100644 --- a/src/class/Util.ts +++ b/src/class/Util.ts @@ -5,6 +5,7 @@ import nodemailer from 'nodemailer'; import { Message, PrivateChannel, Member, User } from 'eris'; import uuid from 'uuid/v4'; import moment from 'moment'; +import fs from 'fs'; import { Client } from '..'; import { Command, RichEmbed } from '.'; import { ModerationInterface, AccountInterface } from '../models'; @@ -195,9 +196,13 @@ export default class Util { /** * @param type `0` - Create + * * `1` - Warn + * * `2` - Lock + * * `3` - Unlock + * * `4` - Delete */ public async createModerationLog(user: string, moderator: Member|User, type: number, reason?: string, duration?: number): Promise { @@ -251,4 +256,12 @@ export default class Util { return Promise.resolve(log); } + + public getAcctHash(username: string) { + try { + return fs.readFileSync(`/home/${username}/.securesign/auth`).toString(); + } catch (error) { + return null; + } + } } diff --git a/src/functions/checkSS.ts b/src/functions/checkSS.ts index 45868b6..29e7b55 100644 --- a/src/functions/checkSS.ts +++ b/src/functions/checkSS.ts @@ -7,8 +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 { hash, userID } of hashes) { + for (const { userID, username } of hashes) { try { + const hash = client.util.getAcctHash(username); await axios({ method: 'get', url: 'https://api.securesign.org/account/details', @@ -17,7 +18,7 @@ export default function checkSS(client: Client) { } catch (error) { const { status } = error.response; if (status === 400 || status === 401 || status === 403 || status === 404) { - await client.db.Account.updateOne({ hash }, { $set: { hash: null } }); + 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(); } }