From 1d9fd01bae859561cf303a20c6f2e370fdecb772 Mon Sep 17 00:00:00 2001 From: Hamidreza Ghavami <70919649+hamid-gh98@users.noreply.github.com> Date: Fri, 12 May 2023 19:29:02 +0430 Subject: [PATCH 01/16] only get enabled inbounds and clients --- web/service/sub.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/web/service/sub.go b/web/service/sub.go index 9a86c3eb..bc34366f 100644 --- a/web/service/sub.go +++ b/web/service/sub.go @@ -38,7 +38,7 @@ func (s *SubService) GetSubs(subId string, host string) ([]string, string, error continue } for _, client := range clients { - if client.SubID == subId { + if client.Enable && client.SubID == subId { link := s.getLink(inbound, client.Email) result = append(result, link) clientTraffics = append(clientTraffics, s.getClientTraffics(inbound.ClientStats, client.Email)) @@ -73,7 +73,7 @@ func (s *SubService) GetSubs(subId string, host string) ([]string, string, error func (s *SubService) getInboundsBySubId(subId string) ([]*model.Inbound, error) { db := database.GetDB() var inbounds []*model.Inbound - err := db.Model(model.Inbound{}).Preload("ClientStats").Where("settings like ?", fmt.Sprintf(`%%"subId": "%s"%%`, subId)).Find(&inbounds).Error + err := db.Model(model.Inbound{}).Preload("ClientStats").Where("settings like ? and enable = ?", fmt.Sprintf(`%%"subId": "%s"%%`, subId), true).Find(&inbounds).Error if err != nil && err != gorm.ErrRecordNotFound { return nil, err } From f9d242bb48507a794494ed7f0348630db42d8395 Mon Sep 17 00:00:00 2001 From: Hamidreza Ghavami <70919649+hamid-gh98@users.noreply.github.com> Date: Fri, 12 May 2023 19:30:49 +0430 Subject: [PATCH 02/16] add check for geosite function --- web/html/xui/settings.html | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/web/html/xui/settings.html b/web/html/xui/settings.html index d50822c2..d4b4c028 100644 --- a/web/html/xui/settings.html +++ b/web/html/xui/settings.html @@ -307,6 +307,9 @@ }, } }, + created() { + this.checkForGeosites(); + }, methods: { loading(spinning = true, obj) { if (obj == null) this.spinning = spinning; @@ -401,6 +404,27 @@ this.saveBtnDisable = true; } }, + checkForGeosites() { + const domainsToCheck = [ + { + query: "category-ru-gov", + key: "this.settingsData.domains.ru", + data: [ + "geosite:category-ru-gov", + "regexp:.*\\.ru$" + ] + }, + ]; + this.loading(true); + domainsToCheck.forEach(async (dd) => { + const msg = await HttpUtil.get(`/xui/setting/searchDatafiles?query=${dd.query}`); + if (msg.success && msg.obj) { + [dd.key] = dd.data; + console.log([dd.key]) + } + }) + this.loading(false); + }, checkRequiredOutbounds() { const newTemplateSettings = this.templateSettings; const haveIPv4Outbounds = newTemplateSettings.outbounds.some((o) => o?.tag === "IPv4"); From 431d608faa0c4cf49012e39a760dada114b6af61 Mon Sep 17 00:00:00 2001 From: Hamidreza Ghavami <70919649+hamid-gh98@users.noreply.github.com> Date: Fri, 12 May 2023 19:32:04 +0430 Subject: [PATCH 03/16] add searchDatafiles route --- web/controller/index.go | 1 - web/controller/setting.go | 18 ++++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/web/controller/index.go b/web/controller/index.go index 802f3f7d..5b97a7cc 100644 --- a/web/controller/index.go +++ b/web/controller/index.go @@ -101,5 +101,4 @@ func (a *IndexController) getSecretStatus(c *gin.Context) { if err == nil { jsonObj(c, status, nil) } - } diff --git a/web/controller/setting.go b/web/controller/setting.go index bd9c2a5f..248f3ee5 100644 --- a/web/controller/setting.go +++ b/web/controller/setting.go @@ -3,6 +3,7 @@ package controller import ( "errors" "time" + "x-ui/util/common" "x-ui/web/entity" "x-ui/web/service" "x-ui/web/session" @@ -44,6 +45,7 @@ func (a *SettingController) initRouter(g *gin.RouterGroup) { g.GET("/getDefaultJsonConfig", a.getDefaultJsonConfig) g.POST("/updateUserSecret", a.updateSecret) g.POST("/getUserSecret", a.getUserSecret) + g.GET("/searchDatafiles", a.searchDatafiles) } func (a *SettingController) getAllSetting(c *gin.Context) { @@ -149,6 +151,7 @@ func (a *SettingController) updateSecret(c *gin.Context) { } jsonMsg(c, I18n(c, "pages.settings.toasts.modifyUser"), err) } + func (a *SettingController) getUserSecret(c *gin.Context) { loginUser := session.GetLoginUser(c) user := a.userService.GetUserSecret(loginUser.Id) @@ -156,3 +159,18 @@ func (a *SettingController) getUserSecret(c *gin.Context) { jsonObj(c, user, nil) } } + +func (a *SettingController) searchDatafiles(c *gin.Context) { + searchString := c.Query("query") + if searchString == "" { + err := common.NewError("data query parameter is empty") + jsonMsg(c, "Invalid query:", err) + return + } + found, err := a.settingService.SearchDatafiles(searchString) + if err != nil { + jsonMsg(c, "Something went wrong!", err) + return + } + jsonObj(c, found, nil) +} From 4adc1580120a0a9a222a03b5a64f20d26b86a162 Mon Sep 17 00:00:00 2001 From: Hamidreza Ghavami <70919649+hamid-gh98@users.noreply.github.com> Date: Fri, 12 May 2023 19:33:10 +0430 Subject: [PATCH 04/16] add service function to search data files --- web/service/setting.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/web/service/setting.go b/web/service/setting.go index d3072252..6635bf48 100644 --- a/web/service/setting.go +++ b/web/service/setting.go @@ -1,10 +1,12 @@ package service import ( + "bufio" _ "embed" "encoding/json" "errors" "fmt" + "os" "reflect" "strconv" "strings" @@ -16,6 +18,7 @@ import ( "x-ui/util/random" "x-ui/util/reflect_util" "x-ui/web/entity" + "x-ui/xray" ) //go:embed config.json @@ -351,3 +354,27 @@ func (s *SettingService) UpdateAllSetting(allSetting *entity.AllSetting) error { } return common.Combine(errs...) } + +func (s *SettingService) SearchDatafiles(query string) (bool, error) { + // Open the file for reading + file, err := os.Open(xray.GetGeositePath()) + if err != nil { + return false, common.NewErrorf("Error opening geosite.dat: %v", err) + } + defer file.Close() + + // Create a scanner to read the file line-by-line + scanner := bufio.NewScanner(file) + for scanner.Scan() { + line := scanner.Text() + if strings.Contains(strings.ToLower(line), strings.ToLower(query)) { + return true, nil + } + } + + err = scanner.Err() + if err != nil { + return false, common.NewErrorf("Error while scanning geosite.dat: %v", err) + } + return false, nil +} From 733fd2ffdb3812c66baf772d86b2f74d91a8d44f Mon Sep 17 00:00:00 2001 From: Hamidreza Ghavami <70919649+hamid-gh98@users.noreply.github.com> Date: Fri, 12 May 2023 21:53:05 +0430 Subject: [PATCH 05/16] Show client email in QR Modal --- web/html/common/qrcode_modal.html | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/web/html/common/qrcode_modal.html b/web/html/common/qrcode_modal.html index 2bd2f00f..855c349a 100644 --- a/web/html/common/qrcode_modal.html +++ b/web/html/common/qrcode_modal.html @@ -7,7 +7,10 @@ {{ i18n "pages.inbounds.clickOnQRcode" }} - + + {{ i18n "pages.inbounds.email" }}: "[[ qrModal.clientName ]]" + +