Add project sources
This commit is contained in:
184
static/dashboard.js
Normal file
184
static/dashboard.js
Normal file
@@ -0,0 +1,184 @@
|
||||
let currentNetworkId = null;
|
||||
let updateInterval = null;
|
||||
|
||||
async function setNetwork() {
|
||||
const networkId = document.getElementById('networkId').value.trim();
|
||||
|
||||
if (!networkId) {
|
||||
showError('Inserisci un Network ID');
|
||||
return;
|
||||
}
|
||||
|
||||
if (networkId.length !== 16) {
|
||||
showError('Il Network ID deve essere lungo 16 caratteri');
|
||||
return;
|
||||
}
|
||||
|
||||
currentNetworkId = networkId;
|
||||
clearError();
|
||||
|
||||
// Avvia il polling automatico
|
||||
if (updateInterval) {
|
||||
clearInterval(updateInterval);
|
||||
}
|
||||
|
||||
// Primo aggiornamento immediato
|
||||
await updateNodes();
|
||||
|
||||
// Poi ogni 5 secondi
|
||||
updateInterval = setInterval(updateNodes, 5000);
|
||||
}
|
||||
|
||||
async function updateNodes() {
|
||||
if (!currentNetworkId) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await fetch(`/api/nodes?network_id=${currentNetworkId}`);
|
||||
|
||||
if (!response.ok) {
|
||||
const error = await response.json();
|
||||
console.error('API Error:', error);
|
||||
updateStatusIndicator(false);
|
||||
showError(error.error || 'Errore nel caricamento dei nodi');
|
||||
return;
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
updateStatusIndicator(true);
|
||||
renderNodes(data);
|
||||
updateStats(data);
|
||||
clearError();
|
||||
|
||||
} catch (error) {
|
||||
console.error('Fetch error:', error);
|
||||
updateStatusIndicator(false);
|
||||
showError('Errore di connessione al server');
|
||||
}
|
||||
}
|
||||
|
||||
function updateStatusIndicator(isOnline) {
|
||||
const indicator = document.getElementById('status-indicator');
|
||||
if (isOnline) {
|
||||
indicator.classList.remove('offline');
|
||||
indicator.classList.add('online');
|
||||
} else {
|
||||
indicator.classList.remove('online');
|
||||
indicator.classList.add('offline');
|
||||
}
|
||||
}
|
||||
|
||||
function showError(message) {
|
||||
let errorDiv = document.getElementById('error-message');
|
||||
if (!errorDiv) {
|
||||
errorDiv = document.createElement('div');
|
||||
errorDiv.id = 'error-message';
|
||||
errorDiv.className = 'error-banner';
|
||||
document.querySelector('.container').insertBefore(errorDiv, document.querySelector('header').nextSibling);
|
||||
}
|
||||
errorDiv.textContent = message;
|
||||
errorDiv.style.display = 'block';
|
||||
}
|
||||
|
||||
function clearError() {
|
||||
const errorDiv = document.getElementById('error-message');
|
||||
if (errorDiv) {
|
||||
errorDiv.style.display = 'none';
|
||||
}
|
||||
}
|
||||
|
||||
function updateStats(data) {
|
||||
document.getElementById('total-nodes').textContent = data.total_nodes || 0;
|
||||
document.getElementById('online-nodes').textContent = data.online_nodes || 0;
|
||||
|
||||
const now = new Date();
|
||||
const timeString = now.toLocaleTimeString('it-IT');
|
||||
document.getElementById('last-update').textContent = timeString;
|
||||
}
|
||||
|
||||
function renderNodes(data) {
|
||||
const container = document.getElementById('nodes-container');
|
||||
|
||||
if (!data.nodes || data.nodes.length === 0) {
|
||||
container.innerHTML = '<p class="empty-state">Nessun nodo trovato</p>';
|
||||
return;
|
||||
}
|
||||
|
||||
container.innerHTML = data.nodes.map(node => createNodeCard(node)).join('');
|
||||
}
|
||||
|
||||
function createNodeCard(node) {
|
||||
const isOnline = node.online;
|
||||
const statusClass = isOnline ? 'online' : 'offline';
|
||||
const statusText = isOnline ? '🟢 Online' : '🔴 Offline';
|
||||
|
||||
const lastCheck = new Date(node.last_check);
|
||||
const timeAgo = getTimeAgo(lastCheck);
|
||||
|
||||
return `
|
||||
<div class="node-card ${statusClass}">
|
||||
<div class="node-header">
|
||||
<div class="node-hostname">${escapeHtml(node.hostname)}</div>
|
||||
<div class="node-status-badge ${statusClass}"></div>
|
||||
</div>
|
||||
|
||||
<div class="node-info">
|
||||
<div class="node-info-label">IP ZeroTier</div>
|
||||
<div class="node-info-value">${escapeHtml(node.ip)}</div>
|
||||
</div>
|
||||
|
||||
<div class="node-info">
|
||||
<div class="node-info-label">ID</div>
|
||||
<div class="node-info-value" style="font-size: 0.8em;">${escapeHtml(node.id)}</div>
|
||||
</div>
|
||||
|
||||
<div class="node-status-text ${statusClass}">
|
||||
${statusText}
|
||||
</div>
|
||||
|
||||
<div class="node-timestamp">
|
||||
Verificato ${timeAgo}
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
|
||||
function getTimeAgo(date) {
|
||||
const now = new Date();
|
||||
const seconds = Math.floor((now - date) / 1000);
|
||||
|
||||
if (seconds < 60) return 'proprio ora';
|
||||
if (seconds < 120) return 'un minuto fa';
|
||||
|
||||
const minutes = Math.floor(seconds / 60);
|
||||
if (minutes < 60) return `${minutes}m fa`;
|
||||
|
||||
const hours = Math.floor(minutes / 60);
|
||||
if (hours < 24) return `${hours}h fa`;
|
||||
|
||||
const days = Math.floor(hours / 24);
|
||||
return `${days}d fa`;
|
||||
}
|
||||
|
||||
function escapeHtml(text) {
|
||||
const div = document.createElement('div');
|
||||
div.textContent = text;
|
||||
return div.innerHTML;
|
||||
}
|
||||
|
||||
// Load network ID from localStorage if exists
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
const networkIdInput = document.getElementById('networkId');
|
||||
const saved = localStorage.getItem('zerotier_network_id');
|
||||
if (saved) {
|
||||
networkIdInput.value = saved;
|
||||
}
|
||||
|
||||
// Salva network ID nel localStorage quando cambia
|
||||
networkIdInput.addEventListener('change', (e) => {
|
||||
if (e.target.value) {
|
||||
localStorage.setItem('zerotier_network_id', e.target.value);
|
||||
}
|
||||
});
|
||||
});
|
||||
304
static/style.css
Normal file
304
static/style.css
Normal file
@@ -0,0 +1,304 @@
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
min-height: 100vh;
|
||||
padding: 20px;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.container {
|
||||
max-width: 1200px;
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
header {
|
||||
text-align: center;
|
||||
color: white;
|
||||
margin-bottom: 40px;
|
||||
}
|
||||
|
||||
header h1 {
|
||||
font-size: 2.5em;
|
||||
margin-bottom: 5px;
|
||||
text-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
|
||||
}
|
||||
|
||||
header .subtitle {
|
||||
font-size: 1.1em;
|
||||
opacity: 0.9;
|
||||
}
|
||||
|
||||
/* Config Section */
|
||||
.config-section {
|
||||
background: white;
|
||||
padding: 20px;
|
||||
border-radius: 10px;
|
||||
margin-bottom: 30px;
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
align-items: center;
|
||||
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
.error-banner {
|
||||
background: #ffebee;
|
||||
border-left: 4px solid #f44336;
|
||||
color: #c62828;
|
||||
padding: 15px 20px;
|
||||
border-radius: 5px;
|
||||
margin-bottom: 20px;
|
||||
display: none;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.config-section label {
|
||||
font-weight: 600;
|
||||
min-width: 100px;
|
||||
}
|
||||
|
||||
.config-section input {
|
||||
flex: 1;
|
||||
padding: 10px 15px;
|
||||
border: 2px solid #e0e0e0;
|
||||
border-radius: 5px;
|
||||
font-size: 1em;
|
||||
transition: border-color 0.3s;
|
||||
}
|
||||
|
||||
.config-section input:focus {
|
||||
outline: none;
|
||||
border-color: #667eea;
|
||||
}
|
||||
|
||||
.config-section button {
|
||||
padding: 10px 25px;
|
||||
background: #667eea;
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 5px;
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
transition: background 0.3s;
|
||||
}
|
||||
|
||||
.config-section button:hover {
|
||||
background: #5568d3;
|
||||
}
|
||||
|
||||
.status-dot {
|
||||
width: 12px;
|
||||
height: 12px;
|
||||
border-radius: 50%;
|
||||
animation: pulse 2s infinite;
|
||||
}
|
||||
|
||||
.status-dot.online {
|
||||
background: #4caf50;
|
||||
}
|
||||
|
||||
.status-dot.offline {
|
||||
background: #f44336;
|
||||
}
|
||||
|
||||
@keyframes pulse {
|
||||
0%, 100% { opacity: 1; }
|
||||
50% { opacity: 0.5; }
|
||||
}
|
||||
|
||||
/* Stats Section */
|
||||
.stats-section {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
|
||||
gap: 20px;
|
||||
margin-bottom: 40px;
|
||||
}
|
||||
|
||||
.stat-box {
|
||||
background: white;
|
||||
padding: 25px;
|
||||
border-radius: 10px;
|
||||
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.stat-label {
|
||||
font-size: 0.9em;
|
||||
color: #999;
|
||||
margin-bottom: 10px;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.stat-value {
|
||||
font-size: 2.5em;
|
||||
font-weight: bold;
|
||||
color: #667eea;
|
||||
}
|
||||
|
||||
/* Nodes Section */
|
||||
.nodes-section {
|
||||
background: white;
|
||||
padding: 30px;
|
||||
border-radius: 10px;
|
||||
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
.nodes-section h2 {
|
||||
margin-bottom: 20px;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.nodes-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
|
||||
gap: 20px;
|
||||
}
|
||||
|
||||
.empty-state {
|
||||
grid-column: 1 / -1;
|
||||
text-align: center;
|
||||
padding: 40px;
|
||||
color: #999;
|
||||
font-size: 1.1em;
|
||||
}
|
||||
|
||||
/* Node Card */
|
||||
.node-card {
|
||||
border: 2px solid #e0e0e0;
|
||||
border-radius: 8px;
|
||||
padding: 20px;
|
||||
transition: all 0.3s;
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.node-card::before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
height: 4px;
|
||||
background: #4caf50;
|
||||
}
|
||||
|
||||
.node-card.offline::before {
|
||||
background: #f44336;
|
||||
}
|
||||
|
||||
.node-card.offline {
|
||||
opacity: 0.7;
|
||||
border-color: #ffcdd2;
|
||||
}
|
||||
|
||||
.node-card:hover {
|
||||
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.15);
|
||||
transform: translateY(-2px);
|
||||
}
|
||||
|
||||
.node-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: start;
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
|
||||
.node-hostname {
|
||||
font-weight: 700;
|
||||
font-size: 1.2em;
|
||||
color: #333;
|
||||
word-break: break-word;
|
||||
}
|
||||
|
||||
.node-status-badge {
|
||||
display: inline-block;
|
||||
width: 24px;
|
||||
height: 24px;
|
||||
border-radius: 50%;
|
||||
background: #4caf50;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.node-status-badge.offline {
|
||||
background: #f44336;
|
||||
}
|
||||
|
||||
.node-status-badge::after {
|
||||
content: '';
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
width: 10px;
|
||||
height: 10px;
|
||||
background: white;
|
||||
border-radius: 50%;
|
||||
}
|
||||
|
||||
.node-info {
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.node-info-label {
|
||||
font-size: 0.85em;
|
||||
color: #999;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.5px;
|
||||
margin-bottom: 3px;
|
||||
}
|
||||
|
||||
.node-info-value {
|
||||
font-family: 'Monaco', 'Menlo', monospace;
|
||||
font-size: 0.95em;
|
||||
color: #333;
|
||||
word-break: break-all;
|
||||
background: #f5f5f5;
|
||||
padding: 8px;
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
.node-status-text {
|
||||
font-size: 0.9em;
|
||||
color: #4caf50;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.node-status-text.offline {
|
||||
color: #f44336;
|
||||
}
|
||||
|
||||
.node-timestamp {
|
||||
font-size: 0.75em;
|
||||
color: #ccc;
|
||||
margin-top: 10px;
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
/* Responsive */
|
||||
@media (max-width: 768px) {
|
||||
header h1 {
|
||||
font-size: 1.8em;
|
||||
}
|
||||
|
||||
.config-section {
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.config-section label {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.config-section input,
|
||||
.config-section button {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.nodes-grid {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user