forked from evilvodun/wifi_passwords
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
66 lines (47 loc) · 1.92 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
from fastapi import FastAPI, Depends, Request, HTTPException
from fastapi.templating import Jinja2Templates
from fastapi.staticfiles import StaticFiles
from starlette import status
from sqlmodel import SQLModel
import uvicorn
from configuration.database import engine
from models.wifi import Wifi
from repository import Repository
from schemas.wifi import WifiInput
app = FastAPI(
title="Steal saved wifi passwords with Flipper Zero on windows",
version="1.0.0"
)
# Add global API prefix
API_PREFIX: str = "/api/v1"
backend = FastAPI()
app.mount(API_PREFIX, backend, name="api")
app.mount("/static", StaticFiles(directory="static"), name="static")
templates = Jinja2Templates(directory="templates")
@app.get("/")
def static(request: Request, repository: Repository = Depends()):
return templates.TemplateResponse("index.html", {"request": request, "wifis": repository.list()})
@backend.post("/", status_code=status.HTTP_201_CREATED)
def create_wifis(wifi_input: WifiInput, repository: Repository = Depends()) -> object:
response = repository.create(Wifi.from_orm(wifi_input))
if not response:
raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST)
return {
"id": response.id
}
@backend.get("/", status_code=status.HTTP_200_OK)
def get_wifis(repository: Repository = Depends()):
return repository.list()
@backend.delete("/{wifi_id}", status_code=status.HTTP_204_NO_CONTENT)
def delete_wifis(wifi_id: int, repository: Repository = Depends()):
if not repository.delete_by_id(wifi_id):
raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST)
@backend.get("/danger", status_code=status.HTTP_204_NO_CONTENT)
def danger_delete(repository: Repository = Depends()):
return repository.delete_all()
@backend.on_event("startup")
def on_startup():
SQLModel.metadata.create_all(engine)
# Start Uvicorn Server
if __name__ == "__main__":
uvicorn.run("main:app", reload=True)