Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/MHSanaei/3x-ui.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/web/job
diff options
context:
space:
mode:
authorMHSanaei <ho3ein.sanaei@gmail.com>2024-02-10 01:22:20 +0300
committerMHSanaei <ho3ein.sanaei@gmail.com>2024-02-10 01:22:20 +0300
commit4daaf0a647564aa51719259b1d4bce69503fe1d7 (patch)
treec77d36d0de7c1dd74efed7369ad1a89afa67d69b /web/job
parentf5dacd28e1534ef97a3abe56065a32a9a1d59c79 (diff)
clear log hourly if !j.hasLimitIp and "./access.log" exist
Diffstat (limited to 'web/job')
-rw-r--r--web/job/check_client_ip_job.go19
1 files changed, 18 insertions, 1 deletions
diff --git a/web/job/check_client_ip_job.go b/web/job/check_client_ip_job.go
index 65e2a0ca..2cf72555 100644
--- a/web/job/check_client_ip_job.go
+++ b/web/job/check_client_ip_job.go
@@ -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
}