if args.domain != None and args.domain != "":
# Re-check single domain
fba.cursor.execute(
- "SELECT domain, software, origin, nodeinfo_url FROM instances WHERE software IN ('pleroma', 'mastodon', 'friendica', 'misskey', 'gotosocial', 'bookwyrm', 'takahe') AND domain = ?", [args.domain]
+ "SELECT domain, software, origin, nodeinfo_url FROM instances WHERE software IN ('pleroma', 'mastodon', 'friendica', 'misskey', 'bookwyrm', 'takahe') AND domain = ?", [args.domain]
)
else:
# Re-check after "timeout" (aka. minimum interval)
fba.cursor.execute(
- "SELECT domain, software, origin, nodeinfo_url FROM instances WHERE software IN ('pleroma', 'mastodon', 'friendica', 'misskey', 'gotosocial', 'bookwyrm', 'takahe') AND (last_blocked IS NULL OR last_blocked < ?) ORDER BY rowid DESC", [time.time() - config.get("recheck_block")]
+ "SELECT domain, software, origin, nodeinfo_url FROM instances WHERE software IN ('pleroma', 'mastodon', 'friendica', 'misskey', 'bookwyrm', 'takahe') AND (last_blocked IS NULL OR last_blocked < ?) ORDER BY rowid DESC", [time.time() - config.get("recheck_block")]
)
rows = fba.cursor.fetchall()
fba.connection.commit()
except Exception as e:
print(f"ERROR: blocker='{blocker}',software='{software}',exception[{type(e)}]:'{str(e)}'")
- elif software == "gotosocial":
- print(f"INFO: blocker='{blocker}',software='{software}'")
- gotosocial.fetch_blocks(blocker, origin, nodeinfo_url)
else:
print("WARNING: Unknown software:", blocker, software)
# Loop through some instances
fba.cursor.execute(
- "SELECT domain, origin, software, nodeinfo_url FROM instances WHERE software IN ('pleroma', 'mastodon', 'friendica', 'misskey', 'gotosocial', 'bookwyrm', 'takahe', 'lemmy') AND (last_instance_fetch IS NULL OR last_instance_fetch < ?) ORDER BY rowid DESC", [time.time() - config.get("recheck_instance")]
+ "SELECT domain, origin, software, nodeinfo_url FROM instances WHERE software IN ('pleroma', 'mastodon', 'friendica', 'misskey', 'bookwyrm', 'takahe', 'lemmy') AND (last_instance_fetch IS NULL OR last_instance_fetch < ?) ORDER BY rowid DESC", [time.time() - config.get("recheck_instance")]
)
rows = fba.cursor.fetchall()
+++ /dev/null
-# Fedi API Block - An aggregator for fetching blocking data from fediverse nodes
-# Copyright (C) 2023 Free Software Foundation
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU Affero General Public License as published
-# by the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU Affero General Public License for more details.
-#
-# 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 inspect
-import validators
-
-from fba import blacklist
-from fba import blocks
-from fba import config
-from fba import fba
-from fba import instances
-
-def fetch_blocks(domain: str, origin: str, nodeinfo_url: str):
- print(f"DEBUG: domain='{domain}',origin='{origin}',nodeinfo_url='{nodeinfo_url}' - CALLED!")
- if type(domain) != str:
- raise ValueError(f"Parameter domain[]={type(domain)} is not 'str'")
- elif domain == "":
- raise ValueError(f"Parameter 'domain' is empty")
- elif type(origin) != str and origin != None:
- raise ValueError(f"Parameter origin[]={type(origin)} is not 'str'")
- elif origin == "":
- raise ValueError(f"Parameter 'origin' is empty")
- elif type(nodeinfo_url) != str:
- raise ValueError(f"Parameter nodeinfo_url[]={type(nodeinfo_url)} is not 'str'")
- elif nodeinfo_url == "":
- raise ValueError(f"Parameter 'nodeinfo_url' is empty")
-
- try:
- # Blocks
- federation = fba.get_response(domain, f"/api/v1/instance/peers?filter=suspended", fba.api_headers, (config.get("connection_timeout"), config.get("read_timeout"))).json()
-
- if (federation == None):
- print("WARNING: No valid response:", domain);
- elif "error" in federation:
- print("WARNING: API returned error:", federation["error"])
- else:
- print(f"INFO: Checking {len(federation)} entries from domain='{domain}',software='gotosocial' ...")
- for peer in federation:
- blocked = peer["domain"].lower()
- print("DEBUG: BEFORE blocked:", blocked)
- blocked = fba.tidyup_domain(blocked)
- print("DEBUG: AFTER blocked:", blocked)
-
- if blocked == "":
- print("WARNING: blocked is empty:", domain)
- continue
- elif blacklist.is_blacklisted(blocked):
- print(f"DEBUG: blocked='{blocked}' is blacklisted - skipping!")
- continue
- elif blocked.count("*") > 0:
- # GTS does not have hashes for obscured domains, so we have to guess it
- fba.cursor.execute(
- "SELECT domain, origin, nodeinfo_url FROM instances WHERE domain LIKE ? ORDER BY rowid LIMIT 1", [blocked.replace("*", "_")]
- )
- searchres = fba.cursor.fetchone()
-
- if searchres == None:
- print(f"WARNING: Cannot deobsfucate blocked='{blocked}' - SKIPPED!")
- continue
-
- blocked = searchres[0]
- origin = searchres[1]
- nodeinfo_url = searchres[2]
- elif not validators.domain(blocked):
- print(f"WARNING: blocked='{blocked}',software='gotosocial' is not a valid domain name - skipped!")
- continue
-
- print("DEBUG: Looking up instance by domain:", blocked)
- if not validators.domain(blocked):
- print(f"WARNING: blocked='{blocked}',software='gotosocial' is not a valid domain name - skipped!")
- continue
- elif not instances.is_registered(blocked):
- print(f"DEBUG: Domain blocked='{blocked}' wasn't found, adding ..., domain='{domain}',origin='{origin}',nodeinfo_url='{nodeinfo_url}'")
- instances.add(blocked, domain, inspect.currentframe().f_code.co_name, nodeinfo_url)
-
- if not blocks.is_instance_blocked(domain, blocked, "reject"):
- print(f"DEBUG: domain='{domain}' is blocking '{blocked}' for unknown reason at this point")
- blocks.add_instance(domain, blocked, "unknown", "reject")
-
- blockdict.append({
- "blocked": blocked,
- "reason" : None
- })
- else:
- print(f"DEBUG: Updating block last seen for domain='{domain}',blocked='{blocked}' ...")
- blocks.update_last_seen(domain, blocked, "reject")
-
- if "public_comment" in peer:
- print("DEBUG: Updating block reason:", domain, blocked, peer["public_comment"])
- blocks.update_reason(peer["public_comment"], domain, blocked, "reject")
-
- for entry in blockdict:
- if entry["blocked"] == blocked:
- print(f"DEBUG: Setting block reason for blocked='{blocked}':'{peer['public_comment']}'")
- entry["reason"] = peer["public_comment"]
-
- print("DEBUG: Committing changes ...")
- fba.connection.commit()
- except Exception as e:
- print(f"ERROR: domain='{domain}',software='gotosocial',exception[{type(e)}]:'{str(e)}'")
-
- print("DEBUG: EXIT!")