From 9a003e49791cffe0fb360a2821086d2bc2dbeea7 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Mon, 22 May 2023 04:52:13 +0200 Subject: [PATCH] Continued: - fetching .well-known/nodeinfo for auto-discovery added --- fba.py | 31 +++++++++++++++++++++++++++++++ fetch_blocks.py | 6 +++--- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/fba.py b/fba.py index 954318d..4e74fd8 100644 --- a/fba.py +++ b/fba.py @@ -156,6 +156,37 @@ def fetch_nodeinfo(domain: str) -> list: # NOISY-DEBUG: print("DEBUG: json[]:", type(json)) if json is None or len(json) == 0: print("WARNING: Failed fetching nodeinfo from domain:", domain) + json = fetch_wellknown_nodeinfo(domain) + + # NOISY-DEBUG: print("DEBUG: Returning json[]:", type(json)) + return json + +def fetch_wellknown_nodeinfo(domain: str) -> list: + # NOISY-DEBUG: print("DEBUG: Fetching .well-known info for domain:", domain) + json = {} + + try: + res = reqto.get(f"https://{domain}/.well-known/nodeinfo", headers=headers, timeout=(config["connection_timeout"], config["read_timeout"])) + # NOISY-DEBUG: print("DEBUG: domain,res.ok:", domain, res.ok) + if res.ok and res.json() is not None: + nodeinfo = res.json() + # NOISY-DEBUG: print("DEBUG: Found entries:", len(nodeinfo), domain) + if "links" in nodeinfo: + # NOISY-DEBUG: print("DEBUG: Found links in nodeinfo():", len(nodeinfo["links"])) + for link in nodeinfo["links"]: + # NOISY-DEBUG: print("DEBUG: rel,href:", link["rel"], link["href"]) + if link["rel"] == "http://nodeinfo.diaspora.software/ns/schema/2.0": + # NOISY-DEBUG: print("DEBUG: Fetching nodeinfo from:", link["href"]) + res = reqto.get(link["href"]) + # NOISY-DEBUG: print("DEBUG: href,res.ok:", link["href"], res.ok) + if res.ok and res.json() is not None: + # NOISY-DEBUG: print("DEBUG: Found JSON nodeinfo():", len(res.json())) + json = res.json() + break + + except: + print("WARNING: Failed fetching .well-known info:", domain) + pass # NOISY-DEBUG: print("DEBUG: Returning json[]:", type(json)) return json diff --git a/fetch_blocks.py b/fetch_blocks.py index 4bdf158..0f75e15 100644 --- a/fetch_blocks.py +++ b/fetch_blocks.py @@ -226,7 +226,7 @@ for blocker, software in fba.cursor.fetchall(): elif blocked.count("*") < 1: # No obsfucation for this instance fba.cursor.execute( - "SELECT hash FROM instances WHERE domain = ? LIMIT 1", [blocked] + "SELECT hash FROM instances WHERE domain = ?", [blocked] ) if fba.cursor.fetchone() == None: @@ -369,7 +369,7 @@ for blocker, software in fba.cursor.fetchall(): if blocked == "": print("WARNING: blocked is empty:", blocker) continue - if blocked.count("*") > 0: + elif blocked.count("*") > 0: # GTS does not have hashes for obscured domains, so we have to guess it fba.cursor.execute( "SELECT domain FROM instances WHERE domain LIKE ? ORDER BY rowid LIMIT 1", [blocked.replace("*", "_")] @@ -419,7 +419,7 @@ for blocker, software in fba.cursor.fetchall(): except Exception as e: print("error:", e, blocker, software) else: - print("WARNING: Unknown software:", software) + print("WARNING: Unknown software:", blocker, software) if fba.config["bot_enabled"] and len(blockdict) > 0: send_bot_post(blocker, blockdict) -- 2.39.5