Files

45 lines
1.3 KiB
Python
Raw Permalink Normal View History

2026-01-28 22:37:47 +03:00
from fastapi import APIRouter, HTTPException
from pydantic import BaseModel
from services import process
from utils.auth import verify_token
from typing import Optional
from fastapi import Depends
router = APIRouter(dependencies=[Depends(verify_token)])
class ProcessActionResponse(BaseModel):
status: str
message: str
stdout: Optional[str] = None
stderr: Optional[str] = None
class ProcessStats(BaseModel):
status: str
pid: Optional[int] = None
cpu_percent: float
memory_mb: float
uptime: Optional[str] = None
@router.post("/server/process/{action}", response_model=ProcessActionResponse)
def manage_process(action: str):
"""
Control the OpenVPN server process.
Action: start, stop, restart
"""
if action not in ["start", "stop", "restart"]:
raise HTTPException(status_code=400, detail="Invalid action. Use start, stop, or restart")
result = process.control_service(action)
if result["status"] == "error":
raise HTTPException(status_code=500, detail=result["message"])
return result
@router.get("/server/process/stats", response_model=ProcessStats)
def get_process_stats():
"""
Get current telemetry for the OpenVPN process.
"""
return process.get_process_stats()