From fde61fa3cafa4c850757d39a5c00eb631c080730 Mon Sep 17 00:00:00 2001 From: bmeeks8 Date: Mon, 3 Mar 2014 20:27:18 -0500 Subject: Fix display order issue with Suricata Dashboard Widget. --- config/suricata/suricata_alerts.js | 64 ++++++++++++++------------------------ 1 file changed, 24 insertions(+), 40 deletions(-) (limited to 'config/suricata/suricata_alerts.js') diff --git a/config/suricata/suricata_alerts.js b/config/suricata/suricata_alerts.js index 7678656d..db95bd0c 100644 --- a/config/suricata/suricata_alerts.js +++ b/config/suricata/suricata_alerts.js @@ -1,63 +1,48 @@ -var suricatalines = Array(); var suricatatimer; var suricataisBusy = false; var suricataisPaused = false; -function suricata_alerts_fetch_new_rules() { +function suricata_alerts_fetch_new_rules_callback(callback_data) { + var data_split; + var new_data_to_add = Array(); + var data = callback_data.content; - //get new alerts from suricata_alerts.widget.php - url = "/widgets/widgets/suricata_alerts.widget.php?getNewAlerts=1" + new Date().getTime(); + data_split = data.split("\n"); - jQuery.ajax(url, { - type: 'GET', - success: function(callback_data) { - var data_split; - var new_data_to_add = Array(); - var data = callback_data; - - data_split = data.split("\n"); - - // Loop through rows and generate replacement HTML - for(var x=0; x' + row_split[1] + ''; - line += '' + row_split[2] + '
' + row_split[3] + ''; - line += '' + 'Priority: ' + row_split[4] + '
' + row_split[5] + ''; - new_data_to_add[new_data_to_add.length] = line; - } - suricata_alerts_update_div_rows(new_data_to_add); - suricataisBusy = false; - } - }); + // Loop through rows and generate replacement HTML + for(var x=0; x' + row_split[1] + ''; + line += '' + row_split[2] + '
' + row_split[3] + ''; + line += '' + 'Pri: ' + row_split[4] + ' ' + row_split[5] + ''; + new_data_to_add[new_data_to_add.length] = line; + } + suricata_alerts_update_div_rows(new_data_to_add); + suricataisBusy = false; } function suricata_alerts_update_div_rows(data) { if(suricataisPaused) return; - var isIE = navigator.appName.indexOf('Microsoft') != -1; - var isSafari = navigator.userAgent.indexOf('Safari') != -1; - var isOpera = navigator.userAgent.indexOf('Opera') != -1; - var rows = jQuery('#suricata-alert-entries>tr'); // Number of rows to move by - var move = rows.length + data.length - nentries; + var move = rows.length + data.length - suri_nentries; if (move < 0) move = 0; - for (var i = move; i < rows.length; i++) { - jQuery(rows[i - move]).html(jQuery(rows[i]).html()); + for (var i = rows.length - 1; i >= move; i--) { + jQuery(rows[i]).html(jQuery(rows[i - move]).html()); } var tbody = jQuery('#suricata-alert-entries'); - for (var i = 0; i < data.length; i++) { - var rowIndex = rows.length - move + i; - if (rowIndex < rows.length) { - jQuery(rows[rowIndex]).html(data[i]); + for (var i = data.length - 1; i >= 0; i--) { + if (i < rows.length) { + jQuery(rows[i]).html(data[i]); } else { - jQuery(tbody).append('' + data[i] + ''); + jQuery(tbody).prepend('' + data[i] + ''); } } @@ -75,9 +60,8 @@ function fetch_new_surialerts() { if(suricataisBusy) return; - //get new alerts from suricata_alerts.widget.php suricataisBusy = true; - suricata_alerts_fetch_new_rules(); + getURL('/widgets/widgets/suricata_alerts.widget.php?getNewAlerts=' + new Date().getTime(), suricata_alerts_fetch_new_rules_callback); } function suricata_alerts_toggle_pause() { -- cgit v1.2.3