From 5aa27770cfdea4f59628a5303b20dc66319ed738 Mon Sep 17 00:00:00 2001 From: Hossin Asaadi Date: Wed, 9 Nov 2022 09:57:14 -0500 Subject: [PATCH] add IP limit for all Inbound Clients --- database/model/model.go | 7 +++++++ web/job/check_clinet_ip_job.go | 25 +++++++++++++------------ 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/database/model/model.go b/database/model/model.go index b7142157..987083a8 100644 --- a/database/model/model.go +++ b/database/model/model.go @@ -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"` +} diff --git a/web/job/check_clinet_ip_job.go b/web/job/check_clinet_ip_job.go index a7cac64a..bf71116b 100644 --- a/web/job/check_clinet_ip_job.go +++ b/web/job/check_clinet_ip_job.go @@ -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))