Skip to content
This repository was archived by the owner on Apr 18, 2022. It is now read-only.

Commit b619594

Browse files
committed
fix ip + revert dotenv
1 parent 6a9efb6 commit b619594

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

index.js

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,10 @@ const fs = require('fs');
44
const app = express();
55
const crypto = require('crypto');
66
const cookieParser = require('cookie-parser');
7-
const dotenv = require('dotenv');
87
require('better-logging')(console, {
98
format: ctx => `${ctx.date} ${ctx.time24} ${ctx.type} ${ctx.msg}`
109
});
11-
const result = dotenv.config()
12-
13-
if (result.error) {
14-
throw result.error;
15-
}
10+
require('dotenv').config();
1611

1712
let timeoutObject = new Object();
1813
let failedCounter = new Object();
@@ -50,21 +45,22 @@ function checkFileExist(path, exit) {
5045
return (false);
5146
}
5247

48+
checkFileExist(".env", true);
5349
checkFileExist("views/bot.pug", true);
5450

5551
app.use(cookieParser());
5652
app.set('view engine', 'pug');
5753

5854
app.get("/" + endpointName, function (userReq, userRes) {
59-
const IP = (userReq.headers["x-real-ip"] || userReq.connection.remoteAddress);
55+
const IP = userReq.headers["x-real-ip"];
6056
clearTimeout(timeoutObject[IP]);
6157
userRes.setHeader('Content-Type', 'text/css');
6258
userRes.setHeader('Cache-Control', 'no-store');
6359
userRes.end();
6460
});
6561

6662
app.all("*", function (userReq, userRes, next) {
67-
const IP = (userReq.headers["x-real-ip"] || userReq.connection.remoteAddress);
63+
const IP = userReq.headers["x-real-ip"];
6864
const secretCookie = crypto.createHash('md5').update(IP).digest('hex');
6965
if (userReq.headers['user-agent'].toLowerCase().includes("bot") || checkFileExist(jailPath + "/" + IP, false))
7066
userRes.render('bot', { website: process.env.WEBSITE_NAME });
@@ -90,7 +86,7 @@ app.all('*', proxy(targetToProxy, {
9086
return req.method == 'GET';
9187
},
9288
userResHeaderDecorator(headers, userReq, userRes, proxyReq, proxyRes) {
93-
const IP = (headers["x-real-ip"] || userReq.connection.remoteAddress);
89+
const IP = headers["x-real-ip"];
9490
if (headers['content-type'] && !whitelist.includes(IP) && (userReq.method == "GET" || userReq.method == "POST")) {
9591
if (headers['content-type'].includes("text/html") && (proxyRes.statusCode >= 200 && proxyRes.statusCode < 400)) {
9692
if (!timeoutObject[IP] || timeoutObject[IP]._called)

0 commit comments

Comments
 (0)