67 lines
2.9 KiB
JavaScript
Raw Normal View History

2022-01-12 19:53:36 -05:00
/**
* tools.js - Copyright(C) 2021 Donald Zou [https://github.com/donaldzou]
*/
$(".ip_dropdown").on("change",function (){
$(".modal.show .btn").removeAttr("disabled");
2021-05-13 18:00:40 -04:00
});
2022-01-12 19:53:36 -05:00
$(".conf_dropdown").on("change", function (){
$(".modal.show .ip_dropdown").html('<option value="none" selected="selected" disabled>Loading...');
2021-05-13 18:00:40 -04:00
$.ajax({
url: "/get_ping_ip",
method: "POST",
2022-01-12 19:53:36 -05:00
data: "config=" + $(this).children("option:selected").val(),
2021-05-13 18:00:40 -04:00
success: function (res){
2022-01-12 19:53:36 -05:00
$(".modal.show .ip_dropdown").html("");
$(".modal.show .ip_dropdown").append('<option value="none" selected="selected" disabled>Choose an IP');
$(".modal.show .ip_dropdown").append(res);
2021-05-13 18:00:40 -04:00
}
2022-01-12 19:53:36 -05:00
});
2021-05-13 18:00:40 -04:00
});
// Ping Tools
2022-01-12 19:53:36 -05:00
$(".send_ping").on("click", function (){
$(this).attr("disabled","disabled");
$(this).html("Pinging...");
$("#ping_modal .form-control").attr("disabled","disabled");
2021-05-13 18:00:40 -04:00
$.ajax({
method:"POST",
2022-01-12 19:53:36 -05:00
data: "ip="+ $(':selected', $("#ping_modal .ip_dropdown")).val() +
"&count=" + $("#ping_modal .ping_count").val(),
2021-05-13 18:00:40 -04:00
url: "/ping_ip",
success: function (res){
2022-01-12 19:53:36 -05:00
$(".ping_result tbody").html("");
let html = '<tr><th scope="row">Address</th><td>'+res.address+'</td></tr>' +
'<tr><th scope="row">Is Alive</th><td>'+res.is_alive+'</td></tr>' +
'<tr><th scope="row">Min RTT</th><td>'+res.min_rtt+'ms</td></tr>' +
'<tr><th scope="row">Average RTT </th><td>'+res.avg_rtt+'ms</td></tr>' +
'<tr><th scope="row">Max RTT</th><td>'+res.max_rtt+'ms</td></tr>' +
'<tr><th scope="row">Package Sent</th><td>'+res.package_sent+'</td></tr>' +
'<tr><th scope="row">Package Received</th><td>'+res.package_received+'</td></tr>' +
'<tr><th scope="row">Package Loss</th><td>'+res.package_loss+'</td></tr>';
$(".ping_result tbody").html(html);
$(".send_ping").removeAttr("disabled");
$(".send_ping").html("Ping");
$("#ping_modal .form-control").removeAttr("disabled");
2021-05-13 18:00:40 -04:00
}
2022-01-12 19:53:36 -05:00
});
2021-05-13 18:00:40 -04:00
});
// Traceroute Tools
2022-01-12 19:53:36 -05:00
$(".send_traceroute").on("click", function (){
$(this).attr("disabled","disabled");
2021-05-13 18:00:40 -04:00
$(this).html("Tracing...");
2022-01-12 19:53:36 -05:00
$("#traceroute_modal .form-control").attr("disabled","disabled");
2021-05-13 18:00:40 -04:00
$.ajax({
url: "/traceroute_ip",
method: "POST",
2022-01-12 19:53:36 -05:00
data: "ip=" + $(':selected', $("#traceroute_modal .ip_dropdown")).val(),
2021-05-13 18:00:40 -04:00
success: function (res){
$(".traceroute_result tbody").html("");
2022-01-12 19:53:36 -05:00
res.forEach((ele) =>
$(".traceroute_result tbody").append('<tr><th scope="row">'+ele.hop+'</th><td>'+ele.ip+'</td><td>'+ele.avg_rtt+'</td><td>'+ele.min_rtt+'</td><td>'+ele.max_rtt+'</td></tr>'));
$(".send_traceroute").removeAttr("disabled").html("Traceroute");
$("#traceroute_modal .form-control").removeAttr("disabled");
2021-05-13 18:00:40 -04:00
}
2022-01-12 19:53:36 -05:00
});
});