Skip to content

Dashboard and Admin API ​

A running process can be watched and changed through the built-in HTTP Admin API and the browser dashboard on top of it. Neither Node nor a separate web server is needed: the page is built into the binary.

Enabling ​

sh
ours run -c config.yaml --dashboard 127.0.0.1:9090

or in the configuration, the admin section:

yaml
admin:
  listen: 127.0.0.1:9090

The --dashboard flag, if given, takes precedence over admin.listen. Without users (admin.users) an address with a token appears on stderr:

Dashboard: http://127.0.0.1:9090/#token=4f2c…

Open it in a browser. The token is random and valid until the process restarts; the page removes it from the address bar and remembers it until the tab is closed. Without the token the page shows only a login form, where you can paste the token. If systemd sends stderr to its journal, ours prints the address without the token. Configure admin.users to sign in with a name and password. See Login.

  • The address is loopback only (127.0.0.1, [::1]): an external address is a startup error. The Admin API has no TLS, and both the token and the password travel in clear text. To reach it from another machine, forward the port over SSH: ssh -L 9090:127.0.0.1:9090 router, then open http://127.0.0.1:<local port>/ (localhost works too). A reverse proxy with a public hostname or a path prefix is not supported.
  • The Admin API works only together with run. Without --dashboard and admin.listen nothing is opened and no extra memory is spent on watching connections.

The dashboard is in Russian and English: the button next to the theme switch in the bottom left changes the language, and on the first visit the browser's language picks it.

Login ​

Two modes, chosen by admin.users:

admin.usersHow to log in
not set or emptyThe random token of this run: Authorization: Bearer <token> on every /api/*; the dashboard's static files are open
setHTTP Basic: Authorization: Basic base64(name:password) on every path, including /; the token is not accepted

With users, both / and /api/* without credentials answer 401 with WWW-Authenticate: Basic realm="ours", charset="UTF-8": the browser shows its own login window and from then on attaches the name and password to all of the page's requests by itself. The token field is not shown in this mode, and stderr prints the address without #token=.

yaml
admin:
  listen: 127.0.0.1:9090
  users:
    - username: admin
      password_hash: "$argon2id$v=19$m=19456,t=2,p=1$…"
    - username: prometheus
      password_hash: "$argon2id$v=19$m=19456,t=2,p=1$…"
      role: metrics

The password is not stored in the configuration, only its argon2id hash in PHC format. The hash is made by the command

sh
ours generate password-hash            # asks for the password twice, without echo
printf '%s\n' "$PASS" | ours generate password-hash   # from stdin, the first line

with the parameters OWASP recommends (m=19456,t=2,p=1). A password field, a hash of another algorithm (bcrypt, argon2i and the like), or argon2id weaker than m=19456 KiB or t=2 is a configuration error with its location.

Roles:

roleWhat is available
admin (default)The dashboard and the whole API
metricsOnly GET /api/v1/metrics; everything else is 403
  • Checking a hash is expensive (19 MiB of memory, tens of milliseconds of CPU), so it runs in a separate thread, no more than one at a time. A header that passed the check is remembered for 10 minutes (up to 64 entries) as an HMAC-SHA256 with a random key of the process; the password itself is not stored. A configuration reload (SIGHUP, --watch, applying from the dashboard) forgets everything remembered.
  • A wrong name or password is answered after a second. Refusals are logged at the debug level each, and at info the first one per minute, with the number of refusals since the previous such line.
  • A reload applies new admin.users immediately. A new admin.listen too: the process starts listening on the new address and closes the old one (if the new address is taken, there is an error in the log and the old one stays). Turning on an Admin API that was not there at startup, or turning off a running one, takes a restart; the log warns about it.

Build features ​

FeatureWhat it gives
apiThe Admin API (/api/v1/*)
dashboardThe dashboard page; enables api

Both are in the default build. A build with api but without dashboard writes Admin API (no dashboard in this build) and serves only the API. Without api the --dashboard flag is a startup error.

Dashboard sections ​

The dashboard polls for the process snapshot every two seconds while the tab is visible. Refresh fetches a snapshot immediately. Pause stops polling until you choose Resume. The theme button cycles through the system, light and dark themes.

If the process becomes unreachable, the dashboard marks the last snapshot as stale and disables configuration actions until it reconnects. In token mode, after a restart open the newly printed URL or enter the new token in the existing tab.

Overview ​

  • Active connections, separate counts of inbounds, outbounds, groups and rules, the default outbound.
  • Groups: the current choice separately for TCP and UDP, the latest probe delays. In rank: manual groups a member can be chosen by hand; groups with probes can run a probe now.
  • Subscriptions: the source, the time and error of the last download, the number of servers, what was skipped and why, traffic information from the provider; the Update all button.
  • Route check: the inbound, the destination, the network and the protocol found by sniffing, and a trace of the rules, as in ours explain. Sniffing, DNS and process lookup are not performed.

Config ​

  • A graph of the components and the links between them: inbounds, rules, groups, outbounds, DNS, detour chains. A large graph opens at no less than 60 %, from the inbounds, and is moved from there; zoom with buttons, the mouse wheel and two fingers, by hand from 5 to 180 %. A group with more than five members shows five: the currently chosen ones first (with pick above 1, all taken), and a "K more" line expands the others and collapses them back; the links of collapsed members go from that line. The browser remembers the zoom, position and expanded groups when you leave the page and restores them the next time it is opened; for another configuration, only the zoom. Expand gives the graph the whole window, Collapse or Esc returns it to the page.
  • Graph and YAML switch between the component graph and the YAML editor. An object of the graph opens as its own YAML fragment; editing the object changes only its text, the rest of the file and the comments stay. To reorder a rule in the draft, drag its number or open the rule and choose Up or Down. The editor has line numbers. The position in a check error ("line 29, column 7") is a link that puts the cursor at that place.
  • Show changes — a full build of the draft without applying it: which components would be rebuilt and how many connections would be closed, kept and moved (an estimate).
  • Apply — reloads the running process with this text. Connection policies are as for any reload (reload).
  • Restore previous — restores the previous active configuration after confirmation. The reload policy may close connections. An unapplied draft stays in the editor.
  • Save to file — writes the applied text to the configuration file. Available only if the process was started with a single -c (not stdin, not -C). The file is replaced atomically with mode 0600; if the file changed on disk since it was read, or it is a symbolic link, the write is refused. With --watch saving causes an ordinary reload.
  • Download — gets the text of the configuration.

Applying and saving are separate steps: a configuration applied from the dashboard does not reach the disk until it is saved.

Connections ​

Live connections and the latest finished ones: the inbound, the source and destination, the domain (from the request, fakeip or sniffing), the chosen chain of outbounds and groups, duration, volume and speed, a trace of the rules by which the route was chosen. A connection can be closed, and you can jump to the rule that matched in the editor.

Up to 4096 live and 256 finished connections are kept, up to 128 trace steps per connection; records beyond that are skipped with a mark.

Adblock ​

Appears when the configuration has an adblock section. Tabs:

  • Statistics — queries, blocked, allowlisted, average time and cache share over 24 hours, 7 or 30 days; a chart by hour (by day for 7 and 30 days), top names and clients, list hits, upstreams and whether their queries are filtered. Pause for 10 minutes, clearing the statistics.
  • Query log — time, client, name and type, result (answered, blocked, blocked by CNAME, allowlisted, rewritten, not checked), rule and list, upstream and time or "cache". "Block" and "Unblock" add ||name^ or @@||name^ to adblock.rules of the draft and, if the draft has not been changed, check and apply it right away; saving to the file is in the Config section.
  • Lists and rules — lists with their source, number of rules, update time, error or first warning with its line; a list switch (the list's enabled through the draft); update now; your own rules; checking a domain.
  • Clients — configured clients and the ones active during the period.
  • Settings — current values, pause and stop until restart (without changing the config), turning off and on in the config (adblock.enabled through the draft).

Events ​

The last 256 log records (not below log.level) with filters by level and text: connection and DNS errors, group switches, reloads.

Clients ​

WireGuard endpoints with their peers, and vless, hysteria2, tuic inbounds with their users. Add creates a peer (like ours client add), applies the change immediately and shows the wg/awg configuration with a QR code, sing-box and Xray; the client's private key is visible only this once. The peer is appended to the endpoint's config_file; without one, to the YAML, which is saved to the file if the active configuration had been saved (otherwise there is a warning: unsaved edits have to be saved by hand first). Links are the users' links with QR codes and a subscription.

Admin API ​

HTTP/1.1 on the same address, version 1 under /api/v1/. Every request to /api/* must carry an Authorization header: Bearer <token> or, with admin.users, Basic (see Login); the Host header must be the listener's address, localhost or a loopback address with another port (as an SSH tunnel ssh -L 8080:127.0.0.1:9090 passes it), but not a name that merely points to loopback; Origin, if present, must be http:// with the same Host. The page / opened by a foreign name answers with a hint of which address to open it at.

The OpenAPI 3.1 description is admin-api.json: resources, request bodies, response fields. Within a version, fields may be added to responses; a change that breaks clients gets /api/v2/. A request without a version (/api/state and the other pre-version-1 paths) is a 404 with a hint about /api/v1/. Until 1.0 the API is considered unstable: the version protects against unnoticed breakage, but does not promise that v1 will live long.

Reading is split into separate resources so that a client does not pull everything for the sake of one field (the dashboard polls the live resources every 2 seconds, and config only when revision changes):

RequestWhat it returns
GET /api/v1/statusapi (the API version, 1), version (the build, as ours version), revision, modules — modules with their own requests, can_rollback, can_save, saved
GET /api/v1/configrevision, source (YAML), config (what the modules decoded), objects (where each object is written), graph (components and dependencies)
GET /api/v1/connectionsconnections — live ones and the last 256 closed, total_live, omitted; a connection's state is a code (routing, dialing, active, closed, rejected, failed, error), reason the cause (the refusal method, what rejected it, the error text), started_ms the start (Unix, ms)
GET /api/v1/groupsGroups: members, the choice for TCP/UDP (tcp/udp the best, chosen all taken with pick above 1), probe delays
GET /api/v1/eventsThe last 256 log records: time_ms (Unix, ms), level, message
GET /api/v1/metricsCounters in the Prometheus text format (see below)
GET /api/v1/subscriptionsThe state of the subscriptions
GET /api/v1/clientsPeers of WireGuard endpoints and users of inbounds with links

Actions:

RequestWhat it does
POST /api/v1/subscriptions/updateDownload the subscriptions now; {"name": "work"} for one
POST /api/v1/preview{"revision", "source"} — check the text and show the changes: changes — change (added, removed, updated, dependency with the changed causes)
POST /api/v1/apply{"revision", "source"} — apply the text
POST /api/v1/rollback{"revision"} — restore the previous configuration
POST /api/v1/save{"revision"} — save the active configuration to the file
POST /api/v1/select{"revision", "group", "member"} — the choice in a manual group
POST /api/v1/probe{"revision", "group"} — probe the group now (the answer waits up to 8 seconds; other requests are served meanwhile)
POST /api/v1/close{"revision", "id"} — close a connection
POST /api/v1/route{"revision", "inbound", "destination", …} — route check: decision (outbound, default, reject, hijack-dns), outbound, the refusal method
POST /api/v1/edit, POST /api/v1/moveEdit and move an object in the text of the draft
POST /api/v1/draft{"revision", "source", "op": "set"|"append", "path": "adblock.rules", "value"} — set a value or append a list element at a path in the text of the draft (the value's YAML as is); missing keys are added
POST /api/v1/clients/add{"tag", "name"} — a new peer; the answer is formats (wg, awg, qr, sing-box, xray) with the private key, unavailable, warnings, revision
POST /api/v1/clients/remove{"tag", "client"} — remove a peer (by name or public key)
POST /api/v1/clients/export{"tag", "name"} — the peer's configurations without the private key; for an inbound {"tag", "name"?, "host"?} — links (link, QR) and subscription; an empty tag means all inbounds
GET /api/v1/<module>/…, POST /api/v1/<module>/…Requests of a module; the list of modules with an API is modules in /api/v1/status

Requests of the adblock module (without revision):

RequestWhat it does
GET /api/v1/adblock/statusState: whether it is on, pause, lists (rules, memory, update, error, warnings), clients, settings
GET /api/v1/adblock/stats?period=86400Statistics for a period in seconds
GET /api/v1/adblock/log?limit=&search=&result=&client=The log, newest first; result is blocked, allowed, rewritten, not_checked, …
POST /api/v1/adblock/pause{"minutes": 10}; 0 lifts the pause
POST /api/v1/adblock/stop{"stopped": true} — do not filter until the process restarts; false — filter again
POST /api/v1/adblock/updateDownload or reread the lists now; {"name": "oisd"} for one
POST /api/v1/adblock/check{"domain", "qtype"?, "client"?, "profile"?} — what the rules would decide
POST /api/v1/adblock/clear_statsClear the statistics and the log
  • Every POST except updating subscriptions, clients/* and module requests carries the string revision from /api/v1/status or /api/v1/config. If the configuration has changed since, the answer is 409: refresh the state and retry.
  • Applying, rolling back and external reloads increase the revision; a choice in a group and probes do not.
  • Errors are returned as {"error": "…"}: 404 is an unknown request, 409 a revision conflict, 400 everything else; 401 means the token or the name and password are missing or did not match; 403 is Host, Origin, or the metrics role outside metrics; 413 a body larger than 2 MiB; 503 the queue or the number of connections is exhausted.
  • Limits: headers up to 16 KiB, a body up to 2 MiB, up to 32 simultaneous connections (beyond that the answer is 503), a queue of 16 requests, 15 seconds per request. Requests are executed one at a time, in the same loop as SIGHUP and --watch: applying from the API and reloading from disk never interleave. A group probe waits for the network outside this loop.
sh
TOKEN=4f2c…
curl -s -H "Authorization: Bearer $TOKEN" http://127.0.0.1:9090/api/v1/status | jq .revision
curl -s -u admin http://127.0.0.1:9090/api/v1/status | jq .revision   # with admin.users

Metrics ​

GET /api/v1/metrics returns counters in the Prometheus text format. The process starts counting only with the Admin API enabled (--dashboard or admin.listen); without it the counters are not kept and cost nothing.

MetricLabelsWhat it counts
ours_connections—Connections open now
ours_inbound_connections_totalinboundConnections the inbound passed to routing
ours_inbound_refused_totalinboundConnections the inbound closed before routing: a failed handshake or authentication, scanners, visitors of the REALITY site
ours_outbound_connections_totaloutboundConnections sent to the outbound
ours_outbound_errors_totaloutboundConnections the outbound could not open
ours_user_connections_totaluserConnections of an authenticated user
ours_inbound_bytes_total, ours_outbound_bytes_total, ours_user_bytes_totalinbound/outbound/user, direction (up, down)Bytes of connections
ours_panics_total—Panics; each one is a bug in ours
  • Bytes are added when a connection closes: a long download shows in the counter after it ends, and live connections are in /api/v1/connections.
  • Each thread counts into its own table that nobody else writes; there is no shared lock on the connection path.
  • The token changes on every start, so for Prometheus create a user with the metrics role in admin.users: its name and password do not change, and it can read nothing but metrics. The address is loopback only: Prometheus on the same machine or through ssh -L.
yaml
# prometheus.yml
scrape_configs:
  - job_name: ours
    metrics_path: /api/v1/metrics
    static_configs:
      - targets: ["127.0.0.1:9090"]
    basic_auth:
      username: prometheus
      password_file: /etc/prometheus/ours-password
sh
curl -s -u prometheus http://127.0.0.1:9090/api/v1/metrics

GPL-3.0-or-later