From: moisseev Date: Fri, 26 May 2023 13:12:23 +0000 (+0300) Subject: [WebUI] Add ability to compute fuzzy hashes X-Git-Tag: 3.6~99^2 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=aed812a7388be8fb9217e4c75a19d12f0e27c324;p=rspamd.git [WebUI] Add ability to compute fuzzy hashes from sample message source --- diff --git a/interface/index.html b/interface/index.html index 2fad32b2f..ca991a8d2 100644 --- a/interface/index.html +++ b/interface/index.html @@ -427,11 +427,18 @@ - + +
diff --git a/interface/js/app/upload.js b/interface/js/app/upload.js index f9f6c53c6..1145db785 100644 --- a/interface/js/app/upload.js +++ b/interface/js/app/upload.js @@ -139,8 +139,13 @@ define(["jquery"], }]; } + function get_server(rspamd) { + var checked_server = rspamd.getSelector("selSrv"); + return (checked_server === "All SERVERS") ? "local" : checked_server; + } + // @upload text - function scanText(rspamd, tables, data, server, headers) { + function scanText(rspamd, tables, data, headers) { rspamd.query("checkv2", { data: data, params: { @@ -195,7 +200,39 @@ define(["jquery"], rspamd.alertMessage("alert-error", "Cannot tokenize message: no text data"); } }, - server: server + server: get_server(rspamd) + }); + } + + function getFuzzyHashes(rspamd, data) { + function fillHashTable(rules) { + $("#hashTable tbody").empty(); + for (const [rule, hashes] of Object.entries(rules)) { + hashes.forEach(function (hash, i) { + $("#hashTable tbody").append("" + + (i === 0 ? '' + rule + "" : "") + + "" + hash + ""); + }); + } + $("#hash-card").slideDown(); + } + + rspamd.query("plugins/fuzzy/hashes?flag=" + $("#fuzzy-flag").val(), { + data: data, + params: { + processData: false, + }, + method: "POST", + success: function (neighbours_status) { + var json = neighbours_status[0].data; + if (json.success) { + rspamd.alertMessage("alert-success", "Message successfully processed"); + fillHashTable(json.hashes); + } else { + rspamd.alertMessage("alert-error", "Unexpected error processing message"); + } + }, + server: get_server(rspamd) }); } @@ -230,22 +267,26 @@ define(["jquery"], $("html, body").animate({scrollTop:0}, 1000); return false; }); - // @init upload + + $(".card-close-btn").on("click", function () { + $(this).closest(".card").slideUp(); + }); + $("[data-upload]").on("click", function () { var source = $(this).data("upload"); var data = $("#scanMsgSource").val(); var headers = {}; if ($.trim(data).length > 0) { if (source === "scan") { - var checked_server = rspamd.getSelector("selSrv"); - var server = (checked_server === "All SERVERS") ? "local" : checked_server; headers = ["IP", "User", "From", "Rcpt", "Helo", "Hostname"].reduce(function (o, header) { var value = $("#scan-opt-" + header.toLowerCase()).val(); if (value !== "") o[header] = value; return o; }, {}); if ($("#scan-opt-pass-all").prop("checked")) headers.Pass = "all"; - scanText(rspamd, tables, data, server, headers); + scanText(rspamd, tables, data, headers); + } else if (source === "compute-fuzzy") { + getFuzzyHashes(rspamd, data); } else { if (source === "fuzzy") { headers = { @@ -262,6 +303,5 @@ define(["jquery"], }); }; - return ui; });