mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-11-05 12:45:00 +03:00
feat(xray): update xray-core to v26.9.30 and adapt panel
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.
This commit is contained in:
@@ -18,6 +18,7 @@ import type { NamePath } from 'antd/es/form/interface';
|
||||
import { RandomUtil } from '@/utils';
|
||||
import { activateOnKey } from '@/utils/a11y';
|
||||
import { OutboundProtocols, UTLS_FINGERPRINT } from '@/schemas/primitives';
|
||||
import { upgradeLegacyXdnsMasks, XDNS_LEGACY_EDNS0 } from '@/lib/xray/xdns-mask';
|
||||
|
||||
const UTLS_FINGERPRINT_OPTIONS = Object.values(UTLS_FINGERPRINT).map((value) => ({
|
||||
value,
|
||||
@@ -244,28 +245,34 @@ export default function FinalMaskForm({
|
||||
}: FinalMaskFormProps) {
|
||||
const base = asPath(name);
|
||||
|
||||
// Migrate legacy TCP mask shapes once on mount so configs saved before
|
||||
// #6334 (fragment ranges) and #6487 (xmc profiles) render in the list UI.
|
||||
// Migrate legacy mask shapes once on mount so configs saved before #6334 (fragment
|
||||
// ranges), #6487 (xmc profiles) and #6718 (xdns objects) render in the list UI.
|
||||
const migratedRef = useRef(false);
|
||||
useEffect(() => {
|
||||
if (migratedRef.current) return;
|
||||
migratedRef.current = true;
|
||||
const tcp = form.getFieldValue([...base, 'tcp']);
|
||||
if (!Array.isArray(tcp)) return;
|
||||
let anyChanged = false;
|
||||
const next = tcp.map((mask) => {
|
||||
if (!mask || typeof mask !== 'object') return mask;
|
||||
const m = mask as Record<string, unknown>;
|
||||
if (m.type !== 'fragment' && m.type !== 'xmc') return mask;
|
||||
if (!m.settings || typeof m.settings !== 'object') return mask;
|
||||
const settings = m.settings as Record<string, unknown>;
|
||||
const { next: migrated, changed } =
|
||||
m.type === 'fragment' ? migrateFragmentSettings(settings) : migrateXmcSettings(settings);
|
||||
if (!changed) return mask;
|
||||
anyChanged = true;
|
||||
return { ...m, settings: migrated };
|
||||
});
|
||||
if (anyChanged) form.setFieldValue([...base, 'tcp'], next);
|
||||
if (Array.isArray(tcp)) {
|
||||
let anyChanged = false;
|
||||
const next = tcp.map((mask) => {
|
||||
if (!mask || typeof mask !== 'object') return mask;
|
||||
const m = mask as Record<string, unknown>;
|
||||
if (m.type !== 'fragment' && m.type !== 'xmc') return mask;
|
||||
if (!m.settings || typeof m.settings !== 'object') return mask;
|
||||
const settings = m.settings as Record<string, unknown>;
|
||||
const { next: migrated, changed } =
|
||||
m.type === 'fragment' ? migrateFragmentSettings(settings) : migrateXmcSettings(settings);
|
||||
if (!changed) return mask;
|
||||
anyChanged = true;
|
||||
return { ...m, settings: migrated };
|
||||
});
|
||||
if (anyChanged) form.setFieldValue([...base, 'tcp'], next);
|
||||
}
|
||||
const udp = form.getFieldValue([...base, 'udp']);
|
||||
if (Array.isArray(udp)) {
|
||||
const { next, changed } = upgradeLegacyXdnsMasks(udp);
|
||||
if (changed) form.setFieldValue([...base, 'udp'], next);
|
||||
}
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, []);
|
||||
|
||||
@@ -958,11 +965,7 @@ function UdpMaskItem({
|
||||
);
|
||||
}
|
||||
if (type === 'xdns') {
|
||||
return (
|
||||
<Form.Item label="Domains" name={[fieldName, 'settings', 'domains']}>
|
||||
<Select mode="tags" style={{ width: '100%' }} tokenSeparators={[',']} />
|
||||
</Form.Item>
|
||||
);
|
||||
return <XdnsSettings udpFieldName={fieldName} />;
|
||||
}
|
||||
if (type === 'xicmp') {
|
||||
return (
|
||||
@@ -1255,6 +1258,113 @@ function UdpHeaderCustom({
|
||||
);
|
||||
}
|
||||
|
||||
const XDNS_RECORD_TYPE_OPTIONS = [
|
||||
{ value: 16, label: 'TXT' },
|
||||
{ value: 1, label: 'A' },
|
||||
{ value: 28, label: 'AAAA' },
|
||||
{ value: 5, label: 'CNAME' },
|
||||
];
|
||||
|
||||
// Every xdns key needs a registered field: the finalmask watch drops keys without one.
|
||||
// Resolvers and extraPoll are read by clients only; a server keeps them for the share link.
|
||||
function XdnsSettings({ udpFieldName }: { udpFieldName: number }) {
|
||||
const { t } = useTranslation();
|
||||
return (
|
||||
<>
|
||||
<Form.List name={[udpFieldName, 'settings', 'domains']}>
|
||||
{(domains, { add, remove }) => (
|
||||
<>
|
||||
<Form.Item label="Domains">
|
||||
<Button
|
||||
type="primary"
|
||||
size="small"
|
||||
icon={<PlusOutlined />}
|
||||
aria-label={t('add')}
|
||||
onClick={() => add({ name: '', types: [16], edns0: XDNS_LEGACY_EDNS0 })}
|
||||
/>
|
||||
</Form.Item>
|
||||
{domains.map((domain, di) => (
|
||||
<div key={domain.key}>
|
||||
<Divider style={{ margin: 0 }}>
|
||||
Domain {di + 1}
|
||||
<DeleteOutlined
|
||||
className="danger-icon"
|
||||
role="button"
|
||||
tabIndex={0}
|
||||
aria-label={t('remove')}
|
||||
onClick={() => remove(domain.name)}
|
||||
onKeyDown={activateOnKey(() => remove(domain.name))}
|
||||
/>
|
||||
</Divider>
|
||||
<Form.Item label="Name" name={[domain.name, 'name']}>
|
||||
<Input placeholder="t.example.com" />
|
||||
</Form.Item>
|
||||
<Form.Item
|
||||
label="Record Types"
|
||||
name={[domain.name, 'types']}
|
||||
rules={[{ required: true, type: 'array', min: 1 }]}
|
||||
>
|
||||
<Select mode="multiple" options={XDNS_RECORD_TYPE_OPTIONS} />
|
||||
</Form.Item>
|
||||
<Form.Item label="EDNS0" name={[domain.name, 'edns0']}>
|
||||
<InputNumber min={512} max={4096} placeholder="off" />
|
||||
</Form.Item>
|
||||
<Form.Item label="Length Limit" name={[domain.name, 'lenLimit']}>
|
||||
<InputNumber min={0} max={255} placeholder="255" />
|
||||
</Form.Item>
|
||||
<Form.Item label="Label Limit" name={[domain.name, 'labelLimit']}>
|
||||
<InputNumber min={0} max={63} placeholder="63" />
|
||||
</Form.Item>
|
||||
</div>
|
||||
))}
|
||||
</>
|
||||
)}
|
||||
</Form.List>
|
||||
<Form.List name={[udpFieldName, 'settings', 'resolvers']}>
|
||||
{(resolvers, { add, remove }) => (
|
||||
<>
|
||||
<Form.Item label="Resolvers (client)">
|
||||
<Button
|
||||
type="primary"
|
||||
size="small"
|
||||
icon={<PlusOutlined />}
|
||||
aria-label={t('add')}
|
||||
onClick={() => add({ type: 'udp', settings: { addr: '' } })}
|
||||
/>
|
||||
</Form.Item>
|
||||
{resolvers.map((resolver, ri) => (
|
||||
<Form.Item key={resolver.key} label={`Resolver ${ri + 1}`}>
|
||||
<Space.Compact block>
|
||||
<Form.Item name={[resolver.name, 'type']} noStyle>
|
||||
<Select
|
||||
style={{ width: 80 }}
|
||||
options={[
|
||||
{ value: 'udp', label: 'UDP' },
|
||||
{ value: 'tcp', label: 'TCP' },
|
||||
]}
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item name={[resolver.name, 'settings', 'addr']} noStyle>
|
||||
<Input placeholder="8.8.8.8:53" />
|
||||
</Form.Item>
|
||||
<Button
|
||||
icon={<DeleteOutlined />}
|
||||
aria-label={t('remove')}
|
||||
onClick={() => remove(resolver.name)}
|
||||
/>
|
||||
</Space.Compact>
|
||||
</Form.Item>
|
||||
))}
|
||||
</>
|
||||
)}
|
||||
</Form.List>
|
||||
<Form.Item label="Extra Poll (client)" name={[udpFieldName, 'settings', 'extraPoll']}>
|
||||
<InputNumber min={0} max={3} placeholder="0" />
|
||||
</Form.Item>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
function NoiseItems({
|
||||
udpFieldName,
|
||||
form,
|
||||
@@ -1352,6 +1462,8 @@ function ItemEditor({
|
||||
{ value: 'str', label: 'String' },
|
||||
{ value: 'hex', label: 'Hex' },
|
||||
{ value: 'base64', label: 'Base64' },
|
||||
// Only the noise mask parses tag expressions (xray-core 26.9.30, #6862).
|
||||
...(delayMode === 'string' ? [{ value: 'exp', label: 'Expression' }] : []),
|
||||
]}
|
||||
/>
|
||||
</Form.Item>
|
||||
@@ -1420,7 +1532,7 @@ function ItemEditor({
|
||||
}
|
||||
return (
|
||||
<Form.Item label="Packet" name={[fieldName, 'packet']}>
|
||||
<Input placeholder="binary data" />
|
||||
<Input placeholder={type === 'exp' ? '<b 0d0a0d0a><t><rc 20-40>' : 'binary data'} />
|
||||
</Form.Item>
|
||||
);
|
||||
}}
|
||||
|
||||
@@ -18,7 +18,10 @@ import {
|
||||
import type { StreamSettings } from '@/schemas/api/inbound';
|
||||
import type { Sniffing } from '@/schemas/primitives';
|
||||
import type { z } from 'zod';
|
||||
import { normalizeStreamSettingsForWire } from '@/lib/xray/stream-wire-normalize';
|
||||
import {
|
||||
dropEmptyFinalMask,
|
||||
normalizeStreamSettingsForWire,
|
||||
} from '@/lib/xray/stream-wire-normalize';
|
||||
import { canEnableSniffing } from '@/lib/xray/protocol-capabilities';
|
||||
import { tlsCertUsesFiles } from '@/schemas/protocols/security/tls';
|
||||
import { SockoptStreamSettingsSchema } from '@/schemas/protocols/stream/sockopt';
|
||||
@@ -322,25 +325,7 @@ export function dropLegacyOptionalEmpties(
|
||||
if (Array.isArray(fb) && fb.length === 0) delete settings.fallbacks;
|
||||
|
||||
if (stream) {
|
||||
// StreamSettings emits `finalmask` only when at least one transport
|
||||
// mask exists (legacy `hasFinalMask`). Drop the whole block when all
|
||||
// sub-fields are empty; otherwise drop only the empty sub-arrays so
|
||||
// the wire payload doesn't carry a stray `"tcp": []` next to a
|
||||
// populated UDP mask list (and vice versa).
|
||||
const fm = stream.finalmask as
|
||||
| { tcp?: unknown[]; udp?: unknown[]; quicParams?: unknown }
|
||||
| undefined;
|
||||
if (fm && typeof fm === 'object') {
|
||||
const hasTcp = Array.isArray(fm.tcp) && fm.tcp.length > 0;
|
||||
const hasUdp = Array.isArray(fm.udp) && fm.udp.length > 0;
|
||||
const hasQuic = fm.quicParams != null;
|
||||
if (!hasTcp && !hasUdp && !hasQuic) {
|
||||
delete stream.finalmask;
|
||||
} else {
|
||||
if (!hasTcp) delete fm.tcp;
|
||||
if (!hasUdp) delete fm.udp;
|
||||
}
|
||||
}
|
||||
dropEmptyFinalMask(stream);
|
||||
|
||||
// Hysteria's per-client auth lives in settings.clients[*].auth; the
|
||||
// streamSettings.hysteriaSettings.auth slot is a holdover from older
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
import { XHttpXmuxSchema } from '@/schemas/protocols/stream/xhttp';
|
||||
import { OutboundDomainStrategySchema } from '@/schemas/protocols/outbound';
|
||||
import { AmneziaWGOutboundSettingsSchema } from '@/schemas/protocols/outbound';
|
||||
import { normalizeStreamSettingsForWire } from '@/lib/xray/stream-wire-normalize';
|
||||
import {
|
||||
dropEmptyFinalMask,
|
||||
normalizeStreamSettingsForWire,
|
||||
} from '@/lib/xray/stream-wire-normalize';
|
||||
import { Wireguard } from '@/utils';
|
||||
import type { Sniffing, SniffingDest } from '@/schemas/primitives';
|
||||
import type { OutboundDomainStrategy } from '@/schemas/protocols/outbound';
|
||||
@@ -258,20 +261,50 @@ function wireguardFromWire(raw: Raw): WireguardOutboundFormSettings {
|
||||
secretKey,
|
||||
pubKey,
|
||||
address: addressArr.join(','),
|
||||
domainStrategy: ((): WireguardOutboundFormSettings['domainStrategy'] => {
|
||||
const allowed = ['ForceIP', 'ForceIPv4', 'ForceIPv4v6', 'ForceIPv6', 'ForceIPv6v4'];
|
||||
const s = asString(raw.domainStrategy);
|
||||
return (allowed.includes(s) ? s : '') as WireguardOutboundFormSettings['domainStrategy'];
|
||||
})(),
|
||||
reserved: reservedArr.join(','),
|
||||
remoteDNS: asArray(raw.remoteDNS)
|
||||
.map((x) => asString(x))
|
||||
.join(','),
|
||||
remoteDNS: isLegacyLocalRemoteDNS(raw.remoteDNS)
|
||||
? ''
|
||||
: asArray(raw.remoteDNS)
|
||||
.map((x) => asString(x))
|
||||
.join(','),
|
||||
peers,
|
||||
noKernelTun: asBool(raw.noKernelTun),
|
||||
};
|
||||
}
|
||||
|
||||
// remoteDNS ["local"] is a mode xray-core 26.9.30 removed; the core now panics parsing
|
||||
// it as an address, so liftLegacyWireguardStrategy carries it over to targetStrategy.
|
||||
function isLegacyLocalRemoteDNS(value: unknown): boolean {
|
||||
const list = asArray(value);
|
||||
return list.length === 1 && list[0] === 'local';
|
||||
}
|
||||
|
||||
const isAsIs = (strategy: OutboundDomainStrategy | '') => strategy === '' || strategy === 'AsIs';
|
||||
|
||||
// xray-core 26.9.30 (#6771) ignores wireguard's settings.domainStrategy: sockopt.domainStrategy
|
||||
// now picks the endpoint's family, targetStrategy the targets'. Mirrors the Go seeder.
|
||||
function liftLegacyWireguardStrategy(
|
||||
settings: Raw,
|
||||
targetStrategy: OutboundDomainStrategy | '',
|
||||
streamSettings: OutboundStreamFormValues | undefined,
|
||||
): { targetStrategy: OutboundDomainStrategy | ''; streamSettings?: OutboundStreamFormValues } {
|
||||
const legacy = targetStrategyFromWire(settings.domainStrategy);
|
||||
const family = legacy.startsWith('ForceIP') && legacy !== 'ForceIP' ? legacy : '';
|
||||
const lifted = family || (isLegacyLocalRemoteDNS(settings.remoteDNS) ? 'ForceIP' : '');
|
||||
let stream = streamSettings;
|
||||
const sockopt = asObject((stream as Raw | undefined)?.sockopt);
|
||||
if (family && isAsIs(targetStrategyFromWire(sockopt.domainStrategy))) {
|
||||
stream = {
|
||||
...(stream ?? {}),
|
||||
sockopt: { ...sockopt, domainStrategy: family },
|
||||
} as OutboundStreamFormValues;
|
||||
}
|
||||
return {
|
||||
targetStrategy: lifted && isAsIs(targetStrategy) ? lifted : targetStrategy,
|
||||
streamSettings: stream,
|
||||
};
|
||||
}
|
||||
|
||||
function hysteriaFromWire(raw: Raw): HysteriaOutboundFormSettings {
|
||||
return {
|
||||
address: asString(raw.address),
|
||||
@@ -604,15 +637,20 @@ export function rawOutboundToFormValues(raw: RawOutboundRow): OutboundFormValues
|
||||
typed = { protocol: 'vless', settings: vlessFromWire(settings) };
|
||||
}
|
||||
|
||||
const placed =
|
||||
protocol === 'wireguard'
|
||||
? liftLegacyWireguardStrategy(settings, targetStrategy, streamSettings)
|
||||
: { targetStrategy, streamSettings };
|
||||
|
||||
return {
|
||||
...typed,
|
||||
tag,
|
||||
sendThrough,
|
||||
// The freedom card owns the strategy for freedom, so the shared root field
|
||||
// stays empty and cannot disagree with what the card is showing.
|
||||
targetStrategy: protocol === 'freedom' ? '' : targetStrategy,
|
||||
targetStrategy: protocol === 'freedom' ? '' : placed.targetStrategy,
|
||||
mux,
|
||||
streamSettings,
|
||||
streamSettings: placed.streamSettings,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -715,7 +753,6 @@ function wireguardToWire(s: WireguardOutboundFormSettings) {
|
||||
.map((x) => x.trim())
|
||||
.filter(Boolean)
|
||||
: [],
|
||||
domainStrategy: s.domainStrategy || undefined,
|
||||
reserved: s.reserved
|
||||
? s.reserved
|
||||
.split(',')
|
||||
@@ -912,14 +949,23 @@ export function formValuesToWirePayload(values: OutboundFormValues): WireOutboun
|
||||
result.targetStrategy = values.targetStrategy;
|
||||
}
|
||||
|
||||
// streamSettings emission gates on canEnableStream — non-stream protocols
|
||||
// still emit just `sockopt` if that key is present (legacy behavior).
|
||||
// Non-stream protocols emit only `sockopt`; wireguard also keeps `finalmask`, which the
|
||||
// core dials its peer through (the one non-stream protocol the mask editor renders for).
|
||||
if (values.streamSettings) {
|
||||
if (STREAM_PROTOCOLS.has(values.protocol)) {
|
||||
result.streamSettings = stripUiOnlyStreamFields(values.streamSettings);
|
||||
} else {
|
||||
const sockopt = (values.streamSettings as { sockopt?: unknown }).sockopt;
|
||||
if (sockopt) result.streamSettings = { sockopt };
|
||||
const { sockopt, finalmask } = values.streamSettings as {
|
||||
sockopt?: unknown;
|
||||
finalmask?: unknown;
|
||||
};
|
||||
const stream: Raw = {};
|
||||
if (sockopt) stream.sockopt = sockopt;
|
||||
if (values.protocol === 'wireguard' && finalmask && typeof finalmask === 'object') {
|
||||
stream.finalmask = { ...(finalmask as Raw) };
|
||||
dropEmptyFinalMask(stream);
|
||||
}
|
||||
if (Object.keys(stream).length > 0) result.streamSettings = stream;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import { Base64 } from '@/utils';
|
||||
|
||||
import { upgradeLegacyXdnsMasks } from './xdns-mask';
|
||||
|
||||
// Focused share-link parser for the OutboundFormModal's link-import
|
||||
// helper. Each parser returns a wire-shape outbound record (the same
|
||||
// shape OutboundsTab.tsx stores in templateSettings.outbounds[]) or
|
||||
@@ -279,6 +281,7 @@ function applyFinalMaskParam(stream: Raw, params: URLSearchParams): void {
|
||||
const parsed = JSON.parse(fm) as Record<string, unknown>;
|
||||
if (parsed && typeof parsed === 'object') {
|
||||
sanitizeFinalMaskQuicParams(parsed);
|
||||
if (Array.isArray(parsed.udp)) parsed.udp = upgradeLegacyXdnsMasks(parsed.udp).next;
|
||||
stream.finalmask = parsed;
|
||||
}
|
||||
} catch {
|
||||
|
||||
@@ -323,6 +323,21 @@ export function normalizeSockoptForWire(
|
||||
return out;
|
||||
}
|
||||
|
||||
// Emit `finalmask` only when a mask exists (legacy `hasFinalMask`), and drop an empty
|
||||
// sub-array beside a populated one so the payload carries no stray `"tcp": []`.
|
||||
export function dropEmptyFinalMask(stream: Record<string, unknown>): void {
|
||||
const fm = stream.finalmask as { tcp?: unknown[]; udp?: unknown[]; quicParams?: unknown };
|
||||
if (!fm || typeof fm !== 'object') return;
|
||||
const hasTcp = Array.isArray(fm.tcp) && fm.tcp.length > 0;
|
||||
const hasUdp = Array.isArray(fm.udp) && fm.udp.length > 0;
|
||||
if (!hasTcp && !hasUdp && fm.quicParams == null) {
|
||||
delete stream.finalmask;
|
||||
return;
|
||||
}
|
||||
if (!hasTcp) delete fm.tcp;
|
||||
if (!hasUdp) delete fm.udp;
|
||||
}
|
||||
|
||||
export function normalizeStreamSettingsForWire(
|
||||
stream: Record<string, unknown>,
|
||||
opts: { side: StreamWireSide },
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
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 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 { name, types: [type], edns0: XDNS_LEGACY_EDNS0 };
|
||||
}
|
||||
|
||||
// xray-core 26.9.30 (#6718) parses xdns domains/resolvers only as objects. 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[]) : [];
|
||||
const isLegacy = (v: unknown) => typeof v === 'string';
|
||||
if (!rawDomains.some(isLegacy) && !rawResolvers.some(isLegacy)) {
|
||||
return { next: settings, changed: false };
|
||||
}
|
||||
const domains: unknown[] = [];
|
||||
const listed = new Set<string>();
|
||||
const addDomain = (domain: Raw) => {
|
||||
const key = String(domain.name ?? '').toLowerCase();
|
||||
if (key && listed.has(key)) return;
|
||||
listed.add(key);
|
||||
domains.push(domain);
|
||||
};
|
||||
for (const entry of rawDomains) {
|
||||
if (typeof entry === 'string') {
|
||||
const domain = legacyDomain(entry);
|
||||
if (domain) addDomain(domain);
|
||||
} else if (entry && typeof entry === 'object') {
|
||||
addDomain(entry as Raw);
|
||||
}
|
||||
}
|
||||
const resolvers: unknown[] = [];
|
||||
for (const entry of rawResolvers) {
|
||||
if (typeof entry !== 'string') {
|
||||
resolvers.push(entry);
|
||||
continue;
|
||||
}
|
||||
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;
|
||||
addDomain(domain);
|
||||
resolvers.push({ type: 'udp', settings: { addr } });
|
||||
}
|
||||
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 };
|
||||
}
|
||||
Reference in New Issue
Block a user