diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index 2413907b27..8257de62ba 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,13 @@ +2013-05-20 Miguel de Dios + + * extensions/net_tools.php: added a entry to godmode for set the + paths of commands. + + Fixes: #2220 + + * include/functions_config.php, include/functions_extensions.php: + cleaned source code style. + 2013-05-20 Sergio Martin * include/functions_html.php diff --git a/pandora_console/extensions/net_tools.php b/pandora_console/extensions/net_tools.php index 58f214aaaf..9b0b150ab2 100644 --- a/pandora_console/extensions/net_tools.php +++ b/pandora_console/extensions/net_tools.php @@ -19,11 +19,46 @@ $id_agente = get_parameter ("id_agente"); // This extension is usefull only if the agent has associated IP $address = agents_get_address($id_agente); -if(!empty($address) || empty($id_agente)) { +if (!empty($address) || empty($id_agente)) { extensions_add_opemode_tab_agent ('network_tools','Network Tools','extensions/net_tools/nettool.png',"main_net_tools", "v1r1"); } function whereis_the_command ($command) { + global $config; + + if (isset($config['network_tools_config'])) { + $network_tools_config = json_decode($config['network_tools_config'], true); + $traceroute_path = $network_tools_config['traceroute_path']; + $ping_path = $network_tools_config['ping_path']; + $nmap_path = $network_tools_config['nmap_path']; + $dig_path = $network_tools_config['dig_path']; + $snmpget_path = $network_tools_config['snmpget_path']; + + switch ($command) { + case 'traceroute': + if (!empty($traceroute_path)) + return $traceroute_path; + break; + case 'ping': + if (!empty($ping_path)) + return $ping_path; + break; + case 'nmap': + if (!empty($nmap_path)) + return $nmap_path; + break; + case 'dig': + if (!empty($dig_path)) + return $dig_path; + break; + case 'snmpget': + if (!empty($snmpget_path)) + return $snmpget_path; + break; + } + } + + ob_start(); system('whereis '. $command); @@ -58,13 +93,14 @@ function main_net_tools () { echo ""; echo "
"; echo __("Operation"); + ui_print_help_tip(__('You can set the command path in the menu Administration -> Extensions -> Config Network Tools')); echo ""; echo ""; echo ""; echo __("SNMP Community"); @@ -76,8 +112,8 @@ function main_net_tools () { echo ""; - $operation = get_parameter ("operation",0); - $community = get_parameter ("community","public"); + $operation = get_parameter ("operation", 0); + $community = get_parameter ("community", "public"); switch($operation) { case 1: @@ -176,4 +212,84 @@ function main_net_tools () { echo ""; } + +function godmode_net_tools() { + global $config; + + ui_print_page_header (__('Config Network Tools')); + + $update_traceroute = (bool)get_parameter('update_traceroute', 0); + + $traceroute_path = (string)get_parameter('traceroute_path', ''); + $ping_path = (string)get_parameter('ping_path', ''); + $nmap_path = (string)get_parameter('nmap_path', ''); + $dig_path = (string)get_parameter('dig_path', ''); + $snmpget_path = (string)get_parameter('snmpget_path', ''); + + + if ($update_traceroute) { + $network_tools_config = array(); + $network_tools_config['traceroute_path'] = $traceroute_path; + $network_tools_config['ping_path'] = $ping_path; + $network_tools_config['nmap_path'] = $nmap_path; + $network_tools_config['dig_path'] = $dig_path; + $network_tools_config['snmpget_path'] = $snmpget_path; + + $result = config_update_value('network_tools_config', json_encode($network_tools_config)); + + ui_print_result_message($result, __('Set the paths.'), + __('Set the paths.')); + } + else { + + if (isset($config['network_tools_config'])) { + $network_tools_config = json_decode($config['network_tools_config'], true); + $traceroute_path = $network_tools_config['traceroute_path']; + $ping_path = $network_tools_config['ping_path']; + $nmap_path = $network_tools_config['nmap_path']; + $dig_path = $network_tools_config['dig_path']; + $snmpget_path = $network_tools_config['snmpget_path']; + } + } + + $table = null; + $table->width = "80%"; + + $table->data = array(); + + $table->data[0][0] = __("Traceroute path"); + $table->data[0][0] .= ui_print_help_tip(__('If it is empty, Pandora searchs the traceroute system.'), true); + $table->data[0][1] = html_print_input_text('traceroute_path', $traceroute_path, '', 40, 255, true); + + $table->data[1][0] = __("Ping path"); + $table->data[1][0] .= ui_print_help_tip(__('If it is empty, Pandora searchs the ping system.'), true); + $table->data[1][1] = html_print_input_text('ping_path', $ping_path, '', 40, 255, true); + + $table->data[2][0] = __("Nmap path"); + $table->data[2][0] .= ui_print_help_tip(__('If it is empty, Pandora searchs the nmap system.'), true); + $table->data[2][1] = html_print_input_text('nmap_path', $nmap_path, '', 40, 255, true); + + $table->data[3][0] = __("Dig path"); + $table->data[3][0] .= ui_print_help_tip(__('If it is empty, Pandora searchs the dig system.'), true); + $table->data[3][1] = html_print_input_text('dig_path', $dig_path, '', 40, 255, true); + + $table->data[4][0] = __("Snmpget path"); + $table->data[4][0] .= ui_print_help_tip(__('If it is empty, Pandora searchs the snmpget system.'), true); + $table->data[4][1] = html_print_input_text('snmpget_path', $snmpget_path, '', 40, 255, true); + + echo '
'; + echo "
"; + echo "" . __('Options') . ""; + html_print_input_hidden('update_traceroute', 1); + html_print_table($table); + echo "
"; + + echo '
'; + html_print_submit_button (__('Update'), 'update_button', false, 'class="sub upd"'); + echo '
'; + echo '
'; +} + +extensions_add_godmode_menu_option (__('Config Network Tools'), 'PM'); +extensions_add_godmode_function ('godmode_net_tools'); ?> diff --git a/pandora_console/include/functions_config.php b/pandora_console/include/functions_config.php index 9fffba168d..aa76ae5922 100644 --- a/pandora_console/include/functions_config.php +++ b/pandora_console/include/functions_config.php @@ -77,7 +77,7 @@ function config_update_config () { // Include functions_io to can call __() function include_once($config['homedir'] . '/include/functions_io.php'); - + /* If user is not even log it, don't try this */ if (! isset ($config['id_user'])) { $config['error_config_update_config'] = array(); diff --git a/pandora_console/include/functions_extensions.php b/pandora_console/include/functions_extensions.php index 80e0f0c3b6..cd03bb246b 100644 --- a/pandora_console/include/functions_extensions.php +++ b/pandora_console/include/functions_extensions.php @@ -285,7 +285,7 @@ function extensions_load_extensions ($extensions) { foreach ($extensions as $extension) { $extension_file = $extension['file']; - require_once (realpath ($extension['dir']."/".$extension_file)); + require_once (realpath ($extension['dir'] . "/" . $extension_file)); } }