def info():
conn = sqlite3.connect("blocks.db")
c = conn.cursor()
- c.execute("select (select count(domain) from instances), (select count(domain) from instances where software in ('pleroma', 'mastodon', 'misskey', 'gotosocial', 'friendica')), (select count(blocker) from blocks)")
+ c.execute("SELECT (SELECT count(domain) FROM instances), (SELECT count(domain) FROM instances WHERE software in ('pleroma', 'mastodon', 'misskey', 'gotosocial', 'friendica')), (SELECT count(blocker) FROM blocks)")
known, indexed, blocks = c.fetchone()
c.close()
return {
elif blocked != None:
if blocked > 500:
raise HTTPException(status_code=400, detail="Too many results")
- c.execute("select blocked, count(blocked) from blocks where block_level = 'reject' group by blocked order by count(blocked) desc limit ?", (blocked,))
+ c.execute("SELECT blocked, count(blocked) FROM blocks WHERE block_level = 'reject' group by blocked order by count(blocked) desc limit ?", (blocked,))
elif blockers != None:
if blockers > 500:
raise HTTPException(status_code=400, detail="Too many results")
- c.execute("select blocker, count(blocker) from blocks where block_level = 'reject' group by blocker order by count(blocker) desc limit ?", (blockers,))
+ c.execute("SELECT blocker, count(blocker) FROM blocks WHERE block_level = 'reject' group by blocker order by count(blocker) desc limit ?", (blockers,))
scores = c.fetchall()
c.close()
if domain != None:
wildchar = "*." + ".".join(domain.split(".")[-domain.count("."):])
punycode = domain.encode('idna').decode('utf-8')
- c.execute("select blocker, blocked, block_level, reason, first_added, last_seen from blocks where blocked = ? or blocked = ? or blocked = ? or blocked = ? or blocked = ? or blocked = ? order by first_added asc",
+ c.execute("SELECT blocker, blocked, block_level, reason, first_added, last_seen FROM blocks WHERE blocked = ? OR blocked = ? OR blocked = ? OR blocked = ? OR blocked = ? OR blocked = ? order by first_added asc",
(domain, "*." + domain, wildchar, get_hash(domain), punycode, "*." + punycode))
elif reverse != None:
- c.execute("select blocker, blocked, block_level, reason, first_added, last_seen from blocks where blocker = ? order by first_added asc", (reverse,))
+ c.execute("SELECT blocker, blocked, block_level, reason, first_added, last_seen FROM blocks WHERE blocker = ? order by first_added asc", (reverse,))
else:
- c.execute("select blocker, blocked, block_level, reason, first_added, last_seen from blocks where reason like ? and reason != '' order by first_added asc", ("%"+reason+"%",))
+ c.execute("SELECT blocker, blocked, block_level, reason, first_added, last_seen FROM blocks WHERE reason like ? AND reason != '' order by first_added asc", ("%"+reason+"%",))
blocks = c.fetchall()
c.close()
if domain != None:
wildchar = "*." + ".".join(domain.split(".")[-domain.count("."):])
punycode = domain.encode('idna').decode('utf-8')
- c.execute("select blocker, blocked, block_level, reason, first_added, last_seen from blocks where blocked = ? or blocked = ? or blocked = ? or blocked = ? or blocked = ? or blocked = ? order by first_added desc limit 50",
+ c.execute("SELECT blocker, blocked, block_level, reason, first_added, last_seen FROM blocks WHERE blocked = ? OR blocked = ? OR blocked = ? OR blocked = ? OR blocked = ? OR blocked = ? order by first_added desc limit 50",
(domain, "*." + domain, wildchar, get_hash(domain), punycode, "*." + punycode))
else:
- c.execute("select blocker, blocked, block_level, reason, first_added, last_seen from blocks order by first_added desc limit 50")
+ c.execute("SELECT blocker, blocked, block_level, reason, first_added, last_seen FROM blocks order by first_added desc limit 50")
blocks = c.fetchall()
c.close()
c = conn.cursor()
c.execute(
- "select domain, software from instances where software in ('pleroma', 'mastodon', 'friendica', 'misskey', 'gotosocial')"
+ "SELECT domain, software FROM instances WHERE software in ('pleroma', 'mastodon', 'friendica', 'misskey', 'gotosocial')"
)
for blocker, software in c.fetchall():
if blocked.count("*") > 1:
# -ACK!-oma also started obscuring domains without hash
c.execute(
- "select domain from instances where domain like ? order by rowid limit 1", (blocked.replace("*", "_"),)
+ "SELECT domain FROM instances WHERE domain LIKE ? ORDER BY rowid LIMIT 1", (blocked.replace("*", "_"),)
)
searchres = c.fetchone()
if searchres != None:
blocked = searchres[0]
c.execute(
- "select domain from instances where domain = ?", (blocked,)
+ "SELECT domain FROM instances WHERE domain = ?", (blocked,)
)
if c.fetchone() == None:
c.execute(
- "insert into instances select ?, ?, ?",
+ "INSERT INTO instances SELECT ?, ?, ?",
(blocked, get_hash(blocked), get_type(blocked)),
)
timestamp = int(time())
c.execute(
- "select * from blocks where blocker = ? and blocked = ? and block_level = ?",
+ "SELECT * FROM blocks WHERE blocker = ? AND blocked = ? AND block_level = ?",
(blocker, blocked, block_level),
)
if c.fetchone() == None:
c.execute(
- "insert into blocks select ?, ?, '', ?, ?, ?",
+ "INSERT INTO blocks SELECT ?, ?, '', ?, ?, ?",
(blocker, blocked, block_level, timestamp, timestamp),
)
if block_level == "reject":
})
else:
c.execute(
- "update blocks set last_seen = ? where blocker = ? and blocked = ? and block_level = ?",
+ "UPDATE blocks set last_seen = ? WHERE blocker = ? AND blocked = ? AND block_level = ?",
(timestamp, blocker, blocked, block_level)
)
conn.commit()
if blocked.count("*") > 1:
# same domain guess as above, but for reasons field
c.execute(
- "select domain from instances where domain like ? order by rowid limit 1", (blocked.replace("*", "_"),)
+ "SELECT domain FROM instances WHERE domain LIKE ? ORDER BY rowid LIMIT 1", (blocked.replace("*", "_"),)
)
searchres = c.fetchone()
if searchres != None:
blocked = searchres[0]
c.execute(
- "update blocks set reason = ? where blocker = ? and blocked = ? and block_level = ? and reason = ''",
+ "UPDATE blocks set reason = ? WHERE blocker = ? AND blocked = ? AND block_level = ? AND reason = ''",
(reason["reason"], blocker, blocked, block_level),
)
for entry in blockdict:
blocked = tidyup(blocked)
if blocked.count("*") <= 1:
c.execute(
- "select hash from instances where hash = ?", (blocked_hash,)
+ "SELECT hash FROM instances WHERE hash = ?", (blocked_hash,)
)
if c.fetchone() == None:
c.execute(
- "insert into instances select ?, ?, ?",
+ "INSERT INTO instances SELECT ?, ?, ?",
(blocked, get_hash(blocked), get_type(blocked)),
)
else:
# Doing the hash search for instance names as well to tidy up DB
c.execute(
- "select domain from instances where hash = ?", (blocked_hash,)
+ "SELECT domain FROM instances WHERE hash = ?", (blocked_hash,)
)
searchres = c.fetchone()
if searchres != None:
timestamp = int(time())
c.execute(
- "select * from blocks where blocker = ? and blocked = ? and block_level = ?",
+ "SELECT * FROM blocks WHERE blocker = ? AND blocked = ? AND block_level = ?",
(blocker, blocked if blocked.count("*") <= 1 else blocked_hash, block_level),
)
if c.fetchone() == None:
c.execute(
- "insert into blocks select ?, ?, ?, ?, ?, ?",
+ "INSERT INTO blocks SELECT ?, ?, ?, ?, ?, ?",
(
blocker,
blocked if blocked.count("*") <= 1 else blocked_hash,
})
else:
c.execute(
- "update blocks set last_seen = ? where blocker = ? and blocked = ? and block_level = ?",
+ "UPDATE blocks set last_seen = ? WHERE blocker = ? AND blocked = ? AND block_level = ?",
(timestamp, blocker, blocked if blocked.count("*") <= 1 else blocked_hash, block_level),
)
if reason != '':
c.execute(
- "update blocks set reason = ? where blocker = ? and blocked = ? and block_level = ? and reason = ''",
+ "UPDATE blocks set reason = ? WHERE blocker = ? AND blocked = ? AND block_level = ? AND reason = ''",
(reason, blocker, blocked if blocked.count("*") <= 1 else blocked_hash, block_level),
)
conn.commit()
if blocked.count("*") > 0:
# Some friendica servers also obscure domains without hash
c.execute(
- "select domain from instances where domain like ? order by rowid limit 1", (blocked.replace("*", "_"),)
+ "SELECT domain FROM instances WHERE domain LIKE ? ORDER BY rowid LIMIT 1", (blocked.replace("*", "_"),)
)
searchres = c.fetchone()
if searchres != None:
if blocked.count("?") > 0:
# Some obscure them with question marks, not sure if that's dependent on version or not
c.execute(
- "select domain from instances where domain like ? order by rowid limit 1", (blocked.replace("?", "_"),)
+ "SELECT domain FROM instances WHERE domain LIKE ? ORDER BY rowid LIMIT 1", (blocked.replace("?", "_"),)
)
searchres = c.fetchone()
if searchres != None:
blocked = searchres[0]
c.execute(
- "select domain from instances where domain = ?", (blocked,)
+ "SELECT domain FROM instances WHERE domain = ?", (blocked,)
)
if c.fetchone() == None:
c.execute(
- "insert into instances select ?, ?, ?",
+ "INSERT INTO instances SELECT ?, ?, ?",
(blocked, get_hash(blocked), get_type(blocked)),
)
timestamp = int(time())
c.execute(
- "select * from blocks where blocker = ? and blocked = ?",
+ "SELECT * FROM blocks WHERE blocker = ? AND blocked = ?",
(blocker, blocked),
)
if c.fetchone() == None:
c.execute(
- "insert into blocks select ?, ?, ?, ?, ?, ?",
+ "INSERT INTO blocks SELECT ?, ?, ?, ?, ?, ?",
(
blocker,
blocked,
})
else:
c.execute(
- "update blocks set last_seen = ? where blocker = ? and blocked = ? and block_level = ?",
+ "UPDATE blocks set last_seen = ? WHERE blocker = ? AND blocked = ? AND block_level = ?",
(timestamp, blocker, blocked, block_level),
)
if reason != '':
c.execute(
- "update blocks set reason = ? where blocker = ? and blocked = ? and block_level = ? and reason = ''",
+ "UPDATE blocks set reason = ? WHERE blocker = ? AND blocked = ? AND block_level = ? AND reason = ''",
(reason, blocker, blocked, block_level),
)
conn.commit()
if blocked.count("*") > 0:
# GTS does not have hashes for obscured domains, so we have to guess it
c.execute(
- "select domain from instances where domain like ? order by rowid limit 1", (blocked.replace("*", "_"),)
+ "SELECT domain FROM instances WHERE domain LIKE ? ORDER BY rowid LIMIT 1", (blocked.replace("*", "_"),)
)
searchres = c.fetchone()
if searchres != None:
blocked = searchres[0]
c.execute(
- "select domain from instances where domain = ?", (blocked,)
+ "SELECT domain FROM instances WHERE domain = ?", (blocked,)
)
if c.fetchone() == None:
c.execute(
- "insert into instances select ?, ?, ?",
+ "INSERT INTO instances SELECT ?, ?, ?",
(blocked, get_hash(blocked), get_type(blocked)),
)
c.execute(
- "select * from blocks where blocker = ? and blocked = ? and block_level = ?",
+ "SELECT * FROM blocks WHERE blocker = ? AND blocked = ? AND block_level = ?",
(blocker, blocked, "reject"),
)
timestamp = int(time())
if c.fetchone() == None:
c.execute(
- "insert into blocks select ?, ?, ?, ?, ?, ?",
+ "INSERT INTO blocks SELECT ?, ?, ?, ?, ?, ?",
(blocker, blocked, "", "reject", timestamp, timestamp),
)
blockdict.append(
})
else:
c.execute(
- "update blocks set last_seen = ? where blocker = ? and blocked = ? and block_level = ?",
+ "UPDATE blocks set last_seen = ? WHERE blocker = ? AND blocked = ? AND block_level = ?",
(timestamp, blocker, blocked, "reject"),
)
if "public_comment" in peer:
reason = peer["public_comment"]
c.execute(
- "update blocks set reason = ? where blocker = ? and blocked = ? and block_level = ? and reason = ''",
+ "UPDATE blocks set reason = ? WHERE blocker = ? AND blocked = ? AND block_level = ? AND reason = ''",
(reason, blocker, blocked, "reject"),
)
for entry in blockdict: