mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-10-04 21:22:07 +03:00
62423cacd1
Bump xtls/xray-core to b26a91de4f (v26.9.30) and the three binary pins (DockerInit.sh, release.yml Linux + Windows) in lockstep. No deleted symbols; the sing and sing-shadowsocks indirect deps drop out with the SS2022 rewrite. XDNS finalmask (#6718) replaced its string lists with objects: domains are {name, types, edns0, lenLimit, labelLimit} and client resolvers {type, settings.addr}. The loader no longer parses the old lists, so a single stored xdns mask keeps the whole core from starting. The new leaf package internal/util/maskcompat converts them: "name[:type]" becomes a domain and "name[:type]+udp://addr" a domain plus a udp resolver. A bare name maps to TXT, the type legacy clients queried by default, and each converted domain keeps the 1232-byte EDNS0 the old code always used (without it the server caps answers at 512). It runs from: - the XdnsFinalmaskObjectsFix seeder, over inbound streams, hosts, the xray template, the global sub-JSON mask and cached subscription outbounds; - inbound save (normalizeStreamSettings) and GetXrayConfig, for rows that never went through the seeder; - both link importers, since fm= from an older panel carries the lists. The finalmask form edits the object shape (every key needs a registered field, or the finalmask watch drops it on save) and lifts legacy masks on open. The udp-mask golden fixture moves to the object shape, which TestGoldenStreamFixturesBuildInXray now builds through the core. The wire format changed as well, so pre-upgrade clients need the new core. WireGuard outbound (#6771) dropped settings.domainStrategy and the remoteDNS "local" mode. The endpoint lookup now follows sockopt.domainStrategy and in-tunnel targets the outbound's targetStrategy. The old key is silently ignored, which undid the IPv4-first endpoint lookup the WARP outbound depends on (#5205), and "local" now panics the core at startup because remoteDNS goes through netip.MustParseAddr. The WireguardDomainStrategyFix seeder moves a stored family preference to both keys (a value already set wins) and turns "local" into targetStrategy; the outbound form lifts legacy rows the same way and drops its select, the WARP modal writes the new placement, and the inbound form loses a field the server never read. ValidateOutboundConfig now refuses a non-IP remoteDNS entry, which conf.Build() lets through, on template save and for outbound subscriptions. Noise finalmask items accept type "exp" (#6862), a tag expression. The form offers it for noise items only: header-custom items go through the core's PraseByteSlice, which refuses it. TUN gained autoSystemDnsToGateway (Linux) and autoSystemWfpBlockLeak (Windows). Both pass through the settings schema so a value set in JSON survives the next form save. MASQUE (inbound, outbound, transport) and the XDRIVE transport are new protocols the panel does not offer yet; their new loader refusals only cover configs the panel never generates. The FakeDNS IPv6 pool default, the SS2022 rewrite (same gRPC account; emails are now deduped case-insensitively, as the panel already does), the restored udphop interval default and the rest change no panel-facing config.
117 lines
4.3 KiB
Go
117 lines
4.3 KiB
Go
package database
|
|
|
|
import (
|
|
"encoding/json"
|
|
"testing"
|
|
|
|
"github.com/mhsanaei/3x-ui/v3/internal/database/model"
|
|
)
|
|
|
|
const legacyXdnsFinalmask = `{"udp":[{"type":"xdns","settings":{"domains":["t.example.com"]}}]}`
|
|
|
|
// assertXdnsUpgraded fails unless the finalmask's xdns domains are objects, the only
|
|
// shape xray-core 26.9.30 parses.
|
|
func assertXdnsUpgraded(t *testing.T, where string, finalmask any) {
|
|
t.Helper()
|
|
fm, _ := finalmask.(map[string]any)
|
|
udp, _ := fm["udp"].([]any)
|
|
if len(udp) != 1 {
|
|
t.Fatalf("%s: udp masks = %v, want one", where, fm["udp"])
|
|
}
|
|
mask, _ := udp[0].(map[string]any)
|
|
settings, _ := mask["settings"].(map[string]any)
|
|
domains, _ := settings["domains"].([]any)
|
|
if len(domains) != 1 {
|
|
t.Fatalf("%s: domains = %v, want one entry", where, settings["domains"])
|
|
}
|
|
domain, ok := domains[0].(map[string]any)
|
|
if !ok || domain["name"] != "t.example.com" {
|
|
t.Fatalf("%s: domain = %#v, want an object named t.example.com", where, domains[0])
|
|
}
|
|
}
|
|
|
|
func TestXdnsFinalmaskSeederUpgradesEveryStoredMask(t *testing.T) {
|
|
initMigrateDB(t)
|
|
ib := seedInboundWithStream(t, "xdns-in", 5353,
|
|
`{"network":"kcp","security":"none","finalmask":`+legacyXdnsFinalmask+`}`)
|
|
host := &model.Host{InboundId: ib.Id, Remark: "h", Address: "cdn.example.com", Port: 53, FinalMask: legacyXdnsFinalmask}
|
|
if err := GetDB().Create(host).Error; err != nil {
|
|
t.Fatalf("create host: %v", err)
|
|
}
|
|
seedTemplate(t, `{"outbounds":[{"protocol":"vless","tag":"dns-tunnel","settings":{},"streamSettings":{"network":"kcp","finalmask":`+legacyXdnsFinalmask+`}}]}`)
|
|
if err := GetDB().Create(&model.Setting{Key: "subJsonFinalMask", Value: legacyXdnsFinalmask}).Error; err != nil {
|
|
t.Fatalf("seed subJsonFinalMask: %v", err)
|
|
}
|
|
sub := &model.OutboundSubscription{
|
|
Remark: "donor", Url: "https://donor.example.com/sub",
|
|
LastFetchedOutbounds: `[{"protocol":"vless","tag":"sub-1","settings":{},"streamSettings":{"network":"kcp","finalmask":` + legacyXdnsFinalmask + `}}]`,
|
|
}
|
|
if err := GetDB().Create(sub).Error; err != nil {
|
|
t.Fatalf("create outbound subscription: %v", err)
|
|
}
|
|
if err := GetDB().Where("seeder_name = ?", "XdnsFinalmaskObjectsFix").
|
|
Delete(&model.HistoryOfSeeders{}).Error; err != nil {
|
|
t.Fatalf("clear seeder history: %v", err)
|
|
}
|
|
|
|
if err := runSeeders(false); err != nil {
|
|
t.Fatalf("runSeeders: %v", err)
|
|
}
|
|
|
|
var stored model.Inbound
|
|
if err := GetDB().First(&stored, ib.Id).Error; err != nil {
|
|
t.Fatalf("reload inbound: %v", err)
|
|
}
|
|
var stream map[string]any
|
|
if err := json.Unmarshal([]byte(stored.StreamSettings), &stream); err != nil {
|
|
t.Fatalf("inbound stream is not JSON: %v", err)
|
|
}
|
|
assertXdnsUpgraded(t, "inbound stream", stream["finalmask"])
|
|
|
|
var storedHost model.Host
|
|
if err := GetDB().First(&storedHost, host.Id).Error; err != nil {
|
|
t.Fatalf("reload host: %v", err)
|
|
}
|
|
var hostMask any
|
|
if err := json.Unmarshal([]byte(storedHost.FinalMask), &hostMask); err != nil {
|
|
t.Fatalf("host finalMask is not JSON: %v", err)
|
|
}
|
|
assertXdnsUpgraded(t, "host finalMask", hostMask)
|
|
|
|
var template struct {
|
|
Outbounds []struct {
|
|
StreamSettings struct {
|
|
Finalmask any `json:"finalmask"`
|
|
} `json:"streamSettings"`
|
|
} `json:"outbounds"`
|
|
}
|
|
if err := json.Unmarshal([]byte(storedTemplate(t)), &template); err != nil || len(template.Outbounds) != 1 {
|
|
t.Fatalf("stored template unreadable (%v)", err)
|
|
}
|
|
assertXdnsUpgraded(t, "template outbound", template.Outbounds[0].StreamSettings.Finalmask)
|
|
|
|
var subMask model.Setting
|
|
if err := GetDB().Where("key = ?", "subJsonFinalMask").First(&subMask).Error; err != nil {
|
|
t.Fatalf("reload subJsonFinalMask: %v", err)
|
|
}
|
|
var subFinalmask any
|
|
if err := json.Unmarshal([]byte(subMask.Value), &subFinalmask); err != nil {
|
|
t.Fatalf("subJsonFinalMask is not JSON: %v", err)
|
|
}
|
|
assertXdnsUpgraded(t, "subJsonFinalMask", subFinalmask)
|
|
|
|
var storedSub model.OutboundSubscription
|
|
if err := GetDB().First(&storedSub, sub.Id).Error; err != nil {
|
|
t.Fatalf("reload outbound subscription: %v", err)
|
|
}
|
|
var cached []struct {
|
|
StreamSettings struct {
|
|
Finalmask any `json:"finalmask"`
|
|
} `json:"streamSettings"`
|
|
}
|
|
if err := json.Unmarshal([]byte(storedSub.LastFetchedOutbounds), &cached); err != nil || len(cached) != 1 {
|
|
t.Fatalf("cached subscription outbounds unreadable (%v)", err)
|
|
}
|
|
assertXdnsUpgraded(t, "cached subscription outbound", cached[0].StreamSettings.Finalmask)
|
|
}
|