pipe_rl.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. // File size is limited by Nginx site to 10M
  3. // To speed things up, we do not include prerequisites
  4. header('Content-Type: text/plain');
  5. require_once "vars.inc.php";
  6. // Do not show errors, we log to using error_log
  7. ini_set('error_reporting', 0);
  8. // Init Redis
  9. $redis = new Redis();
  10. try {
  11. if (!empty(getenv('REDIS_SLAVEOF_IP'))) {
  12. $redis->connect(getenv('REDIS_SLAVEOF_IP'), getenv('REDIS_SLAVEOF_PORT'));
  13. }
  14. else {
  15. $redis->connect('redis-mailcow', 6379);
  16. }
  17. }
  18. catch (Exception $e) {
  19. exit;
  20. }
  21. $raw_data_content = file_get_contents('php://input');
  22. $raw_data_decoded = json_decode($raw_data_content, true);
  23. $data['time'] = time();
  24. $data['rcpt'] = implode(', ', $raw_data_decoded['rcpt']);
  25. $data['from'] = $raw_data_decoded['from'];
  26. $data['user'] = $raw_data_decoded['user'];
  27. $symbol_rl_key = array_search('RATELIMITED', array_column($raw_data_decoded['symbols'], 'name'));
  28. $data['rl_info'] = implode($raw_data_decoded['symbols'][$symbol_rl_key]['options']);
  29. preg_match('/(.+)\((.+)\)/i', $data['rl_info'], $rl_matches);
  30. if (!empty($rl_matches[1]) && !empty($rl_matches[2])) {
  31. $data['rl_name'] = $rl_matches[1];
  32. $data['rl_hash'] = $rl_matches[2];
  33. }
  34. else {
  35. $data['rl_name'] = 'err';
  36. $data['rl_hash'] = 'err';
  37. }
  38. $data['qid'] = $raw_data_decoded['qid'];
  39. $data['ip'] = $raw_data_decoded['ip'];
  40. $data['message_id'] = $raw_data_decoded['message_id'];
  41. $data['header_subject'] = implode(' ', $raw_data_decoded['header_subject']);
  42. $data['header_from'] = implode(', ', $raw_data_decoded['header_from']);
  43. $redis->lpush('RL_LOG', json_encode($data));
  44. exit;