From 1361ecd2e955a7a0bbfed4c5c243d6a352324eb9 Mon Sep 17 00:00:00 2001 From: Arturo Gonzalez Date: Tue, 16 May 2017 16:37:48 +0200 Subject: [PATCH 1/5] Added tags select field --- .../godmode/massive/massive_edit_modules.php | 27 +++++++++++++++++++ .../operation/agentes/ver_agente.php | 2 ++ 2 files changed, 29 insertions(+) diff --git a/pandora_console/godmode/massive/massive_edit_modules.php b/pandora_console/godmode/massive/massive_edit_modules.php index bfc3aab6de..923210086d 100755 --- a/pandora_console/godmode/massive/massive_edit_modules.php +++ b/pandora_console/godmode/massive/massive_edit_modules.php @@ -303,6 +303,13 @@ $table->data['form_modules_3'][1] = html_print_select($status_list, 'status_module', 'selected', '', __('All'), AGENT_MODULE_STATUS_ALL, true); $table->data['form_modules_3'][3] = ''; +$tags = tags_get_user_tags(); +$table->rowstyle['form_modules_4'] = 'vertical-align: top;'; +$table->rowclass['form_modules_4'] = 'select_modules_row select_modules_row_2'; +$table->data['form_modules_4'][0] = __('Tags'); +$table->data['form_modules_4'][1] = html_print_select ($tags, 'tags[]', + $tags_name, false, __('Any'), -1, true, true, true); + $table->rowstyle['form_modules_2'] = 'vertical-align: top;'; $table->rowclass['form_modules_2'] = 'select_modules_row select_modules_row_2'; $table->data['form_modules_2'][0] = __('Modules'); @@ -662,8 +669,10 @@ $(document).ready (function () { clean_lists(); + $(".select_modules_row").css('display', ''); $(".select_agents_row").css('display', ''); + $(".select_modules_row_2").css('display', 'none'); // Trigger change to refresh selection when change selection mode $("#agents_selection_mode").change (function() { @@ -720,6 +729,13 @@ $(document).ready (function () { var status_module = $('#status_module').val(); if (status_module != '-1') params['status_module'] = status_module; + + var tags_to_search = $('#tags').val(); + if (tags_to_search != null) { + if (tags_to_search[0] != -1) { + params['tags'] = tags_to_search; + } + } $("#module_loading").show (); $("tr#delete_table-edit1, tr#delete_table-edit0, tr#delete_table-edit2").hide (); @@ -926,6 +942,7 @@ $(document).ready (function () { else if(selector == 'modules') { $(".select_agents_row").hide(); $(".select_modules_row").show(); + $("#module_type").trigger("change"); } }); @@ -1041,6 +1058,16 @@ $(document).ready (function () { } }); + $("#tags").change(function() { + + selector = $("#form_edit input[name=selection_mode]:checked").val(); + if(selector == 'agents') { + $("#id_agents").trigger("change"); + } + else if(selector == 'modules') { + $("#module_type").trigger("change"); + } + }); }); function disabled_status () { diff --git a/pandora_console/operation/agentes/ver_agente.php b/pandora_console/operation/agentes/ver_agente.php index 9d6fe5a1b3..4a984e46e3 100644 --- a/pandora_console/operation/agentes/ver_agente.php +++ b/pandora_console/operation/agentes/ver_agente.php @@ -549,6 +549,8 @@ if (is_ajax ()) { // Use 0 as not received $id_tipo_modulo = (int) get_parameter ('id_tipo_modulo', 0); $status_modulo = (int) get_parameter ('status_module', -1); + + $tags = (array) get_parameter ('tags', array()); // Filter $filter = array(); From 4b94e7ce2bf11c83c6d08d509b1673892f42e8ff Mon Sep 17 00:00:00 2001 From: Arturo Gonzalez Date: Wed, 17 May 2017 09:59:10 +0200 Subject: [PATCH 2/5] Added tag filter to module massive operations (edit and modules selection first) --- .../godmode/massive/massive_edit_modules.php | 2 +- .../operation/agentes/ver_agente.php | 33 +++++++++++++++---- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/pandora_console/godmode/massive/massive_edit_modules.php b/pandora_console/godmode/massive/massive_edit_modules.php index 923210086d..4f77c3e824 100755 --- a/pandora_console/godmode/massive/massive_edit_modules.php +++ b/pandora_console/godmode/massive/massive_edit_modules.php @@ -719,7 +719,7 @@ $(document).ready (function () { var params = { "page" : "operation/agentes/ver_agente", "get_agent_modules_json" : 1, - "get_distinct_name" : 1, + "get_id_and_name" : 1, "indexed" : 0 }; diff --git a/pandora_console/operation/agentes/ver_agente.php b/pandora_console/operation/agentes/ver_agente.php index 4a984e46e3..9e5b35c7f4 100644 --- a/pandora_console/operation/agentes/ver_agente.php +++ b/pandora_console/operation/agentes/ver_agente.php @@ -551,7 +551,7 @@ if (is_ajax ()) { $status_modulo = (int) get_parameter ('status_module', -1); $tags = (array) get_parameter ('tags', array()); - + // Filter $filter = array(); if ($disabled !== -1) @@ -631,7 +631,7 @@ if (is_ajax ()) { agents_get_group_agents( array_keys (users_get_groups ()), $search, "none")); - $agent_modules = agents_get_modules ($id_agent, $fields, $filter, $indexed); + $agent_modules = agents_get_modules ($id_agent, $fields, $filter, $indexed, true, false, $tags); } // Restore db connection metaconsole_restore_db(); @@ -644,20 +644,39 @@ if (is_ajax ()) { agents_get_group_agents( array_keys(users_get_groups ()), $search, "none")); - $agent_modules = agents_get_modules ($id_agent, $fields, $filter, $indexed); + $agent_modules = agents_get_modules ($id_agent, $fields, $filter, $indexed, true, false, $tags); } if (empty($agent_modules)) $agent_modules = array(); + + if (!empty($tags)) { + $implode_tags = implode(",", $tags); + $tag_modules = db_get_all_rows_sql("SELECT DISTINCT id_agente_modulo FROM ttag_module WHERE id_tag IN (" . $implode_tags . ")"); + if ($tag_modules) { + $final_modules = array(); + foreach ($agent_modules as $key => $module) { + $in_array = false; + foreach ($tag_modules as $t_module) { + if ($module['id_agente_modulo'] == $t_module['id_agente_modulo']) { + $in_array = true; + } + } + if ($in_array) { + $final_modules[] = $module; + } + } + $agent_modules = $final_modules; + } + else { + $agent_modules = array(); + } + } foreach ($agent_modules as $key => $module) { $agent_modules[$key]['nombre'] = io_safe_output($module['nombre']); } - - //Hack to translate text "any" in PHP to javascript - //$agent_modules['any_text'] = __('Any'); - echo json_encode ($agent_modules); return; From d49f1f991611b057b1090c6b23a094dcbd2493d8 Mon Sep 17 00:00:00 2001 From: Arturo Gonzalez Date: Wed, 17 May 2017 10:41:30 +0200 Subject: [PATCH 3/5] Added tags filter to mosule massive operations (agent selection first) --- .../godmode/massive/massive_edit_modules.php | 21 ++++++------- pandora_console/include/javascript/pandora.js | 9 +++--- .../operation/agentes/ver_agente.php | 30 +++++++++++++++++-- 3 files changed, 44 insertions(+), 16 deletions(-) diff --git a/pandora_console/godmode/massive/massive_edit_modules.php b/pandora_console/godmode/massive/massive_edit_modules.php index 4f77c3e824..1285b015b7 100755 --- a/pandora_console/godmode/massive/massive_edit_modules.php +++ b/pandora_console/godmode/massive/massive_edit_modules.php @@ -341,8 +341,12 @@ $table->data['form_agents_2'][1] = html_print_select($status_list, 'status_agents', 'selected', '', __('All'), AGENT_STATUS_ALL, true); $table->data['form_agents_2'][3] = ''; - - +$tags = tags_get_user_tags(); +$table->rowstyle['form_agents_4'] = 'vertical-align: top;'; +$table->rowclass['form_agents_4'] = 'select_agents_row select_agents_row_2'; +$table->data['form_agents_4'][0] = __('Tags'); +$table->data['form_agents_4'][1] = html_print_select ($tags, 'tags[]', + $tags_name, false, __('Any'), -1, true, true, true); $table->rowstyle['form_agents_3'] = 'vertical-align: top;'; $table->rowclass['form_agents_3'] = 'select_agents_row select_agents_row_2'; @@ -974,7 +978,6 @@ $(document).ready (function () { $("#groups_select").change ( function () { - if (this.value < 0) { clean_lists(); $(".select_agents_row_2").css('display', 'none'); @@ -1059,14 +1062,12 @@ $(document).ready (function () { }); $("#tags").change(function() { - selector = $("#form_edit input[name=selection_mode]:checked").val(); - if(selector == 'agents') { - $("#id_agents").trigger("change"); - } - else if(selector == 'modules') { - $("#module_type").trigger("change"); - } + $("#module_type").trigger("change"); + }); + $("#tags1").change(function() { + selector = $("#form_edit input[name=selection_mode]:checked").val(); + $("#id_agents").trigger("change"); }); }); diff --git a/pandora_console/include/javascript/pandora.js b/pandora_console/include/javascript/pandora.js index 9480896cf3..e9d12424b0 100644 --- a/pandora_console/include/javascript/pandora.js +++ b/pandora_console/include/javascript/pandora.js @@ -175,7 +175,9 @@ function agent_changed_by_multiple_agents (event, id_agent, selected) { //val() because the var is same idAgents.push($(val).val()); }); - + + var tags_to_search = $('#tags1').val(); + //Hack to find only enabled modules //Pass a flag as global var find_modules = 'all'; @@ -226,6 +228,7 @@ function agent_changed_by_multiple_agents (event, id_agent, selected) { "page": "operation/agentes/ver_agente", "get_agent_modules_json_for_multiple_agents": 1, "id_agent[]": idAgents, + "tags[]": tags_to_search, "all": find_modules, "module_types_excluded[]": module_types_excluded, "name": module_name, @@ -401,8 +404,6 @@ function alert_templates_changed_by_multiple_agents_with_alerts (event, id_agent templates.push($(val).val()); }); - console.log(templates); - $('#module').attr ('disabled', 1); $('#module').empty (); $('#module').append ($('').html ("Loading...").attr ("value", 0)); @@ -1092,7 +1093,7 @@ function openURLTagWindow(url) { window.open(url, '','width=300, height=300, toolbar=no, location=no, directories=no, status=no, menubar=no'); } -function removeTinyMCE(elementID) {console.log(elementID); +function removeTinyMCE(elementID) { if (elementID.length > 0 && !isEmptyObject(tinyMCE)) tinyMCE.EditorManager.execCommand('mceRemoveControl', true, elementID); } diff --git a/pandora_console/operation/agentes/ver_agente.php b/pandora_console/operation/agentes/ver_agente.php index 9e5b35c7f4..381b089b68 100644 --- a/pandora_console/operation/agentes/ver_agente.php +++ b/pandora_console/operation/agentes/ver_agente.php @@ -301,6 +301,7 @@ if (is_ajax ()) { if ($get_agent_modules_json_for_multiple_agents) { $idAgents = get_parameter('id_agent'); + $tags = get_parameter('tags', null); $module_types_excluded = get_parameter('module_types_excluded', array()); $module_name = (string) get_parameter('name'); $selection_mode = get_parameter('selection_mode', 'common'); @@ -491,7 +492,7 @@ if (is_ajax ()) { } else { if(implode(',', $idAgents) < 0) { - $sql = 'SELECT DISTINCT(nombre) FROM tagente_modulo + $sql = 'SELECT DISTINCT nombre, id_agente_modulo FROM tagente_modulo WHERE nombre IN ( SELECT nombre FROM tagente_modulo @@ -499,7 +500,7 @@ if (is_ajax ()) { HAVING count(nombre) = (SELECT count(nombre) FROM tagente_modulo))'; } else { - $sql = 'SELECT DISTINCT(nombre) + $sql = 'SELECT DISTINCT nombre, id_agente_modulo FROM tagente_modulo t1 WHERE ' . $filter . ' AND t1.delete_pending = 0 @@ -521,6 +522,31 @@ if (is_ajax ()) { $nameModules = db_get_all_rows_sql($sql); + if ($tags != null) { + if ((count($tags) >= 1) && ($tags[0] != "") && ($tags[0] != -1)) { + $implode_tags = implode(",", $tags); + $tag_modules = db_get_all_rows_sql("SELECT DISTINCT id_agente_modulo FROM ttag_module WHERE id_tag IN (" . $implode_tags . ")"); + if ($tag_modules) { + $final_modules = array(); + foreach ($nameModules as $key => $module) { + $in_array = false; + foreach ($tag_modules as $t_module) { + if ($module['id_agente_modulo'] == $t_module['id_agente_modulo']) { + $in_array = true; + } + } + if ($in_array) { + $final_modules[] = $module; + } + } + $nameModules = $final_modules; + } + else { + $nameModules = array(); + } + } + } + if ($nameModules == false) { $nameModules = array(); } From 4a6b1a0dafe0ca413d3d2c69349e0e6cb03a92a8 Mon Sep 17 00:00:00 2001 From: Arturo Gonzalez Date: Wed, 17 May 2017 10:56:42 +0200 Subject: [PATCH 4/5] Added tags filter to massive module deletion (anget first and module first selection) --- .../massive/massive_delete_modules.php | 34 +++++++++++++++++-- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/pandora_console/godmode/massive/massive_delete_modules.php b/pandora_console/godmode/massive/massive_delete_modules.php index 04814ed1b6..ceb55af00a 100755 --- a/pandora_console/godmode/massive/massive_delete_modules.php +++ b/pandora_console/godmode/massive/massive_delete_modules.php @@ -444,7 +444,12 @@ $table->data['form_agents_1'][3] = __('Select all modules of this group') . ' ' html_print_checkbox_extended ("force_group", 'group', '', '', false, '', 'style="margin-right: 40px;"', true); - +$tags = tags_get_user_tags(); +$table->rowstyle['form_modules_4'] = 'vertical-align: top;'; +$table->rowclass['form_modules_4'] = 'select_modules_row select_modules_row_2'; +$table->data['form_modules_4'][0] = __('Tags'); +$table->data['form_modules_4'][1] = html_print_select ($tags, 'tags[]', + $tags_name, false, __('Any'), -1, true, true, true); $table->rowclass['form_agents_2'] = 'select_agents_row'; $table->data['form_agents_2'][0] = __('Status'); @@ -489,7 +494,12 @@ $table->data['form_modules_2'][2] .= html_print_select( $table->data['form_modules_2'][3] = html_print_select (array(), 'agents[]', $agents_select, false, __('None'), 0, true, true, false, '', false, 'width:100%'); - +$tags = tags_get_user_tags(); +$table->rowstyle['form_agents_4'] = 'vertical-align: top;'; +$table->rowclass['form_agents_4'] = 'select_agents_row select_agents_row_2'; +$table->data['form_agents_4'][0] = __('Tags'); +$table->data['form_agents_4'][1] = html_print_select ($tags, 'tags[]', + $tags_name, false, __('Any'), -1, true, true, true); $table->rowstyle['form_agents_3'] = 'vertical-align: top;'; $table->rowclass['form_agents_3'] = 'select_agents_row select_agents_row_2'; @@ -544,6 +554,7 @@ $(document).ready (function () { .css('display', ''); $(".select_agents_row") .css('display', ''); + $(".select_modules_row_2").css('display', 'none'); // Trigger change to refresh selection when change selection mode $("#agents_selection_mode").change (function() { @@ -573,7 +584,7 @@ $(document).ready (function () { var params = { "page" : "operation/agentes/ver_agente", "get_agent_modules_json" : 1, - "get_distinct_name" : 1, + "get_id_and_name" : 1, "indexed" : 0, "privilege" : "AW" }; @@ -584,6 +595,13 @@ $(document).ready (function () { var status_module = $('#status_module').val(); if (status_module != '-1') params['status_module'] = status_module; + + var tags_to_search = $('#tags').val(); + if (tags_to_search != null) { + if (tags_to_search[0] != -1) { + params['tags'] = tags_to_search; + } + } $("#module_loading").show (); $("tr#delete_table-edit1, tr#delete_table-edit2").hide (); @@ -656,6 +674,7 @@ $(document).ready (function () { else if (selector == 'modules') { $(".select_agents_row").hide(); $(".select_modules_row").show(); + $("#module_type").trigger("change"); } }); @@ -714,6 +733,15 @@ $(document).ready (function () { $("#status_agents").change(function() { $("#groups_select").trigger("change"); }); + + $("#tags").change(function() { + selector = $("#form_edit input[name=selection_mode]:checked").val(); + $("#module_type").trigger("change"); + }); + $("#tags1").change(function() { + selector = $("#form_edit input[name=selection_mode]:checked").val(); + $("#id_agents").trigger("change"); + }); $("#form_modules").submit(function() { var get_parameters_count = window.location.href.slice( From 33ff4f8abae59f8baa727d8f0f27cf708ce19422 Mon Sep 17 00:00:00 2001 From: Arturo Gonzalez Date: Wed, 17 May 2017 11:11:27 +0200 Subject: [PATCH 5/5] Added tags filter to copy modules in massive operations --- .../godmode/massive/massive_copy_modules.php | 33 +++++++++++++++---- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/pandora_console/godmode/massive/massive_copy_modules.php b/pandora_console/godmode/massive/massive_copy_modules.php index d386f34406..3d51a85a51 100755 --- a/pandora_console/godmode/massive/massive_copy_modules.php +++ b/pandora_console/godmode/massive/massive_copy_modules.php @@ -130,6 +130,11 @@ foreach ($agent_alerts as $alert) { $alerts[$alert['id']] = $name; } +$tags = tags_get_user_tags(); +$table->data['tags'][0] = __('Tags'); +$table->data['tags'][1] = html_print_select ($tags, 'tags[]', + $tags_name, false, __('Any'), -1, true, true, true); + $table->data['operations'][0] = __('Operations'); $table->data['operations'][1] = ''; $table->data['operations'][1] .= html_print_checkbox ('copy_modules', 1, true, true); @@ -282,12 +287,16 @@ $(document).ready (function () { } }); + $("#tags").change(function() { + $("#source_id_agent").trigger("change"); + }); + $("#status_agents_destiny").change(function() { $("#destiny_id_group").trigger("change"); }); $("#source_id_agent").change (function () { - var id_agent = this.value; + var id_agent = $("#source_id_agent").val(); if (id_agent == 0) { $("#submit-go").attr("disabled", "disabled"); @@ -302,6 +311,21 @@ $(document).ready (function () { return; } + var params = { + "page" : "operation/agentes/ver_agente", + "get_agent_modules_json" : 1, + "get_id_and_name" : 1, + "disabled" : 0, + "id_agent" : id_agent + }; + + var tags_to_search = $('#tags').val(); + if (tags_to_search != null) { + if (tags_to_search[0] != -1) { + params['tags'] = tags_to_search; + } + } + $("#submit-go").attr("disabled", false); $("#modules_loading").show (); @@ -313,12 +337,7 @@ $(document).ready (function () { var no_alerts; /* Get modules */ jQuery.post ("ajax.php", - {"page" : "operation/agentes/ver_agente", - "get_agent_modules_json" : 1, - "id_agent" : this.value, - "disabled" : 0, - "get_id_and_name" : 1 - }, + params, function (data, status) { if (data.length == 0) { no_modules = true;