2014-06-09 Alejandro Gallardo <alejandro.gallardo@artica.es>

* include/functions_api.php: Added the parameter
	"address resolution" to the functions
	"api_get_netflow_get_data" and "api_get_netflow_get_stats".

	* include/functions_netflow.php: Added the parameter
	"address resolution" to the functions "netflow_get_data",
	"netflow_get_stats", "netflow_get_summary",
	"netflow_get_record" and "netflow_draw_item".
	
	* operation/netflow/nf_live_view.php: Added an option to
	apply IP address resolution to the netflow searches.


git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@10147 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
alexhigh 2014-06-09 18:23:36 +00:00
parent c1db85e927
commit 7fdb68ac1b
5 changed files with 97 additions and 80 deletions

View File

@ -1,3 +1,17 @@
2014-06-09 Alejandro Gallardo <alejandro.gallardo@artica.es>
* include/functions_api.php: Added the parameter
"address resolution" to the functions
"api_get_netflow_get_data" and "api_get_netflow_get_stats".
* include/functions_netflow.php: Added the parameter
"address resolution" to the functions "netflow_get_data",
"netflow_get_stats", "netflow_get_summary",
"netflow_get_record" and "netflow_draw_item".
* operation/netflow/nf_live_view.php: Added an option to
apply IP address resolution to the netflow searches.
2014-06-09 Miguel de Dios <miguel.dedios@artica.es>
* include/javascript/update_manager.js,

View File

@ -67,7 +67,7 @@ $table->data[7][1] = html_print_input_text ('netflow_max_lifetime', $config['net
$table->data[8][0] = '<b>' . __('Name resolution for IP address') . '</b>' .
ui_print_help_tip (__("Resolve the IP addresses to get their hostnames."), true);
$onclick = "if (!confirm('".__('Warning').". ".__('IP address resolution can take a lot of time').".')) return false;";
$onclick = "if (!confirm('".__('Warning').". ".__('IP address resolution can take a lot of time')."')) return false;";
$table->data[8][1] = __('Yes').'&nbsp;&nbsp;'.html_print_radio_button_extended ('netflow_get_ip_hostname', 1, '', $config["netflow_get_ip_hostname"], false, $onclick, '', true).'&nbsp;&nbsp;&nbsp;';
$table->data[8][1] .= __('No').'&nbsp;&nbsp;'.html_print_radio_button ('netflow_get_ip_hostname', 0, '', $config["netflow_get_ip_hostname"], true);

View File

@ -6445,9 +6445,10 @@ function api_get_netflow_get_data ($discard_1, $discard_2, $params) {
$aggregate = $params['data'][4];
$max = $params['data'][5];
$unit = $params['data'][6];
$address_resolution = $params['data'][7];
// Get netflow data
$data = netflow_get_data ($start_date, $end_date, $interval_length, $filter, $aggregate, $max, $unit);
$data = netflow_get_data ($start_date, $end_date, $interval_length, $filter, $aggregate, $max, $unit, '', $address_resolution);
returnData('json', $data);
return;
@ -6463,9 +6464,10 @@ function api_get_netflow_get_stats ($discard_1, $discard_2, $params) {
$aggregate = $params['data'][3];
$max = $params['data'][4];
$unit = $params['data'][5];
$address_resolution = $params['data'][6];
// Get netflow data
$data = netflow_get_stats ($start_date, $end_date, $filter, $aggregate, $max, $unit);
$data = netflow_get_stats ($start_date, $end_date, $filter, $aggregate, $max, $unit, '', $address_resolution);
returnData('json', $data);
return;

View File

@ -421,13 +421,13 @@ function netflow_is_net ($address) {
* @return An array with netflow stats.
*
*/
function netflow_get_data ($start_date, $end_date, $interval_length, $filter, $aggregate, $max, $unit, $connection_name = '') {
function netflow_get_data ($start_date, $end_date, $interval_length, $filter, $aggregate, $max, $unit, $connection_name = '', $address_resolution = false) {
global $nfdump_date_format;
global $config;
// Requesting remote data
if (defined ('METACONSOLE') && $connection_name != '') {
$data = metaconsole_call_remote_api ($connection_name, 'netflow_get_data', "$start_date|$end_date|$interval_length|" . base64_encode(json_encode($filter)) . "|$aggregate|$max|$unit");
$data = metaconsole_call_remote_api ($connection_name, 'netflow_get_data', "$start_date|$end_date|$interval_length|" . base64_encode(json_encode($filter)) . "|$aggregate|$max|$unit" . (int)$address_resolution);
return json_decode ($data, true);
}
@ -510,7 +510,7 @@ function netflow_get_data ($start_date, $end_date, $interval_length, $filter, $a
// Address resolution start
$get_hostnames = false;
if ($config['netflow_get_ip_hostname'] && ($aggregate == "srcip" || $aggregate == "dstip")) {
if ($address_resolution && ($aggregate == "srcip" || $aggregate == "dstip")) {
$get_hostnames = true;
global $hostnames;
@ -617,12 +617,12 @@ function netflow_get_data ($start_date, $end_date, $interval_length, $filter, $a
*
* @return An array with netflow stats.
*/
function netflow_get_stats ($start_date, $end_date, $filter, $aggregate, $max, $unit, $connection_name = '') {
function netflow_get_stats ($start_date, $end_date, $filter, $aggregate, $max, $unit, $connection_name = '', $address_resolution = false) {
global $config, $nfdump_date_format;
// Requesting remote data
if (defined ('METACONSOLE') && $connection_name != '') {
$data = metaconsole_call_remote_api ($connection_name, 'netflow_get_stats', "$start_date|$end_date|" . base64_encode(json_encode($filter)) . "|$aggregate|$max|$unit");
$data = metaconsole_call_remote_api ($connection_name, 'netflow_get_stats', "$start_date|$end_date|" . base64_encode(json_encode($filter)) . "|$aggregate|$max|$unit|" . (int)$address_resolution);
return json_decode ($data, true);
}
@ -663,7 +663,7 @@ function netflow_get_stats ($start_date, $end_date, $filter, $aggregate, $max, $
else {
// Address resolution start
if ($config['netflow_get_ip_hostname'] && ($aggregate == "srcip" || $aggregate == "dstip")) {
if ($address_resolution && ($aggregate == "srcip" || $aggregate == "dstip")) {
global $hostnames;
if (!isset($hostnames[$val[4]])) {
@ -771,7 +771,7 @@ function netflow_get_summary ($start_date, $end_date, $filter, $connection_name
*
* @return An array with netflow stats.
*/
function netflow_get_record ($start_date, $end_date, $filter, $max, $unit) {
function netflow_get_record ($start_date, $end_date, $filter, $max, $unit, $address_resolution = false) {
global $nfdump_date_format;
global $config;
@ -836,7 +836,7 @@ function netflow_get_record ($start_date, $end_date, $filter, $max, $unit) {
}
// Address resolution start
if ($config['netflow_get_ip_hostname']) {
if ($address_resolution) {
global $hostnames;
for ($i = 0; $i < count($values); $i++) {
@ -1091,7 +1091,7 @@ function netflow_get_valid_subintervals () {
*
* @return The netflow report in the appropriate format.
*/
function netflow_draw_item ($start_date, $end_date, $interval_length, $type, $filter, $max_aggregates, $connection_name = '', $output = 'HTML', $only_image = false) {
function netflow_draw_item ($start_date, $end_date, $interval_length, $type, $filter, $max_aggregates, $connection_name = '', $output = 'HTML', $address_resolution = false) {
$aggregate = $filter['aggregate'];
$unit = $filter['output'];
$interval = $end_date - $start_date;
@ -1100,7 +1100,7 @@ function netflow_draw_item ($start_date, $end_date, $interval_length, $type, $fi
switch ($type) {
case '0':
case 'netflow_area':
$data = netflow_get_data ($start_date, $end_date, $interval_length, $filter, $aggregate, $max_aggregates, $unit, $connection_name);
$data = netflow_get_data ($start_date, $end_date, $interval_length, $filter, $aggregate, $max_aggregates, $unit, $connection_name, $address_resolution);
if (empty ($data)) {
break;
}
@ -1158,7 +1158,7 @@ function netflow_draw_item ($start_date, $end_date, $interval_length, $type, $fi
break;
case '2':
case 'netflow_data':
$data = netflow_get_data ($start_date, $end_date, $interval_length, $filter, $aggregate, $max_aggregates, $unit, $connection_name);
$data = netflow_get_data ($start_date, $end_date, $interval_length, $filter, $aggregate, $max_aggregates, $unit, $connection_name, $address_resolution);
if (empty ($data)) {
break;
@ -1187,7 +1187,7 @@ function netflow_draw_item ($start_date, $end_date, $interval_length, $type, $fi
case '3':
case 'netflow_statistics':
$data = netflow_get_stats ($start_date, $end_date, $filter,
$aggregate, $max_aggregates, $unit, $connection_name);
$aggregate, $max_aggregates, $unit, $connection_name, $address_resolution);
if (empty ($data)) {
break;
}
@ -1203,7 +1203,7 @@ function netflow_draw_item ($start_date, $end_date, $interval_length, $type, $fi
case 'netflow_summary':
$data_summary = netflow_get_summary ($start_date, $end_date,
$filter, $connection_name);
if (empty ($data)) {
if (empty ($data_summary)) {
break;
}
if ($output == 'HTML' || $output == 'PDF') {
@ -1217,7 +1217,7 @@ function netflow_draw_item ($start_date, $end_date, $interval_length, $type, $fi
case 'netflow_pie':
$data_pie = netflow_get_stats ($start_date, $end_date,
$filter, $aggregate, $max_aggregates, $unit,
$connection_name);
$connection_name, $address_resolution);
if (empty ($data_pie)) {
break;
}
@ -1249,7 +1249,7 @@ function netflow_draw_item ($start_date, $end_date, $interval_length, $type, $fi
$data_pie = netflow_get_stats ($start_date, $end_date,
$filter, $aggregate, $max_aggregates, $unit,
$connection_name);
$connection_name, $address_resolution);
if (empty ($data_pie)) {
break;
}
@ -1279,7 +1279,7 @@ function netflow_draw_item ($start_date, $end_date, $interval_length, $type, $fi
}
break;
case 'netflow_mesh':
$netflow_data = netflow_get_record($start_date, $end_date, $filter, $max_aggregates, $unit);
$netflow_data = netflow_get_record($start_date, $end_date, $filter, $max_aggregates, $unit, $address_resolution);
switch ($aggregate) {
case "srcport":
@ -1328,7 +1328,7 @@ function netflow_draw_item ($start_date, $end_date, $interval_length, $type, $fi
return $html;
break;
case 'netflow_host_treemap':
$netflow_data = netflow_get_record($start_date, $end_date, $filter, $max_aggregates, $unit);
$netflow_data = netflow_get_record($start_date, $end_date, $filter, $max_aggregates, $unit, $address_resolution);
switch ($aggregate) {
case "srcip":

View File

@ -79,7 +79,6 @@ $filter['ip_src'] = get_parameter('ip_src','');
$filter['dst_port'] = get_parameter('dst_port','');
$filter['src_port'] = get_parameter('src_port','');
$filter['advanced_filter'] = get_parameter('advanced_filter','');
$filter['advanced_filter'] = get_parameter('advanced_filter','');
// Read chart configuration
$chart_type = get_parameter('chart_type', 'netflow_area');
@ -90,6 +89,7 @@ $date = get_parameter_post ('date', date (DATE_FORMAT, get_system_time ()));
$time = get_parameter_post ('time', date (TIME_FORMAT, get_system_time ()));
$connection_name = get_parameter('connection_name', '');
$interval_length = (int) get_parameter('interval_length', 300);
$address_resolution = (int) get_parameter('address_resolution', $config['netflow_get_ip_hostname']);
// Read buttons
$draw = get_parameter('draw_button', '');
@ -173,6 +173,38 @@ enterprise_hook('open_meta_frame');
echo '<form method="post" action="' . $config['homeurl'] . 'index.php?sec=netf&sec2=operation/netflow/nf_live_view&pure='.$pure.'">';
echo "<table class='databox' width='99%'>";
if (defined ('METACONSOLE')) {
$list_servers = array();
$servers = db_get_all_rows_sql ("SELECT *
FROM tmetaconsole_setup");
if ($servers === false)
$servers = array();
foreach ($servers as $server) {
// If connection was good then retrieve all data server
if (metaconsole_load_external_db ($server)) {
$connection = true;
}
else {
$connection = false;
}
$row = db_get_row('tconfig', 'token', 'activate_netflow');
if ($row['value']) {
$list_servers[$server['server_name']] = $server['server_name'];
}
metaconsole_restore_db();
}
echo "<tr>";
echo "<td>" . '<b>'.__('Connection').'</b>' . "</td>";
echo "<td>" . html_print_select($list_servers, 'connection_name', $connection_name, '', '', 0, true, false, false) . "</td>";
echo "</tr>";
}
echo "<tr>";
echo "<td>" .
@ -209,37 +241,11 @@ echo '<form method="post" action="' . $config['homeurl'] . 'index.php?sec=netf&s
'50' => '50');
echo "<td>" . html_print_select ($max_values, 'max_aggregates', $max_aggregates, '', '', 0, true) . "</td>";
if (defined ('METACONSOLE')) {
$list_servers = array();
$servers = db_get_all_rows_sql ("SELECT *
FROM tmetaconsole_setup");
if ($servers === false)
$servers = array();
foreach ($servers as $server) {
// If connection was good then retrieve all data server
if (metaconsole_load_external_db ($server)) {
$connection = true;
}
else {
$connection = false;
}
$row = db_get_row('tconfig', 'token', 'activate_netflow');
if ($row['value']) {
$list_servers[$server['server_name']] = $server['server_name'];
}
metaconsole_restore_db();
}
echo "<td>" . '<b>'.__('Connection').'</b>' . "</td>";
echo "<td>" . html_print_select($list_servers, 'connection_name', $connection_name, '', '', 0, true, false, false) . "</td>";
}
$onclick = "if (!confirm('".__('Warning').". ".__('IP address resolution can take a lot of time')."')) return false;";
$radio_buttons = __('Yes').'&nbsp;&nbsp;'.html_print_radio_button_extended ('address_resolution', 1, '', $address_resolution, false, $onclick, '', true).'&nbsp;&nbsp;&nbsp;';
$radio_buttons .= __('No').'&nbsp;&nbsp;'.html_print_radio_button ('address_resolution', 0, '', $address_resolution, true);
echo "<td>" . '<b>'.__('IP address resolution').'</b>' . ui_print_help_tip (__("Resolve the IP addresses to get their hostnames."), true) . "</td>";
echo "<td>$radio_buttons</td>";
echo "</tr>";
@ -380,14 +386,11 @@ echo '<form method="post" action="' . $config['homeurl'] . 'index.php?sec=netf&s
echo'</form>';
if ($draw != '') {
// Get the command to call nfdump
$command = netflow_get_command ($filter);
// Draw
echo "<br/>";
echo netflow_draw_item ($start_date, $end_date,
$interval_length, $chart_type, $filter,
$max_aggregates, $connection_name);
$max_aggregates, $connection_name, 'HTML', $address_resolution);
}
enterprise_hook('close_meta_frame');
@ -399,16 +402,16 @@ ui_include_time_picker();
// Hide the normal filter and display the advanced filter
function displayAdvancedFilter () {
// Erase the normal filter
$("#text-ip_dst").value = '';
$("#text-ip_src").value = '';
$("#text-dst_port").value = '';
$("#text-src_port").value = '';
$("#text-ip_dst").val('');
$("#text-ip_src").val('');
$("#text-dst_port").val('');
$("#text-src_port").val('');
// Hide the normal filter
$(".filter_normal").css('display', 'none');
$(".filter_normal").hide();
// Show the advanced filter
$(".filter_advance").css('display', '');
$(".filter_advance").show();
};
// Hide the advanced filter and display the normal filter
@ -417,16 +420,16 @@ ui_include_time_picker();
$("#textarea_advanced_filter").val('');
// Hide the advanced filter
$(".filter_advance").css('display', 'none');
$(".filter_advance").hide();
// Show the normal filter
$(".filter_normal").css('display', '');
$(".filter_normal").show();
};
// Ask the user to define a name for the filter in order to save it
function defineFilterName () {
if ($("#text-name").val() == '') {
$(".filter_save").css('display', '');
$(".filter_save").show();
return false;
}
@ -447,14 +450,11 @@ ui_include_time_picker();
var filter_type;
// Hide information and name/group row
$(".filter_save").css('display', 'none');
$(".filter_save").css('display', 'none');
$(".filter_save").hide();
// Clean fields
if ($("#filter_id").val() == 0) {
//displayNormalFilter ();
$(".filter_normal").css('display', '');
$(".filter_advance").css('display', 'none');
displayNormalFilter();
// Check right filter type
$("#radiobtn0001").attr("checked", "checked");
@ -468,7 +468,7 @@ ui_include_time_picker();
$("#output").val('');
// Hide update filter button
$("#submit-update_button").css("visibility", "hidden");
$("#submit-update_button").hide();
}
else {
@ -491,24 +491,21 @@ ui_include_time_picker();
filter_type = data;
// Display the appropriate filter
if (filter_type == 0) {
$(".filter_normal").css('display', '');
$(".filter_advance").css('display', 'none');
$(".filter_normal").show();
$(".filter_advance").hide();
// Check right filter type
$("#radiobtn0001").attr("checked", "checked");
}
else {
$(".filter_normal").css('display', 'none');
$(".filter_advance").css('display', '');
$(".filter_normal").hide();
$(".filter_advance").show();
// Check right filter type
$("#radiobtn0002").attr("checked", "checked");
}
});
// Shows update filter button
$("#submit-update_button").css("visibility", "");
// Get filter values from DB
<?php
if (! defined ('METACONSOLE')) {
@ -541,6 +538,10 @@ ui_include_time_picker();
});
},
"json");
// Shows update filter button
$("#submit-update_button").show();
}
});
@ -548,10 +549,10 @@ ui_include_time_picker();
$(document).ready( function() {
// Hide update filter button
if ($("#filter_id").val() == 0) {
$("#submit-update_button").css("visibility", "hidden");
$("#submit-update_button").hide();
}
else {
$("#submit-update_button").css("visibility", "");
$("#submit-update_button").show();
}
// Change color of name and group if save button has been pushed