mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-04 16:34:52 +03:00
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:
@@ -506,7 +506,21 @@ export const EXAMPLES: Record<string, unknown> = {
|
||||
"totalGB": 0,
|
||||
"trafficReset": "never",
|
||||
"trafficResetDay": 1,
|
||||
"updated_at": 0
|
||||
"updated_at": 0,
|
||||
"wgDeviceLimit": 0,
|
||||
"wireguardDevices": [
|
||||
{
|
||||
"allowedIPs": [
|
||||
""
|
||||
],
|
||||
"enable": false,
|
||||
"id": "",
|
||||
"name": "",
|
||||
"preSharedKey": "",
|
||||
"privateKey": "",
|
||||
"publicKey": ""
|
||||
}
|
||||
]
|
||||
},
|
||||
"ClientInbound": {
|
||||
"clientId": 0,
|
||||
@@ -601,7 +615,21 @@ export const EXAMPLES: Record<string, unknown> = {
|
||||
"trafficReset": "",
|
||||
"trafficResetDay": 0,
|
||||
"updatedAt": 0,
|
||||
"uuid": ""
|
||||
"uuid": "",
|
||||
"wgDeviceLimit": 0,
|
||||
"wireguardDevices": [
|
||||
{
|
||||
"allowedIPs": [
|
||||
""
|
||||
],
|
||||
"enable": false,
|
||||
"id": "",
|
||||
"name": "",
|
||||
"preSharedKey": "",
|
||||
"privateKey": "",
|
||||
"publicKey": ""
|
||||
}
|
||||
]
|
||||
},
|
||||
"ClientRenewalPreview": {
|
||||
"canRenew": true,
|
||||
@@ -1350,5 +1378,16 @@ export const EXAMPLES: Record<string, unknown> = {
|
||||
"id": 0,
|
||||
"password": "",
|
||||
"username": ""
|
||||
},
|
||||
"WireguardDevice": {
|
||||
"allowedIPs": [
|
||||
""
|
||||
],
|
||||
"enable": false,
|
||||
"id": "",
|
||||
"name": "",
|
||||
"preSharedKey": "",
|
||||
"privateKey": "",
|
||||
"publicKey": ""
|
||||
}
|
||||
};
|
||||
|
||||
@@ -2125,6 +2125,15 @@ export const SCHEMAS: Record<string, unknown> = {
|
||||
"description": "Last update timestamp",
|
||||
"format": "int64",
|
||||
"type": "integer"
|
||||
},
|
||||
"wgDeviceLimit": {
|
||||
"type": "integer"
|
||||
},
|
||||
"wireguardDevices": {
|
||||
"items": {
|
||||
"$ref": "#/components/schemas/WireguardDevice"
|
||||
},
|
||||
"type": "array"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
@@ -2339,6 +2348,15 @@ export const SCHEMAS: Record<string, unknown> = {
|
||||
},
|
||||
"uuid": {
|
||||
"type": "string"
|
||||
},
|
||||
"wgDeviceLimit": {
|
||||
"type": "integer"
|
||||
},
|
||||
"wireguardDevices": {
|
||||
"items": {
|
||||
"$ref": "#/components/schemas/WireguardDevice"
|
||||
},
|
||||
"type": "array"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
@@ -2374,7 +2392,9 @@ export const SCHEMAS: Record<string, unknown> = {
|
||||
"trafficReset",
|
||||
"trafficResetDay",
|
||||
"updatedAt",
|
||||
"uuid"
|
||||
"uuid",
|
||||
"wgDeviceLimit",
|
||||
"wireguardDevices"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
@@ -5406,5 +5426,43 @@ export const SCHEMAS: Record<string, unknown> = {
|
||||
"username"
|
||||
],
|
||||
"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"
|
||||
}
|
||||
};
|
||||
|
||||
@@ -501,6 +501,8 @@ export interface Client {
|
||||
trafficReset?: string;
|
||||
trafficResetDay?: number;
|
||||
updated_at?: number;
|
||||
wgDeviceLimit?: number;
|
||||
wireguardDevices?: WireguardDevice[];
|
||||
}
|
||||
|
||||
export interface ClientInbound {
|
||||
@@ -555,6 +557,8 @@ export interface ClientRecord {
|
||||
trafficResetDay: number;
|
||||
updatedAt: number;
|
||||
uuid: string;
|
||||
wgDeviceLimit: number;
|
||||
wireguardDevices: WireguardDevice[];
|
||||
}
|
||||
|
||||
export interface ClientRenewalPreview {
|
||||
@@ -1235,3 +1239,13 @@ export interface User {
|
||||
username: string;
|
||||
}
|
||||
|
||||
export interface WireguardDevice {
|
||||
allowedIPs: string[];
|
||||
enable: boolean;
|
||||
id: string;
|
||||
name: string;
|
||||
preSharedKey?: string;
|
||||
privateKey: string;
|
||||
publicKey: string;
|
||||
}
|
||||
|
||||
|
||||
@@ -520,6 +520,8 @@ export const ClientSchema = z.object({
|
||||
trafficReset: z.enum(['never', 'hourly', 'daily', 'weekly', 'monthly']).optional(),
|
||||
trafficResetDay: z.number().int().min(1).max(31).optional(),
|
||||
updated_at: z.number().int().optional(),
|
||||
wgDeviceLimit: z.number().int().optional(),
|
||||
wireguardDevices: z.array(z.lazy(() => WireguardDeviceSchema)).optional(),
|
||||
});
|
||||
export type Client = z.infer<typeof ClientSchema>;
|
||||
|
||||
@@ -577,6 +579,8 @@ export const ClientRecordSchema = z.object({
|
||||
trafficResetDay: z.number().int(),
|
||||
updatedAt: z.number().int(),
|
||||
uuid: z.string(),
|
||||
wgDeviceLimit: z.number().int(),
|
||||
wireguardDevices: z.array(z.lazy(() => WireguardDeviceSchema)),
|
||||
});
|
||||
export type ClientRecord = z.infer<typeof ClientRecordSchema>;
|
||||
|
||||
@@ -1310,3 +1314,14 @@ export const UserSchema = z.object({
|
||||
});
|
||||
export type User = z.infer<typeof UserSchema>;
|
||||
|
||||
export const WireguardDeviceSchema = z.object({
|
||||
allowedIPs: z.array(z.string()),
|
||||
enable: z.boolean(),
|
||||
id: z.string(),
|
||||
name: z.string(),
|
||||
preSharedKey: z.string().optional(),
|
||||
privateKey: z.string(),
|
||||
publicKey: z.string(),
|
||||
});
|
||||
export type WireguardDevice = z.infer<typeof WireguardDeviceSchema>;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user