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)) {