From 40a32110b8664fde97379486c7b863131fded0ad Mon Sep 17 00:00:00 2001 From: yuyx <237899745@qq.com> Date: Mon, 1 Dec 2025 13:07:30 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E9=A9=B1=E5=8A=A8?= =?UTF-8?q?=E7=AE=A1=E7=90=86=E5=99=A8=E7=99=BB=E5=BD=95=E8=AE=A4=E8=AF=81?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 添加用户名验证(之前只验证密码) - check_auth 函数现在同时验证用户名和密码 - 默认用户名: admin,密码: admin(或环境变量设置的密码) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- cups-driver-manager/driver_manager.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/cups-driver-manager/driver_manager.py b/cups-driver-manager/driver_manager.py index 9b558ce..44d99c3 100644 --- a/cups-driver-manager/driver_manager.py +++ b/cups-driver-manager/driver_manager.py @@ -26,7 +26,8 @@ UPLOAD_FOLDER = '/tmp/cups-drivers' MAX_CONTENT_LENGTH = 100 * 1024 * 1024 # 100MB ALLOWED_EXTENSIONS = {'deb', 'ppd', 'gz', 'tar', 'tgz', 'zip', 'rpm', 'sh', 'run'} -# 管理员密码(首次运行时会提示设置,或使用环境变量) +# 管理员凭据(可通过环境变量设置) +ADMIN_USERNAME = os.environ.get('DRIVER_MANAGER_USERNAME', 'admin') ADMIN_PASSWORD = os.environ.get('DRIVER_MANAGER_PASSWORD', 'admin') app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER @@ -35,9 +36,9 @@ app.config['MAX_CONTENT_LENGTH'] = MAX_CONTENT_LENGTH # 确保上传目录存在 os.makedirs(UPLOAD_FOLDER, exist_ok=True) -def check_auth(password): - """验证密码""" - return password == ADMIN_PASSWORD +def check_auth(username, password): + """验证用户名和密码""" + return username == ADMIN_USERNAME and password == ADMIN_PASSWORD def authenticate(): """发送401响应""" @@ -52,7 +53,7 @@ def requires_auth(f): @wraps(f) def decorated(*args, **kwargs): auth = request.authorization - if not auth or not check_auth(auth.password): + if not auth or not check_auth(auth.username, auth.password): return authenticate() return f(*args, **kwargs) return decorated