From ea92857524cc624eb526627d2eb931d84c4c72cf Mon Sep 17 00:00:00 2001 From: lanrenwo Date: Sat, 2 Dec 2023 15:38:18 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E8=B7=AF=E7=94=B1?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E7=9A=84=E7=BC=96=E8=BE=91=E6=A8=A1=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/src/pages/group/List.vue | 71 +++++++++++++++++++++++++++++++++--- 1 file changed, 65 insertions(+), 6 deletions(-) diff --git a/web/src/pages/group/List.vue b/web/src/pages/group/List.vue index 4f71eb7..562c936 100644 --- a/web/src/pages/group/List.vue +++ b/web/src/pages/group/List.vue @@ -281,11 +281,15 @@ - 输入CIDR格式如: 192.168.1.0/24 - + 输入CIDR格式如: 192.168.1.0/24 + + + + @@ -304,11 +308,15 @@ - 输入CIDR格式如: 192.168.2.0/24 - + 输入CIDR格式如: 192.168.2.0/24 + + + + @@ -365,6 +373,7 @@ +
注意:域名拆分隧道,仅支持AnyConnect的桌面客户端,不支持移动端.
@@ -398,6 +407,25 @@ + + + + + +
AnyConnect最多支持{{ this.maxRouteRows }}条路由,当前共 {{ ipEditForm.ip_list.split("\n").length }} 条
+
+ + 更新 + 取 消 + +
+
@@ -424,6 +452,7 @@ export default { activeTab : "general", readMore: {}, readMinRows : 5, + maxRouteRows : 2500, defAuth : { type:'local', radius:{addr:"", secret:""}, @@ -450,11 +479,17 @@ export default { auth : {}, }, authLoginDialog : false, - authLoginLoading : false, + ipListDialog : false, + authLoginLoading : false, authLoginForm : { name : "", pwd : "", - }, + }, + ipEditForm: { + ip_list: "", + type : "", + }, + ipEditLoading : false, authLoginRules: { name: [ {required: true, message: '请输入账号', trigger: 'blur'}, @@ -644,6 +679,30 @@ export default { }); }); }, + openIpListDialog(type) { + this.ipListDialog = true; + this.ipEditForm.type = type; + this.ipEditForm.ip_list = this.ruleForm[type].map(item => item.val + (item.note ? "," + item.note : "")).join("\n"); + }, + ipEdit() { + this.ipEditLoading = true; + // ip_list不能超过this.maxRouteRows行 + if (this.ipEditForm.ip_list.split("\n").length > this.maxRouteRows) { + this.$message.error("错误:AnyConnect最多支持" + this.maxRouteRows + "条路由."); + this.ipEditLoading = false; + return false; + } + let arr = this.ipEditForm.ip_list.split("\n").map(item => { + let ip = item.split(","); + if (ip.length > 2) { + ip[1] = ip.slice(1).join(","); + } + return {val: ip[0], note: ip[1] ? ip[1] : ""}; + }); + this.ruleForm[this.ipEditForm.type] = arr; + this.ipEditLoading = false; + this.ipListDialog = false; + }, resetForm(formName) { this.$refs[formName].resetFields(); }, From 5d24eda7fcabbbf3aed676620775e48c692fe801 Mon Sep 17 00:00:00 2001 From: lanrenwo Date: Sun, 3 Dec 2023 22:09:46 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E4=B8=8D=E9=99=90=E5=88=B6=E8=B7=AF?= =?UTF-8?q?=E7=94=B1=E7=9A=84=E6=95=B0=E9=87=8F=EF=BC=8C=E5=B9=B6=E6=A3=80?= =?UTF-8?q?=E6=B5=8BCIDR=E6=A0=BC=E5=BC=8F=E7=9A=84=E6=AD=A3=E7=A1=AE?= =?UTF-8?q?=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/src/pages/group/List.vue | 47 ++++++++++++++++++++++++------------ 1 file changed, 32 insertions(+), 15 deletions(-) diff --git a/web/src/pages/group/List.vue b/web/src/pages/group/List.vue index 562c936..8d1d221 100644 --- a/web/src/pages/group/List.vue +++ b/web/src/pages/group/List.vue @@ -373,7 +373,7 @@ -
注意:域名拆分隧道,仅支持AnyConnect的桌面客户端,不支持移动端.
+
注:域名拆分隧道,仅支持AnyConnect的桌面客户端,不支持移动端.
@@ -412,13 +412,13 @@ :close-on-click-modal="false" title="编辑模式" :visible.sync="ipListDialog" - width="600px" + width="650px" custom-class="valgin-dialog" center> - -
AnyConnect最多支持{{ this.maxRouteRows }}条路由,当前共 {{ ipEditForm.ip_list.split("\n").length }} 条
+ +
当前共 {{ ipEditForm.ip_list.trim() === '' ? 0 : ipEditForm.ip_list.trim().split("\n").length }} 条(注:AnyConnect客户端最多支持{{ this.maxRouteRows }}条路由)
更新 @@ -686,23 +686,40 @@ export default { }, ipEdit() { this.ipEditLoading = true; - // ip_list不能超过this.maxRouteRows行 - if (this.ipEditForm.ip_list.split("\n").length > this.maxRouteRows) { - this.$message.error("错误:AnyConnect最多支持" + this.maxRouteRows + "条路由."); + let ipList = []; + if (this.ipEditForm.ip_list.trim() !== "") { + ipList = this.ipEditForm.ip_list.trim().split("\n"); + } + let arr = []; + for (let i = 0; i < ipList.length; i++) { + let item = ipList[i]; + let ip = item.split(","); + if (ip.length > 2) { + ip[1] = ip.slice(1).join(","); + } + let note = ip[1] ? ip[1] : ""; + const pushToArr = () => { + arr.push({val: ip[0], note: note}); + }; + if (this.ipEditForm.type == "route_include" && ip[0] == "all") { + pushToArr(); + continue; + } + if (!this.isValidCIDR(ip[0])) { + this.$message.error("错误:CIDR格式错误 " + item); this.ipEditLoading = false; - return false; + return; + } + pushToArr(); } - let arr = this.ipEditForm.ip_list.split("\n").map(item => { - let ip = item.split(","); - if (ip.length > 2) { - ip[1] = ip.slice(1).join(","); - } - return {val: ip[0], note: ip[1] ? ip[1] : ""}; - }); this.ruleForm[this.ipEditForm.type] = arr; this.ipEditLoading = false; this.ipListDialog = false; }, + isValidCIDR(str) { + const cidrRegex = /^([0-9]{1,3}\.){3}[0-9]{1,3}\/([0-9]|[1-2][0-9]|3[0-2])$/; + return cidrRegex.test(str); + }, resetForm(formName) { this.$refs[formName].resetFields(); }, From 3d03f6adb86723b7553af7ed33f41c2cb612bd8f Mon Sep 17 00:00:00 2001 From: lanrenwo Date: Mon, 4 Dec 2023 13:08:37 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E5=A4=A7=E9=87=8F?= =?UTF-8?q?=E8=B7=AF=E7=94=B1=E5=AF=BC=E8=87=B4=E5=BC=B9=E7=AA=97=E5=8D=A1?= =?UTF-8?q?=E9=A1=BF=E7=9A=84=E9=97=AE=E9=A2=98=EF=BC=88=E5=BD=93=E7=82=B9?= =?UTF-8?q?=E5=87=BB=E2=80=9C=E8=B7=AF=E7=94=B1=E8=AE=BE=E7=BD=AE=E2=80=9D?= =?UTF-8?q?=E6=97=B6=EF=BC=8C=E6=89=8D=E5=8A=A0=E8=BD=BD=E8=B7=AF=E7=94=B1?= =?UTF-8?q?=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/src/pages/group/List.vue | 60 +++++++++++++++++++----------------- 1 file changed, 32 insertions(+), 28 deletions(-) diff --git a/web/src/pages/group/List.vue b/web/src/pages/group/List.vue index 8d1d221..298abae 100644 --- a/web/src/pages/group/List.vue +++ b/web/src/pages/group/List.vue @@ -291,19 +291,21 @@ @click.prevent="openIpListDialog('route_include')"> - - - - - - - - - - - + + + + + + + + + + + + + @@ -318,19 +320,21 @@ @click.prevent="openIpListDialog('route_exclude')"> - - - - - - - - - - - + + + + + + + + + + + + + @@ -341,8 +345,8 @@ - - + + From 7c040e2a0fba8a5a3e600ae29992ca4d0b0b4dad Mon Sep 17 00:00:00 2001 From: lanrenwo Date: Mon, 4 Dec 2023 13:44:06 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E8=BF=87=E6=BB=A4=E6=96=87=E6=9C=AC?= =?UTF-8?q?=E6=A1=86=E5=86=85=E7=9A=84=E7=A9=BA=E8=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/src/pages/group/List.vue | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/web/src/pages/group/List.vue b/web/src/pages/group/List.vue index 298abae..97fdaae 100644 --- a/web/src/pages/group/List.vue +++ b/web/src/pages/group/List.vue @@ -346,7 +346,7 @@ @click.prevent="addDomain(ruleForm.link_acl)"> - + @@ -697,6 +697,9 @@ export default { let arr = []; for (let i = 0; i < ipList.length; i++) { let item = ipList[i]; + if (item.trim() === "") { + continue; + } let ip = item.split(","); if (ip.length > 2) { ip[1] = ip.slice(1).join(","); From 8a3d34b737a4894f9eeed0807130fe22fa92c21f Mon Sep 17 00:00:00 2001 From: lanrenwo Date: Mon, 4 Dec 2023 18:32:09 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E4=BC=98=E5=8C=96isValidCIDR=E5=87=BD?= =?UTF-8?q?=E6=95=B0=EF=BC=8C=E8=A7=A3=E5=86=B3=E9=83=A8=E5=88=86=E6=A0=BC?= =?UTF-8?q?=E5=BC=8F=E6=A3=80=E6=B5=8B=E6=9C=89=E8=AF=AF=EF=BC=8C=E5=B9=B6?= =?UTF-8?q?=E7=BB=99=E4=BA=88=E5=BB=BA=E8=AE=AE=E6=8F=90=E7=A4=BA=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/src/pages/group/List.vue | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/web/src/pages/group/List.vue b/web/src/pages/group/List.vue index 97fdaae..6d5975c 100644 --- a/web/src/pages/group/List.vue +++ b/web/src/pages/group/List.vue @@ -712,10 +712,11 @@ export default { pushToArr(); continue; } - if (!this.isValidCIDR(ip[0])) { - this.$message.error("错误:CIDR格式错误 " + item); - this.ipEditLoading = false; - return; + let valid = this.isValidCIDR(ip[0]); + if (!valid.valid) { + this.$message.error("错误:CIDR格式错误,建议 " + ip[0] + " 改为 " + valid.suggestion); + this.ipEditLoading = false; + return; } pushToArr(); } @@ -723,9 +724,28 @@ export default { this.ipEditLoading = false; this.ipListDialog = false; }, - isValidCIDR(str) { - const cidrRegex = /^([0-9]{1,3}\.){3}[0-9]{1,3}\/([0-9]|[1-2][0-9]|3[0-2])$/; - return cidrRegex.test(str); + isValidCIDR(input) { + const cidrRegex = /^((25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(25[0-5]|2[0-4]\d|[01]?\d\d?)\/([12]?\d|3[0-2])$/; + if (!cidrRegex.test(input)) { + return { valid: false, suggestion: null }; + } + const [ip, mask] = input.split('/'); + const maskNum = parseInt(mask); + const ipParts = ip.split('.').map(part => parseInt(part)); + const binaryIP = ipParts.map(part => part.toString(2).padStart(8, '0')).join(''); + for (let i = maskNum; i < 32; i++) { + if (binaryIP[i] === '1') { + const binaryNetworkPart = binaryIP.substring(0, maskNum).padEnd(32, '0'); + const networkIPParts = []; + for (let j = 0; j < 4; j++) { + const octet = binaryNetworkPart.substring(j * 8, (j + 1) * 8); + networkIPParts.push(parseInt(octet, 2)); + } + const suggestedIP = networkIPParts.join('.'); + return { valid: false, suggestion: `${suggestedIP}/${mask}` }; + } + } + return { valid: true, suggestion: null }; }, resetForm(formName) { this.$refs[formName].resetFields();