diff --git a/app/app.py b/app/app.py index b0c38d5..6b9b3bf 100644 --- a/app/app.py +++ b/app/app.py @@ -87,19 +87,35 @@ def index(): return render_template("index.html", my_ip=caller_ip()) +DEFAULT_LIMIT = 200 +MAX_LIMIT = 2000 + + @app.get("/decisions") def list_decisions(): - q = request.args.get("ip", "").strip() - params = {} - if q: - if not valid_ip(q): - return render_template("_decisions.html", error="invalid IP", decisions=[]), 400 - params["ip"] = q + ip = request.args.get("ip", "").strip() + reason = request.args.get("reason", "").strip() + origin = request.args.get("origin", "").strip() + try: + limit = max(1, min(MAX_LIMIT, int(request.args.get("limit", DEFAULT_LIMIT)))) + except ValueError: + limit = DEFAULT_LIMIT + + params = {"limit": limit} + if ip: + if not valid_ip(ip): + return render_template("_decisions.html", error="invalid IP", decisions=[], total=0, limit=limit), 400 + params["ip"] = ip + if reason: + params["scenarios_containing"] = reason + if origin: + params["origins"] = origin + r = _bouncer("GET", "/v1/decisions", params=params) if r.status_code != 200: - return render_template("_decisions.html", error=f"LAPI {r.status_code}: {r.text[:200]}", decisions=[]), 502 + return render_template("_decisions.html", error=f"LAPI {r.status_code}: {r.text[:200]}", decisions=[], total=0, limit=limit), 502 decisions = r.json() or [] - return render_template("_decisions.html", decisions=decisions, error=None) + return render_template("_decisions.html", decisions=decisions, error=None, total=len(decisions), limit=limit) @app.post("/unban") diff --git a/app/templates/_decisions.html b/app/templates/_decisions.html index 21d6a22..58e10b6 100644 --- a/app/templates/_decisions.html +++ b/app/templates/_decisions.html @@ -2,23 +2,27 @@

{{ error }}

{% endif %} {% if decisions %} +

+ Showing {{ total }} decision{{ '' if total == 1 else 's' }} + (server limit {{ limit }}{% if total == limit %} — at cap, raise limit if more expected{% endif %}). +

- 0 selected of {{ decisions|length }} + 0 selected
- + {% for d in decisions %} - + @@ -38,14 +42,25 @@
IDIP / valueScopeTypeReasonUntilOrigin
{{ d.id }} {{ d.value }} {{ d.scope }}
{% else %} {% if not error %}

No active decisions.

{% endif %} diff --git a/app/templates/index.html b/app/templates/index.html index 966aa1f..ebf1f4a 100644 --- a/app/templates/index.html +++ b/app/templates/index.html @@ -22,6 +22,11 @@ section { margin-top: 1.5rem; padding: 1rem; background:#181818; border-radius:6px; } .err { color:#f88; } code { background:#222; padding:.1rem .3rem; border-radius:3px; } + .row > * { flex: 0 0 auto; } + .grow { flex: 1 1 200px; } + .htmx-request #decisions::after { content: " loading…"; color:#888; } + .hidden-row { display:none; } + select { background:#222; color:#ddd; border:1px solid #444; padding:.4rem; border-radius:4px; } @@ -36,13 +41,47 @@

Active decisions

-
- + + + + + -
+
+ + +
Loading…
+

Unban by IP