feat: 防火墙操作支持 ipv6 网段 (#6415)

This commit is contained in:
ssongliu 2024-09-09 11:19:29 +08:00 committed by GitHub
parent 466617847f
commit ab825a1a70
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 40 additions and 9 deletions

View File

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

View File

@ -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<Host.RuleForward>();
@ -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)) {

View File

@ -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<Host.RuleIP>();
@ -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)) {

View File

@ -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<Host.RulePort>();
@ -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)) {