From f4764e19b1dd613d84a3a2add29103045f8d8f9e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Sat, 1 Jul 2023 19:01:15 +0200 Subject: [PATCH] Continued: - improved/added some debug logger messages --- fba/commands.py | 6 +++--- fba/http/federation.py | 18 +++++++++++------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/fba/commands.py b/fba/commands.py index 58fe8a5..fc5de72 100644 --- a/fba/commands.py +++ b/fba/commands.py @@ -76,18 +76,18 @@ def check_nodeinfo(args: argparse.Namespace) -> int: logger.debug("args[]='%s' - CALLED!", type(args)) # Fetch rows - database.cursor.execute("SELECT domain, nodeinfo_url FROM instances WHERE nodeinfo_url IS NOT NULL ORDER BY domain ASC") + database.cursor.execute("SELECT domain, software, nodeinfo_url FROM instances WHERE nodeinfo_url IS NOT NULL ORDER BY domain ASC") cnt = 0 for row in database.cursor.fetchall(): - logger.debug("Checking row[domain]='%s',row[nodeinfo_url]='%s' ...", row["domain"], row["nodeinfo_url"]) + logger.debug("Checking row[domain]='%s',row[software]='%s',row[nodeinfo_url]='%s' ...", row["domain"], row["software"], row["nodeinfo_url"]) punycode = row["domain"].encode("idna").decode("utf-8") if row["nodeinfo_url"].startswith("/"): logger.debug("row[nodeinfo_url]='%s' is a relative URL and always matches", row["nodeinfo_url"]) continue elif row["nodeinfo_url"].find(punycode) == -1 and row["nodeinfo_url"].find(row["domain"]) == -1: - logger.warning("punycode='%s' is not found in row[nodeinfo_url]='%s'", punycode, row["nodeinfo_url"]) + logger.warning("punycode='%s' is not found in row[nodeinfo_url]='%s',row[software]='%s'", punycode, row["nodeinfo_url"], row["software"]) cnt = cnt + 1 logger.info("Found %d row(s)", cnt) diff --git a/fba/http/federation.py b/fba/http/federation.py index b053c7c..240bd73 100644 --- a/fba/http/federation.py +++ b/fba/http/federation.py @@ -260,7 +260,7 @@ def fetch_nodeinfo(domain: str, path: str = None) -> dict: logger.debug("data[]='%s'", type(data)) if "error_message" not in data and "json" in data: - logger.debug("Success: request='%s'", request) + logger.debug("Success: request='%s' - Setting detection_mode=STATIC_CHECK ...", request) instances.set_detection_mode(domain, "STATIC_CHECK") instances.set_nodeinfo_url(domain, request) break @@ -351,7 +351,7 @@ def fetch_wellknown_nodeinfo(domain: str) -> dict: logger.debug("link[href]='%s',data[]='%s'", link["href"], type(data)) if "error_message" not in data and "json" in data: - logger.debug("Found JSON data()=%d,link[href]='%s'", len(data), link["href"]) + logger.debug("Found JSON data()=%d,link[href]='%s' - Setting detection_mode=AUTO_DISCOVERY ...", len(data), link["href"]) instances.set_detection_mode(domain, "AUTO_DISCOVERY") instances.set_nodeinfo_url(domain, link["href"]) @@ -403,7 +403,7 @@ def fetch_generator_from_path(domain: str, path: str = "/") -> str: logger.debug("software[%s]='%s'", type(software), software) if software is not None and software != "": - logger.info("domain='%s' is generated by software='%s'", domain, software) + logger.info("domain='%s' is generated by software='%s' - Setting detection_mode=GENERATOR ...", domain, software) instances.set_detection_mode(domain, "GENERATOR") elif isinstance(site_name, bs4.element.Tag) and isinstance(site_name.get("content"), str): logger.debug("Found property=og:site_name, domain='%s'", domain) @@ -411,7 +411,7 @@ def fetch_generator_from_path(domain: str, path: str = "/") -> str: logger.debug("software[%s]='%s'", type(software), software) if software is not None and software != "": - logger.info("domain='%s' has og:site_name='%s'", domain, software) + logger.debug("domain='%s' has og:site_name='%s' - Setting detection_mode=SITE_NAME ...", domain, software) instances.set_detection_mode(domain, "SITE_NAME") logger.debug("software[]='%s'", type(software)) @@ -470,7 +470,7 @@ def determine_software(domain: str, path: str = None) -> str: logger.debug("Generator for domain='%s' is: '%s'", domain, software) if "status" in data and data["status"] == "error" and "message" in data: - logger.warning("JSON response is an error: '%s'", data["message"]) + logger.warning("JSON response is an error: '%s' - Resetting detection_mode,nodeinfo_url ...", data["message"]) instances.set_last_error(domain, data["message"]) instances.set_detection_mode(domain, None) instances.set_nodeinfo_url(domain, None) @@ -481,16 +481,20 @@ def determine_software(domain: str, path: str = None) -> str: software = data["software"]["name"] logger.debug("software[%s]='%s' - FOUND!", type(software), software) elif "message" in data: - logger.warning("JSON response contains only a message: '%s'", data["message"]) + logger.warning("JSON response contains only a message: '%s' - Resetting detection_mode,nodeinfo_url ...", data["message"]) instances.set_last_error(domain, data["message"]) instances.set_detection_mode(domain, None) instances.set_nodeinfo_url(domain, None) + + logger.debug("Invoking fetch_generator_from_path(%s) ...", domain) software = fetch_generator_from_path(domain) logger.debug("Generator for domain='%s' is: '%s'", domain, software) elif "software" not in data or "name" not in data["software"]: - logger.debug("JSON response from domain='%s' does not include [software][name], fetching / ...", domain) + logger.debug("JSON response from domain='%s' does not include [software][name] - Resetting detection_mode,nodeinfo_url ...", domain) instances.set_detection_mode(domain, None) instances.set_nodeinfo_url(domain, None) + + logger.debug("Invoking fetch_generator_from_path(%s) ...", domain) software = fetch_generator_from_path(domain) logger.debug("Generator for domain='%s' is: '%s'", domain, software) -- 2.39.5