2021-12-29 12:17:44 -05:00
|
|
|
let $body = $("body");
|
|
|
|
|
|
|
|
// Progress Bar
|
2021-12-29 23:26:15 -05:00
|
|
|
let $progress_bar = $(".progress-bar");
|
2021-12-29 12:17:44 -05:00
|
|
|
function startProgressBar(){
|
|
|
|
$progress_bar.css("width","0%")
|
2021-12-29 23:26:15 -05:00
|
|
|
.css("opacity", "100")
|
|
|
|
.css("background", "rgb(255,69,69)")
|
|
|
|
.css("background",
|
|
|
|
"linear-gradient(145deg, rgba(255,69,69,1) 0%, rgba(0,115,186,1) 100%)")
|
|
|
|
.css("width","25%");
|
2021-12-29 12:17:44 -05:00
|
|
|
setTimeout(function(){
|
|
|
|
stillLoadingProgressBar();
|
2021-12-29 23:26:15 -05:00
|
|
|
},300);
|
2021-12-29 12:17:44 -05:00
|
|
|
}
|
|
|
|
function stillLoadingProgressBar(){
|
2021-12-29 23:26:15 -05:00
|
|
|
$progress_bar.css("transition", "3s ease-in-out").css("width", "75%");
|
2021-12-29 12:17:44 -05:00
|
|
|
}
|
|
|
|
function endProgressBar(){
|
2021-12-29 23:26:15 -05:00
|
|
|
$progress_bar.css("transition", "0.3s ease-in-out").css("width","100%");
|
2021-12-29 12:17:44 -05:00
|
|
|
setTimeout(function(){
|
2021-12-29 23:26:15 -05:00
|
|
|
$progress_bar.css("opacity", "0");
|
|
|
|
},250);
|
2021-12-29 12:17:44 -05:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function showToast(msg) {
|
|
|
|
$('#alertToast').toast('show');
|
|
|
|
$('#alertToast .toast-body').html(msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-08-05 23:15:50 -04:00
|
|
|
// Config Toggle
|
2021-12-29 12:17:44 -05:00
|
|
|
$body.on("click", ".switch", function (){
|
2021-08-05 23:15:50 -04:00
|
|
|
$(this).siblings($(".spinner-border")).css("display", "inline-block");
|
2021-12-29 23:26:15 -05:00
|
|
|
$(this).remove();
|
2021-08-05 23:15:50 -04:00
|
|
|
location.replace("/switch/"+$(this).attr('id'));
|
2021-12-29 23:26:15 -05:00
|
|
|
});
|
2021-08-05 23:15:50 -04:00
|
|
|
|
|
|
|
// Generating Keys
|
|
|
|
function generate_key(){
|
|
|
|
$.ajax({
|
|
|
|
"url": "/generate_peer",
|
|
|
|
"method": "GET",
|
|
|
|
}).done(function(res){
|
2021-12-29 23:26:15 -05:00
|
|
|
$("#private_key").val(res.private_key);
|
|
|
|
$("#public_key").val(res.public_key);
|
|
|
|
$("#preshare_key").val(res.preshared_key);
|
2021-08-05 23:15:50 -04:00
|
|
|
$("#add_peer_alert").addClass("d-none");
|
2021-12-29 23:26:15 -05:00
|
|
|
$("#re_generate_key i").removeClass("rotating");
|
|
|
|
});
|
2021-08-05 23:15:50 -04:00
|
|
|
}
|
|
|
|
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){
|
2021-12-29 23:26:15 -05:00
|
|
|
if(res.status === "failed"){
|
|
|
|
$("#add_peer_alert").html(res.msg).removeClass("d-none");
|
2021-08-05 23:15:50 -04:00
|
|
|
}else{
|
|
|
|
$("#add_peer_alert").addClass("d-none");
|
|
|
|
}
|
2021-12-29 23:26:15 -05:00
|
|
|
$("#public_key").val(res.data);
|
|
|
|
$("#re_generate_key i").removeClass("rotating");
|
|
|
|
});
|
2021-08-05 23:15:50 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Add Peer
|
2021-12-29 12:17:44 -05:00
|
|
|
$("#private_key").on("change",function(){
|
2021-12-29 23:26:15 -05:00
|
|
|
if ($(this).val().length > 0){
|
|
|
|
$("#re_generate_key i").addClass("rotating");
|
|
|
|
generate_public_key();
|
2021-08-05 23:15:50 -04:00
|
|
|
}else{
|
2021-12-29 23:26:15 -05:00
|
|
|
$("#public_key").removeAttr("disabled").val("");
|
2021-08-05 23:15:50 -04:00
|
|
|
}
|
2021-12-29 23:26:15 -05:00
|
|
|
});
|
|
|
|
|
2021-08-05 23:15:50 -04:00
|
|
|
$('#add_modal').on('show.bs.modal', function (event) {
|
2021-12-29 23:26:15 -05:00
|
|
|
generate_key();
|
|
|
|
});
|
|
|
|
$("#re_generate_key").on("click",function (){
|
|
|
|
$("#public_key").attr("disabled","disabled");
|
|
|
|
$("#re_generate_key i").addClass("rotating");
|
|
|
|
generate_key();
|
|
|
|
});
|
2021-12-29 12:17:44 -05:00
|
|
|
let addModal = new bootstrap.Modal(document.getElementById('add_modal'), {
|
|
|
|
keyboard: false
|
2021-12-29 23:26:15 -05:00
|
|
|
});
|
2021-12-29 12:17:44 -05:00
|
|
|
|
|
|
|
$(".add_btn").on("click", function(){
|
|
|
|
addModal.toggle();
|
2021-12-29 23:26:15 -05:00
|
|
|
});
|
2021-12-29 12:17:44 -05:00
|
|
|
|
|
|
|
$("#save_peer").on("click",function(){
|
2021-12-29 23:26:15 -05:00
|
|
|
let $public_key = $("#public_key");
|
|
|
|
let $private_key = $("#private_key");
|
|
|
|
let $allowed_ips = $("#allowed_ips");
|
|
|
|
let $new_add_DNS = $("#new_add_DNS");
|
|
|
|
let $new_add_endpoint_allowed_ip = $("#new_add_endpoint_allowed_ip");
|
|
|
|
let $new_add_name = $("#new_add_name");
|
|
|
|
let $new_add_MTU = $("#new_add_MTU");
|
|
|
|
let $new_add_keep_alive = $("#new_add_keep_alive");
|
|
|
|
let $enable_preshare_key = $("#enable_preshare_key");
|
|
|
|
|
|
|
|
$(this).attr("disabled","disabled");
|
|
|
|
$(this).html("Saving...");
|
|
|
|
if ($allowed_ips.val() !== "" && $public_key.val() !== "" && $new_add_DNS.val() !== "" && $new_add_endpoint_allowed_ip.val() !== ""){
|
|
|
|
let conf = $(this).attr('conf_id');
|
|
|
|
let data_list = [$private_key, $allowed_ips, $new_add_name, $new_add_DNS, $new_add_endpoint_allowed_ip,$new_add_MTU, $new_add_keep_alive];
|
|
|
|
data_list.forEach((ele) => ele.attr("disabled", "disabled"));
|
2021-08-05 23:15:50 -04:00
|
|
|
$.ajax({
|
|
|
|
method: "POST",
|
|
|
|
url: "/add_peer/"+conf,
|
|
|
|
headers:{
|
|
|
|
"Content-Type": "application/json"
|
|
|
|
},
|
|
|
|
data: JSON.stringify({
|
2021-12-29 23:26:15 -05:00
|
|
|
"private_key":$private_key.val(),
|
|
|
|
"public_key":$public_key.val(),
|
|
|
|
"allowed_ips": $allowed_ips.val(),
|
|
|
|
"name":$new_add_name.val(),
|
|
|
|
"DNS": $new_add_DNS.val(),
|
|
|
|
"endpoint_allowed_ip": $new_add_endpoint_allowed_ip.val(),
|
|
|
|
"MTU": $new_add_MTU.val(),
|
|
|
|
"keep_alive": $new_add_keep_alive.val(),
|
|
|
|
"enable_preshared_key": $enable_preshare_key.prop("checked"),
|
2021-08-05 23:15:50 -04:00
|
|
|
}),
|
|
|
|
success: function (response){
|
2021-12-29 23:26:15 -05:00
|
|
|
if(response !== "true"){
|
|
|
|
$("#add_peer_alert").html(response).removeClass("d-none");
|
|
|
|
data_list.forEach((ele) => ele.removeAttr("disabled"));
|
|
|
|
$("#save_peer").removeAttr("disabled").html("Save");
|
2021-08-05 23:15:50 -04:00
|
|
|
}
|
|
|
|
else{
|
2021-12-29 12:17:44 -05:00
|
|
|
load_data("");
|
2021-12-29 23:26:15 -05:00
|
|
|
addModal.toggle();
|
2021-08-05 23:15:50 -04:00
|
|
|
}
|
|
|
|
}
|
2021-12-29 23:26:15 -05:00
|
|
|
});
|
2021-08-14 23:30:05 -04:00
|
|
|
}else{
|
2021-12-29 23:26:15 -05:00
|
|
|
$("#add_peer_alert").html("Please fill in all required box.").removeClass("d-none");
|
|
|
|
$(this).removeAttr("disabled");
|
|
|
|
$(this).html("Save");
|
2021-08-05 23:15:50 -04:00
|
|
|
}
|
2021-12-29 23:26:15 -05:00
|
|
|
});
|
2021-08-05 23:15:50 -04:00
|
|
|
|
2021-12-29 23:26:15 -05:00
|
|
|
|
|
|
|
let qrcodeModal = new bootstrap.Modal(document.getElementById('qrcode_modal'), {
|
|
|
|
keyboard: false
|
|
|
|
});
|
2021-08-05 23:15:50 -04:00
|
|
|
// QR Code
|
2021-12-29 12:17:44 -05:00
|
|
|
$body.on("click", ".btn-qrcode-peer", function (){
|
2021-12-29 23:26:15 -05:00
|
|
|
let src = $(this).attr('img_src');
|
2021-12-23 21:26:24 -05:00
|
|
|
$.ajax({
|
|
|
|
"url": src,
|
|
|
|
"method": "GET"
|
|
|
|
}).done(function(res){
|
2021-12-29 23:26:15 -05:00
|
|
|
$("#qrcode_img").attr('src', res);
|
2021-12-23 21:26:24 -05:00
|
|
|
qrcodeModal.toggle();
|
2021-12-29 23:26:15 -05:00
|
|
|
});
|
|
|
|
});
|
2021-08-05 23:15:50 -04:00
|
|
|
|
|
|
|
// Delete Peer Modal
|
2021-12-29 23:26:15 -05:00
|
|
|
let deleteModal = new bootstrap.Modal(document.getElementById('delete_modal'), {
|
2021-08-05 23:15:50 -04:00
|
|
|
keyboard: false
|
|
|
|
});
|
|
|
|
|
2021-12-29 12:17:44 -05:00
|
|
|
$body.on("click", ".btn-delete-peer", function(){
|
2021-12-29 23:26:15 -05:00
|
|
|
let peer_id = $(this).attr("id");
|
2021-08-05 23:15:50 -04:00
|
|
|
$("#delete_peer").attr("peer_id", peer_id);
|
|
|
|
deleteModal.toggle();
|
2021-12-29 23:26:15 -05:00
|
|
|
});
|
2021-08-05 23:15:50 -04:00
|
|
|
|
2021-12-29 23:26:15 -05:00
|
|
|
$("#delete_peer").on("click",function(){
|
|
|
|
$(this).attr("disabled","disabled");
|
|
|
|
$(this).html("Deleting...");
|
|
|
|
let peer_id = $(this).attr("peer_id");
|
|
|
|
let config = $(this).attr("conf_id");
|
2021-08-05 23:15:50 -04:00
|
|
|
$.ajax({
|
|
|
|
method: "POST",
|
|
|
|
url: "/remove_peer/"+config,
|
|
|
|
headers:{
|
|
|
|
"Content-Type": "application/json"
|
|
|
|
},
|
|
|
|
data: JSON.stringify({"action": "delete", "peer_id": peer_id}),
|
|
|
|
success: function (response){
|
|
|
|
if(response !== "true"){
|
2021-12-29 23:26:15 -05:00
|
|
|
$("#remove_peer_alert").html(response+$("#add_peer_alert").html()).removeClass("d-none");
|
2021-08-05 23:15:50 -04:00
|
|
|
}
|
|
|
|
else{
|
|
|
|
deleteModal.toggle();
|
2021-08-14 17:13:16 -04:00
|
|
|
load_data($('#search_peer_textbox').val());
|
2021-08-05 23:15:50 -04:00
|
|
|
$('#alertToast').toast('show');
|
|
|
|
$('#alertToast .toast-body').html("Peer deleted!");
|
2021-12-29 23:26:15 -05:00
|
|
|
$("#delete_peer").removeAttr("disabled").html("Delete");
|
2021-08-05 23:15:50 -04:00
|
|
|
}
|
|
|
|
}
|
2021-12-29 23:26:15 -05:00
|
|
|
});
|
2021-08-05 23:15:50 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
// Peer Setting Modal
|
2021-12-29 23:26:15 -05:00
|
|
|
let settingModal = new bootstrap.Modal(document.getElementById('setting_modal'), {
|
2021-08-05 23:15:50 -04:00
|
|
|
keyboard: false
|
2021-12-29 23:26:15 -05:00
|
|
|
});
|
2021-12-29 12:17:44 -05:00
|
|
|
$body.on("click", ".btn-setting-peer", function(){
|
2021-12-29 23:26:15 -05:00
|
|
|
startProgressBar();
|
|
|
|
let peer_id = $(this).attr("id");
|
2021-08-05 23:15:50 -04:00
|
|
|
$("#save_peer_setting").attr("peer_id", peer_id);
|
|
|
|
$.ajax({
|
|
|
|
method: "POST",
|
|
|
|
url: "/get_peer_data/"+$("#setting_modal").attr("conf_id"),
|
|
|
|
headers:{
|
|
|
|
"Content-Type": "application/json"
|
|
|
|
},
|
|
|
|
data: JSON.stringify({"id": peer_id}),
|
|
|
|
success: function(response){
|
2021-12-29 23:26:15 -05:00
|
|
|
let peer_name = ((response.name === "") ? "Untitled Peer" : response.name);
|
2021-08-05 23:15:50 -04:00
|
|
|
$("#setting_modal .peer_name").html(peer_name);
|
2021-12-29 23:26:15 -05:00
|
|
|
$("#setting_modal #peer_name_textbox").val(response.name);
|
|
|
|
$("#setting_modal #peer_private_key_textbox").val(response.private_key);
|
|
|
|
$("#setting_modal #peer_DNS_textbox").val(response.DNS);
|
|
|
|
$("#setting_modal #peer_allowed_ip_textbox").val(response.allowed_ip);
|
|
|
|
$("#setting_modal #peer_endpoint_allowed_ips").val(response.endpoint_allowed_ip);
|
|
|
|
$("#setting_modal #peer_mtu").val(response.mtu);
|
|
|
|
$("#setting_modal #peer_keep_alive").val(response.keep_alive);
|
|
|
|
$("#setting_modal #peer_preshared_key_textbox").val(response.preshared_key);
|
2021-08-14 17:13:16 -04:00
|
|
|
settingModal.toggle();
|
2021-12-29 23:26:15 -05:00
|
|
|
endProgressBar();
|
2021-08-05 23:15:50 -04:00
|
|
|
}
|
2021-12-29 23:26:15 -05:00
|
|
|
});
|
2021-08-05 23:15:50 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
$('#setting_modal').on('hidden.bs.modal', function (event) {
|
|
|
|
$("#setting_peer_alert").addClass("d-none");
|
2021-12-29 23:26:15 -05:00
|
|
|
});
|
2021-08-05 23:15:50 -04:00
|
|
|
|
2021-12-29 23:26:15 -05:00
|
|
|
$("#peer_private_key_textbox").on("change",function(){
|
|
|
|
let $save_peer_setting = $("#save_peer_setting");
|
2021-08-05 23:15:50 -04:00
|
|
|
if ($(this).val().length > 0){
|
|
|
|
$.ajax({
|
2021-12-29 23:26:15 -05:00
|
|
|
"url": "/check_key_match/"+$save_peer_setting.attr("conf_id"),
|
2021-08-05 23:15:50 -04:00
|
|
|
"method": "POST",
|
|
|
|
"headers":{"Content-Type": "application/json"},
|
|
|
|
"data": JSON.stringify({
|
|
|
|
"private_key": $("#peer_private_key_textbox").val(),
|
2021-12-29 23:26:15 -05:00
|
|
|
"public_key": $save_peer_setting.attr("peer_id")
|
2021-08-05 23:15:50 -04:00
|
|
|
})
|
|
|
|
}).done(function(res){
|
2021-12-29 23:26:15 -05:00
|
|
|
if(res.status === "failed"){
|
|
|
|
$("#setting_peer_alert").html(res.status).removeClass("d-none");
|
2021-08-05 23:15:50 -04:00
|
|
|
}else{
|
|
|
|
$("#setting_peer_alert").addClass("d-none");
|
|
|
|
}
|
2021-12-29 23:26:15 -05:00
|
|
|
});
|
2021-08-05 23:15:50 -04:00
|
|
|
}
|
2021-12-29 23:26:15 -05:00
|
|
|
});
|
2021-08-05 23:15:50 -04:00
|
|
|
|
2021-12-29 23:26:15 -05:00
|
|
|
$("#save_peer_setting").on("click",function (){
|
|
|
|
$(this).attr("disabled","disabled");
|
|
|
|
$(this).html("Saving...");
|
|
|
|
let $peer_DNS_textbox = $("#peer_DNS_textbox");
|
|
|
|
let $peer_allowed_ip_textbox = $("#peer_allowed_ip_textbox");
|
|
|
|
let $peer_endpoint_allowed_ips = $("#peer_endpoint_allowed_ips");
|
|
|
|
let $peer_name_textbox = $("#peer_name_textbox");
|
|
|
|
let $peer_private_key_textbox = $("#peer_private_key_textbox");
|
|
|
|
let $peer_preshared_key_textbox = $("#peer_preshared_key_textbox");
|
|
|
|
let $peer_mtu = $("#peer_mtu");
|
|
|
|
let $peer_keep_alive = $("#peer_keep_alive");
|
|
|
|
|
|
|
|
if ($peer_DNS_textbox.val() !== "" &&
|
|
|
|
$peer_allowed_ip_textbox.val() !== "" && $peer_endpoint_allowed_ips.val() !== ""){
|
|
|
|
let peer_id = $(this).attr("peer_id");
|
|
|
|
let conf_id = $(this).attr("conf_id");
|
|
|
|
let data_list = [$peer_name_textbox, $peer_DNS_textbox, $peer_private_key_textbox, $peer_preshared_key_textbox, $peer_allowed_ip_textbox, $peer_endpoint_allowed_ips, $peer_mtu, $peer_keep_alive];
|
|
|
|
data_list.forEach((ele) => ele.attr("disabled","disabled"));
|
2021-08-05 23:15:50 -04:00
|
|
|
$.ajax({
|
|
|
|
method: "POST",
|
|
|
|
url: "/save_peer_setting/"+conf_id,
|
|
|
|
headers:{
|
|
|
|
"Content-Type": "application/json"
|
|
|
|
},
|
|
|
|
data: JSON.stringify({
|
|
|
|
id: peer_id,
|
2021-12-29 23:26:15 -05:00
|
|
|
name: $peer_name_textbox.val(),
|
|
|
|
DNS: $peer_DNS_textbox.val(),
|
|
|
|
private_key: $peer_private_key_textbox.val(),
|
|
|
|
allowed_ip: $peer_allowed_ip_textbox.val(),
|
|
|
|
endpoint_allowed_ip: $peer_endpoint_allowed_ips.val(),
|
|
|
|
MTU: $peer_mtu.val(),
|
|
|
|
keep_alive: $peer_keep_alive.val(),
|
|
|
|
preshared_key: $peer_preshared_key_textbox.val()
|
2021-08-05 23:15:50 -04:00
|
|
|
}),
|
|
|
|
success: function (response){
|
2021-12-29 23:26:15 -05:00
|
|
|
if (response.status === "failed"){
|
|
|
|
$("#setting_peer_alert").html(response.msg).removeClass("d-none");
|
2021-08-05 23:15:50 -04:00
|
|
|
}else{
|
|
|
|
settingModal.toggle();
|
2021-12-29 23:26:15 -05:00
|
|
|
load_data($('#search_peer_textbox').val());
|
2021-08-05 23:15:50 -04:00
|
|
|
$('#alertToast').toast('show');
|
|
|
|
$('#alertToast .toast-body').html("Peer Saved!");
|
|
|
|
}
|
2021-12-29 23:26:15 -05:00
|
|
|
$("#save_peer_setting").removeAttr("disabled").html("Save");
|
|
|
|
data_list.forEach((ele) => ele.removeAttr("disabled"));
|
2021-08-05 23:15:50 -04:00
|
|
|
}
|
2021-12-29 23:26:15 -05:00
|
|
|
});
|
2021-08-24 21:04:01 -04:00
|
|
|
}else{
|
2021-12-29 23:26:15 -05:00
|
|
|
$("#setting_peer_alert").html("Please fill in all required box.").removeClass("d-none");
|
|
|
|
$("#save_peer_setting").removeAttr("disabled").html("Save");
|
2021-08-05 23:15:50 -04:00
|
|
|
}
|
2021-12-29 23:26:15 -05:00
|
|
|
});
|
2021-08-05 23:15:50 -04:00
|
|
|
|
2021-12-29 23:26:15 -05:00
|
|
|
$(".peer_private_key_textbox_switch").on("click",function (){
|
|
|
|
let $peer_private_key_textbox = $("#peer_private_key_textbox");
|
|
|
|
let mode = (($peer_private_key_textbox.attr('type') === 'password') ? "text":"password");
|
|
|
|
let icon = (($peer_private_key_textbox.attr('type') === 'password') ? "bi bi-eye-slash-fill":"bi bi-eye-fill");
|
|
|
|
$peer_private_key_textbox.attr('type',mode);
|
|
|
|
$(".peer_private_key_textbox_switch i").removeClass().addClass(icon);
|
|
|
|
});
|
2021-08-14 17:13:16 -04:00
|
|
|
|
|
|
|
|
|
|
|
// Search Peer
|
2021-12-29 23:26:15 -05:00
|
|
|
let typingTimer;
|
|
|
|
let doneTypingInterval = 200;
|
|
|
|
let $input = $('#search_peer_textbox');
|
2021-08-14 17:13:16 -04:00
|
|
|
$input.on('keyup', function () {
|
|
|
|
clearTimeout(typingTimer);
|
|
|
|
typingTimer = setTimeout(doneTyping, doneTypingInterval);
|
|
|
|
});
|
|
|
|
$input.on('keydown', function () {
|
|
|
|
clearTimeout(typingTimer);
|
|
|
|
});
|
|
|
|
function doneTyping () {
|
2021-12-29 23:26:15 -05:00
|
|
|
load_data($input.val());
|
2021-08-14 17:13:16 -04:00
|
|
|
}
|
|
|
|
|
2021-12-29 23:26:15 -05:00
|
|
|
|
2021-08-14 17:13:16 -04:00
|
|
|
// Sorting
|
2021-12-29 12:17:44 -05:00
|
|
|
$body.on("change", "#sort_by_dropdown", function (){
|
2021-08-14 17:13:16 -04:00
|
|
|
$.ajax({
|
|
|
|
method:"POST",
|
|
|
|
data: JSON.stringify({'sort':$("#sort_by_dropdown option:selected").val()}),
|
|
|
|
headers:{"Content-Type": "application/json"},
|
|
|
|
url: "/update_dashboard_sort",
|
|
|
|
success: function (res){
|
2021-12-29 23:26:15 -05:00
|
|
|
load_data($('#search_peer_textbox').val());
|
2021-08-14 17:13:16 -04:00
|
|
|
}
|
2021-12-29 23:26:15 -05:00
|
|
|
});
|
|
|
|
});
|
2021-08-14 17:13:16 -04:00
|
|
|
|
2021-12-29 23:26:15 -05:00
|
|
|
// Click key to copy animation
|
2021-12-29 12:17:44 -05:00
|
|
|
$body.on("mouseenter", ".key", function(){
|
2021-12-29 23:26:15 -05:00
|
|
|
let label = $(this).parent().siblings().children()[1];
|
|
|
|
label.style.opacity = "100";
|
2021-08-14 17:13:16 -04:00
|
|
|
})
|
2021-12-29 12:17:44 -05:00
|
|
|
$body.on("mouseout", ".key", function(){
|
2021-12-29 23:26:15 -05:00
|
|
|
let label = $(this).parent().siblings().children()[1];
|
|
|
|
label.style.opacity = "0";
|
2021-08-14 17:13:16 -04:00
|
|
|
setTimeout(function (){
|
2021-12-29 23:26:15 -05:00
|
|
|
label.innerHTML = "CLICK TO COPY";
|
|
|
|
},200);
|
2021-08-14 17:13:16 -04:00
|
|
|
});
|
2021-12-29 23:26:15 -05:00
|
|
|
|
2021-12-29 12:17:44 -05:00
|
|
|
$body.on("click", ".key", function(){
|
2021-12-29 23:26:15 -05:00
|
|
|
var label = $(this).parent().siblings().children()[1];
|
|
|
|
copyToClipboard($(this));
|
|
|
|
label.innerHTML = "COPIED!";
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* CopyToClipboard
|
|
|
|
* @param element
|
|
|
|
*/
|
2021-08-14 17:13:16 -04:00
|
|
|
function copyToClipboard(element) {
|
2021-12-29 23:26:15 -05:00
|
|
|
let $temp = $("<input>");
|
2021-12-29 12:17:44 -05:00
|
|
|
$body.append($temp);
|
2021-12-29 23:26:15 -05:00
|
|
|
$temp.val($(element).text()).trigger( "select" );
|
2021-08-14 17:13:16 -04:00
|
|
|
document.execCommand("copy");
|
|
|
|
$temp.remove();
|
|
|
|
}
|
|
|
|
|
2021-09-08 12:39:25 -04:00
|
|
|
// Update Interval
|
2021-12-29 12:17:44 -05:00
|
|
|
$body.on("click", ".update_interval", function(){
|
|
|
|
let prev = $(".interval-btn-group.active button");
|
2021-12-27 21:01:02 -05:00
|
|
|
$(".interval-btn-group button").removeClass("active");
|
2021-12-29 23:26:15 -05:00
|
|
|
let _new = $(this);
|
2021-12-29 12:17:44 -05:00
|
|
|
_new.addClass("active");
|
|
|
|
let interval = $(this).data("refresh-interval");
|
2021-12-27 21:01:02 -05:00
|
|
|
$.ajax({
|
|
|
|
method:"POST",
|
|
|
|
data: "interval="+$(this).data("refresh-interval"),
|
|
|
|
url: "/update_dashboard_refresh_interval",
|
|
|
|
success: function (res){
|
2021-12-29 12:17:44 -05:00
|
|
|
if (res === "true"){
|
|
|
|
load_interval = interval;
|
|
|
|
clearInterval(load_timeout);
|
|
|
|
load_timeout = setInterval(function (){
|
|
|
|
load_data($('#search_peer_textbox').val());
|
|
|
|
}, interval);
|
|
|
|
showToast("Refresh Interval set to "+Math.round(interval/1000)+" seconds");
|
|
|
|
}else{
|
|
|
|
$(".interval-btn-group button").removeClass("active");
|
|
|
|
$('.interval-btn-group button[data-refresh-interval="'+load_interval+'"]').addClass("active");
|
|
|
|
showToast("Refresh Interval set unsuccessful");
|
|
|
|
}
|
2021-12-27 21:01:02 -05:00
|
|
|
}
|
|
|
|
})
|
|
|
|
});
|
2021-12-29 23:26:15 -05:00
|
|
|
|
|
|
|
// Refresh Button
|
2021-12-29 12:17:44 -05:00
|
|
|
$body.on("click", ".refresh", function (){
|
2021-08-14 23:30:05 -04:00
|
|
|
load_data($('#search_peer_textbox').val());
|
|
|
|
});
|
2021-09-03 17:32:51 -04:00
|
|
|
|
2021-12-29 12:17:44 -05:00
|
|
|
|
2021-09-08 12:39:25 -04:00
|
|
|
// Switch display mode
|
2021-12-29 12:17:44 -05:00
|
|
|
$body.on("click", ".display_mode", function(){
|
2021-12-27 21:01:02 -05:00
|
|
|
$(".display-btn-group button").removeClass("active");
|
|
|
|
$(this).addClass("active");
|
|
|
|
let display_mode = $(this).data("display-mode");
|
2021-09-03 17:32:51 -04:00
|
|
|
$.ajax({
|
|
|
|
method:"GET",
|
2021-12-27 21:01:02 -05:00
|
|
|
url: "/switch_display_mode/"+$(this).data("display-mode"),
|
2021-09-03 17:32:51 -04:00
|
|
|
success: function (res){
|
2021-12-29 12:17:44 -05:00
|
|
|
if (res === "true"){
|
|
|
|
if (display_mode === "list"){
|
2021-12-27 21:01:02 -05:00
|
|
|
Array($(".peer_list").children()).forEach(function(child){
|
|
|
|
$(child).removeClass().addClass("col-12");
|
2021-12-29 23:26:15 -05:00
|
|
|
});
|
2021-12-29 12:17:44 -05:00
|
|
|
showToast("Displaying as List");
|
2021-12-27 21:01:02 -05:00
|
|
|
}else{
|
|
|
|
Array($(".peer_list").children()).forEach(function(child){
|
|
|
|
$(child).removeClass().addClass("col-sm-6 col-lg-4");
|
2021-12-29 12:17:44 -05:00
|
|
|
});
|
|
|
|
showToast("Displaying as Grid");
|
2021-12-27 21:01:02 -05:00
|
|
|
}
|
2021-12-29 12:17:44 -05:00
|
|
|
}
|
2021-09-03 17:32:51 -04:00
|
|
|
}
|
2021-12-29 23:26:15 -05:00
|
|
|
});
|
|
|
|
});
|