Node API Reference
Tài liệu chi tiết về các REST API endpoints của OV-Node
Authentication
Tất cả các API endpoints đều yêu cầu xác thực bằng API Key trong header key
Base URL
URL cơ sở cho tất cả API requests
http://YOUR_NODE_IP:9090Thay thế YOUR_NODE_IP bằng IP hoặc domain của Node.
Get Status
Lấy trạng thái hiện tại của Node và cập nhật cấu hình OpenVPN
Endpoint
POST /sync/get-statusHeaders
{
"key": "YOUR_API_KEY",
"Content-Type": "application/json"
}Request Body
{
"set_new_setting": false,
"protocol": "udp", // optional: "udp" or "tcp"
"port": 1194, // optional: OpenVPN port
"dns": "1.1.1.1" // optional: DNS server
}• set_new_setting: true để cập nhật cấu hình OpenVPN, false để chỉ lấy status
Response
{
"success": true,
"msg": "Node status retrieved successfully",
"data": {
"status": "running",
"cpu_usage": 15.2,
"memory_usage": 45.8
}
}cURL Example
curl -X POST http://YOUR_NODE_IP:9090/sync/get-status \
-H "key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"set_new_setting": false
}'Create User
Tạo người dùng OpenVPN mới trên Node
Endpoint
POST /sync/create-userHeaders
{
"key": "YOUR_API_KEY",
"Content-Type": "application/json"
}Request Body
{
"name": "username"
}Username chỉ được chứa chữ cái, số và dấu gạch dưới
Response (Success)
{
"success": true,
"msg": "User created successfully",
"data": {
"client_name": "username"
}
}Response (Error)
{
"success": false,
"msg": "Failed to create user",
"data": null
}cURL Example
curl -X POST http://YOUR_NODE_IP:9090/sync/create-user \
-H "key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"name": "testuser"
}'Delete User
Xóa người dùng OpenVPN khỏi Node
Endpoint
POST /sync/delete-userHeaders
{
"key": "YOUR_API_KEY",
"Content-Type": "application/json"
}Request Body
{
"name": "username"
}Response
{
"success": true,
"msg": "User deleted successfully",
"data": {
"client_name": "username"
}
}cURL Example
curl -X POST http://YOUR_NODE_IP:9090/sync/delete-user \
-H "key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"name": "testuser"
}'Download OVPN File
Tải file cấu hình .ovpn của người dùng
Endpoint
GET /sync/download/ovpn/{client_name}Headers
{
"key": "YOUR_API_KEY"
}Path Parameters
client_name: Tên người dùng cần tải file cấu hìnhResponse
Trả về file .ovpn với header:
Content-Type: application/x-openvpn-profile
Content-Disposition: attachment; filename="username.ovpn"cURL Example
curl -X GET http://YOUR_NODE_IP:9090/sync/download/ovpn/testuser \
-H "key: YOUR_API_KEY" \
--output testuser.ovpnOpenVPN Health Check
Kiểm tra tình trạng hoạt động của OpenVPN service
Endpoint
GET /sync/openvpn/healthHeaders
{
"key": "YOUR_API_KEY"
}Response (Healthy)
{
"success": true,
"msg": "OpenVPN health check completed",
"data": {
"healthy": true,
"service_running": true,
"port_listening": true,
"config_valid": true,
"issues": []
}
}Response (Unhealthy)
{
"success": false,
"msg": "OpenVPN health check completed",
"data": {
"healthy": false,
"service_running": false,
"port_listening": false,
"config_valid": true,
"issues": [
"OpenVPN service is not running",
"Port 1194 is not listening"
]
}
}cURL Example
curl -X GET http://YOUR_NODE_IP:9090/sync/openvpn/health \
-H "key: YOUR_API_KEY"Auto-Fix OpenVPN
Tự động phát hiện và sửa các vấn đề của OpenVPN service
Endpoint
POST /sync/openvpn/fixHeaders
{
"key": "YOUR_API_KEY"
}Response (Success)
{
"success": true,
"msg": "OpenVPN auto-fix completed",
"data": {
"success": true,
"actions_taken": [
"Fixed missing IP in config",
"Restarted OpenVPN service"
],
"healthy": true
}
}cURL Example
curl -X POST http://YOUR_NODE_IP:9090/sync/openvpn/fix \
-H "key: YOUR_API_KEY"Tự động sửa lỗi
Endpoint này sẽ tự động thực hiện các hành động sau nếu cần:
- • Sửa cấu hình OpenVPN thiếu IP
- • Enable service nếu chưa được enable
- • Khởi động lại service
- • Xác minh service đang chạy
HTTP Status Codes
Các mã trạng thái HTTP thường gặp
OK
Request thành công
Unauthorized
API key không hợp lệ hoặc thiếu
Unprocessable Entity
Request body không hợp lệ
Internal Server Error
Lỗi server, kiểm tra logs
Best Practices
Khuyến nghị khi sử dụng API
- Luôn kiểm tra
successfield trong response - Xử lý lỗi 401 bằng cách kiểm tra lại API key
- Sử dụng HTTPS trong production với reverse proxy (nginx)
- Giữ API key bí mật và không commit vào git
- Sử dụng health check endpoint để monitoring
