notify.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. declare(strict_types=1);
  3. use AuditExpress\Http;
  4. use AuditExpress\OutboxStorage;
  5. use AuditExpress\RateLimiter;
  6. use AuditExpress\Security;
  7. ['root' => $root, 'config' => $config] = require __DIR__ . '/_bootstrap.php';
  8. if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
  9. Http::methodNotAllowed(['POST']);
  10. exit;
  11. }
  12. Security::validateCsrf();
  13. (new RateLimiter($root, $config, RateLimiter::clientIp()))->check('notify');
  14. $maxBody = (int) ($config['max_body_bytes'] ?? 1_048_576);
  15. $body = Http::readJsonBody($maxBody > 0 ? $maxBody : null);
  16. $email = (string) ($body['email'] ?? '');
  17. $tool = (string) ($body['tool'] ?? '');
  18. $allowedTools = (array) ($config['allowed_notify_tools'] ?? ['process-mapper']);
  19. if ($tool === '' || !in_array($tool, $allowedTools, true)) {
  20. Http::json(['error' => 'Outil invalide ou non autorisé'], 400);
  21. exit;
  22. }
  23. if ($email === '' || !filter_var($email, FILTER_VALIDATE_EMAIL)) {
  24. Http::json(['error' => 'Email invalide'], 400);
  25. exit;
  26. }
  27. (new OutboxStorage($root . '/storage/outbox'))->storeNotify($tool, $email);
  28. Http::json(['status' => 'ok']);