- Profiler: server_files_missing/require_* helpers; 409 for /server/configure, start/restart and POST /profiles when the PKI is not initialized or server files (honouring fqdn_server) are missing; stop stays allowed; DELETE /system/pki returns 409 while OpenVPN runs; GET /system/init/status adds pki_ready, server_ready, missing. - UI: shared usePkiStatus; VPN menu item locked until the PKI is ready, route guard for /config/vpn, Start/Restart and New Client disabled with hints, lock notice on the VPN page. - Test: one pytest (test_pki_guard.py). - Docs: plan and summary in DOCS/Changes, API reference, README, Index. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
4.4 KiB
OpenVPN Profiler API Reference
This module (APP_PROFILER) is built with FastAPI and provides management capabilities.
Base URL: http://<your-server>:8000/api
Authentication
All endpoints (except initial setup) require a Bearer Token.
Header: Authorization: Bearer <JWT_TOKEN>
Note: The token is shared with the Core Monitoring API.
1. User Profiles
Manage OpenVPN Client profiles (.ovpn configs and certificates).
GET /profiles
List all user profiles.
- Response: Array of profile objects (id, username, status, expiration_date, note, etc.).
POST /profiles
Create a new user profile.
- Body:
{"username": "jdoe"} - Action: Generates keys, requests certificate, builds
.ovpnfile. - Response
409: PKI initialization is running, or the PKI is not initialized ("PKI is not initialized. Initialize PKI first.").
DELETE /profiles/{id}
Revoke a user profile.
- Action: Revokes certificate in CRL and marks profile as revoked in DB.
PUT /profiles/{id}/note
Set or clear the free-text note of a profile.
- Body:
{"note": "text"}(max 1000 characters; empty ornullclears the note) - Response: Updated profile object (including
note).404if the profile does not exist.
GET /profiles/{id}/download
Download the .ovpn configuration file for a user.
- Response: File stream (application/x-openvpn-profile).
2. System Configuration
Manage global settings for the server and PKI.
GET /config
Get current configuration.
- Query Params:
section(optional: 'server' or 'pki') - Response:
{ "server": {...}, "pki": {...} }
PUT /config/server
Update OpenVPN Server settings (e.g., protocol, port, DNS).
- Body: JSON object matching
SystemSettingsschema.
PUT /config/pki
Update PKI settings (e.g., Key Size, Certificate Expiry).
- Body: JSON object matching
PKISettingschema.
POST /system/init
Start PKI initialization (init-pki, CA, server certificate, DH, TLS key, CRL) as a background job. Returns immediately.
- Response
202:{"state": "running"} - Response
409: a job is already running, or the PKI is already complete (ca.crt,dh.pem,ta.key,crl.pemand the server certificate). An incomplete PKI left by an interrupted run is removed and initialization starts again. - Note: Job state is kept in memory; the Profiler must run as a single process (one uvicorn worker). After a restart the state is
idle.
GET /system/init/status
Current state of the initialization job.
- Response:
{ "state": "idle|running|done|error", "step": "init-pki|ca|server-cert|dh|ta-key|crl|null", "initialized": true, "started_at": "2026-10-04T10:00:00Z", "finished_at": null, "error": null, "pki_ready": true, "server_ready": true, "missing": [] } initializedreflects the files on disk (complete PKI), independent ofstate.pki_ready: the PKI is initialized and no job is running (client certificates can be issued).server_ready:pki_readyand every fileserver.confreferences exists;missinglists the absent ones (relative to the PKI directory:ca.crt,issued/<fqdn_server>.crt,private/<fqdn_server>.key,dh.pem,ta.key, andcrl.pemonly whencrl_verifyis on). The check uses the currentfqdn_server, so renaming the server after init makes it not ready.errorcontains the EasyRSA message whenstateiserror.
DELETE /system/pki
DANGER: Completely wipes the PKI directory and resets the job state.
- Response
409: an initialization job is running, or OpenVPN is running ("Stop OpenVPN first").
3. Server Management
POST /server/configure
Generate the server.conf file based on current database settings.
- Response:
{"message": "Server configuration generated", "path": "/etc/openvpn/server.conf"} - Response
409: the PKI is not initialized or an init job is running ("PKI is not initialized. Initialize PKI first."), or server files are missing ("PKI server files are missing: ...").
POST /server/process/{action}
Control the OpenVPN system service.
- Path Param:
action(start, stop, restart) - Response: Status of the command execution.
- Response
409: forstartandrestartonly, same conditions asPOST /server/configure.stopis always allowed.
GET /server/process/stats
Get telemetry for the OpenVPN process.
- Response:
{ "status": "running", "cpu_percent": 1.2, "memory_mb": 45.0 }