I wrote a small python script that takes postfix/dovecot logs and uploads it to mariadb database. The table has only 2 rows, id(key)
and log(text)
.
Everything is working except when I search in HTML page for a particular log, it displays this:
Oct 30 00:14:26 mailserver postfix/smtpd[1321]: NOQUEUE: reject: RCPT from mx.mailbox.rs[109.245.241.198]: 450 4.1.8 : Sender address rejected: Domain not found; from= to= proto=ESMTP helo=
As you see, "from="
, "to="
, and "helo="
are empty and they should be there.
I have a full log in database:
Oct 30 00:14:26 mailserver postfix/smtpd[1321]: NOQUEUE: reject: RCPT from mx.mailbox.rs[109.245.241.198]: 450 4.1.8 <xxx@xxx.xx>: Sender address rejected: Domain not found; from=<xxx@mail.xxx.xxx> to=<xxx@mxxx.xx> proto=ESMTP helo=<mx.mailbox.rs>
It seems that "<>"
these signs are the problem.
Database encoding is utf8
. I use datatables.net for displaying results and searching the logs.
Here is the code
<?php
// Database connection info
$dbDetails = array(
'host' => 'localhost',
'user' => 'xxx',
'pass' => 'xxx',
'db' => 'xxx',
'charset' => 'utf8'
);
// DB table to use
$table = 'logs';
// Table's primary key
$primaryKey = 'id';
// Array of database columns which should be read and sent back to DataTables.
// The `db` parameter represents the column name in the database.
// The `dt` parameter represents the DataTables column identifier.
$columns = array(
array( 'db' => 'id', 'dt' => 0 ),
array( 'db' => 'log', 'dt' => 1 ),
);
// Include SQL query processing class
require 'ssp.class.php';
// Output data as json format
echo json_encode(
SSP::simple( $_GET, $dbDetails, $table, $primaryKey, $columns )
);
<!-- DataTables CSS library -->
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.22/css/jquery.dataTables.min.css"/>
<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<!-- DataTables JS library -->
<script type="text/javascript" src="https://cdn.datatables.net/1.10.22/js/jquery.dataTables.min.js"></script>
<script>
$(document).ready(function(){
$('#memListTable').DataTable({
"processing": true,
"serverSide": true,
"ajax": "getData.php"
});
});
</script>
<table id="memListTable" class="display" style="width:100%">
<thead>
<tr>
<th>ID</th>
<th>Log</th>
</tr>
</thead>
<tfoot>
<tr>
<th>ID</th>
<th>Log</th>
</tr>
</tfoot>
</table>
</html>
EDIT2
I tried using:
function filter(&$value) {
$value = htmlspecialchars($value, ENT_SUBSTITUTE, ENT_COMPAT, 'UTF-8');
}
array_walk_recursive($columns, "filter");
with no luck.