From 1c1f53267ad65b11c849c1c339c78b8c6daf78cb Mon Sep 17 00:00:00 2001 From: MHSanaei Date: Sat, 26 Aug 2023 16:54:01 +0330 Subject: [PATCH] Add encrypt subscription ON/OFF switch Co-Authored-By: SudoSpace <79229394+sudospaes@users.noreply.github.com> --- sub/subController.go | 7 ++++++- web/assets/js/model/models.js | 1 + web/controller/setting.go | 1 + web/entity/entity.go | 1 + web/html/xui/settings.html | 1 + web/service/setting.go | 5 +++++ web/translation/translate.en_US.toml | 2 ++ web/translation/translate.fa_IR.toml | 2 ++ web/translation/translate.ru_RU.toml | 2 ++ web/translation/translate.vi_VN.toml | 2 ++ web/translation/translate.zh_Hans.toml | 2 ++ 11 files changed, 25 insertions(+), 1 deletion(-) diff --git a/sub/subController.go b/sub/subController.go index b0e62ecf..5f7c69cf 100644 --- a/sub/subController.go +++ b/sub/subController.go @@ -26,6 +26,7 @@ func (a *SUBController) initRouter(g *gin.RouterGroup) { } func (a *SUBController) subs(c *gin.Context) { + subEncrypt, _ := a.settingService.GetSubEncrypt() subShowInfo, _ := a.settingService.GetSubShowInfo() subId := c.Param("subid") host := strings.Split(c.Request.Host, ":")[0] @@ -43,6 +44,10 @@ func (a *SUBController) subs(c *gin.Context) { c.Writer.Header().Set("Profile-Update-Interval", headers[1]) c.Writer.Header().Set("Profile-Title", headers[2]) - c.String(200, base64.StdEncoding.EncodeToString([]byte(result))) + if subEncrypt { + c.String(200, base64.StdEncoding.EncodeToString([]byte(result))) + } else { + c.String(200, result) + } } } diff --git a/web/assets/js/model/models.js b/web/assets/js/model/models.js index 1accec71..122145fb 100644 --- a/web/assets/js/model/models.js +++ b/web/assets/js/model/models.js @@ -194,6 +194,7 @@ class AllSetting { this.subCertFile = ""; this.subKeyFile = ""; this.subUpdates = 0; + this.subEncrypt = true; this.subShowInfo = true; this.timeLocation = "Asia/Tehran"; diff --git a/web/controller/setting.go b/web/controller/setting.go index d991633a..32eccefe 100644 --- a/web/controller/setting.go +++ b/web/controller/setting.go @@ -79,6 +79,7 @@ func (a *SettingController) getDefaultSettings(c *gin.Context) { "subDomain": func() (interface{}, error) { return a.settingService.GetSubDomain() }, "subKeyFile": func() (interface{}, error) { return a.settingService.GetSubKeyFile() }, "subCertFile": func() (interface{}, error) { return a.settingService.GetSubCertFile() }, + "subEncrypt": func() (interface{}, error) { return a.settingService.GetSubEncrypt() }, "subShowInfo": func() (interface{}, error) { return a.settingService.GetSubShowInfo() }, } diff --git a/web/entity/entity.go b/web/entity/entity.go index 10a6a97d..1428abe0 100644 --- a/web/entity/entity.go +++ b/web/entity/entity.go @@ -55,6 +55,7 @@ type AllSetting struct { SubCertFile string `json:"subCertFile" form:"subCertFile"` SubKeyFile string `json:"subKeyFile" form:"subKeyFile"` SubUpdates int `json:"subUpdates" form:"subUpdates"` + SubEncrypt bool `json:"subEncrypt" form:"subEncrypt"` SubShowInfo bool `json:"subShowInfo" form:"subShowInfo"` } diff --git a/web/html/xui/settings.html b/web/html/xui/settings.html index e1741302..b31ad04f 100644 --- a/web/html/xui/settings.html +++ b/web/html/xui/settings.html @@ -406,6 +406,7 @@ + diff --git a/web/service/setting.go b/web/service/setting.go index 6f38f1ef..b1565e1f 100644 --- a/web/service/setting.go +++ b/web/service/setting.go @@ -51,6 +51,7 @@ var defaultValueMap = map[string]string{ "subCertFile": "", "subKeyFile": "", "subUpdates": "12", + "subEncrypt": "true", "subShowInfo": "true", } @@ -397,6 +398,10 @@ func (s *SettingService) GetSubUpdates() (int, error) { return s.getInt("subUpdates") } +func (s *SettingService) GetSubEncrypt() (bool, error) { + return s.getBool("subEncrypt") +} + func (s *SettingService) GetSubShowInfo() (bool, error) { return s.getBool("subShowInfo") } diff --git a/web/translation/translate.en_US.toml b/web/translation/translate.en_US.toml index 5ac63f57..edf5510d 100644 --- a/web/translation/translate.en_US.toml +++ b/web/translation/translate.en_US.toml @@ -274,6 +274,8 @@ "subDomainDesc" = "Leave blank by default to monitor all domains and IPs" "subUpdates" = "Subscription update intervals" "subUpdatesDesc" = "Interval hours between updates in client application" +"subEncrypt" = "Encrypt configs" +"subEncryptDesc" = "Encrypt the returned configs in subscription" "subShowInfo" = "Show usage info" "subShowInfoDesc" = "Show remianed traffic and date after config name" diff --git a/web/translation/translate.fa_IR.toml b/web/translation/translate.fa_IR.toml index a145965d..02862c2f 100644 --- a/web/translation/translate.fa_IR.toml +++ b/web/translation/translate.fa_IR.toml @@ -274,6 +274,8 @@ "subDomainDesc" = "برای نظارت بر همه دامنه ها و آی‌پی ها به طور پیش فرض خالی بگذارید" "subUpdates" = "فاصله به روز رسانی های سابسکریپشن" "subUpdatesDesc" = "ساعت های فاصله بین به روز رسانی در برنامه کاربر" +"subEncrypt" = "رمزگذاری کانفیگ ها" +"subEncryptDesc" = "رمزگذاری کانفیگ های بازگشتی سابسکریپشن" "subShowInfo" = "نمایش اطلاعات مصرف" "subShowInfoDesc" = "ترافیک و زمان باقیمانده را در هر کانفیگ نمایش میدهد" diff --git a/web/translation/translate.ru_RU.toml b/web/translation/translate.ru_RU.toml index 53b6fedd..8587a585 100644 --- a/web/translation/translate.ru_RU.toml +++ b/web/translation/translate.ru_RU.toml @@ -274,6 +274,8 @@ "subDomainDesc" = "Оставьте пустым по умолчанию, чтобы отслеживать все домены и IP-адреса" "subUpdates" = "Интервалы обновления подписки" "subUpdatesDesc" = "Часовой интервал между обновлениями в клиентском приложении" +"subEncrypt" = "Шифровать конфиги" +"subEncryptDesc" = "Шифровать возвращенные конфиги в подписке" "subShowInfo" = "Показать информацию об использовании" "subShowInfoDesc" = "Показывать восстановленный трафик и дату после имени конфигурации" diff --git a/web/translation/translate.vi_VN.toml b/web/translation/translate.vi_VN.toml index 8ea0bfd2..691804e9 100644 --- a/web/translation/translate.vi_VN.toml +++ b/web/translation/translate.vi_VN.toml @@ -274,6 +274,8 @@ "subDomainDesc" = "Mặc định để trống để nghe tất cả các tên miền và IP" "subUpdates" = "Khoảng thời gian cập nhật đăng ký" "subUpdatesDesc" = "Số giờ giữa các cập nhật trong ứng dụng khách" +"subEncrypt" = "Mã hóa cấu hình" +"subEncryptDesc" = "Mã hóa các cấu hình được trả về trong đăng ký" "subShowInfo" = "Hiển thị thông tin sử dụng" "subShowInfoDesc" = "Hiển thị lưu lượng truy cập còn lại và ngày sau tên cấu hình" diff --git a/web/translation/translate.zh_Hans.toml b/web/translation/translate.zh_Hans.toml index fa9b84a3..581e67ee 100644 --- a/web/translation/translate.zh_Hans.toml +++ b/web/translation/translate.zh_Hans.toml @@ -274,6 +274,8 @@ "subDomainDesc" = "留空默认监控所有域名和IP" "subUpdates" = "订阅更新间隔" "subUpdatesDesc" = "客户端应用程序更新之间的间隔时间" +"subEncrypt" = "加密配置" +"subEncryptDesc" = "在订阅中加密返回的配置" "subShowInfo" = "显示使用信息" "subShowInfoDesc" = "在配置名称后显示剩余流量和日期"