瀏覽代碼

feat(clients): add Generate button for WireGuard/AmneziaWG PresharedKey (#6455)

* feat(clients): add Generate button for WireGuard/AmneziaWG PresharedKey

Matches existing key regenerate controls on the client form. Value is
32 random bytes base64 via Wireguard.generatePresharedKey (same as
wg genpsk). Field stays optional.

Fixes #6343

* fix(clients): keep FormField for WireGuard PresharedKey generate

Restore RHF FormField (noStyle inside Space.Compact) so the regenerate
control matches inbound reality patterns and satisfies oxfmt.

---------

Co-authored-by: mrchatam <[email protected]>
mrchatam 4 小時之前
父節點
當前提交
22763fe8f6
共有 1 個文件被更改,包括 16 次插入4 次删除
  1. 16 4
      frontend/src/pages/clients/ClientFormModal.tsx

+ 16 - 4
frontend/src/pages/clients/ClientFormModal.tsx

@@ -522,6 +522,10 @@ export default function ClientFormModal({
     methods.setValue('wgPublicKey', kp.publicKey);
   }
 
+  function regenerateWireguardPresharedKey() {
+    methods.setValue('wgPreSharedKey', Wireguard.keyToBase64(Wireguard.generatePresharedKey()));
+  }
+
   function regenerateMtprotoSecret() {
     methods.setValue('secret', generateMtprotoSecret(mtprotoDomain));
   }
@@ -1251,16 +1255,24 @@ export default function ClientFormModal({
                           >
                             <Input disabled />
                           </FormField>
-                          <FormField
-                            name="wgPreSharedKey"
+                          <Form.Item
                             label={t(
                               showAmneziawg
                                 ? 'pages.clients.amneziaWgPreSharedKey'
                                 : 'pages.clients.wireguardPreSharedKey',
                             )}
                           >
-                            <Input />
-                          </FormField>
+                            <Space.Compact style={{ display: 'flex' }}>
+                              <FormField name="wgPreSharedKey" noStyle>
+                                <Input style={{ flex: 1 }} />
+                              </FormField>
+                              <Button
+                                aria-label={t('regenerate')}
+                                icon={<ReloadOutlined />}
+                                onClick={regenerateWireguardPresharedKey}
+                              />
+                            </Space.Compact>
+                          </Form.Item>
                           {showWireguard && showAmneziawg ? (
                             <>
                               <FormField