-
Notifications
You must be signed in to change notification settings - Fork 246
/
index.js
97 lines (82 loc) · 3.71 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import { createBareServer } from "@tomphttp/bare-server-node";
import { createServer } from "node:http";
import express from "express";
import path from "path";
import dotenv from "dotenv";
import useragent from "express-useragent";
import cookieParser from "cookie-parser";
import { check } from './inj.js';
dotenv.config();
const bare = createBareServer("/bare/");
const __dirname = process.cwd();
const httpServer = createServer();
const app = express(httpServer);
app.use(useragent.express());
app.use(cookieParser());
app.use(express.urlencoded({ extended: true }));
app.use("/edu/", express.static(path.join(__dirname, "/assets/uv")));
app.use(express.static(path.join(__dirname, "/static")));
// security checkpoint, don't delete
const checkpoint = async (req, res, next) => {
const license = req.cookies['license'];
const host = req.headers.host || '';
if (req.path.endsWith('.css') || req.path.endsWith('.js') || req.path.endsWith('.png') || req.path.endsWith('.jpg') || req.path.endsWith('.svg') || req.path.endsWith('.ico')) {
return next();
}
try {
if (license) {
return next();
} else {
const isAllowed = await check(host);
if (isAllowed) {
return next();
} else {
return res.sendFile(path.join(__dirname, '/static/wall.html'));
}
}
} catch (error) {
return res.status(500).send('Internal Server Error');
}
};
app.use(checkpoint);
const routes = [
{ path: "/", file: "/static/home.html" },
{ path: "/v", file: "/static/home.html" },
{ path: "/s", file: "/static/search.html" },
{ path: "/ut", file: "/static/utils.html" },
{ path: "/op", file: "/static/settings.html" },
{ path: "/tos", file: "/static/tos.html" },
{ path: "/creds", file: "/static/credits.html" }
];
routes.forEach(route => {
app.get(route.path, (req, res) => {
if (req.useragent.isMobile && !req.useragent.isTablet) {
return res.sendFile(path.join(__dirname, "/static/mobile/not-supported.html"));
}
res.sendFile(path.join(__dirname, route.file));
});
});
app.use((_, res) => res.status(404).sendFile(path.join(__dirname, "/static/404.html")));
httpServer.on("request", (req, res) => {
if (bare.shouldRoute(req)) {
bare.routeRequest(req, res);
} else {
app(req, res);
}
});
httpServer.on("error", (err) => console.log('Server error:', err));
httpServer.on("upgrade", (req, socket, head) => {
if (bare.shouldRoute(req)) bare.routeUpgrade(req, socket, head);
else socket.end();
});
httpServer.listen({ port: 3000 }, () => {
const addr = httpServer.address();
console.log(`
███████╗░██████╗░██╗░░░██╗██╗███╗░░██╗░█████╗░██╗░░██╗
██╔════╝██╔═══██╗██║░░░██║██║████╗░██║██╔══██╗╚██╗██╔╝
█████╗░░██║██╗██║██║░░░██║██║██╔██╗██║██║░░██║░╚███╔╝░
██╔══╝░░╚██████╔╝██║░░░██║██║██║╚████║██║░░██║░██╔██╗░
████ ███╗░╚═██╔═╝░╚██████╔╝██║██║░╚███║╚█████╔╝██╔╝╚██╗
╚══════╝░░░╚═╝░░░░╚═════╝░╚═╝╚═╝░░╚══╝░╚════╝░╚═╝░░╚═╝\n
Port: ${addr.port}`);
});