From 4278ffff26623ea0a8cda3fdcb472ab2cc959784 Mon Sep 17 00:00:00 2001 From: "jose.gonzalez@pandorafms.com" Date: Fri, 2 Dec 2022 14:25:22 +0100 Subject: [PATCH] Module editor improvements --- .../godmode/agentes/configurar_agente.php | 866 +++++++++-------- .../godmode/agentes/module_manager_editor.php | 89 +- .../agentes/module_manager_editor_common.php | 884 ++++++++++-------- .../agentes/module_manager_editor_network.php | 105 +-- pandora_console/include/functions_html.php | 34 + 5 files changed, 1108 insertions(+), 870 deletions(-) diff --git a/pandora_console/godmode/agentes/configurar_agente.php b/pandora_console/godmode/agentes/configurar_agente.php index d072bbc02c..70df1cb88e 100644 --- a/pandora_console/godmode/agentes/configurar_agente.php +++ b/pandora_console/godmode/agentes/configurar_agente.php @@ -42,184 +42,24 @@ use PandoraFMS\Event; check_login(); -$tab = (string) get_parameter('tab', 'main'); -$id_agente = (int) get_parameter('id_agente'); -$agentAddress = (string) get_parameter('direccion'); -$alias = (string) get_parameter('alias'); -$alias_as_name = (int) get_parameter_post('alias_as_name'); -$direccion_agente = (string) get_parameter_post('direccion'); -$unique_ip = (int) get_parameter_post('unique_ip'); -// $alerttype = get_parameter('alerttype'); UNUSED. -$id_module = (int) get_parameter('id_module'); -$id_agent_module = (int) get_parameter('id_agent_module'); -$intervalo = (string) get_parameter_post('intervalo', SECONDS_5MINUTES); -$comentarios = (string) get_parameter_post('comentarios'); -$modo = (int) get_parameter_post('modo'); -$id_parent = (int) get_parameter_post('id_agent_parent'); -$server_name = (string) get_parameter_post('server_name'); -$id_os = (int) get_parameter_post('id_os'); -$disabled = (int) get_parameter_post('disabled'); -$custom_id = (string) get_parameter_post('custom_id'); -$cascade_protection = (int) get_parameter_post('cascade_protection'); -$cascade_protection_module = (int) get_parameter_post('cascade_protection_module'); -$safe_mode = (int) get_parameter_post('safe_mode'); -$safe_mode_module = (int) get_parameter_post('safe_mode_module'); -$icon_path = (string) get_parameter_post('icon_path'); -$update_gis_data = (int) get_parameter_post('update_gis_data'); -$url_description = (string) get_parameter('url_description'); -$quiet = (int) get_parameter('quiet'); -$cps = (int) get_parameter_switch('cps', -1); -$fixed_ip = (int) get_parameter_switch('fixed_ip'); -$secondary_groups = (string) get_parameter('secondary_hidden'); -$grupo = (int) get_parameter_post('grupo'); -$id_extension = get_parameter('id_extension'); -$type_module_t = get_parameter('moduletype'); -$wizardSection = (string) get_parameter('wizard_section'); -$fix_module = get_parameter_get('fix_module', 0); -$address_list = (string) get_parameter_post('address_list'); -$agentName = (string) get_parameter_post('agente'); -$disabled = (bool) get_parameter_post('disabled'); -$satellite_server = (int) get_parameter('satellite_server', 0); -$max_timeout = (int) get_parameter('max_timeout'); -$max_retries = (int) get_parameter('max_retries'); -$min = (int) get_parameter('min'); -$max = (int) get_parameter('max'); -$interval = (int) get_parameter('module_interval', $intervalo); -$ff_interval = (int) get_parameter('module_ff_interval'); -$quiet_module = (int) get_parameter('quiet_module'); -$cps_module = (int) get_parameter('cps_module'); -$id_plugin = (int) get_parameter('id_plugin'); -$id_export = (int) get_parameter('id_export'); -$disabled = (bool) get_parameter('disabled'); -$tcp_send = (string) get_parameter('tcp_send'); -$tcp_rcv = (string) get_parameter('tcp_rcv'); -$tcp_port = (int) get_parameter('tcp_port'); -$delete_ip = (string) get_parameter_post('address_list'); -// Correction in order to not insert 0 as port. -$is_port_empty = (string) get_parameter('tcp_port'); -$prediction_module = (int) get_parameter('prediction_module'); +// Get tab parameter to check ACL in each tabs. +$tab = get_parameter('tab', 'main'); -$id_module_type = (int) get_parameter('id_module_type'); -$name = (string) get_parameter('name'); -$description = (string) get_parameter('description'); -$id_module_group = (int) get_parameter('id_module_group'); -$flag = (bool) get_parameter('flag'); -$post_process = (string) get_parameter('post_process', 0.0); -$configuration_data = (string) get_parameter('configuration_data'); -$old_configuration_data = (string) get_parameter('old_configuration_data'); -$custom_string_1 = (string) get_parameter('custom_string_1'); -$custom_string_2 = (string) get_parameter('custom_string_2'); -$custom_string_3 = (string) get_parameter('custom_string_3'); -$custom_integer_1 = (int) get_parameter('custom_integer_1'); -$custom_integer_2 = (int) get_parameter('custom_integer_2'); -$custom_id = (string) get_parameter('custom_id'); -$history_data = (int) get_parameter('history_data'); -$dynamic_interval = (int) get_parameter('dynamic_interval'); -$dynamic_max = (int) get_parameter('dynamic_max'); -$dynamic_min = (int) get_parameter('dynamic_min'); -$dynamic_two_tailed = (int) get_parameter('dynamic_two_tailed'); -$min_warning = (float) get_parameter('min_warning'); -$max_warning = (float) get_parameter('max_warning'); -$str_warning = (string) get_parameter('str_warning'); -$min_critical = (float) get_parameter('min_critical'); -$max_critical = (float) get_parameter('max_critical'); -$str_critical = (string) get_parameter('str_critical'); -$ff_event = (int) get_parameter('ff_event'); -$ff_event_normal = (int) get_parameter('ff_event_normal'); -$ff_event_warning = (int) get_parameter('ff_event_warning'); -$ff_event_critical = (int) get_parameter('ff_event_critical'); -$ff_type = (int) get_parameter('ff_type'); -$each_ff = (int) get_parameter('each_ff', $module['each_ff']); -$ff_timeout = (int) get_parameter('ff_timeout'); -$unit = (string) get_parameter('unit'); -$id_tag = (array) get_parameter('id_tag_selected'); -$serialize_ops = (string) get_parameter('serialize_ops'); -$critical_instructions = (string) get_parameter('critical_instructions'); -$warning_instructions = (string) get_parameter('warning_instructions'); -$unknown_instructions = (string) get_parameter('unknown_instructions'); -$critical_inverse = (int) get_parameter('critical_inverse'); -$warning_inverse = (int) get_parameter('warning_inverse'); -$percentage_critical = (int) get_parameter('percentage_critical'); -$percentage_warning = (int) get_parameter('percentage_warning'); -$combo_snmp_oid = (string) get_parameter_post('combo_snmp_oid'); -$id_category = (int) get_parameter('id_category'); -$hour_from = get_parameter('hour_from'); -$minute_from = get_parameter('minute_from'); -$mday_from = get_parameter('mday_from'); -$month_from = get_parameter('month_from'); -$wday_from = get_parameter('wday_from'); -$hour_to = get_parameter('hour_to'); -$minute_to = get_parameter('minute_to'); -$mday_to = get_parameter('mday_to'); -$month_to = get_parameter('month_to'); -$wday_to = get_parameter('wday_to'); -$http_user = get_parameter('http_user'); -$http_pass = get_parameter('http_pass'); -$snmp_community = (string) get_parameter('snmp_community'); -$snmp_oid = (string) get_parameter('snmp_oid'); -$select_snmp_oid = (string) get_parameter('select_snmp_oid'); -$tcp_send = (string) get_parameter('snmp_version'); -$plugin_user = (string) get_parameter('snmp3_auth_user'); -$snmp3_auth_pass = (string) get_parameter('snmp3_auth_pass'); -$snmp3_privacy_pass = (string) get_parameter('snmp3_privacy_pass'); -$snmp3_security_level = (string) get_parameter('snmp3_security_level'); -$snmp3_auth_method = (string) get_parameter('snmp3_auth_method'); -$custom_string_1 = (string) get_parameter('snmp3_privacy_method'); -$command_os = (string) get_parameter('command_os'); -$command_text = (string) get_parameter('command_text'); -$command_credential_identifier = (string) get_parameter('command_credential_identifier'); -$plugin_user = (string) get_parameter('plugin_user'); -$id_module_component_type = (int) get_parameter('id_module_component_type'); -$plugin_parameter = (string) get_parameter('plugin_parameter'); -$parent_module_id = (int) get_parameter('parent_module_id'); -$ip_target = (string) get_parameter('ip_target'); -$estimation_type = (string) get_parameter('estimation_type', 'estimation_calculation'); -$estimation_days = (int) get_parameter('estimation_days', -1); -$estimation_interval = (string) get_parameter('estimation_interval', '300'); -$active_snmp_v3 = get_parameter('active_snmp_v3'); -$throw_unknown_events = (bool) get_parameter('throw_unknown_events'); -$module_macro_names = (array) get_parameter('module_macro_names'); -$module_macro_values = (array) get_parameter('module_macro_values'); -$moduletype = (int) get_parameter('moduletype'); -$id_extension = (int) get_parameter('id_extension'); -$updateGisData = get_parameter('update_gis_data'); -$lastLatitude = get_parameter('latitude'); -$lastLongitude = get_parameter('longitude'); -$lastAltitude = get_parameter('altitude'); -$idAgente = get_parameter('id_agente'); -// Get macros. -$macros = (string) get_parameter('macros'); -$macros_names = (array) get_parameter('macro_name', []); -// Actions. -$pure = (bool) get_parameter('pure'); -$create_agent = (bool) get_parameter('create_agent'); -$update_agent = (bool) get_parameter('update_agent'); -$delete_conf_file = (bool) get_parameter('delete_conf_file'); -$action_delete_ip = (bool) get_parameter('delete_ip'); -$updateGIS = (bool) get_parameter('update_gis'); -$update_module = (bool) get_parameter('update_module'); -$create_module = (bool) get_parameter('create_module'); -$edit_module = (bool) get_parameter('edit_module'); -$delete_module = (bool) get_parameter('delete_module'); -$enable_module = (int) get_parameter('enable_module'); -$disable_module = (int) get_parameter('disable_module'); -// It is the id_agent_module to duplicate. -$duplicate_module = (int) get_parameter('duplicate_module'); - -// Variable definitions. +// See if id_agente is set (either POST or GET, otherwise -1. +$id_agente = (int) get_parameter('id_agente'); $group = 0; $all_groups = [$group]; -if ($id_agente > 0) { +if ($id_agente) { $group = agents_get_agent_group($id_agente); $all_groups = agents_get_all_groups_agent($id_agente, $group); } -if (check_acl_one_of_groups($config['id_user'], $all_groups, 'AW') === false) { +if (!check_acl_one_of_groups($config['id_user'], $all_groups, 'AW')) { $access_granted = false; switch ($tab) { case 'alert': case 'module': - if (check_acl_one_of_groups($config['id_user'], $all_groups, 'AD') === true) { + if (check_acl_one_of_groups($config['id_user'], $all_groups, 'AD')) { $access_granted = true; } break; @@ -229,7 +69,7 @@ if (check_acl_one_of_groups($config['id_user'], $all_groups, 'AW') === false) { break; } - if ($access_granted === false) { + if (!$access_granted) { db_pandora_audit( AUDIT_LOG_ACL_VIOLATION, 'Trying to access agent manager' @@ -243,10 +83,22 @@ require_once 'include/functions_modules.php'; require_once 'include/functions_alerts.php'; require_once 'include/functions_reporting.php'; +// Get passed variables. +$alerttype = get_parameter('alerttype'); +$id_agent_module = (int) get_parameter('id_agent_module'); + // Init vars. +$descripcion = ''; +$comentarios = ''; +$campo_1 = ''; +$campo_2 = ''; +$campo_3 = ''; +$maximo = 0; +$minimo = 0; $nombre_agente = ''; +$alias = get_parameter('alias', ''); $alias_as_name = 0; -$direccion_agente = $agentAddress; +$direccion_agente = get_parameter('direccion', ''); $direccion_agente = trim(io_safe_output($direccion_agente)); $direccion_agente = io_safe_input($direccion_agente); $unique_ip = 0; @@ -258,6 +110,20 @@ $id_server = ''; $max_alerts = 0; $modo = 1; $update_module = 0; +$modulo_id_agente = ''; +$modulo_id_tipo_modulo = ''; +$modulo_nombre = ''; +$modulo_descripcion = ''; +$alerta_id_aam = ''; +$alerta_campo1 = ''; +$alerta_campo2 = ''; +$alerta_campo3 = ''; +$alerta_dis_max = ''; +$alerta_dis_min = ''; +$alerta_min_alerts = 0; +$alerta_max_alerts = 1; +$alerta_time_threshold = ''; +$alerta_descripcion = ''; $disabled = ''; $id_parent = 0; $modulo_max = ''; @@ -308,23 +174,31 @@ $quiet = 0; $macros = ''; $cps = 0; $fixed_ip = 0; + +$create_agent = (bool) get_parameter('create_agent'); $module_macros = []; // Create agent. -if ($create_agent === true) { - $mssg_warning = false; - $alias_safe_output = strip_tags(io_safe_output($alias)); +if ($create_agent) { + $mssg_warning = 0; + $alias_safe_output = strip_tags(io_safe_output(get_parameter('alias', ''))); $alias = io_safe_input(trim(preg_replace('/[\/\\\|%#&$]/', '', $alias_safe_output))); + $alias_as_name = (int) get_parameter_post('alias_as_name', 0); + $direccion_agente = (string) get_parameter_post('direccion', ''); + $unique_ip = (int) get_parameter_post('unique_ip', 0); + // Safe_output only validate ip. $direccion_agente = trim(io_safe_output($direccion_agente)); - if (validate_address($direccion_agente) === false) { - $mssg_warning = true; + if (!validate_address($direccion_agente)) { + $mssg_warning = 1; } // Safe-input before validate ip. $direccion_agente = io_safe_input($direccion_agente); - $nombre_agente = hash_agent_name($alias, $nombre_agente); + + $nombre_agente = hash('sha256', $alias.'|'.$direccion_agente.'|'.time().'|'.sprintf('%04d', rand(0, 10000))); + $grupo = (int) get_parameter_post('grupo'); if ((bool) check_acl($config['id_user'], $grupo, 'AW') === false) { db_pandora_audit( @@ -335,6 +209,26 @@ if ($create_agent === true) { return; } + $intervalo = (string) get_parameter_post('intervalo', SECONDS_5MINUTES); + $comentarios = (string) get_parameter_post('comentarios', ''); + $modo = (int) get_parameter_post('modo'); + $id_parent = (int) get_parameter_post('id_agent_parent'); + $server_name = (string) get_parameter_post('server_name'); + $id_os = (int) get_parameter_post('id_os'); + $disabled = (int) get_parameter_post('disabled'); + $custom_id = (string) get_parameter_post('custom_id', ''); + $cascade_protection = (int) get_parameter_post('cascade_protection', 0); + $cascade_protection_module = (int) get_parameter_post('cascade_protection_module', 0); + $safe_mode = (int) get_parameter_post('safe_mode', 0); + $safe_mode_module = (int) get_parameter_post('safe_mode_module', 0); + $icon_path = (string) get_parameter_post('icon_path', ''); + $update_gis_data = (int) get_parameter_post('update_gis_data', 0); + $url_description = (string) get_parameter('url_description'); + $quiet = (int) get_parameter('quiet', 0); + $cps = (int) get_parameter_switch('cps', -1); + $fixed_ip = (int) get_parameter_switch('fixed_ip', 0); + + $secondary_groups = (string) get_parameter('secondary_hidden', ''); $fields = db_get_all_fields_in_table('tagent_custom_fields'); if ($fields === false) { @@ -348,14 +242,14 @@ if ($create_agent === true) { } // Check if agent exists (BUG WC-50518-2). - if (empty($alias) === true) { + if ($alias == '') { $agent_creation_error = __('No agent alias specified'); $agent_created_ok = 0; } else if (group_allow_more_agents($grupo, true, 'create') === false) { $agent_creation_error = __('Agent cannot be created due to the maximum agent limit for this group'); $agent_created_ok = 0; } else { - if ((bool) $alias_as_name === true) { + if ($alias_as_name) { $sql = 'SELECT nombre FROM tagente WHERE nombre = "'.$alias.'"'; $exists_alias = db_get_row_sql($sql); $nombre_agente = $alias; @@ -549,7 +443,12 @@ if ($id_agente) { ] ).''; - $templatetab['active'] = ($tab === 'template'); + if ($tab == 'template') { + $templatetab['active'] = true; + } else { + $templatetab['active'] = false; + } + // Inventory. $inventorytab = enterprise_hook('inventory_tab'); @@ -592,42 +491,35 @@ if ($id_agente) { } // Group tab. - $grouptab['text'] = html_print_anchor( + $grouptab['text'] = ''.html_print_image( + 'images/group.png', + true, [ - 'href' => 'index.php?sec=gagente&sec2=godmode/agentes/modificar_agente&ag_group='.$group, - 'content' => html_print_image( - 'images/group.png', - true, - [ - 'title' => __('Group'), - 'class' => 'invert_filter', - ] - ), - ], - true - ); + 'title' => __('Group'), + 'class' => 'invert_filter', + ] + ).''; $grouptab['active'] = false; $gistab = []; - // GIS tab. - if ((bool) $config['activate_gis'] === true) { - $gistab['text'] = html_print_anchor( - [ - 'href' => 'index.php?sec=gagente&sec2=godmode/agentes/configurar_agente&tab=gis&id_agente='.$id_agente, - 'content' => html_print_image( - 'images/gm_gis.png', - true, - [ - 'title' => __('GIS data'), - 'class' => 'invert_filter', - ] - ), - ], - true - ); - $gistab['active'] = ($tab === 'gis'); + // GIS tab. + if ($config['activate_gis']) { + $gistab['text'] = ''.html_print_image( + 'images/gm_gis.png', + true, + [ + 'title' => __('GIS data'), + 'class' => 'invert_filter', + ] + ).''; + + if ($tab == 'gis') { + $gistab['active'] = true; + } else { + $gistab['active'] = false; + } } // Agent wizard tab. @@ -673,71 +565,89 @@ if ($id_agente) { ).''; $agent_wizard['sub_menu'] .= ''; $agent_wizard['sub_menu'] .= ''; - $agent_wizard['active'] = ($tab === 'agent_wizard'); + + + if ($tab == 'agent_wizard') { + $agent_wizard['active'] = true; + } else { + $agent_wizard['active'] = false; + } + $total_incidents = agents_get_count_incidents($id_agente); // Incident tab. if ($total_incidents > 0) { - $incidenttab['text'] = html_print_anchor( + $incidenttab['text'] = ''.html_print_image( + 'images/book_edit.png', + true, [ - 'href' => 'index.php?sec=gagente&sec2=godmode/agentes/configurar_agente&tab=incident&id_agente='.$id_agente, - 'content' => html_print_image( - 'images/book_edit.png', - true, - [ - 'title' => __('Incidents'), - 'class' => 'invert_filter', - ] - ), - ], - true - ); + 'title' => __('Incidents'), + 'class' => 'invert_filter', + ] + ).''; - $incidenttab['active'] = ($tab === 'incident'); + if ($tab == 'incident') { + $incidenttab['active'] = true; + } else { + $incidenttab['active'] = false; + } } - if ((bool) check_acl_one_of_groups($config['id_user'], $all_groups, 'AW') === true) { - $onheader = [ - 'view' => $viewtab, - 'separator' => '', - 'main' => $maintab, - 'module' => $moduletab, - 'ncm' => $ncm_tab, - 'alert' => $alerttab, - 'template' => $templatetab, - 'inventory' => $inventorytab, - 'pluginstab' => $pluginstab, - 'collection' => $collectiontab, - 'group' => $grouptab, - 'gis' => $gistab, - 'agent_wizard' => $agent_wizard, - - ]; - - if ((bool) $has_remote_conf === true) { + if (check_acl_one_of_groups($config['id_user'], $all_groups, 'AW')) { + if ($has_remote_conf) { $agent_name = agents_get_name($id_agente); $agent_name = io_safe_output($agent_name); $agent_md5 = md5($agent_name, false); - $remote_configuration_tab['text'] = html_print_anchor( + $remote_configuration_tab['text'] = ''.html_print_image( + 'images/remote_configuration.png', + true, [ - 'href' => 'index.php?sec=gagente&sec2=godmode/agentes/configurar_agente&tab=remote_configuration&id_agente='.$id_agente.'&disk_conf='.$agent_md5, - 'content' => html_print_image( - 'images/remote_configuration.png', - true, - [ - 'title' => __('Remote configuration'), - 'class' => 'invert_filter', - ] - ), - ], - true - ); + 'title' => __('Remote configuration'), + 'class' => 'invert_filter', + ] + ).''; + if ($tab == 'remote_configuration') { + $remote_configuration_tab['active'] = true; + } else { + $remote_configuration_tab['active'] = false; + } - $remote_configuration_tab['active'] = ($tab === 'remote_configuration'); - $onheader[] = $remote_configuration_tab; + $onheader = [ + 'view' => $viewtab, + 'separator' => '', + 'main' => $maintab, + 'remote_configuration' => $remote_configuration_tab, + 'module' => $moduletab, + 'ncm' => $ncm_tab, + 'alert' => $alerttab, + 'template' => $templatetab, + 'inventory' => $inventorytab, + 'pluginstab' => $pluginstab, + 'collection' => $collectiontab, + 'group' => $grouptab, + 'gis' => $gistab, + 'agent_wizard' => $agent_wizard, + ]; + } else { + $onheader = [ + 'view' => $viewtab, + 'separator' => '', + 'main' => $maintab, + 'module' => $moduletab, + 'ncm' => $ncm_tab, + 'alert' => $alerttab, + 'template' => $templatetab, + 'inventory' => $inventorytab, + 'pluginstab' => $pluginstab, + 'collection' => $collectiontab, + 'group' => $grouptab, + 'gis' => $gistab, + 'agent_wizard' => $agent_wizard, + + ]; } // Only if the agent has incidents associated show incidents tab. @@ -755,12 +665,14 @@ if ($id_agente) { // Extensions tabs. foreach ($config['extensions'] as $extension) { - if (isset($extension['extension_god_tab']) === true) { + if (isset($extension['extension_god_tab'])) { if (check_acl($config['id_user'], $group, $extension['extension_god_tab']['acl'])) { $image = $extension['extension_god_tab']['icon']; $name = $extension['extension_god_tab']['name']; $id = $extension['extension_god_tab']['id']; + $id_extension = get_parameter('id_extension', ''); + if ($id_extension == $id) { $active = true; } else { @@ -807,6 +719,7 @@ if ($id_agente) { break; case 'module': + $type_module_t = get_parameter('moduletype', ''); $tab_name = __('Modules'); if ($type_module_t === 'webux') { $help_header = 'wux_console'; @@ -838,7 +751,7 @@ if ($id_agente) { break; case 'agent_wizard': - switch ($wizardSection) { + switch (get_parameter('wizard_section')) { case 'snmp_explorer': $help_header = 'agent_snmp_explorer_tab'; $tab_name = __('SNMP Wizard'); @@ -861,6 +774,7 @@ if ($id_agente) { break; case 'extension': + $id_extension = get_parameter('id_extension', ''); switch ($id_extension) { case 'snmp_explorer': $tab_description = '- '.__('SNMP explorer'); @@ -878,12 +792,14 @@ if ($id_agente) { break; } - if ($pure === false) { + $helper = ($help_header === 'main_tab') ? 'main_tab' : ''; + $pure = get_parameter('pure', 0); + if (!$pure) { ui_print_standard_header( agents_get_alias($id_agente), 'images/agent.png', false, - ($help_header === 'main_tab') ? $help_header : '', + $helper, false, $onheader, [ @@ -923,7 +839,9 @@ if ($id_agente) { ); } -if ($delete_conf_file === true) { +$delete_conf_file = (bool) get_parameter('delete_conf_file'); + +if ($delete_conf_file) { $correct = false; // Delete remote configuration. if (isset($config['remote_config'])) { @@ -947,8 +865,8 @@ if ($delete_conf_file === true) { } // Show agent creation results. -if ($create_agent === true) { - if (isset($agent_creation_error) === false) { +if ($create_agent) { + if (!isset($agent_creation_error)) { $agent_creation_error = __('Could not be created'); } @@ -958,13 +876,14 @@ if ($create_agent === true) { $agent_creation_error ); - if ($mssg_warning === true) { + if ($mssg_warning) { ui_print_warning_message(__('The ip or dns name entered cannot be resolved')); } } // Fix / Normalize module data. -if (isset($_GET['fix_module']) === true) { +if (isset($_GET['fix_module'])) { + $id_module = get_parameter_get('fix_module', 0); // Get info about this module. $media = reporting_get_agentmodule_data_average($id_module, 30758400); // Get average over the year. @@ -973,7 +892,7 @@ if (isset($_GET['fix_module']) === true) { $result = true; // If the value of media is 0 or something went wrong, don't delete. - if (empty($media) === false) { + if (!empty($media)) { $where = [ 'datos' => '>'.$media, 'id_agente_modulo' => $id_module, @@ -999,23 +918,31 @@ if (isset($_GET['fix_module']) === true) { ); } +$update_agent = (bool) get_parameter('update_agent'); + // Update AGENT. -if ($update_agent === true) { +if ($update_agent) { // If modified some agent paramenter. - $mssg_warning = false; - $nombre_agente = str_replace('`', '‘', $agentName); - $alias_safe_output = strip_tags(io_safe_output($alias)); + $mssg_warning = 0; + $id_agente = (int) get_parameter_post('id_agente'); + $nombre_agente = str_replace('`', '‘', (string) get_parameter_post('agente', '')); + $alias_safe_output = strip_tags(io_safe_output(get_parameter('alias', ''))); $alias = io_safe_input(trim(preg_replace('/[\/\\\|%#&$]/', '', $alias_safe_output))); + $alias_as_name = (int) get_parameter_post('alias_as_name', 0); + $direccion_agente = (string) get_parameter_post('direccion', ''); + $unique_ip = (int) get_parameter_post('unique_ip', 0); // Safe_output only validate ip. $direccion_agente = trim(io_safe_output($direccion_agente)); - if (validate_address($direccion_agente) === false) { - $mssg_warning = true; + if (!validate_address($direccion_agente)) { + $mssg_warning = 1; } // Safe-input before validate ip. $direccion_agente = io_safe_input($direccion_agente); + $address_list = (string) get_parameter_post('address_list', ''); + if ($address_list != $direccion_agente && $direccion_agente == agents_get_address($id_agente) && $address_list != agents_get_address($id_agente) @@ -1027,14 +954,34 @@ if ($update_agent === true) { * c) selectbox is not the current IP. */ - if (empty($address_list) === false) { + if (!empty($address_list)) { $direccion_agente = $address_list; } } - $comentarios = str_replace('`', '‘', $comentarios); + $grupo = (int) get_parameter_post('grupo', 0); + $intervalo = (int) get_parameter_post('intervalo', SECONDS_5MINUTES); + $comentarios = str_replace('`', '‘', (string) get_parameter_post('comentarios', '')); + $modo = (int) get_parameter_post('modo', 0); + // Mode: Learning, Normal or Autodisabled. + $id_os = (int) get_parameter_post('id_os'); + $disabled = (bool) get_parameter_post('disabled'); + $server_name = (string) get_parameter_post('server_name', ''); + $id_parent = (int) get_parameter_post('id_agent_parent'); + $custom_id = (string) get_parameter_post('custom_id', ''); + $cascade_protection = (int) get_parameter_post('cascade_protection', 0); + $cascade_protection_module = (int) get_parameter('cascade_protection_module', 0); + $safe_mode_module = (int) get_parameter('safe_mode_module', 0); + $icon_path = (string) get_parameter_post('icon_path', ''); + $update_gis_data = (int) get_parameter_post('update_gis_data', 0); + $url_description = (string) get_parameter('url_description'); + $quiet = (int) get_parameter('quiet', 0); + $cps = get_parameter_switch('cps', -1); $old_values = db_get_row('tagente', 'id_agente', $id_agente); $fields = db_get_all_fields_in_table('tagent_custom_fields'); + $secondary_groups = (string) get_parameter('secondary_hidden', ''); + $satellite_server = (int) get_parameter('satellite_server', 0); + $fixed_ip = (int) get_parameter_switch('fixed_ip', 0); if ($fields === false) { $fields = []; @@ -1081,12 +1028,12 @@ if ($update_agent === true) { } } - if ($mssg_warning === true) { + if ($mssg_warning) { ui_print_warning_message(__('The ip or dns name entered cannot be resolved')); } // Verify if there is another agent with the same name but different ID. - if (empty($alias) === true) { + if ($alias == '') { ui_print_error_message(__('No agent alias specified')); // If there is an agent with the same name, but a different ID. } @@ -1105,14 +1052,16 @@ if ($update_agent === true) { ui_print_error_message(__('Duplicate main IP address')); } else { // If different IP is specified than previous, add the IP. - if (empty($direccion_agente) === false + if ($direccion_agente != '' && $direccion_agente != agents_get_address($id_agente) ) { agents_add_address($id_agente, $direccion_agente); } + $action_delete_ip = (bool) get_parameter('delete_ip', false); // If IP is set for deletion, delete first. - if ($action_delete_ip === true) { + if ($action_delete_ip) { + $delete_ip = get_parameter_post('address_list'); if (empty($direccion_agente) === true) { $direccion_agente = agents_delete_address($id_agente, $delete_ip, true); } else { @@ -1245,7 +1194,7 @@ if ($id_agente) { } $agent = db_get_row('tagente', 'id_agente', $id_agente, false, false); - if (empty($agent) === true) { + if (empty($agent)) { // Close out the page. ui_print_error_message(__('There was a problem loading the agent')); return; @@ -1254,9 +1203,9 @@ if ($id_agente) { $intervalo = $agent['intervalo']; // Define interval in seconds. $nombre_agente = $agent['nombre']; - if (empty($alias) === true) { + if (empty($alias)) { $alias = $agent['alias']; - if (empty($alias) === true) { + if (empty($alias)) { $alias = $nombre_agente; } } @@ -1285,6 +1234,15 @@ if ($id_agente) { $fixed_ip = (int) $agent['fixed_ip']; } +$update_module = (bool) get_parameter('update_module'); +$create_module = (bool) get_parameter('create_module'); +$delete_module = (bool) get_parameter('delete_module'); +$enable_module = (int) get_parameter('enable_module'); +$disable_module = (int) get_parameter('disable_module'); +// It is the id_agent_module to duplicate. +$duplicate_module = (int) get_parameter('duplicate_module'); +$edit_module = (bool) get_parameter('edit_module'); + // GET DATA for MODULE UPDATE OR MODULE INSERT. if ($update_module || $create_module) { $id_grupo = agents_get_agent_group($id_agente); @@ -1299,23 +1257,56 @@ if ($update_module || $create_module) { exit; } + $id_agent_module = (int) get_parameter('id_agent_module'); + $id_module_type = (int) get_parameter('id_module_type'); + $name = (string) get_parameter('name'); + $description = (string) get_parameter('description'); + $id_module_group = (int) get_parameter('id_module_group'); + $flag = (bool) get_parameter('flag'); + /* * Don't read as (float) because it lost it's decimals when put into MySQL * where are very big and PHP uses scientific notation, p.e: * 1.23E-10 is 0.000000000123. */ - if (empty($is_port_empty) === true) { + $post_process = (string) get_parameter('post_process', 0.0); + if (get_parameter('prediction_module')) { + $prediction_module = 1; + } else { + $prediction_module = 0; + } + + $max_timeout = (int) get_parameter('max_timeout'); + $max_retries = (int) get_parameter('max_retries'); + $min = (int) get_parameter('min'); + $max = (int) get_parameter('max'); + $interval = (int) get_parameter('module_interval', $intervalo); + $ff_interval = (int) get_parameter('module_ff_interval'); + $quiet_module = (int) get_parameter('quiet_module'); + $cps_module = (int) get_parameter('cps_module'); + $id_plugin = (int) get_parameter('id_plugin'); + $id_export = (int) get_parameter('id_export'); + $disabled = (bool) get_parameter('disabled'); + $tcp_send = (string) get_parameter('tcp_send'); + $tcp_rcv = (string) get_parameter('tcp_rcv'); + $tcp_port = (int) get_parameter('tcp_port'); + // Correction in order to not insert 0 as port. + $is_port_empty = get_parameter('tcp_port', ''); + if ($is_port_empty === '') { $tcp_port = null; } + $configuration_data = (string) get_parameter('configuration_data'); + $old_configuration_data = (string) get_parameter('old_configuration_data'); $new_configuration_data = ''; + $custom_string_1_default = ''; $custom_string_2_default = ''; $custom_string_3_default = ''; $custom_integer_1_default = 0; $custom_integer_2_default = 0; - if ($update_module === true) { + if ($update_module) { $module = modules_get_agentmodule($id_agent_module); $custom_string_1_default = $module['custom_string_1']; @@ -1327,26 +1318,33 @@ if ($update_module || $create_module) { if ($id_module_type === 25) { // Web analysis, from MODULE_WUX. - $custom_string_1 = base64_encode($custom_string_1); + $custom_string_1 = base64_encode((string) get_parameter('custom_string_1')); // If the custom_string_1 parameter come empty, set the content // of the module (it is base64_encoded). if (empty($custom_string_1) === true) { $custom_string_1 = $custom_string_1_default; } + + $custom_integer_1 = (int) get_parameter('custom_integer_1', $custom_integer_1_default); + } else { + $custom_string_1 = (string) get_parameter('custom_string_1', $custom_string_1_default); + $custom_integer_1 = (int) get_parameter('prediction_module', $custom_integer_1_default); } - $custom_string_1 = (empty($custom_string_1) === true) ? $custom_string_1_default : $custom_string_1; - $custom_string_2 = (empty($custom_string_2) === true) ? $custom_string_2_default : $custom_string_2; - $custom_string_3 = (empty($custom_string_3) === true) ? $custom_string_3_default : $custom_string_3; - $custom_integer_1 = ($custom_integer_1 === 0) ? $custom_integer_1_default : $custom_integer_1; - $custom_integer_2 = ($custom_integer_2 === 0) ? $custom_integer_2_default : $custom_integer_2; + $custom_string_2 = (string) get_parameter('custom_string_2', $custom_string_2_default); + $custom_string_3 = (string) get_parameter('custom_string_3', $custom_string_3_default); + $custom_integer_2 = (int) get_parameter('custom_integer_2', 0); + + // Get macros. + $macros = (string) get_parameter('macros'); + $macros_names = (array) get_parameter('macro_name', []); if (empty($macros) === false) { $macros = json_decode(base64_decode($macros), true); foreach ($macros as $k => $m) { $m_hide = '0'; - if (isset($m['hide']) === true) { + if (isset($m['hide'])) { $m_hide = $m['hide']; } @@ -1399,79 +1397,146 @@ if ($update_module || $create_module) { agents_get_name($id_agente) ); + $snmp_community = (string) get_parameter('snmp_community'); + $snmp_oid = (string) get_parameter('snmp_oid'); // Change double quotes by single. $snmp_oid = preg_replace('/"/', ''', $snmp_oid); if (empty($snmp_oid) === true) { // The user did not set any OID manually but did a SNMP walk. - $snmp_oid = $select_snmp_oid; + $snmp_oid = (string) get_parameter('select_snmp_oid'); } if ($id_module_type >= 15 && $id_module_type <= 18) { // New support for snmp v3. - $plugin_pass = io_input_password($snmp3_auth_pass); - $custom_string_1 = $snmp3_privacy_method; - $custom_string_2 = io_input_password($snmp3_privacy_pass); - $custom_string_3 = $snmp3_security_level; - $plugin_parameter = $snmp3_auth_method; + $tcp_send = (string) get_parameter('snmp_version'); + $plugin_user = (string) get_parameter('snmp3_auth_user'); + $plugin_pass = io_input_password( + (string) get_parameter('snmp3_auth_pass') + ); + $plugin_parameter = (string) get_parameter('snmp3_auth_method'); + + $custom_string_1 = (string) get_parameter('snmp3_privacy_method'); + $custom_string_2 = io_input_password( + (string) get_parameter('snmp3_privacy_pass') + ); + $custom_string_3 = (string) get_parameter('snmp3_security_level'); } else if ($id_module_type >= 34 && $id_module_type <= 37) { - $tcp_send = $command_text; - $custom_string_1 = $command_credential_identifier; - $custom_string_2 = $command_os; + $tcp_send = (string) get_parameter('command_text'); + $custom_string_1 = (string) get_parameter( + 'command_credential_identifier' + ); + $custom_string_2 = (string) get_parameter('command_os'); } else { - if ($id_module_component_type !== 7) { - $plugin_pass = io_input_password($plugin_pass); + $plugin_user = (string) get_parameter('plugin_user'); + if (get_parameter('id_module_component_type') == 7) { + $plugin_pass = (int) get_parameter('plugin_pass'); + } else { + $plugin_pass = io_input_password( + (string) get_parameter('plugin_pass') + ); } + + $plugin_parameter = (string) get_parameter('plugin_parameter'); } + $parent_module_id = (int) get_parameter('parent_module_id'); + $ip_target = (string) get_parameter('ip_target'); // No autofill if the module is a webserver module. - if (empty($ip_target) === true + if ($ip_target == '' && $id_module_type < MODULE_TYPE_WEB_DATA && $id_module_type > MODULE_TYPE_WEB_CONTENT_STRING ) { $ip_target = 'auto'; } + $custom_id = (string) get_parameter('custom_id'); + $history_data = (int) get_parameter('history_data'); + $dynamic_interval = (int) get_parameter('dynamic_interval'); + $dynamic_max = (int) get_parameter('dynamic_max'); + $dynamic_min = (int) get_parameter('dynamic_min'); + $dynamic_two_tailed = (int) get_parameter('dynamic_two_tailed'); + $min_warning = (float) get_parameter('min_warning'); + $max_warning = (float) get_parameter('max_warning'); + $str_warning = (string) get_parameter('str_warning'); + $min_critical = (float) get_parameter('min_critical'); + $max_critical = (float) get_parameter('max_critical'); + $str_critical = (string) get_parameter('str_critical'); + $ff_event = (int) get_parameter('ff_event'); + $ff_event_normal = (int) get_parameter('ff_event_normal'); + $ff_event_warning = (int) get_parameter('ff_event_warning'); + $ff_event_critical = (int) get_parameter('ff_event_critical'); + $ff_type = (int) get_parameter('ff_type'); + $each_ff = (int) get_parameter('each_ff', $module['each_ff']); + $ff_timeout = (int) get_parameter('ff_timeout'); + $unit = (string) get_parameter('unit'); if ($unit === '0') { $unit = ''; } - if ($hour_to !== '*') { + $id_tag = (array) get_parameter('id_tag_selected'); + $serialize_ops = (string) get_parameter('serialize_ops'); + $critical_instructions = (string) get_parameter('critical_instructions'); + $warning_instructions = (string) get_parameter('warning_instructions'); + $unknown_instructions = (string) get_parameter('unknown_instructions'); + $critical_inverse = (int) get_parameter('critical_inverse'); + $warning_inverse = (int) get_parameter('warning_inverse'); + $percentage_critical = (int) get_parameter('percentage_critical'); + $percentage_warning = (int) get_parameter('percentage_warning'); + + $id_category = (int) get_parameter('id_category'); + + $hour_from = get_parameter('hour_from'); + $minute_from = get_parameter('minute_from'); + $mday_from = get_parameter('mday_from'); + $month_from = get_parameter('month_from'); + $wday_from = get_parameter('wday_from'); + + $hour_to = get_parameter('hour_to'); + $minute_to = get_parameter('minute_to'); + $mday_to = get_parameter('mday_to'); + $month_to = get_parameter('month_to'); + $wday_to = get_parameter('wday_to'); + + $http_user = get_parameter('http_user'); + $http_pass = get_parameter('http_pass'); + + if ($hour_to != '*') { $hour_to = '-'.$hour_to; } else { $hour_to = ''; } - if ($minute_to !== '*') { + if ($minute_to != '*') { $minute_to = '-'.$minute_to; } else { $minute_to = ''; } - if ($mday_to !== '*') { + if ($mday_to != '*') { $mday_to = '-'.$mday_to; } else { $mday_to = ''; } - if ($month_to !== '*') { + if ($month_to != '*') { $month_to = '-'.$month_to; } else { $month_to = ''; } - if ($wday_to !== '*') { + if ($wday_to != '*') { $wday_to = '-'.$wday_to; } else { $wday_to = ''; } $cron_interval = $minute_from.$minute_to.' '.$hour_from.$hour_to.' '.$mday_from.$mday_to.' '.$month_from.$month_to.' '.$wday_from.$wday_to; - if (cron_check_syntax($cron_interval) === false) { + if (!cron_check_syntax($cron_interval)) { $cron_interval = ''; } - if ((int) $prediction_module !== MODULE_PREDICTION_SYNTHETIC) { + if ($prediction_module != MODULE_PREDICTION_SYNTHETIC) { unset($serialize_ops); enterprise_hook( 'modules_delete_synthetic_operations', @@ -1480,17 +1545,30 @@ if ($update_module || $create_module) { } if ($prediction_module === MODULE_PREDICTION_PLANNING) { - $custom_string_2 = $estimation_type; + $custom_string_2 = get_parameter('estimation_type', 'estimation_calculation'); if ($custom_string_2 === 'estimation_calculation') { - $custom_string_1 = $estimation_days; + $custom_string_1 = get_parameter('estimation_days', -1); } else { - $custom_string_1 = $estimation_interval; + $custom_string_1 = get_parameter('estimation_interval', '300'); } } + $active_snmp_v3 = get_parameter('active_snmp_v3'); + + /* + * if ($active_snmp_v3) { + * // LOST CODE?. + * + * } + */ + + $throw_unknown_events = (bool) get_parameter('throw_unknown_events', false); // Set the event type that can show. $disabled_types_event = [EVENTS_GOING_UNKNOWN => (int) $throw_unknown_events]; $disabled_types_event = io_json_mb_encode($disabled_types_event); + + $module_macro_names = (array) get_parameter('module_macro_names', []); + $module_macro_values = (array) get_parameter('module_macro_values', []); $module_macros = modules_get_module_macros_json($module_macro_names, $module_macro_values); // Make changes in the conf file if necessary. @@ -1504,7 +1582,9 @@ if ($update_module || $create_module) { $success_action = NOERR; // MODULE UPDATE. -if ($update_module === true) { +if ($update_module) { + $id_agent_module = (int) get_parameter('id_agent_module'); + $values = [ 'id_agente_modulo' => $id_agent_module, 'descripcion' => $description, @@ -1574,13 +1654,13 @@ if ($update_module === true) { ]; - if ($id_module_type === 30 || $id_module_type === 31 || $id_module_type === 32 || $id_module_type === 33) { + if ($id_module_type == 30 || $id_module_type == 31 || $id_module_type == 32 || $id_module_type == 33) { $plugin_parameter_split = explode(' ', $values['plugin_parameter']); $values['plugin_parameter'] = ''; foreach ($plugin_parameter_split as $key => $value) { - if ((int) $key === 1) { + if ($key == 1) { if ($http_user) { $values['plugin_parameter'] .= 'http_auth_user '.$http_user.' '; } @@ -1588,21 +1668,23 @@ if ($update_module === true) { if ($http_pass) { $values['plugin_parameter'] .= 'http_auth_pass '.$http_pass.' '; } - } - $values['plugin_parameter'] .= $value.' '; + $values['plugin_parameter'] .= $value.' '; + } else { + $values['plugin_parameter'] .= $value.' '; + } } } // In local modules, the interval is updated by agent. - $module_kind = $moduletype; - if ($module_kind === MODULE_DATA) { + $module_kind = (int) get_parameter('moduletype'); + if ($module_kind == MODULE_DATA) { unset($values['module_interval']); } - if ($prediction_module === MODULE_PREDICTION_SYNTHETIC - && empty($serialize_ops) === true + if ($prediction_module == MODULE_PREDICTION_SYNTHETIC + && $serialize_ops == '' ) { $result = false; } else { @@ -1611,10 +1693,10 @@ if ($update_module === true) { FROM tagente_modulo WHERE id_agente_modulo ='.$id_agent_module ); - if (((int) $check_dynamic['dynamic_interval'] === $dynamic_interval) - && ((int) $check_dynamic['dynamic_max'] === $dynamic_max) - && ((int) $check_dynamic['dynamic_min'] === $dynamic_min) - && ((int) $check_dynamic['dynamic_two_tailed'] === $dynamic_two_tailed) + if (($check_dynamic['dynamic_interval'] == $dynamic_interval) + && ($check_dynamic['dynamic_max'] == $dynamic_max) + && ($check_dynamic['dynamic_min'] == $dynamic_min) + && ($check_dynamic['dynamic_two_tailed'] == $dynamic_two_tailed) ) { $result = modules_update_agent_module($id_agent_module, $values, false, $id_tag); } else { @@ -1623,7 +1705,7 @@ if ($update_module === true) { } } - if (is_error($result) === true) { + if (is_error($result)) { switch ($result) { case ERR_EXIST: $msg = __('There was a problem updating module. Another module already exists with the same name.'); @@ -1686,14 +1768,32 @@ if ($update_module === true) { } // MODULE INSERT. -if ($create_module === true) { +if ($create_module) { // Old configuration data must always be empty in case of creation. $old_configuration_data = ''; - if (empty($snmp_oid) === true) { + if (isset($_POST['combo_snmp_oid'])) { + $combo_snmp_oid = get_parameter_post('combo_snmp_oid'); + } + + if ($snmp_oid == '') { $snmp_oid = $combo_snmp_oid; } + $id_module = (int) get_parameter('id_module'); + + switch ($config['dbtype']) { + case 'oracle': + if (empty($description) || !isset($description)) { + $description = ' '; + } + break; + + default: + // Default. + break; + } + $values = [ 'id_tipo_modulo' => $id_module_type, 'descripcion' => $description, @@ -1783,7 +1883,7 @@ if ($create_module === true) { } } - if ($prediction_module === MODULE_PREDICTION_SYNTHETIC && empty($serialize_ops) === true) { + if ($prediction_module == MODULE_PREDICTION_SYNTHETIC && $serialize_ops == '') { $id_agent_module = false; } else { $id_agent_module = modules_create_agent_module( @@ -1795,7 +1895,7 @@ if ($create_module === true) { ); } - if (is_error($id_agent_module) === true) { + if (is_error($id_agent_module)) { switch ($id_agent_module) { case ERR_EXIST: $msg = __('There was a problem adding module. Another module already exists with the same name.'); @@ -1856,7 +1956,7 @@ if ($create_module === true) { // MODULE ENABLE/DISABLE // =====================. -if ($enable_module === true) { +if ($enable_module) { $result = modules_change_disabled($enable_module, 0); $module_name = modules_get_agentmodule_name($enable_module); @@ -1891,7 +1991,7 @@ if ($enable_module === true) { } } -if ($disable_module === true) { +if ($disable_module) { $result = modules_change_disabled($disable_module, 1); $module_name = modules_get_agentmodule_name($disable_module); @@ -1913,6 +2013,7 @@ if ($disable_module === true) { // Successfull action. $success_action = $result; + if ($result === NOERR) { db_pandora_audit( AUDIT_LOG_MODULE_MANAGEMENT, @@ -1950,18 +2051,19 @@ if ($update_module || $create_module // MODULE DELETION // =================. -if ($delete_module === true) { +if ($delete_module) { // DELETE agent module ! + $id_borrar_modulo = (int) get_parameter_get('delete_module', 0); $module_data = db_get_row_sql( 'SELECT tam.id_agente, tam.nombre FROM tagente_modulo tam, tagente_estado tae WHERE tam.id_agente_modulo = tae.id_agente_modulo - AND tam.id_agente_modulo = '.$id_agent_module + AND tam.id_agente_modulo = '.$id_borrar_modulo ); $id_grupo = (int) agents_get_agent_group($id_agente); $all_groups = agents_get_all_groups_agent($id_agente, $id_grupo); - if ((bool) check_acl_one_of_groups($config['id_user'], $all_groups, 'AW') === false) { + if (! check_acl_one_of_groups($config['id_user'], $all_groups, 'AW')) { db_pandora_audit( AUDIT_LOG_ACL_VIOLATION, 'Trying to delete a module without admin rights' @@ -1971,7 +2073,7 @@ if ($delete_module === true) { exit; } - if (empty($module_data) === true || $id_agent_module < 1) { + if (empty($module_data) || $id_borrar_modulo < 1) { db_pandora_audit( AUDIT_LOG_HACK_ATTEMPT, 'Expected variable from form is not correct' @@ -1982,10 +2084,10 @@ if ($delete_module === true) { } // Also call base function to delete modules. - modules_delete_agent_module($id_agent_module); + modules_delete_agent_module($id_borrar_modulo); // Check for errors. - if (isset($error) === true && (empty($error) === false || $error !== 0)) { + if ($error != 0) { ui_print_error_message(__('There was a problem deleting the module')); } else { echo ' diff --git a/pandora_console/godmode/agentes/module_manager_editor.php b/pandora_console/godmode/agentes/module_manager_editor.php index 49c23f3fe5..bf47db1db1 100644 --- a/pandora_console/godmode/agentes/module_manager_editor.php +++ b/pandora_console/godmode/agentes/module_manager_editor.php @@ -730,27 +730,45 @@ if ((bool) $config['enterprise_installed'] === true && $id_agent_module) { echo ''; // TODO: Change to the ui_print_error system. -echo '
'; - -ui_toggle( +$outputForm = ''; +$outputForm .= ui_toggle( html_print_table($table_simple, true), __('Base options'), '', '', - false + false, + true, + '', + '', + 'box-shadow white_table_graph white_table_graph_fixed' ); -ui_toggle( +$outputForm .= ui_toggle( html_print_table($table_advanced, true), - __('Advanced options') -); -ui_toggle( - html_print_table($table_macros, true), - __('Custom macros') + __('Advanced options'), + '', + '', + true, + true, + '', + '', + 'box-shadow white_table_graph white_table_graph_fixed' ); -if ($moduletype != 13) { - ui_toggle( +$outputForm .= ui_toggle( + html_print_table($table_macros, true), + __('Custom macros'), + '', + '', + true, + true, + '', + '', + 'box-shadow white_table_graph white_table_graph_fixed' +); + +if ((int) $moduletype !== 13) { + $outputForm .= ui_toggle( html_print_table( $table_new_relations, true @@ -758,7 +776,14 @@ if ($moduletype != 13) { $table_relations, true ), - __('Module relations') + __('Module relations'), + '', + '', + true, + true, + '', + '', + 'box-shadow white_table_graph white_table_graph_fixed' ); } @@ -786,11 +811,6 @@ if ($id_agent_module) { $actionButtons .= html_print_input_hidden('update_module', 1); $actionButtons .= html_print_input_hidden('id_agent_module', $id_agent_module); $actionButtons .= html_print_input_hidden('id_module_type', $id_module_type); - - html_print_action_buttons( - $actionButtons, - [ 'type' => 'form_action' ] - ); } else { $actionButtons = html_print_submit_button( __('Create'), @@ -802,22 +822,33 @@ if ($id_agent_module) { $actionButtons .= html_print_input_hidden('id_module', $moduletype); $actionButtons .= html_print_input_hidden('create_module', 1); - - html_print_action_buttons( - $actionButtons, - ['type' => 'form_action'] - ); } +$actionButtons .= html_print_go_back_button( + 'index.php?sec=gagente&sec2=godmode/agentes/configurar_agente&tab=module&id_agente='.$id_agente, + ['button_class' => ''], + true +); + +$outputForm .= html_print_action_buttons( + $actionButtons, + ['type' => 'form_action'], + true +); + if ((bool) $config['enterprise_installed'] === true && $remote_conf === true) { - ?> - - var check_remote_conf = true;'; } -echo '
'; +$outputForm .= ''; + +html_print_div( + [ + 'class' => 'max_floating_element_size', + 'content' => $outputForm, + ], + false +); ui_require_jquery_file('ui'); ui_require_jquery_file('form'); diff --git a/pandora_console/godmode/agentes/module_manager_editor_common.php b/pandora_console/godmode/agentes/module_manager_editor_common.php index 68b903e687..138fbfd0e6 100644 --- a/pandora_console/godmode/agentes/module_manager_editor_common.php +++ b/pandora_console/godmode/agentes/module_manager_editor_common.php @@ -31,6 +31,8 @@ require_once $config['homedir'].'/include/functions_modules.php'; require_once $config['homedir'].'/include/functions_categories.php'; require_once $config['homedir'].'/include/graphs/functions_d3.php'; +use PandoraFMS\Agent; + include_javascript_d3(); @@ -98,10 +100,10 @@ function add_component_selection($id_network_component_type) global $table_simple; global $config; - if ($config['style'] === 'pandora_black' && !is_metaconsole()) { + if ($config['style'] === 'pandora_black' && is_metaconsole() === false) { $background_row = 'background-color: #444'; } else { - $background_row = 'background-color: #cfcfcf'; + $background_row = 'background-color: #FFF'; } $data = []; @@ -163,8 +165,9 @@ $disabledBecauseInPolicy = false; $disabledTextBecauseInPolicy = ''; $largeClassDisabledBecauseInPolicy = ''; -$page = get_parameter('page', ''); - +$update_module_id = (int) get_parameter_get('update_module'); +$edit_module = (bool) get_parameter_get('edit_module'); +$page = get_parameter('page', ''); $in_policies_page = strstr($page, 'policy_modules'); if ($in_policies_page === false && $id_agent_module) { @@ -190,24 +193,6 @@ if ($disabledBecauseInPolicy) { $classdisabledBecauseInPolicy = ''; } -$update_module_id = (int) get_parameter_get('update_module'); -$edit_module = (bool) get_parameter_get('edit_module'); -$table_simple = new stdClass(); -$table_simple->id = 'simple'; -$table_simple->class = 'w100p mrgn_10px floating_form'; -$table_simple->data = []; -$table_simple->style = []; -$table_simple->cellclass = []; -$table_simple->colspan = []; -$table_simple->rowspan = []; -$table_simple->cellpadding = 2; -$table_simple->cellspacing = 0; -$table_simple->rowspan[3][2] = 3; -$table_simple->rowspan[4][2] = 3; - -$dataRow = 0; -$dataCol = 0; - if (empty($id_agent_module) === false && isset($id_agente) === true) { $moduleIdContent = html_print_div( [ @@ -220,7 +205,51 @@ if (empty($id_agent_module) === false && isset($id_agente) === true) { $moduleIdContent = ''; } +$policy_link = db_get_value( + 'policy_linked', + 'tagente_modulo', + 'id_agente_modulo', + $id_agent_module +); + +if ((int) $policy_link !== 0) { + $disabled_enable = 1; +} else { + $disabled_enable = 0; +} + +if ((isset($id_agent_module) === true && $id_agent_module > 0) || (int) $id_policy_module !== 0) { + $edit = false; +} else { + $edit = true; +} + +$table_simple = new stdClass(); +$table_simple->id = 'simple'; +$table_simple->class = 'w100p floating_form'; +$table_simple->data = []; +$table_simple->style = []; +$table_simple->cellclass = []; +$table_simple->colspan = []; +$table_simple->rowspan = []; +$table_simple->cellpadding = 2; +$table_simple->cellspacing = 0; +$table_simple->rowspan[3][2] = 3; +$table_simple->rowspan[4][2] = 3; +// Special configuration for some rows. +$table_simple->rowclass['caption_target_ip'] = 'field_half_width pdd_t_10px'; +$table_simple->rowclass['target_ip'] = 'field_half_width'; +$table_simple->rowclass['caption_tcp_send_receive'] = 'field_half_width pdd_t_10px'; +$table_simple->rowclass['tcp_send_receive'] = 'field_half_width'; +$table_simple->rowclass['caption_configuration_data'] = 'field_half_width pdd_t_10px'; +$table_simple->rowclass['textarea_configuration_data'] = 'field_half_width'; +$table_simple->rowclass['configuration_data'] = 'field_half_width'; +$table_simple->cellstyle['configuration_data'][0] = 'justify-content: flex-end;'; + +$table_simple->rowclass['caption_module_name'] = 'field_half_width pdd_t_10px'; +$table_simple->rowclass['module_name'] = 'field_half_width'; $table_simple->data['caption_module_name'][0] = __('Name'); +$table_simple->data['caption_module_name'][1] = __('Disabled'); $table_simple->data['module_name'][0] = html_print_input_text_extended( 'name', $name, @@ -234,21 +263,7 @@ $table_simple->data['module_name'][0] = html_print_input_text_extended( true ).$moduleIdContent; -$disabled_enable = 0; -$policy_link = db_get_value( - 'policy_linked', - 'tagente_modulo', - 'id_agente_modulo', - $id_agent_module -); - -if ($policy_link != 0) { - $disabled_enable = 1; -} - -$table_simple->rowclass['disable_module'] = 'flex_center '; -$table_simple->data['disable_module'][0] = __('Disabled'); -$table_simple->data['disable_module'][1] .= html_print_checkbox_switch( +$table_simple->data['module_name'][1] = html_print_checkbox_switch( 'disabled', 1, $disabled, @@ -270,14 +285,13 @@ $table_simple->data['disable_module'][1] .= html_print_checkbox_switch( ); */ // Caption for Module group and Type. -$table_simple->cellstyle['captions_module_n_type'][0] = 'width: 50%;'; -$table_simple->cellstyle['captions_module_n_type'][1] = 'width: 50%;'; +$table_simple->rowclass['captions_module_n_type'] = 'field_half_width pdd_t_10px'; +$table_simple->rowclass['module_n_type'] = 'field_half_width'; $table_simple->data['captions_module_n_type'][0] = html_print_input_hidden('id_module_type_hidden', $id_module_type, true); $table_simple->data['captions_module_n_type'][0] .= __('Module group'); $table_simple->data['captions_module_n_type'][1] = __('Type').ui_print_help_icon($help_type, true, '', 'images/help_green.png', '', 'module_type_help'); // Module group and Type. -$table_simple->cellstyle['module_n_type'][0] = 'width: 50%;'; -$table_simple->cellstyle['module_n_type'][1] = 'width: 50%;'; +$table_simple->rowclass['module_n_type'] = 'field_half_width'; $table_simple->data['module_n_type'][0] .= html_print_select_from_sql( 'SELECT id_mg, name FROM tmodule_group ORDER BY name', 'id_module_group', @@ -292,14 +306,6 @@ $table_simple->data['module_n_type'][0] .= html_print_select_from_sql( 'width: 480px' ); -if ((isset($id_agent_module) === true && $id_agent_module > 0) || (int) $id_policy_module !== 0) { - $edit = false; -} else { - $edit = true; -} - -$in_policy = strstr($page, 'policy_modules'); - if ($edit === false) { $sql = sprintf( 'SELECT id_tipo, nombre @@ -418,10 +424,13 @@ $tableBasicThresholds = new stdClass(); $tableBasicThresholds->class = 'w100p table_section'; $tableBasicThresholds->id = 'basic_thresholds'; $tableBasicThresholds->style = []; +$tableBasicThresholds->rowclass = []; $tableBasicThresholds->data = []; // WARNING THRESHOLD. if (modules_is_string_type($id_module_type) === false) { + $tableBasicThresholds->rowclass['caption_warning_threshold'] = 'field_half_width pdd_t_10px'; + $tableBasicThresholds->rowclass['warning_threshold'] = 'field_half_width'; $tableBasicThresholds->cellclass['caption_warning_threshold'] = 'show_hide_thresholds_minmax'; $tableBasicThresholds->cellclass['warning_threshold'] = 'show_hide_thresholds_minmax'; $tableBasicThresholds->data['caption_warning_threshold'][0] .= __('Warning threshold').' ('.__('Min / Max').')'; @@ -462,6 +471,8 @@ if (modules_is_string_type($id_module_type) === false) { } if (modules_is_string_type($id_module_type) === true) { + $tableBasicThresholds->rowclass['caption_warning_threshold'] = 'field_half_width pdd_t_10px'; + $tableBasicThresholds->rowclass['warning_threshold'] = 'field_half_width'; $tableBasicThresholds->cellclass['caption_warning_threshold'] = 'show_hide_thresholds_string'; $tableBasicThresholds->cellclass['warning_threshold'] = 'show_hide_thresholds_string'; $tableBasicThresholds->data['caption_warning_threshold'][0] .= __('Warning threshold').' ('.__('Str.').')'; @@ -491,8 +502,9 @@ if (modules_is_string_type($id_module_type) === true) { ); } - // CRITICAL THRESHOLD. +$tableBasicThresholds->rowclass['caption_critical_threshold'] = 'field_half_width pdd_t_10px'; +$tableBasicThresholds->rowclass['critical_threshold'] = 'field_half_width'; $tableBasicThresholds->cellclass['caption_critical_threshold'] = 'show_hide_thresholds_minmax'; $tableBasicThresholds->cellclass['critical_threshold'] = 'show_hide_thresholds_minmax'; $tableBasicThresholds->data['caption_critical_threshold'][0] .= __('Critical threshold').' ('.__('Min / Max').')'; @@ -589,65 +601,8 @@ if ($disabledBecauseInPolicy) { ); } -// Advanced form part. -$table_advanced = new stdClass(); -$table_advanced->id = 'advanced'; -$table_advanced->width = '100%'; -$table_advanced->class = 'no-class'; -$table_advanced->data = []; -$table_advanced->style = []; -$table_advanced->style[0] = $table_advanced->style[3] = $table_advanced->style[5] = 'font-weight: bold;'; -$table_advanced->colspan = []; - -$table_advanced->colspan[5][1] = 3; - -$table_advanced->data['captions_custom_id_unit'][0] = __('Custom ID'); -$table_advanced->data['captions_custom_id_unit'][1] = __('Unit'); -// $table_advanced->colspan[0][1] = 2; -$table_advanced->data['custom_id_unit'][0] = html_print_input_text( - 'custom_id', - $custom_id, - '', - 20, - 65, - true, - (($config['module_custom_id_ro'] && $__code_from != 'policies') ? true : $disabledBecauseInPolicy), - false, - '', - (($config['module_custom_id_ro'] && $__code_from != 'policies') ? 'readonly' : $classdisabledBecauseInPolicy) -); - -$table_advanced->data['custom_id_unit'][1] = html_print_input_text( - 'unit', - $unit, - '', - 20, - 65, - true, - $disabledBecauseInPolicy, - false, - '', - $classdisabledBecauseInPolicy -); -// $table_advanced->colspan[1][4] = 3; -$table_advanced->data['custom_id_unit'][1] = html_print_extended_select_for_unit( - 'unit', - $unit, - '', - 'none', - '0', - false, - true, - false, - false -); -$table_advanced->colspan[0][4] = 3; - -// Tags +// Business Logic for Advanced Part. global $__code_from; -$table_advanced->data['caption_tags_module_parent'][0] = __('Tags available'); -$table_advanced->data['caption_tags_module_parent'][1] = __('Tags selected'); -$table_advanced->data['caption_tags_module_parent'][2] = __('Tags from policy'); // Code comes from module_editor. if ($__code_from === 'modules') { $__table_modules = 'ttag_module'; @@ -666,8 +621,86 @@ if ($__code_from === 'modules') { $__sql = ''; } +$module_id_policy_module = 0; +if (isset($module['id_policy_module']) === true) { + $module_id_policy_module = $module['id_policy_module']; +} + +$cps_array[-1] = __('Disabled'); +if ($cps_module > 0) { + $cps_array[$cps_module] = __('Enabled'); +} else { + $cps_inc = 0; + if ($id_agent_module) { + $cps_inc = enterprise_hook('service_modules_cps', [$id_agent_module]); + if ($cps_inc === ENTERPRISE_NOT_HOOK) { + $cps_inc = 0; + } + } + + $cps_array[$cps_inc] = __('Enabled'); +} + + +// Advanced form part. +$table_advanced = new stdClass(); +$table_advanced->id = 'advanced'; +$table_advanced->width = '100%'; +$table_advanced->class = 'w100p floating_form'; +$table_advanced->data = []; +$table_advanced->style = []; +$table_advanced->rowclass = []; +$table_advanced->cellclass = []; +$table_advanced->colspan = []; +$table_advanced->rowspan = []; + +$table_advanced->data['title_1'] = html_print_subtitle_table(__('Identification and Categorization'), [], true); +$table_advanced->rowclass['captions_custom_category'] = 'field_half_width pdd_t_10px'; +$table_advanced->rowclass['custom_id_category'] = 'field_half_width'; +$table_advanced->data['captions_custom_category'][0] = __('Custom ID'); +$table_advanced->data['captions_custom_category'][1] = __('Category'); + +$table_advanced->data['custom_id_category'][0] = html_print_input_text( + 'custom_id', + $custom_id, + '', + 20, + 65, + true, + (($config['module_custom_id_ro'] && $__code_from !== 'policies') ? true : $disabledBecauseInPolicy), + false, + '', + (($config['module_custom_id_ro'] && $__code_from !== 'policies') ? 'readonly' : $classdisabledBecauseInPolicy) +); + +if ((bool) check_acl($config['id_user'], 0, 'PM') === true) { + $table_advanced->data['custom_id_category'][1] = html_print_select( + categories_get_all_categories('forselect'), + 'id_category', + $id_category, + '', + __('None'), + 0, + true, + false, + true, + '', + $disabledBecauseInPolicy + ); +} else { + // Store in a hidden field if is not visible to avoid delete the value. + $table_advanced->data['custom_id_category'][1] .= html_print_input_hidden('id_category', $id_category, true); +} + +// Tags. +$table_advanced->rowclass['caption_tags_module_parent'] = 'field_half_width pdd_t_10px'; +$table_advanced->rowclass['tags_module_parent'] = 'field_half_width'; +$table_advanced->data['caption_tags_module_parent'][0] = __('Tags available'); + +$tagsAvailableData = ''; +$tagsCompleteData = ''; if (tags_has_user_acl_tags($config['id_user']) === false) { - $table_advanced->data['tags_module_parent'][0] = html_print_select_from_sql( + $tagsAvailableData .= html_print_select_from_sql( "SELECT id_tag, name FROM ttag WHERE id_tag NOT IN ( @@ -692,7 +725,7 @@ if (tags_has_user_acl_tags($config['id_user']) === false) { if (empty($user_tags) === false) { $id_user_tags = array_keys($user_tags); - $table_advanced->data['tags_module_parent'][0] = html_print_select_from_sql( + $tagsAvailableData .= html_print_select_from_sql( 'SELECT id_tag, name FROM ttag WHERE id_tag IN ('.implode(',', $id_user_tags).") AND @@ -714,7 +747,7 @@ if (tags_has_user_acl_tags($config['id_user']) === false) { '5' ); } else { - $table_advanced->data['tags_module_parent'][0] = html_print_select_from_sql( + $tagsAvailableData .= html_print_select_from_sql( "SELECT id_tag, name FROM ttag WHERE id_tag NOT IN ( @@ -737,48 +770,113 @@ if (tags_has_user_acl_tags($config['id_user']) === false) { } } -$table_advanced->data['tags_module_parent'][2] = html_print_image( - 'images/darrowright.png', +$tagsAvailableData .= html_print_image( + 'images/svg/plus.svg', true, [ 'id' => 'right', 'title' => __('Add tags to module'), - 'class' => 'invert_filter', + 'class' => 'invert_filter clickable', + 'style' => 'width: 32px;', ] ); -$table_advanced->data['tags_module_parent'][2] .= '



'.html_print_image( - 'images/darrowleft.png', - true, - [ - 'id' => 'left', - 'title' => __('Delete tags to module'), - 'class' => 'invert_filter', - ] -); -$table_advanced->data['tags_module_parent'][3] = ''; -// .__('Tags selected') -$table_advanced->data['tags_module_parent'][4] = html_print_select_from_sql( - "SELECT a.id_tag, name - FROM ttag a, $__table_modules b - WHERE a.id_tag = b.id_tag AND $__id_where = $__id - $__sql - ORDER BY name", - 'id_tag_selected[]', - '', - '', - '', - '', - true, - true, - false, - $disabledBecauseInPolicy, - 'width: 200px', - '5' -); + +$tagsCompleteData = html_print_div( + [ + 'class' => 'tags_available_container', + 'content' => $tagsAvailableData, + ], + true +); + +$tagsCompleteData .= html_print_div( + [ + 'class' => 'tags_selected_container', + 'content' => html_print_select_from_sql( + "SELECT a.id_tag, name + FROM ttag a, $__table_modules b + WHERE a.id_tag = b.id_tag AND $__id_where = $__id + $__sql + ORDER BY name", + 'id_tag_selected[]', + '', + '', + '', + '', + true, + true, + false, + $disabledBecauseInPolicy, + 'width: 200px;', + '5' + ), + ], + true +); + +$table_advanced->data['tags_module_parent'][0] .= html_print_div( + [ + 'class' => 'tags_complete_container', + 'content' => $tagsCompleteData, + ], + true +); + +if ((bool) $in_policies_page === false) { + // Cannot select the current module to be itself parent. + $module_parent_filter = ($id_agent_module) ? ['tagente_modulo.id_agente_modulo' => '<>'.$id_agent_module] : []; + $table_advanced->data['caption_tags_module_parent'][1] = __('Module parent'); + // TODO. Review cause dont know not works. + /* + $agent = new Agent($id_agente); + $modules_can_be_parent = $agent->searchModules( + $module_parent_filter, + 0 + ); + */ + $modules_can_be_parent = agents_get_modules( + $id_agente, + false, + $module_parent_filter + ); + // If the user cannot have access to parent module, only print the name. + if ((int) $parent_module_id !== 0 + && in_array($parent_module_id, array_keys($modules_can_be_parent)) === true + ) { + $parentModuleOutput = db_get_value( + 'nombre', + 'tagente_modulo', + 'id_agente_modulo', + $parent_module_id + ); + } else { + $parentModuleOutput = html_print_select( + $modules_can_be_parent, + 'parent_module_id', + $parent_module_id, + '', + __('Not assigned'), + '0', + true + ); + } + + $table_advanced->cellstyle['tags_module_parent'][1] = 'align-self: flex-start;'; + $table_advanced->data['tags_module_parent'][1] = html_print_div( + [ + 'class' => 'parent_module_container w100p', + 'content' => $parentModuleOutput, + ], + true, + ); +} + +$table_advanced->rowclass['caption_tags_from_policy_module_parent'] = 'field_half_width pdd_t_10px'; +$table_advanced->rowclass['tags_from_policy_module_parent'] = 'field_half_width'; if ($__code_from === 'modules') { - $table_advanced->data['tags_module_parent'][5] = ''.''.''; - $table_advanced->data['tags_module_parent'][6] = html_print_select_from_sql( + $table_advanced->data['caption_tags_from_policy_module_parent'][0] = __('Tags from policy'); + $table_advanced->data['tags_from_policy_module_parent'][0] = html_print_select_from_sql( "SELECT a.id_tag, name FROM ttag a, $__table_modules b WHERE a.id_tag = b.id_tag AND $__id_where = $__id @@ -796,73 +894,123 @@ if ($__code_from === 'modules') { 'width: 200px', '5' ); + + $table_advanced->data['tags_from_policy_module_parent'][1] = ''; } -$module_id_policy_module = 0; -if (isset($module['id_policy_module']) === true) { - $module_id_policy_module = $module['id_policy_module']; -} +$table_advanced->rowclass['caption_textarea_description_instructions'] = 'field_half_width pdd_t_10px'; +$table_advanced->rowclass['textarea_description_instructions'] = 'field_half_width'; +$table_advanced->data['caption_textarea_description_instructions'][0] = __('Description'); +$table_advanced->data['caption_textarea_description_instructions'][1] = __('Unknown instructions'); +$table_advanced->data['textarea_description_instructions'][0] = html_print_textarea( + 'unknown_instructions', + 5, + 35, + $unknown_instructions, + $disabledTextBecauseInPolicy, + true, + $largeClassDisabledBecauseInPolicy +); +$table_advanced->data['textarea_description_instructions'][1] = html_print_textarea( + 'description', + 5, + 35, + $description, + $disabledTextBecauseInPolicy, + true, + $largeClassDisabledBecauseInPolicy +); +$table_advanced->rowclass['caption_textarea_crit_warn_instructions'] = 'field_half_width pdd_t_10px'; +$table_advanced->rowclass['textarea_crit_warn_instructions'] = 'field_half_width'; +$table_advanced->data['caption_textarea_crit_warn_instructions'][1] = __('Warning instructions'); +$table_advanced->data['caption_textarea_crit_warn_instructions'][0] = __('Critical instructions'); +$table_advanced->data['textarea_crit_warn_instructions'][0] = html_print_textarea( + 'critical_instructions', + 5, + 35, + $critical_instructions, + $disabledTextBecauseInPolicy, + true, + $largeClassDisabledBecauseInPolicy +); + +$table_advanced->data['textarea_crit_warn_instructions'][1] = html_print_textarea( + 'warning_instructions', + 5, + 35, + $warning_instructions, + $disabledTextBecauseInPolicy, + true, + $largeClassDisabledBecauseInPolicy +); + +$table_advanced->data['title_2'] = html_print_subtitle_table(__('Execution interval'), [], true); +$table_advanced->data['caption_execution_interval'][0] = __('Interval'); // In the data modules, the interval is not in seconds. It is a factor -// to be multiplied for the agent interval -if ($moduletype == MODULE_DATA) { - $table_advanced->data[1][0] = __('Interval'); - $table_advanced->colspan[1][1] = 2; +// to be multiplied for the agent interval. +if ((int) $moduletype === MODULE_DATA) { $interval_factor = 1; - if (isset($id_agente)) { + if (isset($id_agente) === true) { $agent_interval = (float) agents_get_interval($id_agente); if ($agent_interval > 0) { $interval = (float) $interval; $interval_factor = ($interval / $agent_interval); } - $table_advanced->data[1][1] = human_time_description_raw($interval).' ('.sprintf(__('Agent interval x %s'), $interval_factor).') '; + $table_advanced->data['execution_interval'][0] = human_time_description_raw($interval).' ('.sprintf(__('Agent interval x %s'), $interval_factor).') '; } else { - $table_advanced->data[1][1] = sprintf(__('Agent interval x %s'), $interval_factor); + $table_advanced->data['execution_interval'][0] = sprintf(__('Agent interval x %s'), $interval_factor); } - if ($__code_from == 'policies') { + if ($__code_from === 'policies') { // If is the policy form, module_interval will store the factor (not the seconds). // So server will transform it to interval in seconds. - $table_advanced->data[1][1] = sprintf(__('Default').': 1', $interval_factor); - $table_advanced->data[1][1] .= html_print_input_hidden('module_interval', $interval_factor, true); + $table_advanced->data['execution_interval'][0] = sprintf(__('Default').': 1', $interval_factor); + $table_advanced->data['execution_interval'][0] .= html_print_input_hidden('module_interval', $interval_factor, true); } // If it is a non policy form, the module_interval will not provided and will. // be taken the agent interval (this code is at configurar_agente.php). } else { - $table_advanced->data[1][0] = __('Interval'); - $table_advanced->colspan[1][1] = 2; - $table_advanced->data[1][1] = html_print_extended_select_for_time('module_interval', $interval, '', '', '0', false, true, false, false, $classdisabledBecauseInPolicy, $disabledBecauseInPolicy); + $table_advanced->data['execution_interval'][0] = html_print_extended_select_for_time('module_interval', $interval, '', '', '0', false, true, false, false, $classdisabledBecauseInPolicy, $disabledBecauseInPolicy); } -$table_advanced->data[1][1] .= html_print_input_hidden('moduletype', $moduletype, true); +$table_advanced->data['execution_interval'][0] .= html_print_input_hidden('moduletype', $moduletype, true); -$table_advanced->data[1][3] = __('Post process'); -$table_advanced->data[1][4] = html_print_extended_select_for_post_process( - 'post_process', - $post_process, - '', - '', - '0', - false, - true, - 'width:10em', - false, - $disabledBecauseInPolicy -); -$table_advanced->colspan[1][4] = 3; +if (isset($id_agente) === true && (int) $moduletype === MODULE_DATA) { + $has_remote_conf = enterprise_hook('config_agents_has_remote_configuration', [$agent['id_agente']]); + $table_advanced->data['caption_cron_from_select'][0] = __('Cron from'); + $table_advanced->data['cron_from_select'][0] = html_print_extended_select_for_cron($hour_from, $minute_from, $mday_from, $month_from, $wday_from, true, ((bool) $has_remote_conf === true) ? $disabledBecauseInPolicy : true); -$table_advanced->data[2][0] = __('Min. Value'); -$table_advanced->colspan[2][1] = 2; + $table_advanced->data['caption_cron_to_select'][0] = __('Cron to'); + $table_advanced->data['cron_to_select'][0] = html_print_extended_select_for_cron($hour_to, $minute_to, $mday_to, $month_to, $wday_to, true, ((bool) $has_remote_conf === true) ? $disabledBecauseInPolicy : true, true); +} else { + $table_advanced->data['caption_cron_from_select'][0] = __('Cron from'); + $table_advanced->data['cron_from_select'][1] = html_print_extended_select_for_cron($hour_from, $minute_from, $mday_from, $month_from, $wday_from, true, $disabledBecauseInPolicy); -$table_advanced->data[2][1] = html_print_input_text('min', $min, '', 5, 15, true, $disabledBecauseInPolicy, false, '', $classdisabledBecauseInPolicy); -$table_advanced->data[2][3] = __('Max. Value'); -$table_advanced->data[2][4] = html_print_input_text('max', $max, '', 5, 15, true, $disabledBecauseInPolicy, false, '', $classdisabledBecauseInPolicy); -$table_advanced->colspan[2][4] = 3; + $table_advanced->data['caption_cron_to_select'][0] = __('Cron to'); + $table_advanced->data['cron_to_select'][1] = html_print_extended_select_for_cron($hour_to, $minute_to, $mday_to, $month_to, $wday_to, true, $disabledBecauseInPolicy, true); +} -$table_advanced->data[3][0] = __('Dynamic Threshold Interval'); -$table_advanced->data[3][1] = html_print_extended_select_for_time( +$table_advanced->data['title_3'] = html_print_subtitle_table(__('Thresholds and state changes'), [], true); + + +$table_advanced->rowclass['caption_textarea_crit_warn_instructions'] = 'field_half_width pdd_t_10px'; +$table_advanced->rowclass['textarea_crit_warn_instructions'] = 'field_half_width'; +$table_advanced->cellclass['caption_min_max_values'][0] = 'field_quarter_width'; +$table_advanced->cellclass['caption_min_max_values'][1] = 'field_quarter_width'; +$table_advanced->cellclass['min_max_values'][0] = 'field_quarter_width'; +$table_advanced->cellclass['min_max_values'][1] = 'field_quarter_width'; + +$table_advanced->data['caption_min_max_values'][0] = __('Min. Value'); +$table_advanced->data['caption_min_max_values'][1] = __('Max. Value'); + +$table_advanced->data['min_max_values'][0] = html_print_input_text('min', $min, '', 5, 15, true, $disabledBecauseInPolicy, false, '', $classdisabledBecauseInPolicy); +$table_advanced->data['min_max_values'][1] = html_print_input_text('max', $max, '', 5, 15, true, $disabledBecauseInPolicy, false, '', $classdisabledBecauseInPolicy); + +$table_advanced->data['caption_dynamic_threshold_interval'][0] = __('Dynamic Threshold Interval'); +$table_advanced->data['dynamic_threshold_interval'][0] = html_print_extended_select_for_time( 'dynamic_interval', $dynamic_interval, '', @@ -875,7 +1023,7 @@ $table_advanced->data[3][1] = html_print_extended_select_for_time( $classdisabledBecauseInPolicy, $disabledBecauseInPolicy ); -$table_advanced->data[3][1] .= ''.html_print_image( +$table_advanced->data['dynamic_threshold_interval'][1] .= ''.html_print_image( 'images/cog.png', true, [ @@ -884,12 +1032,14 @@ $table_advanced->data[3][1] .= ''.html_prin ] ).''; -$table_advanced->cellclass[3][2] = 'hide_dinamic'; -$table_advanced->cellclass[3][3] = 'hide_dinamic'; +$table_advanced->rowclass['caption_adv_dynamic_threshold_interval'] = 'hide_dinamic pdd_t_10px'; +$table_advanced->rowclass['adv_dynamic_threshold_interval'] = 'hide_dinamic'; +$table_advanced->data['caption_adv_dynamic_threshold_interval'][0] = __('Dynamic Threshold Min.'); +$table_advanced->data['caption_adv_dynamic_threshold_interval'][1] = __('Dynamic Threshold Max.'); +$table_advanced->data['caption_adv_dynamic_threshold_interval'][2] = __('Dynamic Threshold Two Tailed'); -$table_advanced->data[3][2] = ''.__('Dynamic Threshold Min. ').''; -$table_advanced->data[3][2] .= html_print_input_text( +$table_advanced->data['adv_dynamic_threshold_interval'][0] = html_print_input_text( 'dynamic_min', $dynamic_min, '', @@ -901,8 +1051,7 @@ $table_advanced->data[3][2] .= html_print_input_text( '', $classdisabledBecauseInPolicy ); -$table_advanced->data[3][2] .= '
'.__('Dynamic Threshold Max. ').''; -$table_advanced->data[3][2] .= html_print_input_text( +$table_advanced->data['adv_dynamic_threshold_interval'][1] = html_print_input_text( 'dynamic_max', $dynamic_max, '', @@ -914,81 +1063,28 @@ $table_advanced->data[3][2] .= html_print_input_text( '', $classdisabledBecauseInPolicy ); -$table_advanced->data[3][3] = ''.__('Dynamic Threshold Two Tailed: ').''; -$table_advanced->data[3][3] .= html_print_checkbox('dynamic_two_tailed', 1, $dynamic_two_tailed, true, $disabledBecauseInPolicy); - - - -$table_advanced->data[4][0] = __('Export target'); -// Default text message for export target select and disabled option -$none_text = __('None'); -$disabled_export = false; - -if ($__code_from == 'policies') { - $none_text = __('Not needed'); - $disabled_export = true; -} - -$table_advanced->data[4][1] = html_print_select_from_sql( - 'SELECT id, name FROM tserver_export ORDER BY name', - 'id_export', - $id_export, - '', - $none_text, - '0', - true, - false, - false, - $disabled_export -); -$table_advanced->colspan[4][1] = 2; - -// Code comes from module_editor. -if ($__code_from == 'modules') { - $throw_unknown_events_check = modules_is_disable_type_event($id_agent_module, EVENTS_GOING_UNKNOWN); -} else { - global $__id_pol_mod; - - $throw_unknown_events_check = policy_module_is_disable_type_event($__id_pol_mod, EVENTS_GOING_UNKNOWN); -} - -$table_advanced->data[4][3] = __('Discard unknown events'); -$table_advanced->data[4][4] = html_print_checkbox( - 'throw_unknown_events', +$table_advanced->data['adv_dynamic_threshold_interval'][2] = html_print_checkbox( + 'dynamic_two_tailed', 1, - $throw_unknown_events_check, + $dynamic_two_tailed, true, $disabledBecauseInPolicy ); -$table_advanced->colspan[4][4] = 3; - // FF stands for Flip-flop. -$table_advanced->colspan[5][1] = 5; -$table_advanced->cellclass[5][1] = 'font_bold'; - - -$table_advanced->data[5][0] = __('FF threshold').' '; - -$table_advanced->data[5][1] .= __('Keep counters'); -$table_advanced->data[5][1] .= html_print_checkbox( - 'ff_type', - 1, - $ff_type, - true, - $disabledBecauseInPolicy -).'
'; - -$table_advanced->data[5][1] .= html_print_radio_button( - 'each_ff', - 0, - '', - $each_ff, - true, - $disabledBecauseInPolicy +$table_advanced->data['caption_ff_thresholds'][0] = __('FF threshold').' '; +$table_advanced->data['ff_thresholds'][0] .= html_print_switch_radio_button( + [ + html_print_radio_button_extended('each_ff', 0, __('All state changing'), $each_ff, false, '', '', true, false, '', 'ff_all_state'), + html_print_radio_button_extended('each_ff', 1, __('Each state changing'), $each_ff, false, '', '', true, false, '', 'ff_each_state'), + ], + [], + true ); -$table_advanced->data[5][1] .= ' '.__('All state changing').' : '; -$table_advanced->data[5][1] .= html_print_input_text( +$table_advanced->rowclass['caption_all_ff_thresholds'] = 'all_ff_thresholds_visibility pdd_t_10px'; +$table_advanced->rowclass['all_ff_thresholds'] = 'all_ff_thresholds_visibility'; +$table_advanced->data['caption_all_ff_thresholds'][0] = __('Change all states'); +$table_advanced->data['all_ff_thresholds'][0] = html_print_input_text( 'ff_event', $ff_event, '', @@ -999,19 +1095,15 @@ $table_advanced->data[5][1] .= html_print_input_text( false, '', $classdisabledBecauseInPolicy -).'
'; -$table_advanced->data[5][1] .= html_print_radio_button( - 'each_ff', - 1, - '', - $each_ff, - true, - $disabledBecauseInPolicy ); -$table_advanced->data[5][1] .= ' '.__('Each state changing').' : '; -$table_advanced->data[5][1] .= __('To normal'); -$table_advanced->data[5][1] .= html_print_input_text( +$table_advanced->rowclass['caption_each_ff_thresholds'] = 'each_ff_thresholds_visibility pdd_t_10px'; +$table_advanced->data['caption_each_ff_thresholds'][0] = __('To normal'); +$table_advanced->data['caption_each_ff_thresholds'][1] = __('To warning'); +$table_advanced->data['caption_each_ff_thresholds'][2] = __('To critical'); + +$table_advanced->rowclass['each_ff_thresholds'] = 'each_ff_thresholds_visibility'; +$table_advanced->data['each_ff_thresholds'][0] = html_print_input_text( 'ff_event_normal', $ff_event_normal, '', @@ -1022,10 +1114,9 @@ $table_advanced->data[5][1] .= html_print_input_text( false, '', $classdisabledBecauseInPolicy -).' '; +); -$table_advanced->data[5][1] .= __('To warning'); -$table_advanced->data[5][1] .= html_print_input_text( +$table_advanced->data['each_ff_thresholds'][1] = html_print_input_text( 'ff_event_warning', $ff_event_warning, '', @@ -1036,10 +1127,9 @@ $table_advanced->data[5][1] .= html_print_input_text( false, '', $classdisabledBecauseInPolicy -).' '; +); -$table_advanced->data[5][1] .= __('To critical'); -$table_advanced->data[5][1] .= html_print_input_text( +$table_advanced->data['each_ff_thresholds'][2] = html_print_input_text( 'ff_event_critical', $ff_event_critical, '', @@ -1052,9 +1142,18 @@ $table_advanced->data[5][1] .= html_print_input_text( $classdisabledBecauseInPolicy ); +$table_advanced->data['caption_ff_keep_counters'][0] = __('Keep counters'); +$table_advanced->data['ff_keep_counters'][0] = html_print_checkbox_switch( + 'ff_type', + 1, + $ff_type, + true, + $disabledBecauseInPolicy +); -$table_advanced->data[6][0] = __('FF interval'); -$table_advanced->data[6][1] = html_print_input_text( +$table_advanced->data['caption_ff_interval_timeout'][0] = __('FF interval'); +$table_advanced->data['caption_ff_interval_timeout'][1] = __('FF timeout'); +$table_advanced->data['ff_interval_timeout'][0] = html_print_input_text( 'module_ff_interval', $ff_interval, '', @@ -1066,14 +1165,11 @@ $table_advanced->data[6][1] = html_print_input_text( '', $classdisabledBecauseInPolicy ); -$table_advanced->colspan[6][1] = 2; - -$table_advanced->data[6][3] = __('FF timeout'); $module_type_name = modules_get_type_name($id_module_type); -$table_advanced->data[6][4] = ''; -if (preg_match('/async/', $module_type_name) || $edit) { - $table_advanced->data[6][4] .= ''.html_print_input_text( +$table_advanced->data['ff_interval_timeout'][1] = ''; +if ((bool) preg_match('/async/', $module_type_name) === true || $edit === true) { + $table_advanced->data['ff_interval_timeout'][1] .= ''.html_print_input_text( 'ff_timeout', $ff_timeout, '', @@ -1084,151 +1180,117 @@ if (preg_match('/async/', $module_type_name) || $edit) { ).''; } -if (!preg_match('/async/', $module_type_name) || $edit) { - $table_advanced->data[6][4] .= ''.__('Disabled').''; +if ((bool) preg_match('/async/', $module_type_name) === false || $edit === true) { + $table_advanced->data['ff_interval_timeout'][1] .= ''.__('Disabled').''; } -$table_advanced->colspan[6][4] = 3; -$table_advanced->data[8][0] = __('Quiet'); -$table_advanced->data[8][1] = html_print_checkbox('quiet_module', 1, $quiet_module, true, $disabledBecauseInPolicy); -$cps_array[-1] = __('Disabled'); -if ($cps_module > 0) { - $cps_array[$cps_module] = __('Enabled'); -} else { - $cps_inc = 0; - if ($id_agent_module) { - $cps_inc = enterprise_hook('service_modules_cps', [$id_agent_module]); - if ($cps_inc === ENTERPRISE_NOT_HOOK) { - $cps_inc = 0; - } - } - $cps_array[$cps_inc] = __('Enabled'); -} -$table_advanced->data[8][2] = ''; -$table_advanced->data[8][3] = __('Cascade Protection Services'); -$table_advanced->colspan[8][4] = 3; -$table_advanced->data[8][4] = html_print_select($cps_array, 'cps_module', $cps_module, '', '', 0, true, false, true, '', $disabledBecauseInPolicy); -$textarea_custom_style = ' class="min-height-0px"'; -$table_advanced->data[9][0] = __('Description'); -$table_advanced->colspan[9][1] = 6; -$table_advanced->data[9][1] = html_print_textarea( - 'description', - 3, - 65, - $description, - $disabledTextBecauseInPolicy.$textarea_custom_style, + + + +$table_advanced->data['title_4'] = html_print_subtitle_table(__('Data and their processing'), [], true); + +$table_advanced->data['caption_process_unit'][0] = __('Unit'); +$table_advanced->data['caption_process_unit'][1] = __('Post process'); +$table_advanced->data['process_unit'][0] = html_print_extended_select_for_unit( + 'unit', + $unit, + '', + 'none', + '0', + false, true, - $largeClassDisabledBecauseInPolicy + false, + false +); +$table_advanced->data['process_unit'][1] = html_print_extended_select_for_post_process( + 'post_process', + $post_process, + '', + '', + '0', + false, + true, + 'width:10em', + false, + $disabledBecauseInPolicy ); -$table_advanced->data[10][0] = __('Critical instructions'); -$table_advanced->data[10][1] = html_print_textarea('critical_instructions', 3, 65, $critical_instructions, $disabledTextBecauseInPolicy.$textarea_custom_style, true, $largeClassDisabledBecauseInPolicy); +$table_advanced->rowstyle['title_5'] = 'width: 100%;'; +$table_advanced->cellstyle['title_5'][0] = 'width: 100%;'; +$table_advanced->data['title_5'][0] = html_print_subtitle_table( + __('Notifications and alerts'), + [], + true +); +$table_advanced->data['title_5'][0] .= html_print_div( + [ + 'class' => 'section_table_title_line', + 'content' => '', + ], + true +); -$table_advanced->colspan[10][1] = 6; - -$table_advanced->data[11][0] = __('Warning instructions'); -$table_advanced->data[11][1] = html_print_textarea('warning_instructions', 3, 65, $warning_instructions, $disabledTextBecauseInPolicy.$textarea_custom_style, true, $largeClassDisabledBecauseInPolicy); -$table_advanced->colspan[11][1] = 6; - -$table_advanced->data[12][0] = __('Unknown instructions'); -$table_advanced->data[12][1] = html_print_textarea('unknown_instructions', 3, 65, $unknown_instructions, $disabledTextBecauseInPolicy.$textarea_custom_style, true, $largeClassDisabledBecauseInPolicy); -$table_advanced->colspan[12][1] = 6; - -if (isset($id_agente) && $moduletype == MODULE_DATA) { - $has_remote_conf = enterprise_hook('config_agents_has_remote_configuration', [$agent['id_agente']]); - if ($has_remote_conf) { - $table_advanced->data[13][0] = __('Cron from'); - $table_advanced->data[13][1] = html_print_extended_select_for_cron($hour_from, $minute_from, $mday_from, $month_from, $wday_from, true, $disabledBecauseInPolicy); - $table_advanced->colspan[13][1] = 6; - - $table_advanced->data[14][0] = __('Cron to'); - $table_advanced->data[14][1] = html_print_extended_select_for_cron($hour_to, $minute_to, $mday_to, $month_to, $wday_to, true, $disabledBecauseInPolicy, true); - $table_advanced->colspan[14][1] = 6; - } else { - $table_advanced->data[13][0] = __('Cron from'); - $table_advanced->data[13][1] = html_print_extended_select_for_cron($hour_from, $minute_from, $mday_from, $month_from, $wday_from, true, true); - $table_advanced->colspan[13][1] = 6; - - $table_advanced->data[14][0] = __('Cron to'); - $table_advanced->data[14][1] = html_print_extended_select_for_cron($hour_to, $minute_to, $mday_to, $month_to, $wday_to, true, true, true); - $table_advanced->colspan[14][1] = 6; - } +$table_advanced->data['caption_export_target'][0] = __('Export target'); +if ($__code_from === 'policies') { + $none_text = __('Not needed'); + $disabled_export = true; } else { - $table_advanced->data[13][0] = __('Cron from'); - $table_advanced->data[13][1] = html_print_extended_select_for_cron($hour_from, $minute_from, $mday_from, $month_from, $wday_from, true, $disabledBecauseInPolicy); - $table_advanced->colspan[13][1] = 6; - - $table_advanced->data[14][0] = __('Cron to'); - $table_advanced->data[14][1] = html_print_extended_select_for_cron($hour_to, $minute_to, $mday_to, $month_to, $wday_to, true, $disabledBecauseInPolicy, true); - $table_advanced->colspan[14][1] = 6; + $none_text = __('None'); + $disabled_export = false; } -$table_advanced->data[15][0] = __('Timeout'); -$table_advanced->data[15][1] = html_print_input_text('max_timeout', $max_timeout, '', 5, 10, true, $disabledBecauseInPolicy, false, '', $classdisabledBecauseInPolicy); -$table_advanced->data[15][2] = ''; -$table_advanced->data[15][3] = __('Retries'); -$table_advanced->data[15][4] = html_print_input_text('max_retries', $max_retries, '', 5, 10, true, $disabledBecauseInPolicy, false, '', $classdisabledBecauseInPolicy); -$table_advanced->colspan[15][4] = 3; - -if (check_acl($config['id_user'], 0, 'PM')) { - $table_advanced->data[16][0] = __('Category'); - $table_advanced->data[16][1] = html_print_select( - categories_get_all_categories('forselect'), - 'id_category', - $id_category, - '', - __('None'), - 0, - true, - false, - true, - '', - $disabledBecauseInPolicy - ); - $table_advanced->colspan[16][1] = 6; +$table_advanced->data['export_target'][0] = html_print_select_from_sql( + 'SELECT id, name FROM tserver_export ORDER BY name', + 'id_export', + $id_export, + '', + $none_text, + '0', + true, + false, + false, + $disabled_export +); +// Code comes from module_editor. +if ($__code_from === 'modules') { + $throw_unknown_events_check = modules_is_disable_type_event($id_agent_module, EVENTS_GOING_UNKNOWN); } else { - // Store in a hidden field if is not visible to avoid delete the value. - $table_advanced->data[15][4] .= html_print_input_hidden('id_category', $id_category, true); + global $__id_pol_mod; + + $throw_unknown_events_check = policy_module_is_disable_type_event($__id_pol_mod, EVENTS_GOING_UNKNOWN); } -if (!$in_policy) { - // Cannot select the current module to be itself parent. - $module_parent_filter = ($id_agent_module) ? ['tagente_modulo.id_agente_modulo' => "<>$id_agent_module"] : ''; - $table_advanced->data[17][0] = __('Module parent'); - $modules_can_be_parent = agents_get_modules( - $id_agente, - false, - $module_parent_filter - ); - // If the user cannot have access to parent module, only print the name. - if ($parent_module_id != 0 - && !in_array($parent_module_id, array_keys($modules_can_be_parent)) - ) { - $table_advanced->data[17][1] = db_get_value( - 'nombre', - 'tagente_modulo', - 'id_agente_modulo', - $parent_module_id - ); - } else { - $table_advanced->data[17][1] = html_print_select( - $modules_can_be_parent, - 'parent_module_id', - $parent_module_id, - '', - __('Not assigned'), - '0', - true - ); - } -} +$table_advanced->data['caption_discard_unknown'][0] = __('Discard unknown events'); +$table_advanced->data['discard_unknown'][0] = html_print_checkbox_switch( + 'throw_unknown_events', + 1, + $throw_unknown_events_check, + true, + $disabledBecauseInPolicy +); +$table_advanced->data['caption_quiet'][0] = __('Quiet'); +$table_advanced->data['quiet'][0] = html_print_checkbox_switch( + 'quiet_module', + 1, + $quiet_module, + true, + $disabledBecauseInPolicy +); + +$table_advanced->data['caption_cascade_protection'][0] = __('Cascade Protection Services'); +$table_advanced->data['cascade_protection'][0] = html_print_select($cps_array, 'cps_module', $cps_module, '', '', 0, true, false, true, '', $disabledBecauseInPolicy); + +$table_advanced->data['caption_max_timeout_retries'][0] = __('Timeout'); +$table_advanced->data['caption_max_timeout_retries'][1] = __('Retries'); +$table_advanced->data['max_timeout_retries'][0] = html_print_input_text('max_timeout', $max_timeout, '', 5, 10, true, $disabledBecauseInPolicy, false, '', $classdisabledBecauseInPolicy); +$table_advanced->data['max_timeout_retries'][1] = html_print_input_text('max_retries', $max_retries, '', 5, 10, true, $disabledBecauseInPolicy, false, '', $classdisabledBecauseInPolicy); // Advanced form part. $table_macros = new stdClass(); diff --git a/pandora_console/godmode/agentes/module_manager_editor_network.php b/pandora_console/godmode/agentes/module_manager_editor_network.php index 4a39db6d75..38596661dd 100644 --- a/pandora_console/godmode/agentes/module_manager_editor_network.php +++ b/pandora_console/godmode/agentes/module_manager_editor_network.php @@ -78,12 +78,19 @@ $extra_title = __('Network server module'); $data = []; $data[0] = __('Target IP'); +if ((int) $id_module_type !== 6 && $id_module_type !== 7) { + $data[1] = __('Port'); +} + +push_table_simple($data, 'caption_target_ip'); + +$data = []; // Show agent_for defect. -if ($page == 'enterprise/godmode/policies/policy_modules') { - if ($ip_target != 'auto' && $ip_target != '') { +if ($page === 'enterprise/godmode/policies/policy_modules') { + if (empty($ip_target) === false && $ip_target !== 'auto') { $custom_ip_target = $ip_target; $ip_target = 'custom'; - } else if ($ip_target == '') { + } else if (empty($ip_target) === true) { $ip_target = 'force_pri'; $custom_ip_target = ''; } else { @@ -95,7 +102,7 @@ if ($page == 'enterprise/godmode/policies/policy_modules') { $target_ip_values['force_pri'] = __('Force primary key'); $target_ip_values['custom'] = __('Custom'); - $data[1] = html_print_select( + $data[0] = html_print_select( $target_ip_values, 'ip_target', $ip_target, @@ -109,22 +116,18 @@ if ($page == 'enterprise/godmode/policies/policy_modules') { false, 'width:200px;' ); - $data[1] .= html_print_input_text('custom_ip_target', $custom_ip_target, '', 15, 60, true); + $data[0] .= html_print_input_text('custom_ip_target', $custom_ip_target, '', 15, 60, true); } else { - if ($ip_target == 'auto') { + if ($ip_target === 'auto') { $ip_target = agents_get_address($id_agente); } - $data[1] = html_print_input_text('ip_target', $ip_target, '', 15, 60, true); + $data[0] = html_print_input_text('ip_target', $ip_target, '', 15, 60, true); } // In ICMP modules, port is not configurable. -if ($id_module_type >= 6 && $id_module_type <= 7) { - $data[2] = ''; - $data[3] = ''; -} else { - $data[2] = __('Port'); - $data[3] = html_print_input_text( +if ($id_module_type !== 6 && $id_module_type !== 7) { + $data[1] = html_print_input_text( 'tcp_port', $tcp_port, '', @@ -136,6 +139,8 @@ if ($id_module_type >= 6 && $id_module_type <= 7) { '', $classdisabledBecauseInPolicy ); +} else { + $data[1] = ''; } push_table_simple($data, 'target_ip'); @@ -190,12 +195,13 @@ $snmp_versions['3'] = 'v. 3'; $data = []; $data[0] = __('SNMP community'); -$adopt = false; -if ($isFunctionPolicies !== ENTERPRISE_NOT_HOOK && isset($id_agent_module)) { +if ($isFunctionPolicies !== ENTERPRISE_NOT_HOOK && isset($id_agent_module) === true) { $adopt = policies_is_module_adopt($id_agent_module); +} else { + $adopt = false; } -if (!$adopt) { +if ($adopt === false) { $data[1] = html_print_input_text( 'snmp_community', $snmp_community, @@ -221,42 +227,22 @@ if (!$adopt) { } $data[2] = _('SNMP version'); - -if ($id_module_type >= 15 && $id_module_type <= 18) { - $data[3] = html_print_select( - $snmp_versions, - 'snmp_version', - $snmp_version, - '', - '', - '', - true, - false, - false, - '', - $disabledBecauseInPolicy, - false, - '', - $classdisabledBecauseInPolicy - ); -} else { - $data[3] = html_print_select( - $snmp_versions, - 'snmp_version', - 0, - '', - '', - '', - true, - false, - false, - '', - $disabledBecauseInPolicy, - false, - '', - $classdisabledBecauseInPolicy - ); -} +$data[3] = html_print_select( + $snmp_versions, + 'snmp_version', + ($id_module_type >= 15 && $id_module_type <= 18) ? $snmp_version : 0, + '', + '', + '', + true, + false, + false, + '', + $disabledBecauseInPolicy, + false, + '', + $classdisabledBecauseInPolicy +); if ($disabledBecauseInPolicy) { if ($id_module_type >= 15 && $id_module_type <= 18) { @@ -322,7 +308,12 @@ push_table_simple($data, 'snmp_2'); // Advanced stuff. $data = []; $data[0] = __('TCP send'); -$data[1] = html_print_textarea( +$data[1] = __('TCP receive'); + +push_table_simple($data, 'caption_tcp_send_receive'); + +$data = []; +$data[0] = html_print_textarea( 'tcp_send', 2, 65, @@ -331,11 +322,6 @@ $data[1] = html_print_textarea( true, $largeclassdisabledBecauseInPolicy ); -$table_simple->colspan['tcp_send'][1] = 3; - -push_table_simple($data, 'tcp_send'); - -$data[0] = __('TCP receive'); $data[1] = html_print_textarea( 'tcp_rcv', 2, @@ -345,9 +331,8 @@ $data[1] = html_print_textarea( true, $largeclassdisabledBecauseInPolicy ); -$table_simple->colspan['tcp_receive'][1] = 3; -push_table_simple($data, 'tcp_receive'); +push_table_simple($data, 'tcp_send_receive'); if ($id_module_type < 8 || $id_module_type > 11) { // NOT TCP. diff --git a/pandora_console/include/functions_html.php b/pandora_console/include/functions_html.php index 5bf22a21d8..9729a20845 100644 --- a/pandora_console/include/functions_html.php +++ b/pandora_console/include/functions_html.php @@ -6542,3 +6542,37 @@ function html_print_extended_select_for_downtime_cron( echo $returnString; } } + + +/** + * Prints a subtitle for a form or table. + * + * @param string $caption Caption of title. + * @param array $options Available options. + * - `id`: string + * - `style`: string + * - `class`: string. `section_table_title` by default. + * - `wrapper`: string. Must be a valid tag. + * - `wrapper_attributes`: string. Valid attributes for a wrapper. + * @param boolean $return If true, returns a string with formed subtitle. + * + * @return string. + */ +function html_print_subtitle_table(string $caption, array $options=[], bool $return=false) +{ + if (isset($options['wrapper']) === true) { + $startWrapper = '<'.$options['wrapper'].' '.($options['wrapper_attributes'] ?? '').'>'; + $endWrapper = ''; + $caption = $startWrapper.$caption.$endWrapper; + } + + return html_print_div( + [ + 'id' => ($options['id'] ?? ''), + 'class' => ($options['class'] ?? 'section_table_title'), + 'style' => ($options['style'] ?? ''), + 'content' => $caption, + ], + $return + ); +} \ No newline at end of file