Files
OpenVPN-Monitoring-Simple/DOCS/UI/Architecture.md
T

60 lines
5.5 KiB
Markdown
Raw Normal View History

2026-01-28 22:37:47 +03:00
# UI Architecture
The frontend is a Single Page Application (SPA) built with **Vue 3** and **Vite**. It is located in `APP_UI/`.
## Technology Stack
- **Framework**: Vue 3 (Composition API, Script Setup)
- **Build Tool**: Vite
- **Styling**: Bootstrap 5 + Custom CSS (`src/assets/main.css`)
- **Routing**: Vue Router
2026-10-07 13:14:40 +03:00
- **HTTP Client**: Axios (three instances in `useApi.js`: monitoring API, profiler API, `/api/auth`)
- **Checks**: Vitest (`npm test`), ESLint (`npm run lint`)
2026-01-28 22:37:47 +03:00
## Key Features
- **Responsive Design**: Mobile-friendly sidebar and layouts.
2026-10-07 13:14:40 +03:00
- **Theme Support**: Light/Dark mode toggling; the first visit follows the system setting (`prefers-color-scheme`), the choice is saved. The theme is applied before the app is mounted.
2026-01-28 22:37:47 +03:00
- **Real-Time Data**: Polls the Monitoring API (`APP_CORE`) for live statistics.
2026-10-07 13:14:40 +03:00
- **Authentication**: JWT-based auth flow with support for 2FA. The token is kept in `localStorage` (accepted risk, see [Security Architecture](../General/Security_Architecture.md)). A `401` from the monitoring or profiler API ends the session and opens `/login`; `401` from `/api/auth/*` (wrong current password or 2FA code) does not: it is shown as an error. Unknown addresses redirect to `/`.
- **Confirmations and notices**: destructive actions ask through `ConfirmModal` (each instance has a unique id); results are toasts (`useToast`). The native `confirm()` and SweetAlert2 are not used.
- **Charts**: `composables/useTrafficChart.js` (downsampling, labels, theme colors, Chart.js config) is shared by Analytics and the client history window.
2026-01-28 22:37:47 +03:00
## Pages
| Route | View | Purpose |
|---|---|---|
| `/` | `Analytics.vue` | traffic charts |
| `/clients`, `/certificates` | `Clients.vue`, `Certificates.vue` | connected clients (badge "×N" and a list of sessions when a user is connected from several devices), issued profiles |
| `/config/pki`, `/config/vpn` | `PKIConfig.vue`, `VPNConfig.vue` | PKI and server settings |
| `/server` | `ServerManagement.vue` | OpenVPN process control |
| `/backup` | `BackupRestore.vue` | **Backup and Restore** (MANAGEMENT section): destinations table with an add/edit modal (the form is built from the `fields` of `GET /backup/settings`: text, number, switch, password and multi-line secret fields; a field may carry a warning, for example plain FTP or a disabled certificate check; types with a pinned host key (SFTP) show it, and **Test** opens a confirmation with the fingerprint and a Trust button), backup panel (encryption status, **server name** field with the name actually used, destination checkboxes, progress per destination, history), restore panel (source, package list with the server name and the time in UTC and in the browser's local time, passphrase, red Restore button with a confirmation). It polls `GET /backup/status` every 2 s while a job runs. See [Backup and Restore](../Profiler_Management/Backup_Restore.md) |
| `/account` | `Account.vue` | password, username, 2FA |
2026-01-28 22:37:47 +03:00
## Configuration
Run-time configuration is loaded from `/public/config.json`. This allows the Vue app to be built once and deployed to any environment.
**File Structure (`config.json`):**
```json
{
"api_base_url": "/api/v1", // Proxy path to Core Monitoring API
2026-10-07 13:14:40 +03:00
"profiles_api_base_url": "/profiles-api", // Proxy path to Profiler API
2026-01-28 22:37:47 +03:00
"refresh_interval": 30000 // Poll interval in ms
}
```
## Integration
The UI is served by Nginx in production and proxies API requests to:
- `/api/v1/` -> **APP_CORE** (Flask, Port 5000)
- `/profiles-api/` -> **APP_PROFILER** (FastAPI, Port 8000)
See [Deployment Guide](../Deployment/README.md) for Nginx configuration details.
2026-10-07 13:14:40 +03:00
## Web server headers (container image)
`APP_UI/default.conf.template` (also used by the all-in-one image) sends `X-Content-Type-Options`, `X-Frame-Options: DENY`, `Referrer-Policy: no-referrer` and a CSP (`default-src 'self'`, inline styles allowed, `img-src`/`font-src` with `data:`, `connect-src 'self'` plus optional extra origins), compresses text files, serves `/assets/` with `immutable` caching and `index.html`/`config.json` with `no-cache`.
The CSP is written once (`set $csp "..."` in the `server` block) and sent with `add_header Content-Security-Policy $csp always` in the `server` block and in `location /assets/` (a location with its own `add_header` does not inherit the server ones).
**API on another origin.** If `config.json` points the UI to another origin, list it in `OVPMON_CSP_CONNECT_EXTRA` (inside the containers `OVP_CSP_CONNECT_EXTRA`): origins `https://host[:port]` or `http://host[:port]` separated by spaces, empty by default (same origin only). The value goes into a response header, so anything but origins is refused (`;`, quotes, commas, paths, a leading space): by the deploy scripts, by the all-in-one entrypoint and by `/docker-entrypoint.d/15-check-csp-connect-extra.sh` of the `app-ui` image (the container stops with a message). The API on the other origin must also allow this UI origin in `OVPMON_CORS_ORIGINS`.
The `app-ui` image is based on `nginxinc/nginx-unprivileged:alpine`: nginx runs as the user `nginx` (uid 101) and listens on `OVP_UI_PORT` (8080 in the image); docker-compose publishes it as the host port `OVPMON_HTTP_PORT` (default 80). In the all-in-one image the same template listens on 80 (the supervisor runs everything as root, OpenVPN needs it).
The system-service nginx (`deploy/native/nginx/ovpmon.conf.template`) sends the same CSP (headers are declared on the `server` level only); extra origins are set with `install.sh` / `update.sh --csp-connect-extra`, see [System services](../Deployment/System_Services/README.md).