Mark wildcard blocks as such
This commit is contained in:
parent
ce2c200c49
commit
7f3f0928cf
12
api.py
12
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")
|
||||
|
10
index.html
10
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">∗</span>)
|
||||
{% endif %}
|
||||
<br/>
|
||||
{% if block_level in blocks.reasons %}
|
||||
{{blocks.reasons[block_level][block]}}
|
||||
{% endif %}
|
||||
|
Loading…
x
Reference in New Issue
Block a user