INNER CODE UNIT · Python
terminal_ws
sky22333/ansible-ui · app.py:400
def terminal_ws(ws, host_id):
"""处理终端 WebSocket 连接"""
app.logger.info(f"处理WebSocket连接请求: host_id={host_id}")
token = request.args.get('token')
if not token:
app.logger.error("终端WebSocket错误: 未提供令牌")
ws.send(json.dumps({"error": "Authorization required"}))
return
try:
# token 格式: host_id:timestamp:signature
parts = token.split(':')
if len(parts) != 3 or parts[0] != str(host_id):
raise ValueError("Invalid token format")
token_timestamp = int(parts[1])
current_time = int(time.time())