| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244 |
- import { useEffect, useMemo, useState } from 'react';
- import { useTranslation } from 'react-i18next';
- import {
- Button,
- Form,
- Input,
- InputNumber,
- Modal,
- Radio,
- Select,
- Space,
- Switch,
- Tabs,
- message,
- } from 'antd';
- import { DeleteOutlined, MinusOutlined, PlusOutlined, SyncOutlined } from '@ant-design/icons';
- import FinalMaskForm from '@/components/FinalMaskForm';
- import HeaderMapEditor from '@/components/HeaderMapEditor';
- import InputAddon from '@/components/InputAddon';
- import JsonEditor from '@/components/JsonEditor';
- import { Wireguard } from '@/utils';
- import {
- formValuesToWirePayload,
- rawOutboundToFormValues,
- } from '@/lib/xray/outbound-form-adapter';
- import { parseOutboundLink } from '@/lib/xray/outbound-link-parser';
- import {
- OutboundFormBaseSchema,
- ShadowsocksOutboundFormSettingsSchema,
- TrojanOutboundFormSettingsSchema,
- VlessOutboundFormSettingsSchema,
- VmessOutboundFormSettingsSchema,
- type OutboundFormValues,
- } from '@/schemas/forms/outbound-form';
- import {
- ALPN_OPTION,
- Address_Port_Strategy,
- DNSRuleActions,
- DOMAIN_STRATEGY_OPTION,
- MODE_OPTION,
- OutboundDomainStrategies,
- OutboundProtocols as Protocols,
- SNIFFING_OPTION,
- TCP_CONGESTION_OPTION,
- TLS_FLOW_CONTROL,
- USERS_SECURITY,
- UTLS_FINGERPRINT,
- WireguardDomainStrategy,
- } from '@/schemas/primitives';
- import {
- HappyEyeballsSchema,
- SockoptStreamSettingsSchema,
- } from '@/schemas/protocols/stream/sockopt';
- import {
- canEnableReality,
- canEnableStream,
- canEnableTls,
- canEnableTlsFlow,
- } from '@/lib/xray/protocol-capabilities';
- import { SSMethodSchema } from '@/schemas/protocols/inbound/shadowsocks';
- import { antdRule } from '@/utils/zodForm';
- import './OutboundFormModal.css';
- // Pattern A rewrite of OutboundFormModal. Built as a sibling `.new.tsx`
- // file so the build stays green section-by-section. The atomic swap at
- // the end of the rewrite replaces the legacy file in one commit
- // (per Core Decision 7 in the migration spec).
- interface OutboundFormModalProps {
- open: boolean;
- outbound: Record<string, unknown> | null;
- existingTags: string[];
- onClose: () => void;
- onConfirm: (outbound: Record<string, unknown>) => void;
- }
- const PROTOCOL_OPTIONS = Object.values(Protocols).map((p) => ({ value: p, label: p }));
- const SECURITY_OPTIONS = Object.values(USERS_SECURITY).map((v) => ({ value: v, label: v }));
- const FLOW_OPTIONS = Object.values(TLS_FLOW_CONTROL).map((v) => ({ value: v, label: v }));
- const SS_METHOD_OPTIONS = SSMethodSchema.options.map((v) => ({ value: v, label: v }));
- const MODE_OPTIONS = Object.values(MODE_OPTION).map((v) => ({ value: v, label: v }));
- const UTLS_OPTIONS = Object.values(UTLS_FINGERPRINT).map((v) => ({ value: v, label: v }));
- const ALPN_OPTIONS = Object.values(ALPN_OPTION).map((v) => ({ value: v, label: v }));
- const ADDRESS_PORT_STRATEGY_OPTIONS = Object.values(Address_Port_Strategy).map((v) => ({
- value: v,
- label: v,
- }));
- // canEnableMux mirrors the adapter's helper but lives here so the modal
- // can show/hide the Mux section without going through the adapter.
- const MUX_PROTOCOLS = new Set<string>(['vmess', 'vless', 'trojan', 'shadowsocks', 'http', 'socks']);
- function isMuxAllowed(protocol: string, flow: string, network: string): boolean {
- if (!MUX_PROTOCOLS.has(protocol)) return false;
- if (protocol === 'vless' && flow) return false;
- if (network === 'xhttp') return false;
- return true;
- }
- const NETWORK_OPTIONS: { value: string; label: string }[] = [
- { value: 'tcp', label: 'TCP (RAW)' },
- { value: 'kcp', label: 'mKCP' },
- { value: 'ws', label: 'WebSocket' },
- { value: 'grpc', label: 'gRPC' },
- { value: 'httpupgrade', label: 'HTTPUpgrade' },
- { value: 'xhttp', label: 'XHTTP' },
- ];
- // Hysteria appends an extra `hysteria` network branch to the selector
- // — only when the parent protocol is hysteria. Wire-side this matches
- // the legacy modal's `isHysteria ? [...NETWORKS, 'hysteria'] : NETWORKS`.
- const HYSTERIA_NETWORK_OPTION = { value: 'hysteria', label: 'Hysteria' };
- // Per-network bootstrap. Mirrors the legacy class constructors so the
- // initial state for each transport matches what xray-core expects.
- function newStreamSlice(network: string): Record<string, unknown> {
- switch (network) {
- case 'tcp':
- return { network: 'tcp', tcpSettings: { header: { type: 'none' } } };
- case 'kcp':
- return {
- network: 'kcp',
- kcpSettings: {
- mtu: 1350, tti: 20, uplinkCapacity: 5, downlinkCapacity: 20,
- cwndMultiplier: 1, maxSendingWindow: 2097152,
- },
- };
- case 'ws':
- return {
- network: 'ws',
- wsSettings: { path: '/', host: '', headers: {}, heartbeatPeriod: 0 },
- };
- case 'grpc':
- return {
- network: 'grpc',
- grpcSettings: { serviceName: '', authority: '', multiMode: false },
- };
- case 'httpupgrade':
- return {
- network: 'httpupgrade',
- httpupgradeSettings: { path: '/', host: '', headers: {} },
- };
- case 'xhttp':
- return {
- network: 'xhttp',
- xhttpSettings: {
- path: '/', host: '', mode: '', headers: [],
- xPaddingBytes: '100-1000', scMaxEachPostBytes: '1000000',
- },
- };
- case 'hysteria':
- return {
- network: 'hysteria',
- hysteriaSettings: {
- version: 2,
- auth: '',
- udpIdleTimeout: 60,
- },
- };
- default:
- return { network: 'tcp', tcpSettings: { header: { type: 'none' } } };
- }
- }
- // Protocols whose form schema carries a flat connect target — these all
- // get the shared "server" sub-block (address + port) at the top of the
- // protocol section. Wireguard has an address but no port. DNS/freedom/
- // blackhole/loopback have no connect target.
- const SERVER_PROTOCOLS = new Set<string>([
- 'vmess', 'vless', 'trojan', 'shadowsocks', 'socks', 'http', 'hysteria',
- ]);
- function buildAddModeValues(): OutboundFormValues {
- return rawOutboundToFormValues({});
- }
- export default function OutboundFormModal({
- open,
- outbound: outboundProp,
- existingTags,
- onClose,
- onConfirm,
- }: OutboundFormModalProps) {
- const { t } = useTranslation();
- const [messageApi, messageContextHolder] = message.useMessage();
- const [form] = Form.useForm<OutboundFormValues>();
- const [activeKey, setActiveKey] = useState('1');
- const [jsonText, setJsonText] = useState('');
- const [jsonDirty, setJsonDirty] = useState(false);
- const [linkInput, setLinkInput] = useState('');
- // Parse a share link (vmess:// / vless:// / trojan:// / ss:// /
- // hysteria2://) and replace form state with the result. The current
- // tag is preserved when the parsed link doesn't carry one.
- function importLink() {
- const link = linkInput.trim();
- if (!link) return;
- const parsed = parseOutboundLink(link);
- if (!parsed) {
- messageApi.error('Wrong Link!');
- return;
- }
- const currentTag = form.getFieldValue('tag') as string | undefined;
- if (!parsed.tag && currentTag) parsed.tag = currentTag;
- const next = rawOutboundToFormValues(parsed);
- form.resetFields();
- form.setFieldsValue(next);
- setJsonText(JSON.stringify(formValuesToWirePayload(next), null, 2));
- setJsonDirty(false);
- setLinkInput('');
- messageApi.success('Link imported successfully');
- switchTab('1');
- }
- const isEdit = outboundProp != null;
- const title = isEdit
- ? `${t('edit')} ${t('pages.xray.Outbounds')}`
- : `+ ${t('pages.xray.Outbounds')}`;
- const okText = isEdit ? t('pages.clients.submitEdit') : t('create');
- useEffect(() => {
- if (!open) return;
- const initial = outboundProp
- ? rawOutboundToFormValues(outboundProp)
- : buildAddModeValues();
- form.resetFields();
- form.setFieldsValue(initial);
- setActiveKey('1');
- setJsonText(JSON.stringify(formValuesToWirePayload(initial), null, 2));
- setJsonDirty(false);
- }, [open, outboundProp, form]);
- const tag = Form.useWatch('tag', form) ?? '';
- const protocol = (Form.useWatch('protocol', form) ?? 'vless') as string;
- // preserve: true — without it useWatch only reflects values whose
- // Form.Item is currently mounted. The streamSettings selectors live
- // INSIDE `{streamAllowed && network && (...)}`, so the moment that
- // conditional gates them out, useWatch returns undefined, the gate
- // keeps returning false, and the stream block never renders even
- // though streamSettings is in the form store.
- const network = (Form.useWatch(['streamSettings', 'network'], { form, preserve: true }) ?? '') as string;
- const security = (Form.useWatch(['streamSettings', 'security'], { form, preserve: true }) ?? 'none') as string;
- const streamAllowed = canEnableStream({ protocol });
- const tlsAllowed = canEnableTls({ protocol, streamSettings: { network, security } });
- const realityAllowed = canEnableReality({ protocol, streamSettings: { network, security } });
- const tlsFlowAllowed = canEnableTlsFlow({ protocol, streamSettings: { network, security } });
- // Seed streamSettings when the user picks a protocol that supports
- // streams but the form does not yet have a stream slice (new outbound,
- // or wire payload arrived without streamSettings).
- useEffect(() => {
- if (!streamAllowed) return;
- if (network) return;
- form.setFieldValue('streamSettings', { ...newStreamSlice('tcp'), security: 'none' });
- // eslint-disable-next-line react-hooks/exhaustive-deps
- }, [streamAllowed, network]);
- // Wireguard pubKey is a UI-only field derived from secretKey on every
- // edit. The legacy modal did the same on every keystroke. We re-derive
- // here so paste-in secret keys immediately surface the matching pub.
- const wgSecretKey = Form.useWatch(['settings', 'secretKey'], form) as string | undefined;
- useEffect(() => {
- if (protocol !== 'wireguard') return;
- const sk = (wgSecretKey ?? '').trim();
- if (!sk) {
- form.setFieldValue(['settings', 'pubKey'], '');
- return;
- }
- try {
- const { publicKey } = Wireguard.generateKeypair(sk);
- form.setFieldValue(['settings', 'pubKey'], publicKey);
- } catch {
- form.setFieldValue(['settings', 'pubKey'], '');
- }
- // eslint-disable-next-line react-hooks/exhaustive-deps
- }, [protocol, wgSecretKey]);
- // Switching protocol resets the settings sub-object to fresh defaults
- // so leftover fields from the previous protocol do not bleed through.
- // The adapter's rawOutboundToFormValues seeds whatever the new protocol
- // expects (vless flat shape, vmess flat shape, wireguard with secretKey
- // placeholder, etc.).
- function onValuesChange(changed: Partial<OutboundFormValues>) {
- if ('protocol' in changed && changed.protocol) {
- const next = rawOutboundToFormValues({ protocol: changed.protocol });
- form.setFieldValue('settings', next.settings);
- }
- }
- // Security change cascade: swap the security sub-key so the DU branch
- // matches. Seed default field values when entering tls/reality so the
- // sub-forms render without `undefined` field references.
- function onSecurityChange(next: string) {
- const stream = form.getFieldValue('streamSettings') ?? {};
- const cleaned = { ...stream } as Record<string, unknown>;
- delete cleaned.tlsSettings;
- delete cleaned.realitySettings;
- if (next === 'tls') {
- cleaned.tlsSettings = {
- serverName: '',
- alpn: [],
- fingerprint: '',
- echConfigList: '',
- verifyPeerCertByName: '',
- pinnedPeerCertSha256: '',
- };
- } else if (next === 'reality') {
- cleaned.realitySettings = {
- publicKey: '',
- fingerprint: 'chrome',
- serverName: '',
- shortId: '',
- spiderX: '',
- mldsa65Verify: '',
- };
- }
- cleaned.security = next;
- form.setFieldValue('streamSettings', cleaned);
- }
- // Network change cascade: swap the per-network sub-key (tcpSettings,
- // wsSettings, etc.) so the DU branch matches. Preserve security if
- // the new network supports it, otherwise force back to 'none'.
- function onNetworkChange(next: string) {
- const currentSecurity = form.getFieldValue(['streamSettings', 'security']) ?? 'none';
- const stillAllowed = canEnableTls({ protocol, streamSettings: { network: next, security: currentSecurity } });
- const stillReality = canEnableReality({ protocol, streamSettings: { network: next, security: currentSecurity } });
- const newSecurity =
- currentSecurity === 'tls' && !stillAllowed
- ? 'none'
- : currentSecurity === 'reality' && !stillReality
- ? 'none'
- : currentSecurity;
- form.setFieldValue('streamSettings', { ...newStreamSlice(next), security: newSecurity });
- }
- const duplicateTag = useMemo(() => {
- const myTag = tag.trim();
- if (!myTag) return false;
- if (isEdit && (outboundProp?.tag as string | undefined) === myTag) return false;
- return (existingTags || []).includes(myTag);
- }, [tag, existingTags, isEdit, outboundProp]);
- // Bridge form ↔ JSON tab: when leaving the JSON tab back to Basic, push
- // any edits into form state. When entering JSON tab, snapshot current
- // form values so the user sees the live shape.
- function applyJsonToForm(): boolean {
- if (!jsonDirty) return true;
- const raw = jsonText.trim();
- if (!raw) return true;
- let parsed: Record<string, unknown>;
- try {
- parsed = JSON.parse(raw) as Record<string, unknown>;
- } catch (e) {
- messageApi.error(`JSON: ${(e as Error).message}`);
- return false;
- }
- const next = rawOutboundToFormValues(parsed);
- form.resetFields();
- form.setFieldsValue(next);
- setJsonDirty(false);
- return true;
- }
- // Wrap every tab switch with a blur of the active element. AntD marks
- // the outgoing panel `aria-hidden="true"` synchronously when the
- // controlled activeKey flips; if a focused input is still inside that
- // panel (e.g. Input.Search on the JSON tab after user hits Enter to
- // import), Chrome logs a WAI-ARIA warning. Doing the blur right
- // before setActiveKey ensures the panel is unfocused by the time
- // AntD applies the attribute.
- function switchTab(key: string) {
- if (typeof document !== 'undefined') {
- (document.activeElement as HTMLElement | null)?.blur?.();
- }
- setActiveKey(key);
- }
- function onTabChange(key: string) {
- if (key === '2') {
- const values = form.getFieldsValue(true) as OutboundFormValues;
- setJsonText(JSON.stringify(formValuesToWirePayload(values), null, 2));
- setJsonDirty(false);
- switchTab(key);
- return;
- }
- if (key === '1' && activeKey === '2') {
- if (!applyJsonToForm()) return;
- }
- switchTab(key);
- }
- async function onOk() {
- if (activeKey === '2' && !applyJsonToForm()) return;
- let values: OutboundFormValues;
- try {
- values = await form.validateFields();
- } catch {
- return;
- }
- if (duplicateTag) {
- messageApi.error('Tag already used by another outbound');
- return;
- }
- onConfirm(formValuesToWirePayload(values));
- }
- return (
- <>
- {messageContextHolder}
- <Modal
- open={open}
- title={title}
- okText={okText}
- cancelText={t('close')}
- mask={{ closable: false }}
- width={780}
- onOk={onOk}
- onCancel={onClose}
- destroyOnHidden
- >
- <Form
- form={form}
- colon={false}
- labelCol={{ md: { span: 8 } }}
- wrapperCol={{ md: { span: 14 } }}
- onValuesChange={onValuesChange}
- >
- <Tabs
- activeKey={activeKey}
- onChange={onTabChange}
- items={[
- {
- key: '1',
- label: t('pages.xray.basicTemplate'),
- children: (
- <>
- <Form.Item
- label={t('protocol')}
- name="protocol"
- rules={[antdRule(OutboundFormBaseSchema.shape.tag, t)]}
- >
- <Select options={PROTOCOL_OPTIONS} />
- </Form.Item>
- <Form.Item
- label="Tag"
- name="tag"
- validateStatus={duplicateTag ? 'warning' : undefined}
- help={duplicateTag ? 'Tag already used by another outbound' : undefined}
- rules={[
- { required: true, message: 'Tag is required' },
- ]}
- >
- <Input placeholder="unique-tag" />
- </Form.Item>
- <Form.Item label="Send through" name="sendThrough">
- <Input placeholder="local IP" />
- </Form.Item>
- {/* Shared connect target (address + port) for protocols
- whose form schema carries them flat at settings root.
- Hidden for freedom/blackhole/dns/loopback/wireguard. */}
- {SERVER_PROTOCOLS.has(protocol) && (
- <>
- <Form.Item
- label={t('pages.inbounds.address')}
- name={['settings', 'address']}
- rules={[{ required: true, message: 'Address is required' }]}
- >
- <Input />
- </Form.Item>
- <Form.Item
- label={t('pages.inbounds.port')}
- name={['settings', 'port']}
- rules={[{ required: true, message: 'Port is required' }]}
- >
- <InputNumber min={1} max={65535} style={{ width: '100%' }} />
- </Form.Item>
- </>
- )}
- {(protocol === 'vmess' || protocol === 'vless') && (
- <Form.Item
- label="ID"
- name={['settings', 'id']}
- rules={[antdRule(VmessOutboundFormSettingsSchema.shape.id, t)]}
- >
- <Input placeholder="UUID" />
- </Form.Item>
- )}
- {protocol === 'vmess' && (
- <Form.Item
- label={t('security')}
- name={['settings', 'security']}
- rules={[antdRule(VmessOutboundFormSettingsSchema.shape.security, t)]}
- >
- <Select options={SECURITY_OPTIONS} />
- </Form.Item>
- )}
- {protocol === 'vless' && (
- <>
- <Form.Item
- label={t('encryption')}
- name={['settings', 'encryption']}
- rules={[antdRule(VlessOutboundFormSettingsSchema.shape.encryption, t)]}
- >
- <Input />
- </Form.Item>
- <Form.Item label="Reverse tag" name={['settings', 'reverseTag']}>
- <Input placeholder="optional" />
- </Form.Item>
- </>
- )}
- {(protocol === 'trojan' || protocol === 'shadowsocks') && (
- <Form.Item
- label={t('password')}
- name={['settings', 'password']}
- rules={[
- antdRule(
- protocol === 'trojan'
- ? TrojanOutboundFormSettingsSchema.shape.password
- : ShadowsocksOutboundFormSettingsSchema.shape.password,
- t,
- ),
- ]}
- >
- <Input />
- </Form.Item>
- )}
- {protocol === 'shadowsocks' && (
- <>
- <Form.Item
- label={t('encryption')}
- name={['settings', 'method']}
- rules={[antdRule(SSMethodSchema, t)]}
- >
- <Select options={SS_METHOD_OPTIONS} />
- </Form.Item>
- <Form.Item
- label="UDP over TCP"
- name={['settings', 'uot']}
- valuePropName="checked"
- >
- <Switch />
- </Form.Item>
- <Form.Item label="UoT version" name={['settings', 'UoTVersion']}>
- <InputNumber min={1} max={2} />
- </Form.Item>
- </>
- )}
- {(protocol === 'socks' || protocol === 'http') && (
- <>
- <Form.Item label={t('username')} name={['settings', 'user']}>
- <Input />
- </Form.Item>
- <Form.Item label={t('password')} name={['settings', 'pass']}>
- <Input />
- </Form.Item>
- </>
- )}
- {protocol === 'hysteria' && (
- <Form.Item label="Version" name={['settings', 'version']}>
- <InputNumber min={2} max={2} disabled />
- </Form.Item>
- )}
- {protocol === 'loopback' && (
- <Form.Item label="Inbound tag" name={['settings', 'inboundTag']}>
- <Input placeholder="inbound tag used in routing rules" />
- </Form.Item>
- )}
- {protocol === 'blackhole' && (
- <Form.Item label="Response type" name={['settings', 'type']}>
- <Select
- options={[
- { value: '', label: '(empty)' },
- { value: 'none', label: 'none' },
- { value: 'http', label: 'http' },
- ]}
- />
- </Form.Item>
- )}
- {protocol === 'dns' && (
- <>
- <Form.Item label="Rewrite network" name={['settings', 'rewriteNetwork']}>
- <Select
- allowClear
- placeholder="(unchanged)"
- options={[
- { value: 'udp', label: 'udp' },
- { value: 'tcp', label: 'tcp' },
- ]}
- />
- </Form.Item>
- <Form.Item label="Rewrite address" name={['settings', 'rewriteAddress']}>
- <Input placeholder="(unchanged) e.g. 1.1.1.1" />
- </Form.Item>
- <Form.Item label="Rewrite port" name={['settings', 'rewritePort']}>
- <InputNumber min={0} max={65535} style={{ width: '100%' }} />
- </Form.Item>
- <Form.Item label="User level" name={['settings', 'userLevel']}>
- <InputNumber min={0} style={{ width: '100%' }} />
- </Form.Item>
- <Form.List name={['settings', 'rules']}>
- {(fields, { add, remove }) => (
- <>
- <Form.Item label="Rules">
- <Button
- size="small"
- type="primary"
- icon={<PlusOutlined />}
- onClick={() => add({ action: 'direct', qtype: '', domain: '' })}
- />
- </Form.Item>
- {fields.map((field, index) => (
- <div key={field.key}>
- <Form.Item wrapperCol={{ md: { span: 14, offset: 8 } }}>
- <div className="item-heading">
- <span>Rule {index + 1}</span>
- <DeleteOutlined
- className="danger-icon"
- onClick={() => remove(field.name)}
- />
- </div>
- </Form.Item>
- <Form.Item label="Action" name={[field.name, 'action']}>
- <Select
- options={DNSRuleActions.map((a) => ({ value: a, label: a }))}
- />
- </Form.Item>
- <Form.Item label="QType" name={[field.name, 'qtype']}>
- <Input placeholder="1,3,23-24" />
- </Form.Item>
- <Form.Item label={t('domainName')} name={[field.name, 'domain']}>
- <Input placeholder="domain:example.com" />
- </Form.Item>
- </div>
- ))}
- </>
- )}
- </Form.List>
- </>
- )}
- {protocol === 'freedom' && (
- <>
- <Form.Item label="Strategy" name={['settings', 'domainStrategy']}>
- <Select
- options={[
- { value: '', label: `(${t('none')})` },
- ...OutboundDomainStrategies.map((s) => ({ value: s, label: s })),
- ]}
- />
- </Form.Item>
- <Form.Item label="Redirect" name={['settings', 'redirect']}>
- <Input />
- </Form.Item>
- <Form.Item label="Fragment" shouldUpdate noStyle>
- {() => {
- const fragment = (form.getFieldValue(['settings', 'fragment']) ?? {}) as {
- packets?: string;
- length?: string;
- interval?: string;
- maxSplit?: string;
- };
- const enabled = !!(fragment.length || fragment.interval || fragment.maxSplit);
- return (
- <>
- <Form.Item label="Fragment">
- <Switch
- checked={enabled}
- onChange={(checked) => {
- form.setFieldValue(
- ['settings', 'fragment'],
- checked
- ? {
- packets: 'tlshello',
- length: '100-200',
- interval: '10-20',
- maxSplit: '300-400',
- }
- : { packets: '', length: '', interval: '', maxSplit: '' },
- );
- }}
- />
- </Form.Item>
- {enabled && (
- <>
- <Form.Item
- label="Packets"
- name={['settings', 'fragment', 'packets']}
- >
- <Select
- options={[
- { value: '1-3', label: '1-3' },
- { value: 'tlshello', label: 'tlshello' },
- ]}
- />
- </Form.Item>
- <Form.Item label="Length" name={['settings', 'fragment', 'length']}>
- <Input />
- </Form.Item>
- <Form.Item
- label="Interval"
- name={['settings', 'fragment', 'interval']}
- >
- <Input />
- </Form.Item>
- <Form.Item
- label="Max Split"
- name={['settings', 'fragment', 'maxSplit']}
- >
- <Input />
- </Form.Item>
- </>
- )}
- </>
- );
- }}
- </Form.Item>
- <Form.List name={['settings', 'noises']}>
- {(fields, { add, remove }) => (
- <>
- <Form.Item label="Noises">
- <Switch
- checked={fields.length > 0}
- onChange={(checked) => {
- if (checked) {
- add({
- type: 'rand',
- packet: '10-20',
- delay: '10-16',
- applyTo: 'ip',
- });
- } else {
- // remove() with no arg is not supported;
- // walk fields in reverse and drop each.
- for (let i = fields.length - 1; i >= 0; i--) {
- remove(fields[i].name);
- }
- }
- }}
- />
- {fields.length > 0 && (
- <Button
- size="small"
- type="primary"
- className="ml-8"
- icon={<PlusOutlined />}
- onClick={() =>
- add({
- type: 'rand',
- packet: '10-20',
- delay: '10-16',
- applyTo: 'ip',
- })
- }
- />
- )}
- </Form.Item>
- {fields.map((field, index) => (
- <div key={field.key}>
- <Form.Item wrapperCol={{ md: { span: 14, offset: 8 } }}>
- <div className="item-heading">
- <span>Noise {index + 1}</span>
- {fields.length > 1 && (
- <DeleteOutlined
- className="danger-icon"
- onClick={() => remove(field.name)}
- />
- )}
- </div>
- </Form.Item>
- <Form.Item label="Type" name={[field.name, 'type']}>
- <Select
- options={['rand', 'base64', 'str', 'hex'].map((v) => ({
- value: v,
- label: v,
- }))}
- />
- </Form.Item>
- <Form.Item label="Packet" name={[field.name, 'packet']}>
- <Input />
- </Form.Item>
- <Form.Item label="Delay (ms)" name={[field.name, 'delay']}>
- <Input />
- </Form.Item>
- <Form.Item label="Apply to" name={[field.name, 'applyTo']}>
- <Select
- options={['ip', 'ipv4', 'ipv6'].map((v) => ({
- value: v,
- label: v,
- }))}
- />
- </Form.Item>
- </div>
- ))}
- </>
- )}
- </Form.List>
- <Form.List name={['settings', 'finalRules']}>
- {(fields, { add, remove }) => (
- <>
- <Form.Item label="Final Rules">
- <Button
- size="small"
- type="primary"
- icon={<PlusOutlined />}
- onClick={() =>
- add({
- action: 'allow',
- network: '',
- port: '',
- ip: [],
- blockDelay: '',
- })
- }
- />
- <span className="ml-8" style={{ opacity: 0.6 }}>
- Override Xray's default private-IP block
- </span>
- </Form.Item>
- {fields.map((field, index) => (
- <div key={field.key}>
- <Form.Item wrapperCol={{ md: { span: 14, offset: 8 } }}>
- <div className="item-heading">
- <span>Rule {index + 1}</span>
- <DeleteOutlined
- className="danger-icon"
- onClick={() => remove(field.name)}
- />
- </div>
- </Form.Item>
- <Form.Item label="Action" name={[field.name, 'action']}>
- <Select
- options={['allow', 'block'].map((v) => ({
- value: v,
- label: v,
- }))}
- />
- </Form.Item>
- <Form.Item label="Network" name={[field.name, 'network']}>
- <Select
- allowClear
- placeholder="(any)"
- options={['tcp', 'udp', 'tcp,udp'].map((v) => ({
- value: v,
- label: v,
- }))}
- />
- </Form.Item>
- <Form.Item label="Port" name={[field.name, 'port']}>
- <Input placeholder="e.g. 80,443 or 1000-2000" />
- </Form.Item>
- <Form.Item label="IP / CIDR / geoip" name={[field.name, 'ip']}>
- <Select
- mode="tags"
- tokenSeparators={[',', ' ']}
- placeholder="e.g. 10.0.0.0/8, geoip:private"
- />
- </Form.Item>
- <Form.Item shouldUpdate noStyle>
- {() => {
- const ruleAction = form.getFieldValue([
- 'settings',
- 'finalRules',
- field.name,
- 'action',
- ]);
- if (ruleAction !== 'block') return null;
- return (
- <Form.Item
- label="Block delay (ms)"
- name={[field.name, 'blockDelay']}
- >
- <Input placeholder="optional: 5000-10000" />
- </Form.Item>
- );
- }}
- </Form.Item>
- </div>
- ))}
- </>
- )}
- </Form.List>
- </>
- )}
- {protocol === 'vless' && (
- <Form.Item shouldUpdate noStyle>
- {() => {
- const reverseTag = form.getFieldValue(['settings', 'reverseTag']);
- if (!reverseTag) return null;
- const sniff = (form.getFieldValue(['settings', 'reverseSniffing']) ?? {}) as {
- enabled?: boolean;
- };
- return (
- <>
- <Form.Item
- label="Reverse Sniffing"
- name={['settings', 'reverseSniffing', 'enabled']}
- valuePropName="checked"
- >
- <Switch />
- </Form.Item>
- {sniff.enabled && (
- <>
- <Form.Item
- wrapperCol={{ md: { span: 14, offset: 8 } }}
- name={['settings', 'reverseSniffing', 'destOverride']}
- >
- <Select
- mode="multiple"
- className="sniffing-options"
- options={Object.entries(SNIFFING_OPTION).map(([k, v]) => ({
- value: v,
- label: k,
- }))}
- />
- </Form.Item>
- <Form.Item
- label="Metadata Only"
- name={['settings', 'reverseSniffing', 'metadataOnly']}
- valuePropName="checked"
- >
- <Switch />
- </Form.Item>
- <Form.Item
- label="Route Only"
- name={['settings', 'reverseSniffing', 'routeOnly']}
- valuePropName="checked"
- >
- <Switch />
- </Form.Item>
- <Form.Item
- label="IPs Excluded"
- name={['settings', 'reverseSniffing', 'ipsExcluded']}
- >
- <Select
- mode="tags"
- tokenSeparators={[',']}
- placeholder="IP/CIDR/geoip:*"
- />
- </Form.Item>
- <Form.Item
- label="Domains Excluded"
- name={['settings', 'reverseSniffing', 'domainsExcluded']}
- >
- <Select
- mode="tags"
- tokenSeparators={[',']}
- placeholder="domain:*"
- />
- </Form.Item>
- </>
- )}
- </>
- );
- }}
- </Form.Item>
- )}
- {protocol === 'wireguard' && (
- <>
- <Form.Item label={t('pages.inbounds.address')} name={['settings', 'address']}>
- <Input placeholder="comma-separated, e.g. 10.0.0.1,fd00::1" />
- </Form.Item>
- <Form.Item
- label={
- <>
- {t('pages.inbounds.privatekey')}
- <SyncOutlined
- className="random-icon"
- onClick={() => {
- const pair = Wireguard.generateKeypair();
- form.setFieldValue(['settings', 'secretKey'], pair.privateKey);
- form.setFieldValue(['settings', 'pubKey'], pair.publicKey);
- }}
- />
- </>
- }
- name={['settings', 'secretKey']}
- >
- <Input />
- </Form.Item>
- <Form.Item label={t('pages.inbounds.publicKey')} name={['settings', 'pubKey']}>
- <Input disabled />
- </Form.Item>
- <Form.Item label="Domain strategy" name={['settings', 'domainStrategy']}>
- <Select
- options={[
- { value: '', label: `(${t('none')})` },
- ...WireguardDomainStrategy.map((s) => ({ value: s, label: s })),
- ]}
- />
- </Form.Item>
- <Form.Item label="MTU" name={['settings', 'mtu']}>
- <InputNumber min={0} />
- </Form.Item>
- <Form.Item label="Workers" name={['settings', 'workers']}>
- <InputNumber min={0} />
- </Form.Item>
- <Form.Item
- label="No-kernel TUN"
- name={['settings', 'noKernelTun']}
- valuePropName="checked"
- >
- <Switch />
- </Form.Item>
- <Form.Item label="Reserved" name={['settings', 'reserved']}>
- <Input placeholder="comma-separated bytes, e.g. 1,2,3" />
- </Form.Item>
- <Form.List name={['settings', 'peers']}>
- {(fields, { add, remove }) => (
- <>
- <Form.Item label="Peers">
- <Button
- size="small"
- type="primary"
- icon={<PlusOutlined />}
- onClick={() =>
- add({
- publicKey: '',
- psk: '',
- allowedIPs: ['0.0.0.0/0', '::/0'],
- endpoint: '',
- keepAlive: 0,
- })
- }
- />
- </Form.Item>
- {fields.map((field, index) => (
- <div key={field.key}>
- <Form.Item wrapperCol={{ md: { span: 14, offset: 8 } }}>
- <div className="item-heading">
- <span>Peer {index + 1}</span>
- {fields.length > 1 && (
- <DeleteOutlined
- className="danger-icon"
- onClick={() => remove(field.name)}
- />
- )}
- </div>
- </Form.Item>
- <Form.Item label="Endpoint" name={[field.name, 'endpoint']}>
- <Input />
- </Form.Item>
- <Form.Item
- label={t('pages.inbounds.publicKey')}
- name={[field.name, 'publicKey']}
- >
- <Input />
- </Form.Item>
- <Form.Item label="PSK" name={[field.name, 'psk']}>
- <Input />
- </Form.Item>
- <Form.Item label="Allowed IPs">
- <Form.List name={[field.name, 'allowedIPs']}>
- {(ipFields, { add: addIp, remove: removeIp }) => (
- <>
- {ipFields.map((ipField, ipIdx) => (
- <Space.Compact
- key={ipField.key}
- block
- style={{ marginBottom: 4 }}
- >
- <Form.Item noStyle name={ipField.name}>
- <Input />
- </Form.Item>
- {ipFields.length > 1 && (
- <InputAddon onClick={() => removeIp(ipIdx)}>
- <MinusOutlined />
- </InputAddon>
- )}
- </Space.Compact>
- ))}
- <Button
- size="small"
- icon={<PlusOutlined />}
- onClick={() => addIp('')}
- />
- </>
- )}
- </Form.List>
- </Form.Item>
- <Form.Item label="Keep alive" name={[field.name, 'keepAlive']}>
- <InputNumber min={0} />
- </Form.Item>
- </div>
- ))}
- </>
- )}
- </Form.List>
- </>
- )}
- {streamAllowed && network && (
- <>
- <Form.Item
- label={t('transmission')}
- name={['streamSettings', 'network']}
- >
- <Select
- value={network}
- onChange={onNetworkChange}
- options={
- protocol === 'hysteria'
- ? [...NETWORK_OPTIONS, HYSTERIA_NETWORK_OPTION]
- : NETWORK_OPTIONS
- }
- />
- </Form.Item>
- {network === 'tcp' && (
- <Form.Item shouldUpdate noStyle>
- {() => {
- const type =
- form.getFieldValue([
- 'streamSettings',
- 'tcpSettings',
- 'header',
- 'type',
- ]) ?? 'none';
- return (
- <>
- <Form.Item label={`HTTP ${t('camouflage')}`}>
- <Switch
- checked={type === 'http'}
- onChange={(checked) =>
- form.setFieldValue(
- ['streamSettings', 'tcpSettings', 'header'],
- checked
- ? {
- type: 'http',
- request: {
- version: '1.1',
- method: 'GET',
- path: ['/'],
- headers: {},
- },
- response: {
- version: '1.1',
- status: '200',
- reason: 'OK',
- headers: {},
- },
- }
- : { type: 'none' },
- )
- }
- />
- </Form.Item>
- {type === 'http' && (
- <>
- <Form.Item
- label="Request method"
- name={[
- 'streamSettings', 'tcpSettings', 'header',
- 'request', 'method',
- ]}
- >
- <Input placeholder="GET" />
- </Form.Item>
- <Form.Item
- label="Request version"
- name={[
- 'streamSettings', 'tcpSettings', 'header',
- 'request', 'version',
- ]}
- >
- <Input placeholder="1.1" />
- </Form.Item>
- <Form.Item
- label={t('host')}
- name={[
- 'streamSettings',
- 'tcpSettings',
- 'header',
- 'request',
- 'headers',
- 'Host',
- ]}
- normalize={(v: unknown) =>
- typeof v === 'string'
- ? v.split(',').map((s) => s.trim()).filter(Boolean)
- : Array.isArray(v) ? v : []
- }
- getValueProps={(v: unknown) => ({
- value: Array.isArray(v) ? v.join(',') : '',
- })}
- >
- <Input placeholder="example.com,cdn.example.com" />
- </Form.Item>
- <Form.Item
- label={t('path')}
- name={[
- 'streamSettings',
- 'tcpSettings',
- 'header',
- 'request',
- 'path',
- ]}
- normalize={(v: unknown) =>
- typeof v === 'string'
- ? v.split(',').map((s) => s.trim()).filter(Boolean)
- : Array.isArray(v) ? v : ['/']
- }
- getValueProps={(v: unknown) => ({
- value: Array.isArray(v) ? v.join(',') : '/',
- })}
- >
- <Input placeholder="/,/api,/static" />
- </Form.Item>
- <Form.Item
- label="Request headers"
- name={[
- 'streamSettings', 'tcpSettings', 'header',
- 'request', 'headers',
- ]}
- >
- <HeaderMapEditor mode="v2" />
- </Form.Item>
- <Form.Item
- label="Response version"
- name={[
- 'streamSettings', 'tcpSettings', 'header',
- 'response', 'version',
- ]}
- >
- <Input placeholder="1.1" />
- </Form.Item>
- <Form.Item
- label="Response status"
- name={[
- 'streamSettings', 'tcpSettings', 'header',
- 'response', 'status',
- ]}
- >
- <Input placeholder="200" />
- </Form.Item>
- <Form.Item
- label="Response reason"
- name={[
- 'streamSettings', 'tcpSettings', 'header',
- 'response', 'reason',
- ]}
- >
- <Input placeholder="OK" />
- </Form.Item>
- <Form.Item
- label="Response headers"
- name={[
- 'streamSettings', 'tcpSettings', 'header',
- 'response', 'headers',
- ]}
- >
- <HeaderMapEditor mode="v2" />
- </Form.Item>
- </>
- )}
- </>
- );
- }}
- </Form.Item>
- )}
- {network === 'kcp' && (
- <>
- <Form.Item label="MTU" name={['streamSettings', 'kcpSettings', 'mtu']}>
- <InputNumber min={0} />
- </Form.Item>
- <Form.Item label="TTI (ms)" name={['streamSettings', 'kcpSettings', 'tti']}>
- <InputNumber min={0} />
- </Form.Item>
- <Form.Item
- label="Uplink (MB/s)"
- name={['streamSettings', 'kcpSettings', 'uplinkCapacity']}
- >
- <InputNumber min={0} />
- </Form.Item>
- <Form.Item
- label="Downlink (MB/s)"
- name={['streamSettings', 'kcpSettings', 'downlinkCapacity']}
- >
- <InputNumber min={0} />
- </Form.Item>
- <Form.Item
- label="CWND multiplier"
- name={['streamSettings', 'kcpSettings', 'cwndMultiplier']}
- >
- <InputNumber min={1} />
- </Form.Item>
- <Form.Item
- label="Max sending window"
- name={['streamSettings', 'kcpSettings', 'maxSendingWindow']}
- >
- <InputNumber min={0} />
- </Form.Item>
- </>
- )}
- {network === 'ws' && (
- <>
- <Form.Item label={t('host')} name={['streamSettings', 'wsSettings', 'host']}>
- <Input />
- </Form.Item>
- <Form.Item label={t('path')} name={['streamSettings', 'wsSettings', 'path']}>
- <Input />
- </Form.Item>
- <Form.Item
- label="Heartbeat (s)"
- name={['streamSettings', 'wsSettings', 'heartbeatPeriod']}
- >
- <InputNumber min={0} />
- </Form.Item>
- <Form.Item
- label="Headers"
- name={['streamSettings', 'wsSettings', 'headers']}
- >
- <HeaderMapEditor mode="v1" />
- </Form.Item>
- </>
- )}
- {network === 'grpc' && (
- <>
- <Form.Item
- label="Service name"
- name={['streamSettings', 'grpcSettings', 'serviceName']}
- >
- <Input />
- </Form.Item>
- <Form.Item
- label="Authority"
- name={['streamSettings', 'grpcSettings', 'authority']}
- >
- <Input />
- </Form.Item>
- <Form.Item
- label="Multi mode"
- name={['streamSettings', 'grpcSettings', 'multiMode']}
- valuePropName="checked"
- >
- <Switch />
- </Form.Item>
- </>
- )}
- {network === 'httpupgrade' && (
- <>
- <Form.Item
- label={t('host')}
- name={['streamSettings', 'httpupgradeSettings', 'host']}
- >
- <Input />
- </Form.Item>
- <Form.Item
- label={t('path')}
- name={['streamSettings', 'httpupgradeSettings', 'path']}
- >
- <Input />
- </Form.Item>
- <Form.Item
- label="Headers"
- name={['streamSettings', 'httpupgradeSettings', 'headers']}
- >
- <HeaderMapEditor mode="v1" />
- </Form.Item>
- </>
- )}
- {network === 'xhttp' && (
- <>
- <Form.Item
- label={t('host')}
- name={['streamSettings', 'xhttpSettings', 'host']}
- >
- <Input />
- </Form.Item>
- <Form.Item
- label={t('path')}
- name={['streamSettings', 'xhttpSettings', 'path']}
- >
- <Input />
- </Form.Item>
- <Form.Item
- label="Mode"
- name={['streamSettings', 'xhttpSettings', 'mode']}
- >
- <Select options={MODE_OPTIONS} />
- </Form.Item>
- <Form.Item
- label="Padding Bytes"
- name={['streamSettings', 'xhttpSettings', 'xPaddingBytes']}
- >
- <Input />
- </Form.Item>
- <Form.Item
- label="Headers"
- name={['streamSettings', 'xhttpSettings', 'headers']}
- >
- <HeaderMapEditor mode="v1" />
- </Form.Item>
- {/* Padding obfs sub-section: gated by a Switch.
- When on, four extra knobs (key/header/placement/
- method) tune how Xray injects random padding to
- disguise the post body shape. */}
- <Form.Item
- label="Padding obfs mode"
- name={['streamSettings', 'xhttpSettings', 'xPaddingObfsMode']}
- valuePropName="checked"
- >
- <Switch />
- </Form.Item>
- <Form.Item shouldUpdate noStyle>
- {() => {
- const obfs = !!form.getFieldValue([
- 'streamSettings', 'xhttpSettings', 'xPaddingObfsMode',
- ]);
- if (!obfs) return null;
- return (
- <>
- <Form.Item
- label="Padding key"
- name={['streamSettings', 'xhttpSettings', 'xPaddingKey']}
- >
- <Input placeholder="x_padding" />
- </Form.Item>
- <Form.Item
- label="Padding header"
- name={['streamSettings', 'xhttpSettings', 'xPaddingHeader']}
- >
- <Input placeholder="X-Padding" />
- </Form.Item>
- <Form.Item
- label="Padding placement"
- name={['streamSettings', 'xhttpSettings', 'xPaddingPlacement']}
- >
- <Select
- options={[
- { value: '', label: 'Default (queryInHeader)' },
- { value: 'queryInHeader', label: 'queryInHeader' },
- { value: 'header', label: 'header' },
- { value: 'cookie', label: 'cookie' },
- { value: 'query', label: 'query' },
- ]}
- />
- </Form.Item>
- <Form.Item
- label="Padding method"
- name={['streamSettings', 'xhttpSettings', 'xPaddingMethod']}
- >
- <Select
- options={[
- { value: '', label: 'Default (repeat-x)' },
- { value: 'repeat-x', label: 'repeat-x' },
- { value: 'tokenish', label: 'tokenish' },
- ]}
- />
- </Form.Item>
- </>
- );
- }}
- </Form.Item>
- <Form.Item
- noStyle
- shouldUpdate={(prev, curr) =>
- prev?.streamSettings?.xhttpSettings?.mode !==
- curr?.streamSettings?.xhttpSettings?.mode
- }
- >
- {() => {
- const mode = form.getFieldValue([
- 'streamSettings', 'xhttpSettings', 'mode',
- ]);
- return (
- <Form.Item
- label="Uplink HTTP method"
- name={['streamSettings', 'xhttpSettings', 'uplinkHTTPMethod']}
- >
- <Select
- placeholder="Default (POST)"
- options={[
- { value: '', label: 'Default (POST)' },
- { value: 'POST', label: 'POST' },
- { value: 'PUT', label: 'PUT' },
- { value: 'GET', label: 'GET (packet-up only)', disabled: mode !== 'packet-up' },
- ]}
- />
- </Form.Item>
- );
- }}
- </Form.Item>
- {/* Session + sequence + uplinkData placements:
- three orthogonal slots Xray uses to thread
- request metadata through the transport
- (path / header / cookie / query). Key field
- only matters when placement is not 'path'. */}
- <Form.Item
- label="Session placement"
- name={['streamSettings', 'xhttpSettings', 'sessionPlacement']}
- >
- <Select
- placeholder="Default (path)"
- options={[
- { value: '', label: 'Default (path)' },
- { value: 'path', label: 'path' },
- { value: 'header', label: 'header' },
- { value: 'cookie', label: 'cookie' },
- { value: 'query', label: 'query' },
- ]}
- />
- </Form.Item>
- <Form.Item shouldUpdate noStyle>
- {() => {
- const placement = form.getFieldValue([
- 'streamSettings', 'xhttpSettings', 'sessionPlacement',
- ]);
- if (!placement || placement === 'path') return null;
- return (
- <Form.Item
- label="Session key"
- name={['streamSettings', 'xhttpSettings', 'sessionKey']}
- >
- <Input placeholder="x_session" />
- </Form.Item>
- );
- }}
- </Form.Item>
- <Form.Item
- label="Sequence placement"
- name={['streamSettings', 'xhttpSettings', 'seqPlacement']}
- >
- <Select
- placeholder="Default (path)"
- options={[
- { value: '', label: 'Default (path)' },
- { value: 'path', label: 'path' },
- { value: 'header', label: 'header' },
- { value: 'cookie', label: 'cookie' },
- { value: 'query', label: 'query' },
- ]}
- />
- </Form.Item>
- <Form.Item shouldUpdate noStyle>
- {() => {
- const placement = form.getFieldValue([
- 'streamSettings', 'xhttpSettings', 'seqPlacement',
- ]);
- if (!placement || placement === 'path') return null;
- return (
- <Form.Item
- label="Sequence key"
- name={['streamSettings', 'xhttpSettings', 'seqKey']}
- >
- <Input placeholder="x_seq" />
- </Form.Item>
- );
- }}
- </Form.Item>
- {/* Mode-conditional sub-sections. */}
- <Form.Item shouldUpdate noStyle>
- {() => {
- const mode = form.getFieldValue([
- 'streamSettings', 'xhttpSettings', 'mode',
- ]);
- if (mode !== 'packet-up') return null;
- return (
- <>
- <Form.Item
- label="Min upload interval (ms)"
- name={['streamSettings', 'xhttpSettings', 'scMinPostsIntervalMs']}
- >
- <Input placeholder="30" />
- </Form.Item>
- <Form.Item
- label="Max upload size (bytes)"
- name={['streamSettings', 'xhttpSettings', 'scMaxEachPostBytes']}
- >
- <Input placeholder="1000000" />
- </Form.Item>
- <Form.Item
- label="Uplink data placement"
- name={['streamSettings', 'xhttpSettings', 'uplinkDataPlacement']}
- >
- <Select
- options={[
- { value: '', label: 'Default (body)' },
- { value: 'body', label: 'body' },
- { value: 'header', label: 'header' },
- { value: 'cookie', label: 'cookie' },
- { value: 'query', label: 'query' },
- ]}
- />
- </Form.Item>
- <Form.Item shouldUpdate noStyle>
- {() => {
- const place = form.getFieldValue([
- 'streamSettings', 'xhttpSettings', 'uplinkDataPlacement',
- ]);
- if (!place || place === 'body') return null;
- return (
- <>
- <Form.Item
- label="Uplink data key"
- name={['streamSettings', 'xhttpSettings', 'uplinkDataKey']}
- >
- <Input placeholder="x_data" />
- </Form.Item>
- <Form.Item
- label="Uplink chunk size"
- name={['streamSettings', 'xhttpSettings', 'uplinkChunkSize']}
- >
- <InputNumber
- min={0}
- placeholder="0 (unlimited)"
- style={{ width: '100%' }}
- />
- </Form.Item>
- </>
- );
- }}
- </Form.Item>
- </>
- );
- }}
- </Form.Item>
- <Form.Item shouldUpdate noStyle>
- {() => {
- const mode = form.getFieldValue([
- 'streamSettings', 'xhttpSettings', 'mode',
- ]);
- if (mode !== 'stream-up' && mode !== 'stream-one') return null;
- return (
- <Form.Item
- label="No gRPC header"
- name={['streamSettings', 'xhttpSettings', 'noGRPCHeader']}
- valuePropName="checked"
- >
- <Switch />
- </Form.Item>
- );
- }}
- </Form.Item>
- {/* XMUX is the connection-multiplexing layer
- xHTTP uses to fan out parallel requests over
- a small pool of upstream connections. UI-only
- toggle (enableXmux) hides the 6 nested knobs
- when off. */}
- <Form.Item
- label="XMUX"
- name={['streamSettings', 'xhttpSettings', 'enableXmux']}
- valuePropName="checked"
- >
- <Switch />
- </Form.Item>
- <Form.Item shouldUpdate noStyle>
- {() => {
- if (!form.getFieldValue([
- 'streamSettings', 'xhttpSettings', 'enableXmux',
- ])) return null;
- return (
- <>
- <Form.Item
- label="Max concurrency"
- name={['streamSettings', 'xhttpSettings', 'xmux', 'maxConcurrency']}
- >
- <Input placeholder="16-32" />
- </Form.Item>
- <Form.Item
- label="Max connections"
- name={['streamSettings', 'xhttpSettings', 'xmux', 'maxConnections']}
- >
- <Input placeholder="0" />
- </Form.Item>
- <Form.Item
- label="Max reuse times"
- name={['streamSettings', 'xhttpSettings', 'xmux', 'cMaxReuseTimes']}
- >
- <Input />
- </Form.Item>
- <Form.Item
- label="Max request times"
- name={['streamSettings', 'xhttpSettings', 'xmux', 'hMaxRequestTimes']}
- >
- <Input placeholder="600-900" />
- </Form.Item>
- <Form.Item
- label="Max reusable secs"
- name={['streamSettings', 'xhttpSettings', 'xmux', 'hMaxReusableSecs']}
- >
- <Input placeholder="1800-3000" />
- </Form.Item>
- <Form.Item
- label="Keep alive period"
- name={['streamSettings', 'xhttpSettings', 'xmux', 'hKeepAlivePeriod']}
- >
- <InputNumber min={0} style={{ width: '100%' }} />
- </Form.Item>
- </>
- );
- }}
- </Form.Item>
- </>
- )}
- {network === 'hysteria' && (
- <>
- <Form.Item
- label="Auth password"
- name={['streamSettings', 'hysteriaSettings', 'auth']}
- >
- <Input />
- </Form.Item>
- <Form.Item
- label="UDP idle timeout (s)"
- name={['streamSettings', 'hysteriaSettings', 'udpIdleTimeout']}
- >
- <InputNumber min={1} style={{ width: '100%' }} />
- </Form.Item>
- </>
- )}
- </>
- )}
- {tlsFlowAllowed && (
- <Form.Item label="Flow" name={['settings', 'flow']}>
- <Select
- allowClear
- placeholder={t('none')}
- options={FLOW_OPTIONS}
- />
- </Form.Item>
- )}
- {/* Vision seed knobs only meaningful for the exact
- xtls-rprx-vision flow, on TCP+(tls|reality). The
- legacy class gated this on `canEnableVisionSeed()`
- — same condition encoded inline here. */}
- <Form.Item shouldUpdate noStyle>
- {() => {
- const flow =
- (form.getFieldValue(['settings', 'flow']) ?? '') as string;
- if (!(tlsFlowAllowed && flow === 'xtls-rprx-vision')) return null;
- return (
- <>
- <Form.Item label="Vision testpre" name={['settings', 'testpre']}>
- <InputNumber min={0} style={{ width: '100%' }} />
- </Form.Item>
- <Form.Item
- label="Vision testseed"
- name={['settings', 'testseed']}
- normalize={(v: unknown) =>
- Array.isArray(v)
- ? v
- .map((x) => Number(x))
- .filter((n) => Number.isInteger(n) && n > 0)
- : []
- }
- >
- <Select
- mode="tags"
- tokenSeparators={[',', ' ']}
- placeholder="four positive integers"
- />
- </Form.Item>
- </>
- );
- }}
- </Form.Item>
- {streamAllowed && network && (
- <Form.Item label={t('security')}>
- <Radio.Group
- value={security}
- buttonStyle="solid"
- onChange={(e) => onSecurityChange(e.target.value as string)}
- >
- <Radio.Button value="none">{t('none')}</Radio.Button>
- {tlsAllowed && <Radio.Button value="tls">TLS</Radio.Button>}
- {realityAllowed && <Radio.Button value="reality">Reality</Radio.Button>}
- </Radio.Group>
- </Form.Item>
- )}
- {security === 'tls' && tlsAllowed && (
- <>
- <Form.Item
- label="SNI"
- name={['streamSettings', 'tlsSettings', 'serverName']}
- >
- <Input placeholder="server name" />
- </Form.Item>
- <Form.Item
- label="uTLS"
- name={['streamSettings', 'tlsSettings', 'fingerprint']}
- >
- <Select
- allowClear
- placeholder={t('none')}
- options={UTLS_OPTIONS}
- />
- </Form.Item>
- <Form.Item
- label="ALPN"
- name={['streamSettings', 'tlsSettings', 'alpn']}
- >
- <Select mode="multiple" options={ALPN_OPTIONS} />
- </Form.Item>
- <Form.Item
- label="ECH"
- name={['streamSettings', 'tlsSettings', 'echConfigList']}
- >
- <Input />
- </Form.Item>
- <Form.Item
- label="Verify peer name"
- name={['streamSettings', 'tlsSettings', 'verifyPeerCertByName']}
- >
- <Input placeholder="cloudflare-dns.com" />
- </Form.Item>
- <Form.Item
- label="Pinned SHA256"
- name={['streamSettings', 'tlsSettings', 'pinnedPeerCertSha256']}
- >
- <Input placeholder="base64 SHA256" />
- </Form.Item>
- </>
- )}
- {security === 'reality' && realityAllowed && (
- <>
- <Form.Item
- label="SNI"
- name={['streamSettings', 'realitySettings', 'serverName']}
- >
- <Input />
- </Form.Item>
- <Form.Item
- label="uTLS"
- name={['streamSettings', 'realitySettings', 'fingerprint']}
- >
- <Select options={UTLS_OPTIONS} />
- </Form.Item>
- <Form.Item
- label="Short ID"
- name={['streamSettings', 'realitySettings', 'shortId']}
- >
- <Input />
- </Form.Item>
- <Form.Item
- label="SpiderX"
- name={['streamSettings', 'realitySettings', 'spiderX']}
- >
- <Input />
- </Form.Item>
- <Form.Item
- label={t('pages.inbounds.publicKey')}
- name={['streamSettings', 'realitySettings', 'publicKey']}
- >
- <Input.TextArea autoSize={{ minRows: 2 }} />
- </Form.Item>
- <Form.Item
- label="mldsa65 verify"
- name={['streamSettings', 'realitySettings', 'mldsa65Verify']}
- >
- <Input.TextArea autoSize={{ minRows: 2 }} />
- </Form.Item>
- </>
- )}
- {((streamAllowed && network) || !streamAllowed) && (
- <Form.Item shouldUpdate noStyle>
- {() => {
- const hasSockopt = !!form.getFieldValue([
- 'streamSettings',
- 'sockopt',
- ]);
- return (
- <>
- <Form.Item label="Sockopts">
- <Switch
- checked={hasSockopt}
- onChange={(checked) => {
- form.setFieldValue(
- ['streamSettings', 'sockopt'],
- checked ? SockoptStreamSettingsSchema.parse({}) : undefined,
- );
- }}
- />
- </Form.Item>
- {hasSockopt && (
- <>
- <Form.Item
- label="Dialer proxy"
- name={['streamSettings', 'sockopt', 'dialerProxy']}
- >
- <Input />
- </Form.Item>
- <Form.Item
- label="Domain strategy"
- name={['streamSettings', 'sockopt', 'domainStrategy']}
- >
- <Select
- options={Object.values(DOMAIN_STRATEGY_OPTION).map((v) => ({
- value: v,
- label: v,
- }))}
- />
- </Form.Item>
- <Form.Item
- label="Address+port strategy"
- name={['streamSettings', 'sockopt', 'addressPortStrategy']}
- >
- <Select options={ADDRESS_PORT_STRATEGY_OPTIONS} />
- </Form.Item>
- <Form.Item
- label="Keep alive interval"
- name={['streamSettings', 'sockopt', 'tcpKeepAliveInterval']}
- >
- <InputNumber min={0} />
- </Form.Item>
- <Form.Item
- label="TCP Fast Open"
- name={['streamSettings', 'sockopt', 'tcpFastOpen']}
- valuePropName="checked"
- >
- <Switch />
- </Form.Item>
- <Form.Item
- label="Multipath TCP"
- name={['streamSettings', 'sockopt', 'tcpMptcp']}
- valuePropName="checked"
- >
- <Switch />
- </Form.Item>
- <Form.Item
- label="Penetrate"
- name={['streamSettings', 'sockopt', 'penetrate']}
- valuePropName="checked"
- >
- <Switch />
- </Form.Item>
- <Form.Item
- label="Mark (fwmark)"
- name={['streamSettings', 'sockopt', 'mark']}
- >
- <InputNumber min={0} />
- </Form.Item>
- <Form.Item
- label="Interface"
- name={['streamSettings', 'sockopt', 'interfaceName']}
- >
- <Input />
- </Form.Item>
- <Form.Item
- label="TProxy"
- name={['streamSettings', 'sockopt', 'tproxy']}
- >
- <Select
- options={[
- { value: 'off', label: 'off' },
- { value: 'redirect', label: 'redirect' },
- { value: 'tproxy', label: 'tproxy' },
- ]}
- />
- </Form.Item>
- <Form.Item
- label="TCP congestion"
- name={['streamSettings', 'sockopt', 'tcpcongestion']}
- >
- <Select
- options={Object.values(TCP_CONGESTION_OPTION).map((v) => ({
- value: v,
- label: v,
- }))}
- />
- </Form.Item>
- <Form.Item
- label="IPv6 only"
- name={['streamSettings', 'sockopt', 'V6Only']}
- valuePropName="checked"
- >
- <Switch />
- </Form.Item>
- <Form.Item
- label="Accept proxy protocol"
- name={['streamSettings', 'sockopt', 'acceptProxyProtocol']}
- valuePropName="checked"
- >
- <Switch />
- </Form.Item>
- <Form.Item
- label="TCP user timeout (ms)"
- name={['streamSettings', 'sockopt', 'tcpUserTimeout']}
- >
- <InputNumber min={0} style={{ width: '100%' }} />
- </Form.Item>
- <Form.Item
- label="TCP keep-alive idle (s)"
- name={['streamSettings', 'sockopt', 'tcpKeepAliveIdle']}
- >
- <InputNumber min={0} style={{ width: '100%' }} />
- </Form.Item>
- <Form.Item
- label="TCP max segment"
- name={['streamSettings', 'sockopt', 'tcpMaxSeg']}
- >
- <InputNumber min={0} style={{ width: '100%' }} />
- </Form.Item>
- <Form.Item
- label="TCP window clamp"
- name={['streamSettings', 'sockopt', 'tcpWindowClamp']}
- >
- <InputNumber min={0} style={{ width: '100%' }} />
- </Form.Item>
- <Form.Item
- label="Trusted X-Forwarded-For"
- name={['streamSettings', 'sockopt', 'trustedXForwardedFor']}
- >
- <Select
- mode="tags"
- tokenSeparators={[',', ' ']}
- placeholder="trusted-proxy.example,10.0.0.0/8"
- />
- </Form.Item>
- <Form.Item shouldUpdate noStyle>
- {() => {
- const he = form.getFieldValue([
- 'streamSettings', 'sockopt', 'happyEyeballs',
- ]);
- const hasHe = he != null;
- return (
- <>
- <Form.Item label="Happy Eyeballs">
- <Switch
- checked={hasHe}
- onChange={(v) => {
- form.setFieldValue(
- ['streamSettings', 'sockopt', 'happyEyeballs'],
- v ? HappyEyeballsSchema.parse({}) : undefined,
- );
- }}
- />
- </Form.Item>
- {hasHe && (
- <>
- <Form.Item
- label="Try delay (ms)"
- name={['streamSettings', 'sockopt', 'happyEyeballs', 'tryDelayMs']}
- >
- <InputNumber min={0} style={{ width: '100%' }} placeholder="0 (disabled) — 250 recommended" />
- </Form.Item>
- <Form.Item
- label="Prioritize IPv6"
- name={['streamSettings', 'sockopt', 'happyEyeballs', 'prioritizeIPv6']}
- valuePropName="checked"
- >
- <Switch />
- </Form.Item>
- <Form.Item
- label="Interleave"
- name={['streamSettings', 'sockopt', 'happyEyeballs', 'interleave']}
- >
- <InputNumber min={1} style={{ width: '100%' }} />
- </Form.Item>
- <Form.Item
- label="Max concurrent try"
- name={['streamSettings', 'sockopt', 'happyEyeballs', 'maxConcurrentTry']}
- >
- <InputNumber min={0} style={{ width: '100%' }} />
- </Form.Item>
- </>
- )}
- </>
- );
- }}
- </Form.Item>
- <Form.List name={['streamSettings', 'sockopt', 'customSockopt']}>
- {(fields, { add, remove }) => (
- <>
- <Form.Item label="Custom sockopt">
- <Button
- type="dashed"
- size="small"
- onClick={() => add({ type: 'int', level: '6', opt: '', value: '' })}
- >
- + Add custom option
- </Button>
- </Form.Item>
- {fields.map((field) => (
- <Space.Compact key={field.key} style={{ display: 'flex', marginBottom: 8 }}>
- <Form.Item name={[field.name, 'system']} noStyle>
- <Select
- placeholder="all"
- allowClear
- style={{ width: 100 }}
- options={[
- { value: 'linux', label: 'linux' },
- { value: 'windows', label: 'windows' },
- { value: 'darwin', label: 'darwin' },
- ]}
- />
- </Form.Item>
- <Form.Item name={[field.name, 'type']} noStyle>
- <Select
- style={{ width: 80 }}
- options={[
- { value: 'int', label: 'int' },
- { value: 'str', label: 'str' },
- ]}
- />
- </Form.Item>
- <Form.Item name={[field.name, 'level']} noStyle>
- <Input placeholder="level (6=TCP)" style={{ width: 100 }} />
- </Form.Item>
- <Form.Item name={[field.name, 'opt']} noStyle>
- <Input placeholder="opt (decimal)" style={{ width: 120 }} />
- </Form.Item>
- <Form.Item name={[field.name, 'value']} noStyle>
- <Input placeholder="value" style={{ flex: 1 }} />
- </Form.Item>
- <Button danger onClick={() => remove(field.name)}>−</Button>
- </Space.Compact>
- ))}
- </>
- )}
- </Form.List>
- </>
- )}
- </>
- );
- }}
- </Form.Item>
- )}
- <FinalMaskForm
- name={['streamSettings', 'finalmask']}
- network={network}
- protocol={protocol}
- form={form}
- />
- {(() => {
- const flow = (form.getFieldValue(['settings', 'flow']) ?? '') as string;
- if (!isMuxAllowed(protocol, flow, network)) return null;
- return (
- <Form.Item shouldUpdate noStyle>
- {() => {
- const muxEnabled = !!form.getFieldValue(['mux', 'enabled']);
- return (
- <>
- <Form.Item
- label={t('pages.settings.mux')}
- name={['mux', 'enabled']}
- valuePropName="checked"
- >
- <Switch />
- </Form.Item>
- {muxEnabled && (
- <>
- <Form.Item
- label="Concurrency"
- name={['mux', 'concurrency']}
- >
- <InputNumber min={-1} max={1024} />
- </Form.Item>
- <Form.Item
- label="xudp concurrency"
- name={['mux', 'xudpConcurrency']}
- >
- <InputNumber min={-1} max={1024} />
- </Form.Item>
- <Form.Item
- label="xudp UDP 443"
- name={['mux', 'xudpProxyUDP443']}
- >
- <Select
- options={['reject', 'allow', 'skip'].map((v) => ({
- value: v,
- label: v,
- }))}
- />
- </Form.Item>
- </>
- )}
- </>
- );
- }}
- </Form.Item>
- );
- })()}
- </>
- ),
- },
- {
- key: '2',
- label: 'JSON',
- children: (
- <Space orientation="vertical" size={10} style={{ width: '100%', marginTop: 10 }}>
- <Input.Search
- value={linkInput}
- placeholder="vmess:// vless:// trojan:// ss:// hysteria2://"
- enterButton="Import"
- onChange={(e) => setLinkInput(e.target.value)}
- onSearch={importLink}
- />
- <JsonEditor
- value={jsonText}
- onChange={(next) => {
- setJsonText(next);
- setJsonDirty(true);
- }}
- minHeight="360px"
- maxHeight="600px"
- />
- </Space>
- ),
- },
- ]}
- />
- </Form>
- </Modal>
- </>
- );
- }
|