From: Enju Aihara <9839590-EnjuAihara@users.noreply.gitlab.com> Date: Fri, 22 Apr 2022 12:58:23 +0000 (+0200) Subject: also use hash to find blocks X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=8e4ba7958e9ecb4eb4c63d04df9138a40786d971;p=fba.git also use hash to find blocks --- diff --git a/api.py b/api.py index ffdb03e..713e041 100644 --- 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()