[fix] access log path

better to not hardcode the access log path, maybe some ppl dont want to use the default ./access.log
This commit is contained in:
Hamidreza Ghavami 2024-03-09 00:37:17 +03:30
parent 1d2e7f1b21
commit 76cce395f4
No known key found for this signature in database
GPG key ID: 402C6797325182D9

View file

@ -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)