aboutsummaryrefslogtreecommitdiffstats
path: root/interface/js/app/config.js
diff options
context:
space:
mode:
Diffstat (limited to 'interface/js/app/config.js')
-rw-r--r--interface/js/app/config.js436
1 files changed, 218 insertions, 218 deletions
diff --git a/interface/js/app/config.js b/interface/js/app/config.js
index e580b2497..cb8fb0c75 100644
--- a/interface/js/app/config.js
+++ b/interface/js/app/config.js
@@ -23,165 +23,165 @@
*/
define(["jquery"],
-function($) {
- var interface = {}
+ function($) {
+ var interface = {}
- function save_map_success(rspamd) {
- rspamd.alertMessage("alert-modal alert-success", "Map data successfully saved");
- $("#modalDialog").modal("hide");
- }
- function save_map_error(rspamd, serv, jqXHR, textStatus, errorThrown) {
- rspamd.alertMessage("alert-modal alert-error", "Save map error on " +
+ function save_map_success(rspamd) {
+ rspamd.alertMessage("alert-modal alert-success", "Map data successfully saved");
+ $("#modalDialog").modal("hide");
+ }
+ function save_map_error(rspamd, serv, jqXHR, textStatus, errorThrown) {
+ rspamd.alertMessage("alert-modal alert-error", "Save map error on " +
serv.name + ": " + errorThrown);
- }
- // @upload map from modal
- function saveMap(rspamd, action, id) {
- var data = $("#" + id).find("textarea").val();
- $.ajax({
- data: data,
- dataType: "text",
- type: "POST",
- jsonp: false,
- url: action,
- beforeSend: function (xhr) {
- xhr.setRequestHeader("Password", rspamd.getPassword());
- xhr.setRequestHeader("Map", id);
- xhr.setRequestHeader("Debug", true);
- },
- error: function (data) {
- save_map_error(rspamd, "local", null, null, data.statusText);
- },
- success: function() {save_map_success(rspamd)},
- });
- }
+ }
+ // @upload map from modal
+ function saveMap(rspamd, action, id) {
+ var data = $("#" + id).find("textarea").val();
+ $.ajax({
+ data: data,
+ dataType: "text",
+ type: "POST",
+ jsonp: false,
+ url: action,
+ beforeSend: function (xhr) {
+ xhr.setRequestHeader("Password", rspamd.getPassword());
+ xhr.setRequestHeader("Map", id);
+ xhr.setRequestHeader("Debug", true);
+ },
+ error: function (data) {
+ save_map_error(rspamd, "local", null, null, data.statusText);
+ },
+ success: function() {save_map_success(rspamd)},
+ });
+ }
- // @get maps id
- function getMaps(rspamd) {
- var items = [];
- var $listmaps = $("#listMaps")
- $listmaps.closest(".widget-box").hide();
- $.ajax({
- dataType: "json",
- url: "maps",
- jsonp: false,
- beforeSend: function (xhr) {
- xhr.setRequestHeader("Password", rspamd.getPassword());
- },
- error: function (data) {
- rspamd.alertMessage("alert-modal alert-error", data.statusText);
- },
- success: function (data) {
- $listmaps.empty();
- $("#modalBody").empty();
- $tbody = $("<tbody>");
+ // @get maps id
+ function getMaps(rspamd) {
+ var items = [];
+ var $listmaps = $("#listMaps")
+ $listmaps.closest(".widget-box").hide();
+ $.ajax({
+ dataType: "json",
+ url: "maps",
+ jsonp: false,
+ beforeSend: function (xhr) {
+ xhr.setRequestHeader("Password", rspamd.getPassword());
+ },
+ error: function (data) {
+ rspamd.alertMessage("alert-modal alert-error", data.statusText);
+ },
+ success: function (data) {
+ $listmaps.empty();
+ $("#modalBody").empty();
+ $tbody = $("<tbody>");
- $.each(data, function (i, item) {
+ $.each(data, function (i, item) {
+ if ((item.editable === false || rspamd.read_only)) {
+ var label = "<span class=\"label label-default\">Read</span>";
+ } else {
+ var label = "<span class=\"label label-default\">Read</span>&nbsp;<span class=\"label label-success\">Write</span>";
+ }
+ var $tr = $("<tr>");
+ $("<td class=\"col-md-2 maps-cell\">" + label + "</td>").appendTo($tr);
+ $span = $("<span class=\"map-link\" data-toggle=\"modal\" data-target=\"#modalDialog\">" + item.uri + "</span>").data("item",item);
+ $span.wrap("<td>").parent().appendTo($tr);
+ $("<td>" + item.description + "</td>").appendTo($tr);
+ $tr.appendTo($tbody);
+ });
+ $tbody.appendTo($listmaps);
+ $listmaps.closest(".widget-box").show();
+ }
+ });
+ }
+ // @get map by id
+ function getMapById(rspamd, item) {
+ return $.ajax({
+ dataType: "text",
+ url: "getmap",
+ jsonp: false,
+ beforeSend: function (xhr) {
+ xhr.setRequestHeader("Password", rspamd.getPassword());
+ xhr.setRequestHeader("Map", item.map);
+ },
+ error: function () {
+ rspamd.alertMessage("alert-error", "Cannot receive maps data");
+ },
+ success: function (text) {
+ var disabled = "";
if ((item.editable === false || rspamd.read_only)) {
- var label = "<span class=\"label label-default\">Read</span>";
- } else {
- var label = "<span class=\"label label-default\">Read</span>&nbsp;<span class=\"label label-success\">Write</span>";
+ disabled = "disabled=\"disabled\"";
}
- var $tr = $("<tr>");
- $("<td class=\"col-md-2 maps-cell\">" + label + "</td>").appendTo($tr);
- $span = $("<span class=\"map-link\" data-toggle=\"modal\" data-target=\"#modalDialog\">" + item.uri + "</span>").data("item",item);
- $span.wrap("<td>").parent().appendTo($tr);
- $("<td>" + item.description + "</td>").appendTo($tr);
- $tr.appendTo($tbody);
- });
- $tbody.appendTo($listmaps);
- $listmaps.closest(".widget-box").show();
- }
- });
- }
- // @get map by id
- function getMapById(rspamd, item) {
- return $.ajax({
- dataType: "text",
- url: "getmap",
- jsonp: false,
- beforeSend: function (xhr) {
- xhr.setRequestHeader("Password", rspamd.getPassword());
- xhr.setRequestHeader("Map", item.map);
- },
- error: function () {
- rspamd.alertMessage("alert-error", "Cannot receive maps data");
- },
- success: function (text) {
- var disabled = "";
- if ((item.editable === false || rspamd.read_only)) {
- disabled = "disabled=\"disabled\"";
- }
- $("#"+item.map).remove();
- $("<form class=\"form-horizontal form-map\" method=\"post\" action=\"savemap\" data-type=\"map\" id=\"" +
+ $("#"+item.map).remove();
+ $("<form class=\"form-horizontal form-map\" method=\"post\" action=\"savemap\" data-type=\"map\" id=\"" +
item.map + "\" style=\"display:none\">" +
"<textarea class=\"list-textarea\"" + disabled + ">" + text +
"</textarea>" +
"</form").appendTo("#modalBody");
- }
- });
- }
+ }
+ });
+ }
- function loadActionsFromForm() {
- var values = [];
- var inputs = $("#actionsForm :input[data-id=\"action\"]");
- // Rspamd order: [spam, rewrite_subject, probable_spam, greylist]
- values[0] = parseFloat(inputs[3].value);
- values[1] = parseFloat(inputs[2].value);
- values[2] = parseFloat(inputs[1].value);
- values[3] = parseFloat(inputs[0].value);
+ function loadActionsFromForm() {
+ var values = [];
+ var inputs = $("#actionsForm :input[data-id=\"action\"]");
+ // Rspamd order: [spam, rewrite_subject, probable_spam, greylist]
+ values[0] = parseFloat(inputs[3].value);
+ values[1] = parseFloat(inputs[2].value);
+ values[2] = parseFloat(inputs[1].value);
+ values[3] = parseFloat(inputs[0].value);
- return JSON.stringify(values);
- }
+ return JSON.stringify(values);
+ }
- function getActions(rspamd) {
- $.ajax({
- dataType: "json",
- type: "GET",
- url: "actions",
- jsonp: false,
- beforeSend: function (xhr) {
- xhr.setRequestHeader("Password", rspamd.getPassword());
- },
- success: function (data) {
+ function getActions(rspamd) {
+ $.ajax({
+ dataType: "json",
+ type: "GET",
+ url: "actions",
+ jsonp: false,
+ beforeSend: function (xhr) {
+ xhr.setRequestHeader("Password", rspamd.getPassword());
+ },
+ success: function (data) {
// Order of sliders greylist -> probable spam -> rewrite subject -> spam
- $("#actionsBody").empty();
- $("#actionsForm").empty();
- var items = [];
- $.each(data, function (i, item) {
- var idx = -1;
- var label;
- if (item.action === "add header") {
- label = "Probably Spam";
- idx = 1;
- } else if (item.action === "greylist") {
- label = "Greylist";
- idx = 0;
- } else if (item.action === "rewrite subject") {
- label = "Rewrite subject";
- idx = 2;
- } else if (item.action === "reject") {
- label = "Spam";
- idx = 3;
- }
- if (idx >= 0) {
- items.push({
- idx: idx,
- html: "<div class=\"form-group\">" +
+ $("#actionsBody").empty();
+ $("#actionsForm").empty();
+ var items = [];
+ $.each(data, function (i, item) {
+ var idx = -1;
+ var label;
+ if (item.action === "add header") {
+ label = "Probably Spam";
+ idx = 1;
+ } else if (item.action === "greylist") {
+ label = "Greylist";
+ idx = 0;
+ } else if (item.action === "rewrite subject") {
+ label = "Rewrite subject";
+ idx = 2;
+ } else if (item.action === "reject") {
+ label = "Spam";
+ idx = 3;
+ }
+ if (idx >= 0) {
+ items.push({
+ idx: idx,
+ html: "<div class=\"form-group\">" +
"<label class=\"control-label col-sm-2\">" + label + "</label>" +
"<div class=\"controls slider-controls col-sm-10\">" +
"<input class=\"action-scores form-control\" data-id=\"action\" type=\"number\" value=\"" + item.value + "\">" +
"</div>" +
"</div>"
- });
- }
- });
+ });
+ }
+ });
- items.sort(function (a, b) {
- return a.idx - b.idx;
- });
+ items.sort(function (a, b) {
+ return a.idx - b.idx;
+ });
- $("#actionsBody").html("<form id=\"actionsForm\"><fieldset id=\"actionsFormField\">" +
+ $("#actionsBody").html("<form id=\"actionsForm\"><fieldset id=\"actionsFormField\">" +
items.map(function (e) {
return e.html;
}).join("") +
@@ -190,95 +190,95 @@ function($) {
"<button class=\"btn btn-primary\" type=\"button\" id=\"saveActionsBtn\">Save actions</button>" +
"<button class=\"btn btn-primary\" type=\"button\" id=\"saveActionsClusterBtn\">Save cluster</button>" +
"</div></div></fieldset></form>");
- if (rspamd.read_only) {
- $("#saveActionsClusterBtn").attr("disabled", true);
- $("#saveActionsBtn").attr("disabled", true);
- $("#actionsFormField").attr("disabled", true);
- }
+ if (rspamd.read_only) {
+ $("#saveActionsClusterBtn").attr("disabled", true);
+ $("#saveActionsBtn").attr("disabled", true);
+ $("#actionsFormField").attr("disabled", true);
+ }
- function saveActions(callback) {
- var elts = loadActionsFromForm();
- // String to array for comparison
- var eltsArray = JSON.parse(loadActionsFromForm());
- if (eltsArray[0] < 0) {
- rspamd.alertMessage("alert-modal alert-error", "Spam can not be negative");
- } else if (eltsArray[1] < 0) {
- rspamd.alertMessage("alert-modal alert-error", "Rewrite subject can not be negative");
- } else if (eltsArray[2] < 0) {
- rspamd.alertMessage("alert-modal alert-error", "Probable spam can not be negative");
- } else if (eltsArray[3] < 0) {
- rspamd.alertMessage("alert-modal alert-error", "Greylist can not be negative");
- } else if (
- (eltsArray[2] === null || eltsArray[3] < eltsArray[2]) &&
+ function saveActions(callback) {
+ var elts = loadActionsFromForm();
+ // String to array for comparison
+ var eltsArray = JSON.parse(loadActionsFromForm());
+ if (eltsArray[0] < 0) {
+ rspamd.alertMessage("alert-modal alert-error", "Spam can not be negative");
+ } else if (eltsArray[1] < 0) {
+ rspamd.alertMessage("alert-modal alert-error", "Rewrite subject can not be negative");
+ } else if (eltsArray[2] < 0) {
+ rspamd.alertMessage("alert-modal alert-error", "Probable spam can not be negative");
+ } else if (eltsArray[3] < 0) {
+ rspamd.alertMessage("alert-modal alert-error", "Greylist can not be negative");
+ } else if (
+ (eltsArray[2] === null || eltsArray[3] < eltsArray[2]) &&
(eltsArray[1] === null || eltsArray[2] < eltsArray[1]) &&
(eltsArray[0] === null || eltsArray[1] < eltsArray[0])
- ) {
- callback("saveactions", null, null, "POST", {}, {
- data: elts,
- dataType: "json"
- });
- } else {
- rspamd.alertMessage("alert-modal alert-error", "Incorrect order of metric actions threshold");
+ ) {
+ callback("saveactions", null, null, "POST", {}, {
+ data: elts,
+ dataType: "json"
+ });
+ } else {
+ rspamd.alertMessage("alert-modal alert-error", "Incorrect order of metric actions threshold");
+ }
}
- }
- $("#saveActionsBtn").on("click", function() {
- saveActions(rspamd.queryLocal);
- });
- $("#saveActionsClusterBtn").on("click", function() {
- saveActions(rspamd.queryNeighbours);
- });
- },
- });
- }
+ $("#saveActionsBtn").on("click", function() {
+ saveActions(rspamd.queryLocal);
+ });
+ $("#saveActionsClusterBtn").on("click", function() {
+ saveActions(rspamd.queryNeighbours);
+ });
+ },
+ });
+ }
- // @upload edited actions
- interface.setup = function(rspamd) {
+ // @upload edited actions
+ interface.setup = function(rspamd) {
// Modal form for maps
- $(document).on("click", "[data-toggle=\"modal\"]", function () {
- var item = $(this).data("item");
- getMapById(rspamd, item).done(function() {
- $("#modalTitle").html(item.uri);
- $("#" + item.map).first().show();
- $("#modalDialog .progress").hide();
- $("#modalDialog").modal(show = true, backdrop = true, keyboard = show);
- if (item.editable === false) {
- $("#modalSave").hide();
- $("#modalSaveAll").hide();
- } else {
- $("#modalSave").show();
- $("#modalSaveAll").show();
- }
+ $(document).on("click", "[data-toggle=\"modal\"]", function () {
+ var item = $(this).data("item");
+ getMapById(rspamd, item).done(function() {
+ $("#modalTitle").html(item.uri);
+ $("#" + item.map).first().show();
+ $("#modalDialog .progress").hide();
+ $("#modalDialog").modal(show = true, backdrop = true, keyboard = show);
+ if (item.editable === false) {
+ $("#modalSave").hide();
+ $("#modalSaveAll").hide();
+ } else {
+ $("#modalSave").show();
+ $("#modalSaveAll").show();
+ }
+ });
+ return false;
});
- return false;
- });
- // close modal without saving
- $("[data-dismiss=\"modal\"]").on("click", function () {
- $("#modalBody form").hide();
- });
- // @save forms from modal
- $("#modalSave").on("click", function () {
- var form = $("#modalBody").children().filter(":visible");
- var action = $(form).attr("action");
- var id = $(form).attr("id");
- saveMap(rspamd, action, id);
- });
- $("#modalSaveAll").on("click", function () {
- var form = $("#modalBody").children().filter(":visible");
- var action = $(form).attr("action");
- var id = $(form).attr("id");
- var data = $("#" + id).find("textarea").val();
- rspamd.queryNeighbours(action, save_map_success, save_map_error, "POST", {
- "Map": id,
- }, {
- data: data,
- dataType: "text",
+ // close modal without saving
+ $("[data-dismiss=\"modal\"]").on("click", function () {
+ $("#modalBody form").hide();
+ });
+ // @save forms from modal
+ $("#modalSave").on("click", function () {
+ var form = $("#modalBody").children().filter(":visible");
+ var action = $(form).attr("action");
+ var id = $(form).attr("id");
+ saveMap(rspamd, action, id);
+ });
+ $("#modalSaveAll").on("click", function () {
+ var form = $("#modalBody").children().filter(":visible");
+ var action = $(form).attr("action");
+ var id = $(form).attr("id");
+ var data = $("#" + id).find("textarea").val();
+ rspamd.queryNeighbours(action, save_map_success, save_map_error, "POST", {
+ "Map": id,
+ }, {
+ data: data,
+ dataType: "text",
+ });
});
- });
- }
+ }
- interface.getActions = getActions;
- interface.getMaps = getMaps;
+ interface.getActions = getActions;
+ interface.getMaps = getMaps;
- return interface;
-});
+ return interface;
+ });