diff --git a/cluster/models.py b/cluster/models.py index 2150901..591904d 100644 --- a/cluster/models.py +++ b/cluster/models.py @@ -57,6 +57,10 @@ class Worker(models.Model): def __str__(self): return self.name + @property + def server_address(self): + return self.hostname or self.ip_address or '' + @property def display_name(self): cluster_settings = ClusterSettings.objects.first() @@ -98,7 +102,6 @@ class Worker(models.Model): return False - class WorkerStatus(models.Model): worker = models.OneToOneField(Worker, on_delete=models.CASCADE) last_seen = models.DateTimeField(auto_now=True) diff --git a/templates/vpn_invite/public_vpn_invite.html b/templates/vpn_invite/public_vpn_invite.html index c1689c5..0ed53b8 100644 --- a/templates/vpn_invite/public_vpn_invite.html +++ b/templates/vpn_invite/public_vpn_invite.html @@ -129,6 +129,16 @@ {{ invite_settings.download_5_label }} {% endif %} + {% if cluster_settings and servers|length > 1 %} +
+ + +
+ {% endif %}
Download Config View QR Code @@ -152,33 +162,65 @@ var downloadConfigButton = document.getElementById("downloadConfigButton"); var qrCodeContainer = document.getElementById("qrCodeContainer"); var hasPrivateKey = {% if peer_invite.peer.private_key %}true{% else %}false{% endif %}; - - viewQrButton.addEventListener("click", function(event) { - event.preventDefault(); - if (!hasPrivateKey) { + + viewQrButton.addEventListener("click", function (event) { + event.preventDefault(); + if (!hasPrivateKey) { + return false; + } + if (qrCodeContainer.style.display === "none" || qrCodeContainer.style.display === "") { + // Always refresh image on click to ensure current server selection is respected + qrCodeContainer.innerHTML = ''; + + var img = document.createElement("img"); + var server = document.getElementById("server_select") ? document.getElementById("server_select").value : ""; + var url = "/invite/download_config/?token={{ peer_invite.uuid }}&password={{ password }}&format=qrcode"; + if (server) { + url += "&server=" + encodeURIComponent(server); + } + img.src = url; + img.alt = "QR Code"; + qrCodeContainer.appendChild(img); + + qrCodeContainer.style.display = "block"; + } else { + qrCodeContainer.style.display = "none"; + } + }); + + downloadConfigButton.addEventListener("click", function (event) { + if (!hasPrivateKey) { + if (!confirm("This configuration does not contain a private key. You must add the private key manually in your client before using it.")) { + event.preventDefault(); return false; } - if (qrCodeContainer.style.display === "none" || qrCodeContainer.style.display === "") { - if (qrCodeContainer.getElementsByTagName("img").length === 0) { - var img = document.createElement("img"); - img.src = "/invite/download_config/?token={{ peer_invite.uuid }}&password={{ password }}&format=qrcode"; - img.alt = "QR Code"; - qrCodeContainer.appendChild(img); - } - qrCodeContainer.style.display = "block"; - } else { - qrCodeContainer.style.display = "none"; - } - }); - - downloadConfigButton.addEventListener("click", function(event) { - if (!hasPrivateKey) { - if (!confirm("This configuration does not contain a private key. You must add the private key manually in your client before using it.")) { - event.preventDefault(); - return false; - } + } + var server = document.getElementById("server_select") ? document.getElementById("server_select").value : ""; + var url = "/invite/download_config/?token={{ peer_invite.uuid }}&password={{ password }}"; + if (server) { + url += "&server=" + encodeURIComponent(server); + } + this.href = url; + }); + + // Update href immediately if dropdown changes (optional, but good for UX) + var serverSelect = document.getElementById("server_select"); + if (serverSelect) { + serverSelect.addEventListener("change", function () { + var server = this.value; + var url = "/invite/download_config/?token={{ peer_invite.uuid }}&password={{ password }}"; + if (server) { + url += "&server=" + encodeURIComponent(server); + } + downloadConfigButton.href = url; + + // If QR code is visible, reload it + if (qrCodeContainer.style.display === "block") { + viewQrButton.click(); // Hide + setTimeout(function () { viewQrButton.click(); }, 100); // Show again } }); + } }); {% endif %} diff --git a/templates/wireguard/wireguard_peer_list.html b/templates/wireguard/wireguard_peer_list.html index a2df1f8..37cf215 100644 --- a/templates/wireguard/wireguard_peer_list.html +++ b/templates/wireguard/wireguard_peer_list.html @@ -190,25 +190,35 @@
+ {% if cluster_settings and servers|length > 1 %} +
+ +
+ {% endif %} + + {% trans 'Config' %} + {% trans 'QR Code' %} + {% trans 'VPN Invite' %} + {% trans 'Edit' %} + + - {% else %} - -

- {% trans 'Add WireGuard Instance' %} -

- {% endif %} +{% else %} + +

+ {% trans 'Add WireGuard Instance' %} +

+{% endif %} {% endblock %} @@ -279,21 +289,46 @@ -