]> source.dussan.org Git - rspamd.git/commitdiff
[WebUI] Do not display password form when secure_ip is set 2558/head
authorAlexander Moisseev <moiseev@mezonplus.ru>
Tue, 2 Oct 2018 10:27:12 +0000 (13:27 +0300)
committerAlexander Moisseev <moiseev@mezonplus.ru>
Tue, 2 Oct 2018 14:53:08 +0000 (17:53 +0300)
Fixes: #2553
interface/index.html
interface/js/app/rspamd.js

index 1cf363b96eb0ffe3d76b41e24eb5380ea7cbf187..8d40da51030ad72828c7b1490fda99b6ac292f2e 100644 (file)
 </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">
index fde54128500b3a1b06ca19f9fb19b4f2b00c511a..29bbfbcf13f79d6139386fd708e1fc83adbf8ce8 100644 (file)
@@ -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"
+                    });
+                });
+            }
         });
     };