From e1c6679e8d3177383ab7a68aad361d71726bb7c6 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Sat, 1 Jul 2023 05:20:33 +0200 Subject: [PATCH] Continued: - unwrap data["json"] so more instances can be fetched --- fba/http/federation.py | 52 ++++++++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 25 deletions(-) diff --git a/fba/http/federation.py b/fba/http/federation.py index 732dec2..b1a87fa 100644 --- a/fba/http/federation.py +++ b/fba/http/federation.py @@ -454,35 +454,37 @@ def determine_software(domain: str, path: str = None) -> str: logger.debug("Generator for domain='%s' is: '%s'", domain, software) elif "json" in data: logger.debug("domain='%s',path='%s',data[json] found ...", domain, path) - if "status" in data["json"] and data["json"]["status"] == "error" and "message" in data["json"]: - logger.warning("JSON response is an error: '%s'", data["json"]["message"]) - instances.set_last_error(domain, data["json"]["message"]) - instances.set_detection_mode(domain, None) - instances.set_nodeinfo_url(domain, None) - software = fetch_generator_from_path(domain) - logger.debug("Generator for domain='%s' is: '%s'", domain, software) - elif "software" in data["json"] and "name" in data["json"]["software"]: - logger.debug("Found data[json][software][name] in JSON response") - software = data["json"]["software"]["name"] - logger.debug("software[%s]='%s' - FOUND!", type(software), software) - elif "message" in data["json"]: - logger.warning("JSON response contains only a message: '%s'", data["json"]["message"]) - instances.set_last_error(domain, data["json"]["message"]) - instances.set_detection_mode(domain, None) - instances.set_nodeinfo_url(domain, None) - software = fetch_generator_from_path(domain) - logger.debug("Generator for domain='%s' is: '%s'", domain, software) - elif "software" not in data["json"] or "name" not in data["json"]["software"]: - logger.debug("JSON response from domain='%s' does not include [software][name], fetching / ...", domain) - instances.set_detection_mode(domain, None) - instances.set_nodeinfo_url(domain, None) - software = fetch_generator_from_path(domain) - logger.debug("Generator for domain='%s' is: '%s'", domain, software) - elif "json" not in data: + data = data["json"] + else: logger.debug("JSON response from domain='%s' does not include [software][name], fetching / ...", domain) software = fetch_generator_from_path(domain) 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"]) + instances.set_last_error(domain, data["message"]) + instances.set_detection_mode(domain, None) + instances.set_nodeinfo_url(domain, None) + software = fetch_generator_from_path(domain) + logger.debug("Generator for domain='%s' is: '%s'", domain, software) + elif "software" in data and "name" in data["software"]: + logger.debug("Found data[json][software][name] in JSON response") + 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"]) + instances.set_last_error(domain, data["message"]) + instances.set_detection_mode(domain, None) + instances.set_nodeinfo_url(domain, None) + 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) + instances.set_detection_mode(domain, None) + instances.set_nodeinfo_url(domain, None) + software = fetch_generator_from_path(domain) + logger.debug("Generator for domain='%s' is: '%s'", domain, software) + logger.debug("software[%s]='%s'", type(software), software) if software is None: logger.debug("Returning None - EXIT!") -- 2.39.5