mirror of
https://github.com/eduardogsilva/wireguard_webadmin.git
synced 2025-08-26 21:31:14 +00:00
Add handling for peers without private keys and update translations
This commit is contained in:
@@ -130,8 +130,8 @@
|
||||
{% endif %}
|
||||
</div>
|
||||
<div class="button-group">
|
||||
<a href="/invite/download_config/?token={{ peer_invite.uuid }}&password={{ password }}" target="_blank" class="btn btn-primary">Download Config</a>
|
||||
<a href="#" id="viewQrButton" class="btn btn-secondary">View QR Code</a>
|
||||
<a href="/invite/download_config/?token={{ peer_invite.uuid }}&password={{ password }}" target="_blank" class="btn btn-primary" id="downloadConfigButton">Download Config</a>
|
||||
<a href="#" id="viewQrButton" class="btn btn-secondary"{% if not peer_invite.peer.private_key %} style="opacity: 0.5; cursor: not-allowed;"{% endif %}>View QR Code</a>
|
||||
</div>
|
||||
<div class="qr-code" id="qrCodeContainer">
|
||||
<!-- QR Code will be loaded here when the button is clicked -->
|
||||
@@ -149,9 +149,15 @@
|
||||
<script>
|
||||
document.addEventListener("DOMContentLoaded", function() {
|
||||
var viewQrButton = document.getElementById("viewQrButton");
|
||||
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) {
|
||||
return false;
|
||||
}
|
||||
if (qrCodeContainer.style.display === "none" || qrCodeContainer.style.display === "") {
|
||||
if (qrCodeContainer.getElementsByTagName("img").length === 0) {
|
||||
var img = document.createElement("img");
|
||||
@@ -164,6 +170,15 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
{% endif %}
|
||||
|
@@ -281,6 +281,9 @@
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
$("#qrcodeButton").on("click", function(e) {
|
||||
e.preventDefault();
|
||||
if ($(this).hasClass('disabled')) {
|
||||
return false;
|
||||
}
|
||||
var uuid = $("#peerPreviewModal").data("peer-uuid");
|
||||
$("#qrCodeImg").attr("src", "/tools/download_peer_config/?uuid=" + uuid + "&format=qrcode");
|
||||
$(".info-content").hide();
|
||||
@@ -293,6 +296,16 @@
|
||||
$(".qr-code-content").hide();
|
||||
$(".info-content").show();
|
||||
});
|
||||
|
||||
$("#downloadConfigButton").on("click", function(e) {
|
||||
var hasPrivateKey = $("#peerPreviewModal").data("has-private-key");
|
||||
if (!hasPrivateKey) {
|
||||
if (!confirm("{% trans 'This configuration does not contain a private key. You must add the private key manually in your client before using it.' %}")) {
|
||||
e.preventDefault();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
@@ -335,7 +348,14 @@
|
||||
if (data.name) {
|
||||
$('#peerPreviewModalLabel').text(data.name);
|
||||
}
|
||||
// Future additional peer information can be handled here.
|
||||
// Check if peer has private_key and enable/disable buttons accordingly
|
||||
if (!data.private_key_exists) {
|
||||
$('#qrcodeButton').addClass('disabled').attr('aria-disabled', 'true');
|
||||
$('#peerPreviewModal').data('has-private-key', false);
|
||||
} else {
|
||||
$('#qrcodeButton').removeClass('disabled').removeAttr('aria-disabled');
|
||||
$('#peerPreviewModal').data('has-private-key', true);
|
||||
}
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
console.error("Error fetching peer info:", error);
|
||||
|
Reference in New Issue
Block a user