From 8e4ba7958e9ecb4eb4c63d04df9138a40786d971 Mon Sep 17 00:00:00 2001 From: Enju Aihara <9839590-EnjuAihara@users.noreply.gitlab.com> Date: Fri, 22 Apr 2022 14:58:23 +0200 Subject: [PATCH] also use hash to find blocks --- api.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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() -- 2.39.5