mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2025-09-10 20:26:19 +00:00
[iplimit] fix iplimit
This commit is contained in:
parent
68e1a43cd8
commit
86f66651c0
2 changed files with 13 additions and 14 deletions
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue