|
1 | 1 | <?php |
2 | 2 | date_default_timezone_set('Europe/Berlin'); |
3 | 3 | $config = require 'config.php'; |
| 4 | + |
| 5 | +if (isset($_GET['type'])) { |
| 6 | + $type = strtolower($_GET['type']); |
| 7 | + if ($type === 'raw') { |
| 8 | + header('Content-Type: application/json'); |
| 9 | + echo json_encode($config['services']); |
| 10 | + exit(); |
| 11 | + } |
| 12 | + if ($type === 'check') { |
| 13 | + header('Content-Type: application/json'); |
| 14 | + $all_online = true; |
| 15 | + foreach ($config['services'] as $service) { |
| 16 | + if ($service['is_deployed']) { |
| 17 | + $ch = curl_init($service['address']); |
| 18 | + curl_setopt($ch, CURLOPT_NOBODY, true); |
| 19 | + curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); |
| 20 | + curl_setopt($ch, CURLOPT_TIMEOUT, 5); |
| 21 | + curl_exec($ch); |
| 22 | + $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); |
| 23 | + curl_close($ch); |
| 24 | + if ($code < 200 || $code >= 400) { |
| 25 | + $all_online = false; |
| 26 | + break; |
| 27 | + } |
| 28 | + } |
| 29 | + } |
| 30 | + echo json_encode(['operational' => $all_online]); |
| 31 | + exit(); |
| 32 | + } |
| 33 | +} |
4 | 34 | ?> |
5 | 35 | <!DOCTYPE html> |
6 | 36 | <html lang="en"> |
@@ -101,7 +131,9 @@ function updateUI(card, dot, label, stateKey, colorClass, borderClass) { |
101 | 131 | } |
102 | 132 |
|
103 | 133 | function checkAllServices() { |
104 | | - document.getElementById('last-update').textContent = `Live · Updated ${new RegExp(/\d{2}:\d{2}:\d{2}/).exec(new Date().toString())[0]}`; |
| 134 | + const now = new Date(); |
| 135 | + const timeString = now.toLocaleTimeString('de-DE', { hour: '2-digit', minute: '2-digit', second: '2-digit' }); |
| 136 | + document.getElementById('last-update').textContent = `Live · Updated ${timeString}`; |
105 | 137 | document.querySelectorAll('.service-card').forEach(checkService); |
106 | 138 | } |
107 | 139 |
|
|
0 commit comments