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>2025-09-18 14:56:04 +0300
committermhsanaei <ho3ein.sanaei@gmail.com>2025-09-18 14:56:04 +0300
commit59ea2645db827335a0689d2fb7aeeef4e52af52b (patch)
treea52caa80571fef4919c3df59a4bceacd60ba6aa6 /web/service
parent8c8d280f147ce4e8f604080d1dbf066332e55efc (diff)
new: subJsonEnable
after this subEnable by default is true and subJsonEnable is false
Diffstat (limited to 'web/service')
-rw-r--r--web/service/setting.go21
-rw-r--r--web/service/tgbot.go30
2 files changed, 36 insertions, 15 deletions
diff --git a/web/service/setting.go b/web/service/setting.go
index a54eaea7..39961ad5 100644
--- a/web/service/setting.go
+++ b/web/service/setting.go
@@ -50,7 +50,8 @@ var defaultValueMap = map[string]string{
"tgLang": "en-US",
"twoFactorEnable": "false",
"twoFactorToken": "",
- "subEnable": "false",
+ "subEnable": "true",
+ "subJsonEnable": "false",
"subTitle": "",
"subListen": "",
"subPort": "2096",
@@ -427,6 +428,10 @@ func (s *SettingService) GetSubEnable() (bool, error) {
return s.getBool("subEnable")
}
+func (s *SettingService) GetSubJsonEnable() (bool, error) {
+ return s.getBool("subJsonEnable")
+}
+
func (s *SettingService) GetSubTitle() (string, error) {
return s.getString("subTitle")
}
@@ -575,6 +580,7 @@ func (s *SettingService) GetDefaultSettings(host string) (any, error) {
"defaultKey": func() (any, error) { return s.GetKeyFile() },
"tgBotEnable": func() (any, error) { return s.GetTgbotEnabled() },
"subEnable": func() (any, error) { return s.GetSubEnable() },
+ "subJsonEnable": func() (any, error) { return s.GetSubJsonEnable() },
"subTitle": func() (any, error) { return s.GetSubTitle() },
"subURI": func() (any, error) { return s.GetSubURI() },
"subJsonURI": func() (any, error) { return s.GetSubJsonURI() },
@@ -593,7 +599,14 @@ func (s *SettingService) GetDefaultSettings(host string) (any, error) {
result[key] = value
}
- if result["subEnable"].(bool) && (result["subURI"].(string) == "" || result["subJsonURI"].(string) == "") {
+ subEnable := result["subEnable"].(bool)
+ subJsonEnable := false
+ if v, ok := result["subJsonEnable"]; ok {
+ if b, ok2 := v.(bool); ok2 {
+ subJsonEnable = b
+ }
+ }
+ if (subEnable && result["subURI"].(string) == "") || (subJsonEnable && result["subJsonURI"].(string) == "") {
subURI := ""
subTitle, _ := s.GetSubTitle()
subPort, _ := s.GetSubPort()
@@ -619,13 +632,13 @@ func (s *SettingService) GetDefaultSettings(host string) (any, error) {
} else {
subURI += fmt.Sprintf("%s:%d", subDomain, subPort)
}
- if result["subURI"].(string) == "" {
+ if subEnable && result["subURI"].(string) == "" {
result["subURI"] = subURI + subPath
}
if result["subTitle"].(string) == "" {
result["subTitle"] = subTitle
}
- if result["subJsonURI"].(string) == "" {
+ if subJsonEnable && result["subJsonURI"].(string) == "" {
result["subJsonURI"] = subURI + subJsonPath
}
}
diff --git a/web/service/tgbot.go b/web/service/tgbot.go
index f21af6cc..dd6ac196 100644
--- a/web/service/tgbot.go
+++ b/web/service/tgbot.go
@@ -2093,6 +2093,7 @@ func (t *Tgbot) buildSubscriptionURLs(email string) (string, string, error) {
subPort, _ := t.settingService.GetSubPort()
subPath, _ := t.settingService.GetSubPath()
subJsonPath, _ := t.settingService.GetSubJsonPath()
+ subJsonEnable, _ := t.settingService.GetSubJsonEnable()
subKeyFile, _ := t.settingService.GetSubKeyFile()
subCertFile, _ := t.settingService.GetSubCertFile()
@@ -2137,6 +2138,9 @@ func (t *Tgbot) buildSubscriptionURLs(email string) (string, string, error) {
subURL := fmt.Sprintf("%s://%s%s%s", scheme, host, subPath, client.SubID)
subJsonURL := fmt.Sprintf("%s://%s%s%s", scheme, host, subJsonPath, client.SubID)
+ if !subJsonEnable {
+ subJsonURL = ""
+ }
return subURL, subJsonURL, nil
}
@@ -2146,8 +2150,10 @@ func (t *Tgbot) sendClientSubLinks(chatId int64, email string) {
t.SendMsgToTgbot(chatId, t.I18nBot("tgbot.answers.errorOperation")+"\r\n"+err.Error())
return
}
- msg := "Subscription URL:\r\n<code>" + subURL + "</code>\r\n\r\n" +
- "JSON URL:\r\n<code>" + subJsonURL + "</code>"
+ msg := "Subscription URL:\r\n<code>" + subURL + "</code>"
+ if subJsonURL != "" {
+ msg += "\r\n\r\nJSON URL:\r\n<code>" + subJsonURL + "</code>"
+ }
inlineKeyboard := tu.InlineKeyboard(
tu.InlineKeyboardRow(
tu.InlineKeyboardButton(t.I18nBot("subscription.individualLinks")).WithCallbackData(t.encodeQuery("client_individual_links "+email)),
@@ -2271,15 +2277,17 @@ func (t *Tgbot) sendClientQRLinks(chatId int64, email string) {
t.SendMsgToTgbot(chatId, t.I18nBot("tgbot.answers.errorOperation")+"\r\n"+err.Error())
}
- // Send JSON URL QR (filename: subjson.png)
- if png, err := createQR(subJsonURL, 320); err == nil {
- document := tu.Document(
- tu.ID(chatId),
- tu.FileFromBytes(png, "subjson.png"),
- )
- _, _ = bot.SendDocument(context.Background(), document)
- } else {
- t.SendMsgToTgbot(chatId, t.I18nBot("tgbot.answers.errorOperation")+"\r\n"+err.Error())
+ // Send JSON URL QR (filename: subjson.png) when available
+ if subJsonURL != "" {
+ if png, err := createQR(subJsonURL, 320); err == nil {
+ document := tu.Document(
+ tu.ID(chatId),
+ tu.FileFromBytes(png, "subjson.png"),
+ )
+ _, _ = bot.SendDocument(context.Background(), document)
+ } else {
+ t.SendMsgToTgbot(chatId, t.I18nBot("tgbot.answers.errorOperation")+"\r\n"+err.Error())
+ }
}
// Also generate a few individual links' QRs (first up to 5)