From ba71942caaeac9f674c6bccfff441143aa71c903 Mon Sep 17 00:00:00 2001 From: lan Date: Thu, 9 Feb 2023 14:22:56 +0800 Subject: [PATCH] =?UTF-8?q?add:=E8=A7=A3=E5=86=B3select=E5=8F=AF=E8=B7=B3?= =?UTF-8?q?=E8=BF=87=E6=AC=A1=E6=95=B0=E9=99=90=E5=88=B6=EF=BC=8C=E6=96=B0?= =?UTF-8?q?=E5=A2=9Esha256=E5=8A=A0=E5=AF=86token=EF=BC=8C=E9=99=90?= =?UTF-8?q?=E5=88=B6=E5=8F=96=E4=BB=B6=E7=A0=81+ip+=E6=97=B6=E9=97=B4999s?= =?UTF-8?q?=E5=86=85=E5=8F=96=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/utils.py | 2 +- main.py | 4 ++-- settings.py | 1 + 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/core/utils.py b/core/utils.py index 6d3fda3..f7274a3 100644 --- a/core/utils.py +++ b/core/utils.py @@ -47,4 +47,4 @@ async def get_code(s: AsyncSession): async def get_token(ip, code): - return hashlib.sha256(f"{ip}{code}{int(time.time()) / 1000}000{settings.SECRET_KEY}".encode()).hexdigest() + return hashlib.sha256(f"{ip}{code}{int(time.time() / 1000)}000{settings.ADMIN_PASSWORD}".encode()).hexdigest() diff --git a/main.py b/main.py index ca03236..abcfae7 100644 --- a/main.py +++ b/main.py @@ -130,7 +130,7 @@ async def index(code: str, ip: str = Depends(error_ip_limit), s: AsyncSession = await s.execute(update(Codes).where(Codes.id == info.id).values(count=info.count - 1)) await s.commit() if info.type != 'text': - info.text = f'/select?code={info.code}&token={get_token(code, ip)}' + info.text = f'/select?code={info.code}&token={await get_token(code, ip)}' return { 'detail': f'取件成功,请立即下载,避免失效!', 'data': {'type': info.type, 'text': info.text, 'name': info.name, 'code': info.code} @@ -150,7 +150,7 @@ async def banner(request: Request): @app.get('/select') async def get_file(code: str, token: str, ip: str = Depends(error_ip_limit), s: AsyncSession = Depends(get_session)): # 验证token - if token != get_token(code, ip): + if token != await get_token(code, ip): error_ip_limit.add_ip(ip) raise HTTPException(status_code=403, detail="口令错误,或已过期,次数过多将被禁止访问") # 查出数据库记录 diff --git a/settings.py b/settings.py index 8be69a6..20fa5db 100644 --- a/settings.py +++ b/settings.py @@ -1,6 +1,7 @@ import uuid from starlette.config import Config +import configparser # 配置文件.env,存放为data/.env config = Config("data/.env")