mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-09-04 09:27:15 +00:00
fix: preserve per-inbound WireGuard peer addresses (#6344)
Clients are stored once per email in the client table, so when the same email exists on more than one WireGuard inbound the shared record's AllowedIPs and PreSharedKey win for every inbound. A client present on both a WG and an AWG tunnel was emitted with one tunnel's address on both, so the second tunnel's peer got the wrong allowedIPs. Read the per-inbound client settings for WireGuard inbounds and, when the inbound carries its own entry for that email, use its AllowedIPs and PreSharedKey when building the peer.
This commit is contained in:
@@ -179,6 +179,16 @@ func (s *XrayService) GetXrayConfig() (*xray.Config, error) {
|
||||
}
|
||||
settings := map[string]any{}
|
||||
_ = json.Unmarshal([]byte(inbound.Settings), &settings)
|
||||
var wireguardClientsByEmail map[string]model.Client
|
||||
if inbound.Protocol == model.WireGuard {
|
||||
inboundClients, _ := ParseInboundSettingsClients(inbound.Settings)
|
||||
if len(inboundClients) > 0 {
|
||||
wireguardClientsByEmail = make(map[string]model.Client, len(inboundClients))
|
||||
for _, client := range inboundClients {
|
||||
wireguardClientsByEmail[strings.ToLower(strings.TrimSpace(client.Email))] = client
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dbClients, listErr := s.inboundService.clientService.ListForInbound(nil, inbound.Id)
|
||||
if listErr != nil {
|
||||
@@ -244,6 +254,10 @@ func (s *XrayService) GetXrayConfig() (*xray.Config, error) {
|
||||
entry["auth"] = c.Auth
|
||||
}
|
||||
case model.WireGuard:
|
||||
if inboundClient, ok := wireguardClientsByEmail[strings.ToLower(strings.TrimSpace(c.Email))]; ok {
|
||||
c.AllowedIPs = inboundClient.AllowedIPs
|
||||
c.PreSharedKey = inboundClient.PreSharedKey
|
||||
}
|
||||
wgPeers = append(wgPeers, model.WireguardPeerFromClient(c))
|
||||
continue
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user