from fba import database
from fba import utils
+from fba.helpers import blacklist
from fba.helpers import config
from fba.helpers import json as json_helper
from fba.helpers import tidyup
},
})
+@router.get(config.get("base_url") + "/api/v1/instance/domain_blocks", response_class=JSONResponse)
+def api_domain_blocks(request: Request):
+ blocked = blacklist.get_all()
+ blocking = list()
+
+ for block in blocked:
+ blocking.append({
+ "domain" : block,
+ "digest" : utils.get_hash(block),
+ "severity": "suspend",
+ "comment" : blocked[block],
+ })
+
+ return JSONResponse(status_code=200, content=blocking)
+
@router.get(config.get("base_url") + "/api/v1/instance/peers", response_class=JSONResponse)
def api_peers(request: Request):
database.cursor.execute("SELECT domain FROM instances WHERE nodeinfo_url IS NOT NULL")
logger = logging.getLogger(__name__)
# Don't check these, known trolls/flooders/testing/developing
-blacklist = [
- # Floods federation with fake nodes as "research" project
- "activitypub-troll.cf",
- "activitypub-proxy.cf",
- # Similar troll
- "gab.best",
- # Similar troll
- "4chan.icu",
- # Flooder (?)
- "social.shrimpcam.pw",
- "mastotroll.netz.org",
- "lhr.life",
- "localhost.run",
- "loca.lt",
- # Testing/developing installations
- "ngrok.io",
- "ngrok.app",
- "ngrok-free.app",
- "misskeytest.chn.moe",
- "netlify.app",
- # block flooder
- "everyoneattack.com",
- # CSRF
- "hexbear.net", # See script in /instances
-]
+_blacklist = {
+ "activitypub-troll.cf": "Floods federation with fake nodes as \"research\" project",
+ "activitypub-proxy.cf": "Floods federation with fake nodes as \"research\" project",
+ "gab.best" : "Floods federation tables with fake nodes",
+ "4chan.icu" : "Floods federation tables with fake nodes",
+ "social.shrimpcam.pw" : "Floods federation tables with fake nodes",
+ "mastotroll.netz.org" : "Floods federation tables with fake nodes",
+ "lhr.life" : "Floods federation tables with fake nodes",
+ "localhost.run" : "Floods federation tables with fake nodes",
+ "loca.lt" : "Floods federation tables with fake nodes",
+ "ngrok.io" : "Testing/developing instances shouldn't be part of public instances",
+ "ngrok.app" : "Testing/developing instances shouldn't be part of public instances",
+ "ngrok-free.app" : "Testing/developing instances shouldn't be part of public instances",
+ "misskeytest.chn.moe" : "Testing/developing instances shouldn't be part of public instances",
+ "netlify.app" : "Testing/developing instances shouldn't be part of public instances",
+ "everyoneattack.com" : "Floods federation tables with fake nodes",
+ "hexbear.net" : "Is a Lemmy instance with malicious JavaScript code (shell commands)",
+}
def is_blacklisted(domain: str) -> bool:
logger.debug("domain='%s' - CALLED!", domain)
domain_helper.raise_on(domain)
blacklisted = False
- logger.debug("Checking %d blacklist entries ...", len(blacklist))
- for peer in blacklist:
- logger.debug("Checking peer='%s' ...", peer)
- if peer in domain:
+ logger.debug("Checking %d blacklist entries ...", len(_blacklist))
+ for blocked in _blacklist:
+ logger.debug("Checking blocked='%s' ...", blocked)
+ if blocked in domain:
logger.debug("domain='%s' is blacklisted.", domain)
blacklisted = True
logger.debug("blacklisted='%s' - EXIT!", blacklisted)
return blacklisted
+
+def get_all() -> dict:
+ logger.debug("_blacklist()=%d - CALLED!", len(_blacklist))
+ return _blacklist
instances.set_last_instance_fetch(domain)
peerlist = list()
- try:
- logger.debug("Fetching instances for domain='%s',software='%s',origin='%s'", domain, software, origin)
- peerlist = fetch_peers(domain, software, origin)
- except network.exceptions as exception:
- logger.warning("Cannot fetch peers from domain='%s',software='%s': '%s'", domain, software, type(exception))
+ logger.debug("software='%s'", software)
+ if software is not None:
+ try:
+ logger.debug("Fetching instances for domain='%s',software='%s',origin='%s'", domain, software, origin)
+ peerlist = fetch_peers(domain, software, origin)
+ except network.exceptions as exception:
+ logger.warning("Cannot fetch peers from domain='%s',software='%s': '%s'", domain, software, type(exception))
logger.debug("peerlist[]='%s'", type(peerlist))
if isinstance(peerlist, list):