diff options
| author | zephyr <[email protected]> | 2023-06-25 11:14:33 +0800 |
|---|---|---|
| committer | zephyr <[email protected]> | 2023-06-25 11:14:33 +0800 |
| commit | cc21971645a4a6d60fce48b4da936232bddac9b9 (patch) | |
| tree | 8cbf67768186c1d82eb7938e67138b5cd181aae2 /src | |
| parent | fb724a16b86a5ef1d905577fd3e14126e7b8c842 (diff) | |
fix: no default reg for sourceip table
Diffstat (limited to 'src')
| -rw-r--r-- | src/components/Connections.tsx | 27 | ||||
| -rw-r--r-- | src/i18n/en.ts | 1 | ||||
| -rw-r--r-- | src/i18n/zh-cn.ts | 1 | ||||
| -rw-r--r-- | src/i18n/zh-tw.ts | 1 |
4 files changed, 23 insertions, 7 deletions
diff --git a/src/components/Connections.tsx b/src/components/Connections.tsx index a0d0f37..2cfa731 100644 --- a/src/components/Connections.tsx +++ b/src/components/Connections.tsx @@ -102,16 +102,26 @@ function getConnIpList(conns: FormattedConn[], sourceMap: { reg: string; name: s }); } -function getNameFromSource(source: string, sourceMap: { reg: string; name: string }[]): string { - let sourceName = source; +function getNameFromSource( + source: string, + sourceMap: { reg: string; name: string }[], + defaultVal?: string +): string { + let sourceName = defaultVal ?? source; sourceMap.forEach(({ reg, name }) => { if (!reg) return; - const regExp = new RegExp(reg, 'g'); + if (reg.startsWith('/')) { + const regExp = new RegExp(reg.replace('/', ''), 'g'); - if (regExp.test(source) && name) { - sourceName = `${name}(${source})`; + if (regExp.test(source) && name) { + sourceName = `${name}(${source})`; + } + } else { + if (source === reg && name) { + sourceName = `${name}(${source})`; + } } }); @@ -154,7 +164,7 @@ function formatConnectionDataItem( host: `${host2}:${destinationPort}`, sniffHost: sniffHost ? sniffHost : '-', type: `${type}(${network})`, - source: getNameFromSource(source, sourceMap), + source: getNameFromSource(sourceIP, sourceMap, source), downloadSpeedCurr: download - (prev ? prev.download : 0), uploadSpeedCurr: upload - (prev ? prev.upload : 0), process: process ? process : '-', @@ -319,7 +329,10 @@ function Conn({ apiConfig }) { ))} </tbody> </table> - <Button onClick={() => sourceMap.push({ reg: '', name: '' })}>{t('add_tag')}</Button> + <div> + <div>{t('sourceip_tip')}</div> + <Button onClick={() => sourceMap.push({ reg: '', name: '' })}>{t('add_tag')}</Button> + </div> </BaseModal> <div className={s.header}> <ContentHeader title={t('Connections')} /> diff --git a/src/i18n/en.ts b/src/i18n/en.ts index 6ca6425..7963aae 100644 --- a/src/i18n/en.ts +++ b/src/i18n/en.ts @@ -72,4 +72,5 @@ export const data = { delete: 'Delete', add_tag: 'Add tag', client_tag: 'Client tags', + sourceip_tip: "Prefix with / for regular expressions, otherwise it's a complete match", }; diff --git a/src/i18n/zh-cn.ts b/src/i18n/zh-cn.ts index bac5ccf..3fa27c4 100644 --- a/src/i18n/zh-cn.ts +++ b/src/i18n/zh-cn.ts @@ -73,4 +73,5 @@ export const data = { delete: '删除', add_tag: '添加标签', client_tag: '客户端标签', + sourceip_tip: '/开头为正则,否则为全匹配', }; diff --git a/src/i18n/zh-tw.ts b/src/i18n/zh-tw.ts index 18049d4..a66ee37 100644 --- a/src/i18n/zh-tw.ts +++ b/src/i18n/zh-tw.ts @@ -72,4 +72,5 @@ export const data = { delete: '删除', add_tag: '添加标签', client_tag: '客户端标签', + sourceip_tip: '/开头为正则,否则为全匹配', }; |
