fail2go icon indicating copy to clipboard operation
fail2go copied to clipboard

Implement data structure changes from new f2b

Open strangeman opened this issue 5 years ago • 3 comments

With fresh fail2ban (tested on v0.10.5) fail2go fails with the following error:

fail2rest    | 2020/10/22 10:52:51 http: panic serving 192.168.112.1:43886: interface conversion: interface {} is ogórek.Call, not string
fail2rest    | goroutine 24 [running]:
fail2rest    | net/http.(*conn).serve.func1(0xc0001246e0)
fail2rest    | 	/usr/local/go/src/net/http/server.go:1795 +0x139
fail2rest    | panic(0x9a11c0, 0xc0001d80c0)
fail2rest    | 	/usr/local/go/src/runtime/panic.go:679 +0x1b2
fail2rest    | github.com/Sean-Der/fail2go.interfaceSliceToStringSlice(0xc00018eab0, 0x1, 0x1, 0xc00018eae0, 0x1, 0x1)
fail2rest    | 	/go/pkg/mod/github.com/!sean-!der/[email protected]/utils.go:5 +0x16c
fail2rest    | github.com/Sean-Der/fail2go.(*Conn).JailStatus(0xc0000816c0, 0xc000099289, 0x4, 0xc000099289, 0x4, 0x1, 0xe63b20, 0x0, 0x0, 0x0, ...)
fail2rest    | 	/go/pkg/mod/github.com/!sean-!der/[email protected]/jail.go:24 +0x38d
fail2rest    | github.com/UCCNetsoc/fail2rest/api.(*API).getJail(0xc00009a150, 0xade220, 0xc0001282a0, 0xc0000d9900)
fail2rest    | 	/fail2rest/api/jail.go:23 +0xf6
fail2rest    | net/http.HandlerFunc.ServeHTTP(0xc000081860, 0xade220, 0xc0001282a0, 0xc0000d9900)
fail2rest    | 	/usr/local/go/src/net/http/server.go:2036 +0x44
fail2rest    | github.com/go-chi/chi.(*Mux).routeHTTP(0xc00009d0e0, 0xade220, 0xc0001282a0, 0xc0000d9900)

This behavior caused by changes in the fail2ban data structure. I added needed parsing to the library.

Data sample:

//list of the banned IPs
spew.Dump(action.([]interface{})[2])

 (ogórek.Tuple) (len=2 cap=2) {
  (string) (len=14) "Banned IP list",
  ([]interface {}) (len=1 cap=2) {
   (ogórek.Call) {
    Callable: (ogórek.Class) {
     Module: (string) (len=11) "__builtin__",
     Name: (string) (len=3) "str"
    },
    Args: (ogórek.Tuple) (len=1 cap=1) {
     (string) (len=13) "89.1.1.1"
    }
   },
   (ogórek.Call) {
    Callable: (ogórek.Class) {
     Module: (string) (len=11) "__builtin__",
     Name: (string) (len=3) "str"
    },
    Args: (ogórek.Tuple) (len=1 cap=1) {
     (string) (len=14) "188.2.2.2"
    }
   }
  }
 }

strangeman avatar Oct 22 '20 13:10 strangeman

P.S. If possible, add a hacktoberfest-accepted label to this PR. :)

strangeman avatar Oct 22 '20 13:10 strangeman

amazing work! @strangeman would you be able to support both versions? If you add a _, ok then we can support old stuff as well.

This is the first time I have seen someone do a deep change on this repo! You have any interest in taking it over? Happy to make you an admin and we can transfer to you :)

Sean-Der avatar Oct 23 '20 04:10 Sean-Der

Sorry for the delay, I had switched to other tasks for a while. I implemented backward compatibility for some methods, which input data was changed in the new fail2ban.

About transfer... I don't know, I had reached my goal, I got a working web-interface for fail2ban. :) I'm not sure to have time and resources for the support and future improvements in this product.

strangeman avatar Nov 02 '20 14:11 strangeman

Sorry this didn't get merged sooner :(

I just rebase + tagged. Thank you so much @strangeman

Sean-Der avatar Jun 20 '24 20:06 Sean-Der