From 374d49eb9276dce5d6809d3c75577bfa32e8b1d3 Mon Sep 17 00:00:00 2001 From: mhsanaei Date: Thu, 12 Sep 2024 09:44:17 +0200 Subject: [PATCH] Iplimit - improved Ensure accurate extraction of email. Access logs are needed when the IP limit feature is active. --- web/job/check_client_ip_job.go | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/web/job/check_client_ip_job.go b/web/job/check_client_ip_job.go index 64feeeb4..481d756b 100644 --- a/web/job/check_client_ip_job.go +++ b/web/job/check_client_ip_job.go @@ -36,10 +36,11 @@ func (j *CheckClientIpJob) Run() { } shouldClearAccessLog := false + iplimitActive := j.hasLimitIp() f2bInstalled := j.checkFail2BanInstalled() - isAccessLogAvailable := j.checkAccessLogAvailable() + isAccessLogAvailable := j.checkAccessLogAvailable(iplimitActive) - if j.hasLimitIp() { + if iplimitActive { if f2bInstalled && isAccessLogAvailable { shouldClearAccessLog = j.processLogFile() } else { @@ -123,7 +124,7 @@ func (j *CheckClientIpJob) processLogFile() bool { line := scanner.Text() ipRegx, _ := regexp.Compile(`from \[?([0-9a-fA-F:.]+)\]?:\d+ accepted`) - emailRegx, _ := regexp.Compile(`email:.+`) + emailRegx, _ := regexp.Compile(`email: (\S+)$`) matches := ipRegx.FindStringSubmatch(line) if len(matches) > 1 { @@ -136,7 +137,7 @@ func (j *CheckClientIpJob) processLogFile() bool { if matchesEmail == "" { continue } - matchesEmail = strings.TrimSpace(strings.Split(matchesEmail, "email: ")[1]) + matchesEmail = strings.Split(matchesEmail, "email: ")[1] if InboundClientIps[matchesEmail] != nil { if j.contains(InboundClientIps[matchesEmail], ip) { @@ -174,19 +175,20 @@ func (j *CheckClientIpJob) checkFail2BanInstalled() bool { return err == nil } -func (j *CheckClientIpJob) checkAccessLogAvailable() bool { - isAvailable := true +func (j *CheckClientIpJob) checkAccessLogAvailable(iplimitActive bool) bool { accessLogPath, err := xray.GetAccessLogPath() if err != nil { return false } - switch accessLogPath { - case "none", "": - isAvailable = false + if accessLogPath == "none" || accessLogPath == "" { + if iplimitActive { + logger.Warning("Access log path is not set, and IP limit is active. Please configure the access log path.") + } + return false } - return isAvailable + return true } func (j *CheckClientIpJob) checkError(e error) {