Fix: get real ip

This commit is contained in:
Lazy 2024-03-20 23:44:46 +08:00
parent 4e4631442d
commit ae206e4438

View File

@ -23,7 +23,7 @@ export function login(
): string {
// record the number of login requests
GlobalVariable.set(LOGIN_COUNT, GlobalVariable.get(LOGIN_COUNT, 0) + 1);
const ip = ctx.socket.remoteAddress;
const ip = toText(ctx.header["x-forwarded-for"]) || ctx.socket.remoteAddress;
// check user information
try {
userSystem.checkUser({ userName, passWord }, twoFACode);
@ -168,7 +168,7 @@ export function checkBanIp(ctx: Koa.ParameterizedContext) {
if (!GlobalVariable.map.has(LOGIN_FAILED_KEY)) GlobalVariable.set(LOGIN_FAILED_KEY, {});
// This IpMap also needs to be used when logging in
const ipMap = GlobalVariable.get(LOGIN_FAILED_KEY);
const ip = toText(ctx.socket.remoteAddress) || "";
const ip = toText(ctx.header["x-forwarded-for"]) || ctx.socket.remoteAddress || "";
if (ipMap[ip] > 10 && systemConfig?.loginCheckIp === true) {
if (ipMap[ip] != 999) {
// record the number of bans