commit 6db3a64: [WebUI] Add scan options

moisseev moiseev at mezonplus.ru
Sun Jan 2 23:07:04 UTC 2022


Author: moisseev
Date: 2022-01-02 11:05:58 +0300
URL: https://github.com/rspamd/rspamd/commit/6db3a6437b1ddd6a3506ed363ef58a43e90389f6 (refs/pull/4030/head)

[WebUI] Add scan options
which allow to set HTTP headers for scan request

---
 interface/index.html       | 39 ++++++++++++++++++++++++++++++++++++++-
 interface/js/app/upload.js | 30 +++++++++++++++++++-----------
 2 files changed, 57 insertions(+), 12 deletions(-)

diff --git a/interface/index.html b/interface/index.html
index 2a5e181ae..0fbcbf872 100644
--- a/interface/index.html
+++ b/interface/index.html
@@ -352,12 +352,49 @@
 									<label for="scanMsgSource">Message source:</label>
 									<textarea class="form-control" id="scanMsgSource" rows="10" placeholder="Paste raw message source"></textarea>
 								</div>
+								<div class="collapse row mr-0 mt-3" id="scanOptions">
+									<div class="col-lg-6">
+										<div class="form-group row text-nowrap" title="Emulate IP address from which this message was received">
+											<label for="scan-opt-ip" class="col-form-label col-sm-2">IP:</label>
+											<input name="scan-opt-ip" id="scan-opt-ip" class="form-control col-sm-10" type="text"/>
+										</div>
+										<div class="form-group row text-nowrap" title="Emulate username of the authenticated SMTP client">
+											<label for="scan-opt-user" class="col-form-label col-sm-2">User:</label>
+											<input name="scan-opt-user" id="scan-opt-user" class="form-control col-sm-10" type="text"/>
+										</div>
+										<div class="form-group row text-nowrap" title="Emulate SMTP 'MAIL FROM' command data">
+											<label for="scan-opt-from" class="col-form-label col-sm-2">From:</label>
+											<input name="scan-opt-from" id="scan-opt-from" class="form-control col-sm-10" type="text"/>
+										</div>
+									</div>
+									<div class="col-lg-6">
+										<div class="form-group row text-nowrap" title="Emulate SMTP 'RCPT TO' command data">
+											<label for="scan-opt-rcpt" class="col-form-label col-sm-2">Rcpt:</label>
+											<input name="scan-opt-rcpt" id="scan-opt-rcpt" class="form-control col-sm-10" type="text"/>
+										</div>
+										<div class="form-group row text-nowrap" title="Imitate SMTP 'HELO' passing from the MTA">
+											<label for="scan-opt-helo" class="col-form-label col-sm-2">Helo:</label>
+											<input name="scan-opt-helo" id="scan-opt-helo" class="form-control col-sm-10" type="text"/>
+										</div>
+										<div class="form-group row text-nowrap" title="Imitate resolved hostname passing from the MTA">
+											<label for="scan-opt-hostname" class="col-form-label col-sm-2">Hostname:</label>
+											<input name="scan-opt-hostname" id="scan-opt-hostname" class="form-control col-sm-10" type="text"/>
+										</div>
+										<div class="form-check row text-nowrap pl-0" title="Pass all filters">
+											<label for="scan-opt-pass-all" class="form-check-label col-sm-2">Pass: all</label>
+											<input name="scan-opt-pass-all" id="scan-opt-pass-all" class="form-check-input-reverse" type="checkbox"/>
+										</div>
+									</div>
+								</div>
 							</form>
 						</div>
 					</div>
 					<div class="card-footer">
 						<button type="submit" class="btn btn-primary" data-upload="scan"><i class="fas fa-search"></i> Scan message</button>
-						<button class="btn btn-secondary float-right" id="scanClean"><i class="fas fa-trash-alt"></i> Clean form</button>
+						<div class="form-inline float-right">
+							<button class="btn btn-secondary d-inline-block" id="scanOptionsToggle" data-toggle="collapse" data-target="#scanOptions"><i class="fas fa-bars"></i> Options</button>
+							<button class="btn btn-secondary ml-2" id="scanClean"><i class="fas fa-trash-alt"></i> Clean form</button>
+						</div>
 					</div>
 				</div>
 				<div class="card ro-hide" style="display: none;">
diff --git a/interface/js/app/upload.js b/interface/js/app/upload.js
index 39e85640d..3e95c2171 100644
--- a/interface/js/app/upload.js
+++ b/interface/js/app/upload.js
@@ -127,13 +127,14 @@ define(["jquery"],
         }
 
         // @upload text
-        function scanText(rspamd, tables, data, server) {
+        function scanText(rspamd, tables, data, server, headers) {
             rspamd.query("checkv2", {
                 data: data,
                 params: {
                     processData: false,
                 },
                 method: "POST",
+                headers: headers,
                 success: function (neighbours_status) {
                     function scrollTop(rows_total) {
                         // Is there a way to get an event when all rows are loaded?
@@ -199,7 +200,7 @@ define(["jquery"],
             });
 
             function enable_disable_scan_btn() {
-                $("#scan button").prop("disabled", ($.trim($("textarea").val()).length === 0));
+                $("#scan button:not(#scanOptionsToggle)").prop("disabled", ($.trim($("textarea").val()).length === 0));
             }
             enable_disable_scan_btn();
             $("textarea").on("input", function () {
@@ -207,8 +208,8 @@ define(["jquery"],
             });
 
             $("#scanClean").on("click", function () {
-                $("#scan button").attr("disabled", true);
-                $("#scanMsgSource").val("");
+                $("#scan button:not(#scanOptionsToggle)").attr("disabled", true);
+                $("#scanForm")[0].reset();
                 $("#scanResult").hide();
                 $("#scanOutput tbody").remove();
                 $("html, body").animate({scrollTop:0}, 1000);
@@ -218,18 +219,25 @@ define(["jquery"],
             $("[data-upload]").on("click", function () {
                 var source = $(this).data("upload");
                 var data = $("#scanMsgSource").val();
-                var headers = (source === "fuzzy")
-                    ? {
-                        flag: $("#fuzzyFlagText").val(),
-                        weight: $("#fuzzyWeightText").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;
-                        scanText(rspamd, tables, data, 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);
                     } else {
+                        if (source === "fuzzy") {
+                            headers = {
+                                flag: $("#fuzzyFlagText").val(),
+                                weight: $("#fuzzyWeightText").val()
+                            };
+                        }
                         uploadText(rspamd, data, source, headers);
                     }
                 } else {


More information about the Commits mailing list