diff --git a/src/accesslist.go b/src/accesslist.go index 2df35d7..6cdb34e 100644 --- a/src/accesslist.go +++ b/src/accesslist.go @@ -3,6 +3,7 @@ package main import ( "encoding/json" "net/http" + "sort" "strings" "github.com/google/uuid" @@ -545,3 +546,39 @@ func handleWhitelistEnable(w http.ResponseWriter, r *http.Request) { utils.SendOK(w) } } + +// List all quick ban ip address +func handleListQuickBan(w http.ResponseWriter, r *http.Request) { + currentSummary := statisticCollector.GetCurrentDailySummary() + type quickBanEntry struct { + IpAddr string + Count int + CountryCode string + } + result := []quickBanEntry{} + currentSummary.RequestClientIp.Range(func(key, value interface{}) bool { + ip := key.(string) + count := value.(int) + thisEntry := quickBanEntry{ + IpAddr: ip, + Count: count, + } + + //Get the country code + geoinfo, err := geodbStore.ResolveCountryCodeFromIP(ip) + if err == nil { + thisEntry.CountryCode = geoinfo.CountryIsoCode + } + + result = append(result, thisEntry) + return true + }) + + //Sort result based on count + sort.Slice(result, func(i, j int) bool { + return result[i].Count > result[j].Count + }) + + js, _ := json.Marshal(result) + utils.SendJSONResponse(w, string(js)) +} diff --git a/src/api.go b/src/api.go index 7afa247..112d5b0 100644 --- a/src/api.go +++ b/src/api.go @@ -114,6 +114,9 @@ func RegisterAccessRuleAPIs(authRouter *auth.RouterDef) { authRouter.HandleFunc("/api/whitelist/ip/add", handleIpWhitelistAdd) authRouter.HandleFunc("/api/whitelist/ip/remove", handleIpWhitelistRemove) authRouter.HandleFunc("/api/whitelist/enable", handleWhitelistEnable) + + /* Quick Ban List */ + authRouter.HandleFunc("/api/quickban/list", handleListQuickBan) } // Register the APIs for path blocking rules management functions, WIP diff --git a/src/web/components/access.html b/src/web/components/access.html index 6a59453..4ed89fa 100644 --- a/src/web/components/access.html +++ b/src/web/components/access.html @@ -694,6 +694,7 @@