continue
elif blocked.count("*") > 0:
# Some friendica servers also obscure domains without hash
- fba.cursor.execute(
- "SELECT domain, origin, nodeinfo_url FROM instances WHERE domain LIKE ? ORDER BY rowid LIMIT 1", [blocked.replace("*", "_")]
- )
+ row = instances.deobsure("*", blocked)
- searchres = fba.cursor.fetchone()
-
- # DEBUG: print(f"DEBUG: searchres[]='{type(searchres)}'")
- if searchres is None:
+ # DEBUG: print(f"DEBUG: row[]='{type(row)}'")
+ if row is None:
print(f"WARNING: Cannot deobsfucate blocked='{blocked}' - SKIPPED!")
continue
- blocked = searchres[0]
- origin = searchres[1]
- nodeinfo_url = searchres[2]
+ blocked = row[0]
+ origin = row[1]
+ nodeinfo_url = row[2]
elif blocked.count("?") > 0:
# Some obscure them with question marks, not sure if that's dependent on version or not
- fba.cursor.execute(
- "SELECT domain, origin, nodeinfo_url FROM instances WHERE domain LIKE ? ORDER BY rowid LIMIT 1", [blocked.replace("?", "_")]
- )
-
- searchres = fba.cursor.fetchone()
+ row = instances.deobsure("?", blocked)
- # DEBUG: print(f"DEBUG: searchres[]='{type(searchres)}'")
- if searchres is None:
+ # DEBUG: print(f"DEBUG: row[]='{type(row)}'")
+ if row is None:
print(f"WARNING: Cannot deobsfucate blocked='{blocked}' - SKIPPED!")
continue
- blocked = searchres[0]
- origin = searchres[1]
- nodeinfo_url = searchres[2]
- elif not validators.domain(blocked):
- print(f"WARNING: blocked='{blocked}',software='{software}' is not a valid domain name - skipped!")
- continue
+ blocked = row[0]
+ origin = row[1]
+ nodeinfo_url = row[2]
# DEBUG: print("DEBUG: Looking up instance by domain:", blocked)
if not validators.domain(blocked):
# DEBUG: print(f"DEBUG: reader[]='{type(reader)}'")
for row in reader:
- if not validators.domain(row["#domain"]):
- print(f"WARNING: domain='{row['#domain']}' is not a valid domain - skipped!")
+ domain = None
+ if "#domain" in row:
+ domain = row["#domain"]
+ elif "domain" in row:
+ domain = row["domain"]
+ else:
+ print(f"DEBUG: row='{row}' does not contain domain column")
+ continue
+
+ if domain.find("*") > 0:
+ # Try to de-obsure it
+ row = instances.deobsure("*", domain)
+
+ # DEBUG: print(f"DEBUG: row[{type(row)}]='{row}'")
+ if row is None:
+ print(f"WARNING: Cannot de-obfucate domain='{domain}' - skipped!")
+ continue
+
+ # DEBUG: print(f"DEBUG: domain='{domain}' de-obscured to '{row[0]}'")
+ domain = row[0]
+
+ if not validators.domain(domain):
+ print(f"WARNING: domain='{domain}' is not a valid domain - skipped!")
continue
- elif blacklist.is_blacklisted(row["#domain"]):
- print(f"WARNING: domain='{row['#domain']}' is blacklisted - skipped!")
+ elif blacklist.is_blacklisted(domain):
+ print(f"WARNING: domain='{domain}' is blacklisted - skipped!")
continue
- elif instances.is_recent(row["#domain"]):
- # DEBUG: print(f"DEBUG: domain='{row['#domain']}' has been recently checked - skipped!")
+ elif instances.is_recent(domain):
+ # DEBUG: print(f"DEBUG: domain='{domain}' has been recently checked - skipped!")
continue
try:
- print(f"INFO: Fetching instances for instane='{row['#domain']}' ...")
- federation.fetch_instances(row["#domain"], block["blocker"], None, inspect.currentframe().f_code.co_name)
+ print(f"INFO: Fetching instances for instane='{domain}' ...")
+ federation.fetch_instances(domain, block["blocker"], None, inspect.currentframe().f_code.co_name)
except network.exceptions as exception:
- print(f"WARNING: Exception '{type(exception)}' during fetching instances (fetch_oliphant) from domain='{row['#domain']}'")
- instances.update_last_error(row["#domain"], exception)
+ print(f"WARNING: Exception '{type(exception)}' during fetching instances (fetch_oliphant) from domain='{domain}'")
+ instances.update_last_error(domain, exception)
# DEBUG: print("DEBUG: EXIT!")
# DEBUG: print(f"DEBUG: recently='{recently}' - EXIT!")
return recently
+
+def deobsure(char: str, domain: str, hash: str = None) -> tuple:
+ #print(f"DEBUG: char='{char}',domain='{domain}',hash='{hash}' - CALLED!")
+ if not isinstance(char, str):
+ raise ValueError(f"Parameter char[]='{type(char)}' is not 'str'")
+ elif char == "":
+ raise ValueError("Parameter 'char' is empty")
+ elif not isinstance(domain, str):
+ raise ValueError(f"Parameter domain[]='{type(domain)}' is not 'str'")
+ elif domain == "":
+ raise ValueError("Parameter 'domain' is empty")
+ elif not isinstance(hash, str) and hash is not None:
+ raise ValueError(f"Parameter hash[]='{type(hash)}' is not 'str'")
+
+ if isinstance(hash, str):
+ fba.cursor.execute(
+ "SELECT domain, origin, nodeinfo_url FROM instances WHERE hash = ? LIMIT 1", [hash]
+ )
+ else:
+ fba.cursor.execute(
+ "SELECT domain, origin, nodeinfo_url FROM instances WHERE domain LIKE ? ORDER BY rowid LIMIT 1", [domain.replace(char, "_")]
+ )
+
+ row = fba.cursor.fetchone()
+
+ #print(f"DEBUG: row[]='{type(row)}' - EXIT!")
+ return row
continue
elif blocked.count("*") > 0:
# Doing the hash search for instance names as well to tidy up DB
- fba.cursor.execute(
- "SELECT domain, origin, nodeinfo_url FROM instances WHERE hash = ? LIMIT 1", [blocked_hash]
- )
- searchres = fba.cursor.fetchone()
+ row = instances.deobsure("*", blocked, blocked_hash)
- # DEBUG: print(f"DEBUG: searchres[]='{type(searchres)}'")
- if searchres is None:
+ # DEBUG: print(f"DEBUG: row[]='{type(row)}'")
+ if row is None:
print(f"WARNING: Cannot deobsfucate blocked='{blocked}',blocked_hash='{blocked_hash}' - SKIPPED!")
continue
- # DEBUG: print("DEBUG: Updating domain: ", searchres[0])
- blocked = searchres[0]
- origin = searchres[1]
- nodeinfo_url = searchres[2]
+ # DEBUG: print("DEBUG: Updating domain: ", row[0])
+ blocked = row[0]
+ origin = row[1]
+ nodeinfo_url = row[2]
# DEBUG: print("DEBUG: Looking up instance by domain:", blocked)
if not validators.domain(blocked):
continue
elif blocked.count("*") > 0:
# Obsured domain name with no hash
- # DEBUG: print(f"DEBUG: Trying to de-obscure blocked='{blocked}' ...")
- fba.cursor.execute(
- "SELECT domain, nodeinfo_url FROM instances WHERE domain LIKE ? ORDER BY rowid LIMIT 1", [blocked.replace("*", "_")]
- )
- searchres = fba.cursor.fetchone()
-
- # DEBUG: print(f"DEBUG: searchres[]='{type(searchres)}'")
- if searchres is None:
+ row = instances.deobsure("*", blocked)
+
+ # DEBUG: print(f"DEBUG: row[]='{type(row)}'")
+ if row is None:
print(f"WARNING: Cannot deobsfucate blocked='{blocked}' - SKIPPED!")
continue
- # DEBUG: print(f"DEBUG: blocked='{blocked}' de-obscured to '{searchres[0]}'")
- blocked = searchres[0]
- nodeinfo_url = searchres[1]
+ # DEBUG: print(f"DEBUG: blocked='{blocked}' de-obscured to '{row[0]}'")
+ blocked = row[0]
+ origin = row[1]
+ nodeinfo_url = row[2]
# DEBUG: print(f"DEBUG: blocked='{blocked}'")
if not validators.domain(blocked):
# DEBUG: print(f"DEBUG: blocked='{blocked}' is blacklisted - skipping!")
continue
elif blocked.count("*") > 0:
- # Obsured domain with no hash
- # DEBUG: print(f"DEBUG: Trying to de-obscure blocked='{blocked}' ...")
- fba.cursor.execute(
- "SELECT domain, origin, nodeinfo_url FROM instances WHERE domain LIKE ? ORDER BY rowid LIMIT 1", [blocked.replace("*", "_")]
- )
- searchres = fba.cursor.fetchone()
-
- # DEBUG: print(f"DEBUG: searchres[]='{type(searchres)}'")
- if searchres is None:
+ # Obsured domain name with no hash
+ row = instances.deobsure("*", blocked)
+
+ # DEBUG: print(f"DEBUG: row[]='{type(row)}'")
+ if row is None:
print(f"WARNING: Cannot deobsfucate blocked='{blocked}' - SKIPPED!")
continue
- # DEBUG: print(f"DEBUG: blocked='{blocked}' de-obscured to '{searchres[0]}'")
- blocked = searchres[0]
- origin = searchres[1]
- nodeinfo_url = searchres[2]
- elif not validators.domain(blocked):
- print(f"WARNING: blocked='{blocked}',software='pleroma' is not a valid domain name - skipped!")
- continue
+ # DEBUG: print(f"DEBUG: blocked='{blocked}' de-obscured to '{row[0]}'")
+ blocked = row[0]
+ origin = row[1]
+ nodeinfo_url = row[2]
# DEBUG: print(f"DEBUG: blocked='{blocked}'")
- if blocked.split(".")[-1] == "arpa":
+ if not validators.domain(blocked):
+ print(f"WARNING: blocked='{blocked}',software='pleroma' is not a valid domain name - skipped!")
+ continue
+ elif blocked.split(".")[-1] == "arpa":
print(f"WARNING: blocked='{blocked}' is a reversed .arpa domain and should not be used generally.")
continue
elif not instances.is_registered(blocked):
{% extends "base.html" %}
-{% block title %}Scoreboard - {% if mode == 'software' %}TOP {{amount}} used software{% elif mode == 'command' %}TOP {{amount}} scripts{% elif mode == 'error_code' %}TOP {{amount}} error codes{% elif mode == 'reference' %}TOP {{amount}} referencing instances{% elif mode == 'blocked' %}TOP {{amount}} deferated instances{% elif mode == 'blocker' %}TOP {{amount}} deferating instances{% endif %}{% endblock %}
+{% block title %}Scoreboard - {% if mode == 'software' %}TOP {{amount}} used software{% elif mode == 'command' %}TOP {{amount}} commands{% elif mode == 'error_code' %}TOP {{amount}} error codes{% elif mode == 'reference' %}TOP {{amount}} referencing instances{% elif mode == 'blocked' %}TOP {{amount}} deferated instances{% elif mode == 'blocker' %}TOP {{amount}} deferating instances{% endif %}{% endblock %}
{% block header %}
{% if mode == 'blocker' %}
{% elif mode == 'software' %}
<h1>Top {{amount}} used software</h1>
{% elif mode == 'command' %}
- <h1>TOP {{amount}} scripts</h1>
+ <h1>TOP {{amount}} commands</h1>
{% elif mode == 'error_code' %}
<h1>TOP {{amount}} error codes</h1>
{% endif %}