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