]> git.mxchange.org Git - fba.git/commitdiff
also use hash to find blocks
authorEnju Aihara <9839590-EnjuAihara@users.noreply.gitlab.com>
Fri, 22 Apr 2022 12:58:23 +0000 (14:58 +0200)
committerEnju Aihara <9839590-EnjuAihara@users.noreply.gitlab.com>
Fri, 22 Apr 2022 12:58:23 +0000 (14:58 +0200)
api.py

diff --git a/api.py b/api.py
index ffdb03e6e1f7bed77fad686bf9280f7a5b6d5a98..713e0413f85adda64f390530a830cdbab4d8cc1a 100644 (file)
--- a/api.py
+++ b/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()