288 lines
9.6 KiB
HTML
288 lines
9.6 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="it">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Proxmox API Tester</title>
|
|
<style>
|
|
body {
|
|
font-family: Arial, sans-serif;
|
|
max-width: 1400px;
|
|
margin: 0 auto;
|
|
padding: 20px;
|
|
background-color: #f5f5f5;
|
|
}
|
|
h1 {
|
|
color: #333;
|
|
}
|
|
.button-container {
|
|
margin: 20px 0;
|
|
}
|
|
button {
|
|
background-color: #4CAF50;
|
|
color: white;
|
|
padding: 10px 20px;
|
|
margin: 5px;
|
|
border: none;
|
|
border-radius: 4px;
|
|
cursor: pointer;
|
|
font-size: 14px;
|
|
}
|
|
button:hover {
|
|
background-color: #45a049;
|
|
}
|
|
button.backup-btn {
|
|
background-color: #2196F3;
|
|
}
|
|
button.backup-btn:hover {
|
|
background-color: #0b7dda;
|
|
}
|
|
#result {
|
|
background-color: white;
|
|
padding: 20px;
|
|
border-radius: 4px;
|
|
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
|
|
margin-top: 20px;
|
|
}
|
|
pre {
|
|
background-color: #f4f4f4;
|
|
padding: 15px;
|
|
border-radius: 4px;
|
|
overflow-x: auto;
|
|
}
|
|
.error {
|
|
color: #d32f2f;
|
|
}
|
|
.success {
|
|
color: #388e3c;
|
|
}
|
|
table {
|
|
width: 100%;
|
|
border-collapse: collapse;
|
|
margin-top: 15px;
|
|
}
|
|
th, td {
|
|
padding: 10px;
|
|
text-align: left;
|
|
border-bottom: 1px solid #ddd;
|
|
}
|
|
th {
|
|
background-color: #4CAF50;
|
|
color: white;
|
|
}
|
|
tr:hover {
|
|
background-color: #f5f5f5;
|
|
}
|
|
.backup-size {
|
|
color: #666;
|
|
font-size: 0.9em;
|
|
}
|
|
.backup-date {
|
|
color: #666;
|
|
}
|
|
input[type="text"] {
|
|
padding: 8px;
|
|
margin: 5px;
|
|
border: 1px solid #ddd;
|
|
border-radius: 4px;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<h1>🔧 Proxmox API Tester</h1>
|
|
|
|
<div class="button-container">
|
|
<h3>Informazioni Generali</h3>
|
|
<button onclick="testConnection()">Test Connessione</button>
|
|
<button onclick="getNodes()">Lista Nodi</button>
|
|
<button onclick="getResources()">Tutte le Risorse</button>
|
|
<button onclick="getStorage()">Storage Disponibili</button>
|
|
</div>
|
|
|
|
<div class="button-container">
|
|
<h3>Gestione Backup</h3>
|
|
<button class="backup-btn" onclick="getAllBackups()">📦 Tutti i Backup</button>
|
|
<button class="backup-btn" onclick="promptVMBackups()">🔍 Backup di una VM</button>
|
|
</div>
|
|
|
|
<div id="result">
|
|
<p>Clicca su un pulsante per testare le API di Proxmox</p>
|
|
</div>
|
|
|
|
<script>
|
|
function formatBytes(bytes) {
|
|
if (bytes === 0) return '0 Bytes';
|
|
const k = 1024;
|
|
const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
|
|
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
|
return Math.round(bytes / Math.pow(k, i) * 100) / 100 + ' ' + sizes[i];
|
|
}
|
|
|
|
function formatDate(timestamp) {
|
|
const date = new Date(timestamp * 1000);
|
|
return date.toLocaleString('it-IT');
|
|
}
|
|
|
|
async function makeRequest(endpoint) {
|
|
const resultDiv = document.getElementById('result');
|
|
resultDiv.innerHTML = '<p>Caricamento...</p>';
|
|
|
|
try {
|
|
const response = await fetch(endpoint);
|
|
const data = await response.json();
|
|
|
|
if (data.status === 'success') {
|
|
resultDiv.innerHTML = `
|
|
<h3 class="success">✓ Richiesta completata</h3>
|
|
<pre>${JSON.stringify(data.data, null, 2)}</pre>
|
|
`;
|
|
} else {
|
|
resultDiv.innerHTML = `
|
|
<h3 class="error">✗ Errore</h3>
|
|
<p>${data.message}</p>
|
|
`;
|
|
}
|
|
} catch (error) {
|
|
resultDiv.innerHTML = `
|
|
<h3 class="error">✗ Errore di connessione</h3>
|
|
<p>${error.message}</p>
|
|
`;
|
|
}
|
|
}
|
|
|
|
async function getAllBackups() {
|
|
const resultDiv = document.getElementById('result');
|
|
resultDiv.innerHTML = '<p>Caricamento backup...</p>';
|
|
|
|
try {
|
|
const response = await fetch('/api/backups');
|
|
const data = await response.json();
|
|
|
|
if (data.status === 'success' && data.data.length > 0) {
|
|
let tableHTML = `
|
|
<h3 class="success">✓ Trovati ${data.count} backup</h3>
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>VM/CT</th>
|
|
<th>Nome File</th>
|
|
<th>Storage</th>
|
|
<th>Dimensione</th>
|
|
<th>Data</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
`;
|
|
|
|
data.data.forEach(backup => {
|
|
const volid = backup.volid || '';
|
|
const parts = volid.split('/');
|
|
const filename = parts[parts.length - 1];
|
|
const vmid = filename.match(/-(\d+)-/)?.[1] || 'N/A';
|
|
|
|
tableHTML += `
|
|
<tr>
|
|
<td><strong>${vmid}</strong></td>
|
|
<td>${filename}</td>
|
|
<td>${backup.storage}</td>
|
|
<td class="backup-size">${formatBytes(backup.size || 0)}</td>
|
|
<td class="backup-date">${formatDate(backup.ctime || 0)}</td>
|
|
</tr>
|
|
`;
|
|
});
|
|
|
|
tableHTML += '</tbody></table>';
|
|
resultDiv.innerHTML = tableHTML;
|
|
} else if (data.status === 'success') {
|
|
resultDiv.innerHTML = '<h3>Nessun backup trovato</h3>';
|
|
} else {
|
|
resultDiv.innerHTML = `
|
|
<h3 class="error">✗ Errore</h3>
|
|
<p>${data.message}</p>
|
|
`;
|
|
}
|
|
} catch (error) {
|
|
resultDiv.innerHTML = `
|
|
<h3 class="error">✗ Errore di connessione</h3>
|
|
<p>${error.message}</p>
|
|
`;
|
|
}
|
|
}
|
|
|
|
async function promptVMBackups() {
|
|
const vmid = prompt('Inserisci il VMID (es: 100, 101, 102):');
|
|
if (!vmid) return;
|
|
|
|
const resultDiv = document.getElementById('result');
|
|
resultDiv.innerHTML = '<p>Caricamento backup per VM ' + vmid + '...</p>';
|
|
|
|
try {
|
|
const response = await fetch('/api/backups/vm/' + vmid);
|
|
const data = await response.json();
|
|
|
|
if (data.status === 'success' && data.data.length > 0) {
|
|
let tableHTML = `
|
|
<h3 class="success">✓ Trovati ${data.count} backup per VM ${vmid}</h3>
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>Nome File</th>
|
|
<th>Storage</th>
|
|
<th>Dimensione</th>
|
|
<th>Data</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
`;
|
|
|
|
data.data.forEach(backup => {
|
|
const volid = backup.volid || '';
|
|
const parts = volid.split('/');
|
|
const filename = parts[parts.length - 1];
|
|
|
|
tableHTML += `
|
|
<tr>
|
|
<td>${filename}</td>
|
|
<td>${backup.storage}</td>
|
|
<td class="backup-size">${formatBytes(backup.size || 0)}</td>
|
|
<td class="backup-date">${formatDate(backup.ctime || 0)}</td>
|
|
</tr>
|
|
`;
|
|
});
|
|
|
|
tableHTML += '</tbody></table>';
|
|
resultDiv.innerHTML = tableHTML;
|
|
} else if (data.status === 'success') {
|
|
resultDiv.innerHTML = '<h3>Nessun backup trovato per questa VM</h3>';
|
|
} else {
|
|
resultDiv.innerHTML = `
|
|
<h3 class="error">✗ Errore</h3>
|
|
<p>${data.message}</p>
|
|
`;
|
|
}
|
|
} catch (error) {
|
|
resultDiv.innerHTML = `
|
|
<h3 class="error">✗ Errore di connessione</h3>
|
|
<p>${error.message}</p>
|
|
`;
|
|
}
|
|
}
|
|
|
|
function testConnection() {
|
|
makeRequest('/api/test-connection');
|
|
}
|
|
|
|
function getNodes() {
|
|
makeRequest('/api/nodes');
|
|
}
|
|
|
|
function getResources() {
|
|
makeRequest('/api/cluster/resources');
|
|
}
|
|
|
|
function getStorage() {
|
|
makeRequest('/api/storage');
|
|
}
|
|
</script>
|
|
</body>
|
|
</html> |