aboutsummaryrefslogtreecommitdiffstats
path: root/interface
diff options
context:
space:
mode:
Diffstat (limited to 'interface')
-rw-r--r--interface/css/rspamd.css36
-rw-r--r--interface/index.html40
-rw-r--r--interface/js/rspamd.js283
3 files changed, 247 insertions, 112 deletions
diff --git a/interface/css/rspamd.css b/interface/css/rspamd.css
index 2b5693a7d..159d6ca50 100644
--- a/interface/css/rspamd.css
+++ b/interface/css/rspamd.css
@@ -608,3 +608,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%;
+}
diff --git a/interface/index.html b/interface/index.html
index b83639edc..d73acf7a7 100644
--- a/interface/index.html
+++ b/interface/index.html
@@ -66,6 +66,46 @@
</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">
diff --git a/interface/js/rspamd.js b/interface/js/rspamd.js
index 778eea431..eec754cb4 100644
--- a/interface/js/rspamd.js
+++ b/interface/js/rspamd.js
@@ -33,6 +33,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
@@ -143,43 +145,14 @@
}
// @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) {
@@ -203,13 +176,7 @@
}
// @clean credentials
function cleanCredentials() {
- if (!supportsSessionStorage()) {
- $.removeCookie('rspamdlogged');
- $.removeCookie('rspamdsession');
- $.removeCookie('rspamdpasswd');
- } else {
- sessionStorage.clear();
- }
+ sessionStorage.clear();
$('#statWidgets').empty();
$('#listMaps').empty();
$('#modalBody').empty();
@@ -220,14 +187,8 @@
}
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;
}
@@ -339,6 +300,7 @@
});
});
}
+
// @ ms to date
function msToTime(seconds) {
years = seconds / 31536000 >> 0 // 3600*24*365
@@ -363,74 +325,175 @@
}
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');
@@ -1324,13 +1387,9 @@
// @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);
@@ -1385,7 +1444,7 @@
$('#resetHistory').removeAttr('disabled', true);
}
- saveCredentials(data, password);
+ saveCredentials(password);
$(dialog).hide();
$(backdrop).hide();
displayUI();