From d4f5482e99209bf3addf227a1ede2b8b692e9fc4 Mon Sep 17 00:00:00 2001 From: manuel Date: Thu, 7 Mar 2019 13:37:36 +0100 Subject: [PATCH] Added custom field combo values in agent custom field Former-commit-id: 55ca33d3de14c868e1eec3f32179b33dc3ff589b --- pandora_console/extras/mr/25.sql | 4 + .../pandoradb_migrate_6.0_to_7.0.mysql.sql | 4 + .../godmode/agentes/agent_manager.php | 31 +++- .../godmode/agentes/configure_field.php | 151 +++++++++++++++++- .../godmode/agentes/fields_manager.php | 16 +- .../godmode/massive/massive_edit_agents.php | 29 ++++ 6 files changed, 221 insertions(+), 14 deletions(-) diff --git a/pandora_console/extras/mr/25.sql b/pandora_console/extras/mr/25.sql index 0809bc486e..d69c619586 100644 --- a/pandora_console/extras/mr/25.sql +++ b/pandora_console/extras/mr/25.sql @@ -143,5 +143,9 @@ INSERT INTO tlog_graph_models (`title`,`regexp`,`fields`,`average`) VALUES ('Pag INSERT INTO tlog_graph_models (`title`,`regexp`,`fields`,`average`) VALUES ('Users login', 'Starting Session \d+\ of user (.*)', 'user', 0); +-- ---------------------------------------------------------------------- +-- Add column in table `tagent_custom_fields` +-- ---------------------------------------------------------------------- +ALTER TABLE tagent_custom_fields ADD COLUMN `combo_values` VARCHAR(200) DEFAULT ''; COMMIT; diff --git a/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql b/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql index d8377484c3..b9e44bf064 100644 --- a/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql +++ b/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql @@ -2034,3 +2034,7 @@ INSERT INTO `tnotification_user` (`id_mensaje`, `id_user`) SELECT `id_mensaje`, -- ---------------------------------------------------------------------- INSERT INTO `trecon_script` (`name`,`description`,`script`,`macros`) VALUES ('Discovery.Application.VMware', 'Discovery Application script to monitor VMware technologies (ESXi, VCenter, VSphere)', '/usr/share/pandora_server/util/recon_scripts/vmware-plugin.pl', '{"1":{"macro":"_field1_","desc":"Configuration file","help":"","value":"","hide":""}}'); INSERT INTO `trecon_script` (`name`,`description`,`script`,`macros`) VALUES ('Discovery.Cloud', 'Discovery Cloud script to monitor Cloud technologies (AWS.EC2, AWS.S3, AWS.RDS, RDS,ȊWS.EKS)', '/usr/share/pandora_server/util/recon_scripts/pcm_client.pl', '{"1":{"macro":"_field1_","desc":"Configuration file","help":"","value":"","hide":""}}'); +-- ---------------------------------------------------------------------- +-- Add column in table `tagent_custom_fields` +-- ---------------------------------------------------------------------- +ALTER TABLE tagent_custom_fields ADD COLUMN `combo_values` VARCHAR(200) DEFAULT ''; diff --git a/pandora_console/godmode/agentes/agent_manager.php b/pandora_console/godmode/agentes/agent_manager.php index 143d6d880b..a7fc1f156a 100644 --- a/pandora_console/godmode/agentes/agent_manager.php +++ b/pandora_console/godmode/agentes/agent_manager.php @@ -708,6 +708,13 @@ foreach ($fields as $field) { __('This field allows url insertion using the BBCode\'s url tag').'.
'.__('The format is: [url=\'url to navigate\']\'text to show\'[/url]').'.

'.__('e.g.: [url=google.com]Google web search[/url]'), true ); + $combo = []; + $combo = $field['combo_values']; + $combo = explode(',', $combo); + $combo_values = []; + foreach ($combo as $value) { + $combo_values[$value] = $value; + } $custom_value = db_get_value_filter( 'description', @@ -747,6 +754,28 @@ foreach ($fields as $field) { ); } + if ($field['combo_values'] !== '') { + $data[1] = html_print_select( + $combo_values, + 'customvalue_'.$field['id_field'], + $custom_value, + '', + __('None'), + '', + true, + false, + false, + '', + false, + false, + false, + false, + false, + '', + false + ); + }; + array_push($table->data, $data); } @@ -757,7 +786,7 @@ if (!empty($fields)) { echo '
'; -// The context help about the learning mode +// The context help about the learning mode. if ($modo == 0) { echo ""; } else { diff --git a/pandora_console/godmode/agentes/configure_field.php b/pandora_console/godmode/agentes/configure_field.php index 25afef0c21..5f7c6b91d0 100755 --- a/pandora_console/godmode/agentes/configure_field.php +++ b/pandora_console/godmode/agentes/configure_field.php @@ -25,13 +25,16 @@ $id_field = (int) get_parameter('id_field', 0); $name = (string) get_parameter('name', ''); $display_on_front = (bool) get_parameter('display_on_front', 0); $is_password_type = (bool) get_parameter('is_password_type', 0); - -// Header +$is_combo_enable = (bool) get_parameter('is_combo_enable', 0); +$combo_values = (string) get_parameter('combo_values', ''); +// Header. if ($id_field) { $field = db_get_row_filter('tagent_custom_fields', ['id_field' => $id_field]); $name = $field['name']; $display_on_front = $field['display_on_front']; $is_password_type = $field['is_password_type']; + $combo_values = $field['combo_values']; + $is_combo_enable = $config['is_combo_enable']; ui_print_page_header(__('Update agent custom field'), 'images/custom_field.png', false, '', true, ''); } else { ui_print_page_header(__('Create agent custom field'), 'images/custom_field.png', false, '', true, ''); @@ -40,17 +43,87 @@ if ($id_field) { $table = new stdClass(); $table->width = '100%'; $table->class = 'databox filters'; +$table->id = 'configure_field'; $table->style[0] = 'font-weight: bold'; $table->style[2] = 'font-weight: bold'; +$table->style[4] = 'font-weight: bold'; +$table->style[6] = 'font-weight: bold'; + +echo "'; + +echo "'; + +echo "'; + +echo "'; + + $table->data = []; + $table->data[0][0] = __('Name'); -$table->data[0][1] = html_print_input_text('name', $name, '', 35, 100, true); +$table->data[0][1] = html_print_input_text( + 'name', + $name, + '', + 35, + 100, + true +); -$table->data[0][2] = __('Pass type').ui_print_help_tip(__('The fields with pass type enabled will be displayed like html input type pass in html'), true); -$table->data[0][3] = html_print_checkbox('is_password_type', 1, $is_password_type, true); +$table->data[1][0] = __('Pass type').ui_print_help_tip( + __('The fields with pass type enabled will be displayed like html input type pass in html'), + true +); +$table->data[1][1] = html_print_checkbox_switch( + 'is_password_type', + 1, + $is_password_type, + true +); -$table->data[0][4] = __('Display on front').ui_print_help_tip(__('The fields with display on front enabled will be displayed into the agent details'), true); -$table->data[0][5] = html_print_checkbox('display_on_front', 1, $display_on_front, true); +$table->data[2][0] = __('Display on front').ui_print_help_tip( + __('The fields with display on front enabled will be displayed into the agent details'), + true +); +$table->data[2][1] = html_print_checkbox_switch( + 'display_on_front', + 1, + $display_on_front, + true +); + +$table->data[3][0] = __('Enabled combo'); +$table->data[3][1] = html_print_checkbox_switch_extended( + 'is_combo_enable', + 0, + $config['is_combo_enable'], + false, + '', + '', + true +); + +$table->rowstyle[4] = 'display: none;'; +$table->data[4][0] = __('Combo values').ui_print_help_tip( + __('Set values separated by comma'), + true +); +$table->data[4][1] = html_print_input_text( + 'combo_values', + io_safe_output($combo_values), + '', + 35, + 200, + true +); echo '
'; html_print_table($table); @@ -67,3 +140,67 @@ if ($id_field) { echo '
'; echo ''; +?> + + diff --git a/pandora_console/godmode/agentes/fields_manager.php b/pandora_console/godmode/agentes/fields_manager.php index 867942871d..0be7166062 100644 --- a/pandora_console/godmode/agentes/fields_manager.php +++ b/pandora_console/godmode/agentes/fields_manager.php @@ -26,7 +26,7 @@ if (!check_acl($config['id_user'], 0, 'PM')) { return; } -// Header +// Header. ui_print_page_header(__('Agents custom fields manager'), 'images/custom_field.png', false, '', true, ''); $create_field = (bool) get_parameter('create_field'); @@ -36,10 +36,12 @@ $id_field = (int) get_parameter('id_field', 0); $name = (string) get_parameter('name', ''); $display_on_front = (int) get_parameter('display_on_front', 0); $is_password_type = (int) get_parameter('is_password_type', 0); +$combo_values = (string) get_parameter('combo_values', ''); +$combo_value_selected = (string) get_parameter('combo_value_selected', ''); -// Create field +// Create field. if ($create_field) { - // Check if name field is empty + // Check if name field is empty. if ($name == '') { ui_print_error_message(__('The name must not be empty')); } else if ($name == db_get_value('name', 'tagent_custom_fields', 'name', $name)) { @@ -51,20 +53,22 @@ if ($create_field) { 'name' => $name, 'display_on_front' => $display_on_front, 'is_password_type' => $is_password_type, + 'combo_values' => $combo_values, ] ); ui_print_success_message(__('Field successfully created')); } } -// Update field +// Update field. if ($update_field) { - // Check if name field is empty + // Check if name field is empty. if ($name != '') { $values = [ 'name' => $name, 'display_on_front' => $display_on_front, 'is_password_type' => $is_password_type, + 'combo_values' => $combo_values, ]; $result = db_process_sql_update('tagent_custom_fields', $values, ['id_field' => $id_field]); @@ -79,7 +83,7 @@ if ($update_field) { } } -// Delete field +// Delete field. if ($delete_field) { $result = db_process_sql_delete( 'tagent_custom_fields', diff --git a/pandora_console/godmode/massive/massive_edit_agents.php b/pandora_console/godmode/massive/massive_edit_agents.php index 2011eec564..74d05c10d0 100755 --- a/pandora_console/godmode/massive/massive_edit_agents.php +++ b/pandora_console/godmode/massive/massive_edit_agents.php @@ -689,6 +689,13 @@ foreach ($fields as $field) { __('This field allows url insertion using the BBCode\'s url tag').'.
'.__('The format is: [url=\'url to navigate\']\'text to show\'[/url]').'.

'.__('e.g.: [url=google.com]Google web search[/url]'), true ); + $combo = []; + $combo = $field['combo_values']; + $combo = explode(',', $combo); + $combo_values = []; + foreach ($combo as $value) { + $combo_values[$value] = $value; + } $custom_value = db_get_value_filter('description', 'tagent_custom_data', ['id_field' => $field['id_field'], 'id_agent' => $id_agente]); @@ -714,6 +721,28 @@ foreach ($fields as $field) { $data[1] = html_print_textarea('customvalue_'.$field['id_field'], 2, 65, $custom_value, 'style="min-height: 30px;"', true); } + if ($field['combo_values'] !== '') { + $data[1] = html_print_select( + $combo_values, + 'customvalue_'.$field['id_field'], + $custom_value, + '', + __('No change'), + '', + true, + false, + false, + '', + false, + false, + false, + false, + false, + '', + false + ); + }; + array_push($table->data, $data); }