mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-11-26 12:34:47 +03:00
b04039c2bd
xray-core v26.10.10 serves MASQUE: CONNECT-IP over HTTP/3 or HTTP/2, always behind TLS, as an inbound and an outbound protocol riding a dedicated "masque" transport. The panel could not create either. Inbound: MASQUE is a multi-user protocol whose users log in with their email and password over Basic auth. The panel keeps the client's "password" like trojan and GenXrayInboundConfig hands it to the core as "pass", so the full-config path, the live AddInbound path and node pushes all emit what the core reads; one user with an empty pass makes the core refuse the whole inbound. Live user adds build a masque.Account from either key, client-only changes diff per user so a new client does not drop every connected tunnel, and client creation, copy, validation and edits key on the password. The address pool and MTU get form fields, TLS is mandatory, and the port check follows the core's listener choice: HTTP/2 on TCP when the ALPN offers h2, HTTP/3 on UDP when it offers h3 or not h2. Nodes may host MASQUE from v3.9.1, the first panel release that knows to rename the password. MASQUE has no share-link format, so links and Clash skip it; the JSON subscription builds the client's masque outbound with its email and password, and the subscription allowlist now lets a subId see MASQUE inbounds at all. The IP-limit job, client pages and traffic tracking list the protocol. Outbound: the form edits the server, remote DNS, and the transport's host, path, Basic credentials, headers and WARP block (enrolled key, endpoint public key, tunnel addresses), which xray-core refuses next to user/pass. The outbound test probes it through the core, since its default HTTP/3 dial is UDP.
110 lines
4.6 KiB
TypeScript
110 lines
4.6 KiB
TypeScript
// Pure-function ports of the legacy Inbound class capability predicates
|
|
// (canEnableTls, canEnableReality, canEnableTlsFlow, canEnableStream,
|
|
// canEnableVisionSeed, isSS2022, isSSMultiUser). Each accepts the minimal
|
|
// slice of an InboundFormValues it needs, so the same predicate can be
|
|
// called against a partial-row, a full form value, or a hand-built test
|
|
// fixture without the caller projecting a whole object.
|
|
|
|
const TLS_ELIGIBLE_PROTOCOLS = ['vmess', 'vless', 'trojan', 'shadowsocks'];
|
|
const TLS_NETWORKS = ['tcp', 'ws', 'http', 'grpc', 'httpupgrade', 'xhttp'];
|
|
const REALITY_ELIGIBLE_PROTOCOLS = ['vless', 'trojan'];
|
|
const REALITY_NETWORKS = ['tcp', 'http', 'grpc', 'xhttp'];
|
|
const STREAM_PROTOCOLS = [
|
|
'vmess',
|
|
'vless',
|
|
'trojan',
|
|
'shadowsocks',
|
|
'hysteria',
|
|
'wireguard',
|
|
'tunnel',
|
|
'masque',
|
|
];
|
|
const VISION_FLOW = 'xtls-rprx-vision';
|
|
const SS_2022_PREFIX = '2022';
|
|
const SS_BLAKE3_CHACHA20 = '2022-blake3-chacha20-poly1305';
|
|
|
|
export interface CapabilityProtocolSlice {
|
|
protocol: string;
|
|
settings?: { encryption?: string; decryption?: string };
|
|
streamSettings?: { network?: string; security?: string };
|
|
}
|
|
|
|
export interface CapabilityVlessSlice extends CapabilityProtocolSlice {
|
|
settings?: { encryption?: string; decryption?: string; clients?: { flow?: string }[] };
|
|
}
|
|
|
|
export interface CapabilityShadowsocksSlice extends CapabilityProtocolSlice {
|
|
settings?: { encryption?: string; method?: string };
|
|
}
|
|
|
|
export function canEnableTls(values: CapabilityProtocolSlice): boolean {
|
|
if (values.protocol === 'hysteria' || values.protocol === 'masque') return true;
|
|
if (!TLS_ELIGIBLE_PROTOCOLS.includes(values.protocol)) return false;
|
|
return TLS_NETWORKS.includes(values.streamSettings?.network ?? '');
|
|
}
|
|
|
|
export function canEnableReality(values: CapabilityProtocolSlice): boolean {
|
|
if (!REALITY_ELIGIBLE_PROTOCOLS.includes(values.protocol)) return false;
|
|
return REALITY_NETWORKS.includes(values.streamSettings?.network ?? '');
|
|
}
|
|
|
|
// VLESS encryption (vlessenc / ML-KEM) is on when encryption or decryption holds
|
|
// a generated value (e.g. "mlkem768x25519plus.native.0rtt.<key>") rather than
|
|
// the "none"/"" sentinel. The value is never the literal "vlessenc" (that is the
|
|
// `xray vlessenc` subcommand). decryption is the server-side value; encryption is
|
|
// stored for link generation — either being set means it is on.
|
|
function hasVlessEncryption(settings: CapabilityProtocolSlice['settings']): boolean {
|
|
const isSet = (v?: string) => v != null && v !== '' && v !== 'none';
|
|
return isSet(settings?.encryption) || isSet(settings?.decryption);
|
|
}
|
|
|
|
export function canEnableTlsFlow(values: CapabilityProtocolSlice): boolean {
|
|
if (values.protocol !== 'vless') return false;
|
|
const network = values.streamSettings?.network;
|
|
const security = values.streamSettings?.security;
|
|
|
|
// Classic XTLS Vision: raw TCP carried over TLS or REALITY.
|
|
if (network === 'tcp' && (security === 'tls' || security === 'reality')) return true;
|
|
|
|
// vlessenc carries Vision over XHTTP without transport TLS.
|
|
if (network === 'xhttp' && hasVlessEncryption(values.settings)) return true;
|
|
|
|
return false;
|
|
}
|
|
|
|
export function canEnableStream(values: { protocol: string }): boolean {
|
|
return STREAM_PROTOCOLS.includes(values.protocol);
|
|
}
|
|
|
|
// mtproto and amneziawg are served by an external process/interface, not
|
|
// Xray, so the Xray sniffing block does not apply to either. Every other
|
|
// inbound supports sniffing.
|
|
export function canEnableSniffing(values: { protocol: string }): boolean {
|
|
return (
|
|
values.protocol !== 'mtproto' && values.protocol !== 'amneziawg' && values.protocol !== 'tuic'
|
|
);
|
|
}
|
|
|
|
// Vision seed applies only when XTLS Vision (TCP/TLS) flow is selected
|
|
// AND at least one VLESS client uses the vision flow. Excludes UDP variant.
|
|
export function canEnableVisionSeed(values: CapabilityVlessSlice): boolean {
|
|
if (!canEnableTlsFlow(values)) return false;
|
|
const clients = values.settings?.clients;
|
|
if (!Array.isArray(clients)) return false;
|
|
return clients.some((c) => c?.flow === VISION_FLOW);
|
|
}
|
|
|
|
// Why: legacy returns true on non-SS protocols too (the method getter
|
|
// resolves to "" and "" !== blake3-chacha20-poly1305). Preserved for
|
|
// parity with the legacy class; in practice the callers all narrow on
|
|
// protocol === shadowsocks before checking.
|
|
export function isSSMultiUser(values: CapabilityShadowsocksSlice): boolean {
|
|
const method = values.protocol === 'shadowsocks' ? (values.settings?.method ?? '') : '';
|
|
return method !== SS_BLAKE3_CHACHA20;
|
|
}
|
|
|
|
export function isSS2022(values: CapabilityShadowsocksSlice): boolean {
|
|
const method = values.protocol === 'shadowsocks' ? (values.settings?.method ?? '') : '';
|
|
return method.substring(0, 4) === SS_2022_PREFIX;
|
|
}
|