diff options
author | Alexander Moisseev <moiseev@mezonplus.ru> | 2018-10-02 13:27:12 +0300 |
---|---|---|
committer | Alexander Moisseev <moiseev@mezonplus.ru> | 2018-10-02 17:53:08 +0300 |
commit | 626fe0339c3dee9c9a909fa4f42bd4c92cb851b5 (patch) | |
tree | 9b76ec0949630a90f7822780bc55514ef0735bbd /interface | |
parent | 647986d925162a8bd1ee18dde1b074e3edabb22d (diff) | |
download | rspamd-626fe0339c3dee9c9a909fa4f42bd4c92cb851b5.tar.gz rspamd-626fe0339c3dee9c9a909fa4f42bd4c92cb851b5.zip |
[WebUI] Do not display password form when secure_ip is set
Fixes: #2553
Diffstat (limited to 'interface')
-rw-r--r-- | interface/index.html | 4 | ||||
-rw-r--r-- | interface/js/app/rspamd.js | 103 |
2 files changed, 53 insertions, 54 deletions
diff --git a/interface/index.html b/interface/index.html index 1cf363b96..8d40da510 100644 --- a/interface/index.html +++ b/interface/index.html @@ -357,11 +357,11 @@ </div> <!-- login modal --> -<div id="connectDialog" class="modal" tabindex="-1" role="dialog" aria-labelledby="RSPAMD Connect"> +<div id="connectDialog" class="modal" tabindex="-1" role="dialog" style="display:none"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> - <h3>RSPAMD Connect</h3> + <h3>Login to Rspamd</h3> </div> <div class="modal-body" id="connectBody"> <form id="connectForm"> diff --git a/interface/js/app/rspamd.js b/interface/js/app/rspamd.js index fde541285..29bbfbcf1 100644 --- a/interface/js/app/rspamd.js +++ b/interface/js/app/rspamd.js @@ -134,13 +134,6 @@ function ($, D3pie, visibility, NProgress, tab_stat, tab_graph, tab_config, sessionStorage.setItem("Password", password); } - function isLogged() { - if (sessionStorage.getItem("Credentials") !== null) { - return true; - } - return false; - } - function displayUI() { // In many browsers local storage can only store string. // So when we store the boolean true or false, it actually stores the strings "true" or "false". @@ -300,53 +293,59 @@ function ($, D3pie, visibility, NProgress, tab_stat, tab_graph, tab_config, }; ui.connect = function () { - if (isLogged()) { - displayUI(); - return; - } - - var dialog = $("#connectDialog"); - var backdrop = $("#backDrop"); - $("#mainUI").hide(); - $(dialog).show(); - $(backdrop).show(); - $("#connectPassword").focus(); - $("#connectForm").off("submit"); - - $("#connectForm").on("submit", function (e) { - e.preventDefault(); - var password = $("#connectPassword").val(); - if (!(/^[\u0020-\u007e]*$/).test(password)) { - alertMessage("alert-modal alert-error", "Invalid characters in the password"); + // Query "/stat" to check if user is already logged in or client ip matches "secure_ip" + $.ajax({ + type: "GET", + url: "stat", + async: false, + success: function () { + displayUI(); + }, + error: function () { + var dialog = $("#connectDialog"); + var backdrop = $("#backDrop"); + $("#mainUI").hide(); + $(dialog).show(); + $(backdrop).show(); $("#connectPassword").focus(); - return; - } - - ui.query("auth", { - headers: { - Password: password - }, - success: function (json) { - var data = json[0].data; - $("#connectPassword").val(""); - if (data.auth === "ok") { - sessionStorage.setItem("read_only", data.read_only); - saveCredentials(password); - $(dialog).hide(); - $(backdrop).hide(); - displayUI(); + $("#connectForm").off("submit"); + + $("#connectForm").on("submit", function (e) { + e.preventDefault(); + var password = $("#connectPassword").val(); + if (!(/^[\u0020-\u007e]*$/).test(password)) { + alertMessage("alert-modal alert-error", "Invalid characters in the password"); + $("#connectPassword").focus(); + return; } - }, - error: function (jqXHR) { - ui.alertMessage("alert-modal alert-error", jqXHR.statusText); - $("#connectPassword").val(""); - $("#connectPassword").focus(); - }, - params: { - global: false, - }, - server: "local" - }); + + ui.query("auth", { + headers: { + Password: password + }, + success: function (json) { + var data = json[0].data; + $("#connectPassword").val(""); + if (data.auth === "ok") { + sessionStorage.setItem("read_only", data.read_only); + saveCredentials(password); + $(dialog).hide(); + $(backdrop).hide(); + displayUI(); + } + }, + error: function (jqXHR) { + ui.alertMessage("alert-modal alert-error", jqXHR.statusText); + $("#connectPassword").val(""); + $("#connectPassword").focus(); + }, + params: { + global: false, + }, + server: "local" + }); + }); + } }); }; |