Release v1.0.2: Hotfix, Live Diagramme VMs und PVE Nodex

This commit is contained in:
root
2026-08-24 07:03:54 +02:00
parent cc7bc514e1
commit e13319cb88
2 changed files with 23 additions and 10 deletions
+1 -6
View File
@@ -1,6 +1,6 @@
<?php
// /home/docker/pve_dashboard/src/api.php
ini_set('display_errors', 0); // Verhindert, dass PHP-Warnungen das JSON zerstören
ini_set('display_errors', 0);
error_reporting(E_ALL);
require_once 'db.php';
@@ -60,7 +60,6 @@ if (!isset($_SESSION['user_id'])) {
exit;
}
// === PASSWORT ÄNDERN ===
if ($action === 'change_password') {
$oldPass = $_POST['old_password'] ?? '';
$newPass = $_POST['new_password'] ?? '';
@@ -86,11 +85,9 @@ if ($action === 'change_password') {
$isAdmin = ($_SESSION['role'] ?? '') === 'admin';
@session_write_close();
// === PROXMOX API FETCHER (JETZT MIT TICKET-AUTH FÜR ALLE SYSTEME) ===
function getProxmoxData($ip, $tokenId, $tokenSecret, $endpoint, $type = 'pve', $method = "GET", $postData = null, $timeout = 6) {
$port = ($type === 'pbs') ? 8007 : 8006;
// 1. Ticket holen (Login)
$chAuth = curl_init("https://{$ip}:{$port}/api2/json/access/ticket");
curl_setopt_array($chAuth, [
CURLOPT_RETURNTRANSFER => true,
@@ -107,7 +104,6 @@ function getProxmoxData($ip, $tokenId, $tokenSecret, $endpoint, $type = 'pve', $
return ['data' => null, 'error' => 'Authentifizierung fehlgeschlagen'];
}
// 2. Passendes Cookie für das System wählen
$cookieName = 'PVEAuthCookie';
if ($type === 'pbs') $cookieName = 'PBSAuthCookie';
if ($type === 'pmg') $cookieName = 'PMGAuthCookie';
@@ -117,7 +113,6 @@ function getProxmoxData($ip, $tokenId, $tokenSecret, $endpoint, $type = 'pve', $
"CSRFPreventionToken: " . $authRes['data']['CSRFPreventionToken']
];
// 3. Eigentlichen API-Call ausführen
$ch = curl_init("https://{$ip}:{$port}{$endpoint}");
$options = [
CURLOPT_RETURNTRANSFER => true,
+22 -4
View File
@@ -25,7 +25,17 @@ if ($action === 'get_top_vms') {
$stmt = $pdo->query("SELECT * FROM nodes WHERE type = 'pve'"); $nodes = $stmt->fetchAll(PDO::FETCH_ASSOC); $allVms = [];
foreach ($nodes as $node) {
$vms = getProxmoxData($node['ip_address'], $node['token_id'], $node['token_secret'], "/api2/json/cluster/resources?type=vm");
if (isset($vms['data'])) { foreach ($vms['data'] as $vm) { if (checkVmPermission($pdo, $vm['vmid'])) { $vm['node_id'] = $node['id']; $vm['node_ip'] = $node['ip_address']; $allVms[] = $vm; } } }
if (isset($vms['data'])) {
foreach ($vms['data'] as $vm) {
if (checkVmPermission($pdo, $vm['vmid'])) {
$vm['node_id'] = $node['id'];
$vm['node_ip'] = $node['ip_address'];
// MAGISCHER FIX: PVE nennt den Host "node"
$vm['host'] = $vm['node'] ?? 'unknown';
$allVms[] = $vm;
}
}
}
}
usort($allVms, function($a, $b) { return ($b['cpu'] ?? 0) <=> ($a['cpu'] ?? 0); });
echo json_encode(['success' => true, 'data' => array_slice($allVms, 0, 5)]); exit;
@@ -35,7 +45,17 @@ if ($action === 'get_all_vms') {
$stmt = $pdo->query("SELECT * FROM nodes WHERE type = 'pve'"); $nodes = $stmt->fetchAll(PDO::FETCH_ASSOC); $allVms = [];
foreach ($nodes as $node) {
$vms = getProxmoxData($node['ip_address'], $node['token_id'], $node['token_secret'], "/api2/json/cluster/resources?type=vm");
if (isset($vms['data'])) { foreach ($vms['data'] as $vm) { if (checkVmPermission($pdo, $vm['vmid'])) { $vm['node_id'] = $node['id']; $vm['node_ip'] = $node['ip_address']; $allVms[] = $vm; } } }
if (isset($vms['data'])) {
foreach ($vms['data'] as $vm) {
if (checkVmPermission($pdo, $vm['vmid'])) {
$vm['node_id'] = $node['id'];
$vm['node_ip'] = $node['ip_address'];
// MAGISCHER FIX
$vm['host'] = $vm['node'] ?? 'unknown';
$allVms[] = $vm;
}
}
}
}
usort($allVms, function($a, $b) { if ($a['status'] === 'running' && $b['status'] !== 'running') return -1; if ($a['status'] !== 'running' && $b['status'] === 'running') return 1; return $a['vmid'] <=> $b['vmid']; });
echo json_encode(['success' => true, 'data' => $allVms]); exit;
@@ -45,8 +65,6 @@ if ($action === 'vm_action') {
if (!checkVmPermission($pdo, $_POST['vmid'])) exit;
$stmt = $pdo->prepare("SELECT * FROM nodes WHERE id = ?"); $stmt->execute([$_POST['node_id']]); $node = $stmt->fetch(PDO::FETCH_ASSOC);
$res = getProxmoxData($node['ip_address'], $node['token_id'], $node['token_secret'], "/api2/json/nodes/{$_POST['host']}/{$_POST['type']}/{$_POST['vmid']}/status/{$_POST['cmd']}", "POST");
// AUDIT LOG
logAudit("VM {$_POST['cmd']}", "VMID: {$_POST['vmid']} auf Host: {$_POST['host']}");
echo json_encode(['success' => isset($res['data']), 'error' => $res['errors'] ?? 'Fehler']); exit;
}