initial commit
This commit is contained in:
@@ -0,0 +1 @@
|
||||
config.php
|
||||
Vendored
+2
File diff suppressed because one or more lines are too long
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'push_url' => 'https://push.demo.regattatech.de/notify',
|
||||
'api_key' => 'securetoken'
|
||||
];
|
||||
@@ -0,0 +1,112 @@
|
||||
<?php
|
||||
|
||||
$status = $_GET['status'] ?? '';
|
||||
$message = $_GET['message'] ?? '';
|
||||
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="de">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Push Notification senden</title>
|
||||
<link rel="stylesheet" href="assets/css/tailwind.min.css">
|
||||
</head>
|
||||
<body class="bg-gray-100 min-h-screen">
|
||||
|
||||
<div class="max-w-2xl mx-auto py-10 px-4">
|
||||
|
||||
<div class="bg-white shadow-lg rounded-lg p-8">
|
||||
|
||||
<h1 class="text-3xl font-bold mb-6">
|
||||
Push Notification senden
|
||||
</h1>
|
||||
|
||||
<?php if ($status === 'success'): ?>
|
||||
<div class="bg-green-100 border border-green-300 text-green-800 p-4 rounded mb-6">
|
||||
<?= htmlspecialchars($message) ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ($status === 'error'): ?>
|
||||
<div class="bg-red-100 border border-red-300 text-red-800 p-4 rounded mb-6">
|
||||
<?= htmlspecialchars($message) ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<form action="send.php" method="post" id="pushForm">
|
||||
|
||||
<div class="mb-4">
|
||||
<label class="block font-medium mb-2">
|
||||
Titel
|
||||
</label>
|
||||
<input
|
||||
type="text"
|
||||
name="title"
|
||||
required
|
||||
maxlength="255"
|
||||
class="w-full border rounded-lg p-3"
|
||||
>
|
||||
</div>
|
||||
|
||||
<div class="mb-4">
|
||||
<label class="block font-medium mb-2">
|
||||
Nachricht
|
||||
</label>
|
||||
<textarea
|
||||
name="message"
|
||||
required
|
||||
rows="6"
|
||||
class="w-full border rounded-lg p-3"
|
||||
></textarea>
|
||||
</div>
|
||||
|
||||
<div class="mb-6">
|
||||
<label class="block font-medium mb-2">
|
||||
Priorität
|
||||
</label>
|
||||
|
||||
<select
|
||||
name="type"
|
||||
id="type"
|
||||
class="w-full border rounded-lg p-3"
|
||||
>
|
||||
<option value="info">Normal</option>
|
||||
<option value="warning">Wichtig</option>
|
||||
<option value="danger">Sehr Dringend</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<button
|
||||
type="submit"
|
||||
class="bg-blue-600 hover:bg-blue-700 text-white px-6 py-3 rounded-lg"
|
||||
>
|
||||
Senden
|
||||
</button>
|
||||
|
||||
</form>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<script>
|
||||
document.getElementById('pushForm').addEventListener('submit', function(e) {
|
||||
|
||||
const type = document.getElementById('type').value;
|
||||
|
||||
if (type === 'danger') {
|
||||
|
||||
const confirmed = confirm(
|
||||
'Diese Nachricht wird als SEHR DRINGEND versendet.\n\nBist du sicher?'
|
||||
);
|
||||
|
||||
if (!confirmed) {
|
||||
e.preventDefault();
|
||||
}
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@@ -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