From e13319cb885eb1832621084c55da0648c6029095 Mon Sep 17 00:00:00 2001 From: root Date: Mon, 24 Aug 2026 07:03:54 +0200 Subject: [PATCH] Release v1.0.2: Hotfix, Live Diagramme VMs und PVE Nodex --- src/api.php | 7 +------ src/api_pve.php | 26 ++++++++++++++++++++++---- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/src/api.php b/src/api.php index c6c216c..5448651 100644 --- a/src/api.php +++ b/src/api.php @@ -1,6 +1,6 @@ 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, diff --git a/src/api_pve.php b/src/api_pve.php index 8fbbf9e..d4735d7 100644 --- a/src/api_pve.php +++ b/src/api_pve.php @@ -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; }