[iplimit] fix iplimit

This commit is contained in:
Hamidreza Ghavami 2024-03-13 03:44:15 +03:30
parent 68e1a43cd8
commit 86f66651c0
No known key found for this signature in database
GPG key ID: 402C6797325182D9
2 changed files with 13 additions and 14 deletions

View file

@ -44,7 +44,7 @@ func (j *CheckClientIpJob) Run() {
shouldClearAccessLog = j.processLogFile() shouldClearAccessLog = j.processLogFile()
} else { } else {
if !f2bInstalled { if !f2bInstalled {
logger.Warning("fail2ban is not installed. IP limiting may not work properly.") logger.Warning("[iplimit] fail2ban is not installed. IP limiting may not work properly.")
} }
} }
} }
@ -109,13 +109,6 @@ func (j *CheckClientIpJob) hasLimitIp() bool {
return false return false
} }
func (j *CheckClientIpJob) checkFail2BanInstalled() bool {
cmd := "fail2ban-client"
args := []string{"-h"}
err := exec.Command(cmd, args...).Run()
return err == nil
}
func (j *CheckClientIpJob) processLogFile() bool { func (j *CheckClientIpJob) processLogFile() bool {
accessLogPath, err := xray.GetAccessLogPath() accessLogPath, err := xray.GetAccessLogPath()
j.checkError(err) j.checkError(err)
@ -174,15 +167,21 @@ func (j *CheckClientIpJob) processLogFile() bool {
return shouldCleanLog return shouldCleanLog
} }
func (j *CheckClientIpJob) checkAccessLogAvailable(doWarning bool) bool { func (j *CheckClientIpJob) checkFail2BanInstalled() bool {
cmd := "fail2ban-client"
args := []string{"-h"}
err := exec.Command(cmd, args...).Run()
return err == nil
}
func (j *CheckClientIpJob) checkAccessLogAvailable(handleWarning bool) bool {
isAvailable := true
warningMsg := ""
accessLogPath, err := xray.GetAccessLogPath() accessLogPath, err := xray.GetAccessLogPath()
if err != nil { if err != nil {
return false return false
} }
isAvailable := true
warningMsg := ""
// access log is not available if it is set to 'none' or an empty string // access log is not available if it is set to 'none' or an empty string
switch accessLogPath { switch accessLogPath {
case "none": case "none":
@ -193,7 +192,7 @@ func (j *CheckClientIpJob) checkAccessLogAvailable(doWarning bool) bool {
isAvailable = false isAvailable = false
} }
if doWarning && warningMsg != "" { if handleWarning && warningMsg != "" {
logger.Warning(warningMsg) logger.Warning(warningMsg)
} }
return isAvailable return isAvailable

View file

@ -463,7 +463,7 @@ func (s *SettingService) SetWarp(data string) error {
func (s *SettingService) GetIpLimitEnable() (bool, error) { func (s *SettingService) GetIpLimitEnable() (bool, error) {
accessLogPath, err := xray.GetAccessLogPath() accessLogPath, err := xray.GetAccessLogPath()
if err != nil { if err != nil {
return false, nil return false, err
} }
return (accessLogPath != "none" && accessLogPath != ""), nil return (accessLogPath != "none" && accessLogPath != ""), nil
} }