"Nicht angemeldet."]); exit; } function pushAntwort($daten, $code = 200) { http_response_code($code); echo json_encode($daten, JSON_UNESCAPED_UNICODE); exit; } $action = $_GET["action"] ?? "stand"; if ($_SERVER["REQUEST_METHOD"] === "POST") { $body = json_decode(file_get_contents("php://input"), true); if (!is_array($body)) { pushAntwort(["error" => "Konnte die Anfrage nicht lesen."], 400); } try { switch ($action) { case "anmelden": pushAboSpeichern($body["abo"] ?? [], $body["name"] ?? "", $_SERVER["HTTP_USER_AGENT"] ?? ""); pushAntwort(["ok" => true, "abos" => pushAbos()]); case "abmelden": $weg = pushAboEntfernenNachEndpoint(strval($body["endpoint"] ?? "")); pushAntwort(["ok" => true, "entfernt" => $weg, "abos" => pushAbos()]); case "entfernen": $weg = pushAboEntfernen($body["id"] ?? 0); pushAntwort(["ok" => true, "entfernt" => $weg, "abos" => pushAbos()]); case "probe": $titel = trim(strval($body["titel"] ?? "")) ?: "Probe"; $text = trim(strval($body["text"] ?? "")) ?: "Wenn das ankommt, stimmt der Weg."; pushProbe($titel, $text); pushAntwort(["ok" => true]); } pushAntwort(["error" => "Unbekannte Aktion."], 400); } catch (InvalidArgumentException $e) { pushAntwort(["error" => $e->getMessage()], 400); } catch (Throwable $e) { pushAntwort(["error" => $e->getMessage()], 500); } } if ($action === "stand") { pushAntwort([ "schluessel" => pushSchluessel(), "abos" => pushAbos(), ]); } pushAntwort(["error" => "Unbekannte Aktion."], 400);