mirror of https://github.com/bjdgyc/anylink.git
兼容历史单端口配置
This commit is contained in:
parent
4f56ea49c3
commit
24e30509e4
server
|
@ -5,10 +5,9 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
"reflect"
|
|
||||||
|
|
||||||
"github.com/bjdgyc/anylink/base"
|
"github.com/bjdgyc/anylink/base"
|
||||||
"golang.org/x/text/language"
|
"golang.org/x/text/language"
|
||||||
|
@ -28,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"`
|
Port interface{} `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"`
|
||||||
|
@ -45,13 +44,6 @@ type GroupNameId struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
type PortData struct {
|
|
||||||
PortFrom uint16 `json:"port_from"`
|
|
||||||
PortTo uint16 `json:"port_to"`
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// type Group struct {
|
// type Group struct {
|
||||||
// Id int `json:"id" xorm:"pk autoincr not null"`
|
// Id int `json:"id" xorm:"pk autoincr not null"`
|
||||||
// Name string `json:"name" xorm:"varchar(60) not null unique"`
|
// Name string `json:"name" xorm:"varchar(60) not null unique"`
|
||||||
|
@ -172,14 +164,14 @@ func SetGroup(g *Group) error {
|
||||||
}
|
}
|
||||||
v.IpNet = ipNet
|
v.IpNet = ipNet
|
||||||
|
|
||||||
port:="";
|
port := ""
|
||||||
//base.Debug("v.port:",v.Port,v.Ports,reflect.TypeOf(v.Port).Name())
|
switch vp := v.Port.(type) {
|
||||||
switch v := v.Port.(type) {
|
|
||||||
case float64:
|
case float64:
|
||||||
port = strconv.Itoa(int(v))
|
port = strconv.Itoa(int(vp))
|
||||||
case string:
|
case string:
|
||||||
port = v
|
port = vp
|
||||||
}
|
}
|
||||||
|
|
||||||
if regexp.MustCompile(`^\d{1,5}(-\d{1,5})?(,\d{1,5}(-\d{1,5})?)*$`).MatchString(port) {
|
if regexp.MustCompile(`^\d{1,5}(-\d{1,5})?(,\d{1,5}(-\d{1,5})?)*$`).MatchString(port) {
|
||||||
ports := map[uint16]int8{}
|
ports := map[uint16]int8{}
|
||||||
for _, p := range strings.Split(port, ",") {
|
for _, p := range strings.Split(port, ",") {
|
||||||
|
@ -187,7 +179,7 @@ func SetGroup(g *Group) error {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if regexp.MustCompile(`^\d{1,5}-\d{1,5}$`).MatchString(p) {
|
if regexp.MustCompile(`^\d{1,5}-\d{1,5}$`).MatchString(p) {
|
||||||
rp := strings.Split(p, "-");
|
rp := strings.Split(p, "-")
|
||||||
portfrom, err := strconv.Atoi(rp[0])
|
portfrom, err := strconv.Atoi(rp[0])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.New("端口:" + rp[0] + " 格式错误, " + err.Error())
|
return errors.New("端口:" + rp[0] + " 格式错误, " + err.Error())
|
||||||
|
|
|
@ -88,9 +88,12 @@ func checkLinkAcl(group *dbdata.Group, pl *sessdata.Payload) bool {
|
||||||
for _, v := range group.LinkAcl {
|
for _, v := range group.LinkAcl {
|
||||||
// 循环判断ip和端口
|
// 循环判断ip和端口
|
||||||
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 {
|
||||||
if v.Port==ipPort || v.Port==0 || ipProto == waterutil.ICMP {
|
//单端口历史数据兼容
|
||||||
|
port := uint16(v.Port.(float64))
|
||||||
|
if port == ipPort || port == 0 || ipProto == waterutil.ICMP {
|
||||||
if v.Action == dbdata.Allow {
|
if v.Action == dbdata.Allow {
|
||||||
return true
|
return true
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue