vpn-status/assets/app.js

48 lines
1.3 KiB
JavaScript
Raw Normal View History

2013-10-03 22:19:10 +00:00
$(function() {
2013-10-04 09:11:31 +00:00
refreshNodes();
})
function refreshNodes() {
2013-10-03 22:19:10 +00:00
$("#nodeTable tr[data-node]").each(function(){
2013-10-04 12:58:58 +00:00
refreshNode($(this));
2013-10-03 22:19:10 +00:00
});
2013-10-04 09:11:31 +00:00
}
2013-10-04 12:58:58 +00:00
function refreshNode($node) {
var node = $node.data("node");
$.getJSON("/status/"+node, function (data) {
$node.find("span.loading").hide();
var label;
if (data["Status"] === "UP") {
label = "label-success";
$node.addClass("success");
$node.find("td.ping").text(data["Ping"] + "ms");
} else if (data["Status"] === "SLOW") {
label = "label-warning";
$node.addClass("warning");
$node.find("td.ping").text(data["Ping"] + "ms");
} else {
label = "label-danger";
$node.addClass("danger");
}
if (data["Domain"] === "devkid-nas.vpn") {
setNasWakeUpLink($node, data);
}
$node.find("span.status-text").addClass(label).text(data["Status"]);
})
}
function setNasWakeUpLink($node, data) {
var $nasStatus = $node.find("#nasStatus");
2013-10-04 09:11:31 +00:00
if ($nasStatus.length == 0){
var ele = '<a id="nasStatus" href="http://devkid-router.vpn:8080/cgi-bin/wake-nas" class="btn btn-link btn-sm">Wake up NAS</a>'
2013-10-04 12:58:58 +00:00
$node.find(".host").append(ele);
$nasStatus = $node.find("#nasStatus")
2013-10-04 09:11:31 +00:00
}
if (data["Status"] == "DOWN") {
$nasStatus.show();
} else {
$nasStatus.hide();
}
}