Initial commit
This commit is contained in:
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
.venv
|
||||
__pycache__
|
||||
10
Dockerfile
Normal file
10
Dockerfile
Normal file
@ -0,0 +1,10 @@
|
||||
FROM python:3.11-alpine
|
||||
|
||||
WORKDIR /app
|
||||
COPY requirements.txt .
|
||||
RUN python -m pip install --no-cache-dir -r requirements.txt
|
||||
|
||||
COPY index.html .
|
||||
COPY main.py .
|
||||
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]
|
||||
|
||||
20
index.html
Normal file
20
index.html
Normal file
@ -0,0 +1,20 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<title>小司的个人网站</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>小司的个人网站</h1>
|
||||
<p>大家好!欢迎来到我的个人网站!</p>
|
||||
<form action="/login" method="POST">
|
||||
<label for="username">用户名:</label>
|
||||
<input type="text" name="username" value="">
|
||||
<label for="password">密码:</label>
|
||||
<input type="password" name="password" value="" placeholder="******">
|
||||
<input type="submit" value="登录">
|
||||
</form>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
39
main.py
Normal file
39
main.py
Normal file
@ -0,0 +1,39 @@
|
||||
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,
|
||||
)
|
||||
|
||||
3
requirements.txt
Normal file
3
requirements.txt
Normal file
@ -0,0 +1,3 @@
|
||||
fastapi
|
||||
uvicorn
|
||||
python-multipart
|
||||
Reference in New Issue
Block a user