diff --git a/templates/wireguard/wireguard_peer_list.html b/templates/wireguard/wireguard_peer_list.html
index 93a3e9b..7c3e7e7 100644
--- a/templates/wireguard/wireguard_peer_list.html
+++ b/templates/wireguard/wireguard_peer_list.html
@@ -73,6 +73,7 @@
{% trans 'Throughput' %}:
{% trans 'Transfer' %}:
+ {% trans 'Location' %}: {% trans 'Primary Server' %}
{% trans 'Latest Handshake' %}:
{% trans 'Endpoints' %}:
@@ -124,6 +125,7 @@
{% trans 'Throughput' %}: --
{% trans 'Transfer' %}: --
{% trans 'Latest Handshake' %}: --
+{% trans 'Location' %}: --
{% trans 'Endpoints' %}: --
{% trans 'Allowed IPs' %}: --
@@ -325,6 +327,7 @@ var peerHandshake = peerElem.querySelector('[id^="peer-latest-handshake-"]').innerText; var peerEndpoints = peerElem.querySelector('[id^="peer-endpoints-"]').innerText; var peerAllowedIPs = peerElem.querySelector('[id^="peer-allowed-ips-"]').innerHTML; + var peerLocation = peerElem.querySelector('[id^="peer-location-"]').innerText; // Update the modal fields with the card values $('#peerPreviewModalLabel').text(peerNameFromCard); @@ -332,6 +335,7 @@ $('#peerTransfer').text(peerTransfer); $('#peerHandshake').text(peerHandshake); $('#peerEndpoints').text(peerEndpoints); + $('#peerLocation').text(peerLocation); $('#peerAllowedIPs').html(peerAllowedIPs); $('#editPeerButton').attr('href', '/peer/manage/?peer=' + uuid); $('#downloadConfigButton').attr('href', '/tools/download_peer_config/?uuid=' + uuid); @@ -498,6 +502,13 @@ return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i]; }; + const getPeerLocationLabel = (peerInfo) => { + if (peerInfo && peerInfo.source_uuid && String(peerInfo.source_uuid).trim() !== '') { + return peerInfo.source_name || ''; + } + return "{% trans 'Primary Server' %}"; + }; + // Fetch Wireguard status and update UI document.addEventListener('DOMContentLoaded', function() { const fetchWireguardStatus = async (cachePrevious = null) => { @@ -573,6 +584,7 @@ $('#peerEndpoints').text(peerInfo.endpoints); const allowedIpsModalElement = document.getElementById('peerAllowedIPs'); checkAllowedIps(allowedIpsModalElement, peerInfo['allowed-ips']); + $('#peerLocation').text(getPeerLocationLabel(peerInfo)); } } } @@ -585,11 +597,15 @@ const latestHandshake = peerDiv.querySelector(`#peer-latest-handshake-${escapedPeerId}`); const endpoints = peerDiv.querySelector(`#peer-endpoints-${escapedPeerId}`); const allowedIps = peerDiv.querySelector(`#peer-allowed-ips-${escapedPeerId}`); + const location = peerDiv.querySelector(`#peer-location-${escapedPeerId}`); transfer.textContent = `${convertBytes(peerInfo.transfer.tx)} TX, ${convertBytes(peerInfo.transfer.rx)} RX`; latestHandshake.textContent = `${peerInfo['latest-handshakes'] !== '0' ? new Date(parseInt(peerInfo['latest-handshakes']) * 1000).toLocaleString() : '0'}`; endpoints.textContent = `${peerInfo.endpoints}`; checkAllowedIps(allowedIps, peerInfo['allowed-ips']); + if (location) { + location.textContent = getPeerLocationLabel(peerInfo); + } }; const checkAllowedIps = (allowedIpsElement, allowedIpsApiResponse) => { diff --git a/wireguard_peer/views.py b/wireguard_peer/views.py index 1e39926..342fdad 100644 --- a/wireguard_peer/views.py +++ b/wireguard_peer/views.py @@ -8,6 +8,7 @@ from django.http import Http404 from django.shortcuts import get_object_or_404, redirect, render from django.utils.translation import gettext_lazy as _ +from cluster.models import ClusterSettings from user_manager.models import UserAcl from wgwadmlibrary.tools import check_sort_order_conflict, deduplicate_sort_order, default_sort_peers, \ user_allowed_instances, user_allowed_peers, user_has_access_to_instance, user_has_access_to_peer @@ -82,11 +83,17 @@ def view_wireguard_peer_list(request): if settings.WIREGUARD_STATUS_CACHE_ENABLED: refresh_interval = settings.WIREGUARD_STATUS_CACHE_REFRESH_INTERVAL + if ClusterSettings.objects.filter(name='cluster_settings', enabled=True).exists(): + cluster_enabled = True + else: + cluster_enabled = False + context = { 'page_title': page_title, 'wireguard_instances': wireguard_instances, 'current_instance': current_instance, 'peer_list': peer_list, 'add_peer_enabled': add_peer_enabled, 'user_acl': user_acl, 'refresh_interval': refresh_interval, 'load_from_cache': load_from_cache, 'cache_previous_count': cache_previous_count, + 'cluster_enabled': cluster_enabled, } return render(request, 'wireguard/wireguard_peer_list.html', context)