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