修复acl表结构

This commit is contained in:
bjdgyc 2024-04-22 16:47:06 +08:00
parent 1b066ef602
commit cb902a6b9b
3 changed files with 27 additions and 26 deletions

View File

@ -27,7 +27,7 @@ type GroupLinkAcl struct {
// 自上而下匹配 默认 allow * * // 自上而下匹配 默认 allow * *
Action string `json:"action"` // allow、deny Action string `json:"action"` // allow、deny
Val string `json:"val"` Val string `json:"val"`
Port interface{} `json:"port"` //兼容单端口历史数据类型uint16 Port string `json:"port"` // 兼容单端口历史数据类型uint16
Ports map[uint16]int8 `json:"ports"` Ports map[uint16]int8 `json:"ports"`
IpNet *net.IPNet `json:"ip_net"` IpNet *net.IPNet `json:"ip_net"`
Note string `json:"note"` Note string `json:"note"`
@ -164,13 +164,14 @@ func SetGroup(g *Group) error {
} }
v.IpNet = ipNet v.IpNet = ipNet
portsStr := "" portsStr := v.Port
switch vp := v.Port.(type) { v.Port = strings.TrimSpace(portsStr)
case float64: // switch vp := v.Port.(type) {
portsStr = strconv.Itoa(int(vp)) // case float64:
case string: // portsStr = strconv.Itoa(int(vp))
portsStr = vp // case string:
} // portsStr = vp
// }
if regexp.MustCompile(`^\d{1,5}(-\d{1,5})?(,\d{1,5}(-\d{1,5})?)*$`).MatchString(portsStr) { if regexp.MustCompile(`^\d{1,5}(-\d{1,5})?(,\d{1,5}(-\d{1,5})?)*$`).MatchString(portsStr) {
ports := map[uint16]int8{} ports := map[uint16]int8{}

View File

@ -90,17 +90,18 @@ func checkLinkAcl(group *dbdata.Group, pl *sessdata.Payload) bool {
if v.IpNet.Contains(ipDst) { if v.IpNet.Contains(ipDst) {
// 放行允许ip的ping // 放行允许ip的ping
if v.Ports == nil || len(v.Ports) == 0 { // if v.Ports == nil || len(v.Ports) == 0 {
//单端口历史数据兼容 // //单端口历史数据兼容
port := uint16(v.Port.(float64)) // port := uint16(v.Port.(float64))
if port == ipPort || port == 0 || ipProto == waterutil.ICMP { // if port == ipPort || port == 0 || ipProto == waterutil.ICMP {
if v.Action == dbdata.Allow { // if v.Action == dbdata.Allow {
return true // return true
} else { // } else {
return false // return false
} // }
} // }
} else { // } else {
if dbdata.ContainsInPorts(v.Ports, ipPort) || dbdata.ContainsInPorts(v.Ports, 0) || ipProto == waterutil.ICMP { if dbdata.ContainsInPorts(v.Ports, ipPort) || dbdata.ContainsInPorts(v.Ports, 0) || ipProto == waterutil.ICMP {
if v.Action == dbdata.Allow { if v.Action == dbdata.Allow {
return true return true
@ -110,7 +111,6 @@ func checkLinkAcl(group *dbdata.Group, pl *sessdata.Payload) bool {
} }
} }
} }
}
return false return false
} }

View File

@ -344,7 +344,7 @@
<el-tab-pane label="权限控制" name="link_acl"> <el-tab-pane label="权限控制" name="link_acl">
<el-form-item label="权限控制" prop="link_acl"> <el-form-item label="权限控制" prop="link_acl">
<el-row class="msg-info"> <el-row class="msg-info">
<el-col :span="22">输入CIDR格式如: 192.168.3.0/24 端口0表示所有端口,多个端口用,号分隔,连续端口:1234-5678</el-col> <el-col :span="22">输入CIDR格式如: 192.168.3.0/24 端口0表示所有端口,多个端口用','号分隔,连续端口:1234-5678</el-col>
<el-col :span="2"> <el-col :span="2">
<el-button size="mini" type="success" icon="el-icon-plus" circle <el-button size="mini" type="success" icon="el-icon-plus" circle
@click.prevent="addDomain(ruleForm.link_acl)"></el-button> @click.prevent="addDomain(ruleForm.link_acl)"></el-button>