initial commit

This commit is contained in:
Thies Mueller
2026-06-22 20:47:56 +02:00
commit 16039f8ce1
5 changed files with 204 additions and 0 deletions
+83
View File
@@ -0,0 +1,83 @@
<?php
$config = require __DIR__ . '/config.php';
$title = trim($_POST['title'] ?? '');
$message = trim($_POST['message'] ?? '');
$type = $_POST['type'] ?? 'info';
$allowedTypes = [
'info',
'warning',
'danger'
];
if (
empty($title) ||
empty($message) ||
!in_array($type, $allowedTypes, true)
) {
header(
'Location: index.php?status=error&message=' .
urlencode('Ungültige Eingaben.')
);
exit;
}
$payload = [
'type' => $type,
'title' => $title,
'message' => $message
];
$ch = curl_init();
curl_setopt_array($ch, [
CURLOPT_URL => $config['push_url'],
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . $config['api_key'],
'Content-Type: application/json'
],
CURLOPT_POSTFIELDS => json_encode($payload),
CURLOPT_TIMEOUT => 15
]);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if (curl_errno($ch)) {
$error = curl_error($ch);
curl_close($ch);
header(
'Location: index.php?status=error&message=' .
urlencode('cURL Fehler: ' . $error)
);
exit;
}
curl_close($ch);
if ($httpCode >= 200 && $httpCode < 300) {
header(
'Location: index.php?status=success&message=' .
urlencode('Push Notification erfolgreich versendet.')
);
exit;
}
header(
'Location: index.php?status=error&message=' .
urlencode(
'Server antwortete mit HTTP ' .
$httpCode .
': ' .
$response
)
);
exit;