Add Json log parser for Dovecot and Postfix containers

This commit is contained in:
andryyy 2017-05-06 23:52:40 +02:00
parent d614aaf617
commit 8c8bfc0108
4 changed files with 109 additions and 49 deletions

View File

@ -9,7 +9,7 @@ $tfa_data = get_tfa();
<div class="container">
<h4><span class="glyphicon glyphicon-user" aria-hidden="true"></span> <?=$lang['admin']['access'];?></h4>
<div class="panel-group" id="accordion_access">
<div class="panel-group">
<div class="panel panel-danger">
<div class="panel-heading"><?=$lang['admin']['admin_details'];?></div>
<div class="panel-body">
@ -82,52 +82,7 @@ $tfa_data = get_tfa();
<div class="panel-body">
<form method="post">
<div class="table-responsive">
<table class="table table-striped" id="domainadminstable">
<thead>
<tr>
<th style="min-width: 100px;"><?=$lang['admin']['username'];?></th>
<th style="min-width: 166px;"><?=$lang['admin']['admin_domains'];?></th>
<th style="min-width: 76px;"><?=$lang['admin']['active'];?></th>
<th style="min-width: 76px;"><?=$lang['tfa']['tfa'];?></th>
<th style="text-align: right; min-width: 200px;"><?=$lang['admin']['action'];?></th>
</tr>
</thead>
<tbody>
<?php
foreach (get_domain_admins() as $domain_admin) {
$da_data = get_domain_admin_details($domain_admin);
if (!empty($da_data)):
?>
<tr id="data">
<td><?=htmlspecialchars(strtolower($domain_admin));?></td>
<td>
<?php
foreach ($da_data['selected_domains'] as $domain) {
echo htmlspecialchars($domain).'<br />';
}
?>
</td>
<td><?=$da_data['active'];?></td>
<td><?=empty($da_data['tfa_active_int']) ? "" : "";?></td>
<td style="text-align: right;">
<div class="btn-group">
<a href="edit.php?domainadmin=<?=$domain_admin;?>" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> <?=$lang['admin']['edit'];?></a>
<a href="delete.php?domainadmin=<?=$domain_admin;?>" class="btn btn-xs btn-danger"><span class="glyphicon glyphicon-trash"></span> <?=$lang['admin']['remove'];?></a>
</div>
</td>
</td>
</tr>
<?php
else:
?>
<tr id="no-data"><td colspan="4" style="text-align: center; font-style: italic;"><?=$lang['admin']['no_record'];?></td></tr>
<?php
endif;
}
?>
</tbody>
</table>
<table class="table table-striped" id="domainadminstable"></table>
</div>
</form>
<small>
@ -185,7 +140,7 @@ $tfa_data = get_tfa();
<h4><span class="glyphicon glyphicon-wrench" aria-hidden="true"></span> <?=$lang['admin']['configuration'];?></h4>
<div class="panel-group" id="accordion_access">
<div class="panel-group">
<div class="panel panel-default">
<div class="panel-heading"><?=$lang['admin']['dkim_keys'];?></div>
@ -372,9 +327,19 @@ $tfa_data = get_tfa();
</form>
</div>
</div>
</div>
<h4><span class="glyphicon glyphicon-book" aria-hidden="true"></span> Mail Logs</h4>
<div class="panel-group">
<div class="panel panel-default">
<div class="panel-heading">Logs</div>
<div class="panel-body">
<div class="table-responsive">
<table class="table table-striped" id="dovecot_log"></table>
</div>
</div>
</div>
</div>
</div> <!-- /container -->
<script type='text/javascript'>
<?php

View File

@ -5181,4 +5181,30 @@ function delete_forwarding_host($postarray) {
'msg' => sprintf($lang['success']['forwarding_host_removed'], htmlspecialchars($host))
);
}
function get_logs($container, $lines = 100) {
global $lang;
global $redis;
if ($_SESSION['mailcow_cc_role'] != "admin") {
$_SESSION['return'] = array(
'type' => 'danger',
'msg' => sprintf($lang['danger']['access_denied'])
);
return false;
}
$lines = intval($lines);
if ($container == "dovecot-mailcow") {
if ($data = $redis->lRange('DOVECOT_MAILLOG', 1, $lines)) {
foreach ($data as $json_line) {
$data_array[] = json_decode($json_line, true);
}
return $data_array;
}
}
if ($container == "postfix-mailcow") {
if ($data = $redis->lRange('POSTFIX_MAILLOG', 1, $lines)) {
return $data;
}
}
return false;
}
?>

View File

@ -39,4 +39,37 @@ $(document).ready(function() {
});
}
});
$.ajax({
dataType: 'json',
url: '/api/v1/get/logs/dovecot/all',
jsonp: false,
error: function () {
alert('Cannot draw dovecot log table');
},
success: function (data) {
$('#dovecot_log').footable({
"columns": [
{"name":"time","title":"time"},
{"name":"program","title":"program"},
{"name":"priority","title":"priority"},
{"name":"message","title":"message"},
],
"rows": data,
"empty": lang.empty,
"paging": {
"enabled": true,
"limit": 5,
"size": pagination_size
},
"filtering": {
"enabled": true,
"position": "left",
"placeholder": lang.filter_table
},
"sorting": {
"enabled": true
}
});
}
});
});

View File

@ -22,6 +22,7 @@ if (isset($_SESSION['mailcow_cc_role']) || isset($_SESSION['pending_mailcow_cc_u
$action = (isset($query[0])) ? $query[0] : null;
$category = (isset($query[1])) ? $query[1] : null;
$object = (isset($query[2])) ? $query[2] : null;
$extra = (isset($query[3])) ? $query[3] : null;
switch ($action) {
case "get":
@ -57,6 +58,41 @@ if (isset($_SESSION['mailcow_cc_role']) || isset($_SESSION['pending_mailcow_cc_u
break;
}
break;
case "logs":
switch ($object) {
case "dovecot":
if (isset($extra) && !empty($extra) && is_int($extra)) {
$extra = intval($extra);
$logs = get_logs('dovecot-mailcow', $extra);
}
else {
$logs = get_logs('dovecot-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) && is_int($extra)) {
$extra = intval($extra);
$logs = get_logs('postfix-mailcow', $extra);
}
else {
$logs = get_logs('postfix-mailcow', -1);
}
if (isset($logs) && !empty($logs)) {
echo json_encode($logs, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
}
else {
echo '{}';
}
break;
}
break;
case "mailbox":
switch ($object) {
case "all":