From 87ff8afefe55fa06589532ae000a5f6eb51d5795 Mon Sep 17 00:00:00 2001 From: Donald Zou Date: Fri, 19 Dec 2025 09:22:45 +0800 Subject: [PATCH] Add peer tracking toggle to WireGuard dashboard Introduces a 'peer_tracking' configuration option for WireGuard in DashboardConfig and updates the dashboard background thread to respect this setting. The Vue component now includes a UI toggle for peer tracking, updates the server configuration via API, and conditionally loads tracking data based on the toggle state. --- src/dashboard.py | 12 +++--- src/modules/DashboardConfig.py | 3 +- ...ashboardWireguardConfigurationTracking.vue | 39 +++++++++++++++++-- 3 files changed, 44 insertions(+), 10 deletions(-) diff --git a/src/dashboard.py b/src/dashboard.py index 4b6411cd..90f02064 100644 --- a/src/dashboard.py +++ b/src/dashboard.py @@ -92,11 +92,13 @@ def peerInformationBackgroundThread(): c.getPeersTransfer() c.getPeersEndpoint() c.getPeers() - if delay == 6: - if c.configurationInfo.PeerTrafficTracking: - c.logPeersTraffic() - if c.configurationInfo.PeerHistoricalEndpointTracking: - c.logPeersHistoryEndpoint() + if DashboardConfig.GetConfig('WireGuardConfiguration', 'peer_tracking')[1] is True: + print("[WGDashboard] Tracking Peers") + if delay == 6: + if c.configurationInfo.PeerTrafficTracking: + c.logPeersTraffic() + if c.configurationInfo.PeerHistoricalEndpointTracking: + c.logPeersHistoryEndpoint() c.getRestrictedPeersList() except Exception as e: app.logger.error(f"[WGDashboard] Background Thread #1 Error", e) diff --git a/src/modules/DashboardConfig.py b/src/modules/DashboardConfig.py index 5fe28626..118297f7 100644 --- a/src/modules/DashboardConfig.py +++ b/src/modules/DashboardConfig.py @@ -85,7 +85,8 @@ class DashboardConfig: "enable": "true", }, "WireGuardConfiguration": { - "autostart": "" + "autostart": "", + "peer_tracking": "false" } } diff --git a/src/static/app/src/components/settingsComponent/dashboardWireguardConfigurationTracking.vue b/src/static/app/src/components/settingsComponent/dashboardWireguardConfigurationTracking.vue index 64ed3c6d..9f1dddeb 100644 --- a/src/static/app/src/components/settingsComponent/dashboardWireguardConfigurationTracking.vue +++ b/src/static/app/src/components/settingsComponent/dashboardWireguardConfigurationTracking.vue @@ -4,30 +4,61 @@ import LocaleText from "@/components/text/localeText.vue"; import ConfigurationTracking from "@/components/settingsComponent/dashboardWireguardConfigurationTrackingComponents/configurationTracking.vue"; import {WireguardConfigurationsStore} from "@/stores/WireguardConfigurationsStore.js"; -import {onMounted, ref} from "vue"; -import {fetchGet} from "@/utilities/fetch.js"; +import {onMounted, ref, watch} from "vue"; +import {fetchGet, fetchPost} from "@/utilities/fetch.js"; +import {DashboardConfigurationStore} from "@/stores/DashboardConfigurationStore.js"; const store = WireguardConfigurationsStore() +const dashboardStore = DashboardConfigurationStore() +const peerTrackingStatus = ref(dashboardStore.Configuration.WireGuardConfiguration.peer_tracking) const loaded = ref(false) const trackingData = ref({}) onMounted(async () => { + if (peerTrackingStatus.value){ + await loadData() + } +}) + +const loadData = async () => { await fetchGet("/api/getPeerTrackingTableCounts", {}, (ref) => { if (ref.status){ trackingData.value = ref.data } loaded.value = true }) +} + +watch(peerTrackingStatus, async (newVal) => { + await fetchPost("/api/updateDashboardConfigurationItem", { + section: "WireGuardConfiguration", + key: "peer_tracking", + value: newVal + }, async (res) => { + if (res.status){ + dashboardStore.newMessage("Server", newVal ? "Peer tracking enabled" : "Peer tracking disabled", "success") + if (newVal) await loadData() + } + }) })