From: Roland Häder Date: Sun, 11 Jun 2023 02:53:42 +0000 (+0200) Subject: Continued: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=f955b100e984685baeb0c27b0705148d765bb9ce;p=fba.git Continued: - also need to put a try/except block around csrf.determine() invocations --- diff --git a/fba/commands.py b/fba/commands.py index 401f6a4..078bc4f 100644 --- a/fba/commands.py +++ b/fba/commands.py @@ -206,7 +206,7 @@ def fetch_blocks(args: argparse.Namespace): searchres = fba.cursor.fetchone() - print(f"DEBUG: searchres[]='{type(searchres)}'") + # DEBUG: print(f"DEBUG: searchres[]='{type(searchres)}'") if searchres is None: print(f"WARNING: Cannot deobsfucate blocked='{blocked}' - SKIPPED!") continue @@ -222,7 +222,7 @@ def fetch_blocks(args: argparse.Namespace): searchres = fba.cursor.fetchone() - print(f"DEBUG: searchres[]='{type(searchres)}'") + # DEBUG: print(f"DEBUG: searchres[]='{type(searchres)}'") if searchres is None: print(f"WARNING: Cannot deobsfucate blocked='{blocked}' - SKIPPED!") continue diff --git a/fba/federation.py b/fba/federation.py index df408cb..9f1e009 100644 --- a/fba/federation.py +++ b/fba/federation.py @@ -122,9 +122,14 @@ def fetch_peers(domain: str, software: str) -> list: # Init peers variable peers = list() + headers = tuple() # DEBUG: print(f"DEBUG: Checking CSRF for domain='{domain}'") - headers = csrf.determine(domain, dict()) + try: + headers = csrf.determine(domain, dict()) + except network.exceptions as exception: + print(f"WARNING: Exception '{type(exception)}' during checking CSRF - EXIT!") + return # DEBUG: print(f"DEBUG: Fetching peers from '{domain}',software='{software}' ...") data = network.get_json_api( @@ -185,8 +190,14 @@ def fetch_nodeinfo(domain: str, path: str = None) -> list: # DEBUG: print("DEBUG: nodeinfo()={len(nodeinfo))} - EXIT!") return nodeinfo + headers = tuple() + # DEBUG: print(f"DEBUG: Checking CSRF for domain='{domain}'") - headers = csrf.determine(domain, dict()) + try: + headers = csrf.determine(domain, dict()) + except network.exceptions as exception: + print(f"WARNING: Exception '{type(exception)}' during checking CSRF - EXIT!") + return request_paths = [ "/nodeinfo/2.1.json", @@ -229,8 +240,14 @@ def fetch_wellknown_nodeinfo(domain: str) -> list: elif domain == "": raise ValueError("Parameter 'domain' is empty") + headers = tuple() + # DEBUG: print(f"DEBUG: Checking CSRF for domain='{domain}'") - headers = csrf.determine(domain, dict()) + try: + headers = csrf.determine(domain, dict()) + except network.exceptions as exception: + print(f"WARNING: Exception '{type(exception)}' during checking CSRF - EXIT!") + return # DEBUG: print("DEBUG: Fetching .well-known info for domain:", domain) data = network.get_json_api( diff --git a/fba/networks/lemmy.py b/fba/networks/lemmy.py index df63ae0..9b283c0 100644 --- a/fba/networks/lemmy.py +++ b/fba/networks/lemmy.py @@ -27,8 +27,14 @@ def fetch_peers(domain: str) -> list: elif domain == "": raise ValueError("Parameter 'domain' is empty") - print(f"DEBUG: Checking CSRF for domain='{domain}'") - headers = csrf.determine(domain, dict()) + headers = tuple() + + # DEBUG: print(f"DEBUG: Checking CSRF for domain='{domain}'") + try: + headers = csrf.determine(domain, dict()) + except network.exceptions as exception: + print(f"WARNING: Exception '{type(exception)}' during checking CSRF - EXIT!") + return peers = list() try: diff --git a/fba/networks/mastodon.py b/fba/networks/mastodon.py index 424a023..2ce6331 100644 --- a/fba/networks/mastodon.py +++ b/fba/networks/mastodon.py @@ -131,8 +131,14 @@ def fetch_blocks(domain: str, origin: str, nodeinfo_url: str): elif nodeinfo_url == "": raise ValueError("Parameter 'nodeinfo_url' is empty") - print(f"DEBUG: Checking CSRF for domain='{domain}'") - headers = csrf.determine(domain, dict()) + headers = tuple() + + # DEBUG: print(f"DEBUG: Checking CSRF for domain='{domain}'") + try: + headers = csrf.determine(domain, dict()) + except network.exceptions as exception: + print(f"WARNING: Exception '{type(exception)}' during checking CSRF - EXIT!") + return try: # json endpoint for newer mastodongs @@ -222,7 +228,7 @@ def fetch_blocks(domain: str, origin: str, nodeinfo_url: str): ) searchres = fba.cursor.fetchone() - print(f"DEBUG: searchres[]='{type(searchres)}'") + # DEBUG: print(f"DEBUG: searchres[]='{type(searchres)}'") if searchres is None: print(f"WARNING: Cannot deobsfucate blocked='{blocked}',blocked_hash='{blocked_hash}' - SKIPPED!") continue diff --git a/fba/networks/misskey.py b/fba/networks/misskey.py index f3a1eb3..f797912 100644 --- a/fba/networks/misskey.py +++ b/fba/networks/misskey.py @@ -38,7 +38,14 @@ def fetch_peers(domain: str) -> list: peers = list() offset = 0 step = config.get("misskey_limit") - headers = csrf.determine(domain, {"Origin": domain}) + headers = tuple() + + # DEBUG: print(f"DEBUG: Checking CSRF for domain='{domain}'") + try: + headers = csrf.determine(domain, dict()) + except network.exceptions as exception: + print(f"WARNING: Exception '{type(exception)}' during checking CSRF - EXIT!") + return # iterating through all "suspended" (follow-only in its terminology) # instances page-by-page, since that troonware doesn't support @@ -132,7 +139,14 @@ def fetch_blocks(domain: str) -> dict: offset = 0 step = config.get("misskey_limit") - headers = csrf.determine(domain, {"Origin": domain}) + headers = tuple() + + # DEBUG: print(f"DEBUG: Checking CSRF for domain='{domain}'") + try: + headers = csrf.determine(domain, dict()) + except network.exceptions as exception: + print(f"WARNING: Exception '{type(exception)}' during checking CSRF - EXIT!") + return # iterating through all "suspended" (follow-only in its terminology) # instances page-by-page since it doesn't support sending them all at once diff --git a/fba/networks/peertube.py b/fba/networks/peertube.py index 96fc880..44c8c07 100644 --- a/fba/networks/peertube.py +++ b/fba/networks/peertube.py @@ -27,11 +27,16 @@ def fetch_peers(domain: str) -> list: raise ValueError("Parameter 'domain' is empty") print(f"DEBUG: domain='{domain}' is a PeerTube, fetching JSON ...") - peers = list() - start = 0 + peers = list() + start = 0 + headers = tuple() print(f"DEBUG: Checking CSRF for domain='{domain}'") - headers = csrf.determine(domain, dict()) + try: + headers = csrf.determine(domain, dict()) + except network.exceptions as exception: + print(f"WARNING: Exception '{type(exception)}' during checking CSRF - EXIT!") + return for mode in ["followers", "following"]: print(f"DEBUG: domain='{domain}',mode='{mode}'") diff --git a/fba/networks/pleroma.py b/fba/networks/pleroma.py index 86f69cd..8941b8a 100644 --- a/fba/networks/pleroma.py +++ b/fba/networks/pleroma.py @@ -173,7 +173,7 @@ def fetch_blocks(domain: str, origin: str, nodeinfo_url: str): ) searchres = fba.cursor.fetchone() - print(f"DEBUG: searchres[]='{type(searchres)}'") + # DEBUG: print(f"DEBUG: searchres[]='{type(searchres)}'") if searchres is None: print(f"WARNING: Cannot deobsfucate blocked='{blocked}' - SKIPPED!") continue