continue
elif not fba.is_instance_registered(blocked):
# DEBUG: print("DEBUG: Hash wasn't found, adding:", blocked, blocker)
- fba.add_instance(blocked, blocker, inspect.currentframe().f_code.co_name, nodeinfo_url)
+ instances.add(blocked, blocker, inspect.currentframe().f_code.co_name, nodeinfo_url)
if not blocks.is_instance_blocked(blocker, blocked, block_level):
blocks.add_instance(blocker, blocked, reason, block_level)
if not is_instance_registered(domain):
# DEBUG: print("DEBUG: Adding new domain:", domain, origin)
- add_instance(domain, origin, script, path)
+ instances.add(domain, origin, script, path)
# DEBUG: print("DEBUG: Fetching instances for domain:", domain, software)
peerlist = get_peers(domain, software)
try:
if not is_instance_registered(instance):
# DEBUG: print("DEBUG: Adding new instance:", instance, domain)
- add_instance(instance, domain, script)
+ instances.add(instance, domain, script)
except BaseException as e:
print(f"ERROR: instance='{instance}',exception[{type(e)}]:'{str(e)}'")
continue
# DEBUG: print(f"DEBUG: registered='{registered}' - EXIT!")
return registered
-def add_instance(domain: str, origin: str, originator: str, path: str = None):
- # DEBUG: print(f"DEBUG: domain='{domain}',origin='{origin}',originator='{originator}',path='{path}' - 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"origin[]={type(origin)} is not 'str'")
- elif type(originator) != str:
- raise ValueError(f"originator[]={type(originator)} is not 'str'")
- elif originator == "":
- raise ValueError(f"originator cannot be empty")
- elif not validators.domain(domain.split("/")[0]):
- raise ValueError(f"Bad domain name='{domain}'")
- elif origin is not None and not validators.domain(origin.split("/")[0]):
- raise ValueError(f"Bad origin name='{origin}'")
- elif blacklist.is_blacklisted(domain):
- raise Exception(f"domain='{domain}' is blacklisted, but method invoked")
-
- # DEBUG: print("DEBUG: domain,origin,originator,path:", domain, origin, originator, path)
- software = determine_software(domain, path)
- # DEBUG: print("DEBUG: Determined software:", software)
-
- print(f"INFO: Adding instance domain='{domain}' (origin='{origin}',software='{software}')")
- try:
- cursor.execute(
- "INSERT INTO instances (domain, origin, originator, hash, software, first_seen) VALUES (?, ?, ?, ?, ?, ?)",
- (
- domain,
- origin,
- originator,
- get_hash(domain),
- software,
- time.time()
- ),
- )
-
- cache.set_sub_key("is_registered", domain, True)
-
- if instances.has_pending_instance_data(domain):
- # DEBUG: print(f"DEBUG: domain='{domain}' has pending nodeinfo being updated ...")
- instances.set("last_status_code" , domain, None)
- instances.set("last_error_details", domain, None)
- instances.update_instance_data(domain)
- remove_pending_error(domain)
-
- if domain in pending_errors:
- # DEBUG: print("DEBUG: domain has pending error being updated:", domain)
- update_last_error(domain, pending_errors[domain])
- remove_pending_error(domain)
-
- except BaseException as e:
- print(f"ERROR: failed SQL query: domain='{domain}',exception[{type(e)}]:'{str(e)}'")
- sys.exit(255)
- else:
- # DEBUG: print("DEBUG: Updating nodeinfo for domain:", domain)
- update_last_nodeinfo(domain)
-
- # DEBUG: print("DEBUG: EXIT!")
-
def send_bot_post(instance: str, blocklist: dict):
# DEBUG: print(f"DEBUG: instance={instance},blocklist()={len(blocklist)} - CALLED!")
if type(domain) != str:
from fba import config
from fba import fba
-def fetch_blocks(blocker: str, origin: str, nodeinfo_url: str):
+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'")
try:
# Blocks
- federation = fba.get_response(blocker, f"{fba.get_peers_url}?filter=suspended", fba.api_headers, (config.get("connection_timeout"), config.get("read_timeout"))).json()
+ federation = fba.get_response(domain, f"{fba.get_peers_url}?filter=suspended", fba.api_headers, (config.get("connection_timeout"), config.get("read_timeout"))).json()
if (federation == None):
- print("WARNING: No valid response:", blocker);
+ 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 blocker='{blocker}',software='{software}' ...")
+ print(f"INFO: Checking {len(federation)} entries from domain='{domain}',software='gotosocial' ...")
for peer in federation:
blocked = peer["domain"].lower()
# DEBUG: print("DEBUG: BEFORE blocked:", blocked)
# DEBUG: print("DEBUG: AFTER blocked:", blocked)
if blocked == "":
- print("WARNING: blocked is empty:", blocker)
+ print("WARNING: blocked is empty:", domain)
continue
elif blacklist.is_blacklisted(blocked):
# DEBUG: print(f"DEBUG: blocked='{blocked}' is blacklisted - skipping!")
origin = searchres[1]
nodeinfo_url = searchres[2]
elif not validators.domain(blocked):
- print(f"WARNING: blocked='{blocked}',software='{software}' is not a valid domain name - skipped!")
+ print(f"WARNING: blocked='{blocked}',software='gotosocial' is not a valid domain name - skipped!")
continue
# DEBUG: print("DEBUG: Looking up instance by domain:", blocked)
if not validators.domain(blocked):
- print(f"WARNING: blocked='{blocked}',software='{software}' is not a valid domain name - skipped!")
+ print(f"WARNING: blocked='{blocked}',software='gotosocial' is not a valid domain name - skipped!")
continue
elif not fba.is_instance_registered(blocked):
- # DEBUG: print(f"DEBUG: Domain blocked='{blocked}' wasn't found, adding ..., blocker='{blocker}',origin='{origin}',nodeinfo_url='{nodeinfo_url}'")
- fba.add_instance(blocked, blocker, inspect.currentframe().f_code.co_name, nodeinfo_url)
+ # DEBUG: 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(blocker, blocked, "reject"):
- # DEBUG: print(f"DEBUG: blocker='{blocker}' is blocking '{blocked}' for unknown reason at this point")
- blocks.add_instance(blocker, blocked, "unknown", "reject")
+ if not blocks.is_instance_blocked(domain, blocked, "reject"):
+ # DEBUG: 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:
- # DEBUG: print(f"DEBUG: Updating block last seen for blocker='{blocker}',blocked='{blocked}' ...")
- blocks.update_last_seen(blocker, blocked, "reject")
+ # DEBUG: print(f"DEBUG: Updating block last seen for domain='{domain}',blocked='{blocked}' ...")
+ blocks.update_last_seen(domain, blocked, "reject")
if "public_comment" in peer:
- # DEBUG: print("DEBUG: Updating block reason:", blocker, blocked, peer["public_comment"])
- blocks.update_reason(peer["public_comment"], blocker, blocked, "reject")
+ # DEBUG: 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:
# DEBUG: print("DEBUG: Committing changes ...")
fba.connection.commit()
except Exception as e:
- print(f"ERROR: blocker='{blocker}',software='{software}',exception[{type(e)}]:'{str(e)}'")
+ print(f"ERROR: domain='{domain}',software='gotosocial',exception[{type(e)}]:'{str(e)}'")
# DEBUG: print("DEBUG: EXIT!")
continue
elif not fba.is_instance_registered(blocked):
# DEBUG: print(f"DEBUG: Domain blocked='{blocked}' wasn't found, adding ..., domain='{domain}',origin='{origin}',nodeinfo_url='{nodeinfo_url}'")
- fba.add_instance(blocked, domain, inspect.currentframe().f_code.co_name, nodeinfo_url)
+ instances.add(blocked, domain, inspect.currentframe().f_code.co_name, nodeinfo_url)
elif not validators.domain(blocked):
print(f"WARNING: blocked='{blocked}',software='mastodon' is not a valid domain name - skipped!")
continue
continue
elif not fba.is_instance_registered(blocked):
# DEBUG: print("DEBUG: Hash wasn't found, adding:", blocked, domain)
- fba.add_instance(blocked, domain, inspect.currentframe().f_code.co_name, nodeinfo_url)
+ instances.add(blocked, domain, inspect.currentframe().f_code.co_name, nodeinfo_url)
blocking = blocked if blocked.count("*") <= 1 else blocked_hash
# DEBUG: print(f"DEBUG: blocking='{blocking}',blocked='{blocked}',blocked_hash='{blocked_hash}'")
continue
elif not fba.is_instance_registered(blocked):
# DEBUG: print(f"DEBUG: Domain blocked='{blocked}' wasn't found, adding ..., domain='{domain}',origin='{origin}',nodeinfo_url='{nodeinfo_url}'")
- fba.add_instance(blocked, domain, inspect.currentframe().f_code.co_name, nodeinfo_url)
+ instances.add(blocked, domain, inspect.currentframe().f_code.co_name, nodeinfo_url)
if not blocks.is_instance_blocked(domain, blocked, block_level):
# DEBUG: print("DEBUG: Blocking:", domain, blocked, block_level)
continue
elif not fba.is_instance_registered(blocked):
# DEBUG: print(f"DEBUG: Domain blocked='{blocked}' wasn't found, adding ..., domain='{domain}',origin='{origin}',nodeinfo_url='{nodeinfo_url}'")
- fba.add_instance(blocked, domain, inspect.currentframe().f_code.co_name, nodeinfo_url)
+ instances.add(blocked, domain, inspect.currentframe().f_code.co_name, nodeinfo_url)
# DEBUG: print("DEBUG: Updating block reason:", domain, blocked, reason["reason"])
blocks.update_reason(reason["reason"], domain, blocked, block_level)
update_instance_data(domain)
# DEBUG: print("DEBUG: EXIT!")
+
+def add(domain: str, origin: str, originator: str, path: str = None):
+ # DEBUG: print(f"DEBUG: domain='{domain}',origin='{origin}',originator='{originator}',path='{path}' - 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"origin[]={type(origin)} is not 'str'")
+ elif type(originator) != str:
+ raise ValueError(f"originator[]={type(originator)} is not 'str'")
+ elif originator == "":
+ raise ValueError(f"originator cannot be empty")
+ elif not validators.domain(domain.split("/")[0]):
+ raise ValueError(f"Bad domain name='{domain}'")
+ elif origin is not None and not validators.domain(origin.split("/")[0]):
+ raise ValueError(f"Bad origin name='{origin}'")
+ elif blacklist.is_blacklisted(domain):
+ raise Exception(f"domain='{domain}' is blacklisted, but method invoked")
+
+ # DEBUG: print("DEBUG: domain,origin,originator,path:", domain, origin, originator, path)
+ if domain.find("/profile") > 0:
+ # Need to cut off /profile/* part
+ domain = domain.split("/profile/")[0]
+ if instances.is_registered(domain):
+ raise Exception(f"WARNING: After removing /profile/ domain='{domain}' is already registered - EXIT!")
+
+ software = determine_software(domain, path)
+ # DEBUG: print("DEBUG: Determined software:", software)
+
+ print(f"INFO: Adding instance domain='{domain}' (origin='{origin}',software='{software}')")
+ try:
+ cursor.execute(
+ "INSERT INTO instances (domain, origin, originator, hash, software, first_seen) VALUES (?, ?, ?, ?, ?, ?)",
+ (
+ domain,
+ origin,
+ originator,
+ get_hash(domain),
+ software,
+ time.time()
+ ),
+ )
+
+ cache.set_sub_key("is_registered", domain, True)
+
+ if instances.has_pending_instance_data(domain):
+ # DEBUG: print(f"DEBUG: domain='{domain}' has pending nodeinfo being updated ...")
+ instances.set("last_status_code" , domain, None)
+ instances.set("last_error_details", domain, None)
+ instances.update_instance_data(domain)
+ remove_pending_error(domain)
+
+ if domain in pending_errors:
+ # DEBUG: print("DEBUG: domain has pending error being updated:", domain)
+ update_last_error(domain, pending_errors[domain])
+ remove_pending_error(domain)
+
+ except BaseException as e:
+ print(f"ERROR: failed SQL query: domain='{domain}',exception[{type(e)}]:'{str(e)}'")
+ sys.exit(255)
+ else:
+ # DEBUG: print("DEBUG: Updating nodeinfo for domain:", domain)
+ update_last_nodeinfo(domain)
+
+ # DEBUG: print("DEBUG: EXIT!")