diff --git a/src/common/core/antibot/ui/actions.py b/src/common/core/antibot/ui/actions.py index be7c4748c..52b4f80f6 100644 --- a/src/common/core/antibot/ui/actions.py +++ b/src/common/core/antibot/ui/actions.py @@ -1,2 +1,11 @@ -def antibot(): - return {"counter_failed_challenges": 0} +def antibot(**kwargs): + try: + data = kwargs["app"].config["INSTANCES"].get_metrics("antibot") + + if data.get("counter_failed_challenges") is None: + data["counter_failed_challenges"] = 0 + + return data + + except: + return {"counter_failed_challenges": 0} diff --git a/src/common/core/antibot/ui/template.html b/src/common/core/antibot/ui/template.html index 6cc57a3a8..338068f13 100644 --- a/src/common/core/antibot/ui/template.html +++ b/src/common/core/antibot/ui/template.html @@ -36,8 +36,8 @@
- total number + total failed
diff --git a/src/common/core/authbasic/ui/actions.py b/src/common/core/authbasic/ui/actions.py index 64fd4d12f..f40e8fcbb 100644 --- a/src/common/core/authbasic/ui/actions.py +++ b/src/common/core/authbasic/ui/actions.py @@ -1,8 +1,10 @@ -def authbasic(): - return { - "message": "ok", - "data": { - "info": "test", - "count": 3, - }, - } +def authbasic(**kwargs): + try: + data = kwargs["app"].config["INSTANCES"].get_metrics("authbasic") + + if data.get("counter_failed_challenges") is None: + data["counter_failed_challenges"] = 0 + + return data + except: + return {"counter_failed_challenges": 0} diff --git a/src/common/core/badbehavior/ui/actions.py b/src/common/core/badbehavior/ui/actions.py index 84a7b362e..648c1b38f 100644 --- a/src/common/core/badbehavior/ui/actions.py +++ b/src/common/core/badbehavior/ui/actions.py @@ -1,9 +1,13 @@ -def badbehavior(): - return { - "message": "ok", - "data": { - "info": "test", - "count": 3, - "items": [{"code": 400, "count": 24}, {"code": 403, "count": 845}, {"code": 402, "count": 12}], - }, - } +def badbehavior(**kwargs): + try: + # Here we will have a list { 'counter_403': X, 'counter_401': Y ... } + data = kwargs["app"].config["INSTANCES"].get_metrics("badbehavior") + format_data = [] + # Format to fit [{code: 403, count: X}, {code: 401, count: Y} ...] + for key, value in data.items(): + format_data[key] = {"code": int(key.split("_")[1]), "count": value} + + return {"items": format_data} + + except: + return {"items": []} diff --git a/src/common/core/blacklist/ui/actions.py b/src/common/core/blacklist/ui/actions.py index 5b8b538a8..86a9feb87 100644 --- a/src/common/core/blacklist/ui/actions.py +++ b/src/common/core/blacklist/ui/actions.py @@ -1,11 +1,23 @@ -def blacklist(): - return { - "message": "ok", - "data": { - "count_url": 4, - "count_ip": 2, - "count_rdns": 1, - "count_asn": 10, - "count_user_agent": 10, - }, - } +def blacklist(**kwargs): + keys = [ + "counter_blacklist_url", + "counter_blacklist_ip", + "counter_blacklist_rdns", + "counter_blacklist_asn", + "counter_blacklist_usa", + ] + + try: + data = kwargs["app"].config["INSTANCES"].get_metrics("blacklist") + + for key in keys: + if data.get(key) is None: + data[key] = 0 + + return data + + except: + data = {} + for key in keys: + data[key] = 0 + return data diff --git a/src/common/core/blacklist/ui/template.html b/src/common/core/blacklist/ui/template.html index 687dfdcbe..e2c75a2a7 100644 --- a/src/common/core/blacklist/ui/template.html +++ b/src/common/core/blacklist/ui/template.html @@ -235,27 +235,27 @@ value: "{{ plugin['description'] or ''}}", type: "text", }, - count_url: { + counter_blacklist_url: { el: document.querySelector("[data-count-url]"), value: "unknown", type: "text", }, - count_ip: { + counter_blacklist_ip: { el: document.querySelector("[data-count-ip]"), value: "unknown", type: "text", }, - count_rdns: { + counter_blacklist_rdns: { el: document.querySelector("[data-count-rdns]"), value: "unknown", type: "text", }, - count_asn: { + counter_blacklist_asn: { el: document.querySelector("[data-count-asn]"), value: "unknown", type: "text", }, - count_user_agent: { + counter_blacklist_ua: { el: document.querySelector("[data-count-user-agent]"), value: "unknown", type: "text", diff --git a/src/common/core/cors/ui/actions.py b/src/common/core/cors/ui/actions.py index ebc717152..13aab1b98 100644 --- a/src/common/core/cors/ui/actions.py +++ b/src/common/core/cors/ui/actions.py @@ -1,8 +1,11 @@ -def cors(): - return { - "message": "ok", - "data": { - "info": "test", - "count": 3, - }, - } +def cors(**kwargs): + try: + data = kwargs["app"].config["INSTANCES"].get_metrics("cors") + + if data.get("counter_failed_cors") is None: + data["counter_failed_cors"] = 0 + + return data + + except: + return {"counter_failed_cors": 0} diff --git a/src/common/core/cors/ui/template.html b/src/common/core/cors/ui/template.html index e9dfdc281..a71563da4 100644 --- a/src/common/core/cors/ui/template.html +++ b/src/common/core/cors/ui/template.html @@ -74,7 +74,7 @@ value: "{{ plugin['description'] or ''}}", type: "text", }, - count: { + counter_failed_cors: { el: document.querySelector("[data-count]"), value: "unknown", type: "text", diff --git a/src/common/core/country/ui/actions.py b/src/common/core/country/ui/actions.py index a9b64b967..1f3356eb4 100644 --- a/src/common/core/country/ui/actions.py +++ b/src/common/core/country/ui/actions.py @@ -7,3 +7,16 @@ def country(): "whitelist_count": 23, }, } + + +def country(**kwargs): + try: + data = kwargs["app"].config["INSTANCES"].get_metrics("country") + + if data.get("counter_failed_country") is None: + data["counter_failed_country"] = 0 + + return data + + except: + return {"counter_failed_country": 0} diff --git a/src/common/core/country/ui/template.html b/src/common/core/country/ui/template.html index 49ad3ccbb..e3a8c6e63 100644 --- a/src/common/core/country/ui/template.html +++ b/src/common/core/country/ui/template.html @@ -35,11 +35,11 @@ > Country - +blacklist request blockedrequest blocked
@@ -67,46 +67,6 @@ -- Country -
- - -- whitelist request passed -
-- URL + GREYLIST
- +- - denied - + request blocked
- IP -
- - -- - denied - -
-- RDNS -
- - -- - denied - -
-- ASN -
- - -- - denied - -
-- User Agent -
- - -- - denied - -
-- URL + WHITELIST
- +- - denied - + request passed
- IP -
- - -- - denied - -
-- RDNS -
- - -- - denied - -
-- ASN -
- - -- - denied - -
-- User Agent -
- - -- - denied - -
-