1
0
mirror of https://github.com/donaldzou/WGDashboard.git synced 2024-11-07 00:10:13 +01:00
WGDashboard/src/templates/configuration.html

359 lines
13 KiB
HTML
Raw Normal View History

2020-10-18 07:10:13 +02:00
<html>
2021-05-04 07:32:34 +02:00
{% include "header.html" %}
2020-10-18 07:10:13 +02:00
<body>
2021-05-04 07:32:34 +02:00
{% include "navbar.html" %}
2020-10-18 07:10:13 +02:00
<div class="container-fluid">
2021-05-04 07:32:34 +02:00
{% include "sidebar.html" %}
2021-05-14 00:00:40 +02:00
<div id="config_body"></div>
2020-10-18 07:10:13 +02:00
</div>
2020-12-26 06:17:42 +01:00
<div class="modal fade" id="add_modal" data-backdrop="static" data-keyboard="false" tabindex="-1"
2020-10-23 07:31:10 +02:00
aria-labelledby="staticBackdropLabel" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="staticBackdropLabel">Add a new peer</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
2020-12-27 05:42:41 +01:00
<div id="add_peer_alert" class="alert alert-danger alert-dismissible fade show d-none" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
2021-07-02 19:23:04 +02:00
<form id="add_peer_form">
<div class="alert alert-warning" role="alert" style="font-size: 0.8rem">
To generate QR code for this new peer, you need to provide the private key, or use the generated key. If you don't need the QR code, simply remove the private key and insert your existed public key.
</div>
<div>
<label for="private_key">Private Key</label>
</div>
<div class="input-group">
<input type="text" class="form-control" id="private_key" aria-describedby="public_key">
<div class="input-group-append">
<button type="button" class="btn btn-danger" id="re_generate_key">
<i class="bi bi-arrow-repeat"></i>
</button>
</div>
</div>
2020-10-23 07:31:10 +02:00
<div class="form-group">
<label for="public_key">Public Key <code>(Required)</code></label>
<input type="text" class="form-control" id="public_key" aria-describedby="public_key" disabled>
2020-10-23 07:31:10 +02:00
</div>
2020-10-23 07:31:10 +02:00
<div class="form-group">
<label for="allowed_ips">Allowed IPs <code>(Required)</code></label>
2020-10-23 07:31:10 +02:00
<input type="text" class="form-control" id="allowed_ips">
</div>
2021-05-14 00:00:40 +02:00
<div class="form-group">
<label for="new_add_name">Name</label>
2021-05-14 00:00:40 +02:00
<input type="text" class="form-control" id="new_add_name">
</div>
2020-10-23 07:31:10 +02:00
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
<button type="button" class="btn btn-primary" id="save_peer" conf_id={{conf_data['name']}}>Save</button>
</div>
</div>
</div>
</div>
2020-12-26 06:17:42 +01:00
<div class="modal fade" id="delete_modal" data-backdrop="static" data-keyboard="false" tabindex="-1"
aria-labelledby="staticBackdropLabel" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="staticBackdropLabel">Are you sure to delete this peer?</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
2020-12-27 05:42:41 +01:00
<div id="remove_peer_alert" class="alert alert-danger alert-dismissible fade show d-none" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
2020-12-26 06:17:42 +01:00
<h6>This action is not reversible.</h6>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">No</button>
<button type="button" class="btn btn-danger" id="delete_peer" conf_id={{conf_data['name']}} peer_id="">Yes</button>
</div>
</div>
</div>
</div>
2021-04-03 02:48:00 +02:00
<div class="modal fade" id="setting_modal" data-backdrop="static" data-keyboard="false" tabindex="-1"
aria-labelledby="staticBackdropLabel" aria-hidden="true" conf_id={{conf_data['name']}} peer_id="">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header">
<h5 class="peer_name"></h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<div class="mb-3">
<label for="peer_name" class="form-label">Name</label>
<input type="text" class="form-control" id="peer_name_textbox" placeholder="">
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
<button type="button" class="btn btn-primary" id="save_peer_name" conf_id={{conf_data['name']}} peer_id="">Save</button>
</div>
</div>
</div>
</div>
<div class="modal fade" id="qrcode_modal" data-backdrop="static" data-keyboard="false" tabindex="-1"
aria-labelledby="staticBackdropLabel" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header">
<h5 class="peer_name">QR Code</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<img src="" id="qrcode_img" style="width: 100%">
</div>
</div>
</div>
</div>
2021-04-03 02:48:00 +02:00
<div class="position-fixed top-0 right-0 p-3" style="z-index: 5; right: 0; top: 50px;">
<div id="alertToast" class="toast hide" role="alert" aria-live="assertive" aria-atomic="true" data-delay="5000">
<div class="toast-header">
<strong class="mr-auto">Wireguard Dashboard</strong>
<button type="button" class="ml-2 mb-1 close" data-dismiss="toast" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="toast-body">
</div>
</div>
</div>
2021-05-14 00:00:40 +02:00
{% include "tools.html" %}
2020-10-18 07:10:13 +02:00
</body>
2021-05-05 03:26:40 +02:00
{% include "footer.html" %}
2021-04-03 02:48:00 +02:00
<script>
2021-05-04 07:32:34 +02:00
$(".sb-{{conf_data['name']}}-url").addClass("active");
2021-04-03 02:48:00 +02:00
function load_data(){
$.ajax({
method: "GET",
url: "/get_config/"+"{{conf_data['name']}}",
headers:{
"Content-Type": "application/json"
},
async:false,
success: function (response){
$("#config_body").html(response);
2021-05-14 00:00:40 +02:00
$("[refresh-interval={{ dashboard_refresh_interval }}]").addClass("active")
2021-04-03 02:48:00 +02:00
}
})
}
$(document).ready(function(){
load_data();
setInterval(function(){
load_data();
2021-05-14 00:00:40 +02:00
}, {{dashboard_refresh_interval}})
2021-04-03 02:48:00 +02:00
});
2021-05-14 00:00:40 +02:00
$("body").on("click", ".update_interval", function(){
$.ajax({
method:"POST",
data: "interval="+$(this).attr("refresh-interval"),
url: "/update_dashboard_refresh_interval",
success: function (res){
location.reload()
}
})
});
$("body").on("click", ".refresh", function (){
load_data();
});
2021-04-03 02:48:00 +02:00
</script>
2020-10-18 07:10:13 +02:00
<script>
function generate_key(){
$.ajax({
"url": "/generate_peer",
"method": "GET",
}).done(function(res){
$("#private_key").val(res.private_key)
$("#public_key").val(res.public_key)
$("#add_peer_alert").addClass("d-none");
$("#re_generate_key i").removeClass("rotating")
})
}
function generate_public_key(){
$.ajax({
"url": "/generate_public_key",
"method": "POST",
"headers":{"Content-Type": "application/json"},
"data": JSON.stringify({"private_key": $("#private_key").val()})
}).done(function(res){
if(res['status'] === "failed"){
$("#add_peer_alert").html(res['msg']+$("#add_peer_alert").html());
$("#add_peer_alert").removeClass("d-none");
}else{
$("#add_peer_alert").addClass("d-none");
}
$("#public_key").val(res['data'])
$("#re_generate_key i").removeClass("rotating")
})
}
$("#private_key").change(function(){
if ($("#private_key").val().length > 0){
$("#re_generate_key i").addClass("rotating")
generate_public_key()
}else{
$("#public_key").removeAttr("disabled")
$("#public_key").val("")
}
})
$('#add_modal').on('show.bs.modal', function (event) {
generate_key()
})
$("#re_generate_key").click(function (){
$("#public_key").attr("disabled","disabled")
$("#re_generate_key i").addClass("rotating")
generate_key()
})
2021-05-04 07:32:34 +02:00
$("body").on("click", ".switch", function (){
2021-05-05 03:26:40 +02:00
$(this).siblings($(".spinner-border")).css("display", "inline-block");
$(this).remove()
location.replace("/switch/"+$(this).attr('id'));
2021-05-04 07:32:34 +02:00
})
2021-05-05 03:26:40 +02:00
2020-10-23 07:31:10 +02:00
$("#save_peer").click(function(){
if ($("#allowed_ips") !== "" && $("#public_key") !== ""){
2020-10-23 07:31:10 +02:00
var conf = $(this).attr('conf_id')
$.ajax({
method: "POST",
url: "/add_peer/"+conf,
headers:{
"Content-Type": "application/json"
},
data: JSON.stringify({
"private_key":$("#private_key").val(),
"public_key":$("#public_key").val(),
2021-07-02 19:23:04 +02:00
"allowed_ips": $("#allowed_ips").val(),
"name":$("#new_add_name").val()
}),
2020-10-23 07:31:10 +02:00
success: function (response){
2020-12-27 05:42:41 +01:00
if(response != "true"){
$("#add_peer_alert").html(response+$("#add_peer_alert").html());
$("#add_peer_alert").removeClass("d-none");
}
else{
location.reload();
}
2020-10-23 07:31:10 +02:00
}
})
}
})
var qrcodeModal = new bootstrap.Modal(document.getElementById('qrcode_modal'), {
keyboard: false
})
2020-10-19 17:48:08 +02:00
$("body").on("click", ".btn-qrcode-peer", function (){
qrcodeModal.toggle();
$("#qrcode_img").attr('src', $(this).attr('img_src'))
})
2021-07-02 19:23:04 +02:00
var deleteModal = new bootstrap.Modal(document.getElementById('delete_modal'), {
keyboard: false
});
2021-04-03 02:48:00 +02:00
$("body").on("click", ".btn-delete-peer", function(){
var peer_id = $(this).attr("id");
2020-12-26 06:17:42 +01:00
$("#delete_peer").attr("peer_id", peer_id);
2021-07-02 19:23:04 +02:00
deleteModal.toggle();
2021-04-03 02:48:00 +02:00
})
2020-12-27 05:42:41 +01:00
$("#delete_peer").click(function(){
2020-12-26 06:17:42 +01:00
var peer_id = $(this).attr("peer_id");
var config = $(this).attr("conf_id");
$.ajax({
method: "POST",
2020-12-27 05:42:41 +01:00
url: "/remove_peer/"+config,
2020-12-26 06:17:42 +01:00
headers:{
"Content-Type": "application/json"
},
2020-12-27 05:42:41 +01:00
data: JSON.stringify({"action": "delete", "peer_id": peer_id}),
2020-12-26 06:17:42 +01:00
success: function (response){
2021-05-14 00:00:40 +02:00
if(response !== "true"){
2021-07-02 19:23:04 +02:00
$("#remove_peer_alert").html(response+$("#add_peer_alert").html());
$("#remove_peer_alert").removeClass("d-none");
}
else{
deleteModal.toggle();
load_data();
$('#alertToast').toast('show');
$('#alertToast .toast-body').html("Peer deleted!");
}
2020-12-26 06:17:42 +01:00
}
})
});
2021-07-02 19:23:04 +02:00
var settingModal = new bootstrap.Modal(document.getElementById('setting_modal'), {
2021-04-03 02:48:00 +02:00
keyboard: false
})
2021-07-02 19:23:04 +02:00
2021-04-03 02:48:00 +02:00
$("body").on("click", ".btn-setting-peer", function(){
2021-07-02 19:23:04 +02:00
settingModal.toggle();
2021-04-03 02:48:00 +02:00
var peer_id = $(this).attr("id");
$("#save_peer_name").attr("peer_id", peer_id);
$.ajax({
method: "POST",
url: "/get_peer_name/"+$("#setting_modal").attr("conf_id"),
headers:{
"Content-Type": "application/json"
},
data: JSON.stringify({"id": peer_id}),
success: function(response){
if (response == ""){
$("#setting_modal .peer_name").html("Untitled Peer");
2021-04-03 04:22:41 +02:00
$("#peer_name_textbox").val("")
2021-04-03 02:48:00 +02:00
}else{
$("#setting_modal .peer_name").html(response);
$("#peer_name_textbox").val(response)
}
}
})
});
2021-07-02 19:23:04 +02:00
2021-04-03 02:48:00 +02:00
$("#save_peer_name").click(function (){
var peer_id = $(this).attr("peer_id");
$.ajax({
method: "POST",
url: "/save_peer_name/"+"{{conf_data['name']}}",
headers:{
"Content-Type": "application/json"
},
data: JSON.stringify({id: peer_id, name: $("#peer_name_textbox").val()}),
success: function (response){
2021-07-02 19:23:04 +02:00
settingModal.toggle();
2021-04-03 02:48:00 +02:00
load_data();
$('#alertToast').toast('show');
$('#alertToast .toast-body').html("Name Saved!");
}
})
})
2021-05-04 07:32:34 +02:00
2020-10-18 07:10:13 +02:00
</script>
2020-10-23 07:31:10 +02:00
</html>