netadm/routers/web/check_ports.py

35 lines
852 B
Python

from fastapi import APIRouter
from starlette.requests import Request
from starlette.responses import HTMLResponse
from starlette.templating import Jinja2Templates
from config import TEMPLATES_DIR
from scripts import check_available_ports
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):
results = check_available_ports(inputText, result_type="text")
return templates.TemplateResponse(
"body-check_ports.html",
{
"request": request,
"results": results,
},
)