[Web] Add rspamd-stats route to API

master
andryyy 2020-09-06 08:54:09 +02:00
parent 003499200e
commit f3c72832f2
No known key found for this signature in database
GPG Key ID: 8EC34FF2794E25EF
2 changed files with 18 additions and 0 deletions

View File

@ -1673,6 +1673,20 @@ function get_logs($application, $lines = false) {
curl_close($curl);
return false;
}
if ($application == "rspamd-stats") {
$curl = curl_init();
curl_setopt($curl, CURLOPT_UNIX_SOCKET_PATH, '/var/lib/rspamd/rspamd.sock');
curl_setopt($curl, CURLOPT_URL,"http://rspamd/stat");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$stats = curl_exec($curl);
if (!curl_errno($curl)) {
$data_array = json_decode($stats, true);
curl_close($curl);
return $data_array;
}
curl_close($curl);
return false;
}
return false;
}
function getGUID() {

View File

@ -707,6 +707,10 @@ if (isset($_SESSION['mailcow_cc_role']) || isset($_SESSION['pending_mailcow_cc_u
}
echo (isset($logs) && !empty($logs)) ? json_encode($logs, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT) : '{}';
break;
case "rspamd-stats":
$logs = get_logs('rspamd-stats');
echo (isset($logs) && !empty($logs)) ? json_encode($logs, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT) : '{}';
break;
// return no route found if no case is matched
default:
http_response_code(404);