2011-12-21 16:28:01 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
// Pandora FMS - http://pandorafms.com
|
|
|
|
// ==================================================
|
|
|
|
// Copyright (c) 2005-2010 Artica Soluciones Tecnologicas
|
|
|
|
// Please see http://pandorafms.org for full contribution list
|
|
|
|
|
|
|
|
// This program is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU Lesser General Public License
|
|
|
|
// as published by the Free Software Foundation; version 2
|
|
|
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
|
2012-01-11 19:12:33 +01:00
|
|
|
|
|
|
|
include_once("include/functions_users.php");
|
2012-01-17 15:01:49 +01:00
|
|
|
include_once("include/functions_io.php");
|
2012-01-11 19:12:33 +01:00
|
|
|
|
2012-01-11 17:34:53 +01:00
|
|
|
// Date format for nfdump
|
|
|
|
$nfdump_date_format = 'Y/m/d.H:i:s';
|
2011-12-21 16:28:01 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Selects all netflow filters (array (id_name => id_name)) or filters filtered
|
|
|
|
*
|
|
|
|
* @param mixed Array with filter conditions to retrieve filters or false.
|
|
|
|
*
|
|
|
|
* @return array List of all filters
|
|
|
|
*/
|
|
|
|
function netflow_get_filters ($filter = false) {
|
|
|
|
if ($filter === false) {
|
|
|
|
$filters = db_get_all_rows_in_table ("tnetflow_filter", "id_name");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$filters = db_get_all_rows_filter ("tnetflow_filter", $filter);
|
|
|
|
}
|
2012-07-18 15:25:51 +02:00
|
|
|
|
2011-12-21 16:28:01 +01:00
|
|
|
$return = array ();
|
|
|
|
if ($filters === false) {
|
|
|
|
return $return;
|
|
|
|
}
|
|
|
|
foreach ($filters as $filter) {
|
|
|
|
$return[$filter["id_name"]] = $filter["id_name"];
|
|
|
|
}
|
|
|
|
return $return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Selects all netflow reports (array (id_name => id_name)) or filters filtered
|
|
|
|
*
|
|
|
|
* @param mixed Array with filter conditions to retrieve filters or false.
|
|
|
|
*
|
|
|
|
* @return array List of all filters
|
|
|
|
*/
|
|
|
|
function netflow_get_reports ($filter = false) {
|
|
|
|
if ($filter === false) {
|
|
|
|
$filters = db_get_all_rows_in_table ("tnetflow_report", "id_name");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$filters = db_get_all_rows_filter ("tnetflow_report", $filter);
|
|
|
|
}
|
2012-07-18 15:25:51 +02:00
|
|
|
|
2011-12-21 16:28:01 +01:00
|
|
|
$return = array ();
|
|
|
|
if ($filters === false) {
|
|
|
|
return $return;
|
|
|
|
}
|
|
|
|
foreach ($filters as $filter) {
|
|
|
|
$return[$filter["id_name"]] = $filter["id_name"];
|
|
|
|
}
|
|
|
|
return $return;
|
|
|
|
}
|
|
|
|
|
2012-01-11 19:12:33 +01:00
|
|
|
//permite validar si un filtro pertenece a un grupo permitido para el usuario
|
|
|
|
|
|
|
|
function netflow_check_filter_group ($id_sg) {
|
|
|
|
global $config;
|
|
|
|
|
|
|
|
$id_group = db_get_value('id_group', 'tnetflow_filter', 'id_sg', $id_sg);
|
2012-01-12 12:32:49 +01:00
|
|
|
$own_info = get_user_info ($config['id_user']);
|
2012-01-11 19:12:33 +01:00
|
|
|
// Get group list that user has access
|
2012-01-12 12:32:49 +01:00
|
|
|
$groups_user = users_get_groups ($config['id_user'], "IW", $own_info['is_admin'], true);
|
2012-01-11 19:12:33 +01:00
|
|
|
$groups_id = array();
|
|
|
|
$has_permission = false;
|
|
|
|
|
|
|
|
foreach($groups_user as $key => $groups){
|
|
|
|
if ($groups['id_grupo'] == $id_group)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-01-12 11:52:15 +01:00
|
|
|
/* Permite validar si un informe pertenece a un grupo permitido para el usuario.
|
|
|
|
* Si mode = false entonces es modo godmode y solo puede ver el grupo All el admin
|
|
|
|
* Si es modo operation (mode = true) entonces todos pueden ver el grupo All
|
|
|
|
*/
|
2012-01-11 19:12:33 +01:00
|
|
|
|
2012-01-12 11:52:15 +01:00
|
|
|
function netflow_check_report_group ($id_report, $mode=false) {
|
2012-01-11 19:12:33 +01:00
|
|
|
global $config;
|
|
|
|
|
2012-01-12 11:52:15 +01:00
|
|
|
if (!$mode) {
|
|
|
|
$own_info = get_user_info ($config['id_user']);
|
|
|
|
$mode = $own_info['is_admin'];
|
|
|
|
}
|
|
|
|
$id_group = db_get_value('id_group', 'tnetflow_report', 'id_report', $id_report);
|
|
|
|
|
2012-01-11 19:12:33 +01:00
|
|
|
// Get group list that user has access
|
2012-01-12 11:52:15 +01:00
|
|
|
$groups_user = users_get_groups ($config['id_user'], "IW", $mode, true);
|
2012-01-11 19:12:33 +01:00
|
|
|
$groups_id = array();
|
|
|
|
$has_permission = false;
|
|
|
|
|
|
|
|
foreach($groups_user as $key => $groups){
|
|
|
|
if ($groups['id_grupo'] == $id_group)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-01-12 11:52:15 +01:00
|
|
|
|
2011-12-21 16:28:01 +01:00
|
|
|
/**
|
|
|
|
* Get a filter.
|
|
|
|
*
|
|
|
|
* @param int filter id to be fetched.
|
|
|
|
* @param array Extra filter.
|
|
|
|
* @param array Fields to be fetched.
|
|
|
|
*
|
|
|
|
* @return array A netflow filter matching id and filter.
|
|
|
|
*/
|
|
|
|
function netflow_filter_get_filter ($id_sg, $filter = false, $fields = false) {
|
2012-07-18 15:25:51 +02:00
|
|
|
if (! is_array ($filter))
|
|
|
|
$filter = array ();
|
|
|
|
|
|
|
|
$filter['id_sg'] = (int) $id_sg;
|
2012-01-11 19:12:33 +01:00
|
|
|
|
2012-07-18 15:25:51 +02:00
|
|
|
return db_get_row_filter ('tnetflow_filter', $filter, $fields);
|
2011-12-21 16:28:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get options.
|
|
|
|
*
|
|
|
|
* @param int filter id to be fetched.
|
|
|
|
* @param array Extra filter.
|
|
|
|
* @param array Fields to be fetched.
|
|
|
|
*
|
|
|
|
* @return array A netflow filter matching id and filter.
|
|
|
|
*/
|
|
|
|
function netflow_reports_get_reports ($id_report, $filter = false, $fields = false) {
|
|
|
|
if (empty ($id_report))
|
|
|
|
return false;
|
|
|
|
if (! is_array ($filter))
|
|
|
|
$filter = array ();
|
|
|
|
$filter['id_report'] = (int) $id_report;
|
|
|
|
|
|
|
|
return db_get_row_filter ('tnetflow_report', $filter, $fields);
|
|
|
|
}
|
|
|
|
|
|
|
|
function netflow_reports_get_content ($id_rc, $filter = false, $fields = false){
|
|
|
|
if (empty ($id_rc))
|
|
|
|
return false;
|
|
|
|
if (! is_array ($filter))
|
|
|
|
$filter = array ();
|
|
|
|
$filter['id_rc'] = (int) $id_rc;
|
|
|
|
|
|
|
|
return db_get_row_filter ('tnetflow_report_content', $filter, $fields);
|
|
|
|
}
|
|
|
|
|
2012-01-11 17:34:53 +01:00
|
|
|
/**
|
|
|
|
* Compare two flows according to the 'data' column.
|
|
|
|
*
|
|
|
|
* @param array a First flow.
|
|
|
|
* @param array b Second flow.
|
|
|
|
*
|
|
|
|
* @return Result of the comparison.
|
|
|
|
*/
|
|
|
|
function compare_flows ($a, $b) {
|
2012-01-13 14:14:16 +01:00
|
|
|
return $a['data'] < $b['data'];
|
2011-12-21 16:28:01 +01:00
|
|
|
}
|
|
|
|
|
2012-01-11 17:34:53 +01:00
|
|
|
/**
|
|
|
|
* Sort netflow data according to the 'data' column.
|
|
|
|
*
|
|
|
|
* @param array netflow_data Netflow data array.
|
|
|
|
*
|
|
|
|
*/
|
2012-01-13 14:14:16 +01:00
|
|
|
function sort_netflow_data (&$netflow_data) {
|
2012-07-10 13:03:00 +02:00
|
|
|
usort($netflow_data, "compare_flows");
|
2012-01-11 17:34:53 +01:00
|
|
|
}
|
|
|
|
|
2012-01-13 15:52:52 +01:00
|
|
|
function netflow_stat_table ($data, $start_date, $end_date, $aggregate, $unit){
|
2012-01-11 17:34:53 +01:00
|
|
|
global $nfdump_date_format;
|
|
|
|
|
|
|
|
$start_date = date ($nfdump_date_format, $start_date);
|
|
|
|
$end_date = date ($nfdump_date_format, $end_date);
|
2011-12-21 16:28:01 +01:00
|
|
|
$values = array();
|
|
|
|
$table->width = '50%';
|
|
|
|
$table->class = 'databox';
|
|
|
|
$table->data = array();
|
|
|
|
$j = 0;
|
2012-01-23 19:20:30 +01:00
|
|
|
$x = 0;
|
|
|
|
|
|
|
|
$table->head = array ();
|
|
|
|
$table->head[0] = '<b>' . __($aggregate) . '</b>';
|
|
|
|
$table->head[1] = '<b>' . __($unit) . '</b>';
|
2011-12-21 16:28:01 +01:00
|
|
|
|
|
|
|
while (isset ($data[$j])) {
|
|
|
|
$agg = $data[$j]['agg'];
|
|
|
|
if (!isset($values[$agg])){
|
|
|
|
$values[$agg] = $data[$j]['data'];
|
|
|
|
$table->data[$x][0] = $agg;
|
2012-01-13 15:52:52 +01:00
|
|
|
$table->data[$x][1] = format_numeric ($data[$j]['data']);
|
2012-07-10 13:03:00 +02:00
|
|
|
}
|
|
|
|
else {
|
2011-12-21 16:28:01 +01:00
|
|
|
$values[$agg] += $data[$j]['data'];
|
|
|
|
$table->data[$x][0] = $agg;
|
2012-01-13 15:52:52 +01:00
|
|
|
$table->data[$x][1] = format_numeric ($data[$j]['data']);
|
2011-12-21 16:28:01 +01:00
|
|
|
}
|
|
|
|
$j++;
|
|
|
|
$x++;
|
|
|
|
}
|
2012-07-10 13:03:00 +02:00
|
|
|
|
2012-01-13 15:52:52 +01:00
|
|
|
html_print_table($table);
|
2011-12-21 16:28:01 +01:00
|
|
|
}
|
|
|
|
|
2012-01-11 17:34:53 +01:00
|
|
|
/**
|
|
|
|
* Show a table with netflow statistics.
|
|
|
|
*
|
|
|
|
* @param array data Statistic data.
|
|
|
|
* @param string start_date Start date.
|
|
|
|
* @param string end_date End date.
|
2012-01-13 15:52:52 +01:00
|
|
|
* @param string aggregate Aggregate field.
|
2012-01-11 17:34:53 +01:00
|
|
|
*
|
|
|
|
* @return The statistics table.
|
|
|
|
*/
|
2012-01-13 15:52:52 +01:00
|
|
|
function netflow_data_table ($data, $start_date, $end_date, $aggregate) {
|
2012-01-11 17:34:53 +01:00
|
|
|
global $nfdump_date_format;
|
2012-07-18 15:25:51 +02:00
|
|
|
|
2012-01-11 20:16:13 +01:00
|
|
|
$period = $end_date - $start_date;
|
2012-01-11 17:34:53 +01:00
|
|
|
$start_date = date ($nfdump_date_format, $start_date);
|
|
|
|
$end_date = date ($nfdump_date_format, $end_date);
|
2012-07-18 15:25:51 +02:00
|
|
|
|
2012-01-11 20:16:13 +01:00
|
|
|
// Set the format
|
2012-07-18 15:25:51 +02:00
|
|
|
if ($period <= SECONDS_6HOURS) {
|
2012-01-11 20:16:13 +01:00
|
|
|
$time_format = 'H:i:s';
|
|
|
|
}
|
2012-07-18 15:25:51 +02:00
|
|
|
elseif ($period < SECONDS_1DAY) {
|
2012-01-11 20:16:13 +01:00
|
|
|
$time_format = 'H:i';
|
|
|
|
}
|
2012-07-18 15:25:51 +02:00
|
|
|
elseif ($period < SECONDS_15DAYS) {
|
2012-01-11 20:16:13 +01:00
|
|
|
$time_format = 'M d H:i';
|
|
|
|
}
|
2012-07-18 15:25:51 +02:00
|
|
|
elseif ($period < SECONDS_1MONTH) {
|
2012-01-11 20:16:13 +01:00
|
|
|
$time_format = 'M d H\h';
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$time_format = 'M d H\h';
|
|
|
|
}
|
2012-07-18 15:25:51 +02:00
|
|
|
|
2011-12-21 16:28:01 +01:00
|
|
|
$values = array();
|
2012-01-13 15:52:52 +01:00
|
|
|
$table->size = array ('50%');
|
2011-12-21 16:28:01 +01:00
|
|
|
$table->class = 'databox';
|
|
|
|
$table->data = array();
|
2012-07-18 15:25:51 +02:00
|
|
|
|
2012-01-23 19:20:30 +01:00
|
|
|
$table->head = array();
|
|
|
|
$table->head[0] = '<b>'.__('Timestamp').'</b>';
|
2011-12-21 16:28:01 +01:00
|
|
|
|
2012-01-11 20:16:13 +01:00
|
|
|
$j = 0;
|
|
|
|
$source_index = array ();
|
|
|
|
$source_count = 0;
|
|
|
|
foreach ($data['sources'] as $source => $null) {
|
2012-01-23 19:20:30 +01:00
|
|
|
$table->head[$j+1] = $source;
|
2012-01-11 20:16:13 +01:00
|
|
|
$source_index[$j] = $source;
|
|
|
|
$source_count++;
|
2011-12-21 16:28:01 +01:00
|
|
|
$j++;
|
|
|
|
}
|
2012-07-18 15:25:51 +02:00
|
|
|
|
2012-01-23 19:20:30 +01:00
|
|
|
$i = 0;
|
2012-01-11 20:16:13 +01:00
|
|
|
foreach ($data['data'] as $timestamp => $values) {
|
|
|
|
$table->data[$i][0] = date ($time_format, $timestamp);
|
|
|
|
for ($j = 0; $j < $source_count; $j++) {
|
|
|
|
if (isset ($values[$source_index[$j]])) {
|
|
|
|
$table->data[$i][$j+1] = format_numeric ($values[$source_index[$j]]);
|
2012-08-02 Miguel de Dios <miguel.dedios@artica.es>
* pandoradb_data.sql, pandoradb.data.postgreSQL.sql,
pandoradb.data.oracle.sql, include/functions_config.php: fixed the
"list_ACL_IPs_for_API" update.
* operation/events/events_marquee.php, godmode/setup/setup.php,
godmode/reporting/graph_builder.php,
godmode/reporting/map_builder.php, godmode/reporting/graphs.php,
godmode/reporting/visual_console_builder.wizard.php,
godmode/reporting/visual_console_builder.php,
godmode/alerts/configure_alert_compound.php,
godmode/alerts/alert_list.php,
godmode/alerts/configure_alert_template.php,
godmode/alerts/alert_templates.php,
godmode/alerts/configure_alert_action.php,
godmode/alerts/configure_alert_command.php,
godmode/alerts/alert_actions.php,
godmode/alerts/alert_list.builder.php,
godmode/alerts/configure_alert_special_days.php,
include/functions_api.php, include/functions_ui.php,
include/functions_netflow.php, include/functions_alerts.php,
include/functions_menu.php, include/functions_messages.php: cleaned
source code style.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@6846 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2012-08-03 14:48:09 +02:00
|
|
|
}
|
|
|
|
else {
|
2012-01-11 20:16:13 +01:00
|
|
|
$table->data[$i][$j+1] = 0;
|
2011-12-21 16:28:01 +01:00
|
|
|
}
|
|
|
|
}
|
2012-01-11 20:16:13 +01:00
|
|
|
$i++;
|
2011-12-21 16:28:01 +01:00
|
|
|
}
|
2012-07-18 15:25:51 +02:00
|
|
|
|
2012-01-11 17:34:53 +01:00
|
|
|
html_print_table($table);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns 1 if the given address is a network address.
|
|
|
|
*
|
|
|
|
* @param string address Host or network address.
|
|
|
|
*
|
|
|
|
* @return 1 if the address is a network address, 0 otherwise.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
function netflow_is_net ($address) {
|
|
|
|
if (strpos ($address, '/') !== FALSE) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns netflow data for the given period in an array.
|
|
|
|
*
|
|
|
|
* @param string start_date Period start date.
|
|
|
|
* @param string end_date Period end date.
|
|
|
|
* @param string command Command used to retrieve netflow data.
|
2012-01-13 14:14:16 +01:00
|
|
|
* @param string unique_id A unique number that is used to generate a cache file.
|
2012-01-11 17:34:53 +01:00
|
|
|
* @param string aggregate Aggregate field.
|
|
|
|
* @param int max Maximum number of aggregates.
|
|
|
|
* @param string unit Unit to show.
|
|
|
|
*
|
|
|
|
* @return An array with netflow stats.
|
|
|
|
*
|
|
|
|
*/
|
2012-01-13 14:14:16 +01:00
|
|
|
function netflow_get_data ($start_date, $end_date, $command, $unique_id, $aggregate, $max, $unit) {
|
2012-01-11 17:34:53 +01:00
|
|
|
global $nfdump_date_format;
|
|
|
|
global $config;
|
2012-07-18 15:25:51 +02:00
|
|
|
|
2012-01-11 17:34:53 +01:00
|
|
|
// If there is aggregation calculate the top n
|
|
|
|
if ($aggregate != 'none') {
|
2012-01-13 14:14:16 +01:00
|
|
|
$values['data'] = array ();
|
|
|
|
$values['sources'] = array ();
|
|
|
|
$agg_command = $command . " -s $aggregate/$unit -n $max -t ".date($nfdump_date_format, $start_date).'-'.date($nfdump_date_format, $end_date);
|
2012-01-11 17:34:53 +01:00
|
|
|
exec($agg_command, $string);
|
2012-07-18 15:25:51 +02:00
|
|
|
|
2012-01-11 17:34:53 +01:00
|
|
|
foreach($string as $line){
|
|
|
|
if ($line=='') {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$line = preg_replace('/\(\s*\S+\)/','',$line);
|
|
|
|
$line = preg_replace('/\s+/',' ',$line);
|
|
|
|
$val = explode(' ',$line);
|
2012-01-13 14:14:16 +01:00
|
|
|
$values['sources'][$val[4]] = 1;
|
2012-01-11 17:34:53 +01:00
|
|
|
}
|
2012-07-18 15:25:51 +02:00
|
|
|
}
|
|
|
|
else {
|
2012-01-13 14:14:16 +01:00
|
|
|
$values = array ();
|
2012-01-11 17:34:53 +01:00
|
|
|
}
|
2012-07-18 15:25:51 +02:00
|
|
|
|
2012-01-13 14:14:16 +01:00
|
|
|
// Load cache
|
|
|
|
$cache_file = $config['attachment_store'] . '/netflow_' . $unique_id . '.cache';
|
|
|
|
$last_timestamp = netflow_load_cache ($values, $cache_file, $start_date, $end_date, $aggregate);
|
|
|
|
if ($last_timestamp < $end_date) {
|
2012-07-18 15:25:51 +02:00
|
|
|
|
2012-01-13 14:14:16 +01:00
|
|
|
$last_timestamp++;
|
2012-07-18 15:25:51 +02:00
|
|
|
|
2012-01-13 14:14:16 +01:00
|
|
|
// Execute nfdump and save its output in a temporary file
|
|
|
|
$temp_file = $config['attachment_store'] . '/netflow_' . $unique_id . '.tmp';
|
|
|
|
$command .= ' -t '.date($nfdump_date_format, $last_timestamp).'-'.date($nfdump_date_format, $end_date);
|
|
|
|
exec("$command > $temp_file");
|
2012-07-18 15:25:51 +02:00
|
|
|
|
2012-01-13 14:14:16 +01:00
|
|
|
// Parse data file
|
|
|
|
// We must parse from $start_date to avoid creating new intervals!
|
|
|
|
netflow_parse_file ($start_date, $end_date, $temp_file, $values, $aggregate, $unit);
|
2012-01-11 17:34:53 +01:00
|
|
|
|
2012-01-13 14:14:16 +01:00
|
|
|
unlink ($temp_file);
|
2012-01-11 17:34:53 +01:00
|
|
|
}
|
2012-07-18 15:25:51 +02:00
|
|
|
|
2012-01-13 14:14:16 +01:00
|
|
|
// Save cache
|
|
|
|
if ($aggregate == 'none') {
|
|
|
|
netflow_save_cache ($values, $cache_file);
|
|
|
|
}
|
2012-08-02 Miguel de Dios <miguel.dedios@artica.es>
* pandoradb_data.sql, pandoradb.data.postgreSQL.sql,
pandoradb.data.oracle.sql, include/functions_config.php: fixed the
"list_ACL_IPs_for_API" update.
* operation/events/events_marquee.php, godmode/setup/setup.php,
godmode/reporting/graph_builder.php,
godmode/reporting/map_builder.php, godmode/reporting/graphs.php,
godmode/reporting/visual_console_builder.wizard.php,
godmode/reporting/visual_console_builder.php,
godmode/alerts/configure_alert_compound.php,
godmode/alerts/alert_list.php,
godmode/alerts/configure_alert_template.php,
godmode/alerts/alert_templates.php,
godmode/alerts/configure_alert_action.php,
godmode/alerts/configure_alert_command.php,
godmode/alerts/alert_actions.php,
godmode/alerts/alert_list.builder.php,
godmode/alerts/configure_alert_special_days.php,
include/functions_api.php, include/functions_ui.php,
include/functions_netflow.php, include/functions_alerts.php,
include/functions_menu.php, include/functions_messages.php: cleaned
source code style.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@6846 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2012-08-03 14:48:09 +02:00
|
|
|
|
2012-01-11 17:34:53 +01:00
|
|
|
return $values;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns netflow stats for the given period in an array.
|
|
|
|
*
|
|
|
|
* @param string start_date Period start date.
|
|
|
|
* @param string end_date Period end date.
|
|
|
|
* @param string command Command used to retrieve netflow data.
|
|
|
|
* @param string aggregate Aggregate field.
|
|
|
|
* @param int max Maximum number of aggregates.
|
|
|
|
* @param string unit Unit to show.
|
|
|
|
*
|
|
|
|
* @return An array with netflow stats.
|
|
|
|
*/
|
|
|
|
function netflow_get_stats ($start_date, $end_date, $command, $aggregate, $max, $unit){
|
|
|
|
global $nfdump_date_format;
|
2012-07-18 15:25:51 +02:00
|
|
|
|
2012-01-13 15:52:52 +01:00
|
|
|
$command .= " -s $aggregate/$unit -n $max -t " .date($nfdump_date_format, $start_date).'-'.date($nfdump_date_format, $end_date);
|
2012-01-11 17:34:53 +01:00
|
|
|
exec($command, $string);
|
2012-07-18 15:25:51 +02:00
|
|
|
|
2012-08-02 Miguel de Dios <miguel.dedios@artica.es>
* pandoradb_data.sql, pandoradb.data.postgreSQL.sql,
pandoradb.data.oracle.sql, include/functions_config.php: fixed the
"list_ACL_IPs_for_API" update.
* operation/events/events_marquee.php, godmode/setup/setup.php,
godmode/reporting/graph_builder.php,
godmode/reporting/map_builder.php, godmode/reporting/graphs.php,
godmode/reporting/visual_console_builder.wizard.php,
godmode/reporting/visual_console_builder.php,
godmode/alerts/configure_alert_compound.php,
godmode/alerts/alert_list.php,
godmode/alerts/configure_alert_template.php,
godmode/alerts/alert_templates.php,
godmode/alerts/configure_alert_action.php,
godmode/alerts/configure_alert_command.php,
godmode/alerts/alert_actions.php,
godmode/alerts/alert_list.builder.php,
godmode/alerts/configure_alert_special_days.php,
include/functions_api.php, include/functions_ui.php,
include/functions_netflow.php, include/functions_alerts.php,
include/functions_menu.php, include/functions_messages.php: cleaned
source code style.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@6846 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2012-08-03 14:48:09 +02:00
|
|
|
if (! is_array($string)) {
|
2012-01-11 17:34:53 +01:00
|
|
|
return array ();
|
|
|
|
}
|
|
|
|
|
|
|
|
$i = 0;
|
|
|
|
$values = array();
|
2012-08-02 Miguel de Dios <miguel.dedios@artica.es>
* pandoradb_data.sql, pandoradb.data.postgreSQL.sql,
pandoradb.data.oracle.sql, include/functions_config.php: fixed the
"list_ACL_IPs_for_API" update.
* operation/events/events_marquee.php, godmode/setup/setup.php,
godmode/reporting/graph_builder.php,
godmode/reporting/map_builder.php, godmode/reporting/graphs.php,
godmode/reporting/visual_console_builder.wizard.php,
godmode/reporting/visual_console_builder.php,
godmode/alerts/configure_alert_compound.php,
godmode/alerts/alert_list.php,
godmode/alerts/configure_alert_template.php,
godmode/alerts/alert_templates.php,
godmode/alerts/configure_alert_action.php,
godmode/alerts/configure_alert_command.php,
godmode/alerts/alert_actions.php,
godmode/alerts/alert_list.builder.php,
godmode/alerts/configure_alert_special_days.php,
include/functions_api.php, include/functions_ui.php,
include/functions_netflow.php, include/functions_alerts.php,
include/functions_menu.php, include/functions_messages.php: cleaned
source code style.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@6846 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2012-08-03 14:48:09 +02:00
|
|
|
foreach ($string as $line) {
|
2012-01-11 17:34:53 +01:00
|
|
|
if ($line == '') {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
$line = preg_replace('/\(\s*\S+\)/','',$line);
|
|
|
|
$line = preg_replace('/\s+/',' ',$line);
|
|
|
|
$val = explode(' ',$line);
|
2012-07-18 15:25:51 +02:00
|
|
|
|
2012-01-11 17:34:53 +01:00
|
|
|
$values[$i]['date'] = $val[0];
|
|
|
|
$values[$i]['time'] = $val[1];
|
|
|
|
|
|
|
|
//create field to sort array
|
|
|
|
$date = $val[0];
|
|
|
|
$time = $val[1];
|
|
|
|
$end_date = strtotime ($date." ".$time);
|
|
|
|
$values[$i]['datetime'] = $end_date;
|
|
|
|
$values[$i]['agg'] = $val[4];
|
|
|
|
|
|
|
|
switch ($unit){
|
2012-01-17 15:01:49 +01:00
|
|
|
case "flows":
|
|
|
|
$values[$i]['data'] = $val[5];
|
|
|
|
break;
|
2012-01-11 17:34:53 +01:00
|
|
|
case "packets":
|
|
|
|
$values[$i]['data'] = $val[6];
|
|
|
|
break;
|
|
|
|
case "bytes":
|
|
|
|
default:
|
|
|
|
$values[$i]['data'] = $val[7];
|
|
|
|
break;
|
2012-07-18 15:25:51 +02:00
|
|
|
}
|
2012-01-11 17:34:53 +01:00
|
|
|
$i++;
|
|
|
|
}
|
2012-07-18 15:25:51 +02:00
|
|
|
|
2012-01-11 17:34:53 +01:00
|
|
|
sort_netflow_data ($values);
|
2012-07-18 15:25:51 +02:00
|
|
|
|
2012-01-11 17:34:53 +01:00
|
|
|
return $values;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the command needed to run nfdump for the given filter.
|
|
|
|
*
|
|
|
|
* @param array filter Netflow filter.
|
|
|
|
*
|
|
|
|
* @return Command to run.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
function netflow_get_command ($filter) {
|
|
|
|
global $config;
|
2012-07-18 15:25:51 +02:00
|
|
|
|
2012-01-11 17:34:53 +01:00
|
|
|
// Build command
|
|
|
|
$command = 'nfdump -q -N -m';
|
|
|
|
|
|
|
|
// Netflow data path
|
|
|
|
if (isset($config['netflow_path']) && $config['netflow_path'] != '') {
|
|
|
|
$command .= ' -R '.$config['netflow_path'];
|
|
|
|
}
|
2012-07-18 15:25:51 +02:00
|
|
|
|
2012-01-24 Ramon Novoa <rnovoa@artica.es>
* include/functions_config.php,
include/functions_netflow.php,
pandoradb.sql,
pandoradb.postgreSQL.sql,
pandoradb.oracle.sql,
operation/netflow/nf_live_view.php,
extras/pandoradb_migrate_4.0.x_to_4.1.mysql.sql,
extras/pandoradb_migrate_4.0.x_to_4.1.oracle.sql,
extras/pandoradb_migrate_4.0.x_to_4.1.postgreSQL.sql,
godmode/agentes/module_manager_editor_prediction.php,
godmode/agentes/configurar_agente.php,
godmode/menu.php,
godmode/netflow/nf_edit_form.php: Added support for enterprise
netflow modules.
* godmode/netflow/nf_manage.php: Moved to
godmode/setup/setup_netflow.php.
* godmode/netflow/nf_option_form.php: Removed from repository. Not used.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@5416 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2012-01-24 18:11:12 +01:00
|
|
|
// Filter options
|
|
|
|
$command .= netflow_get_filter_arguments ($filter);
|
2012-07-18 15:25:51 +02:00
|
|
|
|
2012-01-24 Ramon Novoa <rnovoa@artica.es>
* include/functions_config.php,
include/functions_netflow.php,
pandoradb.sql,
pandoradb.postgreSQL.sql,
pandoradb.oracle.sql,
operation/netflow/nf_live_view.php,
extras/pandoradb_migrate_4.0.x_to_4.1.mysql.sql,
extras/pandoradb_migrate_4.0.x_to_4.1.oracle.sql,
extras/pandoradb_migrate_4.0.x_to_4.1.postgreSQL.sql,
godmode/agentes/module_manager_editor_prediction.php,
godmode/agentes/configurar_agente.php,
godmode/menu.php,
godmode/netflow/nf_edit_form.php: Added support for enterprise
netflow modules.
* godmode/netflow/nf_manage.php: Moved to
godmode/setup/setup_netflow.php.
* godmode/netflow/nf_option_form.php: Removed from repository. Not used.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@5416 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2012-01-24 18:11:12 +01:00
|
|
|
return $command;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the nfdump command line arguments that match the given filter.
|
|
|
|
*
|
|
|
|
* @param array filter Netflow filter.
|
|
|
|
*
|
|
|
|
* @return Command line argument string.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
function netflow_get_filter_arguments ($filter) {
|
2012-07-18 15:25:51 +02:00
|
|
|
|
2012-01-17 15:01:49 +01:00
|
|
|
// Advanced filter
|
2012-01-11 17:34:53 +01:00
|
|
|
$filter_args = '';
|
2012-01-17 15:01:49 +01:00
|
|
|
if ($filter['advanced_filter'] != '') {
|
2012-01-17 16:37:50 +01:00
|
|
|
$filter_args = preg_replace('/["\r\n]/','', io_safe_output ($filter['advanced_filter']));
|
2012-01-24 Ramon Novoa <rnovoa@artica.es>
* include/functions_config.php,
include/functions_netflow.php,
pandoradb.sql,
pandoradb.postgreSQL.sql,
pandoradb.oracle.sql,
operation/netflow/nf_live_view.php,
extras/pandoradb_migrate_4.0.x_to_4.1.mysql.sql,
extras/pandoradb_migrate_4.0.x_to_4.1.oracle.sql,
extras/pandoradb_migrate_4.0.x_to_4.1.postgreSQL.sql,
godmode/agentes/module_manager_editor_prediction.php,
godmode/agentes/configurar_agente.php,
godmode/menu.php,
godmode/netflow/nf_edit_form.php: Added support for enterprise
netflow modules.
* godmode/netflow/nf_manage.php: Moved to
godmode/setup/setup_netflow.php.
* godmode/netflow/nf_option_form.php: Removed from repository. Not used.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@5416 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2012-01-24 18:11:12 +01:00
|
|
|
return ' "(' . $filter_args . ')"';
|
2012-01-17 15:01:49 +01:00
|
|
|
}
|
2012-07-18 15:25:51 +02:00
|
|
|
|
2012-01-17 15:01:49 +01:00
|
|
|
// Normal filter
|
2012-08-02 Miguel de Dios <miguel.dedios@artica.es>
* pandoradb_data.sql, pandoradb.data.postgreSQL.sql,
pandoradb.data.oracle.sql, include/functions_config.php: fixed the
"list_ACL_IPs_for_API" update.
* operation/events/events_marquee.php, godmode/setup/setup.php,
godmode/reporting/graph_builder.php,
godmode/reporting/map_builder.php, godmode/reporting/graphs.php,
godmode/reporting/visual_console_builder.wizard.php,
godmode/reporting/visual_console_builder.php,
godmode/alerts/configure_alert_compound.php,
godmode/alerts/alert_list.php,
godmode/alerts/configure_alert_template.php,
godmode/alerts/alert_templates.php,
godmode/alerts/configure_alert_action.php,
godmode/alerts/configure_alert_command.php,
godmode/alerts/alert_actions.php,
godmode/alerts/alert_list.builder.php,
godmode/alerts/configure_alert_special_days.php,
include/functions_api.php, include/functions_ui.php,
include/functions_netflow.php, include/functions_alerts.php,
include/functions_menu.php, include/functions_messages.php: cleaned
source code style.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@6846 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2012-08-03 14:48:09 +02:00
|
|
|
if ($filter['ip_dst'] != '') {
|
2012-01-11 17:34:53 +01:00
|
|
|
$filter_args .= ' "(';
|
|
|
|
$val_ipdst = explode(',', $filter['ip_dst']);
|
|
|
|
for($i = 0; $i < count ($val_ipdst); $i++){
|
|
|
|
if ($i > 0) {
|
|
|
|
$filter_args .= ' or ';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (netflow_is_net ($val_ipdst[$i]) == 0) {
|
|
|
|
$filter_args .= 'dst ip '.$val_ipdst[$i];
|
2012-07-18 15:25:51 +02:00
|
|
|
}
|
|
|
|
else {
|
2012-01-11 17:34:53 +01:00
|
|
|
$filter_args .= 'dst net '.$val_ipdst[$i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$filter_args .= ')';
|
|
|
|
}
|
2012-08-02 Miguel de Dios <miguel.dedios@artica.es>
* pandoradb_data.sql, pandoradb.data.postgreSQL.sql,
pandoradb.data.oracle.sql, include/functions_config.php: fixed the
"list_ACL_IPs_for_API" update.
* operation/events/events_marquee.php, godmode/setup/setup.php,
godmode/reporting/graph_builder.php,
godmode/reporting/map_builder.php, godmode/reporting/graphs.php,
godmode/reporting/visual_console_builder.wizard.php,
godmode/reporting/visual_console_builder.php,
godmode/alerts/configure_alert_compound.php,
godmode/alerts/alert_list.php,
godmode/alerts/configure_alert_template.php,
godmode/alerts/alert_templates.php,
godmode/alerts/configure_alert_action.php,
godmode/alerts/configure_alert_command.php,
godmode/alerts/alert_actions.php,
godmode/alerts/alert_list.builder.php,
godmode/alerts/configure_alert_special_days.php,
include/functions_api.php, include/functions_ui.php,
include/functions_netflow.php, include/functions_alerts.php,
include/functions_menu.php, include/functions_messages.php: cleaned
source code style.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@6846 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2012-08-03 14:48:09 +02:00
|
|
|
if ($filter['ip_src'] != '') {
|
2012-01-11 17:34:53 +01:00
|
|
|
if ($filter_args == '') {
|
|
|
|
$filter_args .= ' "(';
|
2012-07-18 15:25:51 +02:00
|
|
|
}
|
|
|
|
else {
|
2012-01-11 17:34:53 +01:00
|
|
|
$filter_args .= ' and (';
|
|
|
|
}
|
|
|
|
$val_ipsrc = explode(',', $filter['ip_src']);
|
2012-08-02 Miguel de Dios <miguel.dedios@artica.es>
* pandoradb_data.sql, pandoradb.data.postgreSQL.sql,
pandoradb.data.oracle.sql, include/functions_config.php: fixed the
"list_ACL_IPs_for_API" update.
* operation/events/events_marquee.php, godmode/setup/setup.php,
godmode/reporting/graph_builder.php,
godmode/reporting/map_builder.php, godmode/reporting/graphs.php,
godmode/reporting/visual_console_builder.wizard.php,
godmode/reporting/visual_console_builder.php,
godmode/alerts/configure_alert_compound.php,
godmode/alerts/alert_list.php,
godmode/alerts/configure_alert_template.php,
godmode/alerts/alert_templates.php,
godmode/alerts/configure_alert_action.php,
godmode/alerts/configure_alert_command.php,
godmode/alerts/alert_actions.php,
godmode/alerts/alert_list.builder.php,
godmode/alerts/configure_alert_special_days.php,
include/functions_api.php, include/functions_ui.php,
include/functions_netflow.php, include/functions_alerts.php,
include/functions_menu.php, include/functions_messages.php: cleaned
source code style.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@6846 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2012-08-03 14:48:09 +02:00
|
|
|
for ($i = 0; $i < count ($val_ipsrc); $i++) {
|
2012-01-11 17:34:53 +01:00
|
|
|
if ($i > 0) {
|
|
|
|
$filter_args .= ' or ';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (netflow_is_net ($val_ipsrc[$i]) == 0) {
|
|
|
|
$filter_args .= 'src ip '.$val_ipsrc[$i];
|
2012-07-18 15:25:51 +02:00
|
|
|
}
|
|
|
|
else {
|
2012-01-11 17:34:53 +01:00
|
|
|
$filter_args .= 'src net '.$val_ipsrc[$i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$filter_args .= ')';
|
|
|
|
}
|
|
|
|
if ($filter['dst_port'] != 0) {
|
|
|
|
if ($filter_args == '') {
|
|
|
|
$filter_args .= ' "(';
|
2012-07-18 15:25:51 +02:00
|
|
|
}
|
|
|
|
else {
|
2012-01-11 17:34:53 +01:00
|
|
|
$filter_args .= ' and (';
|
|
|
|
}
|
|
|
|
$val_dstport = explode(',', $filter['dst_port']);
|
2012-08-02 Miguel de Dios <miguel.dedios@artica.es>
* pandoradb_data.sql, pandoradb.data.postgreSQL.sql,
pandoradb.data.oracle.sql, include/functions_config.php: fixed the
"list_ACL_IPs_for_API" update.
* operation/events/events_marquee.php, godmode/setup/setup.php,
godmode/reporting/graph_builder.php,
godmode/reporting/map_builder.php, godmode/reporting/graphs.php,
godmode/reporting/visual_console_builder.wizard.php,
godmode/reporting/visual_console_builder.php,
godmode/alerts/configure_alert_compound.php,
godmode/alerts/alert_list.php,
godmode/alerts/configure_alert_template.php,
godmode/alerts/alert_templates.php,
godmode/alerts/configure_alert_action.php,
godmode/alerts/configure_alert_command.php,
godmode/alerts/alert_actions.php,
godmode/alerts/alert_list.builder.php,
godmode/alerts/configure_alert_special_days.php,
include/functions_api.php, include/functions_ui.php,
include/functions_netflow.php, include/functions_alerts.php,
include/functions_menu.php, include/functions_messages.php: cleaned
source code style.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@6846 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2012-08-03 14:48:09 +02:00
|
|
|
for ($i = 0; $i < count ($val_dstport); $i++) {
|
2012-01-11 17:34:53 +01:00
|
|
|
if ($i > 0) {
|
|
|
|
$filter_args .= ' or ';
|
|
|
|
}
|
|
|
|
$filter_args .= 'dst port '.$val_dstport[$i];
|
|
|
|
}
|
|
|
|
$filter_args .= ')';
|
|
|
|
}
|
|
|
|
if ($filter['src_port'] != 0) {
|
|
|
|
if ($filter_args == '') {
|
|
|
|
$filter_args .= ' "(';
|
2012-07-18 15:25:51 +02:00
|
|
|
}
|
|
|
|
else {
|
2012-01-11 17:34:53 +01:00
|
|
|
$filter_args .= ' and (';
|
|
|
|
}
|
|
|
|
$val_srcport = explode(',', $filter['src_port']);
|
2012-08-02 Miguel de Dios <miguel.dedios@artica.es>
* pandoradb_data.sql, pandoradb.data.postgreSQL.sql,
pandoradb.data.oracle.sql, include/functions_config.php: fixed the
"list_ACL_IPs_for_API" update.
* operation/events/events_marquee.php, godmode/setup/setup.php,
godmode/reporting/graph_builder.php,
godmode/reporting/map_builder.php, godmode/reporting/graphs.php,
godmode/reporting/visual_console_builder.wizard.php,
godmode/reporting/visual_console_builder.php,
godmode/alerts/configure_alert_compound.php,
godmode/alerts/alert_list.php,
godmode/alerts/configure_alert_template.php,
godmode/alerts/alert_templates.php,
godmode/alerts/configure_alert_action.php,
godmode/alerts/configure_alert_command.php,
godmode/alerts/alert_actions.php,
godmode/alerts/alert_list.builder.php,
godmode/alerts/configure_alert_special_days.php,
include/functions_api.php, include/functions_ui.php,
include/functions_netflow.php, include/functions_alerts.php,
include/functions_menu.php, include/functions_messages.php: cleaned
source code style.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@6846 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2012-08-03 14:48:09 +02:00
|
|
|
for ($i = 0; $i < count ($val_srcport); $i++) {
|
2012-01-11 17:34:53 +01:00
|
|
|
if ($i > 0) {
|
|
|
|
$filter_args .= ' or ';
|
|
|
|
}
|
|
|
|
$filter_args .= 'src port '.$val_srcport[$i];
|
|
|
|
}
|
|
|
|
$filter_args .= ')';
|
|
|
|
}
|
|
|
|
if ($filter_args != '') {
|
2012-01-24 Ramon Novoa <rnovoa@artica.es>
* include/functions_config.php,
include/functions_netflow.php,
pandoradb.sql,
pandoradb.postgreSQL.sql,
pandoradb.oracle.sql,
operation/netflow/nf_live_view.php,
extras/pandoradb_migrate_4.0.x_to_4.1.mysql.sql,
extras/pandoradb_migrate_4.0.x_to_4.1.oracle.sql,
extras/pandoradb_migrate_4.0.x_to_4.1.postgreSQL.sql,
godmode/agentes/module_manager_editor_prediction.php,
godmode/agentes/configurar_agente.php,
godmode/menu.php,
godmode/netflow/nf_edit_form.php: Added support for enterprise
netflow modules.
* godmode/netflow/nf_manage.php: Moved to
godmode/setup/setup_netflow.php.
* godmode/netflow/nf_option_form.php: Removed from repository. Not used.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@5416 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2012-01-24 18:11:12 +01:00
|
|
|
$filter_args .= '"';
|
2012-01-11 17:34:53 +01:00
|
|
|
}
|
2012-07-18 15:25:51 +02:00
|
|
|
|
2012-01-24 Ramon Novoa <rnovoa@artica.es>
* include/functions_config.php,
include/functions_netflow.php,
pandoradb.sql,
pandoradb.postgreSQL.sql,
pandoradb.oracle.sql,
operation/netflow/nf_live_view.php,
extras/pandoradb_migrate_4.0.x_to_4.1.mysql.sql,
extras/pandoradb_migrate_4.0.x_to_4.1.oracle.sql,
extras/pandoradb_migrate_4.0.x_to_4.1.postgreSQL.sql,
godmode/agentes/module_manager_editor_prediction.php,
godmode/agentes/configurar_agente.php,
godmode/menu.php,
godmode/netflow/nf_edit_form.php: Added support for enterprise
netflow modules.
* godmode/netflow/nf_manage.php: Moved to
godmode/setup/setup_netflow.php.
* godmode/netflow/nf_option_form.php: Removed from repository. Not used.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@5416 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2012-01-24 18:11:12 +01:00
|
|
|
return $filter_args;
|
2011-12-21 16:28:01 +01:00
|
|
|
}
|
|
|
|
|
2012-01-13 14:14:16 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Parses netflow data from the given file.
|
|
|
|
*
|
|
|
|
* @param string start_date Period start date.
|
|
|
|
* @param string end_date Period end date.
|
|
|
|
* @param string file File that contains netflow data.
|
|
|
|
* @param array values Array where netflow data will be placed.
|
|
|
|
* @param string aggregate Aggregate field.
|
|
|
|
* @param string unit Unit to show.
|
|
|
|
*
|
|
|
|
* @return Timestamp of the last data read.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
function netflow_parse_file ($start_date, $end_date, $file, &$values, $aggregate, $unit) {
|
|
|
|
global $config;
|
2012-07-18 15:25:51 +02:00
|
|
|
|
2012-01-13 14:14:16 +01:00
|
|
|
// Last timestamp read
|
|
|
|
$last_timestamp = $start_date;
|
2012-07-18 15:25:51 +02:00
|
|
|
|
2012-01-13 14:14:16 +01:00
|
|
|
// Open the data file
|
|
|
|
$fh = @fopen ($file, "r");
|
|
|
|
if ($fh === FALSE) {
|
|
|
|
return $last_timestamp;
|
|
|
|
}
|
2012-07-18 15:25:51 +02:00
|
|
|
|
2012-01-13 14:14:16 +01:00
|
|
|
// Calculate the number of intervals
|
|
|
|
$num_intervals = $config['graph_res'] * 50;
|
|
|
|
$period = $end_date - $start_date;
|
|
|
|
$interval_length = (int) ($period / $num_intervals);
|
2012-07-18 15:25:51 +02:00
|
|
|
|
2012-01-13 14:14:16 +01:00
|
|
|
// Parse flow data
|
|
|
|
$read_flag = 1;
|
|
|
|
$flow = array ();
|
|
|
|
for ($i = 0; $i < $num_intervals; $i++) {
|
|
|
|
$timestamp = $start_date + ($interval_length * $i);
|
|
|
|
|
|
|
|
if ($aggregate != 'none') {
|
|
|
|
$interval_total = array ();
|
|
|
|
$interval_count = array ();
|
2012-07-18 15:25:51 +02:00
|
|
|
}
|
|
|
|
else {
|
2012-01-13 14:14:16 +01:00
|
|
|
$interval_total = 0;
|
|
|
|
$interval_count = 0;
|
|
|
|
}
|
2012-07-18 15:25:51 +02:00
|
|
|
|
2012-01-13 14:14:16 +01:00
|
|
|
do {
|
|
|
|
if ($read_flag == 1) {
|
|
|
|
$read_flag = 0;
|
|
|
|
$line = fgets($fh, 4096);
|
|
|
|
if ($line === false) {
|
|
|
|
$read_flag = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
$line = preg_replace('/\s+/',' ',$line);
|
|
|
|
$val = explode(' ',$line);
|
|
|
|
if (! isset ($val[6])) {
|
|
|
|
$read_flag = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
$flow['date'] = $val[0];
|
|
|
|
$flow['time'] = $val[1];
|
|
|
|
|
2012-07-18 15:25:51 +02:00
|
|
|
switch ($aggregate) {
|
2012-01-13 14:14:16 +01:00
|
|
|
case "proto":
|
|
|
|
$flow['agg'] = $val[3];
|
|
|
|
break;
|
|
|
|
case "srcip":
|
|
|
|
$val2 = explode(':', $val[4]);
|
|
|
|
$flow['agg'] = $val2[0];
|
|
|
|
break;
|
|
|
|
case "srcport":
|
|
|
|
$val2 = explode(':', $val[4]);
|
|
|
|
$flow['agg'] = $val2[1];
|
|
|
|
break;
|
|
|
|
case "dstip":
|
|
|
|
$val2 = explode(':', $val[6]);
|
|
|
|
$flow['agg'] = $val2[0];
|
|
|
|
break;
|
|
|
|
case "dstport":
|
|
|
|
$val2 = explode(':', $val[6]);
|
|
|
|
$flow['agg'] = $val2[1];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch ($unit) {
|
2012-01-17 15:01:49 +01:00
|
|
|
case "flows":
|
|
|
|
$flow['data'] = $val[6];
|
|
|
|
break;
|
2012-01-13 14:14:16 +01:00
|
|
|
case "packets":
|
|
|
|
$flow['data'] = $val[7];
|
|
|
|
break;
|
|
|
|
case "bytes":
|
|
|
|
$flow['data'] = $val[8];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
$flow['timestamp'] = strtotime ($flow['date'] . " " . $flow['time']);
|
|
|
|
$last_timestamp = $flow['timestamp'];
|
|
|
|
}
|
|
|
|
if ($flow['timestamp'] >= $timestamp && $flow['timestamp'] <= $timestamp + $interval_length) {
|
|
|
|
$read_flag = 1;
|
|
|
|
if ($aggregate != 'none') {
|
|
|
|
if (isset ($values['sources'][$flow['agg']])) {
|
|
|
|
if (! isset ($interval_total[$flow['agg']])) {
|
|
|
|
$interval_total[$flow['agg']] = 0;
|
|
|
|
$interval_count[$flow['agg']] = 0;
|
|
|
|
}
|
|
|
|
$interval_total[$flow['agg']] += $flow['data'];
|
|
|
|
$interval_count[$flow['agg']] += 1;
|
|
|
|
}
|
2012-07-18 15:25:51 +02:00
|
|
|
}
|
|
|
|
else {
|
2012-01-13 14:14:16 +01:00
|
|
|
$interval_total += $flow['data'];
|
|
|
|
$interval_count += 1;
|
|
|
|
}
|
|
|
|
}
|
2012-07-18 15:25:51 +02:00
|
|
|
}
|
|
|
|
while ($read_flag == 1);
|
2012-01-13 14:14:16 +01:00
|
|
|
|
|
|
|
if ($aggregate != 'none') {
|
|
|
|
foreach ($interval_total as $agg => $val) {
|
|
|
|
|
|
|
|
// No data for this interval/aggregate
|
|
|
|
if ($interval_count[$agg] == 0) {
|
|
|
|
continue;
|
|
|
|
}
|
2012-07-18 15:25:51 +02:00
|
|
|
|
2012-01-13 14:14:16 +01:00
|
|
|
// Read previous data for this interval
|
|
|
|
if (isset ($values['data'][$timestamp][$agg])) {
|
|
|
|
$previous_value = $values['data'][$timestamp][$agg];
|
2012-07-18 15:25:51 +02:00
|
|
|
}
|
|
|
|
else {
|
2012-01-13 14:14:16 +01:00
|
|
|
$previous_value = 0;
|
|
|
|
}
|
2012-07-18 15:25:51 +02:00
|
|
|
|
2012-01-13 14:14:16 +01:00
|
|
|
// Calculate interval data
|
|
|
|
$values['data'][$timestamp][$agg] = (int) ($interval_total[$agg] / $interval_count[$agg]);
|
2012-07-18 15:25:51 +02:00
|
|
|
|
2012-01-13 14:14:16 +01:00
|
|
|
// Average with previous data
|
|
|
|
if ($previous_value != 0) {
|
|
|
|
$values['data'][$timestamp][$agg] = (int) (($values['data'][$timestamp][$agg] + $previous_data) / 2);
|
|
|
|
}
|
|
|
|
}
|
2012-07-18 15:25:51 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
|
2012-01-13 14:14:16 +01:00
|
|
|
// No data for this interval
|
|
|
|
if ($interval_count == 0) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Read previous data for this interval
|
|
|
|
if (isset ($values[$timestamp]['data'])) {
|
|
|
|
$previous_value = $values[$timestamp]['data'];
|
2012-07-18 15:25:51 +02:00
|
|
|
}
|
|
|
|
else {
|
2012-01-13 14:14:16 +01:00
|
|
|
$previous_value = 0;
|
|
|
|
}
|
2012-07-18 15:25:51 +02:00
|
|
|
|
2012-01-13 14:14:16 +01:00
|
|
|
// Calculate interval data
|
|
|
|
$values[$timestamp]['data'] = (int) ($interval_total / $interval_count);
|
|
|
|
|
|
|
|
// Average with previous data
|
|
|
|
if ($previous_value != 0) {
|
|
|
|
$values[$timestamp]['data'] = (int) (($values[$timestamp]['data'] + $previous_value) / 2);
|
|
|
|
}
|
2012-07-18 15:25:51 +02:00
|
|
|
|
2012-01-13 14:14:16 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|
2012-07-18 15:25:51 +02:00
|
|
|
|
2012-01-13 14:14:16 +01:00
|
|
|
fclose ($fh);
|
|
|
|
return $last_timestamp;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Save data to the specified cache file.
|
|
|
|
*
|
|
|
|
* @param array data Data array.
|
|
|
|
* @param string cache_file Cache file name.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
function netflow_save_cache ($data, $cache_file) {
|
2012-07-18 15:25:51 +02:00
|
|
|
|
2012-01-13 14:14:16 +01:00
|
|
|
@file_put_contents ($cache_file, serialize ($data));
|
2012-07-18 15:25:51 +02:00
|
|
|
|
2012-01-13 14:14:16 +01:00
|
|
|
return;
|
|
|
|
}
|
2012-07-18 15:25:51 +02:00
|
|
|
|
2012-01-13 14:14:16 +01:00
|
|
|
/**
|
|
|
|
* Load data from the specified cache file.
|
|
|
|
*
|
|
|
|
* @param string data Array were cache data will be stored.
|
|
|
|
* @param string cache_file Cache file name.
|
|
|
|
* @param string start_date Period start date.
|
|
|
|
* @param string end_date Period end date.
|
|
|
|
*
|
|
|
|
* @return Timestamp of the last data read from cache.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
function netflow_load_cache (&$data, $cache_file, $start_date, $end_date, $aggregate) {
|
|
|
|
global $config;
|
2012-07-10 Miguel de Dios <miguel.dedios@artica.es>
* include/constants.php: added more constants into the constants
block of time conversion to seconds.
* godmode/alerts/alert_commands.php, godmode/setup/performance.php,
include/help/en/help_date_format.php, include/functions_netflow.php,
include/functions_tags.php, include/graphs/functions_pchart.php,
include/functions_modules.php, extensions/agents_modules.php,
extensions/update_manager.php, extensions/resource_exportation.php,
extensions/module_groups.php,
extensions/update_manager/lib/libupdate_manager_client.php,
extensions/system_info.php, operation/events/events_rss.php,
operation/events/export_csv.php, mobile/operation/events/events.php,
mobile/include/system.class.php: used the new constants time instead
the magic numbers, and cleaned source code style.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@6762 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2012-07-10 15:31:34 +02:00
|
|
|
|
2012-01-13 14:14:16 +01:00
|
|
|
// Open cache file
|
|
|
|
$cache_data = @file_get_contents ($cache_file);
|
|
|
|
$cache_data = @unserialize ($cache_data);
|
2012-07-10 Miguel de Dios <miguel.dedios@artica.es>
* include/constants.php: added more constants into the constants
block of time conversion to seconds.
* godmode/alerts/alert_commands.php, godmode/setup/performance.php,
include/help/en/help_date_format.php, include/functions_netflow.php,
include/functions_tags.php, include/graphs/functions_pchart.php,
include/functions_modules.php, extensions/agents_modules.php,
extensions/update_manager.php, extensions/resource_exportation.php,
extensions/module_groups.php,
extensions/update_manager/lib/libupdate_manager_client.php,
extensions/system_info.php, operation/events/events_rss.php,
operation/events/export_csv.php, mobile/operation/events/events.php,
mobile/include/system.class.php: used the new constants time instead
the magic numbers, and cleaned source code style.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@6762 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2012-07-10 15:31:34 +02:00
|
|
|
|
2012-01-13 14:14:16 +01:00
|
|
|
// Calculate the number of intervals
|
|
|
|
$num_intervals = $config['graph_res'] * 50;
|
|
|
|
$period = $end_date - $start_date;
|
|
|
|
$interval_length = (int) ($period / $num_intervals);
|
|
|
|
$last_timestamp = $start_date;
|
2012-07-10 Miguel de Dios <miguel.dedios@artica.es>
* include/constants.php: added more constants into the constants
block of time conversion to seconds.
* godmode/alerts/alert_commands.php, godmode/setup/performance.php,
include/help/en/help_date_format.php, include/functions_netflow.php,
include/functions_tags.php, include/graphs/functions_pchart.php,
include/functions_modules.php, extensions/agents_modules.php,
extensions/update_manager.php, extensions/resource_exportation.php,
extensions/module_groups.php,
extensions/update_manager/lib/libupdate_manager_client.php,
extensions/system_info.php, operation/events/events_rss.php,
operation/events/export_csv.php, mobile/operation/events/events.php,
mobile/include/system.class.php: used the new constants time instead
the magic numbers, and cleaned source code style.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@6762 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2012-07-10 15:31:34 +02:00
|
|
|
|
2012-01-13 14:14:16 +01:00
|
|
|
// Initializa chart data
|
|
|
|
if ($aggregate == 'none') {
|
|
|
|
if ($cache_data === FALSE) {
|
|
|
|
$cache_data = array ();
|
|
|
|
}
|
|
|
|
for ($i = 0; $i < $num_intervals; $i++) {
|
|
|
|
$timestamp = $start_date + ($interval_length * $i);
|
|
|
|
$interval_count = 0;
|
|
|
|
$interval_total = 0;
|
|
|
|
foreach ($cache_data as $cache_timestamp => $cache_value) {
|
|
|
|
if ($cache_timestamp < $timestamp + $interval_length) {
|
|
|
|
if ($cache_timestamp >= $timestamp) {
|
|
|
|
$interval_count++;
|
|
|
|
$interval_total += $cache_value['data'];
|
|
|
|
$last_timestamp = $cache_timestamp;
|
|
|
|
}
|
|
|
|
unset ($cache_data[$cache_timestamp]);
|
2012-07-10 Miguel de Dios <miguel.dedios@artica.es>
* include/constants.php: added more constants into the constants
block of time conversion to seconds.
* godmode/alerts/alert_commands.php, godmode/setup/performance.php,
include/help/en/help_date_format.php, include/functions_netflow.php,
include/functions_tags.php, include/graphs/functions_pchart.php,
include/functions_modules.php, extensions/agents_modules.php,
extensions/update_manager.php, extensions/resource_exportation.php,
extensions/module_groups.php,
extensions/update_manager/lib/libupdate_manager_client.php,
extensions/system_info.php, operation/events/events_rss.php,
operation/events/export_csv.php, mobile/operation/events/events.php,
mobile/include/system.class.php: used the new constants time instead
the magic numbers, and cleaned source code style.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@6762 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2012-07-10 15:31:34 +02:00
|
|
|
}
|
|
|
|
else {
|
2012-01-13 14:14:16 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-07-10 Miguel de Dios <miguel.dedios@artica.es>
* include/constants.php: added more constants into the constants
block of time conversion to seconds.
* godmode/alerts/alert_commands.php, godmode/setup/performance.php,
include/help/en/help_date_format.php, include/functions_netflow.php,
include/functions_tags.php, include/graphs/functions_pchart.php,
include/functions_modules.php, extensions/agents_modules.php,
extensions/update_manager.php, extensions/resource_exportation.php,
extensions/module_groups.php,
extensions/update_manager/lib/libupdate_manager_client.php,
extensions/system_info.php, operation/events/events_rss.php,
operation/events/export_csv.php, mobile/operation/events/events.php,
mobile/include/system.class.php: used the new constants time instead
the magic numbers, and cleaned source code style.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@6762 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2012-07-10 15:31:34 +02:00
|
|
|
|
2012-01-13 14:14:16 +01:00
|
|
|
if ($interval_count > 0) {
|
|
|
|
$data[$timestamp]['data'] = (int) ($interval_total / $interval_count);
|
2012-07-10 Miguel de Dios <miguel.dedios@artica.es>
* include/constants.php: added more constants into the constants
block of time conversion to seconds.
* godmode/alerts/alert_commands.php, godmode/setup/performance.php,
include/help/en/help_date_format.php, include/functions_netflow.php,
include/functions_tags.php, include/graphs/functions_pchart.php,
include/functions_modules.php, extensions/agents_modules.php,
extensions/update_manager.php, extensions/resource_exportation.php,
extensions/module_groups.php,
extensions/update_manager/lib/libupdate_manager_client.php,
extensions/system_info.php, operation/events/events_rss.php,
operation/events/export_csv.php, mobile/operation/events/events.php,
mobile/include/system.class.php: used the new constants time instead
the magic numbers, and cleaned source code style.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@6762 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2012-07-10 15:31:34 +02:00
|
|
|
}
|
|
|
|
else {
|
2012-01-13 14:14:16 +01:00
|
|
|
$data[$timestamp]['data'] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-07-10 Miguel de Dios <miguel.dedios@artica.es>
* include/constants.php: added more constants into the constants
block of time conversion to seconds.
* godmode/alerts/alert_commands.php, godmode/setup/performance.php,
include/help/en/help_date_format.php, include/functions_netflow.php,
include/functions_tags.php, include/graphs/functions_pchart.php,
include/functions_modules.php, extensions/agents_modules.php,
extensions/update_manager.php, extensions/resource_exportation.php,
extensions/module_groups.php,
extensions/update_manager/lib/libupdate_manager_client.php,
extensions/system_info.php, operation/events/events_rss.php,
operation/events/export_csv.php, mobile/operation/events/events.php,
mobile/include/system.class.php: used the new constants time instead
the magic numbers, and cleaned source code style.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@6762 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2012-07-10 15:31:34 +02:00
|
|
|
else {
|
|
|
|
for ($i = 0; $i < $num_intervals; $i++) {
|
|
|
|
$timestamp = $start_date + ($interval_length * $i);
|
|
|
|
$interval_count = array ();
|
|
|
|
$interval_total = array ();
|
|
|
|
|
|
|
|
foreach ($data['sources'] as $source => $null) {
|
|
|
|
$data['data'][$timestamp][$source] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-13 14:14:16 +01:00
|
|
|
return $last_timestamp;
|
|
|
|
}
|
|
|
|
|
2012-01-20 14:14:09 +01:00
|
|
|
/**
|
|
|
|
* Get the types of netflow charts.
|
|
|
|
*
|
|
|
|
* @return Array of types.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
function netflow_get_chart_types () {
|
2012-07-10 Miguel de Dios <miguel.dedios@artica.es>
* include/constants.php: added more constants into the constants
block of time conversion to seconds.
* godmode/alerts/alert_commands.php, godmode/setup/performance.php,
include/help/en/help_date_format.php, include/functions_netflow.php,
include/functions_tags.php, include/graphs/functions_pchart.php,
include/functions_modules.php, extensions/agents_modules.php,
extensions/update_manager.php, extensions/resource_exportation.php,
extensions/module_groups.php,
extensions/update_manager/lib/libupdate_manager_client.php,
extensions/system_info.php, operation/events/events_rss.php,
operation/events/export_csv.php, mobile/operation/events/events.php,
mobile/include/system.class.php: used the new constants time instead
the magic numbers, and cleaned source code style.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@6762 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2012-07-10 15:31:34 +02:00
|
|
|
|
2012-01-20 14:14:09 +01:00
|
|
|
return array(
|
2012-07-10 Miguel de Dios <miguel.dedios@artica.es>
* include/constants.php: added more constants into the constants
block of time conversion to seconds.
* godmode/alerts/alert_commands.php, godmode/setup/performance.php,
include/help/en/help_date_format.php, include/functions_netflow.php,
include/functions_tags.php, include/graphs/functions_pchart.php,
include/functions_modules.php, extensions/agents_modules.php,
extensions/update_manager.php, extensions/resource_exportation.php,
extensions/module_groups.php,
extensions/update_manager/lib/libupdate_manager_client.php,
extensions/system_info.php, operation/events/events_rss.php,
operation/events/export_csv.php, mobile/operation/events/events.php,
mobile/include/system.class.php: used the new constants time instead
the magic numbers, and cleaned source code style.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@6762 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2012-07-10 15:31:34 +02:00
|
|
|
__('Area graph'),
|
|
|
|
__('Pie graph'),
|
|
|
|
__('Data table'),
|
|
|
|
__('Statistics table'));
|
2012-01-20 14:14:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets valid intervals for a netflow chart in the format:
|
|
|
|
*
|
2012-07-10 Miguel de Dios <miguel.dedios@artica.es>
* include/constants.php: added more constants into the constants
block of time conversion to seconds.
* godmode/alerts/alert_commands.php, godmode/setup/performance.php,
include/help/en/help_date_format.php, include/functions_netflow.php,
include/functions_tags.php, include/graphs/functions_pchart.php,
include/functions_modules.php, extensions/agents_modules.php,
extensions/update_manager.php, extensions/resource_exportation.php,
extensions/module_groups.php,
extensions/update_manager/lib/libupdate_manager_client.php,
extensions/system_info.php, operation/events/events_rss.php,
operation/events/export_csv.php, mobile/operation/events/events.php,
mobile/include/system.class.php: used the new constants time instead
the magic numbers, and cleaned source code style.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@6762 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2012-07-10 15:31:34 +02:00
|
|
|
* interval_length => interval_description
|
2012-01-20 14:14:09 +01:00
|
|
|
*
|
|
|
|
* @return Array of valid intervals.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
function netflow_get_valid_intervals () {
|
2012-07-10 Miguel de Dios <miguel.dedios@artica.es>
* include/constants.php: added more constants into the constants
block of time conversion to seconds.
* godmode/alerts/alert_commands.php, godmode/setup/performance.php,
include/help/en/help_date_format.php, include/functions_netflow.php,
include/functions_tags.php, include/graphs/functions_pchart.php,
include/functions_modules.php, extensions/agents_modules.php,
extensions/update_manager.php, extensions/resource_exportation.php,
extensions/module_groups.php,
extensions/update_manager/lib/libupdate_manager_client.php,
extensions/system_info.php, operation/events/events_rss.php,
operation/events/export_csv.php, mobile/operation/events/events.php,
mobile/include/system.class.php: used the new constants time instead
the magic numbers, and cleaned source code style.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@6762 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2012-07-10 15:31:34 +02:00
|
|
|
return array (
|
|
|
|
(string)SECONDS_10MINUTES => __('10 mins'),
|
|
|
|
(string)SECONDS_15MINUTES => __('15 mins'),
|
|
|
|
(string)SECONDS_30MINUTES => __('30 mins'),
|
|
|
|
(string)SECONDS_1HOUR => __('1 hour'),
|
|
|
|
(string)SECONDS_2HOUR => __('2 hours'),
|
|
|
|
(string)SECONDS_5HOUR => __('5 hours'),
|
|
|
|
(string)SECONDS_12HOURS => __('12 hours'),
|
|
|
|
(string)SECONDS_1DAY => __('1 day'),
|
|
|
|
(string)SECONDS_2DAY => __('2 days'),
|
|
|
|
(string)SECONDS_5DAY => __('5 days'),
|
|
|
|
(string)SECONDS_15DAYS => __('15 days'),
|
|
|
|
(string)SECONDS_1WEEK => __('Last week'),
|
|
|
|
(string)SECONDS_1MONTH => __('Last month'),
|
|
|
|
(string)SECONDS_2MONTHS => __('2 months'),
|
|
|
|
(string)SECONDS_3MONTHS => __('3 months'),
|
|
|
|
(string)SECONDS_6MONTHS => __('6 months'),
|
|
|
|
(string)SECONDS_1YEAR => __('Last year'),
|
|
|
|
(string)SECONDS_2YEARS => __('2 years'));
|
2012-01-20 14:14:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Draw a netflow report item.
|
|
|
|
*
|
|
|
|
* @param string start_date Period start date.
|
|
|
|
* @param string end_date Period end date.
|
|
|
|
* @param string type Chart type.
|
|
|
|
* @param string command Command used to retrieve netflow data.
|
|
|
|
* @param array filter Netflow filter.
|
|
|
|
* @param int max_aggregates Maximum number of aggregates.
|
|
|
|
* @param string unique_id A unique number that is used to generate a cache file.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
function netflow_draw_item ($start_date, $end_date, $type, $filter, $command, $filter, $max_aggregates, $unique_id) {
|
2012-07-10 Miguel de Dios <miguel.dedios@artica.es>
* include/constants.php: added more constants into the constants
block of time conversion to seconds.
* godmode/alerts/alert_commands.php, godmode/setup/performance.php,
include/help/en/help_date_format.php, include/functions_netflow.php,
include/functions_tags.php, include/graphs/functions_pchart.php,
include/functions_modules.php, extensions/agents_modules.php,
extensions/update_manager.php, extensions/resource_exportation.php,
extensions/module_groups.php,
extensions/update_manager/lib/libupdate_manager_client.php,
extensions/system_info.php, operation/events/events_rss.php,
operation/events/export_csv.php, mobile/operation/events/events.php,
mobile/include/system.class.php: used the new constants time instead
the magic numbers, and cleaned source code style.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@6762 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2012-07-10 15:31:34 +02:00
|
|
|
|
2012-01-20 14:14:09 +01:00
|
|
|
$aggregate = $filter['aggregate'];
|
|
|
|
$unit = $filter['output'];
|
|
|
|
$interval = $end_date - $start_date;
|
2012-07-10 Miguel de Dios <miguel.dedios@artica.es>
* include/constants.php: added more constants into the constants
block of time conversion to seconds.
* godmode/alerts/alert_commands.php, godmode/setup/performance.php,
include/help/en/help_date_format.php, include/functions_netflow.php,
include/functions_tags.php, include/graphs/functions_pchart.php,
include/functions_modules.php, extensions/agents_modules.php,
extensions/update_manager.php, extensions/resource_exportation.php,
extensions/module_groups.php,
extensions/update_manager/lib/libupdate_manager_client.php,
extensions/system_info.php, operation/events/events_rss.php,
operation/events/export_csv.php, mobile/operation/events/events.php,
mobile/include/system.class.php: used the new constants time instead
the magic numbers, and cleaned source code style.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@6762 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2012-07-10 15:31:34 +02:00
|
|
|
|
2012-01-20 14:14:09 +01:00
|
|
|
// Process item
|
2012-07-10 Miguel de Dios <miguel.dedios@artica.es>
* include/constants.php: added more constants into the constants
block of time conversion to seconds.
* godmode/alerts/alert_commands.php, godmode/setup/performance.php,
include/help/en/help_date_format.php, include/functions_netflow.php,
include/functions_tags.php, include/graphs/functions_pchart.php,
include/functions_modules.php, extensions/agents_modules.php,
extensions/update_manager.php, extensions/resource_exportation.php,
extensions/module_groups.php,
extensions/update_manager/lib/libupdate_manager_client.php,
extensions/system_info.php, operation/events/events_rss.php,
operation/events/export_csv.php, mobile/operation/events/events.php,
mobile/include/system.class.php: used the new constants time instead
the magic numbers, and cleaned source code style.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@6762 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2012-07-10 15:31:34 +02:00
|
|
|
switch ($type) {
|
2012-01-20 14:14:09 +01:00
|
|
|
case '0':
|
|
|
|
$data = netflow_get_data ($start_date, $end_date, $command, $unique_id, $aggregate, $max_aggregates, $unit);
|
|
|
|
if ($aggregate != 'none') {
|
|
|
|
echo graph_netflow_aggregate_area($data, $interval, 660, 320, 0);
|
2012-07-10 Miguel de Dios <miguel.dedios@artica.es>
* include/constants.php: added more constants into the constants
block of time conversion to seconds.
* godmode/alerts/alert_commands.php, godmode/setup/performance.php,
include/help/en/help_date_format.php, include/functions_netflow.php,
include/functions_tags.php, include/graphs/functions_pchart.php,
include/functions_modules.php, extensions/agents_modules.php,
extensions/update_manager.php, extensions/resource_exportation.php,
extensions/module_groups.php,
extensions/update_manager/lib/libupdate_manager_client.php,
extensions/system_info.php, operation/events/events_rss.php,
operation/events/export_csv.php, mobile/operation/events/events.php,
mobile/include/system.class.php: used the new constants time instead
the magic numbers, and cleaned source code style.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@6762 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2012-07-10 15:31:34 +02:00
|
|
|
}
|
|
|
|
else {
|
2012-01-20 14:14:09 +01:00
|
|
|
echo graph_netflow_total_area($data, $interval, 660, 320, 0);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case '1':
|
|
|
|
$data = netflow_get_stats ($start_date, $end_date, $command, $aggregate, $max_aggregates, $unit);
|
|
|
|
echo graph_netflow_aggregate_pie($data, $aggregate);
|
|
|
|
break;
|
|
|
|
case '2':
|
|
|
|
$data = netflow_get_data ($start_date, $end_date, $command, $unique_id, $aggregate, $max_aggregates, $unit);
|
|
|
|
echo netflow_data_table ($data, $start_date, $end_date, $aggregate);
|
|
|
|
break;
|
|
|
|
case '3':
|
|
|
|
$data = netflow_get_stats ($start_date, $end_date, $command, $aggregate, $max_aggregates, $unit);
|
|
|
|
echo netflow_stat_table ($data, $start_date, $end_date, $aggregate, $unit);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
echo fs_error_image();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-07-18 15:25:51 +02:00
|
|
|
?>
|