From 3287ab2ee43ea7a97ad96354d586bcdb2a11e3e7 Mon Sep 17 00:00:00 2001 From: Daniel Cebrian Date: Wed, 3 Jan 2024 17:06:20 +0100 Subject: [PATCH] #11165 new popup for command whois in netflow --- pandora_console/include/functions_netflow.php | 47 ++++++++++++++ .../operation/network/network_report.php | 64 +++++++++++++++++++ 2 files changed, 111 insertions(+) diff --git a/pandora_console/include/functions_netflow.php b/pandora_console/include/functions_netflow.php index bc8495969f..b78be40301 100644 --- a/pandora_console/include/functions_netflow.php +++ b/pandora_console/include/functions_netflow.php @@ -2293,3 +2293,50 @@ function netflow_build_map_data($start_date, $end_date, $top, $aggregate, $advan array_merge($relations, $orphan_hosts) ); } + + +/** + * Run whois command and return all results as array. + * + * @param integer $ip Ip for search info with command whois. + * + * @return array + */ +function command_whois($ip) +{ + $command = 'whois '.$ip; + $result = ''; + exec($command, $result); + if (empty($result) === false && is_array($result) === true) { + $resultArray = parse_whois_output($result); + } else { + $resultArray = []; + } + + return $resultArray; +} + + +/** + * Parse the result of command whois to array. + * + * @param array $lines Lines result of command whois. + * + * @return array + */ +function parse_whois_output($lines) +{ + $resultArray = []; + if (is_array($lines) === true) { + foreach ($lines as $line) { + $parts = explode(':', $line, 2); + if (count($parts) === 2 && strpos($line, '#') !== 0) { + $key = trim($parts[0]); + $value = trim($parts[1]); + $resultArray[$key] = $value; + } + } + } + + return $resultArray; +} diff --git a/pandora_console/operation/network/network_report.php b/pandora_console/operation/network/network_report.php index 66847f4c1b..bc72602fd0 100644 --- a/pandora_console/operation/network/network_report.php +++ b/pandora_console/operation/network/network_report.php @@ -41,7 +41,10 @@ if (! check_acl($config['id_user'], 0, 'AR')) { // Ajax callbacks. if (is_ajax() === true) { + include_once $config['homedir'].'/include/functions_netflow.php'; $get_filter_values = get_parameter('get_filter_values', 0); + $whois = (bool) get_parameter('whois', 0); + // Get values of the current network filter. if ($get_filter_values) { $id = get_parameter('id'); @@ -51,6 +54,34 @@ if (is_ajax() === true) { echo json_encode($filter_values); } + if ($whois) { + $ip = get_parameter('ip'); + $info = command_whois($ip); + $output = ''; + if (is_array($info) === true && count($info) > 0) { + $table = new \stdClass(); + $table->class = 'details_table dataTable info_table'; + $table->data = []; + $row = 0; + foreach ($info as $key => $value) { + $table->data[$row][0] = $key; + $table->data[$row][1] = $value; + $row++; + } + + $output = html_print_table($table, true); + } else { + $output = ui_print_info_message(__('No data found')); + } + + html_print_div( + [ + 'content' => $output, + 'style' => 'max-height: 600px;', + ], + ); + } + return; } @@ -462,6 +493,7 @@ foreach ($data as $item) { array_merge($hidden_main_link, ['main_value' => $item['host']]), 'image' ); + $row['main'] .= html_print_input_image('whois', 'images/eye.png', 'whois', '', true, ['onclick' => 'whois(\''.$item['host'].'\')']); } $row['main'] .= ''; @@ -572,6 +604,13 @@ html_print_div( 'style' => 'position: initial;', ] ); + +html_print_div( + [ + 'id' => 'modal_whois', + 'class' => 'invisible', + ] +); ?>