mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-10-15 18:35:00 +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.
113 lines
4.6 KiB
TypeScript
113 lines
4.6 KiB
TypeScript
type Raw = Record<string, unknown>;
|
|
|
|
/** The EDNS0 payload the pre-26.9.30 xdns always negotiated; without it answers cap at 512. */
|
|
export const XDNS_LEGACY_EDNS0 = 1232;
|
|
|
|
const LEGACY_RECORD_TYPES: Record<string, number> = { '': 16, txt: 16, a: 1, aaaa: 28 };
|
|
|
|
function isRaw(value: unknown): value is Raw {
|
|
return !!value && typeof value === 'object' && !Array.isArray(value);
|
|
}
|
|
|
|
function legacyDomain(spec: string): Raw | null {
|
|
let name = spec.trim();
|
|
let method = '';
|
|
const colon = name.lastIndexOf(':');
|
|
if (colon >= 0) {
|
|
method = name.slice(colon + 1).toLowerCase();
|
|
name = name.slice(0, colon);
|
|
}
|
|
name = name.replace(/^\.+|\.+$/g, '');
|
|
const type = LEGACY_RECORD_TYPES[method];
|
|
if (!name || type === undefined) return null;
|
|
return { names: [name], types: [type], edns0: XDNS_LEGACY_EDNS0 };
|
|
}
|
|
|
|
/** Folds a 26.9.30 domain's single `name` into the `names` list. */
|
|
function upgradeDomainObject(domain: Raw): Raw {
|
|
if (!('name' in domain)) return domain;
|
|
const { name: raw, ...rest } = domain;
|
|
const name = typeof raw === 'string' ? raw.trim() : '';
|
|
const names = Array.isArray(rest.names) ? [...(rest.names as unknown[])] : [];
|
|
if (name && !names.includes(name)) names.unshift(name);
|
|
return { ...rest, names };
|
|
}
|
|
|
|
/** A 26.9.30 {type, settings:{addr}} resolver as an addrs URL; that loader took only udp/tcp. */
|
|
function legacyResolverAddr(resolver: Raw): string | null {
|
|
const kind = typeof resolver.type === 'string' ? resolver.type.trim().toLowerCase() : '';
|
|
const settings = isRaw(resolver.settings) ? resolver.settings : {};
|
|
const addr = typeof settings.addr === 'string' ? settings.addr.trim() : '';
|
|
if ((kind !== 'udp' && kind !== 'tcp') || !addr) return null;
|
|
return `${kind}://${addr}`;
|
|
}
|
|
|
|
const isLegacyDomain = (v: unknown) => typeof v === 'string' || (isRaw(v) && 'name' in v);
|
|
const isLegacyResolver = (v: unknown) => typeof v === 'string' || (isRaw(v) && !('addrs' in v));
|
|
|
|
// xray-core 26.10.10 (#7090) reads xdns only as names/addrs lists. Mirrors
|
|
// internal/util/maskcompat: a bare name becomes TXT, entries the old core refused are dropped.
|
|
export function upgradeLegacyXdnsSettings(settings: Raw): { next: Raw; changed: boolean } {
|
|
const rawDomains = Array.isArray(settings.domains) ? (settings.domains as unknown[]) : [];
|
|
const rawResolvers = Array.isArray(settings.resolvers) ? (settings.resolvers as unknown[]) : [];
|
|
if (!rawDomains.some(isLegacyDomain) && !rawResolvers.some(isLegacyResolver)) {
|
|
return { next: settings, changed: false };
|
|
}
|
|
const domains: unknown[] = [];
|
|
const listed = new Set<string>();
|
|
const addDomain = (domain: Raw) => {
|
|
const names = Array.isArray(domain.names) ? (domain.names as unknown[]) : [];
|
|
for (const name of names) if (typeof name === 'string') listed.add(name.toLowerCase());
|
|
domains.push(domain);
|
|
};
|
|
const addLegacyDomain = (domain: Raw) => {
|
|
const [name] = domain.names as string[];
|
|
if (!listed.has(name.toLowerCase())) addDomain(domain);
|
|
};
|
|
for (const entry of rawDomains) {
|
|
if (typeof entry === 'string') {
|
|
const domain = legacyDomain(entry);
|
|
if (domain) addLegacyDomain(domain);
|
|
} else if (isRaw(entry)) {
|
|
addDomain(upgradeDomainObject(entry));
|
|
}
|
|
}
|
|
const resolvers: unknown[] = [];
|
|
for (const entry of rawResolvers) {
|
|
if (typeof entry === 'string') {
|
|
const sep = entry.indexOf('+udp://');
|
|
const addr = sep >= 0 ? entry.slice(sep + '+udp://'.length).trim() : '';
|
|
const domain = sep >= 0 ? legacyDomain(entry.slice(0, sep)) : null;
|
|
if (!addr || !domain) continue;
|
|
addLegacyDomain(domain);
|
|
resolvers.push({ addrs: [`udp://${addr}`] });
|
|
} else if (isRaw(entry) && isLegacyResolver(entry)) {
|
|
const addr = legacyResolverAddr(entry);
|
|
if (addr) resolvers.push({ addrs: [addr] });
|
|
} else {
|
|
resolvers.push(entry);
|
|
}
|
|
}
|
|
const next: Raw = { ...settings, domains };
|
|
if (resolvers.length > 0) next.resolvers = resolvers;
|
|
else delete next.resolvers;
|
|
return { next, changed: true };
|
|
}
|
|
|
|
/** Applies upgradeLegacyXdnsSettings to every xdns entry of a finalmask.udp list. */
|
|
export function upgradeLegacyXdnsMasks(udp: unknown[]): { next: unknown[]; changed: boolean } {
|
|
let changed = false;
|
|
const next = udp.map((entry) => {
|
|
const mask = entry as Raw | null;
|
|
if (!mask || typeof mask !== 'object' || String(mask.type).toLowerCase() !== 'xdns') {
|
|
return entry;
|
|
}
|
|
if (!mask.settings || typeof mask.settings !== 'object') return entry;
|
|
const upgraded = upgradeLegacyXdnsSettings(mask.settings as Raw);
|
|
if (!upgraded.changed) return entry;
|
|
changed = true;
|
|
return { ...mask, settings: upgraded.next };
|
|
});
|
|
return { next, changed };
|
|
}
|