feat(sub): make external subscription fetch User-Agent configurable (#6613)
* feat(sub): make external subscription fetch User-Agent configurable Some providers reject fetches that do not send a known client User-Agent. Expose externalSubUserAgent as a panel setting (default v2rayNG/1.8.5) and use it when fetching client external subscription URLs. Fixes #6383 * ci: retrigger frontend after npm registry maintenance The frontend job failed solely on `npm audit` while registry.npmjs.org returned 503 (Service Under Maintenance). Lint, typecheck, vitest, vite build, and storybook all passed. Local `npm audit --omit=dev --audit-level=high` now reports 0 vulnerabilities. * fix(sub): fall back to the default UA when the DB is not initialised externalSubUserAgent read the setting through SettingService.getSetting, which calls Model() on database.GetDB() and panics on a nil *gorm.DB. The fetch path's other DB read, service.ExternalSubscriptionHwid, already treats a nil DB as unreachable and sends no header; the new UA lookup did not, so any fetch before InitDB panicked instead of sending the historical v2rayNG/1.8.5. Production initialises the DB before the sub server starts, but the internal/sub fetch tests run without one: under make test-go's -shuffle=on, whenever one of them ran before the first InitDB test the panic aborted the whole package. Reproduced deterministically with go test -run '^TestDoFetchSubscriptionLinks_RejectsOversizedBody$'. --------- Co-authored-by: mrchatam <mrchatam@users.noreply.github.com> Co-authored-by: MHSanaei <ho3ein.sanaei@gmail.com>
This commit is contained in:
1 parent
9672249edb
commit
bd9ccde1f4
26 files changed
+161
-1
No files matched your search
@@ -107,6 +107,7 @@ type AllSetting struct {
|
||||
SubDomain string `json:"subDomain" form:"subDomain"`
|
||||
SubCertFile string `json:"subCertFile" form:"subCertFile"`
|
||||
SubKeyFile string `json:"subKeyFile" form:"subKeyFile"`
|
||||
ExternalSubUserAgent string `json:"externalSubUserAgent" form:"externalSubUserAgent"`
|
||||
SubUpdates int `json:"subUpdates" form:"subUpdates" validate:"gte=0,lte=525600"`
|
||||
ExternalTrafficInformEnable bool `json:"externalTrafficInformEnable" form:"externalTrafficInformEnable"`
|
||||
ExternalTrafficInformURI string `json:"externalTrafficInformURI" form:"externalTrafficInformURI"`
|
||||
|
||||
@@ -36,6 +36,7 @@ var xrayTemplateConfig string
|
||||
|
||||
const (
|
||||
DefaultSubClashUserAgentRegex = `(?i)(clash|mihomo)`
|
||||
DefaultExternalSubUserAgent = "v2rayNG/1.8.5"
|
||||
DefaultSubJsonUserAgentRegex = ``
|
||||
DefaultRemarkTemplate = "{{INBOUND}}-{{EMAIL}}|📊{{TRAFFIC_LEFT}}|⏳{{DAYS_LEFT}}D"
|
||||
DefaultSubExpiredTemplate = "⛔ {{EMAIL}} | Expired: {{EXPIRE_DATE}}"
|
||||
@@ -146,6 +147,7 @@ var defaultValueMap = map[string]string{
|
||||
"subDomain": "",
|
||||
"subCertFile": "",
|
||||
"subKeyFile": "",
|
||||
"externalSubUserAgent": DefaultExternalSubUserAgent,
|
||||
"subUpdates": "12",
|
||||
"subEncrypt": "true",
|
||||
"subURI": "",
|
||||
@@ -1052,6 +1054,17 @@ func (s *SettingService) GetSubUpdates() (string, error) {
|
||||
return s.getString("subUpdates")
|
||||
}
|
||||
|
||||
func (s *SettingService) GetExternalSubUserAgent() (string, error) {
|
||||
value, err := s.getString("externalSubUserAgent")
|
||||
if err != nil {
|
||||
return DefaultExternalSubUserAgent, err
|
||||
}
|
||||
if value = strings.TrimSpace(value); value == "" {
|
||||
return DefaultExternalSubUserAgent, nil
|
||||
}
|
||||
return value, nil
|
||||
}
|
||||
|
||||
func (s *SettingService) GetSubEncrypt() (bool, error) {
|
||||
return s.getBool("subEncrypt")
|
||||
}
|
||||
|
||||
@@ -1273,6 +1273,8 @@
|
||||
"subDomainDesc": "اسم الدومين لخدمة الاشتراك. (سيبه فاضي عشان يستمع على كل الدومينات والـ IPs). كمان بيتستخدم كدومين افتراضي لرابط الاشتراك اللي بيظهر لو حقل «مسار البروكسي العكسي» فاضي — املا «مسار البروكسي العكسي» لو اللوحة والاشتراك بيتفتحوا من دومينات مختلفة (زي لما يكونوا ورا بروكسي عكسي).",
|
||||
"subUpdates": "فترات التحديث",
|
||||
"subUpdatesDesc": "فترات تحديث رابط الاشتراك في تطبيقات العملاء. (الوحدة: ساعة)",
|
||||
"externalSubUserAgent": "User-Agent للاشتراك الخارجي",
|
||||
"externalSubUserAgentDesc": "ترويسة User-Agent عند جلب رابط الاشتراك الخارجي للعميل. اتركه فارغًا لاستخدام الافتراضي (v2rayNG/1.8.5). بعض المزودين يرفضون العملاء غير المعروفين.",
|
||||
"subEncrypt": "تشفير",
|
||||
"subEncryptDesc": "المحتوى اللي هيترجع من خدمة الاشتراك هيكون مشفر بـ Base64.",
|
||||
"subURI": "مسار البروكسي العكسي",
|
||||
|
||||
Loaded 3 of 26 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user