import axios from 'axios'; import moment from 'moment'; import { randomBytes } from 'crypto'; import { AccountInterface } from '../models'; import { Client } from '..'; export default class AccountUtil { public client: Client; constructor(client: Client) { this.client = client; } /** * This function creates a new user account. * @param data Data/information on the new user account to create. * @param data.userI The Discord ID for the user. * @param data.username The username for the new user, this will also be their username on the machine. * @param data.emailAddress The user's email address. * @param moderator The Discord user ID for the Staff member that created the account. */ public async createAccount(data: { userID: string, username: string, emailAddress: string }, moderator: string): Promise<{ account: AccountInterface, tempPass: string }> { const moderatorMember = await (await this.client.guilds.fetch('446067825673633794')).members.fetch(moderator); const tempPass = this.client.util.randomPassword(); let passHash = await this.client.util.createHash(tempPass); passHash = passHash.replace(/[$]/g, '\\$').replace('\n', ''); const acctName = (await this.client.users.fetch(data.userID)).username.replace(/[!@#$%^&*(),.?":{}|<>]/g, '-').replace(/\s/g, '-'); const etcPasswd = `${acctName},${data.userID},,`; const code = randomBytes(3).toString('hex').toUpperCase(); const accountInterface = await this.client.util.createAccount(passHash, etcPasswd, data.username, data.userID, data.emailAddress, moderator, code); await this.client.util.createModerationLog(data.userID, moderatorMember.user, 0); const req = await axios.get('https://loc.sh/int/directory'); const find = req.data.find((mem) => mem.userID === moderator); this.client.util.transport.sendMail({ to: data.emailAddress, from: 'Library of Code sp-us | Cloud Services ', replyTo: 'cloud-help@libraryofcode.org', subject: 'Approval for CS Account', html: `

Library of Code | Cloud Services

Congratulations, your CS Account application has been approved. Welcome! Please see below for some details regarding your account and our services

Username: ${data.username}

Support Key: ${code} || You may be asked for this support key when contacting Library of Code, please keep the code in a safe area.

SSH Login:

ssh ${data.username}@cloud.libraryofcode.org

Underwritten by: ${moderatorMember.user.username}, ${find.pn.join(', ')}

Useful information

How to log in:

  1. Open your desired terminal application - we recommend using Bash, but you can use your computer's default
  2. Type in your SSH Login as above
  3. When prompted, enter your password Please note that inputs will be blank, so be careful not to type in your password incorrectly

If you fail to authenticate yourself too many times, you will be IP banned and will fail to connect. If this is the case, feel free to DM Ramirez with your public IPv4 address.

Channels and Links

Want to support us?

You can support us by purchasing a Tier 3 subscription! this site for more information.

Library of Code sp-us | Support Team `, }); const guild = await this.client.guilds.fetch('446067825673633794'); const member = await guild.members.fetch(data.userID); member.roles.add('546457886440685578'); const user = await this.client.users.fetch(data.userID); user.send('<: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\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 }; } public async lock(username: string, moderatorID: string, data?: { reason?: string, time?: number}) { const account = await this.client.db.Account.findOne({ username }); if (!account) throw new Error('Account does not exist.'); if (account.locked) throw new Error('Account is already locked.'); if (account.username === 'matthew' || account.root) throw new Error('Permission denied.'); await this.client.util.exec(`lock ${account.username}`); await account.updateOne({ locked: true }); await this.client.util.createModerationLog(account.userID, await this.client.users.fetch(moderatorID), 2, data?.reason, data?.time); this.client.util.transport.sendMail({ to: account.emailAddress, from: 'Library of Code sp-us | Cloud Services ', replyTo: 'cloud-help@libraryofcode.org', subject: 'Your account has been locked', html: `

Library of Code | Cloud Services

Your Cloud Account has been locked until ${data?.time ? moment(data?.time).calendar() : 'indefinitely'} under the EULA.

Reason: ${data?.reason ? data.reason : 'none provided'}

Technician: ${moderatorID !== this.client.user.id ? ((await this.client.users.fetch(moderatorID)).username) : 'SYSTEM'}

Expiration: ${data?.time ? moment(data?.time).format('dddd, MMMM Do YYYY, h:mm:ss A') : 'N/A'}

Library of Code sp-us | Support Team `, }); } }