parser.add_argument("--domain", help="Instance name (aka. 'relay')")
parser.add_argument("--force", action="store_true", help="Forces update of data, no matter what.")
+ ### Remove invalid domains ###
+ parser = subparser_command.add_parser(
+ "remove_invalid",
+ help="Removes invalid domains.",
+ )
+ parser.set_defaults(command=commands.remove_invalid)
+
logger.debug("EXIT!")
def run_command():
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):
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):
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.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
raise ValueError("Parameter 'domain' is empty")
elif domain.lower() != domain:
raise ValueError(f"Parameter domain='{domain}' must be all lower-case")
- elif not validators.hostname(domain.split("/")[0]):
+ elif not validators.domain(domain.split("/")[0]):
raise ValueError(f"domain='{domain}' is not a valid domain")
elif domain.endswith(".arpa"):
raise ValueError(f"domain='{domain}' is a domain for reversed IP addresses, please don't crawl them!")
raise ValueError("Parameter 'domain' is empty")
elif domain.lower() != domain:
wanted = False
- elif not validators.hostname(domain.split("/")[0]):
+ elif not validators.domain(domain.split("/")[0]):
logger.debug("domain='%s' is not a valid domain name - setting False ...", domain)
wanted = False
elif domain.endswith(".arpa"):
"reason": reason,
})
continue
- elif not validators.hostname(domain.split("/")[0]):
+ elif not validators.domain(domain.split("/")[0]):
logger.warning("domain='%s' is not a valid domain - SKIPPED!", domain)
continue
raise ValueError(f"software[]='{type(software)}' is not of type 'str'")
elif software == "":
raise ValueError("Parameter 'software' is empty")
- elif origin is not None and not validators.hostname(origin.split("/")[0]):
+ elif origin is not None and not validators.domain(origin.split("/")[0]):
raise ValueError(f"Bad origin name='{origin}'")
elif blacklist.is_blacklisted(domain):
raise Exception(f"domain='{domain}' is blacklisted, but function invoked")
--- /dev/null
+#!/bin/sh
+
+MODE=""
+if [ "$1" = "--help" ]
+then
+ echo "Usage: $0 [file|--software|--software2|--nodeinfo|--generator|--detection|--no-auto|--no-auto2|--timeout]"
+ exit 255
+elif [ -n "$1" -a -f "$1" ]
+then
+ DOMAINS=$(cat "$1")
+ MODE="file"
+elif [ "$1" = "--software" ]
+then
+ DOMAINS=$(sqlite3 blocks.db "SELECT domain FROM instances WHERE software IS NULL ORDER BY last_updated ASC;")
+ MODE="software"
+elif [ "$1" = "--nodeinfo" ]
+then
+ DOMAINS=$(sqlite3 blocks.db "SELECT domain FROM instances WHERE software IS NULL AND nodeinfo_url IS NOT NULL ORDER BY last_updated ASC;")
+ MODE="nodeinfo"
+elif [ "$1" = "--detection" ]
+then
+ DOMAINS=$(sqlite3 blocks.db "SELECT domain FROM instances WHERE detection_mode IS NULL ORDER BY last_updated ASC;")
+ MODE="detection"
+elif [ "$1" = "--no-auto" ]
+then
+ DOMAINS=$(sqlite3 blocks.db "SELECT domain FROM instances WHERE detection_mode != 'AUTO_DISCOVERY' ORDER BY last_updated ASC;")
+ MODE="noauto"
+elif [ "$1" = "--no-auto2" ]
+then
+ DOMAINS=`sqlite3 blocks.db "SELECT domain FROM instances WHERE software IN ('pleroma', 'mastodon', 'lemmy', 'friendica', 'misskey', 'peertube', 'takahe', 'gotosocial', 'brighteon', 'wildebeest', 'bookwyrm', 'mitra', 'areionskey', 'mammuthus') AND detection_mode != 'AUTO_DISCOVERY' ORDER BY last_updated ASC;"`
+ MODE="noauto2"
+elif [ "$1" = "--timeout" ]
+then
+ DOMAINS=$(sqlite3 blocks.db "SELECT domain FROM instances WHERE last_error_details LIKE '%Timeout%' ORDER BY last_updated ASC;")
+ MODE="software"
+elif [ "$1" = "--software2" ]
+then
+ DOMAINS=$(sqlite3 blocks.db "SELECT domain FROM instances WHERE software IS NOT NULL AND detection_mode IS NULL ORDER BY last_updated ASC;")
+ MODE="software2"
+elif [ "$1" = "--generator" ]
+then
+ DOMAINS=$(sqlite3 blocks.db "SELECT domain FROM instances WHERE detection_mode='GENERATOR' ORDER BY last_updated ASC;")
+ MODE="generator"
+else
+ DOMAINS=$(sqlite3 blocks.db "SELECT domain FROM instances WHERE software IS NULL AND nodeinfo_url IS NOT NULL ORDER BY last_updated ASC;")
+fi
+
+if [ -z "${DOMAINS}" ]
+then
+ echo "$0: No domains found! MODE='${MODE}'"
+ exit 255
+fi
+
+for DOMAIN in ${DOMAINS};
+do
+ echo "$0: DOMAIN='${DOMAIN}'"
+ if [ -n "$1" -a -z "${MODE}" ]
+ then
+ ./fba.py update_nodeinfo --domain=${DOMAIN} "$1"
+ elif [ -n "$2" ]
+ then
+ ./fba.py update_nodeinfo --domain=${DOMAIN} "$2"
+ else
+ ./fba.py update_nodeinfo --domain=${DOMAIN}
+ fi
+done
+echo "$0: All done."
+++ /dev/null
-#!/bin/sh
-
-MODE=""
-if [ "$1" = "--help" ]
-then
- echo "Usage: $ [file|--software|--software2|--nodeinfo|--generator|--detection|--no-auto|--no-auto2|--timeout]"
- exit 255
-elif [ -n "$1" -a -f "$1" ]
-then
- DOMAINS=$(cat "$1")
- MODE="file"
-elif [ "$1" = "--software" ]
-then
- DOMAINS=$(sqlite3 blocks.db "SELECT domain FROM instances WHERE software IS NULL ORDER BY last_updated ASC;")
- MODE="software"
-elif [ "$1" = "--nodeinfo" ]
-then
- DOMAINS=$(sqlite3 blocks.db "SELECT domain FROM instances WHERE software IS NULL AND nodeinfo_url IS NOT NULL ORDER BY last_updated ASC;")
- MODE="nodeinfo"
-elif [ "$1" = "--detection" ]
-then
- DOMAINS=$(sqlite3 blocks.db "SELECT domain FROM instances WHERE detection_mode IS NULL ORDER BY last_updated ASC;")
- MODE="detection"
-elif [ "$1" = "--no-auto" ]
-then
- DOMAINS=$(sqlite3 blocks.db "SELECT domain FROM instances WHERE detection_mode != 'AUTO_DISCOVERY' ORDER BY last_updated ASC;")
- MODE="noauto"
-elif [ "$1" = "--no-auto2" ]
-then
- DOMAINS=`sqlite3 blocks.db "SELECT domain FROM instances WHERE software IN ('pleroma', 'mastodon', 'lemmy', 'friendica', 'misskey', 'peertube', 'takahe', 'gotosocial', 'brighteon', 'wildebeest', 'bookwyrm', 'mitra', 'areionskey', 'mammuthus') AND detection_mode != 'AUTO_DISCOVERY' ORDER BY last_updated ASC;"`
- MODE="noauto2"
-elif [ "$1" = "--timeout" ]
-then
- DOMAINS=$(sqlite3 blocks.db "SELECT domain FROM instances WHERE last_error_details LIKE '%Timeout%' ORDER BY last_updated ASC;")
- MODE="software"
-elif [ "$1" = "--software2" ]
-then
- DOMAINS=$(sqlite3 blocks.db "SELECT domain FROM instances WHERE software IS NOT NULL AND detection_mode IS NULL ORDER BY last_updated ASC;")
- MODE="software2"
-elif [ "$1" = "--generator" ]
-then
- DOMAINS=$(sqlite3 blocks.db "SELECT domain FROM instances WHERE detection_mode='GENERATOR' ORDER BY last_updated ASC;")
- MODE="generator"
-else
- DOMAINS=$(sqlite3 blocks.db "SELECT domain FROM instances WHERE software IS NULL AND nodeinfo_url IS NOT NULL ORDER BY last_updated ASC;")
-fi
-
-if [ -z "${DOMAINS}" ]
-then
- echo "$0: No domains found! MODE='${MODE}'"
- exit 255
-fi
-
-for DOMAIN in ${DOMAINS};
-do
- echo "$0: DOMAIN='${DOMAIN}'"
- if [ -n "$1" -a -z "${MODE}" ]
- then
- ./fba.py update_nodeinfo --domain=${DOMAIN} "$1"
- elif [ -n "$2" ]
- then
- ./fba.py update_nodeinfo --domain=${DOMAIN} "$2"
- else
- ./fba.py update_nodeinfo --domain=${DOMAIN}
- fi
-done
-echo "$0: All done."