From 5e510e7e12770a677aac8de9209f3ea0dc20bb84 Mon Sep 17 00:00:00 2001 From: "alejandro.campos@artica.es" Date: Wed, 16 Nov 2022 10:28:50 +0100 Subject: [PATCH] implemented custom field --- pandora_console/extras/mr/60.sql | 7 ++ .../godmode/agentes/agent_manager.php | 8 +++ .../godmode/agentes/configure_field.php | 70 ++++++++++++++++++- .../godmode/agentes/fields_manager.php | 24 ++++++- pandora_console/pandoradb.sql | 3 + pandora_console/pandoradb_data.sql | 2 +- 6 files changed, 110 insertions(+), 4 deletions(-) create mode 100644 pandora_console/extras/mr/60.sql diff --git a/pandora_console/extras/mr/60.sql b/pandora_console/extras/mr/60.sql new file mode 100644 index 0000000000..40a0a86c4f --- /dev/null +++ b/pandora_console/extras/mr/60.sql @@ -0,0 +1,7 @@ +START TRANSACTION; + +ALTER TABLE `tagent_custom_fields` ADD `is_link_enabled` TINYINT(1) NOT NULL DEFAULT 0; +ALTER TABLE `tagent_custom_fields` ADD COLUMN `link_text` VARCHAR(500) NOT NULL DEFAULT ''; +ALTER TABLE `tagent_custom_fields` ADD COLUMN `link_url` VARCHAR(2048) NOT NULL DEFAULT ''; + +COMMIT; diff --git a/pandora_console/godmode/agentes/agent_manager.php b/pandora_console/godmode/agentes/agent_manager.php index 676a4db993..e5e37e63ea 100644 --- a/pandora_console/godmode/agentes/agent_manager.php +++ b/pandora_console/godmode/agentes/agent_manager.php @@ -872,6 +872,14 @@ foreach ($fields as $field) { true, true ); + } else if ($field['is_link_enabled']) { + $link_text = $field['link_text']; + + if ($field['link_text'] === '') { + $link_text = $field['link_url']; + } + + $data_field[1] = ''.$link_text.''; } else { $data_field[1] = html_print_textarea( 'customvalue_'.$field['id_field'], diff --git a/pandora_console/godmode/agentes/configure_field.php b/pandora_console/godmode/agentes/configure_field.php index 7ef0fe042a..281c4a7447 100755 --- a/pandora_console/godmode/agentes/configure_field.php +++ b/pandora_console/godmode/agentes/configure_field.php @@ -30,6 +30,10 @@ $display_on_front = (bool) get_parameter('display_on_front', 0); $is_password_type = (bool) get_parameter('is_password_type', 0); $is_combo_enable = (bool) get_parameter('is_combo_enable', 0); $combo_values = (string) get_parameter('combo_values', ''); +$is_link_enabled = (bool) get_parameter('is_link_enabled', 0); +$link_text = (string) get_parameter('link_text', ''); +$link_url = (string) get_parameter('link_url', ''); + // Header. if ($id_field) { $field = db_get_row_filter('tagent_custom_fields', ['id_field' => $id_field]); @@ -38,6 +42,9 @@ if ($id_field) { $is_password_type = $field['is_password_type']; $combo_values = $field['combo_values'] ? $field['combo_values'] : ''; $is_combo_enable = $config['is_combo_enable']; + $is_link_enabled = $field['is_link_enabled']; + $link_text = $field['link_text']; + $link_url = $field['link_url']; 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, ''); @@ -128,6 +135,39 @@ $table->data[4][1] = html_print_textarea( true ); +$table->data[5][0] = __('Link type'); +$table->data[5][1] = html_print_checkbox_switch_extended( + 'is_link_enabled', + 1, + $is_link_enabled, + false, + '', + '', + true +); + +$table->rowstyle[6] = 'display: none;'; +$table->data[6][0] = __('Link text'); +$table->data[6][1] = html_print_textarea( + 'link_text', + 3, + 65, + io_safe_output($link_text), + '', + true +); + +$table->rowstyle[7] = 'display: none;'; +$table->data[7][0] = __('Link URL'); +$table->data[7][1] = html_print_textarea( + 'link_url', + 3, + 65, + io_safe_output($link_url), + '', + true +); + echo '
'; html_print_table($table); echo '
'; @@ -167,7 +207,35 @@ $(document).ready (function () { }); } - + if ($('input[type=checkbox][name=is_link_enabled]').is(":checked") === true) { + $('#configure_field-6').show(); + $('#configure_field-7').show(); + $('#configure_field-1').hide(); + $('#configure_field-3').hide(); + } else { + $('#configure_field-6').hide(); + $('#configure_field-7').hide(); + $('#configure_field-1').show(); + $('#configure_field-3').show(); + } + + // if ( $('input[type=checkbox][name=is_link_enabled]').val() === 1) { + + //} + $('input[type=checkbox][name=is_link_enabled]').change(function () { + if( $(this).is(":checked") ){ + $('#configure_field-6').show(); + $('#configure_field-7').show(); + $('#configure_field-1').hide(); + $('#configure_field-3').hide(); + } else{ + $('#configure_field-6').hide(); + $('#configure_field-7').hide(); + $('#configure_field-1').show(); + $('#configure_field-3').show(); + } + }); + $('input[type=checkbox][name=is_combo_enable]').change(function () { if( $(this).is(":checked") ){ $('#configure_field-4').show(); diff --git a/pandora_console/godmode/agentes/fields_manager.php b/pandora_console/godmode/agentes/fields_manager.php index 960ed62776..3f0212388d 100644 --- a/pandora_console/godmode/agentes/fields_manager.php +++ b/pandora_console/godmode/agentes/fields_manager.php @@ -38,14 +38,26 @@ $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', ''); +$is_link_enabled = (bool) get_parameter('is_link_enabled', 0); +$link_text = (string) get_parameter('link_text', ''); +$link_url = (string) get_parameter('link_url', ''); + +if ($is_link_enabled === true && $link_url !== '') { + $parsed_url = parse_url($link_url); + if (empty($parsed_url['scheme']) === true) { + $link_url = 'http://'.ltrim($link_url, '/'); + } +} // Create field. if ($create_field) { // Check if name field is empty. - if ($name == '') { + if ($name === '') { ui_print_error_message(__('The name must not be empty')); } else if ($name == db_get_value('name', 'tagent_custom_fields', 'name', $name)) { ui_print_error_message(__('The name must be unique')); + } else if ($is_link_enabled === true && $link_url === '') { + ui_print_error_message(__('The link URL must not be empty')); } else { $result = db_process_sql_insert( 'tagent_custom_fields', @@ -54,6 +66,9 @@ if ($create_field) { 'display_on_front' => $display_on_front, 'is_password_type' => $is_password_type, 'combo_values' => $combo_values, + 'is_link_enabled' => $is_link_enabled, + 'link_text' => $link_text, + 'link_url' => $link_url, ] ); ui_print_success_message(__('Field successfully created')); @@ -63,12 +78,17 @@ if ($create_field) { // Update field. if ($update_field) { // Check if name field is empty. - if ($name != '') { + if ($name !== '' + && ($is_link_enabled === false || ($is_link_enabled === true && $link_url !== '')) + ) { $values = [ 'name' => $name, 'display_on_front' => $display_on_front, 'is_password_type' => $is_password_type, 'combo_values' => $combo_values, + 'is_link_enabled' => $is_link_enabled, + 'link_text' => $link_text, + 'link_url' => $link_url, ]; $result = db_process_sql_update('tagent_custom_fields', $values, ['id_field' => $id_field]); diff --git a/pandora_console/pandoradb.sql b/pandora_console/pandoradb.sql index 89fa418389..df51e426ff 100644 --- a/pandora_console/pandoradb.sql +++ b/pandora_console/pandoradb.sql @@ -2103,6 +2103,9 @@ CREATE TABLE IF NOT EXISTS `tagent_custom_fields` ( `display_on_front` TINYINT NOT NULL DEFAULT 0, `is_password_type` TINYINT NOT NULL DEFAULT 0, `combo_values` TEXT , + `is_link_enabled` TINYINT(1) NOT NULL DEFAULT 0, + `link_text` VARCHAR(500) NOT NULL DEFAULT '', + `link_url` VARCHAR(2048) NOT NULL DEFAULT '', PRIMARY KEY (`id_field`) ) ENGINE=InnoDB DEFAULT CHARSET=UTF8MB4; diff --git a/pandora_console/pandoradb_data.sql b/pandora_console/pandoradb_data.sql index 369fab0092..fca70188ef 100644 --- a/pandora_console/pandoradb_data.sql +++ b/pandora_console/pandoradb_data.sql @@ -1189,7 +1189,7 @@ INSERT INTO `tplugin` (`id`, `name`, `description`, `max_timeout`, `execute`, `p INSERT INTO `tplugin` (`id`, `name`, `description`, `max_timeout`, `max_retries`, `execute`, `net_dst_opt`, `net_port_opt`, `user_opt`, `pass_opt`, `plugin_type`, `macros`, `parameters`, `no_delete`) VALUES (9,'Packet Loss','Checks for dropped packages after X seconds of testing. It returns % of dropped packets. It uses ping flood mode to launch 50 consecutive pings to a remote destination. On local, stable networks, value should be 0. ',30,0,'/usr/share/pandora_server/util/plugin/packet_loss.sh','','','','',0,'{\"1\":{\"macro\":\"_field1_\",\"desc\":\"Test time\",\"help\":\"\",\"value\":\"8\",\"hide\":\"\"},\"2\":{\"macro\":\"_field2_\",\"desc\":\"Target IP\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"}}','_field1_ _field2_', 1); -INSERT INTO `tagent_custom_fields` VALUES (1,'Serial Number',0,0,''),(2,'Department',0,0,''),(3,'Additional ID',0,0,''),(4,'eHorusID',0,0,''); +INSERT INTO `tagent_custom_fields` VALUES (1,'Serial Number',0,0,'',0,'',''),(2,'Department',0,0,'',0,'',''),(3,'Additional ID',0,0,'',0,'',''),(4,'eHorusID',0,0,'',0,'',''); INSERT INTO `ttag` VALUES (1,'network','Network equipment','http://artica.es','','',''),(2,'critical','Critical modules','','','',''),(3,'dmz','DMZ Network Zone','','','',''),(4,'performance','Performance anda capacity modules','','','',''),(5,'configuration','','','','','');