clear log hourly if !j.hasLimitIp and "./access.log" exist

This commit is contained in:
MHSanaei 2024-02-10 01:52:20 +03:30
parent f5dacd28e1
commit 4daaf0a647

View file

@ -51,6 +51,23 @@ func (j *CheckClientIpJob) Run() {
j.checkFail2BanInstalled()
j.processLogFile()
}
if !j.hasLimitIp() && xray.GetAccessLogPath() == "./access.log" {
go j.clearLogTime()
}
}
func (j *CheckClientIpJob) clearLogTime() {
for {
time.Sleep(time.Hour)
j.clearAccessLog()
}
}
func (j *CheckClientIpJob) clearAccessLog() {
accessLogPath := xray.GetAccessLogPath()
err := os.Truncate(accessLogPath, 0)
j.checkError(err)
}
func (j *CheckClientIpJob) hasLimitIp() bool {
@ -121,7 +138,7 @@ func (j *CheckClientIpJob) processLogFile() {
matches := ipRegx.FindStringSubmatch(line)
if len(matches) > 1 {
ip := matches[1]
if ip == "127.0.0.1" || ip == "[::1]" {
if ip == "127.0.0.1" {
continue
}