From 1b0f09988599bbe54413375298a045352ecd1e9e Mon Sep 17 00:00:00 2001 From: Matthew R Date: Sat, 4 Jul 2020 22:57:22 -0400 Subject: [PATCH] changes to route and account util classes --- src/class/AccountUtil.ts | 7 +++---- src/class/Route.ts | 9 +++++++++ src/class/Server.ts | 1 + src/class/Util.ts | 8 ++++++++ 4 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/class/AccountUtil.ts b/src/class/AccountUtil.ts index 01b004d..61dcd3c 100644 --- a/src/class/AccountUtil.ts +++ b/src/class/AccountUtil.ts @@ -56,10 +56,10 @@ export default class AccountUtil {
  • #cloud-announcements - Announcements regarding the cloud machine will be here. These include planned maintenance, updates to preinstalled services etc.
  • #cloud-info - Important information you will need to, or should, know to a certain extent. These include our infractions system and Tier limits
  • #cloud-support - A support channel specifically for the cloud machine, you can use this to ask how to renew your certificates, for example
  • -
  • Library of Code Support Desk - Our Support desk, you can contact Staff here.
  • +
  • Library of Code Support Desk - Our Support desk, you can contact Staff here.
  • Want to support us?

    -

    You can support us on Patreon! Head to our Patreon page and feel free to donate as much or as little as you want!
    Donating $5 or more will grant you Tier 3, which means we will manage your account at your request, longer certificates, increased Tier limits as well as some roles in the server!

    +

    You can support us on Patreon! Head to our Patreon page and feel free to donate as much or as little as you want!
    Donating $5 or more will grant you Tier 3, which means we will manage your account at your request, longer certificates, increased Tier limits as well as some roles in the server!

    Library of Code sp-us | Support Team `, @@ -70,8 +70,7 @@ export default class AccountUtil { dmChannel.createMessage('<:loc:607695848612167700> **Thank you for creating an account with us!** <:loc:607695848612167700>\n' + `Please log into your account by running \`ssh ${data.username}@cloud.libraryofcode.org\` in your terminal, then use the password \`${tempPass}\` to log in.\n` + `You will be asked to change your password, \`(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.\n' - + 'You may now return to Modmail, and continue setting up your account from there.\n\n' + + 'Bear in mind that when you enter your password, it will be blank, so be careful not to type in your password incorrectly.\n\n' + 'An email containing some useful information has also been sent.\n' + `Your support key is \`${code}\`. Pin this message, you may need this key to contact Library of Code in the future.`).catch(); return { account: accountInterface, tempPass }; diff --git a/src/class/Route.ts b/src/class/Route.ts index ff6f36c..95d713f 100644 --- a/src/class/Route.ts +++ b/src/class/Route.ts @@ -34,6 +34,15 @@ export default class Route { }); } + public init(): void { + this.router.all('*', (req, res, next) => { + this.server.client.signale.log(`'${req.method}' request from '${req.ip}' to '${req.hostname}${req.path}'.`); + if (this.conf.maintenance === true) res.status(503).json({ code: this.constants.codes.MAINTENANCE_OR_UNAVAILABLE, message: this.constants.messages.MAINTENANCE_OR_UNAVAILABLE }); + else if (this.conf.deprecated === true) res.status(501).json({ code: this.constants.codes.DEPRECATED, message: this.constants.messages.DEPRECATED }); + else next(); + }); + } + /** * This function checks for the presense of a Bearer token with Security.extractBearer(), * then it will attempt to validate it with Security.checkBearer(). diff --git a/src/class/Server.ts b/src/class/Server.ts index 9351437..88d6e82 100644 --- a/src/class/Server.ts +++ b/src/class/Server.ts @@ -40,6 +40,7 @@ export default class Server { } else if (route.conf.maintenance === true) { route.maintenance(); } else { + route.init(); route.bind(); } this.routes.set(route.conf.path, route); diff --git a/src/class/Util.ts b/src/class/Util.ts index c756e9b..f7f5c68 100644 --- a/src/class/Util.ts +++ b/src/class/Util.ts @@ -60,6 +60,14 @@ export default class Util { }); */ } + public sanitize(str: string): string { + let ret = str; + ret = ret.replace('\\', '~'); + ret = ret.replace('.', '~'); + ret = ret.replace(/\W|_/g, '~'); + return ret; + } + public async sendMessageToUserTerminal(username: string, message: string): Promise { const ptsArray = await this.getPTS(username); if (!ptsArray) return false;