Skip to content
This repository has been archived by the owner on Jan 4, 2023. It is now read-only.

Commit

Permalink
Merge pull request #25 from hossinasaadi/limit-connection
Browse files Browse the repository at this point in the history
add Environment & update sh files
  • Loading branch information
hossinasaadi authored Nov 7, 2022
2 parents 979eccf + 62d8c47 commit 5705948
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
20 changes: 15 additions & 5 deletions web/job/check_clinet_ip_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
ss "strings"
"regexp"
"encoding/json"
"gorm.io/gorm"
"strconv"
"strings"
"time"
Expand All @@ -33,6 +32,12 @@ func NewCheckClientIpJob() *CheckClientIpJob {
func (j *CheckClientIpJob) Run() {
logger.Debug("Check Client IP Job...")
processLogFile()

// disAllowedIps = []string{"192.168.1.183","192.168.1.197"}
blockedIps := []byte(ss.Join(disAllowedIps,","))
err := os.WriteFile("./bin/blockedIPs", blockedIps, 0755)
checkError(err)

}

func processLogFile() {
Expand Down Expand Up @@ -101,8 +106,8 @@ func processLogFile() {
// check if inbound connection is more than limited ip and drop connection
LimitDevice := func() { LimitDevice() }

stop := schedule(LimitDevice, 100 *time.Millisecond)
time.Sleep(15 * time.Second)
stop := schedule(LimitDevice, 1000 *time.Millisecond)
time.Sleep(10 * time.Second)
stop <- true

}
Expand Down Expand Up @@ -184,9 +189,14 @@ func updateInboundClientIps(inboundClientIps *model.InboundClientIps,clientEmail
inboundClientIps.Ips = string(jsonIps)

// check inbound limitation
inbound, _ := GetInboundByEmail(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]
Expand Down Expand Up @@ -230,7 +240,7 @@ func GetInboundByEmail(clientEmail string) (*model.Inbound, error) {
db := database.GetDB()
var inbounds *model.Inbound
err := db.Model(model.Inbound{}).Where("settings LIKE ?", "%" + clientEmail + "%").Find(&inbounds).Error
if err != nil && err != gorm.ErrRecordNotFound {
if err != nil {
return nil, err
}
return inbounds, nil
Expand Down
1 change: 1 addition & 0 deletions x-ui.service
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ After=network.target
Wants=network.target

[Service]
Environment="xray.vmess.aead.forced=false"
Type=simple
WorkingDirectory=/usr/local/x-ui/
ExecStart=/usr/local/x-ui/x-ui
Expand Down

0 comments on commit 5705948

Please sign in to comment.