import bs4
+from fba.helpers import blacklist
from fba.helpers import config
from fba.helpers import domain as domain_helper
from fba.helpers import tidyup
-from fba.http import federation
from fba.http import network
from fba.models import blocks
logger.debug("domain='%s' - CALLED!", domain)
domain_helper.raise_on(domain)
- if not instances.is_registered(domain):
+ if blacklist.is_blacklisted(domain):
+ raise Exception(f"domain='{domain}' is blacklisted but function is invoked.")
+ elif not instances.is_registered(domain):
raise Exception(f"domain='{domain}' is not registered but function is invoked.")
- logger.debug("Fetching mastodon blocks from domain='%s'", domain)
+ logger.info("Fetching mastodon blocks from domain='%s'", domain)
doc = None
for path in ["/about/more", "/about"]:
try:
# replaced find_next_siblings with find_all_next to account for instances that e.g. hide lists in dropdown menu
for line in header.find_all_next("table")[0].find_all("tr")[1:]:
domain = line.find("span").text
- hash = line.find("span")["title"][9:]
+ digest = line.find("span")["title"][9:]
reason = line.find_all("td")[1].text
logger.debug("domain='%s',reason='%s' - BEFORE!", domain, reason)
logger.warning("domain='%s' is empty,line='%s' - SKIPPED!", domain, line)
continue
- logger.debug("Appending domain='%s',hash='%s',reason='%s' to blocklist header_text='%s' ...", domain, hash, reason, blocklist)
+ logger.debug("Appending domain='%s',digest='%s',reason='%s' to blocklist header_text='%s' ...", domain, digest, reason, blocklist)
blocklist[header_text].append({
"domain": domain,
- "hash" : hash,
+ "digest": digest,
"reason": reason,
})
else:
logger.debug("domain='%s' - CALLED!", domain)
domain_helper.raise_on(domain)
- if not instances.is_registered(domain):
+ if blacklist.is_blacklisted(domain):
+ raise Exception(f"domain='{domain}' is blacklisted but function is invoked.")
+ elif not instances.is_registered(domain):
raise Exception(f"domain='{domain}' is not registered but function is invoked.")
blocklist = list()
- logger.debug("Invoking federation.fetch_blocks(%s) ...", domain)
- rows = federation.fetch_blocks(domain)
-
- logger.debug("rows[%s]()=%d", type(rows), len(rows))
- if len(rows) == 0:
- logger.debug("domain='%s' has returned zero rows, trying /about/more page ...", domain)
- rows = fetch_blocks_from_about(domain)
+ logger.debug("Invoking fetch_blocks_from_about(%s) ...", domain)
+ rows = fetch_blocks_from_about(domain)
logger.debug("rows[%s]()=%d", type(rows), len(rows))
if len(rows) > 0:
blocklist.append({
"blocker" : domain,
"blocked" : block["domain"],
- "hash" : block["digest"] if "digest" in block else None,
+ "digest" : block["digest"] if "digest" in block else None,
"reason" : reason,
"block_level": blocks.alias_block_level(block["severity"]),
})