notify.php 996 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. declare(strict_types=1);
  3. use AuditExpress\Http;
  4. $root = require __DIR__ . '/_bootstrap.php';
  5. if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
  6. Http::methodNotAllowed(['POST']);
  7. exit;
  8. }
  9. $body = Http::readJsonBody();
  10. $email = (string) ($body['email'] ?? '');
  11. $tool = (string) ($body['tool'] ?? 'unknown');
  12. if ($email === '' || !filter_var($email, FILTER_VALIDATE_EMAIL)) {
  13. Http::json(['error' => 'Email invalide'], 400);
  14. exit;
  15. }
  16. $outboxDir = $root . '/storage/outbox';
  17. if (!is_dir($outboxDir)) {
  18. @mkdir($outboxDir, 0775, true);
  19. }
  20. $id = date('Ymd_His') . '_' . bin2hex(random_bytes(4));
  21. $meta = [
  22. 'id' => $id,
  23. 'type' => 'notify_interest',
  24. 'tool' => $tool,
  25. 'email' => $email,
  26. 'created_at' => date(DATE_ATOM),
  27. ];
  28. file_put_contents(
  29. $outboxDir . DIRECTORY_SEPARATOR . $id . '_notify.json',
  30. json_encode($meta, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT)
  31. );
  32. Http::json(['status' => 'ok']);