From 40da700ef33f5fb3cfc7ba1bdda33448426f5680 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Sun, 21 May 2023 09:51:48 +0200 Subject: [PATCH] Continued: - added top-referencing instances scoreboard --- api.py | 18 ++++++++++++++---- index.html | 8 ++++++-- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/api.py b/api.py index 410e67e..05debfa 100644 --- a/api.py +++ b/api.py @@ -25,8 +25,8 @@ def info(): } @app.get(fba.config["base_url"] + "/top") -def top(blocked: int = None, blockers: int = None): - if blocked == None and blockers == None: +def top(blocked: int = None, blockers: int = None, reference: int = None): + if blocked == None and blockers == None and reference == None: raise HTTPException(status_code=400, detail="No filter specified") elif blocked != None: if blocked > 500: @@ -36,6 +36,11 @@ def top(blocked: int = None, blockers: int = None): if blockers > 500: raise HTTPException(status_code=400, detail="Too many results") fba.c.execute("SELECT blocker, COUNT(blocker) FROM blocks WHERE block_level = 'reject' group by blocker ORDER BY COUNT(blocker) DESC LIMIT ?", [blockers]) + elif reference != None: + if reference > 500: + raise HTTPException(status_code=400, detail="Too many results") + fba.c.execute("SELECT origin, COUNT(domain) FROM instances ORDER BY COUNT(domain) DESC LIMIT ?", [reference]) + scores = fba.c.fetchall() scoreboard = [] @@ -81,13 +86,17 @@ def blocked(domain: str = None, reason: str = None, reverse: str = None): return result @app.get(fba.config["base_url"] + "/scoreboard") -def index(request: Request, blockers: int = None, blocked: int = None): - if blockers == None and blocked == None: +def index(request: Request, blockers: int = None, blocked: int = None, reference: int = None): + scores = None + + if blockers == None and blocked == None and reference == None: raise HTTPException(status_code=400, detail="No filter specified") elif blockers != None: scores = get(f"http://127.0.0.1:{fba.config['port']}{fba.config['base_url']}/top?blockers={blockers}") elif blocked != None: scores = get(f"http://127.0.0.1:{fba.config['port']}{fba.config['base_url']}/top?blocked={blocked}") + elif reference != None: + scores = get(f"http://127.0.0.1:{fba.config['port']}{fba.config['base_url']}/top?reference={reference}") if scores != None: if not scores.ok: @@ -101,6 +110,7 @@ def index(request: Request, blockers: int = None, blocked: int = None): "scoreboard": True, "blockers": blockers, "blocked": blocked, + "reference": reference, "scores": scores }) diff --git a/index.html b/index.html index efdc6e9..2b5ca55 100644 --- a/index.html +++ b/index.html @@ -84,12 +84,14 @@

Top {{blockers}} defederating instances

{% elif blocked %}

Top {{blocked}} defederated instances

+ {% elif reference %} +

Top {{reference}} referencing instances

{% endif %}
- + {% for entry in scores %} @@ -155,7 +157,9 @@

- top 50 defederating / defederated instances + top 50 defederating / + defederated instances / + referencing instances

known instances: {{info.known_instances}}
-- 2.39.5
№ InstanceDefederations{% if reference %}References{% else %}Blocks{% endif %}
{{loop.index}}