'
. html_print_image ("images/edit.png", true, array ("title" => __('Report list')))
. '';
//Header
ui_print_page_header (__('Netflow'), "images/networkmap/so_cisco_new.png", false, "", false, $buttons);
echo"
".__('Filter graph')."
";
echo '';
if ($id!=''){
echo"$report_name
";
$sql1 = "select id_filter from tnetflow_report_content where id_report='".$id."'";
$all_filters = db_get_all_rows_sql($sql1);
$x = 0;
while(isset($all_filters[$x]['id_filter'])) {
$filter = $all_filters[$x]['id_filter'];
$sql = "SELECT * FROM tnetflow_report_content WHERE id_report='".$id."' and id_filter='".$filter."'";
$content_report = db_get_row_sql($sql);
$name_filter = $content_report['id_filter'];
$interval = $content_report['period'];
$date = $content_report['date'];
$max_val= $content_report['max'];
$element = $content_report['show_graph'];
$date_time = date($time_format, $date+84600);
if($update_date){
$date = get_parameter_post ('date');
$time = get_parameter_post ('time');
$period = get_parameter('period','0');
$date = strtotime ($date." ".$time);
if(($period!='None')&&($period!='0'))
$interval = $period;
}
$limit = $date - $interval;
$date_limit = date ($time_format, $limit);
$sql = "SELECT * FROM tnetflow_filter WHERE id_name = '".$name_filter."'";
$result = db_get_row_sql($sql,false,true);
$assign_group = $result['group'];
$ip_dst = $result['ip_dst'];
$ip_src = $result['ip_src'];
$dst_port = $result['dst_port'];
$src_port = $result['src_port'];
$aggregate = $result['aggregate'];
$show_packets = $result['show_packets'];
$show_bytes = $result['show_bytes'];
$show_bps = $result['show_bps'];
$show_bpp = $result['show_bpp'];
if(isset($ip_dst)){
$val_ipdst = explode(',',$ip_dst);
$count_ipdst = count($val_ipdst);
}
if(isset($ip_src)){
$val_ipsrc = explode(',',$ip_src);
$count_ipsrc = count($val_ipsrc);
}
if(isset($dst_port)&&($dst_port!='0')){
$val_dstport = explode(',',$dst_port);
$count_dstport = count($val_dstport);
}
if(isset($src_port)&&($src_port!='0')){
$val_srcport = explode(',',$src_port);
$count_srcport = count($val_srcport);
}
//// Build command line
$command = 'nfdump -q';
if (isset($config['netflow_path']))
$command .= ' -R '.$config['netflow_path'];
if (isset($aggregate)&&($aggregate!='none')){
$command .= ' -s '.$aggregate;
if (isset($max_val))
$command .= ' -n '.$max_val;
}
//filter options
if (isset($ip_dst)&&($ip_dst!='')){
$command .= ' "';
for($i=0;$i<$count_ipdst;$i++){
if ($i==0)
$command .= 'dst ip '.$val_ipdst[$i];
else
$command .= ' or dst ip '.$val_ipdst[$i];
}
if (isset($ip_src)&&($ip_src!='')){
$command .= ' and (';
for($i=0;$i<$count_ipsrc;$i++){
if ($i==0)
$command .= 'src ip '.$val_ipsrc[$i];
else
$command .= ' or src ip '.$val_ipsrc[$i];
}
$command .= ')';
}
if (isset($dst_port)&&($dst_port!='')&&($dst_port!='0')){
$command .= ' and (';
for($i=0;$i<$count_dstport;$i++){
if ($i==0)
$command .= 'dst port '. $val_dstport[$i];
else
$command .= ' or dst port '.$val_dstport[$i];
}
$command .= ')';
}
if (isset($src_port)&&($src_port!='')&&($src_port!='0')){
$command .= ' and (';
for($i=0;$i<$count_srcport;$i++){
if ($i==0)
$command .= 'src port '. $val_srcport[$i];
else
$command .= ' or src port '.$val_srcport[$i];
}
$command .= ')';
}
$command .= '"';
} else if (isset($ip_src)&&($ip_src!='')){
$command .= ' "';
for($i=0;$i<$count_ipsrc;$i++){
if ($i==0)
$command .= 'src ip '.$val_ipsrc[$i];
else
$command .= ' or src ip '.$val_ipsrc[$i];
}
if (isset($dst_port)&&($dst_port!='')&&($dst_port!='0')){
$command .= ' and (';
for($i=0;$i<$count_dstport;$i++){
if ($i==0)
$command .= 'dst port '. $val_dstport[$i];
else
$command .= ' or dst port '.$val_dstport[$i];
}
$command .= ')';
}
if (isset($src_port)&&($src_port!='')&&($src_port!='0')){
$command .= ' and (';
for($i=0;$i<$count_srcport;$i++){
if ($i==0)
$command .= 'src port '. $val_srcport[$i];
else
$command .= ' or src port '.$val_srcport[$i];
}
$command .= ')';
} else {
$command .= '"';
}
} else if (isset($dst_port)&&($dst_port!='')&&($dst_port!='0')){
$command .= ' "';
for($i=0;$i<$count_dstport;$i++){
if ($i==0)
$command .= 'dst port '.$val_dstport[$i];
else
$command .= ' or dst port '.$val_dstport[$i];
}
if (isset($src_port)&&($src_port!='')&&($src_port!='0')){
$command .= ' and (';
for($i=0;$i<$count_srcport;$i++){
if ($i==0)
$command .= 'src port '. $val_srcport[$i];
else
$command .= ' or src port '.$val_srcport[$i];
}
$command .= ')';
} else {
$command .= '"';
}
} else {
if (isset($src_port)&&($src_port!='')&&($src_port!='0')){
$command .= ' "(';
for($i=0;$i<$count_ipdst;$i++){
if ($i==0)
$command .= 'dst ip '.$val_ipdst[$i];
else
$command .= ' or dst ip '.$val_ipdst[$i];
}
$command .= ' )"';
}
}
if ($show_packets)
$show = 'packets';
if ($show_bytes)
$show = 'bytes';
if ($show_bps)
$show = 'bps';
if ($show_bpp)
$show = 'bpp';
//create interval to divide command execution
if ($interval<43200)
$inter = 1;
else if (($interval>=43200)&&($interval<=86400))
$inter = 25;
else if ($interval > 86400 && $interval < 604800) //1296000)
$inter = 150;
else if ($interval >= 604800 && $interval <= 1296000)
$inter = 600;
else
$inter = 1600;
if ($aggregate!='none')
$inter = 1;
$fecha_limite = date ($time_format, $limit);
$res = $interval/$inter;
// Data iterator
$j = 0;
$values = array();
// Calculate interval date
for ($i = 0; $i < $inter; $i++) {
$timestamp = $limit + ($res * $i);
$timestamp_short = date($time_format, $timestamp);
$end_date = $timestamp + $res;
$end = date ($time_format, $end_date);
if($aggregate!='none'){
$result = exec_command_aggregate($timestamp_short, $end, $command, $show);
$result = orderMultiDimensionalArray($result, 'datetime');
} else {
$result = exec_command($timestamp_short, $end, $command, $show);
}
$total = 0;
$count = 0;
if(!empty($result)){
foreach($result as $data){
$dates = $data['date'];
$times = $data['time'];
$total += $data['data'];
$count++;
}
$values[$j]['date'] = $dates;
$values[$j]['time'] = $times;
if ($count > 0) {
$values[$j]['data'] = $total / $count;
$var = $values[$j]['data'];
} else {
$values[$j]['data'] = 0;
}
$j++;
}
}
if($aggregate!='none'){
switch ($element){
case '0':
echo grafico_netflow_aggregate_area($result, $interval, 880, 540, '', '','','',$date);
break;
case '1':
echo grafico_netflow_aggregate_pie($result);
break;
case '2':
echo netflow_show_table_values($result, $date_limit, $date_time);
break;
case '3':
echo netflow_show_total_period($result, $date_limit, $date_time);
break;
}
}else{
switch ($element){
case '0':
echo grafico_netflow_total_area($values, $interval, 660, 320, '', '','','',$date);
break;
}
}
$x++;
}
}
?>