feat: Can now censure unreachable domains and wildcards

pull/20/head
db0 2023-09-06 11:21:32 +02:00
parent 5f9cf5da01
commit 6c2f7ba838
3 changed files with 21 additions and 5 deletions

View File

@ -60,7 +60,7 @@ class Suspicions(Resource):
def ensure_instance_registered(domain): def ensure_instance_registered(domain, allow_unreachable=False):
if domain.endswith("test.dbzer0.com"): if domain.endswith("test.dbzer0.com"):
# Fake instances for testing chain of trust # Fake instances for testing chain of trust
requested_lemmy = Lemmy(f"https://{domain}") requested_lemmy = Lemmy(f"https://{domain}")
@ -75,7 +75,18 @@ def ensure_instance_registered(domain):
else: else:
nodeinfo = get_nodeinfo(domain) nodeinfo = get_nodeinfo(domain)
if not nodeinfo: if not nodeinfo:
raise e.BadRequest(f"Error encountered while polling domain {domain}. Please check it's running correctly") if not allow_unreachable:
raise e.BadRequest(f"Error encountered while polling domain {domain}. Please check it's running correctly")
else:
software = "unknown"
if "*" in domain:
software = "wildcard"
nodeinfo = {
"openRegistrations": False,
"software": {
"name": software
}
}
software = nodeinfo["software"]["name"] software = nodeinfo["software"]["name"]
if software == "lemmy": if software == "lemmy":
requested_lemmy = Lemmy(f"https://{domain}") requested_lemmy = Lemmy(f"https://{domain}")

View File

@ -95,7 +95,7 @@ class Censures(Resource):
unbroken_chain, chainbreaker = database.has_unbroken_chain(instance.id) unbroken_chain, chainbreaker = database.has_unbroken_chain(instance.id)
if not unbroken_chain: if not unbroken_chain:
raise e.Forbidden(f"Guarantee chain for this instance has been broken. Chain ends at {chainbreaker.domain}!") raise e.Forbidden(f"Guarantee chain for this instance has been broken. Chain ends at {chainbreaker.domain}!")
target_instance, nodeinfo, admin_usernames = ensure_instance_registered(domain) target_instance, nodeinfo, admin_usernames = ensure_instance_registered(domain, allow_unreachable=True)
if not target_instance: if not target_instance:
raise e.NotFound(f"Something went wrong trying to register this instance.") raise e.NotFound(f"Something went wrong trying to register this instance.")
if not target_instance: if not target_instance:

View File

@ -8,7 +8,7 @@ def get_lemmy_admins(domain):
site = requested_lemmy.site.get() site = requested_lemmy.site.get()
if not site: if not site:
logger.warning(f"Error retrieving mastodon site info for {domain}") logger.warning(f"Error retrieving mastodon site info for {domain}")
return None raise Exception(f"Error retrieving mastodon site info for {domain}")
return [a["person"]["name"] for a in site["admins"]] return [a["person"]["name"] for a in site["admins"]]
def get_mastodon_admins(domain): def get_mastodon_admins(domain):
@ -17,13 +17,18 @@ def get_mastodon_admins(domain):
return [site["contact"]["account"]["username"]] return [site["contact"]["account"]["username"]]
except Exception as err: except Exception as err:
logger.warning(f"Error retrieving mastodon site info for {domain}: {err}") logger.warning(f"Error retrieving mastodon site info for {domain}: {err}")
return None raise Exception(f"Error retrieving mastodon site info for {domain}: {err}")
def get_unknown_admins(domain):
return []
def get_admin_for_software(software: str, domain: str): def get_admin_for_software(software: str, domain: str):
software_map = { software_map = {
"lemmy": get_lemmy_admins, "lemmy": get_lemmy_admins,
"mastodon": get_mastodon_admins, "mastodon": get_mastodon_admins,
"friendica": get_mastodon_admins, "friendica": get_mastodon_admins,
"unknown": get_unknown_admins,
"wildcard": get_unknown_admins,
} }
if software not in software_map: if software not in software_map:
return [] return []