From d626b2f4bd519e76aa64977a64e842c7d867fa44 Mon Sep 17 00:00:00 2001 From: ssongliu <73214554+ssongliu@users.noreply.github.com> Date: Tue, 2 Jan 2024 21:56:28 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E9=80=82=E9=85=8D=20Fail2ban=200.10.2?= =?UTF-8?q?=20=E7=89=88=E6=9C=AC=20(#3503)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Refs #3490 --- backend/utils/toolbox/fail2ban.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/backend/utils/toolbox/fail2ban.go b/backend/utils/toolbox/fail2ban.go index 74ecdccbd..a745f6327 100644 --- a/backend/utils/toolbox/fail2ban.go +++ b/backend/utils/toolbox/fail2ban.go @@ -93,12 +93,17 @@ func (f *Fail2ban) ReBanIPs(ips []string) error { func (f *Fail2ban) ListBanned() ([]string, error) { var lists []string - stdout, err := cmd.Exec("fail2ban-client get sshd banip") + stdout, err := cmd.Exec("fail2ban-client status sshd | grep 'Banned IP list:'") if err != nil { return lists, err } - itemList := strings.Split(strings.ReplaceAll(stdout, "\n", ""), " ") - for _, item := range itemList { + itemList := strings.Split(strings.Trim(stdout, "\n"), "Banned IP list:") + if len(itemList) != 2 { + return lists, nil + } + + ips := strings.Fields(itemList[1]) + for _, item := range ips { if len(item) != 0 { lists = append(lists, item) }