Skip to content

loghunt 0.2.0: fit your server (--allow, thresholds, --since/--until, --blocklist-format) - #1

Merged
winxtxrgit merged 8 commits into
mainfrom
feat/0.2.0
Nov 26, 2026
Merged

winxtxrgit merged 8 commits into
mainfrom
feat/0.2.0

Conversation

@winxtxrgit

@winxtxrgit winxtxrgit commented Nov 26, 2026 •

Copy link
Copy Markdown
Owner

The first release meant for PyPI. 0.1.0 was never uploaded, so this PR also carries the release workflow (dc3c206), which was committed but never pushed to main.

Each feature is its own commit. The last commit fixes a test that failed on Windows only: the test read the HTML report without an encoding, and Windows defaults to cp1252. loghunt itself was writing the report correctly.

What's new

Flag What it does
--allow IP|CIDR|@FILE Never flag these IPs: uptime checks, office NAT, your own scanners. They still count toward traffic, but are never flagged, grouped into a campaign or written to the blocklist. ::ffff:x.x.x.x matches the IPv4 range.
--burst --flood --login-posts --probes Tune the rules for your site. Campaigns use the same numbers for group totals. --flood below --burst is rejected.
--since / --until Analyse one incident window. UTC unless an offset is given; --since inclusive, --until exclusive. Same accepted formats on Python 3.10 to 3.13.
--blocklist-format plain (default), nginx, apache, ipset or nftables, written so the server or firewall can load the file as it is. ipset and nftables files replace their old contents when reloaded.

The JSON output gains allowed, thresholds and window; the terminal summary and HTML footer report the allowlist and window when they are used. Existing JSON keys are unchanged.

ROADMAP.md lays out 0.3 to 0.5 and what is not planned. One change from the first draft: fail2ban became nftables, because fail2ban has no file to load, only commands to run.

Verification

  • pytest: 104 passed (55 before), checked locally on each intermediate commit; CI passes on all 6 jobs (Ubuntu 3.10 to 3.13, Windows, macOS)
  • ruff check and ruff format --check clean
  • The bundled sample gives the same result with default options
  • The generated nginx file passes nginx -t, and the Apache file passes httpd -t (Apache 2.4)
  • Not run against the real tools: the ipset and nftables output. The tests check the structure (separate IPv4/IPv6 sets, flush or delete before reload, no empty elements = { }), but nobody has run ipset restore or nft -c -f on them yet

To release after merging

  1. On PyPI, add a pending Trusted Publisher: project loghunt, owner winxtxrgit, repository loghunt, workflow release.yml, environment pypi
  2. Publish a GitHub release with the tag v0.2.0. The workflow checks that the tag matches __version__, smoke-tests the wheel and uploads it

🤖 Generated with Claude Code

winxtxrgit and others added 8 commits October 24, 2026 06:50
A published release builds the sdist and wheel, checks them with
`twine check --strict`, verifies the tag matches the package version,
smoke-tests the wheel on the bundled sample, then uploads with Trusted
Publishing (OIDC) from the `pypi` environment. No token is stored.
Every action is pinned to a commit SHA.

The version now lives only in src/loghunt/__init__.py. The README uses
absolute image and license URLs so they render on PyPI, installs from
PyPI, and shows a PyPI badge.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Five releases from "find attackers in a log you have" to "watch a log as
it grows": fit your server (0.2), read more log formats (0.3), catch
botnets that rotate User-Agents (0.4), and a --follow mode (0.5). Also
lists what is not planned and why: blocking by itself, network lookups
during analysis, and scores that cannot explain themselves.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
--allow takes an IP, a CIDR range or @file with one entry per line
(# starts a comment) and can be repeated. Allowed IPs still count toward
traffic totals, but are never flagged, never grouped into a campaign and
never written to the blocklist, so three uptime monitors running the
same login check cannot become a "botnet".

An IPv4 client logged as ::ffff:203.0.113.9 by a dual-stack socket
matches the IPv4 range. A bad entry stops the run with exit status 2 and
names the file and line.

The terminal summary, the JSON ("allowed") and the HTML footer say how
many IPs were skipped.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The defaults suit a small-to-medium site; a busy shop or a WordPress
site with many real logins needs higher numbers. Campaigns use the same
login and probe numbers for their group totals.

--flood below --burst is rejected, because the flood check runs first
and would hide every burst. The JSON output now records the thresholds
a run used ("thresholds"); the HTML footer already did.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Accepts 2026-10-20, 2026-10-20 08:30 and 2026-10-20T08:30:15 with an
optional Z, +07:00 or +0700 offset; without one the time is UTC, like
every loghunt output. The parser is a fixed regex rather than
datetime.fromisoformat, which accepts different inputs on 3.10 and 3.12.

--since is inclusive and --until exclusive, so --since 2026-10-20
--until 2026-10-21 is the whole day. Requests outside the window are
counted and reported (terminal, JSON "window", HTML footer) but not
analysed, so every count, including campaign totals, is per window.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Writes a file the server or firewall loads as it is: nginx deny rules,
an Apache 2.4 RequireAll block, ipset restore commands (separate IPv4
and IPv6 sets) or an nft -f table that drops both. The ipset and
nftables files replace their old contents when loaded again, so a cron
job never piles up stale entries. The nginx and Apache output passes
nginx -t and httpd -t.

The ROADMAP listed fail2ban; it has no file to load, only commands to
run, so nftables took its place.

Every format keeps only well-formed addresses, and an IPv4-mapped IPv6
address is written as its IPv4, once.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
0.1.0 was never uploaded, so 0.2.0 is the first version on PyPI. It
adds --allow, the threshold flags, --since/--until and
--blocklist-format on top of 0.1.0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Path.read_text() without an encoding uses cp1252 on Windows, so the
window test read the report's "→" as mojibake and failed there. loghunt
writes every file as UTF-8; the new tests now read them the same way.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@winxtxrgit
winxtxrgit merged commit 41cba82 into main Nov 26, 2026
6 checks passed
@winxtxrgit
winxtxrgit deleted the feat/0.2.0 branch November 26, 2026 03:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant