From a2aca447bbec7560e80e0fa1b8582d7808764aec Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Mon, 3 Jul 2023 20:04:45 +0200 Subject: [PATCH] Continued: - renamed /api/index.json to /api/top.json - count each checked domain and calculate percentage --- daemon.py | 8 +++++--- fba/commands.py | 4 +++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/daemon.py b/daemon.py index af6cee9..cdc6ef5 100755 --- a/daemon.py +++ b/daemon.py @@ -103,7 +103,7 @@ def api_scoreboard(mode: str, amount: int): return scores -@router.get(config.get("base_url") + "/api/index.json", response_class=JSONResponse) +@router.get(config.get("base_url") + "/api/top.json", response_class=JSONResponse) def api_index(request: Request, mode: str, value: str, amount: int): if mode is None or value is None or amount is None: raise HTTPException(status_code=500, detail="No filter specified") @@ -131,7 +131,9 @@ def api_index(request: Request, mode: str, value: str, amount: int): if mode == "domain": database.cursor.execute("SELECT blocker, blocked, block_level, reason, first_seen, last_seen \ FROM blocks \ -WHERE blocked = ? OR blocked = ? OR blocked = ? OR blocked = ? OR blocked = ? OR blocked = ? ORDER BY first_seen ASC LIMIT ?", +WHERE blocked = ? OR blocked = ? OR blocked = ? OR blocked = ? OR blocked = ? OR blocked = ? \ +ORDER BY block_level ASC, first_seen ASC \ +LIMIT ?", [ domain, "*." + domain, @@ -292,7 +294,7 @@ def top(request: Request, mode: str, value: str, amount: int = config.get("api_l elif mode in ["domain", "reverse"] and not utils.is_domain_wanted(value): raise HTTPException(status_code=500, detail="Invalid or blocked domain specified") - response = requests.get(f"http://{config.get('host')}:{config.get('port')}{config.get('base_url')}/api/index.json?mode={mode}&value={value}&amount={amount}") + response = requests.get(f"http://{config.get('host')}:{config.get('port')}{config.get('base_url')}/api/top.json?mode={mode}&value={value}&amount={amount}") if response is not None: blocklist = response.json() diff --git a/fba/commands.py b/fba/commands.py index 231ec4e..05970a1 100644 --- a/fba/commands.py +++ b/fba/commands.py @@ -1390,10 +1390,11 @@ def update_nodeinfo(args: argparse.Namespace) -> int: domains = database.cursor.fetchall() logger.info("Checking %d domain(s) ...", len(domains)) + cnt = 0 for row in domains: logger.debug("row[]='%s'", type(row)) try: - logger.info("Checking nodeinfo for row[domain]='%s',row[software]='%s' ...", row["domain"], row["software"]) + logger.info("Checking nodeinfo for row[domain]='%s',row[software]='%s' (%s%%) ...", row["domain"], row["software"], "{:5.1f}".format(cnt / len(domains) * 100)) software = federation.determine_software(row["domain"]) logger.debug("Determined software='%s'", software) @@ -1408,6 +1409,7 @@ def update_nodeinfo(args: argparse.Namespace) -> int: instances.set_last_nodeinfo(row["domain"]) instances.update_data(row["domain"]) + cnt = cnt + 1 logger.debug("Success! - EXIT!") return 0 -- 2.39.5