All checks were successful
Build and Deploy MITM Webserver / build (push) Successful in 9s
64 lines
1.4 KiB
Python
64 lines
1.4 KiB
Python
from fastapi import FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
import os
|
|
import src.Models.netplan as netplan
|
|
import src.network_api as network_api
|
|
import src.routes_sniffer as sniffer_router
|
|
from asyncio import subprocess
|
|
from fastapi import HTTPException
|
|
|
|
|
|
app = FastAPI(
|
|
root_path="/api",
|
|
title="MITM Webserver Backend",
|
|
description="Backend API for MITM Webserver",
|
|
version="1.0.0",
|
|
docs_url="/docs",
|
|
redoc_url="/redoc",
|
|
openapi_url="/openapi.json",
|
|
)
|
|
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=["*"],
|
|
allow_credentials=True,
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
|
|
|
|
# ---------------------
|
|
# Startup / Shutdown
|
|
# ---------------------
|
|
|
|
|
|
@app.on_event("shutdown")
|
|
def shutdown_event():
|
|
network_api.shutdown_network_api()
|
|
|
|
|
|
# ---------------------
|
|
# Basic Endpoints
|
|
# ---------------------
|
|
|
|
@app.get("/hello")
|
|
def hello():
|
|
return {"message": "Hello from FastAPI 🎉"}
|
|
|
|
@app.get("/versions")
|
|
def versions():
|
|
message = os.popen("python --version").read().strip()
|
|
return {"message": message}
|
|
|
|
@app.get("/nft/ruleset")
|
|
def nft_ruleset():
|
|
message = os.popen("sudo nft --json list ruleset").read().strip()
|
|
return {"message": message}
|
|
|
|
|
|
# ---------------------
|
|
# Routers
|
|
# ---------------------
|
|
|
|
app.include_router(network_api.router, prefix="/network", tags=["network"])
|
|
app.include_router(sniffer_router.router, prefix="/sniff") |