diff --git a/README.md b/README.md index 53dac10..b341484 100644 --- a/README.md +++ b/README.md @@ -4,4 +4,6 @@ This service provides an REST API which can be used to retrieve various informat It's reliant on the [Lemmy Fediverse Observer](https://lemmy.fediverse.observer/) -The currently running instance is on https://overseer.dbzer0.com \ No newline at end of file +The currently running instance is on https://overseer.dbzer0.com + +See devlog: https://dbzer0.com/blog/overseer-a-fediverse-chain-of-trust/ \ No newline at end of file diff --git a/overseer/apis/v1/whitelist.py b/overseer/apis/v1/whitelist.py index 4339585..8eb9741 100644 --- a/overseer/apis/v1/whitelist.py +++ b/overseer/apis/v1/whitelist.py @@ -1,4 +1,5 @@ from overseer.apis.v1.base import * +from overseer.utils import get_nodeinfo class Whitelist(Resource): get_parser = reqparse.RequestParser() @@ -68,21 +69,34 @@ class WhitelistDomain(Resource): if domain.endswith("test.dbzer0.com"): requested_lemmy = Lemmy(f"https://{domain}") requested_lemmy._requestor.nodeinfo = {"software":{"name":"lemmy"}} - site = {"site_view":{"local_site":{"require_email_verification": True,"registration_mode":"open"}}} + open_registrations = False + email_verify = True + software = "lemmy" else: - requested_lemmy = Lemmy(f"https://{domain}") - site = requested_lemmy.site.get() - if not site: - raise e.BadRequest(f"Error encountered while polling domain {domain}. Please check it's running correctly") + nodeinfo = get_nodeinfo(domain) + if not nodeinfo: + raise e.BadRequest(f"Error encountered while polling domain {domain}. Please check it's running correctly") + software = nodeinfo["software"]["name"] + if software == "lemmy": + requested_lemmy = Lemmy(f"https://{domain}") + site = requested_lemmy.site.get() + if not site: + raise e.BadRequest(f"Error encountered while polling lemmy domain {domain}. Please check it's running correctly") + open_registrations = site["site_view"]["local_site"]["registration_mode"] == "open" + email_verify = site["site_view"]["local_site"]["require_email_verification"] + software = software + else: + open_registrations = nodeinfo["openRegistrations"] + email_verify = False api_key = pm_new_api_key(domain) if not api_key: raise e.BadRequest("Failed to generate API Key") new_instance = Instance( domain=domain, api_key=hash_api_key(api_key), - open_registrations=site["site_view"]["local_site"]["registration_mode"] == "open", - email_verify=site["site_view"]["local_site"]["require_email_verification"], - software=requested_lemmy.nodeinfo['software']['name'], + open_registrations=open_registrations, + email_verify=email_verify, + software=software, ) new_instance.create() if guarantor_instance: diff --git a/overseer/templates/index.md b/overseer/templates/index.md index c6927e9..722b209 100644 --- a/overseer/templates/index.md +++ b/overseer/templates/index.md @@ -2,6 +2,14 @@ This is a [FOSS service](https://github.com/db0/lemmy-overseer) to help Lemmy instances detect and avoid suspcicious instances +[Release Devlog](https://dbzer0.com/blog/overseer-a-fediverse-chain-of-trust/) + +## Scope + +This Overseer is focused around anti-spam verification. We make no judgement on the content of the guaranteed communities other than they have been verified to not be fake spam instances and are making a good effort to block spam accounts. + +However using the endorsement system, you can create a further customized whitelist around the endorsement of instances you trust. + ## REST API [Full Documentation](/api) diff --git a/overseer/utils.py b/overseer/utils.py index 6fca757..06c879e 100644 --- a/overseer/utils.py +++ b/overseer/utils.py @@ -10,6 +10,7 @@ from datetime import datetime import dateutil.relativedelta from loguru import logger from overseer.flask import SQLITE_MODE +import requests random.seed(random.SystemRandom().randint(0, 2**32 - 1)) @@ -100,4 +101,12 @@ def validate_regex(regex_string): re.compile(regex_string, re.IGNORECASE) except: return False - return True \ No newline at end of file + return True + +def get_nodeinfo(domain): + try: + wellknown = requests.get(f"https://{domain}/.well-known/nodeinfo", timeout=2).json() + nodeinfo = requests.get(wellknown['links'][0]['href'], timeout=2).json() + return nodeinfo + except Exception as err: + return None \ No newline at end of file