esp32·adblocker·rebornhttp api reference

HTTPS control plane, REST endpoints, real-time telemetry, and JSON metrics schemas.

Overview & Security Pipeline

Every route below is served by the HTTPS server in main/web_ui.cpp on port 443 (using an ECDSA P-256 certificate generated at first boot; plain HTTP port 80 only issues 301 redirects to HTTPS). Every request passes through auth_wrap, which enforces:

  1. Setup gate: While no admin account exists, all GET requests redirect to /setup and all POST requests receive 403 Forbidden (except /setup itself).
  2. Session gate: Unauthenticated requests without a valid sid cookie receive a 303 redirect to /login on GET, or 401 Unauthorized on POST.
  3. Security headers: Cache-Control: no-store, X-Content-Type-Options: nosniff, X-Frame-Options: DENY, Referrer-Policy: same-origin, and strict Content-Security-Policy.
  4. CSRF validation: All mutating POST routes require both a matching Origin/Referer and the session's CSRF token passed either as ?csrf=<token> in the query string or via the X-CSRF: <token> request header.

CLI Scripting: Authenticate via curl, grab the CSRF token, and interact with the endpoints:

curl -k -c cookies.txt -X POST -d 'user=admin&pass=secret' https://esp32adblock.local/login
TOKEN=$(curl -k -b cookies.txt https://esp32adblock.local/ | grep -o "var CSRF='[^']*'" | cut -d"'" -f2)
curl -k -b cookies.txt -H "X-CSRF: $TOKEN" -X POST https://esp32adblock.local/reload

Endpoint Matrix

MethodPathDescription
GET/setupFirst-boot setup wizard: certificate fingerprint and admin credentials creation.
POST/setupCreate the initial admin account (opens session, redirects to /setup/network).
GET/setup/networkFirst-boot network setup: Ethernet DHCP/Static and Wi-Fi scan/join.
GET/loginAdmin authentication sign-in form.
POST/loginVerify credentials and issue sid session cookie. 5 failures trigger a 60s lockout.
POST/logoutDestroy active session and invalidate cookie.
GET/Main switchboard status dashboard. Polls /metrics every 10s without full page reload.
GET/metricsRaw JSON telemetry, counter states, and latency histograms.
GET/metrics/viewRendered HTML dashboard covering all metrics with auto-refresh.
POST/metrics/resetReset volatile counters and histograms to zero.
POST/reloadTrigger immediate asynchronous blocklist re-download and index rebuild.
POST/blocklist/stopAbort in-progress blocklist download; previous list remains active.
POST/pauseSet persistent global sinkhole pause (on=1 allows all traffic, on=0 resumes).
POST/pause/timedSuspend blocking for min minutes (1–1440) for scope=me, scope=host, or scope=all.
POST/pause/resumeEnd an active timed pause early (ip=<IPv4>, ip=all, or ip=every).
POST/checkTest domain against live engine: reports BLOCKED, ALLOWED, or REWRITE → ip.
POST/whitelist/addAdd a domain to the whitelist (takes effect on the next query).
POST/whitelist/removeRemove a domain from the whitelist.
POST/rewrite/setDefine local LAN static rewrite (e.g., printer → 192.168.1.50, up to 48 rules).
POST/rewrite/clearRemove a specific local LAN rewrite entry.
GET/logRecent query log buffer (512-entry ring buffer with UTC timestamps).
GET/censusPassive L2 wire census: tracks clients seen via ARP, DHCP, and DNS.
GET/topTop queried/blocked domains and clients with 60-bucket history bar chart.
POST/acl/addAdd client IPv4 address to Access Control List.
POST/acl/removeRemove client from ACL.
POST/acl/clearClear ACL (empty ACL allows all LAN clients).
POST/bypass/addAdd client IP to standing bypass list (resolves unfiltered, never cached).
POST/dot/setConfigure DNS-over-TLS upstream server address and SNI hostname.
POST/ota/updateUpload binary firmware image. Requires valid RSA-3072 signature.
POST/rebootTrigger hardware microcontroller reboot.

JSON Metrics (GET /metrics)

Returns a compact JSON telemetry document reflecting internal kernel state:

FieldTypeDescription
upstreamstringIP of currently selected upstream resolver.
uptime_sintSystem uptime in seconds since boot.
queries_totalintTotal DNS queries received on standard socket paths.
blockedintTotal queries sinkholed on socket path.
forwardedintTotal queries forwarded to upstream resolver.
l2_blockedintQueries blocked directly in L2 Ethernet frame hook (~1.8ms path).
l2_cachedintForward-cache hits served directly in L2 Ethernet frame hook.
cache_hit_ratefloatCache hit percentage (cache_hits / cache_probes * 100).
blocklist_countintTotal unique 40-bit domain hashes loaded in PSRAM.
sd_statusstringMicroSD snapshot status (loaded, saved, absent, etc.).
heap_freeintAvailable internal SRAM bytes.
psram_freeintAvailable external PSRAM bytes.
latency_usobjectMicrosecond percentiles (p50, p99, max) for blocked, cached, and forwarded.

Crash Flight Recorder (GET /lastwords)

Retrieves the RTC-persisted telemetry buffer recorded immediately before the previous system restart or crash:

{
  "available": true,
  "reset_reason": "sw",
  "queries_total": 48219,
  "heap_free_min": 182390,
  "queries": [
    { "domain": "ads.example.com", "qtype": 1, "blocked": true, "ts_s": 3812 }
  ]
}