netadm/web/routers/check_ports.py

35 lines
852 B
Python
Raw Normal View History

2024-10-01 14:38:06 +00:00
from fastapi import APIRouter
from starlette.requests import Request
from starlette.responses import HTMLResponse
from starlette.templating import Jinja2Templates
from config import TEMPLATES_DIR
2024-10-01 15:31:38 +00:00
from scripts import check_available_ports
2024-10-01 14:38:06 +00:00
router = APIRouter()
templates = Jinja2Templates(directory=TEMPLATES_DIR)
@router.get("", response_class=HTMLResponse)
async def check_ports(request: Request):
return templates.TemplateResponse(
"body-check_ports.html",
{
"request": request,
},
)
@router.get("/start")
async def start_check_ports(request: Request, inputText: str):
2024-10-01 15:31:38 +00:00
results = check_available_ports(inputText, result_type="text")
2024-10-01 14:38:06 +00:00
return templates.TemplateResponse(
"body-check_ports.html",
{
"request": request,
"results": results,
},
)