From adc069b74ac58eb5a97d93c0cf72fe86027d3ad1 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Fri, 16 Jun 2023 01:45:16 +0200 Subject: [PATCH] Continued: - rewrote block for fetching nodeinfo, fetch is provided path is None or matches with request or http[s]://domain/path - if a protocol is given in 'path' parameter, then it needs to be removed --- fba/federation.py | 44 ++++++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/fba/federation.py b/fba/federation.py index 2d0b6d7..fc33f0d 100644 --- a/fba/federation.py +++ b/fba/federation.py @@ -13,6 +13,8 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . +from urllib.parse import urlparse + import bs4 import validators @@ -245,26 +247,28 @@ def fetch_nodeinfo(domain: str, path: str = None) -> dict: for request in request_paths: # DEBUG: print(f"DEBUG: path[{type(path)}]='{path}',request='{request}'") - if path is not None and path != "" and path != request: - # DEBUG: print(f"DEBUG: path='{path}' does not match request='{request}' - SKIPPED!") - continue - - # DEBUG: print(f"DEBUG: Fetching request='{request}' from domain='{domain}' ...") - data = network.get_json_api( - domain, - request, - headers, - (config.get("nodeinfo_connection_timeout"), config.get("nodeinfo_read_timeout")) - ) - - # DEBUG: print(f"DEBUG: response.ok={response.ok},response.status_code={response.status_code},data[]='{type(data)}'") - if "error_message" not in data: - # DEBUG: print("DEBUG: Success:", request) - instances.set_detection_mode(domain, "STATIC_CHECK") - instances.set_nodeinfo_url(domain, request) - break - - print(f"WARNING: Failed fetching nodeinfo from domain='{domain}',status_code='{data['status_code']}',error_message='{data['error_message']}'") + if path is None or path == request or path == f"http://{domain}{path}" or path == f"https://{domain}{path}": + # DEBUG: print(f"DEBUG: Fetching request='{request}' from domain='{domain}' ...") + if path == f"http://{domain}{path}" or path == f"https://{domain}{path}": + print(f"DEBUG: domain='{domain}',path='{path}' has protocol in path, splitting ...") + components = urlparse(path) + path = components.path + + data = network.get_json_api( + domain, + request, + headers, + (config.get("nodeinfo_connection_timeout"), config.get("nodeinfo_read_timeout")) + ) + + # DEBUG: print(f"DEBUG: response.ok={response.ok},response.status_code={response.status_code},data[]='{type(data)}'") + if "error_message" not in data: + # DEBUG: print("DEBUG: Success:", request) + instances.set_detection_mode(domain, "STATIC_CHECK") + instances.set_nodeinfo_url(domain, request) + break + + print(f"WARNING: Failed fetching nodeinfo from domain='{domain}',status_code='{data['status_code']}',error_message='{data['error_message']}'") # DEBUG: print(f"DEBUG: data()={len(data)} - EXIT!") return data -- 2.39.5