InboundFormModal.tsx 84 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361
  1. import { useEffect, useRef, useState } from 'react';
  2. import { useTranslation } from 'react-i18next';
  3. import dayjs from 'dayjs';
  4. import {
  5. Button,
  6. Card,
  7. Checkbox,
  8. Empty,
  9. Form,
  10. Input,
  11. InputNumber,
  12. Modal,
  13. Radio,
  14. Select,
  15. Space,
  16. Switch,
  17. Tabs,
  18. Tooltip,
  19. Typography,
  20. message,
  21. } from 'antd';
  22. import {
  23. ArrowDownOutlined,
  24. ArrowUpOutlined,
  25. DeleteOutlined,
  26. MinusOutlined,
  27. PlusOutlined,
  28. SyncOutlined,
  29. } from '@ant-design/icons';
  30. import { HttpUtil, NumberFormatter, RandomUtil, SizeFormatter, Wireguard } from '@/utils';
  31. import {
  32. rawInboundToFormValues,
  33. formValuesToWirePayload,
  34. } from '@/lib/xray/inbound-form-adapter';
  35. import { createDefaultInboundSettings } from '@/lib/xray/inbound-defaults';
  36. import {
  37. canEnableReality,
  38. canEnableStream,
  39. canEnableTls,
  40. isSS2022,
  41. } from '@/lib/xray/protocol-capabilities';
  42. import { SSMethodSchema } from '@/schemas/protocols/inbound/shadowsocks';
  43. import { getRandomRealityTarget } from '@/models/reality-targets';
  44. import {
  45. InboundFormBaseSchema,
  46. InboundFormSchema,
  47. type FallbackRow,
  48. type InboundFormValues,
  49. } from '@/schemas/forms/inbound-form';
  50. import { antdRule } from '@/utils/zodForm';
  51. import {
  52. ALPN_OPTION,
  53. DOMAIN_STRATEGY_OPTION,
  54. Protocols,
  55. SNIFFING_OPTION,
  56. TCP_CONGESTION_OPTION,
  57. TLS_CIPHER_OPTION,
  58. TLS_VERSION_OPTION,
  59. USAGE_OPTION,
  60. UTLS_FINGERPRINT,
  61. } from '@/schemas/primitives';
  62. import { SockoptStreamSettingsSchema } from '@/schemas/protocols/stream/sockopt';
  63. import { TlsStreamSettingsSchema } from '@/schemas/protocols/security/tls';
  64. import { RealityStreamSettingsSchema } from '@/schemas/protocols/security/reality';
  65. import DateTimePicker from '@/components/DateTimePicker';
  66. import HeaderMapEditor from '@/components/HeaderMapEditor';
  67. import InputAddon from '@/components/InputAddon';
  68. import JsonEditor from '@/components/JsonEditor';
  69. import type { FormInstance } from 'antd';
  70. import type { NamePath } from 'antd/es/form/interface';
  71. const { TextArea } = Input;
  72. import type { DBInbound } from '@/models/dbinbound';
  73. import type { NodeRecord } from '@/api/queries/useNodesQuery';
  74. // Pattern A rewrite of InboundFormModal. Built as a sibling file so the
  75. // build stays green while the rewrite progresses section by section.
  76. // InboundsPage continues to render the old InboundFormModal.tsx until the
  77. // atomic swap at the end (Core Decision 7).
  78. const { Text } = Typography;
  79. // Sub-editor for one slice of the form (settings, streamSettings, sniffing).
  80. // Holds a local text buffer so the user can type freely; on every keystroke
  81. // we try to JSON.parse and forward the result to form state. Invalid JSON
  82. // is held in the buffer until the next valid moment — no panic on partial
  83. // input. The buffer seeds once on mount; the modal's destroyOnHidden makes
  84. // each open a fresh editor instance, so we don't need to re-sync on outer
  85. // form changes.
  86. function AdvancedSliceEditor({
  87. form,
  88. path,
  89. minHeight,
  90. maxHeight,
  91. }: {
  92. form: FormInstance<InboundFormValues>;
  93. path: NamePath;
  94. minHeight?: string;
  95. maxHeight?: string;
  96. }) {
  97. const [text, setText] = useState(() =>
  98. JSON.stringify(form.getFieldValue(path) ?? {}, null, 2),
  99. );
  100. return (
  101. <JsonEditor
  102. value={text}
  103. minHeight={minHeight}
  104. maxHeight={maxHeight}
  105. onChange={(next) => {
  106. setText(next);
  107. try {
  108. form.setFieldValue(path, JSON.parse(next));
  109. } catch {
  110. }
  111. }}
  112. />
  113. );
  114. }
  115. const PROTOCOL_OPTIONS = Object.values(Protocols).map((p) => ({ value: p, label: p }));
  116. const TRAFFIC_RESETS = ['never', 'hourly', 'daily', 'weekly', 'monthly'] as const;
  117. const NODE_ELIGIBLE_PROTOCOLS = new Set<string>([
  118. Protocols.VLESS,
  119. Protocols.VMESS,
  120. Protocols.TROJAN,
  121. Protocols.SHADOWSOCKS,
  122. Protocols.HYSTERIA,
  123. Protocols.WIREGUARD,
  124. ]);
  125. interface InboundFormModalProps {
  126. open: boolean;
  127. onClose: () => void;
  128. onSaved: () => void;
  129. mode: 'add' | 'edit';
  130. dbInbound: DBInbound | null;
  131. dbInbounds: DBInbound[];
  132. availableNodes?: NodeRecord[];
  133. }
  134. function buildAddModeValues(): InboundFormValues {
  135. const settings = createDefaultInboundSettings('vless') ?? undefined;
  136. return rawInboundToFormValues({
  137. protocol: 'vless',
  138. settings,
  139. streamSettings: { network: 'tcp', security: 'none' },
  140. sniffing: {},
  141. port: RandomUtil.randomInteger(10000, 60000),
  142. listen: '',
  143. tag: '',
  144. enable: true,
  145. trafficReset: 'never',
  146. });
  147. }
  148. export default function InboundFormModal({
  149. open,
  150. onClose,
  151. onSaved,
  152. mode,
  153. dbInbound,
  154. dbInbounds,
  155. availableNodes,
  156. }: InboundFormModalProps) {
  157. const { t } = useTranslation();
  158. const [messageApi, messageContextHolder] = message.useMessage();
  159. const [form] = Form.useForm<InboundFormValues>();
  160. const [saving, setSaving] = useState(false);
  161. const fallbackKeyRef = useRef(0);
  162. const [fallbacks, setFallbacks] = useState<FallbackRow[]>([]);
  163. const selectableNodes = (availableNodes || []).filter((n) => n.enable);
  164. const protocol = (Form.useWatch('protocol', form) ?? '') as string;
  165. const isNodeEligible = NODE_ELIGIBLE_PROTOCOLS.has(protocol);
  166. const sniffingEnabled = Form.useWatch(['sniffing', 'enabled'], form) ?? false;
  167. const vlessEncryption = Form.useWatch(['settings', 'encryption'], form) ?? '';
  168. const ssMethod = Form.useWatch(['settings', 'method'], form);
  169. const isSSWith2022 = isSS2022({
  170. protocol,
  171. settings: typeof ssMethod === 'string' ? { method: ssMethod } : {},
  172. });
  173. const mixedUdpOn = Form.useWatch(['settings', 'udp'], form) ?? false;
  174. const network = Form.useWatch(['streamSettings', 'network'], form) ?? '';
  175. const security = Form.useWatch(['streamSettings', 'security'], form) ?? 'none';
  176. const streamEnabled = canEnableStream({ protocol });
  177. const tlsAllowed = canEnableTls({ protocol, streamSettings: { network, security } });
  178. const realityAllowed = canEnableReality({ protocol, streamSettings: { network, security } });
  179. const isFallbackHost =
  180. (protocol === Protocols.VLESS || protocol === Protocols.TROJAN)
  181. && network === 'tcp'
  182. && (security === 'tls' || security === 'reality');
  183. const fallbackChildOptions = (dbInbounds || [])
  184. .filter((ib) => ib.id !== dbInbound?.id)
  185. .map((ib) => ({
  186. label: `${ib.remark || `#${ib.id}`} · ${ib.protocol}:${ib.port}`,
  187. value: ib.id,
  188. }));
  189. const loadFallbacks = async (masterId: number | null) => {
  190. if (!masterId) {
  191. setFallbacks([]);
  192. return;
  193. }
  194. const msg = await HttpUtil.get(`/panel/api/inbounds/${masterId}/fallbacks`);
  195. if (!msg?.success || !Array.isArray(msg.obj)) {
  196. setFallbacks([]);
  197. return;
  198. }
  199. setFallbacks(
  200. (msg.obj as { childId: number; name?: string; alpn?: string; path?: string; xver?: number }[])
  201. .map((r) => ({
  202. rowKey: `fb-${++fallbackKeyRef.current}`,
  203. childId: r.childId,
  204. name: r.name || '',
  205. alpn: r.alpn || '',
  206. path: r.path || '',
  207. xver: r.xver || 0,
  208. })),
  209. );
  210. };
  211. const saveFallbacks = async (masterId: number) => {
  212. if (!masterId) return true;
  213. const payload = {
  214. fallbacks: fallbacks.filter((c) => c.childId).map((c, i) => ({
  215. childId: c.childId,
  216. name: c.name,
  217. alpn: c.alpn,
  218. path: c.path,
  219. xver: Number(c.xver) || 0,
  220. sortOrder: i,
  221. })),
  222. };
  223. const msg = await HttpUtil.post(
  224. `/panel/api/inbounds/${masterId}/fallbacks`,
  225. payload,
  226. { headers: { 'Content-Type': 'application/json' } },
  227. );
  228. return !!msg?.success;
  229. };
  230. const addFallback = () => {
  231. setFallbacks((prev) => [...prev, {
  232. rowKey: `fb-${++fallbackKeyRef.current}`,
  233. childId: null,
  234. name: '',
  235. alpn: '',
  236. path: '',
  237. xver: 0,
  238. }]);
  239. };
  240. const updateFallback = (rowKey: string, patch: Partial<FallbackRow>) => {
  241. setFallbacks((prev) => prev.map((r) => r.rowKey === rowKey ? { ...r, ...patch } : r));
  242. };
  243. const removeFallback = (idx: number) => {
  244. setFallbacks((prev) => prev.filter((_, i) => i !== idx));
  245. };
  246. // Move a fallback row up/down by swapping adjacent indices. The order
  247. // is persisted via the fallback row's sortOrder (rebuilt by index on
  248. // save), so reordering survives reloads.
  249. const moveFallback = (idx: number, direction: -1 | 1) => {
  250. setFallbacks((prev) => {
  251. const target = idx + direction;
  252. if (target < 0 || target >= prev.length) return prev;
  253. const next = prev.slice();
  254. [next[idx], next[target]] = [next[target], next[idx]];
  255. return next;
  256. });
  257. };
  258. // One-shot: add a fresh fallback row for every eligible inbound (i.e.
  259. // every option in fallbackChildOptions) that is not already wired up.
  260. // Convenient for operators who want catch-all routing to every host
  261. // they manage on the panel.
  262. const addAllFallbacks = () => {
  263. setFallbacks((prev) => {
  264. const alreadyHave = new Set(prev.map((r) => r.childId));
  265. const additions = fallbackChildOptions
  266. .filter((opt) => !alreadyHave.has(opt.value))
  267. .map<FallbackRow>((opt) => ({
  268. rowKey: `fb-${++fallbackKeyRef.current}`,
  269. childId: opt.value,
  270. name: '',
  271. alpn: '',
  272. path: '',
  273. xver: 0,
  274. }));
  275. if (additions.length === 0) return prev;
  276. return [...prev, ...additions];
  277. });
  278. };
  279. const genRealityKeypair = async () => {
  280. setSaving(true);
  281. try {
  282. const msg = await HttpUtil.get('/panel/api/server/getNewX25519Cert');
  283. if (msg?.success) {
  284. const obj = msg.obj as { privateKey: string; publicKey: string };
  285. form.setFieldValue(['streamSettings', 'realitySettings', 'privateKey'], obj.privateKey);
  286. form.setFieldValue(['streamSettings', 'realitySettings', 'settings', 'publicKey'], obj.publicKey);
  287. }
  288. } finally {
  289. setSaving(false);
  290. }
  291. };
  292. const clearRealityKeypair = () => {
  293. form.setFieldValue(['streamSettings', 'realitySettings', 'privateKey'], '');
  294. form.setFieldValue(['streamSettings', 'realitySettings', 'settings', 'publicKey'], '');
  295. };
  296. const genMldsa65 = async () => {
  297. setSaving(true);
  298. try {
  299. const msg = await HttpUtil.get('/panel/api/server/getNewmldsa65');
  300. if (msg?.success) {
  301. const obj = msg.obj as { seed: string; verify: string };
  302. form.setFieldValue(['streamSettings', 'realitySettings', 'mldsa65Seed'], obj.seed);
  303. form.setFieldValue(['streamSettings', 'realitySettings', 'settings', 'mldsa65Verify'], obj.verify);
  304. }
  305. } finally {
  306. setSaving(false);
  307. }
  308. };
  309. const clearMldsa65 = () => {
  310. form.setFieldValue(['streamSettings', 'realitySettings', 'mldsa65Seed'], '');
  311. form.setFieldValue(['streamSettings', 'realitySettings', 'settings', 'mldsa65Verify'], '');
  312. };
  313. const randomizeRealityTarget = () => {
  314. const tgt = getRandomRealityTarget() as { target: string; sni: string };
  315. form.setFieldValue(['streamSettings', 'realitySettings', 'target'], tgt.target);
  316. form.setFieldValue(
  317. ['streamSettings', 'realitySettings', 'serverNames'],
  318. tgt.sni.split(',').map((s) => s.trim()).filter(Boolean),
  319. );
  320. };
  321. const randomizeShortIds = () => {
  322. form.setFieldValue(
  323. ['streamSettings', 'realitySettings', 'shortIds'],
  324. RandomUtil.randomShortIds().split(',').map((s) => s.trim()).filter(Boolean),
  325. );
  326. };
  327. const getNewEchCert = async () => {
  328. const sni = form.getFieldValue(['streamSettings', 'tlsSettings', 'serverName']);
  329. setSaving(true);
  330. try {
  331. const msg = await HttpUtil.post('/panel/api/server/getNewEchCert', { sni });
  332. if (msg?.success) {
  333. const obj = msg.obj as { echServerKeys: string; echConfigList: string };
  334. form.setFieldValue(['streamSettings', 'tlsSettings', 'echServerKeys'], obj.echServerKeys);
  335. form.setFieldValue(['streamSettings', 'tlsSettings', 'settings', 'echConfigList'], obj.echConfigList);
  336. }
  337. } finally {
  338. setSaving(false);
  339. }
  340. };
  341. const clearEchCert = () => {
  342. form.setFieldValue(['streamSettings', 'tlsSettings', 'echServerKeys'], '');
  343. form.setFieldValue(['streamSettings', 'tlsSettings', 'settings', 'echConfigList'], '');
  344. };
  345. const onSecurityChange = (next: string) => {
  346. const current = (form.getFieldValue('streamSettings') as Record<string, unknown>) ?? {};
  347. const cleaned: Record<string, unknown> = { ...current, security: next };
  348. delete cleaned.tlsSettings;
  349. delete cleaned.realitySettings;
  350. if (next === 'tls') cleaned.tlsSettings = TlsStreamSettingsSchema.parse({});
  351. if (next === 'reality') cleaned.realitySettings = RealityStreamSettingsSchema.parse({});
  352. form.setFieldValue('streamSettings', cleaned);
  353. };
  354. const xhttpMode = Form.useWatch(['streamSettings', 'xhttpSettings', 'mode'], form);
  355. const xhttpObfsMode = Form.useWatch(['streamSettings', 'xhttpSettings', 'xPaddingObfsMode'], form) ?? false;
  356. const xhttpSessionPlacement = Form.useWatch(['streamSettings', 'xhttpSettings', 'sessionPlacement'], form);
  357. const xhttpSeqPlacement = Form.useWatch(['streamSettings', 'xhttpSettings', 'seqPlacement'], form);
  358. const xhttpUplinkPlacement = Form.useWatch(['streamSettings', 'xhttpSettings', 'uplinkDataPlacement'], form);
  359. const externalProxyArr = Form.useWatch(['streamSettings', 'externalProxy'], form);
  360. const externalProxyOn = Array.isArray(externalProxyArr) && externalProxyArr.length > 0;
  361. const sockoptValue = Form.useWatch(['streamSettings', 'sockopt'], form);
  362. const sockoptOn = !!sockoptValue && typeof sockoptValue === 'object' && Object.keys(sockoptValue as object).length > 0;
  363. const toggleExternalProxy = (on: boolean) => {
  364. if (on) {
  365. const port = (form.getFieldValue('port') as number) ?? 443;
  366. form.setFieldValue(['streamSettings', 'externalProxy'], [{
  367. forceTls: 'same',
  368. dest: typeof window !== 'undefined' ? window.location.hostname : '',
  369. port,
  370. remark: '',
  371. sni: '',
  372. fingerprint: '',
  373. alpn: [],
  374. }]);
  375. } else {
  376. form.setFieldValue(['streamSettings', 'externalProxy'], []);
  377. }
  378. };
  379. const toggleSockopt = (on: boolean) => {
  380. if (on) {
  381. form.setFieldValue(
  382. ['streamSettings', 'sockopt'],
  383. SockoptStreamSettingsSchema.parse({}),
  384. );
  385. } else {
  386. form.setFieldValue(['streamSettings', 'sockopt'], undefined);
  387. }
  388. };
  389. const wgSecretKey = Form.useWatch(['settings', 'secretKey'], form);
  390. const wgPubKey = typeof wgSecretKey === 'string' && wgSecretKey.length > 0
  391. ? Wireguard.generateKeypair(wgSecretKey).publicKey
  392. : '';
  393. const regenInboundWg = () => {
  394. const kp = Wireguard.generateKeypair();
  395. form.setFieldValue(['settings', 'secretKey'], kp.privateKey);
  396. };
  397. const regenWgPeerKeypair = (peerName: number) => {
  398. const kp = Wireguard.generateKeypair();
  399. form.setFieldValue(['settings', 'peers', peerName, 'privateKey'], kp.privateKey);
  400. form.setFieldValue(['settings', 'peers', peerName, 'publicKey'], kp.publicKey);
  401. };
  402. const matchesVlessAuth = (
  403. block: { id?: string; label?: string } | undefined | null,
  404. authId: string,
  405. ) => {
  406. if (block?.id === authId) return true;
  407. const label = (block?.label || '').toLowerCase().replace(/[-_\s]/g, '');
  408. if (authId === 'mlkem768') return label.includes('mlkem768');
  409. if (authId === 'x25519') return label.includes('x25519');
  410. return false;
  411. };
  412. const getNewVlessEnc = async (authId: string) => {
  413. if (!authId) return;
  414. setSaving(true);
  415. try {
  416. const msg = await HttpUtil.get('/panel/api/server/getNewVlessEnc');
  417. if (!msg?.success) return;
  418. const obj = msg.obj as {
  419. auths?: { decryption: string; encryption: string; label?: string; id?: string }[];
  420. };
  421. const block = (obj.auths || []).find((a) => matchesVlessAuth(a, authId));
  422. if (!block) return;
  423. form.setFieldValue(['settings', 'decryption'], block.decryption);
  424. form.setFieldValue(['settings', 'encryption'], block.encryption);
  425. } finally {
  426. setSaving(false);
  427. }
  428. };
  429. const clearVlessEnc = () => {
  430. form.setFieldValue(['settings', 'decryption'], 'none');
  431. form.setFieldValue(['settings', 'encryption'], 'none');
  432. };
  433. const selectedVlessAuth = (() => {
  434. const enc = typeof vlessEncryption === 'string' ? vlessEncryption : '';
  435. if (!enc || enc === 'none') return 'None';
  436. const parts = enc.split('.').filter(Boolean);
  437. const authKey = parts[parts.length - 1] || '';
  438. if (!authKey) return t('pages.inbounds.vlessAuthCustom');
  439. return authKey.length > 300
  440. ? t('pages.inbounds.vlessAuthMlkem768')
  441. : t('pages.inbounds.vlessAuthX25519');
  442. })();
  443. useEffect(() => {
  444. if (!open) return;
  445. const initial = mode === 'edit' && dbInbound
  446. ? rawInboundToFormValues(dbInbound)
  447. : buildAddModeValues();
  448. form.resetFields();
  449. form.setFieldsValue(initial);
  450. if (
  451. mode === 'edit'
  452. && dbInbound
  453. && (dbInbound.protocol === Protocols.VLESS || dbInbound.protocol === Protocols.TROJAN)
  454. ) {
  455. loadFallbacks(dbInbound.id);
  456. } else {
  457. setFallbacks([]);
  458. }
  459. }, [open, mode, dbInbound, form]);
  460. // Why: protocol picker reset cascades through the form — clearing the
  461. // settings DU branch and dropping a nodeId that no longer applies. The
  462. // legacy modal did this imperatively in onProtocolChange; here we hook
  463. // into AntD's onValuesChange and let setFieldValue keep the rest of
  464. // the form state intact.
  465. const onValuesChange = (changed: Partial<InboundFormValues>) => {
  466. if (mode === 'edit') return;
  467. if ('protocol' in changed && typeof changed.protocol === 'string') {
  468. const next = changed.protocol;
  469. const settings = createDefaultInboundSettings(next) ?? undefined;
  470. form.setFieldValue('settings', settings);
  471. if (!NODE_ELIGIBLE_PROTOCOLS.has(next)) {
  472. form.setFieldValue('nodeId', null);
  473. }
  474. }
  475. };
  476. const submit = async () => {
  477. let values: InboundFormValues;
  478. try {
  479. values = await form.validateFields();
  480. } catch {
  481. return;
  482. }
  483. const parsed = InboundFormSchema.safeParse(values);
  484. if (!parsed.success) {
  485. const issue = parsed.error.issues[0];
  486. messageApi.error(
  487. t(issue?.message ?? 'somethingWentWrong', {
  488. defaultValue: issue?.message ?? 'invalid',
  489. }),
  490. );
  491. return;
  492. }
  493. setSaving(true);
  494. try {
  495. const payload = formValuesToWirePayload(parsed.data);
  496. const url = mode === 'edit' && dbInbound
  497. ? `/panel/api/inbounds/update/${dbInbound.id}`
  498. : '/panel/api/inbounds/add';
  499. const msg = await HttpUtil.post(url, payload);
  500. if (msg?.success) {
  501. if (isFallbackHost) {
  502. const obj = msg.obj as { id?: number; Id?: number } | null;
  503. const masterId = mode === 'edit'
  504. ? dbInbound!.id
  505. : (obj?.id ?? obj?.Id ?? 0);
  506. if (masterId) await saveFallbacks(masterId);
  507. }
  508. onSaved();
  509. onClose();
  510. }
  511. } finally {
  512. setSaving(false);
  513. }
  514. };
  515. const title = mode === 'edit'
  516. ? t('pages.inbounds.modifyInbound')
  517. : t('pages.inbounds.addInbound');
  518. const okText = mode === 'edit'
  519. ? t('pages.clients.submitEdit')
  520. : t('create');
  521. const basicTab = (
  522. <>
  523. <Form.Item name="enable" label={t('enable')} valuePropName="checked">
  524. <Switch />
  525. </Form.Item>
  526. <Form.Item name="remark" label={t('pages.inbounds.remark')}>
  527. <Input />
  528. </Form.Item>
  529. {selectableNodes.length > 0 && isNodeEligible && (
  530. <Form.Item name="nodeId" label={t('pages.inbounds.deployTo')}>
  531. <Select
  532. disabled={mode === 'edit'}
  533. placeholder={t('pages.inbounds.localPanel')}
  534. allowClear
  535. >
  536. <Select.Option value={null}>{t('pages.inbounds.localPanel')}</Select.Option>
  537. {selectableNodes.map((n) => (
  538. <Select.Option
  539. key={n.id}
  540. value={n.id}
  541. disabled={n.status === 'offline'}
  542. >
  543. {n.name}{n.status === 'offline' ? ' (offline)' : ''}
  544. </Select.Option>
  545. ))}
  546. </Select>
  547. </Form.Item>
  548. )}
  549. <Form.Item name="protocol" label={t('pages.inbounds.protocol')}>
  550. <Select disabled={mode === 'edit'} options={PROTOCOL_OPTIONS} />
  551. </Form.Item>
  552. <Form.Item name="listen" label={t('pages.inbounds.address')}>
  553. <Input placeholder={t('pages.inbounds.monitorDesc')} />
  554. </Form.Item>
  555. <Form.Item
  556. name="port"
  557. label={t('pages.inbounds.port')}
  558. rules={[antdRule(InboundFormBaseSchema.shape.port, t)]}
  559. >
  560. <InputNumber min={1} max={65535} />
  561. </Form.Item>
  562. <Form.Item
  563. label={
  564. <Tooltip title={t('pages.inbounds.meansNoLimit')}>
  565. {t('pages.inbounds.totalFlow')}
  566. </Tooltip>
  567. }
  568. >
  569. <Form.Item
  570. noStyle
  571. shouldUpdate={(prev, curr) => prev.total !== curr.total}
  572. >
  573. {({ getFieldValue, setFieldValue }) => {
  574. const totalBytes = (getFieldValue('total') as number) ?? 0;
  575. const totalGB = totalBytes
  576. ? Math.round((totalBytes / SizeFormatter.ONE_GB) * 100) / 100
  577. : 0;
  578. return (
  579. <InputNumber
  580. value={totalGB}
  581. min={0}
  582. step={1}
  583. onChange={(v) => {
  584. const bytes = NumberFormatter.toFixed(
  585. (Number(v) || 0) * SizeFormatter.ONE_GB,
  586. 0,
  587. );
  588. setFieldValue('total', bytes);
  589. }}
  590. />
  591. );
  592. }}
  593. </Form.Item>
  594. </Form.Item>
  595. <Form.Item name="trafficReset" label={t('pages.inbounds.periodicTrafficResetTitle')}>
  596. <Select>
  597. {TRAFFIC_RESETS.map((r) => (
  598. <Select.Option key={r} value={r}>
  599. {t(`pages.inbounds.periodicTrafficReset.${r}`)}
  600. </Select.Option>
  601. ))}
  602. </Select>
  603. </Form.Item>
  604. <Form.Item
  605. label={
  606. <Tooltip title={t('pages.inbounds.leaveBlankToNeverExpire')}>
  607. {t('pages.inbounds.expireDate')}
  608. </Tooltip>
  609. }
  610. >
  611. <Form.Item
  612. noStyle
  613. shouldUpdate={(prev, curr) => prev.expiryTime !== curr.expiryTime}
  614. >
  615. {({ getFieldValue, setFieldValue }) => {
  616. const expiry = (getFieldValue('expiryTime') as number) ?? 0;
  617. return (
  618. <DateTimePicker
  619. value={expiry > 0 ? dayjs(expiry) : null}
  620. onChange={(d) => setFieldValue('expiryTime', d ? d.valueOf() : 0)}
  621. />
  622. );
  623. }}
  624. </Form.Item>
  625. </Form.Item>
  626. </>
  627. );
  628. const fallbacksCard = (
  629. <Card size="small" className="mt-12" title={t('pages.inbounds.fallbacks.title') || 'Fallbacks'}>
  630. {fallbacks.length === 0 && (
  631. <Empty
  632. description={t('pages.inbounds.fallbacks.empty') || 'No fallbacks yet'}
  633. styles={{ image: { height: 40 } }}
  634. style={{ margin: '8px 0 12px' }}
  635. />
  636. )}
  637. {fallbacks.map((record, idx) => (
  638. <div
  639. key={record.rowKey}
  640. style={{ border: '1px solid var(--app-border-tertiary)', borderRadius: 6, padding: '10px 12px', marginBottom: 8 }}
  641. >
  642. <Space.Compact block style={{ marginBottom: 6 }}>
  643. <Select
  644. value={record.childId}
  645. options={fallbackChildOptions}
  646. showSearch
  647. placeholder={t('pages.inbounds.fallbacks.pickInbound') || 'Pick an inbound'}
  648. filterOption={(input, option) =>
  649. ((option?.label as string) || '').toLowerCase().includes(input.toLowerCase())
  650. }
  651. style={{ width: '100%' }}
  652. onChange={(v) => updateFallback(record.rowKey, { childId: v })}
  653. />
  654. <Button
  655. disabled={idx === 0}
  656. onClick={() => moveFallback(idx, -1)}
  657. title="Move up"
  658. >
  659. <ArrowUpOutlined />
  660. </Button>
  661. <Button
  662. disabled={idx === fallbacks.length - 1}
  663. onClick={() => moveFallback(idx, 1)}
  664. title="Move down"
  665. >
  666. <ArrowDownOutlined />
  667. </Button>
  668. <Button danger onClick={() => removeFallback(idx)}>
  669. <DeleteOutlined />
  670. </Button>
  671. </Space.Compact>
  672. <Space.Compact block>
  673. <InputAddon>SNI</InputAddon>
  674. <Input
  675. placeholder={t('pages.inbounds.fallbacks.matchAny') || 'any'}
  676. value={record.name}
  677. onChange={(e) => updateFallback(record.rowKey, { name: e.target.value })}
  678. />
  679. <InputAddon>ALPN</InputAddon>
  680. <Input
  681. placeholder={t('pages.inbounds.fallbacks.matchAny') || 'any'}
  682. value={record.alpn}
  683. onChange={(e) => updateFallback(record.rowKey, { alpn: e.target.value })}
  684. />
  685. <InputAddon>Path</InputAddon>
  686. <Input
  687. placeholder="/"
  688. value={record.path}
  689. onChange={(e) => updateFallback(record.rowKey, { path: e.target.value })}
  690. />
  691. <InputAddon>xver</InputAddon>
  692. <InputNumber
  693. min={0}
  694. max={2}
  695. value={record.xver}
  696. onChange={(v) => updateFallback(record.rowKey, { xver: Number(v) || 0 })}
  697. />
  698. </Space.Compact>
  699. </div>
  700. ))}
  701. <Space>
  702. <Button size="small" onClick={addFallback}>
  703. <PlusOutlined /> {t('pages.inbounds.fallbacks.add') || 'Add fallback'}
  704. </Button>
  705. <Button
  706. size="small"
  707. onClick={addAllFallbacks}
  708. disabled={fallbackChildOptions.length === 0
  709. || fallbacks.length >= fallbackChildOptions.length}
  710. title="Add a fallback row for every eligible inbound not yet wired up"
  711. >
  712. Add all
  713. </Button>
  714. </Space>
  715. </Card>
  716. );
  717. const protocolTab = (
  718. <>
  719. {protocol === Protocols.WIREGUARD && (
  720. <>
  721. <Form.Item
  722. name={['settings', 'secretKey']}
  723. label={
  724. <>
  725. Secret key{' '}
  726. <SyncOutlined className="random-icon" onClick={regenInboundWg} />
  727. </>
  728. }
  729. >
  730. <Input />
  731. </Form.Item>
  732. <Form.Item label="Public key">
  733. <Input value={wgPubKey} disabled />
  734. </Form.Item>
  735. <Form.Item name={['settings', 'mtu']} label="MTU">
  736. <InputNumber />
  737. </Form.Item>
  738. <Form.Item
  739. name={['settings', 'noKernelTun']}
  740. label="No-kernel TUN"
  741. valuePropName="checked"
  742. >
  743. <Switch />
  744. </Form.Item>
  745. <Form.List name={['settings', 'peers']}>
  746. {(fields, { add, remove }) => (
  747. <>
  748. <Form.Item label="Peers">
  749. <Button
  750. size="small"
  751. onClick={() => add({
  752. publicKey: '',
  753. allowedIPs: [],
  754. })}
  755. >
  756. <PlusOutlined /> Add peer
  757. </Button>
  758. </Form.Item>
  759. {fields.map((field, idx) => (
  760. <div key={field.key} className="wg-peer">
  761. <Form.Item label={`Peer ${idx + 1}`}>
  762. {fields.length > 1 && (
  763. <Button
  764. size="small"
  765. danger
  766. onClick={() => remove(field.name)}
  767. >
  768. <MinusOutlined />
  769. </Button>
  770. )}
  771. </Form.Item>
  772. <Form.Item
  773. name={[field.name, 'privateKey']}
  774. label={
  775. <>
  776. Secret key{' '}
  777. <SyncOutlined
  778. className="random-icon"
  779. onClick={() => regenWgPeerKeypair(field.name)}
  780. />
  781. </>
  782. }
  783. >
  784. <Input />
  785. </Form.Item>
  786. <Form.Item name={[field.name, 'publicKey']} label="Public key">
  787. <Input />
  788. </Form.Item>
  789. <Form.Item name={[field.name, 'preSharedKey']} label="PSK">
  790. <Input />
  791. </Form.Item>
  792. <Form.List name={[field.name, 'allowedIPs']}>
  793. {(ipFields, { add: addIp, remove: removeIp }) => (
  794. <Form.Item label="Allowed IPs">
  795. <Button size="small" onClick={() => addIp('')}>
  796. <PlusOutlined />
  797. </Button>
  798. {ipFields.map((ipField) => (
  799. <Space.Compact key={ipField.key} block className="mt-4">
  800. <Form.Item name={ipField.name} noStyle>
  801. <Input />
  802. </Form.Item>
  803. {ipFields.length > 1 && (
  804. <Button size="small" onClick={() => removeIp(ipField.name)}>
  805. <MinusOutlined />
  806. </Button>
  807. )}
  808. </Space.Compact>
  809. ))}
  810. </Form.Item>
  811. )}
  812. </Form.List>
  813. <Form.Item name={[field.name, 'keepAlive']} label="Keep-alive">
  814. <InputNumber min={0} />
  815. </Form.Item>
  816. </div>
  817. ))}
  818. </>
  819. )}
  820. </Form.List>
  821. </>
  822. )}
  823. {protocol === Protocols.TUN && (
  824. <>
  825. <Form.Item name={['settings', 'name']} label="Interface name">
  826. <Input placeholder="xray0" />
  827. </Form.Item>
  828. <Form.Item name={['settings', 'mtu']} label="MTU">
  829. <InputNumber min={0} />
  830. </Form.Item>
  831. <Form.List name={['settings', 'gateway']}>
  832. {(fields, { add, remove }) => (
  833. <Form.Item label="Gateway">
  834. <Button size="small" onClick={() => add('')}>
  835. <PlusOutlined />
  836. </Button>
  837. {fields.map((field, j) => (
  838. <Space.Compact key={field.key} block className="mt-4">
  839. <Form.Item name={field.name} noStyle>
  840. <Input placeholder={j === 0 ? '10.0.0.1/16' : 'fc00::1/64'} />
  841. </Form.Item>
  842. <Button size="small" onClick={() => remove(field.name)}>
  843. <MinusOutlined />
  844. </Button>
  845. </Space.Compact>
  846. ))}
  847. </Form.Item>
  848. )}
  849. </Form.List>
  850. <Form.List name={['settings', 'dns']}>
  851. {(fields, { add, remove }) => (
  852. <Form.Item label="DNS">
  853. <Button size="small" onClick={() => add('')}>
  854. <PlusOutlined />
  855. </Button>
  856. {fields.map((field, j) => (
  857. <Space.Compact key={field.key} block className="mt-4">
  858. <Form.Item name={field.name} noStyle>
  859. <Input placeholder={j === 0 ? '1.1.1.1' : '8.8.8.8'} />
  860. </Form.Item>
  861. <Button size="small" onClick={() => remove(field.name)}>
  862. <MinusOutlined />
  863. </Button>
  864. </Space.Compact>
  865. ))}
  866. </Form.Item>
  867. )}
  868. </Form.List>
  869. <Form.Item name={['settings', 'userLevel']} label="User level">
  870. <InputNumber min={0} />
  871. </Form.Item>
  872. <Form.List name={['settings', 'autoSystemRoutingTable']}>
  873. {(fields, { add, remove }) => (
  874. <Form.Item
  875. label={
  876. <Tooltip title="Windows-only. CIDRs added to the system routing table automatically so matching traffic goes through TUN.">
  877. Auto system routes
  878. </Tooltip>
  879. }
  880. >
  881. <Button size="small" onClick={() => add('')}>
  882. <PlusOutlined />
  883. </Button>
  884. {fields.map((field, j) => (
  885. <Space.Compact key={field.key} block className="mt-4">
  886. <Form.Item name={field.name} noStyle>
  887. <Input placeholder={j === 0 ? '0.0.0.0/0' : '::/0'} />
  888. </Form.Item>
  889. <Button size="small" onClick={() => remove(field.name)}>
  890. <MinusOutlined />
  891. </Button>
  892. </Space.Compact>
  893. ))}
  894. </Form.Item>
  895. )}
  896. </Form.List>
  897. <Form.Item
  898. name={['settings', 'autoOutboundsInterface']}
  899. label={
  900. <Tooltip title="Physical interface for outbound traffic. Use 'auto' to detect; auto-enabled when Auto system routes is set.">
  901. Auto outbounds interface
  902. </Tooltip>
  903. }
  904. >
  905. <Input placeholder="auto" />
  906. </Form.Item>
  907. </>
  908. )}
  909. {protocol === Protocols.TUNNEL && (
  910. <>
  911. <Form.Item name={['settings', 'rewriteAddress']} label="Rewrite address">
  912. <Input />
  913. </Form.Item>
  914. <Form.Item name={['settings', 'rewritePort']} label="Rewrite port">
  915. <InputNumber min={0} max={65535} />
  916. </Form.Item>
  917. <Form.Item name={['settings', 'allowedNetwork']} label="Allowed network">
  918. <Select>
  919. <Select.Option value="tcp,udp">TCP, UDP</Select.Option>
  920. <Select.Option value="tcp">TCP</Select.Option>
  921. <Select.Option value="udp">UDP</Select.Option>
  922. </Select>
  923. </Form.Item>
  924. <Form.List name={['settings', 'portMap']}>
  925. {(fields, { add, remove }) => (
  926. <>
  927. <Form.Item label="Port map">
  928. <Button size="small" onClick={() => add({ name: '', value: '' })}>
  929. <PlusOutlined />
  930. </Button>
  931. </Form.Item>
  932. {fields.length > 0 && (
  933. <Form.Item wrapperCol={{ span: 24 }}>
  934. {fields.map((field, idx) => (
  935. <Space.Compact key={field.key} className="mb-8" block>
  936. <InputAddon>{String(idx + 1)}</InputAddon>
  937. <Form.Item name={[field.name, 'name']} noStyle>
  938. <Input placeholder="5555" />
  939. </Form.Item>
  940. <Form.Item name={[field.name, 'value']} noStyle>
  941. <Input placeholder="1.1.1.1:7777" />
  942. </Form.Item>
  943. <Button onClick={() => remove(field.name)}>
  944. <MinusOutlined />
  945. </Button>
  946. </Space.Compact>
  947. ))}
  948. </Form.Item>
  949. )}
  950. </>
  951. )}
  952. </Form.List>
  953. <Form.Item
  954. name={['settings', 'followRedirect']}
  955. label="Follow redirect"
  956. valuePropName="checked"
  957. >
  958. <Switch />
  959. </Form.Item>
  960. </>
  961. )}
  962. {(protocol === Protocols.HTTP || protocol === Protocols.MIXED) && (
  963. <>
  964. <Form.List name={['settings', 'accounts']}>
  965. {(fields, { add, remove }) => (
  966. <>
  967. <Form.Item label="Accounts">
  968. <Button size="small" onClick={() => add({ user: '', pass: '' })}>
  969. <PlusOutlined /> Add
  970. </Button>
  971. </Form.Item>
  972. {fields.length > 0 && (
  973. <Form.Item wrapperCol={{ span: 24 }}>
  974. {fields.map((field, idx) => (
  975. <Space.Compact key={field.key} className="mb-8" block>
  976. <InputAddon>{String(idx + 1)}</InputAddon>
  977. <Form.Item name={[field.name, 'user']} noStyle>
  978. <Input placeholder="Username" />
  979. </Form.Item>
  980. <Form.Item name={[field.name, 'pass']} noStyle>
  981. <Input placeholder="Password" />
  982. </Form.Item>
  983. <Button onClick={() => remove(field.name)}>
  984. <MinusOutlined />
  985. </Button>
  986. </Space.Compact>
  987. ))}
  988. </Form.Item>
  989. )}
  990. </>
  991. )}
  992. </Form.List>
  993. {protocol === Protocols.HTTP && (
  994. <Form.Item
  995. name={['settings', 'allowTransparent']}
  996. label="Allow transparent"
  997. valuePropName="checked"
  998. >
  999. <Switch />
  1000. </Form.Item>
  1001. )}
  1002. {protocol === Protocols.MIXED && (
  1003. <>
  1004. <Form.Item name={['settings', 'auth']} label="Auth">
  1005. <Select>
  1006. <Select.Option value="noauth">noauth</Select.Option>
  1007. <Select.Option value="password">password</Select.Option>
  1008. </Select>
  1009. </Form.Item>
  1010. <Form.Item
  1011. name={['settings', 'udp']}
  1012. label="UDP"
  1013. valuePropName="checked"
  1014. >
  1015. <Switch />
  1016. </Form.Item>
  1017. {mixedUdpOn && (
  1018. <Form.Item name={['settings', 'ip']} label="UDP IP">
  1019. <Input />
  1020. </Form.Item>
  1021. )}
  1022. </>
  1023. )}
  1024. </>
  1025. )}
  1026. {protocol === Protocols.SHADOWSOCKS && (
  1027. <>
  1028. <Form.Item name={['settings', 'method']} label="Encryption method">
  1029. <Select
  1030. onChange={(v) => {
  1031. form.setFieldValue(
  1032. ['settings', 'password'],
  1033. RandomUtil.randomShadowsocksPassword(v as string),
  1034. );
  1035. }}
  1036. >
  1037. {SSMethodSchema.options.map((m) => (
  1038. <Select.Option key={m} value={m}>{m}</Select.Option>
  1039. ))}
  1040. </Select>
  1041. </Form.Item>
  1042. {isSSWith2022 && (
  1043. <Form.Item
  1044. name={['settings', 'password']}
  1045. label={
  1046. <>
  1047. Password{' '}
  1048. <SyncOutlined
  1049. className="random-icon"
  1050. onClick={() => {
  1051. const method = form.getFieldValue(['settings', 'method']);
  1052. form.setFieldValue(
  1053. ['settings', 'password'],
  1054. RandomUtil.randomShadowsocksPassword(method as string),
  1055. );
  1056. }}
  1057. />
  1058. </>
  1059. }
  1060. >
  1061. <Input />
  1062. </Form.Item>
  1063. )}
  1064. <Form.Item name={['settings', 'network']} label="Network">
  1065. <Select style={{ width: 120 }}>
  1066. <Select.Option value="tcp,udp">TCP, UDP</Select.Option>
  1067. <Select.Option value="tcp">TCP</Select.Option>
  1068. <Select.Option value="udp">UDP</Select.Option>
  1069. </Select>
  1070. </Form.Item>
  1071. <Form.Item
  1072. name={['settings', 'ivCheck']}
  1073. label="ivCheck"
  1074. valuePropName="checked"
  1075. >
  1076. <Switch />
  1077. </Form.Item>
  1078. </>
  1079. )}
  1080. {protocol === Protocols.VLESS && (
  1081. <>
  1082. <Form.Item name={['settings', 'decryption']} label={t('pages.inbounds.decryption')}>
  1083. <Input />
  1084. </Form.Item>
  1085. <Form.Item name={['settings', 'encryption']} label={t('pages.inbounds.encryption')}>
  1086. <Input />
  1087. </Form.Item>
  1088. <Form.Item label=" ">
  1089. <Space size={8} wrap>
  1090. <Button type="primary" loading={saving} onClick={() => getNewVlessEnc('x25519')}>
  1091. {t('pages.inbounds.vlessAuthX25519')}
  1092. </Button>
  1093. <Button type="primary" loading={saving} onClick={() => getNewVlessEnc('mlkem768')}>
  1094. {t('pages.inbounds.vlessAuthMlkem768')}
  1095. </Button>
  1096. <Button danger onClick={clearVlessEnc}>{t('clear')}</Button>
  1097. </Space>
  1098. <Text type="secondary" className="vless-auth-state">
  1099. {t('pages.inbounds.vlessAuthSelected', { auth: selectedVlessAuth })}
  1100. </Text>
  1101. </Form.Item>
  1102. </>
  1103. )}
  1104. {isFallbackHost && fallbacksCard}
  1105. </>
  1106. );
  1107. // Switching `network` swaps which per-network key (tcpSettings, wsSettings,
  1108. // grpcSettings, ...) appears on the wire. We clear the previously selected
  1109. // network's settings blob and seed a default empty object for the new one
  1110. // so AntD's Form.Items aren't pointed at undefined nested paths.
  1111. const onNetworkChange = (next: string) => {
  1112. const ALL = ['tcpSettings', 'kcpSettings', 'wsSettings', 'grpcSettings', 'httpupgradeSettings', 'xhttpSettings'];
  1113. const current = (form.getFieldValue('streamSettings') as Record<string, unknown>) ?? {};
  1114. const cleaned: Record<string, unknown> = { ...current, network: next };
  1115. for (const k of ALL) {
  1116. if (k !== `${next}Settings`) delete cleaned[k];
  1117. }
  1118. cleaned[`${next}Settings`] = {};
  1119. form.setFieldValue('streamSettings', cleaned);
  1120. };
  1121. const streamTab = (
  1122. <>
  1123. {protocol !== Protocols.HYSTERIA && (
  1124. <Form.Item label="Transmission">
  1125. <Select
  1126. value={network}
  1127. style={{ width: '75%' }}
  1128. onChange={onNetworkChange}
  1129. >
  1130. <Select.Option value="tcp">TCP (RAW)</Select.Option>
  1131. <Select.Option value="kcp">mKCP</Select.Option>
  1132. <Select.Option value="ws">WebSocket</Select.Option>
  1133. <Select.Option value="grpc">gRPC</Select.Option>
  1134. <Select.Option value="httpupgrade">HTTPUpgrade</Select.Option>
  1135. <Select.Option value="xhttp">XHTTP</Select.Option>
  1136. </Select>
  1137. </Form.Item>
  1138. )}
  1139. {network === 'tcp' && (
  1140. <>
  1141. <Form.Item
  1142. name={['streamSettings', 'tcpSettings', 'acceptProxyProtocol']}
  1143. label="Proxy Protocol"
  1144. valuePropName="checked"
  1145. >
  1146. <Switch />
  1147. </Form.Item>
  1148. <Form.Item label={`HTTP ${t('camouflage')}`}>
  1149. <Form.Item
  1150. noStyle
  1151. shouldUpdate={(prev, curr) =>
  1152. prev.streamSettings?.tcpSettings?.header?.type
  1153. !== curr.streamSettings?.tcpSettings?.header?.type
  1154. }
  1155. >
  1156. {({ getFieldValue, setFieldValue }) => {
  1157. const headerType = getFieldValue(
  1158. ['streamSettings', 'tcpSettings', 'header', 'type'],
  1159. ) as string | undefined;
  1160. return (
  1161. <Switch
  1162. checked={headerType === 'http'}
  1163. onChange={(v) => {
  1164. setFieldValue(
  1165. ['streamSettings', 'tcpSettings', 'header'],
  1166. v
  1167. ? {
  1168. type: 'http',
  1169. request: {
  1170. version: '1.1',
  1171. method: 'GET',
  1172. path: ['/'],
  1173. headers: {},
  1174. },
  1175. }
  1176. : { type: 'none' },
  1177. );
  1178. }}
  1179. />
  1180. );
  1181. }}
  1182. </Form.Item>
  1183. </Form.Item>
  1184. {/* Host + path camouflage inputs only render when the Switch
  1185. above is on. Both are string[] on the wire; normalize +
  1186. getValueProps translate to/from comma-joined input. Mirrors
  1187. the symmetric outbound side. */}
  1188. <Form.Item
  1189. noStyle
  1190. shouldUpdate={(prev, curr) =>
  1191. prev.streamSettings?.tcpSettings?.header?.type
  1192. !== curr.streamSettings?.tcpSettings?.header?.type
  1193. }
  1194. >
  1195. {({ getFieldValue }) => {
  1196. const headerType = getFieldValue(
  1197. ['streamSettings', 'tcpSettings', 'header', 'type'],
  1198. ) as string | undefined;
  1199. if (headerType !== 'http') return null;
  1200. return (
  1201. <>
  1202. <Form.Item
  1203. label={t('host')}
  1204. name={[
  1205. 'streamSettings', 'tcpSettings', 'header',
  1206. 'request', 'headers', 'Host',
  1207. ]}
  1208. normalize={(v: unknown) =>
  1209. typeof v === 'string'
  1210. ? v.split(',').map((s) => s.trim()).filter(Boolean)
  1211. : Array.isArray(v) ? v : []
  1212. }
  1213. getValueProps={(v: unknown) => ({
  1214. value: Array.isArray(v) ? v.join(',') : '',
  1215. })}
  1216. >
  1217. <Input placeholder="example.com,cdn.example.com" />
  1218. </Form.Item>
  1219. <Form.Item
  1220. label={t('path')}
  1221. name={[
  1222. 'streamSettings', 'tcpSettings', 'header',
  1223. 'request', 'path',
  1224. ]}
  1225. normalize={(v: unknown) =>
  1226. typeof v === 'string'
  1227. ? v.split(',').map((s) => s.trim()).filter(Boolean)
  1228. : Array.isArray(v) ? v : ['/']
  1229. }
  1230. getValueProps={(v: unknown) => ({
  1231. value: Array.isArray(v) ? v.join(',') : '/',
  1232. })}
  1233. >
  1234. <Input placeholder="/,/api,/static" />
  1235. </Form.Item>
  1236. </>
  1237. );
  1238. }}
  1239. </Form.Item>
  1240. </>
  1241. )}
  1242. {network === 'ws' && (
  1243. <>
  1244. <Form.Item
  1245. name={['streamSettings', 'wsSettings', 'acceptProxyProtocol']}
  1246. label="Proxy Protocol"
  1247. valuePropName="checked"
  1248. >
  1249. <Switch />
  1250. </Form.Item>
  1251. <Form.Item name={['streamSettings', 'wsSettings', 'host']} label={t('host')}>
  1252. <Input />
  1253. </Form.Item>
  1254. <Form.Item name={['streamSettings', 'wsSettings', 'path']} label={t('path')}>
  1255. <Input />
  1256. </Form.Item>
  1257. <Form.Item
  1258. name={['streamSettings', 'wsSettings', 'heartbeatPeriod']}
  1259. label="Heartbeat Period"
  1260. >
  1261. <InputNumber min={0} />
  1262. </Form.Item>
  1263. <Form.Item
  1264. label="Headers"
  1265. name={['streamSettings', 'wsSettings', 'headers']}
  1266. >
  1267. <HeaderMapEditor mode="v1" />
  1268. </Form.Item>
  1269. </>
  1270. )}
  1271. {network === 'grpc' && (
  1272. <>
  1273. <Form.Item
  1274. name={['streamSettings', 'grpcSettings', 'serviceName']}
  1275. label="Service Name"
  1276. >
  1277. <Input />
  1278. </Form.Item>
  1279. <Form.Item
  1280. name={['streamSettings', 'grpcSettings', 'authority']}
  1281. label="Authority"
  1282. >
  1283. <Input />
  1284. </Form.Item>
  1285. <Form.Item
  1286. name={['streamSettings', 'grpcSettings', 'multiMode']}
  1287. label="Multi Mode"
  1288. valuePropName="checked"
  1289. >
  1290. <Switch />
  1291. </Form.Item>
  1292. </>
  1293. )}
  1294. {network === 'xhttp' && (
  1295. <>
  1296. <Form.Item name={['streamSettings', 'xhttpSettings', 'host']} label={t('host')}>
  1297. <Input />
  1298. </Form.Item>
  1299. <Form.Item name={['streamSettings', 'xhttpSettings', 'path']} label={t('path')}>
  1300. <Input />
  1301. </Form.Item>
  1302. <Form.Item name={['streamSettings', 'xhttpSettings', 'mode']} label="Mode">
  1303. <Select style={{ width: '50%' }}>
  1304. {(['auto', 'packet-up', 'stream-up', 'stream-one'] as const).map((m) => (
  1305. <Select.Option key={m} value={m}>{m}</Select.Option>
  1306. ))}
  1307. </Select>
  1308. </Form.Item>
  1309. {xhttpMode === 'packet-up' && (
  1310. <>
  1311. <Form.Item
  1312. name={['streamSettings', 'xhttpSettings', 'scMaxBufferedPosts']}
  1313. label="Max Buffered Upload"
  1314. >
  1315. <InputNumber />
  1316. </Form.Item>
  1317. <Form.Item
  1318. name={['streamSettings', 'xhttpSettings', 'scMaxEachPostBytes']}
  1319. label="Max Upload Size (Byte)"
  1320. >
  1321. <Input />
  1322. </Form.Item>
  1323. </>
  1324. )}
  1325. {xhttpMode === 'stream-up' && (
  1326. <Form.Item
  1327. name={['streamSettings', 'xhttpSettings', 'scStreamUpServerSecs']}
  1328. label="Stream-Up Server"
  1329. >
  1330. <Input />
  1331. </Form.Item>
  1332. )}
  1333. <Form.Item
  1334. name={['streamSettings', 'xhttpSettings', 'serverMaxHeaderBytes']}
  1335. label="Server Max Header Bytes"
  1336. >
  1337. <InputNumber min={0} placeholder="0 (default)" />
  1338. </Form.Item>
  1339. <Form.Item
  1340. name={['streamSettings', 'xhttpSettings', 'xPaddingBytes']}
  1341. label="Padding Bytes"
  1342. >
  1343. <Input />
  1344. </Form.Item>
  1345. <Form.Item
  1346. name={['streamSettings', 'xhttpSettings', 'uplinkHTTPMethod']}
  1347. label="Uplink HTTP Method"
  1348. >
  1349. <Select>
  1350. <Select.Option value="">Default (POST)</Select.Option>
  1351. <Select.Option value="POST">POST</Select.Option>
  1352. <Select.Option value="PUT">PUT</Select.Option>
  1353. <Select.Option value="GET" disabled={xhttpMode !== 'packet-up'}>
  1354. GET (packet-up only)
  1355. </Select.Option>
  1356. </Select>
  1357. </Form.Item>
  1358. <Form.Item
  1359. name={['streamSettings', 'xhttpSettings', 'xPaddingObfsMode']}
  1360. label="Padding Obfs Mode"
  1361. valuePropName="checked"
  1362. >
  1363. <Switch />
  1364. </Form.Item>
  1365. {xhttpObfsMode && (
  1366. <>
  1367. <Form.Item
  1368. name={['streamSettings', 'xhttpSettings', 'xPaddingKey']}
  1369. label="Padding Key"
  1370. >
  1371. <Input placeholder="x_padding" />
  1372. </Form.Item>
  1373. <Form.Item
  1374. name={['streamSettings', 'xhttpSettings', 'xPaddingHeader']}
  1375. label="Padding Header"
  1376. >
  1377. <Input placeholder="X-Padding" />
  1378. </Form.Item>
  1379. <Form.Item
  1380. name={['streamSettings', 'xhttpSettings', 'xPaddingPlacement']}
  1381. label="Padding Placement"
  1382. >
  1383. <Select>
  1384. <Select.Option value="">Default (queryInHeader)</Select.Option>
  1385. <Select.Option value="queryInHeader">queryInHeader</Select.Option>
  1386. <Select.Option value="header">header</Select.Option>
  1387. <Select.Option value="cookie">cookie</Select.Option>
  1388. <Select.Option value="query">query</Select.Option>
  1389. </Select>
  1390. </Form.Item>
  1391. <Form.Item
  1392. name={['streamSettings', 'xhttpSettings', 'xPaddingMethod']}
  1393. label="Padding Method"
  1394. >
  1395. <Select>
  1396. <Select.Option value="">Default (repeat-x)</Select.Option>
  1397. <Select.Option value="repeat-x">repeat-x</Select.Option>
  1398. <Select.Option value="tokenish">tokenish</Select.Option>
  1399. </Select>
  1400. </Form.Item>
  1401. </>
  1402. )}
  1403. <Form.Item
  1404. name={['streamSettings', 'xhttpSettings', 'sessionPlacement']}
  1405. label="Session Placement"
  1406. >
  1407. <Select>
  1408. <Select.Option value="">Default (path)</Select.Option>
  1409. <Select.Option value="path">path</Select.Option>
  1410. <Select.Option value="header">header</Select.Option>
  1411. <Select.Option value="cookie">cookie</Select.Option>
  1412. <Select.Option value="query">query</Select.Option>
  1413. </Select>
  1414. </Form.Item>
  1415. {xhttpSessionPlacement && xhttpSessionPlacement !== 'path' && (
  1416. <Form.Item
  1417. name={['streamSettings', 'xhttpSettings', 'sessionKey']}
  1418. label="Session Key"
  1419. >
  1420. <Input placeholder="x_session" />
  1421. </Form.Item>
  1422. )}
  1423. <Form.Item
  1424. name={['streamSettings', 'xhttpSettings', 'seqPlacement']}
  1425. label="Sequence Placement"
  1426. >
  1427. <Select>
  1428. <Select.Option value="">Default (path)</Select.Option>
  1429. <Select.Option value="path">path</Select.Option>
  1430. <Select.Option value="header">header</Select.Option>
  1431. <Select.Option value="cookie">cookie</Select.Option>
  1432. <Select.Option value="query">query</Select.Option>
  1433. </Select>
  1434. </Form.Item>
  1435. {xhttpSeqPlacement && xhttpSeqPlacement !== 'path' && (
  1436. <Form.Item
  1437. name={['streamSettings', 'xhttpSettings', 'seqKey']}
  1438. label="Sequence Key"
  1439. >
  1440. <Input placeholder="x_seq" />
  1441. </Form.Item>
  1442. )}
  1443. {xhttpMode === 'packet-up' && (
  1444. <>
  1445. <Form.Item
  1446. name={['streamSettings', 'xhttpSettings', 'uplinkDataPlacement']}
  1447. label="Uplink Data Placement"
  1448. >
  1449. <Select>
  1450. <Select.Option value="">Default (body)</Select.Option>
  1451. <Select.Option value="body">body</Select.Option>
  1452. <Select.Option value="header">header</Select.Option>
  1453. <Select.Option value="cookie">cookie</Select.Option>
  1454. <Select.Option value="query">query</Select.Option>
  1455. </Select>
  1456. </Form.Item>
  1457. {xhttpUplinkPlacement && xhttpUplinkPlacement !== 'body' && (
  1458. <Form.Item
  1459. name={['streamSettings', 'xhttpSettings', 'uplinkDataKey']}
  1460. label="Uplink Data Key"
  1461. >
  1462. <Input placeholder="x_data" />
  1463. </Form.Item>
  1464. )}
  1465. </>
  1466. )}
  1467. <Form.Item
  1468. name={['streamSettings', 'xhttpSettings', 'noSSEHeader']}
  1469. label="No SSE Header"
  1470. valuePropName="checked"
  1471. >
  1472. <Switch />
  1473. </Form.Item>
  1474. </>
  1475. )}
  1476. {network === 'httpupgrade' && (
  1477. <>
  1478. <Form.Item
  1479. name={['streamSettings', 'httpupgradeSettings', 'acceptProxyProtocol']}
  1480. label="Proxy Protocol"
  1481. valuePropName="checked"
  1482. >
  1483. <Switch />
  1484. </Form.Item>
  1485. <Form.Item
  1486. name={['streamSettings', 'httpupgradeSettings', 'host']}
  1487. label={t('host')}
  1488. >
  1489. <Input />
  1490. </Form.Item>
  1491. <Form.Item
  1492. name={['streamSettings', 'httpupgradeSettings', 'path']}
  1493. label={t('path')}
  1494. >
  1495. <Input />
  1496. </Form.Item>
  1497. <Form.Item
  1498. label="Headers"
  1499. name={['streamSettings', 'httpupgradeSettings', 'headers']}
  1500. >
  1501. <HeaderMapEditor mode="v1" />
  1502. </Form.Item>
  1503. </>
  1504. )}
  1505. {network === 'kcp' && (
  1506. <>
  1507. <Form.Item name={['streamSettings', 'kcpSettings', 'mtu']} label="MTU">
  1508. <InputNumber min={576} max={1460} />
  1509. </Form.Item>
  1510. <Form.Item name={['streamSettings', 'kcpSettings', 'tti']} label="TTI (ms)">
  1511. <InputNumber min={10} max={100} />
  1512. </Form.Item>
  1513. <Form.Item name={['streamSettings', 'kcpSettings', 'upCap']} label="Uplink (MB/s)">
  1514. <InputNumber min={0} />
  1515. </Form.Item>
  1516. <Form.Item name={['streamSettings', 'kcpSettings', 'downCap']} label="Downlink (MB/s)">
  1517. <InputNumber min={0} />
  1518. </Form.Item>
  1519. <Form.Item
  1520. name={['streamSettings', 'kcpSettings', 'cwndMultiplier']}
  1521. label="CWND Multiplier"
  1522. >
  1523. <InputNumber min={1} />
  1524. </Form.Item>
  1525. <Form.Item
  1526. name={['streamSettings', 'kcpSettings', 'maxSendingWindow']}
  1527. label="Max Sending Window"
  1528. >
  1529. <InputNumber min={0} />
  1530. </Form.Item>
  1531. </>
  1532. )}
  1533. <Form.Item label="External Proxy">
  1534. <Switch checked={externalProxyOn} onChange={toggleExternalProxy} />
  1535. </Form.Item>
  1536. {externalProxyOn && (
  1537. <Form.List name={['streamSettings', 'externalProxy']}>
  1538. {(fields, { add, remove }) => (
  1539. <>
  1540. <Form.Item label=" " colon={false}>
  1541. <Button
  1542. size="small"
  1543. type="primary"
  1544. onClick={() => add({
  1545. forceTls: 'same',
  1546. dest: '',
  1547. port: 443,
  1548. remark: '',
  1549. sni: '',
  1550. fingerprint: '',
  1551. alpn: [],
  1552. })}
  1553. >
  1554. <PlusOutlined />
  1555. </Button>
  1556. </Form.Item>
  1557. <Form.Item wrapperCol={{ span: 24 }}>
  1558. {fields.map((field) => (
  1559. <div key={field.key} style={{ margin: '8px 0' }}>
  1560. <Space.Compact block>
  1561. <Form.Item name={[field.name, 'forceTls']} noStyle>
  1562. <Select style={{ width: '20%' }}>
  1563. <Select.Option value="same">{t('pages.inbounds.same')}</Select.Option>
  1564. <Select.Option value="none">{t('none')}</Select.Option>
  1565. <Select.Option value="tls">TLS</Select.Option>
  1566. </Select>
  1567. </Form.Item>
  1568. <Form.Item name={[field.name, 'dest']} noStyle>
  1569. <Input style={{ width: '30%' }} placeholder={t('host')} />
  1570. </Form.Item>
  1571. <Form.Item name={[field.name, 'port']} noStyle>
  1572. <InputNumber style={{ width: '15%' }} min={1} max={65535} />
  1573. </Form.Item>
  1574. <Form.Item name={[field.name, 'remark']} noStyle>
  1575. <Input style={{ width: '25%' }} placeholder={t('pages.inbounds.remark')} />
  1576. </Form.Item>
  1577. <InputAddon onClick={() => remove(field.name)}>
  1578. <MinusOutlined />
  1579. </InputAddon>
  1580. </Space.Compact>
  1581. <Form.Item
  1582. noStyle
  1583. shouldUpdate={(prev, curr) =>
  1584. prev.streamSettings?.externalProxy?.[field.name]?.forceTls
  1585. !== curr.streamSettings?.externalProxy?.[field.name]?.forceTls
  1586. }
  1587. >
  1588. {({ getFieldValue }) => {
  1589. const ft = getFieldValue([
  1590. 'streamSettings', 'externalProxy', field.name, 'forceTls',
  1591. ]);
  1592. if (ft !== 'tls') return null;
  1593. return (
  1594. <Space.Compact style={{ marginTop: 6 }} block>
  1595. <Form.Item name={[field.name, 'sni']} noStyle>
  1596. <Input style={{ width: '30%' }} placeholder="SNI (defaults to host)" />
  1597. </Form.Item>
  1598. <Form.Item name={[field.name, 'fingerprint']} noStyle>
  1599. <Select style={{ width: '30%' }} placeholder="Fingerprint">
  1600. <Select.Option value="">Default</Select.Option>
  1601. {Object.values(UTLS_FINGERPRINT).map((fp) => (
  1602. <Select.Option key={fp} value={fp}>{fp}</Select.Option>
  1603. ))}
  1604. </Select>
  1605. </Form.Item>
  1606. <Form.Item name={[field.name, 'alpn']} noStyle>
  1607. <Select mode="multiple" style={{ width: '40%' }} placeholder="ALPN">
  1608. {Object.values(ALPN_OPTION).map((a) => (
  1609. <Select.Option key={a} value={a}>{a}</Select.Option>
  1610. ))}
  1611. </Select>
  1612. </Form.Item>
  1613. </Space.Compact>
  1614. );
  1615. }}
  1616. </Form.Item>
  1617. </div>
  1618. ))}
  1619. </Form.Item>
  1620. </>
  1621. )}
  1622. </Form.List>
  1623. )}
  1624. <Form.Item label="Sockopt">
  1625. <Switch checked={sockoptOn} onChange={toggleSockopt} />
  1626. </Form.Item>
  1627. {sockoptOn && (
  1628. <>
  1629. <Form.Item name={['streamSettings', 'sockopt', 'mark']} label="Route Mark">
  1630. <InputNumber min={0} />
  1631. </Form.Item>
  1632. <Form.Item
  1633. name={['streamSettings', 'sockopt', 'tcpKeepAliveInterval']}
  1634. label="TCP Keep Alive Interval"
  1635. >
  1636. <InputNumber min={0} />
  1637. </Form.Item>
  1638. <Form.Item
  1639. name={['streamSettings', 'sockopt', 'tcpKeepAliveIdle']}
  1640. label="TCP Keep Alive Idle"
  1641. >
  1642. <InputNumber min={0} />
  1643. </Form.Item>
  1644. <Form.Item name={['streamSettings', 'sockopt', 'tcpMaxSeg']} label="TCP Max Seg">
  1645. <InputNumber min={0} />
  1646. </Form.Item>
  1647. <Form.Item
  1648. name={['streamSettings', 'sockopt', 'tcpUserTimeout']}
  1649. label="TCP User Timeout"
  1650. >
  1651. <InputNumber min={0} />
  1652. </Form.Item>
  1653. <Form.Item
  1654. name={['streamSettings', 'sockopt', 'tcpWindowClamp']}
  1655. label="TCP Window Clamp"
  1656. >
  1657. <InputNumber min={0} />
  1658. </Form.Item>
  1659. <Form.Item
  1660. name={['streamSettings', 'sockopt', 'acceptProxyProtocol']}
  1661. label="Proxy Protocol"
  1662. valuePropName="checked"
  1663. >
  1664. <Switch />
  1665. </Form.Item>
  1666. <Form.Item
  1667. name={['streamSettings', 'sockopt', 'tcpFastOpen']}
  1668. label="TCP Fast Open"
  1669. valuePropName="checked"
  1670. >
  1671. <Switch />
  1672. </Form.Item>
  1673. <Form.Item
  1674. name={['streamSettings', 'sockopt', 'tcpMptcp']}
  1675. label="Multipath TCP"
  1676. valuePropName="checked"
  1677. >
  1678. <Switch />
  1679. </Form.Item>
  1680. <Form.Item
  1681. name={['streamSettings', 'sockopt', 'penetrate']}
  1682. label="Penetrate"
  1683. valuePropName="checked"
  1684. >
  1685. <Switch />
  1686. </Form.Item>
  1687. <Form.Item
  1688. name={['streamSettings', 'sockopt', 'V6Only']}
  1689. label="V6 Only"
  1690. valuePropName="checked"
  1691. >
  1692. <Switch />
  1693. </Form.Item>
  1694. <Form.Item
  1695. name={['streamSettings', 'sockopt', 'domainStrategy']}
  1696. label="Domain Strategy"
  1697. >
  1698. <Select style={{ width: '50%' }}>
  1699. {Object.values(DOMAIN_STRATEGY_OPTION).map((d) => (
  1700. <Select.Option key={d} value={d}>{d}</Select.Option>
  1701. ))}
  1702. </Select>
  1703. </Form.Item>
  1704. <Form.Item
  1705. name={['streamSettings', 'sockopt', 'tcpcongestion']}
  1706. label="TCP Congestion"
  1707. >
  1708. <Select style={{ width: '50%' }}>
  1709. {Object.values(TCP_CONGESTION_OPTION).map((c) => (
  1710. <Select.Option key={c} value={c}>{c}</Select.Option>
  1711. ))}
  1712. </Select>
  1713. </Form.Item>
  1714. <Form.Item name={['streamSettings', 'sockopt', 'tproxy']} label="TProxy">
  1715. <Select style={{ width: '50%' }}>
  1716. <Select.Option value="off">Off</Select.Option>
  1717. <Select.Option value="redirect">Redirect</Select.Option>
  1718. <Select.Option value="tproxy">TProxy</Select.Option>
  1719. </Select>
  1720. </Form.Item>
  1721. <Form.Item name={['streamSettings', 'sockopt', 'dialerProxy']} label="Dialer Proxy">
  1722. <Input />
  1723. </Form.Item>
  1724. <Form.Item
  1725. name={['streamSettings', 'sockopt', 'interfaceName']}
  1726. label="Interface Name"
  1727. >
  1728. <Input />
  1729. </Form.Item>
  1730. <Form.Item
  1731. name={['streamSettings', 'sockopt', 'trustedXForwardedFor']}
  1732. label="Trusted X-Forwarded-For"
  1733. >
  1734. <Select mode="tags" style={{ width: '100%' }} tokenSeparators={[',']}>
  1735. <Select.Option value="CF-Connecting-IP">CF-Connecting-IP</Select.Option>
  1736. <Select.Option value="X-Real-IP">X-Real-IP</Select.Option>
  1737. <Select.Option value="True-Client-IP">True-Client-IP</Select.Option>
  1738. <Select.Option value="X-Client-IP">X-Client-IP</Select.Option>
  1739. </Select>
  1740. </Form.Item>
  1741. </>
  1742. )}
  1743. </>
  1744. );
  1745. const securityTab = (
  1746. <>
  1747. <Form.Item label={t('pages.inbounds.securityTab')}>
  1748. <Form.Item
  1749. noStyle
  1750. shouldUpdate={(prev, curr) =>
  1751. prev.streamSettings?.security !== curr.streamSettings?.security
  1752. }
  1753. >
  1754. {({ getFieldValue }) => {
  1755. const sec = getFieldValue(['streamSettings', 'security']) ?? 'none';
  1756. return (
  1757. <Select
  1758. value={sec}
  1759. disabled={!tlsAllowed}
  1760. onChange={onSecurityChange}
  1761. style={{ width: 180 }}
  1762. >
  1763. <Select.Option value="none">none</Select.Option>
  1764. <Select.Option value="tls">tls</Select.Option>
  1765. {realityAllowed && <Select.Option value="reality">reality</Select.Option>}
  1766. </Select>
  1767. );
  1768. }}
  1769. </Form.Item>
  1770. </Form.Item>
  1771. {security === 'tls' && (
  1772. <>
  1773. <Form.Item name={['streamSettings', 'tlsSettings', 'serverName']} label="SNI">
  1774. <Input placeholder="Server Name Indication" />
  1775. </Form.Item>
  1776. <Form.Item name={['streamSettings', 'tlsSettings', 'cipherSuites']} label="Cipher Suites">
  1777. <Select>
  1778. <Select.Option value="">Auto</Select.Option>
  1779. {Object.entries(TLS_CIPHER_OPTION).map(([k, v]) => (
  1780. <Select.Option key={v} value={v}>{k}</Select.Option>
  1781. ))}
  1782. </Select>
  1783. </Form.Item>
  1784. <Form.Item label="Min/Max Version">
  1785. <Space.Compact block>
  1786. <Form.Item name={['streamSettings', 'tlsSettings', 'minVersion']} noStyle>
  1787. <Select style={{ width: '50%' }}>
  1788. {Object.values(TLS_VERSION_OPTION).map((v) => (
  1789. <Select.Option key={v} value={v}>{v}</Select.Option>
  1790. ))}
  1791. </Select>
  1792. </Form.Item>
  1793. <Form.Item name={['streamSettings', 'tlsSettings', 'maxVersion']} noStyle>
  1794. <Select style={{ width: '50%' }}>
  1795. {Object.values(TLS_VERSION_OPTION).map((v) => (
  1796. <Select.Option key={v} value={v}>{v}</Select.Option>
  1797. ))}
  1798. </Select>
  1799. </Form.Item>
  1800. </Space.Compact>
  1801. </Form.Item>
  1802. <Form.Item
  1803. name={['streamSettings', 'tlsSettings', 'settings', 'fingerprint']}
  1804. label="uTLS"
  1805. >
  1806. <Select>
  1807. <Select.Option value="">None</Select.Option>
  1808. {Object.values(UTLS_FINGERPRINT).map((fp) => (
  1809. <Select.Option key={fp} value={fp}>{fp}</Select.Option>
  1810. ))}
  1811. </Select>
  1812. </Form.Item>
  1813. <Form.Item name={['streamSettings', 'tlsSettings', 'alpn']} label="ALPN">
  1814. <Select mode="multiple" tokenSeparators={[',']} style={{ width: '100%' }}>
  1815. {Object.values(ALPN_OPTION).map((a) => (
  1816. <Select.Option key={a} value={a}>{a}</Select.Option>
  1817. ))}
  1818. </Select>
  1819. </Form.Item>
  1820. <Form.Item
  1821. name={['streamSettings', 'tlsSettings', 'rejectUnknownSni']}
  1822. label="Reject Unknown SNI"
  1823. valuePropName="checked"
  1824. >
  1825. <Switch />
  1826. </Form.Item>
  1827. <Form.Item
  1828. name={['streamSettings', 'tlsSettings', 'disableSystemRoot']}
  1829. label="Disable System Root"
  1830. valuePropName="checked"
  1831. >
  1832. <Switch />
  1833. </Form.Item>
  1834. <Form.Item
  1835. name={['streamSettings', 'tlsSettings', 'enableSessionResumption']}
  1836. label="Session Resumption"
  1837. valuePropName="checked"
  1838. >
  1839. <Switch />
  1840. </Form.Item>
  1841. <Form.List name={['streamSettings', 'tlsSettings', 'certificates']}>
  1842. {(certFields, { add, remove }) => (
  1843. <>
  1844. <Form.Item label={t('certificate')}>
  1845. <Button
  1846. type="primary"
  1847. size="small"
  1848. onClick={() => add({
  1849. useFile: true,
  1850. certificateFile: '',
  1851. keyFile: '',
  1852. certificate: [],
  1853. key: [],
  1854. oneTimeLoading: false,
  1855. usage: 'encipherment',
  1856. buildChain: false,
  1857. })}
  1858. >
  1859. <PlusOutlined />
  1860. </Button>
  1861. </Form.Item>
  1862. {certFields.map((certField, idx) => (
  1863. <div key={certField.key}>
  1864. <Form.Item
  1865. name={[certField.name, 'useFile']}
  1866. label={`${t('certificate')} ${idx + 1}`}
  1867. >
  1868. <Radio.Group buttonStyle="solid">
  1869. <Radio.Button value={true}>
  1870. {t('pages.inbounds.certificatePath')}
  1871. </Radio.Button>
  1872. <Radio.Button value={false}>
  1873. {t('pages.inbounds.certificateContent')}
  1874. </Radio.Button>
  1875. </Radio.Group>
  1876. </Form.Item>
  1877. {certFields.length > 1 && (
  1878. <Form.Item label=" ">
  1879. <Button
  1880. size="small"
  1881. danger
  1882. onClick={() => remove(certField.name)}
  1883. >
  1884. <MinusOutlined /> Remove
  1885. </Button>
  1886. </Form.Item>
  1887. )}
  1888. <Form.Item
  1889. noStyle
  1890. shouldUpdate={(prev, curr) =>
  1891. prev.streamSettings?.tlsSettings?.certificates?.[certField.name]?.useFile
  1892. !== curr.streamSettings?.tlsSettings?.certificates?.[certField.name]?.useFile
  1893. }
  1894. >
  1895. {({ getFieldValue }) => {
  1896. const useFile = getFieldValue([
  1897. 'streamSettings', 'tlsSettings', 'certificates',
  1898. certField.name, 'useFile',
  1899. ]);
  1900. return useFile ? (
  1901. <>
  1902. <Form.Item
  1903. name={[certField.name, 'certificateFile']}
  1904. label={t('pages.inbounds.publicKey')}
  1905. >
  1906. <Input />
  1907. </Form.Item>
  1908. <Form.Item
  1909. name={[certField.name, 'keyFile']}
  1910. label={t('pages.inbounds.privatekey')}
  1911. >
  1912. <Input />
  1913. </Form.Item>
  1914. </>
  1915. ) : (
  1916. <>
  1917. <Form.Item
  1918. name={[certField.name, 'certificate']}
  1919. label={t('pages.inbounds.publicKey')}
  1920. normalize={(v) => typeof v === 'string'
  1921. ? v.split('\n')
  1922. : v}
  1923. getValueProps={(v) => ({
  1924. value: Array.isArray(v) ? v.join('\n') : v,
  1925. })}
  1926. >
  1927. <TextArea autoSize={{ minRows: 3, maxRows: 8 }} />
  1928. </Form.Item>
  1929. <Form.Item
  1930. name={[certField.name, 'key']}
  1931. label={t('pages.inbounds.privatekey')}
  1932. normalize={(v) => typeof v === 'string'
  1933. ? v.split('\n')
  1934. : v}
  1935. getValueProps={(v) => ({
  1936. value: Array.isArray(v) ? v.join('\n') : v,
  1937. })}
  1938. >
  1939. <TextArea autoSize={{ minRows: 3, maxRows: 8 }} />
  1940. </Form.Item>
  1941. </>
  1942. );
  1943. }}
  1944. </Form.Item>
  1945. <Form.Item
  1946. name={[certField.name, 'oneTimeLoading']}
  1947. label="One Time Loading"
  1948. valuePropName="checked"
  1949. >
  1950. <Switch />
  1951. </Form.Item>
  1952. <Form.Item
  1953. name={[certField.name, 'usage']}
  1954. label="Usage Option"
  1955. >
  1956. <Select style={{ width: '50%' }}>
  1957. {Object.values(USAGE_OPTION).map((u) => (
  1958. <Select.Option key={u} value={u}>{u}</Select.Option>
  1959. ))}
  1960. </Select>
  1961. </Form.Item>
  1962. <Form.Item
  1963. noStyle
  1964. shouldUpdate={(prev, curr) =>
  1965. prev.streamSettings?.tlsSettings?.certificates?.[certField.name]?.usage
  1966. !== curr.streamSettings?.tlsSettings?.certificates?.[certField.name]?.usage
  1967. }
  1968. >
  1969. {({ getFieldValue }) => {
  1970. const usage = getFieldValue([
  1971. 'streamSettings', 'tlsSettings', 'certificates',
  1972. certField.name, 'usage',
  1973. ]);
  1974. if (usage !== 'issue') return null;
  1975. return (
  1976. <Form.Item
  1977. name={[certField.name, 'buildChain']}
  1978. label="Build Chain"
  1979. valuePropName="checked"
  1980. >
  1981. <Switch />
  1982. </Form.Item>
  1983. );
  1984. }}
  1985. </Form.Item>
  1986. </div>
  1987. ))}
  1988. </>
  1989. )}
  1990. </Form.List>
  1991. <Form.Item name={['streamSettings', 'tlsSettings', 'echServerKeys']} label="ECH key">
  1992. <Input />
  1993. </Form.Item>
  1994. <Form.Item
  1995. name={['streamSettings', 'tlsSettings', 'settings', 'echConfigList']}
  1996. label="ECH config"
  1997. >
  1998. <Input />
  1999. </Form.Item>
  2000. <Form.Item label=" ">
  2001. <Space>
  2002. <Button type="primary" loading={saving} onClick={getNewEchCert}>
  2003. Get New ECH Cert
  2004. </Button>
  2005. <Button danger onClick={clearEchCert}>Clear</Button>
  2006. </Space>
  2007. </Form.Item>
  2008. </>
  2009. )}
  2010. {security === 'reality' && (
  2011. <>
  2012. <Form.Item
  2013. name={['streamSettings', 'realitySettings', 'show']}
  2014. label="Show"
  2015. valuePropName="checked"
  2016. >
  2017. <Switch />
  2018. </Form.Item>
  2019. <Form.Item name={['streamSettings', 'realitySettings', 'xver']} label="Xver">
  2020. <InputNumber min={0} />
  2021. </Form.Item>
  2022. <Form.Item
  2023. name={['streamSettings', 'realitySettings', 'settings', 'fingerprint']}
  2024. label="uTLS"
  2025. >
  2026. <Select>
  2027. {Object.values(UTLS_FINGERPRINT).map((fp) => (
  2028. <Select.Option key={fp} value={fp}>{fp}</Select.Option>
  2029. ))}
  2030. </Select>
  2031. </Form.Item>
  2032. <Form.Item
  2033. name={['streamSettings', 'realitySettings', 'target']}
  2034. label={
  2035. <>
  2036. Target{' '}
  2037. <SyncOutlined className="random-icon" onClick={randomizeRealityTarget} />
  2038. </>
  2039. }
  2040. >
  2041. <Input />
  2042. </Form.Item>
  2043. <Form.Item
  2044. name={['streamSettings', 'realitySettings', 'serverNames']}
  2045. label={
  2046. <>
  2047. SNI{' '}
  2048. <SyncOutlined className="random-icon" onClick={randomizeRealityTarget} />
  2049. </>
  2050. }
  2051. >
  2052. <Select mode="tags" tokenSeparators={[',']} style={{ width: '100%' }} />
  2053. </Form.Item>
  2054. <Form.Item
  2055. name={['streamSettings', 'realitySettings', 'maxTimediff']}
  2056. label="Max Time Diff (ms)"
  2057. >
  2058. <InputNumber min={0} />
  2059. </Form.Item>
  2060. <Form.Item
  2061. name={['streamSettings', 'realitySettings', 'minClientVer']}
  2062. label="Min Client Ver"
  2063. >
  2064. <Input placeholder="25.9.11" />
  2065. </Form.Item>
  2066. <Form.Item
  2067. name={['streamSettings', 'realitySettings', 'maxClientVer']}
  2068. label="Max Client Ver"
  2069. >
  2070. <Input placeholder="25.9.11" />
  2071. </Form.Item>
  2072. <Form.Item
  2073. name={['streamSettings', 'realitySettings', 'shortIds']}
  2074. label={
  2075. <>
  2076. Short IDs{' '}
  2077. <SyncOutlined className="random-icon" onClick={randomizeShortIds} />
  2078. </>
  2079. }
  2080. >
  2081. <Select mode="tags" tokenSeparators={[',']} style={{ width: '100%' }} />
  2082. </Form.Item>
  2083. <Form.Item
  2084. name={['streamSettings', 'realitySettings', 'settings', 'spiderX']}
  2085. label="SpiderX"
  2086. >
  2087. <Input />
  2088. </Form.Item>
  2089. <Form.Item
  2090. name={['streamSettings', 'realitySettings', 'settings', 'publicKey']}
  2091. label={t('pages.inbounds.publicKey')}
  2092. >
  2093. <Input.TextArea autoSize={{ minRows: 1, maxRows: 4 }} />
  2094. </Form.Item>
  2095. <Form.Item
  2096. name={['streamSettings', 'realitySettings', 'privateKey']}
  2097. label={t('pages.inbounds.privatekey')}
  2098. >
  2099. <Input.TextArea autoSize={{ minRows: 1, maxRows: 4 }} />
  2100. </Form.Item>
  2101. <Form.Item label=" ">
  2102. <Space>
  2103. <Button type="primary" loading={saving} onClick={genRealityKeypair}>
  2104. Get New Cert
  2105. </Button>
  2106. <Button danger onClick={clearRealityKeypair}>Clear</Button>
  2107. </Space>
  2108. </Form.Item>
  2109. <Form.Item
  2110. name={['streamSettings', 'realitySettings', 'mldsa65Seed']}
  2111. label="mldsa65 Seed"
  2112. >
  2113. <Input.TextArea autoSize={{ minRows: 2, maxRows: 6 }} />
  2114. </Form.Item>
  2115. <Form.Item
  2116. name={['streamSettings', 'realitySettings', 'settings', 'mldsa65Verify']}
  2117. label="mldsa65 Verify"
  2118. >
  2119. <Input.TextArea autoSize={{ minRows: 2, maxRows: 6 }} />
  2120. </Form.Item>
  2121. <Form.Item label=" ">
  2122. <Space>
  2123. <Button type="primary" loading={saving} onClick={genMldsa65}>
  2124. Get New Seed
  2125. </Button>
  2126. <Button danger onClick={clearMldsa65}>Clear</Button>
  2127. </Space>
  2128. </Form.Item>
  2129. </>
  2130. )}
  2131. </>
  2132. );
  2133. const advancedTab = (
  2134. <Tabs
  2135. items={[
  2136. {
  2137. key: 'settings',
  2138. label: t('pages.inbounds.advanced.settings'),
  2139. children: (
  2140. <AdvancedSliceEditor
  2141. form={form}
  2142. path="settings"
  2143. minHeight="320px"
  2144. maxHeight="540px"
  2145. />
  2146. ),
  2147. },
  2148. ...(streamEnabled
  2149. ? [{
  2150. key: 'stream',
  2151. label: t('pages.inbounds.advanced.stream'),
  2152. children: (
  2153. <AdvancedSliceEditor
  2154. form={form}
  2155. path="streamSettings"
  2156. minHeight="320px"
  2157. maxHeight="540px"
  2158. />
  2159. ),
  2160. }]
  2161. : []),
  2162. {
  2163. key: 'sniffing',
  2164. label: t('pages.inbounds.advanced.sniffing'),
  2165. children: (
  2166. <AdvancedSliceEditor
  2167. form={form}
  2168. path="sniffing"
  2169. minHeight="240px"
  2170. maxHeight="420px"
  2171. />
  2172. ),
  2173. },
  2174. ]}
  2175. />
  2176. );
  2177. const sniffingTab = (
  2178. <>
  2179. <Form.Item name={['sniffing', 'enabled']} label={t('enable')} valuePropName="checked">
  2180. <Switch />
  2181. </Form.Item>
  2182. {sniffingEnabled && (
  2183. <>
  2184. <Form.Item name={['sniffing', 'destOverride']} wrapperCol={{ span: 24 }}>
  2185. <Checkbox.Group>
  2186. {Object.entries(SNIFFING_OPTION).map(([key, value]) => (
  2187. <Checkbox key={key} value={value}>{key}</Checkbox>
  2188. ))}
  2189. </Checkbox.Group>
  2190. </Form.Item>
  2191. <Form.Item
  2192. name={['sniffing', 'metadataOnly']}
  2193. label={t('pages.inbounds.sniffingMetadataOnly')}
  2194. valuePropName="checked"
  2195. >
  2196. <Switch />
  2197. </Form.Item>
  2198. <Form.Item
  2199. name={['sniffing', 'routeOnly']}
  2200. label={t('pages.inbounds.sniffingRouteOnly')}
  2201. valuePropName="checked"
  2202. >
  2203. <Switch />
  2204. </Form.Item>
  2205. <Form.Item
  2206. name={['sniffing', 'ipsExcluded']}
  2207. label={t('pages.inbounds.sniffingIpsExcluded')}
  2208. >
  2209. <Select
  2210. mode="tags"
  2211. tokenSeparators={[',']}
  2212. placeholder="IP/CIDR/geoip:*/ext:*"
  2213. style={{ width: '100%' }}
  2214. />
  2215. </Form.Item>
  2216. <Form.Item
  2217. name={['sniffing', 'domainsExcluded']}
  2218. label={t('pages.inbounds.sniffingDomainsExcluded')}
  2219. >
  2220. <Select
  2221. mode="tags"
  2222. tokenSeparators={[',']}
  2223. placeholder="domain:*/ext:*"
  2224. style={{ width: '100%' }}
  2225. />
  2226. </Form.Item>
  2227. </>
  2228. )}
  2229. </>
  2230. );
  2231. return (
  2232. <>
  2233. {messageContextHolder}
  2234. <Modal
  2235. open={open}
  2236. title={title}
  2237. okText={okText}
  2238. cancelText={t('close')}
  2239. confirmLoading={saving}
  2240. mask={{ closable: false }}
  2241. width={780}
  2242. onOk={submit}
  2243. onCancel={onClose}
  2244. destroyOnHidden
  2245. >
  2246. <Form
  2247. form={form}
  2248. colon={false}
  2249. labelCol={{ sm: { span: 8 } }}
  2250. wrapperCol={{ sm: { span: 14 } }}
  2251. onValuesChange={onValuesChange}
  2252. >
  2253. <Tabs items={[
  2254. { key: 'basic', label: t('pages.xray.basicTemplate'), children: basicTab },
  2255. ...(([
  2256. Protocols.VLESS,
  2257. Protocols.SHADOWSOCKS,
  2258. Protocols.HTTP,
  2259. Protocols.MIXED,
  2260. Protocols.TUNNEL,
  2261. Protocols.TUN,
  2262. Protocols.WIREGUARD,
  2263. ] as string[]).includes(protocol) || isFallbackHost
  2264. ? [{ key: 'protocol', label: t('pages.inbounds.protocol'), children: protocolTab }]
  2265. : []),
  2266. ...(streamEnabled
  2267. ? [
  2268. { key: 'stream', label: t('pages.inbounds.streamTab'), children: streamTab },
  2269. { key: 'security', label: t('pages.inbounds.securityTab'), children: securityTab },
  2270. ]
  2271. : []),
  2272. { key: 'sniffing', label: t('pages.inbounds.sniffingTab'), children: sniffingTab },
  2273. { key: 'advanced', label: t('pages.xray.advancedTemplate'), children: advancedTab },
  2274. ]} />
  2275. </Form>
  2276. </Modal>
  2277. </>
  2278. );
  2279. }