]> source.dussan.org Git - rspamd.git/commitdiff
[WebUI] Fix history clustering
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Sat, 25 Mar 2017 14:01:29 +0000 (14:01 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Sat, 25 Mar 2017 14:01:29 +0000 (14:01 +0000)
interface/js/app/graph.js
interface/js/app/history.js
interface/js/app/rspamd.js

index 5fff7ed818d00115d4a26a8de151dbc2651a5b0f..a43cf2b643da94aeed62d81533e2a6a535a19724 100644 (file)
@@ -200,7 +200,7 @@ function($, D3Evolution, unused) {
             rspamd.queryNeighbours("graph", function (req_data) {
                 var neighbours_data = req_data
                     .filter(function (d) { return d.status }) // filter out unavailable neighbours
-                    .map(function (d){ return d.data; })
+                    .map(function (d){ return d.data; });
 
                 if (neighbours_data.length > 1) {
                     neighbours_data.reduce(function (res, curr) {
index a72d0ca36c063c073828113e3f0d2452f714b3bb..f0e053b20336a3acf7dd5cc2f6197d1db75b6fd7 100644 (file)
@@ -52,7 +52,7 @@ function($, _, Humanize) {
 
         item.score = {
             "options": {
-                "sortValue": item.score,
+                "sortValue": item.score
             },
             "value": score_content
         };
@@ -87,17 +87,17 @@ function($, _, Humanize) {
             item.time = {
                 "value": unix_time_format(item.unix_time),
                 "options": {
-                    "sortValue": item.unix_time,
-                },
+                    "sortValue": item.unix_time
+                }
             };
             var scan_time = item.time_real.toFixed(3) + '/' +
                 item.time_virtual.toFixed(3);
             item.scan_time = {
                 "options": {
-                    "sortValue": item.time_real,
+                    "sortValue": item.time_real
                 },
                 "value": scan_time
-            }
+            };
             item.id = item['message-id'];
             item.rcpt_mime = item.rcpt_mime.join(",");
             items.push(item);
@@ -110,19 +110,19 @@ function($, _, Humanize) {
         var items = [];
 
         $.each(data, function (i, item) {
-            item.time = unix_time_format(item.unix_time)
+            item.time = unix_time_format(item.unix_time);
             preprocess_item(item);
             item.scan_time = {
                 "options": {
-                    "sortValue": item.scan_time,
+                    "sortValue": item.scan_time
                 },
                 "value": item.scan_time
             };
             item.time = {
                 "value": unix_time_format(item.unix_time),
                 "options": {
-                    "sortValue": item.unix_time,
-                },
+                    "sortValue": item.unix_time
+                }
             };
 
             items.push(item)
@@ -150,7 +150,7 @@ function($, _, Humanize) {
                 "breakpoints": "xs sm md",
                 "style": {
                     "font-size": "11px",
-                    "minWidth": 150,
+                    "minWidth": 150
                 }
             }, {
                 "name": "sender_mime",
@@ -158,7 +158,7 @@ function($, _, Humanize) {
                 "breakpoints": "xs sm md",
                 "style": {
                     "font-size": "11px",
-                    "minWidth": 150,
+                    "minWidth": 150
                 }
             }, {
                 "name": "rcpt_mime",
@@ -168,7 +168,7 @@ function($, _, Humanize) {
                     "font-size": "11px",
                     "word-break": "break-all",
                     "minWidth": 150,
-                    "maxWidth": 300,
+                    "maxWidth": 300
                 }
             }, {
                 "name": "subject",
@@ -176,7 +176,7 @@ function($, _, Humanize) {
                 "breakpoints": "xs sm md",
                 "style": {
                     "font-size": "11px",
-                    "minWidth": 150,
+                    "minWidth": 150
                 }
             }, {
                 "name": "action",
@@ -365,7 +365,7 @@ function($, _, Humanize) {
         return func();
     }
 
-    interface.getHistory = function (rspamd, tables) {
+    interface.getHistory = function (rspamd, tables, neighbours, checked_server) {
         FooTable.actionFilter = FooTable.Filtering.extend({
         construct : function(instance) {
             this._super(instance);
@@ -416,163 +416,193 @@ function($, _, Humanize) {
         }
         });
 
-        $.ajax({
-            dataType: 'json',
-            url: 'history',
-            jsonp: false,
-            beforeSend: function (xhr) {
-                xhr.setRequestHeader('Password', rspamd.getPassword());
-            },
-            error: function () {
-                rspamd.alertMessage('alert-error', 'Cannot receive history');
-            },
-            success: function (data) {
-                var items = process_history_data(data);
-                ft.history = FooTable.init("#historyTable", {
-                    "columns": get_history_columns(data),
-                    "rows": items,
-                    "paging": {
-                      "enabled": true,
-                      "limit": 5,
-                      "size": 25
-                    },
-                    "filtering": {
-                      "enabled": true,
-                      "position": "left"
+        if (checked_server === "All SERVERS") {
+            rspamd.queryNeighbours("history", function (req_data) {
+                var neighbours_data = req_data
+                    .filter(function (d) { return d.status }) // filter out unavailable neighbours
+                    .map(function (d){ return d.data; });
+                if (neighbours_data.length > 0) {
+                    var data = {};
+                    data.rows = neighbours_data.map(function(e) {return e.rows;});
+                    data.version = neighbours_data[0].version;
+
+                    var items = process_history_data(data);
+                    ft.history = FooTable.init("#historyTable", {
+                        "columns": get_history_columns(data),
+                        "rows": items,
+                        "paging": {
+                            "enabled": true,
+                            "limit": 5,
+                            "size": 25
+                        },
+                        "filtering": {
+                            "enabled": true,
+                            "position": "left"
+                        },
+                        "sorting": {
+                            "enabled": true
+                        },
+                        components: {
+                            filtering: FooTable.actionFilter
+                        }
+                    });
+                }
+
+            });
+        }
+        else {
+            $.ajax({
+                dataType: 'json',
+                url: neighbours[checked_server].url + 'history',
+                jsonp: false,
+                beforeSend: function (xhr) {
+                    xhr.setRequestHeader('Password', rspamd.getPassword());
+                },
+                error: function () {
+                    rspamd.alertMessage('alert-error', 'Cannot receive history');
+                },
+                success: function (data) {
+                    var items = process_history_data(data);
+                    ft.history = FooTable.init("#historyTable", {
+                        "columns": get_history_columns(data),
+                        "rows": items,
+                        "paging": {
+                            "enabled": true,
+                            "limit": 5,
+                            "size": 25
+                        },
+                        "filtering": {
+                            "enabled": true,
+                            "position": "left"
+                        },
+                        "sorting": {
+                            "enabled": true
+                        },
+                        components: {
+                            filtering: FooTable.actionFilter
+                        }
+                    });
+                }
+            });
+        }
+        $('#updateHistory').off('click');
+        $('#updateHistory').on('click', function (e) {
+            e.preventDefault();
+            interface.getHistory(rspamd, tables);
+        });
+
+        // @reset history log
+        $('#resetHistory').off('click');
+        $('#resetHistory').on('click', function (e) {
+            e.preventDefault();
+            if (!confirm("Are you sure you want to reset history log?")) {
+                return;
+            }
+            if (ft.history) {
+                ft.history.destroy();
+                ft.history = undefined;
+            }
+            if (ft.errors) {
+                ft.errors.destroy();
+                ft.errors = undefined;
+            }
+            if (checked_server === "All SERVERS") {
+                rspamd.queryNeighbours("errors", function (data) {
+                    interface.getHistory(rspamd, tables, neighbours, checked_server);
+                    interface.getErrors(rspamd, tables, neighbours, checked_server);
+                });
+            }
+            else {
+                $.ajax({
+                    dataType: 'json',
+                    type: 'GET',
+                    jsonp: false,
+                    url: neighbours[checked_server].url + 'historyreset',
+                    beforeSend: function (xhr) {
+                        xhr.setRequestHeader('Password', rspamd.getPassword());
                     },
-                    "sorting": {
-                      "enabled": true
+                    success: function () {
+                        interface.getHistory(rspamd, tables, neighbours, checked_server);
+                        interface.getErrors(rspamd, tables, neighbours, checked_server);
                     },
-                    components: {
-                      filtering: FooTable.actionFilter
+                    error: function (data) {
+                        rspamd.alertMessage('alert-modal alert-error', data.statusText);
                     }
                 });
             }
         });
     };
 
-    interface.getErrors = function(rspamd, tables) {
-        if (rspamd.read_only) return;
-
+    function drawErrorsTable(data) {
         var items = [];
-        $.ajax({
-            dataType: 'json',
-            url: 'errors',
-            jsonp: false,
-            beforeSend: function (xhr) {
-                xhr.setRequestHeader('Password', rspamd.getPassword());
+        $.each(data, function (i, item) {
+            items.push(
+                item.ts = unix_time_format(item.ts)
+            );
+        });
+        ft.errors = FooTable.init("#errorsLog", {
+            "columns": [
+                {"sorted": true,"direction": "DESC","name":"ts","title":"Time","style":{"font-size":"11px","width":300,"maxWidth":300}},
+                {"name":"type","title":"Worker type","breakpoints":"xs sm","style":{"font-size":"11px","width":150,"maxWidth":150}},
+                {"name":"pid","title":"PID","breakpoints":"xs sm","style":{"font-size":"11px","width":110,"maxWidth":110}},
+                {"name":"module","title":"Module","style":{"font-size":"11px"}},
+                {"name":"id","title":"Internal ID","style":{"font-size":"11px"}},
+                {"name":"message","title":"Message","breakpoints":"xs sm","style":{"font-size":"11px"}},
+            ],
+            "rows": data,
+            "paging": {
+                "enabled": true,
+                "limit": 5,
+                "size": 25
             },
-            error: function () {
-                rspamd.alertMessage('alert-error', 'Cannot receive errors');
+            "filtering": {
+                "enabled": true,
+                "position": "left"
             },
-            success: function (data) {
-              $.each(data, function (i, item) {
-                items.push(
-                  item.ts = unix_time_format(item.ts)
-                );
-              });
-              ft.errors = FooTable.init("#errorsLog", {
-                "columns": [
-                  {"sorted": true,"direction": "DESC","name":"ts","title":"Time","style":{"font-size":"11px","width":300,"maxWidth":300}},
-                  {"name":"type","title":"Worker type","breakpoints":"xs sm","style":{"font-size":"11px","width":150,"maxWidth":150}},
-                  {"name":"pid","title":"PID","breakpoints":"xs sm","style":{"font-size":"11px","width":110,"maxWidth":110}},
-                  {"name":"module","title":"Module","style":{"font-size":"11px"}},
-                  {"name":"id","title":"Internal ID","style":{"font-size":"11px"}},
-                  {"name":"message","title":"Message","breakpoints":"xs sm","style":{"font-size":"11px"}},
-                ],
-                "rows": data,
-                "paging": {
-                  "enabled": true,
-                  "limit": 5,
-                  "size": 25
+            "sorting": {
+                "enabled": true
+            }
+        });
+    }
+
+    interface.getErrors = function(rspamd, tables, neighbours, checked_server) {
+        if (rspamd.read_only) return;
+
+        if (checked_server !== "All SERVERS") {
+            $.ajax({
+                dataType: 'json',
+                url: neighbours[checked_server].url + 'errors',
+                jsonp: false,
+                beforeSend: function (xhr) {
+                    xhr.setRequestHeader('Password', rspamd.getPassword());
                 },
-                "filtering": {
-                  "enabled": true,
-                  "position": "left"
+                error: function () {
+                    rspamd.alertMessage('alert-error', 'Cannot receive errors');
                 },
-                "sorting": {
-                  "enabled": true
+                success: function (data) {
+                    drawErrorsTable(data);
                 }
-              });
-            }
+            });
+        } else {
+            rspamd.queryNeighbours("errors", function (req_data) {
+                var neighbours_data = req_data
+                    .filter(function (d) {
+                        return d.status
+                    }) // filter out unavailable neighbours
+                    .map(function (d) {
+                        return d.data;
+                    });
+                drawErrorsTable([].concat.apply([], neighbours_data));
+            });
+        }
+        $('#updateErrors').off('click');
+        $('#updateErrors').on('click', function (e) {
+            e.preventDefault();
+            interface.getErrors(rspamd, tables, neighbours, checked_server);
         });
     };
 
     interface.setup = function(rspamd, tables) {
-        $('#updateHistory').on('click', function (e) {
-          e.preventDefault();
-          $.ajax({
-              dataType: 'json',
-              type: 'GET',
-              jsonp: false,
-              url: 'history',
-              beforeSend: function (xhr) {
-                  xhr.setRequestHeader('Password', rspamd.getPassword());
-              },
-              success: function (data) {
-                var items = process_history_data(data);
-                ft.history.rows.load(items);
-              },
-              error: function (data) {
-                  rspamd.alertMessage('alert-modal alert-error', data.statusText);
-              }
-          });
-        });
-        $('#updateErrors').on('click', function (e) {
-          e.preventDefault();
-          var items = [];
-          $.ajax({
-              dataType: 'json',
-              type: 'GET',
-              jsonp: false,
-              url: 'errors',
-              beforeSend: function (xhr) {
-                  xhr.setRequestHeader('Password', rspamd.getPassword());
-              },
-              success: function (data) {
-                $.each(data, function (i, item) {
-                  items.push(
-                    item.ts = unix_time_format(item.ts)
-                  );
-                });
-                ft.errors.rows.load(data);
-              },
-              error: function (data) {
-                  rspamd.alertMessage('alert-modal alert-error', data.statusText);
-              }
-          });
-        });
-        // @reset history log
-        $('#resetHistory').on('click', function (e) {
-          e.preventDefault();
-          if (!confirm("Are you sure you want to reset history log?")) {
-              return;
-          }
-          if (ft.history) {
-              ft.history.destroy();
-              ft.history = undefined;
-          }
-          if (ft.errors) {
-              ft.errors.destroy();
-              ft.errors = undefined;
-          }
-          $.ajax({
-              dataType: 'json',
-              type: 'GET',
-              jsonp: false,
-              url: 'historyreset',
-              beforeSend: function (xhr) {
-                  xhr.setRequestHeader('Password', rspamd.getPassword());
-              },
-              success: function () {
-                  interface.getHistory(rspamd, tables);
-                  interface.getErrors(rspamd, tables);
-              },
-              error: function (data) {
-                  rspamd.alertMessage('alert-modal alert-error', data.statusText);
-              }
-          });
-        });
     };
     return interface;
 });
\ No newline at end of file
index 598112e9baa9df908e1774a6589d4c633a2107d9..c19e3c9ad6bb5e67f05970679b3f5af0d5be1444 100644 (file)
@@ -111,8 +111,8 @@ define(['jquery', 'd3pie', 'visibility', 'app/stats', 'app/graph', 'app/config',
                     tab_symbols.getSymbols(interface, tables, checked_server);
                     break;
                 case "#history_nav":
-                    tab_history.getHistory(interface, tables, checked_server);
-                    tab_history.getErrors(interface, tables, checked_server);
+                    tab_history.getHistory(interface, tables, neighbours, checked_server);
+                    tab_history.getErrors(interface, tables, neighbours, checked_server);
                     break;
                 case "#disconnect":
                     disconnect();