mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2026-09-22 00:00:50 +00:00
fix(fail2ban): treat process as active when client ping succeeds (#13679)
Fail2ban UI currently keys isActive only on systemd fail2ban.service. If the daemon is alive under another process manager, whitelist and blacklist stay disabled. Detect liveness with fail2ban-client ping. Fixes #13678 Co-authored-by: zhudaguaneren <218366267+zhudaguaneren@users.noreply.github.com>
This commit is contained in:
co-authored by
zhudaguaneren
parent
205ef3009a
commit
a6e2efa6c9
@@ -42,10 +42,21 @@ func (f *Fail2ban) Status() (bool, bool, bool) {
|
||||
isEnable, _ := controller.CheckEnable("fail2ban.service")
|
||||
isActive, _ := controller.CheckActive("fail2ban.service")
|
||||
isExist, _ := controller.CheckExist("fail2ban.service")
|
||||
if !isActive && isFail2banAlive() {
|
||||
isActive = true
|
||||
}
|
||||
|
||||
return isEnable, isActive, isExist
|
||||
}
|
||||
|
||||
func isFail2banAlive() bool {
|
||||
stdout, err := cmd.NewCommandMgr(cmd.WithTimeout(5*time.Second)).RunWithStdout("fail2ban-client", "ping")
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
return strings.Contains(strings.ToLower(stdout), "pong")
|
||||
}
|
||||
|
||||
func (f *Fail2ban) Version() string {
|
||||
stdout, err := cmd.NewCommandMgr(cmd.WithTimeout(20*time.Second)).RunWithStdout("fail2ban-client", "version")
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user