fix: wrong behavior of the live monitor view

parent bc99d6de
......@@ -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)
......
......@@ -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"""
......
......@@ -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'))
......
......@@ -109,6 +109,8 @@ var notif = function(type, message, timeout) {
i = '<i class="fa fa-fw fa-exclamation-circle" aria-hidden="true"></i>&nbsp;';
break;
case NOTIF_INFO:
t = 'info';
i = '<i class="fa fa-fw fa-info-circle" aria-hidden="true"></i>&nbsp;';
default:
t = 'info';
i = '<i class="fa fa-fw fa-info-circle" aria-hidden="true"></i>&nbsp;';
......@@ -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 -%}
......
......@@ -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) {
......
......@@ -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);
}
}
});
};
......
......@@ -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") }}';
......
{% extends "layout.html" %}
{% block body %}
{% include "notifications.html" %}
<div class="main">
<ul class="breadcrumb" style="margin-bottom: 5px;">
<li><a href="{{ url_for('view.home') }}">{{ _('Home') }}</a></li>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment