Files
netmaker-status-script/index.html
T

328 lines
12 KiB
HTML

<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Netmaker GW-Status</title>
<!-- Standard Favicon (relativer Pfad und Cache-Buster) -->
<link rel="icon" href="favicon.ico?v=1" type="image/x-icon">
<!-- Extra für dein iPhone / Safari -->
<link rel="apple-touch-icon" href="favicon.ico?v=1">
<style>
body {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
background-color: #121212;
color: #e0e0e0;
margin: 0;
padding: 20px;
font-size: 14px;
}
/* Header-Bereich für Logo, Titel und Bereinigungs-Button */
.header-container {
display: flex;
align-items: center;
border-bottom: 2px solid #444;
padding-bottom: 10px;
margin-bottom: 20px;
}
.header-logo {
height: 70px;
margin-right: 15px;
}
h1 {
font-size: 1.5rem;
margin: 0;
}
/* Bereinigungs-Button */
.cleanup-btn {
margin-left: auto; /* Schiebt den Button ganz nach rechts */
background-color: #1e1e1e;
color: #e0e0e0;
border: 1px solid #444;
padding: 8px 12px;
border-radius: 6px;
cursor: pointer;
font-size: 0.9rem;
transition: all 0.2s;
display: flex;
align-items: center;
gap: 5px;
}
.cleanup-btn:hover {
background-color: #ff4444;
color: white;
border-color: #ff4444;
}
/* Suchfeld */
.search-container {
max-width: 1000px;
margin-bottom: 30px;
}
#searchInput {
width: 100%;
padding: 12px 15px;
border-radius: 6px;
border: 1px solid #333;
background-color: #1e1e1e;
color: #fff;
font-size: 1rem;
box-sizing: border-box;
transition: border-color 0.2s;
}
#searchInput:focus { outline: none; border-color: #4da6ff; }
#searchInput::placeholder { color: #888; }
#dashboard { max-width: 1000px; }
/* Server-Block Header */
.server-group-title {
font-size: 1.1rem;
color: #4da6ff;
margin-top: 25px;
margin-bottom: 8px;
padding: 10px;
border-radius: 6px;
background-color: #1a1a1a;
border: 1px solid #333;
display: flex;
justify-content: space-between;
align-items: center;
transition: all 0.3s ease;
}
.server-group-left {
display: flex;
align-items: center;
gap: 10px;
}
/* Styling wenn das Gateway offline ist */
.server-group-title.gateway-offline {
border: 1px solid rgba(255, 68, 68, 0.4);
background-color: rgba(255, 68, 68, 0.08);
}
.server-group-title.gateway-offline .server-group-left {
color: #ff4444;
}
/* Zusammenfassungs-Badge (Neutrales Info-Design) */
.summary-badge {
font-size: 0.85rem;
padding: 4px 10px;
border-radius: 12px;
font-weight: 600;
background: rgba(77, 166, 255, 0.15);
color: #4da6ff;
border: 1px solid rgba(77, 166, 255, 0.3);
}
/* Roter Badge für Offline-Gateway */
.gateway-offline-badge {
font-size: 0.85rem;
padding: 4px 10px;
border-radius: 12px;
font-weight: 600;
background: rgba(255, 68, 68, 0.15);
color: #ff4444;
border: 1px solid rgba(255, 68, 68, 0.3);
}
/* Listen-Layout */
.node-list {
display: flex;
flex-direction: column;
gap: 6px;
margin-bottom: 25px;
}
.node-row {
display: flex;
align-items: center;
background: #1e1e1e;
padding: 8px 12px;
border-radius: 6px;
border: 1px solid #2a2a2a;
transition: background 0.2s;
}
.node-row:hover { background: #252525; }
.status-dot {
width: 10px;
height: 10px;
border-radius: 50%;
margin-right: 15px;
flex-shrink: 0;
}
.online .status-dot { background-color: #00C851; box-shadow: 0 0 8px rgba(0, 200, 81, 0.5); }
.offline .status-dot { background-color: #ff4444; box-shadow: 0 0 8px rgba(255, 68, 68, 0.5); }
.client-name { font-weight: 600; width: 250px; margin-right: 15px; flex-shrink: 0; }
.handshake { color: #888; font-size: 0.85rem; flex-grow: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.time { color: #aaa; font-size: 0.85rem; text-align: right; white-space: nowrap; margin-left: 15px; width: 90px; flex-shrink: 0; }
@media (max-width: 700px) {
.node-row { flex-wrap: wrap; gap: 5px; padding: 10px; }
.client-name { width: auto; margin-right: 10px; }
.handshake { width: 100%; margin-left: 25px; margin-top: 4px; }
.time { width: auto; margin-left: 25px; text-align: left; }
}
</style>
</head>
<body>
<div class="header-container">
<img src="https://api.scalar.com/cdn/images/nihKnpk06xBjyKI4sa5CZ/38l8utJFkH2jkoeca3c7U.png" alt="Netmaker Logo" class="header-logo">
<h1>GW-Status</h1>
<button id="cleanupBtn" class="cleanup-btn" title="Entfernt alle inaktiven Nodes">🧹 Bereinigen</button>
</div>
<div class="search-container">
<input type="text" id="searchInput" placeholder="🔍 Nodes durchsuchen..." autocomplete="off">
</div>
<div id="dashboard">
<p>Lade Status-Daten...</p>
</div>
<script>
const API_URL = 'api.php';
// --- Neue Funktion für den Bereinigungs-Button ---
document.getElementById('cleanupBtn').addEventListener('click', async () => {
if (confirm('Möchtest du wirklich alle alten, inaktiven Nodes aus der Datenbank löschen?')) {
try {
const response = await fetch(API_URL + '?action=cleanup');
if (response.ok) {
fetchStatus(); // Lädt das Dashboard nach dem Löschen direkt neu
} else {
alert('Fehler bei der Bereinigung.');
}
} catch (err) {
console.error('Verbindungsfehler:', err);
alert('Konnte die API nicht erreichen.');
}
}
});
function applySearchFilter() {
const searchTerm = document.getElementById('searchInput').value.toLowerCase();
const serverGroups = document.querySelectorAll('.server-group-title');
const nodeLists = document.querySelectorAll('.node-list');
nodeLists.forEach((list, index) => {
let hasVisibleNodes = false;
const rows = list.querySelectorAll('.node-row');
rows.forEach(row => {
const clientName = row.querySelector('.client-name').textContent.toLowerCase();
if (clientName.includes(searchTerm)) {
row.style.display = 'flex';
hasVisibleNodes = true;
} else {
row.style.display = 'none';
}
});
const header = serverGroups[index];
if (header) {
if (searchTerm !== '') {
header.style.display = hasVisibleNodes ? 'flex' : 'none';
list.style.display = hasVisibleNodes ? 'flex' : 'none';
} else {
header.style.display = 'flex';
list.style.display = 'flex';
}
}
});
}
document.getElementById('searchInput').addEventListener('input', applySearchFilter);
async function fetchStatus() {
try {
const response = await fetch(API_URL);
const data = await response.json();
const isSearching = document.getElementById('searchInput').value.trim() !== '';
const servers = {};
data.forEach(node => {
if (!servers[node.server]) servers[node.server] = [];
servers[node.server].push(node);
});
const dashboard = document.getElementById('dashboard');
dashboard.innerHTML = '';
for (const [serverName, nodes] of Object.entries(servers)) {
let onlineCount = 0;
let minDiffMinutes = Infinity;
const now = new Date();
const rowElements = nodes.map(node => {
const safeDateString = node.last_seen.replace(' ', 'T') + 'Z';
const lastSeen = new Date(safeDateString);
const diffMinutes = (now - lastSeen) / 1000 / 60;
if (diffMinutes < minDiffMinutes) {
minDiffMinutes = diffMinutes;
}
const isOnline = (node.status === 'true' && diffMinutes < 5);
if (isOnline) onlineCount++;
let timeText = Math.round(diffMinutes) + ' Min.';
if (diffMinutes < 1) timeText = '< 1 Min.';
const row = document.createElement('div');
row.className = `node-row ${isOnline ? 'online' : 'offline'}`;
row.innerHTML = `
<div class="status-dot"></div>
<div class="client-name">${node.client}</div>
<div class="handshake">Handshake: ${node.handshake}</div>
<div class="time" title="Letztes Update: ${lastSeen.toLocaleString()}">vor ${timeText}</div>
`;
return row;
});
const isGatewayOffline = (minDiffMinutes >= 5);
const header = document.createElement('div');
header.className = `server-group-title ${isGatewayOffline ? 'gateway-offline' : ''}`;
let badgeHTML = '';
if (isGatewayOffline) {
badgeHTML = `<div class="gateway-offline-badge">Gateway Offline</div>`;
} else {
badgeHTML = `<div class="summary-badge">${onlineCount} / ${nodes.length} online</div>`;
}
header.innerHTML = `
<div class="server-group-left">
<span>🖥️ ${serverName}</span>
</div>
${badgeHTML}
`;
dashboard.appendChild(header);
const listContainer = document.createElement('div');
listContainer.className = 'node-list';
rowElements.forEach(row => listContainer.appendChild(row));
dashboard.appendChild(listContainer);
}
if (isSearching) applySearchFilter();
} catch (err) {
console.error("Fehler beim Abrufen der Daten:", err);
}
}
fetchStatus();
setInterval(fetchStatus, 30000);
</script>
</body>
</html>