Fix WireGuard client create: let 3x-ui allocate unique allowedIPs
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+14
-1
@@ -320,13 +320,15 @@ class XuiClient:
|
|||||||
raise XuiApiError(f"Inbound #{inbound_id} — не WireGuard (protocol={proto})")
|
raise XuiApiError(f"Inbound #{inbound_id} — не WireGuard (protocol={proto})")
|
||||||
|
|
||||||
keys = await self.get_new_x25519()
|
keys = await self.get_new_x25519()
|
||||||
|
# Leave allowedIPs empty — 3x-ui allocates a unique peer address
|
||||||
|
# (e.g. 10.0.0.3/32). Sending 0.0.0.0/0 collides with other clients.
|
||||||
client = {
|
client = {
|
||||||
"email": email,
|
"email": email,
|
||||||
"enable": True,
|
"enable": True,
|
||||||
"privateKey": keys["privateKey"],
|
"privateKey": keys["privateKey"],
|
||||||
"publicKey": keys["publicKey"],
|
"publicKey": keys["publicKey"],
|
||||||
"preSharedKey": "",
|
"preSharedKey": "",
|
||||||
"allowedIPs": ["0.0.0.0/0", "::/0"],
|
"allowedIPs": [],
|
||||||
"keepAlive": 0,
|
"keepAlive": 0,
|
||||||
"totalGB": total_gb,
|
"totalGB": total_gb,
|
||||||
"expiryTime": int(expiry_time),
|
"expiryTime": int(expiry_time),
|
||||||
@@ -337,12 +339,23 @@ class XuiClient:
|
|||||||
}
|
}
|
||||||
await self.add_client_raw(client, [inbound_id])
|
await self.add_client_raw(client, [inbound_id])
|
||||||
details = await self.get_client(email)
|
details = await self.get_client(email)
|
||||||
|
allowed_ips = []
|
||||||
|
if isinstance(details, dict):
|
||||||
|
allowed_ips = details.get("allowedIPs") or details.get("allowed_ips") or []
|
||||||
|
if not allowed_ips:
|
||||||
|
# Client may be nested under inbounds / clients list
|
||||||
|
for key in ("client", "obj"):
|
||||||
|
nested = details.get(key)
|
||||||
|
if isinstance(nested, dict) and nested.get("allowedIPs"):
|
||||||
|
allowed_ips = nested["allowedIPs"]
|
||||||
|
break
|
||||||
return {
|
return {
|
||||||
"protocol": "wireguard",
|
"protocol": "wireguard",
|
||||||
"email": email,
|
"email": email,
|
||||||
"inbound_id": inbound_id,
|
"inbound_id": inbound_id,
|
||||||
"privateKey": keys["privateKey"],
|
"privateKey": keys["privateKey"],
|
||||||
"publicKey": keys["publicKey"],
|
"publicKey": keys["publicKey"],
|
||||||
|
"allowedIPs": allowed_ips,
|
||||||
"expiryTime": int(expiry_time),
|
"expiryTime": int(expiry_time),
|
||||||
"details": details,
|
"details": details,
|
||||||
"inbound": {
|
"inbound": {
|
||||||
|
|||||||
@@ -63,7 +63,8 @@
|
|||||||
<p class="muted" style="margin:0">Ключи клиента (конфиг соберите в 3x-ui или ниже):</p>
|
<p class="muted" style="margin:0">Ключи клиента (конфиг соберите в 3x-ui или ниже):</p>
|
||||||
<pre class="mono">PrivateKey = {{ created.privateKey }}
|
<pre class="mono">PrivateKey = {{ created.privateKey }}
|
||||||
PublicKey = {{ created.publicKey }}
|
PublicKey = {{ created.publicKey }}
|
||||||
{% if created.inbound %}Endpoint port = {{ created.inbound.port }}{% endif %}</pre>
|
{% if created.allowedIPs %}AllowedIPs = {{ created.allowedIPs | join(', ') }}
|
||||||
|
{% endif %}{% if created.inbound %}Endpoint port = {{ created.inbound.port }}{% endif %}</pre>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user