Compare commits

...

99 Commits

Author SHA1 Message Date
Matthew 309f080b37
fix auto tier 2024-01-08 20:43:29 -05:00
Matthew 64f67c9a18
fix auto tier 2024-01-08 20:35:11 -05:00
Matthew c283487b5a
fix auto tier 2024-01-08 20:34:30 -05:00
Matthew 9ecc9f1324
qol changes for Util.ts 2024-01-08 20:32:32 -05:00
Matthew 2a9492ccbb
prettify whois 2024-01-07 13:51:40 -05:00
Matthew 7337f77027
fix attempt x3 2024-01-07 13:45:25 -05:00
Matthew a2e9a87e69
fix attempt 2024-01-07 13:40:04 -05:00
Matthew e653484be4
update technician name formatting function 2024-01-07 13:29:57 -05:00
Matthew 276467519f
qol changes for Util.ts 2024-01-06 19:10:42 -05:00
Matthew 77e50b61c5
fix css in AccountUtil.ts (p2) 2024-01-06 19:08:18 -05:00
Matthew 60683688ce
fix css in AccountUtil.ts 2024-01-06 19:06:53 -05:00
Matthew 3d930792fe
various improvements to handling modlogs 2024-01-06 19:06:44 -05:00
Matthew 9d9485700a
fix dm issue with createAccount func 2024-01-06 19:03:02 -05:00
Matthew 88e2273f5f
fix dm issue with resetpassword.ts 2024-01-06 19:01:40 -05:00
Matthew f231cc4fdd
fix .join() in various commands 2023-11-14 17:58:50 -05:00
Matthew b6da450c94
fix .join() in notify 2023-10-31 18:48:39 -04:00
Matthew 81f58cab27
Merge remote-tracking branch 'origin/master' 2023-10-31 18:20:46 -04:00
Matthew a36b579a9c
try to fix issue with Util's .join() func 2023-10-31 18:19:55 -04:00
Matthew 9ce84fb89b Merge pull request 'add pax to sudoers' (#15) from pax/cloudservices:master into master
Reviewed-on: #15
2023-10-22 08:17:44 -04:00
Pax 1e73890594 add pax to sudoers 2023-10-21 20:04:25 +03:00
Matthew 84bdaae2d2
add subdomain check to selfserv 2023-06-30 07:54:12 -04:00
Matthew d7567ccb5a change tech full name 2023-03-09 18:36:49 -05:00
Matthew 87753431f8 update tsconfig 2023-03-09 18:36:35 -05:00
Matthew 45e5496f24 change from yarn to npm 2023-03-09 18:36:25 -05:00
Matthew c9b4fdd583 fix issue with subdomain creations 2023-03-09 13:41:42 -05:00
Matthew f91cc0221a
update calculation t3 staff benefit 2022-09-01 20:29:38 -04:00
Matthew 84a539c65a
fix bug with cwg_data 2022-07-16 03:01:39 -04:00
Matthew 5bf3425ee0
Add staff benefits policy and changes to t2 eds checks 2022-07-10 01:01:32 -04:00
Matthew 48e5579a8c
edit regex validation 2022-03-01 19:54:56 -05:00
Matthew 6958d4d6b1
fix issue 2022-03-01 15:17:56 -05:00
Matthew 33a9493a98
fix issue 2022-03-01 15:15:02 -05:00
Matthew c812a2fe02
fix issue 2022-03-01 15:13:25 -05:00
Matthew 1164034e55
mem fix 2022-03-01 15:06:05 -05:00
Matthew cf42db6cc7
fix 2022-03-01 15:02:18 -05:00
Matthew 436152ffef
fixes 2022-03-01 14:59:56 -05:00
Matthew d62e8846a4
typo fix and port check 2022-03-01 12:18:56 -05:00
Matthew b3f9abf692
add cwg selvserv 2022-03-01 11:55:11 -05:00
Matthew b9ce4ddce4
changes 2022-03-01 11:36:02 -05:00
Matthew 4211689f73
edit embed fields for cwg 2022-02-03 19:36:05 -05:00
Matthew 86fb5a7dee
Merge branch 'master' of gitlab.libraryofcode.org:engineering/cloudservices 2022-02-03 15:11:06 -05:00
Matthew 374dd04e0a
text changes 2022-02-03 15:10:55 -05:00
Hiroyuki 1b085c8740
fix: delete account message collector filter 2021-12-27 20:36:12 -04:00
Matthew a9a70080cb
warnings do not count against Community Report negatively 2021-12-10 17:14:49 -05:00
Matthew 8615d61815
fix 2021-12-09 21:55:15 -05:00
Matthew 2880dc4eb7
fixes and whatnot or whatever 2021-12-09 21:34:27 -05:00
Matthew ae272d7aee
Merge branch 'master' of gitlab.libraryofcode.org:engineering/cloudservices 2021-11-28 15:21:43 -05:00
Matthew 8e9b260481
symlink cloud certs instead of writing 2021-11-28 15:20:55 -05:00
Hiroyuki 46b83daf78
refactor: cwg_delete command level
Approved by Bsian, AD, FSEN, FSCR, Director of Engineering and NightRaven, AD, FSO, Head of Information Security
2021-10-13 16:18:41 -04:00
Matthew 7e20b362c3
fixes and whatnot 2021-10-12 00:35:36 -04:00
Matthew 3e1731ef89
fix 2021-10-11 21:11:19 -04:00
Matthew 361fa4a5cc
fixes 2021-10-11 21:05:12 -04:00
Matthew 5ca005cf90
changes 2021-10-11 20:57:44 -04:00
Hiroyuki a075bfdc6e
fix: usermod lock logic 2021-09-16 19:55:28 -04:00
Hiroyuki 785baaa902
fix: usermod bug fixes 2021-09-14 14:42:22 -04:00
Hiroyuki 2bad7fb05a
feat: convert MD to HTML for emails 2021-09-13 12:47:54 -04:00
Hiroyuki 578aa0db8c
fix(usermod): misc 2021-09-12 23:06:02 -04:00
Hiroyuki 669d9d0fef
feat: update modlogs usernames 2021-09-12 22:17:42 -04:00
Hiroyuki e826e464c9
fix: modlogs command pagination embed
closes #8
2021-09-12 22:15:43 -04:00
Hiroyuki 69fe6256fa
fix: usermod account unlock logic 2021-09-12 22:07:12 -04:00
Hiroyuki d4c740206d
refactor: usermod account lock logic 2021-09-12 21:52:03 -04:00
Hiroyuki ec343d541c
fix: notify embed Technician field 2021-09-12 21:44:31 -04:00
Hiroyuki 502321ee2e Merge branch 'master' into 'master'
hopefully fix bug mentioned in #8

See merge request engineering/cloudservices!6
2021-09-13 01:42:56 +00:00
Hiroyuki 248bd88469
refactor: notify embed style 2021-09-12 21:40:02 -04:00
Hiroyuki bef1f3e59f
fix: usermod command logistics 2021-09-12 21:35:35 -04:00
Hiroyuki 7fd95aa586
fix: detailed help command permissions 2021-09-12 21:31:31 -04:00
eirk cb550aa578 hopefully fix bug mentioned in #8 2021-09-12 12:31:22 +00:00
Hiroyuki f4f5fdf381
fix: help command permissions parsing 2021-09-11 16:46:27 -04:00
Hiroyuki 12aab5aa56
fix: argument parsing 2021-09-11 16:42:44 -04:00
Hiroyuki 64a68e51a3
feat: usermod command 2021-09-11 16:38:35 -04:00
Hiroyuki b40b39ca12
Merge branch 'eirk/cloudservices-master' 2021-09-10 19:05:44 -04:00
eirk 3cfefda5ce useless awaits 2021-08-23 13:23:20 -04:00
eirk 87b320f2fb fix pagination 2021-08-22 21:49:00 -04:00
eirk 4c2690d7fd update gitignore (again) 2021-08-22 21:28:23 -04:00
eirk 9bac31de61 update .gitignore 2021-08-22 21:23:08 -04:00
eirk 2870b4a4ac update package.json 2021-08-22 21:19:49 -04:00
eirk 9b412ae7df one liner 2021-08-10 17:18:35 -04:00
eirk 7629d3284b add guild integrations intent back 2021-08-10 17:15:08 -04:00
eirk 11b4828dc1 use cache when possible 2021-08-10 17:14:02 -04:00
eirk 9ada0b1d4e changes requested by matthew 2021-08-10 15:27:07 -04:00
Matthew f10a67ff58
disable ci 2021-08-09 14:43:47 -04:00
Matthew 0da741f453
logging 2021-08-09 14:42:37 -04:00
Matthew cc4cd3d06c
logging 2021-08-09 14:41:20 -04:00
Matthew 760337a181
logging 2021-08-09 14:38:21 -04:00
Matthew 39d8760f5f
logging 2021-08-09 14:37:45 -04:00
Matthew 406ba69637
logging 2021-08-09 14:36:39 -04:00
Matthew 96d47a040c
logging 2021-08-09 14:30:51 -04:00
Matthew 60f8c78180
logging 2021-08-09 14:29:09 -04:00
Matthew fb3ec73898
logging 2021-08-09 14:25:53 -04:00
Matthew f07d155d96
logging 2021-08-09 14:18:40 -04:00
Matthew 647e3be766
logging 2021-08-09 14:16:36 -04:00
eirk aebfb7a574 use ID instead of Id 2021-08-08 19:41:32 -07:00
eirk ebbbc67943 remove .vscode/ 2021-08-07 12:10:21 -04:00
eirk 2e84994610 fix uuid (again) and helmet 2021-08-06 17:21:16 -04:00
eirk 1fb9bc2628 fix uuid 2021-08-06 17:19:39 -04:00
eirk f113fabc30 switch from eris to discord.js, formatting 2021-08-06 17:11:27 -04:00
Hiroyuki 08be688daa Merge branch 'TheGreench-master-patch-00039' into 'master'
Fix error message, missing the *.cloud*

See merge request engineering/cloudservices!4
2021-07-31 21:09:24 +00:00
TheGreench 9cc21aba44 Fix error message, missing the *.cloud* 2021-07-31 19:52:41 +00:00
Hiroyuki 8c9f70df10
refactor(tsc): potentially fix build 2021-07-26 12:53:25 -04:00
Hiroyuki 0bf94819d5
fix(commands/modlogs): RichEmbed field length 2021-07-26 12:47:07 -04:00
83 changed files with 1626 additions and 4177 deletions

View File

@ -39,6 +39,8 @@
"import/prefer-default-export": "off",
"no-useless-constructor": "off",
"@typescript-eslint/no-useless-constructor": 2,
"import/extensions": "off"
"import/extensions": "off",
"consistent-return": "off",
"no-continue": "off"
}
}

61
.gitignore vendored
View File

@ -1,10 +1,57 @@
node_modules
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
# Runtime data
pids
*.pid
*.seed
*.pid.lock
# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release
# Dependency directories
node_modules/
jspm_packages/
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# dotenv environment variables file
.env
.env.test
# parcel-bundler cache (https://parceljs.org/)
.cache
# Serverless directories
.serverless/
# macOS files
.DS_Store
*.DS_Store
# Database files
*.sqlite
# IDE and text editor configuration files
.vscode/
.idea/
# other files
dist/
src/config.json
package-lock.json
htmlEmail_templates
yarn-error.log
src/keys.json
dist
htmlEmail_templates
securesign_genrsa.ts
.idea
.vscode

View File

@ -7,7 +7,7 @@ typescript_build:
script:
- cp ../config.json ./src/config.json
- yarn install --ignore-engines
- tsc -p ./tsconfig.json
- npx tsc -p ./tsconfig.json
lint:
stage: test

10
.vscode/settings.json vendored
View File

@ -1,10 +0,0 @@
{
"eslint.enable": true,
"eslint.validate": [
{
"language": "typescript",
"autoFix": true
}
],
"editor.tabSize": 2
}

View File

@ -1,7 +1,7 @@
{
"name": "cloudservices-rewrite",
"version": "1.2.0",
"description": "The official LOC Cloud Services system, this is a rewrite of the original version. ",
"version": "2.0",
"description": "The official LOC Cloud Services system, this is a rewrite the original version, using discord.js.",
"main": "dist/Client.js",
"scripts": {
"lint": "eslint ./ --ext ts --fix",
@ -12,40 +12,41 @@
"license": "AGPL-3.0-only",
"private": false,
"dependencies": {
"axios": "^0.19.0",
"axios": "^0.21.1",
"body-parser": "^1.19.0",
"eris": "bsian03/eris#dev",
"eris-pagination": "git+https://github.com/bsian03/eris-pagination#c0f77b118e98309e89e6522ef545f9d121601f21",
"cron": "^1.8.2",
"discord.js": "^13.0.0",
"express": "^4.17.1",
"fs-extra": "^8.1.0",
"helmet": "^3.21.2",
"ioredis": "^4.14.1",
"fs-extra": "^10.0.0",
"hastebin-gen": "^2.0.5",
"helmet": "^4.6.0",
"ioredis": "^4.27.7",
"jsonwebtoken": "^8.5.1",
"moment": "^2.27.0",
"moment-precise-range-plugin": "^1.3.0",
"mongoose": "^5.7.4",
"nodemailer": "^6.3.1",
"moment": "^2.29.1",
"mongoose": "^5.13.5",
"nodemailer": "^6.6.3",
"showdown": "^1.9.1",
"signale": "^1.4.0",
"uuid": "^3.3.3",
"x509": "bsian03/node-x509"
"uuid": "^8.3.2"
},
"devDependencies": {
"@types/express": "^4.17.6",
"@types/express-serve-static-core": "^4.17.5",
"@types/fs-extra": "^8.0.0",
"@types/helmet": "^0.0.45",
"@types/ioredis": "^4.0.18",
"@types/jsonwebtoken": "^8.5.0",
"@types/mongoose": "^5.7.14",
"@types/nodemailer": "^6.2.1",
"@types/signale": "^1.2.1",
"@types/uuid": "^3.4.5",
"@typescript-eslint/eslint-plugin": "2.31.0",
"@typescript-eslint/parser": "2.31.0",
"eslint": "^6.5.1",
"eslint-config-airbnb-base": "^14.0.0",
"eslint-plugin-import": "^2.18.2",
"madge": "^3.9.2",
"typescript": "^3.6.4"
"@types/cron": "^1.7.3",
"@types/express": "^4.17.13",
"@types/express-serve-static-core": "^4.17.24",
"@types/fs-extra": "^9.0.12",
"@types/ioredis": "^4.26.7",
"@types/jsonwebtoken": "^8.5.4",
"@types/node": "^16.4.13",
"@types/nodemailer": "^6.4.4",
"@types/showdown": "^1.9.4",
"@types/signale": "^1.4.2",
"@types/uuid": "^8.3.1",
"@typescript-eslint/eslint-plugin": "^4.29.0",
"@typescript-eslint/parser": "^4.29.0",
"eslint": "^7.32.0",
"eslint-config-airbnb-base": "^14.2.1",
"eslint-plugin-import": "^2.23.4",
"madge": "^5.0.1",
"typescript": "^4.3.5"
}
}

View File

@ -1,8 +1,8 @@
import os from 'os';
import jwt from 'jsonwebtoken';
import { TextChannel } from 'eris';
import { TextChannel, MessageEmbed } from 'discord.js';
import { Server } from '..';
import { RichEmbed, Route } from '../../class';
import { Route } from '../../class';
export default class Root extends Route {
constructor(server: Server) {
@ -59,18 +59,18 @@ export default class Root extends Route {
const token = <any> jwt.verify(req.query.t.toString(), this.server.client.config.keyPair.privateKey);
const check = await this.server.storage.get<boolean>(req.query.t.toString());
if (check) return res.sendStatus(401);
const embed = new RichEmbed();
const embed = new MessageEmbed();
embed.setTitle('Referral Authorization');
embed.setDescription(req.query.t.toString());
embed.addField('Referred User', `${token.referredUserAndDiscrim} | ${token.referredUserID}`, true);
embed.addField('Referrer User', token.referrerUsername, true);
embed.addField('Referral Code', token.referralCode, true);
embed.setTimestamp();
embed.setFooter(this.server.client.user.username, this.server.client.user.avatarURL);
const channel = <TextChannel> this.server.client.guilds.get('446067825673633794').channels.get('580950455581147146');
embed.setFooter(this.server.client.user.username, this.server.client.user.avatarURL());
const channel = this.server.client.guilds.cache.get('446067825673633794').channels.cache.get('580950455581147146') as TextChannel;
res.sendStatus(200);
await this.server.storage.set(req.query.t.toString(), true);
return channel.createMessage({ content: `<@${token.staffUserID}>`, embed });
return channel.send({ content: `<@${token.staffUserID}>`, embeds: [embed] });
} catch {
return res.sendStatus(401);
}

View File

@ -1,7 +1,7 @@
/* eslint-disable no-continue */
import { TextChannel } from 'eris';
import { TextChannel, MessageEmbed, TextBasedChannel } from 'discord.js';
import { Server } from '..';
import { Route, RichEmbed } from '../../class';
import { Route } from '../../class';
export default class Webhook extends Route {
constructor(server: Server) {
@ -12,7 +12,7 @@ export default class Webhook extends Route {
this.router.post('/s1', async (req, res) => {
try {
if (req.headers.authorization !== this.server.security.keys.iv.toString('base64')) return res.status(401).json({ code: this.constants.codes.UNAUTHORIZED, message: this.constants.codes.UNAUTHORIZED });
const embed = new RichEmbed();
const embed = new MessageEmbed();
embed.setTitle('Service Request');
embed.setDescription(`https://staff.libraryofcode.org/browse/${req.body.key}\n${req.body.url}`);
embed.setColor('#FF00FF');
@ -20,10 +20,10 @@ export default class Webhook extends Route {
embed.addField('Reporter', req.body.reporter, true);
embed.addField('Status', req.body.status, true);
embed.addField('Summary', req.body.summary);
embed.setFooter(this.server.client.user.username, this.server.client.user.avatarURL);
embed.setFooter(this.server.client.user.username, this.server.client.user.avatarURL());
embed.setTimestamp();
const chan = <TextChannel> this.server.client.getChannel('780513128240382002');
chan.createMessage({ content: '<@&741797822940315650>', embed });
const channel = this.server.client.channels.cache.get('780513128240382002') as TextChannel;
channel.send({ content: '<@&741797822940315650>', embeds: [embed] });
return res.status(200).json({ code: this.constants.codes.SUCCESS, message: this.constants.codes.SUCCESS });
} catch (err) {
return this.handleError(err, res);
@ -47,17 +47,18 @@ export default class Webhook extends Route {
} else {
await account.updateOne({ $set: { tier: 3 } });
}
const embed = new RichEmbed();
const embed = new MessageEmbed();
embed.setTitle('Cloud Account | Tier Change');
embed.setColor('#0099ff');
embed.addField('User', `${account.username} | <@${account.userID}>`, true);
embed.addField('Technician', 'SYSTEM', true);
embed.addField('Old Tier -> New Tier', `${account.tier} -> 3`, true);
embed.setFooter(this.server.client.user.username, this.server.client.user.avatarURL);
embed.setFooter(this.server.client.user.username, this.server.client.user.avatarURL());
embed.setTimestamp();
await this.server.client.util.sendMessageToUserTerminal(account.username, 'A technician has changed your tier to 3').catch(() => { });
this.server.client.createMessage('580950455581147146', { embed });
this.server.client.getDMChannel(account.userID).then((channel) => channel.createMessage({ embed })).catch();
const channel = this.server.client.channels.cache.get('580950455581147146') as TextChannel;
channel.send({ embeds: [embed] });
this.server.client.users.cache.get(account.userID).send({ embeds: [embed] });
return res.sendStatus(200);
});
@ -74,17 +75,18 @@ export default class Webhook extends Route {
} else {
await account.updateOne({ $set: { tier: 1 } });
}
const embed = new RichEmbed();
const embed = new MessageEmbed();
embed.setTitle('Cloud Account | Tier Change');
embed.setColor('#0099ff');
embed.addField('User', `${account.username} | <@${account.userID}>`, true);
embed.addField('Technician', 'SYSTEM', true);
embed.addField('Old Tier -> New Tier', `${account.tier} -> 1`, true);
embed.setFooter(this.server.client.user.username, this.server.client.user.avatarURL);
embed.setFooter(this.server.client.user.username, this.server.client.user.avatarURL());
embed.setTimestamp();
await this.server.client.util.sendMessageToUserTerminal(account.username, 'A technician has changed your tier.').catch(() => { });
this.server.client.createMessage('580950455581147146', { embed });
this.server.client.getDMChannel(account.userID).then((channel) => channel.createMessage({ embed })).catch();
const ch = this.server.client.channels.cache.get('580950455581147146') as TextChannel;
ch.send({ embeds: [embed] });
this.server.client.users.cache.get(account.userID).send({ embeds: [embed] });
return res.sendStatus(200);
});
@ -105,17 +107,18 @@ export default class Webhook extends Route {
} else {
await account.updateOne({ $set: { tier: 2 } });
}
const embed = new RichEmbed();
const embed = new MessageEmbed();
embed.setTitle('Cloud Account | Tier Change');
embed.setColor('#0099ff');
embed.addField('User', `${account.username} | <@${account.userID}>`, true);
embed.addField('Technician', 'SYSTEM', true);
embed.addField('Old Tier -> New Tier', `${account.tier} -> 2`, true);
embed.setFooter(this.server.client.user.username, this.server.client.user.avatarURL);
embed.setFooter(this.server.client.user.username, this.server.client.user.avatarURL());
embed.setTimestamp();
await this.server.client.util.sendMessageToUserTerminal(account.username, 'A technician has changed your tier to 2').catch(() => { });
this.server.client.createMessage('580950455581147146', { embed });
this.server.client.getDMChannel(account.userID).then((channel) => channel.createMessage({ embed })).catch();
const ch = this.server.client.channels.cache.get('580950455581147146') as TextChannel;
ch.send({ embeds: [embed] });
this.server.client.users.cache.get(account.userID).send({ embeds: [embed] });
return res.sendStatus(200);
});
@ -132,17 +135,48 @@ export default class Webhook extends Route {
} else {
await account.updateOne({ $set: { tier: 1 } });
}
const embed = new RichEmbed();
const embed = new MessageEmbed();
embed.setTitle('Cloud Account | Tier Change');
embed.setColor('#0099ff');
embed.addField('User', `${account.username} | <@${account.userID}>`, true);
embed.addField('Technician', 'SYSTEM', true);
embed.addField('Old Tier -> New Tier', `${account.tier} -> 1`, true);
embed.setFooter(this.server.client.user.username, this.server.client.user.avatarURL);
embed.setFooter(this.server.client.user.username, this.server.client.user.avatarURL());
embed.setTimestamp();
await this.server.client.util.sendMessageToUserTerminal(account.username, 'A technician has changed your tier.').catch(() => { });
this.server.client.createMessage('580950455581147146', { embed });
this.server.client.getDMChannel(account.userID).then((channel) => channel.createMessage({ embed })).catch();
const ch = this.server.client.channels.cache.get('580950455581147146') as TextChannel;
ch.send({ embeds: [embed] });
this.server.client.users.cache.get(account.userID).send({ embeds: [embed] });
return res.sendStatus(200);
});
this.router.get('/set-tier', async (req, res) => {
if (req.query?.auth !== this.server.security.keys.internal.toString('hex')) return res.status(401).json({ code: this.constants.codes.UNAUTHORIZED, message: this.constants.messages.UNAUTHORIZED });
if (!req.query?.userID) return res.status(400).json({ code: this.constants.codes.CLIENT_ERROR });
if (Number(req.query.t.toString()) > 3 || Number(req.query.t.toString()) < 1) return res.status(400).json({ code: this.constants.codes.CLIENT_ERROR });
const account = await this.server.client.db.Account.findOne({ userID: req.query.userID.toString() });
if (!account) return res.sendStatus(404);
const tier = await this.server.client.db.Tier.findOne({ id: Number(req.query.t.toString()) });
if (account.ramLimitNotification !== -1) {
await account.updateOne({ $set: { tier: Number(req.query.t.toString()), ramLimitNotification: tier.resourceLimits.ram - 20 } });
} else {
await account.updateOne({ $set: { tier: Number(req.query.t.toString()) } });
}
const embed = new MessageEmbed();
embed.setTitle('Cloud Account | Tier Change');
embed.setColor('#0099ff');
embed.addField('User', `${account.username} | <@${account.userID}>`, true);
embed.addField('Technician', 'SYSTEM', true);
embed.addField('Old Tier -> New Tier', `${account.tier} -> ${Number(req.query.t.toString())}`, true);
embed.setFooter(this.server.client.user.username, this.server.client.user.avatarURL());
embed.setTimestamp();
await this.server.client.util.sendMessageToUserTerminal(account.username, 'A technician has changed your tier.').catch(() => { });
const ch = this.server.client.channels.cache.get('580950455581147146') as TextChannel;
ch.send({ embeds: [embed] });
this.server.client.users.cache.get(account.userID).send({ embeds: [embed] });
return res.sendStatus(200);
});

View File

@ -4,6 +4,8 @@ import { randomBytes } from 'crypto';
import { AccountInterface } from '../models';
import { Client } from '..';
export const LINUX_USERNAME_REGEX = /^[a-z][-a-z0-9]*$/;
export default class AccountUtil {
public client: Client;
@ -20,15 +22,15 @@ export default class AccountUtil {
* @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 = this.client.guilds.get('446067825673633794').members.get(moderator);
const moderatorMember = this.client.guilds.cache.get('446067825673633794').members.cache.get(moderator);
const tempPass = this.client.util.randomPassword();
let passHash = await this.client.util.createHash(tempPass); passHash = passHash.replace(/[$]/g, '\\$').replace('\n', '');
const acctName = this.client.users.get(data.userID).username.replace(/[!@#$%^&*(),.?":{}|<>]/g, '-').replace(/\s/g, '-');
const passHash = (await this.client.util.createHash(tempPass)).replace(/[$]/g, '\\$').replace('\n', '');
const acctName = this.client.users.cache.get(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, 0);
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);
@ -39,13 +41,13 @@ export default class AccountUtil {
subject: 'Approval for CS Account',
html: `
<body>
<style>* {font-family: 'Calibri';}</style>
<style>* {font-family: 'Calibri',sans-serif;}</style>
<h1>Library of Code | Cloud Services</h1>
<h2>Congratulations, your CS Account application has been approved. Welcome! Please see below for some details regarding your account and our services</h2>
<p><b>Username:</b> ${data.username}</p>
<p><b>Support Key:</b> ${code} || <i>You may be asked for this support key when contacting Library of Code, please keep the code in a safe area.</i></p>
<p><b>SSH Login:</b> <pre><code style="font-family: Courier;">ssh ${data.username}@cloud.libraryofcode.org</code></pre>
<p><b>Underwritten by:</b> ${moderatorMember.user.username}, ${find.pn.join(', ')}
<p><b>SSH Login:</b> <pre><code style="font-family: Courier,sans-serif;">ssh ${data.username}@cloud.libraryofcode.org</code></pre>
<p><b>Underwritten by:</b> ${moderatorMember.user.username}${find.isManager ? ' [k]' : ' '}</p>
<h2>Useful information</h2>
<h3>How to log in:</h3>
<ol>
@ -70,15 +72,20 @@ export default class AccountUtil {
</body>
`,
});
this.client.guilds.get('446067825673633794').members.get(data.userID).addRole('546457886440685578');
const dmChannel = await this.client.getDMChannel(data.userID).catch();
dmChannel.createMessage('<:loc:607695848612167700> **Thank you for creating an account with us!** <:loc:607695848612167700>\n'
const guild = this.client.guilds.cache.get('446067825673633794');
const member = guild.members.cache.get(data.userID);
await member.roles.add('546457886440685578');
const user = this.client.users.cache.get(data.userID);
try {
await 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();
+ `Your support key is \`${code}\`. Pin this message, you may need this key to contact Library of Code in the future.`);
} catch (error) {
this.client.util.handleError(error);
}
return { account: accountInterface, tempPass };
}
@ -90,7 +97,7 @@ export default class AccountUtil {
await this.client.util.exec(`lock ${account.username}`);
await account.updateOne({ locked: true });
await this.client.util.createModerationLog(account.userID, this.client.users.get(moderatorID), 2, data?.reason, data?.time);
await this.client.util.createModerationLog(account.userID, this.client.users.cache.get(moderatorID), 2, data?.reason, data?.time);
this.client.util.transport.sendMail({
to: account.emailAddress,
@ -101,7 +108,7 @@ export default class AccountUtil {
<h1>Library of Code | Cloud Services</h1>
<p>Your Cloud Account has been locked until ${data?.time ? moment(data?.time).calendar() : 'indefinitely'} under the EULA.</p>
<p><b>Reason:</b> ${data?.reason ? data.reason : 'none provided'}</p>
<p><b>Technician:</b> ${moderatorID !== this.client.user.id ? this.client.users.get(moderatorID).username : 'SYSTEM'}</p>
<p><b>Technician:</b> ${moderatorID !== this.client.user.id ? (this.client.users.cache.get(moderatorID).username) : 'SYSTEM'}</p>
<p><b>Expiration:</b> ${data?.time ? moment(data?.time).format('dddd, MMMM Do YYYY, h:mm:ss A') : 'N/A'}</p>
<b><i>Library of Code sp-us | Support Team</i></b>

View File

@ -1,4 +1,4 @@
import Eris from 'eris';
import { Client as DiscordClient, Intents } from 'discord.js';
import Redis from 'ioredis';
import mongoose from 'mongoose';
import signale from 'signale';
@ -8,8 +8,7 @@ import { Account, AccountInterface, Moderation, ModerationInterface, Domain, Dom
import { emojis } from '../stores';
import { Command, CSCLI, Util, Collection, Server, Event } from '.';
export default class Client extends Eris.Client {
export default class Client extends DiscordClient {
public config: { 'token': string; 'cloudflare': string; 'prefix': string; 'emailPass': string; 'mongoURL': string; 'port': number; 'keyPair': { 'publicKey': string; 'privateKey': string; }; vendorKey: string; internalKey: string; };
public util: Util;
@ -35,7 +34,36 @@ export default class Client extends Eris.Client {
public buildError: boolean
constructor() {
super(config.token, { getAllUsers: true, restMode: true, defaultImageFormat: 'png', intents: ['guildBans', 'guildEmojis', 'guildInvites', 'guildMembers', 'guildMessageReactions', 'guildMessages', 'guildPresences', 'guildWebhooks', 'guilds', 'directMessages'] });
super({
shards: 'auto',
intents: [
Intents.FLAGS.GUILDS,
Intents.FLAGS.GUILD_MEMBERS,
Intents.FLAGS.GUILD_BANS,
Intents.FLAGS.GUILD_EMOJIS_AND_STICKERS,
Intents.FLAGS.GUILD_WEBHOOKS,
Intents.FLAGS.GUILD_INVITES,
Intents.FLAGS.GUILD_INTEGRATIONS,
Intents.FLAGS.GUILD_PRESENCES,
Intents.FLAGS.GUILD_MESSAGES,
Intents.FLAGS.GUILD_MESSAGE_REACTIONS,
Intents.FLAGS.DIRECT_MESSAGES,
],
partials: [
'USER',
'CHANNEL',
'GUILD_MEMBER',
'MESSAGE',
'REACTION',
],
allowedMentions: {
parse: [
'users',
'roles',
],
repliedUser: false,
},
});
process.title = 'cloudservices';
this.config = config;
@ -44,7 +72,9 @@ export default class Client extends Eris.Client {
this.events = new Collection<Event>();
this.functions = new Collection<Function>();
this.db = { Account, Domain, Moderation, Tier };
this.redis = new Redis();
this.redis = new Redis({
password: config.redis,
});
this.stores = { emojis };
this.signale = signale;
this.signale.config({
@ -74,7 +104,7 @@ export default class Client extends Eris.Client {
const funcRequire: Function = require(`${__dirname}/../functions/${func}`).default;
this.functions.set(func.split('.')[0], funcRequire);
} catch (error) {
this.signale.error(`Error occured loading ${func}`);
this.signale.error(`Error occurred loading ${func}`);
await this.util.handleError(error);
}
});
@ -83,7 +113,6 @@ export default class Client extends Eris.Client {
public loadCommand(CommandFile: any) {
// eslint-disable-next-line no-useless-catch
try {
// eslint-disable-next-line
const command: Command = new CommandFile(this);
if (command.subcmds.length) {
command.subcmds.forEach((C) => {
@ -126,19 +155,17 @@ export default class Client extends Eris.Client {
public async init() {
await mongoose.connect(config.mongoURL, { useNewUrlParser: true, useUnifiedTopology: true });
await this.connect();
await this.login(config.token);
this.on('ready', () => {
this.signale.info(`Connected to Discord as ${this.user.username}#${this.user.discriminator}`);
});
const intervals = await fs.readdir(`${__dirname}/../intervals`);
intervals.forEach((interval) => {
// eslint-disable-next-line
if (interval === 'index.js') return;
require(`${__dirname}/../intervals/${interval}`).default(this);
this.signale.complete(`Loaded interval ${interval.split('.')[0]}`);
});
this.server = new Server(this, { port: this.config.port });
// eslint-disable-next-line no-new
const corepath = '/opt/CloudServices/dist';
const cmdFiles = await fs.readdir('/opt/CloudServices/dist/commands');

View File

@ -1,4 +1,4 @@
import { Message, TextableChannel } from 'eris';
import { Message, TextBasedChannels } from 'discord.js';
import { Client, Collection } from '.';
export default class Command {
@ -39,15 +39,15 @@ export default class Command {
this.permissions = {};
}
public success(channel: TextableChannel, txt: string) {
return channel.createMessage(`***${this.client.stores.emojis.success} ${txt}***`);
public success(channel: TextBasedChannels, txt: string) {
return channel.send(`***${this.client.stores.emojis.success} ${txt}***`);
}
public loading(channel: TextableChannel, txt: string) {
return channel.createMessage(`***${this.client.stores.emojis.loading} ${txt}***`);
public loading(channel: TextBasedChannels, txt: string) {
return channel.send(`***${this.client.stores.emojis.loading} ${txt}***`);
}
public error(channel: TextableChannel, txt: string) {
return channel.createMessage(`***${this.client.stores.emojis.error} ${txt}***`);
public error(channel: TextBasedChannels, txt: string) {
return channel.send(`***${this.client.stores.emojis.error} ${txt}***`);
}
}

View File

@ -29,7 +29,11 @@ export default class Context {
}
public send(v: string) {
this.socket.write(`${v.toString()}\n`);
this.socket.write(`${v.toString()}\n`, (err) => {
if (err) {
this.client.signale.error(`Error occurred while writing: ${err}`);
}
});
this.socket.destroy();
}
}

View File

@ -5,9 +5,8 @@ import { gzip, gzipSync, unzip } from 'zlib';
type JSONData = [{key: string, value: any}?];
/**
* Persistant local JSON-based storage.
* Persistent local JSON-based storage.
* - auto-locking system to prevent corrupted data
* - uses gzip compression to keep DB storage space utilization low
* @author Matthew <matthew@staff.libraryofcode.org>

View File

@ -0,0 +1,56 @@
import { Message, MessageEmbed, EmojiResolvable, User, MessageReaction } from 'discord.js';
export default async function PaginationEmbed(message: Message, pages: MessageEmbed[], options?: {leftArrow?: EmojiResolvable, rightArrow?: EmojiResolvable, timeout?: number }) {
// eslint-disable-next-line no-param-reassign
options = {
leftArrow: options?.leftArrow ?? '⬅️',
rightArrow: options?.rightArrow ?? '➡️',
timeout: options?.timeout ?? 120000,
};
let pageNumber: number = 0;
const paginationMessage = await message.channel.send({ content: `Page ${pageNumber + 1} of ${pages.length}`, embeds: [pages[pageNumber]] });
await paginationMessage.react(options.leftArrow);
await paginationMessage.react(options.rightArrow);
const filter = (reaction: MessageReaction, user: User) => {
if ([options.leftArrow, options.rightArrow].includes(reaction.emoji.name)
&& !user.bot
&& user.id === message.author.id) {
return true;
}
return false;
};
const reactionCollector = paginationMessage.createReactionCollector({
filter,
time: options.timeout,
dispose: true,
});
reactionCollector.on('collect', (reaction, user) => {
reaction.users.remove(user);
if (reaction.emoji.name === options.leftArrow) {
if (pageNumber > 0) {
pageNumber -= 1;
} else {
pageNumber = pages.length - 1;
}
} else if (reaction.emoji.name === options.rightArrow) {
if (pageNumber + 1 < pages.length) {
pageNumber += 1;
} else {
pageNumber = 0;
}
}
paginationMessage.edit({ content: `Page ${pageNumber + 1} / ${pages.length}`, embeds: [pages[pageNumber]] });
});
reactionCollector.on('end', () => {
if (!paginationMessage.deleted) {
paginationMessage.reactions.removeAll();
}
});
return paginationMessage;
}

View File

@ -104,7 +104,7 @@ export default class Report {
* @param pin The last 4 digits of the member's PIN number.
* @param reason A reason for the hard inquiry.
* ```ts
* Report.hard('253600545972027394', 1102, 'Verification and Elibility for Personal Account');
* Report.hard('253600545972027394', 1102, 'Verification and Eligibility for Personal Account');
* ```
*/
public static async hard(userID: string, pin: number, reason: string, auth: string): Promise<HardReport> {

View File

@ -1,176 +0,0 @@
/* eslint-disable no-param-reassign */
export default class RichEmbed {
title?: string
type?: string
description?: string
url?: string
timestamp?: Date
color?: number
footer?: { text: string, icon_url?: string, proxy_icon_url?: string}
image?: { url: string, proxy_url?: string, height?: number, width?: number }
thumbnail?: { url?: string, proxy_url?: string, height?: number, width?: number }
video?: { url: string, height?: number, width?: number }
provider?: { name: string, url?: string}
author?: { name: string, url?: string, proxy_icon_url?: string, icon_url?: string}
fields?: {name: string, value: string, inline?: boolean}[]
constructor(data: {
title?: string, type?: string, description?: string, url?: string, timestamp?: Date, color?: number, fields?: {name: string, value: string, inline?: boolean}[]
footer?: { text: string, icon_url?: string, proxy_icon_url?: string}, image?: { url: string, proxy_url?: string, height?: number, width?: number },
thumbnail?: { url: string, proxy_url?: string, height?: number, width?: number }, video?: { url: string, height?: number, width?: number },
provider?: { name: string, url?: string}, author?: { name: string, url?: string, proxy_icon_url?: string, icon_url?: string},
} = {}) {
/*
let types: {
title?: string, type?: string, description?: string, url?: string, timestamp?: Date, color?: number, fields?: {name: string, value: string, inline?: boolean}[]
footer?: { text: string, icon_url?: string, proxy_icon_url?: string}, image?: { url?: string, proxy_url?: string, height?: number, width?: number },
thumbnail?: { url?: string, proxy_url?: string, height?: number, width?: number }, video?: { url?: string, height?: number, width?: number },
provider?: { name?: string, url?: string}, author?: { name?: string, url?: string, proxy_icon_url?: string, icon_url?: string}
};
*/
this.title = data.title;
this.description = data.description;
this.url = data.url;
this.color = data.color;
this.author = data.author;
this.timestamp = data.timestamp;
this.fields = data.fields || [];
this.thumbnail = data.thumbnail;
this.image = data.image;
this.footer = data.footer;
}
/**
* Sets the title of this embed.
*/
setTitle(title: string) {
if (typeof title !== 'string') throw new TypeError('RichEmbed titles must be a string.');
if (title.length > 256) throw new RangeError('RichEmbed titles may not exceed 256 characters.');
this.title = title;
return this;
}
/**
* Sets the description of this embed.
*/
setDescription(description: string) {
if (typeof description !== 'string') throw new TypeError('RichEmbed descriptions must be a string.');
if (description.length > 2048) throw new RangeError('RichEmbed descriptions may not exceed 2048 characters.');
this.description = description;
return this;
}
/**
* Sets the URL of this embed.
*/
setURL(url: string) {
if (typeof url !== 'string') throw new TypeError('RichEmbed URLs must be a string.');
if (!url.startsWith('http://') || !url.startsWith('https://')) url = `https://${url}`;
this.url = url;
return this;
}
/**
* Sets the color of this embed.
*/
setColor(color: string | number) {
if (typeof color === 'string' || typeof color === 'number') {
if (typeof color === 'string') {
const regex = /[^a-f0-9]/gi;
color = color.replace(/#/g, '');
if (regex.test(color)) throw new RangeError('Hexadecimal colours must not contain characters other than 0-9 and a-f.');
color = parseInt(color, 16);
} else if (color < 0 || color > 16777215) throw new RangeError('Base 10 colours must not be less than 0 or greater than 16777215.');
this.color = color;
return this;
}
throw new TypeError('RichEmbed colours must be hexadecimal as string or number.');
}
/**
* Sets the author of this embed.
*/
setAuthor(name: string, icon_url?: string, url?: string) {
if (typeof name !== 'string') throw new TypeError('RichEmbed Author names must be a string.');
if (url && typeof url !== 'string') throw new TypeError('RichEmbed Author URLs must be a string.');
if (icon_url && typeof icon_url !== 'string') throw new TypeError('RichEmbed Author icons must be a string.');
this.author = { name, icon_url, url };
return this;
}
/**
* Sets the timestamp of this embed.
*/
setTimestamp(timestamp = new Date()) {
// eslint-disable-next-line no-restricted-globals
if (isNaN(timestamp.getTime())) throw new TypeError('Expecting ISO8601 (Date constructor)');
this.timestamp = timestamp;
return this;
}
/**
* Adds a field to the embed (max 25).
*/
addField(name: string, value: string, inline = false) {
if (typeof name !== 'string') throw new TypeError('RichEmbed Field names must be a string.');
if (typeof value !== 'string') throw new TypeError('RichEmbed Field values must be a string.');
if (typeof inline !== 'boolean') throw new TypeError('RichEmbed Field inlines must be a boolean.');
if (this.fields.length >= 25) throw new RangeError('RichEmbeds may not exceed 25 fields.');
if (name.length > 256) throw new RangeError('RichEmbed field names may not exceed 256 characters.');
if (!/\S/.test(name)) throw new RangeError('RichEmbed field names may not be empty.');
if (value.length > 1024) throw new RangeError('RichEmbed field values may not exceed 1024 characters.');
if (!/\S/.test(value)) throw new RangeError('RichEmbed field values may not be empty.');
this.fields.push({ name, value, inline });
return this;
}
/**
* Convenience function for `<RichEmbed>.addField('\u200B', '\u200B', inline)`.
*/
addBlankField(inline = false) {
return this.addField('\u200B', '\u200B', inline);
}
/**
* Set the thumbnail of this embed.
*/
setThumbnail(url: string) {
if (typeof url !== 'string') throw new TypeError('RichEmbed Thumbnail URLs must be a string.');
this.thumbnail = { url };
return this;
}
/**
* Set the image of this embed.
*/
setImage(url: string) {
if (typeof url !== 'string') throw new TypeError('RichEmbed Image URLs must be a string.');
if (!url.startsWith('http://') || !url.startsWith('https://')) url = `https://${url}`;
this.image = { url };
return this;
}
/**
* Sets the footer of this embed.
*/
setFooter(text: string, icon_url?: string) {
if (typeof text !== 'string') throw new TypeError('RichEmbed Footers must be a string.');
if (icon_url && typeof icon_url !== 'string') throw new TypeError('RichEmbed Footer icon URLs must be a string.');
if (text.length > 2048) throw new RangeError('RichEmbed footer text may not exceed 2048 characters.');
this.footer = { text, icon_url };
return this;
}
}

View File

@ -44,7 +44,7 @@ export default class Route {
}
/**
* This function checks for the presense of a Bearer token with Security.extractBearer(),
* This function checks for the presence of a Bearer token with Security.extractBearer(),
* then it will attempt to validate it with Security.checkBearer().
* If it can authenticate the request, it'll add a custom property on Request called
* `account`, which will hold an the bearer token's account owner. The account is of the

View File

@ -6,7 +6,6 @@ import fs from 'fs-extra';
import { Client, Collection, LocalStorage, Route } from '.';
import { Security } from '../api';
export default class Server {
public routes: Collection<Route>

View File

@ -1,16 +1,25 @@
/* eslint-disable import/no-unresolved */
/* eslint-disable no-await-in-loop */
/* eslint-disable no-param-reassign */
import axios from 'axios';
import { randomBytes } from 'crypto';
import childProcess from 'child_process';
import nodemailer from 'nodemailer';
import { Message, PrivateChannel, GroupChannel, Member, User } from 'eris';
import uuid from 'uuid/v4';
import { ColorResolvable, DMChannel, Message, MessageEmbed, TextChannel, User } from 'discord.js';
import { v4 as uuid } from 'uuid';
import moment from 'moment';
import fs from 'fs';
import hastebin from 'hastebin-gen';
import { getUserByUid } from '../functions';
import { AccountUtil, Client, Command, RichEmbed } from '.';
import { ModerationInterface, AccountInterface, Account } from '../models';
import { AccountUtil, Client, Command, PaginationEmbed } from '.';
import { AccountInterface, ModerationInterface } from '../models';
import { Certificate } from '../../types/x509';
enum TechnicianNameFormatOpt {
Full = 0,
Partial,
Basic
}
export default class Util {
public client: Client;
@ -43,7 +52,7 @@ export default class Util {
cmd.stdout.on('data', writeFunction);
cmd.stderr.on('data', writeFunction);
cmd.on('error', writeFunction);
cmd.once('close', (code, signal) => {
cmd.once('close', (code) => {
cmd.stdout.off('data', writeFunction);
cmd.stderr.off('data', writeFunction);
cmd.off('error', writeFunction);
@ -93,7 +102,6 @@ export default class Util {
return returnArray;
}
/**
* Resolves a command
* @param query Command input
@ -123,34 +131,37 @@ export default class Util {
}
}
public async handleError(error: Error, message?: Message, command?: Command): Promise<void> {
public async handleError(error: Error | any, message?: Message, command?: Command): Promise<void> {
try {
this.client.signale.error(error);
const info = { content: `\`\`\`js\n${error.stack}\n\`\`\``, embed: null };
if (message) {
const embed = new RichEmbed();
embed.setColor('FF0000');
embed.setAuthor(`Error caused by ${message.author.username}#${message.author.discriminator}`, message.author.avatarURL);
const embed = new MessageEmbed();
embed.setColor('#FF0000');
embed.setAuthor(`Error caused by ${message.author.username}#${message.author.discriminator}`, message.author.avatarURL());
embed.setTitle('Message content');
embed.setDescription(message.content);
embed.addField('User', `${message.author.mention} (\`${message.author.id}\`)`, true);
embed.addField('Channel', message.channel.mention, true);
embed.addField('User', `${message.author.toString()} (\`${message.author.id}\`)`, true);
embed.addField('Channel', `<#${message.channel.id}>`, true);
let guild: string;
if (message.channel instanceof PrivateChannel || message.channel instanceof GroupChannel) guild = '@me';
else guild = message.channel.guild.id;
if (message.channel instanceof DMChannel) guild = '@me';
else guild = message.guild.id;
embed.addField('Message link', `[Click here](https://discordapp.com/channels/${guild}/${message.channel.id}/${message.id})`, true);
embed.setTimestamp(new Date(message.timestamp));
embed.setTimestamp(new Date(message.createdTimestamp));
info.embed = embed;
}
await this.client.createMessage('595788220764127272', info);
const ch = this.client.channels.cache.get('595788220764127272') as TextChannel;
await ch.send(info);
const msg = message.content.slice(this.client.config.prefix.length).trim().split(/ +/g);
if (command) this.resolveCommand(msg).then((c) => { c.cmd.enabled = false; });
if (message) message.channel.createMessage(`***${this.client.stores.emojis.error} An unexpected error has occured - please contact a member of the Engineering Team.${command ? ' This command has been disabled.' : ''}***`);
if (message) message.channel.send(`***${this.client.stores.emojis.error} An unexpected error has occurred - please contact a member of the Engineering Team.${command ? ' This command has been disabled.' : ''}***`);
} catch (err) {
this.client.signale.error(err);
}
}
public createPaginationEmbed = PaginationEmbed;
public splitFields(fields: { name: string, value: string, inline?: boolean }[]): { name: string, value: string, inline?: boolean }[][] {
let index = 0;
const array: {name: string, value: string, inline?: boolean}[][] = [[]];
@ -178,18 +189,15 @@ export default class Util {
return arrayString;
}
public async createHash(password: string): Promise<string> {
const hashed = await this.exec(`mkpasswd -m sha-512 "${password}"`);
return hashed;
return this.exec(`mkpasswd -m sha-512 "${password}"`);
}
public isValidEmail(email: string): boolean {
const checkAt = email.indexOf('@');
if (checkAt < 1) return false;
const checkDomain = email.indexOf('.', checkAt + 2);
if (checkDomain < checkAt) return false;
return true;
return checkDomain >= checkAt;
}
public randomPassword(): string {
@ -217,13 +225,15 @@ export default class Util {
this.exec(`deluser ${username} --remove-home --backup-to /management/Archives && rm -rf -R ${account.homepath}`),
this.client.db.Account.deleteOne({ username }),
];
this.client.removeGuildMemberRole('446067825673633794', account.userID, '546457886440685578', 'Cloud Account Deleted').catch();
const guild = this.client.guilds.cache.get('446067825673633794');
const member = await guild.members.fetch(account.userID);
await member.roles.remove('546457886440685578', 'Cloud Account Deleted');
// @ts-ignore
await Promise.all(tasks);
}
public async messageCollector(message: Message, question: string, timeout: number, shouldDelete = false, choices: string[] = null, filter = (msg: Message): boolean|void => {}): Promise<Message> {
const msg = await message.channel.createMessage(question);
const msg = await message.channel.send(question);
return new Promise((res, rej) => {
const func = (Msg: Message) => {
if (filter(Msg) === false) return;
@ -250,7 +260,7 @@ export default class Util {
*
* `4` - Delete
*/
public async createModerationLog(user: string, moderator: Member|User, type: number, reason?: string, duration?: number): Promise<ModerationInterface> {
public async createModerationLog(user: string, moderator: User, type: number, reason?: string, duration?: number): Promise<ModerationInterface> {
const moderatorID = moderator.id;
const account = await this.client.db.Account.findOne({ $or: [{ username: user }, { userID: user }] });
if (!account) return Promise.reject(new Error(`Account ${user} not found`));
@ -270,44 +280,65 @@ export default class Util {
} else date = null;
}
const expiration = { date, processed };
const expiration: { date: Date; processed: boolean } = { date, processed };
logInput.expiration = expiration;
const log = new this.client.db.Moderation(logInput);
await log.save();
let embedTitle: string;
let color: string;
let color: ColorResolvable;
let archType: string;
switch (type) {
default: archType = 'Staff'; embedTitle = 'Cloud Account | Generic'; color = '0892e1'; break;
case 0: archType = 'Technician'; embedTitle = 'Cloud Account | Create'; color = '00ff00'; break;
case 1: archType = 'Technician'; embedTitle = 'Account Warning | Warn'; color = 'ffff00'; break;
case 2: archType = 'Technician'; embedTitle = 'Account Infraction | Lock'; color = 'ff6600'; break;
case 3: archType = 'Technician'; embedTitle = 'Account Reclaim | Unlock'; color = '0099ff'; break;
case 4: archType = 'Director'; embedTitle = 'Cloud Account | Delete'; color = 'ff0000'; break;
default: archType = 'Staff'; embedTitle = 'Cloud Account | Generic'; color = '#0892e1'; break;
case 0: archType = 'Technician'; embedTitle = 'Cloud Account | Create'; color = '#00ff00'; break;
case 1: archType = 'Technician'; embedTitle = 'Account Warning | Warn'; color = '#ffff00'; break;
case 2: archType = 'Technician'; embedTitle = 'Account Infraction | Lock'; color = '#ff6600'; break;
case 3: archType = 'Technician'; embedTitle = 'Account Infraction | Unlock'; color = '#0099ff'; break;
case 4: archType = 'Manager'; embedTitle = 'Cloud Account | Delete'; color = '#ff0000'; break;
}
const req = await axios.get('https://loc.sh/int/directory');
const find = req.data.find((mem) => mem.userID === moderator.id);
const embed = new RichEmbed()
const embed = new MessageEmbed()
.setTitle(embedTitle)
.setColor(color)
.addField('User', `${username} | <@${userID}>`, true)
.addField(archType, moderatorID === this.client.user.id ? 'SYSTEM' : `${moderator.username}, ${find.pn.join(', ')} (<@${moderatorID}>)`, true)
.setFooter(this.client.user.username, this.client.user.avatarURL)
.addField(archType, moderatorID === this.client.user.id ? 'SYSTEM' : `${moderator.username}${find.isManager ? ' [k] ' : ' '}(<@${moderatorID}>)`, true)
.setFooter(this.client.user.username, this.client.user.avatarURL())
.setTimestamp();
if (reason) embed.addField('Reason', reason || 'Not specified');
if (type === 2) embed.addField('Lock Expiration', `${date ? moment(date).format('dddd, MMMM Do YYYY, h:mm:ss A') : 'Indefinitely'}`);
this.client.createMessage('580950455581147146', { embed }); this.client.getDMChannel(userID).then((channel) => channel.createMessage({ embed })).catch();
const ch = this.client.channels.cache.get('580950455581147146') as TextChannel;
ch.send({ embeds: [embed] });
this.client.users.fetch(userID).then((channel) => channel.send({ embeds: [embed] })).catch();
return Promise.resolve(log);
}
public getAcctHash(userpath: string) {
try {
return fs.readFileSync(`${userpath}/.securesign/auth`).toString();
} catch (error) {
return null;
}
public async getTechnicianName(tech: User, format: TechnicianNameFormatOpt = TechnicianNameFormatOpt.Full) {
if (!tech) return 'SYSTEM (UT)';
if (tech.id === this.client.user.id) return 'SYSTEM (SELF)';
const req = await axios.get('https://loc.sh/int/directory');
const find = req.data.find((mem) => mem.userID === tech.id);
if (!find) return 'SYSTEM (UF)';
if (format === TechnicianNameFormatOpt.Full) {
return `${tech.username}${find.isManager ? ' [k]' : ''}${find.title ? ` (${find.title} / ${find.dept})` : ` (${find.dept})`} <<@${tech.id}>>`;
} else if (format === TechnicianNameFormatOpt.Partial) {
return `${tech.username}${find.isManager ? ' [k]' : ''}${find.title ? ` (${find.title})` : ` (${find.dept})`} <<@${tech.id}>>`;
}
return `${tech.username}${find.isManager ? ' [k]' : ''} <<@${tech.id}>>`;
}
public parseCertificate(pem: string) {
return axios.post<Certificate>('https://certapi.libraryofcode.org/parse', pem)
.then((response) => response.data);
}
public upload(text: string, extension = 'txt') {
return hastebin(text, {
url: 'https://snippets.cloud.libraryofcode.org',
extension,
});
}
}

View File

@ -8,8 +8,8 @@ export { default as Event } from './Event';
export { default as Handler } from './Handler';
export { default as LocalStorage } from './LocalStorage';
export { default as Report } from './Report';
export { default as RichEmbed } from './RichEmbed';
export { default as Route } from './Route';
export { default as Security } from './Security';
export { default as Server } from './Server';
export { default as Util } from './Util';
export { default as PaginationEmbed } from './PaginationEmbed';

View File

@ -1,4 +1,4 @@
import { Message } from 'eris';
import { Message, TextChannel } from 'discord.js';
import { Client, Command } from '../class';
export default class AddReferral extends Command {
@ -19,10 +19,10 @@ export default class AddReferral extends Command {
if (!account) return this.error(message.channel, 'Cannot find user.');
await account.updateOne({ $inc: { totalReferrals: 1 } });
this.client.getDMChannel(account.userID).then((chan) => {
chan.createMessage('__**Referral - Application Approval**__\nAn applicant who used your referral code during the application process has been approved. Your referral count has been increased.');
this.client.users.fetch(account.userID).then((chan) => {
chan.send('__**Referral - Application Approval**__\nAn applicant who used your referral code during the application process has been approved. Your referral count has been increased.');
}).catch(() => {});
return this.success(message.channel, `Added referral value to account.\nReferrer: \`${account.username}\` | <@${account.userID}>`);
return this.success(message.channel as TextChannel, `Added referral value to account.\nReferrer: \`${account.username}\` | <@${account.userID}>`);
} catch (error) {
return this.client.util.handleError(error, message, this);
}

View File

@ -1,4 +1,4 @@
import { Message } from 'eris';
import { Message } from 'discord.js';
import { Client, Command } from '../class';
export default class Announce extends Command {

View File

@ -1,6 +1,6 @@
/* eslint-disable no-useless-escape */
import { Message } from 'eris';
import { Client, Command, Report, RichEmbed } from '../class';
import { Message, MessageEmbed, TextChannel } from 'discord.js';
import { Client, Command, Report } from '../class';
export default class ApplyT2 extends Command {
constructor(client: Client) {
@ -24,7 +24,7 @@ export default class ApplyT2 extends Command {
const decision = await Report.tier2(account.userID, this.client.config.internalKey);
if (decision.status === 'SUCCESS') {
await loading.delete();
message.channel.createMessage(`__**Decision**__\n\n**Status:** ${decision.decision}\n**Processed by:** EDS (A\*01)`);
message.channel.send(`__**Decision**__\n\n**Status:** ${decision.decision}\n**Processed by:** EDS (A\*01)`);
if (decision.decision === 'APPROVED') {
const tier = await this.client.db.Tier.findOne({ id: 2 });
@ -33,21 +33,23 @@ export default class ApplyT2 extends Command {
} else {
await account.updateOne({ $set: { tier: 2 } });
}
const embed = new RichEmbed();
const embed = new MessageEmbed();
embed.setTitle('Cloud Account | Tier Change');
embed.setColor('#0099ff');
embed.addField('User', `${account.username} | <@${account.userID}>`, true);
embed.addField('Technician', 'SYSTEM', true);
embed.addField('Old Tier -> New Tier', `${account.tier} -> 2`, true);
embed.setFooter(this.client.user.username, this.client.user.avatarURL);
embed.setFooter(this.client.user.username, this.client.user.avatarURL());
embed.setTimestamp();
await this.client.util.sendMessageToUserTerminal(account.username, 'A technician has changed your tier to 2').catch(() => { });
this.client.createMessage('580950455581147146', { embed }); return this.client.getDMChannel(account.userID).then((channel) => channel.createMessage({ embed })).catch();
const ch = this.client.channels.cache.get('580950455581147146') as TextChannel;
ch.send({ embeds: [embed] });
return this.client.users.fetch(account.userID).then((channel) => channel.send({ embeds: [embed] })).catch();
}
return null;
}
await loading.delete();
return message.channel.createMessage(`__**Decision**__\n\n**Status:** ${decision.decision}\n**Processed by:** EDS (A*01)\n\n\n*Pre-Declines will not result in a hard pull, and they may be due to a server issue or insufficient information. You may want to contact a Staff member for further information.*`);
return message.channel.send(`__**Decision**__\n\n**Status:** ${decision.decision}\n**Processed by:** EDS (A*01)\n\n\n*Pre-Declines will not result in a hard pull, and they may be due to a server issue or insufficient information. You may want to contact a Staff member for further information.*`);
} catch (error) {
return this.client.util.handleError(error, message, this);
}

View File

@ -1,5 +1,5 @@
import jwt from 'jsonwebtoken';
import { Message } from 'eris';
import { Message } from 'discord.js';
import { Client, Command } from '../class';
export default class AuthReferral extends Command {
@ -18,13 +18,23 @@ export default class AuthReferral extends Command {
if (!args.length) return this.client.commands.get('help').run(message, [this.name]);
const referrer = await this.client.db.Account.findOne({ $or: [{ username: args[0] }, { referralCode: args[0] }, { userID: args[0].replace(/[<@!>]/gi, '') }] });
if (!referrer) return this.error(message.channel, 'Cannot find referrer.');
const referred = await this.client.getRESTGuildMember('446067825673633794', args[1]);
const referred = await message.guild.members.fetch(args[1]);
if (!referred) return this.error(message.channel, 'Cannot find referred member.');
const token = jwt.sign({ staffUserID: message.author.id, referralCode: referrer.referralCode, referrerUserID: referrer.userID, referrerUsername: referrer.username, referredUserID: referred.id, referredUserAndDiscrim: `${referred.username}#${referred.discriminator}` }, this.client.config.keyPair.privateKey, { expiresIn: '24 hours', issuer: 'Library of Code sp-us | Cloud Services Daemon' });
this.client.getDMChannel(referrer.userID).then(async (chan) => {
await chan.createMessage(`__**Referral Request Authorization**__\nYour referral code has been used in an application recently submitted to us. We need to authorize this request, please visit https://loc.sh/rv and enter the authorization token below. This token expires in 24 hours. If you did not authorize this request, please contact us immediately by DMing Ramirez or opening a ticket at https://loc.sh/cs-help.\n**Referred User:** ${referred.username}#${referred.discriminator} | <@${referred.user.id}>`);
await chan.createMessage(`\`${token}\``);
const token = jwt.sign(
{ staffUserID: message.author.id,
referralCode: referrer.referralCode,
referrerUserID: referrer.userID,
referrerUsername: referrer.username,
referredUserID: referred.id,
referredUserAndDiscrim: `${referred.user.username}#${referred.user.discriminator}` },
this.client.config.keyPair.privateKey, { expiresIn: '24 hours', issuer: 'Library of Code sp-us | Cloud Services Daemon' },
);
this.client.users.fetch(referrer.userID).then(async (user) => {
await user.send('__**Referral Request Authorization**__\n'
+ 'Your referral code has been used in an application recently submitted to us. We need to authorize this request, please visit https://loc.sh/rv and enter the authorization token below. This token expires in 24 hours. If you did not authorize this request, please contact us immediately by DMing Ramirez or opening a ticket at https://loc.sh/cs-help.\n'
+ `**Referred User:** ${referred.user.username}#${referred.user.discriminator} | ${referred.user.toString()}`);
await user.send(`\`${token}\``);
}).catch(() => {
this.error(message.channel, 'Could not DM referrer.');
});

View File

@ -1,4 +1,4 @@
import { Message } from 'eris';
import { Message } from 'discord.js';
import { Client, Command } from '../class';
import Bearer_Revoke from './bearer_revoke';
@ -19,8 +19,8 @@ export default class Bearer extends Command {
if (!account) return this.error(message.channel, 'Account not found.');
// eslint-disable-next-line no-underscore-dangle
const bearer = await this.client.server.security.createBearer(account._id);
const dm = await this.client.getDMChannel(message.author.id);
const msg = await dm.createMessage(`__**Library of Code sp-us | Cloud Services [API]**__\n*This message will automatically be deleted in 60 seconds, copy the token and save it. You cannot recover it.*\n\n${bearer}`);
const dm = await this.client.users.fetch(message.author.id);
const msg = await dm.send(`__**Library of Code sp-us | Cloud Services [API]**__\n*This message will automatically be deleted in 60 seconds, copy the token and save it. You cannot recover it.*\n\n${bearer}`);
this.success(message.channel, 'Bearer token sent to direct messages.');
return setTimeout(() => {
msg.delete();

View File

@ -1,4 +1,4 @@
import { Message } from 'eris';
import { Message } from 'discord.js';
import { Client, Command } from '../class';
export default class Bearer_Revoke extends Command {

View File

@ -1,5 +1,5 @@
import axios from 'axios';
import { Message } from 'eris';
import { Message } from 'discord.js';
import { Client, Command } from '../class';
export default class Cloudflare extends Command {

View File

@ -1,5 +1,6 @@
import { Message, PrivateChannel, GroupChannel } from 'eris';
import { GuildMember, Message } from 'discord.js';
import { Client, Command } from '../class';
import { LINUX_USERNAME_REGEX } from '../class/AccountUtil';
export default class CreateAccount extends Command {
constructor(client: Client) {
@ -20,10 +21,10 @@ export default class CreateAccount extends Command {
public async run(message: Message, args: string[]) {
try {
if (message.channel instanceof PrivateChannel || message.channel instanceof GroupChannel) return message; // Stop TS being gay
if (!args[2]) return this.client.commands.get('help').run(message, [this.name]);
if (!message.channel.guild.members.has(args[0])) return this.error(message.channel, 'User not found.');
if (message.channel.guild.members.get(args[0]).bot) return this.error(message.channel, 'I cannot create accounts for bots.');
const member: GuildMember = await message.guild.members.fetch(args[0]);
if (!member) return this.error(message.channel, 'User not found.');
if (member.user.bot) return this.error(message.channel, 'I cannot create accounts for bots.');
const checkUser = await this.client.db.Account.findOne({ userID: args[0] });
if (checkUser) return this.error(message.channel, `<@${args[0]}> already has an account.`);
const checkEmail = await this.client.db.Account.findOne({ emailAddress: args[1] });
@ -32,7 +33,7 @@ export default class CreateAccount extends Command {
if (checkAccount) return this.error(message.channel, 'Account already exists with this username.');
if (!this.client.util.isValidEmail(args[1])) return this.error(message.channel, 'Invalid email address supplied.');
if (!/^[a-z][-a-z0-9]*$/.test(args[2])) return this.error(message.channel, 'Invalid username supplied.');
if (!LINUX_USERNAME_REGEX.test(args[2])) return this.error(message.channel, 'Invalid username supplied.');
const confirmation = await this.loading(message.channel, 'Creating account...');
const data = await this.client.util.accounts.createAccount({ userID: args[0], username: args[2], emailAddress: args[1] }, message.author.id);

View File

@ -1,9 +1,10 @@
import { Message } from 'eris';
import { Message } from 'discord.js';
import { Client, Command } from '../class';
import Create from './cwg_create';
import Data from './cwg_data';
import Delete from './cwg_delete';
import UpdateCert from './cwg_updatecert';
import SelvServ from './cwg_selfserv';
export default class CWG extends Command {
constructor(client: Client) {
@ -11,8 +12,8 @@ export default class CWG extends Command {
this.name = 'cwg';
this.description = 'Manages aspects for the CWG.';
this.usage = `Run ${this.client.config.prefix}${this.name} [subcommand] for usage information`;
this.permissions = { roles: ['446104438969466890'] };
this.subcmds = [Create, Data, Delete, UpdateCert];
// this.permissions = { roles: ['446104438969466890'] };
this.subcmds = [Create, Data, Delete, UpdateCert, SelvServ];
this.enabled = true;
}

View File

@ -1,9 +1,9 @@
import fs, { writeFile, unlink } from 'fs-extra';
import fs, { writeFile, unlink, symlink } from 'fs-extra';
import axios from 'axios';
import { randomBytes } from 'crypto';
import { Message } from 'eris';
import { Message, MessageEmbed, TextChannel } from 'discord.js';
import { AccountInterface } from '../models';
import { Client, Command, RichEmbed } from '../class';
import { Client, Command } from '../class';
import { parseCertificate } from '../functions';
export default class CWG_Create extends Command {
@ -13,7 +13,7 @@ export default class CWG_Create extends Command {
super(client);
this.name = 'create';
this.description = 'Bind a domain to the CWG';
this.usage = `${this.client.config.prefix}cwg create [User ID | Username] [Domain] [Port] <Cert Chain> <Private Key> || Use snippets raw URL`;
this.usage = `${this.client.config.prefix}cwg create <User ID | Username> <Domain> <Port> [Cert Chain] [Private Key] || Use snippets raw URL`;
this.permissions = { roles: ['662163685439045632', '701454780828221450'] };
this.aliases = ['bind'];
this.enabled = true;
@ -45,7 +45,7 @@ export default class CWG_Create extends Command {
try {
answer = await this.client.util.messageCollector(
message,
`***${this.client.stores.emojis.error} This port is already binded to a domain. Do you wish to continue? (y/n)***`,
`***${this.client.stores.emojis.error} This port is already bound to a domain. Do you wish to continue? (y/n)***`,
30000, true, ['y', 'n'], (msg) => msg.author.id === message.author.id && msg.channel.id === message.channel.id,
);
} catch (error) {
@ -59,7 +59,7 @@ export default class CWG_Create extends Command {
let certs: { cert?: string, key?: string } = {};
if (!args[1].endsWith('.cloud.libraryofcode.org')) {
const urls = args.slice(3, 5);
if (urls.some((l) => !l.includes('snippets.cloud.libraryofcode.org/raw/'))) return this.error(message.channel, 'Invalid snippets URL. Make sure to use https://snippets.libraryofcode.org/raw/*.');
if (urls.some((l) => !l.includes('snippets.cloud.libraryofcode.org/raw/'))) return this.error(message.channel, 'Invalid snippets URL. Make sure to use https://snippets.cloud.libraryofcode.org/raw/*.');
const tasks = urls.map((l) => axios({ method: 'GET', url: l }));
const response = await Promise.all(tasks);
@ -80,12 +80,11 @@ export default class CWG_Create extends Command {
// @ts-ignore
await Promise.all(tasks);
const embed = new RichEmbed()
const embed = new MessageEmbed()
.setTitle('Domain Creation')
.setColor(3066993)
.addField('Account Username', `${account.username} | <@${account.userID}>`, true)
.addField('Account ID', account.id, true)
.addField('Technician', `<@${message.author.id}>`, true)
.addField('Technician', await this.client.util.getTechnicianName(message.author), true)
.addField('Domain', domain.domain, true)
.addField('Port', String(domain.port), true);
@ -95,20 +94,20 @@ export default class CWG_Create extends Command {
embed.addField('Certificate Issuer', cert.issuer.organizationName, true)
.addField('Certificate Subject', cert.subject.commonName, true)
.setFooter(this.client.user.username, this.client.user.avatarURL)
.setTimestamp(new Date(message.timestamp));
.setFooter(this.client.user.username, this.client.user.avatarURL())
.setTimestamp(new Date(message.createdTimestamp));
const completed = [
edit.edit(`***${this.client.stores.emojis.success} Successfully binded ${domain.domain} to port ${domain.port} for ${account.username}.***`),
this.client.createMessage('580950455581147146', { embed }),
this.client.getDMChannel(account.userID).then((r) => r.createMessage({ embed })),
edit.edit(`***${this.client.stores.emojis.success} Successfully bound ${domain.domain} to port ${domain.port} for ${account.username}.***`),
(this.client.channels.cache.get('580950455581147146') as TextChannel).send({ embeds: [embed] }),
this.client.users.fetch(account.userID).then((r) => r.send({ embeds: [embed] })),
this.client.util.transport.sendMail({
to: account.emailAddress,
from: 'Library of Code sp-us | Support Team <help@libraryofcode.org>',
subject: 'Your domain has been binded',
subject: 'Your domain has been bound',
html: `
<h1>Library of Code sp-us | Cloud Services</h1>
<p>Hello, this is an email informing you that a new domain under your account has been binded.
<p>Hello, this is an email informing you that a new domain under your account has been bound.
Information is below.</p>
<b>Domain:</b> ${domain.domain}<br>
<b>Port:</b> ${domain.port}<br>
@ -124,8 +123,8 @@ export default class CWG_Create extends Command {
];
if (!domain.domain.includes('cloud.libraryofcode.org')) {
const content = `__**DNS Record Setup**__\nYou recently a binded a custom domain to your Library of Code sp-us Account. You'll have to update your DNS records. We've provided the records below.\n\n\`${domain.domain} IN CNAME cloud.libraryofcode.org AUTO/500\`\nThis basically means you need to make a CNAME record with the key/host of ${domain.domain} and the value/point to cloud.libraryofcode.org. If you have any questions, don't hesitate to ask us.`;
completed.push(this.client.getDMChannel(account.userID).then((r) => r.createMessage(content)));
const content = `__**DNS Record Setup**__\nYou recently a bound a custom domain to your Library of Code sp-us Account. You'll have to update your DNS records. We've provided the records below.\n\n\`${domain.domain} IN CNAME cloud.libraryofcode.org AUTO/500\`\nThis basically means you need to make a CNAME record with the key/host of ${domain.domain} and the value/point to cloud.libraryofcode.org. If you have any questions, don't hesitate to ask us.`;
completed.push(this.client.users.fetch(account.userID).then((r) => r.send(content)));
}
return Promise.all(completed);
@ -181,7 +180,7 @@ export default class CWG_Create extends Command {
}
public async createCertAndPrivateKey(domain: string, certChain: string, privateKey: string) {
if (!this.isValidCertificateChain(certChain)) throw new Error('Invalid Certificate Chain');
// if (!this.isValidCertificateChain(certChain)) throw new Error('Invalid Certificate Chain');
// if (!this.isValidPrivateKey(privateKey)) throw new Error('Invalid Private Key');
const path = `/opt/CloudServices/temp/${domain}`;
await Promise.all([writeFile(`${path}.chain.crt`, certChain), writeFile(`${path}.key.pem`, privateKey)]);
@ -190,27 +189,31 @@ export default class CWG_Create extends Command {
throw new Error('Certificate and Private Key do not match');
}
if (domain.endsWith('.cloud.libraryofcode.org')) {
await Promise.all([symlink('/etc/ssl/private/cloud-libraryofcode-org.chain.crt', `/etc/ssl/certs/cwg/${domain}.chain.crt`), symlink('/etc/ssl/private/cloud-libraryofcode-org.key', `/etc/ssl/private/cwg/${domain}.key.pem`)]);
} else {
await Promise.all([writeFile(`/etc/ssl/certs/cwg/${domain}.chain.crt`, certChain), writeFile(`/etc/ssl/private/cwg/${domain}.key.pem`, privateKey)]);
}
return { cert: `/etc/ssl/certs/cwg/${domain}.chain.crt`, key: `/etc/ssl/private/cwg/${domain}.key.pem` };
}
public checkOccurance(text: string, query: string) {
public checkOccurrence(text: string, query: string) {
return (text.match(new RegExp(query, 'g')) || []).length;
}
public isValidCertificateChain(cert: string) {
if (!cert.replace(/^\s+|\s+$/g, '').startsWith('-----BEGIN CERTIFICATE-----')) return false;
if (!cert.replace(/^\s+|\s+$/g, '').endsWith('-----END CERTIFICATE-----')) return false;
if (this.checkOccurance(cert.replace(/^\s+|\s+$/g, ''), '-----BEGIN CERTIFICATE-----') !== 2) return false;
if (this.checkOccurance(cert.replace(/^\s+|\s+$/g, ''), '-----END CERTIFICATE-----') !== 2) return false;
if (this.checkOccurrence(cert.replace(/^\s+|\s+$/g, ''), '-----BEGIN CERTIFICATE-----') !== 2) return false;
if (this.checkOccurrence(cert.replace(/^\s+|\s+$/g, ''), '-----END CERTIFICATE-----') !== 2) return false;
return true;
}
public isValidPrivateKey(key: string) {
if (!key.replace(/^\s+|\s+$/g, '').startsWith('-----BEGIN PRIVATE KEY-----') && !key.replace(/^\s+|\s+$/g, '').startsWith('-----BEGIN RSA PRIVATE KEY-----') && !key.replace(/^\s+|\s+$/g, '').startsWith('-----BEGIN ECC PRIVATE KEY-----')) return false;
if (!key.replace(/^\s+|\s+$/g, '').endsWith('-----END PRIVATE KEY-----') && !key.replace(/^\s+|\s+$/g, '').endsWith('-----END RSA PRIVATE KEY-----') && !key.replace(/^\s+|\s+$/g, '').endsWith('-----END ECC PRIVATE KEY-----')) return false;
if ((this.checkOccurance(key.replace(/^\s+|\s+$/g, ''), '-----BEGIN PRIVATE KEY-----') !== 1) && (this.checkOccurance(key.replace(/^\s+|\s+$/g, ''), '-----BEGIN RSA PRIVATE KEY-----') !== 1) && (this.checkOccurance(key.replace(/^\s+|\s+$/g, ''), '-----BEGIN ECC PRIVATE KEY-----') !== 1)) return false;
if ((this.checkOccurance(key.replace(/^\s+|\s+$/g, ''), '-----END PRIVATE KEY-----') !== 1) && (this.checkOccurance(key.replace(/^\s+|\s+$/g, ''), '-----END RSA PRIVATE KEY-----') !== 1) && (this.checkOccurance(key.replace(/^\s+|\s+$/g, ''), '-----END ECC PRIVATE KEY-----') !== 1)) return false;
if ((this.checkOccurrence(key.replace(/^\s+|\s+$/g, ''), '-----BEGIN PRIVATE KEY-----') !== 1) && (this.checkOccurrence(key.replace(/^\s+|\s+$/g, ''), '-----BEGIN RSA PRIVATE KEY-----') !== 1) && (this.checkOccurrence(key.replace(/^\s+|\s+$/g, ''), '-----BEGIN ECC PRIVATE KEY-----') !== 1)) return false;
if ((this.checkOccurrence(key.replace(/^\s+|\s+$/g, ''), '-----END PRIVATE KEY-----') !== 1) && (this.checkOccurrence(key.replace(/^\s+|\s+$/g, ''), '-----END RSA PRIVATE KEY-----') !== 1) && (this.checkOccurrence(key.replace(/^\s+|\s+$/g, ''), '-----END ECC PRIVATE KEY-----') !== 1)) return false;
return true;
}

View File

@ -1,16 +1,14 @@
import fs from 'fs';
import moment from 'moment';
import x509 from 'x509';
import { createPaginationEmbed } from 'eris-pagination';
import { Message } from 'eris';
import { Client, Command, RichEmbed } from '../class';
import { Message, MessageEmbed } from 'discord.js';
import { Client, Command, PaginationEmbed } from '../class';
export default class CWG_Data extends Command {
constructor(client: Client) {
super(client);
this.name = 'data';
this.description = 'Check CWG data';
this.usage = `${this.client.config.prefix}cwg data [Domain | Port]`;
this.usage = `${this.client.config.prefix}cwg data <Domain | Port>`;
this.permissions = { roles: ['662163685439045632', '701454780828221450'] };
this.enabled = true;
}
@ -30,24 +28,31 @@ export default class CWG_Data extends Command {
}
return this.error(message.channel, 'The domain or port you provided could not be found.');
}
const embeds = dom.map((domain) => {
const cert = fs.readFileSync(domain.x509.cert, { encoding: 'utf8' });
const embed = new RichEmbed();
const embeds = await Promise.all(dom.map(async (domain) => {
let pem: string;
try {
pem = fs.readFileSync(domain.x509.cert, { encoding: 'utf8' });
} catch {
pem = fs.readFileSync('/etc/ssl/private/cloud-libraryofcode-org.chain.crt', { encoding: 'utf8' });
}
const cert = await this.client.util.parseCertificate(pem);
const embed = new MessageEmbed();
embed.setTitle('Domain Information');
embed.addField('Account Username', domain.account.username, true);
embed.addField('Account ID', domain.account.userID, true);
embed.addField('Domain', domain.domain, true);
embed.addField('Port', String(domain.port), true);
embed.addField('Certificate Issuer', x509.getIssuer(cert).organizationName, true);
embed.addField('Certificate Subject', x509.getSubject(cert).commonName, true);
embed.addField('Certificate Expiration Date', moment(x509.parseCert(cert).notAfter).format('dddd, MMMM Do YYYY, h:mm:ss A'), true);
embed.setFooter(this.client.user.username, this.client.user.avatarURL);
embed.addField('Certificate Issuer', `${cert.issuer.organization[0]} (${cert.issuer.commonName})` || 'N/A', true);
embed.addField('Certificate Subject', cert.subject.commonName || 'N/A', true);
embed.addField('Certificate Expiration Date', cert.notAfter ? moment(cert.notAfter).format('dddd, MMMM Do YYYY, h:mm:ss A') || 'N/A' : 'N/A', true);
embed.setFooter(this.client.user.username, this.client.user.avatarURL());
embed.setTimestamp();
return embed;
});
}));
this.client.signale.log(embeds);
if (embeds.length === 1) return message.channel.createMessage({ embed: embeds[0] });
return createPaginationEmbed(message, embeds);
if (embeds.length === 1) return message.channel.send({ embeds: [embeds[0]] });
return this.client.util.createPaginationEmbed(message, embeds);
} catch (error) {
return this.client.util.handleError(error, message, this);
}

View File

@ -1,15 +1,15 @@
import fs from 'fs-extra';
import axios from 'axios';
import { Message } from 'eris';
import { Client, Command, RichEmbed } from '../class';
import { Message, MessageEmbed, TextChannel } from 'discord.js';
import { Client, Command } from '../class';
export default class CWG_Delete extends Command {
constructor(client: Client) {
super(client);
this.name = 'delete';
this.description = 'Unbind a domain to the CWG';
this.description = 'Unbind a domain from the CWG';
this.usage = `${this.client.config.prefix}cwg delete [Domain | Port]`;
this.permissions = { roles: ['662163685439045632'] };
this.permissions = { roles: ['662163685439045632', '701454780828221450'] };
this.aliases = ['unbind'];
this.enabled = true;
}
@ -20,13 +20,13 @@ export default class CWG_Delete extends Command {
const domain = await this.client.db.Domain.findOne({ $or: [{ domain: args[0] }, { port: Number(args[0]) || 0 }] });
if (!domain) return this.error(message.channel, 'The domain or port you provided could not be found.');
const edit = await this.loading(message.channel, 'Deleting domain...');
const embed = new RichEmbed();
const embed = new MessageEmbed();
embed.setTitle('Domain Deletion');
embed.addField('Account Username', `${domain.account.username} | <@${domain.account.userID}>`, true);
embed.addField('Account ID', domain.account.userID, true);
embed.addField('Technician', await this.client.util.getTechnicianName(message.author), true);
embed.addField('Domain', domain.domain, true);
embed.addField('Port', String(domain.port), true);
embed.setFooter(this.client.user.username, this.client.user.avatarURL);
embed.setFooter(this.client.user.username, this.client.user.avatarURL());
embed.setTimestamp();
if (domain.domain.includes('cloud.libraryofcode.org')) {
const resultID = await axios({
@ -51,8 +51,9 @@ export default class CWG_Delete extends Command {
await this.client.db.Domain.deleteOne({ domain: domain.domain });
await this.client.util.exec('systemctl reload nginx');
edit.edit(`***${this.client.stores.emojis.success} Domain ${domain.domain} with port ${domain.port} has been successfully deleted.***`);
this.client.createMessage('580950455581147146', { embed });
return this.client.getDMChannel(domain.account.userID).then((channel) => channel.createMessage({ embed })).catch(() => {});
const ch = this.client.channels.cache.get('580950455581147146') as TextChannel;
ch.send({ embeds: [embed] });
return this.client.users.fetch(domain.account.userID).then((u) => u.send({ embeds: [embed] })).catch(() => {});
} catch (error) {
return this.client.util.handleError(error, message, this);
}

View File

@ -0,0 +1,227 @@
import fs, { writeFile, unlink, symlink } from 'fs-extra';
import axios from 'axios';
import { randomBytes } from 'crypto';
import { Message, MessageEmbed, TextChannel } from 'discord.js';
import { AccountInterface } from '../models';
import { Client, Command } from '../class';
import { parseCertificate } from '../functions';
export default class CWG_SelfService extends Command {
public urlRegex: RegExp;
constructor(client: Client) {
super(client);
this.name = 'selfserv';
this.description = 'Creates a subdomain on your account. Do not include the entire subdomain: if you want `mydomain.cloud.libraryofcode.org`, just supply `mydomain` in the command parameters.\nYou must receive an authentication token from the Instant Application Service, see `?apply` for more information.';
this.usage = `${this.client.config.prefix}cwg selfserv <desired subdomain> <authentication token>`;
this.aliases = ['ss'];
this.enabled = true;
this.urlRegex = /^[a-zA-Z0-9\-._~:/?#[\]@!$&'()*+,;=]+$/;
}
public async run(message: Message, args: string[]) {
if (!args[0].endsWith('.cloud.libraryofcode.org')) return this.error(message.channel, 'Only subdomains may be created with this command. If you\'d like to use a custom domain please contact a Technician.');
const reqDomain = `${escape(args[0])}.cloud.libraryofcode.org`;
try {
if (!args[1]) return this.client.commands.get('help').run(message, ['cwg', this.name]);
const account = await this.client.db.Account.findOne({ userID: message.author.id });
if (!account) return this.error(message.channel, 'Cannot locate account.');
if (!this.domainTextValidation(args[0])) return this.error(message.channel, 'The domain value you provided is invalid.');
if (await this.client.db.Domain.exists({ domain: reqDomain })) return this.error(message.channel, 'This domain already exists.');
if (await this.checkAuthorizationToken(message.author.id, args[1]) !== true) return this.error(message.channel, 'Permission denied.');
const edit = await this.loading(message.channel, 'Binding domain...');
const certs: { cert?: string, key?: string } = {};
certs.cert = await fs.readFile('/etc/ssl/private/cloud-libraryofcode-org.chain.crt', { encoding: 'utf8' });
certs.key = await fs.readFile('/etc/ssl/private/cloud-libraryofcode-org.key', { encoding: 'utf8' });
let port: number;
try {
port = await this.getPort();
} catch {
return this.error(message.channel, 'Unable to acquire port automatically. Please contact a Technician.');
}
const domain = await this.createDomain(account, reqDomain, port, certs);
const tasks = [message.delete(), this.client.util.exec('systemctl reload nginx')];
// @ts-ignore
await Promise.all(tasks);
const embed = new MessageEmbed()
.setTitle('Domain Creation')
.setColor(3066993)
.addField('Account Username', `${account.username} | <@${account.userID}>`, true)
.addField('Technician', 'SYSTEM', true)
.addField('Domain', domain.domain, true)
.addField('Port', String(domain.port), true);
const certPath = `/opt/CloudServices/temp/${randomBytes(5).toString('hex')}`;
await writeFile(certPath, certs.cert, { encoding: 'utf8' });
const cert = await parseCertificate(this.client, certPath);
embed.addField('Certificate Issuer', cert.issuer.organizationName, true)
.addField('Certificate Subject', cert.subject.commonName, true)
.setFooter(this.client.user.username, this.client.user.avatarURL())
.setTimestamp(new Date(message.createdTimestamp));
const completed = [
edit.edit(`***${this.client.stores.emojis.success} Your subdomain has been created, please check your DMs or email address for more information.***`),
(this.client.channels.cache.get('580950455581147146') as TextChannel).send({ embeds: [embed] }),
this.client.users.fetch(account.userID).then((r) => r.send({ embeds: [embed] })),
this.client.util.transport.sendMail({
to: account.emailAddress,
from: 'Library of Code sp-us | Support Team <help@libraryofcode.org>',
replyTo: 'Dept of Engineering <engineering@libraryofcode.org>',
subject: 'Your domain has been created',
html: `
<h1>Library of Code sp-us | Cloud Services</h1>
<p>Hello, this is an email informing you that a new domain under your account has been bound.
Information is below.</p>
<b>Domain:</b> ${domain.domain}<br>
<b>Port:</b> ${domain.port}<br>
<b>Certificate Issuer:</b> ${cert.issuer.organizationName}<br>
<b>Certificate Subject:</b> ${cert.subject.commonName}<br>
<b>Responsible Engineer:</b> SYSTEM<br><br>
If you have any questions about additional setup, you can reply to this email or send a message in #cloud-support in our Discord server.<br>
<b><i>Library of Code sp-us | Support Team</i></b>
`,
}),
];
return Promise.all(completed);
} catch (err) {
this.client.util.handleError(err, message, this);
const tasks = [fs.unlink(`/etc/nginx/sites-enabled/${reqDomain}`), fs.unlink(`/etc/nginx/sites-available/${reqDomain}`), this.client.db.Domain.deleteMany({ domain: reqDomain })];
return Promise.allSettled(tasks);
}
}
public async getPort() {
const port = Number(await this.client.redis.get('cwgsspc'));
if (await this.client.db.Domain.exists({ port })) throw new Error('Error retreiving port.');
if (port >= Number(process.env.MAX_CWG_PORT)) throw new Error('Error retrieving port.');
await this.client.redis.incr('cwgsspc');
return port;
}
public domainTextValidation(domain: string) {
if (domain.length >= 25) return false;
return /[A-Za-z0-9](?:[A-Za-z0-9-]{0,19}[A-Za-z0-9])?/.test(domain);
}
public async checkAuthorizationToken(userID: string, token: string) {
try {
const resp = await axios({
url: 'https://comm.libraryofcode.org/internal/check-cwg-self-auth',
params: {
userID,
token,
internalKey: this.client.config.internalKey,
},
});
if (resp?.status === 204) {
return true;
}
return false;
} catch {
return false;
}
}
/**
* This function binds a domain to a port on the CWG.
* @param account The account of the user.
* @param subdomain The domain to use. `mydomain.cloud.libraryofcode.org`
* @param port The port to use, must be between 1024 and 65535.
* @param x509Certificate The contents the certificate and key files.
* @example await CWG.createDomain(account, 'mydomain.cloud.libraryofcode.org', 6781);
*/
public async createDomain(account: AccountInterface, domain: string, port: number, x509Certificate: { cert?: string, key?: string }) {
try {
if (port <= 1024 || port >= 65535) throw new RangeError(`Port range must be between 1024 and 65535, received ${port}.`);
if (await this.client.db.Domain.exists({ domain })) throw new Error(`Domain ${domain} already exists in the database.`);
if (!await this.client.db.Account.exists({ userID: account.userID })) throw new Error(`Cannot find account ${account.userID}.`);
let x509: { cert: string, key: string };
if (x509Certificate) {
x509 = await this.createCertAndPrivateKey(domain, x509Certificate.cert, x509Certificate.key);
} else {
x509 = {
cert: '/etc/ssl/private/cloud-libraryofcode-org.chain.crt',
key: '/etc/ssl/private/cloud-libraryofcode-org.key',
};
}
let cfg = await fs.readFile('/opt/CloudServices/src/static/nginx.conf', { encoding: 'utf8' });
cfg = cfg.replace(/\[DOMAIN]/g, domain);
cfg = cfg.replace(/\[PORT]/g, String(port));
cfg = cfg.replace(/\[CERTIFICATE]/g, x509.cert);
cfg = cfg.replace(/\[KEY]/g, x509.key);
await fs.writeFile(`/etc/nginx/sites-available/${domain}`, cfg, { encoding: 'utf8' });
await fs.symlink(`/etc/nginx/sites-available/${domain}`, `/etc/nginx/sites-enabled/${domain}`);
const entry = new this.client.db.Domain({
account,
domain,
port,
x509,
enabled: true,
});
return entry.save();
} catch (error) {
const tasks = [fs.unlink(`/etc/nginx/sites-enabled/${domain}`), fs.unlink(`/etc/nginx/sites-available/${domain}`), this.client.db.Domain.deleteMany({ domain })];
await Promise.allSettled(tasks);
throw error;
}
}
public async createCertAndPrivateKey(domain: string, certChain: string, privateKey: string) {
if (!this.isValidCertificateChain(certChain)) throw new Error('Invalid Certificate Chain');
// if (!this.isValidPrivateKey(privateKey)) throw new Error('Invalid Private Key');
const path = `/opt/CloudServices/temp/${domain}`;
await Promise.all([writeFile(`${path}.chain.crt`, certChain), writeFile(`${path}.key.pem`, privateKey)]);
if (!this.isMatchingPair(`${path}.chain.crt`, `${path}.key.pem`)) {
await Promise.all([unlink(`${path}.chain.crt`), unlink(`${path}.key.pem`)]);
throw new Error('Certificate and Private Key do not match');
}
if (domain.endsWith('.cloud.libraryofcode.org')) {
await Promise.all([symlink('/etc/ssl/private/cloud-libraryofcode-org.chain.crt', `/etc/ssl/certs/cwg/${domain}.chain.crt`), symlink('/etc/ssl/private/cloud-libraryofcode-org.key', `/etc/ssl/private/cwg/${domain}.key.pem`)]);
} else {
await Promise.all([writeFile(`/etc/ssl/certs/cwg/${domain}.chain.crt`, certChain), writeFile(`/etc/ssl/private/cwg/${domain}.key.pem`, privateKey)]);
}
return { cert: `/etc/ssl/certs/cwg/${domain}.chain.crt`, key: `/etc/ssl/private/cwg/${domain}.key.pem` };
}
public checkOccurrence(text: string, query: string) {
return (text.match(new RegExp(query, 'g')) || []).length;
}
public isValidCertificateChain(cert: string) {
if (!cert.replace(/^\s+|\s+$/g, '').startsWith('-----BEGIN CERTIFICATE-----')) return false;
if (!cert.replace(/^\s+|\s+$/g, '').endsWith('-----END CERTIFICATE-----')) return false;
if (this.checkOccurrence(cert.replace(/^\s+|\s+$/g, ''), '-----BEGIN CERTIFICATE-----') !== 2) return false;
if (this.checkOccurrence(cert.replace(/^\s+|\s+$/g, ''), '-----END CERTIFICATE-----') !== 2) return false;
return true;
}
public isValidPrivateKey(key: string) {
if (!key.replace(/^\s+|\s+$/g, '').startsWith('-----BEGIN PRIVATE KEY-----') && !key.replace(/^\s+|\s+$/g, '').startsWith('-----BEGIN RSA PRIVATE KEY-----') && !key.replace(/^\s+|\s+$/g, '').startsWith('-----BEGIN ECC PRIVATE KEY-----')) return false;
if (!key.replace(/^\s+|\s+$/g, '').endsWith('-----END PRIVATE KEY-----') && !key.replace(/^\s+|\s+$/g, '').endsWith('-----END RSA PRIVATE KEY-----') && !key.replace(/^\s+|\s+$/g, '').endsWith('-----END ECC PRIVATE KEY-----')) return false;
if ((this.checkOccurrence(key.replace(/^\s+|\s+$/g, ''), '-----BEGIN PRIVATE KEY-----') !== 1) && (this.checkOccurrence(key.replace(/^\s+|\s+$/g, ''), '-----BEGIN RSA PRIVATE KEY-----') !== 1) && (this.checkOccurrence(key.replace(/^\s+|\s+$/g, ''), '-----BEGIN ECC PRIVATE KEY-----') !== 1)) return false;
if ((this.checkOccurrence(key.replace(/^\s+|\s+$/g, ''), '-----END PRIVATE KEY-----') !== 1) && (this.checkOccurrence(key.replace(/^\s+|\s+$/g, ''), '-----END RSA PRIVATE KEY-----') !== 1) && (this.checkOccurrence(key.replace(/^\s+|\s+$/g, ''), '-----END ECC PRIVATE KEY-----') !== 1)) return false;
return true;
}
public async isMatchingPair(cert: string, privateKey: string) {
const result: string = await this.client.util.exec(`${__dirname}/../bin/checkCertSignatures ${cert} ${privateKey}`);
const { ok }: { ok: boolean } = JSON.parse(result);
return ok;
}
}

View File

@ -1,6 +1,6 @@
import { writeFile, unlink } from 'fs-extra';
import axios from 'axios';
import { Message } from 'eris';
import { Message } from 'discord.js';
import { Client, Command } from '../class';
export default class CWG_UpdateCert extends Command {
@ -49,23 +49,23 @@ export default class CWG_UpdateCert extends Command {
}
}
public checkOccurance(text: string, query: string) {
public checkOccurrence(text: string, query: string) {
return (text.match(new RegExp(query, 'g')) || []).length;
}
public isValidCertificateChain(cert: string) {
if (!cert.replace(/^\s+|\s+$/g, '').startsWith('-----BEGIN CERTIFICATE-----')) return false;
if (!cert.replace(/^\s+|\s+$/g, '').endsWith('-----END CERTIFICATE-----')) return false;
if (this.checkOccurance(cert.replace(/^\s+|\s+$/g, ''), '-----BEGIN CERTIFICATE-----') !== 2) return false;
if (this.checkOccurance(cert.replace(/^\s+|\s+$/g, ''), '-----END CERTIFICATE-----') !== 2) return false;
if (this.checkOccurrence(cert.replace(/^\s+|\s+$/g, ''), '-----BEGIN CERTIFICATE-----') !== 2) return false;
if (this.checkOccurrence(cert.replace(/^\s+|\s+$/g, ''), '-----END CERTIFICATE-----') !== 2) return false;
return true;
}
public isValidPrivateKey(key: string) {
if (!key.replace(/^\s+|\s+$/g, '').startsWith('-----BEGIN PRIVATE KEY-----')) return false;
if (!key.replace(/^\s+|\s+$/g, '').endsWith('-----END PRIVATE KEY-----')) return false;
if (this.checkOccurance(key.replace(/^\s+|\s+$/g, ''), '-----BEGIN PRIVATE KEY-----') !== 1) return false;
if (this.checkOccurance(key.replace(/^\s+|\s+$/g, ''), '-----END PRIVATE KEY-----') !== 1) return false;
if (this.checkOccurrence(key.replace(/^\s+|\s+$/g, ''), '-----BEGIN PRIVATE KEY-----') !== 1) return false;
if (this.checkOccurrence(key.replace(/^\s+|\s+$/g, ''), '-----END PRIVATE KEY-----') !== 1) return false;
return true;
}

View File

@ -1,5 +1,5 @@
import { Message, PrivateChannel } from 'eris';
import uuid from 'uuid/v4';
import { Message } from 'discord.js';
import { v4 as uuid } from 'uuid';
import { Client, Command } from '../class';
export default class DeleteAccount extends Command {
@ -18,9 +18,9 @@ export default class DeleteAccount extends Command {
try {
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.***`);
if (!account) return message.channel.send(`${this.client.stores.emojis.error} ***Account not found.***`);
const { root, username, userID, emailAddress, homepath } = account;
if (root) return message.channel.createMessage(`${this.client.stores.emojis.error} ***Permission denied.***`);
if (root) return message.channel.send(`${this.client.stores.emojis.error} ***Permission denied.***`);
const pad = (number: number, amount: number): string => '0'.repeat(amount - number.toString().length) + number;
const randomNumber = Math.floor(Math.random() * 9999);
@ -28,17 +28,17 @@ export default class DeleteAccount extends Command {
try {
await this.client.util.messageCollector(message,
`***Please confirm that you are permanently deleting ${username}'s account by entering ${verify}. This action cannot be reversed.***`,
15000, true, [verify], (msg) => !(message.channel instanceof PrivateChannel && msg.author.id === message.author.id));
15000, true, [verify], (msg) => msg.author.id === message.author.id);
} catch (error) {
if (error.message.includes('Did not supply')) return message;
throw error;
}
const deleting = await message.channel.createMessage(`${this.client.stores.emojis.loading} ***Deleting account, please wait...***`);
const deleting = await message.channel.send(`${this.client.stores.emojis.loading} ***Deleting account, please wait...***`);
const reason = args.slice(1).join(' ');
const logInput = { username, userID, logID: uuid(), moderatorID: message.author.id, type: 4, date: new Date(), reason: null };
if (reason) logInput.reason = reason;
await this.client.util.createModerationLog(args[0], message.member, 4, reason);
await this.client.util.createModerationLog(args[0], message.author, 4, reason);
await this.client.util.deleteAccount(username);
message.delete().catch(() => {});

View File

@ -1,5 +1,5 @@
import { randomBytes } from 'crypto';
import { Message } from 'eris';
import { Message } from 'discord.js';
import { Client, Command } from '../class';
export default class EmailCode extends Command {

View File

@ -1,6 +1,6 @@
/* eslint-disable no-eval */
import axios from 'axios';
import { Message } from 'eris';
import { Message } from 'discord.js';
import { inspect } from 'util';
import { Client, Command } from '../class';
@ -11,7 +11,7 @@ export default class Eval extends Command {
this.aliases = ['e'];
this.description = 'Evaluate JavaScript code';
this.enabled = true;
this.permissions = { users: ['253600545972027394', '278620217221971968', '239261547959025665'] };
this.permissions = { users: ['253600545972027394', '278620217221971968', '239261547959025665', '143414786913206272'] };
this.guildOnly = false;
}
@ -45,22 +45,21 @@ export default class Eval extends Command {
evaled = error.stack;
}
evaled = evaled.replace(new RegExp(this.client.config.token, 'gi'), 'juul');
evaled = evaled.replace(new RegExp(this.client.config.emailPass, 'gi'), 'juul');
evaled = evaled.replace(new RegExp(this.client.config.cloudflare, 'gi'), 'juul');
evaled = evaled.replace(new RegExp(this.client.config.token, 'gi'), 'token');
evaled = evaled.replace(new RegExp(this.client.config.emailPass, 'gi'), 'emailPass');
evaled = evaled.replace(new RegExp(this.client.config.cloudflare, 'gi'), 'cloudflare');
const display = this.client.util.splitString(evaled, 1975);
if (display[5]) {
try {
const { data } = await axios.post('https://snippets.cloud.libraryofcode.org/documents', display.join(''));
return message.channel.createMessage(`${this.client.stores.emojis.success} Your evaluation evaled can be found on https://snippets.cloud.libraryofcode.org/${data.key}`);
return message.channel.send(`${this.client.stores.emojis.success} Your evaluation evaled can be found on https://snippets.cloud.libraryofcode.org/${data.key}`);
} catch (error) {
return message.channel.createMessage(`${this.client.stores.emojis.error} ${error}`);
return message.channel.send(`${this.client.stores.emojis.error} ${error}`);
}
}
return display.forEach((m) => message.channel.createMessage(`\`\`\`js\n${m}\n\`\`\``));
return display.forEach((m) => message.channel.send(`\`\`\`js\n${m}\n\`\`\``));
} catch (error) {
return this.client.util.handleError(error, message, this);
}

View File

@ -1,4 +1,4 @@
import { Message } from 'eris';
import { Message } from 'discord.js';
import axios from 'axios';
import { Client, Command } from '../class';
@ -9,7 +9,7 @@ export default class Exec extends Command {
this.description = 'Executes command';
this.aliases = ['ex'];
this.enabled = true;
this.permissions = { users: ['253600545972027394', '278620217221971968', '239261547959025665'] };
this.permissions = { users: ['253600545972027394', '278620217221971968', '239261547959025665', '143414786913206272'] };
this.guildOnly = false;
}
@ -38,7 +38,7 @@ export default class Exec extends Command {
}
await response.delete();
return splitResult.forEach((m) => message.channel.createMessage(`\`\`\`bash\n${m}\n\`\`\``));
return splitResult.forEach((m) => message.channel.send(`\`\`\`bash\n${m}\n\`\`\``));
} catch (error) {
return this.client.util.handleError(error, message, this);
}

View File

@ -1,4 +1,4 @@
import { Message } from 'eris';
import { Message } from 'discord.js';
import { Client, Command } from '../class';
export default class GetReferral extends Command {
@ -16,8 +16,8 @@ export default class GetReferral extends Command {
const account = await this.client.db.Account.findOne({ userID: message.author.id });
if (!account) return this.error(message.channel, 'You do not have a Cloud Services account.');
return this.client.getDMChannel(message.author.id).then((chan) => {
chan.createMessage(`__**CS Account Referral Code**__\n*Referral codes are considered to be somewhat private information. Applicants with referral codes have a greater chance of approval, don't refer someone you don't trust :).*\nYour referral code: \`${account.referralCode}\`\nReferrals Granted: \`${account.totalReferrals ? account.totalReferrals : '0'}\``);
return this.client.users.fetch(message.author.id).then((u) => {
u.send(`__**CS Account Referral Code**__\n*Referral codes are considered to be somewhat private information. Applicants with referral codes have a greater chance of approval, don't refer someone you don't trust :).*\nYour referral code: \`${account.referralCode}\`\nReferrals Granted: \`${account.totalReferrals ? account.totalReferrals : '0'}\``);
}).catch(() => this.error(message.channel, 'Could not send you a DM.'));
} catch (err) {
return this.client.util.handleError(err, message, this);

View File

@ -1,6 +1,5 @@
import { Message } from 'eris';
import { createPaginationEmbed } from 'eris-pagination';
import { Client, Command, RichEmbed } from '../class';
import { Message, MessageEmbed } from 'discord.js';
import { Client, Command } from '../class';
export default class Help extends Command {
constructor(client: Client) {
@ -23,42 +22,43 @@ export default class Help extends Command {
const perms: string[] = [];
let allowedRoles = c.permissions && c.permissions.roles && c.permissions.roles.map((r) => `<@&${r}>`).join(', ');
if (allowedRoles) { allowedRoles = `**Roles:** ${allowedRoles}`; perms.push(allowedRoles); }
let allowedUsers = c.permissions && c.permissions.users && c.permissions.users.map((u) => `<@${u}>`).join(', ');
let allowedUsers = c.permissions && c.permissions.users && c.permissions.users.map((u) => `<@!${u}>`).join(', ');
if (allowedUsers) { allowedUsers = `**Users:** ${allowedUsers}`; perms.push(allowedUsers); }
const displayedPerms = perms.length ? `**Permissions:**\n${perms.join('\n')}` : '';
return { name: `${this.client.config.prefix}${c.name}`, value: `**Description:** ${c.description}\n**Aliases:** ${aliases}\n**Usage:** ${c.usage}\n${displayedPerms}`, inline: false };
});
const splitCommands = this.client.util.splitFields(commands);
const cmdPages: RichEmbed[] = [];
const cmdPages: MessageEmbed[] = [];
splitCommands.forEach((splitCmd) => {
const embed = new RichEmbed();
embed.setTimestamp(); embed.setFooter(`Requested by ${message.author.username}#${message.author.discriminator}`, message.author.avatarURL);
embed.setAuthor(`${this.client.user.username}#${this.client.user.discriminator}`, this.client.user.avatarURL);
const embed = new MessageEmbed();
embed.setTimestamp();
embed.setFooter(`Requested by ${message.author.username}#${message.author.discriminator}`, message.author.avatarURL());
embed.setAuthor(`${this.client.user.username}#${this.client.user.discriminator}`, this.client.user.avatarURL());
embed.setDescription(`Command list for ${this.client.user.username}`);
splitCmd.forEach((c) => embed.addField(c.name, c.value, c.inline));
return cmdPages.push(embed);
});
if (cmdPages.length === 1) return message.channel.createMessage({ embed: cmdPages[0] });
return createPaginationEmbed(message, cmdPages);
if (cmdPages.length === 1) return message.channel.send({ embeds: [cmdPages[0]] });
return this.client.util.createPaginationEmbed(message, cmdPages);
}
const resolved = await this.client.util.resolveCommand(args, message);
if (!resolved) return message.channel.createMessage(`${this.client.stores.emojis.error} **Command not found!**`);
if (!resolved) return message.channel.send(`${this.client.stores.emojis.error} **Command not found!**`);
const { cmd } = resolved;
const perms: string[] = [];
let allowedRoles = cmd.permissions && cmd.permissions.roles && cmd.permissions.roles.map((r) => `<@&${r}>`).join(', ');
if (allowedRoles) { allowedRoles = `**Roles:** ${allowedRoles}`; perms.push(allowedRoles); }
let allowedUsers = cmd.permissions && cmd.permissions.users && cmd.permissions.users.map((u) => `<@${u}>`).join(', ');
let allowedUsers = cmd.permissions && cmd.permissions.users && cmd.permissions.users.map((u) => `<@!${u}>`).join(', ');
if (allowedUsers) { allowedUsers = `**Users:** ${allowedUsers}`; perms.push(allowedUsers); }
const displayedPerms = perms.length ? `\n**Permissions:**\n${perms.join('\n')}` : '';
const aliases = cmd.aliases.length ? `\n**Aliases:** ${cmd.aliases.map((alias) => `${this.client.config.prefix}${cmd.parentName ? `${cmd.parentName} ` : ''}${alias}`).join(', ')}` : '';
const subcommands = cmd.subcommands.size ? `\n**Subcommands:** ${cmd.subcommands.map((s) => `${cmd.name} ${s.name}`).join(', ')}` : '';
const embed = new RichEmbed();
embed.setTimestamp(); embed.setFooter(`Requested by ${message.author.username}#${message.author.discriminator}`, message.author.avatarURL);
embed.setTitle(`${this.client.config.prefix}${cmd.parentName ? `${cmd.parentName}${cmd.name}` : cmd.name}`); embed.setAuthor(`${this.client.user.username}#${this.client.user.discriminator}`, this.client.user.avatarURL);
const embed = new MessageEmbed();
embed.setTimestamp(); embed.setFooter(`Requested by ${message.author.username}#${message.author.discriminator}`, message.author.avatarURL());
embed.setTitle(`${this.client.config.prefix}${cmd.parentName ? `${cmd.parentName}${cmd.name}` : cmd.name}`); embed.setAuthor(`${this.client.user.username}#${this.client.user.discriminator}`, this.client.user.avatarURL());
const description = `**Description**: ${cmd.description}\n**Usage:** ${cmd.usage}${aliases}${displayedPerms}${subcommands}`;
embed.setDescription(description);
message.channel.createMessage({ embed });
message.channel.send({ embeds: [embed] });
} catch (error) {
this.client.util.handleError(error, message, this);
}

View File

@ -28,6 +28,7 @@ export { default as systemd } from './systemd';
export { default as tier } from './tier';
export { default as unban } from './unban';
export { default as unlock } from './unlock';
export { default as usermod } from './usermod';
export { default as users } from './users';
export { default as warn } from './warn';
export { default as whois } from './whois';

View File

@ -1,7 +1,7 @@
import { Message } from 'eris';
import { Message, MessageEmbed } from 'discord.js';
import { totalmem } from 'os';
import { Client, Command, RichEmbed } from '../class';
import { version as erisVersion } from '../../node_modules/eris/package.json';
import { Client, Command } from '../class';
import { version as discordjsVersion } from '../../node_modules/discord.js/package.json';
import { version as expressVersion } from '../../node_modules/express/package.json';
import { version as mongooseVersion } from '../../node_modules/mongoose/package.json';
import { version as ioredisVersion } from '../../node_modules/ioredis/package.json';
@ -18,20 +18,20 @@ export default class Info extends Command {
public async run(message: Message) {
try {
const embed = new RichEmbed();
const embed = new MessageEmbed();
embed.setTitle('Information');
embed.setThumbnail(this.client.user.avatarURL);
embed.setThumbnail(this.client.user.avatarURL());
embed.addField('Language(s)', '<:ts:604565354554982401> TypeScript, <:Go:703449475405971466> Go', true);
embed.addField('Runtime', `Node (${process.version})`, true);
embed.addField('Compilers/Transpilers', `TypeScript [tsc] (${tscVersion}) | Go [gc] (${await this.client.util.exec('go version')})`, true);
embed.addField('Process Manager', `SystemD (${(await this.client.util.exec('systemd --version')).split('\n')[0]})`, true);
embed.addField('Discord Library', `Eris (${erisVersion})`, true);
embed.addField('Discord Library', `Discord.js (${discordjsVersion})`, true);
embed.addField('HTTP Server Library', `Express (${expressVersion})`, true);
embed.addField('Database Library', `MongoDB w/ Mongoose ODM (${mongooseVersion})`, true);
embed.addField('Cache Library', `Redis w/ IORedis (${ioredisVersion})`, true);
embed.addField('Memory Usage', `${Math.round(process.memoryUsage().rss / 1024 / 1024)} MB / ${Math.round(totalmem() / 1024 / 1024 / 1024)} GB`, true);
embed.addField('Repository', 'https://loc.sh/csdgit | Licensed under GNU Affero General Public License V3', true);
return message.channel.createMessage({ embed });
return message.channel.send({ embeds: [embed] });
} catch (err) {
return this.client.util.handleError(err, message, this);
}

View File

@ -1,5 +1,5 @@
import { Message } from 'eris';
import { Client, Command, RichEmbed } from '../class';
import { Message, MessageEmbed } from 'discord.js';
import { Client, Command } from '../class';
import { dataConversion } from '../functions';
import setRamNotification from './limits_setramnotification';
@ -16,7 +16,7 @@ export default class Limits extends Command {
public async run(message: Message) {
try {
const tiers = await this.client.db.Tier.find();
const embed = new RichEmbed();
const embed = new MessageEmbed();
embed.setTitle('Resource Limit Information');
const account = await this.client.db.Account.findOne({ userID: message.author.id });
if (account) {
@ -29,12 +29,12 @@ export default class Limits extends Command {
}
embed.setDescription(`Your resource limit is ${dataConversion(tier.resourceLimits?.ram * 1024 * 1024) ?? '0 B'}.\n${msg}`);
}
embed.setFooter(this.client.user.username, this.client.user.avatarURL);
embed.setFooter(this.client.user.username, this.client.user.avatarURL());
embed.setTimestamp();
for (const tier of tiers.sort((a, b) => a.id - b.id)) {
embed.addField(`Tier ${tier.id}`, `**RAM:** ${dataConversion(tier.resourceLimits?.ram * 1024 * 1024) ?? '0 B'}\n**Storage:** ${dataConversion(tier.resourceLimits?.storage * 1024 * 1024) ?? '0 B'}`);
}
return message.channel.createMessage({ embed });
return message.channel.send({ embeds: [embed] });
} catch (error) {
return this.client.util.handleError(error, message, this);
}

View File

@ -1,11 +1,11 @@
import { Message } from 'eris';
import { Message, TextChannel } from 'discord.js';
import { Client, Command } from '../class';
export default class Limits_SetRAMNotification extends Command {
constructor(client: Client) {
super(client);
this.name = 'set-ram-notification';
this.description = 'Sets your personal perference for receiving RAM resource limit notifications. Set the limit to "-1" to disable notifications.';
this.description = 'Sets your personal preference for receiving RAM resource limit notifications. Set the limit to "-1" to disable notifications.';
this.usage = `${this.client.config.prefix}limits set-ram-notification <limit in mb>`;
this.enabled = true;
}
@ -13,16 +13,16 @@ export default class Limits_SetRAMNotification extends Command {
public async run(message: Message, args: string[]) {
try {
const account = await this.client.db.Account.findOne({ userID: message.author.id });
if (!account) return this.error(message.channel, 'You do not appear to have an account.');
if (!account) return this.error(message.channel as TextChannel, 'You do not appear to have an account.');
const tier = await this.client.db.Tier.findOne({ id: account.tier });
if (Number(args[0]) >= tier.resourceLimits.ram) return this.error(message.channel, 'You cannot set your notification limit to be set to or above your hard limit.');
if (Number(args[0]) < 0) return this.error(message.channel, 'You cannot set your notification limit to a negative number.');
if (Number(args[0]) >= tier.resourceLimits.ram) return this.error(message.channel as TextChannel, 'You cannot set your notification limit to be set to or above your hard limit.');
if (Number(args[0]) < 0) return this.error(message.channel as TextChannel, 'You cannot set your notification limit to a negative number.');
if (Number(args[0]) === 0) {
await account.updateOne({ $set: { ramLimitNotification: 0 } });
return this.success(message.channel, 'You have disabled notifications.');
return this.success(message.channel as TextChannel, 'You have disabled notifications.');
}
await account.updateOne({ $set: { ramLimitNotification: Number(args[0]) } });
return this.success(message.channel, `You will now receive notifications when you go above ${Number(args[0])} MB.`);
return this.success(message.channel as TextChannel, `You will now receive notifications when you go above ${Number(args[0])} MB.`);
} catch (error) {
return this.client.util.handleError(error, message, this);
}

View File

@ -1,4 +1,4 @@
import { Message } from 'eris';
import { Message } from 'discord.js';
import { Client, Command } from '../class';
export default class Load extends Command {

View File

@ -1,5 +1,5 @@
import moment, { unitOfTime } from 'moment';
import { Message } from 'eris';
import { Message } from 'discord.js';
import { Client, Command } from '../class';
export default class Lock extends Command {
@ -12,7 +12,7 @@ export default class Lock extends Command {
this.usage = `${this.client.config.prefix}lock [User Name | User ID/Mention] <Time> [Reason]`;
}
public async run(message: Message, args: string[]) { // eslint-disable-line
public async run(message: Message, args: string[]) {
try {
if (!args.length) 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].replace(/[<@!>]/gi, '') }] });
@ -29,7 +29,7 @@ export default class Lock extends Command {
const momentMilliseconds = moment.duration(Number(length), unit as unitOfTime.Base).asMilliseconds();
const reason = momentMilliseconds ? args.slice(2).join(' ') : args.slice(1).join(' ');
await this.client.util.createModerationLog(account.userID, message.member, 2, reason, momentMilliseconds);
await this.client.util.createModerationLog(account.userID, message.author, 2, reason, momentMilliseconds);
edit.edit(`***${this.client.stores.emojis.success} Account ${account.username} has been locked by Technician ${message.author.username}#${message.author.discriminator}.***`);
message.delete();

View File

@ -1,6 +1,5 @@
import { Message } from 'eris';
import { createPaginationEmbed } from 'eris-pagination';
import { Client, Command, RichEmbed } from '../class';
import { Message, MessageEmbed } from 'discord.js';
import { Client, Command } from '../class';
export default class Modlogs extends Command {
constructor(client: Client) {
@ -19,8 +18,8 @@ export default class Modlogs extends Command {
const query = await this.client.db.Moderation.find({ $or: [{ username: args.join(' ') }, { userID: args[0] }] });
if (!query.length) return msg.edit(`***${this.client.stores.emojis.error} Cannot locate modlogs for ${args.join(' ')}***`);
const formatted = query.sort((a, b) => a.date.getTime() - b.date.getTime()).map((log) => {
const { username, moderatorID, reason, type, date, logID } = log;
const formatted = await Promise.all(query.sort((a, b) => a.date.getTime() - b.date.getTime()).map(async (log) => {
const { username, moderatorID, type, date, reason, logID } = log;
let name: string;
switch (type) {
default: name = 'Generic'; break;
@ -30,20 +29,21 @@ export default class Modlogs extends Command {
case 3: name = 'Unlock'; break;
case 4: name = 'Delete'; break;
}
const value = `**ID:** ${logID}\n**Account name:** ${username}\n**Moderator:** <@${moderatorID}>\n**Reason:** ${reason || 'Not supplied'}\n**Date:** ${date.toLocaleString('en-us')} EST`;
let value = `**ID:** ${logID}\n**Account name:** ${username}\n**Moderator:** <@${moderatorID}>\n**Reason:** ${reason || 'Not supplied'}\n**Date:** ${date.toLocaleString('en-us')} EST`;
if (value.length > 1024) value = value.replace(reason, await this.client.util.upload(reason));
const inline = true;
return { name, value, inline };
});
const users = [...new Set(query.map((log) => log.userID))].map((u) => `<@${u}>`);
}));
const users = [...new Set(query.map((log) => log.userID))].map((u) => u.toString());
const logs = this.client.util.splitFields(formatted);
const embeds = logs.map((l) => {
const embed = new RichEmbed();
const embed = new MessageEmbed();
embed.setDescription(`List of Cloud moderation logs for ${users.join(', ')}`);
embed.setAuthor('Library of Code | Cloud Services', this.client.user.avatarURL, 'https://libraryofcode.org/');
embed.setAuthor('Library of Code | Cloud Services', this.client.user.avatarURL(), 'https://libraryofcode.org/');
embed.setTitle('Cloud Modlogs/Infractions');
embed.setFooter(`Requested by ${message.author.username}#${message.author.discriminator}`, message.author.avatarURL);
embed.setFooter(`Requested by ${message.author.username}#${message.author.discriminator}`, message.author.avatarURL());
l.forEach((f) => embed.addField(f.name, f.value, f.inline));
embed.setTimestamp();
embed.setColor(3447003);
@ -51,9 +51,9 @@ export default class Modlogs extends Command {
});
if (embeds.length === 1) {
msg.edit({ content: '', embed: embeds[0] });
msg.edit({ content: null, embeds: [embeds[0]] });
} else {
createPaginationEmbed(message, embeds, {});
this.client.util.createPaginationEmbed(message, embeds);
}
return msg;
} catch (error) {

View File

@ -1,5 +1,7 @@
import { Message } from 'eris';
import { Client, Command, RichEmbed } from '../class';
import { Message, MessageEmbed, TextChannel } from 'discord.js';
import axios from 'axios';
import { Converter } from 'showdown';
import { Client, Command } from '../class';
export default class Notify extends Command {
constructor(client: Client) {
@ -17,17 +19,20 @@ export default class Notify extends Command {
const edit = await this.loading(message.channel, 'Sending notification...');
const account = await this.client.db.Account.findOne({ $or: [{ username: args[0] }, { userID: args[0].replace(/[<@!>]/gi, '') }] });
if (!account) return edit.edit(`***${this.client.stores.emojis.error} Cannot find user.***`);
const embed = new RichEmbed()
const embed = new MessageEmbed()
.setTitle('Cloud Account | Notification')
.setDescription(args.slice(1).join(' '))
.addField('Technician', `<@${message.author.id}>`, true)
.setFooter(this.client.user.username, this.client.user.avatarURL)
.setFooter(this.client.user.username, this.client.user.avatarURL())
.setTimestamp();
this.client.getDMChannel(account.userID).then((channel) => {
channel.createMessage({ embed });
this.client.users.fetch(account.userID).then((u) => {
u.send({ embeds: [embed] });
});
embed.addField('User', `${account.username} | <@${account.userID}>`, true);
this.client.createMessage('580950455581147146', { embed });
const req = await axios.get('https://loc.sh/int/directory');
const technician = req.data.find((mem) => mem.userID === message.author.id);
embed.addField('Technician', message.author.id === this.client.user.id ? 'SYSTEM' : `${message.author.username}${technician.isManager ? ' [k] ' : ' '}(<@${message.author.id}>)`, true);
const ch = this.client.channels.cache.get('580950455581147146') as TextChannel;
ch.send({ embeds: [embed] });
this.client.util.transport.sendMail({
to: account.emailAddress,
from: 'Library of Code sp-us | Cloud Services <help@libraryofcode.org>',
@ -35,7 +40,7 @@ export default class Notify extends Command {
subject: 'Notification',
html: `
<h1>Library of Code sp-us | Cloud Services</h1>
<p>${args.slice(1).join(' ')}</p>
<p>${new Converter().makeHtml(args.slice(1).join(' '))}</p>
<p><strong>Technician:</strong> ${message.author.username}</p>
<b><i>Library of Code sp-us | Support Team</i></b>

View File

@ -1,4 +1,4 @@
import { Message } from 'eris';
import { Message } from 'discord.js';
import { Client, Command } from '../class';
export default class Ping extends Command {
@ -12,8 +12,8 @@ export default class Ping extends Command {
public async run(message: Message) {
try {
const clientStart: number = Date.now();
const msg: Message = await message.channel.createMessage('🏓 Pong!');
msg.edit(`🏓 Pong!\nClient: \`${Date.now() - clientStart}ms\`\nResponse: \`${msg.createdAt - message.createdAt}ms\``);
const msg: Message = await message.channel.send('🏓 Pong!');
msg.edit(`🏓 Pong!\nClient: \`${Date.now() - clientStart}ms\`\nResponse: \`${msg.createdTimestamp - message.createdTimestamp}ms\``);
} catch (error) {
this.client.util.handleError(error, message, this);
}

View File

@ -1,4 +1,4 @@
import { Message } from 'eris';
import { Message } from 'discord.js';
import axios from 'axios';
import { Client, Command } from '../class';
@ -41,7 +41,6 @@ export default class Pull extends Command {
+ `***${this.client.stores.emojis.loading} Reinstalling dependencies...***`);
const passedPull = await updateMessage.edit(continueMessage);
let install: string;
try {
install = await this.client.util.exec('yarn install', { cwd: '/opt/CloudServices' });
@ -76,7 +75,7 @@ export default class Pull extends Command {
updatedMessage += `${this.client.stores.emojis.error} Could not upload error: ${e}`;
}
} else {
split.forEach((m) => message.channel.createMessage(`\`\`\`bash\n${m}\n\`\`\``));
split.forEach((m) => message.channel.send(`\`\`\`bash\n${m}\n\`\`\``));
}
}
this.client.buildError = true;

View File

@ -1,4 +1,4 @@
import { Message } from 'eris';
import { Message } from 'discord.js';
import { Client, Command } from '../class';
export default class ResetPassword extends Command {
@ -25,14 +25,13 @@ export default class ResetPassword extends Command {
await this.client.util.exec(`echo '${account.username}:${tempPass}@' | chpasswd && chage -d0 ${account.username}`);
let completeMessage = `${this.client.stores.emojis.success} ***Password for ${account.username} reset to \`${tempPass}@\`***`;
const dmChannel = await this.client.getDMChannel(account.userID);
const dmChannel = await this.client.users.fetch(account.userID);
try {
await dmChannel.createMessage(`We received a password reset request from you, your new password is \`${tempPass}@\`.\n`
await dmChannel.send(`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;
completeMessage += '\n*Unable to DM user*';
}
return msg.edit(completeMessage);
} catch (error) {

View File

@ -1,4 +1,4 @@
import { Message } from 'eris';
import { Message } from 'discord.js';
import { Client, Command } from '../class';
export default class Restart extends Command {
@ -6,7 +6,7 @@ export default class Restart extends Command {
super(client);
this.name = 'restart';
this.description = 'Restart the bot';
this.permissions = { users: ['253600545972027394', '278620217221971968'] };
this.permissions = { users: ['253600545972027394', '278620217221971968', '143414786913206272'] };
this.enabled = true;
}

View File

@ -1,4 +1,4 @@
import { Message } from 'eris';
import { Message } from 'discord.js';
import { Client, Command } from '../class';
import SetLimit_RAM from './setlimit_ram';

View File

@ -1,4 +1,4 @@
import { Message } from 'eris';
import { Message } from 'discord.js';
import { Client, Command } from '../class';
export default class SetLimit_RAM extends Command {

View File

@ -1,7 +1,7 @@
import moment from 'moment';
import { Message } from 'eris';
import os, { totalmem } from 'os';
import { Client, Command, RichEmbed } from '../class';
import { Message, MessageEmbed } from 'discord.js';
import os from 'os';
import { Client, Command } from '../class';
import { dataConversion } from '../functions';
export default class SysInfo extends Command {
@ -14,21 +14,21 @@ export default class SysInfo extends Command {
public async run(message: Message) {
const availableMemory: string = await this.client.util.exec('free -b');
const usedMemory = dataConversion(totalmem() - Number(availableMemory.split('\n')[1].split(' ').slice(-1)[0]));
const usedMemory = dataConversion(os.totalmem() - Number(availableMemory.split('\n')[1].split(' ').slice(-1)[0]));
const date = new Date();
date.setMilliseconds(-(moment.duration(os.uptime(), 's').asMilliseconds()));
const embed = new RichEmbed();
const embed = new MessageEmbed();
embed.setTitle('System Information & Statistics');
embed.addField('Hostname', os.hostname(), true);
embed.addField('Uptime', `${moment.duration(os.uptime(), 's').humanize()} | Last restart was on ${moment(date).format('dddd, MMMM Do YYYY, h:mm:ss A')} EST`, true);
embed.addField('CPU', `${os.cpus()[0].model} ${os.cpus()[0].speed / 1000}GHz | ${os.cpus().length} Cores | ${os.arch()}`, true);
embed.addField('Load Average (last 15 minutes)', os.loadavg()[2].toFixed(3), true);
embed.addField('Memory/RAM', `${usedMemory} / ${dataConversion(totalmem())}`, true);
embed.addField('Memory/RAM', `${usedMemory} / ${dataConversion(os.totalmem())}`, true);
embed.addField('Network Interfaces (IPv4)', os.networkInterfaces().enp0s3.filter((r) => r.family === 'IPv4')[0].address, true);
// embed.addField('Network Interfaces (IPv6)', os.networkInterfaces().enp0s3.filter((r) => r.family === 'IPv6')[0].address.replace(/:/gi, '\:'), true); // eslint-disable-line
embed.setFooter(this.client.user.username, this.client.user.avatarURL);
embed.setFooter(this.client.user.username, this.client.user.avatarURL());
embed.setTimestamp();
message.channel.createMessage({ embed });
message.channel.send({ embeds: [embed] });
}
}

View File

@ -1,4 +1,4 @@
import { Message } from 'eris';
import { Message } from 'discord.js';
import { Client, Command } from '../class';
import SystemD_Linger from './systemd_linger';
import SystemD_Status from './systemd_status';

View File

@ -1,5 +1,5 @@
/* eslint-disable consistent-return */
import { Message } from 'eris';
import { Message } from 'discord.js';
import { Client, Command } from '../class';
export default class SystemdD_Linger extends Command {

View File

@ -1,4 +1,4 @@
import { Message } from 'eris';
import { Message } from 'discord.js';
import { Client, Command } from '../class';
export default class SystemD_Restart extends Command {

View File

@ -1,4 +1,4 @@
import { Message } from 'eris';
import { Message } from 'discord.js';
import { Client, Command } from '../class';
export default class SystemD_Start extends Command {

View File

@ -1,5 +1,5 @@
import { Message } from 'eris';
import { Client, Command, RichEmbed } from '../class';
import { Message, MessageEmbed } from 'discord.js';
import { Client, Command } from '../class';
export default class SystemD_Status extends Command {
constructor(client: Client) {
@ -22,12 +22,12 @@ export default class SystemD_Status extends Command {
if (err.toString().includes('could not be found')) return this.error(message.channel, 'The service name you provided doesn\'t exist.');
return this.error(message.channel, err.toString());
}
const embed = new RichEmbed();
const embed = new MessageEmbed();
embed.setTitle(`SystemD Status | ${args[0]}`);
embed.setDescription(`\`\`\`sh\n${cmd}\n\`\`\``);
embed.setFooter(this.client.user.username, this.client.user.avatarURL);
embed.setFooter(this.client.user.username, this.client.user.avatarURL());
embed.setTimestamp();
return message.channel.createMessage({ embed });
return message.channel.send({ embeds: [embed] });
} catch (err) {
return this.client.util.handleError(err, message, this);
}

View File

@ -1,4 +1,4 @@
import { Message } from 'eris';
import { Message } from 'discord.js';
import { Client, Command } from '../class';
export default class SystemD_Stop extends Command {

View File

@ -1,5 +1,5 @@
import { Message } from 'eris';
import { Client, Command, RichEmbed } from '../class';
import { Message, MessageEmbed, TextChannel } from 'discord.js';
import { Client, Command } from '../class';
export default class Tier extends Command {
constructor(client: Client) {
@ -18,8 +18,8 @@ export default class Tier extends Command {
const account = await this.client.db.Account.findOne({ $or: [{ username: args[0] }, { userID: args[0].replace(/[<@!>]/gi, '') }] });
if (!account) return edit.edit(`***${this.client.stores.emojis.error} Cannot find user.***`);
if (account.root) return edit.edit(`***${this.client.stores.emojis.error} Permission denied.***`);
if (Number.isNaN(Number(args[1]))) return edit.edit(`***${this.client.stores.emojis.error} The tier you provided is not a valid number. It should be between 1 and 3.***`);
if (Number(args[1]) > 3 || Number(args[1]) < 1) return edit.edit(`***${this.client.stores.emojis.error} You can only choose a Tier between 1 and 3.***`);
if (Number.isNaN(Number(args[1]))) return edit.edit(`***${this.client.stores.emojis.error} The tier you provided is not a valid number. It should be between 0 and 3.***`);
if (Number(args[1]) > 3 || Number(args[1]) < 0) return edit.edit(`***${this.client.stores.emojis.error} You can only choose a Tier between 0 and 3.***`);
message.delete();
const tier = await this.client.db.Tier.findOne({ id: Number(args[1]) });
if (account.ramLimitNotification !== -1) {
@ -28,16 +28,18 @@ export default class Tier extends Command {
await account.updateOne({ $set: { tier: Number(args[1]) } });
}
edit.edit(`***${this.client.stores.emojis.success} Tier for ${account.username} has been changed to ${args[1]}.***`);
const embed = new RichEmbed();
const embed = new MessageEmbed();
embed.setTitle('Cloud Account | Tier Change');
embed.setColor('#0099ff');
embed.addField('User', `${account.username} | <@${account.userID}>`, true);
embed.addField('Technician', `<@${message.author.id}>`, true);
embed.addField('Technician', await this.client.util.getTechnicianName(message.author), true);
embed.addField('Old Tier -> New Tier', `${account.tier} -> ${args[1]}`, true);
embed.setFooter(this.client.user.username, this.client.user.avatarURL);
embed.setFooter(this.client.user.username, this.client.user.avatarURL());
embed.setTimestamp();
await this.client.util.sendMessageToUserTerminal(account.username, `A technician has changed your tier to ${args[1]}`).catch(() => { });
this.client.createMessage('580950455581147146', { embed }); return this.client.getDMChannel(account.userID).then((channel) => channel.createMessage({ embed })).catch();
const ch = this.client.channels.cache.get('580950455581147146') as TextChannel;
ch.send({ embeds: [embed] });
return this.client.users.fetch(account.userID).then((u) => u.send({ embeds: [embed] })).catch();
} catch (error) {
return this.client.util.handleError(error, message, this);
}

View File

@ -1,4 +1,4 @@
import { Message } from 'eris';
import { Message } from 'discord.js';
import { Client, Command } from '../class';
export default class Unban extends Command {
@ -16,7 +16,7 @@ export default class Unban extends Command {
public async run(message: Message, args: string[]) {
try {
if (!args[1]) return this.client.commands.get('help').run(message, [this.name]);
const msg = await message.channel.createMessage(`${this.client.stores.emojis.loading} ***Unbanning IP...***`);
const msg = await message.channel.send(`${this.client.stores.emojis.loading} ***Unbanning IP...***`);
try {
await this.client.util.exec(`sudo fail2ban-client set ${args[0]} unbanip ${args[1]}`);
} catch (error) {

View File

@ -1,4 +1,4 @@
import { Message } from 'eris';
import { Message } from 'discord.js';
import { Client, Command } from '../class';
export default class Unlock extends Command {
@ -21,7 +21,7 @@ export default class Unlock extends Command {
await this.client.util.exec(`unlock ${account.username}`);
await account.updateOne({ locked: false });
await this.client.util.createModerationLog(account.userID, message.member, 3, args.slice(1).join(' '));
await this.client.util.createModerationLog(account.userID, message.author, 3, args.slice(1).join(' '));
message.delete();
edit.edit(`***${this.client.stores.emojis.success} Account ${account.username} has been unlocked by Technician ${message.author.username}#${message.author.discriminator}.***`);
} catch (error) {

93
src/commands/usermod.ts Normal file
View File

@ -0,0 +1,93 @@
import { Message } from 'discord.js';
import { rename } from 'fs/promises';
import { Client, Command } from '../class';
import { LINUX_USERNAME_REGEX } from '../class/AccountUtil';
export default class Usermod extends Command {
constructor(client: Client) {
super(client);
this.name = 'usermod';
this.description = 'Modifies properties of a user\'s cloud account';
this.usage = `${this.client.config.prefix}usermod [account] [property: username | email] [value]`;
this.permissions = { roles: ['662163685439045632', '701454780828221450'] };
this.enabled = true;
}
public async run(message: Message, args: string[]) {
if (!args.length) return this.client.commands.get('help').run(message, [this.name]);
const [, property, value] = args;
const account = await this.client.db.Account.findOne({ $or: [{ username: args[0] }, { userID: args[0] }] });
if (!account) return this.error(message.channel, 'Cannot find user.');
if (account.root || account.username === 'matthew') return this.error(message.channel, 'You cannot modify properties of root accounts.');
switch (property) {
case 'email': {
if (value === account.emailAddress) return this.error(message.channel, 'The new email address cannot be the same as the old one.');
if (await this.client.db.Account.exists({ emailAddress: value })) return this.error(message.channel, 'An account with this email address already exists.');
if (!this.client.util.isValidEmail(value)) return this.error(message.channel, 'The supplied email address is invalid.');
const modifyingPropertyResponse = await this.loading(message.channel, `Modifying \`${property}\` of \`${account.username}\`'s account...`);
await this.client.commands.get('notify')
.run(message, [account.username, ...`Your email address has been changed from ${account.emailAddress} to ${value}.`.split(' ')]);
await account.updateOne({ emailAddress: value });
modifyingPropertyResponse.delete();
this.success(message.channel, `Successfully updated \`${account.username}\`'s email address.`);
break;
}
case 'username': {
if (value === account.username) return this.error(message.channel, 'The username cannot be the same as the old one.');
if (await this.client.db.Account.exists({ username: value })) return this.error(message.channel, 'An account with this username already exists.');
if (!LINUX_USERNAME_REGEX.test(value)) return this.error(message.channel, 'Please supply a valid username.');
if (value === 'root') return this.error(message.channel, 'This username is unavailable.');
const modifyingPropertyResponse = await this.loading(message.channel, `Modifying \`${property}\` of \`${account.username}\`'s account...`);
try {
await this.client.commands.get('notify')
.run(message, [account.username, ...`Changing your username from \`${account.username}\` to \`${value}\`.`.split(' ')]);
if (!account.locked) await this.client.util.exec(`lock ${account.username}`);
await this.client.util.exec(`usermod -l ${value} ${account.username}`);
await rename(account.homepath, `/home/${value}`);
await this.client.util.exec(`usermod -d /home/${value} ${value}`);
await this.client.util.exec(`groupmod -n ${value} ${account.username}`);
if (!account.locked) await this.client.util.exec(`unlock ${value}`);
await account.updateOne({
username: value,
homepath: `/home/${value}`,
});
await this.client.db.Moderation.updateMany(
{
username: account.username,
date: { $gt: account.createdAt },
},
{ username: value },
);
await this.client.commands.get('notify')
.run(message, [value, ...`Your username has been successfully changed. Remember to use \`ssh ${value}@cloud.libraryofcode.org\` when logging in.`.split(' ')]);
} catch (error) {
if (!account.locked) await this.client.util.exec(`unlock ${account.username}`);
await this.client.commands.get('notify')
.run(message, [account.username, ...'Your username change was unsuccessful. Please contact a Technician for more details.'.split(' ')]);
await this.client.util.handleError(error);
return this.error(message.channel, 'Failed to modify username. Please check <#595788220764127272> for more information.');
}
modifyingPropertyResponse.delete();
this.success(message.channel, 'Successfully modified username.');
break;
}
default:
this.error(message.channel, 'Please specify a valid option.');
break;
}
}
}

View File

@ -1,7 +1,6 @@
/* eslint-disable no-await-in-loop */
import { Message } from 'eris';
import { createPaginationEmbed } from 'eris-pagination';
import { Client, Command, RichEmbed } from '../class';
import { Message, MessageEmbed } from 'discord.js';
import { Client, Command } from '../class';
export default class Users extends Command {
constructor(client: Client) {
@ -47,10 +46,10 @@ export default class Users extends Command {
const data = this.client.util.splitFields(embedFields);
const embeds = data.map((l) => {
const embed = new RichEmbed();
embed.setAuthor('Library of Code | Cloud Services', this.client.user.avatarURL, 'https://libraryofcode.org/');
const embed = new MessageEmbed();
embed.setAuthor('Library of Code | Cloud Services', this.client.user.avatarURL(), 'https://libraryofcode.org/');
embed.setTitle('Cloud Accounts');
embed.setFooter(`Requested by ${message.author.username}#${message.author.discriminator}`, message.author.avatarURL);
embed.setFooter(`Requested by ${message.author.username}#${message.author.discriminator}`, message.author.avatarURL());
l.forEach((f) => embed.addField(f.name, f.value, true));
embed.setTimestamp();
embed.setColor(3447003);
@ -58,10 +57,10 @@ export default class Users extends Command {
});
if (embeds.length === 1) {
msg.edit({ content: '', embed: embeds[0] });
msg.edit({ content: null, embeds: [embeds[0]] });
} else {
msg.delete();
createPaginationEmbed(message, embeds, {});
this.client.util.createPaginationEmbed(message, embeds);
}
return msg;
} catch (error) {

View File

@ -1,4 +1,5 @@
import { Message } from 'eris';
import { Message } from 'discord.js';
import { Converter } from 'showdown';
import { Client, Command } from '../class';
export default class Warn extends Command {
@ -18,7 +19,7 @@ export default class Warn extends Command {
const account = await this.client.db.Account.findOne({ $or: [{ username: args[0] }, { userID: args[0].replace(/[<@!>]/gi, '') }] });
if (!account) return edit.edit(`***${this.client.stores.emojis.error} Cannot find user.***`);
if (account.root) return edit.edit(`***${this.client.stores.emojis.error} Permission denied.***`);
await this.client.util.createModerationLog(account.userID, message.member, 1, args.slice(1).join(' '));
await this.client.util.createModerationLog(account.userID, message.author, 1, args.slice(1).join(' '));
message.delete();
edit.edit(`***${this.client.stores.emojis.success} Account ${account.username} has been warned by Technician ${message.author.username}#${message.author.discriminator}.***`);
await this.client.util.sendMessageToUserTerminal(account.username, `WARNING FROM TECHNICIAN: ${args.slice(1).join(' ')}`).catch(() => { });
@ -30,7 +31,7 @@ export default class Warn extends Command {
html: `
<h1>Library of Code sp-us | Cloud Services</h1>
<p>Your account has received an official warning from a Moderator. Please get the underlying issue resolved to avoid <i>possible</i> moderative action.</p>
<p><strong>Reason:</strong> ${args.slice(1).join(' ') ? args.slice(1).join(' ') : 'Not Specified'}</p>
<p><strong>Reason:</strong> ${args.slice(1).length ? new Converter().makeHtml(args.slice(1).join(' ')) : 'Not Specified'}</p>
<p><strong>Technician:</strong> ${message.author.username}</p>
<b><i>Library of Code sp-us | Support Team</i></b>

View File

@ -1,6 +1,6 @@
import moment from 'moment';
import { Message, GuildTextableChannel, Member, Role } from 'eris';
import { Client, Command, Report, RichEmbed } from '../class';
import { Message, TextChannel, Role, MessageEmbed, GuildMember } from 'discord.js';
import { Client, Command } from '../class';
import { dataConversion } from '../functions';
import { AccountInterface } from '../models';
@ -16,22 +16,26 @@ export default class Whois extends Command {
public fullRoles = ['662163685439045632', '701454780828221450'];
public IP_REGEX = /((^\s*((([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]))\s*$)|(^\s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(%.+)?\s*$))/g
public IP_REGEX = /((^\s*((([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]))\s*$)|(^\s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(%.+)?\s*$))/g;
public async run(message: Message<GuildTextableChannel>, args: string[]) {
public IP_V4_REGEX = /^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$/
public IP_V6_REGEX = /(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))/
public async run(message: Message, args: string[]) {
try {
let full = false;
let account: AccountInterface;
if (args[1] === '--full' && this.fullRoles.some((r) => message.member.roles.includes(r) || message.author.id === '554168666938277889')) full = true;
if (args[1] === '--full' && this.fullRoles.some((r) => message.member.roles.cache.has(r) || message.author.id === '554168666938277889')) full = true;
const user = args[0] || message.author.id;
if (full) account = await this.client.db.Account.findOne({ $or: [{ username: user }, { userID: user }, { emailAddress: user }, { supportKey: user.toUpperCase() }, { referralCode: args[0] }] });
else account = await this.client.db.Account.findOne({ $or: [{ username: user }, { userID: user }] });
if (!account) return this.error(message.channel, 'Account not found.');
if (!account) return this.error(message.channel as TextChannel, 'Account not found.');
const thumbnail = this.client.users.get(account.userID)?.avatarURL || message.channel.guild.iconURL;
const thumbnail = (await this.client.users.fetch(account.userID))?.avatarURL() || message.guild.iconURL();
const embed = new RichEmbed();
const embed = new MessageEmbed();
embed.setTitle('Account Information');
embed.setThumbnail(thumbnail);
if (full) await this.full(account, embed, message.member);
@ -42,33 +46,34 @@ export default class Whois extends Command {
if (account.locked) details += '__This account is currently locked.__\n';
switch (true) {
case account.permissions.director:
details += 'This account belongs to a Director.\n';
role = message.member.guild.roles.get('662163685439045632');
details += 'This account belongs to a Manager.\n';
role = await message.member.guild.roles.fetch('662163685439045632');
break;
case account.permissions.technician:
details += 'This account belongs to a Technician.\n';
role = message.member.guild.roles.get('701454780828221450');
role = await message.member.guild.roles.fetch('701454780828221450');
break;
case account.permissions.staff:
details += 'This account belongs to a Staff member.\n';
role = message.member.guild.roles.get('453689940140883988');
role = await message.member.guild.roles.fetch('453689940140883988');
break;
default:
role = message.member.guild.roles.get(message.member.guild.id);
role = await message.member.guild.roles.fetch(message.member.guild.id);
break;
}
if (account.root) details += '**This account has root/administrative privileges.**\n';
if (account.root) details += '**This account has administrative privileges.**\n';
embed.setColor(role.color || 0x36393f);
if (details) embed.addField('Additional Details', details, true);
embed.setTimestamp();
return message.channel.createMessage({ embed });
embed.setFooter('Library of Code | Cloud Services', message.guild.iconURL());
return message.channel.send({ embeds: [embed] });
} catch (error) {
return this.client.util.handleError(error, message, this);
}
}
public async full(account: AccountInterface, embed: RichEmbed, member: Member) {
public async full(account: AccountInterface, embed: MessageEmbed, member: GuildMember) {
const [cpuUsage, data, fingerInformation, chage, memory] = await Promise.all([
this.client.util.exec(`top -b -n 1 -u ${account.username} | awk 'NR>7 { sum += $9; } END { print sum; }'`),
this.client.redis.get(`storage-${account.username}`),
@ -76,33 +81,34 @@ export default class Whois extends Command {
this.client.util.exec(`chage -l ${account.username}`),
this.client.util.exec(`memory ${account.username}`),
]);
const finger = !member.roles.includes('662163685439045632') ? fingerInformation.replace(this.IP_REGEX, '[MASKED IP ADDRRESS]') : fingerInformation;
const finger = !member.roles.cache.has('662163685439045632') ? fingerInformation.replace(this.IP_REGEX, '[MASKED IP ADDRESS]') : fingerInformation;
embed.setDescription(`${finger}\n${chage}`);
embed.addField('Username', `${account.username} | <@${account.userID}>`, true);
embed.addField('ID', account.userID, true);
embed.addField('Username', `${account.username} <<@${account.userID}>>`, true);
embed.addField('Discord ID', account.userID, true);
embed.addField('Email Address', account.emailAddress, true);
embed.addField('Tier', String(account.tier), true);
embed.addField('Support Key', account.supportKey, true);
embed.addField('Referral Code & Total', `${account.referralCode} | ${account.totalReferrals}`, true);
embed.addField('Created By', this.client.users.get(account.createdBy) ? `<@${this.client.users.get(account.createdBy).id}>` : 'SYSTEM', true);
embed.addField('Created By', (await this.client.util.getTechnicianName(await this.client.users.fetch(account.createdBy))), true);
embed.addField('Created At', moment(account.createdAt).format('dddd, MMMM Do YYYY, h:mm:ss A'), true);
embed.addField('CPU Usage', `${cpuUsage.split('\n')[0] || '0'}%`, true);
embed.addField('Memory', dataConversion(Number(memory) * 1000), true);
embed.addField('Storage', data ? dataConversion(Number(data)) : 'N/A', true);
}
public async default(account: AccountInterface, embed: RichEmbed) {
public async default(account: AccountInterface, embed: MessageEmbed) {
const [cpuUsage, data, memory] = await Promise.all([
this.client.util.exec(`top -b -n 1 -u ${account.username} | awk 'NR>7 { sum += $9; } END { print sum; }'`),
this.client.redis.get(`storage-${account.username}`),
this.client.util.exec(`memory ${account.username}`),
]);
embed.addField('Username', `${account.username} | <@${account.userID}>`, true);
embed.addField('ID', account.userID, true);
embed.setDescription('*CPU Usage and Memory are fetched in real-time, storage information is cached.*');
embed.addField('Username', `${account.username} <<@${account.userID}>>`, true);
embed.addField('Discord ID', account.userID, true);
embed.addField('Tier', String(account.tier), true);
embed.addField('Created By', this.client.users.get(account.createdBy) ? `<@${this.client.users.get(account.createdBy).id}>` : 'SYSTEM', true);
embed.addField('Created By', (await this.client.util.getTechnicianName(await this.client.users.fetch(account.createdBy), 2)), true);
embed.addField('Created At', moment(account.createdAt).format('dddd, MMMM Do YYYY, h:mm:ss A'), true);
embed.addField('CPU Usage', `${cpuUsage.split('\n')[0] || '0'}%`, true);
embed.addField('Memory', dataConversion(Number(memory) * 1000), true);

View File

@ -1,5 +1,5 @@
import { Message, TextChannel } from 'eris';
import { Client, Event, RichEmbed } from '../class';
import { Message, TextChannel, MessageEmbed } from 'discord.js';
import { Client, Event } from '../class';
export default class extends Event {
public client: Client
@ -10,9 +10,6 @@ export default class extends Event {
this.event = 'messageCreate';
}
public info(message: Message) {
}
public async run(message: Message) {
try {
if (message.author.bot && message.author.id !== '554168666938277889') return;
@ -28,8 +25,9 @@ export default class extends Event {
let hasRolePerms: boolean = false;
if (resolved.cmd.permissions.roles) {
for (const role of resolved.cmd.permissions.roles) {
if (message.member && message.member.roles.includes(role)) {
hasRolePerms = true; break;
if (message.member && message.member.roles.cache.has(role)) {
hasRolePerms = true;
break;
}
}
}
@ -37,9 +35,15 @@ export default class extends Event {
hasUserPerms = true;
hasRolePerms = true;
}
if (message.author.id === '554168666938277889') { hasUserPerms = true; hasRolePerms = true; }
if (message.author.id === '554168666938277889') {
hasUserPerms = true;
hasRolePerms = true;
}
if (!hasRolePerms && !hasUserPerms) return;
if (!resolved.cmd.enabled) { message.channel.createMessage(`***${this.client.stores.emojis.error} This command has been disabled***`); return; }
if (!resolved.cmd.enabled) {
message.channel.send(`***${this.client.stores.emojis.error} This command has been disabled***`);
return;
}
await resolved.cmd.run(message, resolved.args);
} catch (error) {
this.client.util.handleError(error, message);

View File

@ -59,13 +59,6 @@ func main() {
fmt.Printf("Connected to Redis [GO]\n")
HandleError(err, 1)
/*for {
fmt.Printf("Calling handler func [GO]\n")
if status == false {
handler(*config)
time.Sleep(1000000 * time.Millisecond)
}
}*/
handler(*config)
}

View File

@ -1,60 +1,72 @@
/* eslint-disable no-await-in-loop */
import { Client, RichEmbed } from '../class';
import { MessageEmbed, TextChannel } from 'discord.js';
import { Client } from '../class';
export default function checkStaffStatus(client: Client) {
setInterval(async () => {
const accounts = await client.db.Account.find();
for (const acc of accounts) {
const tier3 = await client.db.Tier.findOne({ id: 3 });
let user = client.guilds.get('446067825673633794').members.get(acc.userID);
let user = client.guilds.cache.get('446067825673633794').members.cache.get(acc.userID);
try {
if (!user) user = await client.guilds.get('446067825673633794').getRESTMember(acc.userID);
if (!user) user = await client.guilds.cache.get('446067825673633794').members.fetch(acc.userID);
} catch (error) {
continue; // eslint-disable-line no-continue
}
if (!acc.permissions.director && user.roles.includes('662163685439045632')) {
if (!acc.permissions.director && user.roles.cache.has('662163685439045632')) {
await client.db.Account.updateOne({ username: acc.username }, { $set: { 'permissions.director': true } });
if (acc.ramLimitNotification !== -1) {
await client.db.Account.updateOne({ username: acc.username }, { $set: { ramLimitNotification: tier3.resourceLimits.ram - 20 } });
}
}
if (!acc.permissions.technician && user.roles.includes('701454780828221450')) {
if (!acc.permissions.technician && user.roles.cache.has('701454780828221450')) {
await client.db.Account.updateOne({ username: acc.username }, { $set: { 'permissions.technician': true } });
if (acc.ramLimitNotification !== -1) {
await client.db.Account.updateOne({ username: acc.username }, { $set: { ramLimitNotification: tier3.resourceLimits.ram - 20 } });
}
}
if (!acc.permissions.staff && user.roles.includes('446104438969466890')) {
if (!acc.permissions.staff && user.roles.cache.has('446104438969466890')) {
await client.db.Account.updateOne({ username: acc.username }, { $set: { 'permissions.staff': true } });
if (acc.ramLimitNotification !== -1) {
await client.db.Account.updateOne({ username: acc.username }, { $set: { ramLimitNotification: tier3.resourceLimits.ram - 20 } });
}
}
if (!acc.permissions.intern && user.roles.cache.has('701481967149121627')) {
await client.db.Account.updateOne({ username: acc.username }, { $set: { 'permissions.intern': true } });
if (acc.ramLimitNotification !== -1) {
await client.db.Account.updateOne({ username: acc.username }, { $set: { ramLimitNotification: tier3.resourceLimits.ram - 20 } });
}
}
if (acc.permissions.director && !user.roles.includes('662163685439045632')) {
if (acc.permissions.director && !user.roles.cache.has('662163685439045632')) {
await client.db.Account.updateOne({ username: acc.username }, { $set: { 'permissions.director': false } });
}
if (acc.permissions.technician && !user.roles.includes('701454780828221450')) {
if (acc.permissions.technician && !user.roles.cache.has('701454780828221450')) {
await client.db.Account.updateOne({ username: acc.username }, { $set: { 'permissions.technician': false } });
}
if (acc.permissions.staff && !user.roles.includes('446104438969466890')) {
if (acc.permissions.staff && !user.roles.cache.has('446104438969466890')) {
await client.db.Account.updateOne({ username: acc.username }, { $set: { 'permissions.staff': false } });
}
if (acc.permissions.intern && !user.roles.cache.has('701481967149121627')) {
await client.db.Account.updateOne({ username: acc.username }, { $set: { 'permissions.intern': false } });
}
if (acc.permissions.staff && acc.tier < 3) {
if ((acc.permissions.staff || acc.permissions.intern || acc.permissions.technician || acc.permissions.director || user.roles.cache.has('858049948401401866')) && (acc.tier < 3 && acc.tier > 0)) {
await client.db.Account.updateOne({ username: acc.username }, { $set: { tier: 3 } });
const embed = new RichEmbed();
const embed = new MessageEmbed();
embed.setTitle('Cloud Account | Tier Change');
embed.setColor('#0099ff');
embed.addField('User', `${acc.username} | <@${acc.userID}>`, true);
embed.addField('Moderator', `<@${client.user.id}>`, true);
embed.addField('Technician', 'SYSTEM', true);
embed.addField('Old Tier -> New Tier', `${acc.tier} -> 3`, true);
embed.setFooter(client.user.username, client.user.avatarURL);
embed.addField('Reason', 'T3 Staff Benefit', true);
embed.setFooter(client.user.username, client.user.avatarURL());
embed.setTimestamp();
client.createMessage('580950455581147146', { embed });
client.getDMChannel(acc.userID).then((chan) => {
chan.createMessage('***Your account has automatically been upgraded to Tier 3 since you are a Staff member.***');
const ch = await client.channels.fetch('580950455581147146') as TextChannel;
ch.send({ embeds: [embed] });
client.users.fetch(acc.userID).then((chan) => {
chan.send('***Your CS Account tier has been upgraded to `Tier 3` automatically as apart of your staff benefit.***');
});
}
}

View File

@ -1,7 +1,8 @@
/* eslint-disable no-useless-escape */
/* eslint-disable no-continue */
/* eslint-disable no-await-in-loop */
import { Client, RichEmbed } from '../class';
import { MessageEmbed, TextChannel } from 'discord.js';
import { Client } from '../class';
import { Tiers } from '../models';
const channelID = '691824484230889546';
@ -32,15 +33,16 @@ export default function memory(client: Client) {
client.signale.info(`RAM Hard Limit Reached | ${acc.username} | ${memoryConversion}/${userLimits.hard} MB`);
await client.util.sendMessageToUserTerminal(acc.username, 'REACHED RAM LIMIT; SENDING KILL SIGNAL');
client.util.exec(`killall -9 -u ${acc.username}`);
const embed = new RichEmbed();
const embed = new MessageEmbed();
embed.setTitle('Resource Enforcement Notification');
embed.setDescription('Someone has reached the (hard) resource limit for their tier on RAM. The system has automatically killed all of their processes.');
embed.addField('User', `${acc.username} | <@${acc.userID}> | ${acc.userID}`, true);
embed.addField('Tier', String(acc.tier), true);
embed.addField('Memory Usage', `${String(memoryConversion)} MB`, true);
embed.addField('Memory Limit', `${String(userLimits.hard)} MB`, true);
client.createMessage(channelID, { embed });
client.util.createModerationLog(acc.userID, client.guilds.get('446067825673633794').members.get(client.user.id), 1, `You have exceeded your resource limit of '${String(userLimits.hard)} MB'. Any process running on your user account has been sent a STOP/KILL signal. If you have any questions, please contact a Technician.`);
const ch = client.channels.cache.get(channelID) as TextChannel;
ch.send({ embeds: [embed] });
client.util.createModerationLog(acc.userID, (await (await client.guilds.fetch('446067825673633794')).members.fetch(client.user.id)).user, 1, `You have exceeded your resource limit of '${String(userLimits.hard)} MB'. Any process running on your user account has been sent a STOP/KILL signal. If you have any questions, please contact a Technician. DN/C`);
client.util.transport.sendMail({
to: acc.emailAddress,
from: 'Library of Code sp-us | Cloud Services <help@libraryofcode.org>',
@ -54,34 +56,36 @@ export default function memory(client: Client) {
<b><i>Library of Code sp-us | Support Team</i></b>
`,
});
client.createMessage(channelID, { embed });
ch.send({ embeds: [embed] });
set.delete(acc.username);
} else if ((memoryConversion >= userLimits.soft) && !set.has(acc.username)) {
client.signale.info(`RAM Soft Limit Reached | ${acc.username} | ${memoryConversion}/${userLimits.soft} MB`);
const embed = new RichEmbed();
if (client.users.get(acc.userID)) embed.setThumbnail(client.users.get(acc.userID).avatarURL);
const embed = new MessageEmbed();
const user = await client.users.fetch(acc.userID);
if (user) embed.setThumbnail(user.avatarURL());
embed.setTitle('Resource Limit Notification');
embed.setDescription('Someone has reached the (soft) resource limit for their tier on RAM.');
embed.addField('User', `${acc.username} | <@${acc.userID}> | ${acc.userID}`, true);
embed.addField('Tier', String(acc.tier), true);
embed.addField('Memory Usage', `${String(memoryConversion)} MB`, true);
embed.addField('Memory Limit', `${String(userLimits.hard)} MB`, true);
embed.setFooter(client.user.username, client.user.avatarURL);
embed.setFooter(client.user.username, client.user.avatarURL());
embed.setTimestamp();
if (acc.ramLimitNotification !== 0) {
await client.createMessage(channelID, { embed });
const ch = client.channels.cache.get(channelID) as TextChannel;
await ch.send({ embeds: [embed] });
}
if ((memoryConversion >= acc.ramLimitNotification) && (acc.ramLimitNotification !== 0)) {
const notifyEmbed = new RichEmbed()
const notifyEmbed = new MessageEmbed()
.setTitle('Cloud Account | Notification')
.setDescription(`You are about to reach your RAM resource limits, you are currently using '${String(Math.round(memoryConversion))} MB' and your limit is '${String(userLimits.hard)} MB'. Please correct your usage to avoid further action.`)
.addField('User', `${acc.username} | <@${acc.userID}>`, true)
.addField('Technician', 'SYSTEM', true)
.addField('Additional Information', 'This notification was sent by the system. You can set your notification preferences by running \`=limits set-ram-notification <preferred ram threshold in MB>\`, you can disable these notifications by running \`=limits set-ram-notification -1\`.')
.setFooter(client.user.username, client.user.avatarURL)
.setFooter(client.user.username, client.user.avatarURL())
.setTimestamp();
client.getDMChannel(acc.userID).then((channel) => {
channel.createMessage({ embed: notifyEmbed });
client.users.fetch(acc.userID).then((u) => {
u.send({ embeds: [notifyEmbed] });
});
await client.util.sendMessageToUserTerminal(acc.username, `You are about to reach your RAM resource limits, you are currently using '${String(Math.round(memoryConversion))} MB' and your limit is '${String(userLimits.hard)} MB'. Please correct your usage to avoid further action.`).catch(() => { });
client.util.transport.sendMail({
@ -96,7 +100,8 @@ export default function memory(client: Client) {
<b><i>Library of Code sp-us | Support Team</i></b>
`,
});
client.createMessage('580950455581147146', { embed: notifyEmbed });
const channel = client.channels.cache.get('580950455581147146') as TextChannel;
channel.send({ embeds: [notifyEmbed] });
}
set.add(acc.username);
}

View File

@ -1,4 +1,5 @@
/* eslint-disable no-await-in-loop */
/* eslint-disable no-unreachable */
// import fs from 'fs-extra';
import { spawn } from 'child_process';
import { Client } from '../class';

54
src/intervals/t2Checks.ts Normal file
View File

@ -0,0 +1,54 @@
/* eslint-disable no-await-in-loop */
import axios, { AxiosError } from 'axios';
import cron from 'cron';
import { MessageEmbed, TextChannel } from 'discord.js';
import { Client } from '../class';
async function checkt2(auth: string, userID: string) {
try {
const { data } = await axios({
method: 'get',
url: `https://eds.libraryofcode.org/cs/t2rev/?userID=${userID}&auth=${auth}`,
});
return {
status: 'SUCCESS',
decision: data.decision,
id: data.id,
processedBy: data.processedBy,
token: data.token,
};
} catch (err) {
const error = <AxiosError>err;
if (error.response?.status === 404 || error.response.status === 400 || error.response.status === 401) return { id: 'N/A', processedBy: 'N/A', status: 'CLIENT_ERROR', decision: 'PRE-DECLINED' };
return { id: 'N/A', processedBy: 'N/A', status: 'SERVER_ERROR', decision: 'PRE-DECLINED' };
}
}
export default async function t2checkCron(client: Client) {
const checkTier2StatusJob = new cron.CronJob('13 21 * * *', async () => {
const users = await client.db.Account.find({ tier: 2 }).lean();
for (const user of users) {
const check = await checkt2(client.config.internalKey, user.userID);
const member = client.guilds.cache.get('446067825673633794').members.cache.get(user.userID);
if (member.roles.cache.has('585600289747369987') || member.roles.cache.has('858049948401401866') || member.roles.cache.has('995554888836718612')) continue;
if (check.decision === 'DECLINED') {
const embed = new MessageEmbed();
embed.setTitle('Cloud Account | Tier Change');
embed.setColor('#0099ff');
embed.addField('User', `${user.username} | <@${user.userID}>`, true);
embed.addField('Technician', 'SYSTEM', true);
embed.addField('Old Tier -> New Tier', `${user.tier} -> 1`, true);
embed.setFooter(client.user.username, client.user.avatarURL());
embed.setTimestamp();
const ch = client.channels.cache.get('580950455581147146') as TextChannel;
await client.db.Account.updateOne({ userID: user.userID }, { $set: { tier: 1 } });
ch.send({ embeds: [embed] });
return client.users.fetch(user.userID).then((u) => u.send({ embeds: [embed], content: `__**Tier 2 Account Review**__\n\nHello, <@${user.userID}>.\nWe periodically run automatic account review inquiries for users with Tier 2. This means we request an account review from EDS to determine if you're still eligible to keep Tier 2.\nUnfortunately, according to EDS' records, you are currently ineligible for Tier 2. Because of this, we're going to automatically revoke your Tier 2 status. You can re-apply to Tier 2 at any time if you feel that you meet the requirements. If you have any questions, or if you believe this may be a mistake, please contact our support team as soon as possible. Thank you.` })).catch();
}
}
});
checkTier2StatusJob.start();
}

View File

@ -13,6 +13,7 @@ export interface AccountInterface extends Document {
referralCode: string,
totalReferrals: number,
permissions: {
intern: boolean,
staff: boolean,
technician: boolean,
director: boolean,
@ -38,6 +39,7 @@ const Account = new Schema<AccountInterface>({
referralCode: String,
totalReferrals: Number,
permissions: {
intern: Boolean,
staff: Boolean,
technician: Boolean,
director: Boolean,

View File

@ -11,6 +11,7 @@ export interface DomainInterface extends Document {
key: string
},
enabled: true
created: Date,
}
const Domain = new Schema<DomainInterface>({
@ -19,6 +20,7 @@ const Domain = new Schema<DomainInterface>({
port: Number,
x509: { cert: String, key: String },
enabled: Boolean,
created: Date,
});
export default model<DomainInterface>('Domain', Domain);

View File

@ -1,10 +1,13 @@
{
"compilerOptions": {
/* Basic Options */
// "incremental": true, /* Enable incremental compilation */
"target": "ES2017", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */
"target": "ES2019", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
"lib": ["ES2019.Object", "ES2020.Promise"], /* Specify library files to be included in the compilation. */
"lib": [
"ES2019.Object",
"ES2020.Promise",
"es2015.promise"
], /* Specify library files to be included in the compilation. */
// "allowJs": true, /* Allow javascript files to be compiled. */
// "checkJs": true, /* Report errors in .js files. */
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
@ -21,23 +24,21 @@
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
/* Strict Type-Checking Options */
"strict": false, /* Enable all strict type-checking options. */
// "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
// "strictNullChecks": true, /* Enable strict null checks. */
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
// "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
// "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
"strict": true, /* Enable all strict type-checking options. */
"skipLibCheck": true,
"noImplicitAny": false, /* Raise error on expressions and declarations with an implied 'any' type. */
"strictNullChecks": false, /* Enable strict null checks. */
"strictFunctionTypes": true, /* Enable strict checking of function types. */
"strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
"strictPropertyInitialization": false, /* Enable strict checking of property initialization in classes. */
"noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
"alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
/* Additional Checks */
// "noUnusedLocals": true, /* Report errors on unused locals. */
// "noUnusedParameters": true, /* Report errors on unused parameters. */
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
/* Module Resolution Options */
"moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
"resolveJsonModule": true,
@ -47,16 +48,13 @@
// "typeRoots": [], /* List of folders to include type definitions from. */
// "types": [], /* Type declaration files to be included in compilation. */
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
"preserveSymlinks": true /* Do not resolve the real path of symlinks. */
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
/* Source Map Options */
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
/* Experimental Options */
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */

8
types/eris.d.ts vendored
View File

@ -1,8 +0,0 @@
import { EmbedOptions } from 'eris';
import RichEmbed from '../src/class/RichEmbed';
declare global {
namespace Eris {
type MessageContent = string | { content?: string; tts?: boolean; disableEveryone?: boolean; embed?: EmbedOptions | RichEmbed; flags?: number };
}
}

97
types/x509.d.ts vendored
View File

@ -1,54 +1,51 @@
declare module 'x509' {
namespace Certificate {
interface Issuer {
countryName: string,
stateOrProvinceName: string,
localityName: string,
organizationName: string,
organizationalUnitName: string,
export interface Certificate {
status: true | false,
subject: {
commonName: string,
emailAddress: string
}
interface Subject {
countryName: string,
postalCode: string,
stateOrProvinceName: string,
localityName: string,
streetAddress: string,
organizationName: string,
organizationalUnitName: string,
organization: string[],
organizationalUnit: string[],
locality: string[],
country: string[],
},
issuer: {
commonName: string,
emailAddress: string
}
interface Extensions {
keyUsage: string,
authorityInformationAccess: string,
certificatePolicies: string,
basicConstraints: string,
cRLDistributionPoints: string,
subjectAlternativeName: string,
extendedKeyUsage: string,
authorityKeyIdentifier: string,
subjectKeyIdentifier: string,
cTPrecertificateSCTs: string
}
}
interface FullCertificate {
version: number,
subject: Certificate.Subject,
issuer: Certificate.Issuer,
fingerPrint: string,
serial: string,
notBefore: Date,
notAfter: Date,
subjectHash: string,
organization: string[],
organizationalUnit: string[],
locality: string[],
country: string[],
},
aia: {
issuingCertificateURL: string,
ocspServer: string,
},
validationType: 'DV' | 'OV' | 'EV',
signatureAlgorithm: string,
publicKey: { algorithm: string };
altNames: string[]
extensions: Certificate.Extensions
}
function getAltNames(cert: string): string[];
function getIssuer(cert: string): Certificate.Issuer;
function getSubject(cert: string): Certificate.Subject;
function parseCert(cert: string): FullCertificate
publicKeyAlgorithm: string,
serialNumber: number,
notAfter: Date,
/**
- 0: KeyUsageCRLSign
- 1: KeyUsageCertificateSign
- 2: KeyUsageContentCommitment
- 3: KeyUsageDataEncipherment
- 4: KeyUsageDecipherOnly
- 5: KeyUsageDigitalSignature
- 6: KeyUsageEncipherOnly
- 7: KeyUsageKeyAgreement
- 8: KeyUsageKeyEncipherment
*/
keyUsage: number[],
keyUsageAsText: ['CRL Signing', 'Certificate Signing', 'Content Commitment', 'Data Encipherment', 'Decipher Only', 'Digital Signature', 'Encipher Only', 'Key Agreement', 'Key Encipherment'],
/**
- 0: Any/All Usage
- 1: TLS Web Server Auth
- 2: TLS Web Client Auth
- 3: Code Signing
- 4: Email Protection (S/MIME)
*/
extendedKeyUsage: number[],
extendedKeyUsageAsText: ['All/Any Usages', 'TLS Web Server Authentication', 'TLS Web Client Authentication', 'Code Signing', 'E-mail Protection (S/MIME)'],
san: string,
emailAddresses: string,
fingerprint: string,
}

2986
yarn.lock

File diff suppressed because it is too large Load Diff