From 577ba30913afb4f4853e4cb4504938fb83ad0a3d Mon Sep 17 00:00:00 2001
From: somebodywashere <68244480+somebodywashere@users.noreply.github.com>
Date: Mon, 19 Jun 2023 12:48:34 +0000
Subject: [PATCH] Added seperate log file for IP Limit
---
web/job/check_client_ip_job.go | 10 +++++++++-
x-ui.sh | 8 +++++++-
2 files changed, 16 insertions(+), 2 deletions(-)
diff --git a/web/job/check_client_ip_job.go b/web/job/check_client_ip_job.go
index 2fe8fe79..c0e2a258 100644
--- a/web/job/check_client_ip_job.go
+++ b/web/job/check_client_ip_job.go
@@ -2,6 +2,7 @@ package job
import (
"encoding/json"
+ "log"
"os"
"regexp"
"x-ui/database"
@@ -66,6 +67,13 @@ func hasLimitIp() bool {
for _, client := range clients {
limitIp := client.LimitIP
if limitIp > 0 {
+ logIpFile, err := os.Create("/var/log/3xipl.log")
+ if err != nil {
+ log.Panic(err)
+ }
+ defer logIpFile.Close()
+ log.SetOutput(logIpFile)
+ log.SetFlags(log.LstdFlags)
return true
}
}
@@ -242,7 +250,7 @@ func updateInboundClientIps(inboundClientIps *model.InboundClientIps, clientEmai
disAllowedIps = append(disAllowedIps, ips[limitIp:]...)
for i := limitIp; i < len(ips); i++ {
- logger.Notice("[LIMIT_IP] Email=", clientEmail, " SRC=", ips[i])
+ log.Println("[LIMIT_IP] Email=", clientEmail, " SRC=", ips[i])
}
}
}
diff --git a/x-ui.sh b/x-ui.sh
index 503fdc26..dc54846a 100644
--- a/x-ui.sh
+++ b/x-ui.sh
@@ -746,7 +746,13 @@ install_iplimit() {
touch /var/log/3xipl-banned.log
fi
- echo $'\n[3x-ipl]\nenabled=true\nfilter=3x-ipl\naction=3x-ipl\nlogpath=%(syslog_daemon)s\nmaxretry=3\nfindtime=100\nbantime=300' >> /etc/fail2ban/jail.local
+ #Check if service log file exists so fail2ban fail2ban won't return error
+ if ! test -f "/var/log/3xipl.log"; then
+ touch /var/log/3xipl.log
+ fi
+
+
+ echo $'\n[3x-ipl]\nenabled=true\nfilter=3x-ipl\naction=3x-ipl\nlogpath=/var/log/3xipl.log\nmaxretry=3\nfindtime=100\nbantime=300' >> /etc/fail2ban/jail.local
echo $'[Definition]\nfailregex = [LIMIT_IP].+Email= .+.+SRC= \nignoreregex =' > /etc/fail2ban/filter.d/3x-ipl.conf