diff --git a/burpui/api/misc.py b/burpui/api/misc.py index 23c5ace2..1f8d5bf2 100644 --- a/burpui/api/misc.py +++ b/burpui/api/misc.py @@ -115,18 +115,20 @@ class Counters(Resource): not current_user.acl.is_admin() and \ not current_user.acl.is_client_allowed(client, server): self.abort(403, "Not allowed to view '{}' counters".format(client)) - bui.client.is_one_backup_running() - if isinstance(bui.client.running, dict): + running = bui.client.is_one_backup_running() + if isinstance(running, dict): if server and client not in bui.client.running[server]: self.abort(404, "'{}' not found in the list of running clients for '{}'".format(client, server)) else: found = False - for (k, a) in iteritems(bui.client.running): - found = found or (client in a) + for (_, cls) in iteritems(running): + if client in cls: + found = True + break if not found: api.bort(404, "'{}' not found in running clients".format(client)) else: - if client not in bui.client.running: + if client not in running: self.abort(404, "'{}' not found in running clients".format(client)) try: counters = bui.client.get_counters(client, agent=server) diff --git a/burpui/misc/backend/multi.py b/burpui/misc/backend/multi.py index 19cefda1..1bfd3b17 100644 --- a/burpui/misc/backend/multi.py +++ b/burpui/misc/backend/multi.py @@ -225,20 +225,20 @@ class Burp(BUIbackend): @implement def is_one_backup_running(self, agent=None): """See :func:`burpui.misc.backend.interface.BUIbackend.is_one_backup_running`""" - r = [] + res = [] if agent: try: - r = self.servers[agent].is_one_backup_running(agent) + res = self.servers[agent].is_one_backup_running(agent) except BUIserverException: pass else: - r = {} + res = {} for name, serv in iteritems(self.servers): try: - r[name] = serv.is_one_backup_running() + res[name] = serv.is_one_backup_running() except BUIserverException: - r[name] = [] - return r + res[name] = [] + return res def _get_version(self, method=None): """get versions""" diff --git a/burpui/routes.py b/burpui/routes.py index 0f86f91a..9b9aa69d 100644 --- a/burpui/routes.py +++ b/burpui/routes.py @@ -274,16 +274,13 @@ def cli_settings(server=None, client=None, conf=None): def live_monitor(server=None, name=None): """Live status monitor view""" server = server or request.args.get('serverName') - bui.client.is_one_backup_running() + running = bui.client.is_one_backup_running() if bui.standalone: - if not bui.client.running: + if not running: flash(_('Sorry, there are no running backups'), 'warning') return redirect(url_for('.home')) else: - run = False - for a in bui.client.servers: - run = run or (a in bui.client.running and bui.client.running[a]) - if not run: + if not any([x for _, x in iteritems(running)]): flash(_('Sorry, there are no running backups'), 'warning') return redirect(url_for('.home')) diff --git a/burpui/templates/gerard.js b/burpui/templates/gerard.js index 21f8edcd..cd718255 100644 --- a/burpui/templates/gerard.js +++ b/burpui/templates/gerard.js @@ -109,6 +109,8 @@ var notif = function(type, message, timeout) { i = ' '; break; case NOTIF_INFO: + t = 'info'; + i = ' '; default: t = 'info'; i = ' '; @@ -131,6 +133,9 @@ var anim = function(elem, timeout) { }; var errorsHandler = function(json) { + if (!json) { + return false; + } if ('notif' in json) { message = json.notif; } else if ('message' in json) { @@ -429,7 +434,7 @@ var cancel_refresh = function() { auto_refresh = undefined; } } -var auto_refresh_function = function() { +var auto_refresh_function = function(oneshot) { {% if clients -%} _clients(); {% endif -%} @@ -439,8 +444,10 @@ var auto_refresh_function = function() { {% if servers and overview -%} _servers(); {% endif -%} - cancel_refresh() - schedule_refresh(); + if (!oneshot) { + cancel_refresh() + schedule_refresh(); + } }; {% endif -%} diff --git a/burpui/templates/js/client.js b/burpui/templates/js/client.js index 132b4282..c1192c75 100644 --- a/burpui/templates/js/client.js +++ b/burpui/templates/js/client.js @@ -63,6 +63,7 @@ var __icons = { {{ macros.timestamp_filter() }} +var __init_complete = false; var _client_table = $('#table-client').DataTable( { {{ macros.translate_datatable() }} {{ macros.get_page_length() }} @@ -97,6 +98,9 @@ var _client_table = $('#table-client').DataTable( { rowCallback: function( row, data ) { row.className += ' clickable'; }, + initComplete: function ( settings, json ) { + __init_complete = true; + }, columns: [ { data: null, @@ -156,6 +160,9 @@ var _client_table = $('#table-client').DataTable( { var first = true; var _client = function() { + if (!__init_complete) { + return; + } if (first) { first = false; } else { @@ -255,7 +262,9 @@ var refresh_status = function( is_running ) { }, {{ config.LIVEREFRESH * 1000 }}); } else { _cache_id = new Date().getTime(); - auto_refresh_function(); + if (__init_complete && is_running) { + auto_refresh_function(true); + } } }; if (_get_running) { diff --git a/burpui/templates/js/clients.js b/burpui/templates/js/clients.js index dc3f612b..2469970c 100644 --- a/burpui/templates/js/clients.js +++ b/burpui/templates/js/clients.js @@ -58,6 +58,7 @@ var _cache_id = _EXTRA; {{ macros.timestamp_filter() }} +var __init_complete = false; var _clients_table = $('#table-clients').DataTable( { {{ macros.translate_datatable() }} {{ macros.get_page_length() }} @@ -98,6 +99,9 @@ var _clients_table = $('#table-clients').DataTable( { } row.className += ' clickable'; }, + initComplete: function( settings, json ) { + __init_complete = true; + }, columns: [ { data: 'name', @@ -176,6 +180,9 @@ var _clients_table = $('#table-clients').DataTable( { var first = true; var _clients = function() { + if (!__init_complete) { + return; + } if (first) { first = false; } else { @@ -253,7 +260,9 @@ var refresh_status = function( is_running ) { }, {{ config.LIVEREFRESH * 1000 }}); } else { _cache_id = new Date().getTime(); - auto_refresh_function(); + if (__init_complete && is_running) { + auto_refresh_function(true); + } } }); }; diff --git a/burpui/templates/js/live-monitor.js b/burpui/templates/js/live-monitor.js index d9f30a5b..e5416fd6 100644 --- a/burpui/templates/js/live-monitor.js +++ b/burpui/templates/js/live-monitor.js @@ -50,6 +50,7 @@ app.controller('LiveCtrl', function($scope, $http, $timeout) { } }; + var last_status = 404; $scope.load = function() { $http.get(counters, { headers: { 'X-From-UI': true } }) .then(function(response) { @@ -60,23 +61,26 @@ app.controller('LiveCtrl', function($scope, $http, $timeout) { $scope.clients = []; $scope.clients.push(data); } - if (status === 404) { + if ($scope.clients.length == 0) { + var message = "{{ _('No more backup running') }}"; $scope.stopTimer(); - notif(NOTIF_INFO, "{{ _('Backup complete. Will redirect you in 5 seconds') }}"); - $timeout(function() { + $http.post('{{ url_for("api.alert") }}', {'message': message}, { headers: { 'X-From-UI': true } }) + .then(function(response2) { document.location = '{{ url_for("view.home") }}'; - }, 5000); + }); return; } - if ($scope.clients.length == 0) { - $http.post('{{ url_for("api.alert") }}', {'message': "{{ _('No more backup running') }}"}, { headers: { 'X-From-UI': true } }); - document.location = '{{ url_for("view.home") }}'; - } + last_status = response.status; timer = $timeout($scope.load, {{ config.LIVEREFRESH * 1000 }}); }, function(response) { var data = response.data; $scope.stopTimer(); - errorsHandler(data); + if (response.status === 404 && response.status !== last_status) { + $scope.stopTimer(); + notif(NOTIF_INFO, "{{ _('Backup complete') }}"); + } else { + errorsHandler(data); + } notif(NOTIF_INFO, "{{ _('Will redirect you in 5 seconds') }}"); $timeout(function() { document.location = '{{ url_for("view.home") }}'; diff --git a/burpui/templates/live-monitor.html b/burpui/templates/live-monitor.html index 4515ae6f..cb636ff8 100644 --- a/burpui/templates/live-monitor.html +++ b/burpui/templates/live-monitor.html @@ -1,5 +1,6 @@ {% extends "layout.html" %} {% block body %} + {% include "notifications.html" %}