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; }
function Process_stat_tab($tab_changed, $profile_changed) { // the default display page - the profile stats $_SESSION['display'] = 'default'; // if it's a new profile, only admin tasks make sense // no refresh if ($_SESSION['profileinfo']['status'] == 'new') { $_SESSION['tablock'] = "A new profile needs to be completed first."; } else { unset($_SESSION['tablock']); } if (isset($_COOKIE['extended_channellist'])) { $_POST['extended_channellist'] = $_COOKIE['extended_channellist']; } $parse_opts = array("extended_channellist" => array("required" => 0, "default" => 1, "allow_null" => 0, "match" => array(0, 1), "validate" => NULL)); list($form_data, $has_errors) = ParseForm($parse_opts); $_COOKIE['extended_channellist'] = $form_data['extended_channellist']; // just display profile status if ($tab_changed || $profile_changed) { unset($_SESSION['form_data']); return; } // Delete this profile - process confirmed action if (array_key_exists('deleteprofile_x', $_POST)) { $parse_opts = array("switch" => array("required" => 1, "default" => NULL, "allow_null" => 0, "match" => "/^[A-Za-z0-9\\.][A-Za-z0-9\\-+_\\/]+\$/", "validate" => "profile_exists_validate", "must_exist" => 1)); list($form_data, $has_errors) = ParseForm($parse_opts); if ($has_errors > 0) { return; } if ($form_data['switch'] != $_SESSION['profileswitch']) { SetMessage('error', "Profile to delete is not current profile"); return; } // Do the work $cmd_opts['profile'] = $_SESSION['profileswitch']; if (array_key_exists('pid', $_SESSION)) { $cmd_opts['pid'] = $_SESSION['pid']; } $cmd_out = nfsend_query("delete-profile", $cmd_opts, 0); if (is_array($cmd_out)) { SetMessage('info', "Profile '" . $cmd_opts['profile'] . "' deleted"); unset($_SESSION['ProfileList']); $profiles = GetProfiles(); // as current profile no longer exists, switch to 'live' $_SESSION['profile'] = 'live'; $_SESSION['profilegroup'] = '.'; $_SESSION['profileswitch'] = './live'; $profileinfo = ReadProfile($_SESSION['profileswitch']); $_SESSION['profileinfo'] = $profileinfo; } // else errors are displayed anyway - nothing to do return; } // Cancel building the profile if (array_key_exists('cancelbuild_x', $_POST)) { $parse_opts = array("switch" => array("required" => 1, "default" => NULL, "allow_null" => 0, "match" => "/^[A-Za-z0-9\\.][A-Za-z0-9\\-+_\\/]+\$/", "validate" => "profile_exists_validate", "must_exist" => 1)); list($form_data, $has_errors) = ParseForm($parse_opts); if ($has_errors > 0) { return; } if ($form_data['switch'] != $_SESSION['profileswitch']) { SetMessage('error', "Profile to delete is not current profile"); return; } // Do the work $cmd_opts['profile'] = $_SESSION['profileswitch']; $cmd_out = nfsend_query("cancel-profile", $cmd_opts, 0); if (is_array($cmd_out)) { SetMessage('info', "Building profile '" . $cmd_opts['profile'] . "' canceled"); $profiles = GetProfiles(); $_SESSION['cancel-inprogress'] = 1; } // else errors are displayed anyway - nothing to do $_SESSION['refresh'] = 5; return; } // put profile into another group? if (array_key_exists('regroup', $_POST)) { if (!array_key_exists('groupselect', $_POST) || !array_key_exists('profilegroup', $_POST)) { SetMessage('error', "Missing parameters"); return; } $_group = Util::htmlentities($_POST['groupselect']); if ($_group == '(nogroup)') { $_group = '.'; } else { if ($_group == 'New group ...') { $_group = Util::htmlentities($_POST['profilegroup']); } } if ($_group != '.' && !preg_match("/^[A-Za-z0-9][A-Za-z0-9\\-+_]+\$/", $_group)) { SetMessage('error', "Illegal characters in group name '{$_group}'"); return; } else { $cmd_opts['profile'] = $_SESSION['profile']; $cmd_opts['profilegroup'] = $_SESSION['profilegroup']; $cmd_opts['newgroup'] = $_group; } if ($cmd_opts['profilegroup'] == $cmd_opts['newgroup']) { // nothing changed return; } // Do the work $cmd_out = nfsend_query("modify-profile", $cmd_opts, 0); if (is_array($cmd_out)) { // update new info in SESSION $_SESSION['profilegroup'] = $cmd_opts['newgroup']; $_SESSION['profileswitch'] = $cmd_opts['newgroup'] . '/' . $_SESSION['profile']; $profileinfo = ReadProfile($_SESSION['profileswitch']); $_SESSION['profileinfo'] = $profileinfo; unset($_SESSION['ProfileList']); $profiles = GetProfiles(); } // else errors are displayed anyway - nothing to do return; } // Edit a profile if (array_key_exists('edit', $_POST)) { $cmd_opts = array(); if (array_key_exists('profile_maxsize', $_POST)) { $_tmp = ParseMaxSize($_POST['profile_maxsize']); if (strlen($_tmp) > 0) { $cmd_opts['maxsize'] = $_tmp; } else { SetMessage('warning', "Invalid value for maxsize"); } } if (array_key_exists('profile_expire', $_POST)) { $_tmp = ParseExpire($_POST['profile_expire']); if ($_tmp >= 0) { $cmd_opts['expire'] = $_tmp; } else { SetMessage('warning', "Invalid value for expire"); } } if (array_key_exists('description', $_POST)) { $_tmp = preg_replace("/\r/", '', $_POST['description']); if (!get_magic_quotes_gpc()) { $description = addslashes($_tmp); } else { $description = $_tmp; } $cmd_opts['description'] = explode("\n", $description); } if (array_key_exists('profile_type', $_POST)) { $_tmp = $_POST['profile_type']; if (!is_numeric($_tmp) || $_tmp > 6) { SetMessage('warning', "Invalid value for profile_type"); } else { if ($_SESSION['profileinfo']['type'] != $_tmp) { $cmd_opts['profile_type'] = $_tmp; } } } if (count(array_keys($cmd_opts)) > 0) { $cmd_opts['profile'] = $_SESSION['profileswitch']; // Do the work $cmd_out = nfsend_query("modify-profile", $cmd_opts, 0); if (is_array($cmd_out)) { $profileinfo = ReadProfile($_SESSION['profileswitch']); $_SESSION['profileinfo'] = $profileinfo; } } return; } // Cancel an edit or add a channel dialog if (array_key_exists('edit_channel_cancel', $_POST) || array_key_exists('add_channel_cancel', $_POST)) { // nothing to do - default will do return; } // Add a new channel - provide add dialog if (array_key_exists('add_channel_x', $_POST)) { $_POST['add_channel'] = $_POST['add_channel_x']; } if (array_key_exists('add_channel', $_POST)) { $_SESSION['display'] = 'add_channel'; $_SESSION['refresh'] = 0; return; } // edit a channel - provide edit dialog if (array_key_exists('edit_channel', $_POST)) { $parse_opts = array("edit_channel" => array("required" => 1, "default" => NULL, "allow_null" => 0, "match" => "/^[A-Za-z0-9][A-Za-z0-9\\-+_]+\$/", "validate" => NULL)); list($form_data, $has_errors) = ParseForm($parse_opts); $form_data['profileswitch'] = $_SESSION['profileswitch']; if ($has_errors > 0) { return; } $_channel = $form_data['edit_channel']; if (!array_key_exists($_channel, $_SESSION['profileinfo']['channel'])) { SetMessage('error', "Channel '{$_channel}' does not exists in profile '" . $form_data['profile'] . "'"); return; } $_SESSION['form_data'] = $form_data; $_SESSION['refresh'] = 0; $_SESSION['display'] = 'edit_channel'; return; } // edit or add a channel? - process commited form entries if (array_key_exists('edit_channel_commit', $_POST) || array_key_exists('add_channel_commit', $_POST)) { if (array_key_exists('edit_channel_commit', $_POST)) { $_display = "edit_channel"; } else { $_display = "add_channel"; } $_SESSION['refresh'] = 0; $parse_opts = array("name" => array("required" => 1, "default" => NULL, "allow_null" => 0, "match" => "/^[A-Za-z0-9][A-Za-z0-9\\-+_]*\$/", "validate" => NULL), "colour" => array("required" => 1, "default" => NULL, "allow_null" => 0, "match" => "/^#[0-9a-f]{6}/i", "validate" => NULL), "sign" => array("required" => 1, "default" => '+', "allow_null" => 0, "match" => array('+', '-'), "validate" => NULL), "order" => array("required" => 1, "default" => 1, "allow_null" => 0, "match" => "/^[0-9]{1,2}/", "validate" => NULL), "filter" => array("required" => 1, "default" => NULL, "allow_null" => 0, "match" => "/^[\\s!-~]+\$/", "validate" => 'filter_validate'), "configured" => array("required" => 1, "default" => array(), "allow_null" => 0, "match" => NULL, "validate" => 'channel_validate')); list($form_data, $has_errors) = ParseForm($parse_opts); $form_data['profile'] = $_SESSION['profile']; $form_data['profilegroup'] = $_SESSION['profilegroup']; // additional checks if (!is_null($form_data['name'])) { $_channel = $form_data['name']; if ($_display == "edit_channel") { // verify channel in existing profile if (!array_key_exists($_channel, $_SESSION['profileinfo']['channel'])) { SetMessage('error', "Channel '{$_channel}' does not exist in profile '{$profile}'"); $has_errors = 1; } } else { // verify channel name for new channel if (array_key_exists($_channel, $_SESSION['profileinfo']['channel'])) { SetMessage('error', "Channel '{$_channel}' already exist in profile '" . $_SESSION['profile'] . "'"); $has_errors = 1; } } } // else error already reported by ParseForm // must not change the sourcelist or the filter of a channel in profile 'live' if ($form_data['profile'] == 'live') { unset($form_data['sourcelist']); unset($form_data['filter']); } else { $form_data['sourcelist'] = implode('|', $form_data['configured']); } unset($form_data['configured']); $_SESSION['form_data'] = $form_data; if ($has_errors > 0) { $_SESSION['display'] = $_display; return; } // Do the work $command = $_display == 'add_channel' ? 'add-channel' : 'modify-channel'; // make sure parameters match for nfsend $form_data['channel'] = $form_data['name']; unset($form_data['name']); $cmd_out = nfsend_query($command, $form_data, 0); if (is_array($cmd_out)) { $profileinfo = ReadProfile($_SESSION['profileswitch']); $_SESSION['profileinfo'] = $profileinfo; unset($_SESSION['form_data']); } else { // fishy something went wrong $_SESSION['display'] = $_display; } return; } // delete a channel if (array_key_exists('delete_channel_commit_x', $_POST)) { if (!array_key_exists('name', $_POST)) { SetMessage('error', "Missing channel name"); return; } $profile = $_SESSION['profile']; $_channelname = $_POST['name']; if (!array_key_exists($_channelname, $_SESSION['profileinfo']['channel'])) { SetMessage('error', "Channel '{$_tmp}' does not exist in profile '{$profile}'"); return; } // do the work $cmd_opts['profile'] = $_SESSION['profileswitch']; $cmd_opts['channel'] = $_channelname; $cmd_out = nfsend_query("delete-channel", $cmd_opts, 0); if (is_array($cmd_out)) { $profileinfo = ReadProfile($_SESSION['profileswitch']); $_SESSION['profileinfo'] = $profileinfo; } return; } // Cancel a new profile dialog if (array_key_exists('new_profile_cancel', $_POST)) { if (array_key_exists("new_profile", $_SESSION)) { unset($_SESSION['new_profile']); } // default will do return; } // create a new profile - provide the new profile dialog // this input comes directly from the profile select menu if (array_key_exists('new_profile', $_SESSION)) { unset($_SESSION['new_profile']); $_SESSION['display'] = 'new_profile'; return; } // create a new profile - process commited form if (array_key_exists('new_profile_commit', $_POST)) { $parse_opts = array("newprofileswitch" => array("required" => 1, "default" => NULL, "allow_null" => 0, "match" => "/^[A-Za-z0-9\\.][A-Za-z0-9\\-+_\\/]+\$/", "validate" => "profile_exists_validate", "must_exist" => 0), "tstart" => array("required" => 1, "default" => NULL, "allow_null" => 1, "match" => "/^[0-9]+[0-9\\-]+[0-9]+\$/", "validate" => "date_time_validate"), "tend" => array("required" => 1, "default" => NULL, "allow_null" => 1, "match" => "/^[0-9]+[0-9\\-]+[0-9]+\$/", "validate" => "date_time_validate"), "channel_wizard" => array("required" => 1, "default" => NULL, "allow_null" => 0, "match" => array('classic', 'individual'), "validate" => NULL), "expire" => array("required" => 0, "default" => 0, "allow_null" => 0, "match" => "/^[\\s!-~]+\$/", "validate" => 'expire_validate'), "maxsize" => array("required" => 0, "default" => 0, "allow_null" => 0, "match" => "/^[\\s!-~]+\$/", "validate" => 'maxsize_validate'), "description" => array("required" => 0, "default" => NULL, "allow_null" => 1, "match" => "/^[\\s!-~]+\$/", "validate" => 'description_validate'), "filter" => array("required" => 0, "default" => NULL, "allow_null" => 1, "match" => "/^[\\s!-~]+\$/", "validate" => 'filter_validate'), "channel" => array("required" => 0, "default" => array(), "allow_null" => 1, "match" => NULL, "validate" => 'channel_validate'), "shadow" => array("required" => 1, "default" => 1, "allow_null" => 1, "match" => array(0, 1), "validate" => NULL), "num_channels" => array("required" => 0, "default" => 0, "allow_null" => 1, "match" => "/^[0-9]{1,3}\$/", "validate" => NULL)); list($form_data, $has_errors) = ParseForm($parse_opts); if (preg_match("/^(.+)\\/(.+)/", $form_data['newprofileswitch'], $matches)) { $_profilegroup = $matches[1]; $_profilename = $matches[2]; $form_data['profileswitch'] = $form_data['newprofileswitch']; $form_data['profile'] = $_profilename; $form_data['profilegroup'] = $_profilegroup; unset($form_data['newprofileswitch']); } else { $has_errors = 1; } // additional checks if (!is_null($form_data['tend']) && !is_null($form_data['tstart']) && $form_data['tend'] < $form_data['tstart']) { $ts = UNIX2DISPLAY($form_data['tstart']); $te = UNIX2DISPLAY($form_data['tend']); $form_data['tstart'] = NULL; $form_data['tend'] = NULL; SetMessage('error', "Profile end time '{$te}' earlier then Start time '{$ts}'"); $has_errors = 1; } if (!is_null($form_data['tend']) && is_null($form_data['tstart'])) { $te = UNIX2DISPLAY($form_data['tend']); SetMessage('error', "Profile has end time '{$te}', but no start time set"); $has_errors = 1; } if ($form_data['channel_wizard'] == 'classic') { if (is_null($form_data['filter']) || count($form_data['channel']) == 0) { SetMessage('error', "A classic profile needs a valid filter and at least one selected channel"); $has_errors = 1; } } if ($has_errors > 0) { $_SESSION['form_data'] = $form_data; $_SESSION['display'] = 'new_profile'; $_SESSION['refresh'] = 0; return; } // do the work if (array_key_exists('channel_wizard', $form_data)) { $type = $form_data['channel_wizard']; if (NewProfileCreate($form_data, $type) == TRUE) { // update NfSen to include the new profile unset($_SESSION['ProfileList']); $profiles = GetProfiles(); // switch to new profile $_SESSION['profileswitch'] = $form_data['profileswitch']; $_SESSION['profile'] = $form_data['profile']; $_SESSION['profilegroup'] = $form_data['profilegroup']; $_SESSION['profileinfo'] = ReadProfile($_SESSION['profileswitch']); SetMessage('info', "Profile '" . $form_data['profile'] . "' created"); // if ( $_SESSION['profileinfo']['type'] == 1 && $_SESSION['profileinfo']['status'] != 'new' ) if ($_SESSION['profileinfo']['tstart'] < $_SESSION['profileinfo']['tend']) { $_SESSION['refresh'] = 5; } } else { $_SESSION['form_data'] = $form_data; $_SESSION['display'] = 'new_profile'; } } return; } if (array_key_exists('commit_profile_x', $_POST)) { if ($_SESSION['profileinfo']['status'] != 'new' && $_SESSION['profileinfo']['status'] != 'stalled') { SetMessage('error', "Can not commit a profile, not in status 'new or stalled'"); return; } // Do the work // if it fails, the default will do if (NewProfileCommit($_SESSION['profileswitch'])) { $profileinfo = ReadProfile($_SESSION['profileswitch']); $_SESSION['profileinfo'] = $profileinfo; unset($_SESSION['tablock']); if ($_SESSION['profileinfo']['tstart'] < $_SESSION['profileinfo']['tend']) { $_SESSION['refresh'] = 5; } } return; } // refresh time if profile building in progress if (preg_match("/built/", $_SESSION['profileinfo']['status'])) { $_SESSION['refresh'] = 5; } }
function Process_alert_tab($tab_changed, $profile_changed) { global $num_ConditionList; global $ConditionList; global $num_ConditionList; global $ConditionList; global $ActionList; global $FlowStat_type; global $SumStat_type_options; global $SumStat_comp_type; global $SumStat_scale; // register 'get-alertgraph' command for rrdgraph.php if (!array_key_exists('rrdgraph_cmds', $_SESSION) || !array_key_exists('get-alertgraph', $_SESSION['rrdgraph_cmds'])) { $_SESSION['rrdgraph_cmds']['get-alertgraph'] = 1; $_SESSION['rrdgraph_getparams']['alert'] = 1; } $_SESSION['action'] = 'list'; // Delete an alert? if (array_key_exists('delete_alert_x', $_POST)) { $parse_opts = array("alert" => array("required" => 1, "default" => NULL, "allow_null" => 0, "match" => $_SESSION['alertlist'], "validate" => null, "must_exist" => 1)); list($form_data, $has_errors) = ParseForm($parse_opts); if ($has_errors) { return; } $cmd_out = nfsend_query("delete-alert", $form_data, 0); $_SESSION['action'] = 'list'; UpdateAlertList(); return; } // Arm the alert if (array_key_exists('arm_trigger_x', $_POST)) { $parse_opts = array("alert" => array("required" => 1, "default" => NULL, "allow_null" => 0, "match" => $_SESSION['alertlist'], "validate" => null, "must_exist" => 1)); list($form_data, $has_errors) = ParseForm($parse_opts); if ($has_errors) { return; } $cmd_out = nfsend_query("arm-alert", $form_data, 0); $_SESSION['action'] = 'list'; UpdateAlert($_SESSION['alertinfo']['name']); return; } // cancel a new alert dialog if (array_key_exists('new_alert_cancel', $_POST)) { $_SESSION['action'] = 'list'; return; } // provide the add new alert dialog? if (array_key_exists('new_alert_x', $_POST)) { $_SESSION['action'] = 'new'; $_SESSION['refresh'] = 0; // preset alert info for new alert $alertinfo['alert'] = ''; $alertinfo['type'] = 0; $alertinfo['visible_0'] = 1; $alertinfo['status'] = 'disabled'; $alertinfo['trigger_type'] = 0; $alertinfo['trigger_status'] = 0; $alertinfo['trigger_number'] = 0; $alertinfo['trigger_blocks'] = 0; $alertinfo['action_type'] = 0; $alertinfo['action_email'] = ''; $alertinfo['action_subject'] = 'Alert triggered'; $alertinfo['action_system'] = ''; $alertinfo['filter'] = array(); $alertinfo['channellist'] = implode('|', array_keys($_SESSION['profileinfo']['channel'])); for ($i = 0; $i < 2 * $num_ConditionList; $i++) { $alertinfo["visible_{$i}"] = 0; $alertinfo["op_{$i}"] = 0; $alertinfo["type_{$i}"] = 0; $alertinfo["comp_{$i}"] = 0; $alertinfo["comp_type_{$i}"] = 0; $alertinfo["stat_type_{$i}"] = 0; $alertinfo["comp_value_{$i}"] = 0; $alertinfo["scale_{$i}"] = 0; } $_SESSION['alertinfo'] = $alertinfo; // disable page refresh $_SESSION['refresh'] = 0; return; } // create the new alert $ModifyOrNew = NULL; if (array_key_exists('new_alert_commit_x', $_POST) || array_key_exists('new_alert_commit', $_POST)) { $ModifyOrNew = 'new'; } if (array_key_exists('edit_alert_commit', $_POST)) { $ModifyOrNew = 'modify'; } if ($ModifyOrNew != NULL) { $parse_opts = array("alert" => array("required" => 1, "default" => NULL, "allow_null" => 0, "match" => "/^[A-Za-z0-9][A-Za-z0-9\\-+_]*\$/", "validate" => 'alert_name_check', "must_exists" => $ModifyOrNew == 'modify'), "channellist" => array("required" => 0, "default" => '', "allow_null" => 0, "match" => null, "validate" => 'channellist_validate'), "filter" => array("required" => 0, "default" => NULL, "allow_null" => 1, "match" => "/^[\\s!-~]*\$/", "validate" => 'filter_validate'), "type" => array("required" => 1, "default" => 0, "allow_null" => 1, "match" => array(0, 1, 2), "validate" => null), "status" => array("required" => 0, "default" => 'disabled', "allow_null" => 1, "match" => array('enabled', 'disabled'), "validate" => null), "trigger_type" => array("required" => 1, "default" => 0, "allow_null" => 1, "match" => array(0, 1, 2), "validate" => null), "trigger_number" => array("required" => 1, "default" => 1, "allow_null" => 0, "match" => range(1, 9), "validate" => null), "trigger_blocks" => array("required" => 1, "default" => 0, "allow_null" => 1, "match" => range(0, 9), "validate" => null), "plugin_condition" => array("required" => 0, "default" => -1, "allow_null" => 0, "match" => range(-1, count($_SESSION['alert_condition_plugin'])), "validate" => null), "action_plugin" => array("required" => 0, "default" => -1, "allow_null" => 0, "match" => range(-1, count($_SESSION['alert_action_plugin'])), "validate" => null), "action_email" => array("required" => 0, "default" => '', "allow_null" => 1, "match" => null, "validate" => 'check_email_address'), "action_subject" => array("required" => 0, "default" => 'Alert triggered', "allow_null" => 1, "match" => "/^[\\s!-~]+\$/", "validate" => 'subject_validate'), "action_system" => array("required" => 0, "default" => null, "allow_null" => 1, "match" => "/^[\\s!-~]+\$/", "validate" => null)); for ($i = 0; $i < 2 * $num_ConditionList; $i++) { $name = "op_{$i}"; $parse_opts[$name] = array("required" => 0, "default" => 0, "allow_null" => 1, "match" => array(0, 1), "validate" => null); $name = "visible_{$i}"; $parse_opts[$name] = array("required" => 0, "default" => 0, "allow_null" => 1, "match" => array(0, 1), "validate" => null); $name = "type_{$i}"; $parse_opts[$name] = array("required" => 0, "default" => 0, "allow_null" => 1, "match" => range(0, count($SumStat_type_options) - 1), "validate" => null); $name = "comp_{$i}"; $parse_opts[$name] = array("required" => 0, "default" => 0, "allow_null" => 1, "match" => array(0, 1, 2), "validate" => null); $name = "comp_type_{$i}"; $parse_opts[$name] = array("required" => 0, "default" => 0, "allow_null" => 1, "match" => range(0, count($SumStat_comp_type) - 1), "validate" => null); $name = "stat_type_{$i}"; $parse_opts[$name] = array("required" => 0, "default" => 0, "allow_null" => 1, "match" => range(0, count($FlowStat_type) - 1), "validate" => null); $name = "comp_value_{$i}"; $parse_opts[$name] = array("required" => 0, "default" => 0, "allow_null" => 1, "match" => "/^\\d+\$/", "validate" => null); $name = "scale_{$i}"; $parse_opts[$name] = array("required" => 0, "default" => 0, "allow_null" => 1, "match" => range(0, count($SumStat_scale) - 1), "validate" => null); } list($alertinfo, $has_errors) = ParseForm($parse_opts); $form_values = $alertinfo; if ($has_errors) { if ($ModifyOrNew == 'new') { $_SESSION['action'] = 'new'; $_SESSION['refresh'] = 0; } else { $_SESSION['action'] = 'details'; $_SESSION['refresh'] = 0; } return; } // process action types $action_type = 0; for ($i = 1; $i < 4; $i++) { if (array_key_exists("action_{$i}", $_POST)) { $action_type += 1 << $i - 1; } } $alertinfo['action_type'] = $action_type; $form_values['action_type'] = $action_type; if ($alertinfo['type'] == 2) { $lim = 2 * $num_ConditionList; } else { $lim = $alertinfo['type'] == 0 ? 0 : $num_ConditionList; } if ($alertinfo['action_plugin'] > -1) { $alertinfo['action_plugin'] = $_SESSION['alert_action_plugin'][$alertinfo['action_plugin']]; } else { unset($alertinfo['action_plugin']); } // prepare condition array $condition = array(); if ($alertinfo['type'] == 2) { $condition[] = $_SESSION['alert_condition_plugin'][$alertinfo['plugin_condition']]; } else { for ($i = 0; $i < 2 * $num_ConditionList; $i++) { if ($i >= $lim && $i < $lim + $num_ConditionList && $alertinfo["visible_{$i}"]) { // add to condition array $condition[] = implode(':', array($alertinfo["op_{$i}"], $alertinfo["type_{$i}"], $alertinfo["comp_{$i}"], $alertinfo["comp_type_{$i}"], $alertinfo["stat_type_{$i}"], $alertinfo["comp_value_{$i}"], $alertinfo["scale_{$i}"])); } } } for ($i = 0; $i < 2 * $num_ConditionList; $i++) { // delete other condition values unset($alertinfo["visible_{$i}"]); unset($alertinfo["op_{$i}"]); unset($alertinfo["type_{$i}"]); unset($alertinfo["comp_{$i}"]); unset($alertinfo["comp_type_{$i}"]); unset($alertinfo["stat_type_{$i}"]); unset($alertinfo["comp_value_{$i}"]); unset($alertinfo["scale_{$i}"]); } unset($alertinfo['plugin_condition']); $alertinfo['condition'] = $condition; ob_start(); print "Add/modify alert - alertinfo\n"; print_r($alertinfo); ReportLog(ob_get_contents()); ob_clean(); if ($ModifyOrNew == 'new') { $cmd_out = nfsend_query("add-alert", $alertinfo, 0); if (!is_array($cmd_out)) { $_SESSION['action'] = 'new'; $_SESSION['alertinfo'] = $form_values; return; } // Update alert list UpdateAlertList(); } else { $cmd_out = nfsend_query("modify-alert", $alertinfo, 0); if (!is_array($cmd_out)) { $_SESSION['action'] = 'details'; $_SESSION['refresh'] = 0; return; } } // prepare details view of new alert UpdateAlert($alertinfo['alert']); return; } // status change $status = 'none'; if (array_key_exists('status', $_POST) && !array_key_exists('status_hidden', $_POST)) { // status set to enabled $status = 'enabled'; } if (!array_key_exists('status', $_POST) && array_key_exists('status_hidden', $_POST)) { // status set to disabled $status = 'disabled'; } if ($status != 'none') { // redisplay alert $_SESSION['action'] = 'details'; $_SESSION['refresh'] = 0; $cmd_out = nfsend_query("modify-alert", array('alert' => $_SESSION['alertinfo']['name'], 'status' => $status), 0); if (!is_array($cmd_out)) { return; } UpdateAlert($_SESSION['alertinfo']['name']); return; } if (array_key_exists('view_alert_x', $_POST)) { $parse_opts = array("alert" => array("required" => 1, "default" => NULL, "allow_null" => 0, "match" => $_SESSION['alertlist'], "validate" => null, "must_exist" => 1)); list($form_data, $has_errors) = ParseForm($parse_opts); if ($has_errors) { return; } $_SESSION['refresh'] = 0; UpdateAlert($form_data['alert']); return; } if (array_key_exists('edit_alert_cancel', $_POST)) { // redisplay current alert $_SESSION['action'] = 'details'; $_SESSION['refresh'] = 0; return; } // everything else - show alert list UpdateAlertList(); return; }