Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/MHSanaei/3x-ui.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMHSanaei <ho3ein.sanaei@gmail.com>2023-05-23 17:24:15 +0300
committerMHSanaei <ho3ein.sanaei@gmail.com>2023-05-23 17:24:15 +0300
commit2223a21cfcd7173aae9c38558ce5865ebbd27097 (patch)
tree409a026e6b69bcb7cbe704e4ccd2b142e0f7ac60
parent47ccc7b501faeac895e295e86fc4ae2aea3a31ed (diff)
bug fix - limit ip
-rw-r--r--web/job/check_client_ip_job.go30
1 files changed, 16 insertions, 14 deletions
diff --git a/web/job/check_client_ip_job.go b/web/job/check_client_ip_job.go
index 17daab7b..764c3700 100644
--- a/web/job/check_client_ip_job.go
+++ b/web/job/check_client_ip_job.go
@@ -36,15 +36,21 @@ func (j *CheckClientIpJob) Run() {
// disAllowedIps = []string{"192.168.1.183","192.168.1.197"}
blockedIps := []byte(strings.Join(disAllowedIps, ","))
- err := os.WriteFile(xray.GetBlockedIPsPath(), blockedIps, 0755)
- checkError(err)
+ // check if file exists, if not create one
+ _, err := os.Stat(xray.GetBlockedIPsPath())
+ if os.IsNotExist(err) {
+ _, err = os.OpenFile(xray.GetBlockedIPsPath(), os.O_RDWR|os.O_CREATE, 0755)
+ checkError(err)
+ }
+ err = os.WriteFile(xray.GetBlockedIPsPath(), blockedIps, 0755)
+ checkError(err)
}
func processLogFile() {
accessLogPath := GetAccessLogPath()
if accessLogPath == "" {
- logger.Warning("xray log not init in config.json")
+ logger.Warning("access.log doesn't exist in your config.json")
return
}
@@ -73,7 +79,7 @@ func processLogFile() {
if matchesEmail == "" {
continue
}
- matchesEmail = strings.Split(matchesEmail, "email: ")[1]
+ matchesEmail = strings.TrimSpace(strings.Split(matchesEmail, "email: ")[1])
if InboundClientIps[matchesEmail] != nil {
if contains(InboundClientIps[matchesEmail], ip) {
@@ -94,9 +100,11 @@ func processLogFile() {
sort.Strings(ips)
if err != nil {
addInboundClientIps(clientEmail, ips)
+
} else {
updateInboundClientIps(inboundClientIps, clientEmail, ips)
}
+
}
// check if inbound connection is more than limited ip and drop connection
@@ -155,9 +163,6 @@ func addInboundClientIps(clientEmail string, ips []string) error {
jsonIps, err := json.Marshal(ips)
checkError(err)
- // Trim any leading/trailing whitespace from clientEmail
- clientEmail = strings.TrimSpace(clientEmail)
-
inboundClientIps.ClientEmail = clientEmail
inboundClientIps.Ips = string(jsonIps)
@@ -199,8 +204,6 @@ func updateInboundClientIps(inboundClientIps *model.InboundClientIps, clientEmai
json.Unmarshal([]byte(inbound.Settings), &settings)
clients := settings["clients"]
- var disAllowedIps []string // initialize the slice
-
for _, client := range clients {
if client.Email == clientEmail {
@@ -222,7 +225,6 @@ func updateInboundClientIps(inboundClientIps *model.InboundClientIps, clientEmai
}
return nil
}
-
func DisableInbound(id int) error {
db := database.GetDB()
result := db.Model(model.Inbound{}).
@@ -249,7 +251,6 @@ func GetInboundByEmail(clientEmail string) (*model.Inbound, error) {
}
func LimitDevice() {
- var destIp, destPort, srcIp, srcPort string
localIp, err := LocalIP()
checkError(err)
@@ -265,15 +266,15 @@ func LimitDevice() {
data := strings.Split(row, " ")
- if len(data) < 2 {
- continue // Skip this row if it doesn't have at least two elements
- }
+ destIp, destPort, srcIp, srcPort := "", "", "", ""
destIp = string(ipRegx.FindString(data[0]))
+
destPort = portRegx.FindString(data[0])
destPort = strings.Replace(destPort, ":", "", -1)
srcIp = string(ipRegx.FindString(data[1]))
+
srcPort = portRegx.FindString(data[1])
srcPort = strings.Replace(srcPort, ":", "", -1)
@@ -285,6 +286,7 @@ func LimitDevice() {
}
}
}
+
}
func LocalIP() ([]string, error) {