initial commit
This commit is contained in:
@@ -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;
|
||||
Reference in New Issue
Block a user