mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-03-14 01:34:47 +08:00
parent
b8a89d86a0
commit
d626b2f4bd
@ -93,12 +93,17 @@ func (f *Fail2ban) ReBanIPs(ips []string) error {
|
|||||||
|
|
||||||
func (f *Fail2ban) ListBanned() ([]string, error) {
|
func (f *Fail2ban) ListBanned() ([]string, error) {
|
||||||
var lists []string
|
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 {
|
if err != nil {
|
||||||
return lists, err
|
return lists, err
|
||||||
}
|
}
|
||||||
itemList := strings.Split(strings.ReplaceAll(stdout, "\n", ""), " ")
|
itemList := strings.Split(strings.Trim(stdout, "\n"), "Banned IP list:")
|
||||||
for _, item := range itemList {
|
if len(itemList) != 2 {
|
||||||
|
return lists, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
ips := strings.Fields(itemList[1])
|
||||||
|
for _, item := range ips {
|
||||||
if len(item) != 0 {
|
if len(item) != 0 {
|
||||||
lists = append(lists, item)
|
lists = append(lists, item)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user