40 lines
940 B
Python
40 lines
940 B
Python
from pathlib import Path
|
|
from typing import Annotated
|
|
|
|
import uvicorn
|
|
from fastapi import FastAPI, Form
|
|
from fastapi.responses import HTMLResponse, PlainTextResponse
|
|
|
|
|
|
app = FastAPI()
|
|
|
|
SECRET_PATH = Path("./secret/flag.txt")
|
|
HTML_PATH = Path("./index.html")
|
|
|
|
|
|
if not SECRET_PATH.exists():
|
|
flag = "konaph{example_flag}"
|
|
else:
|
|
flag = SECRET_PATH.read_text()
|
|
|
|
|
|
@app.get("/")
|
|
async def _() -> HTMLResponse:
|
|
return HTMLResponse(content=HTML_PATH.read_text())
|
|
|
|
|
|
@app.post("/login")
|
|
async def _(username: Annotated[str, Form()], password: Annotated[str, Form()]):
|
|
if username == "im_tsukasa" and password == "ker0r0_k4w4ii":
|
|
return PlainTextResponse(f"登录成功!答案为 {flag}。\n给此方 BOT 私发:提交答案 {flag}")
|
|
return PlainTextResponse("用户名或密码错误!", status_code=401)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
uvicorn.run(
|
|
app=app,
|
|
host="0.0.0.0",
|
|
port=8000,
|
|
)
|
|
|