mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2025-08-30 23:06:18 +00:00
Write access.log to accessp.log on truncate
Optimised launching of fail2ban
This commit is contained in:
parent
63274d1bd5
commit
962f2e8eb0
2 changed files with 23 additions and 6 deletions
|
@ -32,13 +32,18 @@ func (j *CheckClientIpJob) Run() {
|
||||||
logger.Debug("Check Client IP Job...")
|
logger.Debug("Check Client IP Job...")
|
||||||
|
|
||||||
if hasLimitIp() {
|
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)
|
logIpFile, err := os.OpenFile("/var/log/3xipl.log", os.O_CREATE|os.O_APPEND|os.O_RDWR, 0644)
|
||||||
if err != nil {
|
checkError(err)
|
||||||
logger.Errorf("Failed to create or open IP Limit Log file: %s", err)
|
|
||||||
}
|
|
||||||
defer logIpFile.Close()
|
defer logIpFile.Close()
|
||||||
log.SetOutput(logIpFile)
|
log.SetOutput(logIpFile)
|
||||||
log.SetFlags(log.LstdFlags)
|
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()
|
processLogFile()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -140,6 +145,12 @@ func processLogFile() {
|
||||||
time.Sleep(time.Second * 3)
|
time.Sleep(time.Second * 3)
|
||||||
//added 3 seconds delay before cleaning logs to reduce chance of logging IP that already has been banned
|
//added 3 seconds delay before cleaning logs to reduce chance of logging IP that already has been banned
|
||||||
if shouldCleanLog {
|
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
|
// clean log
|
||||||
if err := os.Truncate(GetAccessLogPath(), 0); err != nil {
|
if err := os.Truncate(GetAccessLogPath(), 0); err != nil {
|
||||||
checkError(err)
|
checkError(err)
|
||||||
|
|
12
x-ui.sh
12
x-ui.sh
|
@ -733,7 +733,6 @@ install_iplimit() {
|
||||||
esac
|
esac
|
||||||
echo -e "${green}Fail2ban installed successfully!${plain}\n"
|
echo -e "${green}Fail2ban installed successfully!${plain}\n"
|
||||||
else
|
else
|
||||||
sudo systemctl stop fail2ban
|
|
||||||
echo -e "${yellow}Fail2ban is already installed.${plain}\n"
|
echo -e "${yellow}Fail2ban is already installed.${plain}\n"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -788,9 +787,16 @@ actionunban = <iptables> -D f2b-<name> -s <ip> -j <blocktype>
|
||||||
|
|
||||||
[Init]
|
[Init]
|
||||||
EOF
|
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 enable fail2ban
|
||||||
sudo systemctl start fail2ban
|
|
||||||
|
|
||||||
echo -e "${green}IP Limit installed and configured successfully!${plain}\n"
|
echo -e "${green}IP Limit installed and configured successfully!${plain}\n"
|
||||||
before_show_menu
|
before_show_menu
|
||||||
|
|
Loading…
Reference in a new issue