```
feat(auth): 添加用户权限获取接口并完善JWT令牌角色信息 - 在JWT令牌中添加用户角色信息 - 新增get_my_permissions接口用于获取当前用户权限码列表 - 重构认证回调逻辑,增加错误日志记录 - 更新用户信息获取接口使用Authorization头验证 ```
This commit is contained in:
@@ -165,14 +165,23 @@ class SSHService:
|
||||
mac_match = re.search(r'([0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4})', line, re.IGNORECASE)
|
||||
if mac_match:
|
||||
mac = mac_match.group(1).lower()
|
||||
# 提取状态字段
|
||||
if 'Up' in line:
|
||||
if re.search(r'\b(up|online)\b', line.lower()):
|
||||
devices[mac] = 'online'
|
||||
elif 'Offline' in line:
|
||||
elif re.search(r'\b(offline|down)\b', line.lower()):
|
||||
devices[mac] = 'offline'
|
||||
|
||||
return devices
|
||||
|
||||
def _clean_output(self, output: str) -> str:
|
||||
"""清理终端控制字符和 More 分页标记,避免污染解析"""
|
||||
# 移除 ANSI 转义序列
|
||||
output = re.sub(r'\x1b\[[0-9;]*[a-zA-Z]', '', output)
|
||||
# 移除 ---- More ---- 行(含前后控制字符)
|
||||
output = re.sub(r'---- More ----[^\n]*', '', output)
|
||||
# 将独立的 \r(不跟 \n)替换为空,避免覆盖行内容
|
||||
output = re.sub(r'\r(?!\n)', '', output)
|
||||
return output
|
||||
|
||||
def parse_onu_info(self, output: str) -> Tuple[Dict[str, ONUInfo], Dict[str, List[ONUInfo]]]:
|
||||
"""增强解析:提取完整 ONU 信息
|
||||
返回: (unique_devices, duplicate_devices)
|
||||
@@ -180,6 +189,7 @@ class SSHService:
|
||||
- duplicate_devices: MAC -> [ONUInfo, ...] (出现在多个端口的 MAC)
|
||||
"""
|
||||
all_records: Dict[str, List[ONUInfo]] = {}
|
||||
output = self._clean_output(output)
|
||||
lines = output.split('\n')
|
||||
|
||||
current_slot = None
|
||||
@@ -227,9 +237,11 @@ class SSHService:
|
||||
|
||||
mac = mac_match.group(1).lower()
|
||||
|
||||
# 提取状态
|
||||
# 提取状态:H3C OLT 不同固件版本可能输出 Up/UP/up/Online/online
|
||||
status = 'offline'
|
||||
if 'Up' in line:
|
||||
line_lower = line.lower()
|
||||
# 检查行末状态字段(避免误匹配 "Onu" 中的字母)
|
||||
if re.search(r'\b(up|online)\b', line_lower):
|
||||
status = 'online'
|
||||
|
||||
# 提取端口信息: Onu1/0/2:1 -> slot=2, port=1, port_id="1/0/2:1"
|
||||
|
||||
Reference in New Issue
Block a user