From 7f3f0928cf9fb45b4eed4da91cb527fe8206c5b5 Mon Sep 17 00:00:00 2001
From: Mint <>
Date: Mon, 8 Aug 2022 14:29:44 +0300
Subject: [PATCH] Mark wildcard blocks as such

---
 api.py     | 12 +++++++-----
 index.html | 10 +++++++++-
 2 files changed, 16 insertions(+), 6 deletions(-)

diff --git a/api.py b/api.py
index d37d22e..ca3badb 100644
--- a/api.py
+++ b/api.py
@@ -39,7 +39,7 @@ def blocked(domain: str = None, reason: str = None):
     if domain != None:
         wildchar = "*." + ".".join(domain.split(".")[-domain.count("."):])
         punycode = domain.encode('idna').decode('utf-8')
-        c.execute("select blocker, block_level, reason from blocks where blocked = ? or blocked = ? or blocked = ? or blocked = ? or blocked = ? or blocked = ?",
+        c.execute("select blocker, blocked, block_level, reason from blocks where blocked = ? or blocked = ? or blocked = ? or blocked = ? or blocked = ? or blocked = ?",
                   (domain, "*." + domain, wildchar, get_hash(domain), punycode, "*." + punycode))
     else:
         c.execute("select * from blocks where reason like ? and reason != ''", ("%"+reason+"%",))
@@ -48,19 +48,21 @@ def blocked(domain: str = None, reason: str = None):
 
     result = {}
     reasons = {}
+    wildcards = {}
     if domain != None:
-        for domain, block_level, reason in blocks:
+        for domain, blocked, block_level, reason in blocks:
             if block_level in result:
                 result[block_level].append(domain)
             else:
                 result[block_level] = [domain]
-                
+            if blocked == "*." + ".".join(blocked.split(".")[-blocked.count("."):]):
+                wildcards.append(domain)
             if reason != "":
                 if block_level in reasons:
                     reasons[block_level][domain] = reason
                 else:
                     reasons[block_level] = {domain: reason}
-        return {"blocks": result, "reasons": reasons}
+        return {"blocks": result, "reasons": reasons, "wildcards": wildcards}
 
     for blocker, blocked, reason, block_level in blocks:
         if block_level in result:
@@ -88,7 +90,7 @@ def index(request: Request, domain: str = None, reason: str = None):
         if not blocks.ok:
             raise HTTPException(status_code=blocks.status_code, detail=blocks.text)
         blocks = blocks.json()
-    return templates.TemplateResponse("index.html", {"request": request, "domain": domain, "blocks": blocks, "reason": reason, "info": info})
+    return templates.TemplateResponse("index.html", {"request": request, "domain": domain, "blocks": blocks, "wildcards": wildcards, "reason": reason, "info": info})
 
 if __name__ == "__main__":
     uvicorn.run("api:app", host="127.0.0.1", port=port, log_level="info")
diff --git a/index.html b/index.html
index 4ba78b3..9819402 100644
--- a/index.html
+++ b/index.html
@@ -44,6 +44,10 @@
         input[type="submit"]:hover {
             border-color: #f08;
         }
+
+        span[title] {
+            text-decoration: underline dotted;
+        }
     </style>
 </head>
 <body>
@@ -71,7 +75,11 @@
                 {% for block in blocks.blocks[block_level] %}
                     <div class="block">
                         <img src="https://proxy.duckduckgo.com/ip3/{{block}}.ico" width=16/>
-                        <b><a href="https://{{block}}">{{block}}</a></b><br/>
+                        <b><a href="https://{{block}}">{{block}}</a></b>
+                        {% if block in wildcards %}
+                            (<span title="wildcard block">&lowast;</span>)
+                        {% endif %}
+                        <br/>
                         {% if block_level in blocks.reasons %}
                             {{blocks.reasons[block_level][block]}}
                         {% endif %}
-- 
2.39.5