def check_instance(args: argparse.Namespace) -> int:
logger.debug("args.domain='%s' - CALLED!", args.domain)
status = 0
- if not validators.hostname(args.domain):
+ if not validators.domain(args.domain):
logger.warning("args.domain='%s' is not valid", args.domain)
status = 100
elif blacklist.is_blacklisted(args.domain):
logger.debug("args[]='%s' - CALLED!", type(args))
if args.domain is not None and args.domain != "":
logger.debug("args.domain='%s' - checking ...", args.domain)
- if not validators.hostname(args.domain):
+ if not validators.domain(args.domain):
logger.warning("args.domain='%s' is not valid.", args.domain)
return 100
elif blacklist.is_blacklisted(args.domain):
blocking = list()
- if not federation.is_excluded_blocklist(blocker):
+ if blocker != "chaos.social" and not blocklists.is_excluded(blocker):
logger.debug("blocker='%s',software='%s'", blocker, software)
if software == "pleroma":
logger.info("blocker='%s',software='%s'", blocker, software)
logger.debug("Invoking instances.set_total_blocks(%s, %d) ...", blocker, len(blocking))
instances.set_total_blocks(blocker, blocking)
else:
- logger.debug("Skipping chaos.social, run ./fba.py fetch_cs instead!")
+ logger.debug("Skipping blocker='%s', run ./fba.py fetch_cs or fetch_oliphant instead!", blocker)
logger.info("Checking %d entries from blocker='%s',software='%s' ...", len(blocking), blocker, software)
blockdict = list()
logger.debug("args[]='%s' - CALLED!", type(args))
logger.debug("args.domain='%s' - checking ...", args.domain)
- if not validators.hostname(args.domain):
+ if not validators.domain(args.domain):
logger.warning("args.domain='%s' is not valid.", args.domain)
return 100
elif blacklist.is_blacklisted(args.domain):
logger.debug("Invoking locking.acquire() ...")
locking.acquire()
+ # Initialize values
+ domain = tidyup.domain(args.domain)
+ origin = software = None
+
+ # Fetch record
+ database.cursor.execute("SELECT origin, software FROM instances WHERE domain = ? LIMIT 1", [args.domain])
+ row = database.cursor.fetchone()
+ if row is not None:
+ origin = row["origin"]
+ software = row["software"]
+
# Initial fetch
try:
- logger.info("Fetching instances from args.domain='%s' ...", args.domain)
- federation.fetch_instances(args.domain, None, None, inspect.currentframe().f_code.co_name)
+ logger.info("Fetching instances from args.domain='%s',origin='%s',software='%s' ...", domain, origin, software)
+ federation.fetch_instances(domain, origin, software, inspect.currentframe().f_code.co_name)
except network.exceptions as exception:
logger.warning("Exception '%s' during fetching instances (fetch_instances) from args.domain='%s'", type(exception), args.domain)
instances.set_last_error(args.domain, exception)
domain = utils.deobfuscate(domain, block["blocker"])
logger.debug("domain='%s' - AFTER!", domain)
- if not validators.hostname(domain):
+ if not validators.domain(domain):
logger.debug("domain='%s' is not a valid domain - SKIPPED!")
continue
elif blacklist.is_blacklisted(domain):
if not isinstance(text, str):
logger.debug("text[]='%s' is not of type 'str' - SKIPPED!", type(text))
continue
- elif validators.hostname(text.strip()):
+ elif validators.domain(text.strip()):
logger.debug("text='%s' is a domain - SKIPPED!", text.strip())
continue
if isinstance(args.domain, str) and args.domain != "" and domain_helper.is_wanted(args.domain):
database.cursor.execute("SELECT domain, software, nodeinfo_url FROM instances WHERE has_obfuscation = 1 AND domain = ?", [args.domain])
- elif isinstance(args.software, str) and args.software != "" and validators.hostname(args.software) == args.software:
+ elif isinstance(args.software, str) and args.software != "" and validators.domain(args.software) == args.software:
database.cursor.execute("SELECT domain, software, nodeinfo_url FROM instances WHERE has_obfuscation = 1 AND software = ?", [args.software])
else:
database.cursor.execute("SELECT domain, software, nodeinfo_url FROM instances WHERE has_obfuscation = 1")
logger.warning("Unknown software: domain='%s',software='%s'", row["domain"], row["software"])
logger.debug("row[domain]='%s'", row["domain"])
+
# chaos.social requires special care ...
- if not blocklists.is_excluded(row["domain"]):
+ if row["domain"] != "chaos.social" and not blocklists.is_excluded(row["domain"]):
logger.debug("Invoking instances.set_total_blocks(%s, %d) ...", row["domain"], len(blocking))
instances.set_last_blocked(row["domain"])
instances.set_total_blocks(row["domain"], blocking)
logger.debug("Success! - EXIT!")
return 0
+
+def remove_invalid(args: argparse.Namespace) -> int:
+ logger.debug("args[]='%s' - CALLED!", type(args))
+
+ logger.debug("Invoking locking.acquire() ...")
+ locking.acquire()
+
+ database.cursor.execute("SELECT domain FROM instances ORDER BY domain ASC")
+ rows = database.cursor.fetchall()
+
+ logger.info("Checking %d domains ...", len(rows))
+ for row in rows:
+ logger.debug("row[domain]='%s'", row["domain"])
+ if not validators.domain(row["domain"].split("/")[0]):
+ logger.info("Invalid row[domain]='%s' found, removing ...", row["domain"])
+ database.cursor.execute("DELETE FROM blocks WHERE blocker = ? OR blocked = ?", [row["domain"], row["domain"]])
+ database.cursor.execute("DELETE FROM instances WHERE domain = ? LIMIT 1", [row["domain"]])
+
+ logger.debug("Invoking commit() ...")
+ database.connection.commit()
+
+ logger.info("Vaccum cleaning database ...")
+ database.cursor.execute("VACUUM")
+
+ logger.debug("Success! - EXIT!")
+ return 0