diff --git a/frontend/src/pages/inbounds/InboundFormModal.new.tsx b/frontend/src/pages/inbounds/InboundFormModal.new.tsx index 49768a0c..dc1cb908 100644 --- a/frontend/src/pages/inbounds/InboundFormModal.new.tsx +++ b/frontend/src/pages/inbounds/InboundFormModal.new.tsx @@ -18,7 +18,7 @@ import { } from 'antd'; import { MinusOutlined, PlusOutlined, SyncOutlined } from '@ant-design/icons'; -import { HttpUtil, NumberFormatter, RandomUtil, SizeFormatter } from '@/utils'; +import { HttpUtil, NumberFormatter, RandomUtil, SizeFormatter, Wireguard } from '@/utils'; import { rawInboundToFormValues, formValuesToWirePayload, @@ -105,6 +105,21 @@ export default function InboundFormModalNew({ settings: typeof ssMethod === 'string' ? { method: ssMethod } : {}, }); const mixedUdpOn = Form.useWatch(['settings', 'udp'], form) ?? false; + const wgSecretKey = Form.useWatch(['settings', 'secretKey'], form); + const wgPubKey = typeof wgSecretKey === 'string' && wgSecretKey.length > 0 + ? Wireguard.generateKeypair(wgSecretKey).publicKey + : ''; + + const regenInboundWg = () => { + const kp = Wireguard.generateKeypair(); + form.setFieldValue(['settings', 'secretKey'], kp.privateKey); + }; + + const regenWgPeerKeypair = (peerName: number) => { + const kp = Wireguard.generateKeypair(); + form.setFieldValue(['settings', 'peers', peerName, 'privateKey'], kp.privateKey); + form.setFieldValue(['settings', 'peers', peerName, 'publicKey'], kp.publicKey); + }; const matchesVlessAuth = ( block: { id?: string; label?: string } | undefined | null, @@ -336,6 +351,111 @@ export default function InboundFormModalNew({ const protocolTab = ( <> + {protocol === Protocols.WIREGUARD && ( + <> + + Secret key{' '} + + + } + > + + + + + + + + + + + + + {(fields, { add, remove }) => ( + <> + + + + {fields.map((field, idx) => ( +
+ + {fields.length > 1 && ( + + )} + + + Secret key{' '} + regenWgPeerKeypair(field.name)} + /> + + } + > + + + + + + + + + + {(ipFields, { add: addIp, remove: removeIp }) => ( + + + {ipFields.map((ipField) => ( + + + + + {ipFields.length > 1 && ( + + )} + + ))} + + )} + + + + +
+ ))} + + )} +
+ + )} + {protocol === Protocols.TUN && ( <> @@ -715,6 +835,7 @@ export default function InboundFormModalNew({ Protocols.MIXED, Protocols.TUNNEL, Protocols.TUN, + Protocols.WIREGUARD, ] as string[]).includes(protocol) ? [{ key: 'protocol', label: t('pages.inbounds.protocol'), children: protocolTab }] : []),