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
path: root/web
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 /web
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
Diffstat (limited to 'web')
-rw-r--r--web/html/xui/client_modal.html23
-rw-r--r--web/job/check_client_ip_job.go40
2 files changed, 48 insertions, 15 deletions
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
+}