mirror of
https://github.com/donaldzou/WGDashboard.git
synced 2025-12-20 10:26:17 +00:00
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.
This commit is contained in:
@@ -92,11 +92,13 @@ def peerInformationBackgroundThread():
|
|||||||
c.getPeersTransfer()
|
c.getPeersTransfer()
|
||||||
c.getPeersEndpoint()
|
c.getPeersEndpoint()
|
||||||
c.getPeers()
|
c.getPeers()
|
||||||
if delay == 6:
|
if DashboardConfig.GetConfig('WireGuardConfiguration', 'peer_tracking')[1] is True:
|
||||||
if c.configurationInfo.PeerTrafficTracking:
|
print("[WGDashboard] Tracking Peers")
|
||||||
c.logPeersTraffic()
|
if delay == 6:
|
||||||
if c.configurationInfo.PeerHistoricalEndpointTracking:
|
if c.configurationInfo.PeerTrafficTracking:
|
||||||
c.logPeersHistoryEndpoint()
|
c.logPeersTraffic()
|
||||||
|
if c.configurationInfo.PeerHistoricalEndpointTracking:
|
||||||
|
c.logPeersHistoryEndpoint()
|
||||||
c.getRestrictedPeersList()
|
c.getRestrictedPeersList()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
app.logger.error(f"[WGDashboard] Background Thread #1 Error", e)
|
app.logger.error(f"[WGDashboard] Background Thread #1 Error", e)
|
||||||
|
|||||||
@@ -85,7 +85,8 @@ class DashboardConfig:
|
|||||||
"enable": "true",
|
"enable": "true",
|
||||||
},
|
},
|
||||||
"WireGuardConfiguration": {
|
"WireGuardConfiguration": {
|
||||||
"autostart": ""
|
"autostart": "",
|
||||||
|
"peer_tracking": "false"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,30 +4,61 @@ import LocaleText from "@/components/text/localeText.vue";
|
|||||||
import ConfigurationTracking
|
import ConfigurationTracking
|
||||||
from "@/components/settingsComponent/dashboardWireguardConfigurationTrackingComponents/configurationTracking.vue";
|
from "@/components/settingsComponent/dashboardWireguardConfigurationTrackingComponents/configurationTracking.vue";
|
||||||
import {WireguardConfigurationsStore} from "@/stores/WireguardConfigurationsStore.js";
|
import {WireguardConfigurationsStore} from "@/stores/WireguardConfigurationsStore.js";
|
||||||
import {onMounted, ref} from "vue";
|
import {onMounted, ref, watch} from "vue";
|
||||||
import {fetchGet} from "@/utilities/fetch.js";
|
import {fetchGet, fetchPost} from "@/utilities/fetch.js";
|
||||||
|
import {DashboardConfigurationStore} from "@/stores/DashboardConfigurationStore.js";
|
||||||
|
|
||||||
const store = WireguardConfigurationsStore()
|
const store = WireguardConfigurationsStore()
|
||||||
|
const dashboardStore = DashboardConfigurationStore()
|
||||||
|
const peerTrackingStatus = ref(dashboardStore.Configuration.WireGuardConfiguration.peer_tracking)
|
||||||
const loaded = ref(false)
|
const loaded = ref(false)
|
||||||
const trackingData = ref({})
|
const trackingData = ref({})
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
|
if (peerTrackingStatus.value){
|
||||||
|
await loadData()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
const loadData = async () => {
|
||||||
await fetchGet("/api/getPeerTrackingTableCounts", {}, (ref) => {
|
await fetchGet("/api/getPeerTrackingTableCounts", {}, (ref) => {
|
||||||
if (ref.status){
|
if (ref.status){
|
||||||
trackingData.value = ref.data
|
trackingData.value = ref.data
|
||||||
}
|
}
|
||||||
loaded.value = true
|
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()
|
||||||
|
}
|
||||||
|
})
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div class="card">
|
<div class="card">
|
||||||
<div class="card-header">
|
<div class="card-header d-flex align-items-center">
|
||||||
<h6 class="my-2">
|
<h6 class="my-2">
|
||||||
<LocaleText t="Peer Tracking"></LocaleText>
|
<LocaleText t="Peer Tracking"></LocaleText>
|
||||||
</h6>
|
</h6>
|
||||||
|
<div class="form-check form-switch ms-auto">
|
||||||
|
<input class="form-check-input"
|
||||||
|
v-model="peerTrackingStatus"
|
||||||
|
type="checkbox" role="switch" id="peerTrackingStatus">
|
||||||
|
<label class="form-check-label" for="peerTrackingStatus">
|
||||||
|
<LocaleText t="Enabled" v-if="peerTrackingStatus"></LocaleText>
|
||||||
|
<LocaleText t="Disabled" v-else></LocaleText>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="card-body d-flex flex-column gap-3">
|
<div class="card-body d-flex flex-column gap-3" v-if="peerTrackingStatus">
|
||||||
<template v-if="!loaded">
|
<template v-if="!loaded">
|
||||||
<div class="spinner-border text-body m-auto"></div>
|
<div class="spinner-border text-body m-auto"></div>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
Reference in New Issue
Block a user