From b277c71c44fd59731b610f3688c6ff22b802da23 Mon Sep 17 00:00:00 2001 From: fermin831 Date: Wed, 3 Oct 2018 13:02:51 +0200 Subject: [PATCH] [Tags performance] Check massive operations --- .../godmode/massive/massive_add_tags.php | 250 -------------- .../godmode/massive/massive_copy_modules.php | 1 - .../godmode/massive/massive_delete_alerts.php | 1 - .../godmode/massive/massive_delete_tags.php | 305 ------------------ .../godmode/massive/massive_edit_modules.php | 4 +- 5 files changed, 2 insertions(+), 559 deletions(-) delete mode 100755 pandora_console/godmode/massive/massive_add_tags.php delete mode 100755 pandora_console/godmode/massive/massive_delete_tags.php diff --git a/pandora_console/godmode/massive/massive_add_tags.php b/pandora_console/godmode/massive/massive_add_tags.php deleted file mode 100755 index 729f2dcfcb..0000000000 --- a/pandora_console/godmode/massive/massive_add_tags.php +++ /dev/null @@ -1,250 +0,0 @@ - $name_module) { - $modules_id[] = $id_module; - } - } - } - - - $conttotal = 0; - $contsuccess = 0; - foreach ($modules_id as $id_module) { - $err_count = tags_insert_module_tag($id_module, $id_tags); - - if ($err_count == 0) { - $contsuccess ++; - } - - $conttotal ++; - } - - if ($contsuccess > 0) { - db_pandora_audit("Massive management", "Add tags", false, false, - ""); - } - else { - db_pandora_audit("Massive management", "Fail try to add tags", - false, false, ""); - } - - ui_print_result_message ($contsuccess > 0, - __('Successfully added') . "(" . $contsuccess . "/" . $conttotal . ")", - __('Could not be added')); - -} - -$id_agents = get_parameter ('id_agents'); -$id_tags = get_parameter ('id_tags'); -$modules = get_parameter ('module'); - -$add = (bool) get_parameter_post ('add'); - -if ($add) { - process_manage_add ($id_agents, $modules, $id_tags); -} - -$groups = users_get_groups (); -$own_info = get_user_info($config['id_user']); -if (!$own_info['is_admin'] && !check_acl ($config['id_user'], 0, "AW")) - $return_all_group = false; -else - $return_all_group = true; - -$table->id = 'add_table'; -$table->width = '98%'; -$table->data = array (); -$table->style = array (); -$table->style[0] = 'font-weight: bold; vertical-align:top'; -$table->style[2] = 'font-weight: bold; vertical-align:top'; -$table->size = array (); -$table->size[0] = '15%'; -$table->size[1] = '40%'; -$table->size[2] = '15%'; -$table->size[3] = '40%'; - -$table->data = array (); - -$table->data[0][0] = __('Group'); -$table->data[0][1] = html_print_select_groups(false, "AW", - $return_all_group, 'id_group', 0, '', 'Select', -1, true, false, - true, '', false, 'width:180px;'); - -$table->data[1][0] = __('Agents'); -$table->data[1][0] .= ''; - -$agents = agents_get_group_agents( - array_keys(users_get_groups ($config["id_user"], "AW", false))); -$table->data[1][1] = html_print_select ($agents, - 'id_agents[]', '', '', '', '', true, true, true, '', false, 'width:180px;'); - -$table->data[1][2] = __('Modules'); -$table->data[1][2] .= ''; -$table->data[1][3] = '' . - html_print_select (array(), 'module[]', '', false, '', '', true, true, false, '', false, 'width:180px;'); - - -$table->data[2][0] = __('Tags'); -$tags = tags_get_all_tags(); -$table->data[2][1] = html_print_select ($tags, - 'id_tags[]', '', '', '', '', true, true, true, '', false, 'width:180px;'); - - -echo '
'; -html_print_table ($table); - -echo '
'; -html_print_input_hidden ('add', 1); - -html_print_submit_button (__('Add'), 'go', false, 'class="sub add"'); -echo '
'; -echo '
'; - -// TODO: Change to iu_print_error system -echo ''; - -//Hack to translate text "none" in PHP to javascript -echo ''; - -ui_require_jquery_file ('form'); -ui_require_jquery_file ('pandora.controls'); -?> - - diff --git a/pandora_console/godmode/massive/massive_copy_modules.php b/pandora_console/godmode/massive/massive_copy_modules.php index 23739110d1..aae7d4e2df 100755 --- a/pandora_console/godmode/massive/massive_copy_modules.php +++ b/pandora_console/godmode/massive/massive_copy_modules.php @@ -120,7 +120,6 @@ $table->class = 'databox filters'; $table->data = array (); $modules = array (); -// TODO TAGS agents_get_modules if ($source_id_agent) $modules = agents_get_modules ($source_id_agent, 'nombre'); diff --git a/pandora_console/godmode/massive/massive_delete_alerts.php b/pandora_console/godmode/massive/massive_delete_alerts.php index f96f467672..eb0fd60dc3 100755 --- a/pandora_console/godmode/massive/massive_delete_alerts.php +++ b/pandora_console/godmode/massive/massive_delete_alerts.php @@ -120,7 +120,6 @@ function process_manage_delete ($id_alert_template, $id_agents, $module_names) { $modules_id = array(); foreach ($id_agents as $id_agent) { - // TODO TAGS agents_get_modules $current_modules_agent = agents_get_modules($id_agent, 'id_agente_modulo', array ('disabled' => 0)); if ($current_modules_agent != false) { // And their modules diff --git a/pandora_console/godmode/massive/massive_delete_tags.php b/pandora_console/godmode/massive/massive_delete_tags.php deleted file mode 100755 index 296a7ab8e1..0000000000 --- a/pandora_console/godmode/massive/massive_delete_tags.php +++ /dev/null @@ -1,305 +0,0 @@ - $id) { - $id_agents[$key] = (int)$id; - } - - $data = db_get_all_rows_sql(" - SELECT nombre - FROM tagente_modulo - WHERE id_agente IN (" . implode(',', $id_agents) . ") - AND id_agente_modulo IN ( - SELECT t1.id_agente_modulo - FROM ttag_module t1 - WHERE id_tag = " . $id_tag . " - AND id_policy_module = 0) - GROUP BY nombre;"); - - if (empty($data)) { - echo json_encode(array()); - } - else { - $modules = array(); - foreach ($data as $row) { - $modules[] = $row['nombre']; - } - - echo json_encode($modules); - } - } - else { - echo json_encode(array()); - } - - return; - } - - return; -} - -function process_manage_delete ($id_agents, $modules, $id_tag) { - - if (empty ($id_agents) || $id_agents[0] == 0) { - ui_print_error_message(__('No agents selected')); - return false; - } - - if (empty ($modules) || $modules[0] == "0") { - ui_print_error_message(__('No modules selected')); - return false; - } - - if (empty ($id_tag)) { - ui_print_error_message(__('No tag selected')); - return false; - } - - $modules_id = array(); - foreach ($modules as $module) { - $data = db_get_all_rows_sql(" - SELECT id_agente_modulo - FROM tagente_modulo - WHERE nombre = '" . $module . "' - AND id_agente IN (" . implode(",", $id_agents) . ") - "); - - if (empty($data)) { - $data = array(); - } - - foreach ($data as $row) { - $modules_id[$row['id_agente_modulo']] = $row['id_agente_modulo']; - } - } - - $conttotal = 0; - $contsuccess = 0; - foreach ($modules_id as $id_module) { - $success = tags_remove_tag($id_tag, $id_module); - - if ($success) { - $contsuccess ++; - } - - $conttotal ++; - } - - if ($contsuccess > 0) { - db_pandora_audit("Massive management", "Delete tags", false, false, - ""); - } - else { - db_pandora_audit("Massive management", "Fail try to delete tags", - false, false, ""); - } - - ui_print_result_message ($contsuccess > 0, - __('Successfully deleted') . "(" . $contsuccess . "/" . $conttotal . ")", - __('Could not be deleted')); - -} - -$id_agents = get_parameter ('id_agents'); -$id_tag = (int)get_parameter ('id_tag'); -$modules = get_parameter ('modules'); - -$delete = (bool) get_parameter_post ('delete'); - -if ($delete) { - process_manage_delete ($id_agents, $modules, $id_tag); -} - -$groups = users_get_groups (); -$own_info = get_user_info($config['id_user']); -if (!$own_info['is_admin'] && !check_acl ($config['id_user'], 0, "AW")) - $return_all_group = false; -else - $return_all_group = true; - -$table->id = 'add_table'; -$table->width = '98%'; -$table->data = array (); -$table->style = array (); -$table->style[0] = 'font-weight: bold; vertical-align:top'; -$table->style[2] = 'font-weight: bold; vertical-align:top'; -$table->size = array (); -$table->size[0] = '15%'; -$table->size[1] = '40%'; -$table->size[2] = '15%'; -$table->size[3] = '40%'; - -$table->data = array (); - -$table->data[0][0] = __('Tags'); -$tags = tags_get_all_tags(); -$table->data[0][1] = html_print_select ($tags, - 'id_tag', '', '', '', '', true, false, true, '', false, 'min-width:180px;'); - -$table->data[1][0] = __('Agents'); -$table->data[1][0] .= ''; -$table->data[1][1] = html_print_select (array(), - 'id_agents[]', '', '', '', '', true, true, true, '', false, 'min-width:180px;'); - -$table->data[2][0] = __('Modules'); -$table->data[2][0] .= ''; -$table->data[2][1] = '' . - html_print_select (array(), 'modules[]', '', false, '', '', true, true, false, '', false, 'min-width:180px;'); - - - - - -echo '
'; -html_print_table ($table); - -echo '
'; -html_print_input_hidden ('delete', 1); - -html_print_submit_button (__('Delete'), 'go', false, 'class="sub delete"'); -echo '
'; -echo '
'; - -// TODO: Change to iu_print_error system -echo ''; - -//Hack to translate text "none" in PHP to javascript -echo ''; - -ui_require_jquery_file ('form'); -ui_require_jquery_file ('pandora.controls'); -?> - - diff --git a/pandora_console/godmode/massive/massive_edit_modules.php b/pandora_console/godmode/massive/massive_edit_modules.php index 4d326a8e22..4ef69a581b 100755 --- a/pandora_console/godmode/massive/massive_edit_modules.php +++ b/pandora_console/godmode/massive/massive_edit_modules.php @@ -276,9 +276,9 @@ if ($module_type != '') { else { $filter = false; } -// TODO TAGS agents_get_modules + $names = agents_get_modules (array_keys ($agents), - 'DISTINCT(nombre)', $filter, false); + 'DISTINCT(tagente_modulo.nombre)', $filter, false); foreach ($names as $name) { $modules[$name['nombre']] = $name['nombre']; }