From 3911ba09104e3fbc177e3d4ff676b758bb19b64f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9?= Date: Sun, 20 May 2018 23:28:36 +0200 Subject: [PATCH] [Web] Add Rspamd stats export to API --- data/web/json_api.php | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/data/web/json_api.php b/data/web/json_api.php index d43d8a4c..8fe0c22e 100644 --- a/data/web/json_api.php +++ b/data/web/json_api.php @@ -634,10 +634,21 @@ if (isset($_SESSION['mailcow_cc_role']) || isset($_SESSION['pending_mailcow_cc_u switch ($category) { case "rspamd": switch ($object) { - case "stat": - $data = file_get_contents('http://rspamd-mailcow:11334/stat'); - if (!empty($data)) { - echo $data; + case "actions": + $curl = curl_init(); + curl_setopt($curl, CURLOPT_UNIX_SOCKET_PATH, '/rspamd-sock/rspamd.sock'); + curl_setopt($curl, CURLOPT_URL,"http://rspamd/stat"); + curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); + $data = curl_exec($curl); + if ($data) { + $return = array(); + $stats_array = json_decode($data, true)['actions']; + $stats_array['soft reject'] = $stats_array['soft reject'] + $stats_array['greylist']; + unset($stats_array['greylist']); + foreach ($stats_array as $action => $count) { + $return[] = array($action, $count); + } + echo json_encode($return, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT); } elseif (!isset($data) || empty($data)) { echo '{}';