";result+=html});document.querySelector(".peer_list").innerHTML=result;if(response.dashboard_refresh_interval!==configuration_timeout){configuration_timeout=response.dashboard_refresh_interval;removeConfigurationInterval();setConfigurationInterval()}}}function addPeersByBulk(){let $new_add_amount=$("#new_add_amount");$add_peer.setAttribute("disabled","disabled");$add_peer.innerHTML=`Adding ${$new_add_amount.val()} peers...`;let $new_add_DNS=$("#new_add_DNS");$new_add_DNS.val(window.configurations.cleanIp($new_add_DNS.val()));let $new_add_endpoint_allowed_ip=$("#new_add_endpoint_allowed_ip");$new_add_endpoint_allowed_ip.val(window.configurations.cleanIp($new_add_endpoint_allowed_ip.val()));let $new_add_MTU=$("#new_add_MTU");let $new_add_keep_alive=$("#new_add_keep_alive");let $enable_preshare_key=$("#enable_preshare_key");let data_list=[$new_add_DNS,$new_add_endpoint_allowed_ip,$new_add_MTU,$new_add_keep_alive];if($new_add_amount.val()>0&&!$new_add_amount.hasClass("is-invalid")){if($new_add_DNS.val()!==""&&$new_add_endpoint_allowed_ip.val()!==""){let conf=$add_peer.getAttribute("conf_id");let keys=[];for(let i=0;i<$new_add_amount.val();i++){keys.push(window.wireguard.generateKeypair())}$.ajax({method:"POST",url:"/add_peer_bulk/"+conf,headers:{"Content-Type":"application/json"},data:JSON.stringify({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"),keys:keys,amount:$new_add_amount.val()}),success:function(response){if(response!=="true"){$("#add_peer_alert").html(response).removeClass("d-none");data_list.forEach(ele=>ele.removeAttr("disabled"));$add_peer.removeAttribute("disabled");$add_peer.innerHTML="Save"}else{window.configurations.loadPeers("");data_list.forEach(ele=>ele.removeAttr("disabled"));$("#add_peer_form").trigger("reset");$add_peer.removeAttribute("disabled");$add_peer.innerHTML="Save";window.configurations.showToast($new_add_amount.val()+" peers added successful!");window.configurations.addModal().toggle()}}})}else{$("#add_peer_alert").html("Please fill in all required box.").removeClass("d-none");$add_peer.removeAttribute("disabled");$add_peer.innerHTML="Add"}}else{$add_peer.removeAttribute("disabled");$add_peer.innerHTML="Add"}}function deletePeers(config,peer_ids){$.ajax({method:"POST",url:"/remove_peer/"+config,headers:{"Content-Type":"application/json"},data:JSON.stringify({action:"delete",peer_ids:peer_ids}),success:function(response){if(response!=="true"){if(window.configurations.deleteModal()._isShown){$("#remove_peer_alert").html(response+$("#add_peer_alert").html()).removeClass("d-none");$("#delete_peer").removeAttr("disabled").html("Delete")}if(window.configurations.deleteBulkModal()._isShown){let $bulk_remove_peer_alert=$("#bulk_remove_peer_alert");$bulk_remove_peer_alert.html(response+$bulk_remove_peer_alert.html()).removeClass("d-none");$("#confirm_delete_bulk_peers").removeAttr("disabled").html("Delete")}}else{if(window.configurations.deleteModal()._isShown){window.configurations.deleteModal().toggle()}if(window.configurations.deleteBulkModal()._isShown){$("#confirm_delete_bulk_peers").removeAttr("disabled").html("Delete");$("#selected_peer_list").html("");$(".delete-bulk-peer-item.active").removeClass("active");window.configurations.deleteBulkModal().toggle()}window.configurations.loadPeers($("#search_peer_textbox").val());$("#alertToast").toast("show");$("#alertToast .toast-body").html("Peer deleted!");$("#delete_peer").removeAttr("disabled").html("Delete")}}})}function noResponding(){document.querySelectorAll(".no-response").forEach(ele=>ele.classList.add("active"));setTimeout(function(){document.querySelectorAll(".no-response").forEach(ele=>ele.classList.add("show"));document.querySelector("#right_body").classList.add("no-responding");document.querySelector(".navbar").classList.add("no-responding")},10)}function removeNoResponding(){document.querySelectorAll(".no-response").forEach(ele=>ele.classList.remove("show"));document.querySelector("#right_body").classList.remove("no-responding");document.querySelector(".navbar").classList.remove("no-responding");setTimeout(function(){document.querySelectorAll(".no-response").forEach(ele=>ele.classList.remove("active"))},1010)}function setConfigurationInterval(){configuration_interval=setInterval(function(){loadPeers($("#search_peer_textbox").val())},configuration_timeout)}function removeConfigurationInterval(){clearInterval(configuration_interval)}function startProgressBar(){$progress_bar.css("width","0%").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%");setTimeout(function(){stillLoadingProgressBar()},300)}function stillLoadingProgressBar(){$progress_bar.css("transition","3s ease-in-out").css("width","75%")}function endProgressBar(){$progress_bar.css("transition","0.3s ease-in-out").css("width","100%");setTimeout(function(){$progress_bar.css("opacity","0")},250)}function roundN(value,digits){let tenToN=10**digits;return Math.round(value*tenToN)/tenToN}let d1=new Date;let time=0;let count=0;function loadPeers(searchString){startProgressBar();d1=new Date;$.ajax({method:"GET",url:`/get_config/${conf_name}?search=${encodeURIComponent(searchString)}`,headers:{"Content-Type":"application/json"}}).done(function(response){removeNoResponding();peers=response.peer_data;configurationAlert(response);configurationHeader(response);configurationPeers(response);$(".dot.dot-running").attr("title","Peer Connected").tooltip();$(".dot.dot-stopped").attr("title","Peer Disconnected").tooltip();$("i[data-toggle='tooltip']").tooltip();endProgressBar();let d2=new Date;let seconds=d2-d1;time+=seconds;count+=1;console.log(`Average ${time/count}ms`);$("#peer_loading_time").html(`Peer Loading Time: ${seconds}ms`)}).fail(function(){noResponding()})}function generate_key(){let keys=window.wireguard.generateKeypair();document.querySelector("#private_key").value=keys.privateKey;document.querySelector("#public_key").value=keys.publicKey;document.querySelector("#add_peer_alert").classList.add("d-none");document.querySelector("#re_generate_key i").classList.remove("rotating");document.querySelector("#enable_preshare_key").value=keys.presharedKey}function showToast(msg){$("#alertToast").toast("show");$("#alertToast .toast-body").html(msg)}function updateRefreshInterval(res,interval){if(res==="true"){configuration_timeout=interval;removeConfigurationInterval();setConfigurationInterval();showToast("Refresh Interval set to "+Math.round(interval/1e3)+" seconds")}else{$(".interval-btn-group button").removeClass("active");$('.interval-btn-group button[data-refresh-interval="'+configuration_timeout+'"]').addClass("active");showToast("Refresh Interval set unsuccessful")}}function cleanIp(val){let clean_ip=val.split(",");for(let i=0;i${ip}`}}}function download_one_config(conf){let link=document.createElement("a");link.download=conf.filename;let blob=new Blob([conf.content],{type:"text/conf"});link.href=window.URL.createObjectURL(blob);link.click()}function toggleBulkIP(element){let $selected_peer_list=$("#selected_peer_list");let id=element.data("id");let name=element.data("name")===""?"Untitled Peer":element.data("name");if(element.hasClass("active")){element.removeClass("active");$("#selected_peer_list .badge[data-id='"+id+"']").remove()}else{element.addClass("active");$selected_peer_list.append(''+name+" - "+id+"")}}function copyToClipboard(element){let $temp=$("");$body.append($temp);$temp.val($(element).text()).trigger("select");document.execCommand("copy");$temp.remove()}function getAvailableIps(){$.ajax({url:`/available_ips/${$add_peer.getAttribute("conf_id")}`,method:"GET"}).done(function(res){available_ips=res;let $list_group=document.querySelector("#available_ip_modal .modal-body .list-group");$list_group.innerHTML="";document.querySelector("#allowed_ips").value=available_ips[0];available_ips.forEach(ip=>$list_group.innerHTML+=`${ip}`)})}window.configurations={addModal:()=>{return addModal},deleteBulkModal:()=>{return deleteBulkModal},deleteModal:()=>{return deleteModal},ipModal:()=>{return ipModal},qrcodeModal:()=>{return qrcodeModal},settingModal:()=>{return settingModal},loadPeers:searchString=>{loadPeers(searchString)},addPeersByBulk:()=>{addPeersByBulk()},deletePeers:(config,peers_ids)=>{deletePeers(config,peers_ids)},getAvailableIps:()=>{getAvailableIps()},generateKeyPair:()=>{generate_key()},showToast:message=>{showToast(message)},updateRefreshInterval:(res,interval)=>{updateRefreshInterval(res,interval)},copyToClipboard:element=>{copyToClipboard(element)},toggleDeleteByBulkIP:element=>{toggleBulkIP(element)},downloadOneConfig:conf=>{download_one_config(conf)},triggerIp:ip=>{trigger_ip(ip)},cleanIp:val=>{return cleanIp(val)},startProgressBar:()=>{startProgressBar()},stillLoadingProgressBar:()=>{stillLoadingProgressBar()},endProgressBar:()=>{endProgressBar()}}})();let $body=$("body");let available_ips=[];let $add_peer=document.getElementById("save_peer");document.querySelector(".add_btn").addEventListener("click",()=>{window.configurations.addModal().toggle()});document.querySelector(".info").addEventListener("click",event=>{let selector=document.querySelector(".switch");if(selector.contains(event.target)){selector.style.display="none";document.querySelector("div[role=status]").style.display="inline-block";location.replace(`/switch/${selector.getAttribute("id")}`)}});document.querySelector("#private_key").addEventListener("change",event=>{let publicKey=document.querySelector("#public_key");if(event.target.value.length===44){publicKey.value=window.wireguard.generatePublicKey(event.target.value);publicKey.setAttribute("disabled","disabled")}else{publicKey.attributes.removeNamedItem("disabled");publicKey.value=""}});$("#add_modal").on("show.bs.modal",function(){window.configurations.generateKeyPair();window.configurations.getAvailableIps()}).on("hide.bs.modal",function(){$("#allowed_ips_indicator").html("")});$("#re_generate_key").on("click",function(){$("#public_key").attr("disabled","disabled");$("#re_generate_key i").addClass("rotating");window.configurations.generateKeyPair()});$("#allowed_ips").on("keyup",function(){let s=window.configurations.cleanIp($(this).val());s=s.split(",");if(available_ips.includes(s[s.length-1])){$("#allowed_ips_indicator").removeClass().addClass("text-success").html('')}else{$("#allowed_ips_indicator").removeClass().addClass("text-warning").html('')}});$("#peer_name_textbox").on("keyup",function(){$(".peer_name").html($(this).val())});$add_peer.addEventListener("click",function(){let $bulk_add=$("#bulk_add");if($bulk_add.prop("checked")){if(!$("#new_add_amount").hasClass("is-invalid")){window.configurations.addPeersByBulk()}}else{let $public_key=$("#public_key");let $private_key=$("#private_key");let $allowed_ips=$("#allowed_ips");$allowed_ips.val(window.configurations.cleanIp($allowed_ips.val()));let $new_add_DNS=$("#new_add_DNS");$new_add_DNS.val(window.configurations.cleanIp($new_add_DNS.val()));let $new_add_endpoint_allowed_ip=$("#new_add_endpoint_allowed_ip");$new_add_endpoint_allowed_ip.val(window.configurations.cleanIp($new_add_endpoint_allowed_ip.val()));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");$add_peer.setAttribute("disabled","disabled");$add_peer.innerHTML="Adding...";if($allowed_ips.val()!==""&&$public_key.val()!==""&&$new_add_DNS.val()!==""&&$new_add_endpoint_allowed_ip.val()!==""){let conf=$add_peer.getAttribute("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"));$.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(),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"),preshared_key:$enable_preshare_key.val()}),success:function(response){if(response!=="true"){$("#add_peer_alert").html(response).removeClass("d-none");data_list.forEach(ele=>ele.removeAttr("disabled"));$add_peer.removeAttribute("disabled");$add_peer.innerHTML="Save"}else{window.configurations.loadPeers("");data_list.forEach(ele=>ele.removeAttr("disabled"));$("#add_peer_form").trigger("reset");$add_peer.removeAttribute("disabled");$add_peer.innerHTML="Save";window.configurations.showToast("Add peer successful!");window.configurations.addModal().toggle()}}})}else{$("#add_peer_alert").html("Please fill in all required box.").removeClass("d-none");$add_peer.removeAttribute("disabled");$add_peer.innerHTML="Add"}}});$("#new_add_amount").on("keyup",function(){let $bulk_amount_validation=$("#bulk_amount_validation");if($(this).val().length>0){if(isNaN($(this).val())){$(this).removeClass("is-valid").addClass("is-invalid");$bulk_amount_validation.html("Please enter a valid integer")}else if($(this).val()>available_ips.length){$(this).removeClass("is-valid").addClass("is-invalid");$bulk_amount_validation.html(`Cannot create more than ${available_ips.length} peers.`)}else if($(this).val()<1){$(this).removeClass("is-valid").addClass("is-invalid");$bulk_amount_validation.html("Please enter at least 1 or more.")}else{$(this).removeClass("is-invalid").addClass("is-valid")}}else{$(this).removeClass("is-invalid").removeClass("is-valid")}});$("#bulk_add").on("change",function(){let hide=$(".non-bulk").find("input");let amount=$("#new_add_amount");if($(this).prop("checked")===true){for(let i=0;i{document.querySelector("#add_modal").classList.add("ip_modal_open")}).on("hidden.bs.modal",()=>{document.querySelector("#add_modal").classList.remove("ip_modal_open");let ips=[];let $selected_ip_list=document.querySelector("#selected_ip_list");for(let i=0;i<$selected_ip_list.childElementCount;i++){ips.push($selected_ip_list.children[i].dataset.ip)}ips.forEach(ele=>window.configurations.triggerIp(ele))});$body.on("click",".available-ip-badge",function(){$(".available-ip-item[data-ip='"+$(this).data("ip")+"']").removeClass("active");$(this).remove()});$body.on("click",".available-ip-item",function(){window.configurations.triggerIp($(this).data("ip"))});$("#search_available_ip").on("click",function(){window.configurations.ipModal().toggle();let $allowed_ips=document.querySelector("#allowed_ips");if($allowed_ips.value.length>0){let s=$allowed_ips.value.split(",");for(let i=0;i{window.configurations.ipModal().toggle();let ips=[];let $selected_ip_list=$("#selected_ip_list");$selected_ip_list.children().each(function(){ips.push($(this).data("ip"))});$("#allowed_ips").val(ips.join(", "));ips.forEach(ele=>window.configurations.triggerIp(ele))});$body.on("click",".btn-qrcode-peer",function(){let src=$(this).data("imgsrc");$.ajax({url:src,method:"GET"}).done(function(res){$("#qrcode_img").attr("src",res);window.configurations.qrcodeModal().toggle()})});$body.on("click",".btn-delete-peer",function(){let peer_id=$(this).attr("id");$("#delete_peer").attr("peer_id",peer_id);window.configurations.deleteModal().toggle()});$("#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");let peer_ids=[peer_id];window.configurations.deletePeers(config,peer_ids)});$body.on("click",".btn-setting-peer",function(){window.configurations.startProgressBar();let peer_id=$(this).attr("id");$("#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){let peer_name=response.name===""?"Untitled":response.name;$("#setting_modal .peer_name").html(peer_name);$("#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);window.configurations.settingModal().toggle();window.configurations.endProgressBar()}})});$("#setting_modal").on("hidden.bs.modal",function(){$("#setting_peer_alert").addClass("d-none")});$("#peer_private_key_textbox").on("change",function(){let $save_peer_setting=$("#save_peer_setting");if($(this).val().length>0){$.ajax({url:"/check_key_match/"+$save_peer_setting.attr("conf_id"),method:"POST",headers:{"Content-Type":"application/json"},data:JSON.stringify({private_key:$("#peer_private_key_textbox").val(),public_key:$save_peer_setting.attr("peer_id")})}).done(function(res){if(res.status==="failed"){$("#setting_peer_alert").html(res.status).removeClass("d-none")}else{$("#setting_peer_alert").addClass("d-none")}})}});$("#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"));$.ajax({method:"POST",url:"/save_peer_setting/"+conf_id,headers:{"Content-Type":"application/json"},data:JSON.stringify({id:peer_id,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()}),success:function(response){if(response.status==="failed"){$("#setting_peer_alert").html(response.msg).removeClass("d-none")}else{window.configurations.settingModal().toggle();window.configurations.loadPeers($("#search_peer_textbox").val());$("#alertToast").toast("show");$("#alertToast .toast-body").html("Peer Saved!")}$("#save_peer_setting").removeAttr("disabled").html("Save");data_list.forEach(ele=>ele.removeAttr("disabled"))}})}else{$("#setting_peer_alert").html("Please fill in all required box.").removeClass("d-none");$("#save_peer_setting").removeAttr("disabled").html("Save")}});$(".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)});let typingTimer;let doneTypingInterval=200;$("#search_peer_textbox").on("keyup",function(){clearTimeout(typingTimer);typingTimer=setTimeout(()=>{window.configurations.loadPeers($(this).val())},doneTypingInterval)}).on("keydown",function(){clearTimeout(typingTimer)});$body.on("change","#sort_by_dropdown",function(){$.ajax({method:"POST",data:JSON.stringify({sort:$("#sort_by_dropdown option:selected").val()}),headers:{"Content-Type":"application/json"},url:"/update_dashboard_sort",success:function(){window.configurations.loadPeers($("#search_peer_textbox").val())}})});$body.on("mouseenter",".key",function(){let label=$(this).parent().siblings().children()[1];label.style.opacity="100"}).on("mouseout",".key",function(){let label=$(this).parent().siblings().children()[1];label.style.opacity="0";setTimeout(function(){label.innerHTML="CLICK TO COPY"},200)}).on("click",".key",function(){let label=$(this).parent().siblings().children()[1];window.configurations.copyToClipboard($(this));label.innerHTML="COPIED!"});$body.on("click",".update_interval",function(){$(".interval-btn-group button").removeClass("active");let _new=$(this);_new.addClass("active");let interval=$(this).data("refresh-interval");$.ajax({method:"POST",data:"interval="+$(this).data("refresh-interval"),url:"/update_dashboard_refresh_interval",success:function(res){window.configurations.updateRefreshInterval(res,interval)}})});$body.on("click",".refresh",function(){window.configurations.loadPeers($("#search_peer_textbox").val())});$body.on("click",".display_mode",function(){$(".display-btn-group button").removeClass("active");$(this).addClass("active");let display_mode=$(this).data("display-mode");$.ajax({method:"GET",url:"/switch_display_mode/"+$(this).data("display-mode"),success:function(res){if(res==="true"){if(display_mode==="list"){Array($(".peer_list").children()).forEach(function(child){$(child).removeClass().addClass("col-12")});window.configurations.showToast("Displaying as List")}else{Array($(".peer_list").children()).forEach(function(child){$(child).removeClass().addClass("col-sm-6 col-lg-4")});window.configurations.showToast("Displaying as Grids")}}}})});let $setting_btn_menu=$(".setting_btn_menu");$setting_btn_menu.css("top",($setting_btn_menu.height()+54)*-1);let $setting_btn=$(".setting_btn");$setting_btn.on("click",function(){if($setting_btn_menu.hasClass("show")){$setting_btn_menu.removeClass("showing");setTimeout(function(){$setting_btn_menu.removeClass("show")},201)}else{$setting_btn_menu.addClass("show");setTimeout(function(){$setting_btn_menu.addClass("showing")},10)}});$("html").on("click",function(r){if(document.querySelector(".setting_btn")!==r.target){if(!document.querySelector(".setting_btn").contains(r.target)){if(!document.querySelector(".setting_btn_menu").contains(r.target)){$setting_btn_menu.removeClass("showing");setTimeout(function(){$setting_btn_menu.removeClass("show")},310)}}}});$("#delete_peers_by_bulk_btn").on("click",()=>{let $delete_bulk_modal_list=$("#delete_bulk_modal .list-group");$delete_bulk_modal_list.html("");peers.forEach(peer=>{let name;if(peer.name===""){name="Untitled Peer"}else{name=peer.name}$delete_bulk_modal_list.append(''+name+" "+peer.id+"")});window.configurations.deleteBulkModal().toggle()});$body.on("click",".delete-bulk-peer-item",function(){window.configurations.toggleDeleteByBulkIP($(this))}).on("click",".delete-peer-bulk-badge",function(){window.configurations.toggleDeleteByBulkIP($(".delete-bulk-peer-item[data-id='"+$(this).data("id")+"']"))});let $selected_peer_list=document.getElementById("selected_peer_list");let changeObserver=new MutationObserver(function(){if($selected_peer_list.hasChildNodes()){$("#confirm_delete_bulk_peers").removeAttr("disabled")}else{$("#confirm_delete_bulk_peers").attr("disabled","disabled")}});changeObserver.observe($selected_peer_list,{attributes:true,childList:true,characterData:true});let confirm_delete_bulk_peers_interval;$("#confirm_delete_bulk_peers").on("click",function(){let btn=$(this);if(confirm_delete_bulk_peers_interval!==undefined){clearInterval(confirm_delete_bulk_peers_interval);confirm_delete_bulk_peers_interval=undefined;btn.html("Delete")}else{let timer=5;btn.html(`Deleting in ${timer} secs... Click to cancel`);confirm_delete_bulk_peers_interval=setInterval(function(){timer-=1;btn.html(`Deleting in ${timer} secs... Click to cancel`);if(timer===0){btn.html(`Deleting...`);btn.attr("disabled","disabled");let ips=[];$selected_peer_list.childNodes.forEach(ele=>ips.push(ele.dataset.id));window.configurations.deletePeers(btn.data("conf"),ips);clearInterval(confirm_delete_bulk_peers_interval);confirm_delete_bulk_peers_interval=undefined}},1e3)}});$("#select_all_delete_bulk_peers").on("click",function(){$(".delete-bulk-peer-item").each(function(){if(!$(this).hasClass("active")){window.configurations.toggleDeleteByBulkIP($(this))}})});$(window.configurations.deleteBulkModal()._element).on("hidden.bs.modal",function(){$(".delete-bulk-peer-item").each(function(){if($(this).hasClass("active")){window.configurations.toggleDeleteByBulkIP($(this))}})});$body.on("click",".btn-download-peer",function(e){e.preventDefault();let link=$(this).attr("href");$.ajax({url:link,method:"GET",success:function(res){window.configurations.downloadOneConfig(res)}})});$("#download_all_peers").on("click",function(){$.ajax({url:$(this).data("url"),method:"GET",success:function(res){if(res.peers.length>0){window.wireguard.generateZipFiles(res);window.configurations.showToast("Peers' zip file download successful!")}else{window.configurations.showToast("Oops! There are no peer can be download.")}}})});
\ No newline at end of file
+!function () { let e, t = 0, a = $(".progress-bar"), i = { keyboard: !1, backdrop: "static" }, o = new bootstrap.Modal(document.getElementById("add_modal"), i), n = new bootstrap.Modal(document.getElementById("delete_bulk_modal"), i), l = new bootstrap.Modal(document.getElementById("available_ip_modal"), i), s = new bootstrap.Modal(document.getElementById("qrcode_modal"), i), r = new bootstrap.Modal(document.getElementById("setting_modal"), i), d = new bootstrap.Modal(document.getElementById("delete_modal"), i); function c() { e = setInterval((function () { f($("#search_peer_textbox").val()) }), t) } function u() { clearInterval(e) } function p() { a.css("width", "0%").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%"), setTimeout((function () { _() }), 300) } function _() { a.css("transition", "3s ease-in-out").css("width", "75%") } function m() { a.css("transition", "0.3s ease-in-out").css("width", "100%"), setTimeout((function () { a.css("opacity", "0") }), 250) } function g(e, t) { let a = 10 ** t; return Math.round(e * a) / a } $("[data-toggle='tooltip']").tooltip(), $("[data-toggle='popover']").popover(); let v = new Date, h = 0, b = 0; function f(e) { p(), v = new Date, $.ajax({ method: "GET", url: `/get_config/${conf_name}?search=${encodeURIComponent(e)}`, headers: { "Content-Type": "application/json" } }).done((function (e) { document.querySelectorAll(".no-response").forEach((e => e.classList.remove("show"))), document.querySelector("#right_body").classList.remove("no-responding"), document.querySelector(".navbar").classList.remove("no-responding"), setTimeout((function () { document.querySelectorAll(".no-response").forEach((e => e.classList.remove("active"))) }), 1010), peers = e.peer_data, function (e) { if ("" === e.listen_port && "stopped" === e.status) { let e = document.createElement("div"); e.classList.add("alert"), e.classList.add("alert-warning"), e.setAttribute("role", "alert"), e.innerHTML = "Peer QR Code and configuration file download required a specified Listen Port.", document.querySelector("#config_info_alert").appendChild(e) } if ("N/A" === e.conf_address) { let e = document.createElement("div"); e.classList.add("alert"), e.classList.add("alert-warning"), e.setAttribute("role", "alert"), e.innerHTML = "Configuration Address need to be specified to have peers connect to it.", document.querySelector("#config_info_alert").appendChild(e) } }(e), function (e) { let t = document.getElementById("conf_status_btn"); "checked" === e.checked ? t.innerHTML = ` ON` : t.innerHTML = ` OFF`, t.classList.remove("info_loading"), document.querySelectorAll("#sort_by_dropdown option").forEach((e => e.removeAttribute("selected"))), document.querySelector(`#sort_by_dropdown option[value="${e.sort_tag}"]`).setAttribute("selected", "selected"), document.querySelectorAll(".interval-btn-group button").forEach((e => e.classList.remove("active"))), document.querySelector(`button[data-refresh-interval="${e.dashboard_refresh_interval}"]`).classList.add("active"), document.querySelectorAll(".display-btn-group button").forEach((e => e.classList.remove("active"))), document.querySelector(`button[data-display-mode="${e.peer_display_mode}"]`).classList.add("active"), document.querySelector("#conf_status").innerHTML = `${e.status}`, document.querySelector("#conf_connected_peers").innerHTML = e.running_peer, document.querySelector("#conf_total_data_usage").innerHTML = `${e.total_data_usage[0]} GB`, document.querySelector("#conf_total_data_received").innerHTML = `${e.total_data_usage[2]} GB`, document.querySelector("#conf_total_data_sent").innerHTML = `${e.total_data_usage[1]} GB`, document.querySelector("#conf_public_key").innerHTML = e.public_key, document.querySelector("#conf_listen_port").innerHTML = "" === e.listen_port ? "N/A" : e.listen_port, document.querySelector("#conf_address").innerHTML = e.conf_address, document.querySelectorAll(".info h6").forEach((e => e.classList.remove("info_loading"))) }(e), function (e) { let a = ""; if (0 === e.peer_data.length) document.querySelector(".peer_list").innerHTML = '
Oops! No peers found ‘︿’
'; else { let i = "list" === e.peer_display_mode ? "col-12" : "col-sm-6 col-lg-4"; e.peer_data.forEach((function (t) { let o = 0, n = 0; o += t.cumu_receive, n += t.cumu_sent; let l = '', s = '
' + ("" === t.name ? "Untitled" : t.name) + '
', r = '
' + g(t.total_receive + o, 4) + ' GB
' + g(t.total_sent + n, 4) + " GB
", d = '
PEERCLICK TO COPY
' + t.id + "
", c = '
ALLOWED IP
' + t.allowed_ips + "
", u = '
LATEST HANDSHAKE
' + t.latest_handshake + "
", p = '
END POINT
' + t.endpoint + "
", _ = '
'; "" !== t.private_key && (_ += '
'), _ += "
"; let m = '
' + s + l + r + d + c + u + l + p + l + _ + "
"; a += m })), document.querySelector(".peer_list").innerHTML = a, e.dashboard_refresh_interval !== t && (t = e.dashboard_refresh_interval, u(), c()) } }(e), $(".dot.dot-running").attr("title", "Peer Connected").tooltip(), $(".dot.dot-stopped").attr("title", "Peer Disconnected").tooltip(), $("i[data-toggle='tooltip']").tooltip(), m(); let a = new Date - v; h += a, b += 1, console.log(`Average ${h / b}ms`), $("#peer_loading_time").html(`Peer Loading Time: ${a}ms`) })).fail((function () { document.querySelectorAll(".no-response").forEach((e => e.classList.add("active"))), setTimeout((function () { document.querySelectorAll(".no-response").forEach((e => e.classList.add("show"))), document.querySelector("#right_body").classList.add("no-responding"), document.querySelector(".navbar").classList.add("no-responding") }), 10) })) } function w(e) { $("#alertToast").toast("show"), $("#alertToast .toast-body").html(e) } window.configurations = { addModal: () => o, deleteBulkModal: () => n, deleteModal: () => d, ipModal: () => l, qrcodeModal: () => s, settingModal: () => r, loadPeers: e => { f(e) }, addPeersByBulk: () => { !function () { let e = $("#new_add_amount"); $add_peer.setAttribute("disabled", "disabled"), $add_peer.innerHTML = `Adding ${e.val()} peers...`; let t = $("#new_add_DNS"); t.val(window.configurations.cleanIp(t.val())); let a = $("#new_add_endpoint_allowed_ip"); a.val(window.configurations.cleanIp(a.val())); let i = $("#new_add_MTU"), o = $("#new_add_keep_alive"), n = $("#enable_preshare_key"), l = [t, a, i, o]; if (e.val() > 0 && !e.hasClass("is-invalid")) if ("" !== t.val() && "" !== a.val()) { let s = $add_peer.getAttribute("conf_id"), r = []; for (let t = 0; t < e.val(); t++)r.push(window.wireguard.generateKeypair()); $.ajax({ method: "POST", url: "/add_peer_bulk/" + s, headers: { "Content-Type": "application/json" }, data: JSON.stringify({ DNS: t.val(), endpoint_allowed_ips: a.val(), MTU: i.val(), keep_alive: o.val(), enable_preshared_key: n.prop("checked"), keys: r, amount: e.val() }), success: function (t) { "true" !== t ? ($("#add_peer_alert").html(t).removeClass("d-none"), l.forEach((e => e.removeAttr("disabled"))), $add_peer.removeAttribute("disabled"), $add_peer.innerHTML = "Save") : (window.configurations.loadPeers(""), l.forEach((e => e.removeAttr("disabled"))), $("#add_peer_form").trigger("reset"), $add_peer.removeAttribute("disabled"), $add_peer.innerHTML = "Save", window.configurations.showToast(e.val() + " peers added successful!"), window.configurations.addModal().toggle()) } }) } else $("#add_peer_alert").html("Please fill in all required box.").removeClass("d-none"), $add_peer.removeAttribute("disabled"), $add_peer.innerHTML = "Add"; else $add_peer.removeAttribute("disabled"), $add_peer.innerHTML = "Add" }() }, deletePeers: (e, t) => { !function (e, t) { $.ajax({ method: "POST", url: "/remove_peer/" + e, headers: { "Content-Type": "application/json" }, data: JSON.stringify({ action: "delete", peer_ids: t }), success: function (e) { if ("true" !== e) { if (window.configurations.deleteModal()._isShown && ($("#remove_peer_alert").html(e + $("#add_peer_alert").html()).removeClass("d-none"), $("#delete_peer").removeAttr("disabled").html("Delete")), window.configurations.deleteBulkModal()._isShown) { let t = $("#bulk_remove_peer_alert"); t.html(e + t.html()).removeClass("d-none"), $("#confirm_delete_bulk_peers").removeAttr("disabled").html("Delete") } } else window.configurations.deleteModal()._isShown && window.configurations.deleteModal().toggle(), window.configurations.deleteBulkModal()._isShown && ($("#confirm_delete_bulk_peers").removeAttr("disabled").html("Delete"), $("#selected_peer_list").html(""), $(".delete-bulk-peer-item.active").removeClass("active"), window.configurations.deleteBulkModal().toggle()), window.configurations.loadPeers($("#search_peer_textbox").val()), $("#alertToast").toast("show"), $("#alertToast .toast-body").html("Peer deleted!"), $("#delete_peer").removeAttr("disabled").html("Delete") } }) }(e, t) }, getAvailableIps: () => { $.ajax({ url: `/available_ips/${$add_peer.getAttribute("conf_id")}`, method: "GET" }).done((function (e) { available_ips = e; let t = document.querySelector("#available_ip_modal .modal-body .list-group"); t.innerHTML = "", document.querySelector("#allowed_ips").value = available_ips[0], available_ips.forEach((e => t.innerHTML += `${e}`)) })) }, generateKeyPair: () => { !function () { let e = window.wireguard.generateKeypair(); document.querySelector("#private_key").value = e.privateKey, document.querySelector("#public_key").value = e.publicKey, document.querySelector("#add_peer_alert").classList.add("d-none"), document.querySelector("#re_generate_key i").classList.remove("rotating"), document.querySelector("#enable_preshare_key").value = e.presharedKey }() }, showToast: e => { w(e) }, updateRefreshInterval: (e, a) => { !function (e, a) { "true" === e ? (t = a, u(), c(), w("Refresh Interval set to " + Math.round(a / 1e3) + " seconds")) : ($(".interval-btn-group button").removeClass("active"), $('.interval-btn-group button[data-refresh-interval="' + t + '"]').addClass("active"), w("Refresh Interval set unsuccessful")) }(e, a) }, copyToClipboard: e => { !function (e) { let t = $(""); $body.append(t), t.val($(e).text()).trigger("select"), document.execCommand("copy"), t.remove() }(e) }, toggleDeleteByBulkIP: e => { !function (e) { let t = $("#selected_peer_list"), a = e.data("id"), i = "" === e.data("name") ? "Untitled Peer" : e.data("name"); e.hasClass("active") ? (e.removeClass("active"), $("#selected_peer_list .badge[data-id='" + a + "']").remove()) : (e.addClass("active"), t.append('' + i + " - " + a + "")) }(e) }, downloadOneConfig: e => { !function (e) { let t = document.createElement("a"); t.download = e.filename; let a = new Blob([e.content], { type: "text/conf" }); t.href = window.URL.createObjectURL(a), t.click() }(e) }, triggerIp: e => { !function (e) { let t = document.querySelector(`.available-ip-item[data-ip='${e}']`); t && (t.classList.contains("active") ? (t.classList.remove("active"), document.querySelector(`#selected_ip_list .badge[data-ip='${e}']`).remove()) : (t.classList.add("active"), document.querySelector("#selected_ip_list").innerHTML += `${e}`)) }(e) }, cleanIp: e => function (e) { let t = e.split(","); for (let e = 0; e < t.length; e++)t[e] = t[e].trim(" "); return t.filter(Boolean).join(",") }(e), startProgressBar: () => { p() }, stillLoadingProgressBar: () => { _() }, endProgressBar: () => { m() } } }(); let typingTimer, $body = $("body"), available_ips = [], $add_peer = document.getElementById("save_peer"); document.querySelector(".add_btn").addEventListener("click", (() => { window.configurations.addModal().toggle() })), document.querySelector(".info").addEventListener("click", (e => { let t = document.querySelector(".switch"); t.contains(e.target) && (t.style.display = "none", document.querySelector("div[role=status]").style.display = "inline-block", location.replace(`/switch/${t.getAttribute("id")}`)) })), document.querySelector("#private_key").addEventListener("change", (e => { let t = document.querySelector("#public_key"); 44 === e.target.value.length ? (t.value = window.wireguard.generatePublicKey(e.target.value), t.setAttribute("disabled", "disabled")) : (t.attributes.removeNamedItem("disabled"), t.value = "") })), $("#add_modal").on("show.bs.modal", (function () { window.configurations.generateKeyPair(), window.configurations.getAvailableIps() })).on("hide.bs.modal", (function () { $("#allowed_ips_indicator").html("") })), $("#re_generate_key").on("click", (function () { $("#public_key").attr("disabled", "disabled"), $("#re_generate_key i").addClass("rotating"), window.configurations.generateKeyPair() })), $("#allowed_ips").on("keyup", (function () { let e = window.configurations.cleanIp($(this).val()); e = e.split(","), available_ips.includes(e[e.length - 1]) ? $("#allowed_ips_indicator").removeClass().addClass("text-success").html('') : $("#allowed_ips_indicator").removeClass().addClass("text-warning").html('') })), $("#peer_name_textbox").on("keyup", (function () { $(".peer_name").html($(this).val()) })), $add_peer.addEventListener("click", (function () { if ($("#bulk_add").prop("checked")) $("#new_add_amount").hasClass("is-invalid") || window.configurations.addPeersByBulk(); else { let e = $("#public_key"), t = $("#private_key"), a = $("#allowed_ips"); a.val(window.configurations.cleanIp(a.val())); let i = $("#new_add_DNS"); i.val(window.configurations.cleanIp(i.val())); let o = $("#new_add_endpoint_allowed_ip"); o.val(window.configurations.cleanIp(o.val())); let n = $("#new_add_name"), l = $("#new_add_MTU"), s = $("#new_add_keep_alive"), r = $("#enable_preshare_key"); if ($add_peer.setAttribute("disabled", "disabled"), $add_peer.innerHTML = "Adding...", "" !== a.val() && "" !== e.val() && "" !== i.val() && "" !== o.val()) { let d = $add_peer.getAttribute("conf_id"), c = [t, a, n, i, o, l, s]; c.forEach((e => e.attr("disabled", "disabled"))), $.ajax({ method: "POST", url: "/add_peer/" + d, headers: { "Content-Type": "application/json" }, data: JSON.stringify({ private_key: t.val(), public_key: e.val(), allowed_ips: a.val(), name: n.val(), DNS: i.val(), endpoint_allowed_ips: o.val(), MTU: l.val(), keep_alive: s.val(), enable_preshared_key: r.prop("checked"), preshared_key: r.val() }), success: function (e) { "true" !== e ? ($("#add_peer_alert").html(e).removeClass("d-none"), c.forEach((e => e.removeAttr("disabled"))), $add_peer.removeAttribute("disabled"), $add_peer.innerHTML = "Save") : (window.configurations.loadPeers(""), c.forEach((e => e.removeAttr("disabled"))), $("#add_peer_form").trigger("reset"), $add_peer.removeAttribute("disabled"), $add_peer.innerHTML = "Save", window.configurations.showToast("Add peer successful!"), window.configurations.addModal().toggle()) } }) } else $("#add_peer_alert").html("Please fill in all required box.").removeClass("d-none"), $add_peer.removeAttribute("disabled"), $add_peer.innerHTML = "Add" } })), $("#new_add_amount").on("keyup", (function () { let e = $("#bulk_amount_validation"); $(this).val().length > 0 ? isNaN($(this).val()) ? ($(this).removeClass("is-valid").addClass("is-invalid"), e.html("Please enter a valid integer")) : $(this).val() > available_ips.length ? ($(this).removeClass("is-valid").addClass("is-invalid"), e.html(`Cannot create more than ${available_ips.length} peers.`)) : $(this).val() < 1 ? ($(this).removeClass("is-valid").addClass("is-invalid"), e.html("Please enter at least 1 or more.")) : $(this).removeClass("is-invalid").addClass("is-valid") : $(this).removeClass("is-invalid").removeClass("is-valid") })), $("#bulk_add").on("change", (function () { let e = $(".non-bulk").find("input"), t = $("#new_add_amount"); if (!0 === $(this).prop("checked")) { for (let t = 0; t < e.length; t++)$(e[t]).attr("disabled", "disabled"); t.removeAttr("disabled") } else { for (let t = 0; t < e.length; t++)"public_key" !== $(e[t]).attr("id") && $(e[t]).removeAttr("disabled"); t.attr("disabled", "disabled") } })), $("#available_ip_modal").on("show.bs.modal", (() => { document.querySelector("#add_modal").classList.add("ip_modal_open") })).on("hidden.bs.modal", (() => { document.querySelector("#add_modal").classList.remove("ip_modal_open"); let e = [], t = document.querySelector("#selected_ip_list"); for (let a = 0; a < t.childElementCount; a++)e.push(t.children[a].dataset.ip); e.forEach((e => window.configurations.triggerIp(e))) })), $body.on("click", ".available-ip-badge", (function () { $(".available-ip-item[data-ip='" + $(this).data("ip") + "']").removeClass("active"), $(this).remove() })), $body.on("click", ".available-ip-item", (function () { window.configurations.triggerIp($(this).data("ip")) })), $("#search_available_ip").on("click", (function () { window.configurations.ipModal().toggle(); let e = document.querySelector("#allowed_ips"); if (e.value.length > 0) { let t = e.value.split(","); for (let e = 0; e < t.length; e++)t[e] = t[e].trim(), window.configurations.triggerIp(t[e]) } })).tooltip(), $("#confirm_ip").on("click", (() => { window.configurations.ipModal().toggle(); let e = []; $("#selected_ip_list").children().each((function () { e.push($(this).data("ip")) })), $("#allowed_ips").val(e.join(", ")), e.forEach((e => window.configurations.triggerIp(e))) })), $body.on("click", ".btn-qrcode-peer", (function () { let e = $(this).data("imgsrc"); $.ajax({ url: e, method: "GET" }).done((function (e) { $("#qrcode_img").attr("src", e), window.configurations.qrcodeModal().toggle() })) })), $body.on("click", ".btn-delete-peer", (function () { let e = $(this).attr("id"); $("#delete_peer").attr("peer_id", e), window.configurations.deleteModal().toggle() })), $("#delete_peer").on("click", (function () { $(this).attr("disabled", "disabled"), $(this).html("Deleting..."); let e = $(this).attr("peer_id"), t = $(this).attr("conf_id"), a = [e]; window.configurations.deletePeers(t, a) })), $body.on("click", ".btn-setting-peer", (function () { window.configurations.startProgressBar(); let e = $(this).attr("id"); $("#save_peer_setting").attr("peer_id", e), $.ajax({ method: "POST", url: "/get_peer_data/" + $("#setting_modal").attr("conf_id"), headers: { "Content-Type": "application/json" }, data: JSON.stringify({ id: e }), success: function (e) { let t = "" === e.name ? "Untitled" : e.name; $("#setting_modal .peer_name").html(t), $("#setting_modal #peer_name_textbox").val(e.name), $("#setting_modal #peer_private_key_textbox").val(e.private_key), $("#setting_modal #peer_DNS_textbox").val(e.DNS), $("#setting_modal #peer_allowed_ip_textbox").val(e.allowed_ips), $("#setting_modal #peer_endpoint_allowed_ips").val(e.endpoint_allowed_ips), $("#setting_modal #peer_mtu").val(e.mtu), $("#setting_modal #peer_keep_alive").val(e.keepalive), $("#setting_modal #peer_preshared_key_textbox").val(e.preshared_key), window.configurations.settingModal().toggle(), window.configurations.endProgressBar() } }) })), $("#setting_modal").on("hidden.bs.modal", (function () { $("#setting_peer_alert").addClass("d-none") })), $("#peer_private_key_textbox").on("change", (function () { let e = $("#save_peer_setting"); $(this).val().length > 0 && $.ajax({ url: "/check_key_match/" + e.attr("conf_id"), method: "POST", headers: { "Content-Type": "application/json" }, data: JSON.stringify({ private_key: $("#peer_private_key_textbox").val(), public_key: e.attr("peer_id") }) }).done((function (e) { "failed" === e.status ? $("#setting_peer_alert").html(e.status).removeClass("d-none") : $("#setting_peer_alert").addClass("d-none") })) })), $("#save_peer_setting").on("click", (function () { $(this).attr("disabled", "disabled"), $(this).html("Saving..."); let e = $("#peer_DNS_textbox"), t = $("#peer_allowed_ip_textbox"), a = $("#peer_endpoint_allowed_ips"), i = $("#peer_name_textbox"), o = $("#peer_private_key_textbox"), n = $("#peer_preshared_key_textbox"), l = $("#peer_mtu"), s = $("#peer_keep_alive"); if ("" !== e.val() && "" !== t.val() && "" !== a.val()) { let r = $(this).attr("peer_id"), d = $(this).attr("conf_id"), c = [i, e, o, n, t, a, l, s]; c.forEach((e => e.attr("disabled", "disabled"))), $.ajax({ method: "POST", url: "/save_peer_setting/" + d, headers: { "Content-Type": "application/json" }, data: JSON.stringify({ id: r, name: i.val(), DNS: e.val(), private_key: o.val(), allowed_ips: t.val(), endpoint_allowed_ips: a.val(), MTU: l.val(), keep_alive: s.val(), preshared_key: n.val() }), success: function (e) { "failed" === e.status ? $("#setting_peer_alert").html(e.msg).removeClass("d-none") : (window.configurations.settingModal().toggle(), window.configurations.loadPeers($("#search_peer_textbox").val()), $("#alertToast").toast("show"), $("#alertToast .toast-body").html("Peer Saved!")), $("#save_peer_setting").removeAttr("disabled").html("Save"), c.forEach((e => e.removeAttr("disabled"))) } }) } else $("#setting_peer_alert").html("Please fill in all required box.").removeClass("d-none"), $("#save_peer_setting").removeAttr("disabled").html("Save") })), $(".peer_private_key_textbox_switch").on("click", (function () { let e = $("#peer_private_key_textbox"), t = "password" === e.attr("type") ? "text" : "password", a = "password" === e.attr("type") ? "bi bi-eye-slash-fill" : "bi bi-eye-fill"; e.attr("type", t), $(".peer_private_key_textbox_switch i").removeClass().addClass(a) })); let doneTypingInterval = 200; $("#search_peer_textbox").on("keyup", (function () { clearTimeout(typingTimer), typingTimer = setTimeout((() => { window.configurations.loadPeers($(this).val()) }), doneTypingInterval) })).on("keydown", (function () { clearTimeout(typingTimer) })), $body.on("change", "#sort_by_dropdown", (function () { $.ajax({ method: "POST", data: JSON.stringify({ sort: $("#sort_by_dropdown option:selected").val() }), headers: { "Content-Type": "application/json" }, url: "/update_dashboard_sort", success: function () { window.configurations.loadPeers($("#search_peer_textbox").val()) } }) })), $body.on("mouseenter", ".key", (function () { $(this).parent().siblings().children()[1].style.opacity = "100" })).on("mouseout", ".key", (function () { let e = $(this).parent().siblings().children()[1]; e.style.opacity = "0", setTimeout((function () { e.innerHTML = "CLICK TO COPY" }), 200) })).on("click", ".key", (function () { let e = $(this).parent().siblings().children()[1]; window.configurations.copyToClipboard($(this)), e.innerHTML = "COPIED!" })), $body.on("click", ".update_interval", (function () { $(".interval-btn-group button").removeClass("active"), $(this).addClass("active"); let e = $(this).data("refresh-interval"); $.ajax({ method: "POST", data: "interval=" + $(this).data("refresh-interval"), url: "/update_dashboard_refresh_interval", success: function (t) { window.configurations.updateRefreshInterval(t, e) } }) })), $body.on("click", ".refresh", (function () { window.configurations.loadPeers($("#search_peer_textbox").val()) })), $body.on("click", ".display_mode", (function () { $(".display-btn-group button").removeClass("active"), $(this).addClass("active"); let e = $(this).data("display-mode"); $.ajax({ method: "GET", url: "/switch_display_mode/" + $(this).data("display-mode"), success: function (t) { "true" === t && ("list" === e ? (Array($(".peer_list").children()).forEach((function (e) { $(e).removeClass().addClass("col-12") })), window.configurations.showToast("Displaying as List")) : (Array($(".peer_list").children()).forEach((function (e) { $(e).removeClass().addClass("col-sm-6 col-lg-4") })), window.configurations.showToast("Displaying as Grids"))) } }) })); let $setting_btn_menu = $(".setting_btn_menu"); $setting_btn_menu.css("top", -1 * ($setting_btn_menu.height() + 54)); let $setting_btn = $(".setting_btn"); $setting_btn.on("click", (function () { $setting_btn_menu.hasClass("show") ? ($setting_btn_menu.removeClass("showing"), setTimeout((function () { $setting_btn_menu.removeClass("show") }), 201)) : ($setting_btn_menu.addClass("show"), setTimeout((function () { $setting_btn_menu.addClass("showing") }), 10)) })), $("html").on("click", (function (e) { document.querySelector(".setting_btn") !== e.target && (document.querySelector(".setting_btn").contains(e.target) || document.querySelector(".setting_btn_menu").contains(e.target) || ($setting_btn_menu.removeClass("showing"), setTimeout((function () { $setting_btn_menu.removeClass("show") }), 310))) })), $("#delete_peers_by_bulk_btn").on("click", (() => { let e = $("#delete_bulk_modal .list-group"); e.html(""), peers.forEach((t => { let a; a = "" === t.name ? "Untitled Peer" : t.name, e.append('' + a + " " + t.id + "") })), window.configurations.deleteBulkModal().toggle() })), $body.on("click", ".delete-bulk-peer-item", (function () { window.configurations.toggleDeleteByBulkIP($(this)) })).on("click", ".delete-peer-bulk-badge", (function () { window.configurations.toggleDeleteByBulkIP($(".delete-bulk-peer-item[data-id='" + $(this).data("id") + "']")) })); let confirm_delete_bulk_peers_interval, $selected_peer_list = document.getElementById("selected_peer_list"), changeObserver = new MutationObserver((function () { $selected_peer_list.hasChildNodes() ? $("#confirm_delete_bulk_peers").removeAttr("disabled") : $("#confirm_delete_bulk_peers").attr("disabled", "disabled") })); changeObserver.observe($selected_peer_list, { attributes: !0, childList: !0, characterData: !0 }), $("#confirm_delete_bulk_peers").on("click", (function () { let e = $(this); if (void 0 !== confirm_delete_bulk_peers_interval) clearInterval(confirm_delete_bulk_peers_interval), confirm_delete_bulk_peers_interval = void 0, e.html("Delete"); else { let t = 5; e.html(`Deleting in ${t} secs... Click to cancel`), confirm_delete_bulk_peers_interval = setInterval((function () { if (t -= 1, e.html(`Deleting in ${t} secs... Click to cancel`), 0 === t) { e.html("Deleting..."), e.attr("disabled", "disabled"); let t = []; $selected_peer_list.childNodes.forEach((e => t.push(e.dataset.id))), window.configurations.deletePeers(e.data("conf"), t), clearInterval(confirm_delete_bulk_peers_interval), confirm_delete_bulk_peers_interval = void 0 } }), 1e3) } })), $("#select_all_delete_bulk_peers").on("click", (function () { $(".delete-bulk-peer-item").each((function () { $(this).hasClass("active") || window.configurations.toggleDeleteByBulkIP($(this)) })) })), $(window.configurations.deleteBulkModal()._element).on("hidden.bs.modal", (function () { $(".delete-bulk-peer-item").each((function () { $(this).hasClass("active") && window.configurations.toggleDeleteByBulkIP($(this)) })) })), $body.on("click", ".btn-download-peer", (function (e) { e.preventDefault(); let t = $(this).attr("href"); $.ajax({ url: t, method: "GET", success: function (e) { window.configurations.downloadOneConfig(e) } }) })), $("#download_all_peers").on("click", (function () { $.ajax({ url: $(this).data("url"), method: "GET", success: function (e) { e.peers.length > 0 ? (window.wireguard.generateZipFiles(e), window.configurations.showToast("Peers' zip file download successful!")) : window.configurations.showToast("Oops! There are no peer can be download.") } }) }));
\ No newline at end of file
diff --git a/src/templates/configuration.html b/src/templates/configuration.html
index a7f2ce0..8b01eaa 100644
--- a/src/templates/configuration.html
+++ b/src/templates/configuration.html
@@ -1,8 +1,9 @@
{% with title=title%}
- {% include "header.html"%}
+{% include "header.html"%}
{% endwith %}
+
@@ -10,15 +11,15 @@
Oops! I can't connect to the server.
- {% include "navbar.html" %}
-
- {% include "sidebar.html" %}
+ {% include "navbar.html" %}
+