fix: 修复驱动管理器登录认证问题
- 添加用户名验证(之前只验证密码) - check_auth 函数现在同时验证用户名和密码 - 默认用户名: admin,密码: admin(或环境变量设置的密码) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -26,7 +26,8 @@ UPLOAD_FOLDER = '/tmp/cups-drivers'
|
|||||||
MAX_CONTENT_LENGTH = 100 * 1024 * 1024 # 100MB
|
MAX_CONTENT_LENGTH = 100 * 1024 * 1024 # 100MB
|
||||||
ALLOWED_EXTENSIONS = {'deb', 'ppd', 'gz', 'tar', 'tgz', 'zip', 'rpm', 'sh', 'run'}
|
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')
|
ADMIN_PASSWORD = os.environ.get('DRIVER_MANAGER_PASSWORD', 'admin')
|
||||||
|
|
||||||
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
|
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)
|
os.makedirs(UPLOAD_FOLDER, exist_ok=True)
|
||||||
|
|
||||||
def check_auth(password):
|
def check_auth(username, password):
|
||||||
"""验证密码"""
|
"""验证用户名和密码"""
|
||||||
return password == ADMIN_PASSWORD
|
return username == ADMIN_USERNAME and password == ADMIN_PASSWORD
|
||||||
|
|
||||||
def authenticate():
|
def authenticate():
|
||||||
"""发送401响应"""
|
"""发送401响应"""
|
||||||
@@ -52,7 +53,7 @@ def requires_auth(f):
|
|||||||
@wraps(f)
|
@wraps(f)
|
||||||
def decorated(*args, **kwargs):
|
def decorated(*args, **kwargs):
|
||||||
auth = request.authorization
|
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 authenticate()
|
||||||
return f(*args, **kwargs)
|
return f(*args, **kwargs)
|
||||||
return decorated
|
return decorated
|
||||||
|
|||||||
Reference in New Issue
Block a user