sshmon/views/pages/index.ejs

80 lines
3.7 KiB
Plaintext
Raw Normal View History

2022-08-18 06:31:00 +00:00
<html>
<head>
<script>
const addresses = ["<%- addresses.join(`", \"`) %>"];
async function addIP() {
const addrElement = document.getElementById("addresses");
const ip = document.getElementById("ipaddr").value;
addresses.push("ip")
addrElement.innerHTML += '<div id="' + ip + '_main"><tr><td><input type="button" name="' + ip + '_rem" value="x" onClick="removeIP(\"' + ip + '\")"></td><td><div style="display: inline-block;" id="' + ip + '_addr">' + ip + '</div></td><td><div style="display: inline-block; margin-left: 5em" id="' + ip + '_status"><span style="color:blue;">PINGING...</span></div></td></tr></div>'
const b = document.getElementById(ip + "_status");
await fetch('http://localhost:8080/addIP/' + ip)
2022-08-22 09:28:10 +00:00
window.location.reload(true);
2022-08-18 06:31:00 +00:00
}
async function removeIP(ip) {
const tab = document.getElementById("tab");
tab.deleteRow(addresses.indexOf(ip.toString()));
await fetch('http://localhost:8080/removeIP/' + ip)
const a = document.getElementById(ip + "_main");
a.remove();
2022-09-16 16:30:37 +00:00
window.location.reload(true);
2022-08-18 06:31:00 +00:00
}
async function aaa() {
const date = new Date();
2022-08-24 08:44:13 +00:00
document.getElementById("main").innerHTML = "Last checked: " + date.toLocaleString();
document.getElementById("eta").innerHTML = "Next scheduled check: " + new Date(date.getTime() + <%= timeoutDelay %>).toLocaleString();
2022-08-18 06:31:00 +00:00
addresses.forEach(async a => {
const b = document.getElementById(a + "_status");
if(!b) return;
b.innerHTML = '<span style="color:blue;">PINGING...</span>'
await fetch('http://localhost:8080/ping/' + a)
.then((response) => response.json())
.then(async (data) => {
2022-08-24 08:44:13 +00:00
b.innerHTML = data.alive ? '<span style="color:green;">UP (' + data.numeric_host + ") " + data.time + 'ms</span>' : '<span style="color:red;">DOWN' + ((data.host == "unknown") ? " (UNKNOWN HOST)" : (" (" + data.numeric_host + ")")) + " since " + new Date(Number((await (await fetch('http://localhost:8080/downtime/' + a)).json()).downSince)).toLocaleString() + '</span>'
2022-08-18 06:31:00 +00:00
});
})
setTimeout(aaa, <%= timeoutDelay %>)
}
2022-08-18 08:57:58 +00:00
window.onload = aaa;
2022-08-18 06:31:00 +00:00
</script>
</head>
<body>
2022-08-18 08:57:58 +00:00
<%- include("../partials/navbar.ejs", { activeLink: "home", username, loggedIn }) %>
2022-08-18 06:31:00 +00:00
<div id="main"></div>
<div id="eta"></div><br />
<input type="text" name="ipaddr" id="ipaddr" value="">
<input type="submit" id="but" name="but" value="Add" onClick="addIP()"><br /><br />
<div id="addresses">
<table id="tab">
<% addresses.forEach(a => { %>
<div id="<%= a %>_main">
<tr>
<td>
<input type="button" name="<%= a %>_rem" value="x" onClick="removeIP('<%= a %>')">
</td><td>
<div style="display: inline-block;" id="<%= a %>_addr"><%= a %></div>
</td><td>
<div style="display: inline-block; margin-left: 5em" id="<%= a %>_status">
<span>WAITING</span>
</div>
</td>
</tr>
</div>
<% }) %>
</table>
</div>
<script>
document.getElementById("ipaddr")
.addEventListener("keyup", function(event) {
event.preventDefault();
if (event.keyCode === 13) document.getElementById("but").click();
});
</script>
</body>
</html>