]> git.mxchange.org Git - fba.git/commitdiff
Testing:
authorRoland Häder <roland@mxchange.org>
Fri, 30 Jun 2023 23:37:25 +0000 (01:37 +0200)
committerRoland Häder <roland@mxchange.org>
Fri, 30 Jun 2023 23:38:42 +0000 (01:38 +0200)
- allow no redirects as normal Fediverse instances should neve redirect
- send_bot_post() accepts as 2nd parameter a list, not a dictionary

fba/commands.py
fba/csrf.py
fba/http/network.py

index 58a39bc8826be4f2435effa50c80aa68f0779edd..55be64e8ee8c7421c13ff77749750377c2d2d261 100644 (file)
@@ -360,7 +360,7 @@ def fetch_blocks(args: argparse.Namespace) -> int:
         logger.debug("Invoking cookies.clear(%s) ...", blocker)
         cookies.clear(blocker)
 
-        logger.debug("config[bot_enabled]='%s',blockdict()=%d'", config.get("bot_enabled"), len(blockdict))
+        logger.debug("config.get(bot_enabled)='%s',blockdict()=%d'", config.get("bot_enabled"), len(blockdict))
         if config.get("bot_enabled") and len(blockdict) > 0:
             logger.info("Sending bot POST for blocker='%s',blockdict()=%d ...", blocker, len(blockdict))
             network.send_bot_post(blocker, blockdict)
@@ -501,6 +501,7 @@ def fetch_todon_wiki(args: argparse.Namespace) -> int:
         logger.debug("Invoking commit() ...")
         database.connection.commit()
 
+        logger.debug("config.get(bot_enabled)='%s',blockdict()=%d", config.get("bot_enabled"), len(blockdict))
         if config.get("bot_enabled") and len(blockdict) > 0:
             logger.info("Sending bot POST for blocker='todon.eu',blockdict()=%d ...", len(blockdict))
             network.send_bot_post("todon.eu", blockdict)
@@ -580,6 +581,7 @@ def fetch_cs(args: argparse.Namespace):
         logger.debug("Invoking commit() ...")
         database.connection.commit()
 
+        logger.debug("config.get(bot_enabled)='%s',blockdict()=%d", config.get("bot_enabled"), len(blockdict))
         if config.get("bot_enabled") and len(blockdict) > 0:
             logger.info("Sending bot POST for blocker='chaos.social',blockdict()=%d ...", len(blockdict))
             network.send_bot_post("chaos.social", blockdict)
@@ -870,6 +872,7 @@ def fetch_oliphant(args: argparse.Namespace) -> int:
         logger.debug("Invoking commit() ...")
         database.connection.commit()
 
+        logger.debug("config.get(bot_enabled)='%s',blockdict()=%d", config.get("bot_enabled"), len(blockdict))
         if config.get("bot_enabled") and len(blockdict) > 0:
             logger.info("Sending bot POST for blocker='%s',blockdict()=%d ...", block["blocker"], len(blockdict))
             network.send_bot_post(block["blocker"], blockdict)
@@ -1100,6 +1103,7 @@ def fetch_joinfediverse(args: argparse.Namespace) -> int:
         logger.debug("Invoking commit() ...")
         database.connection.commit()
 
+        logger.debug("config.get(bot_enabled)='%s',blockdict()=%d", config.get("bot_enabled"), len(blockdict))
         if config.get("bot_enabled") and len(blockdict) > 0:
             logger.info("Sending bot POST for blocker='%s,blockdict()=%d ...", blocker, len(blockdict))
             network.send_bot_post(blocker, blockdict)
@@ -1200,6 +1204,7 @@ def recheck_obfuscation(args: argparse.Namespace) -> int:
         logger.debug("Invoking commit() ...")
         database.connection.commit()
 
+        logger.debug("config.get(bot_enabled)='%s',blockdict()=%d", config.get("bot_enabled"), len(blockdict))
         if config.get("bot_enabled") and len(blockdict) > 0:
             logger.info("Sending bot POST for blocker='%s,blockdict()=%d ...", row["domain"], len(blockdict))
             network.send_bot_post(row["domain"], blockdict)
index e68fcb63ef0ee25eebafcb09fc39afca50957e9a..401b7cd6ba252fe758bb8b923bb5e76b845f059c 100644 (file)
@@ -43,7 +43,8 @@ def determine(domain: str, headers: dict) -> dict:
     response = reqto.get(
         f"https://{domain}/",
         headers=network.web_headers,
-        timeout=(config.get("connection_timeout"), config.get("read_timeout"))
+        timeout=(config.get("connection_timeout"), config.get("read_timeout")),
+        allow_redirects=False
     )
 
     logger.debug("response.ok='%s',response.status_code=%d,response.text()=%d", response.ok, response.status_code, len(response.text))
index f347b79f2a1c0eaab43a42f91f9fb8f2406ab923..7081ba8f3dd4a03ab62fa2c7b89545d9f698f381 100644 (file)
@@ -80,7 +80,8 @@ def post_json_api(domain: str, path: str, data: str = "", headers: dict = dict()
             data=data,
             headers={**api_headers, **headers},
             timeout=(config.get("connection_timeout"), config.get("read_timeout")),
-            cookies=cookies.get_all(domain) if cookies.has(domain) else dict()
+            cookies=cookies.get_all(domain) if cookies.has(domain) else dict(),
+            allow_redirects=False
         )
 
         logger.debug("Parsing JSON response from domain='%s',path='%s' ...", domain, path)
@@ -165,7 +166,8 @@ def get_json_api(domain: str, path: str, headers: dict, timeout: tuple) -> dict:
             f"https://{domain}{path}",
             headers={**api_headers, **headers},
             timeout=timeout,
-            cookies=cookies.get_all(domain) if cookies.has(domain) else {}
+            cookies=cookies.get_all(domain) if cookies.has(domain) else {},
+            allow_redirects=False
         )
 
     except exceptions as exception:
@@ -190,12 +192,14 @@ def get_json_api(domain: str, path: str, headers: dict, timeout: tuple) -> dict:
     logger.debug("Returning json_reply(%d)[]='%s' - EXIT!", len(json_reply), type(json_reply))
     return json_reply
 
-def send_bot_post(domain: str, blocklist: dict):
+def send_bot_post(domain: str, blocklist: list):
     logger.debug("domain='%s',blocklist()=%d - CALLED!", domain, len(blocklist))
     domain_helper.raise_on(domain)
 
-    if not isinstance(blocklist, dict):
-        raise ValueError(f"Parameter blocklist[]='{type(blocklist)}' is not 'dict'")
+    if not isinstance(blocklist, list):
+        raise ValueError(f"Parameter blocklist[]='{type(blocklist)}' is not 'list'")
+    elif len(blocklist) == 0:
+        raise ValueError("Parameter 'blocklist' is empty")
 
     message = f"{domain} has blocked the following instances:\n\n"
     truncated = False
@@ -228,7 +232,8 @@ def send_bot_post(domain: str, blocklist: dict):
             "content_type": "text/plain"
         },
         headers=botheaders,
-        timeout=10
+        timeout=(config.get("connection_timeout"), config.get("read_timeout")),
+        allow_redirects=False
     ).json()
 
     return True
@@ -252,7 +257,8 @@ def fetch_response(domain: str, path: str, headers: dict, timeout: tuple) -> req
             f"https://{domain}{path}",
             headers=headers,
             timeout=timeout,
-            cookies=cookies.get_all(domain) if cookies.has(domain) else {}
+            cookies=cookies.get_all(domain) if cookies.has(domain) else {},
+            allow_redirects=False
         )
 
     except exceptions as exception: