OutboundFormModal.tsx 111 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241
  1. import { useEffect, useMemo, useState } from 'react';
  2. import { useTranslation } from 'react-i18next';
  3. import {
  4. Button,
  5. Form,
  6. Input,
  7. InputNumber,
  8. Modal,
  9. Radio,
  10. Select,
  11. Space,
  12. Switch,
  13. Tabs,
  14. message,
  15. } from 'antd';
  16. import { DeleteOutlined, MinusOutlined, PlusOutlined, ReloadOutlined } from '@ant-design/icons';
  17. import FinalMaskForm from '@/components/FinalMaskForm';
  18. import HeaderMapEditor from '@/components/HeaderMapEditor';
  19. import InputAddon from '@/components/InputAddon';
  20. import JsonEditor from '@/components/JsonEditor';
  21. import { Wireguard } from '@/utils';
  22. import {
  23. formValuesToWirePayload,
  24. rawOutboundToFormValues,
  25. } from '@/lib/xray/outbound-form-adapter';
  26. import { parseOutboundLink } from '@/lib/xray/outbound-link-parser';
  27. import {
  28. OutboundFormBaseSchema,
  29. ShadowsocksOutboundFormSettingsSchema,
  30. TrojanOutboundFormSettingsSchema,
  31. VlessOutboundFormSettingsSchema,
  32. VmessOutboundFormSettingsSchema,
  33. type OutboundFormValues,
  34. } from '@/schemas/forms/outbound-form';
  35. import {
  36. ALPN_OPTION,
  37. Address_Port_Strategy,
  38. DNSRuleActions,
  39. DOMAIN_STRATEGY_OPTION,
  40. MODE_OPTION,
  41. OutboundDomainStrategies,
  42. OutboundProtocols as Protocols,
  43. SNIFFING_OPTION,
  44. TCP_CONGESTION_OPTION,
  45. TLS_FLOW_CONTROL,
  46. USERS_SECURITY,
  47. UTLS_FINGERPRINT,
  48. WireguardDomainStrategy,
  49. } from '@/schemas/primitives';
  50. import {
  51. HappyEyeballsSchema,
  52. SockoptStreamSettingsSchema,
  53. } from '@/schemas/protocols/stream/sockopt';
  54. import {
  55. canEnableReality,
  56. canEnableStream,
  57. canEnableTls,
  58. canEnableTlsFlow,
  59. } from '@/lib/xray/protocol-capabilities';
  60. import { SSMethodSchema } from '@/schemas/protocols/inbound/shadowsocks';
  61. import { antdRule } from '@/utils/zodForm';
  62. import './OutboundFormModal.css';
  63. // Pattern A rewrite of OutboundFormModal. Built as a sibling `.new.tsx`
  64. // file so the build stays green section-by-section. The atomic swap at
  65. // the end of the rewrite replaces the legacy file in one commit
  66. // (per Core Decision 7 in the migration spec).
  67. interface OutboundFormModalProps {
  68. open: boolean;
  69. outbound: Record<string, unknown> | null;
  70. existingTags: string[];
  71. onClose: () => void;
  72. onConfirm: (outbound: Record<string, unknown>) => void;
  73. }
  74. const PROTOCOL_OPTIONS = Object.values(Protocols).map((p) => ({ value: p, label: p }));
  75. const SECURITY_OPTIONS = Object.values(USERS_SECURITY).map((v) => ({ value: v, label: v }));
  76. const FLOW_OPTIONS = Object.values(TLS_FLOW_CONTROL).map((v) => ({ value: v, label: v }));
  77. const SS_METHOD_OPTIONS = SSMethodSchema.options.map((v) => ({ value: v, label: v }));
  78. const MODE_OPTIONS = Object.values(MODE_OPTION).map((v) => ({ value: v, label: v }));
  79. const UTLS_OPTIONS = Object.values(UTLS_FINGERPRINT).map((v) => ({ value: v, label: v }));
  80. const ALPN_OPTIONS = Object.values(ALPN_OPTION).map((v) => ({ value: v, label: v }));
  81. const ADDRESS_PORT_STRATEGY_OPTIONS = Object.values(Address_Port_Strategy).map((v) => ({
  82. value: v,
  83. label: v,
  84. }));
  85. // canEnableMux mirrors the adapter's helper but lives here so the modal
  86. // can show/hide the Mux section without going through the adapter.
  87. const MUX_PROTOCOLS = new Set<string>(['vmess', 'vless', 'trojan', 'shadowsocks', 'http', 'socks']);
  88. function isMuxAllowed(protocol: string, flow: string, network: string): boolean {
  89. if (!MUX_PROTOCOLS.has(protocol)) return false;
  90. if (protocol === 'vless' && flow) return false;
  91. if (network === 'xhttp') return false;
  92. return true;
  93. }
  94. const NETWORK_OPTIONS: { value: string; label: string }[] = [
  95. { value: 'tcp', label: 'RAW' },
  96. { value: 'kcp', label: 'mKCP' },
  97. { value: 'ws', label: 'WebSocket' },
  98. { value: 'grpc', label: 'gRPC' },
  99. { value: 'httpupgrade', label: 'HTTPUpgrade' },
  100. { value: 'xhttp', label: 'XHTTP' },
  101. ];
  102. // Hysteria appends an extra `hysteria` network branch to the selector
  103. // — only when the parent protocol is hysteria. Wire-side this matches
  104. // the legacy modal's `isHysteria ? [...NETWORKS, 'hysteria'] : NETWORKS`.
  105. const HYSTERIA_NETWORK_OPTION = { value: 'hysteria', label: 'Hysteria' };
  106. // Per-network bootstrap. Mirrors the legacy class constructors so the
  107. // initial state for each transport matches what xray-core expects.
  108. function newStreamSlice(network: string): Record<string, unknown> {
  109. switch (network) {
  110. case 'tcp':
  111. return { network: 'tcp', tcpSettings: { header: { type: 'none' } } };
  112. case 'kcp':
  113. return {
  114. network: 'kcp',
  115. kcpSettings: {
  116. mtu: 1350, tti: 20, uplinkCapacity: 5, downlinkCapacity: 20,
  117. cwndMultiplier: 1, maxSendingWindow: 2097152,
  118. },
  119. };
  120. case 'ws':
  121. return {
  122. network: 'ws',
  123. wsSettings: { path: '/', host: '', headers: {}, heartbeatPeriod: 0 },
  124. };
  125. case 'grpc':
  126. return {
  127. network: 'grpc',
  128. grpcSettings: { serviceName: '', authority: '', multiMode: false },
  129. };
  130. case 'httpupgrade':
  131. return {
  132. network: 'httpupgrade',
  133. httpupgradeSettings: { path: '/', host: '', headers: {} },
  134. };
  135. case 'xhttp':
  136. return {
  137. network: 'xhttp',
  138. xhttpSettings: {
  139. path: '/', host: '', mode: '', headers: [],
  140. xPaddingBytes: '100-1000', scMaxEachPostBytes: '1000000',
  141. },
  142. };
  143. case 'hysteria':
  144. return {
  145. network: 'hysteria',
  146. hysteriaSettings: {
  147. version: 2,
  148. auth: '',
  149. udpIdleTimeout: 60,
  150. },
  151. };
  152. default:
  153. return { network: 'tcp', tcpSettings: { header: { type: 'none' } } };
  154. }
  155. }
  156. // Protocols whose form schema carries a flat connect target — these all
  157. // get the shared "server" sub-block (address + port) at the top of the
  158. // protocol section. Wireguard has an address but no port. DNS/freedom/
  159. // blackhole/loopback have no connect target.
  160. const SERVER_PROTOCOLS = new Set<string>([
  161. 'vmess', 'vless', 'trojan', 'shadowsocks', 'socks', 'http', 'hysteria',
  162. ]);
  163. function buildAddModeValues(): OutboundFormValues {
  164. return rawOutboundToFormValues({});
  165. }
  166. export default function OutboundFormModal({
  167. open,
  168. outbound: outboundProp,
  169. existingTags,
  170. onClose,
  171. onConfirm,
  172. }: OutboundFormModalProps) {
  173. const { t } = useTranslation();
  174. const [messageApi, messageContextHolder] = message.useMessage();
  175. const [form] = Form.useForm<OutboundFormValues>();
  176. const [activeKey, setActiveKey] = useState('1');
  177. const [jsonText, setJsonText] = useState('');
  178. const [jsonDirty, setJsonDirty] = useState(false);
  179. const [linkInput, setLinkInput] = useState('');
  180. // Parse a share link (vmess:// / vless:// / trojan:// / ss:// /
  181. // hysteria2://) and replace form state with the result. The current
  182. // tag is preserved when the parsed link doesn't carry one.
  183. function importLink() {
  184. const link = linkInput.trim();
  185. if (!link) return;
  186. const parsed = parseOutboundLink(link);
  187. if (!parsed) {
  188. messageApi.error('Wrong Link!');
  189. return;
  190. }
  191. const currentTag = form.getFieldValue('tag') as string | undefined;
  192. if (!parsed.tag && currentTag) parsed.tag = currentTag;
  193. const next = rawOutboundToFormValues(parsed);
  194. form.resetFields();
  195. form.setFieldsValue(next);
  196. setJsonText(JSON.stringify(formValuesToWirePayload(next), null, 2));
  197. setJsonDirty(false);
  198. setLinkInput('');
  199. messageApi.success('Link imported successfully');
  200. switchTab('1');
  201. }
  202. const isEdit = outboundProp != null;
  203. const title = isEdit
  204. ? `${t('edit')} ${t('pages.xray.Outbounds')}`
  205. : `+ ${t('pages.xray.Outbounds')}`;
  206. const okText = isEdit ? t('pages.clients.submitEdit') : t('create');
  207. useEffect(() => {
  208. if (!open) return;
  209. const initial = outboundProp
  210. ? rawOutboundToFormValues(outboundProp)
  211. : buildAddModeValues();
  212. form.resetFields();
  213. form.setFieldsValue(initial);
  214. setActiveKey('1');
  215. setJsonText(JSON.stringify(formValuesToWirePayload(initial), null, 2));
  216. setJsonDirty(false);
  217. }, [open, outboundProp, form]);
  218. const tag = Form.useWatch('tag', form) ?? '';
  219. const protocol = (Form.useWatch('protocol', form) ?? 'vless') as string;
  220. // preserve: true — without it useWatch only reflects values whose
  221. // Form.Item is currently mounted. The streamSettings selectors live
  222. // INSIDE `{streamAllowed && network && (...)}`, so the moment that
  223. // conditional gates them out, useWatch returns undefined, the gate
  224. // keeps returning false, and the stream block never renders even
  225. // though streamSettings is in the form store.
  226. const network = (Form.useWatch(['streamSettings', 'network'], { form, preserve: true }) ?? '') as string;
  227. const security = (Form.useWatch(['streamSettings', 'security'], { form, preserve: true }) ?? 'none') as string;
  228. const streamAllowed = canEnableStream({ protocol });
  229. const tlsAllowed = canEnableTls({ protocol, streamSettings: { network, security } });
  230. const realityAllowed = canEnableReality({ protocol, streamSettings: { network, security } });
  231. const tlsFlowAllowed = canEnableTlsFlow({ protocol, streamSettings: { network, security } });
  232. // Seed streamSettings when the user picks a protocol that supports
  233. // streams but the form does not yet have a stream slice (new outbound,
  234. // or wire payload arrived without streamSettings).
  235. useEffect(() => {
  236. if (!streamAllowed) return;
  237. if (network) return;
  238. form.setFieldValue('streamSettings', { ...newStreamSlice('tcp'), security: 'none' });
  239. // eslint-disable-next-line react-hooks/exhaustive-deps
  240. }, [streamAllowed, network]);
  241. // Wireguard pubKey is a UI-only field derived from secretKey on every
  242. // edit. The legacy modal did the same on every keystroke. We re-derive
  243. // here so paste-in secret keys immediately surface the matching pub.
  244. const wgSecretKey = Form.useWatch(['settings', 'secretKey'], form) as string | undefined;
  245. useEffect(() => {
  246. if (protocol !== 'wireguard') return;
  247. const sk = (wgSecretKey ?? '').trim();
  248. if (!sk) {
  249. form.setFieldValue(['settings', 'pubKey'], '');
  250. return;
  251. }
  252. try {
  253. const { publicKey } = Wireguard.generateKeypair(sk);
  254. form.setFieldValue(['settings', 'pubKey'], publicKey);
  255. } catch {
  256. form.setFieldValue(['settings', 'pubKey'], '');
  257. }
  258. // eslint-disable-next-line react-hooks/exhaustive-deps
  259. }, [protocol, wgSecretKey]);
  260. // Switching protocol resets the settings sub-object to fresh defaults
  261. // so leftover fields from the previous protocol do not bleed through.
  262. // The adapter's rawOutboundToFormValues seeds whatever the new protocol
  263. // expects (vless flat shape, vmess flat shape, wireguard with secretKey
  264. // placeholder, etc.).
  265. function onValuesChange(changed: Partial<OutboundFormValues>) {
  266. if ('protocol' in changed && changed.protocol) {
  267. const next = rawOutboundToFormValues({ protocol: changed.protocol });
  268. form.setFieldValue('settings', next.settings);
  269. }
  270. }
  271. // Security change cascade: swap the security sub-key so the DU branch
  272. // matches. Seed default field values when entering tls/reality so the
  273. // sub-forms render without `undefined` field references.
  274. function onSecurityChange(next: string) {
  275. const stream = form.getFieldValue('streamSettings') ?? {};
  276. const cleaned = { ...stream } as Record<string, unknown>;
  277. delete cleaned.tlsSettings;
  278. delete cleaned.realitySettings;
  279. if (next === 'tls') {
  280. cleaned.tlsSettings = {
  281. serverName: '',
  282. alpn: [],
  283. fingerprint: '',
  284. echConfigList: '',
  285. verifyPeerCertByName: '',
  286. pinnedPeerCertSha256: '',
  287. };
  288. } else if (next === 'reality') {
  289. cleaned.realitySettings = {
  290. publicKey: '',
  291. fingerprint: 'chrome',
  292. serverName: '',
  293. shortId: '',
  294. spiderX: '',
  295. mldsa65Verify: '',
  296. };
  297. }
  298. cleaned.security = next;
  299. form.setFieldValue('streamSettings', cleaned);
  300. }
  301. // Network change cascade: swap the per-network sub-key (tcpSettings,
  302. // wsSettings, etc.) so the DU branch matches. Preserve security if
  303. // the new network supports it, otherwise force back to 'none'.
  304. function onNetworkChange(next: string) {
  305. const currentSecurity = form.getFieldValue(['streamSettings', 'security']) ?? 'none';
  306. const stillAllowed = canEnableTls({ protocol, streamSettings: { network: next, security: currentSecurity } });
  307. const stillReality = canEnableReality({ protocol, streamSettings: { network: next, security: currentSecurity } });
  308. const newSecurity =
  309. currentSecurity === 'tls' && !stillAllowed
  310. ? 'none'
  311. : currentSecurity === 'reality' && !stillReality
  312. ? 'none'
  313. : currentSecurity;
  314. form.setFieldValue('streamSettings', { ...newStreamSlice(next), security: newSecurity });
  315. }
  316. const duplicateTag = useMemo(() => {
  317. const myTag = tag.trim();
  318. if (!myTag) return false;
  319. if (isEdit && (outboundProp?.tag as string | undefined) === myTag) return false;
  320. return (existingTags || []).includes(myTag);
  321. }, [tag, existingTags, isEdit, outboundProp]);
  322. // Bridge form ↔ JSON tab: when leaving the JSON tab back to Basic, push
  323. // any edits into form state. When entering JSON tab, snapshot current
  324. // form values so the user sees the live shape.
  325. function applyJsonToForm(): boolean {
  326. if (!jsonDirty) return true;
  327. const raw = jsonText.trim();
  328. if (!raw) return true;
  329. let parsed: Record<string, unknown>;
  330. try {
  331. parsed = JSON.parse(raw) as Record<string, unknown>;
  332. } catch (e) {
  333. messageApi.error(`JSON: ${(e as Error).message}`);
  334. return false;
  335. }
  336. const next = rawOutboundToFormValues(parsed);
  337. form.resetFields();
  338. form.setFieldsValue(next);
  339. setJsonDirty(false);
  340. return true;
  341. }
  342. // Wrap every tab switch with a blur of the active element. AntD marks
  343. // the outgoing panel `aria-hidden="true"` synchronously when the
  344. // controlled activeKey flips; if a focused input is still inside that
  345. // panel (e.g. Input.Search on the JSON tab after user hits Enter to
  346. // import), Chrome logs a WAI-ARIA warning. Doing the blur right
  347. // before setActiveKey ensures the panel is unfocused by the time
  348. // AntD applies the attribute.
  349. function switchTab(key: string) {
  350. if (typeof document !== 'undefined') {
  351. (document.activeElement as HTMLElement | null)?.blur?.();
  352. }
  353. setActiveKey(key);
  354. }
  355. function onTabChange(key: string) {
  356. if (key === '2') {
  357. const values = form.getFieldsValue(true) as OutboundFormValues;
  358. setJsonText(JSON.stringify(formValuesToWirePayload(values), null, 2));
  359. setJsonDirty(false);
  360. switchTab(key);
  361. return;
  362. }
  363. if (key === '1' && activeKey === '2') {
  364. if (!applyJsonToForm()) return;
  365. }
  366. switchTab(key);
  367. }
  368. async function onOk() {
  369. if (activeKey === '2' && !applyJsonToForm()) return;
  370. try {
  371. await form.validateFields();
  372. } catch {
  373. return;
  374. }
  375. if (duplicateTag) {
  376. messageApi.error('Tag already used by another outbound');
  377. return;
  378. }
  379. const values = form.getFieldsValue(true) as OutboundFormValues;
  380. onConfirm(formValuesToWirePayload(values));
  381. }
  382. return (
  383. <>
  384. {messageContextHolder}
  385. <Modal
  386. open={open}
  387. title={title}
  388. okText={okText}
  389. cancelText={t('close')}
  390. mask={{ closable: false }}
  391. width={780}
  392. onOk={onOk}
  393. onCancel={onClose}
  394. destroyOnHidden
  395. >
  396. <Form
  397. form={form}
  398. colon={false}
  399. labelCol={{ md: { span: 8 } }}
  400. wrapperCol={{ md: { span: 14 } }}
  401. onValuesChange={onValuesChange}
  402. >
  403. <Tabs
  404. activeKey={activeKey}
  405. onChange={onTabChange}
  406. items={[
  407. {
  408. key: '1',
  409. label: t('pages.xray.basicTemplate'),
  410. children: (
  411. <>
  412. <Form.Item
  413. label={t('protocol')}
  414. name="protocol"
  415. rules={[antdRule(OutboundFormBaseSchema.shape.tag, t)]}
  416. >
  417. <Select options={PROTOCOL_OPTIONS} />
  418. </Form.Item>
  419. <Form.Item
  420. label={t('pages.xray.outbound.tag')}
  421. name="tag"
  422. validateStatus={duplicateTag ? 'warning' : undefined}
  423. help={duplicateTag ? t('pages.xray.outboundForm.tagDuplicate') : undefined}
  424. rules={[
  425. { required: true, message: t('pages.xray.outboundForm.tagRequired') },
  426. ]}
  427. >
  428. <Input placeholder={t('pages.xray.outboundForm.tagPlaceholder')} />
  429. </Form.Item>
  430. <Form.Item label={t('pages.xray.outbound.sendThrough')} name="sendThrough">
  431. <Input placeholder={t('pages.xray.outboundForm.localIpPlaceholder')} />
  432. </Form.Item>
  433. {/* Shared connect target (address + port) for protocols
  434. whose form schema carries them flat at settings root.
  435. Hidden for freedom/blackhole/dns/loopback/wireguard. */}
  436. {SERVER_PROTOCOLS.has(protocol) && (
  437. <>
  438. <Form.Item
  439. label={t('pages.inbounds.address')}
  440. name={['settings', 'address']}
  441. rules={[{ required: true, message: t('pages.xray.outboundForm.addressRequired') }]}
  442. >
  443. <Input />
  444. </Form.Item>
  445. <Form.Item
  446. label={t('pages.inbounds.port')}
  447. name={['settings', 'port']}
  448. rules={[{ required: true, message: t('pages.xray.outboundForm.portRequired') }]}
  449. >
  450. <InputNumber min={1} max={65535} style={{ width: '100%' }} />
  451. </Form.Item>
  452. </>
  453. )}
  454. {(protocol === 'vmess' || protocol === 'vless') && (
  455. <Form.Item
  456. label="ID"
  457. name={['settings', 'id']}
  458. rules={[antdRule(VmessOutboundFormSettingsSchema.shape.id, t)]}
  459. >
  460. <Input placeholder="UUID" />
  461. </Form.Item>
  462. )}
  463. {protocol === 'vmess' && (
  464. <Form.Item
  465. label={t('security')}
  466. name={['settings', 'security']}
  467. rules={[antdRule(VmessOutboundFormSettingsSchema.shape.security, t)]}
  468. >
  469. <Select options={SECURITY_OPTIONS} />
  470. </Form.Item>
  471. )}
  472. {protocol === 'vless' && (
  473. <>
  474. <Form.Item
  475. label={t('encryption')}
  476. name={['settings', 'encryption']}
  477. rules={[antdRule(VlessOutboundFormSettingsSchema.shape.encryption, t)]}
  478. >
  479. <Input />
  480. </Form.Item>
  481. <Form.Item label={t('pages.clients.reverseTag')} name={['settings', 'reverseTag']}>
  482. <Input placeholder={t('pages.xray.outboundForm.optional')} />
  483. </Form.Item>
  484. </>
  485. )}
  486. {(protocol === 'trojan' || protocol === 'shadowsocks') && (
  487. <Form.Item
  488. label={t('password')}
  489. name={['settings', 'password']}
  490. rules={[
  491. antdRule(
  492. protocol === 'trojan'
  493. ? TrojanOutboundFormSettingsSchema.shape.password
  494. : ShadowsocksOutboundFormSettingsSchema.shape.password,
  495. t,
  496. ),
  497. ]}
  498. >
  499. <Input />
  500. </Form.Item>
  501. )}
  502. {protocol === 'shadowsocks' && (
  503. <>
  504. <Form.Item
  505. label={t('encryption')}
  506. name={['settings', 'method']}
  507. rules={[antdRule(SSMethodSchema, t)]}
  508. >
  509. <Select options={SS_METHOD_OPTIONS} />
  510. </Form.Item>
  511. <Form.Item
  512. label={t('pages.xray.outboundForm.udpOverTcp')}
  513. name={['settings', 'uot']}
  514. valuePropName="checked"
  515. >
  516. <Switch />
  517. </Form.Item>
  518. <Form.Item label={t('pages.xray.outboundForm.uotVersion')} name={['settings', 'UoTVersion']}>
  519. <InputNumber min={1} max={2} />
  520. </Form.Item>
  521. </>
  522. )}
  523. {(protocol === 'socks' || protocol === 'http') && (
  524. <>
  525. <Form.Item label={t('username')} name={['settings', 'user']}>
  526. <Input />
  527. </Form.Item>
  528. <Form.Item label={t('password')} name={['settings', 'pass']}>
  529. <Input />
  530. </Form.Item>
  531. </>
  532. )}
  533. {protocol === 'hysteria' && (
  534. <Form.Item label={t('pages.inbounds.form.version')} name={['settings', 'version']}>
  535. <InputNumber min={2} max={2} disabled />
  536. </Form.Item>
  537. )}
  538. {protocol === 'loopback' && (
  539. <Form.Item label={t('pages.xray.outboundForm.inboundTag')} name={['settings', 'inboundTag']}>
  540. <Input placeholder={t('pages.xray.outboundForm.inboundTagPlaceholder')} />
  541. </Form.Item>
  542. )}
  543. {protocol === 'blackhole' && (
  544. <Form.Item label={t('pages.xray.outboundForm.responseType')} name={['settings', 'type']}>
  545. <Select
  546. options={[
  547. { value: '', label: '(empty)' },
  548. { value: 'none', label: 'none' },
  549. { value: 'http', label: 'http' },
  550. ]}
  551. />
  552. </Form.Item>
  553. )}
  554. {protocol === 'dns' && (
  555. <>
  556. <Form.Item label={t('pages.xray.outboundForm.rewriteNetwork')} name={['settings', 'rewriteNetwork']}>
  557. <Select
  558. allowClear
  559. placeholder={t('pages.xray.outboundForm.unchanged')}
  560. options={[
  561. { value: 'udp', label: 'udp' },
  562. { value: 'tcp', label: 'tcp' },
  563. ]}
  564. />
  565. </Form.Item>
  566. <Form.Item label={t('pages.inbounds.form.rewriteAddress')} name={['settings', 'rewriteAddress']}>
  567. <Input placeholder={t('pages.xray.outboundForm.unchangedAddress')} />
  568. </Form.Item>
  569. <Form.Item label={t('pages.inbounds.form.rewritePort')} name={['settings', 'rewritePort']}>
  570. <InputNumber min={0} max={65535} style={{ width: '100%' }} />
  571. </Form.Item>
  572. <Form.Item label={t('pages.xray.tun.userLevel')} name={['settings', 'userLevel']}>
  573. <InputNumber min={0} style={{ width: '100%' }} />
  574. </Form.Item>
  575. <Form.List name={['settings', 'rules']}>
  576. {(fields, { add, remove }) => (
  577. <>
  578. <Form.Item label={t('pages.xray.outboundForm.rules')}>
  579. <Button
  580. size="small"
  581. type="primary"
  582. icon={<PlusOutlined />}
  583. onClick={() => add({ action: 'direct', qtype: '', domain: '' })}
  584. />
  585. </Form.Item>
  586. {fields.map((field, index) => (
  587. <div key={field.key}>
  588. <Form.Item wrapperCol={{ md: { span: 14, offset: 8 } }}>
  589. <div className="item-heading">
  590. <span>{t('pages.xray.outboundForm.ruleN', { n: index + 1 })}</span>
  591. <DeleteOutlined
  592. className="danger-icon"
  593. onClick={() => remove(field.name)}
  594. />
  595. </div>
  596. </Form.Item>
  597. <Form.Item label={t('pages.xray.outboundForm.action')} name={[field.name, 'action']}>
  598. <Select
  599. options={DNSRuleActions.map((a) => ({ value: a, label: a }))}
  600. />
  601. </Form.Item>
  602. <Form.Item label="QType" name={[field.name, 'qtype']}>
  603. <Input placeholder="1,3,23-24" />
  604. </Form.Item>
  605. <Form.Item label={t('domainName')} name={[field.name, 'domain']}>
  606. <Input placeholder="domain:example.com" />
  607. </Form.Item>
  608. </div>
  609. ))}
  610. </>
  611. )}
  612. </Form.List>
  613. </>
  614. )}
  615. {protocol === 'freedom' && (
  616. <>
  617. <Form.Item label={t('pages.xray.balancer.balancerStrategy')} name={['settings', 'domainStrategy']}>
  618. <Select
  619. options={[
  620. { value: '', label: `(${t('none')})` },
  621. ...OutboundDomainStrategies.map((s) => ({ value: s, label: s })),
  622. ]}
  623. />
  624. </Form.Item>
  625. <Form.Item label={t('pages.xray.outboundForm.redirect')} name={['settings', 'redirect']}>
  626. <Input />
  627. </Form.Item>
  628. <Form.Item label={t('pages.xray.outboundForm.fragment')} shouldUpdate noStyle>
  629. {() => {
  630. const fragment = (form.getFieldValue(['settings', 'fragment']) ?? {}) as {
  631. packets?: string;
  632. length?: string;
  633. interval?: string;
  634. maxSplit?: string;
  635. };
  636. const enabled = !!(fragment.length || fragment.interval || fragment.maxSplit);
  637. return (
  638. <>
  639. <Form.Item label="Fragment">
  640. <Switch
  641. checked={enabled}
  642. onChange={(checked) => {
  643. form.setFieldValue(
  644. ['settings', 'fragment'],
  645. checked
  646. ? {
  647. packets: 'tlshello',
  648. length: '100-200',
  649. interval: '10-20',
  650. maxSplit: '300-400',
  651. }
  652. : { packets: '', length: '', interval: '', maxSplit: '' },
  653. );
  654. }}
  655. />
  656. </Form.Item>
  657. {enabled && (
  658. <>
  659. <Form.Item
  660. label={t('pages.settings.subFormats.packets')}
  661. name={['settings', 'fragment', 'packets']}
  662. >
  663. <Select
  664. options={[
  665. { value: '1-3', label: '1-3' },
  666. { value: 'tlshello', label: 'tlshello' },
  667. ]}
  668. />
  669. </Form.Item>
  670. <Form.Item label={t('pages.settings.subFormats.length')} name={['settings', 'fragment', 'length']}>
  671. <Input />
  672. </Form.Item>
  673. <Form.Item
  674. label={t('pages.settings.subFormats.interval')}
  675. name={['settings', 'fragment', 'interval']}
  676. >
  677. <Input />
  678. </Form.Item>
  679. <Form.Item
  680. label={t('pages.settings.subFormats.maxSplit')}
  681. name={['settings', 'fragment', 'maxSplit']}
  682. >
  683. <Input />
  684. </Form.Item>
  685. </>
  686. )}
  687. </>
  688. );
  689. }}
  690. </Form.Item>
  691. <Form.List name={['settings', 'noises']}>
  692. {(fields, { add, remove }) => (
  693. <>
  694. <Form.Item label={t('pages.settings.subFormats.noises')}>
  695. <Switch
  696. checked={fields.length > 0}
  697. onChange={(checked) => {
  698. if (checked) {
  699. add({
  700. type: 'rand',
  701. packet: '10-20',
  702. delay: '10-16',
  703. applyTo: 'ip',
  704. });
  705. } else {
  706. // remove() with no arg is not supported;
  707. // walk fields in reverse and drop each.
  708. for (let i = fields.length - 1; i >= 0; i--) {
  709. remove(fields[i].name);
  710. }
  711. }
  712. }}
  713. />
  714. {fields.length > 0 && (
  715. <Button
  716. size="small"
  717. type="primary"
  718. className="ml-8"
  719. icon={<PlusOutlined />}
  720. onClick={() =>
  721. add({
  722. type: 'rand',
  723. packet: '10-20',
  724. delay: '10-16',
  725. applyTo: 'ip',
  726. })
  727. }
  728. />
  729. )}
  730. </Form.Item>
  731. {fields.map((field, index) => (
  732. <div key={field.key}>
  733. <Form.Item wrapperCol={{ md: { span: 14, offset: 8 } }}>
  734. <div className="item-heading">
  735. <span>{t('pages.settings.subFormats.noiseItem', { n: index + 1 })}</span>
  736. {fields.length > 1 && (
  737. <DeleteOutlined
  738. className="danger-icon"
  739. onClick={() => remove(field.name)}
  740. />
  741. )}
  742. </div>
  743. </Form.Item>
  744. <Form.Item label={t('pages.settings.subFormats.type')} name={[field.name, 'type']}>
  745. <Select
  746. options={['rand', 'base64', 'str', 'hex'].map((v) => ({
  747. value: v,
  748. label: v,
  749. }))}
  750. />
  751. </Form.Item>
  752. <Form.Item label={t('pages.settings.subFormats.packet')} name={[field.name, 'packet']}>
  753. <Input />
  754. </Form.Item>
  755. <Form.Item label={t('pages.settings.subFormats.delayMs')} name={[field.name, 'delay']}>
  756. <Input />
  757. </Form.Item>
  758. <Form.Item label={t('pages.settings.subFormats.applyTo')} name={[field.name, 'applyTo']}>
  759. <Select
  760. options={['ip', 'ipv4', 'ipv6'].map((v) => ({
  761. value: v,
  762. label: v,
  763. }))}
  764. />
  765. </Form.Item>
  766. </div>
  767. ))}
  768. </>
  769. )}
  770. </Form.List>
  771. <Form.List name={['settings', 'finalRules']}>
  772. {(fields, { add, remove }) => (
  773. <>
  774. <Form.Item label={t('pages.xray.outboundForm.finalRules')}>
  775. <Button
  776. size="small"
  777. type="primary"
  778. icon={<PlusOutlined />}
  779. onClick={() =>
  780. add({
  781. action: 'allow',
  782. network: '',
  783. port: '',
  784. ip: [],
  785. blockDelay: '',
  786. })
  787. }
  788. />
  789. <span className="ml-8" style={{ opacity: 0.6 }}>
  790. {t('pages.xray.outboundForm.overrideXrayPrivateIp')}
  791. </span>
  792. </Form.Item>
  793. {fields.map((field, index) => (
  794. <div key={field.key}>
  795. <Form.Item wrapperCol={{ md: { span: 14, offset: 8 } }}>
  796. <div className="item-heading">
  797. <span>{t('pages.xray.outboundForm.ruleN', { n: index + 1 })}</span>
  798. <DeleteOutlined
  799. className="danger-icon"
  800. onClick={() => remove(field.name)}
  801. />
  802. </div>
  803. </Form.Item>
  804. <Form.Item label={t('pages.xray.outboundForm.action')} name={[field.name, 'action']}>
  805. <Select
  806. options={['allow', 'block'].map((v) => ({
  807. value: v,
  808. label: v,
  809. }))}
  810. />
  811. </Form.Item>
  812. <Form.Item label={t('pages.inbounds.network')} name={[field.name, 'network']}>
  813. <Select
  814. allowClear
  815. placeholder="(any)"
  816. options={['tcp', 'udp', 'tcp,udp'].map((v) => ({
  817. value: v,
  818. label: v,
  819. }))}
  820. />
  821. </Form.Item>
  822. <Form.Item label={t('pages.inbounds.port')} name={[field.name, 'port']}>
  823. <Input placeholder="e.g. 80,443 or 1000-2000" />
  824. </Form.Item>
  825. <Form.Item label="IP / CIDR / geoip" name={[field.name, 'ip']}>
  826. <Select
  827. mode="tags"
  828. tokenSeparators={[',', ' ']}
  829. placeholder="e.g. 10.0.0.0/8, geoip:private"
  830. />
  831. </Form.Item>
  832. <Form.Item shouldUpdate noStyle>
  833. {() => {
  834. const ruleAction = form.getFieldValue([
  835. 'settings',
  836. 'finalRules',
  837. field.name,
  838. 'action',
  839. ]);
  840. if (ruleAction !== 'block') return null;
  841. return (
  842. <Form.Item
  843. label={t('pages.xray.outboundForm.blockDelay')}
  844. name={[field.name, 'blockDelay']}
  845. >
  846. <Input placeholder="optional: 5000-10000" />
  847. </Form.Item>
  848. );
  849. }}
  850. </Form.Item>
  851. </div>
  852. ))}
  853. </>
  854. )}
  855. </Form.List>
  856. </>
  857. )}
  858. {protocol === 'vless' && (
  859. <Form.Item shouldUpdate noStyle>
  860. {() => {
  861. const reverseTag = form.getFieldValue(['settings', 'reverseTag']);
  862. if (!reverseTag) return null;
  863. const sniff = (form.getFieldValue(['settings', 'reverseSniffing']) ?? {}) as {
  864. enabled?: boolean;
  865. };
  866. return (
  867. <>
  868. <Form.Item
  869. label={t('pages.xray.outboundForm.reverseSniffing')}
  870. name={['settings', 'reverseSniffing', 'enabled']}
  871. valuePropName="checked"
  872. >
  873. <Switch />
  874. </Form.Item>
  875. {sniff.enabled && (
  876. <>
  877. <Form.Item
  878. wrapperCol={{ md: { span: 14, offset: 8 } }}
  879. name={['settings', 'reverseSniffing', 'destOverride']}
  880. >
  881. <Select
  882. mode="multiple"
  883. className="sniffing-options"
  884. options={Object.entries(SNIFFING_OPTION).map(([k, v]) => ({
  885. value: v,
  886. label: k,
  887. }))}
  888. />
  889. </Form.Item>
  890. <Form.Item
  891. label={t('pages.inbounds.sniffingMetadataOnly')}
  892. name={['settings', 'reverseSniffing', 'metadataOnly']}
  893. valuePropName="checked"
  894. >
  895. <Switch />
  896. </Form.Item>
  897. <Form.Item
  898. label={t('pages.inbounds.sniffingRouteOnly')}
  899. name={['settings', 'reverseSniffing', 'routeOnly']}
  900. valuePropName="checked"
  901. >
  902. <Switch />
  903. </Form.Item>
  904. <Form.Item
  905. label={t('pages.inbounds.sniffingIpsExcluded')}
  906. name={['settings', 'reverseSniffing', 'ipsExcluded']}
  907. >
  908. <Select
  909. mode="tags"
  910. tokenSeparators={[',']}
  911. placeholder="IP/CIDR/geoip:*"
  912. />
  913. </Form.Item>
  914. <Form.Item
  915. label={t('pages.inbounds.sniffingDomainsExcluded')}
  916. name={['settings', 'reverseSniffing', 'domainsExcluded']}
  917. >
  918. <Select
  919. mode="tags"
  920. tokenSeparators={[',']}
  921. placeholder="domain:*"
  922. />
  923. </Form.Item>
  924. </>
  925. )}
  926. </>
  927. );
  928. }}
  929. </Form.Item>
  930. )}
  931. {protocol === 'wireguard' && (
  932. <>
  933. <Form.Item label={t('pages.inbounds.address')} name={['settings', 'address']}>
  934. <Input placeholder="comma-separated, e.g. 10.0.0.1,fd00::1" />
  935. </Form.Item>
  936. <Form.Item label={t('pages.inbounds.privatekey')}>
  937. <Space.Compact block>
  938. <Form.Item name={['settings', 'secretKey']} noStyle>
  939. <Input style={{ width: 'calc(100% - 32px)' }} />
  940. </Form.Item>
  941. <Button
  942. icon={<ReloadOutlined />}
  943. onClick={() => {
  944. const pair = Wireguard.generateKeypair();
  945. form.setFieldValue(['settings', 'secretKey'], pair.privateKey);
  946. form.setFieldValue(['settings', 'pubKey'], pair.publicKey);
  947. }}
  948. />
  949. </Space.Compact>
  950. </Form.Item>
  951. <Form.Item label={t('pages.inbounds.publicKey')} name={['settings', 'pubKey']}>
  952. <Input disabled />
  953. </Form.Item>
  954. <Form.Item label={t('pages.xray.wireguard.domainStrategy')} name={['settings', 'domainStrategy']}>
  955. <Select
  956. options={[
  957. { value: '', label: `(${t('none')})` },
  958. ...WireguardDomainStrategy.map((s) => ({ value: s, label: s })),
  959. ]}
  960. />
  961. </Form.Item>
  962. <Form.Item label="MTU" name={['settings', 'mtu']}>
  963. <InputNumber min={0} />
  964. </Form.Item>
  965. <Form.Item label={t('pages.xray.outboundForm.workers')} name={['settings', 'workers']}>
  966. <InputNumber min={0} />
  967. </Form.Item>
  968. <Form.Item
  969. label={t('pages.inbounds.info.noKernelTun')}
  970. name={['settings', 'noKernelTun']}
  971. valuePropName="checked"
  972. >
  973. <Switch />
  974. </Form.Item>
  975. <Form.Item label={t('pages.xray.outboundForm.reserved')} name={['settings', 'reserved']}>
  976. <Input placeholder="comma-separated bytes, e.g. 1,2,3" />
  977. </Form.Item>
  978. <Form.List name={['settings', 'peers']}>
  979. {(fields, { add, remove }) => (
  980. <>
  981. <Form.Item label={t('pages.inbounds.form.peers')}>
  982. <Button
  983. size="small"
  984. type="primary"
  985. icon={<PlusOutlined />}
  986. onClick={() =>
  987. add({
  988. publicKey: '',
  989. psk: '',
  990. allowedIPs: ['0.0.0.0/0', '::/0'],
  991. endpoint: '',
  992. keepAlive: 0,
  993. })
  994. }
  995. />
  996. </Form.Item>
  997. {fields.map((field, index) => (
  998. <div key={field.key}>
  999. <Form.Item wrapperCol={{ md: { span: 14, offset: 8 } }}>
  1000. <div className="item-heading">
  1001. <span>{t('pages.inbounds.info.peerNumber', { n: index + 1 })}</span>
  1002. {fields.length > 1 && (
  1003. <DeleteOutlined
  1004. className="danger-icon"
  1005. onClick={() => remove(field.name)}
  1006. />
  1007. )}
  1008. </div>
  1009. </Form.Item>
  1010. <Form.Item label={t('pages.xray.wireguard.endpoint')} name={[field.name, 'endpoint']}>
  1011. <Input />
  1012. </Form.Item>
  1013. <Form.Item
  1014. label={t('pages.inbounds.publicKey')}
  1015. name={[field.name, 'publicKey']}
  1016. >
  1017. <Input />
  1018. </Form.Item>
  1019. <Form.Item label="PSK" name={[field.name, 'psk']}>
  1020. <Input />
  1021. </Form.Item>
  1022. <Form.Item label={t('pages.xray.wireguard.allowedIPs')}>
  1023. <Form.List name={[field.name, 'allowedIPs']}>
  1024. {(ipFields, { add: addIp, remove: removeIp }) => (
  1025. <>
  1026. {ipFields.map((ipField, ipIdx) => (
  1027. <Space.Compact
  1028. key={ipField.key}
  1029. block
  1030. style={{ marginBottom: 4 }}
  1031. >
  1032. <Form.Item noStyle name={ipField.name}>
  1033. <Input />
  1034. </Form.Item>
  1035. {ipFields.length > 1 && (
  1036. <InputAddon onClick={() => removeIp(ipIdx)}>
  1037. <MinusOutlined />
  1038. </InputAddon>
  1039. )}
  1040. </Space.Compact>
  1041. ))}
  1042. <Button
  1043. size="small"
  1044. icon={<PlusOutlined />}
  1045. onClick={() => addIp('')}
  1046. />
  1047. </>
  1048. )}
  1049. </Form.List>
  1050. </Form.Item>
  1051. <Form.Item label={t('pages.inbounds.info.keepAlive')} name={[field.name, 'keepAlive']}>
  1052. <InputNumber min={0} />
  1053. </Form.Item>
  1054. </div>
  1055. ))}
  1056. </>
  1057. )}
  1058. </Form.List>
  1059. </>
  1060. )}
  1061. {streamAllowed && network && (
  1062. <>
  1063. <Form.Item
  1064. label={t('transmission')}
  1065. name={['streamSettings', 'network']}
  1066. >
  1067. <Select
  1068. value={network}
  1069. onChange={onNetworkChange}
  1070. options={
  1071. protocol === 'hysteria'
  1072. ? [...NETWORK_OPTIONS, HYSTERIA_NETWORK_OPTION]
  1073. : NETWORK_OPTIONS
  1074. }
  1075. />
  1076. </Form.Item>
  1077. {network === 'tcp' && (
  1078. <Form.Item shouldUpdate noStyle>
  1079. {() => {
  1080. const type =
  1081. form.getFieldValue([
  1082. 'streamSettings',
  1083. 'tcpSettings',
  1084. 'header',
  1085. 'type',
  1086. ]) ?? 'none';
  1087. return (
  1088. <>
  1089. <Form.Item label={`HTTP ${t('camouflage')}`}>
  1090. <Switch
  1091. checked={type === 'http'}
  1092. onChange={(checked) =>
  1093. form.setFieldValue(
  1094. ['streamSettings', 'tcpSettings', 'header'],
  1095. checked
  1096. ? {
  1097. type: 'http',
  1098. request: {
  1099. version: '1.1',
  1100. method: 'GET',
  1101. path: ['/'],
  1102. headers: {},
  1103. },
  1104. response: {
  1105. version: '1.1',
  1106. status: '200',
  1107. reason: 'OK',
  1108. headers: {},
  1109. },
  1110. }
  1111. : { type: 'none' },
  1112. )
  1113. }
  1114. />
  1115. </Form.Item>
  1116. {type === 'http' && (
  1117. <>
  1118. <Form.Item
  1119. label={t('pages.inbounds.form.requestMethod')}
  1120. name={[
  1121. 'streamSettings', 'tcpSettings', 'header',
  1122. 'request', 'method',
  1123. ]}
  1124. >
  1125. <Input placeholder="GET" />
  1126. </Form.Item>
  1127. <Form.Item
  1128. label={t('pages.inbounds.form.requestVersion')}
  1129. name={[
  1130. 'streamSettings', 'tcpSettings', 'header',
  1131. 'request', 'version',
  1132. ]}
  1133. >
  1134. <Input placeholder="1.1" />
  1135. </Form.Item>
  1136. <Form.Item
  1137. label={t('host')}
  1138. name={[
  1139. 'streamSettings',
  1140. 'tcpSettings',
  1141. 'header',
  1142. 'request',
  1143. 'headers',
  1144. 'Host',
  1145. ]}
  1146. normalize={(v: unknown) =>
  1147. typeof v === 'string'
  1148. ? v.split(',').map((s) => s.trim()).filter(Boolean)
  1149. : Array.isArray(v) ? v : []
  1150. }
  1151. getValueProps={(v: unknown) => ({
  1152. value: Array.isArray(v) ? v.join(',') : '',
  1153. })}
  1154. >
  1155. <Input placeholder="example.com,cdn.example.com" />
  1156. </Form.Item>
  1157. <Form.Item
  1158. label={t('path')}
  1159. name={[
  1160. 'streamSettings',
  1161. 'tcpSettings',
  1162. 'header',
  1163. 'request',
  1164. 'path',
  1165. ]}
  1166. normalize={(v: unknown) =>
  1167. typeof v === 'string'
  1168. ? v.split(',').map((s) => s.trim()).filter(Boolean)
  1169. : Array.isArray(v) ? v : ['/']
  1170. }
  1171. getValueProps={(v: unknown) => ({
  1172. value: Array.isArray(v) ? v.join(',') : '/',
  1173. })}
  1174. >
  1175. <Input placeholder="/,/api,/static" />
  1176. </Form.Item>
  1177. <Form.Item
  1178. label={t('pages.inbounds.form.requestHeaders')}
  1179. name={[
  1180. 'streamSettings', 'tcpSettings', 'header',
  1181. 'request', 'headers',
  1182. ]}
  1183. >
  1184. <HeaderMapEditor mode="v2" />
  1185. </Form.Item>
  1186. <Form.Item
  1187. label={t('pages.inbounds.form.responseVersion')}
  1188. name={[
  1189. 'streamSettings', 'tcpSettings', 'header',
  1190. 'response', 'version',
  1191. ]}
  1192. >
  1193. <Input placeholder="1.1" />
  1194. </Form.Item>
  1195. <Form.Item
  1196. label={t('pages.inbounds.form.responseStatus')}
  1197. name={[
  1198. 'streamSettings', 'tcpSettings', 'header',
  1199. 'response', 'status',
  1200. ]}
  1201. >
  1202. <Input placeholder="200" />
  1203. </Form.Item>
  1204. <Form.Item
  1205. label={t('pages.inbounds.form.responseReason')}
  1206. name={[
  1207. 'streamSettings', 'tcpSettings', 'header',
  1208. 'response', 'reason',
  1209. ]}
  1210. >
  1211. <Input placeholder="OK" />
  1212. </Form.Item>
  1213. <Form.Item
  1214. label={t('pages.inbounds.form.responseHeaders')}
  1215. name={[
  1216. 'streamSettings', 'tcpSettings', 'header',
  1217. 'response', 'headers',
  1218. ]}
  1219. >
  1220. <HeaderMapEditor mode="v2" />
  1221. </Form.Item>
  1222. </>
  1223. )}
  1224. </>
  1225. );
  1226. }}
  1227. </Form.Item>
  1228. )}
  1229. {network === 'kcp' && (
  1230. <>
  1231. <Form.Item label="MTU" name={['streamSettings', 'kcpSettings', 'mtu']}>
  1232. <InputNumber min={0} />
  1233. </Form.Item>
  1234. <Form.Item label={t('pages.inbounds.form.ttiMs')} name={['streamSettings', 'kcpSettings', 'tti']}>
  1235. <InputNumber min={0} />
  1236. </Form.Item>
  1237. <Form.Item
  1238. label={t('pages.inbounds.form.uplinkMbps')}
  1239. name={['streamSettings', 'kcpSettings', 'uplinkCapacity']}
  1240. >
  1241. <InputNumber min={0} />
  1242. </Form.Item>
  1243. <Form.Item
  1244. label={t('pages.inbounds.form.downlinkMbps')}
  1245. name={['streamSettings', 'kcpSettings', 'downlinkCapacity']}
  1246. >
  1247. <InputNumber min={0} />
  1248. </Form.Item>
  1249. <Form.Item
  1250. label={t('pages.inbounds.form.cwndMultiplier')}
  1251. name={['streamSettings', 'kcpSettings', 'cwndMultiplier']}
  1252. >
  1253. <InputNumber min={1} />
  1254. </Form.Item>
  1255. <Form.Item
  1256. label={t('pages.inbounds.form.maxSendingWindow')}
  1257. name={['streamSettings', 'kcpSettings', 'maxSendingWindow']}
  1258. >
  1259. <InputNumber min={0} />
  1260. </Form.Item>
  1261. </>
  1262. )}
  1263. {network === 'ws' && (
  1264. <>
  1265. <Form.Item label={t('host')} name={['streamSettings', 'wsSettings', 'host']}>
  1266. <Input />
  1267. </Form.Item>
  1268. <Form.Item label={t('path')} name={['streamSettings', 'wsSettings', 'path']}>
  1269. <Input />
  1270. </Form.Item>
  1271. <Form.Item
  1272. label={t('pages.inbounds.form.heartbeatPeriod')}
  1273. name={['streamSettings', 'wsSettings', 'heartbeatPeriod']}
  1274. >
  1275. <InputNumber min={0} />
  1276. </Form.Item>
  1277. <Form.Item
  1278. label={t('pages.inbounds.form.headers')}
  1279. name={['streamSettings', 'wsSettings', 'headers']}
  1280. >
  1281. <HeaderMapEditor mode="v1" />
  1282. </Form.Item>
  1283. </>
  1284. )}
  1285. {network === 'grpc' && (
  1286. <>
  1287. <Form.Item
  1288. label={t('pages.inbounds.form.serviceName')}
  1289. name={['streamSettings', 'grpcSettings', 'serviceName']}
  1290. >
  1291. <Input />
  1292. </Form.Item>
  1293. <Form.Item
  1294. label={t('pages.inbounds.form.authority')}
  1295. name={['streamSettings', 'grpcSettings', 'authority']}
  1296. >
  1297. <Input />
  1298. </Form.Item>
  1299. <Form.Item
  1300. label={t('pages.inbounds.form.multiMode')}
  1301. name={['streamSettings', 'grpcSettings', 'multiMode']}
  1302. valuePropName="checked"
  1303. >
  1304. <Switch />
  1305. </Form.Item>
  1306. </>
  1307. )}
  1308. {network === 'httpupgrade' && (
  1309. <>
  1310. <Form.Item
  1311. label={t('host')}
  1312. name={['streamSettings', 'httpupgradeSettings', 'host']}
  1313. >
  1314. <Input />
  1315. </Form.Item>
  1316. <Form.Item
  1317. label={t('path')}
  1318. name={['streamSettings', 'httpupgradeSettings', 'path']}
  1319. >
  1320. <Input />
  1321. </Form.Item>
  1322. <Form.Item
  1323. label={t('pages.inbounds.form.headers')}
  1324. name={['streamSettings', 'httpupgradeSettings', 'headers']}
  1325. >
  1326. <HeaderMapEditor mode="v1" />
  1327. </Form.Item>
  1328. </>
  1329. )}
  1330. {network === 'xhttp' && (
  1331. <>
  1332. <Form.Item
  1333. label={t('host')}
  1334. name={['streamSettings', 'xhttpSettings', 'host']}
  1335. >
  1336. <Input />
  1337. </Form.Item>
  1338. <Form.Item
  1339. label={t('path')}
  1340. name={['streamSettings', 'xhttpSettings', 'path']}
  1341. >
  1342. <Input />
  1343. </Form.Item>
  1344. <Form.Item
  1345. label={t('pages.inbounds.info.mode')}
  1346. name={['streamSettings', 'xhttpSettings', 'mode']}
  1347. >
  1348. <Select options={MODE_OPTIONS} />
  1349. </Form.Item>
  1350. <Form.Item
  1351. label={t('pages.inbounds.form.paddingBytes')}
  1352. name={['streamSettings', 'xhttpSettings', 'xPaddingBytes']}
  1353. >
  1354. <Input />
  1355. </Form.Item>
  1356. <Form.Item
  1357. label={t('pages.inbounds.form.headers')}
  1358. name={['streamSettings', 'xhttpSettings', 'headers']}
  1359. >
  1360. <HeaderMapEditor mode="v1" />
  1361. </Form.Item>
  1362. {/* Padding obfs sub-section: gated by a Switch.
  1363. When on, four extra knobs (key/header/placement/
  1364. method) tune how Xray injects random padding to
  1365. disguise the post body shape. */}
  1366. <Form.Item
  1367. label={t('pages.inbounds.form.paddingObfsMode')}
  1368. name={['streamSettings', 'xhttpSettings', 'xPaddingObfsMode']}
  1369. valuePropName="checked"
  1370. >
  1371. <Switch />
  1372. </Form.Item>
  1373. <Form.Item shouldUpdate noStyle>
  1374. {() => {
  1375. const obfs = !!form.getFieldValue([
  1376. 'streamSettings', 'xhttpSettings', 'xPaddingObfsMode',
  1377. ]);
  1378. if (!obfs) return null;
  1379. return (
  1380. <>
  1381. <Form.Item
  1382. label={t('pages.inbounds.form.paddingKey')}
  1383. name={['streamSettings', 'xhttpSettings', 'xPaddingKey']}
  1384. >
  1385. <Input placeholder="x_padding" />
  1386. </Form.Item>
  1387. <Form.Item
  1388. label={t('pages.inbounds.form.paddingHeader')}
  1389. name={['streamSettings', 'xhttpSettings', 'xPaddingHeader']}
  1390. >
  1391. <Input placeholder="X-Padding" />
  1392. </Form.Item>
  1393. <Form.Item
  1394. label={t('pages.inbounds.form.paddingPlacement')}
  1395. name={['streamSettings', 'xhttpSettings', 'xPaddingPlacement']}
  1396. >
  1397. <Select
  1398. options={[
  1399. { value: '', label: 'Default (queryInHeader)' },
  1400. { value: 'queryInHeader', label: 'queryInHeader' },
  1401. { value: 'header', label: 'header' },
  1402. { value: 'cookie', label: 'cookie' },
  1403. { value: 'query', label: 'query' },
  1404. ]}
  1405. />
  1406. </Form.Item>
  1407. <Form.Item
  1408. label={t('pages.inbounds.form.paddingMethod')}
  1409. name={['streamSettings', 'xhttpSettings', 'xPaddingMethod']}
  1410. >
  1411. <Select
  1412. options={[
  1413. { value: '', label: 'Default (repeat-x)' },
  1414. { value: 'repeat-x', label: 'repeat-x' },
  1415. { value: 'tokenish', label: 'tokenish' },
  1416. ]}
  1417. />
  1418. </Form.Item>
  1419. </>
  1420. );
  1421. }}
  1422. </Form.Item>
  1423. <Form.Item
  1424. noStyle
  1425. shouldUpdate={(prev, curr) =>
  1426. prev?.streamSettings?.xhttpSettings?.mode !==
  1427. curr?.streamSettings?.xhttpSettings?.mode
  1428. }
  1429. >
  1430. {() => {
  1431. const mode = form.getFieldValue([
  1432. 'streamSettings', 'xhttpSettings', 'mode',
  1433. ]);
  1434. return (
  1435. <Form.Item
  1436. label={t('pages.inbounds.form.uplinkHttpMethod')}
  1437. name={['streamSettings', 'xhttpSettings', 'uplinkHTTPMethod']}
  1438. >
  1439. <Select
  1440. placeholder="Default (POST)"
  1441. options={[
  1442. { value: '', label: 'Default (POST)' },
  1443. { value: 'POST', label: 'POST' },
  1444. { value: 'PUT', label: 'PUT' },
  1445. { value: 'GET', label: 'GET (packet-up only)', disabled: mode !== 'packet-up' },
  1446. ]}
  1447. />
  1448. </Form.Item>
  1449. );
  1450. }}
  1451. </Form.Item>
  1452. {/* Session + sequence + uplinkData placements:
  1453. three orthogonal slots Xray uses to thread
  1454. request metadata through the transport
  1455. (path / header / cookie / query). Key field
  1456. only matters when placement is not 'path'. */}
  1457. <Form.Item
  1458. label={t('pages.inbounds.form.sessionPlacement')}
  1459. name={['streamSettings', 'xhttpSettings', 'sessionPlacement']}
  1460. >
  1461. <Select
  1462. placeholder="Default (path)"
  1463. options={[
  1464. { value: '', label: 'Default (path)' },
  1465. { value: 'path', label: 'path' },
  1466. { value: 'header', label: 'header' },
  1467. { value: 'cookie', label: 'cookie' },
  1468. { value: 'query', label: 'query' },
  1469. ]}
  1470. />
  1471. </Form.Item>
  1472. <Form.Item shouldUpdate noStyle>
  1473. {() => {
  1474. const placement = form.getFieldValue([
  1475. 'streamSettings', 'xhttpSettings', 'sessionPlacement',
  1476. ]);
  1477. if (!placement || placement === 'path') return null;
  1478. return (
  1479. <Form.Item
  1480. label={t('pages.inbounds.form.sessionKey')}
  1481. name={['streamSettings', 'xhttpSettings', 'sessionKey']}
  1482. >
  1483. <Input placeholder="x_session" />
  1484. </Form.Item>
  1485. );
  1486. }}
  1487. </Form.Item>
  1488. <Form.Item
  1489. label={t('pages.inbounds.form.sequencePlacement')}
  1490. name={['streamSettings', 'xhttpSettings', 'seqPlacement']}
  1491. >
  1492. <Select
  1493. placeholder="Default (path)"
  1494. options={[
  1495. { value: '', label: 'Default (path)' },
  1496. { value: 'path', label: 'path' },
  1497. { value: 'header', label: 'header' },
  1498. { value: 'cookie', label: 'cookie' },
  1499. { value: 'query', label: 'query' },
  1500. ]}
  1501. />
  1502. </Form.Item>
  1503. <Form.Item shouldUpdate noStyle>
  1504. {() => {
  1505. const placement = form.getFieldValue([
  1506. 'streamSettings', 'xhttpSettings', 'seqPlacement',
  1507. ]);
  1508. if (!placement || placement === 'path') return null;
  1509. return (
  1510. <Form.Item
  1511. label={t('pages.inbounds.form.sequenceKey')}
  1512. name={['streamSettings', 'xhttpSettings', 'seqKey']}
  1513. >
  1514. <Input placeholder="x_seq" />
  1515. </Form.Item>
  1516. );
  1517. }}
  1518. </Form.Item>
  1519. {/* Mode-conditional sub-sections. */}
  1520. <Form.Item shouldUpdate noStyle>
  1521. {() => {
  1522. const mode = form.getFieldValue([
  1523. 'streamSettings', 'xhttpSettings', 'mode',
  1524. ]);
  1525. if (mode !== 'packet-up') return null;
  1526. return (
  1527. <>
  1528. <Form.Item
  1529. label={t('pages.xray.outboundForm.minUploadInterval')}
  1530. name={['streamSettings', 'xhttpSettings', 'scMinPostsIntervalMs']}
  1531. >
  1532. <Input placeholder="30" />
  1533. </Form.Item>
  1534. <Form.Item
  1535. label={t('pages.xray.outboundForm.maxUploadSizeBytes')}
  1536. name={['streamSettings', 'xhttpSettings', 'scMaxEachPostBytes']}
  1537. >
  1538. <Input placeholder="1000000" />
  1539. </Form.Item>
  1540. <Form.Item
  1541. label={t('pages.inbounds.form.uplinkDataPlacement')}
  1542. name={['streamSettings', 'xhttpSettings', 'uplinkDataPlacement']}
  1543. >
  1544. <Select
  1545. options={[
  1546. { value: '', label: 'Default (body)' },
  1547. { value: 'body', label: 'body' },
  1548. { value: 'header', label: 'header' },
  1549. { value: 'cookie', label: 'cookie' },
  1550. { value: 'query', label: 'query' },
  1551. ]}
  1552. />
  1553. </Form.Item>
  1554. <Form.Item shouldUpdate noStyle>
  1555. {() => {
  1556. const place = form.getFieldValue([
  1557. 'streamSettings', 'xhttpSettings', 'uplinkDataPlacement',
  1558. ]);
  1559. if (!place || place === 'body') return null;
  1560. return (
  1561. <>
  1562. <Form.Item
  1563. label={t('pages.inbounds.form.uplinkDataKey')}
  1564. name={['streamSettings', 'xhttpSettings', 'uplinkDataKey']}
  1565. >
  1566. <Input placeholder="x_data" />
  1567. </Form.Item>
  1568. <Form.Item
  1569. label={t('pages.xray.outboundForm.uplinkChunkSize')}
  1570. name={['streamSettings', 'xhttpSettings', 'uplinkChunkSize']}
  1571. >
  1572. <InputNumber
  1573. min={0}
  1574. placeholder="0 (unlimited)"
  1575. style={{ width: '100%' }}
  1576. />
  1577. </Form.Item>
  1578. </>
  1579. );
  1580. }}
  1581. </Form.Item>
  1582. </>
  1583. );
  1584. }}
  1585. </Form.Item>
  1586. <Form.Item shouldUpdate noStyle>
  1587. {() => {
  1588. const mode = form.getFieldValue([
  1589. 'streamSettings', 'xhttpSettings', 'mode',
  1590. ]);
  1591. if (mode !== 'stream-up' && mode !== 'stream-one') return null;
  1592. return (
  1593. <Form.Item
  1594. label={t('pages.xray.outboundForm.noGrpcHeader')}
  1595. name={['streamSettings', 'xhttpSettings', 'noGRPCHeader']}
  1596. valuePropName="checked"
  1597. >
  1598. <Switch />
  1599. </Form.Item>
  1600. );
  1601. }}
  1602. </Form.Item>
  1603. {/* XMUX is the connection-multiplexing layer
  1604. xHTTP uses to fan out parallel requests over
  1605. a small pool of upstream connections. UI-only
  1606. toggle (enableXmux) hides the 6 nested knobs
  1607. when off. */}
  1608. <Form.Item
  1609. label="XMUX"
  1610. name={['streamSettings', 'xhttpSettings', 'enableXmux']}
  1611. valuePropName="checked"
  1612. >
  1613. <Switch />
  1614. </Form.Item>
  1615. <Form.Item shouldUpdate noStyle>
  1616. {() => {
  1617. if (!form.getFieldValue([
  1618. 'streamSettings', 'xhttpSettings', 'enableXmux',
  1619. ])) return null;
  1620. return (
  1621. <>
  1622. <Form.Item
  1623. label={t('pages.xray.outboundForm.maxConcurrency')}
  1624. name={['streamSettings', 'xhttpSettings', 'xmux', 'maxConcurrency']}
  1625. >
  1626. <Input placeholder="16-32" />
  1627. </Form.Item>
  1628. <Form.Item
  1629. label={t('pages.xray.outboundForm.maxConnections')}
  1630. name={['streamSettings', 'xhttpSettings', 'xmux', 'maxConnections']}
  1631. >
  1632. <Input placeholder="0" />
  1633. </Form.Item>
  1634. <Form.Item
  1635. label={t('pages.xray.outboundForm.maxReuseTimes')}
  1636. name={['streamSettings', 'xhttpSettings', 'xmux', 'cMaxReuseTimes']}
  1637. >
  1638. <Input />
  1639. </Form.Item>
  1640. <Form.Item
  1641. label={t('pages.xray.outboundForm.maxRequestTimes')}
  1642. name={['streamSettings', 'xhttpSettings', 'xmux', 'hMaxRequestTimes']}
  1643. >
  1644. <Input placeholder="600-900" />
  1645. </Form.Item>
  1646. <Form.Item
  1647. label={t('pages.xray.outboundForm.maxReusableSecs')}
  1648. name={['streamSettings', 'xhttpSettings', 'xmux', 'hMaxReusableSecs']}
  1649. >
  1650. <Input placeholder="1800-3000" />
  1651. </Form.Item>
  1652. <Form.Item
  1653. label={t('pages.xray.outboundForm.keepAlivePeriod')}
  1654. name={['streamSettings', 'xhttpSettings', 'xmux', 'hKeepAlivePeriod']}
  1655. >
  1656. <InputNumber min={0} style={{ width: '100%' }} />
  1657. </Form.Item>
  1658. </>
  1659. );
  1660. }}
  1661. </Form.Item>
  1662. </>
  1663. )}
  1664. {network === 'hysteria' && (
  1665. <>
  1666. <Form.Item
  1667. label={t('pages.xray.outboundForm.authPassword')}
  1668. name={['streamSettings', 'hysteriaSettings', 'auth']}
  1669. >
  1670. <Input />
  1671. </Form.Item>
  1672. <Form.Item
  1673. label={t('pages.inbounds.form.udpIdleTimeout')}
  1674. name={['streamSettings', 'hysteriaSettings', 'udpIdleTimeout']}
  1675. >
  1676. <InputNumber min={1} style={{ width: '100%' }} />
  1677. </Form.Item>
  1678. </>
  1679. )}
  1680. </>
  1681. )}
  1682. {tlsFlowAllowed && (
  1683. <Form.Item label={t('pages.clients.flow')} name={['settings', 'flow']}>
  1684. <Select
  1685. allowClear
  1686. placeholder={t('none')}
  1687. options={FLOW_OPTIONS}
  1688. />
  1689. </Form.Item>
  1690. )}
  1691. {/* Vision seed knobs only meaningful for the exact
  1692. xtls-rprx-vision flow, on TCP+(tls|reality). The
  1693. legacy class gated this on `canEnableVisionSeed()`
  1694. — same condition encoded inline here. */}
  1695. <Form.Item shouldUpdate noStyle>
  1696. {() => {
  1697. const flow =
  1698. (form.getFieldValue(['settings', 'flow']) ?? '') as string;
  1699. if (!(tlsFlowAllowed && flow === 'xtls-rprx-vision')) return null;
  1700. return (
  1701. <>
  1702. <Form.Item label={t('pages.xray.outboundForm.visionTestpre')} name={['settings', 'testpre']}>
  1703. <InputNumber min={0} style={{ width: '100%' }} />
  1704. </Form.Item>
  1705. <Form.Item
  1706. label={t('pages.inbounds.form.visionTestseed')}
  1707. name={['settings', 'testseed']}
  1708. normalize={(v: unknown) =>
  1709. Array.isArray(v)
  1710. ? v
  1711. .map((x) => Number(x))
  1712. .filter((n) => Number.isInteger(n) && n > 0)
  1713. : []
  1714. }
  1715. >
  1716. <Select
  1717. mode="tags"
  1718. tokenSeparators={[',', ' ']}
  1719. placeholder="four positive integers"
  1720. />
  1721. </Form.Item>
  1722. </>
  1723. );
  1724. }}
  1725. </Form.Item>
  1726. {streamAllowed && network && (
  1727. <Form.Item label={t('security')}>
  1728. <Radio.Group
  1729. value={security}
  1730. buttonStyle="solid"
  1731. onChange={(e) => onSecurityChange(e.target.value as string)}
  1732. >
  1733. <Radio.Button value="none">{t('none')}</Radio.Button>
  1734. {tlsAllowed && <Radio.Button value="tls">TLS</Radio.Button>}
  1735. {realityAllowed && <Radio.Button value="reality">Reality</Radio.Button>}
  1736. </Radio.Group>
  1737. </Form.Item>
  1738. )}
  1739. {security === 'tls' && tlsAllowed && (
  1740. <>
  1741. <Form.Item
  1742. label="SNI"
  1743. name={['streamSettings', 'tlsSettings', 'serverName']}
  1744. >
  1745. <Input placeholder={t('pages.xray.outboundForm.serverNamePlaceholder')} />
  1746. </Form.Item>
  1747. <Form.Item
  1748. label="uTLS"
  1749. name={['streamSettings', 'tlsSettings', 'fingerprint']}
  1750. >
  1751. <Select
  1752. allowClear
  1753. placeholder={t('none')}
  1754. options={UTLS_OPTIONS}
  1755. />
  1756. </Form.Item>
  1757. <Form.Item
  1758. label="ALPN"
  1759. name={['streamSettings', 'tlsSettings', 'alpn']}
  1760. >
  1761. <Select mode="multiple" options={ALPN_OPTIONS} />
  1762. </Form.Item>
  1763. <Form.Item
  1764. label="ECH"
  1765. name={['streamSettings', 'tlsSettings', 'echConfigList']}
  1766. >
  1767. <Input />
  1768. </Form.Item>
  1769. <Form.Item
  1770. label={t('pages.xray.outboundForm.verifyPeerName')}
  1771. name={['streamSettings', 'tlsSettings', 'verifyPeerCertByName']}
  1772. >
  1773. <Input placeholder="cloudflare-dns.com" />
  1774. </Form.Item>
  1775. <Form.Item
  1776. label={t('pages.xray.outboundForm.pinnedSha256')}
  1777. name={['streamSettings', 'tlsSettings', 'pinnedPeerCertSha256']}
  1778. >
  1779. <Input placeholder="base64 SHA256" />
  1780. </Form.Item>
  1781. </>
  1782. )}
  1783. {security === 'reality' && realityAllowed && (
  1784. <>
  1785. <Form.Item
  1786. label="SNI"
  1787. name={['streamSettings', 'realitySettings', 'serverName']}
  1788. >
  1789. <Input />
  1790. </Form.Item>
  1791. <Form.Item
  1792. label="uTLS"
  1793. name={['streamSettings', 'realitySettings', 'fingerprint']}
  1794. >
  1795. <Select options={UTLS_OPTIONS} />
  1796. </Form.Item>
  1797. <Form.Item
  1798. label={t('pages.xray.outboundForm.shortId')}
  1799. name={['streamSettings', 'realitySettings', 'shortId']}
  1800. >
  1801. <Input />
  1802. </Form.Item>
  1803. <Form.Item
  1804. label={t('pages.inbounds.form.spiderX')}
  1805. name={['streamSettings', 'realitySettings', 'spiderX']}
  1806. >
  1807. <Input />
  1808. </Form.Item>
  1809. <Form.Item
  1810. label={t('pages.inbounds.publicKey')}
  1811. name={['streamSettings', 'realitySettings', 'publicKey']}
  1812. >
  1813. <Input.TextArea autoSize={{ minRows: 2 }} />
  1814. </Form.Item>
  1815. <Form.Item
  1816. label={t('pages.inbounds.form.mldsa65Verify')}
  1817. name={['streamSettings', 'realitySettings', 'mldsa65Verify']}
  1818. >
  1819. <Input.TextArea autoSize={{ minRows: 2 }} />
  1820. </Form.Item>
  1821. </>
  1822. )}
  1823. {((streamAllowed && network) || !streamAllowed) && (
  1824. <Form.Item shouldUpdate noStyle>
  1825. {() => {
  1826. const hasSockopt = !!form.getFieldValue([
  1827. 'streamSettings',
  1828. 'sockopt',
  1829. ]);
  1830. return (
  1831. <>
  1832. <Form.Item label={t('pages.xray.outboundForm.sockopts')}>
  1833. <Switch
  1834. checked={hasSockopt}
  1835. onChange={(checked) => {
  1836. form.setFieldValue(
  1837. ['streamSettings', 'sockopt'],
  1838. checked ? SockoptStreamSettingsSchema.parse({}) : undefined,
  1839. );
  1840. }}
  1841. />
  1842. </Form.Item>
  1843. {hasSockopt && (
  1844. <>
  1845. <Form.Item
  1846. label={t('pages.inbounds.form.dialerProxy')}
  1847. name={['streamSettings', 'sockopt', 'dialerProxy']}
  1848. >
  1849. <Input />
  1850. </Form.Item>
  1851. <Form.Item
  1852. label={t('pages.xray.wireguard.domainStrategy')}
  1853. name={['streamSettings', 'sockopt', 'domainStrategy']}
  1854. >
  1855. <Select
  1856. options={Object.values(DOMAIN_STRATEGY_OPTION).map((v) => ({
  1857. value: v,
  1858. label: v,
  1859. }))}
  1860. />
  1861. </Form.Item>
  1862. <Form.Item
  1863. label={t('pages.inbounds.form.addressPortStrategy')}
  1864. name={['streamSettings', 'sockopt', 'addressPortStrategy']}
  1865. >
  1866. <Select options={ADDRESS_PORT_STRATEGY_OPTIONS} />
  1867. </Form.Item>
  1868. <Form.Item
  1869. label={t('pages.xray.outboundForm.keepAliveInterval')}
  1870. name={['streamSettings', 'sockopt', 'tcpKeepAliveInterval']}
  1871. >
  1872. <InputNumber min={0} />
  1873. </Form.Item>
  1874. <Form.Item
  1875. label={t('pages.inbounds.form.tcpFastOpen')}
  1876. name={['streamSettings', 'sockopt', 'tcpFastOpen']}
  1877. valuePropName="checked"
  1878. >
  1879. <Switch />
  1880. </Form.Item>
  1881. <Form.Item
  1882. label={t('pages.inbounds.form.multipathTcp')}
  1883. name={['streamSettings', 'sockopt', 'tcpMptcp']}
  1884. valuePropName="checked"
  1885. >
  1886. <Switch />
  1887. </Form.Item>
  1888. <Form.Item
  1889. label={t('pages.inbounds.form.penetrate')}
  1890. name={['streamSettings', 'sockopt', 'penetrate']}
  1891. valuePropName="checked"
  1892. >
  1893. <Switch />
  1894. </Form.Item>
  1895. <Form.Item
  1896. label={t('pages.xray.outboundForm.markFwmark')}
  1897. name={['streamSettings', 'sockopt', 'mark']}
  1898. >
  1899. <InputNumber min={0} />
  1900. </Form.Item>
  1901. <Form.Item
  1902. label={t('pages.xray.outboundForm.interface')}
  1903. name={['streamSettings', 'sockopt', 'interfaceName']}
  1904. >
  1905. <Input />
  1906. </Form.Item>
  1907. <Form.Item
  1908. label="TProxy"
  1909. name={['streamSettings', 'sockopt', 'tproxy']}
  1910. >
  1911. <Select
  1912. options={[
  1913. { value: 'off', label: 'off' },
  1914. { value: 'redirect', label: 'redirect' },
  1915. { value: 'tproxy', label: 'tproxy' },
  1916. ]}
  1917. />
  1918. </Form.Item>
  1919. <Form.Item
  1920. label={t('pages.inbounds.form.tcpCongestion')}
  1921. name={['streamSettings', 'sockopt', 'tcpcongestion']}
  1922. >
  1923. <Select
  1924. options={Object.values(TCP_CONGESTION_OPTION).map((v) => ({
  1925. value: v,
  1926. label: v,
  1927. }))}
  1928. />
  1929. </Form.Item>
  1930. <Form.Item
  1931. label={t('pages.xray.outboundForm.ipv6Only')}
  1932. name={['streamSettings', 'sockopt', 'V6Only']}
  1933. valuePropName="checked"
  1934. >
  1935. <Switch />
  1936. </Form.Item>
  1937. <Form.Item
  1938. label={t('pages.xray.outboundForm.acceptProxyProtocol')}
  1939. name={['streamSettings', 'sockopt', 'acceptProxyProtocol']}
  1940. valuePropName="checked"
  1941. >
  1942. <Switch />
  1943. </Form.Item>
  1944. <Form.Item
  1945. label={t('pages.xray.outboundForm.tcpUserTimeoutMs')}
  1946. name={['streamSettings', 'sockopt', 'tcpUserTimeout']}
  1947. >
  1948. <InputNumber min={0} style={{ width: '100%' }} />
  1949. </Form.Item>
  1950. <Form.Item
  1951. label={t('pages.xray.outboundForm.tcpKeepAliveIdleS')}
  1952. name={['streamSettings', 'sockopt', 'tcpKeepAliveIdle']}
  1953. >
  1954. <InputNumber min={0} style={{ width: '100%' }} />
  1955. </Form.Item>
  1956. <Form.Item
  1957. label={t('pages.inbounds.form.tcpMaxSeg')}
  1958. name={['streamSettings', 'sockopt', 'tcpMaxSeg']}
  1959. >
  1960. <InputNumber min={0} style={{ width: '100%' }} />
  1961. </Form.Item>
  1962. <Form.Item
  1963. label={t('pages.inbounds.form.tcpWindowClamp')}
  1964. name={['streamSettings', 'sockopt', 'tcpWindowClamp']}
  1965. >
  1966. <InputNumber min={0} style={{ width: '100%' }} />
  1967. </Form.Item>
  1968. <Form.Item
  1969. label={t('pages.inbounds.form.trustedXForwardedFor')}
  1970. name={['streamSettings', 'sockopt', 'trustedXForwardedFor']}
  1971. >
  1972. <Select
  1973. mode="tags"
  1974. tokenSeparators={[',', ' ']}
  1975. placeholder="trusted-proxy.example,10.0.0.0/8"
  1976. />
  1977. </Form.Item>
  1978. <Form.Item shouldUpdate noStyle>
  1979. {() => {
  1980. const he = form.getFieldValue([
  1981. 'streamSettings', 'sockopt', 'happyEyeballs',
  1982. ]);
  1983. const hasHe = he != null;
  1984. return (
  1985. <>
  1986. <Form.Item label="Happy Eyeballs">
  1987. <Switch
  1988. checked={hasHe}
  1989. onChange={(v) => {
  1990. form.setFieldValue(
  1991. ['streamSettings', 'sockopt', 'happyEyeballs'],
  1992. v ? HappyEyeballsSchema.parse({}) : undefined,
  1993. );
  1994. }}
  1995. />
  1996. </Form.Item>
  1997. {hasHe && (
  1998. <>
  1999. <Form.Item
  2000. label={t('pages.inbounds.form.tryDelayMs')}
  2001. name={['streamSettings', 'sockopt', 'happyEyeballs', 'tryDelayMs']}
  2002. >
  2003. <InputNumber min={0} style={{ width: '100%' }} placeholder="0 (disabled) — 250 recommended" />
  2004. </Form.Item>
  2005. <Form.Item
  2006. label={t('pages.inbounds.form.prioritizeIPv6')}
  2007. name={['streamSettings', 'sockopt', 'happyEyeballs', 'prioritizeIPv6']}
  2008. valuePropName="checked"
  2009. >
  2010. <Switch />
  2011. </Form.Item>
  2012. <Form.Item
  2013. label={t('pages.inbounds.form.interleave')}
  2014. name={['streamSettings', 'sockopt', 'happyEyeballs', 'interleave']}
  2015. >
  2016. <InputNumber min={1} style={{ width: '100%' }} />
  2017. </Form.Item>
  2018. <Form.Item
  2019. label={t('pages.inbounds.form.maxConcurrentTry')}
  2020. name={['streamSettings', 'sockopt', 'happyEyeballs', 'maxConcurrentTry']}
  2021. >
  2022. <InputNumber min={0} style={{ width: '100%' }} />
  2023. </Form.Item>
  2024. </>
  2025. )}
  2026. </>
  2027. );
  2028. }}
  2029. </Form.Item>
  2030. <Form.List name={['streamSettings', 'sockopt', 'customSockopt']}>
  2031. {(fields, { add, remove }) => (
  2032. <>
  2033. <Form.Item label={t('pages.inbounds.form.customSockopt')}>
  2034. <Button
  2035. type="dashed"
  2036. size="small"
  2037. onClick={() => add({ type: 'int', level: '6', opt: '', value: '' })}
  2038. >
  2039. + {t('pages.inbounds.form.addCustomOption')}
  2040. </Button>
  2041. </Form.Item>
  2042. {fields.map((field) => (
  2043. <Space.Compact key={field.key} style={{ display: 'flex', marginBottom: 8 }}>
  2044. <Form.Item name={[field.name, 'system']} noStyle>
  2045. <Select
  2046. placeholder="all"
  2047. allowClear
  2048. style={{ width: 100 }}
  2049. options={[
  2050. { value: 'linux', label: 'linux' },
  2051. { value: 'windows', label: 'windows' },
  2052. { value: 'darwin', label: 'darwin' },
  2053. ]}
  2054. />
  2055. </Form.Item>
  2056. <Form.Item name={[field.name, 'type']} noStyle>
  2057. <Select
  2058. style={{ width: 80 }}
  2059. options={[
  2060. { value: 'int', label: 'int' },
  2061. { value: 'str', label: 'str' },
  2062. ]}
  2063. />
  2064. </Form.Item>
  2065. <Form.Item name={[field.name, 'level']} noStyle>
  2066. <Input placeholder="level (6=TCP)" style={{ width: 100 }} />
  2067. </Form.Item>
  2068. <Form.Item name={[field.name, 'opt']} noStyle>
  2069. <Input placeholder="opt (decimal)" style={{ width: 120 }} />
  2070. </Form.Item>
  2071. <Form.Item name={[field.name, 'value']} noStyle>
  2072. <Input placeholder="value" style={{ flex: 1 }} />
  2073. </Form.Item>
  2074. <Button danger onClick={() => remove(field.name)}>−</Button>
  2075. </Space.Compact>
  2076. ))}
  2077. </>
  2078. )}
  2079. </Form.List>
  2080. </>
  2081. )}
  2082. </>
  2083. );
  2084. }}
  2085. </Form.Item>
  2086. )}
  2087. <FinalMaskForm
  2088. name={['streamSettings', 'finalmask']}
  2089. network={network}
  2090. protocol={protocol}
  2091. form={form}
  2092. />
  2093. {(() => {
  2094. const flow = (form.getFieldValue(['settings', 'flow']) ?? '') as string;
  2095. if (!isMuxAllowed(protocol, flow, network)) return null;
  2096. return (
  2097. <Form.Item shouldUpdate noStyle>
  2098. {() => {
  2099. const muxEnabled = !!form.getFieldValue(['mux', 'enabled']);
  2100. return (
  2101. <>
  2102. <Form.Item
  2103. label={t('pages.settings.mux')}
  2104. name={['mux', 'enabled']}
  2105. valuePropName="checked"
  2106. >
  2107. <Switch />
  2108. </Form.Item>
  2109. {muxEnabled && (
  2110. <>
  2111. <Form.Item
  2112. label={t('pages.settings.subFormats.concurrency')}
  2113. name={['mux', 'concurrency']}
  2114. >
  2115. <InputNumber min={-1} max={1024} />
  2116. </Form.Item>
  2117. <Form.Item
  2118. label={t('pages.settings.subFormats.xudpConcurrency')}
  2119. name={['mux', 'xudpConcurrency']}
  2120. >
  2121. <InputNumber min={-1} max={1024} />
  2122. </Form.Item>
  2123. <Form.Item
  2124. label={t('pages.settings.subFormats.xudpUdp443')}
  2125. name={['mux', 'xudpProxyUDP443']}
  2126. >
  2127. <Select
  2128. options={['reject', 'allow', 'skip'].map((v) => ({
  2129. value: v,
  2130. label: v,
  2131. }))}
  2132. />
  2133. </Form.Item>
  2134. </>
  2135. )}
  2136. </>
  2137. );
  2138. }}
  2139. </Form.Item>
  2140. );
  2141. })()}
  2142. </>
  2143. ),
  2144. },
  2145. {
  2146. key: '2',
  2147. label: 'JSON',
  2148. children: (
  2149. <Space orientation="vertical" size={10} style={{ width: '100%', marginTop: 10 }}>
  2150. <Input.Search
  2151. value={linkInput}
  2152. placeholder="vmess:// vless:// trojan:// ss:// hysteria2://"
  2153. enterButton="Import"
  2154. onChange={(e) => setLinkInput(e.target.value)}
  2155. onSearch={importLink}
  2156. />
  2157. <JsonEditor
  2158. value={jsonText}
  2159. onChange={(next) => {
  2160. setJsonText(next);
  2161. setJsonDirty(true);
  2162. }}
  2163. minHeight="360px"
  2164. maxHeight="600px"
  2165. />
  2166. </Space>
  2167. ),
  2168. },
  2169. ]}
  2170. />
  2171. </Form>
  2172. </Modal>
  2173. </>
  2174. );
  2175. }