diff --git a/pandora_console/godmode/massive/massive_edit_plugins.php b/pandora_console/godmode/massive/massive_edit_plugins.php new file mode 100644 index 0000000000..e25d9ff53e --- /dev/null +++ b/pandora_console/godmode/massive/massive_edit_plugins.php @@ -0,0 +1,990 @@ +", $plugin['description']); + } + if (isset($plugin['macros'])) { + $macros = json_decode($plugin['macros'], true); + if (!empty($macros)) { + $macros = array_values($macros); + + if (!empty($macros)) { + $plugin['macros'] = $macros; + } + } + } + + echo json_encode($plugin); + return; + } + + if ($get_agents) { + $sql = "SELECT ta.id_agente, ta.nombre AS agent_name, + tam.nombre AS module_name + FROM tagente ta + INNER JOIN tagente_modulo tam + ON ta.id_agente = tam.id_agente + AND tam.id_plugin = $plugin_id + ORDER BY ta.nombre, tam.nombre"; + $result = db_get_all_rows_sql($sql); + if (empty($result)) $result = array(); + + $agents = array(); + + $current_element = array(); + foreach ($result as $key => $value) { + $id = (int) $value['id_agente']; + $name = $value['agent_name']; + $module_name = $value['module_name']; + + if (!empty($current_element) && $current_element['id'] !== $id) { + $agents[] = $current_element; + $current_element = array(); + } + + $current_element['id'] = $id; + $current_element['name'] = $name; + + if (!isset($current_element['module_names'])) + $current_element['module_names'] = array(); + $current_element['module_names'][] = $module_name; + } + if (!empty($current_element)) { + $agents[] = $current_element; + } + + echo json_encode($agents); + return; + } + + if ($get_module_plugin_macros) { + $fields = array('macros'); + $filter = array( + 'id_plugin' => $plugin_id, + 'id_agente' => $agent_ids, + 'nombre' => $module_names + ); + $module_plugin_macros = db_get_all_rows_filter('tagente_modulo', $filter, $fields); + if (empty($module_plugin_macros)) $module_plugin_macros = array(); + + $module_plugin_macros = array_reduce($module_plugin_macros, function($carry, $item) { + + $macros = json_decode($item['macros'], true); + if (!empty($macros)) { + $macros = array_values($macros); + if (!empty($macros)) { + $carry[] = $macros; + } + } + + return $carry; + + }, array()); + + echo json_encode($module_plugin_macros); + return; + } + + return; +} + +$update = (bool) get_parameter('update'); + +if ($update) { + try { + $plugin = db_get_row('tplugin', 'id', $plugin_id); + // Macros retrieved from the plugin definition + $plugin_macros = array(); + if (isset($plugin['macros'])) { + $plugin_macros = json_decode($plugin['macros'], true); + if (!empty($plugin_macros)) { + $plugin_macros = array_values($plugin_macros); + } + } + + // Error + if (empty($plugin_macros)) + throw new Exception(__('Error retrieving the plugin macros')); + + // Macros returned by the form + $macros = get_parameter('macros', array()); + + // Error + if (empty($macros)) + throw new Exception(__('Error retrieving the modified macros')); + + $fields = array('id_agente_modulo', 'macros'); + $filter = array( + 'id_plugin' => $plugin_id, + 'id_agente' => $agent_ids, + 'nombre' => $module_names + ); + $module_plugin_macros = db_get_all_rows_filter('tagente_modulo', $filter, $fields); + if (empty($module_plugin_macros)) $module_plugin_macros = array(); + + // Error + if (empty($module_plugin_macros)) + throw new Exception(__('Error retrieving the module plugin macros')); + + // Begin transaction + // db_process_sql_begin(); + $errors = 0; + $count = 0; + + foreach ($module_plugin_macros as $item) { + + $module_id = $item['id_agente_modulo']; + $module_macros_str = $item['macros']; + // Macros retrieved from the agent module + $module_macros = json_decode($module_macros_str, true); + + // Error + if (empty($module_macros)) + throw new Exception(__('Error retrieving the module plugin macros data')); + + // Get the new module plugin macros + $result_macros = array_map(function ($item) use ($macros, $module_macros) { + + $result = array( + 'macro' => $item['macro'], + 'desc' => $item['desc'], + 'help' => $item['help'], + 'hide' => $item['hide'] + ); + + // Get the default value os the module plugin macro + $default = array_reduce($module_macros, function ($carry, $module_macro) use ($result) { + + if (isset($module_macro['macro']) && $module_macro['macro'] == $result['macro']) { + $carry = $module_macro['value']; + } + + return $carry; + + }, ''); + + set_if_defined($result['value'], $macros[$item['macro']]); + set_unless_defined($result['value'], $default); + + return $result; + + }, $plugin_macros); + + // Error + if (empty($result_macros)) + throw new Exception(__('Error building the new macros')); + + $module_macros = json_encode($result_macros); + if (empty($module_macros)) { + $module_macros = $module_macros_str; + } + + $values = array('macros' => $module_macros); + $where = array('id_agente_modulo' => $module_id); + // $result = db_process_sql_update('tagente_modulo', $values, $where, 'AND', false); + $result = db_process_sql_update('tagente_modulo', $values, $where); + + if (!$result) + $errors++; + else + $count += $result; + + } + + // if (!$errors) { + // db_process_sql_commit(); + // } + // else { + // db_process_sql_rollback(); + // } + + // Result message + ui_print_info_message(sprintf(__('%d modules updated'), $count)); + } + catch (Exception $e) { + ui_print_error_message($e->getMessage()); + } +} + +$table = new StdClass(); +$table->id = 'massive_plugin_edition'; +$table->width = '100%'; +$table->rowstyle = array(); +$table->data = array(); + +// Plugins +$filter = array('order' => 'name'); +$fields = array('id', 'name'); +$plugins = db_get_all_rows_filter('tplugin', $filter, $fields); + +if (empty($plugins)) { + ui_print_empty_data(__('There are not registered plugins')); + return; +} + +$plugins_aux = array(); +foreach ($plugins as $plugin) { + $plugins_aux[$plugin['id']] = $plugin['name']; +} +$plugins = $plugins_aux; +unset($plugins_aux); + +$plugins_select = html_print_select ($plugins, 'plugin_id', + $plugin_id, '', __('None'), 0, true, false, false); + +$row = array(); +$row[] = '' . __('Plugin') . ''; +$row[] = $plugins_select; + +$table->data['plugin-ids-row'] = $row; + +// Agents & modules +$row = array(); + +// Agents +$agents_select = html_print_select ($agent_ids, 'agent_ids[]', + false, '', '', 0, true, true, false); + +$row[] = '' . __('Agents') . ''; +$row[] = $agents_select; + +// Modules +// $modules_select = html_print_select ($module_ids, 'module_ids', +// false, '', '', 0, true, true, false); +$modules_select = html_print_select ($module_names, 'module_names[]', + false, '', '', 0, true, true, false); + +$row[] = '' . _('Modules') . ''; +$row[] = $modules_select; + +$table->rowstyle['agents-modules-row'] = 'vertical-align: top; display: none'; +$table->data['agents-modules-row'] = $row; + +echo '
'; + +?> + + diff --git a/pandora_console/godmode/massive/massive_operations.php b/pandora_console/godmode/massive/massive_operations.php index 923b2fa9cd..67faa3e41a 100755 --- a/pandora_console/godmode/massive/massive_operations.php +++ b/pandora_console/godmode/massive/massive_operations.php @@ -58,6 +58,10 @@ $options_modules = array( 'edit_modules' => __('Bulk module edit'), 'copy_modules' => __('Bulk module copy')); +$options_plugins = array( + 'edit_plugins' => __('Bulk plugin edit') + ); + if (! check_acl ($config['id_user'], 0, "PM")) { unset($options_modules['edit_modules']); } @@ -107,6 +111,9 @@ elseif (in_array($option, array_keys($options_snmp))) { elseif (in_array($option, array_keys($options_satellite))) { $tab = 'massive_satellite'; } +elseif (in_array($option, array_keys($options_plugins))) { + $tab = 'massive_plugins'; +} else { $option = ''; } @@ -133,6 +140,9 @@ switch ($tab) { case 'massive_satellite': $options = $options_satellite; break; + case 'massive_plugins': + $options = $options_plugins; + break; } // Set the default option of the category @@ -140,35 +150,30 @@ if ($option == '') { $option = array_shift(array_keys($options)); } -$alertstab = array( - 'text' => '' - . html_print_image ('images/op_alerts.png', true, - array ('title' => __('Alerts operations'))) - . '', - 'active' => $tab == 'massive_alerts'); +$alertstab = array('text' => '' + . html_print_image ('images/op_alerts.png', true, + array ('title' => __('Alerts operations'))) + . '', 'active' => $tab == 'massive_alerts'); -$userstab = array( - 'text' => '' - . html_print_image ('images/op_workspace.png', true, - array ('title' => __('Users operations'))) - . '', - 'active' => $tab == 'massive_users'); +$userstab = array('text' => '' + . html_print_image ('images/op_workspace.png', true, + array ('title' => __('Users operations'))) + . '', 'active' => $tab == 'massive_users'); -$agentstab = array( - 'text' => '' - . html_print_image ('images/bricks.png', true, - array ('title' => __('Agents operations'))) - . '', - 'active' => $tab == 'massive_agents'); - -$modulestab = array( - 'text' => '' - . html_print_image ('images/brick.png', true, - array ('title' => __('Modules operations'))) - . '', - 'active' => $tab == 'massive_modules'); +$agentstab = array('text' => '' + . html_print_image ('images/bricks.png', true, + array ('title' => __('Agents operations'))) + . '', 'active' => $tab == 'massive_agents'); +$modulestab = array('text' => '' + . html_print_image ('images/brick.png', true, + array ('title' => __('Modules operations'))) + . '', 'active' => $tab == 'massive_modules'); +$pluginstab = array('text' => '' + . html_print_image ('images/plugin.png', true, + array ('title' => __('Plugins operations'))) + . '', 'active' => $tab == 'massive_plugins'); $policiestab = enterprise_hook('massive_policies_tab'); @@ -189,6 +194,7 @@ if ($satellitetab == ENTERPRISE_NOT_HOOK) $onheader = array(); $onheader['massive_agents'] = $agentstab; $onheader['massive_modules'] = $modulestab; +$onheader['massive_plugins'] = $pluginstab; if (check_acl ($config['id_user'], 0, "PM")) { $onheader['user_agents'] = $userstab; } @@ -221,8 +227,7 @@ $submit_template_standby = get_parameter('id_alert_template_standby'); $submit_add = get_parameter('crtbutton'); echo '