From bf22fd754cd661f7260dbf599e525433c0bed81f Mon Sep 17 00:00:00 2001
From: =?utf8?q?Roland=20H=C3=A4der?=
Date: Sun, 4 Jun 2023 01:03:30 +0200
Subject: [PATCH] Continued: - exposed originator (Python script) Top "10"
---
api.py | 11 +++++++++--
templates/index.html | 3 ++-
templates/scoreboard.html | 6 ++++++
3 files changed, 17 insertions(+), 3 deletions(-)
diff --git a/api.py b/api.py
index 871398e..d89cf3f 100644
--- a/api.py
+++ b/api.py
@@ -44,7 +44,7 @@ def info():
}
@router.get(fba.config["base_url"] + "/api/top.json", response_class=JSONResponse)
-def top(blocked: int = None, blockers: int = None, reference: int = None, software: int = None):
+def top(blocked: int = None, blockers: int = None, reference: int = None, software: int = None, originator: int = None):
if blocked != None:
if blocked > 500:
raise HTTPException(status_code=400, detail="Too many results")
@@ -61,6 +61,10 @@ def top(blocked: int = None, blockers: int = None, reference: int = None, softwa
if software > 500:
raise HTTPException(status_code=400, detail="Too many results")
fba.cursor.execute("SELECT software, COUNT(domain) FROM instances WHERE software IS NOT NULL GROUP BY software ORDER BY COUNT(domain) DESC, software ASC LIMIT ?", [software])
+ elif originator != None:
+ if originator > 500:
+ raise HTTPException(status_code=400, detail="Too many results")
+ fba.cursor.execute("SELECT originator, COUNT(domain) FROM instances WHERE originator IS NOT NULL GROUP BY originator ORDER BY COUNT(domain) DESC, originator ASC LIMIT ?", [originator])
else:
raise HTTPException(status_code=400, detail="No filter specified")
@@ -139,7 +143,7 @@ def mutual(domains: list[str] = Query()):
return JSONResponse(status_code=200, content={})
@router.get(fba.config["base_url"] + "/scoreboard")
-def index(request: Request, blockers: int = None, blocked: int = None, reference: int = None, software: int = None):
+def index(request: Request, blockers: int = None, blocked: int = None, reference: int = None, software: int = None, originator: int = None):
scores = None
if blockers != None and blockers > 0:
@@ -150,6 +154,8 @@ def index(request: Request, blockers: int = None, blocked: int = None, reference
res = requests.get(f"http://{fba.config['host']}:{fba.config['port']}{fba.config['base_url']}/api/top.json?reference={reference}")
elif software != None and software > 0:
res = requests.get(f"http://{fba.config['host']}:{fba.config['port']}{fba.config['base_url']}/api/top.json?software={software}")
+ elif originator != None and originator > 0:
+ res = requests.get(f"http://{fba.config['host']}:{fba.config['port']}{fba.config['base_url']}/api/top.json?originator={originator}")
else:
raise HTTPException(status_code=400, detail="No filter specified")
@@ -167,6 +173,7 @@ def index(request: Request, blockers: int = None, blocked: int = None, reference
"blocked" : blocked,
"reference" : reference,
"software" : software,
+ "originator": originator,
"scores" : res.json()
})
diff --git a/templates/index.html b/templates/index.html
index 39fcfcc..857c820 100644
--- a/templates/index.html
+++ b/templates/index.html
@@ -132,7 +132,8 @@
top 50 defederating /
defederated instances /
referencing instances /
- used software
+ used software /
+ originators
known instances: {{info.known_instances}}
diff --git a/templates/scoreboard.html b/templates/scoreboard.html
index 83e1f08..baacd00 100644
--- a/templates/scoreboard.html
+++ b/templates/scoreboard.html
@@ -9,6 +9,9 @@
text-align: center;
font-family: sans;
}
+ pre {
+ margin: 0px;
+ }
.block_level {
background-color: #1c1c3c;
width: 80em;
@@ -99,6 +102,8 @@
{% if software %}
{{entry['domain']}}
+ {% elif originator %}
+ {{entry['domain']}}
{% else %}
{{entry['domain']}}
â
@@ -110,6 +115,7 @@
--
2.39.5
|