diff --git a/pandora_console/godmode/setup/setup_integria.php b/pandora_console/godmode/setup/setup_integria.php index a3b25b7e07..8ad155e41f 100644 --- a/pandora_console/godmode/setup/setup_integria.php +++ b/pandora_console/godmode/setup/setup_integria.php @@ -131,18 +131,23 @@ if (get_parameter('update_config', 0) == 1) { } // Get parameters from Integria IMS API. -$group_values = []; +$integria_group_values = []; $integria_criticity_values = []; $integria_users_values = []; $integria_types_values = []; +$integria_status_values = []; $integria_groups_csv = integria_api_call($config['integria_hostname'], $config['integria_user'], $config['integria_pass'], $config['integria_api_pass'], 'get_groups', []); -get_array_from_csv_data($integria_groups_csv, $group_values); +get_array_from_csv_data_pair($integria_groups_csv, $integria_group_values); + +$integria_status_csv = integria_api_call($config['integria_hostname'], $config['integria_user'], $config['integria_pass'], $config['integria_api_pass'], 'get_incidents_status', []); + +get_array_from_csv_data_pair($integria_status_csv, $integria_status_values); $integria_criticity_levels_csv = integria_api_call($config['integria_hostname'], $config['integria_user'], $config['integria_pass'], $config['integria_api_pass'], 'get_incident_priorities', []); -get_array_from_csv_data($integria_criticity_levels_csv, $integria_criticity_values); +get_array_from_csv_data_pair($integria_criticity_levels_csv, $integria_criticity_values); $integria_users_csv = integria_api_call($config['integria_hostname'], $config['integria_user'], $config['integria_pass'], $config['integria_api_pass'], 'get_users', []); @@ -156,7 +161,7 @@ foreach ($csv_array as $csv_line) { $integria_types_csv = integria_api_call($config['integria_hostname'], $config['integria_user'], $config['integria_pass'], $config['integria_api_pass'], 'get_types', []); -get_array_from_csv_data($integria_types_csv, $integria_types_values); +get_array_from_csv_data_pair($integria_types_csv, $integria_types_values); // Enable table. $table_enable = new StdClass(); @@ -226,11 +231,41 @@ $table_cr_settings->class = 'databox filters'; $table_cr_settings->size['name'] = '30%'; $table_cr_settings->style['name'] = 'font-weight: bold'; +// Custom response incident title. +$row = []; +$row['name'] = __('Title'); +$row['control'] = html_print_input_text( + 'incident_title', + $config['incident_title'], + __('Name'), + 50, + 100, + true, + false, + false +).ui_print_help_icon('response_macros', true); +$table_cr_settings->data['custom_response_incident_title'] = $row; + +// Custom response incident description. +$row = []; +$row['name'] = __('Description'); +$row['control'] = html_print_input_text( + 'incident_content', + $config['incident_content'], + '', + 50, + 100, + true, + false, + false +).ui_print_help_icon('response_macros', true); +$table_cr_settings->data['custom_response_incident_content'] = $row; + // Custom response default group. $row = []; -$row['name'] = __('Default group'); +$row['name'] = __('Group'); $row['control'] = html_print_select( - $group_values, + $integria_group_values, 'default_group', $config['default_group'], '', @@ -246,7 +281,7 @@ $table_cr_settings->data['custom_response_def_group'] = $row; // Custom response default criticity. $row = []; -$row['name'] = __('Default criticity'); +$row['name'] = __('Criticity'); $row['control'] = html_print_select( $integria_criticity_values, 'default_criticity', @@ -262,27 +297,31 @@ $row['control'] = html_print_select( ); $table_cr_settings->data['custom_response_def_criticity'] = $row; +// Custom response default creator. +$row = []; +$row['name'] = __('Creator'); +$row['control'] = html_print_autocomplete_users_from_integria( + 'default_creator', + $config['default_creator'], + true +); + +$table_cr_settings->data['custom_response_def_creator'] = $row; + // Custom response default owner. $row = []; -$row['name'] = __('Default owner'); -$row['control'] = html_print_select( - $integria_users_values, +$row['name'] = __('Owner'); +$row['control'] = html_print_autocomplete_users_from_integria( 'default_owner', $config['default_owner'], - '', - __('Select'), - 0, - true, - false, - true, - '', - false + true ); + $table_cr_settings->data['custom_response_def_owner'] = $row; // Custom response default incident type. $row = []; -$row['name'] = __('Incident type'); +$row['name'] = __('Type'); $row['control'] = html_print_select( $integria_types_values, 'incident_type', @@ -298,35 +337,23 @@ $row['control'] = html_print_select( ); $table_cr_settings->data['custom_response_incident_type'] = $row; -// Custom response incident title. +// Custom response default incident status. $row = []; -$row['name'] = __('Incident title'); -$row['control'] = html_print_input_text( - 'incident_title', - $config['incident_title'], - __('Name'), - 50, - 100, - true, - false, - false -).ui_print_help_icon('response_macros', true); -$table_cr_settings->data['custom_response_incident_title'] = $row; - -// Custom response incident content. -$row = []; -$row['name'] = __('Incident content'); -$row['control'] = html_print_input_text( - 'incident_content', - $config['incident_content'], +$row['name'] = __('Status'); +$row['control'] = html_print_select( + $integria_status_values, + 'incident_status', + $config['incident_status'], '', - 50, - 100, + __('Select'), + 0, true, false, + true, + '', false -).ui_print_help_icon('response_macros', true); -$table_cr_settings->data['custom_response_incident_content'] = $row; +); +$table_cr_settings->data['custom_response_incident_status'] = $row; // Test. $row = []; @@ -374,7 +401,7 @@ if ($has_connection != false) { // Form custom response settings. echo '
'; echo '
'; - echo ''.__('Custom response settings').''; + echo ''.__('Incident default values').''; html_print_table($table_cr_settings); @@ -503,6 +530,7 @@ echo ''; type: "POST", url: "ajax.php", dataType: "json", + timeout: timeout ? timeout * 1000 : 0, data: data }) .done(function(data, textStatus, xhr) { diff --git a/pandora_console/include/functions.php b/pandora_console/include/functions.php index 59120a9726..3ff3768d32 100644 --- a/pandora_console/include/functions.php +++ b/pandora_console/include/functions.php @@ -5451,7 +5451,7 @@ if (!function_exists('getallheaders')) { * * @return boolean True if API request succeeded, false if API request failed. */ -function integria_api_call($api_hostname, $user, $user_pass, $api_pass, $operation, $params_array, $show_credentials_error_msg=false) +function integria_api_call($api_hostname, $user, $user_pass, $api_pass, $operation, $params_array=[], $show_credentials_error_msg=false) { $params_string = implode(',', $params_array); @@ -5466,8 +5466,8 @@ function integria_api_call($api_hostname, $user, $user_pass, $api_pass, $operati // Build URL for API request. $url = $api_hostname.'/integria/include/api.php'; - ob_start(); - $out = fopen('php://output', 'w'); + // ob_start(); + // $out = fopen('php://output', 'w'); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); @@ -5478,9 +5478,8 @@ function integria_api_call($api_hostname, $user, $user_pass, $api_pass, $operati curl_setopt($ch, CURLOPT_STDERR, $out); $result = curl_exec($ch); - fclose($out); - $debug = ob_get_clean(); - + // fclose($out); + // $debug = ob_get_clean(); $http_status = curl_getinfo($ch, CURLINFO_HTTP_CODE); $error = false; @@ -5504,7 +5503,7 @@ function integria_api_call($api_hostname, $user, $user_pass, $api_pass, $operati // Parse CSV consisting of one or more lines of the form key-value pair into an array. -function get_array_from_csv_data($csv_data, &$array_values) +function get_array_from_csv_data_pair($csv_data, &$array_values) { $csv_array = explode("\n", $csv_data); diff --git a/pandora_console/include/functions_config.php b/pandora_console/include/functions_config.php index d638cb3bf8..734e1780f4 100644 --- a/pandora_console/include/functions_config.php +++ b/pandora_console/include/functions_config.php @@ -1467,6 +1467,10 @@ function config_update_config() $error_update[] = __('Integria default criticity'); } + if (!config_update_value('default_creator', (string) get_parameter('default_creator', $config['default_creator']))) { + $error_update[] = __('Integria default creator'); + } + if (!config_update_value('default_owner', (string) get_parameter('default_owner', $config['default_owner']))) { $error_update[] = __('Integria default owner'); } @@ -1475,6 +1479,10 @@ function config_update_config() $error_update[] = __('Integria default incident type'); } + if (!config_update_value('incident_status', (int) get_parameter('incident_status', $config['incident_status']))) { + $error_update[] = __('Integria default incident status'); + } + if (!config_update_value('incident_title', (string) get_parameter('incident_title', $config['incident_title']))) { $error_update[] = __('Integria default incident title'); } diff --git a/pandora_console/include/functions_html.php b/pandora_console/include/functions_html.php index fc704e2d46..19dd060d84 100644 --- a/pandora_console/include/functions_html.php +++ b/pandora_console/include/functions_html.php @@ -3356,3 +3356,108 @@ function html_print_input($data, $wrapper='div', $input_only=false) return $output; } + + +/** + * Print an autocomplete input filled out with Integria IMS users. + * + * @param string $name The name of ajax control, by default is "users". + * @param string $default The default value to show in the ajax control. + * @param boolean $return If it is true return a string with the output instead to echo the output. + * @param string $size Size. + * + * @return mixed If the $return is true, return the output as string. + */ +function html_print_autocomplete_users_from_integria( + $name='users', + $default='', + $return=false, + $size='30' +) { + global $config; + + ob_start(); + + html_print_input_text_extended( + $name, + $default, + 'text-'.$name, + '', + $size, + 100, + false, + '', + ['style' => 'background: url(images/user_green.png) no-repeat right;'] + ); + html_print_input_hidden($name.'_hidden', $id_agent_module); + ui_print_help_tip(__('Type at least two characters to search the user.'), false); + + $javascript_ajax_page = ui_get_full_url('ajax.php', false, false, false, false); + ?> + + width = '100%'; $table->id = 'add_alert_table'; -$table->class = 'databox filters'; +$table->class = 'databox filters integria_incidents_options'; $table->head = []; $table->data = []; $table->size = []; $table->size = []; -$table->size[0] = '15%'; -$table->size[1] = '90%'; +$table->style[0] = 'width: 33%; padding-right: 50px; padding-left: 100px;'; +$table->style[1] = 'width: 33%; padding-right: 50px; padding-left: 50px;'; +$table->style[2] = 'width: 33%; padding-right: 100px; padding-left: 50px;'; +$table->colspan[0][0] = 2; +$table->colspan[3][0] = 3; -$table->data[0][0] = __('Group'); -$table->data[0][1] = html_print_select( - $group_values, - 'default_group', - $config['default_group'], - '', - __('Select'), - 0, - true, - false, - true, - '', - false -); - -$table->data[1][0] = __('Default Criticity'); -$table->data[1][1] = html_print_select( - $integria_criticity_values, - 'default_criticity', - $config['default_criticity'], - '', - __('Select'), - 0, - true, - false, - true, - '', - false -); - -$table->data[2][0] = __('Default Owner'); -$table->data[2][1] = html_print_select( - $integria_users_values, - 'default_owner', - $config['default_owner'], - '', - __('Select'), - 0, - true, - false, - true, - '', - false -); - -$table->data[0][2] = __('Incident Type'); -$table->data[0][3] = html_print_select( - $integria_types_values, - 'incident_type', - $config['incident_type'], - '', - __('Select'), - 0, - true, - false, - true, - '', - false -); - -$table->data[1][2] = __('Incident title').ui_print_help_icon('response_macros', true); -$table->data[1][3] = html_print_input_text( +$table->data[0][0] = '

'.__('Title').': '.ui_print_help_icon('response_macros', true).'

'; +$table->data[0][0] .= '
'.html_print_input_text( 'incident_title', - $config['incident_title'], + $update ? $incident_details[3] : $config['incident_title'], __('Name'), 50, 100, true, false, true -); +).'
'; -$table->data[2][2] = __('Incident content').ui_print_help_icon('response_macros', true); -$table->data[2][3] = html_print_input_text( - 'incident_content', - $config['incident_content'], +$table->data[1][0] = '

'.__('Type').':

'; +$table->data[1][0] .= '
'.html_print_select( + $integria_types_values, + 'type', + $update ? $incident_details[17] : $config['incident_type'], '', - 50, - 100, + __('Select'), + 0, true, false, + true, + '', + false, + 'width: 100%;' +).'
'; + +$table->data[2][0] = '

'.__('Status').':

'; +$table->data[2][0] .= '
'.html_print_select( + $integria_status_values, + 'status', + $update ? $incident_details[6] : $config['incident_status'], + '', + __('Select'), + 0, + true, + false, + true, + '', + false, + 'width: 100%;' +).'
'; + +$table->data[1][1] = '

'.__('Group').':

'; +$table->data[1][1] .= '
'.html_print_select( + $integria_group_values, + 'group', + $update ? $incident_details[8] : $config['default_group'], + '', + __('Select'), + 0, + true, + false, + true, + '', + false, + 'width: 100%;' +).'
'; + +$table->data[2][1] = '

'.__('Creator').':

'; +$table->data[2][1] .= '
'.html_print_autocomplete_users_from_integria( + 'creator', + $update ? $incident_details[10] : $config['default_creator'], true -); +).'
'; + +$table->data[1][2] = '

'.__('Criticity').':

'; +$table->data[1][2] .= '
'.html_print_select( + $integria_criticity_values, + 'criticity', + $update ? $incident_details[7] : $config['default_criticity'], + '', + __('Select'), + 0, + true, + false, + true, + '', + false, + 'width: 100%;' +).'
'; + +$table->data[2][2] = '

'.__('Owner').':

'; + +$table->data[2][2] .= '
'.html_print_autocomplete_users_from_integria( + 'owner', + $update ? $incident_details[10] : $config['default_owner'], + true +).'
'; + +$table->data[3][0] = '

'.__('Description').': '.ui_print_help_icon('response_macros', true).'

'; +$table->data[3][0] .= '
'.html_print_textarea( + 'incident_content', + 3, + 20, + $update ? $incident_details[4] : $config['incident_content'], + '', + true +).'
'; echo '
'; html_print_table($table); -html_print_input_hidden('create_incident', 1); + +if (!$update) { + html_print_input_hidden('create_incident', 1); +} else { + html_print_input_hidden('update_incident', 1); +} + echo '
'; html_print_submit_button(__('Create'), 'accion', false, 'class="sub wand"'); echo '
';