added endpoint for blocklist download api

This commit is contained in:
carnivuth
2026-01-27 17:42:07 +01:00
parent 95dfa53e18
commit 9306fe641e

View File

@@ -21,6 +21,12 @@ from firewall.raw import Raw
from database import get_database
from config import Config,get_config
from firewall.fwtype import FWType
# imports for the __init_subclass__ method, do not remove pls
from firewall.iptables import Iptables
from firewall.raw import Raw
from tracker import AccessTracker
from analyzer import Analyzer
from templates import html_templates
@@ -952,8 +958,9 @@ class Handler(BaseHTTPRequestHandler):
request_path == f"{self.config.dashboard_secret_path}/api/get_banlist"
):
# get fwtype from request params
fwtype = query_params.get("fwtype",["iptables"])[0]
# Query distinct suspicious IPs
results = (
session.query(distinct(AccessLog.ip))
@@ -972,16 +979,10 @@ class Handler(BaseHTTPRequestHandler):
self.send_response(200)
self.send_header("Content-type", "text/plain")
self.send_header(
"Content-Disposition",
f'attachment; filename="{fwtype}.txt"',
)
self.send_header("Content-Disposition", f'attachment; filename="{fwtype}.txt"',)
self.send_header("Content-Length", str(len(banlist)))
self.end_headers()
self.wfile.write(banlist.encode())
public_ips = [ip for (ip,) in results if is_valid_public_ip(ip, server_ip)]
self.wfile.write(f"asdasdd {fwtype} {public_ips}".encode())
return
# API endpoint for downloading malicious IPs file