2024-01-24 17:29:52 +01:00
|
|
|
<!DOCTYPE html>
|
|
|
|
<html lang="en">
|
|
|
|
<head>
|
|
|
|
<title>MinIPAM</title>
|
|
|
|
<style>
|
|
|
|
.status_online {
|
|
|
|
background-color: lawngreen;
|
2024-01-24 18:39:01 +01:00
|
|
|
color: black;
|
2024-01-24 17:29:52 +01:00
|
|
|
}
|
|
|
|
.status_offline {
|
|
|
|
background-color: orangered;
|
2024-01-24 18:39:01 +01:00
|
|
|
color: black;
|
2024-01-24 17:29:52 +01:00
|
|
|
}
|
|
|
|
.status_free {
|
|
|
|
background-color: dimgray;
|
2024-01-24 18:39:01 +01:00
|
|
|
color: black;
|
|
|
|
}
|
|
|
|
body {
|
|
|
|
background-color: black;
|
|
|
|
color: white;
|
2024-01-24 17:29:52 +01:00
|
|
|
}
|
|
|
|
</style>
|
|
|
|
<script>
|
|
|
|
function formatHumanFriendlyTime(timestamp) {
|
|
|
|
const now = new Date();
|
|
|
|
const time = new Date(timestamp);
|
|
|
|
|
|
|
|
// Calculate the difference in milliseconds
|
|
|
|
const diffMilliseconds = now - time;
|
|
|
|
|
|
|
|
// Convert milliseconds to seconds
|
|
|
|
const diffSeconds = Math.floor(diffMilliseconds / 1000);
|
|
|
|
|
|
|
|
// Define time thresholds in seconds
|
|
|
|
const minuteThreshold = 60;
|
|
|
|
const hourThreshold = 3600;
|
|
|
|
const dayThreshold = 86400;
|
|
|
|
|
|
|
|
// Format the time relative to the current moment
|
|
|
|
if (diffSeconds < minuteThreshold) {
|
|
|
|
return `${diffSeconds} seconds ago`;
|
|
|
|
} else if (diffSeconds < hourThreshold) {
|
|
|
|
const minutes = Math.floor(diffSeconds / 60);
|
|
|
|
return `${minutes} minute${minutes > 1 ? 's' : ''} ago`;
|
|
|
|
} else if (diffSeconds < dayThreshold) {
|
|
|
|
const hours = Math.floor(diffSeconds / 3600);
|
|
|
|
return `${hours} hour${hours > 1 ? 's' : ''} ago`;
|
|
|
|
} else {
|
|
|
|
const days = Math.floor(diffSeconds / 86400);
|
|
|
|
return `${days} day${days > 1 ? 's' : ''} ago`;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var data = {}
|
|
|
|
function start() {
|
|
|
|
|
|
|
|
let xhr = new XMLHttpRequest();
|
|
|
|
xhr.open('GET', '/data');
|
|
|
|
xhr.onload = function() {
|
|
|
|
if (xhr.status != 200) { // analyze HTTP status of the response
|
|
|
|
alert(`Error ${xhr.status}: ${xhr.statusText}`); // e.g. 404: Not Found
|
|
|
|
} else { // show the result
|
|
|
|
data = JSON.parse(xhr.responseText)
|
2024-01-24 18:39:01 +01:00
|
|
|
let last=""
|
2024-01-24 17:29:52 +01:00
|
|
|
for (const subnet in data.Subnets) {
|
2024-01-24 18:39:01 +01:00
|
|
|
document.getElementById("subnetscontainer").innerHTML+="<button onClick=viewSubnet(this.innerText)>"+subnet+"</button>"
|
|
|
|
last=subnet
|
|
|
|
}
|
|
|
|
if(last != "") {
|
|
|
|
viewSubnet(last)
|
2024-01-24 17:29:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
};
|
|
|
|
xhr.send();
|
|
|
|
}
|
2024-01-24 18:39:01 +01:00
|
|
|
function viewSubnet(subnet) {
|
2024-01-24 17:29:52 +01:00
|
|
|
|
|
|
|
usedAddresses = data.Subnets[subnet].used_addresses
|
|
|
|
totalAddresses = data.Subnets[subnet].total_addresses
|
|
|
|
|
|
|
|
document.getElementById("subnetCidrField").innerText=subnet
|
|
|
|
document.getElementById("subnetUsedField").innerText=usedAddresses+" of "+totalAddresses
|
|
|
|
document.getElementById("subnetUsageBar").max=totalAddresses
|
|
|
|
document.getElementById("subnetUsageBar").value=usedAddresses
|
|
|
|
|
|
|
|
|
|
|
|
let tableHTML = '<table border="1"><thead><tr><th>IP Address</th><th>RevDNS</th><th>First seen</th><th>Last seen</th></tr></thead><tbody>';
|
|
|
|
|
2024-01-24 18:39:01 +01:00
|
|
|
|
|
|
|
const hosts = data.Subnets[subnet].hosts;
|
|
|
|
|
|
|
|
// Iterate over IPs in the subnet
|
|
|
|
data.Subnets[subnet].host_list.forEach(ip => {
|
|
|
|
const hostDetails = hosts[ip] || {}; // Get host details if available
|
|
|
|
|
|
|
|
// Determine the status based on the presence in hosts and online status
|
|
|
|
let revdns="";
|
|
|
|
let ls=""
|
|
|
|
let fs=""
|
|
|
|
let status;
|
|
|
|
if (ip in hosts) {
|
|
|
|
status = hostDetails.online ? 'online' : 'offline';
|
|
|
|
revdns = hostDetails.rev_dns;
|
|
|
|
ls = formatHumanFriendlyTime(hostDetails.last_seen)
|
|
|
|
fs = formatHumanFriendlyTime(hostDetails.first_seen)
|
|
|
|
|
|
|
|
} else {
|
|
|
|
status = 'free';
|
|
|
|
}
|
|
|
|
// Add a row to the HTML table
|
|
|
|
tableHTML += `<tr class="status_${status}"><td>${ip}</td><td>${revdns}</td><td>${fs}</td><td>${ls}</td></tr>`;
|
|
|
|
});
|
2024-01-24 17:29:52 +01:00
|
|
|
|
|
|
|
tableHTML += '</tbody></table>';
|
2024-01-24 18:39:01 +01:00
|
|
|
document.getElementById("subnetview").innerHTML=""
|
2024-01-24 17:29:52 +01:00
|
|
|
document.getElementById("subnetview").innerHTML=tableHTML
|
|
|
|
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
</head>
|
|
|
|
<body onLoad="start()">
|
|
|
|
Subnets:<br>
|
|
|
|
<div id="subnetscontainer"></div>
|
|
|
|
<hr>
|
|
|
|
<p>Subnet <span id="subnetCidrField"></span></p>
|
2024-01-24 18:39:01 +01:00
|
|
|
<p>Space usage <span id="subnetUsedField"></span></p>
|
|
|
|
<progress id="subnetUsageBar"></progress><br>
|
2024-01-24 17:29:52 +01:00
|
|
|
<div id="subnetview"></div>
|
|
|
|
</body>
|
|
|
|
</html>
|