From e61afba608540037d1204af3f440bdd0f67ed042 Mon Sep 17 00:00:00 2001 From: Donald Zou Date: Sun, 17 Aug 2025 18:58:28 +0800 Subject: [PATCH] Completed feature for #843 --- src/dashboard.py | 4 ++-- src/modules/DashboardConfig.py | 2 +- src/modules/Peer.py | 23 +++++++++++++++---- src/static/app/src/App.vue | 5 +++- src/static/app/src/main.js | 16 ++++++------- .../src/stores/DashboardConfigurationStore.js | 2 +- 6 files changed, 34 insertions(+), 18 deletions(-) diff --git a/src/dashboard.py b/src/dashboard.py index 755eda6c..bbc4e93a 100644 --- a/src/dashboard.py +++ b/src/dashboard.py @@ -490,12 +490,12 @@ def API_updateDashboardConfigurationItem(): valid, msg = DashboardConfig.SetConfig( data["section"], data["key"], data['value']) if not valid: - return ResponseObject(False, msg, status_code=404) + return ResponseObject(False, msg) if data['section'] == "Server": if data['key'] == 'wg_conf_path': WireguardConfigurations.clear() WireguardConfigurations.clear() - InitWireguardConfigurationsList() + InitWireguardConfigurationsList() return ResponseObject(True, data=DashboardConfig.GetConfig(data["section"], data["key"])[1]) @app.get(f'{APP_PREFIX}/api/getDashboardAPIKeys') diff --git a/src/modules/DashboardConfig.py b/src/modules/DashboardConfig.py index a390de08..1b78b830 100644 --- a/src/modules/DashboardConfig.py +++ b/src/modules/DashboardConfig.py @@ -251,7 +251,7 @@ class DashboardConfig: except Exception as e: return False - def GetConfig(self, section, key) ->tuple[bool, bool] | tuple[bool, str] | tuple[bool, list[str]] | tuple[bool, None]: + def GetConfig(self, section, key) ->tuple[bool, bool] | tuple[bool, str] | tuple[bool, list[str]] | tuple[bool, None]: if section not in self.__config: return False, None diff --git a/src/modules/Peer.py b/src/modules/Peer.py index bf374e39..0c0f85dd 100644 --- a/src/modules/Peer.py +++ b/src/modules/Peer.py @@ -2,6 +2,9 @@ Peer """ import os, subprocess, uuid, random, re + +import jinja2 + from .PeerJob import PeerJob from .PeerShareLink import PeerShareLink from .Utilities import GenerateWireguardPublicKey, ValidateIPAddressesWithRange, ValidateDNSAddress @@ -136,7 +139,10 @@ class Peer: interfaceSection = { "PrivateKey": self.private_key, "Address": self.allowed_ip, - "MTU": self.mtu, + "MTU": ( + self.configuration.configurationInfo.OverridePeerSettings.MTU + if self.configuration.configurationInfo.OverridePeerSettings.MTU else self.mtu + ), "DNS": ( self.configuration.configurationInfo.OverridePeerSettings.DNS if self.configuration.configurationInfo.OverridePeerSettings.DNS else self.DNS @@ -144,9 +150,16 @@ class Peer: } peerSection = { "PublicKey": self.configuration.PublicKey, - "AllowedIPs": self.endpoint_allowed_ip, - "Endpoint": f'{self.configuration.DashboardConfig.GetConfig("Peers", "remote_endpoint")[1]}:{self.configuration.ListenPort}', - "PersistentKeepalive": self.keepalive, + "AllowedIPs": ( + self.configuration.configurationInfo.OverridePeerSettings.EndpointAllowedIPs + if self.configuration.configurationInfo.OverridePeerSettings.EndpointAllowedIPs else self.endpoint_allowed_ip + ), + "Endpoint": f'{(self.configuration.configurationInfo.OverridePeerSettings.PeerRemoteEndpoint if self.configuration.configurationInfo.OverridePeerSettings.PeerRemoteEndpoint else self.configuration.DashboardConfig.GetConfig("Peers", "remote_endpoint")[1])}:{(self.configuration.configurationInfo.OverridePeerSettings.ListenPort if self.configuration.configurationInfo.OverridePeerSettings.ListenPort else self.configuration.ListenPort)}', + "PersistentKeepalive": ( + self.configuration.configurationInfo.OverridePeerSettings.PersistentKeepalive + if self.configuration.configurationInfo.OverridePeerSettings.PersistentKeepalive + else self.keepalive + ), "PresharedKey": self.preshared_key } combine = [interfaceSection.items(), peerSection.items()] @@ -161,7 +174,7 @@ class Peer: peerConfiguration += f"{key} = {val}\n" return { "fileName": finalFilename, - "file": peerConfiguration + "file": jinja2.Template(peerConfiguration).render(configuration=self.configuration) } def getJobs(self): diff --git a/src/static/app/src/App.vue b/src/static/app/src/App.vue index 6e46310a..181aa11a 100644 --- a/src/static/app/src/App.vue +++ b/src/static/app/src/App.vue @@ -4,6 +4,7 @@ import {DashboardConfigurationStore} from "@/stores/DashboardConfigurationStore. import {computed, watch} from "vue"; const store = DashboardConfigurationStore(); import "@/utilities/wireguard.js" +import {fetchGet} from "@/utilities/fetch.js"; store.initCrossServerConfiguration(); if (window.IS_WGDASHBOARD_DESKTOP){ store.IsElectronApp = true; @@ -15,7 +16,9 @@ watch(store.CrossServerConfiguration, () => { deep: true }); const route = useRoute() - +fetchGet("/api/locale", {}, (res) => { + store.Locale = res.data +})