mirror of
https://github.com/alireza0/x-ui.git
synced 2026-03-14 05:23:09 +00:00
add IP limit for all Inbound Clients
This commit is contained in:
@@ -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"`
|
||||||
|
}
|
||||||
|
|||||||
@@ -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))
|
||||||
|
|||||||
Reference in New Issue
Block a user