* Bild (SVG): * * Parameter: rz = wc1 | wc2 | cube v = it | web g = small | big t = hell | dunkel * Fragen: helpdesk@windcores.de */ declare(strict_types=1); const WCE_QUELLE = 'https://portal.windcores-colocation.de/energy/'; const WCE_CACHE_SEK = 600; ini_set('session.use_cookies', '0'); ini_set('log_errors', '0'); ini_set('display_errors', '0'); $erlaubt = [ 'rz' => ['wc2', 'wc1', 'cube'], 'v' => ['it', 'web'], 'g' => ['big', 'small'], 't' => ['hell', 'dunkel'], ]; $p = []; foreach ($erlaubt as $k => $werte) { $x = $_GET[$k] ?? $werte[0]; $p[$k] = is_string($x) && in_array($x, $werte, true) ? $x : $werte[0]; } $bild = isset($_GET['bild']); if ($bild) { unset($p['g']); $url = WCE_QUELLE . 'badge.php?' . http_build_query($p); } else { $url = WCE_QUELLE . 'widget.php?' . http_build_query($p + ['eigen' => 1]); } $cache = rtrim(sys_get_temp_dir(), '/\\') . '/wc-energy-' . md5($url); $body = null; if (is_file($cache) && time() - (int)filemtime($cache) < WCE_CACHE_SEK) { $body = (string)file_get_contents($cache); } else { $neu = wce_holen($url); if ($neu !== null) { $body = $neu; $tmp = $cache . '.' . getmypid(); if (@file_put_contents($tmp, $neu) !== false) @rename($tmp, $cache); } elseif (is_file($cache)) { $body = (string)file_get_contents($cache); // alter Stand ist besser als nichts } } header_remove('Set-Cookie'); header('X-Content-Type-Options: nosniff'); header('Referrer-Policy: no-referrer'); if ($body === null) { http_response_code(503); header('Cache-Control: no-store'); header('Content-Type: text/plain; charset=utf-8'); echo 'Energie-Status derzeit nicht verfügbar.'; exit; } header('Cache-Control: public, max-age=300'); if ($bild) { header('Content-Type: image/svg+xml; charset=utf-8'); } else { header('Content-Type: text/html; charset=utf-8'); header("Content-Security-Policy: default-src 'none'; style-src 'unsafe-inline'; img-src data:; font-src data:; script-src 'unsafe-inline'; frame-ancestors 'self'"); } echo $body; /** Abruf per cURL, sonst per file_get_contents. Gibt null bei Fehler zurück. */ function wce_holen(string $url): ?string { if (function_exists('curl_init')) { $ch = curl_init($url); curl_setopt_array($ch, [ CURLOPT_RETURNTRANSFER => true, CURLOPT_TIMEOUT => 8, CURLOPT_CONNECTTIMEOUT => 4, CURLOPT_USERAGENT => 'wc-energy-proxy/1.0', CURLOPT_FOLLOWLOCATION => false, ]); $b = curl_exec($ch); $code = (int)curl_getinfo($ch, CURLINFO_RESPONSE_CODE); curl_close($ch); return ($b !== false && $code === 200 && $b !== '') ? (string)$b : null; } if (!ini_get('allow_url_fopen')) return null; $ctx = stream_context_create(['http' => ['timeout' => 8, 'ignore_errors' => true, 'header' => "User-Agent: wc-energy-proxy/1.0\r\n"]]); $b = @file_get_contents($url, false, $ctx); $kopf = function_exists('http_get_last_response_headers') ? (http_get_last_response_headers() ?? []) : ($http_response_header ?? []); return ($b !== false && $b !== '' && isset($kopf[0]) && strpos($kopf[0], ' 200') !== false) ? $b : null; }