-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
72 lines (55 loc) · 2.16 KB
/
index.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
const path = require("path");
const cors = require("cors");
const express = require("express");
const app = express();
const port = process.env.PORT || 8080;
const key = process.env.KEY || "you should watch gawr gura NOW";
const encryptor = require("simple-encryptor")(key);
const allowedOrigins = [`http://localhost:${port}`, "https://linkprotector.firestreaker2.gq"];
app.use(
cors({
origin: function (origin, callback) {
if (!origin || allowedOrigins.includes(origin)) {
callback(null, true);
} else {
callback(new Error("Not allowed by CORS. Please watch Gawr Gura for permission."));
}
},
})
);
app.use(express.json());
app.use(express.static(path.resolve(__dirname, "./static")));
app.get("/", (req, res) => {
res.sendFile(path.resolve(__dirname, "./static", "index.html"));
});
app.get("/unlock", (req, res) => {
res.sendFile(path.resolve(__dirname, "./static", "unlock.html"));
});
app.post("/creation", (req, res) => {
const content = req.body.content;
const password = req.body.password;
const encryptedContent = encryptor.encrypt(content);
const encryptedPassword = encryptor.encrypt(password);
const encryptedUrl = `${encryptedContent}|${encryptedPassword}`;
res.json({ URL: encryptedUrl });
});
app.post("/verification", (req, res) => {
const queryPassword = req.body.password;
const url = req.body.url;
var content = url.split("|")[0];
var originalPassword = url.split("|")[1];
content = encryptor.decrypt(content);
originalPassword = encryptor.decrypt(originalPassword);
if (queryPassword === originalPassword) {
res.json({ URL: content });
/* uncomment if you want logging */
// console.log(`Link has been unlocked.\nURL: ${url}\nPassword: ${originalPassword}\nContent: ${content}`);
} else {
res.json({ URL: "Error: Password Incorrect"})
/* uncomment if you want logging */
// console.log(`Link unlocking has been failed.\nURL: ${url}\nPassword: ${originalPassword}\nAttempted Password: ${queryPassword}\nContent: ${content}`);
}
});
app.listen(port, () => {
console.log(`App is listening on port ${port}`);
});