-from reqto import get
-from reqto import post
-from hashlib import sha256
-from bs4 import BeautifulSoup
-from json import dumps
-from json import loads
-import re
-from time import time
-import itertools
+import time
+import bs4
import fba
+import itertools
+import re
fba.c.execute(
"SELECT domain, software FROM instances WHERE domain='tooting.intensifi.es'"
)
for blocker, software in fba.c.fetchall():
+ print("DEBUG: blocker,software:", blocker, software)
blockdict = []
blocker = fba.tidyup(blocker)
if software == "pleroma":
- print(blocker)
+ print("DEBUG: blocker:", blocker)
try:
# Blocks
- federation = get(
+ federation = reqto.get(
f"https://{blocker}/nodeinfo/2.1.json", headers=headers, timeout=5
).json()["metadata"]["federation"]
if "mrf_simple" in federation:
)
if fba.c.fetchone() == None:
+ print("DEBUG: Hash wasn't found, adding:", blocked)
fba.add_instance(blocked)
- timestamp = int(time())
+ timestamp = int(time.time())
fba.c.execute(
"SELECT * FROM blocks WHERE blocker = ? AND blocked = ? AND block_level = ?",
(
),
)
if fba.c.fetchone() == None:
- block_instance(blocker, blocked, reason, block_level, timestamp, timestamp)
+ fba.block_instance(blocker, blocked, reason, block_level, timestamp, timestamp)
if block_level == "reject":
blockdict.append(
fba.conn.commit()
except Exception as e:
- print("error:", e, blocker)
+ print("error:", e, blocker, software)
elif software == "mastodon":
- print(blocker)
+ print("DEBUG: blocker:", blocker)
try:
# json endpoint for newer mastodongs
try:
}
# handling CSRF, I've saw at least one server requiring it to access the endpoint
- meta = BeautifulSoup(
- get(f"https://{blocker}/about", headers=headers, timeout=5).text,
+ meta = bs4.BeautifulSoup(
+ reqto.get(f"https://{blocker}/about", headers=headers, timeout=5).text,
"html.parser",
)
try:
except:
reqheaders = headers
- blocks = get(
+ blocks = reqto.get(
f"https://{blocker}/api/v1/instance/domain_blocks", headers=reqheaders, timeout=5
).json()
+ print("DEBUG: blocks():", len(blocks))
for block in blocks:
entry = {'domain': block['domain'], 'hash': block['digest'], 'reason': block['comment']}
+
+ print("DEBUG: severity,domain,hash,comment:", block['severity'], block['domain'], block['digest'], block['comment'])
if block['severity'] == 'suspend':
json['reject'].append(entry)
elif block['severity'] == 'silence':
for block_level, blocks in json.items():
for instance in blocks:
blocked, blocked_hash, reason = instance.values()
+ print("DEBUG: blocked,hash,reason:", blocked, blocked_hash, reason)
+
blocked = fba.tidyup(blocked)
+ print("DEBUG: blocked:", blocked)
- if blocked.count("*") <= 1:
+ if blocked.count("*") < 1:
+ # No obsfucation for this instance
fba.c.execute(
- "SELECT hash FROM instances WHERE hash = ?", (blocked_hash,)
+ "SELECT hash FROM instances WHERE domain = ? LIMIT 1", (blocked,)
)
if fba.c.fetchone() == None:
+ print("DEBUG: Hash wasn't found, adding:", blocked)
fba.add_instance(blocked)
else:
# Doing the hash search for instance names as well to tidy up DB
fba.c.execute(
- "SELECT domain FROM instances WHERE hash = ?", (blocked_hash,)
+ "SELECT domain FROM instances WHERE hash = ? LIMIT 1", (blocked_hash,)
)
searchres = fba.c.fetchone()
+
if searchres != None:
+ print("DEBUG: Updating domain: ", searchres[0])
blocked = searchres[0]
- timestamp = int(time())
+ timestamp = int(time.time())
fba.c.execute(
"SELECT * FROM blocks WHERE blocker = ? AND blocked = ? AND block_level = ?",
(
block_level
),
)
+
if fba.c.fetchone() == None:
- block_instance(blocker, blocked if blocked.count("*") <= 1 else blocked_hash, reason, block_level, timestamp, timestamp)
+ fba.block_instance(blocker, blocked if blocked.count("*") <= 1 else blocked_hash, reason, block_level, timestamp, timestamp)
if block_level == "reject":
blockdict.append(
fba.conn.commit()
except Exception as e:
- print("error:", e, blocker)
+ print("error:", e, blocker, software)
elif software == "friendica" or software == "misskey":
- print(blocker)
+ print("DEBUG: blocker:", blocker)
try:
if software == "friendica":
json = fba.get_friendica_blocks(blocker)
)
if fba.c.fetchone() == None:
+ print("DEBUG: Hash wasn't found, adding:", blocked)
fba.add_instance(blocked)
- timestamp = int(time())
+ timestamp = int(time.time())
fba.c.execute(
"SELECT * FROM blocks WHERE blocker = ? AND blocked = ?",
(blocker, blocked),
)
if fba.c.fetchone() == None:
- block_instance(blocker, blocked, reason, block_level, timestamp, timestamp)
+ fba.block_instance(blocker, blocked, reason, block_level, timestamp, timestamp)
if block_level == "reject":
blockdict.append(
fba.conn.commit()
except Exception as e:
- print("error:", e, blocker)
+ print("error:", e, blocker, software)
elif software == "gotosocial":
- print(blocker)
+ print("DEBUG: blocker:", blocker)
try:
# Blocks
- federation = get(
+ federation = reqto.get(
f"https://{blocker}/api/v1/instance/peers?filter=suspended", headers=headers, timeout=5
).json()
)
if fba.c.fetchone() == None:
+ print("DEBUG: Hash wasn't found, adding:", blocked)
fba.add_instance(blocked)
fba.c.execute(
"SELECT * FROM blocks WHERE blocker = ? AND blocked = ? AND block_level = ?",
- (blocker, blocked, "reject"),
+ (
+ blocker,
+ blocked,
+ "reject"
+ ),
)
- timestamp = int(time())
+ timestamp = int(time.time())
if fba.c.fetchone() == None:
- block_instance(blocker, blocked, "", "reject", timestamp, timestamp)
+ fba.block_instance(blocker, blocked, "", "reject", timestamp, timestamp)
blockdict.append(
{
entry["reason"] = reason
fba.conn.commit()
except Exception as e:
- print("error:", e, blocker)
+ print("error:", e, blocker, software)
else:
print("WARNING: Unknown software:", software)
if fba.config["bot_enabled"] and len(blockdict) > 0:
send_bot_post(blocker, blockdict)
+
blockdict = []
fba.conn.close()