From 15129bf4c86be3fda29069a1e439d2b5a8bfb419 Mon Sep 17 00:00:00 2001 From: mdtrooper Date: Wed, 2 Apr 2014 10:19:39 +0000 Subject: [PATCH] 2014-04-02 Miguel de Dios * godmode/modules/manage_network_components.php, godmode/modules/manage_network_components_form.php, godmode/agentes/configurar_agente.php, include/functions_snmp_browser.php, operation/snmpconsole/snmp_browser.php: implemented the feature to create a network component from snmp browser. Incident: #684 git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@9700 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_console/ChangeLog | 11 ++++ .../godmode/agentes/configurar_agente.php | 2 +- .../modules/manage_network_components.php | 55 +++++++++++++------ .../manage_network_components_form.php | 28 +++++++--- .../include/functions_snmp_browser.php | 45 ++++++++++++--- .../operation/snmpconsole/snmp_browser.php | 3 +- 6 files changed, 108 insertions(+), 36 deletions(-) diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index 2402810f9b..91f0adb2ab 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,14 @@ +2014-04-02 Miguel de Dios + + * godmode/modules/manage_network_components.php, + godmode/modules/manage_network_components_form.php, + godmode/agentes/configurar_agente.php, + include/functions_snmp_browser.php, + operation/snmpconsole/snmp_browser.php: implemented the feature to + create a network component from snmp browser. + + Incident: #684 + 2014-04-01 Miguel de Dios * include/functions_modules.php, operation/agentes/exportdata.php: diff --git a/pandora_console/godmode/agentes/configurar_agente.php b/pandora_console/godmode/agentes/configurar_agente.php index ae35367672..388ffb028f 100644 --- a/pandora_console/godmode/agentes/configurar_agente.php +++ b/pandora_console/godmode/agentes/configurar_agente.php @@ -1311,7 +1311,7 @@ if ($delete_module) { // DELETE agent module ! } // MODULE DUPLICATION -// ================= +// ================== if (!empty($duplicate_module)) { // DUPLICATE agent module ! $id_duplicate_module = $duplicate_module; diff --git a/pandora_console/godmode/modules/manage_network_components.php b/pandora_console/godmode/modules/manage_network_components.php index 8348f09f1c..88bc324982 100644 --- a/pandora_console/godmode/modules/manage_network_components.php +++ b/pandora_console/godmode/modules/manage_network_components.php @@ -127,6 +127,7 @@ $duplicate_network_component = (bool) get_parameter ('duplicate_network_componen $delete_multiple = (bool) get_parameter('delete_multiple'); $multiple_delete = (bool)get_parameter('multiple_delete', 0); $create_network_from_module = (bool) get_parameter ('create_network_from_module', 0); +$create_network_from_snmp_browser = (bool)get_parameter('create_network_from_snmp_browser', 0); if ($duplicate_network_component) { $source_id = (int) get_parameter ('source_id'); @@ -153,6 +154,8 @@ if ($create_component) { $name_check = db_get_value ('name', 'tnetwork_component', 'name', $name); + //remote_snmp = 15 + //remote_snmp_proc = 18 if ($type >= 15 && $type <= 18) { // New support for snmp v3 $tcp_send = $snmp_version; @@ -168,7 +171,9 @@ if ($create_component) { if ($name && !$name_check) { - $id = network_components_create_network_component ($name, $type, $id_group, + $id = network_components_create_network_component ($name, + $type, + $id_group, array ('description' => $description, 'module_interval' => $module_interval, 'max' => $max, @@ -297,7 +302,8 @@ if ($update_component) { $result = ''; } if ($result === false || !$result) { - db_pandora_audit("Module management", "Fail try to update network component #$id"); + db_pandora_audit("Module management", + "Fail try to update network component #$id"); ui_print_error_message (__('Could not be updated')); include_once ('godmode/modules/manage_network_components_form.php'); return; @@ -315,10 +321,12 @@ if ($delete_component) { $result = network_components_delete_network_component ($id); if ($result) { - db_pandora_audit( "Module management", "Delete network component #$id"); + db_pandora_audit( "Module management", + "Delete network component #$id"); } else { - db_pandora_audit( "Module management", "Fail try to delete network component #$id"); + db_pandora_audit( "Module management", + "Fail try to delete network component #$id"); } ui_print_result_message ($result, @@ -340,10 +348,12 @@ if ($multiple_delete) { $str_ids = implode (',', $ids); if ($result) { - db_pandora_audit( "Module management", "Multiple delete network component: $str_ids"); + db_pandora_audit( "Module management", + "Multiple delete network component: $str_ids"); } else { - db_pandora_audit( "Module management", "Fail try to delete network component: $str_ids"); + db_pandora_audit( "Module management", + "Fail try to delete network component: $str_ids"); } ui_print_result_message ($result, @@ -353,8 +363,9 @@ if ($multiple_delete) { $id = 0; } -if ($id || $new_component || $create_network_from_module) { - include_once ($config['homedir'] . '/godmode/modules/manage_network_components_form.php'); +if ($id || $new_component || $create_network_from_module || $create_network_from_snmp_browser) { + include_once ($config['homedir'] . + '/godmode/modules/manage_network_components_form.php'); return; } @@ -490,7 +501,8 @@ $table->head[3] = __('Description'); $table->head[4] = __('Group'); $table->head[5] = __('Max/Min'); $table->head[6] = __('Action') . - html_print_checkbox('all_delete', 0, false, true, false, 'check_all_checkboxes();'); + html_print_checkbox('all_delete', 0, false, true, false, + 'check_all_checkboxes();'); $table->size = array (); $table->size[1] = '75px'; $table->size[6] = '80px'; @@ -504,22 +516,28 @@ foreach ($components as $component) { $component['max'] = $component['min'] = __('N/A'); } - $data[0] = ''; + $data[0] = ''; $data[0] .= io_safe_output($component['name']); $data[0] .= ''; $data[1] = ui_print_moduletype_icon ($component['type'], true); switch ($component['id_modulo']) { case MODULE_NETWORK: - $data[1] .= html_print_image('images/network.png', true, array('title' => __('Network module'))); + $data[1] .= html_print_image('images/network.png', true, + array('title' => __('Network module'))); break; case MODULE_WMI: - $data[1] .= html_print_image('images/wmi.png', true, array('title' => __('WMI module'))); + $data[1] .= html_print_image('images/wmi.png', true, + array('title' => __('WMI module'))); break; case MODULE_PLUGIN: - $data[1] .= html_print_image('images/plugin.png', true, array('title' => __('Plug-in module'))); + $data[1] .= html_print_image('images/plugin.png', true, + array('title' => __('Plug-in module'))); break; } - $data[3] = "". mb_strimwidth (io_safe_output($component['description']), 0, 60, "...") . ""; + $data[3] = "". + mb_strimwidth (io_safe_output($component['description']), 0, 60, "...") . ""; $data[4] = network_components_get_group_name ($component['id_group']); $data[5] = $component['max']." / ".$component['min']; @@ -528,7 +546,7 @@ foreach ($components as $component) { html_print_image('images/copy.png', true, array('alt' => __('Duplicate'), 'title' => __('Duplicate'))) . ''; $data[6] .= '' . + '" onclick="if (! confirm (\'' . __('Are you sure?') . '\')) return false" >' . html_print_image('images/cross.png', true, array('alt' => __('Delete'), 'title' => __('Delete'))) . '' . html_print_checkbox_extended ('delete_multiple[]', $component['id_nc'], false, false, '', 'class="check_delete"', true); @@ -546,11 +564,12 @@ if (isset($data)) { echo ""; } else { - echo "
" . __('There are no defined network components') . "
"; + echo "
" . + __('There are no defined network components') . "
"; } -echo '
'; -echo '
'; +echo ''; +echo '
'; html_print_input_hidden ('new_component', 1); html_print_select (array( 2 => __('Create a new network component'), diff --git a/pandora_console/godmode/modules/manage_network_components_form.php b/pandora_console/godmode/modules/manage_network_components_form.php index 07c57811c8..1113937707 100644 --- a/pandora_console/godmode/modules/manage_network_components_form.php +++ b/pandora_console/godmode/modules/manage_network_components_form.php @@ -26,10 +26,11 @@ if (! check_acl ($config['id_user'], 0, "PM")) { } $create_network_from_module = get_parameter('create_network_from_module'); +$create_network_from_snmp_browser = get_parameter('create_network_from_snmp_browser', 0); $pure = get_parameter('pure', 0); if ($create_network_from_module) { - + $id_agentmodule = get_parameter('create_module_from'); $data_module = db_get_row_filter('tagente_modulo', array ('id_agente_modulo' => $id_agentmodule)); @@ -76,6 +77,7 @@ if ($create_network_from_module) { $id_component_type = 2; } + if (isset ($id)) { $component = network_components_get_network_component ((int) $id); if ($component !== false) { @@ -130,7 +132,8 @@ if (isset ($id)) { $snmp3_security_level = $component["custom_string_3"]; } } - elseif (isset ($new_component) && $new_component) { + elseif (isset ($new_component) && $new_component && !$create_network_from_snmp_browser) { + $name = ""; $snmp_oid = ""; $description = ""; @@ -177,6 +180,9 @@ if (isset ($id)) { } } +if ($create_network_from_snmp_browser) { +} + /** * $id_component_type has these values: * 6 - Module WMI @@ -189,18 +195,24 @@ if (isset ($id)) { if ($id_component_type == 6) { $categories = array (0, 1, 2); - require ($config['homedir'] . "/godmode/modules/manage_network_components_form_common.php"); - require ($config['homedir'] . "/godmode/modules/manage_network_components_form_wmi.php"); + require ($config['homedir'] . + "/godmode/modules/manage_network_components_form_common.php"); + require ($config['homedir'] . + "/godmode/modules/manage_network_components_form_wmi.php"); } else if ($id_component_type == 4) { $categories = array (0, 1, 2); - require ($config['homedir'] . "/godmode/modules/manage_network_components_form_common.php"); - require ($config['homedir'] . "/godmode/modules/manage_network_components_form_plugin.php"); + require ($config['homedir'] . + "/godmode/modules/manage_network_components_form_common.php"); + require ($config['homedir'] . + "/godmode/modules/manage_network_components_form_plugin.php"); } else if ($id_component_type == 2 || $create_network_from_module) { $categories = array (3, 4, 5); - require ($config['homedir'] . "/godmode/modules/manage_network_components_form_common.php"); - require ($config['homedir'] . "/godmode/modules/manage_network_components_form_network.php"); + require ($config['homedir'] . + "/godmode/modules/manage_network_components_form_common.php"); + require ($config['homedir'] . + "/godmode/modules/manage_network_components_form_network.php"); } else { return; diff --git a/pandora_console/include/functions_snmp_browser.php b/pandora_console/include/functions_snmp_browser.php index aa7520a28b..e42da97dd5 100644 --- a/pandora_console/include/functions_snmp_browser.php +++ b/pandora_console/include/functions_snmp_browser.php @@ -303,7 +303,8 @@ function snmp_browser_get_oid ($target_ip, $community, $target_oid, $version = ' else { $snmptranslate_bin = $config['snmptranslate']; } - exec ($snmptranslate_bin . " -Td " . escapeshellarg($oid), $translate_output); + exec ($snmptranslate_bin . " -Td " . escapeshellarg($oid), + $translate_output); foreach ($translate_output as $line) { if (preg_match ('/SYNTAX\s+(.*)/', $line, $matches) == 1) { $oid_data['syntax'] = $matches[1]; @@ -347,7 +348,9 @@ function snmp_browser_get_oid ($target_ip, $community, $target_oid, $version = ' * * @return string The OID data. */ -function snmp_browser_print_oid ($oid = array(), $custom_action = '', $return = false) { +function snmp_browser_print_oid ($oid = array(), $custom_action = '', + $return = false, $community = '', $snmp_version = 1) { + $output = ''; // OID information table @@ -361,20 +364,21 @@ function snmp_browser_print_oid ($oid = array(), $custom_action = '', $return = } } - $table->data[0][0] = ''.__('OID').''; + $table->data[0][0] = '' . __('OID') . ''; $table->data[0][1] = $oid['oid']; - $table->data[1][0] = ''.__('Numeric OID').''; - $table->data[1][1] = '' . $oid['numeric_oid'] . ''; - $table->data[2][0] = ''.__('Value').''; + $table->data[1][0] = '' . __('Numeric OID') . ''; + $table->data[1][1] = '' . + $oid['numeric_oid'] . ''; + $table->data[2][0] = '' . __('Value') . ''; $table->data[2][1] = $oid['value']; $i = 3; if (isset ($oid['type'])) { - $table->data[$i][0] = ''.__('Type').''; + $table->data[$i][0] = '' . __('Type') . ''; $table->data[$i][1] = $oid['type']; $i++; } if (isset ($oid['description'])) { - $table->data[$i][0] = ''.__('Description').''; + $table->data[$i][0] = '' . __('Description') . ''; $table->data[$i][1] = $oid['description']; $i++; } @@ -413,6 +417,31 @@ function snmp_browser_print_oid ($oid = array(), $custom_action = '', $return = $output .= html_print_table($table, true); + $url = "index.php?" . + "sec=gmodules&" . + "sec2=godmode/modules/manage_network_components"; + + $output .= ''; + $output .= html_print_input_hidden('create_network_from_snmp_browser', 1, true); + $output .= html_print_input_hidden('id_component_type', 2, true); + $output .= html_print_input_hidden('type', 17, true); + $name = ''; + if (!empty($oid['oid'])) { + $name = $oid['oid']; + } + $output .= html_print_input_hidden('name', $name, true); + $description = ''; + if (!empty($oid['description'])) { + $description = $oid['description']; + } + $output .= html_print_input_hidden('description', $description, true); + $output .= html_print_input_hidden('snmp_oid', $oid['numeric_oid'], true); + $output .= html_print_input_hidden('snmp_community', $community, true); + $output .= html_print_input_hidden('snmp_version', $snmp_version, true); + $output .= html_print_submit_button(__('Create network component'), + '', false, '', true); + $output .= ''; + if ($return) { return $output; } diff --git a/pandora_console/operation/snmpconsole/snmp_browser.php b/pandora_console/operation/snmpconsole/snmp_browser.php index 026d23e445..82e845d828 100644 --- a/pandora_console/operation/snmpconsole/snmp_browser.php +++ b/pandora_console/operation/snmpconsole/snmp_browser.php @@ -60,7 +60,8 @@ if (is_ajax()) { $target_oid, $snmp_version, $snmp3_auth_user, $snmp3_security_level, $snmp3_auth_method, $snmp3_auth_pass, $snmp3_privacy_method, $snmp3_privacy_pass); - snmp_browser_print_oid ($oid, $custom_action); + snmp_browser_print_oid ($oid, $custom_action, false, $community, + $snmp_version); return; }