From feebd64fd87088c6dfc07bd63fb3e75eb9e7ad69 Mon Sep 17 00:00:00 2001 From: Michal Date: Sun, 26 Jul 2026 13:22:48 +0200 Subject: [PATCH] current state --- micalis.net/index.html | 405 ++++++++++++++++++++++++++++++++++ micalis.net/status.php | 94 ++++++++ micalis.net/status_cache.json | 1 + 3 files changed, 500 insertions(+) create mode 100644 micalis.net/index.html create mode 100644 micalis.net/status.php create mode 100644 micalis.net/status_cache.json diff --git a/micalis.net/index.html b/micalis.net/index.html new file mode 100644 index 0000000..507983e --- /dev/null +++ b/micalis.net/index.html @@ -0,0 +1,405 @@ + + + + + + MicalLab - HomeLab Server + + + + +
+
+

MicalLab

+

Personal HomeLab Server

+
+ + Kontroluji stav služeb... +
+
+ +

🏠 Služby

+ + + +
+

© 2026 MicalLab – Self‑hosted infrastructure

+
+
+ + + + diff --git a/micalis.net/status.php b/micalis.net/status.php new file mode 100644 index 0000000..477d5a4 --- /dev/null +++ b/micalis.net/status.php @@ -0,0 +1,94 @@ + 'gitea', 'name' => 'Gitea', 'url' => 'https://gitea.micalis.net/', 'timeout' => 5], + ['id' => 'nextcloud', 'name' => 'Nextcloud', 'url' => 'https://nextcloud.micalis.net/', 'timeout' => 5], + ['id' => 'aichat', 'name' => 'AI Chat', 'url' => 'https://ai.micalis.net/', 'timeout' => 5], + ['id' => 'jellyfin', 'name' => 'Jellyfin', 'url' => 'https://jellyfin.micalis.net/', 'timeout' => 5], + ['id' => 'amp', 'name' => 'AMP Game Panel', 'url' => 'https://amp.micalis.net/', 'timeout' => 5], + ['id' => 'matrix', 'name' => 'Matrix', 'url' => 'https://matrix.micalis.net/', 'timeout' => 5], + ['id' => 'grafana', 'name' => 'Grafana', 'url' => 'https://grafana.micalis.net/', 'timeout' => 5], +]; + +$cacheFile = __DIR__ . '/status_cache.json'; +$cacheTTL = 60; + +// Zkus načíst z cache +if (file_exists($cacheFile)) { + $cache = json_decode(file_get_contents($cacheFile), true); + if ($cache && isset($cache['timestamp']) && (time() - $cache['timestamp']) < $cacheTTL) { + echo json_encode($cache['data']); + exit; + } +} + +// Funkce pro kontrolu služby +function checkService($url, $timeout = 5) { + $ch = curl_init(); + curl_setopt_array($ch, [ + CURLOPT_URL => $url, + CURLOPT_RETURNTRANSFER => true, + CURLOPT_HEADER => true, + CURLOPT_NOBODY => true, + CURLOPT_TIMEOUT => $timeout, + CURLOPT_SSL_VERIFYPEER => true, + CURLOPT_FOLLOWLOCATION => true, + CURLOPT_MAXREDIRS => 3, + ]); + + curl_exec($ch); + $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); + $error = curl_error($ch); + curl_close($ch); + + // Timeout + if ($error && stripos($error, 'timeout') !== false) { + return ['status' => 'offline', 'message' => 'Timeout']; + } + // Connection error + if ($error || $httpCode === 0) { + return ['status' => 'offline', 'message' => 'Connection failed']; + } + // HTTP error (4xx, 5xx) + if ($httpCode >= 400) { + return ['status' => 'offline', 'message' => "HTTP $httpCode"]; + } + + return ['status' => 'online', 'http_code' => $httpCode, 'message' => 'OK']; +} + +// Zkontroluj všechny služby +$results = []; +foreach ($services as $service) { + $check = checkService($service['url'], $service['timeout']); + $results[] = [ + 'id' => $service['id'], + 'name' => $service['name'], + 'status' => $check['status'], + 'message' => $check['message'], + ]; +} + +$onlineCount = count(array_filter($results, fn($r) => $r['status'] === 'online')); + +$response = [ + 'timestamp' => time(), + 'overall' => [ + 'status' => $onlineCount === count($results) ? 'all_online' : ($onlineCount > 0 ? 'partial' : 'all_offline'), + 'online' => $onlineCount, + 'total' => count($results), + ], + 'services' => $results, +]; + +file_put_contents($cacheFile, json_encode(['timestamp' => time(), 'data' => $response])); + +echo json_encode($response); diff --git a/micalis.net/status_cache.json b/micalis.net/status_cache.json new file mode 100644 index 0000000..db592f9 --- /dev/null +++ b/micalis.net/status_cache.json @@ -0,0 +1 @@ +{"timestamp":1785064933,"data":{"timestamp":1785064933,"overall":{"status":"partial","online":5,"total":7},"services":[{"id":"gitea","name":"Gitea","status":"online","message":"OK"},{"id":"nextcloud","name":"Nextcloud","status":"online","message":"OK"},{"id":"aichat","name":"AI Chat","status":"offline","message":"HTTP 405"},{"id":"jellyfin","name":"Jellyfin","status":"online","message":"OK"},{"id":"amp","name":"AMP Game Panel","status":"online","message":"OK"},{"id":"matrix","name":"Matrix","status":"offline","message":"Connection failed"},{"id":"grafana","name":"Grafana","status":"online","message":"OK"}]}} \ No newline at end of file