]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[WebUI] Initial clusters support
authorAnna Stakhova <anna@rspamd.com>
Sat, 7 Jan 2017 23:57:08 +0000 (23:57 +0000)
committerAnna Stakhova <anna@rspamd.com>
Sat, 7 Jan 2017 23:57:08 +0000 (23:57 +0000)
interface/css/rspamd.css
interface/index.html
interface/js/rspamd.js

index ca0ca815e5e93407ea895c1c79540d752c3453d4..9ec12f2b7fad4e9cc7bbcd2f14bfbe9c1a17c1e6 100644 (file)
@@ -573,3 +573,39 @@ td.maps-cell {
     cursor: inherit;
     display: block;
 }
+
+input.radio {
+       margin: 0 !important;
+       height: initial;
+       -webkit-box-shadow: none !important;
+  box-shadow: none !important;
+}
+
+.glyphicon-ok-circle {
+       color:#468847;
+}
+
+.glyphicon-remove-circle {
+       color:#b94a48;
+}
+
+#clusterTable .col1 {
+       width: 40px;
+}
+
+#clusterTable .col4 {
+       width: 50px;
+       text-align: center;
+}
+
+#clusterTable .col5 {
+       width: 100px;
+}
+
+#clusterTable .col2 {
+       width: 30%;
+}
+
+#clusterTable .col3 {
+       width: 50%;
+}
index 5b0dda706d222fe524c5db662e4134c99c92b8ca..c303286eee4fa6ba7868fa7acf69d4f1cf426f55 100644 (file)
                                                </div>
                                        </div>
                                </div>
+                               <div class="widget-box">
+                                               <!--iv class="widget-title">
+                                                       <span class="icon"><i class="glyphicon glyphicon-tasks"></i></span>
+                                                       <h5>Servers</h5>
+                                               </div-->
+                                               <div class="widget-content nopadding">
+                                                               <table class="table table-log table-hover" id="clusterTable">
+                                                                               <thead>
+                                                                                               <th class="col1" title="Radio"></th>
+                                                                                               <th class="col2" title="SName">Server name</th>
+                                                                                               <th class="col3" title="SHost">Host</th>
+                                                                                               <th class="col4" title="SStatus">Status</th>
+                                                                                               <th class="col5" title="SId">Configuration ID</th>
+                                                                               </thead>
+                                                                               <tbody>
+                                                                                               <tr>
+                                                                                                               <td class="col1" title="Radio"><input type="radio" id ="bu" class="form-control radio" name="clusterName" value="" checked></td>
+                                                                                                               <td class="col2" title="SName">ALL SERVERS</td>
+                                                                                                               <td class="col3" title="SHost"></td>
+                                                                                                               <td class="col4" title="SStatus"></td>
+                                                                                                               <td class="col5" title="SId">?????????????</td>
+                                                                                         </tr>
+                                                                                               <tr>
+                                                                                                               <td class="col1" title="Radio"><input type="radio" class="form-control radio" name="clusterName" value=""></td>
+                                                                                                               <td class="col2" title="SName">Server1</td>
+                                                                                                               <td class="col3" title="SHost">localhost:8080</td>
+                                                                                                               <td class="col4" title="SStatus"><span class="icon"><i class="glyphicon glyphicon-remove-circle"></i></span></td>
+                                                                                                               <td class="col5" title="SId">?????????????</td>
+                                                                                               </tr>
+                                                                                               <tr>
+                                                                                                               <td class="col1" title="Radio"><input type="radio" class="form-control radio" name="clusterName" value=""></td>
+                                                                                                               <td class="col2" title="SName">Server2</td>
+                                                                                                               <td class="col3" title="SHost">localhost:8080</td>
+                                                                                                               <td class="col4" title="SStatus"><span class="icon"><i class="glyphicon glyphicon-ok-circle"></i></span></td>
+                                                                                                               <td class="col5" title="SId">?????????????</td>
+                                                                                               </tr>
+                                                                               </tbody>
+                                                               </table>
+                                               </div>
+                               </div>
                        </div>
 
                        <div class="tab-pane" id="throughput">
index a1d79af5ea1fc870cf36d43097f24ed641b78258..420ca93a7655110e59ea33121f2859e83ac3cf38 100644 (file)
@@ -32,6 +32,8 @@
         var graph;
         var symbols;
         var read_only = false;
+        var neighbours = []; //list of clusters
+        var checked_server = "All SERVERS";
 
         var timer_id = [];
         var selected = []; // Keep graph selectors state
         }
         // @return password
         function getPassword() {
-            if (sessionState()) {
-                if (!supportsSessionStorage()) {
-                    return password = $.cookie('rspamdpasswd');
-                } else {
-                    return password = sessionStorage.getItem('Password');
-                }
-            }
-        }
-        // @return session state
-        function sessionState() {
-            if ((supportsSessionStorage() && (sessionStorage.getItem('Password') !== null)) ||
-                (!supportsSessionStorage() && ($.cookie('rspamdsession')) !== null)) {
-                return true;
-            } else {
-                return false;
-            }
+          return password = sessionStorage.getItem('Password');
         }
 
         // @detect session storate
         supportsSessionStorage();
         // @save credentials
-        function saveCredentials(data, password) {
-            if (!supportsSessionStorage()) {
-                $.cookie('rspamdsession', data, {
-                    expires: 1
-                }, {
-                    path: '/'
-                });
-                $.cookie('rspamdpasswd', password, {
-                    expires: 1
-                }, {
-                    path: '/'
-                });
-            } else {
-                sessionStorage.setItem('Password', password);
-                sessionStorage.setItem('Credentials', JSON.stringify(data));
-            }
+        function saveCredentials(password) {
+          sessionStorage.setItem('Password', password);
         }
         // @update credentials
         function saveActions(data) {
         }
         // @clean credentials
         function cleanCredentials() {
-            if (!supportsSessionStorage()) {
-                $.removeCookie('rspamdlogged');
-                $.removeCookie('rspamdsession');
-                $.removeCookie('rspamdpasswd');
-            } else {
-                sessionStorage.clear();
-            }
+            sessionStorage.clear();
             $('#statWidgets').empty();
             $('#listMaps').empty();
             $('#modalBody').empty();
         }
 
         function isLogged() {
-            if (!supportsSessionStorage()) {
-                if ($.cookie('rspamdpasswd') != null) {
-                    return true;
-                }
-            } else {
-                if (sessionStorage.getItem('Password') != null) {
-                    return true;
-                }
+            if (sessionStorage.getItem('Password') != null) {
+                return true;
             }
             return false;
         }
                 });
             });
         }
+
         // @ ms to date
         function msToTime(seconds) {
              years = seconds / 31536000 >> 0 // 3600*24*365
              }
              return out;
         }
+
+        function displayStatWidgets() {
+          var widgets = $('#statWidgets');
+          $(widgets).empty().hide();
+          var servers = JSON.parse(sessionStorage.getItem('Credentials'));
+
+          var data = servers[checked_server].data;
+          var stat_w = [];
+
+          $.each(data, function (i, item) {
+              var widget = '';
+              if (i == 'auth') {}
+              else if (i == 'error') {}
+              else if (i == 'version') {
+                  widget = '<div class="left"><strong>' + item + '</strong>' +
+                      i + '</div>';
+                  $(widget).appendTo(widgets);
+              } else if (i == 'uptime') {
+                  widget = '<div class="right"><strong>' + msToTime(item) +
+                      '</strong>' + i + '</div>';
+                  $(widget).appendTo(widgets);
+              } else {
+                  widget = '<li class="stat-box"><div class="widget"><strong>' +
+                      Humanize.compactInteger(item) + '</strong>' + i + '</div></li>';
+                  if (i == 'scanned') {
+                      stat_w[0] = widget;
+                  } else if (i == 'clean') {
+                      stat_w[1] = widget;
+                  } else if (i == 'greylist') {
+                      stat_w[2] = widget;
+                  } else if (i == 'probable') {
+                      stat_w[3] = widget;
+                  } else if (i == 'reject') {
+                      stat_w[4] = widget;
+                  } else if (i == 'learned') {
+                      stat_w[5] = widget;
+                  }
+              }
+          });
+          $.each(stat_w, function (i, item) {
+              $(item).appendTo(widgets);
+          });
+          $('#statWidgets .left,#statWidgets .right').wrapAll('<li class="stat-box pull-right"><div class="widget"></div></li>');
+          $('#statWidgets').find('li.pull-right').appendTo('#statWidgets');
+
+          $("#clusterTable tbody").empty();
+          $.each(servers, function (key, val) {
+              var glyph_status;
+              if (val.status) {glyph_status = "glyphicon glyphicon-ok-circle"} else {glyph_status = "glyphicon glyphicon-remove-circle"}
+              if (checked_server == key) {
+                $('#clusterTable tbody').append('<tr>' +
+                    '<td class="col1" title="Radio"><input type="radio" class="form-control radio" name="clusterName" value="' + key + '" checked></td>' +
+                    '<td class="col2" title="SNAme">' + key + '</td>' +
+                    '<td class="col3" title="SHost">' + val.host + '</td>' +
+                    '<td class="col4" title="SStatus"><span class="icon"><i class="' + glyph_status + '"></i></span></td>' +
+                    '<td class="col5" title="SId">' + val.data.config_id + '</td></tr>');
+              } else {
+                $('#clusterTable tbody').append('<tr>' +
+                    '<td class="col1" title="Radio"><input type="radio" class="form-control radio" name="clusterName" value="' + key + '"></td>' +
+                    '<td class="col2" title="SNAme">' + key + '</td>' +
+                    '<td class="col3" title="SHost">' + val.host + '</td>' +
+                    '<td class="col4" title="SStatus"><span class="icon"><i class="' + glyph_status + '"></i></span></td>' +
+                    '<td class="col5" title="SId">' + val.data.config_id + '</td></tr>');
+
+              }
+          });
+          $(widgets).show();
+        }
         // @show widgets
         function statWidgets() {
             $.ajax({
-                dataType: 'json',
-                type: 'GET',
-                url: 'auth',
+                dataType: "json",
+                type: "GET",
+                url: "neighbours",
                 jsonp: false,
                 beforeSend: function (xhr) {
-                    xhr.setRequestHeader('Password', getPassword());
+                    xhr.setRequestHeader("Password", getPassword());
                 },
                 success: function (data) {
-                  if (!supportsSessionStorage()) {
-                      $.cookie('rspamdsession', data, {
-                          expires: 1
-                      }, {
-                          path: '/'
-                      });
-                      } else {
-                          sessionStorage.setItem('Credentials', JSON.stringify(data));
-                      }
-                  }
-            });
-            var widgets = $('#statWidgets');
-            $(widgets).empty().hide();
-            var data;
-            if (!supportsSessionStorage()) {
-                data = $.cookie('rspamdsession');
-            } else {
-                data = JSON.parse(sessionStorage.getItem('Credentials'));
-            }
-            var stat_w = [];
-            $.each(data, function (i, item) {
-                var widget = '';
-                if (i == 'auth') {}
-                else if (i == 'error') {}
-                else if (i == 'version') {
-                    widget = '<div class="left"><strong>' + item + '</strong>' +
-                        i + '</div>';
-                    $(widget).appendTo(widgets);
-                } else if (i == 'uptime') {
-                    widget = '<div class="right"><strong>' + msToTime(item) +
-                        '</strong>' + i + '</div>';
-                    $(widget).appendTo(widgets);
-                } else {
-                    widget = '<li class="stat-box"><div class="widget"><strong>' +
-                        Humanize.compactInteger(item) + '</strong>' + i + '</div></li>';
-                    if (i == 'scanned') {
-                        stat_w[0] = widget;
-                    } else if (i == 'clean') {
-                        stat_w[1] = widget;
-                    } else if (i == 'greylist') {
-                        stat_w[2] = widget;
-                    } else if (i == 'probable') {
-                        stat_w[3] = widget;
-                    } else if (i == 'reject') {
-                        stat_w[4] = widget;
-                    } else if (i == 'learned') {
-                        stat_w[5] = widget;
+                    if (jQuery.isEmptyObject(data)) {
+                        neighbours = { local : { host : "localhost", url : "./" }};
+                    }   else {
+                        neighbours = data;
                     }
+                    var neighbours_status = [];
+                    $.each(neighbours, function (ind) {
+                        neighbours_status.push({
+                            name: ind,
+                            url: neighbours[ind].url,
+                            host: neighbours[ind].host,
+                            checked: false,
+                            data: {},
+                            status: false
+                        });
+                    });
+                    $.each(neighbours_status, function (ind) {
+                        "use strict";
+                        $.ajax({
+                          jsonp: false,
+                          beforeSend: function (xhr) {
+                              xhr.setRequestHeader("Password", getPassword());
+                          },
+                          url: neighbours_status[ind].url + "/auth",
+                          success: function (data) {
+                              neighbours_status[ind].checked = true;
+                              if (jQuery.isEmptyObject(data)) {
+                                  neighbours_status[ind].status = false; //serv does not work
+                              } else {
+                                  neighbours_status[ind].status = true; //serv does not work
+                                  neighbours_status[ind].data = data;
+                                  if (!('config_id' in neighbours_status[ind].data)) {
+                                    neighbours_status[ind].data.config_id = "";
+                                  }
+                              }
+                              if (neighbours_status.every(function (elt) {return elt.checked;})) {
+                                  var neighbours_sum = {
+                                      version: neighbours_status[0].data.version,
+                                      auth: "ok",
+                                      uptime: 0,
+                                      clean: 0,
+                                      probable: 0,
+                                      greylist: 0,
+                                      reject: 0,
+                                      scanned: 0,
+                                      learned: 0,
+                                      read_only: neighbours_status[0].data.read_only,
+                                      config_id: ""
+                                  };
+                                  var status_count = 0;
+                                  for(var e in neighbours_status) {
+                                      if(neighbours_status[e].status == true) {
+                                          neighbours_sum.clean += neighbours_status[e].data.clean;
+                                          neighbours_sum.probable += neighbours_status[e].data.probable;
+                                          neighbours_sum.greylist += neighbours_status[e].data.greylist;
+                                          neighbours_sum.reject += neighbours_status[e].data.reject;
+                                          neighbours_sum.scanned += neighbours_status[e].data.scanned;
+                                          neighbours_sum.learned += neighbours_status[e].data.learned;
+                                          neighbours_sum.uptime += neighbours_status[e].data.uptime;
+                                          status_count++;
+                                      }
+                                  }
+                                  neighbours_sum.uptime = Math.floor(neighbours_sum.uptime / status_count);
+                                  var to_Credentials = {};
+                                  to_Credentials["All SERVERS"] = { name: "All SERVERS",
+                                                                    url: "",
+                                                                    host: "",
+                                                                    checked: true,
+                                                                    data: neighbours_sum,
+                                                                    status: true
+                                                                  }
+                                  neighbours_status.forEach(function (elmt) {
+                                      to_Credentials[elmt.name] = elmt;
+                                  });
+                                  sessionStorage.setItem("Credentials", JSON.stringify(to_Credentials));
+                                  displayStatWidgets();
+                              }
+                          }
+                          //error display
+                        });
+                    });
                 }
             });
-            $.each(stat_w, function (i, item) {
-                $(item).appendTo(widgets);
-            });
-            $('#statWidgets .left,#statWidgets .right').wrapAll('<li class="stat-box pull-right"><div class="widget"></div></li>');
-            $('#statWidgets').find('li.pull-right').appendTo('#statWidgets');
-            $(widgets).show();
         }
+
+        $(document).on('click', 'input:radio[name="clusterName"]', function (e) {
+            checked_server = this.value;
+            statWidgets();
+        });
+
         // @opem modal with target form enabled
         $(document).on('click', '[data-toggle="modal"]', function (e) {
             var source = $(this).data('source');
         // @connect to server
         function connectRSPAMD() {
             if (isLogged()) {
-                var data;
-                if (!supportsSessionStorage()) {
-                    data = $.cookie('rspamdsession');
-                } else {
-                    data = JSON.parse(sessionStorage.getItem('Credentials'));
-                }
-                if (data.read_only) {
+                var data = JSON.parse(sessionStorage.getItem('Credentials'));
+
+                if (data[checked_server].read_only) {
                     read_only = true;
                     $('#learning_nav').hide();
                     $('#resetHistory').attr('disabled', true);
                                 $('#resetHistory').removeAttr('disabled', true);
                             }
 
-                            saveCredentials(data, password);
+                            saveCredentials(password);
                             $(dialog).hide();
                             $(backdrop).hide();
                             displayUI();