pipe_rl.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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. $redis->connect('redis-mailcow', 6379);
  11. $raw_data_content = file_get_contents('php://input');
  12. $raw_data_decoded = json_decode($raw_data_content, true);
  13. $data['time'] = time();
  14. $data['rcpt'] = implode(', ', $raw_data_decoded['rcpt']);
  15. $data['from'] = $raw_data_decoded['from'];
  16. $data['user'] = $raw_data_decoded['user'];
  17. $symbol_rl_key = array_search('RATELIMITED', array_column($raw_data_decoded['symbols'], 'name'));
  18. $data['rl_info'] = implode($raw_data_decoded['symbols'][$symbol_rl_key]['options']);
  19. preg_match('/(.+)\((.+)\)/i', $data['rl_info'], $rl_matches);
  20. if (!empty($rl_matches[1]) && !empty($rl_matches[2])) {
  21. $data['rl_name'] = $rl_matches[1];
  22. $data['rl_hash'] = $rl_matches[2];
  23. }
  24. else {
  25. $data['rl_name'] = 'err';
  26. $data['rl_hash'] = 'err';
  27. }
  28. $data['qid'] = $raw_data_decoded['qid'];
  29. $data['ip'] = $raw_data_decoded['ip'];
  30. $data['message_id'] = $raw_data_decoded['message_id'];
  31. $data['header_subject'] = implode(' ', $raw_data_decoded['header_subject']);
  32. $data['header_from'] = implode(', ', $raw_data_decoded['header_from']);
  33. $redis->lpush('RL_LOG', json_encode($data));
  34. exit;