From 20f3c279100dfec9f37ef7ea9b695800ed90c0bd Mon Sep 17 00:00:00 2001 From: This is XiaoDeng <1744793737@qq.com> Date: Tue, 30 Jan 2024 15:48:21 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9C=A8=E9=83=A8=E5=88=86=E8=BF=9E=E6=8E=A5?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=83=A8=E5=88=86=E6=83=85=E5=86=B5=E4=B8=8B?= =?UTF-8?q?=E6=9C=AA=E9=85=8D=E7=BD=AE=20Access=20Token=20=E7=9A=84?= =?UTF-8?q?=E8=AD=A6=E5=91=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ~~虽然可能并没有什么卵用~~ --- network/v11/http.py | 7 +++++++ network/v11/ws.py | 5 +++++ network/v12/http.py | 7 ++++++- network/v12/ws.py | 5 +++++ 4 files changed, 23 insertions(+), 1 deletion(-) diff --git a/network/v11/http.py b/network/v11/http.py index a98f8ad..8ee550d 100644 --- a/network/v11/http.py +++ b/network/v11/http.py @@ -1,6 +1,7 @@ from network.authentication import verify_access_token import utils.uvicorn_server as uvicorn_server import fastapi +from utils.logger import get_logger import call_action BASE_CONFIG = { @@ -8,6 +9,7 @@ "port": 5700, "access_token": None } +logger = get_logger() class HttpServer: @@ -15,6 +17,11 @@ def __init__(self, config: dict) -> None: self.config = BASE_CONFIG | config self.app = fastapi.FastAPI() self.app.add_route("/{action}", self.handle_request, ["GET", "POST"]) + self.check_access_token() + + def check_access_token(self) -> None: + if self.config["host"] == "0.0.0.0" or self.config["access_token"]: + logger.warning(f'[{self.config["host"]}:{self.config["port"]}] 未配置 Access Token !') async def start_server(self) -> None: await uvicorn_server.run(self.app, host=self.config["host"], port=self.config["port"]) diff --git a/network/v11/ws.py b/network/v11/ws.py index 0ab2d4a..1b8a11d 100644 --- a/network/v11/ws.py +++ b/network/v11/ws.py @@ -22,6 +22,11 @@ def __init__(self, config: dict) -> None: self.app.add_websocket_route("/", self.handle_root_route) self.app.add_websocket_route("/event", self.handle_event_route) self.app.add_websocket_route("/api", self.handle_api_route) + self.check_access_token() + + def check_access_token(self) -> None: + if self.config["host"] == "0.0.0.0" or self.config["access_token"]: + logger.warning(f'[{self.config["host"]}:{self.config["port"]}] 未配置 Access Token !') async def start(self) -> None: await uvicorn_server.run( diff --git a/network/v12/http.py b/network/v12/http.py index f92b3d8..0e8bed4 100644 --- a/network/v12/http.py +++ b/network/v12/http.py @@ -30,10 +30,15 @@ def __init__(self, config: dict) -> None: self.event_list = [] if self.config["event_enabled"] and self.config["event_buffer_size"] <= 0: - logger.warning("警告: 事件缓冲区大小配置不正确,可能导致内存泄露!") + logger.warning(f"[{self.config['host']}:{self.config['port']}] 事件缓冲区大小配置不正确,可能导致内存泄露!") self.app = fastapi.FastAPI() self.app.add_route("/", self.handle_http_connection, ["post"]) + self.check_access_token() + + def check_access_token(self) -> None: + if self.config["host"] == "0.0.0.0" or self.config["access_token"]: + logger.warning(f'[HTTP {self.config["host"]}:{self.config["port"]}] 未配置 Access Token !') async def start_server(self): await uvicorn_server.run(self.app, self.config["port"], self.config["host"]) diff --git a/network/v12/ws.py b/network/v12/ws.py index da011ef..6afb133 100644 --- a/network/v12/ws.py +++ b/network/v12/ws.py @@ -28,6 +28,11 @@ def __init__(self, config: dict) -> None: self.clients: list[fastapi.WebSocket] = [] self.app = fastapi.FastAPI() self.app.add_websocket_route("/", self.handle_ws_connect) + self.check_access_token() + + def check_access_token(self) -> None: + if self.config["host"] == "0.0.0.0" or self.config["access_token"]: + logger.warning(f'[{self.config["host"]}:{self.config["port"]}] 未配置 Access Token !') async def start_server(self) -> None: await uvicorn_server.run(self.app, self.config["port"], self.config["host"])