diff --git a/data/web/inc/functions.inc.php b/data/web/inc/functions.inc.php index 441fd2a6..70855269 100644 --- a/data/web/inc/functions.inc.php +++ b/data/web/inc/functions.inc.php @@ -2367,6 +2367,20 @@ function get_logs($application, $lines = false) { return $data_array; } } + if ($application == "cron-mailcow") { + if (isset($from) && isset($to)) { + $data = $redis->lRange('CRON_LOG', $from - 1, $to - 1); + } + else { + $data = $redis->lRange('CRON_LOG', 0, $lines); + } + if ($data) { + foreach ($data as $json_line) { + $data_array[] = json_decode($json_line, true); + } + return $data_array; + } + } if ($application == "postfix-mailcow") { if (isset($from) && isset($to)) { $data = $redis->lRange('POSTFIX_MAILLOG', $from - 1, $to - 1); diff --git a/data/web/js/site/debug.js b/data/web/js/site/debug.js index e0b9a5ab..f7b9c011 100644 --- a/data/web/js/site/debug.js +++ b/data/web/js/site/debug.js @@ -824,6 +824,66 @@ jQuery(function($){ hideTableExpandCollapseBtn('#tab-dovecot-logs', '#dovecot_log'); }); } + function draw_cron_logs() { + // just recalc width if instance already exists + if ($.fn.DataTable.isDataTable('#cron_log') ) { + $('#cron_log').DataTable().columns.adjust().responsive.recalc(); + return; + } + + var table = $('#cron_log').DataTable({ + responsive: true, + processing: true, + serverSide: false, + stateSave: true, + pageLength: log_pagination_size, + dom: "<'row'<'col-sm-12 col-md-6'f><'col-sm-12 col-md-6'l>>" + + "tr" + + "<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>", + language: lang_datatables, + order: [[0, 'desc']], + initComplete: function(){ + hideTableExpandCollapseBtn('#tab-cron-logs', '#cron_log'); + }, + ajax: { + type: "GET", + url: "/api/v1/get/logs/cron", + dataSrc: function(data){ + return process_table_data(data, 'general_syslog'); + } + }, + columns: [ + { + title: lang.time, + data: 'time', + defaultContent: '', + createdCell: function(td, cellData) { + createSortableDate(td, cellData) + } + }, + { + title: lang.task, + data: 'task', + defaultContent: '' + }, + { + title: lang.priority, + data: 'priority', + defaultContent: '' + }, + { + title: lang.message, + data: 'message', + defaultContent: '', + className: 'dtr-col-md text-break' + } + ] + }); + + table.on('responsive-resize', function (e, datatable, columns){ + hideTableExpandCollapseBtn('#tab-cron-logs', '#cron_log'); + }); + } function rspamd_pie_graph() { $.ajax({ url: '/api/v1/get/rspamd/actions', @@ -1181,7 +1241,7 @@ jQuery(function($){ if (table = $('#' + log_table).DataTable()) { var heading = $('#' + log_table).closest('.card').find('.card-header'); - var load_rows = (table.page.len() + 1) + '-' + (table.page.len() + new_nrows) + var load_rows = (table.data().count() + 1) + '-' + (table.data().count() + new_nrows) $.get('/api/v1/get/logs/' + log_url + '/' + load_rows).then(function(data){ if (data.length === undefined) { mailcow_alert_box(lang.no_new_rows, "info"); return; } @@ -1227,6 +1287,7 @@ jQuery(function($){ onVisible("[id^=ui_logs]", () => draw_ui_logs()); onVisible("[id^=sasl_logs]", () => draw_sasl_logs()); onVisible("[id^=netfilter_log]", () => draw_netfilter_logs()); + onVisible("[id^=cron_log]", () => draw_cron_logs()); onVisible("[id^=rspamd_history]", () => draw_rspamd_history()); onVisible("[id^=rspamd_donut]", () => rspamd_pie_graph()); diff --git a/data/web/json_api.php b/data/web/json_api.php index 3367df94..70d956a4 100644 --- a/data/web/json_api.php +++ b/data/web/json_api.php @@ -896,6 +896,17 @@ if (isset($_GET['query'])) { } echo (isset($logs) && !empty($logs)) ? json_encode($logs, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT) : '{}'; break; + case "cron": + // 0 is first record, so empty is fine + if (isset($extra)) { + $extra = preg_replace('/[^\d\-]/i', '', $extra); + $logs = get_logs('cron-mailcow', $extra); + } + else { + $logs = get_logs('cron-mailcow'); + } + echo (isset($logs) && !empty($logs)) ? json_encode($logs, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT) : '{}'; + break; case "postfix": // 0 is first record, so empty is fine if (isset($extra)) { diff --git a/data/web/templates/debug.twig b/data/web/templates/debug.twig index 006703fb..33933340 100644 --- a/data/web/templates/debug.twig +++ b/data/web/templates/debug.twig @@ -16,6 +16,7 @@
  • +
  • {{ lang.debug.external_logs }}
  • {{ lang.debug.static_logs }}
  • @@ -618,6 +619,29 @@ +
    +
    {{ lang.debug.log_info|format(log_lines+1)|raw }}
    +
    +
    + Crontasks +
    + +
    +
    + +
    +
    +