/* The MIT License (MIT) Copyright (C) 2012-2013 Anton Simonov Copyright (C) 2014-2015 Vsevolod Stakhov Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ (function () { $(document).ready(function () { // begin //$.cookie.json = true; var pie; var history; var graph; var selected = []; // Keep graph selectors state // Bind event handlers to selectors $("#selData").change(function () { selected.selData = this.value; getGraphData(this.value); }); $("#selConvert").change(function () { graph.convert(this.value); }); $("#selType").change(function () { graph.type(this.value); }); $("#selInterpolate").change(function () { graph.interpolate(this.value); }); $('#disconnect').on('click', function (event) { if (pie) { pie.destroy(); } if (graph) { graph.destroy(); graph = undefined; } if (history) { history.destroy(); } cleanCredentials(); connectRSPAMD(); // window.location.reload(); return false; }); $('#refresh').on('click', function (event) { statWidgets(); getChart(); getGraphData(selected.selData); }); // @supports session storage function supportsSessionStorage() { return typeof(Storage) !== "undefined"; } // @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; } } // @detect session storate supportsSessionStorage(); // @request credentials function requestCredentials() { $.ajax({ dataType: 'json', type: 'GET', url: 'auth', beforeSend: function (xhr) { xhr.setRequestHeader('Password', getPassword()); }, success: function (data) { if (data.auth === 'failed') { connectRSPAMD(); } } }); } // @request credentials function updateCredentials() { $.ajax({ dataType: 'json', type: 'GET', url: 'auth', beforeSend: function (xhr) { xhr.setRequestHeader('Password', getPassword()); }, success: function (data) { saveCredentials(data, password); } }); } // @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)); } } // @update credentials function saveActions(data) { if (!supportsSessionStorage()) { $.cookie('rspamdactions', data); } else { sessionStorage.setItem('Actions', JSON.stringify(data)); } } // @update credentials function saveMaps(data) { if (!supportsSessionStorage()) { $.cookie('rspamdmaps', data, { expires: 1 }, { path: '/' }); } else { sessionStorage.setItem('Maps', JSON.stringify(data)); } } // @clean credentials function cleanCredentials() { if (!supportsSessionStorage()) { $.removeCookie('rspamdlogged'); $.removeCookie('rspamdsession'); $.removeCookie('rspamdpasswd'); } else { sessionStorage.clear(); } $('#statWidgets').empty(); $('#listMaps').empty(); $('#historyLog tbody').remove(); $('#modalBody').empty(); password = ''; } function isLogged() { if (!supportsSessionStorage()) { if ($.cookie('rspamdpasswd') != null) { return true; } } else { if (sessionStorage.getItem('Password') != null) { return true; } } return false; } // @alert popover function alertMessage(alertState, alertText) { if ($('.alert').is(':visible')) { $(alert).hide().remove(); } var alert = $('