also use hash to find blocks
This commit is contained in:
parent
1461b53de3
commit
8e4ba7958e
6
api.py
6
api.py
@ -1,9 +1,13 @@
|
||||
from fastapi import FastAPI
|
||||
import sqlite3
|
||||
from hashlib import sha256
|
||||
|
||||
base_url = ""
|
||||
app = FastAPI(docs_url=base_url+"/docs", redoc_url=base_url+"/redoc")
|
||||
|
||||
def get_hash(domain: str) -> str:
|
||||
return sha256(domain.encode("utf-8")).hexdigest()
|
||||
|
||||
@app.get(base_url+"/info")
|
||||
def info():
|
||||
conn = sqlite3.connect("blocks.db")
|
||||
@ -23,7 +27,7 @@ def blocked(domain: str):
|
||||
conn = sqlite3.connect("blocks.db")
|
||||
c = conn.cursor()
|
||||
wildchar = "*." + ".".join(domain.split(".")[-domain.count("."):])
|
||||
c.execute("select blocker, block_level, reason from blocks where blocked = ? or blocked = ?", (domain, wildchar))
|
||||
c.execute("select blocker, block_level, reason from blocks where blocked = ? or blocked = ? or blocked = ?", (domain, wildchar, get_hash(domain)))
|
||||
blocks = c.fetchall()
|
||||
conn.close()
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user