mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-10-12 17:05:01 +03:00
73a028f52d
Move the three Xray binary pins (DockerInit.sh, both release.yml
fetches) to v26.10.10, in lockstep with the xtls/xray-core module that
82c77111 already bumped to 701af60772cd.
xdns finalmask (#7090): a domain now takes a "names" list instead of a
single "name", and a resolver is an "addrs" list of udp:// or tcp://
URLs instead of {type, settings:{addr}}. The loader ignores the old
keys rather than failing, so every mask the 26.9.30 seeder wrote would
load with no domain and no resolver and the tunnel would carry nothing.
maskcompat.UpgradeLegacyXdns now lifts both the pre-26.9.30 string lists
and the 26.9.30 objects straight to names/addrs, dropping entries the
old loader refused. A new seeder (XdnsFinalmaskNamesAddrsFix) reruns it
over every stored finalmask, and the save path, GetXrayConfig, both
link importers and the mask editor's mount lift go through it. Template
outbounds now get the build-time heal too: a 26.9.30 template pasted
after the seeder passes the save check, since the core loads that shape
without error. The editor edits names and addrs as tag lists and no
longer requires record types, which the core now defaults (TXT on a
client, A/CNAME/TXT/AAAA on a server). The wire format did not change,
but clients on an older core cannot read the new config shape.
Lua scripts (#6823): dns.script, routing.script and dns servers[].id
are new. The xray page parsed the dns block with a strict schema, so
loading it dropped script and id and the next save deleted them; the
schema now keeps both and the DNS server modal carries the id through
an edit. The hot routing apply built routing in-process, and that build
now resolves the script file from the panel's working directory, so a
script beside the xray binary failed every rule change into a full
restart and broke the node bridge. RoutingService cannot change the
script anyway, so the panel no longer resolves it there.
TLS client roots (#7105): the core now verifies against its bundled
Mozilla roots instead of the OS store unless tlsSettings.useSystemCA is
set. The outbound TLS form gets a switch for it, so an outbound to a
server signed by a privately installed CA can opt back in.
119 lines
4.6 KiB
Go
119 lines
4.6 KiB
Go
package database
|
|
|
|
import (
|
|
"encoding/json"
|
|
"testing"
|
|
|
|
"github.com/mhsanaei/3x-ui/v3/internal/database/model"
|
|
)
|
|
|
|
// legacyXdnsFinalmask is the 26.9.30 object shape the previous seeder left in panel DBs;
|
|
// xray-core 26.10.10 reads neither its "name" nor its typed resolver.
|
|
const legacyXdnsFinalmask = `{"udp":[{"type":"xdns","settings":{"domains":[{"name":"t.example.com","types":[16],"edns0":1232}],"resolvers":[{"type":"udp","settings":{"addr":"8.8.8.8:53"}}]}}]}`
|
|
|
|
// assertXdnsUpgraded fails unless the finalmask's xdns mask uses the names/addrs lists,
|
|
// the only shape xray-core 26.10.10 reads.
|
|
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)
|
|
got, err := json.Marshal(settings)
|
|
if err != nil {
|
|
t.Fatalf("%s: marshal xdns settings: %v", where, err)
|
|
}
|
|
const want = `{"domains":[{"edns0":1232,"names":["t.example.com"],"types":[16]}],"resolvers":[{"addrs":["udp://8.8.8.8:53"]}]}`
|
|
if string(got) != want {
|
|
t.Fatalf("%s: xdns settings\n got: %s\nwant: %s", where, got, want)
|
|
}
|
|
}
|
|
|
|
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 = ?", "XdnsFinalmaskNamesAddrsFix").
|
|
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)
|
|
}
|