mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2024-11-23 18:49:21 +08:00
feat: 防火墙操作支持 ipv6 网段 (#6415)
This commit is contained in:
parent
466617847f
commit
ab825a1a70
@ -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) {
|
||||
|
@ -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)) {
|
||||
|
@ -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)) {
|
||||
|
@ -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)) {
|
||||
|
Loading…
Reference in New Issue
Block a user