]> git.mxchange.org Git - fba.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Tue, 20 Jun 2023 11:52:59 +0000 (13:52 +0200)
committerRoland Häder <roland@mxchange.org>
Tue, 20 Jun 2023 11:53:57 +0000 (13:53 +0200)
- stopping other bad domains from entering functions
- also need to catch urlib3 exception

fba/federation.py
fba/network.py

index 71e02d91bbb9426eaf601c8adc914cc5753594ef..45aa32d15573e923c9e94ad9163d828518b77892 100644 (file)
@@ -50,6 +50,10 @@ def fetch_instances(domain: str, origin: str, software: str, command: str, path:
         raise ValueError(f"Parameter domain[]='{type(domain)}' is not 'str'")
     elif domain == "":
         raise ValueError("Parameter 'domain' is empty")
+    elif not validators.domain(domain):
+        raise ValueErrror(f"domain='{domain}' is not a valid domain")
+    elif domain.endswith(".arpa"):
+        raise ValueError(f"domain='{domain}' is a domain for reversed IP addresses, please don't crawl them!")
     elif domain.endswith(".tld"):
         raise ValueError(f"domain='{domain}' is a fake domain, please don't crawl them!")
     elif not isinstance(origin, str) and origin is not None:
@@ -144,6 +148,12 @@ def fetch_peers(domain: str, software: str) -> list:
         raise ValueError(f"Parameter domain[]='{type(domain)}' is not 'str'")
     elif domain == "":
         raise ValueError("Parameter 'domain' is empty")
+    elif not validators.domain(domain):
+        raise ValueErrror(f"domain='{domain}' is not a valid domain")
+    elif domain.endswith(".arpa"):
+        raise ValueError(f"domain='{domain}' is a domain for reversed IP addresses, please don't crawl them!")
+    elif domain.endswith(".tld"):
+        raise ValueError(f"domain='{domain}' is a fake domain, please don't crawl them!")
     elif not isinstance(software, str) and software is not None:
         raise ValueError(f"software[]='{type(software)}' is not 'str'")
 
@@ -218,6 +228,12 @@ def fetch_nodeinfo(domain: str, path: str = None) -> dict:
         raise ValueError(f"Parameter domain[]='{type(domain)}' is not 'str'")
     elif domain == "":
         raise ValueError("Parameter 'domain' is empty")
+    elif not validators.domain(domain):
+        raise ValueErrror(f"domain='{domain}' is not a valid domain")
+    elif domain.endswith(".arpa"):
+        raise ValueError(f"domain='{domain}' is a domain for reversed IP addresses, please don't crawl them!")
+    elif domain.endswith(".tld"):
+        raise ValueError(f"domain='{domain}' is a fake domain, please don't crawl them!")
     elif not isinstance(path, str) and path is not None:
         raise ValueError(f"Parameter path[]='{type(path)}' is not 'str'")
 
@@ -288,6 +304,12 @@ def fetch_wellknown_nodeinfo(domain: str) -> dict:
         raise ValueError(f"Parameter domain[]='{type(domain)}' is not 'str'")
     elif domain == "":
         raise ValueError("Parameter 'domain' is empty")
+    elif not validators.domain(domain):
+        raise ValueErrror(f"domain='{domain}' is not a valid domain")
+    elif domain.endswith(".arpa"):
+        raise ValueError(f"domain='{domain}' is a domain for reversed IP addresses, please don't crawl them!")
+    elif domain.endswith(".tld"):
+        raise ValueError(f"domain='{domain}' is a fake domain, please don't crawl them!")
 
     # No CSRF by default, you don't have to add network.api_headers by yourself here
     headers = tuple()
@@ -359,6 +381,12 @@ def fetch_generator_from_path(domain: str, path: str = "/") -> str:
         raise ValueError(f"Parameter domain[]='{type(domain)}' is not 'str'")
     elif domain == "":
         raise ValueError("Parameter 'domain' is empty")
+    elif not validators.domain(domain):
+        raise ValueErrror(f"domain='{domain}' is not a valid domain")
+    elif domain.endswith(".arpa"):
+        raise ValueError(f"domain='{domain}' is a domain for reversed IP addresses, please don't crawl them!")
+    elif domain.endswith(".tld"):
+        raise ValueError(f"domain='{domain}' is a fake domain, please don't crawl them!")
     elif not isinstance(path, str):
         raise ValueError(f"path[]='{type(path)}' is not 'str'")
     elif path == "":
index b4d320d073c48e8db19155e714c34573c6fddf53..5b3aa0ea437f7417229d659d7da2670e4b7ffa77 100644 (file)
@@ -17,6 +17,8 @@
 import json
 import reqto
 import requests
+import urllib3
+import validators
 
 from fba import config
 from fba import fba
@@ -42,7 +44,8 @@ exceptions = (
     requests.exceptions.InvalidURL,
     requests.exceptions.Timeout,
     requests.exceptions.TooManyRedirects,
-    UnicodeEncodeError
+    UnicodeEncodeError,
+    urllib3.exceptions.LocationParseError
 )
 
 def post_json_api(domain: str, path: str, data: str = "", headers: dict = {}) -> dict:
@@ -51,6 +54,10 @@ def post_json_api(domain: str, path: str, data: str = "", headers: dict = {}) ->
         raise ValueError(f"Parameter domain[]='{type(domain)}' is not 'str'")
     elif domain == "":
         raise ValueError("Parameter 'domain' is empty")
+    elif not validators.domain(domain):
+        raise ValueErrror(f"domain='{domain}' is not a valid domain")
+    elif domain.endswith(".arpa"):
+        raise ValueError(f"domain='{domain}' is a domain for reversed IP addresses, please don't crawl them!")
     elif domain.endswith(".tld"):
         raise ValueError(f"domain='{domain}' is a fake domain, please don't crawl them!")
     elif not isinstance(path, str):
@@ -136,6 +143,10 @@ def get_json_api(domain: str, path: str, headers: dict, timeout: tuple) -> dict:
         raise ValueError(f"Parameter domain[]='{type(domain)}' is not 'str'")
     elif domain == "":
         raise ValueError("Parameter 'domain' is empty")
+    elif not validators.domain(domain):
+        raise ValueErrror(f"domain='{domain}' is not a valid domain")
+    elif domain.endswith(".arpa"):
+        raise ValueError(f"domain='{domain}' is a domain for reversed IP addresses, please don't crawl them!")
     elif domain.endswith(".tld"):
         raise ValueError(f"domain='{domain}' is a fake domain, please don't crawl them!")
     elif not isinstance(path, str):
@@ -233,6 +244,10 @@ def fetch_response(domain: str, path: str, headers: dict, timeout: tuple) -> req
         raise ValueError(f"Parameter domain[]='{type(domain)}' is not 'str'")
     elif domain == "":
         raise ValueError("Parameter 'domain' is empty")
+    elif not validators.domain(domain):
+        raise ValueErrror(f"domain='{domain}' is not a valid domain")
+    elif domain.endswith(".arpa"):
+        raise ValueError(f"domain='{domain}' is a domain for reversed IP addresses, please don't crawl them!")
     elif domain.endswith(".tld"):
         raise ValueError(f"domain='{domain}' is a fake domain, please don't crawl them!")
     elif not isinstance(path, str):