]> git.mxchange.org Git - fba.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Mon, 22 May 2023 02:52:13 +0000 (04:52 +0200)
committerRoland Häder <roland@mxchange.org>
Mon, 22 May 2023 02:52:13 +0000 (04:52 +0200)
- fetching .well-known/nodeinfo for auto-discovery added

fba.py
fetch_blocks.py

diff --git a/fba.py b/fba.py
index 954318d2464a04b8028dd5ec957401b69744c0ca..4e74fd8f8697b6b979ea6ec3476857aa70b03938 100644 (file)
--- 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
index 4bdf1580e8a0b618ff9eaf68c46323bde57fe9c6..0f75e156332e6937bf2653bff8aa97eba30dcd13 100644 (file)
@@ -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)