From 76cce395f4936d6582f56b2c7e0760777e8600f2 Mon Sep 17 00:00:00 2001 From: Hamidreza Ghavami <70919649+hamid-gh98@users.noreply.github.com> Date: Sat, 9 Mar 2024 00:37:17 +0330 Subject: [PATCH] [fix] access log path better to not hardcode the access log path, maybe some ppl dont want to use the default ./access.log --- web/job/check_client_ip_job.go | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/web/job/check_client_ip_job.go b/web/job/check_client_ip_job.go index 344160e1..4e22f257 100644 --- a/web/job/check_client_ip_job.go +++ b/web/job/check_client_ip_job.go @@ -36,28 +36,20 @@ func (j *CheckClientIpJob) Run() { } f2bInstalled := j.checkFail2BanInstalled() - accessLogPath := xray.GetAccessLogPath() + isAccessLogAvailable := j.checkAccessLogAvailable() clearAccessLog := false if j.hasLimitIp() { - if f2bInstalled && accessLogPath == "./access.log" { + if f2bInstalled && isAccessLogAvailable { clearAccessLog = j.processLogFile() } else { if !f2bInstalled { logger.Warning("fail2ban is not installed. IP limiting may not work properly.") } - switch accessLogPath { - case "none": - logger.Warning("Access log is set to 'none', check your Xray Configs") - case "": - logger.Warning("Access log doesn't exist in your Xray Configs") - default: - logger.Warning("Current access.log path is not compatible with IP Limit") - } } } - if clearAccessLog || accessLogPath == "./access.log" && time.Now().Unix() - j.lastClear > 3600 { + if clearAccessLog || isAccessLogAvailable && time.Now().Unix()-j.lastClear > 3600 { j.clearAccessLog() } } @@ -178,6 +170,21 @@ func (j *CheckClientIpJob) processLogFile() bool { return shouldCleanLog } +func (j *CheckClientIpJob) checkAccessLogAvailable() bool { + accessLogPath := xray.GetAccessLogPath() + isAvailable := true + // access log is not available if it is set to 'none' or an empty string + switch accessLogPath { + case "none": + logger.Warning("Access log is set to 'none', check your Xray Configs") + isAvailable = false + case "": + logger.Warning("Access log doesn't exist in your Xray Configs") + isAvailable = false + } + return isAvailable +} + func (j *CheckClientIpJob) checkError(e error) { if e != nil { logger.Warning("client ip job err:", e)