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})")
|
||||
|
||||
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 = {
|
||||
"email": email,
|
||||
"enable": True,
|
||||
"privateKey": keys["privateKey"],
|
||||
"publicKey": keys["publicKey"],
|
||||
"preSharedKey": "",
|
||||
"allowedIPs": ["0.0.0.0/0", "::/0"],
|
||||
"allowedIPs": [],
|
||||
"keepAlive": 0,
|
||||
"totalGB": total_gb,
|
||||
"expiryTime": int(expiry_time),
|
||||
@@ -337,12 +339,23 @@ class XuiClient:
|
||||
}
|
||||
await self.add_client_raw(client, [inbound_id])
|
||||
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 {
|
||||
"protocol": "wireguard",
|
||||
"email": email,
|
||||
"inbound_id": inbound_id,
|
||||
"privateKey": keys["privateKey"],
|
||||
"publicKey": keys["publicKey"],
|
||||
"allowedIPs": allowed_ips,
|
||||
"expiryTime": int(expiry_time),
|
||||
"details": details,
|
||||
"inbound": {
|
||||
|
||||
@@ -63,7 +63,8 @@
|
||||
<p class="muted" style="margin:0">Ключи клиента (конфиг соберите в 3x-ui или ниже):</p>
|
||||
<pre class="mono">PrivateKey = {{ created.privateKey }}
|
||||
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 %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user