mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-09-16 15:17:14 +00:00
feat(settings): add setting for Reality scan candidates (#6471)
* feat(settings): allow customizing Reality scan candidate list Persist a realityScanCandidates panel setting (defaulting to the previous hardcoded list), expose it in General Settings with i18n, and have the Find Targets scanner use it when the search box is empty. Fixes #5847 * style(frontend): oxfmt realityScanCandidates in setting.ts * Fix locale JSON syntax This change removes the malformed duplicate key and missing comma in the Android per-app proxy translations across the bundled locale files. The JSON now parses correctly while preserving the translated labels for each language. * docs(i18n): update Happ translations Localize the remaining Happ subscription settings strings across the translation files and refine the English copy. This aligns the labels and descriptions with the current Happ behavior for notifications, TUN options, HWID enforcement, routing presets, and per-app proxy settings. * refactor(reality): drop test-only scaffolding from the candidate setting TestDefaultRealityScanCandidatesCSV compared the CSV against its own initializer and a defaultValueMap lookup, and TestRealityScanCandidateTokensFallsBackWithoutDB drove a no-database state no production caller reaches (the only caller is the scanRealityTargets handler, served after InitDB). The s != nil && GetDB() != nil guard existed only for that second test. None of them could fail except in lockstep with the code they restate. * docs(api): describe the setting-driven scanRealityTargets fallback An empty targets value now probes the realityScanCandidates setting, but the endpoint summary, parameter description and handler comment still promised the built-in seed list, so API consumers were told the wrong target set. Regenerated openapi.json and synced the docs copy, which also lacked the new AllSetting field in the settings reference. --------- Co-authored-by: mrchatam <287639636+mrchatam@users.noreply.github.com> Co-authored-by: Sanaei <ho3ein.sanaei@gmail.com>
This commit is contained in:
@@ -39,6 +39,10 @@ var defaultRealityScanCandidates = []string{
|
||||
"dl.google.com:443",
|
||||
}
|
||||
|
||||
// DefaultRealityScanCandidatesCSV is the shipped default for the
|
||||
// realityScanCandidates setting (comma-separated host:port list).
|
||||
var DefaultRealityScanCandidatesCSV = strings.Join(defaultRealityScanCandidates, ",")
|
||||
|
||||
type RealityScanResult struct {
|
||||
Target string `json:"target" example:"www.cloudflare.com:443"`
|
||||
Host string `json:"host" example:"www.cloudflare.com"`
|
||||
@@ -331,15 +335,32 @@ func (s *ServerService) ScanRealityTarget(target string, sni string, xver int, a
|
||||
return s.probeRealityAddr(host, port, sni, realityScanTimeout, xver, allowPrivate), nil
|
||||
}
|
||||
|
||||
func (s *ServerService) ScanRealityTargets(targetsCSV string) ([]*RealityScanResult, error) {
|
||||
func parseRealityScanCandidateCSV(csv string) []string {
|
||||
var tokens []string
|
||||
for raw := range strings.SplitSeq(targetsCSV, ",") {
|
||||
for raw := range strings.SplitSeq(csv, ",") {
|
||||
if t := strings.TrimSpace(raw); t != "" {
|
||||
tokens = append(tokens, t)
|
||||
}
|
||||
}
|
||||
return tokens
|
||||
}
|
||||
|
||||
// realityScanCandidateTokens returns the operator-configured candidate list,
|
||||
// falling back to the shipped defaults when the setting is empty or unreadable.
|
||||
func (s *ServerService) realityScanCandidateTokens() []string {
|
||||
csv, err := s.settingService.GetRealityScanCandidates()
|
||||
if err != nil {
|
||||
logger.Warning("reality scan: reading candidates setting failed:", err)
|
||||
} else if tokens := parseRealityScanCandidateCSV(csv); len(tokens) > 0 {
|
||||
return tokens
|
||||
}
|
||||
return append([]string(nil), defaultRealityScanCandidates...)
|
||||
}
|
||||
|
||||
func (s *ServerService) ScanRealityTargets(targetsCSV string) ([]*RealityScanResult, error) {
|
||||
tokens := parseRealityScanCandidateCSV(targetsCSV)
|
||||
if len(tokens) == 0 {
|
||||
tokens = append(tokens, defaultRealityScanCandidates...)
|
||||
tokens = s.realityScanCandidateTokens()
|
||||
}
|
||||
|
||||
var tasks []realityProbeTask
|
||||
|
||||
@@ -164,3 +164,19 @@ func TestWriteProxyProtocolV2Signature(t *testing.T) {
|
||||
t.Fatalf("v2 family/protocol byte = 0x%02x, want 0x11 (TCP over IPv4)", hdr[13])
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseRealityScanCandidateCSV(t *testing.T) {
|
||||
got := parseRealityScanCandidateCSV(" a.com:443 , ,b.com:8443 ")
|
||||
want := []string{"a.com:443", "b.com:8443"}
|
||||
if len(got) != len(want) {
|
||||
t.Fatalf("got %v, want %v", got, want)
|
||||
}
|
||||
for i := range want {
|
||||
if got[i] != want[i] {
|
||||
t.Fatalf("got %v, want %v", got, want)
|
||||
}
|
||||
}
|
||||
if tokens := parseRealityScanCandidateCSV(" , "); len(tokens) != 0 {
|
||||
t.Fatalf("empty CSV should yield no tokens, got %v", tokens)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,6 +67,7 @@ var defaultValueMap = map[string]string{
|
||||
"webBasePath": normalizeBasePath(getEnv("XUI_INIT_WEB_BASE_PATH", "/")),
|
||||
"sessionMaxAge": "360",
|
||||
"trustedProxyCIDRs": DefaultTrustedProxyCIDRs,
|
||||
"realityScanCandidates": DefaultRealityScanCandidatesCSV,
|
||||
"ipLimitAllowlist": "",
|
||||
"pageSize": "25",
|
||||
"expireDiff": "0",
|
||||
@@ -705,6 +706,10 @@ func (s *SettingService) GetTrustedProxyCIDRs() (string, error) {
|
||||
return s.getString("trustedProxyCIDRs")
|
||||
}
|
||||
|
||||
func (s *SettingService) GetRealityScanCandidates() (string, error) {
|
||||
return s.getString("realityScanCandidates")
|
||||
}
|
||||
|
||||
func (s *SettingService) GetRemarkTemplate() (string, error) {
|
||||
return s.getString("remarkTemplate")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user