12 hours if CYCLETIME = 300
* 0.5 * 576 * $CYCLETIME = 86400 => 1 day if CYCLETIME = 300
* $scale * 172800 = time range of graph
*/
$WinSizeScale = array ( 0.25, 0.5, 1, 2, 3.5, 7, 15, 30, 90, 120, 183 );
// labels of the scale selector
$WinSizeLabels = array ( '12 Hours', '1 day', '2 days', '4 days', '1 week', '2 weeks', '1 month', '2 months', '6 months', '8 months', '1 year' );
// Definitions for the netflow processing table
$TopNOption = array ( 10, 20, 50, 100, 200, 500);
$ListNOption = array ( 20, 50, 100, 500, 1000, 10000);
$IPStatOption = array ( 'Flow Records',
'Any IP Address', 'SRC IP Address', 'DST IP Address',
'Any Port', 'SRC Port', 'DST Port',
'Any interface', 'IN interface', 'OUT interface',
'Any AS', 'SRC AS', 'DST AS',
'Next Hop IP', 'Next Hop BGP IP', 'Router IP',
'Proto', 'Direction',
'SRC TOS', 'DST TOS', 'TOS',
'Any Mask Bits', 'SRC Mask Bits', 'DST Mask Bits',
'Any VLAN ID', 'SRC VLAN ID', 'DST VLAN ID',
'SRC MAC', 'DST MAC', 'IN MAC', 'OUT MAC',
'IN SRC MAC', 'OUT DST MAC', 'IN DST MAC', 'OUT SRC MAC',
'MPLS Label 1', 'MPLS Label 2', 'MPLS Label 3', 'MPLS Label 4', 'MPLS Label 5', 'MPLS Label 6', 'MPLS Label 7', 'MPLS Label 8', 'MPLS Label 9', 'MPLS Label 10'
);
$IPStatArg = array ( '-s record',
'-s ip', '-s srcip', '-s dstip',
'-s port', '-s srcport', '-s dstport',
'-s if', '-s inif', '-s outif',
'-s as', '-s srcas', '-s dstas',
'-s nhip', '-s nhbip', '-s router',
'-s proto', '-s dir',
'-s srctos', '-s dsttos', '-s tos',
'-s mask', '-s srcmask','-s dstmask',
'-s vlan', '-s srcvlan','-s dstvlan',
'-s srcmac', '-s dstmac', '-s inmac', '-s outmac',
'-s insrcmac', '-s outdstmac','-s indstmac', '-s outsrcmac',
'-s mpls1', '-s mpls2', '-s mpls3', '-s mpls4', '-s mpls5', '-s mpls6', '-s mpls7', '-s mpls8', '-s mpls9', '-s mpls10',
);
$IPStatOrder = array ( 'flows', 'packets', 'bytes', 'pps', 'bps', 'bpp' );
$LimitScale = array ( '-', 'K', 'M', 'G', 'T' );
$OutputFormatOption = array ( 'auto', 'line', 'long', 'extended');
function TimeSlotUpdate ($detail_opts) {
global $WinSizeScale;
global $RRDoffset;
global $CYCLETIME;
if ( isset($_POST['tend']) ) {
$_SESSION['tend'] = $_POST['tend'];
}
// make sure the tend mark is with the profile data
if ( ($_SESSION['tend'] > $_SESSION['profileinfo']['tend']) ||
($_SESSION['tend'] < $_SESSION['profileinfo']['tstart']) )
$_SESSION['tend'] = $_SESSION['profileinfo']['tend'];
/*
* scale factor of the graph. The unit is number of 5min slots/px
* WinSizeScale defines all available scales.
* The default for the graphs is 1 day => scale = 0.5
*/
$scale = $WinSizeScale[$detail_opts['wsize']];
$full_range = $scale * 172800; // a common product
/*
* start of the graph
*/
$_SESSION['tstart'] = $_SESSION['tend'] - $full_range; // see scale factor
/*
* Mark update: The tleft/tright markers are set by the following user inputs:
* - click into the graph
* - adjust graph by the button controls '>' ">>" etc.
* - enter the tleft marker into text field
*/
// process adjust buttons
if ( isset($_POST['adjust']) ) {
$_tmp = $_POST['adjust'];
switch($_tmp) {
case " > ":
if ( ($_SESSION['tright'] + $CYCLETIME ) <= $_SESSION['profileinfo']['tend']) {
$_SESSION['tleft'] += $CYCLETIME; // increase one $CYCLETIME slice ( default 300 )
$_SESSION['tright'] += $CYCLETIME; // increase one $CYCLETIME slice ( default 300 )
}
break;
case " < ":
if ( ($_SESSION['tleft'] - $CYCLETIME ) >= $_SESSION['profileinfo']['tstart']) {
$_SESSION['tleft'] -= $CYCLETIME; // decrease one $CYCLETIME slice ( default 300 )
$_SESSION['tright'] -= $CYCLETIME; // decrease one $CYCLETIME slice ( default 300 )
}
break;
case " << ":
// check if shift is within profile else move to end of profile
if ( ($_SESSION['tleft'] - $full_range) >= $_SESSION['profileinfo']['tstart'] )
$_tmp = $full_range;
else
$_tmp = $_SESSION['tleft'] - $_SESSION['profileinfo']['tstart'];
$_SESSION['tleft'] -= $_tmp;
$_SESSION['tright'] -= $_tmp;
$_SESSION['tstart'] -= $_tmp;
$_SESSION['tend'] -= $_tmp;
break;
case " >> ":
// check if shift is within profile else move to end of profile
if ( ($_SESSION['tright'] + $full_range) <= $_SESSION['profileinfo']['tend'] ) {
$_SESSION['tleft'] += $full_range;
$_SESSION['tright'] += $full_range;
$_SESSION['tstart'] += $full_range;
$_SESSION['tend'] += $full_range;
} else {
// move to end of profile - same as '>|'
$_SESSION['tend'] = $_SESSION['profileinfo']['tend'];
$_tmp = $_SESSION['profileinfo']['tend'] - $_SESSION['tright'];
$_SESSION['tright'] = $_SESSION['profileinfo']['tend'];
$_SESSION['tleft'] = $_SESSION['tleft'] + $_tmp;
$_SESSION['tstart'] = $_SESSION['tend'] - $full_range; // see scale
}
break;
case " >| ":
// move to end of profile
$_SESSION['tend'] = $_SESSION['profileinfo']['tend'];
$_tmp = $_SESSION['profileinfo']['tend'] - $_SESSION['tright'];
$_SESSION['tright'] = $_SESSION['profileinfo']['tend'];
$_SESSION['tleft'] = $_SESSION['tleft'] + $_tmp;
$_SESSION['tstart'] = $_SESSION['tend'] - $full_range; // see scale
break;
case " | ":
// center tleft, if possible, otherwise move as much as we can
$_tmp = ($full_range - ( $_SESSION['tright'] - $_SESSION['tleft']) ) >>1;
// shift only multiple of 5min units
$_tmp -= $_tmp % $CYCLETIME;
$_SESSION['tend'] = min($_SESSION['tright'] + $_tmp, $_SESSION['profileinfo']['tend']);
$_SESSION['tstart'] = $_SESSION['tend'] - $full_range;
break;
case " ^ ":
$max_timeslot = FindMaxValue();
if ( $max_timeslot ) {
$_SESSION['tleft'] = $max_timeslot;
$_SESSION['tright'] = $max_timeslot;
} else {
SetMessage('error', "Could not find max time slot");
}
break;
}
}
// process tleft/tright set by js or bookmark
if ( isset($_POST['tleft']) ) {
$_tmp = $_POST['tleft'];
if ( is_numeric($_tmp) ) {
// make sure we fall at the beginning of a 5min slot
$_SESSION['tleft'] = $_tmp - ($_tmp % $CYCLETIME);
// if tleft is outside the profile, set tleft to end of profile
if ( ($_SESSION['tleft'] < $_SESSION['tstart']) ||
($_SESSION['tleft'] > $_SESSION['tend'])) {
$_SESSION['tleft'] = $_SESSION['tstart'];
SetMessage('error', "Mark outside available timeframe");
}
}
}
if ( $_SESSION['tleft'] < $_SESSION['profileinfo']['tstart'] )
$_SESSION['tleft'] = $_SESSION['profileinfo']['tstart'];
if ( isset($_POST['tright']) ) {
$_tmp = $_POST['tright'];
if ( is_numeric($_tmp) ) {
// make sure we fall at the beginning of a 5min slot
$_SESSION['tright'] = $_tmp - ( $_tmp % $CYCLETIME);
// if tright is outside the profile, reset tright to tleft + $CYCLETIME
if ( ($_SESSION['tright'] < $_SESSION['tstart']) ||
($_SESSION['tright'] > $_SESSION['tend'])) {
$_SESSION['tright'] = $_SESSION['tleft'];
SetMessage('error', "Mark outside available timeframe");
}
}
}
// make sure right > left
if ( $_SESSION['tright'] < $_SESSION['tleft'] ) {
$_SESSION['tright'] = $_SESSION['tleft'];
}
/*
* Follow me:
* If the tleft is within 10% of the left or right margin
* adjust the graph and move the tleft into the middle of
* the graph
*/
$margin = 8640 * $scale; // 10% of graph
$offset = ($full_range - ( $_SESSION['tright'] - $_SESSION['tleft']) ) >>1;
// shift only multiple of cycletime units ( default 300 )
$offset -= $offset % $CYCLETIME;
if ((($_SESSION['tright'] > ($_SESSION['tend'] - $margin)) ||
($_SESSION['tleft'] < ($_SESSION['tstart'] + $margin))) &&
(($_SESSION['tright'] + $offset) < $_SESSION['profileinfo']['tend']) ) {
$_SESSION['tend'] = $_SESSION['tright'] + $offset;
$_SESSION['tstart'] = $_SESSION['tend'] - $full_range;
}
} // End of TimeSlotUpdate
function channellist_validate (&$channellist, $opts) {
if ( $channellist == NULL )
return 0;
$_channels = array();
foreach ( explode('!', $channellist) as $channel ) {
if ( !array_key_exists($channel, $_SESSION['profileinfo']['channel']) ) {
SetMessage('warning', "Requested channel '$channel' does not exists in this profile");
} else {
$_channels[] = $channel;
}
}
$channellist = implode('!', $_channels);
return 0;
} // End of channellist_validate
function srcselector_validate (&$channel_array, $opts) {
$_channels = array();
foreach ( $channel_array as $channel ) {
if ( !array_key_exists($channel, $_SESSION['profileinfo']['channel']) ) {
SetMessage('warning', "Requested channel '$channel' does not exists in this profile");
} else {
$_channels[] = $channel;
}
}
$channel_array = $_channels;
if ( count($channel_array) == 0 ) {
SetMessage('warning', "At least one channel is request");
return 1;
} else {
return 0;
}
} // End of srcselector_validate
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' ) {
$_POST['channellist'] = implode('!', array_keys($_SESSION['profileinfo']['channel']));
} 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'] = $_GET['type'];
}
if ( isset($_GET['proto']) ) {
$_POST['proto'] = $_GET['proto'];
}
if ( isset($_COOKIE['statpref']) ) {
$_POST['statpref'] = $_COOKIE['statpref'];
}
if ( isset($_COOKIE['statvisible']) ) {
$_POST['statvisible'] = $_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();
}
// process form data
$parse_opts = array(
// type
"type" => array( "required" => 0,
"default" => array_key_exists('type', $detail_opts) ? $detail_opts['type'] : 'flows',
"allow_null" => 0,
"match" => $TypeOrder ,
"validate" => NULL),
// proto
"proto" => array( "required" => 0,
"default" => array_key_exists('proto', $detail_opts) ? $detail_opts['proto'] : 'any',
"allow_null" => 0,
"match" => $DisplayOrder ,
"validate" => NULL),
// wsize
"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 - absolute or per sec values
"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 - lin/log display
"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 - line/stacked graphs
"linegraph" => array( "required" => 0,
"default" => array_key_exists('linegraph', $detail_opts) ? $detail_opts['linegraph'] : 0,
"allow_null" => 0,
"match" => array( 0, 1 ),
"validate" => NULL),
// linegraph - line/stacked graphs
"cursor_mode" => array( "required" => 0,
"default" => array_key_exists('cursor_mode', $detail_opts) ?
$detail_opts['cursor_mode'] : 0,
"allow_null" => 0,
"match" => array( 0, 1 ),
"validate" => NULL),
// list of displayed channels in graphs
"channellist" => array( "required" => 0,
"default" => array_key_exists('channellist', $detail_opts) ?
$detail_opts['channellist'] :
implode('!', array_keys($_SESSION['profileinfo']['channel'])),
"allow_null" => 1,
"match" => "/^[A-Za-z0-9][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($_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
// set the tleft to the middle of the graph
$_SESSION['tleft'] = $_SESSION['tend'] - 43200;
$_SESSION['tright'] = $_SESSION['tleft'];
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();
$parse_opts = array(
"modeselect" => array( "required" => 0,
"default" => array_key_exists('modeselect', $process_form) ?
$process_form['modeselect'] : 1,
"allow_null" => 0,
"match" => array( 0, 1),
"validate" => NULL),
"srcselector" => array( "required" => 0,
"default" => array_key_exists('srcselector', $process_form) ?
$process_form['srcselector'] : explode('!', $detail_opts['channellist']),
"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'] : 'auto',
"allow_null" => 0,
"match" => array_key_exists('formatlist', $_SESSION) ?
array_keys($_SESSION['formatlist']) : array('auto'),
"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),
// stat type inputs
"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 = $_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;
} // End of Process_Details_tab
function DisplayDetails () {
global $self;
global $DisplayOrder;
global $TypeOrder;
global $WinSizeLabels;
global $RRDoffset;
global $GMToffset;
global $TZname;
global $CYCLETIME;
?>
0;
print "
Profile: $profile
\n";
$_tmp = explode('!', $detail_opts['channellist']);
$graph_channels = count($_tmp) == 0 ? '@EMPTY' : implode(":", $_tmp);
?>
";
print $label;
print "\n";
}
print "| Profileinfo: | \n"; // Empty right element
print "
\n";
for ( $i=1; $i < count($DisplayOrder); $i++ ) {
$label = $DisplayOrder[$i];
if ( $label == $detail_opts['proto'] )
$label = 'any';
print "\n";
$arg = implode ( " ", array( $graph_channels, $label,
$detail_opts['type'], $_SESSION['profileinfo']['tstart'], $_SESSION['tstart'],
$_SESSION['tend'], $_SESSION['tleft'], $_SESSION['tright'], 288, 100, 1,
$detail_opts['logscale'], $detail_opts['linegraph']));
$_SESSION["rrd_proto_arg_$i"] = $arg;
print " " .
" \n";
print " | \n";
}
print "\n";
$str = strftime("%b %d %Y - %H:%M", $_SESSION['profileinfo']['tstart']);
$expire = $_SESSION['profileinfo']['expire'];
if ( $expire == 0 ) {
$expire = 'never';
} else {
$d = (int)($expire / 24 );
$h = $expire % 24;
$d_ext = $d == 1 ? '' : 's';
$h_ext = $h == 1 ? '' : 's';
if ( $d ) {
$expire = "$d day${d_ext} $h hour{$h_ext}";
} else {
$expire = "$h hour${h_ext}";
}
}
$maxsize = ScaleBytes($_SESSION['profileinfo']['maxsize'], 1, 1024.0);
if ( $maxsize == 0 )
$maxsize = 'unlimited';
print "\n";
switch ( $_SESSION['profileinfo']['type'] & 3 ) {
case 0:
$type = 'live';
break;
case 1:
$type = 'history';
break;
case 2:
$type = 'continuous';
break;
default:
$type = 'unknown';
}
$type .= $is_shadow ? ' / shadow' : '';
print "| Type: | $type | ";
print "| Max: | $maxsize | ";
print "| Exp: | $expire | ";
print "| Start: | $str $TZname | \n";
$str = strftime("%b %d %Y - %H:%M", $_SESSION['profileinfo']['tend']);
print "| End: | $str $TZname | \n";
print " \n";
print " | \n";
$arg = implode ( " ", array( $graph_channels,
$detail_opts['proto'], $detail_opts['type'], $_SESSION['profileinfo']['tstart'],
$_SESSION['tstart'], $_SESSION['tend'], $_SESSION['tleft'], $_SESSION['tright'],
576, 200, 0, $detail_opts['logscale'], $detail_opts['linegraph']));
$_SESSION['rrd_arg_main'] = $arg;
?>
&argref=rrd_arg_main border='0' alt='main-graph'>
|
|
tstart
|
- update -
|
|
tend
|
- update -
|
| $printlabel | \n";
print "\n";
$arg = implode ( " ", array( $graph_channels,
$detail_opts['proto'], $label, $_SESSION['profileinfo']['tstart'],
$_SESSION['tstart'], $_SESSION['tend'], $_SESSION['tleft'],
$_SESSION['tright'], 288, 100, 1, $detail_opts['logscale'], $detail_opts['linegraph']));
$_SESSION["rrd_arg_$i"] = $arg;
print " " . " ";
print " | \n";
}
?>
|
|
Select
|
Display:
|
|
|
|
|
align="left" alt="Hide stat table">
align="left" alt="Show stat table">
Statistics
Netflow Processing
\n";
$run = $_SESSION['run'];
if ( $run != null ) {
$filter = $process_form['filter'];
if ( $process_form['DefaultFilter'] != -1 ) {
$cmd_opts['and_filter'] = $process_form['DefaultFilter'];
}
$cmd_opts['type'] = ($_SESSION['profileinfo']['type'] & 4) > 0 ? 'shadow' : 'real';
$cmd_opts['profile'] = $_SESSION['profileswitch'];
$cmd_opts['srcselector'] = implode(':', $process_form['srcselector']);
print "\n";
$patterns = array();
$replacements = array();
$patterns[0] = '/(\s*)([^\s]+)/';
$replacements[0] = "$1$2";
// gets HAP4NfSens plugin id. returns -1 if HAP4NfSen is not installed.
function getHAP4NfSenId() {
$plugins = GetPlugins();
for ( $i=0;$i= 0) {
// ICMP "port" filter are no currently supported by the HAP4NfSen plugin
function isChecked(&$form, $name) { // helper function used to find out, if an option is checked
return $form[$name]=="checked";
}
$ip_and_port_columns = preg_match('/(flow records)/i', $IPStatOption[$process_form['stattype']]) &&
((isChecked($process_form,'aggr_srcip') && isChecked($process_form,'aggr_srcport')) ||
(isChecked($process_form,'aggr_dstip') && isChecked($process_form,'aggr_dstport')));
$ip_contains_port = $_SESSION["process_form"]["modeselect"]=='0' || !preg_match('/[ip|flow_records]/i', $IPStatOption[$process_form['stattype']]) ||
(preg_match('/(flow records)/i', $IPStatOption[$process_form['stattype']]) && !( // no boxes checked
isChecked($process_form,'aggr_srcip') || isChecked($process_form,'aggr_srcport') ||
isChecked($process_form,'aggr_dstip') || isChecked($process_form,'aggr_dstport')));
$_SESSION["plugin"][$hap4nfsen_id]["cmd_opts"] = $cmd_opts;
$hap_pic = "
";
$default_pattern = array_pop($patterns);
$default_replacement = array_pop($replacements);
if ($ip_contains_port) { // matches cases like ip:port
$max_prot_length = 5; // max. port length = 5 chars(highest port number = 65535)
for ($i=$max_prot_length;$i>=1;$i--) {
$diff = ($max_prot_length-$i); // difference between actual and max port length
$ip_port_pattern_icmp = "/(\s*)([^\s|^:]+)(:)(0\s{4}|\d\.\d\s{2}|\d{2}\.\d\|\d\.\d{2}\s|\d{2}\.\d{2})/";
$ip_port_pattern_normal = "/(\s*)([^\s|^:]+)(:)([\d|\.]{{$i}})(\s{{$diff}})/";
$spaces = '';
for ($k=0;$k<$diff;$k++) {$spaces = $spaces . ' ';} // spaces required to align hap viewer icons
array_push($patterns, $ip_port_pattern_icmp);
array_push($replacements, $default_replacement .
"$3$4 $hap_pic ");
array_push($patterns, $ip_port_pattern_normal);
array_push($replacements, $default_replacement .
"$3$4$spaces $hap_pic ");
}
array_push($patterns, '/(\sIP\sAddr:Port)/i');
array_push($replacements, "$1 $hap_pic");
} else {
if ($ip_and_port_columns) { // matches cases when both ip and port are available but are located in separate columns
// ICMP verion
$ip_and_port_pattern = "/(\s*)([^\s]+)(\s+)(0|\d\.\d)/";
$ip_and_port_replacement = "$1$2$3$4 " .
"$hap_pic";
array_push($patterns, $ip_and_port_pattern);
array_push($replacements, $ip_and_port_replacement);
// non-ICMP version with port filter
$ip_and_port_pattern = "/(\s*)([^\s]+)(\s*)([\d|.]+)/";
$ip_and_port_replacement = "$1$2$3$4 " .
"$hap_pic";
array_push($patterns, $ip_and_port_pattern);
array_push($replacements, $ip_and_port_replacement);
array_push($patterns, '/(\s\s(Src\sIP\sAddr\s*Src\sPt|Dst\sIP\sAddr\s*Dst\sPt))/i');
array_push($replacements, "$1 $hap_pic");
} else { // matches all other cases
array_push($patterns, $default_pattern);
array_push($replacements, $default_replacement .
" $hap_pic");
array_push($patterns, '/(\s(|\s(Src|Dst))\sIP\sAddr)/i');
array_push($replacements, "$1 $hap_pic");
}
}
}
if ( array_key_exists('arg', $cmd_out) ) {
print "** nfdump " . $cmd_out['arg'] . "\n";
}
if ( array_key_exists('filter', $cmd_out) ) {
print "nfdump filter:\n";
foreach ( $cmd_out['filter'] as $line ) {
print "$line\n";
}
}
foreach ( $cmd_out['nfdump'] as $line ) {
print preg_replace($patterns, $replacements, $line) . "\n";
}
}
print "\n";
}
print "\n";
return;
} # End of DisplayProcessing
?>