diff --git a/data/web/js/debug.js b/data/web/js/debug.js index 838fd3c29..2747e604b 100644 --- a/data/web/js/debug.js +++ b/data/web/js/debug.js @@ -343,43 +343,41 @@ jQuery(function($){ var ft_paging = ft.use(FooTable.Paging) return ft_paging.totalRows; }) - } - } - }); - } - function plot_rspamd() { - $.ajax({ - url: '/api/v1/get/rspamd/actions', - success: function(data){ - var total = 0; - $(data).map(function(){total += this[1];}) - rspamd_labels = $.makeArray($(data).map(function(){return "
" + this[0] + " (" + this[1] + ") " + Math.round(this[1]/total * 100) + "%
";})); - rspamd_donut = $.jqplot('rspamd_donut', [data], - { - seriesDefaults: { - renderer: jQuery.jqplot.DonutRenderer, - rendererOptions: { - showDataLabels: true, - dataLabels: rspamd_labels, - dataLabelThreshold: 1, - sliceMargin: 5, - totalLabel: true - }, - shadow: false, - seriesColors: ['#FF4136', '#75CAEB', '#FF851B', '#FF851B', '#28B62C'] - }, - legend: { - show:false, - }, - grid: { - drawGridLines: true, - gridLineColor: '#efefef', - background: '#ffffff', - borderWidth: 0, - shadow: false, + $.ajax({ + url: '/api/v1/get/rspamd/actions', + success: function(data){ + var total = 0; + $(data).map(function(){total += this[1];}) + rspamd_labels = $.makeArray($(data).map(function(){return "
" + this[0] + " (" + this[1] + ") " + Math.round(this[1]/total * 100) + "%
";})); + rspamd_donut_plot = $.jqplot('rspamd_donut', [data], + { + seriesDefaults: { + renderer: jQuery.jqplot.DonutRenderer, + rendererOptions: { + showDataLabels: true, + dataLabels: rspamd_labels, + dataLabelThreshold: 1, + sliceMargin: 5, + totalLabel: true + }, + shadow: false, + seriesColors: ['#FF4136', '#75CAEB', '#FF851B', '#FF851B', '#28B62C'] + }, + legend: { + show:false, + }, + grid: { + drawGridLines: true, + gridLineColor: '#efefef', + background: '#ffffff', + borderWidth: 0, + shadow: false, + } + } + ); } - } - ); + }); + } } }); } @@ -538,8 +536,8 @@ jQuery(function($){ var timer; clearTimeout(timer); timer = setTimeout(function () { - if (typeof rspamd_donut !== 'undefined') { - rspamd_donut.replot({}); + if (typeof rspamd_donut_plot !== 'undefined') { + rspamd_donut_plot.replot({}); } }, 500); }); diff --git a/data/web/json_api.php b/data/web/json_api.php index baeeb48bf..7faa8841c 100644 --- a/data/web/json_api.php +++ b/data/web/json_api.php @@ -158,6 +158,26 @@ if (isset($_SESSION['mailcow_cc_role']) || isset($_SESSION['pending_mailcow_cc_u switch ($category) { case "rspamd": switch ($object) { + 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 '{}'; + } + break; case "stat": $data = file_get_contents('http://rspamd-mailcow:11334/stat'); process_get_return($data);