mirror of
https://github.com/donaldzou/WGDashboard.git
synced 2026-10-30 01:12:07 +00:00
fix: addPeers uses OverridePeerSettings for DNS and AllowedIPs fallback (#1310)
* fix: addPeers uses OverridePeerSettings for DNS and AllowedIPs fallback When adding a peer via the API without explicit DNS or endpoint_allowed_ip values, the endpoint fell back directly to global wg-dashboard.ini defaults, ignoring any per-configuration OverridePeerSettings. This caused new peers to be stored with the wrong DNS and AllowedIPs in the database even when the configuration had overrides set. Resolve by fetching the configuration's OverridePeerSettings before the global defaults. The priority is now: request body → OverridePeerSettings → global default. The existing config lookup that happened later in the function is removed as it is now done earlier. Note: downloadPeer already applied OverridePeerSettings at download time, so client configs were correct; only the stored peer data was affected. * fix: addPeers applies OverridePeerSettings for MTU and PersistentKeepalive Extend the peer-settings priority chain (request body → OverridePeerSettings → global default) to MTU and PersistentKeepalive, matching the same pattern already applied to DNS and EndpointAllowedIPs. * style: align addPeers OverridePeerSettings fallback with project code style
This commit is contained in:
+19
-5
@@ -945,8 +945,17 @@ def API_addPeers(configName):
|
|||||||
allowed_ips: list[str] = data.get('allowed_ips', [])
|
allowed_ips: list[str] = data.get('allowed_ips', [])
|
||||||
allowed_ips_validation: bool = data.get('allowed_ips_validation', True)
|
allowed_ips_validation: bool = data.get('allowed_ips_validation', True)
|
||||||
|
|
||||||
endpoint_allowed_ip: str = data.get('endpoint_allowed_ip', DashboardConfig.GetConfig("Peers", "peer_endpoint_allowed_ip")[1])
|
config = WireguardConfigurations.get(configName)
|
||||||
dns_addresses: str = data.get('DNS', DashboardConfig.GetConfig("Peers", "peer_global_DNS")[1])
|
overridePeerSettings = config.configurationInfo.OverridePeerSettings
|
||||||
|
|
||||||
|
endpoint_allowed_ip: str = data.get('endpoint_allowed_ip', (
|
||||||
|
overridePeerSettings.EndpointAllowedIPs
|
||||||
|
if overridePeerSettings.EndpointAllowedIPs else DashboardConfig.GetConfig("Peers", "peer_endpoint_allowed_ip")[1]
|
||||||
|
))
|
||||||
|
dns_addresses: str = data.get('DNS', (
|
||||||
|
overridePeerSettings.DNS
|
||||||
|
if overridePeerSettings.DNS else DashboardConfig.GetConfig("Peers", "peer_global_DNS")[1]
|
||||||
|
))
|
||||||
|
|
||||||
|
|
||||||
mtu: int = data.get('mtu', None)
|
mtu: int = data.get('mtu', None)
|
||||||
@@ -955,7 +964,10 @@ def API_addPeers(configName):
|
|||||||
preshared_key: str = data.get('preshared_key', "")
|
preshared_key: str = data.get('preshared_key', "")
|
||||||
|
|
||||||
if type(mtu) is not int or mtu < 0 or mtu > 1460:
|
if type(mtu) is not int or mtu < 0 or mtu > 1460:
|
||||||
default: str = DashboardConfig.GetConfig("Peers", "peer_mtu")[1]
|
default: str = (
|
||||||
|
str(overridePeerSettings.MTU)
|
||||||
|
if overridePeerSettings.MTU else DashboardConfig.GetConfig("Peers", "peer_mtu")[1]
|
||||||
|
)
|
||||||
if default.isnumeric():
|
if default.isnumeric():
|
||||||
try:
|
try:
|
||||||
mtu = int(default)
|
mtu = int(default)
|
||||||
@@ -964,7 +976,10 @@ def API_addPeers(configName):
|
|||||||
else:
|
else:
|
||||||
mtu = 0
|
mtu = 0
|
||||||
if type(keep_alive) is not int or keep_alive < 0:
|
if type(keep_alive) is not int or keep_alive < 0:
|
||||||
default = DashboardConfig.GetConfig("Peers", "peer_keep_alive")[1]
|
default = (
|
||||||
|
str(overridePeerSettings.PersistentKeepalive)
|
||||||
|
if overridePeerSettings.PersistentKeepalive else DashboardConfig.GetConfig("Peers", "peer_keep_alive")[1]
|
||||||
|
)
|
||||||
if default.isnumeric():
|
if default.isnumeric():
|
||||||
try:
|
try:
|
||||||
keep_alive = int(default)
|
keep_alive = int(default)
|
||||||
@@ -973,7 +988,6 @@ def API_addPeers(configName):
|
|||||||
else:
|
else:
|
||||||
keep_alive = 0
|
keep_alive = 0
|
||||||
|
|
||||||
config = WireguardConfigurations.get(configName)
|
|
||||||
if not config.getStatus():
|
if not config.getStatus():
|
||||||
config.toggleConfiguration()
|
config.toggleConfiguration()
|
||||||
ipStatus, availableIps = config.getAvailableIP(-1)
|
ipStatus, availableIps = config.getAvailableIP(-1)
|
||||||
|
|||||||
Reference in New Issue
Block a user