linklogger/app/templates/dashboard.html

91 lines
2.3 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>LinkLogger | Dashboard</title>
</head>
<body>
<div>
<!-- Create a table with 5 columns with a total of 750px width -->
<table style="width: 750px; margin: 0 auto;">
<tr>
<th style="width: 150px;">ID</th>
<th style="width: 150px;">Timestamp</th>
<th style="width: 150px;">IP</th>
<th style="width: 150px;">Location</th>
<th style="width: 150px;">ISP</th>
</tr>
</div>
</body>
</html>
<style>
body {
margin: 0;
padding: 0;
font-family: Arial, sans-serif;
background-color: #2c3338;
}
div {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
text-align: center;
font-size: 25px;
color: #ccc;
}
</style>
<script>
// Function to get a cookie by name
function getCookie(name) {
const value = `; ${document.cookie}`;
const parts = value.split(`; ${name}=`);
if (parts.length === 2) return parts.pop().split(';').shift();
return null;
}
// On window load
window.onload = async () => {
const data = await fetch('/api/links/3MY70/logs', {
method: 'GET',
});
const logs = await data.json();
const table = document.querySelector('table');
// For every log, add a row to the table
counter = 1;
logs.forEach(log => {
const row = document.createElement('tr');
let date = new Date(log.timestamp);
let readableDate = date.toLocaleTimeString('en-US', {
month: 'short',
day: 'numeric',
year: 'numeric',
hour: '2-digit',
minute: '2-digit',
second: '2-digit',
hour12: false
}
);
row.innerHTML = `
<td>${counter++}</td>
<td>${readableDate}</td>
<td>${log.ip}</td>
<td>${log.location}</td>
<td>${log.isp}</td>
`;
table.appendChild(row);
});
}
</script>