import json
import sys
import time
+import validators
with open("config.json") as f:
config = json.loads(f.read())
try:
res = reqto.get(f"https://{domain}/api/v3/site", headers=headers, timeout=(config["connection_timeout"], config["read_timeout"]))
- if res.ok and res.json() is not None:
+ if res.ok and isinstance(res.json(), dict):
# NOISY-DEBUG: print("DEBUG: Success, res.json():", len(res.json()))
json = res.json()
except BaseException as e:
print("WARNING: Exception during fetching JSON:", domain, e)
+ update_last_nodeinfo(domain)
+
# NOISY-DEBUG: print("DEBUG: Returning peers[]:", type(peers))
return peers
res = reqto.get(request, headers=headers, timeout=(config["connection_timeout"], config["read_timeout"]))
# NOISY-DEBUG: print("DEBUG: res.ok,res.json[]:", res.ok, type(res.json()))
- if res.ok and res.json() is dict:
+ if res.ok and isinstance(res.json(), dict):
# NOISY-DEBUG: print("DEBUG: Success:", request)
json = res.json()
nodeinfos["detection_mode"][domain] = "STATIC_CHECK"
pass
# NOISY-DEBUG: print("DEBUG: json[]:", type(json))
- if json is None or len(json) == 0:
+ if not isinstance(json, dict) or len(json) == 0:
print("WARNING: Failed fetching nodeinfo from domain:", domain)
# NOISY-DEBUG: print("DEBUG: Returning json[]:", type(json))
try:
res = reqto.get(f"https://{domain}/.well-known/nodeinfo", headers=headers, timeout=(config["connection_timeout"], config["read_timeout"]))
# NOISY-DEBUG: print("DEBUG: domain,res.ok,res.json[]:", domain, res.ok, type(res.json()))
- if res.ok and res.json() is dict:
+ if res.ok and isinstance(res.json(), dict):
nodeinfo = res.json()
# NOISY-DEBUG: print("DEBUG: Found entries:", len(nodeinfo), domain)
if "links" in nodeinfo:
# NOISY-DEBUG: print("DEBUG: Fetching nodeinfo from:", link["href"])
res = reqto.get(link["href"])
# NOISY-DEBUG: print("DEBUG: href,res.ok,res.status_code:", link["href"], res.ok, res.status_code)
- if res.ok and res.json() is dict:
+ if res.ok and isinstance(res.json(), dict):
# NOISY-DEBUG: print("DEBUG: Found JSON nodeinfo():", len(res.json()))
json = res.json()
nodeinfos["detection_mode"][domain] = "AUTO_DISCOVERY"
json = fetch_nodeinfo(domain)
# NOISY-DEBUG: print("DEBUG: json[]:", type(json))
- if json is None or len(json) == 0:
+ if not isinstance(json, dict) or len(json) == 0:
# NOISY-DEBUG: print("DEBUG: Could not determine software type:", domain)
return None
def block_instance(blocker: str, blocked: str, reason: str, block_level: str):
# NOISY-DEBUG: print("DEBUG: blocker,blocked,reason,block_level:", blocker, blocked, reason, block_level)
- if blocker.find("@") > 0:
+ if not validators.domain(blocker):
print("WARNING: Bad blocker:", blocker)
raise
- elif blocked.find("@") > 0:
+ elif not validators.domain(blocked):
print("WARNING: Bad blocked:", blocked)
raise
def add_instance(domain: str, origin: str, originator: str):
# NOISY-DEBUG: print("DEBUG: domain,origin:", domain, origin, originator)
- if domain.find("@") > 0:
+ if not validators.domain(domain):
print("WARNING: Bad domain name:", domain)
raise
- elif origin is not None and origin.find("@") > 0:
+ elif origin is not None and not validators.domain(origin):
print("WARNING: Bad origin name:", origin)
raise
"שרתים מוגבלים" : "Silenced servers",
"Serveurs suspendus" : "Suspended servers",
"Médias filtrés" : "Filtered media",
- "Serveurs limités" : "Silenced servers",
+ "Serveurs limités" : "Limited servers",
+ "Serveurs modérés" : "Limited servers",
}
try: