Initial control project import
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
require_once __DIR__ . '/../../config/config.php';
|
||||
|
||||
if (($_SERVER['REQUEST_METHOD'] ?? 'GET') !== 'POST') {
|
||||
json_out(['ok' => false, 'error' => 'method_not_allowed'], 405);
|
||||
}
|
||||
|
||||
$raw = (string)file_get_contents('php://input');
|
||||
$data = json_decode($raw, true);
|
||||
if (!is_array($data)) {
|
||||
$data = [];
|
||||
}
|
||||
|
||||
$event = (string)($data['event'] ?? '');
|
||||
$allowedEvents = [
|
||||
'push_received',
|
||||
'notification_shown',
|
||||
'notification_show_failed',
|
||||
'notification_click',
|
||||
'notification_close',
|
||||
'client_log_failed',
|
||||
];
|
||||
|
||||
if (!in_array($event, $allowedEvents, true)) {
|
||||
json_out(['ok' => false, 'error' => 'invalid_event'], 422);
|
||||
}
|
||||
|
||||
$endpoint = (string)($data['endpoint'] ?? '');
|
||||
$meta = is_array($data['meta'] ?? null) ? $data['meta'] : [];
|
||||
$context = [
|
||||
'endpoint' => $endpoint,
|
||||
'message' => mb_substr((string)($data['push_id'] ?? ''), 0, 255),
|
||||
'push_id' => (string)($data['push_id'] ?? ''),
|
||||
'tag' => (string)($data['tag'] ?? ''),
|
||||
'visibility_state' => (string)($data['visibility_state'] ?? ''),
|
||||
'client_count' => isset($data['client_count']) ? (int)$data['client_count'] : null,
|
||||
'meta' => $meta,
|
||||
];
|
||||
|
||||
push_log_event($event, $context);
|
||||
|
||||
json_out(['ok' => true]);
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
if (session_status() !== PHP_SESSION_ACTIVE) {
|
||||
session_start();
|
||||
}
|
||||
|
||||
require_once __DIR__ . '/../../config/config.php';
|
||||
|
||||
if (!signed_in()) {
|
||||
json_out([
|
||||
'ok' => false,
|
||||
'error' => 'login_required',
|
||||
], 401);
|
||||
}
|
||||
|
||||
if (($_SERVER['REQUEST_METHOD'] ?? 'GET') !== 'POST') {
|
||||
json_out([
|
||||
'ok' => false,
|
||||
'error' => 'method_not_allowed',
|
||||
], 405);
|
||||
}
|
||||
|
||||
require_csrf();
|
||||
|
||||
$subscription = push_subscription_from_json((string)file_get_contents('php://input'));
|
||||
save_push_subscription($subscription);
|
||||
|
||||
json_out([
|
||||
'ok' => true,
|
||||
]);
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
if (session_status() !== PHP_SESSION_ACTIVE) {
|
||||
session_start();
|
||||
}
|
||||
|
||||
require_once __DIR__ . '/../../config/config.php';
|
||||
|
||||
if (!signed_in()) {
|
||||
json_out([
|
||||
'ok' => false,
|
||||
'error' => 'login_required',
|
||||
], 401);
|
||||
}
|
||||
|
||||
if (($_SERVER['REQUEST_METHOD'] ?? 'GET') !== 'POST') {
|
||||
json_out([
|
||||
'ok' => false,
|
||||
'error' => 'method_not_allowed',
|
||||
], 405);
|
||||
}
|
||||
|
||||
require_csrf();
|
||||
|
||||
$data = push_subscription_from_json((string)file_get_contents('php://input'));
|
||||
$payload = [
|
||||
'title' => (string)($data['title'] ?? 'Seoul Control Center'),
|
||||
'body' => (string)($data['body'] ?? 'Push notification test'),
|
||||
'url' => '/',
|
||||
'tag' => (string)($data['tag'] ?? 'control-test'),
|
||||
'created_at' => date('Y-m-d H:i:s'),
|
||||
];
|
||||
|
||||
json_out([
|
||||
'ok' => true,
|
||||
'data' => send_push_payload($payload),
|
||||
]);
|
||||
Reference in New Issue
Block a user