feat(wireguard): support multiple devices per client (#7143)

A WireGuard client had one key pair and one tunnel address, so an operator who gave the same config to a phone and a laptop saw the two fight over the peer endpoint.

One client can now own extra devices, up to a per-client limit: each has its own keys and address, shares the client's quota, expiry and switch, and gets its own config, QR code and subscription. Devices become extra peers under the client's email, built by the same core-user map the other paths use, and a device change is applied to the running inbound in place instead of rebuilding it.

Nodes advertise a wg-devices capability; the master refuses a device for a node that would ignore it, before storing it and again when pushing the inbound.
This commit is contained in:
Artem K
2026-11-24 21:46:16 +03:00
committed by GitHub
parent 3cb5bb7187
commit f25cecfb40
72 changed files with 4489 additions and 196 deletions
+46 -1
View File
@@ -82,6 +82,21 @@ _openapi:
emitted on future subscription fetches; credentials already imported by
an app remain valid until the external provider revokes them.
url: '#replace-a-clients-external-links-and-external-subscriptions-sends-the-full-set-the-server-replaces-all-rows-disabled-rows-stay-saved-for-editing-but-are-not-emitted-in-generated-subscriptions-the-owning-clients-disabled-or-expired-state-also-stops-these-rows-from-being-emitted-on-future-subscription-fetches-credentials-already-imported-by-an-app-remain-valid-until-the-external-provider-revokes-them'
- depth: 2
title: List WireGuard devices and their per-inbound addresses.
url: '#list-wireguard-devices-and-their-per-inbound-addresses'
- depth: 2
title: Create a WireGuard device on every attached WireGuard inbound.
url: '#create-a-wireguard-device-on-every-attached-wireguard-inbound'
- depth: 2
title: Set the maximum number of WireGuard devices.
url: '#set-the-maximum-number-of-wireguard-devices'
- depth: 2
title: Rename or enable a WireGuard device.
url: '#rename-or-enable-a-wireguard-device'
- depth: 2
title: Delete an additional WireGuard device and release its address.
url: '#delete-an-additional-wireguard-device-and-release-its-address'
- depth: 2
title: Reset the up/down counters for every client globally. Quotas and expiry
are not affected. Triggers an Xray restart if any counter actually
@@ -400,6 +415,16 @@ _openapi:
emitted on future subscription fetches; credentials already imported
by an app remain valid until the external provider revokes them.
id: replace-a-clients-external-links-and-external-subscriptions-sends-the-full-set-the-server-replaces-all-rows-disabled-rows-stay-saved-for-editing-but-are-not-emitted-in-generated-subscriptions-the-owning-clients-disabled-or-expired-state-also-stops-these-rows-from-being-emitted-on-future-subscription-fetches-credentials-already-imported-by-an-app-remain-valid-until-the-external-provider-revokes-them
- content: List WireGuard devices and their per-inbound addresses.
id: list-wireguard-devices-and-their-per-inbound-addresses
- content: Create a WireGuard device on every attached WireGuard inbound.
id: create-a-wireguard-device-on-every-attached-wireguard-inbound
- content: Set the maximum number of WireGuard devices.
id: set-the-maximum-number-of-wireguard-devices
- content: Rename or enable a WireGuard device.
id: rename-or-enable-a-wireguard-device
- content: Delete an additional WireGuard device and release its address.
id: delete-an-additional-wireguard-device-and-release-its-address
- content: Reset the up/down counters for every client globally. Quotas and expiry
are not affected. Triggers an Xray restart if any counter actually
moved.
@@ -778,6 +803,26 @@ _openapi:
still have detached the remaining inbounds. Detach writes nothing
beyond the inbounds, so every error carries the prefix.'
heading: detach-a-client-from-one-or-more-inbounds-without-deleting-the-client
- content: The original credentials remain the primary device. Additional devices
share their parent client email, traffic quota, expiry and enable
state. Keep each device configuration on one device. Device-specific
subscriptions use the existing subscription URL with the wgDevice
query parameter set to the device ID.
heading: list-wireguard-devices-and-their-per-inbound-addresses
- content: Keys are generated once and each inbound allocates an available tunnel
address. All inbounds commit together. The default limit is 5 devices
including primary.
heading: create-a-wireguard-device-on-every-attached-wireguard-inbound
- content: The limit includes primary and disabled devices. Choose 1 to 32. Values
below the current device count are rejected.
heading: set-the-maximum-number-of-wireguard-devices
- content: The primary device is managed through the parent client. Disabled
additional devices retain their reserved addresses.
heading: rename-or-enable-a-wireguard-device
- content: The device is removed from every attached WireGuard inbound. Its
previously downloaded configuration loses access after the
configuration is applied.
heading: delete-an-additional-wireguard-device-and-release-its-address
---
{/* This file was generated by Fumadocs. Do not edit this file directly. Any changes should be made by running the generation command again. */}
@@ -787,7 +832,7 @@ export default function Layout(props) {
return (
<>
{props.children}
<OpenAPIPage document="./public/openapi.json" webhooks={[]} operations={[{"path":"/panel/api/clients/list","method":"get"},{"path":"/panel/api/clients/list/paged","method":"get"},{"path":"/panel/api/clients/get/{email}","method":"get"},{"path":"/panel/api/clients/get","method":"get"},{"path":"/panel/api/clients/get/subId/{subId}","method":"get"},{"path":"/panel/api/clients/get/tgId/{tgId}","method":"get"},{"path":"/panel/api/clients/add","method":"post"},{"path":"/panel/api/clients/renewalPreview","method":"post"},{"path":"/panel/api/clients/update/{email}","method":"post"},{"path":"/panel/api/clients/update","method":"post"},{"path":"/panel/api/clients/del/{email}","method":"post"},{"path":"/panel/api/clients/del","method":"post"},{"path":"/panel/api/clients/{email}/attach","method":"post"},{"path":"/panel/api/clients/{email}/detach","method":"post"},{"path":"/panel/api/clients/{email}/externalLinks","method":"post"},{"path":"/panel/api/clients/resetAllTraffics","method":"post"},{"path":"/panel/api/clients/delDepleted","method":"post"},{"path":"/panel/api/clients/delOrphans","method":"post"},{"path":"/panel/api/clients/export","method":"get"},{"path":"/panel/api/clients/import","method":"post"},{"path":"/panel/api/clients/bulkAdjust","method":"post"},{"path":"/panel/api/clients/bulkEnable","method":"post"},{"path":"/panel/api/clients/bulkDisable","method":"post"},{"path":"/panel/api/clients/bulkDel","method":"post"},{"path":"/panel/api/clients/bulkCreate","method":"post"},{"path":"/panel/api/clients/groups/bulkAdd","method":"post"},{"path":"/panel/api/clients/groups/bulkRemove","method":"post"},{"path":"/panel/api/clients/bulkAttach","method":"post"},{"path":"/panel/api/clients/bulkDetach","method":"post"},{"path":"/panel/api/clients/bulkResetTraffic","method":"post"},{"path":"/panel/api/clients/groups","method":"get"},{"path":"/panel/api/clients/groups/{name}/emails","method":"get"},{"path":"/panel/api/clients/groups/create","method":"post"},{"path":"/panel/api/clients/groups/rename","method":"post"},{"path":"/panel/api/clients/groups/delete","method":"post"},{"path":"/panel/api/clients/groups/resetTraffic","method":"post"},{"path":"/panel/api/clients/resetTraffic/{email}","method":"post"},{"path":"/panel/api/clients/updateTraffic/{email}","method":"post"},{"path":"/panel/api/clients/ips/{email}","method":"post"},{"path":"/panel/api/clients/clearIps/{email}","method":"post"},{"path":"/panel/api/clients/hwids/{email}","method":"post"},{"path":"/panel/api/clients/hwids/{email}","method":"delete"},{"path":"/panel/api/clients/hwids/{email}/{id}","method":"delete"},{"path":"/panel/api/clients/hwids/{email}/{id}/block","method":"post"},{"path":"/panel/api/clients/onlines","method":"post"},{"path":"/panel/api/clients/onlinesByGuid","method":"post"},{"path":"/panel/api/clients/clientIpsByGuid","method":"post"},{"path":"/panel/api/clients/activeInbounds","method":"post"},{"path":"/panel/api/clients/lastOnline","method":"post"},{"path":"/panel/api/clients/traffic/{email}","method":"get"},{"path":"/panel/api/clients/subLinks/{subId}","method":"get"},{"path":"/panel/api/clients/happLink/{id}","method":"post"},{"path":"/panel/api/clients/links/{email}","method":"get"}]} showTitle />
<OpenAPIPage document="./public/openapi.json" webhooks={[]} operations={[{"path":"/panel/api/clients/list","method":"get"},{"path":"/panel/api/clients/list/paged","method":"get"},{"path":"/panel/api/clients/get/{email}","method":"get"},{"path":"/panel/api/clients/get","method":"get"},{"path":"/panel/api/clients/get/subId/{subId}","method":"get"},{"path":"/panel/api/clients/get/tgId/{tgId}","method":"get"},{"path":"/panel/api/clients/add","method":"post"},{"path":"/panel/api/clients/renewalPreview","method":"post"},{"path":"/panel/api/clients/update/{email}","method":"post"},{"path":"/panel/api/clients/update","method":"post"},{"path":"/panel/api/clients/del/{email}","method":"post"},{"path":"/panel/api/clients/del","method":"post"},{"path":"/panel/api/clients/{email}/attach","method":"post"},{"path":"/panel/api/clients/{email}/detach","method":"post"},{"path":"/panel/api/clients/{email}/externalLinks","method":"post"},{"path":"/panel/api/clients/wireguardDevices","method":"get"},{"path":"/panel/api/clients/wireguardDevices","method":"post"},{"path":"/panel/api/clients/wireguardDevices/limit","method":"put"},{"path":"/panel/api/clients/wireguardDevices/{deviceId}","method":"patch"},{"path":"/panel/api/clients/wireguardDevices/{deviceId}","method":"delete"},{"path":"/panel/api/clients/resetAllTraffics","method":"post"},{"path":"/panel/api/clients/delDepleted","method":"post"},{"path":"/panel/api/clients/delOrphans","method":"post"},{"path":"/panel/api/clients/export","method":"get"},{"path":"/panel/api/clients/import","method":"post"},{"path":"/panel/api/clients/bulkAdjust","method":"post"},{"path":"/panel/api/clients/bulkEnable","method":"post"},{"path":"/panel/api/clients/bulkDisable","method":"post"},{"path":"/panel/api/clients/bulkDel","method":"post"},{"path":"/panel/api/clients/bulkCreate","method":"post"},{"path":"/panel/api/clients/groups/bulkAdd","method":"post"},{"path":"/panel/api/clients/groups/bulkRemove","method":"post"},{"path":"/panel/api/clients/bulkAttach","method":"post"},{"path":"/panel/api/clients/bulkDetach","method":"post"},{"path":"/panel/api/clients/bulkResetTraffic","method":"post"},{"path":"/panel/api/clients/groups","method":"get"},{"path":"/panel/api/clients/groups/{name}/emails","method":"get"},{"path":"/panel/api/clients/groups/create","method":"post"},{"path":"/panel/api/clients/groups/rename","method":"post"},{"path":"/panel/api/clients/groups/delete","method":"post"},{"path":"/panel/api/clients/groups/resetTraffic","method":"post"},{"path":"/panel/api/clients/resetTraffic/{email}","method":"post"},{"path":"/panel/api/clients/updateTraffic/{email}","method":"post"},{"path":"/panel/api/clients/ips/{email}","method":"post"},{"path":"/panel/api/clients/clearIps/{email}","method":"post"},{"path":"/panel/api/clients/hwids/{email}","method":"post"},{"path":"/panel/api/clients/hwids/{email}","method":"delete"},{"path":"/panel/api/clients/hwids/{email}/{id}","method":"delete"},{"path":"/panel/api/clients/hwids/{email}/{id}/block","method":"post"},{"path":"/panel/api/clients/onlines","method":"post"},{"path":"/panel/api/clients/onlinesByGuid","method":"post"},{"path":"/panel/api/clients/clientIpsByGuid","method":"post"},{"path":"/panel/api/clients/activeInbounds","method":"post"},{"path":"/panel/api/clients/lastOnline","method":"post"},{"path":"/panel/api/clients/traffic/{email}","method":"get"},{"path":"/panel/api/clients/subLinks/{subId}","method":"get"},{"path":"/panel/api/clients/happLink/{id}","method":"post"},{"path":"/panel/api/clients/links/{email}","method":"get"}]} showTitle />
</>
);
}
+517 -1
View File
@@ -2151,6 +2151,15 @@
"description": "Last update timestamp",
"format": "int64",
"type": "integer"
},
"wgDeviceLimit": {
"type": "integer"
},
"wireguardDevices": {
"items": {
"$ref": "#/components/schemas/WireguardDevice"
},
"type": "array"
}
},
"required": [
@@ -2365,6 +2374,15 @@
},
"uuid": {
"type": "string"
},
"wgDeviceLimit": {
"type": "integer"
},
"wireguardDevices": {
"items": {
"$ref": "#/components/schemas/WireguardDevice"
},
"type": "array"
}
},
"required": [
@@ -2400,7 +2418,9 @@
"trafficReset",
"trafficResetDay",
"updatedAt",
"uuid"
"uuid",
"wgDeviceLimit",
"wireguardDevices"
],
"type": "object"
},
@@ -5433,6 +5453,44 @@
],
"type": "object"
},
"WireguardDevice": {
"description": "WireguardDevice is an additional peer sharing its client's quota and lifecycle.\nThe original client credentials remain the primary device for compatibility.",
"properties": {
"allowedIPs": {
"items": {
"type": "string"
},
"type": "array"
},
"enable": {
"type": "boolean"
},
"id": {
"type": "string"
},
"name": {
"type": "string"
},
"preSharedKey": {
"type": "string"
},
"privateKey": {
"type": "string"
},
"publicKey": {
"type": "string"
}
},
"required": [
"allowedIPs",
"enable",
"id",
"name",
"privateKey",
"publicKey"
],
"type": "object"
},
"WebSocketEnvelope": {
"type": "object",
"required": [
@@ -10022,6 +10080,464 @@
}
}
},
"/panel/api/clients/wireguardDevices": {
"get": {
"tags": [
"Clients"
],
"summary": "List WireGuard devices and their per-inbound addresses.",
"operationId": "get_panel_api_clients_wireguardDevices",
"description": "The original credentials remain the primary device. Additional devices share their parent client email, traffic quota, expiry and enable state. Keep each device configuration on one device. Device-specific subscriptions use the existing subscription URL with the wgDevice query parameter set to the device ID.",
"parameters": [
{
"name": "email",
"in": "query",
"required": true,
"description": "Client email.",
"schema": {
"type": "string"
}
}
],
"responses": {
"200": {
"description": "Successful response",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"success": {
"type": "boolean"
},
"msg": {
"type": "string"
},
"obj": {}
}
},
"example": {
"success": true,
"obj": {
"limit": 5,
"inbounds": [
{
"inboundId": 3,
"devices": [
{
"id": "primary",
"name": "",
"enable": true,
"privateKey": "...",
"publicKey": "...",
"allowedIPs": [
"10.0.0.2/32"
]
},
{
"id": "e3550bd1-0ba0-48b2-8a91-e57263a23d9d",
"name": "Phone",
"enable": true,
"privateKey": "...",
"publicKey": "...",
"allowedIPs": [
"10.0.0.3/32"
]
}
]
}
]
}
}
}
}
}
}
},
"post": {
"tags": [
"Clients"
],
"summary": "Create a WireGuard device on every attached WireGuard inbound.",
"operationId": "post_panel_api_clients_wireguardDevices",
"description": "Keys are generated once and each inbound allocates an available tunnel address. All inbounds commit together. The default limit is 5 devices including primary.",
"parameters": [
{
"name": "email",
"in": "query",
"required": true,
"description": "Client email.",
"schema": {
"type": "string"
}
}
],
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"name": {
"type": "string",
"description": "Device name with 1 to 64 characters on one line."
}
},
"required": [
"name"
]
},
"example": {
"name": "Phone"
}
}
}
},
"responses": {
"200": {
"description": "Successful response",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"success": {
"type": "boolean"
},
"msg": {
"type": "string"
},
"obj": {}
}
},
"example": {
"success": true,
"obj": {
"limit": 5,
"inbounds": [
{
"inboundId": 3,
"devices": [
{
"id": "primary",
"name": "",
"enable": true,
"privateKey": "...",
"publicKey": "...",
"allowedIPs": [
"10.0.0.2/32"
]
},
{
"id": "e3550bd1-0ba0-48b2-8a91-e57263a23d9d",
"name": "Phone",
"enable": true,
"privateKey": "...",
"publicKey": "...",
"allowedIPs": [
"10.0.0.3/32"
]
}
]
}
]
}
}
}
}
}
}
}
},
"/panel/api/clients/wireguardDevices/limit": {
"put": {
"tags": [
"Clients"
],
"summary": "Set the maximum number of WireGuard devices.",
"operationId": "put_panel_api_clients_wireguardDevices_limit",
"description": "The limit includes primary and disabled devices. Choose 1 to 32. Values below the current device count are rejected.",
"parameters": [
{
"name": "email",
"in": "query",
"required": true,
"description": "Client email.",
"schema": {
"type": "string"
}
}
],
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"limit": {
"type": "integer",
"default": 5,
"description": "Maximum device count including primary."
}
},
"required": [
"limit"
]
},
"example": {
"limit": 5
}
}
}
},
"responses": {
"200": {
"description": "Successful response",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"success": {
"type": "boolean"
},
"msg": {
"type": "string"
},
"obj": {}
}
},
"example": {
"success": true,
"obj": {
"limit": 5,
"inbounds": [
{
"inboundId": 3,
"devices": [
{
"id": "primary",
"name": "",
"enable": true,
"privateKey": "...",
"publicKey": "...",
"allowedIPs": [
"10.0.0.2/32"
]
},
{
"id": "e3550bd1-0ba0-48b2-8a91-e57263a23d9d",
"name": "Phone",
"enable": true,
"privateKey": "...",
"publicKey": "...",
"allowedIPs": [
"10.0.0.3/32"
]
}
]
}
]
}
}
}
}
}
}
}
},
"/panel/api/clients/wireguardDevices/{deviceId}": {
"patch": {
"tags": [
"Clients"
],
"summary": "Rename or enable a WireGuard device.",
"operationId": "patch_panel_api_clients_wireguardDevices_deviceId",
"description": "The primary device is managed through the parent client. Disabled additional devices retain their reserved addresses.",
"parameters": [
{
"name": "email",
"in": "query",
"required": true,
"description": "Client email.",
"schema": {
"type": "string"
}
},
{
"name": "deviceId",
"in": "path",
"required": true,
"description": "Additional device UUID.",
"schema": {
"type": "string"
}
}
],
"requestBody": {
"required": false,
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"name": {
"type": "string",
"description": "New device name."
},
"enable": {
"type": "boolean",
"description": "Whether the device can connect."
}
}
},
"example": {
"name": "Work phone",
"enable": true
}
}
}
},
"responses": {
"200": {
"description": "Successful response",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"success": {
"type": "boolean"
},
"msg": {
"type": "string"
},
"obj": {}
}
},
"example": {
"success": true,
"obj": {
"limit": 5,
"inbounds": [
{
"inboundId": 3,
"devices": [
{
"id": "primary",
"name": "",
"enable": true,
"privateKey": "...",
"publicKey": "...",
"allowedIPs": [
"10.0.0.2/32"
]
},
{
"id": "e3550bd1-0ba0-48b2-8a91-e57263a23d9d",
"name": "Phone",
"enable": true,
"privateKey": "...",
"publicKey": "...",
"allowedIPs": [
"10.0.0.3/32"
]
}
]
}
]
}
}
}
}
}
}
},
"delete": {
"tags": [
"Clients"
],
"summary": "Delete an additional WireGuard device and release its address.",
"operationId": "delete_panel_api_clients_wireguardDevices_deviceId",
"description": "The device is removed from every attached WireGuard inbound. Its previously downloaded configuration loses access after the configuration is applied.",
"parameters": [
{
"name": "email",
"in": "query",
"required": true,
"description": "Client email.",
"schema": {
"type": "string"
}
},
{
"name": "deviceId",
"in": "path",
"required": true,
"description": "Additional device UUID.",
"schema": {
"type": "string"
}
}
],
"responses": {
"200": {
"description": "Successful response",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"success": {
"type": "boolean"
},
"msg": {
"type": "string"
},
"obj": {}
}
},
"example": {
"success": true,
"obj": {
"limit": 5,
"inbounds": [
{
"inboundId": 3,
"devices": [
{
"id": "primary",
"name": "",
"enable": true,
"privateKey": "...",
"publicKey": "...",
"allowedIPs": [
"10.0.0.2/32"
]
},
{
"id": "e3550bd1-0ba0-48b2-8a91-e57263a23d9d",
"name": "Phone",
"enable": true,
"privateKey": "...",
"publicKey": "...",
"allowedIPs": [
"10.0.0.3/32"
]
}
]
}
]
}
}
}
}
}
}
}
},
"/panel/api/clients/resetAllTraffics": {
"post": {
"tags": [