add IP limit for all Inbound Clients

This commit is contained in:
Hossin Asaadi
2022-11-09 09:57:14 -05:00
parent e93b80a752
commit 5aa27770cf
2 changed files with 20 additions and 12 deletions

View File

@@ -69,3 +69,10 @@ type Setting struct {
Key string `json:"key" form:"key"` Key string `json:"key" form:"key"`
Value string `json:"value" form:"value"` Value string `json:"value" form:"value"`
} }
type Client struct {
ID string `json:"id"`
AlterIds uint16 `json:"alterId"`
Email string `json:"email"`
LimitIP int `json:"limitIp"`
Security string `json:"security"`
}

View File

@@ -9,7 +9,7 @@ import (
ss "strings" ss "strings"
"regexp" "regexp"
"encoding/json" "encoding/json"
"strconv" // "strconv"
"strings" "strings"
"time" "time"
"net" "net"
@@ -192,24 +192,25 @@ func updateInboundClientIps(inboundClientIps *model.InboundClientIps,clientEmail
inbound, err := GetInboundByEmail(clientEmail) inbound, err := GetInboundByEmail(clientEmail)
checkError(err) checkError(err)
limitIpRegx, _ := regexp.Compile(`"limitIp": .+`)
if inbound.Settings == "" { if inbound.Settings == "" {
logger.Debug("wrong data ",inbound) logger.Debug("wrong data ",inbound)
return nil return nil
} }
limitIpMactch := limitIpRegx.FindString(inbound.Settings) settings := map[string][]model.Client{}
limitIpMactch = ss.Split(limitIpMactch, `"limitIp": `)[1] json.Unmarshal([]byte(inbound.Settings), &settings)
limitIp, err := strconv.Atoi(limitIpMactch) clients := settings["clients"]
for _, client := range clients {
if(limitIp < len(ips) && limitIp != 0 && inbound.Enable) { if client.Email == clientEmail {
if(limitIp == 1){ limitIp := client.LimitIP
limitIp = 2
if(limitIp < len(ips) && limitIp != 0 && inbound.Enable) {
disAllowedIps = append(disAllowedIps,ips[limitIp:]...)
}
} }
disAllowedIps = append(disAllowedIps,ips[limitIp - 1:]...)
} }
logger.Debug("disAllowedIps ",disAllowedIps) logger.Debug("disAllowedIps ",disAllowedIps)
sort.Sort(sort.StringSlice(disAllowedIps)) sort.Sort(sort.StringSlice(disAllowedIps))