openwrt-audit-kit

Your router config,
as something you can read.

Read-only tooling that turns an OpenWrt + AdGuard Home setup into pages you can read, tables you can audit, and JSON you can diff. Written for a documented home network, released for anyone who thinks a firewall should be explainable.

Read-only by construction Python 3 stdlib only POSIX sh Zero CDN, fonts or trackers MIT
Why this exists

A firewall you cannot read is a firewall you cannot trust.

OpenWrt's fw4 and AdGuard Home are excellent. Their configuration formats are not written for humans who come back six months later. uci export firewall is a flat list of sections, LuCI shows one rule at a time, and the AdGuard rule list is a text box. None of them answers the questions an operator actually asks: which devices may talk to the hub, on which ports, and why?

This kit grew out of a home network that is documented the way production systems should be: a Markdown document is the source of truth, every change gets a journal entry, and audits are run against logs, not against memory. The tools here are the glue between that documentation and the live device.

Mirror, not source

The pages the kit renders are mirrors for reading. The documentation is the source; when the device disagrees with the document, the device wins and the mismatch becomes a finding. agview even diffs the device against your Markdown rule tables and reports both directions.

Read-only by construction

SSH in BatchMode with key auth, uci export instead of uci show (no wireless keys in the output), and only the user_rules, filtering and clients sections of adguardhome.yaml, never the whole file. The one tool that writes asks first and is labelled.

Boring output on purpose

One self-contained HTML file plus the same data as JSON. Audit scripts emit Markdown tables, nothing else: the tables are the data of an audit, the findings are written by a human who looked at them. No dashboard, no database, no daemon.

The tools

Seven scripts, one idea.

Everything runs on your workstation against the router. Device names come from the router's DHCP reservations, zones from its network config, so every IP in every table carries a name you recognise.

fwview.py read-only

Reads
uci export firewall | dhcp | network
Writes
one HTML page, one JSON report
Shows
one section per source zone, INPUT apart from FORWARD, then DNAT; every rule as a row with source, destination, ports with service names, logging; IP sets expanded with members and device names.

agview.py read-only

Reads
AdGuard user_rules, rewrites, persistent clients
Writes
HTML + JSON
Shows
rules grouped by the ! --- heading --- lines of your list, client scope resolved to device and zone, the comment above a rule as its rationale, hits per rule from the query log, and a diff against your documentation (--doc).

fwlog-audit.py read-only

Reads
the router's persistent syslog
Writes
Markdown tables for a time window
Shows
lines per log class and hour, INPUT noise per zone, lateral traffic between zones, egress blocks per rule, minutes at the log rate limit (lines you did not see), scan indicators.

dnslog-audit.py read-only

Reads
AdGuard's querylog.json (gzip in transit or from a copy)
Writes
Markdown tables for a time window
Shows
volume per client and zone, which lists fire, exactly which names the default-deny IoT zones reached, DoH/DoT bypass attempts, tunnelling heuristics, seconds at AdGuard's rate limit, upstream latency percentiles.

pushset.sh writes, asks first

Does
validates an IP-set file locally, refuses on any bad line, copies it to the router, creates or reloads the fw4 set (option loadfile). Ships with lists for public DoH/DoT resolvers, Google and Cloudflare ranges.

wificli.sh & modemctl.sh writes

Do
switch single SSIDs or whole radios via UCI; enable or disable the LTE modem on a GL.iNet Spitz Plus. Both carry a long header explaining how to find the right section or USB bus ID before you touch anything.
fwview: firewall rules rendered as one section per source zone, with IP sets expanded to their members and device names
fwview. Zone adminvpn: INPUT rules apart from FORWARD, each IP set expanded in place (SET adminvpn_peers, three addresses) and the destination resolved to a device name. Filter box and zone navigation at the top; the whole thing is one HTML file. Open the full example page (75 rules, pseudonymised MACs).
agview: page header with counts, hits from the query log, documentation diff and a list of hints
agview, header. 121 active rules, hits from 94,187 query-log entries, and the diff against the documentation: 121 documented, 121 on the device, 0 missing either way. Below it, the hints: clients whose flags have no effect, roaming addresses without a reservation, allow-rules that never fired.
agview: a rule group with type, rule text, domain, effect, client with device name and zone, rationale and hit count
agview, rules. One group per heading in your AdGuard list. Each row: type, the rule as written, domain with reach, effect, the client resolved to device and zone, the comment above it as rationale, and how often it fired. Disabled rules are shown, greyed. Open the full example page (121 rules, hits from a real query log).
Workflow

An audit, start to finish.

Four commands, a few minutes, and you have the data for a report. The findings are yours to write; the kit deliberately stops at the tables.

# 1. Fetch AdGuard's query log compressed. AdGuard only flushes it to disk every
#    1,000 entries, so the last hour of a quiet network may still sit in memory.
ssh root@192.168.30.1 'gzip -c /var/persist/adguardhome/data/querylog.json' > querylog.json.gz

# 2. Firewall log of the window, as Markdown tables
scripts/fwlog-audit.py --since '2026-10-25 00:30' --out fwlog.md

# 3. DNS query log of the same window
scripts/dnslog-audit.py --since '2026-10-25 00:30' --querylog querylog.json.gz --out dnslog.md

# 4. Refresh the two mirrors; agview counts hits per rule from the same copy
scripts/fwview.py --out fwview.html
scripts/agview.py --out agview.html --querylog querylog.json.gz --doc docs/dns-filtering.md
PrefixClassLinesShareFirstLastMax/minLimit/minMinutes at limit
reject wgvpn inzone-in5538.5 %25.10. 00:5025.10. 10:284100
reject smarthome_srv forwardzone-fwd3524.5 %25.10. 00:3025.10. 01:3510102
Block-hubsrv-wan-allrule3021.0 %25.10. 00:3025.10. 01:35963
drop wgvpn invalid ct stateinvalid1913.3 %25.10. 01:1825.10. 09:253–0

Table T1 of fwlog-audit.py, from a real ten-hour window. The last column is the one people miss: minutes in which the kernel's log rate limit was saturated, i.e. minutes with hits you never saw.

No router at hand? Every Python tool has --from-dir DIR and reads saved uci export output (and a query-log copy) from a directory instead of SSH. That is how the tests run, and how you can inspect a colleague's export without touching their device.
The firewall4 patch

Sets as objects: source and destination in one rule.

Here is the limitation that shaped this whole project. In stock fw4 a rule or redirect can reference exactly one named set via option ipset. You can say "source is in this set" or "destination is in this set", but not both at once. The moment you want "only these pinned devices (IP + MAC) may reach this group of addresses", you are back to writing one rule per device, or one rule per destination, and keeping them in sync by hand.

My router runs a patched firewall4 that turns option ipset into list ipset. Several sets in one rule are AND-ed; direction (src, dest) and negation apply per entry; a single option ipset keeps working, and a ruleset without multi-set rules renders byte-for-byte identical. Devices become members of sets, rules reference sets, and a new device means one edit instead of a hunt through the rule list.

Stock fw4: one set, one direction
config rule
    option name 'Allow-admin-hub-ha-1'
    option src 'private'
    option src_ip '192.168.20.111'
    option src_mac '02:aa:...'
    option dest 'smarthome_srv'
    option dest_ip '192.168.60.245'
    option dest_port '8123'
    option target 'ACCEPT'

config rule
    option name 'Allow-admin-hub-ha-2'
    # ... same again for the next device
Patched fw4: sets as source and destination
config rule
    option name 'Allow-admin-hub-ha'
    option src 'private'
    option dest 'smarthome_srv'
    list ipset 'admin_pins src'    # ip+mac pairs
    list ipset 'hub_ip dest'       # the hub
    option dest_port '8123'
    option target 'ACCEPT'

# new admin device? add it to admin_pins.
# a fifth device in the zone matches nothing:
# fail-closed by default.

In practice this means a pair set of pinned devices on the source side and an address set on the destination side, in the same rule. On my router eighteen rules use two sets today, the mirror above renders them, and a guard script re-applies the patch after upgrades and shouts if the installed fw4 version is unknown.

Fail-closed matters here. Stock fw4 silently reads option ipset 'setA setB' as a reference to setA alone: the rule matches fewer conditions than you wrote, and nothing tells you. With list support that single-line form becomes a likely mistake, so the second PR rejects unknown tokens with a warning instead of guessing.

Upstream pull requests

Both are open against openwrt/firewall4. The feature series is split so that the three independent fixes found on the way can be backported on their own.

#109

fw4: support multiple ipset references per rule and redirect

option ipset becomes list ipset, references are AND-ed, each validated on its own. Preceded by three fixes: an empty set match emitted for proto 'tcp icmp' with a port set (invalid nft, whole ruleset failed to load), a misleading family-conflict message, and repeated separators in set references shifting the direction to the wrong field. Templates rule.uc, redirect.uc, mangle-rule.uc, core fw4.uc, three new test suites.

#110

fw4: reject unknown tokens in ipset references

A reference with more than three tokens, or a token that is not a direction, now drops the section with the usual invalid value warning instead of being silently truncated. The upgrade risk is stated openly in the PR, and a warn-only variant is offered for discussion. Submitted separately so it can be taken, changed or dropped without touching the feature series.

The kit itself does not need the patch. On stock fw4, fwview simply renders single-set rules. With the patch, it renders every set of a rule in place, which is what makes the mirror readable.

Design notes

Small decisions that keep it maintainable.

Rule names carry the policy

Allow-<zone>-<target>-<service>, Block-<zone>-wan-all, Mute-<zone>-<what>. A log line's prefix is enough to know which rule fired and whether that was expected. fwlog-audit groups by exactly these prefixes.

Mute instead of ignore

Known noise (mDNS, SSDP, NAT-PMP probes, discovery broadcasts) is dropped by small nft include files with their own counters and no log, placed before the zone catch-all. The policy does not change; the log stops lying about its volume and the rate limit stays free for the lines that matter.

Numbers you can diff

Every table is deterministic for a given input. Re-run an audit with the same --since on a later log and diff the Markdown. The JSON next to each HTML mirror is the same data without the layout, for scripts or for a model you are willing to hand your addresses to.

Examples are real, and pseudonymised

The sample pages in reports/ come from real runs. MAC addresses are replaced by deterministic 02:… pseudonyms, consistent across files; device prefixes that were initials are neutral now. Private IPs and zones are untouched so the tables stay legible.

Get started

Clone, point it at your router, read.

  1. Prerequisites. Workstation: Python 3.9+ and OpenSSH. Router: OpenWrt with fw4, dropbear key auth for root, AdGuard Home with its query log on disk. Device names come from uci export dhcp, so reservations pay off twice.
  2. Clone.
    git clone https://github.com/one7two99/openwrt-audit-kit.git
    cd openwrt-audit-kit
  3. First mirror. The default host is root@192.168.30.1; pass your own with --host.
    scripts/fwview.py --host root@192.168.1.1 --out fwview.html
    scripts/agview.py --host root@192.168.1.1 --out agview.html --no-doc
    xdg-open fwview.html
  4. Read the headers. Every script starts with a long comment: purpose, usage, options, exit codes, and what exactly it reads on the device. That comment is the documentation; there is no separate manual to drift.
Your output is sensitive. Rendered pages and tables contain the real IPs, MACs and device names of your network. The repository's .gitignore excludes all generated files; keep it that way before you publish anything.