diff options
author | jim-p <jim@pingle.org> | 2009-10-14 17:10:40 -0400 |
---|---|---|
committer | jim-p <jim@pingle.org> | 2009-10-14 17:11:35 -0400 |
commit | 196610ae4ce93843d877993c6f1a400c7670df1e (patch) | |
tree | 945bf5c141930b56844b018a1d543e137e7ed8ee /config/widget-havp/havp_alerts.js | |
parent | a0275915f127d728e5088920bd8da9a944a7d6b4 (diff) | |
download | pfsense-packages-196610ae4ce93843d877993c6f1a400c7670df1e.tar.gz pfsense-packages-196610ae4ce93843d877993c6f1a400c7670df1e.tar.bz2 pfsense-packages-196610ae4ce93843d877993c6f1a400c7670df1e.zip |
Add separate packages for snort and havp dashboard widgets.
Diffstat (limited to 'config/widget-havp/havp_alerts.js')
-rw-r--r-- | config/widget-havp/havp_alerts.js | 149 |
1 files changed, 149 insertions, 0 deletions
diff --git a/config/widget-havp/havp_alerts.js b/config/widget-havp/havp_alerts.js new file mode 100644 index 00000000..110e3998 --- /dev/null +++ b/config/widget-havp/havp_alerts.js @@ -0,0 +1,149 @@ + +havplastsawtime = '<?php echo time(); ?>'; +var havplines = Array(); +var havptimer; +var havpupdateDelay = 25500; +var havpisBusy = false; +var havpisPaused = false; + +<?php + if(isset($config['syslog']['reverse'])) + echo "var isReverse = true;\n"; + else + echo "var isReverse = false;\n"; +?> + +if (typeof getURL == 'undefined') { + getURL = function(url, callback) { + if (!url) + throw 'No URL for getURL'; + try { + if (typeof callback.operationComplete == 'function') + callback = callback.operationComplete; + } catch (e) {} + if (typeof callback != 'function') + throw 'No callback function for getURL'; + var http_request = null; + if (typeof XMLHttpRequest != 'undefined') { + http_request = new XMLHttpRequest(); + } + else if (typeof ActiveXObject != 'undefined') { + try { + http_request = new ActiveXObject('Msxml2.XMLHTTP'); + } catch (e) { + try { + http_request = new ActiveXObject('Microsoft.XMLHTTP'); + } catch (e) {} + } + } + if (!http_request) + throw 'Both getURL and XMLHttpRequest are undefined'; + http_request.onreadystatechange = function() { + if (http_request.readyState == 4) { + callback( { success : true, + content : http_request.responseText, + contentType : http_request.getResponseHeader("Content-Type") } ); + } + } + http_request.open('GET', url, true); + http_request.send(null); + } +} + +function havp_alerts_fetch_new_rules() { + if(havpisPaused) + return; + if(havpisBusy) + return; + havpisBusy = true; + getURL('widgets/helpers/havp_alerts_helper.php?lastsawtime=' + havplastsawtime, havp_alerts_fetch_new_rules_callback); +} +function havp_alerts_fetch_new_rules_callback(callback_data) { + if(havpisPaused) + return; + + var data_split; + var new_data_to_add = Array(); + var data = callback_data.content; + data_split = data.split("\n"); + for(var x=0; x<data_split.length-1; x++) { + /* loop through rows */ + row_split = data_split[x].split("||"); + var line = ''; + line += '<td width="25%" class="listr">' + row_split[4] + '<br> ' + row_split[3] + '</td>'; + line += '<td width="75%" class="listr">' + row_split[0] + '<br>' + row_split[1] + '</td>'; + havplastsawtime = row_split[2]; + new_data_to_add[new_data_to_add.length] = line; + } + havp_alerts_update_div_rows(new_data_to_add); + havpisBusy = false; +} + + +function havp_alerts_update_div_rows(data) { + if(havpisPaused) + return; + + var isIE = navigator.appName.indexOf('Microsoft') != -1; + var isSafari = navigator.userAgent.indexOf('Safari') != -1; + var isOpera = navigator.userAgent.indexOf('Opera') != -1; + var rulestable = document.getElementById('havp_alerts'); + var rows = rulestable.getElementsByTagName('tr'); + var showanim = 1; + if (isIE) { + showanim = 0; + } + //alert(data.length); + for(var x=0; x<data.length; x++) { + var numrows = rows.length; + /* if reverse logging is enabled we need to show the + * records in a reverse order with new items appearing + * on the top + */ + if(isReverse == false) { + for (var i = 1; i < numrows; i++) { + nextrecord = i + 1; + if(nextrecord < numrows) + rows[i].innerHTML = rows[nextrecord].innerHTML; + } + } else { + for (var i = numrows; i > 0; i--) { + nextrecord = i + 1; + if(nextrecord < numrows) + rows[nextrecord].innerHTML = rows[i].innerHTML; + } + } + var item = document.getElementById('havp-firstrow'); + if(x == data.length-1) + { + /* nothing */ + showanim = false; + } + else + { + showanim = false; + } + if (showanim) + { + // item.style.display = 'none'; + item.innerHTML = data[x]; + // new Effect.Appear(item); + } + else + { + item.innerHTML = data[x]; + } + } + /* rechedule AJAX interval */ + //havptimer = setInterval('havp_alerts_fetch_new_rules()', havpupdateDelay); +} +function havp_alerts_toggle_pause() { + if(havpisPaused) { + havpisPaused = false; + havp_alerts_fetch_new_rules(); + } else { + havpisPaused = true; + } +} +/* start local AJAX engine */ +havptimer = setInterval('havp_alerts_fetch_new_rules()', havpupdateDelay); |