}
@router.get(config.get("base_url") + "/api/top.json", response_class=JSONResponse)
-def api_top(blocked: int = None, blockers: int = None, reference: int = None, software: int = None, command: int = None, error_code: int = None):
- if blocked is not None:
- if blocked > 500:
- raise HTTPException(status_code=400, detail="Too many results")
- fba.cursor.execute("SELECT blocked, COUNT(blocked) FROM blocks WHERE block_level = 'reject' GROUP BY blocked ORDER BY COUNT(blocked) DESC LIMIT ?", [blocked])
- elif blockers is not None:
- if blockers > 500:
- raise HTTPException(status_code=400, detail="Too many results")
- fba.cursor.execute("SELECT blocker, COUNT(blocker) FROM blocks WHERE block_level = 'reject' GROUP BY blocker ORDER BY COUNT(blocker) DESC LIMIT ?", [blockers])
- elif reference is not None:
- if reference > 500:
- raise HTTPException(status_code=400, detail="Too many results")
- fba.cursor.execute("SELECT origin, COUNT(domain) FROM instances WHERE software IS NOT NULL GROUP BY origin ORDER BY COUNT(domain) DESC LIMIT ?", [reference])
- elif software is not None:
- 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 command is not None:
- if command > 500:
- raise HTTPException(status_code=400, detail="Too many results")
- fba.cursor.execute("SELECT command, COUNT(domain) FROM instances WHERE command IS NOT NULL GROUP BY command ORDER BY COUNT(domain) DESC, command ASC LIMIT ?", [command])
- elif error_code is not None:
- if error_code > 500:
- raise HTTPException(status_code=400, detail="Too many results")
- fba.cursor.execute("SELECT last_status_code, COUNT(domain) AS cnt FROM instances WHERE last_status_code IS NOT NULL AND last_status_code != '200' GROUP BY last_status_code ORDER BY cnt DESC LIMIT ?", [error_code])
+def api_top(mode: str, amount: int):
+ if amount > 500:
+ raise HTTPException(status_code=400, detail="Too many results")
+
+ if mode == "blocked":
+ fba.cursor.execute("SELECT blocked, COUNT(blocked) AS score FROM blocks WHERE block_level = 'reject' GROUP BY blocked ORDER BY score DESC LIMIT ?", [amount])
+ elif mode == "blocker":
+ fba.cursor.execute("SELECT blocker, COUNT(blocker) AS score FROM blocks WHERE block_level = 'reject' GROUP BY blocker ORDER BY score DESC LIMIT ?", [amount])
+ elif mode == "reference":
+ fba.cursor.execute("SELECT origin, COUNT(domain) AS score FROM instances WHERE software IS NOT NULL GROUP BY origin ORDER BY score DESC LIMIT ?", [amount])
+ elif mode == "software":
+ fba.cursor.execute("SELECT software, COUNT(domain) AS score FROM instances WHERE software IS NOT NULL GROUP BY software ORDER BY score DESC, software ASC LIMIT ?", [amount])
+ elif mode == "command":
+ fba.cursor.execute("SELECT command, COUNT(domain) AS score FROM instances WHERE command IS NOT NULL GROUP BY command ORDER BY score DESC, command ASC LIMIT ?", [amount])
+ elif mode == "error_code":
+ fba.cursor.execute("SELECT last_status_code, COUNT(domain) AS score FROM instances WHERE last_status_code IS NOT NULL AND last_status_code != '200' GROUP BY last_status_code ORDER BY score DESC LIMIT ?", [amount])
else:
raise HTTPException(status_code=400, detail="No filter specified")
scores = list()
- for domain, highscore in fba.cursor.fetchall():
+ for domain, score in fba.cursor.fetchall():
scores.append({
- "domain" : domain,
- "highscore": highscore
+ "domain": domain,
+ "score" : score
})
return scores
return JSONResponse(status_code=200, content={})
@router.get(config.get("base_url") + "/scoreboard")
-def scoreboard(request: Request, blockers: int = None, blocked: int = None, reference: int = None, software: int = None, command: int = None, error_code: int = None):
+def scoreboard(request: Request, mode: str, amount: int):
response = None
- if blockers is not None and blockers > 0:
- response = requests.get(f"http://{config.get('host')}:{config.get('port')}{config.get('base_url')}/api/top.json?blockers={blockers}")
- elif blocked is not None and blocked > 0:
- response = requests.get(f"http://{config.get('host')}:{config.get('port')}{config.get('base_url')}/api/top.json?blocked={blocked}")
- elif reference is not None and reference > 0:
- response = requests.get(f"http://{config.get('host')}:{config.get('port')}{config.get('base_url')}/api/top.json?reference={reference}")
- elif software is not None and software > 0:
- response = requests.get(f"http://{config.get('host')}:{config.get('port')}{config.get('base_url')}/api/top.json?software={software}")
- elif command is not None and command > 0:
- response = requests.get(f"http://{config.get('host')}:{config.get('port')}{config.get('base_url')}/api/top.json?command={command}")
- elif error_code is not None and error_code > 0:
- response = requests.get(f"http://{config.get('host')}:{config.get('port')}{config.get('base_url')}/api/top.json?error_code={error_code}")
+ if mode == "blocker" and amount > 0:
+ response = requests.get(f"http://{config.get('host')}:{config.get('port')}{config.get('base_url')}/api/top.json?mode=blocker&amount={amount}")
+ elif mode == "blocked" and amount > 0:
+ response = requests.get(f"http://{config.get('host')}:{config.get('port')}{config.get('base_url')}/api/top.json?mode=blocked&amount={amount}")
+ elif mode == "reference" and amount > 0:
+ response = requests.get(f"http://{config.get('host')}:{config.get('port')}{config.get('base_url')}/api/top.json?mode=reference&amount={amount}")
+ elif mode == "software" and amount > 0:
+ response = requests.get(f"http://{config.get('host')}:{config.get('port')}{config.get('base_url')}/api/top.json?mode=software&amount={amount}")
+ elif mode == "command" and amount > 0:
+ response = requests.get(f"http://{config.get('host')}:{config.get('port')}{config.get('base_url')}/api/top.json?mode=command&amount={amount}")
+ elif mode == "error_code" and amount > 0:
+ response = requests.get(f"http://{config.get('host')}:{config.get('port')}{config.get('base_url')}/api/top.json?mode=error_code&amount={amount}")
else:
raise HTTPException(status_code=400, detail="No filter specified")
"slogan" : config.get("slogan"),
"request" : request,
"scoreboard": True,
- "blockers" : blockers,
- "blocked" : blocked,
- "reference" : reference,
- "software" : software,
- "command" : command,
- "error_code": error_code,
+ "mode" : mode,
+ "amount" : amount,
"scores" : network.json_from_response(response)
})
{% extends "base.html" %}
-{% block title %}scoreboard - {% if software %}TOP {{software}} used software{% elif command %}TOP {{command}} scripts{% elif reference %}TOP {{reference}} referencing instances{% elif blocked %}TOP {{blocked}} deferated instances{% elif blockers %}TOP {{blockers}} deferating instances{% endif %}{% endblock %}
+{% block title %}Scoreboard - {% if mode == 'software' %}TOP {{amount}} used software{% elif mode == 'command' %}TOP {{amount}} scripts{% elif mode == 'error_code' %}TOP {{amount}} error codes{% elif mode == 'reference' %}TOP {{amount}} referencing instances{% elif mode == 'blocked' %}TOP {{amount}} deferated instances{% elif mode == 'blocker' %}TOP {{amount}} deferating instances{% endif %}{% endblock %}
{% block header %}
- {% if blockers %}
- <h1>Top {{blockers}} defederating instances</h1>
- {% elif blocked %}
- <h1>Top {{blocked}} defederated instances</h1>
- {% elif reference %}
- <h1>Top {{reference}} referencing instances</h1>
- {% elif software %}
- <h1>Top {{software}} used software</h1>
- {% elif command %}
- <h1>TOP {{command}} scripts</h1>
- {% elif error_code %}
- <h1>TOP {{error_code}} error codes</h1>
+ {% if mode == 'blocker' %}
+ <h1>Top {{amount}} defederating instances</h1>
+ {% elif mode == 'blocked' %}
+ <h1>Top {{amount}} defederated instances</h1>
+ {% elif mode == 'reference' %}
+ <h1>Top {{amount}} referencing instances</h1>
+ {% elif mode == 'software' %}
+ <h1>Top {{amount}} used software</h1>
+ {% elif mode == 'command' %}
+ <h1>TOP {{amount}} scripts</h1>
+ {% elif mode == 'error_code' %}
+ <h1>TOP {{amount}} error codes</h1>
{% endif %}
{% endblock %}
<table>
<thead>
<th>№</th>
- <th>{% if software %}Software{% elif error_code %}Error code{% else %}Instance{% endif %}</th>
- <th>{% if reference %}References{% elif software or error_code %}Total{% else %}Blocks{% endif %}</th>
+ <th>{% if mode == 'software' %}Software{% elif mode == 'error_code' %}Error code{% else %}Instance{% endif %}</th>
+ <th>{% if mode == 'reference' %}References{% elif mode in('software', 'error_code') %}Total{% else %}Blocks{% endif %}</th>
</thead>
<tbody>
<tr>
<td>{{loop.index}}</td>
<td>
- {% if software or command or error_code %}
+ {% if mode in ('software', 'command', 'error_code') %}
{{entry['domain']}}
{% elif entry['domain'] == None %}
-
{% else %}
- <a href="{{base_url}}/top?{% if blockers %}reverse{% elif blocked or reference %}domain{% endif %}={{entry['domain']}}" rel="nofollow noopener noreferrer">{{entry['domain']}}</a>
+ <a href="{{base_url}}/top?{% if mode == 'blocker' %}reverse{% elif mode in('blocked', 'reference') %}domain{% endif %}={{entry['domain']}}" rel="nofollow noopener noreferrer">{{entry['domain']}}</a>
<a class="listlink" href="https://{{entry['domain']}}" rel="external" target="_blank">↗</a>
{% endif %}
</td>
- <td>{{entry['highscore']}}</td>
+ <td>{{entry['score']}}</td>
</tr>
{% endfor %}
</tbody>
{% endblock %}
{% block footer %}
- {% if error_code %}
+ {% if mode == 'error_code' %}
<h2>Please note to error codes:</h2>
<ul>
<li>Error code 999 is fake and covers a lot of reasons why the domain/instance is not reachable. Mostly that the domain is not resolvable or the server refused connection.</li>