Files
OpenVPN-Monitoring-Simple/DOCS/Deployment/System_Services/Web_UI.md
T
ayurishchevandClaude Sonnet 5.5 ad6995bb63 Docs restructure, code review, gatherer reliability, JWT key fail-closed
Documentation
- Three levels: DOCS/General (overview, configuration), DOCS/Deployment
  (choose a method, first steps), details per method in Containers/ and
  System_Services/; new root README and DOCS/README map.
- Remove superseded pages (Deployment.md, Deployment_Docker/Native.md, Index.md);
  split the two scenario guides by section.
- Isolate the Timeweb/Hysteria2 records in DEPLOYMENTS/timeweb-hysteria2/
  (not linked from DOCS, listed in .graphifyignore).
- Add DOCS/code_review/ with a time-stamped analysis of the code base.

Gatherer (BUG-02, BUG-03)
- Session key (CN, address, connected_since_ts), baseline from the
  active_sessions snapshot, grace period for sessions missing from the status.
- Status file integrity (TITLE/TIME/END) and freshness; a torn read skips the tick.
- Cache applied after commit; main loop survives exceptions, backs off, and
  stops cleanly on SIGTERM/SIGINT; new client rows start with the first
  frame's totals; five tests.

JWT signing key (SEC-01)
- No built-in default: Core and Profiler refuse to start with a missing,
  placeholder or short (< 32) key; shipped config.ini has an empty value.
- Same rule in install.sh, update.sh (issues a new key when missing or weak),
  docker lib/entrypoint; five tests, conftest.py for the test key.

Each change has a plan and a summary under DOCS/Changes/.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-05 20:30:45 +03:00

5.4 KiB

System services: the web UI

How the UI reaches the host (no Node needed by default), the build script and the maintainer routine. Install: System services.

Overview

The UI is built from APP_UI (Vue/Vite). The repository carries a ready build in deploy/ui-dist/ together with SOURCE_HASH, a SHA-256 over the UI sources it was built from (APP_UI/src, public, index.html, package.json, package-lock.json, vite.config.js, jsconfig.json). install.sh and update.sh find the UI themselves. The directory is outside APP_UI, so the container builds are not affected.

Three ways to get the UI onto a host

Way Option When
Committed build none (automatic) the normal case: git clone, install.sh, done; no Node, no Docker
Build on the host --build-ui the committed build is stale or missing; builds from APP_UI now with Docker (when its daemon works) or the host's Node 20.19+
Build elsewhere --ui-dist FILE|DIR a tarball from build-ui.sh or a directory with index.html, for example from a CI job or another machine

Order used by install.sh and update.sh: 1. --ui-dist (explicit, always installed), 2. --build-ui (always builds fresh from the sources), 3. the committed deploy/ui-dist of the checkout (automatic), 4. nothing found: install.sh stops (it lists the ways out) unless --no-ui is given (a placeholder page on purpose); update.sh keeps the installed UI. install.sh also still accepts deploy/native/ui-dist.tar.gz as a last resort below the committed directory. --ui-dist and --build-ui exclude each other.

The installed web root records the hash it came from in /var/www/ovpmon/.ui-source-hash (unknown for archives that were not made by build-ui.sh). update.sh compares it with the SOURCE_HASH of the repository build: equal, the UI is not replaced (and it says so); different or missing (for example a host installed with --no-ui), the new UI is staged in phase 3 and swapped in phase 6, with the rest of the update, so it is part of the backup and the automatic rollback. The UI source is decided after git pull, so a pulled new build is used in the same run. The old UI is in the backup.

Staleness guard

When the hash of the current APP_UI sources differs from SOURCE_HASH, the committed build is older than the sources (someone changed the UI and did not refresh the build). install.sh and update.sh then print a loud warning with the two hashes and the remedy, and still use the committed build (it works, it only lacks the latest UI changes). A host that needs the current UI adds --build-ui. A build without a valid SOURCE_HASH counts as stale.

Maintainer routine

After every change in APP_UI (or its package*.json, vite.config.js), before committing:

deploy/native/build-ui.sh --publish      # rebuilds deploy/ui-dist/ and SOURCE_HASH from the current sources
deploy/native/check-ui.sh                # prints fresh | stale | missing; exit 0 | 1 | 2
git add APP_UI deploy/ui-dist

check-ui.sh also fits a release checklist or a CI step (it changes nothing). --publish replaces the content of deploy/ui-dist/ by a move (the old directory is only deleted after the new one is in place).

build-ui.sh

deploy/native/build-ui.sh                          # Docker if it works, otherwise local Node -> deploy/native/ui-dist.tar.gz
deploy/native/build-ui.sh --docker                 # node:20-alpine container (OVPMON_NODE_IMAGE or --image to change)
deploy/native/build-ui.sh --local                  # Node >= 20.19 and npm of this machine, no container
deploy/native/build-ui.sh --local --node-download  # temporary official Node 20, deleted after the build
deploy/native/build-ui.sh --publish                # refresh deploy/ui-dist/ in the repository
deploy/native/build-ui.sh -o /tmp/ui.tar.gz        # tarball for another host (also with --publish)
deploy/native/build-ui.sh --check                  # only check that the builder is usable

Without --docker/--local the script uses Docker when its daemon answers, otherwise the local Node. The tarball holds the content of dist/ and SOURCE_HASH. Nothing is written into the source tree: a container sees APP_UI read-only; --local copies it (without node_modules and dist) into a temporary directory and runs npm ci there (npm install without a lock file), so the repository gets no node_modules and no dist.

--local needs Node 20.19 or newer with npm. When it is missing or too old the script prints what to do and stops:

System What to do
Alpine apk add nodejs npm (check node --version afterwards)
Debian / Ubuntu the distribution's Node is usually too old (Debian 12 and Ubuntu 24.04 ship Node 18): add --node-download (needs apt-get install -y curl xz-utils), or install Node 20+ with npm from nodejs.org / NodeSource
anything else Node 20.19+ from nodejs.org, or build with --docker on a machine with Docker

--node-download fetches SHASUMS256.txt from https://nodejs.org/dist/latest-v20.x/, picks node-v20.*-linux-<x64|arm64>.tar.xz, verifies its SHA-256, unpacks it into a temporary directory (npm cache included), builds with it and deletes everything; nothing is installed on the host. glibc systems only: on Alpine (musl) it refuses and points to apk add nodejs npm. It needs curl, tar, xz and access to nodejs.org (OVPMON_NODE_MAJOR selects another major version).