Skip to content

Commit d30cdbf

Browse files
authored
feat: custom subscription title in panel (#2773)
* feat: custom subscription title in panel * feat: added translations
1 parent cac0022 commit d30cdbf

19 files changed

+56
-3
lines changed

sub/sub.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,16 @@ func (s *Server) initRouter() (*gin.Engine, error) {
107107
SubJsonRules = ""
108108
}
109109

110+
SubTitle, err := s.settingService.GetSubTitle()
111+
if err != nil {
112+
SubTitle = ""
113+
}
114+
110115
g := engine.Group("/")
111116

112117
s.sub = NewSUBController(
113118
g, LinksPath, JsonPath, Encrypt, ShowInfo, RemarkModel, SubUpdates,
114-
SubJsonFragment, SubJsonNoises, SubJsonMux, SubJsonRules)
119+
SubJsonFragment, SubJsonNoises, SubJsonMux, SubJsonRules, SubTitle)
115120

116121
return engine, nil
117122
}

sub/subController.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
)
1010

1111
type SUBController struct {
12+
subTitle string
1213
subPath string
1314
subJsonPath string
1415
subEncrypt bool
@@ -30,9 +31,11 @@ func NewSUBController(
3031
jsonNoise string,
3132
jsonMux string,
3233
jsonRules string,
34+
subTitle string,
3335
) *SUBController {
3436
sub := NewSubService(showInfo, rModel)
3537
a := &SUBController{
38+
subTitle: subTitle,
3639
subPath: subPath,
3740
subJsonPath: jsonPath,
3841
subEncrypt: encrypt,
@@ -82,7 +85,7 @@ func (a *SUBController) subs(c *gin.Context) {
8285
// Add headers
8386
c.Writer.Header().Set("Subscription-Userinfo", header)
8487
c.Writer.Header().Set("Profile-Update-Interval", a.updateInterval)
85-
c.Writer.Header().Set("Profile-Title", subId)
88+
c.Writer.Header().Set("Profile-Title", a.subTitle)
8689

8790
if a.subEncrypt {
8891
c.String(200, base64.StdEncoding.EncodeToString([]byte(result)))
@@ -116,7 +119,7 @@ func (a *SUBController) subJsons(c *gin.Context) {
116119
// Add headers
117120
c.Writer.Header().Set("Subscription-Userinfo", header)
118121
c.Writer.Header().Set("Profile-Update-Interval", a.updateInterval)
119-
c.Writer.Header().Set("Profile-Title", subId)
122+
c.Writer.Header().Set("Profile-Title", a.subTitle)
120123

121124
c.String(200, jsonSub)
122125
}

web/assets/js/model/setting.js

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class AllSetting {
2626
this.xrayTemplateConfig = "";
2727
this.secretEnable = false;
2828
this.subEnable = false;
29+
this.subTitle = "";
2930
this.subListen = "";
3031
this.subPort = 2096;
3132
this.subPath = "/sub/";

web/entity/entity.go

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ type AllSetting struct {
4040
TimeLocation string `json:"timeLocation" form:"timeLocation"`
4141
SecretEnable bool `json:"secretEnable" form:"secretEnable"`
4242
SubEnable bool `json:"subEnable" form:"subEnable"`
43+
SubTitle string `json:"subTitle" form:"subTitle"`
4344
SubListen string `json:"subListen" form:"subListen"`
4445
SubPort int `json:"subPort" form:"subPort"`
4546
SubPath string `json:"subPath" form:"subPath"`

web/html/xui/inbounds.html

+2
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,7 @@
662662
refreshInterval: Number(localStorage.getItem("refreshInterval")) || 5000,
663663
subSettings: {
664664
enable : false,
665+
subTitle : '',
665666
subURI : '',
666667
subJsonURI : '',
667668
},
@@ -711,6 +712,7 @@
711712
this.tgBotEnable = tgBotEnable;
712713
this.subSettings = {
713714
enable : subEnable,
715+
subTitle : subTitle,
714716
subURI: subURI,
715717
subJsonURI: subJsonURI
716718
};

web/html/xui/settings.html

+7
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,13 @@
409409
<a-switch v-model="allSetting.subEnable"></a-switch>
410410
</template>
411411
</a-setting-list-item>
412+
<a-setting-list-item paddings="small">
413+
<template #title>{{ i18n "pages.settings.subTitle"}}</template>
414+
<template #description>{{ i18n "pages.settings.subTitleDesc"}}</template>
415+
<template #control>
416+
<a-input type="text" v-model="allSetting.subTitle"></a-input>
417+
</template>
418+
</a-setting-list-item>
412419
<a-setting-list-item paddings="small">
413420
<template #title>{{ i18n "pages.settings.subListen"}}</template>
414421
<template #description>{{ i18n "pages.settings.subListenDesc"}}</template>

web/service/setting.go

+10
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ var defaultValueMap = map[string]string{
5050
"tgLang": "en-US",
5151
"secretEnable": "false",
5252
"subEnable": "false",
53+
"subTitle": "",
5354
"subListen": "",
5455
"subPort": "2096",
5556
"subPath": "/sub/",
@@ -418,6 +419,10 @@ func (s *SettingService) GetSubEnable() (bool, error) {
418419
return s.getBool("subEnable")
419420
}
420421

422+
func (s *SettingService) GetSubTitle() (string, error) {
423+
return s.getString("subTitle")
424+
}
425+
421426
func (s *SettingService) GetSubListen() (string, error) {
422427
return s.getString("subListen")
423428
}
@@ -562,6 +567,7 @@ func (s *SettingService) GetDefaultSettings(host string) (any, error) {
562567
"defaultKey": func() (any, error) { return s.GetKeyFile() },
563568
"tgBotEnable": func() (any, error) { return s.GetTgbotEnabled() },
564569
"subEnable": func() (any, error) { return s.GetSubEnable() },
570+
"subTitle": func() (any, error) { return s.GetSubTitle() },
565571
"subURI": func() (any, error) { return s.GetSubURI() },
566572
"subJsonURI": func() (any, error) { return s.GetSubJsonURI() },
567573
"remarkModel": func() (any, error) { return s.GetRemarkModel() },
@@ -581,6 +587,7 @@ func (s *SettingService) GetDefaultSettings(host string) (any, error) {
581587

582588
if result["subEnable"].(bool) && (result["subURI"].(string) == "" || result["subJsonURI"].(string) == "") {
583589
subURI := ""
590+
subTitle, _ := s.GetSubTitle()
584591
subPort, _ := s.GetSubPort()
585592
subPath, _ := s.GetSubPath()
586593
subJsonPath, _ := s.GetSubJsonPath()
@@ -607,6 +614,9 @@ func (s *SettingService) GetDefaultSettings(host string) (any, error) {
607614
if result["subURI"].(string) == "" {
608615
result["subURI"] = subURI + subPath
609616
}
617+
if result["subTitle"].(string) == "" {
618+
result["subTitle"] = subTitle
619+
}
610620
if result["subJsonURI"].(string) == "" {
611621
result["subJsonURI"] = subURI + subJsonPath
612622
}

web/translation/translate.en_US.toml

+2
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,8 @@
292292
"subSettings" = "Subscription"
293293
"subEnable" = "Enable Subscription Service"
294294
"subEnableDesc" = "Enables the subscription service."
295+
"subTitle" = "Subscription Title"
296+
"subTitleDesc" = "Title shown in VPN client"
295297
"subListen" = "Listen IP"
296298
"subListenDesc" = "The IP address for the subscription service. (leave blank to listen on all IPs)"
297299
"subPort" = "Listen Port"

web/translation/translate.es_ES.toml

+2
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,8 @@
292292
"subSettings" = "Suscripción"
293293
"subEnable" = "Habilitar Servicio"
294294
"subEnableDesc" = "Función de suscripción con configuración separada."
295+
"subTitle" = "Título de la Suscripción"
296+
"subTitleDesc" = "Título mostrado en el cliente de VPN"
295297
"subListen" = "Listening IP"
296298
"subListenDesc" = "Dejar en blanco por defecto para monitorear todas las IPs."
297299
"subPort" = "Puerto de Suscripción"

web/translation/translate.fa_IR.toml

+2
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,8 @@
292292
"subSettings" = "سابسکریپشن"
293293
"subEnable" = "فعال‌سازی سرویس سابسکریپشن"
294294
"subEnableDesc" = "سرویس سابسکریپشن‌ را فعال‌می‌کند"
295+
"subTitle" = "عنوان اشتراک"
296+
"subTitleDesc" = "عنوان نمایش داده شده در کلاینت VPN"
295297
"subListen" = "آدرس آی‌پی"
296298
"subListenDesc" = "آدرس آی‌پی برای سرویس سابسکریپشن. برای گوش دادن به‌تمام آی‌پی‌ها خالی‌بگذارید"
297299
"subPort" = "پورت"

web/translation/translate.id_ID.toml

+2
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,8 @@
292292
"subSettings" = "Langganan"
293293
"subEnable" = "Aktifkan Layanan Langganan"
294294
"subEnableDesc" = "Mengaktifkan layanan langganan."
295+
"subTitle" = "Judul Langganan"
296+
"subTitleDesc" = "Judul yang ditampilkan di klien VPN"
295297
"subListen" = "IP Pendengar"
296298
"subListenDesc" = "Alamat IP untuk layanan langganan. (biarkan kosong untuk mendengarkan semua IP)"
297299
"subPort" = "Port Pendengar"

web/translation/translate.ja_JP.toml

+2
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,8 @@
292292
"subSettings" = "サブスクリプション設定"
293293
"subEnable" = "サブスクリプションサービスを有効にする"
294294
"subEnableDesc" = "サブスクリプションサービス機能を有効にする"
295+
"subTitle" = "サブスクリプションタイトル"
296+
"subTitleDesc" = "VPNクライアントに表示されるタイトル"
295297
"subListen" = "監視IP"
296298
"subListenDesc" = "サブスクリプションサービスが監視するIPアドレス(空白にするとすべてのIPを監視)"
297299
"subPort" = "監視ポート"

web/translation/translate.pt_BR.toml

+2
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,8 @@
292292
"subSettings" = "Assinatura"
293293
"subEnable" = "Ativar Serviço de Assinatura"
294294
"subEnableDesc" = "Ativa o serviço de assinatura."
295+
"subTitle" = "Título da Assinatura"
296+
"subTitleDesc" = "Título exibido no cliente VPN"
295297
"subListen" = "IP de Escuta"
296298
"subListenDesc" = "O endereço IP para o serviço de assinatura. (deixe em branco para escutar em todos os IPs)"
297299
"subPort" = "Porta de Escuta"

web/translation/translate.ru_RU.toml

+2
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,8 @@
292292
"subSettings" = "Подписка"
293293
"subEnable" = "Включить службу"
294294
"subEnableDesc" = "Функция подписки с отдельной конфигурацией"
295+
"subTitle" = "Заголовок подписки"
296+
"subTitleDesc" = "Название подписки, которое видит клиент в VPN клиенте"
295297
"subListen" = "Прослушивание IP"
296298
"subListenDesc" = "Оставьте пустым по умолчанию, чтобы отслеживать все IP-адреса"
297299
"subPort" = "Порт подписки"

web/translation/translate.tr_TR.toml

+2
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,8 @@
292292
"subSettings" = "Abonelik"
293293
"subEnable" = "Abonelik Hizmetini Etkinleştir"
294294
"subEnableDesc" = "Abonelik hizmetini etkinleştirir."
295+
"subTitle" = "Abonelik Başlığı"
296+
"subTitleDesc" = "VPN istemcisinde gösterilen başlık"
295297
"subListen" = "Dinleme IP"
296298
"subListenDesc" = "Abonelik hizmeti için IP adresi. (tüm IP'leri dinlemek için boş bırakın)"
297299
"subPort" = "Dinleme Portu"

web/translation/translate.uk_UA.toml

+2
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,8 @@
292292
"subSettings" = "Підписка"
293293
"subEnable" = "Увімкнути службу підписки"
294294
"subEnableDesc" = "Вмикає службу підписки."
295+
"subTitle" = "Назва Підписки"
296+
"subTitleDesc" = "Назва, яка відображається у VPN-клієнті"
295297
"subListen" = "Слухати IP"
296298
"subListenDesc" = "IP-адреса для служби підписки. (залиште порожнім, щоб слухати всі IP-адреси)"
297299
"subPort" = "Слухати порт"

web/translation/translate.vi_VN.toml

+2
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,8 @@
292292
"subSettings" = "Gói đăng ký"
293293
"subEnable" = "Bật dịch vụ"
294294
"subEnableDesc" = "Tính năng gói đăng ký với cấu hình riêng"
295+
"subTitle" = "Tiêu đề Đăng ký"
296+
"subTitleDesc" = "Tiêu đề hiển thị trong ứng dụng VPN"
295297
"subListen" = "Listening IP"
296298
"subListenDesc" = "Mặc định để trống để nghe tất cả các IP"
297299
"subPort" = "Cổng gói đăng ký"

web/translation/translate.zh_CN.toml

+2
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,8 @@
292292
"subSettings" = "订阅设置"
293293
"subEnable" = "启用订阅服务"
294294
"subEnableDesc" = "启用订阅服务功能"
295+
"subTitle" = "订阅标题"
296+
"subTitleDesc" = "在VPN客户端中显示的标题"
295297
"subListen" = "监听 IP"
296298
"subListenDesc" = "订阅服务监听的 IP 地址(留空表示监听所有 IP)"
297299
"subPort" = "监听端口"

web/translation/translate.zh_TW.toml

+2
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,8 @@
292292
"subSettings" = "訂閱設定"
293293
"subEnable" = "啟用訂閱服務"
294294
"subEnableDesc" = "啟用訂閱服務功能"
295+
"subTitle" = "訂閱標題"
296+
"subTitleDesc" = "在VPN客戶端中顯示的標題"
295297
"subListen" = "監聽 IP"
296298
"subListenDesc" = "訂閱服務監聽的 IP 地址(留空表示監聽所有 IP)"
297299
"subPort" = "監聽埠"

0 commit comments

Comments
 (0)