diff --git a/web/job/check_client_ip_job.go b/web/job/check_client_ip_job.go index 6ba27939..51bf5d7e 100644 --- a/web/job/check_client_ip_job.go +++ b/web/job/check_client_ip_job.go @@ -32,13 +32,18 @@ func (j *CheckClientIpJob) Run() { logger.Debug("Check Client IP Job...") if hasLimitIp() { + //create log file for Fail2ban IP Limit logIpFile, err := os.OpenFile("/var/log/3xipl.log", os.O_CREATE|os.O_APPEND|os.O_RDWR, 0644) - if err != nil { - logger.Errorf("Failed to create or open IP Limit Log file: %s", err) - } + checkError(err) defer logIpFile.Close() log.SetOutput(logIpFile) log.SetFlags(log.LstdFlags) + + //create file to collect access.log to another file accessp.log (p=persistent) + logAccessP, err := os.OpenFile("/usr/local/x-ui/accessp.log", os.O_CREATE|os.O_APPEND|os.O_RDWR, 0644) + checkError(err) + defer logAccessP.Close() + processLogFile() } @@ -140,6 +145,12 @@ func processLogFile() { time.Sleep(time.Second * 3) //added 3 seconds delay before cleaning logs to reduce chance of logging IP that already has been banned if shouldCleanLog { + //copy log + input, err := os.ReadFile(accessLogPath) + checkError(err) + if err := os.WriteFile("/usr/local/x-ui/accessp.log", input, 0644); err != nil { + checkError(err) + } // clean log if err := os.Truncate(GetAccessLogPath(), 0); err != nil { checkError(err) diff --git a/x-ui.sh b/x-ui.sh index b3e4078e..f5091a68 100644 --- a/x-ui.sh +++ b/x-ui.sh @@ -733,7 +733,6 @@ install_iplimit() { esac echo -e "${green}Fail2ban installed successfully!${plain}\n" else - sudo systemctl stop fail2ban echo -e "${yellow}Fail2ban is already installed.${plain}\n" fi @@ -788,9 +787,16 @@ actionunban = -D f2b- -s -j [Init] EOF - + + #Launching fail2ban + if ! sudo systemctl is-active --quiet fail2ban; then + sudo systemctl start fail2ban + echo test-start + else + systemctl restart fail2ban + echo test-restart + fi sudo systemctl enable fail2ban - sudo systemctl start fail2ban echo -e "${green}IP Limit installed and configured successfully!${plain}\n" before_show_menu