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() + } + }) })