OutboundFormModal.tsx 107 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244
  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, SyncOutlined } 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: 'TCP (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. let values: OutboundFormValues;
  371. try {
  372. values = await form.validateFields();
  373. } catch {
  374. return;
  375. }
  376. if (duplicateTag) {
  377. messageApi.error('Tag already used by another outbound');
  378. return;
  379. }
  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="Tag"
  421. name="tag"
  422. validateStatus={duplicateTag ? 'warning' : undefined}
  423. help={duplicateTag ? 'Tag already used by another outbound' : undefined}
  424. rules={[
  425. { required: true, message: 'Tag is required' },
  426. ]}
  427. >
  428. <Input placeholder="unique-tag" />
  429. </Form.Item>
  430. <Form.Item label="Send through" name="sendThrough">
  431. <Input placeholder="local IP" />
  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: 'Address is required' }]}
  442. >
  443. <Input />
  444. </Form.Item>
  445. <Form.Item
  446. label={t('pages.inbounds.port')}
  447. name={['settings', 'port']}
  448. rules={[{ required: true, message: 'Port is required' }]}
  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="Reverse tag" name={['settings', 'reverseTag']}>
  482. <Input placeholder="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="UDP over TCP"
  513. name={['settings', 'uot']}
  514. valuePropName="checked"
  515. >
  516. <Switch />
  517. </Form.Item>
  518. <Form.Item label="UoT version" 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="Version" name={['settings', 'version']}>
  535. <InputNumber min={2} max={2} disabled />
  536. </Form.Item>
  537. )}
  538. {protocol === 'loopback' && (
  539. <Form.Item label="Inbound tag" name={['settings', 'inboundTag']}>
  540. <Input placeholder="inbound tag used in routing rules" />
  541. </Form.Item>
  542. )}
  543. {protocol === 'blackhole' && (
  544. <Form.Item label="Response type" 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="Rewrite network" name={['settings', 'rewriteNetwork']}>
  557. <Select
  558. allowClear
  559. placeholder="(unchanged)"
  560. options={[
  561. { value: 'udp', label: 'udp' },
  562. { value: 'tcp', label: 'tcp' },
  563. ]}
  564. />
  565. </Form.Item>
  566. <Form.Item label="Rewrite address" name={['settings', 'rewriteAddress']}>
  567. <Input placeholder="(unchanged) e.g. 1.1.1.1" />
  568. </Form.Item>
  569. <Form.Item label="Rewrite port" name={['settings', 'rewritePort']}>
  570. <InputNumber min={0} max={65535} style={{ width: '100%' }} />
  571. </Form.Item>
  572. <Form.Item label="User level" 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="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>Rule {index + 1}</span>
  591. <DeleteOutlined
  592. className="danger-icon"
  593. onClick={() => remove(field.name)}
  594. />
  595. </div>
  596. </Form.Item>
  597. <Form.Item label="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="Strategy" 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="Redirect" name={['settings', 'redirect']}>
  626. <Input />
  627. </Form.Item>
  628. <Form.Item label="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="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="Length" name={['settings', 'fragment', 'length']}>
  671. <Input />
  672. </Form.Item>
  673. <Form.Item
  674. label="Interval"
  675. name={['settings', 'fragment', 'interval']}
  676. >
  677. <Input />
  678. </Form.Item>
  679. <Form.Item
  680. label="Max Split"
  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="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>Noise {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="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="Packet" name={[field.name, 'packet']}>
  753. <Input />
  754. </Form.Item>
  755. <Form.Item label="Delay (ms)" name={[field.name, 'delay']}>
  756. <Input />
  757. </Form.Item>
  758. <Form.Item label="Apply to" 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="Final Rules">
  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. Override Xray&apos;s default private-IP block
  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>Rule {index + 1}</span>
  798. <DeleteOutlined
  799. className="danger-icon"
  800. onClick={() => remove(field.name)}
  801. />
  802. </div>
  803. </Form.Item>
  804. <Form.Item label="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="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="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="Block delay (ms)"
  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="Reverse Sniffing"
  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="Metadata Only"
  892. name={['settings', 'reverseSniffing', 'metadataOnly']}
  893. valuePropName="checked"
  894. >
  895. <Switch />
  896. </Form.Item>
  897. <Form.Item
  898. label="Route Only"
  899. name={['settings', 'reverseSniffing', 'routeOnly']}
  900. valuePropName="checked"
  901. >
  902. <Switch />
  903. </Form.Item>
  904. <Form.Item
  905. label="IPs Excluded"
  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="Domains Excluded"
  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
  937. label={
  938. <>
  939. {t('pages.inbounds.privatekey')}
  940. <SyncOutlined
  941. className="random-icon"
  942. onClick={() => {
  943. const pair = Wireguard.generateKeypair();
  944. form.setFieldValue(['settings', 'secretKey'], pair.privateKey);
  945. form.setFieldValue(['settings', 'pubKey'], pair.publicKey);
  946. }}
  947. />
  948. </>
  949. }
  950. name={['settings', 'secretKey']}
  951. >
  952. <Input />
  953. </Form.Item>
  954. <Form.Item label={t('pages.inbounds.publicKey')} name={['settings', 'pubKey']}>
  955. <Input disabled />
  956. </Form.Item>
  957. <Form.Item label="Domain strategy" name={['settings', 'domainStrategy']}>
  958. <Select
  959. options={[
  960. { value: '', label: `(${t('none')})` },
  961. ...WireguardDomainStrategy.map((s) => ({ value: s, label: s })),
  962. ]}
  963. />
  964. </Form.Item>
  965. <Form.Item label="MTU" name={['settings', 'mtu']}>
  966. <InputNumber min={0} />
  967. </Form.Item>
  968. <Form.Item label="Workers" name={['settings', 'workers']}>
  969. <InputNumber min={0} />
  970. </Form.Item>
  971. <Form.Item
  972. label="No-kernel TUN"
  973. name={['settings', 'noKernelTun']}
  974. valuePropName="checked"
  975. >
  976. <Switch />
  977. </Form.Item>
  978. <Form.Item label="Reserved" name={['settings', 'reserved']}>
  979. <Input placeholder="comma-separated bytes, e.g. 1,2,3" />
  980. </Form.Item>
  981. <Form.List name={['settings', 'peers']}>
  982. {(fields, { add, remove }) => (
  983. <>
  984. <Form.Item label="Peers">
  985. <Button
  986. size="small"
  987. type="primary"
  988. icon={<PlusOutlined />}
  989. onClick={() =>
  990. add({
  991. publicKey: '',
  992. psk: '',
  993. allowedIPs: ['0.0.0.0/0', '::/0'],
  994. endpoint: '',
  995. keepAlive: 0,
  996. })
  997. }
  998. />
  999. </Form.Item>
  1000. {fields.map((field, index) => (
  1001. <div key={field.key}>
  1002. <Form.Item wrapperCol={{ md: { span: 14, offset: 8 } }}>
  1003. <div className="item-heading">
  1004. <span>Peer {index + 1}</span>
  1005. {fields.length > 1 && (
  1006. <DeleteOutlined
  1007. className="danger-icon"
  1008. onClick={() => remove(field.name)}
  1009. />
  1010. )}
  1011. </div>
  1012. </Form.Item>
  1013. <Form.Item label="Endpoint" name={[field.name, 'endpoint']}>
  1014. <Input />
  1015. </Form.Item>
  1016. <Form.Item
  1017. label={t('pages.inbounds.publicKey')}
  1018. name={[field.name, 'publicKey']}
  1019. >
  1020. <Input />
  1021. </Form.Item>
  1022. <Form.Item label="PSK" name={[field.name, 'psk']}>
  1023. <Input />
  1024. </Form.Item>
  1025. <Form.Item label="Allowed IPs">
  1026. <Form.List name={[field.name, 'allowedIPs']}>
  1027. {(ipFields, { add: addIp, remove: removeIp }) => (
  1028. <>
  1029. {ipFields.map((ipField, ipIdx) => (
  1030. <Space.Compact
  1031. key={ipField.key}
  1032. block
  1033. style={{ marginBottom: 4 }}
  1034. >
  1035. <Form.Item noStyle name={ipField.name}>
  1036. <Input />
  1037. </Form.Item>
  1038. {ipFields.length > 1 && (
  1039. <InputAddon onClick={() => removeIp(ipIdx)}>
  1040. <MinusOutlined />
  1041. </InputAddon>
  1042. )}
  1043. </Space.Compact>
  1044. ))}
  1045. <Button
  1046. size="small"
  1047. icon={<PlusOutlined />}
  1048. onClick={() => addIp('')}
  1049. />
  1050. </>
  1051. )}
  1052. </Form.List>
  1053. </Form.Item>
  1054. <Form.Item label="Keep alive" name={[field.name, 'keepAlive']}>
  1055. <InputNumber min={0} />
  1056. </Form.Item>
  1057. </div>
  1058. ))}
  1059. </>
  1060. )}
  1061. </Form.List>
  1062. </>
  1063. )}
  1064. {streamAllowed && network && (
  1065. <>
  1066. <Form.Item
  1067. label={t('transmission')}
  1068. name={['streamSettings', 'network']}
  1069. >
  1070. <Select
  1071. value={network}
  1072. onChange={onNetworkChange}
  1073. options={
  1074. protocol === 'hysteria'
  1075. ? [...NETWORK_OPTIONS, HYSTERIA_NETWORK_OPTION]
  1076. : NETWORK_OPTIONS
  1077. }
  1078. />
  1079. </Form.Item>
  1080. {network === 'tcp' && (
  1081. <Form.Item shouldUpdate noStyle>
  1082. {() => {
  1083. const type =
  1084. form.getFieldValue([
  1085. 'streamSettings',
  1086. 'tcpSettings',
  1087. 'header',
  1088. 'type',
  1089. ]) ?? 'none';
  1090. return (
  1091. <>
  1092. <Form.Item label={`HTTP ${t('camouflage')}`}>
  1093. <Switch
  1094. checked={type === 'http'}
  1095. onChange={(checked) =>
  1096. form.setFieldValue(
  1097. ['streamSettings', 'tcpSettings', 'header'],
  1098. checked
  1099. ? {
  1100. type: 'http',
  1101. request: {
  1102. version: '1.1',
  1103. method: 'GET',
  1104. path: ['/'],
  1105. headers: {},
  1106. },
  1107. response: {
  1108. version: '1.1',
  1109. status: '200',
  1110. reason: 'OK',
  1111. headers: {},
  1112. },
  1113. }
  1114. : { type: 'none' },
  1115. )
  1116. }
  1117. />
  1118. </Form.Item>
  1119. {type === 'http' && (
  1120. <>
  1121. <Form.Item
  1122. label="Request method"
  1123. name={[
  1124. 'streamSettings', 'tcpSettings', 'header',
  1125. 'request', 'method',
  1126. ]}
  1127. >
  1128. <Input placeholder="GET" />
  1129. </Form.Item>
  1130. <Form.Item
  1131. label="Request version"
  1132. name={[
  1133. 'streamSettings', 'tcpSettings', 'header',
  1134. 'request', 'version',
  1135. ]}
  1136. >
  1137. <Input placeholder="1.1" />
  1138. </Form.Item>
  1139. <Form.Item
  1140. label={t('host')}
  1141. name={[
  1142. 'streamSettings',
  1143. 'tcpSettings',
  1144. 'header',
  1145. 'request',
  1146. 'headers',
  1147. 'Host',
  1148. ]}
  1149. normalize={(v: unknown) =>
  1150. typeof v === 'string'
  1151. ? v.split(',').map((s) => s.trim()).filter(Boolean)
  1152. : Array.isArray(v) ? v : []
  1153. }
  1154. getValueProps={(v: unknown) => ({
  1155. value: Array.isArray(v) ? v.join(',') : '',
  1156. })}
  1157. >
  1158. <Input placeholder="example.com,cdn.example.com" />
  1159. </Form.Item>
  1160. <Form.Item
  1161. label={t('path')}
  1162. name={[
  1163. 'streamSettings',
  1164. 'tcpSettings',
  1165. 'header',
  1166. 'request',
  1167. 'path',
  1168. ]}
  1169. normalize={(v: unknown) =>
  1170. typeof v === 'string'
  1171. ? v.split(',').map((s) => s.trim()).filter(Boolean)
  1172. : Array.isArray(v) ? v : ['/']
  1173. }
  1174. getValueProps={(v: unknown) => ({
  1175. value: Array.isArray(v) ? v.join(',') : '/',
  1176. })}
  1177. >
  1178. <Input placeholder="/,/api,/static" />
  1179. </Form.Item>
  1180. <Form.Item
  1181. label="Request headers"
  1182. name={[
  1183. 'streamSettings', 'tcpSettings', 'header',
  1184. 'request', 'headers',
  1185. ]}
  1186. >
  1187. <HeaderMapEditor mode="v2" />
  1188. </Form.Item>
  1189. <Form.Item
  1190. label="Response version"
  1191. name={[
  1192. 'streamSettings', 'tcpSettings', 'header',
  1193. 'response', 'version',
  1194. ]}
  1195. >
  1196. <Input placeholder="1.1" />
  1197. </Form.Item>
  1198. <Form.Item
  1199. label="Response status"
  1200. name={[
  1201. 'streamSettings', 'tcpSettings', 'header',
  1202. 'response', 'status',
  1203. ]}
  1204. >
  1205. <Input placeholder="200" />
  1206. </Form.Item>
  1207. <Form.Item
  1208. label="Response reason"
  1209. name={[
  1210. 'streamSettings', 'tcpSettings', 'header',
  1211. 'response', 'reason',
  1212. ]}
  1213. >
  1214. <Input placeholder="OK" />
  1215. </Form.Item>
  1216. <Form.Item
  1217. label="Response headers"
  1218. name={[
  1219. 'streamSettings', 'tcpSettings', 'header',
  1220. 'response', 'headers',
  1221. ]}
  1222. >
  1223. <HeaderMapEditor mode="v2" />
  1224. </Form.Item>
  1225. </>
  1226. )}
  1227. </>
  1228. );
  1229. }}
  1230. </Form.Item>
  1231. )}
  1232. {network === 'kcp' && (
  1233. <>
  1234. <Form.Item label="MTU" name={['streamSettings', 'kcpSettings', 'mtu']}>
  1235. <InputNumber min={0} />
  1236. </Form.Item>
  1237. <Form.Item label="TTI (ms)" name={['streamSettings', 'kcpSettings', 'tti']}>
  1238. <InputNumber min={0} />
  1239. </Form.Item>
  1240. <Form.Item
  1241. label="Uplink (MB/s)"
  1242. name={['streamSettings', 'kcpSettings', 'uplinkCapacity']}
  1243. >
  1244. <InputNumber min={0} />
  1245. </Form.Item>
  1246. <Form.Item
  1247. label="Downlink (MB/s)"
  1248. name={['streamSettings', 'kcpSettings', 'downlinkCapacity']}
  1249. >
  1250. <InputNumber min={0} />
  1251. </Form.Item>
  1252. <Form.Item
  1253. label="CWND multiplier"
  1254. name={['streamSettings', 'kcpSettings', 'cwndMultiplier']}
  1255. >
  1256. <InputNumber min={1} />
  1257. </Form.Item>
  1258. <Form.Item
  1259. label="Max sending window"
  1260. name={['streamSettings', 'kcpSettings', 'maxSendingWindow']}
  1261. >
  1262. <InputNumber min={0} />
  1263. </Form.Item>
  1264. </>
  1265. )}
  1266. {network === 'ws' && (
  1267. <>
  1268. <Form.Item label={t('host')} name={['streamSettings', 'wsSettings', 'host']}>
  1269. <Input />
  1270. </Form.Item>
  1271. <Form.Item label={t('path')} name={['streamSettings', 'wsSettings', 'path']}>
  1272. <Input />
  1273. </Form.Item>
  1274. <Form.Item
  1275. label="Heartbeat (s)"
  1276. name={['streamSettings', 'wsSettings', 'heartbeatPeriod']}
  1277. >
  1278. <InputNumber min={0} />
  1279. </Form.Item>
  1280. <Form.Item
  1281. label="Headers"
  1282. name={['streamSettings', 'wsSettings', 'headers']}
  1283. >
  1284. <HeaderMapEditor mode="v1" />
  1285. </Form.Item>
  1286. </>
  1287. )}
  1288. {network === 'grpc' && (
  1289. <>
  1290. <Form.Item
  1291. label="Service name"
  1292. name={['streamSettings', 'grpcSettings', 'serviceName']}
  1293. >
  1294. <Input />
  1295. </Form.Item>
  1296. <Form.Item
  1297. label="Authority"
  1298. name={['streamSettings', 'grpcSettings', 'authority']}
  1299. >
  1300. <Input />
  1301. </Form.Item>
  1302. <Form.Item
  1303. label="Multi mode"
  1304. name={['streamSettings', 'grpcSettings', 'multiMode']}
  1305. valuePropName="checked"
  1306. >
  1307. <Switch />
  1308. </Form.Item>
  1309. </>
  1310. )}
  1311. {network === 'httpupgrade' && (
  1312. <>
  1313. <Form.Item
  1314. label={t('host')}
  1315. name={['streamSettings', 'httpupgradeSettings', 'host']}
  1316. >
  1317. <Input />
  1318. </Form.Item>
  1319. <Form.Item
  1320. label={t('path')}
  1321. name={['streamSettings', 'httpupgradeSettings', 'path']}
  1322. >
  1323. <Input />
  1324. </Form.Item>
  1325. <Form.Item
  1326. label="Headers"
  1327. name={['streamSettings', 'httpupgradeSettings', 'headers']}
  1328. >
  1329. <HeaderMapEditor mode="v1" />
  1330. </Form.Item>
  1331. </>
  1332. )}
  1333. {network === 'xhttp' && (
  1334. <>
  1335. <Form.Item
  1336. label={t('host')}
  1337. name={['streamSettings', 'xhttpSettings', 'host']}
  1338. >
  1339. <Input />
  1340. </Form.Item>
  1341. <Form.Item
  1342. label={t('path')}
  1343. name={['streamSettings', 'xhttpSettings', 'path']}
  1344. >
  1345. <Input />
  1346. </Form.Item>
  1347. <Form.Item
  1348. label="Mode"
  1349. name={['streamSettings', 'xhttpSettings', 'mode']}
  1350. >
  1351. <Select options={MODE_OPTIONS} />
  1352. </Form.Item>
  1353. <Form.Item
  1354. label="Padding Bytes"
  1355. name={['streamSettings', 'xhttpSettings', 'xPaddingBytes']}
  1356. >
  1357. <Input />
  1358. </Form.Item>
  1359. <Form.Item
  1360. label="Headers"
  1361. name={['streamSettings', 'xhttpSettings', 'headers']}
  1362. >
  1363. <HeaderMapEditor mode="v1" />
  1364. </Form.Item>
  1365. {/* Padding obfs sub-section: gated by a Switch.
  1366. When on, four extra knobs (key/header/placement/
  1367. method) tune how Xray injects random padding to
  1368. disguise the post body shape. */}
  1369. <Form.Item
  1370. label="Padding obfs mode"
  1371. name={['streamSettings', 'xhttpSettings', 'xPaddingObfsMode']}
  1372. valuePropName="checked"
  1373. >
  1374. <Switch />
  1375. </Form.Item>
  1376. <Form.Item shouldUpdate noStyle>
  1377. {() => {
  1378. const obfs = !!form.getFieldValue([
  1379. 'streamSettings', 'xhttpSettings', 'xPaddingObfsMode',
  1380. ]);
  1381. if (!obfs) return null;
  1382. return (
  1383. <>
  1384. <Form.Item
  1385. label="Padding key"
  1386. name={['streamSettings', 'xhttpSettings', 'xPaddingKey']}
  1387. >
  1388. <Input placeholder="x_padding" />
  1389. </Form.Item>
  1390. <Form.Item
  1391. label="Padding header"
  1392. name={['streamSettings', 'xhttpSettings', 'xPaddingHeader']}
  1393. >
  1394. <Input placeholder="X-Padding" />
  1395. </Form.Item>
  1396. <Form.Item
  1397. label="Padding placement"
  1398. name={['streamSettings', 'xhttpSettings', 'xPaddingPlacement']}
  1399. >
  1400. <Select
  1401. options={[
  1402. { value: '', label: 'Default (queryInHeader)' },
  1403. { value: 'queryInHeader', label: 'queryInHeader' },
  1404. { value: 'header', label: 'header' },
  1405. { value: 'cookie', label: 'cookie' },
  1406. { value: 'query', label: 'query' },
  1407. ]}
  1408. />
  1409. </Form.Item>
  1410. <Form.Item
  1411. label="Padding method"
  1412. name={['streamSettings', 'xhttpSettings', 'xPaddingMethod']}
  1413. >
  1414. <Select
  1415. options={[
  1416. { value: '', label: 'Default (repeat-x)' },
  1417. { value: 'repeat-x', label: 'repeat-x' },
  1418. { value: 'tokenish', label: 'tokenish' },
  1419. ]}
  1420. />
  1421. </Form.Item>
  1422. </>
  1423. );
  1424. }}
  1425. </Form.Item>
  1426. <Form.Item
  1427. noStyle
  1428. shouldUpdate={(prev, curr) =>
  1429. prev?.streamSettings?.xhttpSettings?.mode !==
  1430. curr?.streamSettings?.xhttpSettings?.mode
  1431. }
  1432. >
  1433. {() => {
  1434. const mode = form.getFieldValue([
  1435. 'streamSettings', 'xhttpSettings', 'mode',
  1436. ]);
  1437. return (
  1438. <Form.Item
  1439. label="Uplink HTTP method"
  1440. name={['streamSettings', 'xhttpSettings', 'uplinkHTTPMethod']}
  1441. >
  1442. <Select
  1443. placeholder="Default (POST)"
  1444. options={[
  1445. { value: '', label: 'Default (POST)' },
  1446. { value: 'POST', label: 'POST' },
  1447. { value: 'PUT', label: 'PUT' },
  1448. { value: 'GET', label: 'GET (packet-up only)', disabled: mode !== 'packet-up' },
  1449. ]}
  1450. />
  1451. </Form.Item>
  1452. );
  1453. }}
  1454. </Form.Item>
  1455. {/* Session + sequence + uplinkData placements:
  1456. three orthogonal slots Xray uses to thread
  1457. request metadata through the transport
  1458. (path / header / cookie / query). Key field
  1459. only matters when placement is not 'path'. */}
  1460. <Form.Item
  1461. label="Session placement"
  1462. name={['streamSettings', 'xhttpSettings', 'sessionPlacement']}
  1463. >
  1464. <Select
  1465. placeholder="Default (path)"
  1466. options={[
  1467. { value: '', label: 'Default (path)' },
  1468. { value: 'path', label: 'path' },
  1469. { value: 'header', label: 'header' },
  1470. { value: 'cookie', label: 'cookie' },
  1471. { value: 'query', label: 'query' },
  1472. ]}
  1473. />
  1474. </Form.Item>
  1475. <Form.Item shouldUpdate noStyle>
  1476. {() => {
  1477. const placement = form.getFieldValue([
  1478. 'streamSettings', 'xhttpSettings', 'sessionPlacement',
  1479. ]);
  1480. if (!placement || placement === 'path') return null;
  1481. return (
  1482. <Form.Item
  1483. label="Session key"
  1484. name={['streamSettings', 'xhttpSettings', 'sessionKey']}
  1485. >
  1486. <Input placeholder="x_session" />
  1487. </Form.Item>
  1488. );
  1489. }}
  1490. </Form.Item>
  1491. <Form.Item
  1492. label="Sequence placement"
  1493. name={['streamSettings', 'xhttpSettings', 'seqPlacement']}
  1494. >
  1495. <Select
  1496. placeholder="Default (path)"
  1497. options={[
  1498. { value: '', label: 'Default (path)' },
  1499. { value: 'path', label: 'path' },
  1500. { value: 'header', label: 'header' },
  1501. { value: 'cookie', label: 'cookie' },
  1502. { value: 'query', label: 'query' },
  1503. ]}
  1504. />
  1505. </Form.Item>
  1506. <Form.Item shouldUpdate noStyle>
  1507. {() => {
  1508. const placement = form.getFieldValue([
  1509. 'streamSettings', 'xhttpSettings', 'seqPlacement',
  1510. ]);
  1511. if (!placement || placement === 'path') return null;
  1512. return (
  1513. <Form.Item
  1514. label="Sequence key"
  1515. name={['streamSettings', 'xhttpSettings', 'seqKey']}
  1516. >
  1517. <Input placeholder="x_seq" />
  1518. </Form.Item>
  1519. );
  1520. }}
  1521. </Form.Item>
  1522. {/* Mode-conditional sub-sections. */}
  1523. <Form.Item shouldUpdate noStyle>
  1524. {() => {
  1525. const mode = form.getFieldValue([
  1526. 'streamSettings', 'xhttpSettings', 'mode',
  1527. ]);
  1528. if (mode !== 'packet-up') return null;
  1529. return (
  1530. <>
  1531. <Form.Item
  1532. label="Min upload interval (ms)"
  1533. name={['streamSettings', 'xhttpSettings', 'scMinPostsIntervalMs']}
  1534. >
  1535. <Input placeholder="30" />
  1536. </Form.Item>
  1537. <Form.Item
  1538. label="Max upload size (bytes)"
  1539. name={['streamSettings', 'xhttpSettings', 'scMaxEachPostBytes']}
  1540. >
  1541. <Input placeholder="1000000" />
  1542. </Form.Item>
  1543. <Form.Item
  1544. label="Uplink data placement"
  1545. name={['streamSettings', 'xhttpSettings', 'uplinkDataPlacement']}
  1546. >
  1547. <Select
  1548. options={[
  1549. { value: '', label: 'Default (body)' },
  1550. { value: 'body', label: 'body' },
  1551. { value: 'header', label: 'header' },
  1552. { value: 'cookie', label: 'cookie' },
  1553. { value: 'query', label: 'query' },
  1554. ]}
  1555. />
  1556. </Form.Item>
  1557. <Form.Item shouldUpdate noStyle>
  1558. {() => {
  1559. const place = form.getFieldValue([
  1560. 'streamSettings', 'xhttpSettings', 'uplinkDataPlacement',
  1561. ]);
  1562. if (!place || place === 'body') return null;
  1563. return (
  1564. <>
  1565. <Form.Item
  1566. label="Uplink data key"
  1567. name={['streamSettings', 'xhttpSettings', 'uplinkDataKey']}
  1568. >
  1569. <Input placeholder="x_data" />
  1570. </Form.Item>
  1571. <Form.Item
  1572. label="Uplink chunk size"
  1573. name={['streamSettings', 'xhttpSettings', 'uplinkChunkSize']}
  1574. >
  1575. <InputNumber
  1576. min={0}
  1577. placeholder="0 (unlimited)"
  1578. style={{ width: '100%' }}
  1579. />
  1580. </Form.Item>
  1581. </>
  1582. );
  1583. }}
  1584. </Form.Item>
  1585. </>
  1586. );
  1587. }}
  1588. </Form.Item>
  1589. <Form.Item shouldUpdate noStyle>
  1590. {() => {
  1591. const mode = form.getFieldValue([
  1592. 'streamSettings', 'xhttpSettings', 'mode',
  1593. ]);
  1594. if (mode !== 'stream-up' && mode !== 'stream-one') return null;
  1595. return (
  1596. <Form.Item
  1597. label="No gRPC header"
  1598. name={['streamSettings', 'xhttpSettings', 'noGRPCHeader']}
  1599. valuePropName="checked"
  1600. >
  1601. <Switch />
  1602. </Form.Item>
  1603. );
  1604. }}
  1605. </Form.Item>
  1606. {/* XMUX is the connection-multiplexing layer
  1607. xHTTP uses to fan out parallel requests over
  1608. a small pool of upstream connections. UI-only
  1609. toggle (enableXmux) hides the 6 nested knobs
  1610. when off. */}
  1611. <Form.Item
  1612. label="XMUX"
  1613. name={['streamSettings', 'xhttpSettings', 'enableXmux']}
  1614. valuePropName="checked"
  1615. >
  1616. <Switch />
  1617. </Form.Item>
  1618. <Form.Item shouldUpdate noStyle>
  1619. {() => {
  1620. if (!form.getFieldValue([
  1621. 'streamSettings', 'xhttpSettings', 'enableXmux',
  1622. ])) return null;
  1623. return (
  1624. <>
  1625. <Form.Item
  1626. label="Max concurrency"
  1627. name={['streamSettings', 'xhttpSettings', 'xmux', 'maxConcurrency']}
  1628. >
  1629. <Input placeholder="16-32" />
  1630. </Form.Item>
  1631. <Form.Item
  1632. label="Max connections"
  1633. name={['streamSettings', 'xhttpSettings', 'xmux', 'maxConnections']}
  1634. >
  1635. <Input placeholder="0" />
  1636. </Form.Item>
  1637. <Form.Item
  1638. label="Max reuse times"
  1639. name={['streamSettings', 'xhttpSettings', 'xmux', 'cMaxReuseTimes']}
  1640. >
  1641. <Input />
  1642. </Form.Item>
  1643. <Form.Item
  1644. label="Max request times"
  1645. name={['streamSettings', 'xhttpSettings', 'xmux', 'hMaxRequestTimes']}
  1646. >
  1647. <Input placeholder="600-900" />
  1648. </Form.Item>
  1649. <Form.Item
  1650. label="Max reusable secs"
  1651. name={['streamSettings', 'xhttpSettings', 'xmux', 'hMaxReusableSecs']}
  1652. >
  1653. <Input placeholder="1800-3000" />
  1654. </Form.Item>
  1655. <Form.Item
  1656. label="Keep alive period"
  1657. name={['streamSettings', 'xhttpSettings', 'xmux', 'hKeepAlivePeriod']}
  1658. >
  1659. <InputNumber min={0} style={{ width: '100%' }} />
  1660. </Form.Item>
  1661. </>
  1662. );
  1663. }}
  1664. </Form.Item>
  1665. </>
  1666. )}
  1667. {network === 'hysteria' && (
  1668. <>
  1669. <Form.Item
  1670. label="Auth password"
  1671. name={['streamSettings', 'hysteriaSettings', 'auth']}
  1672. >
  1673. <Input />
  1674. </Form.Item>
  1675. <Form.Item
  1676. label="UDP idle timeout (s)"
  1677. name={['streamSettings', 'hysteriaSettings', 'udpIdleTimeout']}
  1678. >
  1679. <InputNumber min={1} style={{ width: '100%' }} />
  1680. </Form.Item>
  1681. </>
  1682. )}
  1683. </>
  1684. )}
  1685. {tlsFlowAllowed && (
  1686. <Form.Item label="Flow" name={['settings', 'flow']}>
  1687. <Select
  1688. allowClear
  1689. placeholder={t('none')}
  1690. options={FLOW_OPTIONS}
  1691. />
  1692. </Form.Item>
  1693. )}
  1694. {/* Vision seed knobs only meaningful for the exact
  1695. xtls-rprx-vision flow, on TCP+(tls|reality). The
  1696. legacy class gated this on `canEnableVisionSeed()`
  1697. — same condition encoded inline here. */}
  1698. <Form.Item shouldUpdate noStyle>
  1699. {() => {
  1700. const flow =
  1701. (form.getFieldValue(['settings', 'flow']) ?? '') as string;
  1702. if (!(tlsFlowAllowed && flow === 'xtls-rprx-vision')) return null;
  1703. return (
  1704. <>
  1705. <Form.Item label="Vision testpre" name={['settings', 'testpre']}>
  1706. <InputNumber min={0} style={{ width: '100%' }} />
  1707. </Form.Item>
  1708. <Form.Item
  1709. label="Vision testseed"
  1710. name={['settings', 'testseed']}
  1711. normalize={(v: unknown) =>
  1712. Array.isArray(v)
  1713. ? v
  1714. .map((x) => Number(x))
  1715. .filter((n) => Number.isInteger(n) && n > 0)
  1716. : []
  1717. }
  1718. >
  1719. <Select
  1720. mode="tags"
  1721. tokenSeparators={[',', ' ']}
  1722. placeholder="four positive integers"
  1723. />
  1724. </Form.Item>
  1725. </>
  1726. );
  1727. }}
  1728. </Form.Item>
  1729. {streamAllowed && network && (
  1730. <Form.Item label={t('security')}>
  1731. <Radio.Group
  1732. value={security}
  1733. buttonStyle="solid"
  1734. onChange={(e) => onSecurityChange(e.target.value as string)}
  1735. >
  1736. <Radio.Button value="none">{t('none')}</Radio.Button>
  1737. {tlsAllowed && <Radio.Button value="tls">TLS</Radio.Button>}
  1738. {realityAllowed && <Radio.Button value="reality">Reality</Radio.Button>}
  1739. </Radio.Group>
  1740. </Form.Item>
  1741. )}
  1742. {security === 'tls' && tlsAllowed && (
  1743. <>
  1744. <Form.Item
  1745. label="SNI"
  1746. name={['streamSettings', 'tlsSettings', 'serverName']}
  1747. >
  1748. <Input placeholder="server name" />
  1749. </Form.Item>
  1750. <Form.Item
  1751. label="uTLS"
  1752. name={['streamSettings', 'tlsSettings', 'fingerprint']}
  1753. >
  1754. <Select
  1755. allowClear
  1756. placeholder={t('none')}
  1757. options={UTLS_OPTIONS}
  1758. />
  1759. </Form.Item>
  1760. <Form.Item
  1761. label="ALPN"
  1762. name={['streamSettings', 'tlsSettings', 'alpn']}
  1763. >
  1764. <Select mode="multiple" options={ALPN_OPTIONS} />
  1765. </Form.Item>
  1766. <Form.Item
  1767. label="ECH"
  1768. name={['streamSettings', 'tlsSettings', 'echConfigList']}
  1769. >
  1770. <Input />
  1771. </Form.Item>
  1772. <Form.Item
  1773. label="Verify peer name"
  1774. name={['streamSettings', 'tlsSettings', 'verifyPeerCertByName']}
  1775. >
  1776. <Input placeholder="cloudflare-dns.com" />
  1777. </Form.Item>
  1778. <Form.Item
  1779. label="Pinned SHA256"
  1780. name={['streamSettings', 'tlsSettings', 'pinnedPeerCertSha256']}
  1781. >
  1782. <Input placeholder="base64 SHA256" />
  1783. </Form.Item>
  1784. </>
  1785. )}
  1786. {security === 'reality' && realityAllowed && (
  1787. <>
  1788. <Form.Item
  1789. label="SNI"
  1790. name={['streamSettings', 'realitySettings', 'serverName']}
  1791. >
  1792. <Input />
  1793. </Form.Item>
  1794. <Form.Item
  1795. label="uTLS"
  1796. name={['streamSettings', 'realitySettings', 'fingerprint']}
  1797. >
  1798. <Select options={UTLS_OPTIONS} />
  1799. </Form.Item>
  1800. <Form.Item
  1801. label="Short ID"
  1802. name={['streamSettings', 'realitySettings', 'shortId']}
  1803. >
  1804. <Input />
  1805. </Form.Item>
  1806. <Form.Item
  1807. label="SpiderX"
  1808. name={['streamSettings', 'realitySettings', 'spiderX']}
  1809. >
  1810. <Input />
  1811. </Form.Item>
  1812. <Form.Item
  1813. label={t('pages.inbounds.publicKey')}
  1814. name={['streamSettings', 'realitySettings', 'publicKey']}
  1815. >
  1816. <Input.TextArea autoSize={{ minRows: 2 }} />
  1817. </Form.Item>
  1818. <Form.Item
  1819. label="mldsa65 verify"
  1820. name={['streamSettings', 'realitySettings', 'mldsa65Verify']}
  1821. >
  1822. <Input.TextArea autoSize={{ minRows: 2 }} />
  1823. </Form.Item>
  1824. </>
  1825. )}
  1826. {((streamAllowed && network) || !streamAllowed) && (
  1827. <Form.Item shouldUpdate noStyle>
  1828. {() => {
  1829. const hasSockopt = !!form.getFieldValue([
  1830. 'streamSettings',
  1831. 'sockopt',
  1832. ]);
  1833. return (
  1834. <>
  1835. <Form.Item label="Sockopts">
  1836. <Switch
  1837. checked={hasSockopt}
  1838. onChange={(checked) => {
  1839. form.setFieldValue(
  1840. ['streamSettings', 'sockopt'],
  1841. checked ? SockoptStreamSettingsSchema.parse({}) : undefined,
  1842. );
  1843. }}
  1844. />
  1845. </Form.Item>
  1846. {hasSockopt && (
  1847. <>
  1848. <Form.Item
  1849. label="Dialer proxy"
  1850. name={['streamSettings', 'sockopt', 'dialerProxy']}
  1851. >
  1852. <Input />
  1853. </Form.Item>
  1854. <Form.Item
  1855. label="Domain strategy"
  1856. name={['streamSettings', 'sockopt', 'domainStrategy']}
  1857. >
  1858. <Select
  1859. options={Object.values(DOMAIN_STRATEGY_OPTION).map((v) => ({
  1860. value: v,
  1861. label: v,
  1862. }))}
  1863. />
  1864. </Form.Item>
  1865. <Form.Item
  1866. label="Address+port strategy"
  1867. name={['streamSettings', 'sockopt', 'addressPortStrategy']}
  1868. >
  1869. <Select options={ADDRESS_PORT_STRATEGY_OPTIONS} />
  1870. </Form.Item>
  1871. <Form.Item
  1872. label="Keep alive interval"
  1873. name={['streamSettings', 'sockopt', 'tcpKeepAliveInterval']}
  1874. >
  1875. <InputNumber min={0} />
  1876. </Form.Item>
  1877. <Form.Item
  1878. label="TCP Fast Open"
  1879. name={['streamSettings', 'sockopt', 'tcpFastOpen']}
  1880. valuePropName="checked"
  1881. >
  1882. <Switch />
  1883. </Form.Item>
  1884. <Form.Item
  1885. label="Multipath TCP"
  1886. name={['streamSettings', 'sockopt', 'tcpMptcp']}
  1887. valuePropName="checked"
  1888. >
  1889. <Switch />
  1890. </Form.Item>
  1891. <Form.Item
  1892. label="Penetrate"
  1893. name={['streamSettings', 'sockopt', 'penetrate']}
  1894. valuePropName="checked"
  1895. >
  1896. <Switch />
  1897. </Form.Item>
  1898. <Form.Item
  1899. label="Mark (fwmark)"
  1900. name={['streamSettings', 'sockopt', 'mark']}
  1901. >
  1902. <InputNumber min={0} />
  1903. </Form.Item>
  1904. <Form.Item
  1905. label="Interface"
  1906. name={['streamSettings', 'sockopt', 'interfaceName']}
  1907. >
  1908. <Input />
  1909. </Form.Item>
  1910. <Form.Item
  1911. label="TProxy"
  1912. name={['streamSettings', 'sockopt', 'tproxy']}
  1913. >
  1914. <Select
  1915. options={[
  1916. { value: 'off', label: 'off' },
  1917. { value: 'redirect', label: 'redirect' },
  1918. { value: 'tproxy', label: 'tproxy' },
  1919. ]}
  1920. />
  1921. </Form.Item>
  1922. <Form.Item
  1923. label="TCP congestion"
  1924. name={['streamSettings', 'sockopt', 'tcpcongestion']}
  1925. >
  1926. <Select
  1927. options={Object.values(TCP_CONGESTION_OPTION).map((v) => ({
  1928. value: v,
  1929. label: v,
  1930. }))}
  1931. />
  1932. </Form.Item>
  1933. <Form.Item
  1934. label="IPv6 only"
  1935. name={['streamSettings', 'sockopt', 'V6Only']}
  1936. valuePropName="checked"
  1937. >
  1938. <Switch />
  1939. </Form.Item>
  1940. <Form.Item
  1941. label="Accept proxy protocol"
  1942. name={['streamSettings', 'sockopt', 'acceptProxyProtocol']}
  1943. valuePropName="checked"
  1944. >
  1945. <Switch />
  1946. </Form.Item>
  1947. <Form.Item
  1948. label="TCP user timeout (ms)"
  1949. name={['streamSettings', 'sockopt', 'tcpUserTimeout']}
  1950. >
  1951. <InputNumber min={0} style={{ width: '100%' }} />
  1952. </Form.Item>
  1953. <Form.Item
  1954. label="TCP keep-alive idle (s)"
  1955. name={['streamSettings', 'sockopt', 'tcpKeepAliveIdle']}
  1956. >
  1957. <InputNumber min={0} style={{ width: '100%' }} />
  1958. </Form.Item>
  1959. <Form.Item
  1960. label="TCP max segment"
  1961. name={['streamSettings', 'sockopt', 'tcpMaxSeg']}
  1962. >
  1963. <InputNumber min={0} style={{ width: '100%' }} />
  1964. </Form.Item>
  1965. <Form.Item
  1966. label="TCP window clamp"
  1967. name={['streamSettings', 'sockopt', 'tcpWindowClamp']}
  1968. >
  1969. <InputNumber min={0} style={{ width: '100%' }} />
  1970. </Form.Item>
  1971. <Form.Item
  1972. label="Trusted X-Forwarded-For"
  1973. name={['streamSettings', 'sockopt', 'trustedXForwardedFor']}
  1974. >
  1975. <Select
  1976. mode="tags"
  1977. tokenSeparators={[',', ' ']}
  1978. placeholder="trusted-proxy.example,10.0.0.0/8"
  1979. />
  1980. </Form.Item>
  1981. <Form.Item shouldUpdate noStyle>
  1982. {() => {
  1983. const he = form.getFieldValue([
  1984. 'streamSettings', 'sockopt', 'happyEyeballs',
  1985. ]);
  1986. const hasHe = he != null;
  1987. return (
  1988. <>
  1989. <Form.Item label="Happy Eyeballs">
  1990. <Switch
  1991. checked={hasHe}
  1992. onChange={(v) => {
  1993. form.setFieldValue(
  1994. ['streamSettings', 'sockopt', 'happyEyeballs'],
  1995. v ? HappyEyeballsSchema.parse({}) : undefined,
  1996. );
  1997. }}
  1998. />
  1999. </Form.Item>
  2000. {hasHe && (
  2001. <>
  2002. <Form.Item
  2003. label="Try delay (ms)"
  2004. name={['streamSettings', 'sockopt', 'happyEyeballs', 'tryDelayMs']}
  2005. >
  2006. <InputNumber min={0} style={{ width: '100%' }} placeholder="0 (disabled) — 250 recommended" />
  2007. </Form.Item>
  2008. <Form.Item
  2009. label="Prioritize IPv6"
  2010. name={['streamSettings', 'sockopt', 'happyEyeballs', 'prioritizeIPv6']}
  2011. valuePropName="checked"
  2012. >
  2013. <Switch />
  2014. </Form.Item>
  2015. <Form.Item
  2016. label="Interleave"
  2017. name={['streamSettings', 'sockopt', 'happyEyeballs', 'interleave']}
  2018. >
  2019. <InputNumber min={1} style={{ width: '100%' }} />
  2020. </Form.Item>
  2021. <Form.Item
  2022. label="Max concurrent try"
  2023. name={['streamSettings', 'sockopt', 'happyEyeballs', 'maxConcurrentTry']}
  2024. >
  2025. <InputNumber min={0} style={{ width: '100%' }} />
  2026. </Form.Item>
  2027. </>
  2028. )}
  2029. </>
  2030. );
  2031. }}
  2032. </Form.Item>
  2033. <Form.List name={['streamSettings', 'sockopt', 'customSockopt']}>
  2034. {(fields, { add, remove }) => (
  2035. <>
  2036. <Form.Item label="Custom sockopt">
  2037. <Button
  2038. type="dashed"
  2039. size="small"
  2040. onClick={() => add({ type: 'int', level: '6', opt: '', value: '' })}
  2041. >
  2042. + Add custom option
  2043. </Button>
  2044. </Form.Item>
  2045. {fields.map((field) => (
  2046. <Space.Compact key={field.key} style={{ display: 'flex', marginBottom: 8 }}>
  2047. <Form.Item name={[field.name, 'system']} noStyle>
  2048. <Select
  2049. placeholder="all"
  2050. allowClear
  2051. style={{ width: 100 }}
  2052. options={[
  2053. { value: 'linux', label: 'linux' },
  2054. { value: 'windows', label: 'windows' },
  2055. { value: 'darwin', label: 'darwin' },
  2056. ]}
  2057. />
  2058. </Form.Item>
  2059. <Form.Item name={[field.name, 'type']} noStyle>
  2060. <Select
  2061. style={{ width: 80 }}
  2062. options={[
  2063. { value: 'int', label: 'int' },
  2064. { value: 'str', label: 'str' },
  2065. ]}
  2066. />
  2067. </Form.Item>
  2068. <Form.Item name={[field.name, 'level']} noStyle>
  2069. <Input placeholder="level (6=TCP)" style={{ width: 100 }} />
  2070. </Form.Item>
  2071. <Form.Item name={[field.name, 'opt']} noStyle>
  2072. <Input placeholder="opt (decimal)" style={{ width: 120 }} />
  2073. </Form.Item>
  2074. <Form.Item name={[field.name, 'value']} noStyle>
  2075. <Input placeholder="value" style={{ flex: 1 }} />
  2076. </Form.Item>
  2077. <Button danger onClick={() => remove(field.name)}>−</Button>
  2078. </Space.Compact>
  2079. ))}
  2080. </>
  2081. )}
  2082. </Form.List>
  2083. </>
  2084. )}
  2085. </>
  2086. );
  2087. }}
  2088. </Form.Item>
  2089. )}
  2090. <FinalMaskForm
  2091. name={['streamSettings', 'finalmask']}
  2092. network={network}
  2093. protocol={protocol}
  2094. form={form}
  2095. />
  2096. {(() => {
  2097. const flow = (form.getFieldValue(['settings', 'flow']) ?? '') as string;
  2098. if (!isMuxAllowed(protocol, flow, network)) return null;
  2099. return (
  2100. <Form.Item shouldUpdate noStyle>
  2101. {() => {
  2102. const muxEnabled = !!form.getFieldValue(['mux', 'enabled']);
  2103. return (
  2104. <>
  2105. <Form.Item
  2106. label={t('pages.settings.mux')}
  2107. name={['mux', 'enabled']}
  2108. valuePropName="checked"
  2109. >
  2110. <Switch />
  2111. </Form.Item>
  2112. {muxEnabled && (
  2113. <>
  2114. <Form.Item
  2115. label="Concurrency"
  2116. name={['mux', 'concurrency']}
  2117. >
  2118. <InputNumber min={-1} max={1024} />
  2119. </Form.Item>
  2120. <Form.Item
  2121. label="xudp concurrency"
  2122. name={['mux', 'xudpConcurrency']}
  2123. >
  2124. <InputNumber min={-1} max={1024} />
  2125. </Form.Item>
  2126. <Form.Item
  2127. label="xudp UDP 443"
  2128. name={['mux', 'xudpProxyUDP443']}
  2129. >
  2130. <Select
  2131. options={['reject', 'allow', 'skip'].map((v) => ({
  2132. value: v,
  2133. label: v,
  2134. }))}
  2135. />
  2136. </Form.Item>
  2137. </>
  2138. )}
  2139. </>
  2140. );
  2141. }}
  2142. </Form.Item>
  2143. );
  2144. })()}
  2145. </>
  2146. ),
  2147. },
  2148. {
  2149. key: '2',
  2150. label: 'JSON',
  2151. children: (
  2152. <Space orientation="vertical" size={10} style={{ width: '100%', marginTop: 10 }}>
  2153. <Input.Search
  2154. value={linkInput}
  2155. placeholder="vmess:// vless:// trojan:// ss:// hysteria2://"
  2156. enterButton="Import"
  2157. onChange={(e) => setLinkInput(e.target.value)}
  2158. onSearch={importLink}
  2159. />
  2160. <JsonEditor
  2161. value={jsonText}
  2162. onChange={(next) => {
  2163. setJsonText(next);
  2164. setJsonDirty(true);
  2165. }}
  2166. minHeight="360px"
  2167. maxHeight="600px"
  2168. />
  2169. </Space>
  2170. ),
  2171. },
  2172. ]}
  2173. />
  2174. </Form>
  2175. </Modal>
  2176. </>
  2177. );
  2178. }