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>2023-06-08 13:20:35 +0300
committerMHSanaei <ho3ein.sanaei@gmail.com>2023-06-08 13:20:35 +0300
commit29e40a0bce070057c67cdd6f1cb2b7dd152255a6 (patch)
treefd95e9770cd605e2c107c00c9d987b5f713638be /web/job
parent4c1fa59453ba162b546ad0315313f1dbb7cf546b (diff)
access.log #571
access.log will be clear only when limitip is not 0
Diffstat (limited to 'web/job')
-rw-r--r--web/job/check_client_ip_job.go23
1 files changed, 13 insertions, 10 deletions
diff --git a/web/job/check_client_ip_job.go b/web/job/check_client_ip_job.go
index fb1227f8..27a4bd7d 100644
--- a/web/job/check_client_ip_job.go
+++ b/web/job/check_client_ip_job.go
@@ -57,11 +57,6 @@ func processLogFile() {
InboundClientIps := make(map[string][]string)
checkError(err)
- // clean log
- if err := os.Truncate(GetAccessLogPath(), 0); err != nil {
- checkError(err)
- }
-
lines := strings.Split(string(data), "\n")
for _, line := range lines {
ipRegx, _ := regexp.Compile(`[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+`)
@@ -101,7 +96,13 @@ func processLogFile() {
addInboundClientIps(clientEmail, ips)
} else {
- updateInboundClientIps(inboundClientIps, clientEmail, ips)
+ shouldCleanLog := updateInboundClientIps(inboundClientIps, clientEmail, ips)
+ if shouldCleanLog {
+ // clean log
+ if err := os.Truncate(GetAccessLogPath(), 0); err != nil {
+ checkError(err)
+ }
+ }
}
}
@@ -182,7 +183,7 @@ func addInboundClientIps(clientEmail string, ips []string) error {
}
return nil
}
-func updateInboundClientIps(inboundClientIps *model.InboundClientIps, clientEmail string, ips []string) error {
+func updateInboundClientIps(inboundClientIps *model.InboundClientIps, clientEmail string, ips []string) bool {
jsonIps, err := json.Marshal(ips)
checkError(err)
@@ -196,7 +197,7 @@ func updateInboundClientIps(inboundClientIps *model.InboundClientIps, clientEmai
if inbound.Settings == "" {
logger.Debug("wrong data ", inbound)
- return nil
+ return false
}
settings := map[string][]model.Client{}
@@ -211,6 +212,7 @@ func updateInboundClientIps(inboundClientIps *model.InboundClientIps, clientEmai
if limitIp < len(ips) && limitIp != 0 && inbound.Enable {
disAllowedIps = append(disAllowedIps, ips[limitIp:]...)
+ return true
}
}
}
@@ -220,10 +222,11 @@ func updateInboundClientIps(inboundClientIps *model.InboundClientIps, clientEmai
db := database.GetDB()
err = db.Save(inboundClientIps).Error
if err != nil {
- return err
+ return false
}
- return nil
+ return false
}
+
func DisableInbound(id int) error {
db := database.GetDB()
result := db.Model(model.Inbound{}).