diff --git a/data/web/admin.php b/data/web/admin.php index 9c1ec002..22e7ee16 100644 --- a/data/web/admin.php +++ b/data/web/admin.php @@ -22,6 +22,7 @@ $tfa_data = get_tfa();
  • Postfix
  • Dovecot
  • SOGo
  • +
  • Fail2ban
  • Rspamd
  • @@ -324,6 +325,24 @@ $tfa_data = get_tfa(); +
    +
    +
    Fail2ban +
    + + +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    Rspamd history diff --git a/data/web/inc/functions.inc.php b/data/web/inc/functions.inc.php index cdd71dfb..9498cf30 100644 --- a/data/web/inc/functions.inc.php +++ b/data/web/inc/functions.inc.php @@ -1388,7 +1388,7 @@ function get_logs($container, $lines = 100) { } $lines = intval($lines); if ($container == "dovecot-mailcow") { - if ($data = $redis->lRange('DOVECOT_MAILLOG', 1, $lines)) { + if ($data = $redis->lRange('DOVECOT_MAILLOG', 0, $lines)) { foreach ($data as $json_line) { $data_array[] = json_decode($json_line, true); } @@ -1396,7 +1396,7 @@ function get_logs($container, $lines = 100) { } } if ($container == "postfix-mailcow") { - if ($data = $redis->lRange('POSTFIX_MAILLOG', 1, $lines)) { + if ($data = $redis->lRange('POSTFIX_MAILLOG', 0, $lines)) { foreach ($data as $json_line) { $data_array[] = json_decode($json_line, true); } @@ -1404,7 +1404,15 @@ function get_logs($container, $lines = 100) { } } if ($container == "sogo-mailcow") { - if ($data = $redis->lRange('SOGO_LOG', 1, $lines)) { + if ($data = $redis->lRange('SOGO_LOG', 0, $lines)) { + foreach ($data as $json_line) { + $data_array[] = json_decode($json_line, true); + } + return $data_array; + } + } + if ($container == "fail2ban-mailcow") { + if ($data = $redis->lRange('F2B_LOG', 0, $lines)) { foreach ($data as $json_line) { $data_array[] = json_decode($json_line, true); } diff --git a/data/web/js/admin.js b/data/web/js/admin.js index 2c3a18fe..ad87b787 100644 --- a/data/web/js/admin.js +++ b/data/web/js/admin.js @@ -43,6 +43,10 @@ jQuery(function($){ e.preventDefault(); draw_sogo_logs(); }); + $("#refresh_fail2ban_log").on('click', function(e) { + e.preventDefault(); + draw_fail2ban_logs(); + }); $("#refresh_rspamd_history").on('click', function(e) { e.preventDefault(); draw_rspamd_history(); @@ -95,6 +99,41 @@ jQuery(function($){ } }); } + function draw_fail2ban_logs() { + ft_fail2ban_logs = FooTable.init('#fail2ban_log', { + "columns": [ + {"name":"time","formatter":function unix_time_format(tm) { var date = new Date(tm ? tm * 1000 : 0); return date.toLocaleString();},"title":lang.time,"style":{"width":"170px"}}, + {"name":"message","title":lang.message}, + ], + "rows": $.ajax({ + dataType: 'json', + url: '/api/v1/get/logs/fail2ban/1000', + jsonp: false, + error: function () { + console.log('Cannot draw fail2ban log table'); + }, + success: function (data) { + $.each(data, function (i, item) { + item.message = escapeHtml(item.message); + }); + } + }), + "empty": lang.empty, + "paging": { + "enabled": true, + "limit": 5, + "size": log_pagination_size + }, + "filtering": { + "enabled": true, + "position": "left", + "placeholder": lang.filter_table + }, + "sorting": { + "enabled": true + } + }); + } function draw_sogo_logs() { ft_sogo_logs = FooTable.init('#sogo_log', { "columns": [ @@ -454,6 +493,7 @@ jQuery(function($){ draw_postfix_logs(); draw_dovecot_logs(); draw_sogo_logs(); + draw_fail2ban_logs(); draw_domain_admins(); draw_fwd_hosts(); draw_rspamd_history(); diff --git a/data/web/json_api.php b/data/web/json_api.php index 28d2790d..b3b22a7d 100644 --- a/data/web/json_api.php +++ b/data/web/json_api.php @@ -480,6 +480,21 @@ if (isset($_SESSION['mailcow_cc_role']) || isset($_SESSION['pending_mailcow_cc_u echo '{}'; } break; + case "fail2ban": + if (isset($extra) && !empty($extra)) { + $extra = intval($extra); + $logs = get_logs('fail2ban-mailcow', $extra); + } + else { + $logs = get_logs('fail2ban-mailcow', -1); + } + if (isset($logs) && !empty($logs)) { + echo json_encode($logs, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT); + } + else { + echo '{}'; + } + break; case "postfix": if (isset($extra) && !empty($extra)) { $extra = intval($extra);