26 lines
1.1 KiB
Python
26 lines
1.1 KiB
Python
|
|
from fastapi import APIRouter, Depends, HTTPException
|
||
|
|
from sqlalchemy.orm import Session
|
||
|
|
from database import get_db
|
||
|
|
from utils.auth import verify_token
|
||
|
|
from services import generator
|
||
|
|
|
||
|
|
router = APIRouter(dependencies=[Depends(verify_token)])
|
||
|
|
|
||
|
|
@router.post("/server/configure")
|
||
|
|
def configure_server(db: Session = Depends(get_db)):
|
||
|
|
try:
|
||
|
|
# Generate to a temporary location or standard location
|
||
|
|
# As per plan, we behave like srvconf
|
||
|
|
output_path = "/etc/openvpn/server.conf"
|
||
|
|
# Since running locally for dev, maybe output to staging
|
||
|
|
import os
|
||
|
|
if not os.path.exists("/etc/openvpn"):
|
||
|
|
# For local dev safety, don't try to write to /etc/openvpn if not root or not existing
|
||
|
|
output_path = "staging/server.conf"
|
||
|
|
os.makedirs("staging", exist_ok=True)
|
||
|
|
|
||
|
|
content = generator.generate_server_config(db, output_path=output_path)
|
||
|
|
return {"message": "Server configuration generated", "path": output_path}
|
||
|
|
except Exception as e:
|
||
|
|
raise HTTPException(status_code=500, detail=str(e))
|