diff --git a/CHANGELOG.md b/CHANGELOG.md index 972da39..f2160f1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,6 +35,7 @@ * feature: Support IPv4 and IPv6 * feature: Support daily and hourly partitioning * feature: Run Schedules in Background +* feature: Allow Saving of some Filter Information from Flowview --- 2.1 --- * issue: Prepare for sunrise theme in 1.1.17 diff --git a/flowview.php b/flowview.php index 460be62..f25f9ec 100644 --- a/flowview.php +++ b/flowview.php @@ -36,6 +36,9 @@ case 'save': save_filter(); break; + case 'savefilter': + save_filter_form(); + break; case 'sort_filter': sort_filter(); break; @@ -183,20 +186,8 @@ function load_session_for_filter() { function flowview_request_vars() { /* ================= input validation and session storage ================= */ $filters = array( - 'includeif' => array( - 'filter' => FILTER_VALIDATE_INT, - 'default' => '1' - ), - 'statistics' => array( - 'filter' => FILTER_VALIDATE_INT, - 'default' => '0' - ), - 'printed' => array( - 'filter' => FILTER_VALIDATE_INT, - 'default' => '0' - ), 'sortfield' => array( - 'filter' => FILTER_DEFAULT, + 'filter' => FILTER_VALIDATE_INT, 'default' => '' ), 'sortvalue' => array( @@ -217,11 +208,6 @@ function flowview_request_vars() { 'filter' => FILTER_VALIDATE_INT, 'default' => '1000000' ), - 'device' => array( - 'filter' => FILTER_CALLBACK, - 'options' => array('options' => 'sanitize_search_string'), - 'default' => '0' - ), 'predefined_timespan' => array( 'filter' => FILTER_VALIDATE_INT, 'default' => read_user_setting('default_timespan') @@ -240,56 +226,6 @@ function flowview_request_vars() { 'options' => array('options' => 'sanitize_search_string'), 'default' => '' ), - 'protocols' => array( - 'filter' => FILTER_VALIDATE_IS_NUMERIC_ARRAY, - 'default' => array() - ), - 'includeif' => array( - 'filter' => FILTER_VALIDATE_INT, - 'default' => '' - ), - 'tcpflags' => array( - 'filter' => FILTER_VALIDATE_IS_NUMERIC_LIST, - 'default' => '' - ), - 'tosfields' => array( - 'filter' => FILTER_VALIDATE_IS_NUMERIC_LIST, - 'default' => '' - ), - 'sourceip' => array( - 'filter' => FILTER_CALLBACK, - 'options' => array('options' => 'sanitize_search_string'), - 'default' => '' - ), - 'sourceport' => array( - 'filter' => FILTER_VALIDATE_IS_NUMERIC_LIST, - 'default' => '' - ), - 'sourceinterface' => array( - 'filter' => FILTER_VALIDATE_IS_NUMERIC_LIST, - 'default' => '' - ), - 'sourceas' => array( - 'filter' => FILTER_VALIDATE_IS_NUMERIC_LIST, - 'default' => '' - ), - 'destip' => array( - 'filter' => FILTER_CALLBACK, - 'options' => array('options' => 'sanitize_search_string'), - 'default' => '' - ), - 'destport' => array( - 'filter' => FILTER_VALIDATE_IS_NUMERIC_LIST, - 'default' => '' - ), - 'destinterface' => array( - 'filter' => FILTER_VALIDATE_IS_NUMERIC_LIST, - 'default' => '' - ), - 'destas' => array( - 'filter' => FILTER_VALIDATE_IS_NUMERIC_LIST, - 'default' => '' - ), 'domains' => array( 'filter' => FILTER_VALIDATE_REGEXP, 'options' => array('options' => array('regexp' => '(true|false)')), @@ -314,11 +250,6 @@ function flowview_request_vars() { 'filter' => FILTER_VALIDATE_REGEXP, 'options' => array('options' => array('regexp' => '(true|false)')), 'default' => 'false' - ), - 'resolve' => array( - 'filter' => FILTER_VALIDATE_REGEXP, - 'options' => array('options' => array('regexp' => '(Y|N|true|false)')), - 'default' => 'true' ) ); diff --git a/functions.php b/functions.php index b38c357..06c86ea 100644 --- a/functions.php +++ b/functions.php @@ -145,7 +145,6 @@ function applyTimespan() { $.getJSON(returnPage+'?action=gettimespan&predefined_timespan='+$('#predefined_timespan').val(), function(data) { $('#date1').val(data['current_value_date1']); $('#date2').val(data['current_value_date2']); - Pace.stop(); }); } @@ -247,6 +246,31 @@ function changeRType() { 0 ? '&id='+$('#query').val():'') + @@ -696,7 +724,7 @@ function flowview_display_filter($data) { } } - $('#table').unbind('click').click(function() { + $('#table').off('click').on('click', function() { updateSession(); if (!$('#table').is(':checked')) { @@ -832,6 +860,7 @@ function flowview_display_filter($data) { case 'chartbytes': $.getJSON('flowview.php?action=chartdata&type=bytes' + '&domains=' + $('#domains').is(':checked') + + '&query=' + $('#query').val() + '&report=' + $('#report').val() + '&sortfield=' + ($('#sortfield').val() != '' ? $('#sortfield').val():'') + '&sortvalue=' + ($('#sortfield').val() != '' ? $('#sortfield option:selected').html():'Bytes') + @@ -839,8 +868,7 @@ function flowview_display_filter($data) { '&cutoffoctets=' + $('#cutoffoctets').val() + '&exclude=' + $('#exclude').val() + '&date1=' + $('#date1').val() + - '&date2=' + $('#date2').val() + - '&query=' + $('#query').val(), function(data) { + '&date2=' + $('#date2').val(), function(data) { var chartBytes = c3.generate({ bindto: '#chartbytes', @@ -888,6 +916,7 @@ function flowview_display_filter($data) { case 'chartflows': $.getJSON('flowview.php?action=chartdata&type=flows' + '&domains=' + $('#domains').is(':checked') + + '&query=' + $('#query').val() + '&report=' + $('#report').val() + '&sortfield=' + ($('#sortfield').val() != '' ? $('#sortfield').val():'') + '&sortvalue=' + ($('#sortfield').val() != '' ? $('#sortfield option:selected').html():'Bytes') + @@ -895,8 +924,7 @@ function flowview_display_filter($data) { '&cutoffoctets=' + $('#cutoffoctets').val() + '&exclude=' + $('#exclude').val() + '&date1=' + $('#date1').val() + - '&date2=' + $('#date2').val() + - '&query=' + $('#query').val(), function(data) { + '&date2=' + $('#date2').val(), function(data) { var chartFlows = c3.generate({ bindto: '#chartflows', @@ -944,6 +972,7 @@ function flowview_display_filter($data) { case 'chartpackets': $.getJSON('flowview.php?action=chartdata&type=packets' + '&domains=' + $('#domains').is(':checked') + + '&query=' + $('#query').val() + '&report=' + $('#report').val() + '&sortfield=' + ($('#sortfield').val() != '' ? $('#sortfield').val():'') + '&sortvalue=' + ($('#sortfield').val() != '' ? $('#sortfield option:selected').html():'Bytes') + @@ -951,8 +980,7 @@ function flowview_display_filter($data) { '&cutoffoctets=' + $('#cutoffoctets').val() + '&exclude=' + $('#exclude').val() + '&date1=' + $('#date1').val() + - '&date2=' + $('#date2').val() + - '&query=' + $('#query').val(), function(data) { + '&date2=' + $('#date2').val(), function(data) { var chartPackets = c3.generate({ bindto: '#chartpackets', @@ -1031,6 +1059,23 @@ function numFormatter(num) { return num.toFixed(2) + ' ' + suffix; } + function saveFilter() { + $.get(urlPath + 'plugins/flowview/flowview.php' + + '?action=savefilter' + + '&query=' + $('#query').val() + + '&domains=' + $('#domains').is(':checked') + + '&query=' + $('#query').val() + + '×pan=' + $('#predefined_timespan').val() + + '&report=' + report + + '&sortfield=' + ($('#sortfield').val() != '' ? $('#sortfield').val():'') + + '&sortvalue=' + ($('#sortfield').val() != '' ? $('#sortfield option:selected').html():'Bytes') + + '&cutofflines=' + $('#cutofflines').val() + + '&cutoffoctets=' + $('#cutoffoctets').val() + + '&exclude=' + $('#exclude').val(), function() { + Pace.stop(); + }); + } + function updateSession() { $.get(urlPath + 'plugins/flowview/flowview.php' + '?action=updatesess' + @@ -1050,8 +1095,6 @@ function initTimespan() { '&predefined_timespan='+$('#predefined_timespan').val(), function(data) { $('#date1').val(data['current_value_date1']); $('#date2').val(data['current_value_date2']); - - Pace.stop(); }); } } @@ -1065,8 +1108,6 @@ function applyTimespan() { $('#date1').val(data['current_value_date1']); $('#date2').val(data['current_value_date2']); applyFilter(); - - Pace.stop(); }); } } @@ -1081,6 +1122,7 @@ function applyFilter(reset) { loadPageNoHeader(urlPath+'plugins/flowview/flowview.php' + '?action=view' + '&domains=' + $('#domains').is(':checked') + + '&query=' + $('#query').val() + '×pan=' + $('#predefined_timespan').val() + '&report=' + report + '&sortfield=' + ($('#sortfield').val() != '' ? $('#sortfield').val():'') + @@ -1090,7 +1132,6 @@ function applyFilter(reset) { '&exclude=' + $('#exclude').val() + '&date1=' + $('#date1').val() + '&date2=' + $('#date2').val() + - '&query=' + $('#query').val() + '&header=false'); } @@ -1646,6 +1687,61 @@ function run_flow_query($session, $query_id, $start, $end) { $sql_having = ''; } + /* source ip filter */ + if ($data['sourceip'] != '') { + $sql_where = get_ip_filter($sql_where, $data['sourceip'], 'src_addr'); + } + + /* source interface filter */ + if ($data['sourceinterface'] != '') { + $sql_where = get_numeric_filter($sql_where, $data['sourceinterface'], 'src_if'); + } + + /* source port filter */ + if ($data['sourceport'] != '') { + $sql_where = get_numeric_filter($sql_where, $data['sourceport'], 'src_port'); + } + + /* source as filter */ + if ($data['sourceas'] != '') { + $sql_where = get_numeric_filter($sql_where, $data['sourceas'], 'src_as'); + } + + /* destination ip filter */ + if ($data['destip'] != '') { + $sql_where = get_ip_filter($sql_where, $data['destip'], 'dst_addr'); + } + + /* destination interface filter */ + if ($data['destinterface'] != '') { + $sql_where = get_numeric_filter($sql_where, $data['destinterface'], 'dst_if'); + } + + /* destination port filter */ + if ($data['destport'] != '') { + $sql_where = get_numeric_filter($sql_where, $data['destport'], 'dst_port'); + } + + /* destination as filter */ + if ($data['destas'] != '') { + $sql_where = get_numeric_filter($sql_where, $data['destas'], 'dst_as'); + } + + /* protocols filter */ + if ($data['protocols'] != '' && $data['protocols'] != '0') { + $sql_where = get_numeric_filter($sql_where, $data['protocols'], 'protocol'); + } + + /* tcp flags filter */ + if ($data['tcpflags'] != '') { + $sql_where = get_numeric_filter($sql_where, $data['tcpflags'], 'flags'); + } + + /* tos filter */ + if ($data['tosfields'] != '') { + $sql_where = get_numeric_filter($sql_where, $data['tosfields'], 'tos'); + } + // Handle Report Override if (isset_request_var('report') && trim(get_nfilter_request_var('report'), 'sp') != 0) { if (substr(get_nfilter_request_var('report'), 0, 1) == 's') {