From 4a1217fbfaaf0c06408fab472189f9ef0892dd09 Mon Sep 17 00:00:00 2001 From: nguyentrungthat <80239428+nguentrungthat@users.noreply.github.com> Date: Fri, 30 Jan 2026 13:37:13 +0700 Subject: [PATCH] Update regex sh ver --- BACKEND/app/ultils/templates/show_version.ts | 24 +++++++++++++------ .../components/Modal/ModalConfigRamFlash.tsx | 4 ++-- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/BACKEND/app/ultils/templates/show_version.ts b/BACKEND/app/ultils/templates/show_version.ts index a6e69ee..ce19b82 100644 --- a/BACKEND/app/ultils/templates/show_version.ts +++ b/BACKEND/app/ultils/templates/show_version.ts @@ -3,12 +3,14 @@ import XRegExp from 'xregexp' // Parser function const parseLog = (data: string) => { const patterns = [ + // 1. Software Image & Version XRegExp( '^.*Software.*\\((?\\S+)\\),\\s+Version\\s+(?.+?),\\s+RELEASE.*\\((?\\S+)\\)' ), XRegExp('Active-image:\\s+(?\\S+)'), XRegExp('Version:\\s+(?\\S+)'), XRegExp('^ROM:\\s+(?\\S+)'), + // 2. Uptime XRegExp('^(?\\S+)\\s+uptime\\s+is\\s+(?.+)'), XRegExp('Date:\\s+(?\\S+)'), XRegExp('uptime\\s+is.*\\s+(?\\d+)\\syear'), @@ -16,20 +18,26 @@ const parseLog = (data: string) => { XRegExp('uptime\\s+is.*\\s+(?\\d+)\\sday'), XRegExp('uptime\\s+is.*\\s+(?\\d+)\\shour'), XRegExp('uptime\\s+is.*\\s+(?\\d+)\\sminute'), + // 3. Reload Reason & Serial XRegExp('System\\s+image\\s+file\\s+is\\s+"(?:.*?):(?\\S+)"'), XRegExp('(?:Last reload reason:|System returned to ROM by)\\s+(?.+)'), XRegExp('[Pp]rocessor\\s+board\\s+ID\\s+(?\\w+)'), + // 4. MEMORY & HARDWARE + XRegExp('^(?\\d+[KMG])\\s+bytes\\s+of\\s+physical\\s+memory', 'i'), XRegExp( - '[Cc]isco\\s+(?\\S+|\\S+\\d\\S+)\\s+\\(.+\\)\\s+with\\s+(?.+)\\s+bytes' + '[Cc]isco\\s+(?\\S+)\\s+\\(.+?\\)\\s+processor\\s+with\\s+(?\\d+[KMG]\\/\\d+[KMG])\\s+bytes\\s+of\\s+memory', + 'i' ), - // XRegExp("^(?.+)\\s+bytes\\s+of\\s+[Uu][Ss][Bb]+\\s+[Ff]lash"), + // 5. Flash / Storage XRegExp( - '^(?.+?)\\s+bytes\\s+of\\s+(?:' + - '[Uu][Ss][Bb]+\\s+[Ff]lash' + // USB Flash - '|ATA\\s+System\\s+CompactFlash.*' + // ATA System CompactFlash - '|flash\\s+memory\\s+at\\s+bootflash:' + // flash memory at bootflash - ')' + '^(?\\d+[KMG])\\s+bytes\\s+of\\s+(?:' + + '[Uu][Ss][Bb]+\\s+[Ff]lash' + + '|ATA\\s+System\\s+CompactFlash.*' + + '|flash\\s+memory\\s+at\\s+bootflash:' + + ')', + 'i' ), + // 6. Config & MAC XRegExp( 'Base\\s+[Ee]thernet\\s+MAC\\s+[Aa]ddress\\s+:\\s+(?[0-9a-fA-F]{2}(?::[0-9a-fA-F]{2}){5})' ), @@ -65,10 +73,12 @@ const parseLog = (data: string) => { if (match) { const item = match?.groups || {} Object.keys(item).forEach((key) => { + // Chỉ update nếu giá trị tìm thấy không undefined if (item[key] !== undefined) { records[key] = item[key] } }) + // Break inner loop (patterns) để sang dòng tiếp theo break } } diff --git a/FRONTEND/src/components/Modal/ModalConfigRamFlash.tsx b/FRONTEND/src/components/Modal/ModalConfigRamFlash.tsx index 0ce201d..d68a0cc 100644 --- a/FRONTEND/src/components/Modal/ModalConfigRamFlash.tsx +++ b/FRONTEND/src/components/Modal/ModalConfigRamFlash.tsx @@ -264,7 +264,7 @@ export default function ModalConfigRamFlash({ opened, onClose }: Props) { size="xs" /> Models - Ram + RAM Flash