[PR #5466] [CLOSED] feat(wireguard): manage WireGuard peers as clients on the Clients tab #5888

Closed
opened 2026-11-02 04:04:48 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/MHSanaei/3x-ui/pull/5466
Author: @mrAntonD
Created: 6/21/2026
Status: ❌ Closed

Base: main ← Head: feat/wireguard-clients


📝 Commits (10+)

  • 1e9290f feat(wireguard): manage WG peers as clients on the Clients page
  • 67ed0c8 fix(wg): fix peer data loss, delete error, QR/info for WireGuard clients
  • 053200e feat(wg): show config text and download button in QR modal
  • f7c09e4 fix(wg): next IP suggestion, QR public key, and malformed JSON on add
  • 236e49c fix(wg): toggle enable/disable and show config in QR modal
  • 9231c00 feat(wg): download config in info/edit modals, preserve wgPeer on hydrate
  • fe18197 feat(wg): hide subscription/links blocks for WireGuard clients
  • 13ff78a perf(wg): patch peers[] in-place instead of full DB rebuild on add/update/del
  • f4317c9 fix(ci): register WgPeerSettings in codegen and document WG client endpoints
  • 962b9a3 fix(ci): regenerate openapi.json after adding WG client endpoint docs

📊 Changes

33 files changed (+1978 additions, -504 deletions)

View changed files

📝 frontend/public/openapi.json (+233 -2)
📝 frontend/src/generated/examples.ts (+12 -2)
📝 frontend/src/generated/schemas.ts (+39 -1)
📝 frontend/src/generated/types.ts (+9 -0)
📝 frontend/src/generated/zod.ts (+10 -0)
📝 frontend/src/hooks/useClients.ts (+3 -0)
📝 frontend/src/pages/api-docs/endpoints.ts (+31 -0)
📝 frontend/src/pages/clients/ClientFormModal.tsx (+316 -116)
📝 frontend/src/pages/clients/ClientInfoModal.css (+8 -0)
📝 frontend/src/pages/clients/ClientInfoModal.tsx (+223 -96)
📝 frontend/src/pages/clients/ClientQrModal.tsx (+113 -13)
📝 frontend/src/pages/clients/ClientsPage.tsx (+54 -2)
📝 frontend/src/pages/inbounds/form/InboundFormModal.tsx (+1 -7)
📝 frontend/src/pages/inbounds/form/protocols/wireguard.tsx (+3 -123)
📝 frontend/src/pages/inbounds/info/InboundInfoModal.tsx (+18 -86)
📝 frontend/src/pages/inbounds/qr/QrCodeModal.tsx (+3 -2)
📝 frontend/src/pages/inbounds/useInbounds.ts (+15 -2)
📝 frontend/src/schemas/client.ts (+10 -0)
📝 internal/database/model/model.go (+47 -22)
📝 internal/web/controller/inbound.go (+92 -0)

...and 13 more files

📄 Description

Why

WireGuard peers were second-class citizens — managed only inside the Inbounds form alongside transport settings. This meant no per-peer traffic limits, no expiry, no sub IDs, and no per-client QR/config download. Moving peers to the Clients tab gives WireGuard the same UX as any other protocol while keeping the Inbounds form clean.

Screenshot

WireGuard clients on the Clients tab

Summary

  • WireGuard peer management moved to Clients tab: peers are now created/edited/deleted from the Clients page like any other protocol; the Inbounds form retains WG settings (key, MTU, etc.) but the peer list is removed from it
  • Auto-migration on upgrade: existing settings.peers[] are migrated to the clients table on first startup — no data loss
  • Peer count on Inbounds tab: WireGuard inbounds now show active peer count
  • Peers stay in sync on every restart: ReconcileWgPeers runs on each panel start, so peers added directly to settings.peers[] always appear in the Clients tab
  • Duplicate IP prevention: entering an already-used allowedIPs in the client form auto-assigns the first available IP instead; existing clients are not affected when editing

Key changes

Backend

  • model.go — WgPeerSettings struct + wg_settings column on ClientRecord; MarshalJSON/UnmarshalJSON expose it as wgPeer in API responses
  • client_wg_apply.go — AddWgClient, UpdateWgClient, DelWgClient: full CRUD; each mutation patches settings.peers[] in-place (no full DB rebuild)
  • client_wg_peers.go — syncWgPeersFromClients, wgPeerToRecord, SyncWgInbound
  • inbound_migration.go — ReconcileWgPeers called on every panel start to keep settings.peers[] and clients table in sync
  • inbound.go — UpdateInbound preserves settings.peers[] when the form omits them; inboundWgPublicKey derives server public key from secretKey via curve25519; GetInboundOptions exposes wgPublicKey
  • client_crud.go — Delete() routes WG inbounds through DelWgClient
  • client_paging.go — ClientSlim includes wgPeer so next-IP suggestion works from the paged list
  • inbound.go controller — WG CRUD endpoints under /panel/api/inbounds/:id/

Frontend

  • ClientFormModal — WG fields (public/private key, PSK, allowed IPs, keepalive) when WG inbound selected; irrelevant fields hidden; auto-suggests next sequential IP; auto-resolves duplicate allowedIPs on blur (create only — edit mode skips unchanged values)
  • ClientQrModal — generates WireGuard .conf ([Interface] + [Peer]); supports .conf download
  • ClientInfoModal — WG-specific fields shown; subscription/links blocks hidden for WG clients
  • useInbounds — WireGuard added to TRACKED_PROTOCOLS; peer count read from settings.peers

Test plan

  • Existing WG inbound: open Clients tab, verify peers migrated automatically
  • Add new WG peer: form shows WG fields, auto-suggests next available IP
  • Add peer with duplicate IP: field auto-corrects to first available IP on blur
  • Edit peer without changing IP: IP is not modified
  • QR button: shows WireGuard .conf with correct keys and endpoint
  • Info button: shows peer-specific fields
  • Delete: peer removed from both DB and xray config
  • Edit WG inbound (save form): existing peers are preserved
  • Inbounds tab: WireGuard shows peer count
  • Restart panel: peers added directly to settings.peers[] appear in Clients tab

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/MHSanaei/3x-ui/pull/5466 **Author:** [@mrAntonD](https://github.com/mrAntonD) **Created:** 6/21/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `feat/wireguard-clients` --- ### 📝 Commits (10+) - [`1e9290f`](https://github.com/MHSanaei/3x-ui/commit/1e9290f864245246070acd5b5ef52c6e4ae6a01a) feat(wireguard): manage WG peers as clients on the Clients page - [`67ed0c8`](https://github.com/MHSanaei/3x-ui/commit/67ed0c842d35bb814401845116c5e8d1e8c36761) fix(wg): fix peer data loss, delete error, QR/info for WireGuard clients - [`053200e`](https://github.com/MHSanaei/3x-ui/commit/053200ed71f996c9a9ab3336819409a03e2da509) feat(wg): show config text and download button in QR modal - [`f7c09e4`](https://github.com/MHSanaei/3x-ui/commit/f7c09e4214bac8fa56eb7685acf8c5b9278f6b10) fix(wg): next IP suggestion, QR public key, and malformed JSON on add - [`236e49c`](https://github.com/MHSanaei/3x-ui/commit/236e49cf1ae4e6921b402cc74102b4b0b9e3e133) fix(wg): toggle enable/disable and show config in QR modal - [`9231c00`](https://github.com/MHSanaei/3x-ui/commit/9231c00062348abd066a9e36423f248381728e7f) feat(wg): download config in info/edit modals, preserve wgPeer on hydrate - [`fe18197`](https://github.com/MHSanaei/3x-ui/commit/fe18197d30bc0c05d243c080069cffa58c2679f4) feat(wg): hide subscription/links blocks for WireGuard clients - [`13ff78a`](https://github.com/MHSanaei/3x-ui/commit/13ff78a8a4c8025cf65a7f794cd9127a0b2d3b19) perf(wg): patch peers[] in-place instead of full DB rebuild on add/update/del - [`f4317c9`](https://github.com/MHSanaei/3x-ui/commit/f4317c997222512b9b5d8b0d7b5e9e99912cca0c) fix(ci): register WgPeerSettings in codegen and document WG client endpoints - [`962b9a3`](https://github.com/MHSanaei/3x-ui/commit/962b9a3bc1d0d08cc0c8b690e33b6e0a10a03b12) fix(ci): regenerate openapi.json after adding WG client endpoint docs ### 📊 Changes **33 files changed** (+1978 additions, -504 deletions) <details> <summary>View changed files</summary> 📝 `frontend/public/openapi.json` (+233 -2) 📝 `frontend/src/generated/examples.ts` (+12 -2) 📝 `frontend/src/generated/schemas.ts` (+39 -1) 📝 `frontend/src/generated/types.ts` (+9 -0) 📝 `frontend/src/generated/zod.ts` (+10 -0) 📝 `frontend/src/hooks/useClients.ts` (+3 -0) 📝 `frontend/src/pages/api-docs/endpoints.ts` (+31 -0) 📝 `frontend/src/pages/clients/ClientFormModal.tsx` (+316 -116) 📝 `frontend/src/pages/clients/ClientInfoModal.css` (+8 -0) 📝 `frontend/src/pages/clients/ClientInfoModal.tsx` (+223 -96) 📝 `frontend/src/pages/clients/ClientQrModal.tsx` (+113 -13) 📝 `frontend/src/pages/clients/ClientsPage.tsx` (+54 -2) 📝 `frontend/src/pages/inbounds/form/InboundFormModal.tsx` (+1 -7) 📝 `frontend/src/pages/inbounds/form/protocols/wireguard.tsx` (+3 -123) 📝 `frontend/src/pages/inbounds/info/InboundInfoModal.tsx` (+18 -86) 📝 `frontend/src/pages/inbounds/qr/QrCodeModal.tsx` (+3 -2) 📝 `frontend/src/pages/inbounds/useInbounds.ts` (+15 -2) 📝 `frontend/src/schemas/client.ts` (+10 -0) 📝 `internal/database/model/model.go` (+47 -22) 📝 `internal/web/controller/inbound.go` (+92 -0) _...and 13 more files_ </details> ### 📄 Description ## Why WireGuard peers were second-class citizens — managed only inside the Inbounds form alongside transport settings. This meant no per-peer traffic limits, no expiry, no sub IDs, and no per-client QR/config download. Moving peers to the Clients tab gives WireGuard the same UX as any other protocol while keeping the Inbounds form clean. ## Screenshot ![WireGuard clients on the Clients tab](https://raw.githubusercontent.com/mrAntonD/3x-ui/feat/wireguard-clients/wg1.png) ## Summary - **WireGuard peer management moved to Clients tab**: peers are now created/edited/deleted from the Clients page like any other protocol; the Inbounds form retains WG settings (key, MTU, etc.) but the peer list is removed from it - **Auto-migration on upgrade**: existing `settings.peers[]` are migrated to the `clients` table on first startup — no data loss - **Peer count on Inbounds tab**: WireGuard inbounds now show active peer count - **Peers stay in sync on every restart**: `ReconcileWgPeers` runs on each panel start, so peers added directly to `settings.peers[]` always appear in the Clients tab - **Duplicate IP prevention**: entering an already-used `allowedIPs` in the client form auto-assigns the first available IP instead; existing clients are not affected when editing ## Key changes ### Backend - `model.go` — `WgPeerSettings` struct + `wg_settings` column on `ClientRecord`; `MarshalJSON`/`UnmarshalJSON` expose it as `wgPeer` in API responses - `client_wg_apply.go` — `AddWgClient`, `UpdateWgClient`, `DelWgClient`: full CRUD; each mutation patches `settings.peers[]` in-place (no full DB rebuild) - `client_wg_peers.go` — `syncWgPeersFromClients`, `wgPeerToRecord`, `SyncWgInbound` - `inbound_migration.go` — `ReconcileWgPeers` called on every panel start to keep `settings.peers[]` and `clients` table in sync - `inbound.go` — `UpdateInbound` preserves `settings.peers[]` when the form omits them; `inboundWgPublicKey` derives server public key from `secretKey` via curve25519; `GetInboundOptions` exposes `wgPublicKey` - `client_crud.go` — `Delete()` routes WG inbounds through `DelWgClient` - `client_paging.go` — `ClientSlim` includes `wgPeer` so next-IP suggestion works from the paged list - `inbound.go` controller — WG CRUD endpoints under `/panel/api/inbounds/:id/` ### Frontend - `ClientFormModal` — WG fields (public/private key, PSK, allowed IPs, keepalive) when WG inbound selected; irrelevant fields hidden; auto-suggests next sequential IP; auto-resolves duplicate `allowedIPs` on blur (create only — edit mode skips unchanged values) - `ClientQrModal` — generates WireGuard `.conf` (`[Interface]` + `[Peer]`); supports `.conf` download - `ClientInfoModal` — WG-specific fields shown; subscription/links blocks hidden for WG clients - `useInbounds` — WireGuard added to `TRACKED_PROTOCOLS`; peer count read from `settings.peers` ## Test plan - [x] Existing WG inbound: open Clients tab, verify peers migrated automatically - [x] Add new WG peer: form shows WG fields, auto-suggests next available IP - [x] Add peer with duplicate IP: field auto-corrects to first available IP on blur - [x] Edit peer without changing IP: IP is not modified - [x] QR button: shows WireGuard `.conf` with correct keys and endpoint - [x] Info button: shows peer-specific fields - [x] Delete: peer removed from both DB and xray config - [x] Edit WG inbound (save form): existing peers are preserved - [x] Inbounds tab: WireGuard shows peer count - [x] Restart panel: peers added directly to `settings.peers[]` appear in Clients tab --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-02 04:04:48 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
MHSanaei/3x-ui#5888
No description provided.