]> git.mxchange.org Git - fba.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Tue, 20 Jun 2023 13:37:10 +0000 (15:37 +0200)
committerRoland Häder <roland@mxchange.org>
Tue, 20 Jun 2023 13:37:10 +0000 (15:37 +0200)
- added argument --software to command fetch_blocks
- added some missing checks on parameter 'domain'
- removed unused imports

fba/boot.py
fba/commands.py
fba/csrf.py
fba/federation.py
fba/models/blocks.py
fba/models/instances.py
fba/network.py

index 67d02a1e48bd90994dfb1ba9ace5cbd0588c4553..ed80085c1b2f581bb28b0e372e559267f350c156 100644 (file)
@@ -59,7 +59,8 @@ def init_parser():
         "fetch_blocks",
         help="Fetches blocks from registered instances (run command fetch_instances first!).",
     )
-    parser.add_argument("--domain", help="Instance name (aka. domain) to fetch blocks from")
+    parser.add_argument("--domain", help="Instance name (aka. domain)")
+    parser.add_argument("--software", help="Name of software, e.g. 'lemmy'")
     parser.set_defaults(command=commands.fetch_blocks)
 
     ### Fetch blocks from chaos.social ###
index f10fb56482de673673d876d06badafdfd78a5f37..190a92d675e453994de8de5bc4fbc5283e02fbc6 100644 (file)
@@ -153,6 +153,12 @@ def fetch_blocks(args: argparse.Namespace):
         fba.cursor.execute(
             "SELECT domain, software, origin, nodeinfo_url FROM instances WHERE domain = ?", [args.domain]
         )
+    elif args.software is not None and args.software != "":
+        # Re-check single software
+        # DEBUG: print(f"DEBUG: Querying database for args.software='{args.software}' ...")
+        fba.cursor.execute(
+            "SELECT domain, software, origin, nodeinfo_url FROM instances WHERE software = ?", [args.software]
+        )
     else:
         # Re-check after "timeout" (aka. minimum interval)
         fba.cursor.execute(
index 537314e23a5023c9f460fcc4ed07e8fcc868893b..4eedcc77ce393db0c676306d8ce1293682dd1db0 100644 (file)
@@ -16,6 +16,7 @@
 
 import bs4
 import reqto
+import validators
 
 from fba import config
 from fba import network
@@ -28,6 +29,10 @@ def determine(domain: str, headers: dict) -> dict:
         raise ValueError(f"Parameter domain[]='{type(domain)}' is not 'str'")
     elif domain == "":
         raise ValueError("Parameter 'domain' is empty")
+    elif not validators.domain(domain.split("/")[0]):
+        raise ValueError(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(headers, dict):
index 5e01148b6ad9b3b9bb58a69a6e76362c26050541..e583949410a5742463c635924d52f7de2ba768bd 100644 (file)
@@ -82,6 +82,8 @@ def fetch_instances(domain: str, origin: str, software: str, command: str, path:
         return
     elif not validators.domain(domain.split("/")[0]):
         raise ValueError(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")
 
index b23f4e015e88c119b7ffaa22ea7b835b34a25599..2111164e269e4468f3c5f7273119b397028eadda 100644 (file)
@@ -14,7 +14,6 @@
 # You should have received a copy of the GNU Affero General Public License
 # along with this program.  If not, see <https://www.gnu.org/licenses/>.
 
-import sys
 import time
 import validators
 
index e1a11430645241f4090eb6c8c38f6ddaf22b39c3..0ed262ed7b2aeb09f2db5bec69b2e495be1bac3c 100644 (file)
@@ -15,7 +15,6 @@
 # along with this program.  If not, see <https://www.gnu.org/licenses/>.
 
 import json
-import sys
 import time
 
 import requests
index 1378859356d034e438c0bbdff630a9eff99813d9..79ac8f7b03bb4fc6d2abc91b43b6be5b66cf1f12 100644 (file)
@@ -201,6 +201,10 @@ def send_bot_post(domain: str, blocklist: dict):
         raise ValueError(f"Parameter domain[]='{type(domain)}' is not 'str'")
     elif domain == "":
         raise ValueError("Parameter 'domain' is empty")
+    elif not validators.domain(domain.split("/")[0]):
+        raise ValueError(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(blocklist, dict):