This commit is contained in:
Thomas Peterson 2025-11-17 10:58:38 +01:00
parent 162686739e
commit fdac5a8b84

View File

@ -87,8 +87,18 @@ class ServerListTab
['key' => 'type', 'title' => 'Typ', 'width' => 80], ['key' => 'type', 'title' => 'Typ', 'width' => 80],
['key' => 'ipv4', 'title' => 'IPv4', 'width' => 160], ['key' => 'ipv4', 'title' => 'IPv4', 'width' => 160],
['key' => 'docker_status', 'title' => 'Docker', 'width' => 90], ['key' => 'docker_status', 'title' => 'Docker', 'width' => 90],
['key' => 'needs_reboot', 'title' => 'Neustart', 'width' => 90], [
['key' => 'updates_available', 'title' => 'Updates', 'width' => 130], 'key' => 'needs_reboot',
'title' => 'Neustart',
'width' => 150,
'render' => [$this, 'renderNeedsRebootCell'],
],
[
'key' => 'updates_available',
'title' => 'Updates',
'width' => 150,
'render' => [$this, 'renderUpdatesCell'],
],
]); ]);
// Load initial test data // Load initial test data
@ -277,19 +287,13 @@ class ServerListTab
echo "Error: {$result['error']}\n"; echo "Error: {$result['error']}\n";
} elseif (isset($result['success'], $result['servers'])) { } elseif (isset($result['success'], $result['servers'])) {
// Basisdaten setzen, Docker-Status initial auf "pending" // Basisdaten setzen, Docker-Status initial auf "pending"
$serverListTab->currentServerData = array_map( $serverListTab->currentServerData = array_map(static fn($row) => array_merge([
static fn($row) => array_merge( 'docker_status' => 'pending',
[ 'docker' => null,
'docker_status' => 'pending', 'docker_error' => null,
'docker' => null, 'needs_reboot' => 'unbekannt',
'docker_error' => null, 'updates_available' => 'unbekannt',
'needs_reboot' => 'unbekannt', ], $row), $result['servers']);
'updates_available' => 'unbekannt',
],
$row,
),
$result['servers'],
);
$serverListTab->table->setData($serverListTab->currentServerData); $serverListTab->table->setData($serverListTab->currentServerData);
$serverListTab->statusLabel->setText('Server geladen: ' . $result['count'] . ' gefunden'); $serverListTab->statusLabel->setText('Server geladen: ' . $result['count'] . ' gefunden');
@ -299,8 +303,7 @@ class ServerListTab
$ip = $row['ipv4'] ?? ''; $ip = $row['ipv4'] ?? '';
if (empty($ip) || empty($currentPrivateKeyPath) || !file_exists($currentPrivateKeyPath)) { if (empty($ip) || empty($currentPrivateKeyPath) || !file_exists($currentPrivateKeyPath)) {
$serverListTab->currentServerData[$index]['docker_error'] = $serverListTab->currentServerData[$index]['docker_error'] = 'Kein gültiger Private-Key oder IP';
'Kein gültiger Private-Key oder IP';
$serverListTab->currentServerData[$index]['docker_status'] = 'error'; $serverListTab->currentServerData[$index]['docker_status'] = 'error';
continue; continue;
} }
@ -329,13 +332,13 @@ class ServerListTab
$rebootOutput = trim($ssh->exec( $rebootOutput = trim($ssh->exec(
'[ -f /var/run/reboot-required ] && echo yes || echo no', '[ -f /var/run/reboot-required ] && echo yes || echo no',
)); ));
$needsReboot = ($rebootOutput === 'yes'); $needsReboot = $rebootOutput === 'yes';
// Check number of available package updates (Ubuntu) // Check number of available package updates (Ubuntu)
$updatesOutput = trim($ssh->exec( $updatesOutput = trim($ssh->exec(
'apt-get -s upgrade 2>/dev/null | grep -c "^Inst " || echo 0', 'apt-get -s upgrade 2>/dev/null | grep -c "^Inst " || echo 0',
)); ));
$updatesCount = is_numeric($updatesOutput) ? (int) $updatesOutput : 0; $updatesCount = is_numeric($updatesOutput) ? ((int) $updatesOutput) : 0;
// Docker status for main application container // Docker status for main application container
$output = $ssh->exec('docker inspect psc-web-1'); $output = $ssh->exec('docker inspect psc-web-1');
@ -421,15 +424,17 @@ class ServerListTab
if ($needsReboot === null) { if ($needsReboot === null) {
$serverListTab->currentServerData[$i]['needs_reboot'] = 'unbekannt'; $serverListTab->currentServerData[$i]['needs_reboot'] = 'unbekannt';
} else { } else {
$serverListTab->currentServerData[$i]['needs_reboot'] = $serverListTab->currentServerData[$i]['needs_reboot'] = $needsReboot
$needsReboot ? 'ja' : 'nein'; ? 'ja'
: 'nein';
} }
} }
if (array_key_exists('updates', $dockerResult)) { if (array_key_exists('updates', $dockerResult)) {
$updates = (int) ($dockerResult['updates'] ?? 0); $updates = (int) ($dockerResult['updates'] ?? 0);
$serverListTab->currentServerData[$i]['updates_available'] = $serverListTab->currentServerData[$i]['updates_available'] = $updates > 0
$updates > 0 ? ('ja (' . $updates . ')') : 'nein'; ? ('ja (' . $updates . ')')
: 'nein';
} }
if (array_key_exists('docker_error', $dockerResult)) { if (array_key_exists('docker_error', $dockerResult)) {
@ -481,6 +486,42 @@ class ServerListTab
return $this->sftpButton; return $this->sftpButton;
} }
public function renderNeedsRebootCell(array $rowData, int $rowIndex): Label
{
$value = (string) ($rowData['needs_reboot'] ?? '');
$normalized = strtolower(trim($value));
$baseStyle = 'px-4 py-2 border-r border-gray-300 text-sm ';
if ($normalized === 'nein') {
$style = $baseStyle . 'text-green-600';
} elseif ($normalized === 'ja') {
$style = $baseStyle . 'text-red-600';
} else {
$style = $baseStyle . 'text-gray-600';
}
return new Label($value, $style);
}
public function renderUpdatesCell(array $rowData, int $rowIndex): Label
{
$value = (string) ($rowData['updates_available'] ?? '');
$normalized = strtolower(trim($value));
$baseStyle = 'px-4 py-2 border-r border-gray-300 text-sm ';
if ($normalized === 'nein' || $normalized === 'nein (0)') {
$style = $baseStyle . 'text-green-600';
} elseif (str_starts_with($normalized, 'ja')) {
$style = $baseStyle . 'text-red-600';
} else {
$style = $baseStyle . 'text-gray-600';
}
return new Label($value, $style);
}
private function updateDomainDetails(array $domains): void private function updateDomainDetails(array $domains): void
{ {
$this->detailDomainsContainer->clearChildren(); $this->detailDomainsContainer->clearChildren();