[Web] Show fuzzy hash of rejected mail, if any

master
andryyy 2020-10-24 16:27:31 +02:00
parent 6d1c0041f4
commit 0165c9d26b
No known key found for this signature in database
GPG Key ID: 8EC34FF2794E25EF
7 changed files with 35 additions and 5 deletions

View File

@ -51,6 +51,7 @@ $raw_data = mb_convert_encoding($raw_data_content, 'HTML-ENTITIES', "UTF-8");
$headers = getallheaders();
$qid = $headers['X-Rspamd-Qid'];
$fuzzy = $headers['X-Rspamd-Fuzzy'];
$subject = $headers['X-Rspamd-Subject'];
$score = $headers['X-Rspamd-Score'];
$rcpts = $headers['X-Rspamd-Rcpt'];
@ -215,8 +216,8 @@ foreach (json_decode($rcpts, true) as $rcpt) {
foreach ($rcpt_final_mailboxes as $rcpt_final) {
error_log("QUARANTINE: quarantine pipe: processing quarantine message for rcpt " . $rcpt_final . PHP_EOL);
try {
$stmt = $pdo->prepare("INSERT INTO `quarantine` (`qid`, `subject`, `score`, `sender`, `rcpt`, `symbols`, `user`, `ip`, `msg`, `action`)
VALUES (:qid, :subject, :score, :sender, :rcpt, :symbols, :user, :ip, :msg, :action)");
$stmt = $pdo->prepare("INSERT INTO `quarantine` (`qid`, `subject`, `score`, `sender`, `rcpt`, `symbols`, `user`, `ip`, `msg`, `action`, `fuzzy_hashes`)
VALUES (:qid, :subject, :score, :sender, :rcpt, :symbols, :user, :ip, :msg, :action, :fuzzy_hashes)");
$stmt->execute(array(
':qid' => $qid,
':subject' => $subject,
@ -227,7 +228,8 @@ foreach ($rcpt_final_mailboxes as $rcpt_final) {
':user' => $user,
':ip' => $ip,
':msg' => $raw_data,
':action' => $action
':action' => $action,
':fuzzy_hashes' => $fuzzy
));
$stmt = $pdo->prepare('DELETE FROM `quarantine` WHERE `rcpt` = :rcpt AND `id` NOT IN (
SELECT `id`

View File

@ -63,6 +63,8 @@ if (!empty($_GET['hash']) && ctype_alnum($_GET['hash'])) {
$data['score'] = $mailc['score'];
// Get rspamd symbols
$data['symbols'] = json_decode($mailc['symbols']);
// Get fuzzy hashes
$data['fuzzy_hashes'] = json_decode($mailc['fuzzy_hashes']);
$data['subject'] = $mail_parser->getHeader('subject');
(empty($data['subject'])) ? $data['subject'] = '-' : null;
echo json_encode($data);
@ -118,6 +120,8 @@ elseif (!empty($_GET['id']) && ctype_alnum($_GET['id'])) {
$data['score'] = $mailc['score'];
// Get rspamd symbols
$data['symbols'] = json_decode($mailc['symbols']);
// Get fuzzy hashes
$data['fuzzy_hashes'] = json_decode($mailc['fuzzy_hashes']);
// Get text/plain content
$data['text_plain'] = $mail_parser->getMessageBody('text');
// Get html content and convert to text

View File

@ -3,7 +3,7 @@ function init_db_schema() {
try {
global $pdo;
$db_version = "26092020_2000";
$db_version = "24102020_0900";
$stmt = $pdo->query("SHOW TABLES LIKE 'versions'");
$num_results = count($stmt->fetchAll(PDO::FETCH_ASSOC));
@ -260,6 +260,7 @@ function init_db_schema() {
"ip" => "VARCHAR(50)",
"action" => "CHAR(20) NOT NULL DEFAULT 'unknown'",
"symbols" => "JSON",
"fuzzy_hashes" => "JSON",
"sender" => "VARCHAR(255) NOT NULL DEFAULT 'unknown'",
"rcpt" => "VARCHAR(255)",
"msg" => "LONGTEXT",

View File

@ -18,6 +18,14 @@ jQuery(function($){
$('#qid_detail_efrom').text(data.env_from);
$('#qid_detail_score').text(data.score);
$('#qid_detail_symbols').html('');
$('#qid_detail_fuzzy').html('');
if (data.fuzzy_hashes !== null) {
$.each(data.fuzzy_hashes, function (index, value) {
$('#qid_detail_fuzzy').append('<p style="font-family:monospace">' + value + '</p>');
});
} else {
$('#qid_detail_fuzzy').append('-');
}
if (typeof data.symbols !== 'undefined') {
data.symbols.sort(function (a, b) {
if (a.score === 0) return 1

View File

@ -148,6 +148,7 @@ jQuery(function($){
$('#qid_detail_efrom').text(data.env_from);
$('#qid_detail_score').text(data.score);
$('#qid_detail_symbols').html('');
$('#qid_detail_fuzzy').html('');
if (typeof data.symbols !== 'undefined') {
data.symbols.sort(function (a, b) {
if (a.score === 0) return 1
@ -169,7 +170,13 @@ jQuery(function($){
});
$('[data-toggle="tooltip"]').tooltip()
}
if (data.fuzzy_hashes !== null) {
$.each(data.fuzzy_hashes, function (index, value) {
$('#qid_detail_fuzzy').append('<p style="font-family:monospace">' + value + '</p>');
});
} else {
$('#qid_detail_fuzzy').append('-');
}
$('#qid_detail_recipients').html('');
if (typeof data.recipients !== 'undefined') {
$.each(data.recipients, function(index, value) {

View File

@ -26,6 +26,10 @@ if (!isset($_SESSION['mailcow_cc_role'])) {
<label for="qid_detail_recipients"><h4><?=$lang['quarantine']['recipients'];?>:</h4></label>
<p id="qid_detail_recipients"></p>
</div>
<div class="form-group">
<label for="qid_detail_fuzzy"><h4>Fuzzy Hashes:</h4></label>
<p id="qid_detail_fuzzy"></p>
</div>
<div class="form-group">
<label for="qid_detail_hfrom"><h4><?=$lang['quarantine']['sender_header'];?>:</h4></label>
<p><span class="mail-address-item" id="qid_detail_hfrom"></span></p>

View File

@ -56,6 +56,10 @@ elseif (in_array($_GET['action'], array('release', 'delete'))) {
<label for="qid_detail_recipients"><h4><?=$lang['quarantine']['recipients'];?>:</h4></label>
<p id="qid_detail_recipients"></p>
</div>
<div class="form-group">
<label for="qid_detail_fuzzy"><h4>Fuzzy Hashes:</h4></label>
<p id="qid_detail_fuzzy"></p>
</div>
<form method="post" autofill="off">
<div class="form-group">
<button type="submit" class="btn btn-success" name="quick_release" value="<?=$_GET['hash'];?>"><?= $lang['tfa']['confirm']; ?></button>