2026-01-28 22:37:47 +03:00
# 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.
2026-10-04 20:56:36 +03:00
- **Response**: Array of profile objects (id, username, status, expiration_date, note, etc.).
2026-01-28 22:37:47 +03:00
### `POST /profiles`
Create a new user profile.
- **Body**: `{"username": "jdoe"}`
- **Action**: Generates keys, requests certificate, builds `.ovpn` file.
2026-10-04 20:56:36 +03:00
- **Response `409` **: PKI initialization is running (the PKI is not complete yet).
2026-01-28 22:37:47 +03:00
### `DELETE /profiles/{id}`
Revoke a user profile.
- **Action**: Revokes certificate in CRL and marks profile as revoked in DB.
2026-10-04 20:56:36 +03:00
### `PUT /profiles/{id}/note`
Set or clear the free-text note of a profile.
- **Body**: `{"note": "text"}` (max 1000 characters; empty or `null` clears the note)
- **Response**: Updated profile object (including `note` ). `404` if the profile does not exist.
2026-01-28 22:37:47 +03:00
### `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 `SystemSettings` schema.
### `PUT /config/pki`
Update PKI settings (e.g., Key Size, Certificate Expiry).
- **Body**: JSON object matching `PKISetting` schema.
### `POST /system/init`
2026-10-04 20:56:36 +03:00
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.pem` and 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 }`
- `initialized` reflects the files on disk (complete PKI), independent of `state` .
- `error` contains the EasyRSA message when `state` is `error` .
2026-01-28 22:37:47 +03:00
### `DELETE /system/pki`
2026-10-04 20:56:36 +03:00
**DANGER**: Completely wipes the PKI directory and resets the job state.
- **Response `409` **: an initialization job is running.
2026-01-28 22:37:47 +03:00
---
## 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"}`
### `POST /server/process/{action}`
Control the OpenVPN system service.
- **Path Param**: `action` (start, stop, restart)
- **Response**: Status of the command execution.
### `GET /server/process/stats`
Get telemetry for the OpenVPN process.
- **Response**: `{ "status": "running", "cpu_percent": 1.2, "memory_mb": 45.0 }`