From ab825a1a70b700eef053aac795b57e618edec0ba Mon Sep 17 00:00:00 2001 From: ssongliu <73214554+ssongliu@users.noreply.github.com> Date: Mon, 9 Sep 2024 11:19:29 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E9=98=B2=E7=81=AB=E5=A2=99=E6=93=8D?= =?UTF-8?q?=E4=BD=9C=E6=94=AF=E6=8C=81=20ipv6=20=E7=BD=91=E6=AE=B5=20(#641?= =?UTF-8?q?5)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/utils/util.ts | 13 +++++++++++++ .../views/host/firewall/forward/operate/index.vue | 12 +++++++++--- .../src/views/host/firewall/ip/operate/index.vue | 12 +++++++++--- .../src/views/host/firewall/port/operate/index.vue | 12 +++++++++--- 4 files changed, 40 insertions(+), 9 deletions(-) diff --git a/frontend/src/utils/util.ts b/frontend/src/utils/util.ts index a16eb2151..b273f2ef4 100644 --- a/frontend/src/utils/util.ts +++ b/frontend/src/utils/util.ts @@ -347,6 +347,19 @@ export function checkCidr(value: string): boolean { return false; } } +export function checkCidrV6(value: string): boolean { + if (value === '') { + return true; + } + if (checkIpV6(value.split('/')[0])) { + return true; + } + const reg = /^(?:[1-9]|[1-9][0-9]|1[0-1][0-9]|12[0-8])$/; + if (!reg.test(value.split('/')[1])) { + return true; + } + return false; +} export function checkPort(value: string): boolean { if (Number(value) <= 0) { diff --git a/frontend/src/views/host/firewall/forward/operate/index.vue b/frontend/src/views/host/firewall/forward/operate/index.vue index ec982f9f6..5f9f26294 100644 --- a/frontend/src/views/host/firewall/forward/operate/index.vue +++ b/frontend/src/views/host/firewall/forward/operate/index.vue @@ -59,7 +59,7 @@ import DrawerHeader from '@/components/drawer-header/index.vue'; import { MsgSuccess } from '@/utils/message'; import { Host } from '@/api/interface/host'; import { operateForwardRule } from '@/api/modules/host'; -import { checkCidr, checkIp, checkPort, deepCopy } from '@/utils/util'; +import { checkCidr, checkCidrV6, checkIp, checkPort, deepCopy } from '@/utils/util'; const loading = ref(); const oldRule = ref(); @@ -111,8 +111,14 @@ function checkAddress(rule: any, value: string, callback: any) { let addrs = value.split(','); for (const item of addrs) { if (item.indexOf('/') !== -1) { - if (checkCidr(item)) { - return callback(new Error(i18n.global.t('firewall.addressFormatError'))); + if (item.indexOf(':') !== -1) { + if (checkCidrV6(item)) { + return callback(new Error(i18n.global.t('firewall.addressFormatError'))); + } + } else { + if (checkCidr(item)) { + return callback(new Error(i18n.global.t('firewall.addressFormatError'))); + } } } else { if (checkIp(item)) { diff --git a/frontend/src/views/host/firewall/ip/operate/index.vue b/frontend/src/views/host/firewall/ip/operate/index.vue index 163985a45..ec0961e02 100644 --- a/frontend/src/views/host/firewall/ip/operate/index.vue +++ b/frontend/src/views/host/firewall/ip/operate/index.vue @@ -56,7 +56,7 @@ import DrawerHeader from '@/components/drawer-header/index.vue'; import { MsgSuccess } from '@/utils/message'; import { Host } from '@/api/interface/host'; import { operateIPRule, updateAddrRule } from '@/api/modules/host'; -import { checkCidr, checkIpV4V6, deepCopy } from '@/utils/util'; +import { checkCidr, checkCidrV6, checkIpV4V6, deepCopy } from '@/utils/util'; const loading = ref(); const oldRule = ref(); @@ -95,8 +95,14 @@ function checkAddress(rule: any, value: any, callback: any) { let addrs = dialogData.value.rowData.address.split(','); for (const item of addrs) { if (item.indexOf('/') !== -1) { - if (checkCidr(item)) { - return callback(new Error(i18n.global.t('firewall.addressFormatError'))); + if (item.indexOf(':') !== -1) { + if (checkCidrV6(item)) { + return callback(new Error(i18n.global.t('firewall.addressFormatError'))); + } + } else { + if (checkCidr(item)) { + return callback(new Error(i18n.global.t('firewall.addressFormatError'))); + } } } else { if (checkIpV4V6(item)) { diff --git a/frontend/src/views/host/firewall/port/operate/index.vue b/frontend/src/views/host/firewall/port/operate/index.vue index 95b622c75..03374a7fe 100644 --- a/frontend/src/views/host/firewall/port/operate/index.vue +++ b/frontend/src/views/host/firewall/port/operate/index.vue @@ -81,7 +81,7 @@ import DrawerHeader from '@/components/drawer-header/index.vue'; import { MsgError, MsgSuccess } from '@/utils/message'; import { Host } from '@/api/interface/host'; import { operatePortRule, updatePortRule } from '@/api/modules/host'; -import { checkCidr, checkIpV4V6, checkPort, deepCopy } from '@/utils/util'; +import { checkCidr, checkCidrV6, checkIpV4V6, checkPort, deepCopy } from '@/utils/util'; const loading = ref(); const oldRule = ref(); @@ -128,8 +128,14 @@ function checkAddress(rule: any, value: any, callback: any) { let addrs = dialogData.value.rowData.address.split(','); for (const item of addrs) { if (item.indexOf('/') !== -1) { - if (checkCidr(item)) { - return callback(new Error(i18n.global.t('firewall.addressFormatError'))); + if (item.indexOf(':') !== -1) { + if (checkCidrV6(item)) { + return callback(new Error(i18n.global.t('firewall.addressFormatError'))); + } + } else { + if (checkCidr(item)) { + return callback(new Error(i18n.global.t('firewall.addressFormatError'))); + } } } else { if (checkIpV4V6(item)) {