function InitSession($num_vars) { // force loading profil and plugin list unset($_SESSION['ProfileList']); unset($_SESSION['PluginList']); GetProfiles(); GetPlugins(); $_SESSION['auto_filter'] = array(); DefaultFilters(); // make tab and profileinfo exist in _SESSION $_SESSION['tab'] = NULL; $_SESSION['profileswitch'] = NULL; // simulate a POST of tab and profileswitch $_POST['profileswitch'] = './live'; $_POST['tab'] = 2; $_POST['sub_tab'] = 0; // Empty bookmark $vars = array(); for ($i = 0; $i < $num_vars; $i++) { $vars[] = '-'; } $_SESSION['bookmark'] = urlencode(base64_encode(implode('|', $vars))); }
function Process_Details_tab($tab_changed, $profile_changed) { global $DisplayOrder; global $TypeOrder; global $ListNOption; global $TopNOption; global $IPStatOption; global $IPStatOrder; global $WinSizeScale; global $LimitScale; global $OutputFormatOption; $_SESSION['refresh'] = 0; unset($_SESSION['run']); if ($profile_changed || $tab_changed) { unset($_SESSION['detail_opts']); } // register 'get-detailsgraph' command for rrdgraph.php if (!array_key_exists('rrdgraph_cmds', $_SESSION) || !array_key_exists('get-detailsgraph', $_SESSION['rrdgraph_cmds'])) { $_SESSION['rrdgraph_cmds']['get-detailsgraph'] = 1; $_SESSION['rrdgraph_getparams']['profile'] = 1; } // process channels. 'channeltrigger' is a hidden field, always present to // trigger this block // put a compiled list into the POST array, which is scanned afterwards if (isset($_POST['srctrigger'])) { if (isset($_POST['MultipleSources'])) { if ($_POST['MultipleSources'] == 'All') { $_channels = get_channel_list(); if (!empty($_channels)) { $_POST['channellist'] = implode('!', $_channels); } else { $_POST['channellist'] = ''; } } else { $_POST['channellist'] = ''; } } else { $_channels = array(); foreach (array_keys($_SESSION['profileinfo']['channel']) as $channel) { if (array_key_exists($channel, $_POST)) { $_channels[] = $channel; } } $_POST['channellist'] = implode('!', $_channels); } } // move type from URL get to POST if (isset($_GET['type'])) { $_POST['type'] = Util::htmlentities($_GET['type']); } if (isset($_GET['proto'])) { $_POST['proto'] = Util::htmlentities($_GET['proto']); } if (isset($_COOKIE['statpref'])) { $_POST['statpref'] = Util::htmlentities($_COOKIE['statpref']); } if (isset($_COOKIE['statvisible'])) { $_POST['statvisible'] = Util::htmlentities($_COOKIE['statvisible']); } // to get the defaults in the parse_opts array if ($tab_changed || $profile_changed) { unset($_SESSION['detail_opts']); $detail_opts = array(); } else { $detail_opts = array_key_exists('detail_opts', $_SESSION) ? $_SESSION['detail_opts'] : array(); } //getting default channel list if (!empty($detail_opts['channellist'])) { $default_chanellist = $detail_opts['channellist']; } else { $_channels = get_channel_list(); $default_chanellist = implode('!', $_channels); } // process form data $parse_opts = array("type" => array("required" => 0, "default" => array_key_exists('type', $detail_opts) ? $detail_opts['type'] : 'flows', "allow_null" => 0, "match" => $TypeOrder, "validate" => NULL), "proto" => array("required" => 0, "default" => array_key_exists('proto', $detail_opts) ? $detail_opts['proto'] : 'any', "allow_null" => 0, "match" => $DisplayOrder, "validate" => NULL), "wsize" => array("required" => 0, "default" => array_key_exists('wsize', $detail_opts) ? $detail_opts['wsize'] : 1, "allow_null" => 0, "match" => range(0, count($WinSizeScale) - 1), "validate" => NULL), "ratescale" => array("required" => 0, "default" => array_key_exists('ratescale', $detail_opts) ? $detail_opts['ratescale'] : 1, "allow_null" => 0, "match" => array(0, 1), "validate" => NULL), "logscale" => array("required" => 0, "default" => array_key_exists('logscale', $detail_opts) ? $detail_opts['logscale'] : 0, "allow_null" => 0, "match" => array(0, 1), "validate" => NULL), "linegraph" => array("required" => 0, "default" => array_key_exists('linegraph', $detail_opts) ? $detail_opts['linegraph'] : 0, "allow_null" => 0, "match" => array(0, 1), "validate" => NULL), "cursor_mode" => array("required" => 0, "default" => array_key_exists('cursor_mode', $detail_opts) ? $detail_opts['cursor_mode'] : 1, "allow_null" => 0, "match" => array(0, 1), "validate" => NULL), "channellist" => array("required" => 0, "default" => $default_chanellist, "allow_null" => 1, "match" => "/^[a-zA-Z0-9\\-\\!]*\$/", "validate" => 'channellist_validate'), "statpref" => array("required" => 0, "default" => '0:0:0', "allow_null" => 0, "match" => "/^[0-5]:[0-5]:[0-5]\$/", "validate" => NULL), "statvisible" => array("required" => 0, "default" => 1, "allow_null" => 0, "match" => array(0, 1), "validate" => NULL)); list($detail_opts, $has_errors) = ParseForm($parse_opts); //if ( $has_errors ) // return; $_SESSION['detail_opts'] = $detail_opts; // for bookmarking only $_SESSION['channellist'] = $detail_opts['channellist']; // set cookie for javascript functions $_COOKIE['statpref'] = $detail_opts['statpref']; $_COOKIE['statvisible'] = $detail_opts['statvisible']; if ($tab_changed || $profile_changed || isset($_POST['wsize']) || (!isset($_SESSION['tend']) || !isset($_SESSION['tleft']) || !isset($_SESSION['tright']))) { $_SESSION['tend'] = $_SESSION['profileinfo']['tend']; if ($_SESSION['tend'] - 43200 < $_SESSION['profileinfo']['tstart']) { // the middle of the graph is outside the profile, so set the mark // to the beginning of the profile $_SESSION['tleft'] = $_SESSION['profileinfo']['tstart']; } else { $scale = $WinSizeScale[$detail_opts['wsize']]; // set the tleft to the middle of the graph $_SESSION['tleft'] = $_SESSION['tend'] - 14400 * $scale; } //$_SESSION['tright'] = $_SESSION['tleft']; $_SESSION['tright'] = $_SESSION['tend']; if (!array_key_exists('DefaultFilters', $_SESSION)) { DefaultFilters(); } $_SESSION['process_form'] = array(); } TimeSlotUpdate($detail_opts); // process the input data from the netflow processing form // to get the defaults in the parse_opts array if (array_key_exists('process', $_POST)) { $process_form = array(); } else { $process_form = array_key_exists('process_form', $_SESSION) ? $_SESSION['process_form'] : array(); } $default_selector = array(); if (is_array($process_form['srcselector'])) { $default_selector = $process_form['srcselector']; } else { if (!empty($process_form['srcselector'])) { $default_selector[] = $process_form['srcselector']; } } if (empty($default_selector)) { if (!empty($detail_opts['channellist'])) { $default_selector = explode('!', $detail_opts['channellist']); } } $parse_opts = array("modeselect" => array("required" => 0, "default" => array_key_exists('modeselect', $process_form) ? $process_form['modeselect'] : 0, "allow_null" => 0, "match" => array(0, 1), "validate" => NULL), "srcselector" => array("required" => 0, "default" => $default_selector, "allow_null" => 1, "match" => null, "validate" => 'srcselector_validate'), "DefaultFilter" => array("required" => 0, "default" => -1, "allow_null" => 0, "match" => array_merge(array(-1), array_keys($_SESSION['DefaultFilters'])), "validate" => NULL), "filter" => array("required" => 0, "default" => array_key_exists('filter', $process_form) ? implode("\n", $process_form['filter']) : NULL, "allow_null" => 1, "match" => "/^[\\s!-~]*\$/", "validate" => 'filter_validate'), "filter_name" => array("required" => 0, "default" => '', "allow_null" => 0, "match" => "/^\$|^[A-Za-z0-9\\.][A-Za-z0-9\\-+_\\/]+\$/", "validate" => NULL), "filter_edit" => array("required" => 0, "default" => null, "allow_null" => 1, "match" => array_merge(array(null), array_keys($_SESSION['DefaultFilters'])), "validate" => NULL), "filter_delete" => array("required" => 0, "default" => null, "allow_null" => 1, "match" => array_merge(array(null), array_keys($_SESSION['DefaultFilters'])), "validate" => NULL), "listN" => array("required" => 0, "default" => array_key_exists('listN', $process_form) ? $process_form['listN'] : 0, "allow_null" => 0, "match" => range(0, count($ListNOption) - 1), "validate" => NULL), "aggr_bidir" => array("required" => 0, "default" => array_key_exists('aggr_bidir', $process_form) ? $process_form['aggr_bidir'] : '', "allow_null" => 0, "match" => array('', 'checked'), "validate" => NULL), "aggr_proto" => array("required" => 0, "default" => array_key_exists('aggr_proto', $process_form) ? $process_form['aggr_proto'] : '', "allow_null" => 0, "match" => array('', 'checked'), "validate" => NULL), "aggr_srcip" => array("required" => 0, "default" => array_key_exists('aggr_srcip', $process_form) ? $process_form['aggr_srcip'] : '', "allow_null" => 0, "match" => array('', 'checked'), "validate" => NULL), "aggr_srcport" => array("required" => 0, "default" => array_key_exists('aggr_srcport', $process_form) ? $process_form['aggr_srcport'] : '', "allow_null" => 0, "match" => array('', 'checked'), "validate" => NULL), "aggr_dstip" => array("required" => 0, "default" => array_key_exists('aggr_dstip', $process_form) ? $process_form['aggr_dstip'] : '', "allow_null" => 0, "match" => array('', 'checked'), "validate" => NULL), "aggr_dstport" => array("required" => 0, "default" => array_key_exists('aggr_dstport', $process_form) ? $process_form['aggr_dstport'] : '', "allow_null" => 0, "match" => array('', 'checked'), "validate" => NULL), "aggr_srcselect" => array("required" => 0, "default" => array_key_exists('aggr_srcselect', $process_form) ? $process_form['aggr_srcselect'] : 0, "allow_null" => 0, "match" => array(0, 1, 2), "validate" => NULL), "aggr_dstselect" => array("required" => 0, "default" => array_key_exists('aggr_dstselect', $process_form) ? $process_form['aggr_dstselect'] : 0, "allow_null" => 0, "match" => array(0, 1, 2), "validate" => NULL), "aggr_srcnetbits" => array("required" => 0, "default" => array_key_exists('aggr_srcnetbits', $process_form) ? $process_form['aggr_srcnetbits'] : 24, "allow_null" => 0, "match" => "/^[0-9]+\$/", "validate" => NULL), "aggr_dstnetbits" => array("required" => 0, "default" => array_key_exists('aggr_dstnetbits', $process_form) ? $process_form['aggr_dstnetbits'] : 24, "allow_null" => 0, "match" => "/^[0-9]+\$/", "validate" => NULL), "timesorted" => array("required" => 0, "default" => array_key_exists('timesorted', $process_form) ? $process_form['timesorted'] : '', "allow_null" => 0, "match" => array('', 'checked'), "validate" => NULL), "IPv6_long" => array("required" => 0, "default" => array_key_exists('IPv6_long', $process_form) ? $process_form['IPv6_long'] : '', "allow_null" => 0, "match" => array('', 'checked'), "validate" => NULL), "output" => array("required" => 0, "default" => array_key_exists('output', $process_form) ? $process_form['output'] : 'extended', "allow_null" => 0, "match" => array_key_exists('formatlist', $_SESSION) ? array_keys($_SESSION['formatlist']) : array('extended'), "validate" => NULL), "customfmt" => array("required" => 0, "default" => array_key_exists('customfmt', $process_form) ? $process_form['customfmt'] : '', "allow_null" => 1, "match" => "/^\$|^[\\s!-~]+\$/", "validate" => NULL), "fmt_save" => array("required" => 0, "default" => array_key_exists('fmt_save', $process_form) ? $process_form['fmt_save'] : '', "allow_null" => 0, "match" => "/^\$|^[A-Za-z0-9\\.][A-Za-z0-9\\-+_\\/]+\$/", "validate" => NULL), "fmt_delete" => array("required" => 0, "default" => array_key_exists('fmt_delete', $process_form) ? $process_form['fmt_delete'] : '', "allow_null" => 0, "match" => "/^\$|^[A-Za-z0-9\\.][A-Za-z0-9\\-+_\\/]+\$/", "validate" => NULL), "topN" => array("required" => 0, "default" => array_key_exists('topN', $process_form) ? $process_form['topN'] : 0, "allow_null" => 0, "match" => range(0, count($TopNOption) - 1), "validate" => NULL), "stattype" => array("required" => 0, "default" => array_key_exists('stattype', $process_form) ? $process_form['stattype'] : 1, "allow_null" => 0, "match" => range(0, count($IPStatOption) - 1), "validate" => NULL), "statorder" => array("required" => 0, "default" => array_key_exists('statorder', $process_form) ? $process_form['statorder'] : 0, "allow_null" => 0, "match" => range(0, count($IPStatOrder) - 1), "validate" => NULL), "limitoutput" => array("required" => 0, "default" => array_key_exists('limitoutput', $process_form) ? $process_form['limitoutput'] : '', "allow_null" => 0, "match" => array('', 'checked'), "validate" => NULL), "limitwhat" => array("required" => 0, "default" => array_key_exists('limitwhat', $process_form) ? $process_form['limitwhat'] : '', "allow_null" => 0, "match" => array(0, 1), "validate" => NULL), "limithow" => array("required" => 0, "default" => array_key_exists('limithow', $process_form) ? $process_form['limithow'] : 0, "allow_null" => 0, "match" => array(0, 1), "validate" => NULL), "limitsize" => array("required" => 0, "default" => array_key_exists('limitsize', $process_form) ? $process_form['limitsize'] : 0, "allow_null" => 0, "match" => "/^[0-9]+\$/", "validate" => NULL), "limitscale" => array("required" => 0, "default" => array_key_exists('limitscale', $process_form) ? $process_form['limitscale'] : 0, "allow_null" => 0, "match" => range(0, count($LimitScale) - 1), "validate" => NULL)); list($process_form, $has_errors) = ParseForm($parse_opts); $_SESSION['process_form'] = $process_form; //if ( $has_errors ) // return; if (array_key_exists('fmt_save', $_POST)) { if (!get_magic_quotes_gpc()) { $cmd_opts['formatdef'] = addslashes($process_form['customfmt']); } else { $cmd_opts['formatdef'] = $process_form['customfmt']; } $cmd_opts['format'] = $process_form['fmt_save']; $cmd_opts['overwrite'] = 1; $cmd_out = nfsend_query("add-format", $cmd_opts, 0); if (is_array($cmd_out)) { unset($_SESSION['formatlist']); $_SESSION['process_form']['output'] = $process_form['fmt_save']; } } if (array_key_exists('fmt_delete', $_POST)) { $_tmp = Util::htmlentities($_POST['fmt_delete']); if (array_key_exists($_tmp, $OutputFormatOption)) { SetMessage('error', "Can not delete built in format '{$_tmp}'"); } else { if (!array_key_exists($_tmp, $_SESSION['formatlist'])) { SetMessage('error', "Unknon format '{$_tmp}'"); } else { $cmd_opts['format'] = $_tmp; $cmd_out = nfsend_query("delete-format", $cmd_opts, 0); unset($_SESSION['formatlist']); $_SESSION['process_form']['output'] = $parse_opts['output']['default']; } } } if (!array_key_exists('formatlist', $_SESSION)) { foreach ($OutputFormatOption as $opt) { $_SESSION['formatlist'][$opt] = $opt; } $cmd_out = nfsend_query("get-formatlist", array(), 0); if (is_array($cmd_out)) { foreach ($cmd_out as $key => $value) { $_SESSION['formatlist'][$key] = $value; } } $_SESSION['formatlist']['custom ...'] = 0; } if (array_key_exists('filter_save_x', $_POST)) { $cmd_opts['filtername'] = $process_form['filter_name']; $cmd_opts['overwrite'] = 1; $cmd_opts['filter'] = $process_form['filter']; $cmd_out = nfsend_query("add-filter", $cmd_opts, 0); if (is_array($cmd_out)) { unset($_SESSION['DefaultFilters']); $_SESSION['process_form']['DefaultFilter'] = -1; $_SESSION['process_form']['filter'] = array(); } } if (array_key_exists('filter_edit_x', $_POST)) { $cmd_opts['filter'] = $process_form['filter_name']; $cmd_out = nfsend_query("get-filter", $cmd_opts, 0); if (is_array($cmd_out)) { $_SESSION['process_form']['editfilter'] = $cmd_out['filter']; } $_SESSION['anchor'] = '#processing'; } if (array_key_exists('filter_delete_x', $_POST)) { $cmd_opts['filtername'] = $process_form['filter_name']; $cmd_out = nfsend_query("delete-filter", $cmd_opts, 0); if (is_array($cmd_out)) { unset($_SESSION['DefaultFilters']); $_SESSION['process_form']['DefaultFilter'] = -1; } } if (count(array_diff($_SESSION['process_form']['filter'], $_SESSION['auto_filter'])) == 0) { if ($_SESSION['detail_opts']['proto'] == 'any') { $_SESSION['process_form']['filter'] = array(); } else { if ($_SESSION['detail_opts']['proto'] == 'other') { $_SESSION['process_form']['filter'] = array('not (proto tcp or proto udp or proto icmp or proto icmp6)'); } else { $_SESSION['process_form']['filter'] = array('proto ' . $_SESSION['detail_opts']['proto']); } } $_SESSION['auto_filter'] = $_SESSION['process_form']['filter']; } else { $_SESSION['auto_filter'] = array(); } DefaultFilters(); if (array_key_exists('process', $_POST)) { $run = CompileCommand($process_form['modeselect']); $_SESSION['anchor'] = '#processing'; } else { $run = null; } $_SESSION['run'] = $run; }