ip6.biz/src/js/connectivity.js
2021-05-02 20:53:12 +02:00

202 lines
6.8 KiB
JavaScript

var progress_bar = '<div class="progress progress-striped active"><div class="progress-bar" role="progressbar" style="width:0"></div></div>';
function test_ipv4() {
var $p = $("#v4_conn");
$p.find(".proto_supported4").html(progress_bar).find(".progress-bar").css("width", "100%");
$p.find(".proto_address4, .proto_hostname4, .proto_isp4").empty();
$.ajax({
url: "https://v4.ip6.biz/info.php",
dataType: "json",
timeout: 15000,
success: function(resp) {
$p.find(".proto_supported4").html("<span class='label label-success' style='font-size:1em'>Supported</span>");
$p.find(".proto_address4").html("<span class='address'>" + resp.address + "</span>");
$p.find(".proto_hostname4").html(resp.hostname ? resp.hostname : "<span class='label label-warning'>None</span>");
$p.find(".proto_isp4").html("<img class='img-flag' src='/img/flags/" + resp.country + ".png' title='" + resp.country + "' />" + resp.asn);
},
error: function(xopt, err) {
$p.find(".proto_supported4").html("<span class='label label-danger' style='font-size:1em'>Not supported</span>");
},
});
}
function test_ipv6() {
var $p = $("#v6_conn");
$p.find(".proto_supported").html(progress_bar).find(".progress-bar").css("width", "100%");
$p.find(".proto_address, .proto_hostname, .proto_isp, .proto_icmp").empty();
$.ajax({
url: "https://v6.ip6.biz/info.php",
dataType: "json",
timeout: 15000,
success: function(resp) {
$p.find(".proto_supported").html("<span class='label label-success' style='font-size:1em'>Supported</span>");
$p.find(".proto_address").html("<span class='address'>" + resp.address + "</span>");
if (resp.hostname) {
$p.find(".proto_hostname").html(resp.hostname);
} else {
if (resp.rdns_fail) {
$p.find(".proto_hostname").html("<span class='label label-danger'>SERVFAIL</span>");
} else {
$p.find(".proto_hostname").html("<span class='label label-warning'>None</span>");
}
}
$p.find(".proto_isp").html("<img class='img-flag' src='/img/flags/" + resp.country + ".png' title='" + resp.country + "' />" + resp.asn);
$p.find(".proto_icmp").html(progress_bar).find(".progress-bar").css("width", "100%");
$.ajax({
url: "https://v6.ip6.biz/icmp.php",
dataType: "json",
timeout: 2000,
success: function(resp) {
if (resp.status === "OK") {
$p.find(".proto_icmp").html("<span class='label label-success'>Reachable (" + resp.rtt + ")</span>");
} else {
$p.find(".proto_icmp").html("<span class='label label-warning'>Filtered</span>");
}
},
error: function(xopt, err) {
$p.find(".proto_icmp").html("<span class='label label-default'>Not tested</span>");
},
});
},
error: function(xopt, err) {
$p.find(".proto_supported").html("<span class='label label-danger' style='font-size:1em'>Not supported</span>");
},
});
}
function test_browser() {
var $p = $("#browser");
$p.find(".browser_default").html(progress_bar).find(".progress-bar").css("width", "100%");
$p.find(".browser_fallback").empty();
$.ajax({
url: "https://any.ip6.biz/proto.php",
dataType: "json",
timeout: 15000,
success: function(resp) {
$p.find(".browser_default").html("<span class='label label-success' style='font-size:1em'>IPv" + resp.protocol + "</span>");
$p.find(".browser_fallback").html(progress_bar).find(".progress-bar").css("width", "100%");
var fb_start = (new Date()).getTime();
$.ajax({
url: "https://f" + resp.protocol + ".ip6.biz/proto.php",
dataType: "json",
timeout: 15000,
success: function(resp2) {
var fb_time = Math.round(((new Date()).getTime() - fb_start));
var label = fb_time + " ms";
var lclass = "success";
if (fb_time > 1000) {
lclass = "warning";
}
$p.find(".browser_fallback").html("<span class='label label-" + lclass + "'>to IPv" + resp2.protocol + " in " + label + "</span>");
},
error: function(xopt, err) {
$p.find(".browser_fallback").html("<span class='label label-danger'>No</span>");
},
});
if (resp.protocol === "6") {
} else {
}
},
error: function(xopt, err) {
$p.find(".browser_default").html("<span class='label label-default'>Test failed</span>");
},
});
}
function test_dns() {
var $p = $("#dns");
$p.find(".dns_dns4_ip4, .dns_dns4_ip6, .dns_dns6_ip4, .dns_dns6_ip6").html(progress_bar).find(".progress-bar").css("width", "100%");
$.ajax({
url: "https://v4.z4.ip6.biz/proto.php",
dataType: "json",
timeout: 15000,
success: function(resp) {
if (resp.protocol === "4") {
$p.find(".dns_dns4_ip4").html("<span class='label label-success'>Reachable</span>");
} else {
$p.find(".dns_dns4_ip4").html("<span class='label label-default'>Test failed</span>");
}
},
error: function(xopt, err) {
$p.find(".dns_dns4_ip4").html("<span class='label label-danger'>Unreachable</span>");
},
});
$.ajax({
url: "https://v6.z4.ip6.biz/proto.php",
dataType: "json",
timeout: 15000,
success: function(resp) {
if (resp.protocol === "6") {
$p.find(".dns_dns4_ip6").html("<span class='label label-success'>Reachable</span>");
} else {
$p.find(".dns_dns4_ip6").html("<span class='label label-default'>Test failed</span>");
}
},
error: function(xopt, err) {
$p.find(".dns_dns4_ip6").html("<span class='label label-danger'>Unreachable</span>");
},
});
$.ajax({
url: "https://v4.z6.ip6.biz/proto.php",
dataType: "json",
timeout: 15000,
success: function(resp) {
if (resp.protocol === "4") {
$p.find(".dns_dns6_ip4").html("<span class='label label-success'>Reachable</span>");
} else {
$p.find(".dns_dns6_ip4").html("<span class='label label-default'>Test failed</span>");
}
},
error: function(xopt, err) {
$p.find(".dns_dns6_ip4").html("<span class='label label-danger'>Unreachable</span>");
},
});
$.ajax({
url: "https://v6.z6.ip6.biz/proto.php",
dataType: "json",
timeout: 15000,
success: function(resp) {
if (resp.protocol === "6") {
$p.find(".dns_dns6_ip6").html("<span class='label label-success'>Reachable</span>");
} else {
$p.find(".dns_dns6_ip6").html("<span class='label label-default'>Test failed</span>");
}
},
error: function(xopt, err) {
$p.find(".dns_dns6_ip6").html("<span class='label label-danger'>Unreachable</span>");
},
});
}
$(function() {
$("table span.glyphicon-question-sign").each(function(k, el) {
$(el).attr("data-title", $(el).closest("tr").find("th").text()).popover({
placement: "auto right",
container: "body",
});
});
$("#refresh_ipv4").click(function(ev) {
test_ipv4();
ev.preventDefault();
return false;
});
$("#refresh_ipv6").click(function(ev) {
test_ipv6();
ev.preventDefault();
return false;
});
$("#refresh_browser").click(function(ev) {
test_browser();
ev.preventDefault();
return false;
});
$("#refresh_dns").click(function(ev) {
test_dns();
ev.preventDefault();
return false;
});
test_browser();
test_ipv4();
test_ipv6();
test_dns();
});