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