-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathauth.js
57 lines (50 loc) · 1.61 KB
/
auth.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
const { cookie_value, jwt_secret } = require("./config.json");
const jwt = require("jsonwebtoken");
const fs = require("fs");
module.exports = async (request, response, next) => {
if (request.path.includes(".")) {
return;
}
var ip = String(request.ip).replace("::ffff:", "");
fs.appendFileSync("logs/usage.txt", `${request.path} | ${ip} | ${request.protocol} | ${new Date().toUTCString()}\n`);
var public = false;
[
"/ec2",
"/login",
"/logs/network",
"/logs/processes",
"/processes/dashboard",
"/processes/jesterbot",
"/processes/stealthybot",
"/statistics",
"/storage",
"/error"
].forEach(item => {
if (request.path.includes(item)) {
public = true;
}
});
var superior = false;
try {
jwt.verify(request.cookies["_fiojoweonfwouinwiunfuiw"] || "", jwt_secret);
superior = true;
} catch (err) {}
if (["/protocols", "/reset"].includes(request.path)) {
if (superior === true) {
next();
} else {
response.redirect("/error?code=403&route=explicit");
}
} else if (request.path === "/" || public === true) {
next();
} else if (["usage", "messages", "console", "editor", "restart", "pull", "execute"].some(element => request.path.includes(element))) {
try {
jwt.verify(request.cookies[cookie_value] || "", jwt_secret);
next();
} catch (err) {
response.redirect("/error?code=403&route=admin");
}
} else {
next();
}
}