]> source.dussan.org Git - rspamd.git/commitdiff
[WebUI] Distinguish read-only interface, multiple bugs fixed
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 14 Nov 2016 12:51:19 +0000 (12:51 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 14 Nov 2016 12:51:19 +0000 (12:51 +0000)
interface/js/rspamd.js
src/controller.c

index 77fe5e867dd29dd0477eadf35b9a7c6e6981b49c..271a0b79745599dd4b7a12fbe5b1254c56a06c64 100644 (file)
@@ -30,6 +30,9 @@
         var history;
         var graph;
         var symbols;
+        var read_only = false;
+        var btn_class = "";
+        var stat_timeout;
 
         var selected = []; // Keep graph selectors state
 
@@ -63,6 +66,7 @@
                 symbols.destroy();
                 symbols = null;
             }
+            clearTimeout(stat_timeout);
             cleanCredentials();
             connectRSPAMD();
             // window.location.reload();
 
         // @detect session storate
         supportsSessionStorage();
-        // @request credentials
-        function requestCredentials() {
-            $.ajax({
-                dataType: 'json',
-                type: 'GET',
-                url: 'auth',
-                jsonp: false,
-                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()) {
                     $.each(data, function (i, item) {
                         var caption;
                         var label;
-                        if ((item.editable == false)) {
+                        if ((item.editable == false || read_only)) {
                             caption = 'View';
                             label = '<span class="label label-default">Read</span>';
                         } else {
                     },
                     success: function (text) {
                         var disabled = '';
-                        if ((item.editable == false)) {
+                        if ((item.editable == false || read_only)) {
                             disabled = 'disabled="disabled"';
                         }
 
         // @show widgets
         function statWidgets() {
             var widgets = $('#statWidgets');
-            updateCredentials();
             $(widgets).empty().hide();
             var data;
             if (!supportsSessionStorage()) {
             });
             $('#statWidgets .left,#statWidgets .right').wrapAll('<li class="stat-box pull-right"><div class="widget"></div></li>');
             $(widgets).show();
-            window.setTimeout(statWidgets, 10000);
+            stat_timeout = window.setTimeout(statWidgets, 10000);
         }
         // @opem modal with target form enabled
         $(document).on('click', '[data-toggle="modal"]', function (e) {
                                 '" id="_sym_' + item.symbol + '"></span></td>' +
                                 '<td data-order="' + item.frequency + '">' + item.frequency + '</td>' +
                                 '<td data-order="' + item.time + '">' + Number(item.time).toFixed(2) + 'ms</td>' +
-                                '<td><button type="button" class="btn btn-primary btn-sm">Save</button></td>' +
-                                '</tr>');
+                                '<td><button type="button" class="btn btn-primary btn-sm ' + btn_class +
+                                '">Save</button></td></tr>');
                         });
                     });
                     $('<tbody/>', {
                             return e.html;
                         }).join('') +
                         '<br><div class="form-group">' +
-                        '<button class="btn btn-primary" ' +
-                        'type="submit">Save actions</button></div></form>');
+                        '<button class="btn btn-primary ' + btn_class +
+                        'type="submit">Save actions</button></div></form>');
                 }
             });
         }
                     alertMessage('alert-modal alert-error', data.statusText);
                 }
             });
-            getMapById('update');
             return false;
         });
         // @catch changes of file upload form
                 displayUI();
                 return;
             }
-            $.ajax({
-                type: 'GET',
-                url: 'stat',
-                jsonp: false,
-                success: function () {
-                    saveCredentials({}, 'nopassword');
-                    $(dialog).hide();
-                    $(backdrop).hide();
-                    displayUI();
-                },
-            });
             var nav = $('#navBar');
             var ui = $('#mainUI');
             var dialog = $('#connectDialog');
             $(dialog).show();
             $('#connectHost').focus();
             $(backdrop).show();
-            $(document).on('submit', '#connectForm', function (e) {
+            $('#connectForm').one('submit', function (e) {
                 e.preventDefault();
                 var password = $('#connectPassword').val();
                 document.getElementById('connectPassword').value = '';
                                 $('.form-group').addClass('error');
                             });
                         } else {
+                            if (data.read_only) {
+                                read_only = true;
+                                btn_class = "disabled";
+                                $('#learning_nav').parent().addClass('disabled');
+                            }
+                            else {
+                                read_only = false;
+                                btn_class = "";
+                                $('#learning_nav').parent().removeClass('disabled')
+                            }
+
                             saveCredentials(data, password);
                             $(dialog).hide();
                             $(backdrop).hide();
index d19ab22601b6694398cee41a798717fc84cc81cd..da0f44dce931e35c36d9d0a2aaff7f6e6b374b27 100644 (file)
@@ -442,8 +442,8 @@ rspamd_controller_check_forwarded (struct rspamd_controller_session *session,
 }
 
 /* Check for password if it is required by configuration */
-static gboolean rspamd_controller_check_password(
-               struct rspamd_http_connection_entry *entry,
+static gboolean
+rspamd_controller_check_password (struct rspamd_http_connection_entry *entry,
                struct rspamd_controller_session *session,
                struct rspamd_http_message *msg, gboolean is_enable)
 {
@@ -678,6 +678,8 @@ rspamd_controller_handle_auth (struct rspamd_http_connection_entry *conn_ent,
                        st->messages_scanned), "scanned",  0, false);
        ucl_object_insert_key (obj,        ucl_object_fromint (
                        st->messages_learned), "learned",  0, false);
+       ucl_object_insert_key (obj, ucl_object_frombool (!session->is_enable),
+                       "read_only", 0, false);
 
        rspamd_controller_send_ucl (conn_ent, obj);
        ucl_object_unref (obj);