Upload via GUI (364 Dateien)

This commit is contained in:
2026-11-01 11:15:37 +00:00
parent 0945d61744
commit 9b1b7c0d6e
8 changed files with 262 additions and 27 deletions
+62 -9
View File
@@ -42,6 +42,16 @@ function status_app_connection(PDO $pdo, string $platform): array
return ['online' => $lastSeen !== null && strtotime($lastSeen) >= strtotime($cutoff), 'last_seen' => $lastSeen, 'timeout_minutes' => $timeoutMinutes];
}
/** Prüfadresse der Plugin-Webseite (ihr health.php, das ohne Zugangsschlüssel antwortet); leer, wenn kein offizieller Katalog eingetragen ist. */
function status_plugin_site_url(): string
{
if (!function_exists('catalog_defaults')) return '';
$parts = parse_url((string) (catalog_defaults()['plugins_url'] ?? ''));
if (!$parts || ($parts['scheme'] ?? '') !== 'https' || empty($parts['host'])) return '';
$path = rtrim(str_replace(chr(92), '/', dirname((string) ($parts['path'] ?? '/'))), '/');
return 'https://' . $parts['host'] . (!empty($parts['port']) ? ':' . (int) $parts['port'] : '') . $path . '/health.php';
}
function status_component_monitor_target(PDO $pdo, array $component): ?array
{
$type = (string) ($component['monitor_type'] ?? 'auto');
@@ -55,6 +65,10 @@ function status_component_monitor_target(PDO $pdo, array $component): ?array
if (str_contains($name, 'minecraft')) return ['type' => 'minecraft', 'target' => $target, 'label' => 'Minecraft-Server'];
return ['type' => 'http', 'target' => $target, 'label' => 'Webadresse'];
}
if (str_contains($name, 'plugin') && (str_contains($name, 'webseite') || str_contains($name, 'website') || str_contains($name, 'seite') || str_contains($name, 'katalog'))) {
$url = status_plugin_site_url();
return $url !== '' ? ['type' => 'plugin_site', 'target' => $url, 'label' => 'Plugin-Webseite'] : null;
}
if (str_contains($name, 'android') || (str_contains($category, 'app') && str_contains($name, 'mobil'))) return ['type' => 'android_app', 'target' => '', 'label' => 'Android-App-Verbindung'];
if (str_contains($name, 'windows') || str_contains($name, 'desktop') || str_contains($name, 'windows-programm')) return ['type' => 'windows_app', 'target' => '', 'label' => 'Windows-Programm-Verbindung'];
if (str_contains($name, 'datenbank') || str_contains($name, 'database')) return ['type' => 'database', 'target' => '', 'label' => 'Datenbank'];
@@ -64,6 +78,10 @@ function status_component_monitor_target(PDO $pdo, array $component): ?array
if ((str_contains($name, 'push') || str_contains($category, 'benachrichtigung')) && function_exists('fcm_configured') && fcm_configured()) return ['type' => 'fcm', 'target' => '', 'label' => 'Push-Dienst'];
return null;
}
if ($type === 'plugin_site') {
$url = status_plugin_site_url();
return $url !== '' ? ['type' => 'plugin_site', 'target' => $url, 'label' => 'Plugin-Webseite'] : null;
}
if ($type === 'database') return ['type' => 'database', 'target' => '', 'label' => 'Datenbank'];
if ($type === 'android_app') return ['type' => 'android_app', 'target' => '', 'label' => 'Android-App-Verbindung'];
if ($type === 'windows_app') return ['type' => 'windows_app', 'target' => '', 'label' => 'Windows-Programm-Verbindung'];
@@ -129,7 +147,7 @@ function status_execute_component_check(PDO $pdo, array $check): array
$ok = is_resource($socket);
if ($ok) fclose($socket); else $error = 'Server oder Port nicht erreichbar';
} else $error = 'Ungültiges Prüfziel';
} elseif ($check['type'] === 'http') {
} elseif (in_array($check['type'], ['http', 'plugin_site'], true)) {
$url = (string) $check['target'];
if (filter_var($url, FILTER_VALIDATE_URL) && in_array(strtolower((string) parse_url($url, PHP_URL_SCHEME)), ['http', 'https'], true)) {
if (function_exists('curl_init')) {
@@ -210,9 +228,40 @@ function status_incident_states(): array
];
}
function status_components(PDO $pdo, bool $includeDisabled = false): array
/** Gibt es die Spalte is_internal schon (Datenbank-Update eingespielt)? Bis dahin verhält sich alles wie bisher. */
function status_has_internal(PDO $pdo): bool
{
$where = $includeDisabled ? '' : 'WHERE COALESCE(c.is_enabled, 1) = 1 ';
static $cache = [];
$key = spl_object_id($pdo);
if (isset($cache[$key])) return $cache[$key];
try {
$rows = $pdo->query($pdo->getAttribute(PDO::ATTR_DRIVER_NAME) === 'sqlite' ? 'PRAGMA table_info(status_components)' : 'SHOW COLUMNS FROM status_components')->fetchAll();
foreach ($rows as $r) if (($r['name'] ?? $r['Field'] ?? '') === 'is_internal') return $cache[$key] = true;
} catch (Throwable $e) {
// Tabelle fehlt: nichts zu filtern
}
return $cache[$key] = false;
}
/** SQL-Zusatz: nur öffentliche (nicht interne) Dienste; $alias ist der Tabellenname von status_components. */
function status_public_sql(PDO $pdo, string $alias = 'c'): string
{
return status_has_internal($pdo) ? " AND COALESCE({$alias}.is_internal, 0) = 0" : '';
}
/** Nicht öffentlich sichtbar, aber geprüft: Dienst als „intern“ markieren oder die Markierung entfernen. */
function status_set_component_internal(PDO $pdo, int $id, bool $internal): bool
{
if (!status_has_internal($pdo)) return false;
$pdo->prepare('UPDATE status_components SET is_internal = ? WHERE id = ?')->execute([$internal ? 1 : 0, $id]);
return (bool) $pdo->query('SELECT 1 FROM status_components WHERE id = ' . (int) $id)->fetchColumn();
}
/** @param bool $publicOnly nur Dienste, die auf der öffentlichen Statusseite stehen dürfen (nicht intern) */
function status_components(PDO $pdo, bool $includeDisabled = false, bool $publicOnly = false): array
{
$where = $includeDisabled ? 'WHERE 1 = 1 ' : 'WHERE COALESCE(c.is_enabled, 1) = 1 ';
if ($publicOnly) $where .= status_public_sql($pdo) . ' ';
return $pdo->query("SELECT c.*, COALESCE(cat.name, NULLIF(c.category, '')) AS category_name FROM status_components c LEFT JOIN status_categories cat ON cat.id = c.category_id {$where}ORDER BY COALESCE(cat.sort_order, 0), COALESCE(cat.name, c.category, ''), c.sort_order, c.name")->fetchAll();
}
@@ -232,6 +281,7 @@ function status_monitor_types(): array
'smtp' => 'SMTP-Server',
'mail' => 'E-Mail (SMTP und IMAP)',
'fcm' => 'Push-Dienst',
'plugin_site' => 'Plugin-Webseite (offizieller Katalog)',
'tcp' => 'Server und Port',
'manual' => 'Manuell verwalten',
];
@@ -413,16 +463,16 @@ function status_overall(PDO $pdo): array
{
$states = status_component_states();
$worst = 'operational';
foreach (status_components($pdo) as $c) {
foreach (status_components($pdo, false, true) as $c) {
if (($states[$c['status']][2] ?? 0) > $states[$worst][2]) $worst = $c['status'];
}
// Eine offene Störung ohne zugeordnete Komponente zählt mindestens als „eingeschränkt“
$open = (int) $pdo->query("SELECT COUNT(*) FROM status_incidents i LEFT JOIN status_components c ON c.id = i.component_id WHERE i.status <> 'resolved' AND (i.component_id IS NULL OR COALESCE(c.is_enabled, 1) = 1)")->fetchColumn();
$open = (int) $pdo->query("SELECT COUNT(*) FROM status_incidents i LEFT JOIN status_components c ON c.id = i.component_id WHERE i.status <> 'resolved' AND (i.component_id IS NULL OR (COALESCE(c.is_enabled, 1) = 1" . status_public_sql($pdo) . "))")->fetchColumn();
if ($open > 0 && $states[$worst][2] < $states['degraded'][2] && $worst !== 'maintenance') $worst = 'degraded';
$activeMaintenance = status_active_maintenance_map($pdo);
$hasActiveMaintenance = isset($activeMaintenance[0]);
if (!$hasActiveMaintenance) {
foreach (status_components($pdo) as $component) {
foreach (status_components($pdo, false, true) as $component) {
if (isset($activeMaintenance[(int) $component['id']])) { $hasActiveMaintenance = true; break; }
}
}
@@ -434,7 +484,7 @@ function status_overall(PDO $pdo): array
function status_incidents(PDO $pdo, int $days = 14, bool $onlyOpen = false, bool $includeDisabledComponents = false): array
{
$since = date('Y-m-d H:i:s', time() - max(1, $days) * 86400);
$componentFilter = $includeDisabledComponents ? '' : ' AND (i.component_id IS NULL OR COALESCE(c.is_enabled, 1) = 1)';
$componentFilter = $includeDisabledComponents ? '' : ' AND (i.component_id IS NULL OR (COALESCE(c.is_enabled, 1) = 1' . status_public_sql($pdo) . '))';
$sql = "SELECT i.*, c.name AS component_name FROM status_incidents i LEFT JOIN status_components c ON c.id = i.component_id WHERE "
. ($onlyOpen ? "i.status <> 'resolved'" : "(i.status <> 'resolved' OR i.created_at >= ?)") . $componentFilter . ' ORDER BY i.created_at DESC, i.id DESC LIMIT 50';
$stmt = $pdo->prepare($sql);
@@ -455,7 +505,7 @@ function status_maintenance_windows(PDO $pdo, bool $includeHistory = false): arr
$since = date('Y-m-d H:i:s', time() - 60 * 86400);
$where = $includeHistory
? 'WHERE (w.ends_at >= ? OR w.cancelled_at >= ?)'
: 'WHERE w.cancelled_at IS NULL AND w.ends_at >= ? AND (w.component_id IS NULL OR COALESCE(c.is_enabled, 1) = 1)';
: 'WHERE w.cancelled_at IS NULL AND w.ends_at >= ? AND (w.component_id IS NULL OR (COALESCE(c.is_enabled, 1) = 1' . status_public_sql($pdo) . '))';
$stmt = $pdo->prepare("SELECT w.*, c.name AS component_name FROM status_maintenance_windows w LEFT JOIN status_components c ON c.id = w.component_id $where ORDER BY w.starts_at ASC, w.id ASC LIMIT 100");
$stmt->execute($includeHistory ? [$since, $since] : [$now]);
return $stmt->fetchAll();
@@ -629,6 +679,7 @@ function status_restore_core_components(PDO $pdo): int
['Backup-Server', 'Server & Datenbank', 'tcp', ['Backup Server', 'FTP-Backup-Server']],
['Maildienst', 'E-Mail', 'mail', ['Mail Dienst', 'Mail Server']],
['Push-Dienst', 'Benachrichtigungen', 'fcm', ['Push Dienst']],
['Plugin-Webseite', 'Server & Datenbank', 'plugin_site', ['Plugin-Website', 'Pluginseite', 'Plugin Webseite']],
['Minecraft-Server', 'Apps', 'tcp', ['Minecraft Server']],
['Android-App', 'Apps', 'android_app', ['Windelgeschichten-Android-App', 'DeskHub-Mitarbeiter-App für Android']],
['Windows-Programm', 'Apps', 'windows_app', ['DeskHub-Mitarbeiter-App für Windows', 'Windows-App']],
@@ -650,6 +701,7 @@ function status_restore_core_components(PDO $pdo): int
$maxOrder = (int) $pdo->query('SELECT COALESCE(MAX(sort_order), 0) FROM status_components')->fetchColumn();
$restored = 0;
foreach ($defaults as [$name, $categoryName, $monitorType, $aliases]) {
if ($monitorType === 'plugin_site' && status_plugin_site_url() === '') continue; // ohne offiziellen Katalog gibt es nichts zu prüfen
$existing = null;
foreach (array_merge([$name], $aliases) as $candidate) {
$find->execute([$candidate]);
@@ -667,6 +719,7 @@ function status_restore_core_components(PDO $pdo): int
if ($id) {
status_set_component_monitor($pdo, $id, $monitorType, '');
if (in_array($name, ['Minecraft-Server', 'Backup-Server'], true)) status_set_component_enabled($pdo, $id, false);
if ($monitorType === 'plugin_site') status_set_component_internal($pdo, $id, true); // nur für Mitarbeiter sichtbar
$maxOrder += 10;
$restored++;
}
@@ -742,7 +795,7 @@ function status_summary(PDO $pdo): array
'overall' => $overall,
'componentStates' => array_map(fn($k, $v) => ['key' => $k, 'label' => $v[0]], array_keys($states), $states),
'incidentStates' => array_map(fn($k, $v) => ['key' => $k, 'label' => $v], array_keys(status_incident_states()), status_incident_states()),
'components' => array_map(fn($c) => ['id' => (int) $c['id'], 'name' => (string) $c['name'], 'description' => (string) ($c['description'] ?? ''), 'category' => (string) ($c['category_name'] ?? ''), 'categoryId' => $c['category_id'] !== null ? (int) $c['category_id'] : null, 'status' => (string) $c['status'], 'statusLabel' => $states[$c['status']][0] ?? $c['status']], status_components($pdo)),
'components' => array_map(fn($c) => ['id' => (int) $c['id'], 'name' => (string) $c['name'], 'description' => (string) ($c['description'] ?? ''), 'category' => (string) ($c['category_name'] ?? ''), 'categoryId' => $c['category_id'] !== null ? (int) $c['category_id'] : null, 'status' => (string) $c['status'], 'statusLabel' => $states[$c['status']][0] ?? $c['status'], 'internal' => !empty($c['is_internal'])], status_components($pdo)),
'incidents' => array_map(fn($i) => [
'id' => (int) $i['id'], 'title' => (string) $i['title'], 'status' => (string) $i['status'], 'statusLabel' => status_incident_states()[$i['status']] ?? $i['status'],
'component' => $i['component_name'] ?? null, 'componentId' => $i['component_id'] !== null ? (int) $i['component_id'] : null,