diff --git a/web/src/pages/group/List.vue b/web/src/pages/group/List.vue index 4f71eb7..6d5975c 100644 --- a/web/src/pages/group/List.vue +++ b/web/src/pages/group/List.vue @@ -281,48 +281,60 @@ - 输入CIDR格式如: 192.168.1.0/24 - + 输入CIDR格式如: 192.168.1.0/24 + + + + - - - - - - - - - - - + + + + + + + + + + + + + - 输入CIDR格式如: 192.168.2.0/24 - + 输入CIDR格式如: 192.168.2.0/24 + + + + - - - - - - - - - - - + + + + + + + + + + + + + @@ -333,7 +345,7 @@ - + @@ -365,6 +377,7 @@ + 注:域名拆分隧道,仅支持AnyConnect的桌面客户端,不支持移动端. @@ -398,6 +411,25 @@ + + + + + + 当前共 {{ ipEditForm.ip_list.trim() === '' ? 0 : ipEditForm.ip_list.trim().split("\n").length }} 条(注:AnyConnect客户端最多支持{{ this.maxRouteRows }}条路由) + + + 更新 + 取 消 + + + @@ -424,6 +456,7 @@ export default { activeTab : "general", readMore: {}, readMinRows : 5, + maxRouteRows : 2500, defAuth : { type:'local', radius:{addr:"", secret:""}, @@ -450,11 +483,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 +683,70 @@ 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; + 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]; + if (item.trim() === "") { + continue; + } + 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; + } + let valid = this.isValidCIDR(ip[0]); + if (!valid.valid) { + this.$message.error("错误:CIDR格式错误,建议 " + ip[0] + " 改为 " + valid.suggestion); + this.ipEditLoading = false; + return; + } + pushToArr(); + } + this.ruleForm[this.ipEditForm.type] = arr; + this.ipEditLoading = false; + this.ipListDialog = false; + }, + 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(); },