From e1b07d97e48dfe61baad8439b1473741e3573744 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Sun, 21 May 2023 11:38:41 +0200 Subject: [PATCH] Continued: - added top X for used software --- api.py | 43 +++++++++++++++++++++++++------------------ index.html | 18 ++++++++++++------ 2 files changed, 37 insertions(+), 24 deletions(-) diff --git a/api.py b/api.py index d6ce394..f0e11ef 100644 --- a/api.py +++ b/api.py @@ -25,21 +25,25 @@ def info(): } @app.get(fba.config["base_url"] + "/top") -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: +def top(blocked: int = None, blockers: int = None, reference: int = None, software: int = None): + if blocked != None: if blocked > 500: raise HTTPException(status_code=400, detail="Too many results") - fba.c.execute("SELECT blocked, COUNT(blocked) FROM blocks WHERE block_level = 'reject' group by blocked ORDER BY COUNT(blocked) DESC LIMIT ?", [blocked]) + fba.c.execute("SELECT blocked, COUNT(blocked) FROM blocks WHERE block_level = 'reject' GROUP BY blocked ORDER BY COUNT(blocked) DESC LIMIT ?", [blocked]) elif blockers != 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]) + 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]) + fba.c.execute("SELECT origin, COUNT(domain) FROM instances GROUP BY origin ORDER BY COUNT(domain) DESC LIMIT ?", [reference]) + elif software != None: + if software > 500: + raise HTTPException(status_code=400, detail="Too many results") + fba.c.execute("SELECT software, COUNT(domain) FROM instances GROUP BY software ORDER BY COUNT(domain) DESC LIMIT ?", [software]) + else: + raise HTTPException(status_code=400, detail="No filter specified") scores = fba.c.fetchall() @@ -72,11 +76,11 @@ def blocked(domain: str = None, reason: str = None, reverse: str = None): result = {} for blocker, blocked, block_level, reason, first_added, last_seen in blocks: entry = { - "blocker": blocker, - "blocked": blocked, - "reason": reason, + "blocker" : blocker, + "blocked" : blocked, + "reason" : reason, "first_added": first_added, - "last_seen": last_seen + "last_seen" : last_seen } if block_level in result: result[block_level].append(entry) @@ -86,19 +90,21 @@ 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, reference: int = None, ): +def index(request: Request, blockers: int = None, blocked: int = None, reference: int = None, software: 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: + if blockers != None and blockers > 0: scores = requests.get(f"http://127.0.0.1:{fba.config['port']}{fba.config['base_url']}/top?blockers={blockers}") - elif blocked != None: + elif blocked != None and blocked > 0: scores = requests.get(f"http://127.0.0.1:{fba.config['port']}{fba.config['base_url']}/top?blocked={blocked}") - elif reference != None: + elif reference != None and reference > 0: scores = requests.get(f"http://127.0.0.1:{fba.config['port']}{fba.config['base_url']}/top?reference={reference}") + elif software != None and software > 0: + scores = requests.get(f"http://127.0.0.1:{fba.config['port']}{fba.config['base_url']}/top?software={software}") + else: + raise HTTPException(status_code=400, detail="No filter specified") - if scores = None: + if scores == None: raise HTTPException(status_code=500, detail="Could not determine scores") elif not scores.ok: raise HTTPException(status_code=scores.status_code, detail=scores.text) @@ -110,6 +116,7 @@ def index(request: Request, blockers: int = None, blocked: int = None, reference "blockers" : blockers, "blocked" : blocked, "reference" : reference, + "software" : software, "scores" : scores.json() }) diff --git a/index.html b/index.html index 2b5ca55..bcc8bb1 100644 --- a/index.html +++ b/index.html @@ -86,19 +86,24 @@

Top {{blocked}} defederated instances

{% elif reference %}

Top {{reference}} referencing instances

+ {% elif software %} +

Top {{software}} used software

{% endif %}
- - + + {% for entry in scores %} @@ -159,7 +164,8 @@

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

known instances: {{info.known_instances}}
-- 2.39.5
№Instance{% if reference %}References{% else %}Blocks{% endif %}{% if software %}Software{% else %}Instance{% endif %}{% if reference %}References{% elif software %}Total{% else %}Blocks{% endif %}
{{loop.index}} - - {{entry['domain']}}  - ↗ + {% if software %} + {{entry['domain']}} + {% else %} + {{entry['domain']}}  + ↗ + {% endif %} {{entry['highscore']}}