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-06-16 00:38:35 +0300
committerMHSanaei <ho3ein.sanaei@gmail.com>2023-06-16 00:38:35 +0300
commit4cc755c8830adc7c9cdd5ea769f893753a7d0a20 (patch)
tree40f16f104f8b25a80b44dbb57ef443835e48dcad
parent4e89c71095614ff2207f71925e18e5a8cd2cd830 (diff)
fix warning when there is no access.log
after this if limitip is 0 and there is no access.log on xray config you don't see this warning access.log doesn't exist in your config.json ------------- better view on ip log ------------- update dependencies
-rw-r--r--go.mod3
-rw-r--r--go.sum7
-rw-r--r--web/html/xui/client_modal.html23
-rw-r--r--web/job/check_client_ip_job.go40
4 files changed, 51 insertions, 22 deletions
diff --git a/go.mod b/go.mod
index 55a877ca..eaa5ada4 100644
--- a/go.mod
+++ b/go.mod
@@ -6,7 +6,6 @@ require (
github.com/Workiva/go-datastructures v1.1.0
github.com/gin-contrib/sessions v0.0.4
github.com/gin-gonic/gin v1.9.1
- github.com/go-cmd/cmd v1.4.1
github.com/goccy/go-json v0.10.2
github.com/mymmrac/telego v0.25.0
github.com/nicksnyder/go-i18n/v2 v2.2.1
@@ -17,7 +16,7 @@ require (
github.com/xtls/xray-core v1.8.1
go.uber.org/atomic v1.11.0
golang.org/x/text v0.10.0
- google.golang.org/grpc v1.55.0
+ google.golang.org/grpc v1.56.0
gorm.io/driver/sqlite v1.5.2
gorm.io/gorm v1.25.2-0.20230530020048-26663ab9bf55
)
diff --git a/go.sum b/go.sum
index a465b12c..fd75d7f2 100644
--- a/go.sum
+++ b/go.sum
@@ -37,8 +37,6 @@ github.com/gin-gonic/gin v1.7.4/go.mod h1:jD2toBW3GZUr5UMcdrwQA10I7RuaFOl/SGeDjX
github.com/gin-gonic/gin v1.9.1 h1:4idEAncQnU5cB7BeOkPtxjfCSye0AAm1R0RVIqJ+Jmg=
github.com/gin-gonic/gin v1.9.1/go.mod h1:hPrL7YrpYKXt5YId3A/Tnip5kqbEAP+KLuI3SUcPTeU=
github.com/globalsign/mgo v0.0.0-20181015135952-eeefdecb41b8/go.mod h1:xkRDCp4j0OGD1HRkm4kmhM+pmpv3AKq5SU7GMg4oO/Q=
-github.com/go-cmd/cmd v1.4.1 h1:JUcEIE84v8DSy02XTZpUDeGKExk2oW3DA10hTjbQwmc=
-github.com/go-cmd/cmd v1.4.1/go.mod h1:tbBenttXtZU4c5djS1o7PWL5pd2xAr5sIqH1kGdNiRc=
github.com/go-ole/go-ole v1.2.6 h1:/Fpf6oFPoeFik9ty7siob0G6Ke8QvQEuVcuChpwXzpY=
github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0=
github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
@@ -53,7 +51,6 @@ github.com/go-playground/validator/v10 v10.4.1/go.mod h1:nlOn6nFhuKACm19sB/8EGNn
github.com/go-playground/validator/v10 v10.14.1 h1:9c50NUPC30zyuKprjL3vNZ0m5oG+jU0zvx4AqHGnv4k=
github.com/go-playground/validator/v10 v10.14.1/go.mod h1:9iXMNT7sEkjXb0I+enO7QXmzG6QCsPWY4zveKFVRSyU=
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 h1:tfuBGBXKqDEevZMzYi5KSi8KkcZtzBcTgAUUtapy0OI=
-github.com/go-test/deep v1.0.7 h1:/VSMRlnY/JSyqxQUzQLKVMAskpY/NZKFA5j2P+0pP2M=
github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU=
github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc=
@@ -257,8 +254,8 @@ golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8T
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/genproto/googleapis/rpc v0.0.0-20230530153820-e85fd2cbaebc h1:XSJ8Vk1SWuNr8S18z1NZSziL0CPIXLCCMDOEFtHBOFc=
google.golang.org/genproto/googleapis/rpc v0.0.0-20230530153820-e85fd2cbaebc/go.mod h1:66JfowdXAEgad5O9NnYcsNPLCPZJD++2L9X0PCMODrA=
-google.golang.org/grpc v1.55.0 h1:3Oj82/tFSCeUrRTg/5E/7d/W5A1tj6Ky1ABAuZuv5ag=
-google.golang.org/grpc v1.55.0/go.mod h1:iYEXKGkEBhg1PjZQvoYEVPTDkHo1/bjTnfwTeGONTY8=
+google.golang.org/grpc v1.56.0 h1:+y7Bs8rtMd07LeXmL3NxcTLn7mUkbKZqEpPhMNkwJEE=
+google.golang.org/grpc v1.56.0/go.mod h1:I9bI3vqKfayGqPUAwGdOSu7kt6oIJLixfffKrpXqQ9s=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.30.0 h1:kPPoIgf3TsEvrm0PFe15JQ+570QVxYzEvvHqChK+cng=
diff --git a/web/html/xui/client_modal.html b/web/html/xui/client_modal.html
index a2d29417..a1d4dce8 100644
--- a/web/html/xui/client_modal.html
+++ b/web/html/xui/client_modal.html
@@ -121,18 +121,21 @@
},
methods: {
async getDBClientIps(email) {
- try {
- const msg = await HttpUtil.post(`/panel/inbound/clientIps/${email}`);
- if (!msg.success) {
- document.getElementById("clientIPs").value = msg.obj;
- return;
+ const msg = await HttpUtil.post(`/panel/inbound/clientIps/${email}`);
+ if (!msg.success) {
+ document.getElementById("clientIPs").value = msg.obj;
+ return;
+ }
+ let ips = msg.obj;
+ if (typeof ips === 'string' && ips.startsWith('[') && ips.endsWith(']')) {
+ try {
+ ips = JSON.parse(ips);
+ ips = Array.isArray(ips) ? ips.join("\n") : ips;
+ } catch (e) {
+ console.error('Error parsing JSON:', e);
}
- const ips = Array.isArray(msg.obj) ? msg.obj.join(",\n") : msg.obj;
- document.getElementById("clientIPs").value = ips;
- } catch (error) {
- console.error(error);
- document.getElementById("clientIPs").value = 'An error occurred while making the request';
}
+ document.getElementById("clientIPs").value = ips;
},
async clearDBClientIps(email) {
try {
diff --git a/web/job/check_client_ip_job.go b/web/job/check_client_ip_job.go
index 87789517..348f9b9d 100644
--- a/web/job/check_client_ip_job.go
+++ b/web/job/check_client_ip_job.go
@@ -29,7 +29,10 @@ func NewCheckClientIpJob() *CheckClientIpJob {
func (j *CheckClientIpJob) Run() {
logger.Debug("Check Client IP Job...")
- processLogFile()
+
+ if hasLimitIp() {
+ processLogFile()
+ }
blockedIps := []byte(strings.Join(disAllowedIps, ","))
@@ -43,6 +46,33 @@ func (j *CheckClientIpJob) Run() {
checkError(err)
}
+func hasLimitIp() bool {
+ db := database.GetDB()
+ var inbounds []*model.Inbound
+ err := db.Model(model.Inbound{}).Find(&inbounds).Error
+ if err != nil {
+ return false
+ }
+
+ for _, inbound := range inbounds {
+ if inbound.Settings == "" {
+ continue
+ }
+
+ settings := map[string][]model.Client{}
+ json.Unmarshal([]byte(inbound.Settings), &settings)
+ clients := settings["clients"]
+
+ for _, client := range clients {
+ limitIp := client.LimitIP
+ if limitIp > 0 {
+ return true
+ }
+ }
+ }
+ return false
+}
+
func processLogFile() {
accessLogPath := GetAccessLogPath()
if accessLogPath == "" {
@@ -98,7 +128,7 @@ func processLogFile() {
}
}
-
+
time.Sleep(time.Second * 5)
//added 5 seconds delay before cleaning logs to reduce chance of logging IP that already has been banned
if shouldCleanLog {
@@ -211,11 +241,11 @@ func updateInboundClientIps(inboundClientIps *model.InboundClientIps, clientEmai
if limitIp < len(ips) && inbound.Enable {
disAllowedIps = append(disAllowedIps, ips[limitIp:]...)
- for i:=limitIp; i < len(ips); i++ {
+ for i := limitIp; i < len(ips); i++ {
logger.Info("[LIMIT_IP] Email=", clientEmail, " SRC=", ips[i])
}
}
- }
+ }
}
}
logger.Debug("disAllowedIps ", disAllowedIps)
@@ -252,4 +282,4 @@ func GetInboundByEmail(clientEmail string) (*model.Inbound, error) {
return nil, err
}
return inbounds, nil
-} \ No newline at end of file
+}