From f0fd2cb8f5b76369a28467c93cc1c5b7c331191a Mon Sep 17 00:00:00 2001 From: bmeeks8 Date: Fri, 28 Feb 2014 20:21:17 -0500 Subject: Add built-in Dashboard Widget for Suricata and make it persistent. --- config/suricata/suricata_alerts.js | 92 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 config/suricata/suricata_alerts.js (limited to 'config/suricata/suricata_alerts.js') diff --git a/config/suricata/suricata_alerts.js b/config/suricata/suricata_alerts.js new file mode 100644 index 00000000..7678656d --- /dev/null +++ b/config/suricata/suricata_alerts.js @@ -0,0 +1,92 @@ + +var suricatalines = Array(); +var suricatatimer; +var suricataisBusy = false; +var suricataisPaused = false; + +function suricata_alerts_fetch_new_rules() { + + //get new alerts from suricata_alerts.widget.php + url = "/widgets/widgets/suricata_alerts.widget.php?getNewAlerts=1" + new Date().getTime(); + + 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; + } + }); +} +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; + if (move < 0) + move = 0; + + for (var i = move; i < rows.length; i++) { + jQuery(rows[i - move]).html(jQuery(rows[i]).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]); + } else { + jQuery(tbody).append('' + data[i] + ''); + } + } + + // Add the even/odd class to each of the rows now + // they have all been added. + rows = jQuery('#suricata-alert-entries>tr'); + for (var i = 0; i < rows.length; i++) { + rows[i].className = i % 2 == 0 ? 'listMRodd' : 'listMReven'; + } +} + +function fetch_new_surialerts() { + if(suricataisPaused) + return; + if(suricataisBusy) + return; + + //get new alerts from suricata_alerts.widget.php + suricataisBusy = true; + suricata_alerts_fetch_new_rules(); +} + +function suricata_alerts_toggle_pause() { + if(suricataisPaused) { + suricataisPaused = false; + fetch_new_surialerts(); + } else { + suricataisPaused = true; + } +} +/* start local AJAX engine */ +suricatatimer = setInterval('fetch_new_surialerts()', suricataupdateDelay); -- cgit v1.2.3 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 From 15cdf2213efa54130a0962d5a22d30df7cc0cefe Mon Sep 17 00:00:00 2001 From: bmeeks8 Date: Tue, 4 Mar 2014 12:58:22 -0500 Subject: Revert back to Ajax.url() call in widget because getURL() not in 2.1 -- oops! --- config/suricata/suricata_alerts.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'config/suricata/suricata_alerts.js') diff --git a/config/suricata/suricata_alerts.js b/config/suricata/suricata_alerts.js index db95bd0c..9e5b0b29 100644 --- a/config/suricata/suricata_alerts.js +++ b/config/suricata/suricata_alerts.js @@ -6,7 +6,7 @@ var suricataisPaused = false; function suricata_alerts_fetch_new_rules_callback(callback_data) { var data_split; var new_data_to_add = Array(); - var data = callback_data.content; + var data = callback_data; data_split = data.split("\n"); @@ -61,7 +61,14 @@ function fetch_new_surialerts() { return; suricataisBusy = true; - getURL('/widgets/widgets/suricata_alerts.widget.php?getNewAlerts=' + new Date().getTime(), suricata_alerts_fetch_new_rules_callback); + + jQuery.ajax('/widgets/widgets/suricata_alerts.widget.php?getNewAlerts=' + new Date().getTime(), { + type: 'GET', + dataType: 'text', + success: function(data) { + suricata_alerts_fetch_new_rules_callback(data); + } + }); } function suricata_alerts_toggle_pause() { -- cgit v1.2.3 From bca1905789f4fdf938f81a7cfe5dd98751726aa7 Mon Sep 17 00:00:00 2001 From: bmeeks8 Date: Fri, 7 Mar 2014 21:35:27 -0500 Subject: Put [] around IPv6 addr and tidy up Suri Dashboard Widget. --- config/suricata/suricata_alerts.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'config/suricata/suricata_alerts.js') diff --git a/config/suricata/suricata_alerts.js b/config/suricata/suricata_alerts.js index 9e5b0b29..16e0c73c 100644 --- a/config/suricata/suricata_alerts.js +++ b/config/suricata/suricata_alerts.js @@ -14,9 +14,9 @@ function suricata_alerts_fetch_new_rules_callback(callback_data) { for(var x=0; x' + row_split[1] + ''; - line += '' + row_split[2] + '
' + row_split[3] + ''; - line += '' + 'Pri: ' + row_split[4] + ' ' + row_split[5] + ''; + line = '' + row_split[0] + '
' + 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); -- cgit v1.2.3 From 3bd710acc08252498e46e5c5d8608a3c6fbd122f Mon Sep 17 00:00:00 2001 From: bmeeks8 Date: Sat, 8 Mar 2014 12:31:26 -0500 Subject: Add ellipsis class and tooltips to Dashboard Widget IP columns. --- config/suricata/suricata_alerts.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'config/suricata/suricata_alerts.js') diff --git a/config/suricata/suricata_alerts.js b/config/suricata/suricata_alerts.js index 16e0c73c..b6a5d3c3 100644 --- a/config/suricata/suricata_alerts.js +++ b/config/suricata/suricata_alerts.js @@ -14,9 +14,11 @@ function suricata_alerts_fetch_new_rules_callback(callback_data) { for(var x=0; x' + row_split[1] + ''; - line += '' + row_split[2] + '
' + row_split[3] + ''; - line += '' + 'Pri: ' + row_split[4] + ' ' + row_split[5] + ''; + line = '' + row_split[0] + '
' + 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); -- cgit v1.2.3