Skip to content

Commit

Permalink
Update main.py
Browse files Browse the repository at this point in the history
  • Loading branch information
SayesCode authored Nov 6, 2024
1 parent 8ca84ac commit f232a8b
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/onyconnect/main.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,35 @@
from fastapi import FastAPI, Request, Form
from fastapi.responses import HTMLResponse, RedirectResponse
from fastapi.templating import Jinja2Templates
from fastapi.staticfiles import StaticFiles
import os
from tor_config import generate_onion_service
import uvicorn

app = FastAPI()
templates = Jinja2Templates(directory="src/onyconnect/templates")

# Definindo a pasta de templates
templates = Jinja2Templates(directory="templates")

# Montando a pasta 'static' para servir arquivos estáticos
app.mount("/static", StaticFiles(directory="static"), name="static")

@app.get("/", response_class=HTMLResponse)
async def index(request: Request):
return templates.TemplateResponse("index.html", {"request": request})

@app.post("/generate")
async def generate_service(request: Request, port: str = Form(...), directory: str = Form(...)):
# Gerando o serviço Onion usando a função definida em tor_config
hostname = generate_onion_service(port, directory)

# Definindo a mensagem com base no resultado da geração do serviço Onion
if hostname:
message = f"Serviço .onion criado com sucesso: {hostname}"
else:
message = "Falha ao criar o serviço .onion. Verifique as configurações."

# Retornando a resposta com a mensagem para a página
return templates.TemplateResponse("index.html", {"request": request, "message": message})

# Bloco para rodar o servidor Uvicorn diretamente
Expand Down

0 comments on commit f232a8b

Please sign in to comment.