From 9e4a002928ec5c79ba26abc84ccdcc6b446d8d52 Mon Sep 17 00:00:00 2001 From: ziirish Date: Fri, 12 Jan 2018 14:03:24 +0100 Subject: [PATCH] improve status update --- .gitlab-ci.yml | 1 + burpui/api/__init__.py | 7 +++++-- burpui/api/async.py | 8 ++++++-- burpui/templates/gerard.js | 8 ++++---- burpui/templates/js/client.js | 8 +++++--- burpui/templates/js/clients.js | 8 ++++---- 6 files changed, 25 insertions(+), 15 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 4efe1e06..7a47721a 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -101,6 +101,7 @@ build:doc: paths: - docs/_build/html expire_in: 2 mos + allow_failure: true build:docker:latest: stage: build diff --git a/burpui/api/__init__.py b/burpui/api/__init__.py index 946d74b9..0fa98282 100644 --- a/burpui/api/__init__.py +++ b/burpui/api/__init__.py @@ -102,8 +102,11 @@ class Api(ApiPlus): def load_all(self): if config['WITH_LIMIT']: - from ..ext.limit import limiter - self.decorators.append(limiter.limit(config['BUI_RATIO'])) + try: + from ..ext.limit import limiter + self.decorators.append(limiter.limit(config['BUI_RATIO'])) + except ImportError: + self.logger.warning('Unable to import limiter module') """hack to automatically import api modules""" if not self.loaded: sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) diff --git a/burpui/api/async.py b/burpui/api/async.py index be454f38..cb477abf 100644 --- a/burpui/api/async.py +++ b/burpui/api/async.py @@ -18,7 +18,6 @@ from .client import node_fields from .clients import RunningBackup, ClientsReport, RunningClients from ..server import BUIServer # noqa from ..ext.cache import cache -from ..ext.limit import limiter from ..config import config from ..decorators import browser_cache from ..tasks import perform_restore, load_all_tree @@ -58,7 +57,12 @@ class AsyncRestoreStatus(Resource): This resource is part of the :mod:`burpui.api.async` module. """ - decorators = [limiter.exempt] + if config['WITH_LIMIT']: + try: + from ..ext.limit import limiter + decorators = [limiter.exempt] + except ImportError: + pass @ns.doc( responses={ diff --git a/burpui/templates/gerard.js b/burpui/templates/gerard.js index cefdffa5..45c0ba67 100644 --- a/burpui/templates/gerard.js +++ b/burpui/templates/gerard.js @@ -179,25 +179,25 @@ var myFail = function(xhr, stat, err) { {% if not login -%} var _last_running_status = undefined; var _last_call = 0; -var _check_running = function() { +var _check_running = function(force) { {% if server -%} var url = '{{ url_for(api_running_backup, server=server) }}'; {% else -%} var url = '{{ url_for(api_running_backup) }}'; {% endif -%} var now = Date.now(); - if ((now - _last_call) < 5*1000) { + if ((now - _last_call) < 5*1000 && !force) { return; } _last_call = now; $.getJSON(url, function(data) { {% if clients and overview -%} - if (_last_running_status != data.running) { + if (_last_running_status != data.running || force) { $( document ).trigger('refreshClientsStatesEvent', data.running); } {% endif -%} {% if client and overview -%} - if (_last_running_status != data.running) { + if (_last_running_status != data.running || force) { $( document ).trigger('refreshClientStatusEvent', data.running); } {% endif -%} diff --git a/burpui/templates/js/client.js b/burpui/templates/js/client.js index 0e95bc42..cd8315e2 100644 --- a/burpui/templates/js/client.js +++ b/burpui/templates/js/client.js @@ -73,8 +73,8 @@ var _client_table = $('#table-client').DataTable( { } else { $('#client-alert').hide(); $('#table-client').show(); - return data; } + return data; }, error: function(xhr, stat, err) { myFail(xhr, stat, err); @@ -142,8 +142,6 @@ var first = true; var _client = function() { if (first) { first = false; - _check_running(); - refresh_status(false); } else { _client_table.ajax.reload( null, false ); } @@ -313,6 +311,10 @@ $( document ).ready(function() { _client_table.on('draw.dt', function() { $('[data-toggle="tooltip"]').tooltip(); }); +_client_table.on('init.dt', function() { + _check_running(true); + refresh_status(false); +}); $( document ).on('refreshClientStatusEvent', function( event, is_running ) { refresh_status(is_running); }); diff --git a/burpui/templates/js/clients.js b/burpui/templates/js/clients.js index 9681c22e..511962a1 100644 --- a/burpui/templates/js/clients.js +++ b/burpui/templates/js/clients.js @@ -140,7 +140,6 @@ var first = true; var _clients = function() { if (first) { first = false; - _check_running(); } else { _clients_table.ajax.reload( null, false ); } @@ -165,9 +164,7 @@ var refresh_status = function( is_running ) { _.each(running, function(name) { var _row = _clients_table.row('#'+name); var _content = _row.data(); - var _p = $.get({ - url: '{{ url_for("api.client_running_status", server=server) }}?clientName='+name, - }).done(function(_status) { + var _p = $.getJSON('{{ url_for("api.client_running_status", server=server) }}?clientName='+name, function(_status) { _status.static = true; var _new_content = _.merge(_content, _status); _row.data( _new_content ); @@ -219,6 +216,9 @@ var refresh_status = function( is_running ) { _clients_table.on('draw.dt', function() { $('[data-toggle="tooltip"]').tooltip(); }); +_clients_table.on('init.dt', function() { + _check_running(true); +}); $( document ).on('refreshClientsStatesEvent', function( event, is_running ) { refresh_status(is_running); });