Add REST API alongside existing HTML WebAdmin interface
Adds a JSON/REST interface under /api/v1/ that shares the same HTTP
listener, authentication (Basic auth against users.txt), and process as
the existing HTML admin. No new ports or config required.
New class RestAdmin handles dispatch and JSON encoding using cajun.
WebAdmin::buildPage detects the /api/v1/ prefix after authentication
and delegates to RestAdmin.
Endpoints:
GET /api/v1/registrations
GET /api/v1/publications
GET /api/v1/domains
POST /api/v1/domains?uri=...&tlsPort=...
DELETE /api/v1/domains/{uri}
GET /api/v1/users
POST /api/v1/users?user=...&domain=...&password=...&name=...&email=...
GET /api/v1/users/{user@domain}
PUT /api/v1/users/{user@domain}?password=...&name=...&email=...
DELETE /api/v1/users/{user@domain}
GET /api/v1/acls
POST /api/v1/acls?hostOrIp=...&port=...&transport=...
DELETE /api/v1/acls/{key}
GET /api/v1/routes
POST /api/v1/routes?uri=...&destination=...&method=...&event=...&order=...
PUT /api/v1/routes/{key}?...
DELETE /api/v1/routes/{key}
GET /api/v1/filters
GET /api/v1/settings
GET /api/v1/stats
GET /api/v1/congestion
GET /api/v1/loglevel
PUT /api/v1/loglevel?level=...
GET /api/v1/dnscache
DELETE /api/v1/dnscache
POST /api/v1/dnscache/reload
POST /api/v1/restart
POST /api/v1/certs/reload
Write operations use query parameters rather than request bodies to
avoid parsing inbound HTTP bodies. Filter add/edit/delete are not
exposed via REST due to the field count and regex escaping concerns;
use the HTML interface for those. Registration delete removes all
contacts for an AOR. PUT on users and routes has partial-update
semantics (omitted fields are left unchanged).
Response envelopes:
{"data": ...} on success
{"status": "ok"} on action success with no payload
{"error": {"code": N, "message":...}} on error
Required plumbing changes:
- HttpBase::buildPage virtual now takes the HTTP method as its first
parameter; HttpConnection::tryParse captures it from the request
line and passes it through.
- HttpConnection::setPage handles status codes 400, 405, 501, and 503
(previously 200/301/401/404/500 only), and preserves the caller's
body for application/json responses rather than substituting a
canned HTML page on 401/404.
- WebAdmin owns a std::unique_ptr<RestAdmin>, declares RestAdmin as a
friend so it can reach shared state (store, registration/
publication DBs, proxy, DNS cache machinery), and exposes
setApiResponse() as a JSON-aware wrapper around setPage().
Authentication is identical to the HTML admin: HTTP Basic against the
existing users.txt file. The DisableHttpAuth config flag applies to
REST calls as well.