From 4436d96717d2a8a1b26fd31f96487f6f40f4beaa Mon Sep 17 00:00:00 2001 From: Tatiana Llorente Date: Wed, 7 Aug 2019 12:09:34 +0200 Subject: [PATCH 01/81] Fixed scroll in other ip addres in agent view - #4463 --- pandora_console/operation/agentes/estado_generalagente.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandora_console/operation/agentes/estado_generalagente.php b/pandora_console/operation/agentes/estado_generalagente.php index 24aa44e098..3a17e5e49f 100755 --- a/pandora_console/operation/agentes/estado_generalagente.php +++ b/pandora_console/operation/agentes/estado_generalagente.php @@ -432,7 +432,7 @@ if (!empty($addresses)) { // $data_opcional = []; $data_opcional[] = ''.__('Other IP addresses').''; if (!empty($addresses)) { - $data_opcional[] = '
'.implode('
', $addresses).'
'; + $data_opcional[] = '
'.implode('
', $addresses).'
'; } } From 380ce879efbd6806c1d1bb4b9461ab9bb5d7c63e Mon Sep 17 00:00:00 2001 From: Tatiana Llorente Date: Wed, 2 Oct 2019 10:59:40 +0200 Subject: [PATCH 02/81] Added io_safe_output to custom graphs name - #4664 --- pandora_console/godmode/reporting/graphs.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandora_console/godmode/reporting/graphs.php b/pandora_console/godmode/reporting/graphs.php index cb52af5e04..233a8afee0 100644 --- a/pandora_console/godmode/reporting/graphs.php +++ b/pandora_console/godmode/reporting/graphs.php @@ -291,7 +291,7 @@ $table_aux = new stdClass(); $data[5] .= html_print_checkbox_extended('delete_multiple[]', $graph['id_graph'], false, false, '', 'class="check_delete" style="margin-left:2px;"', true); } - $data[0] = ''.ui_print_truncate_text($graph['name'], 70).''; + $data[0] = ''.ui_print_truncate_text(io_safe_output($graph['name']), 70).''; $data[1] = ui_print_truncate_text($graph['description'], 70); From 18679f90e5da43b3558fafa351fe3dab93cf947b Mon Sep 17 00:00:00 2001 From: Tatiana Llorente Date: Wed, 9 Oct 2019 16:24:37 +0200 Subject: [PATCH 03/81] Added token in visual styles to change the font size in items of reports - #4670 --- pandora_console/godmode/setup/setup_visuals.php | 8 +++++++- pandora_console/include/functions_config.php | 8 ++++++++ pandora_console/include/functions_reporting_html.php | 8 +++++--- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/pandora_console/godmode/setup/setup_visuals.php b/pandora_console/godmode/setup/setup_visuals.php index 0e7e41e7d6..fab43724b5 100755 --- a/pandora_console/godmode/setup/setup_visuals.php +++ b/pandora_console/godmode/setup/setup_visuals.php @@ -557,7 +557,7 @@ $row++; // For 5.1 Autohidden menu feature - $table_styles->data['autohidden'][0] = __('Autohidden menu'); + $table_styles->data['autohidden'][0] = __('Automatically hide submenu'); $table_styles->data['autohidden'][1] = html_print_checkbox_switch( 'autohidden_menu', 1, @@ -1032,6 +1032,12 @@ $row++; ); $row++; + + $table_other->data[$row][0] = __('Font size for items reports'); + $table_other->data[$row][1] = ""; + + $row++; + // ---------------------------------------------------------------------- $dirItems = scandir($config['homedir'].'/images/custom_logo'); foreach ($dirItems as $entryDir) { diff --git a/pandora_console/include/functions_config.php b/pandora_console/include/functions_config.php index 6563a6def2..f566e2a89c 100644 --- a/pandora_console/include/functions_config.php +++ b/pandora_console/include/functions_config.php @@ -1269,6 +1269,10 @@ function config_update_config() } // Juanma (06/05/2014) New feature: Custom front page for reports. + if (!config_update_value('font_size_item_report', get_parameter('font_size_item_report', 2))) { + $error_update[] = __('Font size for items reports'); + } + if (!config_update_value('custom_report_front', get_parameter('custom_report_front'))) { $error_update[] = __('Custom report front'); } @@ -2793,6 +2797,10 @@ function config_process_config() config_update_value('custom_report_front', 0); } + if (!isset($config['font_size_item_report'])) { + config_update_value('font_size_item_report', 2); + } + if (!isset($config['custom_report_front_font'])) { config_update_value('custom_report_front_font', 'FreeSans.ttf'); } diff --git a/pandora_console/include/functions_reporting_html.php b/pandora_console/include/functions_reporting_html.php index cf1fa60e70..0ac6569c40 100644 --- a/pandora_console/include/functions_reporting_html.php +++ b/pandora_console/include/functions_reporting_html.php @@ -467,7 +467,7 @@ function reporting_html_SLA($table, $item, $mini, $pdf=0) if ($mini) { $font_size = '1.5'; } else { - $font_size = '3'; + $font_size = $config['font_size_item_report']; } $metaconsole_on = is_metaconsole(); @@ -2513,7 +2513,7 @@ function reporting_html_monitor_report($table, $item, $mini, $pdf=0) if ($mini) { $font_size = '1.5'; } else { - $font_size = '3'; + $font_size = $config['font_size_item_report']; } $table->colspan['module']['cell'] = 3; @@ -2780,10 +2780,12 @@ function reporting_html_min_value(&$table, $item, $mini) function reporting_html_value(&$table, $item, $mini, $only_value=false, $check_empty=false) { + global $config; + if ($mini) { $font_size = '1.5'; } else { - $font_size = '3'; + $font_size = $config['font_size_item_report']; } if (isset($item['visual_format']) && $item['visual_format'] != 0 From 8af72c1c9d5fb0f46592f9b55b9fff1ea49d2835 Mon Sep 17 00:00:00 2001 From: Daniel Barbero Date: Wed, 9 Oct 2019 17:26:06 +0200 Subject: [PATCH 04/81] add Remote CMD --- pandora_console/extras/mr/33.sql | 9 + .../pandoradb_migrate_6.0_to_7.0.mysql.sql | 8 +- .../general/subselect_data_module.php | 3 +- .../godmode/agentes/configurar_agente.php | 21 +- .../godmode/agentes/module_manager_editor.php | 311 ++++++++++++------ .../agentes/module_manager_editor_common.php | 81 +++-- .../agentes/module_manager_editor_network.php | 266 +++++++++++---- .../include/class/CredentialStore.class.php | 2 + .../operation/agentes/status_monitor.php | 9 +- pandora_console/pandoradb_data.sql | 12 +- 10 files changed, 533 insertions(+), 189 deletions(-) create mode 100644 pandora_console/extras/mr/33.sql diff --git a/pandora_console/extras/mr/33.sql b/pandora_console/extras/mr/33.sql new file mode 100644 index 0000000000..885132f68f --- /dev/null +++ b/pandora_console/extras/mr/33.sql @@ -0,0 +1,9 @@ +START TRANSACTION; + +INSERT INTO `ttipo_modulo` VALUES +(34,'remote_cmd', 10, 'Remote CMD command, numeric data', 'mod_remote_cmd.png'), +(35,'remote_cmd_proc', 10, 'Remote CMD command, boolean data', 'mod_remote_cmd_proc.png'), +(36,'remote_cmd_string', 10, 'Remote CMD command, alphanumeric data', 'mod_remote_cmd_string.png'), +(37,'remote_cmd_inc', 10, 'Remote CMD command, incremental data', 'mod_remote_cmd_inc.png'); + +COMMIT; \ No newline at end of file diff --git a/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql b/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql index 6476e79e2b..30cff5136a 100644 --- a/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql +++ b/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql @@ -1654,7 +1654,12 @@ INSERT INTO tmodule VALUES (8, 'Wux module'); -- Table `ttipo_modulo` -- --------------------------------------------------------------------- -INSERT INTO ttipo_modulo VALUES (25,'web_analysis', 8, 'Web analysis data', 'module-wux.png'); +INSERT INTO `ttipo_modulo` VALUES +(25,'web_analysis', 8, 'Web analysis data', 'module-wux.png'), +(34,'remote_cmd', 10, 'Remote CMD command, numeric data', 'mod_remote_cmd.png'), +(35,'remote_cmd_proc', 10, 'Remote CMD command, boolean data', 'mod_remote_cmd_proc.png'), +(36,'remote_cmd_string', 10, 'Remote CMD command, alphanumeric data', 'mod_remote_cmd_string.png'), +(37,'remote_cmd_inc', 10, 'Remote CMD command, incremental data', 'mod_remote_cmd_inc.png'); -- --------------------------------------------------------------------- -- Table `tdashboard` @@ -2293,3 +2298,4 @@ CREATE TABLE `tdeployment_hosts` ( FOREIGN KEY (`target_agent_version_id`) REFERENCES `tagent_repository`(`id`) ON UPDATE CASCADE ON DELETE SET NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8; + diff --git a/pandora_console/general/subselect_data_module.php b/pandora_console/general/subselect_data_module.php index 416897ea15..fca56c692c 100644 --- a/pandora_console/general/subselect_data_module.php +++ b/pandora_console/general/subselect_data_module.php @@ -13,7 +13,8 @@ switch ($_GET['module']) { $sql = sprintf( 'SELECT id_tipo, descripcion FROM ttipo_modulo - WHERE categoria between 3 and 5 ' + WHERE categoria between 3 and 5 + OR categoria = 10 ' ); break; diff --git a/pandora_console/godmode/agentes/configurar_agente.php b/pandora_console/godmode/agentes/configurar_agente.php index 55116f940a..f6cf27a69e 100644 --- a/pandora_console/godmode/agentes/configurar_agente.php +++ b/pandora_console/godmode/agentes/configurar_agente.php @@ -1330,7 +1330,7 @@ if ($update_module || $create_module) { // Change double quotes by single. $snmp_oid = preg_replace('/"/', ''', $snmp_oid); - if (empty($snmp_oid)) { + if (empty($snmp_oid) === true) { // The user did not set any OID manually but did a SNMP walk. $snmp_oid = (string) get_parameter('select_snmp_oid'); } @@ -1339,18 +1339,31 @@ if ($update_module || $create_module) { // New support for snmp v3. $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_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_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) { + hd($_POST); + $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 { $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_pass = io_input_password( + (string) get_parameter('plugin_pass') + ); } $plugin_parameter = (string) get_parameter('plugin_parameter'); diff --git a/pandora_console/godmode/agentes/module_manager_editor.php b/pandora_console/godmode/agentes/module_manager_editor.php index 13c313892a..bf51f2b0fe 100644 --- a/pandora_console/godmode/agentes/module_manager_editor.php +++ b/pandora_console/godmode/agentes/module_manager_editor.php @@ -1,16 +1,32 @@ $element) { - $component[$index] = html_entity_decode($element, ENT_QUOTES, 'UTF-8'); + $component[$index] = html_entity_decode( + $element, + ENT_QUOTES, + 'UTF-8' + ); } - $typeName = local_components_parse_module_extract_value('module_type', $component['data']); + $typeName = local_components_parse_module_extract_value( + 'module_type', + $component['data'] + ); - switch ($config['dbtype']) { - case 'mysql': - $component['type'] = db_get_value_sql( - ' - SELECT id_tipo - FROM ttipo_modulo - WHERE nombre LIKE "'.$typeName.'"' - ); - break; + $component['type'] = db_get_value_sql( + ' + SELECT id_tipo + FROM ttipo_modulo + WHERE nombre LIKE "'.$typeName.'"' + ); - case 'postgresql': - case 'oracle': - $component['type'] = db_get_value_sql( - ' - SELECT id_tipo - FROM ttipo_modulo - WHERE nombre LIKE \''.$typeName.'\'' - ); - break; - } - - $component['throw_unknown_events'] = !local_components_is_disable_type_event($id_component, EVENTS_GOING_UNKNOWN); + $component['throw_unknown_events'] = !local_components_is_disable_type_event( + $id_component, + EVENTS_GOING_UNKNOWN + ); echo io_json_mb_encode($component); return; @@ -136,7 +157,9 @@ if (is_ajax()) { $snmp3_auth_method = get_parameter('snmp3_auth_method'); $snmp3_auth_pass = io_safe_output(get_parameter('snmp3_auth_pass')); $snmp3_privacy_method = get_parameter('snmp3_privacy_method'); - $snmp3_privacy_pass = io_safe_output(get_parameter('snmp3_privacy_pass')); + $snmp3_privacy_pass = io_safe_output( + get_parameter('snmp3_privacy_pass') + ); $snmp_port = get_parameter('snmp_port'); $snmpwalk = get_snmpwalk( @@ -177,7 +200,7 @@ require_once 'include/functions_exportserver.php'; require_once $config['homedir'].'/include/functions_modules.php'; require_once $config['homedir'].'/include/functions_agents.php'; -// Reading a module +// Reading a module. if ($id_agent_module) { $module = modules_get_agentmodule($id_agent_module); $moduletype = $module['id_modulo']; @@ -202,19 +225,25 @@ if ($id_agent_module) { $snmp_community = $module['snmp_community']; $snmp_oid = $module['snmp_oid']; - // New support for snmp v3 + // New support for snmp v3. $snmp_version = $module['tcp_send']; $snmp3_auth_user = $module['plugin_user']; $snmp3_auth_pass = io_output_password($module['plugin_pass']); - // Auth method could be MD5 or SHA + // Auth method could be MD5 or SHA. $snmp3_auth_method = $module['plugin_parameter']; - // Privacy method could be DES or AES + // Privacy method could be DES or AES. $snmp3_privacy_method = $module['custom_string_1']; $snmp3_privacy_pass = io_output_password($module['custom_string_2']); - // Security level Could be noAuthNoPriv | authNoPriv | authPriv + // For Remote cmd fields are reused: + // tcp_send, custom_string_1, custom_string_2. + $command_text = $module['tcp_send']; + $command_credential_identifier = $module['custom_string_1']; + $command_os = $module['custom_string_2']; + + // Security level Could be noAuthNoPriv | authNoPriv | authPriv. $snmp3_security_level = $module['custom_string_3']; $ip_target = $module['ip_target']; @@ -265,39 +294,39 @@ if ($id_agent_module) { $id_category = $module['id_category']; $cron_interval = explode(' ', $module['cron_interval']); - if (isset($cron_interval[4])) { + if (isset($cron_interval[4]) === true) { $minute_from = $cron_interval[0]; $minute = explode('-', $minute_from); $minute_from = $minute[0]; - if (isset($minute[1])) { + if (isset($minute[1]) === true) { $minute_to = $minute[1]; } $hour_from = $cron_interval[1]; $h = explode('-', $hour_from); $hour_from = $h[0]; - if (isset($h[1])) { + if (isset($h[1]) === true) { $hour_to = $h[1]; } $mday_from = $cron_interval[2]; $md = explode('-', $mday_from); $mday_from = $md[0]; - if (isset($md[1])) { + if (isset($md[1]) === true) { $mday_to = $md[1]; } $month_from = $cron_interval[3]; $m = explode('-', $month_from); $month_from = $m[0]; - if (isset($m[1])) { + if (isset($m[1]) === true) { $month_to = $m[1]; } $wday_from = $cron_interval[4]; $wd = explode('-', $wday_from); $wday_from = $wd[0]; - if (isset($wd[1])) { + if (isset($wd[1]) === true) { $wday_to = $wd[1]; } } else { @@ -315,14 +344,17 @@ if ($id_agent_module) { } $module_macros = null; - if (isset($module['module_macros'])) { - $module_macros = json_decode(base64_decode($module['module_macros']), true); + if (isset($module['module_macros']) === true) { + $module_macros = json_decode( + base64_decode($module['module_macros']), + true + ); } } else { - if (!isset($moduletype)) { + if (isset($moduletype) === false) { $moduletype = (string) get_parameter('moduletype'); - // Clean up specific network modules fields + // Clean up specific network modules fields. $name = ''; $description = ''; $id_module_group = 1; @@ -374,7 +406,7 @@ if ($id_agent_module) { $str_critical = ''; $ff_event = 0; - // New support for snmp v3 + // New support for snmp v3. $snmp_version = 1; $snmp3_auth_user = ''; $snmp3_auth_pass = ''; @@ -383,6 +415,11 @@ if ($id_agent_module) { $snmp3_privacy_pass = ''; $snmp3_security_level = ''; + // For Remote CMD. + $command_text = ''; + $command_credential_identifier = ''; + $command_os = ''; + $critical_instructions = ''; $warning_instructions = ''; $unknown_instructions = ''; @@ -418,7 +455,9 @@ if ($id_agent_module) { } } -$is_function_policies = enterprise_include_once('include/functions_policies.php'); +$is_function_policies = enterprise_include_once( + 'include/functions_policies.php' +); if ($is_function_policies !== ENTERPRISE_NOT_HOOK) { $relink_policy = get_parameter('relink_policy', 0); @@ -428,19 +467,32 @@ if ($is_function_policies !== ENTERPRISE_NOT_HOOK) { $policy_info = policies_info_module_policy($id_agent_module); $policy_id = $policy_info['id_policy']; - if ($relink_policy && policies_get_policy_queue_status($policy_id) == STATUS_IN_QUEUE_APPLYING) { - ui_print_error_message(__('This policy is applying and cannot be modified')); + if ($relink_policy + && policies_get_policy_queue_status($policy_id) == STATUS_IN_QUEUE_APPLYING + ) { + ui_print_error_message( + __('This policy is applying and cannot be modified') + ); } else { $result = policies_relink_module($id_agent_module); - ui_print_result_message($result, __('Module will be linked in the next application')); + ui_print_result_message( + $result, + __('Module will be linked in the next application') + ); - db_pandora_audit('Agent management', 'Re-link module '.$id_agent_module); + db_pandora_audit( + 'Agent management', + 'Re-link module '.$id_agent_module + ); } } if ($unlink_policy) { $result = policies_unlink_module($id_agent_module); - ui_print_result_message($result, __('Module will be unlinked in the next application')); + ui_print_result_message( + $result, + __('Module will be unlinked in the next application') + ); db_pandora_audit('Agent management', 'Unlink module '.$id_agent_module); } @@ -452,7 +504,7 @@ $remote_conf = false; if ($__code_from !== 'policies') { // Only check in the module editor. - // Check ACL tags + // Check ACL tags. $tag_acl = true; // If edit a existing module. @@ -479,12 +531,12 @@ switch ($moduletype) { $remote_conf = false; if (enterprise_installed()) { enterprise_include_once('include/functions_config_agents.php'); - $remote_conf = enterprise_hook('config_agents_has_remote_configuration', [$id_agente]); + $remote_conf = enterprise_hook( + 'config_agents_has_remote_configuration', + [$id_agente] + ); } - /* - Categories is an array containing the allowed module types - (generic_data, generic_string, etc) from ttipo_modulo (field categoria) */ $categories = [ 0, 1, @@ -503,12 +555,16 @@ switch ($moduletype) { 'config_agents_get_module_from_conf', [ $id_agente, - io_safe_output(modules_get_agentmodule_name($id_agent_module)), + io_safe_output( + modules_get_agentmodule_name($id_agent_module) + ), ] ); } - enterprise_include('godmode/agentes/module_manager_editor_data.php'); + enterprise_include( + 'godmode/agentes/module_manager_editor_data.php' + ); } break; @@ -519,6 +575,7 @@ switch ($moduletype) { 3, 4, 5, + 10, ]; include 'module_manager_editor_common.php'; include 'module_manager_editor_network.php'; @@ -562,9 +619,12 @@ switch ($moduletype) { include 'module_manager_editor_wmi.php'; break; - // WARNING: type 7 is reserved on enterprise + // WARNING: type 7 is reserved on enterprise. default: - if (enterprise_include('godmode/agentes/module_manager_editor.php') === ENTERPRISE_NOT_HOOK) { + if (enterprise_include( + 'godmode/agentes/module_manager_editor.php' + ) === ENTERPRISE_NOT_HOOK + ) { ui_print_error_message(sprintf(__('Invalid module type'))); return; } @@ -580,7 +640,7 @@ if ($config['enterprise_installed'] && $id_agent_module) { echo ''; -// TODO: Change to the ui_print_error system +// TODO: Change to the ui_print_error system. echo '
'; ui_toggle( @@ -602,12 +662,18 @@ ui_toggle( if ($moduletype != 13) { ui_toggle( - html_print_table($table_new_relations, true).html_print_table($table_relations, true), + html_print_table( + $table_new_relations, + true + ).html_print_table( + $table_relations, + true + ), __('Module relations') ); } -// Submit +// Submit. echo '
'; if ($id_agent_module) { html_print_submit_button( @@ -659,38 +725,84 @@ ui_require_javascript_file('pandora_modules'); diff --git a/pandora_console/godmode/agentes/module_manager_editor_common.php b/pandora_console/godmode/agentes/module_manager_editor_common.php index 5a4653fc29..08f930c95f 100644 --- a/pandora_console/godmode/agentes/module_manager_editor_common.php +++ b/pandora_console/godmode/agentes/module_manager_editor_common.php @@ -132,7 +132,7 @@ function add_component_selection($id_network_component_type) require_once 'include/functions_network_components.php'; enterprise_include_once('include/functions_policies.php'); -// If code comes from policies disable export select +// If code comes from policies disable export select. global $__code_from; $disabledBecauseInPolicy = false; @@ -209,8 +209,7 @@ $table_simple->data[0][1] = html_print_input_text_extended( $largeClassDisabledBecauseInPolicy, true ); -// $table_simple->data[0][1] = html_print_input_text ('name', -// io_safe_output($name), '', 45, 100, true, $disabledBecauseInPolicy); + if (!empty($id_agent_module) && isset($id_agente)) { $table_simple->data[0][1] .= ' '.__('ID').'  '.$id_agent_module.' '; @@ -237,7 +236,13 @@ if ($policy_link != 0) { } $table_simple->data[0][2] = __('Disabled'); -$table_simple->data[0][2] .= html_print_checkbox('disabled', 1, $disabled, true, $disabled_enable); +$table_simple->data[0][2] .= html_print_checkbox( + 'disabled', + 1, + $disabled, + true, + $disabled_enable +); $table_simple->data[0][3] = __('Module group'); $table_simple->data[0][3] .= html_print_select_from_sql( 'SELECT id_mg, name FROM tmodule_group ORDER BY name', @@ -260,12 +265,18 @@ if ((isset($id_agent_module) && $id_agent_module) || $id_policy_module != 0) { $in_policy = strstr($page, 'policy_modules'); 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"] : ''; + // Cannot select the current module to be itself parent. + $module_parent_filter = ($id_agent_module) ? ['tagente_modulo.id_agente_modulo' => "<>$id_agent_module"] : ''; $table_simple->data[1][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))) { + $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_simple->data[1][1] = db_get_value( 'nombre', 'tagente_modulo', @@ -305,7 +316,11 @@ if (!$edit) { } $table_simple->data[2][1] = ''.modules_get_moduletype_description($id_module_type).' ('.$type_names_hash[$id_module_type].')'; - $table_simple->data[2][1] .= html_print_input_hidden('type_names', base64_encode(io_json_mb_encode($type_names_hash)), true); + $table_simple->data[2][1] .= html_print_input_hidden( + 'type_names', + base64_encode(io_json_mb_encode($type_names_hash)), + true + ); } else { if (isset($id_module_type)) { $idModuleType = $id_module_type; @@ -313,12 +328,13 @@ if (!$edit) { $idModuleType = ''; } - // Removed web analysis and log4x from select + // Removed web analysis and log4x from select. $sql = sprintf( - 'SELECT id_tipo, descripcion, nombre + 'SELECT id_tipo, descripcion, nombre, categoria FROM ttipo_modulo - WHERE categoria IN (%s) AND id_tipo NOT IN (24, 25) - ORDER BY descripcion', + WHERE categoria IN (%s) + AND id_tipo NOT IN (24, 25) + ORDER BY id_tipo ASC', implode(',', $categories) ); @@ -326,7 +342,9 @@ if (!$edit) { $type_names_hash = []; $type_description_hash = []; - if (isset($type_names) && is_array($type_names)) { + if (isset($type_names) === true + && is_array($type_names) === true + ) { foreach ($type_names as $tn) { $type_names_hash[$tn['id_tipo']] = $tn['nombre']; $type_description_hash[$tn['id_tipo']] = $tn['descripcion']; @@ -342,7 +360,7 @@ if (!$edit) { 0, true, false, - true, + false, '', false, false, @@ -350,8 +368,12 @@ if (!$edit) { 100 ); - // Store the relation between id and name of the types on a hidden field - $table_simple->data[2][1] .= html_print_input_hidden('type_names', base64_encode(io_json_mb_encode($type_names_hash)), true); + // Store the relation between id and name of the types on a hidden field. + $table_simple->data[2][1] .= html_print_input_hidden( + 'type_names', + base64_encode(io_json_mb_encode($type_names_hash)), + true + ); } if ($edit_module) { @@ -380,15 +402,32 @@ if ($edit_module) { $help_header = 'webserver_module_tab'; } - $table_simple->data[2][0] = __('Type').' '.ui_print_help_icon($help_header, true); + $table_simple->data[2][0] = __('Type').' '; + $table_simple->data[2][0] .= ui_print_help_icon($help_header, true); } if ($disabledBecauseInPolicy) { - $table_simple->data[2][3] .= html_print_input_hidden('id_module_group', $id_module_group, true); + $table_simple->data[2][3] .= html_print_input_hidden( + 'id_module_group', + $id_module_group, + true + ); } $table_simple->data[3][0] = __('Dynamic Threshold Interval'); -$table_simple->data[3][1] = html_print_extended_select_for_time('dynamic_interval', $dynamic_interval, '', 'None', '0', 10, true, 'width:150px', false, $classdisabledBecauseInPolicy, $disabledBecauseInPolicy); +$table_simple->data[3][1] = html_print_extended_select_for_time( + 'dynamic_interval', + $dynamic_interval, + '', + 'None', + '0', + 10, + true, + 'width:150px', + false, + $classdisabledBecauseInPolicy, + $disabledBecauseInPolicy +); $table_simple->data[3][1] .= ''.html_print_image('images/cog.png', true, ['title' => __('Advanced options Dynamic Threshold')]).''; if ($in_policy) { $table_simple->cellclass[2][2] = 'hide_dinamic'; diff --git a/pandora_console/godmode/agentes/module_manager_editor_network.php b/pandora_console/godmode/agentes/module_manager_editor_network.php index c0a6181a8e..76bbf50c47 100644 --- a/pandora_console/godmode/agentes/module_manager_editor_network.php +++ b/pandora_console/godmode/agentes/module_manager_editor_network.php @@ -1,30 +1,50 @@ "; -// This line does not run with the dinamic loader editor in policies. -// ui_require_javascript_file ('pandora_snmp_browser'); -// WARNING REPEAT input hidden errors in console -// Save some variables for javascript functions -// html_print_input_hidden ('ajax_url', ui_get_full_url("ajax.php"), false); -// html_print_input_hidden ('search_matches_translation', __("Search matches"), false); -// Define a custom action to save the OID selected in the SNMP browser to the form -html_print_input_hidden('custom_action', urlencode(base64_encode(' ')), false); +echo ""; + +// Define a custom action to save the OID selected +// in the SNMP browser to the form. +html_print_input_hidden( + 'custom_action', + urlencode( + base64_encode( + ' ' + ) + ), + false +); $isFunctionPolicies = enterprise_include_once('include/functions_policies.php'); @@ -50,17 +70,15 @@ if (strstr($page, 'policy_modules') === false) { define('ID_NETWORK_COMPONENT_TYPE', 2); if (empty($update_module_id)) { - // Function in module_manager_editor_common.php + // Function in module_manager_editor_common.php. add_component_selection(ID_NETWORK_COMPONENT_TYPE); -} else { - // TODO: Print network component if available } $extra_title = __('Network server module'); $data = []; $data[0] = __('Target IP'); -// show agent_for defect; +// Show agent_for defect. if ($page == 'enterprise/godmode/policies/policy_modules') { if ($ip_target != 'auto' && $ip_target != '') { $custom_ip_target = $ip_target; @@ -100,7 +118,7 @@ if ($page == 'enterprise/godmode/policies/policy_modules') { $data[1] = html_print_input_text('ip_target', $ip_target, '', 15, 60, true); } -// In ICMP modules, port is not configurable +// In ICMP modules, port is not configurable. if ($id_module_type >= 6 && $id_module_type <= 7) { $data[2] = ''; $data[3] = ''; @@ -148,7 +166,15 @@ if (!$adopt) { $classdisabledBecauseInPolicy ); } else { - $data[1] = html_print_input_text('snmp_community', $snmp_community, '', 15, 60, true, false); + $data[1] = html_print_input_text( + 'snmp_community', + $snmp_community, + '', + 15, + 60, + true, + false + ); } $data[2] = _('SNMP version'); @@ -213,8 +239,27 @@ $data[1] .= html_print_input_text( $classdisabledBecauseInPolicy ); $data[1] .= ''; $data[1] .= ''; $data[1] .= html_print_button( @@ -231,42 +276,50 @@ $table_simple->colspan['snmp_2'][1] = 3; push_table_simple($data, 'snmp_2'); -// Advanced stuff +// Advanced stuff. $data = []; $data[0] = __('TCP send'); -$data[1] = html_print_textarea('tcp_send', 2, 65, $tcp_send, $disabledTextBecauseInPolicy, true, $largeclassdisabledBecauseInPolicy); +$data[1] = html_print_textarea( + 'tcp_send', + 2, + 65, + $tcp_send, + $disabledTextBecauseInPolicy, + 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, 65, $tcp_rcv, $disabledTextBecauseInPolicy, true, $largeclassdisabledBecauseInPolicy); +$data[1] = html_print_textarea( + 'tcp_rcv', + 2, + 65, + $tcp_rcv, + $disabledTextBecauseInPolicy, + true, + $largeclassdisabledBecauseInPolicy +); $table_simple->colspan['tcp_receive'][1] = 3; push_table_simple($data, 'tcp_receive'); if ($id_module_type < 8 || $id_module_type > 11) { - // NOT TCP + // NOT TCP. $table_simple->rowstyle['tcp_send'] = 'display: none;'; $table_simple->rowstyle['tcp_receive'] = 'display: none;'; } if ($id_module_type < 15 || $id_module_type > 18) { - // NOT SNMP + // NOT SNMP. $table_simple->rowstyle['snmp_1'] = 'display: none'; $table_simple->rowstyle['snmp_2'] = 'display: none'; } -// For a policy -if (!isset($id_agent_module)) { - $snmp3_auth_user = ''; - $snmp3_auth_pass = ''; - $snmp_version = 1; - $snmp3_privacy_method = ''; - $snmp3_privacy_pass = ''; - $snmp3_auth_method = ''; - $snmp3_security_level = ''; -} else if ($id_agent_module === false) { +// For a policy. +if (isset($id_agent_module) === false || $id_agent_module === false) { $snmp3_auth_user = ''; $snmp3_auth_pass = ''; $snmp_version = 1; @@ -274,6 +327,9 @@ if (!isset($id_agent_module)) { $snmp3_privacy_pass = ''; $snmp3_auth_method = ''; $snmp3_security_level = ''; + $command_text = ''; + $command_os = 'inherited'; + $command_credential_identifier = ''; } $data = []; @@ -333,7 +389,22 @@ push_table_simple($data, 'field_snmpv3_row2'); $data = []; $data[0] = __('Auth method'); -$data[1] = html_print_select(['MD5' => __('MD5'), 'SHA' => __('SHA')], 'snmp3_auth_method', $snmp3_auth_method, '', '', '', true, false, false, '', $disabledBecauseInPolicy); +$data[1] = html_print_select( + [ + 'MD5' => __('MD5'), + 'SHA' => __('SHA'), + ], + 'snmp3_auth_method', + $snmp3_auth_method, + '', + '', + '', + true, + false, + false, + '', + $disabledBecauseInPolicy +); $data[2] = __('Security level'); $data[3] = html_print_select( [ @@ -358,13 +429,84 @@ if ($snmp_version != 3) { push_table_simple($data, 'field_snmpv3_row3'); +$data = []; +$data[0] = __('Command'); +$data[1] = html_print_input_text_extended( + 'command_text', + $command_text, + 'command_text', + '', + 100, + 10000, + $disabledBecauseInPolicy, + '', + $largeClassDisabledBecauseInPolicy, + true +); +$table_simple->colspan['row-cmd-row-1'][1] = 3; +push_table_simple($data, 'row-cmd-row-1'); + +require_once $config['homedir'].'/include/class/CredentialStore.class.php'; +$array_credential_identifier = CredentialStore::getKeys(); + +$data[0] = __('Credential identifier'); +$data[1] = html_print_select( + $array_credential_identifier, + 'command_credential_identifier', + $command_credential_identifier, + '', + __('None'), + '', + true, + false, + false, + '', + $disabledBecauseInPolicy +); + +$array_os = [ + 'inherited' => __('Inherited'), + 'linux' => __('Linux'), + 'windows' => __('Windows'), +]; + +$data[2] = __('Target OS'); +$data[3] = html_print_select( + $array_os, + 'command_os', + $command_os, + '', + '', + '', + true, + false, + false, + '', + $disabledBecauseInPolicy +); + +push_table_simple($data, 'row-cmd-row-2'); + +if ($id_module_type !== 34 + && $id_module_type !== 35 + && $id_module_type !== 36 + && $id_module_type !== 37 +) { + $table_simple->rowstyle['row-cmd-row-1'] = 'display: none;'; + $table_simple->rowstyle['row-cmd-row-2'] = 'display: none;'; +} + snmp_browser_print_container(false, '100%', '60%', 'none'); ?> diff --git a/pandora_console/godmode/modules/manage_network_components_form.php b/pandora_console/godmode/modules/manage_network_components_form.php index fd922046d1..114be6a969 100644 --- a/pandora_console/godmode/modules/manage_network_components_form.php +++ b/pandora_console/godmode/modules/manage_network_components_form.php @@ -1,17 +1,32 @@ $id_agentmodule]); + $data_module = db_get_row_filter( + 'tagente_modulo', + ['id_agente_modulo' => $id_agentmodule] + ); $name = $data_module['nombre']; $description = $data_module['descripcion']; @@ -139,16 +160,25 @@ if (isset($id)) { $each_ff = $component['each_ff']; if ($type >= 15 && $type <= 18) { - // New support for snmp v3 + // New support for snmp v3. $snmp_version = $component['tcp_send']; $snmp3_auth_user = $component['plugin_user']; $snmp3_auth_pass = io_output_password($component['plugin_pass']); $snmp3_auth_method = $component['plugin_parameter']; $snmp3_privacy_method = $component['custom_string_1']; - $snmp3_privacy_pass = io_output_password($component['custom_string_2']); + $snmp3_privacy_pass = io_output_password( + $component['custom_string_2'] + ); $snmp3_security_level = $component['custom_string_3']; + } else if ($type >= 34 && $type <= 37) { + $command_text = $component['tcp_send']; + $command_credential_identifier = $component['custom_string_1']; + $command_os = $component['custom_string_2']; } - } else if (isset($new_component) && $new_component && !$create_network_from_snmp_browser) { + } else if (isset($new_component) + && $new_component + && !$create_network_from_snmp_browser + ) { $name = ''; $snmp_oid = ''; $description = ''; @@ -204,21 +234,13 @@ if (isset($id)) { $snmp3_privacy_pass = ''; $snmp3_auth_method = ''; $snmp3_security_level = ''; + + $command_text = ''; + $command_os = 'inherited'; + $command_credential_identifier = ''; } } -if ($create_network_from_snmp_browser) { -} - -/* - * $id_component_type has these values: - * 6 - Module WMI - * 4 - Plugin component - * 2 - network component - * - * You can see this values in file godmode/modules/manage_network_components.php - * in the last lines (in the call function "html_print_select"). - */ $table = new stdClass(); if ($id_component_type == 6) { @@ -242,6 +264,7 @@ if ($id_component_type == 6) { 3, 4, 5, + 10, ]; include $config['homedir'].'/godmode/modules/manage_network_components_form_common.php'; include $config['homedir'].'/godmode/modules/manage_network_components_form_network.php'; @@ -253,7 +276,7 @@ echo ''; $table->width = '100%'; $table->class = 'databox filters'; -// $table came from manage_network_components_form_common.php + if (defined('METACONSOLE')) { if ($id) { $table->head[0] = __('Update Network Component'); @@ -295,61 +318,78 @@ ui_require_javascript_file('pandora_modules'); function type_change () { // type 1-4 - Generic_xxxxxx if ((document.component.type.value > 0) && (document.component.type.value < 5)) { - - $("input[name=snmp_community]").css({backgroundColor: '#ddd !important'}); + $("input[name=snmp_community]") + .css({backgroundColor: '#ddd '}); $("input[name=snmp_community]").attr("disabled", true); - - $("input[name=tcp_rcv]").css({backgroundColor: '#ddd !important'}); + + $("input[name=tcp_rcv]").css({backgroundColor: '#ddd '}); $("input[name=tcp_rcv]").attr("disabled", true); - + - $("input[name=snmp_oid]").css({backgroundColor: '#ddd !important'}); + $("input[name=snmp_oid]") + .css({backgroundColor: '#ddd '}); $("input[name=snmp_oid]").attr("disabled", true); - - $("input[name=tcp_send]").css({backgroundColor: '#ddd !important'}); + + $("input[name=tcp_send]") + .css({backgroundColor: '#ddd '}); $("input[name=tcp_send]").attr("disabled", true); - - $("input[name=tcp_port]").css({backgroundColor: '#ddd !important'}); + + $("input[name=tcp_port]") + .css({backgroundColor: '#ddd '}); $("input[name=tcp_port]").attr("disabled", true); - - $("input[name=snmp3_auth_user]").css({backgroundColor: '#ddd !important'}); + + $("input[name=snmp3_auth_user]") + .css({backgroundColor: '#ddd '}); $("input[name=snmp3_auth_user]").attr("disabled", true); - - $("input[name=snmp3_auth_pass]").css({backgroundColor: '#ddd !important'}); + + $("input[name=snmp3_auth_pass]") + .css({backgroundColor: '#ddd '}); $("input[name=snmp3_auth_pass]").attr("disabled", true); - - $("#snmp3_privacy_method").css({backgroundColor: '#ddd !important'}); + + $("#snmp3_privacy_method").css({backgroundColor: '#ddd '}); $("#snmp3_privacy_method").attr("disabled", true); - - $("input[name=snmp3_privacy_pass]").css({backgroundColor: '#ddd !important'}); + + $("input[name=snmp3_privacy_pass]") + .css({backgroundColor: '#ddd '}); $("input[name=snmp3_privacy_pass]").attr("disabled", true); - - $("#snmp3_auth_method").css({backgroundColor: '#ddd !important'}); + + $("#snmp3_auth_method").css({backgroundColor: '#ddd '}); $("#snmp3_auth_method").attr("disabled", true); - - $("#snmp3_security_level").css({backgroundColor: '#ddd !important'}); + + $("#snmp3_security_level").css({backgroundColor: '#ddd '}); $("#snmp3_security_level").attr("disabled", true); + + $("#command_text").css({backgroundColor: '#ddd '}); + $("#command_text").attr("disabled", true); + + $("#command_credential_identifier") + .css({backgroundColor: '#ddd '}); + $("#command_credential_identifier").attr("disabled", true); + + $("#command_os").css({backgroundColor: '#ddd '}); + $("#command_os").attr("disabled", true); } // type 15-18- SNMP - if ((document.component.type.value > 14) && (document.component.type.value < 19 )) { - document.component.snmp_oid.style.background="#fff"; - document.component.snmp_oid.style.disabled=false; - document.component.snmp_community.style.background="#fff"; - document.component.snmp_community.disabled=false; + if ((document.component.type.value > 14) && (document.component.type.value < 19 )) { document.component.snmp_oid.style.background="#fff"; document.component.snmp_oid.disabled=false; - document.component.tcp_send.style.background="#ddd !important"; + + document.getElementById('text-snmp_community').style.background="#fff"; + document.getElementById('text-snmp_community').disabled=false; + document.component.snmp_oid.style.background="#fff"; + document.component.snmp_oid.disabled=false; + document.component.tcp_send.style.background="#ddd "; document.component.tcp_send.disabled=true; - document.component.tcp_rcv.style.background="#ddd !important"; + document.component.tcp_rcv.style.background="#ddd "; document.component.tcp_rcv.disabled=true; document.component.tcp_port.style.background="#fff"; document.component.tcp_port.disabled=false; - + document.component.snmp_version.style.background="#fff"; document.component.snmp_version.disabled=false; document.component.snmp3_auth_user.style.background="#fff"; @@ -364,94 +404,161 @@ function type_change () { document.component.snmp3_auth_method.disabled=false; document.component.snmp3_security_level.style.background="#fff"; document.component.snmp3_security_level.disabled=false; - + + document.component.command_text.style.background="#ddd"; + document.component.command_text.style.disabled=true; + document.component.command_credential_identifier.style.background="#ddd"; + document.component.command_credential_identifier.disabled=true; + document.component.command_os.style.background="#ddd"; + document.component.command_os.disabled=true; + $("#snmp_version" ).trigger("change"); } + + if ((document.component.type.value >= 34) && (document.component.type.value <= 37 )) { + document.component.snmp_oid.style.background="#ddd"; + document.component.snmp_oid.disabled=true; + document.getElementById('text-snmp_community').style.background="#ddd"; + document.getElementById('text-snmp_community').disabled=true; + document.component.snmp_oid.style.background="#ddd"; + document.component.snmp_oid.disabled=true; + document.component.snmp_version.style.background="#ddd"; + document.component.snmp_version.disabled=true; + + document.component.tcp_send.style.background="#ddd"; + document.component.tcp_send.disabled=true; + document.component.tcp_rcv.style.background="#ddd"; + document.component.tcp_rcv.disabled=true; + document.component.tcp_port.style.background="#fff"; + document.component.tcp_port.disabled=false; + + document.component.snmp3_auth_user.style.background="#ddd "; + document.component.snmp3_auth_user.disabled=true; + document.component.snmp3_auth_pass.background="#ddd "; + document.component.snmp3_auth_pass.disabled=true; + document.component.snmp3_privacy_method.style.background="#ddd "; + document.component.snmp3_privacy_method.disabled=true; + document.component.snmp3_privacy_pass.style.background="#ddd "; + document.component.snmp3_privacy_pass.disabled=true; + document.component.snmp3_auth_method.style.background="#ddd "; + document.component.snmp3_auth_method.disabled=true; + document.component.snmp3_security_level.style.background="#ddd "; + document.component.snmp3_security_level.disabled=true; + + document.component.command_text.style.background="#fff"; + document.component.command_text.style.disabled=false; + document.component.command_credential_identifier.style.background="#fff"; + document.component.command_credential_identifier.disabled=false; + document.component.command_os.style.background="#fff"; + document.component.command_os.disabled=false; + } + // type 6-7 - ICMP if ((document.component.type.value == 6) || (document.component.type.value == 7)) { - document.component.snmp_oid.style.background="#ddd !important"; + document.component.snmp_oid.style.background="#ddd "; document.component.snmp_oid.disabled=true; - document.component.snmp_community.style.background="#ddd !important"; - document.component.snmp_community.disabled=true; - document.component.snmp_oid.style.background="#ddd !important"; + document.getElementById('text-snmp_community').style.background="#ddd"; + document.getElementById('text-snmp_community').disabled=true; + document.component.snmp_oid.style.background="#ddd "; document.component.snmp_oid.disabled=true; - document.component.tcp_send.style.background="#ddd !important"; + document.component.tcp_send.style.background="#ddd "; document.component.tcp_send.disabled=true; - document.component.tcp_rcv.style.background="#ddd !important"; + document.component.tcp_rcv.style.background="#ddd "; document.component.tcp_rcv.disabled=true; - document.component.tcp_port.style.background="#ddd !important"; + document.component.tcp_port.style.background="#ddd "; document.component.tcp_port.disabled=true; - - document.component.snmp_version.style.background="#ddd !important"; + + document.component.snmp_version.style.background="#ddd "; document.component.snmp_version.disabled=true; - document.component.snmp3_auth_user.style.background="#ddd !important"; + document.component.snmp3_auth_user.style.background="#ddd "; document.component.snmp3_auth_user.disabled=true; - document.component.snmp3_auth_pass.background="#ddd !important"; + document.component.snmp3_auth_pass.background="#ddd "; document.component.snmp3_auth_pass.disabled=true; - document.component.snmp3_privacy_method.style.background="#ddd !important"; + document.component.snmp3_privacy_method.style.background="#ddd "; document.component.snmp3_privacy_method.disabled=true; - document.component.snmp3_privacy_pass.style.background="#ddd !important"; + document.component.snmp3_privacy_pass.style.background="#ddd "; document.component.snmp3_privacy_pass.disabled=true; - document.component.snmp3_auth_method.style.background="#ddd !important"; + document.component.snmp3_auth_method.style.background="#ddd "; document.component.snmp3_auth_method.disabled=true; - document.component.snmp3_security_level.style.background="#ddd !important"; + document.component.snmp3_security_level.style.background="#ddd "; document.component.snmp3_security_level.disabled=true; + + document.component.command_text.style.background="#ddd"; + document.component.command_text.style.disabled=true; + document.component.command_credential_identifier.style.background="#ddd"; + document.component.command_credential_identifier.disabled=true; + document.component.command_os.style.background="#ddd"; + document.component.command_os.disabled=true; } // type 8-11 - TCP if ((document.component.type.value > 7) && (document.component.type.value < 12)) { - document.component.snmp_oid.style.background="#ddd !important"; + document.component.snmp_oid.style.background="#ddd "; document.component.snmp_oid.disabled=true; - document.component.snmp_community.style.background="#ddd !important"; - document.component.snmp_community.disabled=true; + document.getElementById('text-snmp_community').style.background="#ddd "; + document.getElementById('text-snmp_community').disabled=true; document.component.tcp_send.style.background="#fff"; document.component.tcp_send.disabled=false; document.component.tcp_rcv.style.background="#fff"; document.component.tcp_rcv.disabled=false; document.component.tcp_port.style.background="#fff"; document.component.tcp_port.disabled=false; - - document.component.snmp_version.style.background="#ddd !important"; + + document.component.snmp_version.style.background="#ddd "; document.component.snmp_version.disabled=true; - document.component.snmp3_auth_user.style.background="#ddd !important"; + document.component.snmp3_auth_user.style.background="#ddd "; document.component.snmp3_auth_user.disabled=true; - document.component.snmp3_auth_pass.background="#ddd !important"; + document.component.snmp3_auth_pass.background="#ddd "; document.component.snmp3_auth_pass.disabled=true; - document.component.snmp3_privacy_method.style.background="#ddd !important"; + document.component.snmp3_privacy_method.style.background="#ddd "; document.component.snmp3_privacy_method.disabled=true; - document.component.snmp3_privacy_pass.style.background="#ddd !important"; + document.component.snmp3_privacy_pass.style.background="#ddd "; document.component.snmp3_privacy_pass.disabled=true; - document.component.snmp3_auth_method.style.background="#ddd !important"; + document.component.snmp3_auth_method.style.background="#ddd "; document.component.snmp3_auth_method.disabled=true; - document.component.snmp3_security_level.style.background="#ddd !important"; + document.component.snmp3_security_level.style.background="#ddd "; document.component.snmp3_security_level.disabled=true; + + document.component.command_text.style.background="#ddd"; + document.component.command_text.style.disabled=true; + document.component.command_credential_identifier.style.background="#ddd"; + document.component.command_credential_identifier.disabled=true; + document.component.command_os.style.background="#ddd"; + document.component.command_os.disabled=true; } // type 12 - UDP if (document.component.type.value == 12) { - document.component.snmp_oid.style.background="#ddd !important"; + document.component.snmp_oid.style.background="#ddd "; document.component.snmp_oid.disabled=true; - document.component.snmp_community.style.background="#ddd !important"; - document.component.snmp_community.disabled=true; + document.getElementById('text-snmp_community').style.background="#ddd "; + document.getElementById('text-snmp_community').disabled=true; document.component.tcp_send.style.background="#fff"; document.component.tcp_send.disabled=false; document.component.tcp_rcv.style.background="#fff"; document.component.tcp_rcv.disabled=false; document.component.tcp_port.style.background="#fff"; document.component.tcp_port.disabled=false; - - document.component.snmp_version.style.background="#ddd !important"; + + document.component.snmp_version.style.background="#ddd "; document.component.snmp_version.disabled=true; - document.component.snmp3_auth_user.style.background="#ddd !important"; + document.component.snmp3_auth_user.style.background="#ddd "; document.component.snmp3_auth_user.disabled=true; - document.component.snmp3_auth_pass.background="#ddd !important"; + document.component.snmp3_auth_pass.background="#ddd "; document.component.snmp3_auth_pass.disabled=true; - document.component.snmp3_privacy_method.style.background="#ddd !important"; + document.component.snmp3_privacy_method.style.background="#ddd "; document.component.snmp3_privacy_method.disabled=true; - document.component.snmp3_privacy_pass.style.background="#ddd !important"; + document.component.snmp3_privacy_pass.style.background="#ddd "; document.component.snmp3_privacy_pass.disabled=true; - document.component.snmp3_auth_method.style.background="#ddd !important"; + document.component.snmp3_auth_method.style.background="#ddd "; document.component.snmp3_auth_method.disabled=true; - document.component.snmp3_security_level.style.background="#ddd !important"; + document.component.snmp3_security_level.style.background="#ddd "; document.component.snmp3_security_level.disabled=true; + + document.component.command_text.style.background="#ddd"; + document.component.command_text.style.disabled=true; + document.component.command_credential_identifier.style.background="#ddd"; + document.component.command_credential_identifier.disabled=true; + document.component.command_os.style.background="#ddd"; + document.component.command_os.disabled=true; } } @@ -470,7 +577,7 @@ $(document).ready (function () { } }); }); - + $("#left").click (function () { jQuery.each($("select[name='id_tag_selected[]'] option:selected"), function (key, value) { tag_name = $(value).html(); @@ -485,38 +592,38 @@ $(document).ready (function () { } }); }); - + $("#submit-crt").click(function () { $('#id_tag_selected option').map(function() { $(this).prop('selected', true); }); }); - + $("#submit-upd").click(function () { $('#id_tag_selected option').map(function() { $(this).prop('selected', true); }); }); - + if ($("#snmp_version").val() == "3") { $("input[name=snmp3_auth_user]").css({backgroundColor: '#fff'}); $("input[name=snmp3_auth_user]").removeAttr('disabled'); - + $("input[name=snmp3_auth_pass]").css({backgroundColor: '#fff'}); $("input[name=snmp3_auth_pass]").removeAttr('disabled'); - + $("#snmp3_privacy_method").css({backgroundColor: '#fff'}); $("#snmp3_privacy_method").removeAttr('disabled'); - + $("input[name=snmp3_privacy_pass]").css({backgroundColor: '#fff'}); $("input[name=snmp3_privacy_pass]").removeAttr('disabled'); - + $("#snmp3_auth_method").css({backgroundColor: '#fff'}); $("#snmp3_auth_method").removeAttr('disabled'); - + $("#snmp3_security_level").css({backgroundColor: '#fff'}); $("#snmp3_security_level").removeAttr('disabled'); - + $("input[name=active_snmp_v3]").val(1); $("input[name=snmp_community]").css({backgroundColor: '#ddd'}); $("input[name=snmp_community]").attr("disabled",true); @@ -525,49 +632,47 @@ $(document).ready (function () { $("input[name=snmp3_auth_user]").val(""); $("input[name=snmp3_auth_user]").css({backgroundColor: '#ddd'}); $("input[name=snmp3_auth_user]").attr("disabled", true); - + $("input[name=snmp3_auth_pass]").val(""); $("input[name=snmp3_auth_pass]").css({backgroundColor: '#ddd'}); $("input[name=snmp3_auth_pass]").attr("disabled", true); - + $("#snmp3_privacy_method").css({backgroundColor: '#ddd'}); $("#snmp3_privacy_method").attr("disabled", true); - + $("input[name=snmp3_privacy_pass]").val(""); $("input[name=snmp3_privacy_pass]").css({backgroundColor: '#ddd'}); $("input[name=snmp3_privacy_pass]").attr("disabled", true); - + $("#snmp3_auth_method").css({backgroundColor: '#ddd'}); $("#snmp3_auth_method").attr("disabled", true); - + $("#snmp3_security_level").css({backgroundColor: '#ddd'}); $("#snmp3_security_level").attr("disabled", true); - + $("input[name=active_snmp_v3]").val(0); - $("input[name=snmp_community]").css({backgroundColor: '#fff'}); - $("input[name=snmp_community]").removeAttr('disabled'); } - + $("#snmp_version").change(function () { if (this.value == "3") { $("input[name=snmp3_auth_user]").css({backgroundColor: '#fff'}); $("input[name=snmp3_auth_user]").removeAttr('disabled'); - + $("input[name=snmp3_auth_pass]").css({backgroundColor: '#fff'}); $("input[name=snmp3_auth_pass]").removeAttr('disabled'); - + $("#snmp3_privacy_method").css({backgroundColor: '#fff'}); $("#snmp3_privacy_method").removeAttr('disabled'); - + $("input[name=snmp3_privacy_pass]").css({backgroundColor: '#fff'}); $("input[name=snmp3_privacy_pass]").removeAttr('disabled'); - + $("#snmp3_auth_method").css({backgroundColor: '#fff'}); $("#snmp3_auth_method").removeAttr('disabled'); - + $("#snmp3_security_level").css({backgroundColor: '#fff'}); $("#snmp3_security_level").removeAttr('disabled'); - + $("input[name=active_snmp_v3]").val(1); $("input[name=snmp_community]").css({backgroundColor: '#ddd'}); $("input[name=snmp_community]").attr("disabled",true); @@ -576,50 +681,50 @@ $(document).ready (function () { $("input[name=snmp3_auth_user]").val(""); $("input[name=snmp3_auth_user]").css({backgroundColor: '#ddd'}); $("input[name=snmp3_auth_user]").attr("disabled", true); - + $("input[name=snmp3_auth_pass]").val(""); $("input[name=snmp3_auth_pass]").css({backgroundColor: '#ddd'}); $("input[name=snmp3_auth_pass]").attr("disabled", true); - + $("#snmp3_privacy_method").css({backgroundColor: '#ddd'}); $("#snmp3_privacy_method").attr("disabled", true); - + $("input[name=snmp3_privacy_pass]").val(""); $("input[name=snmp3_privacy_pass]").css({backgroundColor: '#ddd'}); $("input[name=snmp3_privacy_pass]").attr("disabled", true); - + $("#snmp3_auth_method").css({backgroundColor: '#ddd'}); $("#snmp3_auth_method").attr("disabled", true); - + $("#snmp3_security_level").css({backgroundColor: '#ddd'}); $("#snmp3_security_level").attr("disabled", true); - + $("input[name=active_snmp_v3]").val(0); $("input[name=snmp_community]").css({backgroundColor: '#fff'}); $("input[name=snmp_community]").removeAttr('disabled'); } }); - + $("#type"). change(function () { if ($("#snmp_version").val() == "3") { $("input[name=snmp3_auth_user]").css({backgroundColor: '#fff'}); $("input[name=snmp3_auth_user]").removeAttr('disabled'); - + $("input[name=snmp3_auth_pass]").css({backgroundColor: '#fff'}); $("input[name=snmp3_auth_pass]").removeAttr('disabled'); - + $("#snmp3_privacy_method").css({backgroundColor: '#fff'}); $("#snmp3_privacy_method").removeAttr('disabled'); - + $("input[name=snmp3_privacy_pass]").css({backgroundColor: '#fff'}); $("input[name=snmp3_privacy_pass]").removeAttr('disabled'); - + $("#snmp3_auth_method").css({backgroundColor: '#fff'}); $("#snmp3_auth_method").removeAttr('disabled'); - + $("#snmp3_security_level").css({backgroundColor: '#fff'}); $("#snmp3_security_level").removeAttr('disabled'); - + $("input[name=active_snmp_v3]").val(1); $("input[name=snmp_community]").css({backgroundColor: '#ddd'}); $("input[name=snmp_community]").attr("disabled",true); @@ -628,30 +733,28 @@ $(document).ready (function () { $("input[name=snmp3_auth_user]").val(""); $("input[name=snmp3_auth_user]").css({backgroundColor: '#ddd'}); $("input[name=snmp3_auth_user]").attr("disabled", true); - + $("input[name=snmp3_auth_pass]").val(""); $("input[name=snmp3_auth_pass]").css({backgroundColor: '#ddd'}); $("input[name=snmp3_auth_pass]").attr("disabled", true); - + $("#snmp3_privacy_method").css({backgroundColor: '#ddd'}); $("#snmp3_privacy_method").attr("disabled", true); - + $("input[name=snmp3_privacy_pass]").val(""); $("input[name=snmp3_privacy_pass]").css({backgroundColor: '#ddd'}); $("input[name=snmp3_privacy_pass]").attr("disabled", true); - + $("#snmp3_auth_method").css({backgroundColor: '#ddd'}); $("#snmp3_auth_method").attr("disabled", true); - + $("#snmp3_security_level").css({backgroundColor: '#ddd'}); $("#snmp3_security_level").attr("disabled", true); - + $("input[name=active_snmp_v3]").val(0); - $("input[name=snmp_community]").css({backgroundColor: '#fff'}); - $("input[name=snmp_community]").removeAttr('disabled'); } }); - + $("#snmp_version" ).trigger("change"); }); diff --git a/pandora_console/godmode/modules/manage_network_components_form_common.php b/pandora_console/godmode/modules/manage_network_components_form_common.php index 2a55efb1dd..ed46957725 100644 --- a/pandora_console/godmode/modules/manage_network_components_form_common.php +++ b/pandora_console/godmode/modules/manage_network_components_form_common.php @@ -77,7 +77,7 @@ $sql = sprintf( 'SELECT id_tipo, descripcion FROM ttipo_modulo WHERE categoria IN (%s) - ORDER BY descripcion', + ORDER BY id_tipo ASC', implode(',', $categories) ); $table->data[1][1] = html_print_select_from_sql( diff --git a/pandora_console/godmode/modules/manage_network_components_form_network.php b/pandora_console/godmode/modules/manage_network_components_form_network.php index 0f39406ce9..addf57e05b 100755 --- a/pandora_console/godmode/modules/manage_network_components_form_network.php +++ b/pandora_console/godmode/modules/manage_network_components_form_network.php @@ -1,17 +1,32 @@ colspan['snmp_2'][1] = 3; +$data[1] = html_print_input_text( + 'snmp_oid', + $snmp_oid, + '', + 30, + 400, + true +); + $data[2] = __('SNMP community'); -$data[3] = html_print_input_text('snmp_community', $snmp_community, '', 15, 60, true); +$data[3] = html_print_input_text( + 'snmp_community', + $snmp_community, + '', + 15, + 60, + true +); push_table_row($data, 'snmp_2'); $data = []; $data[0] = __('Auth user'); -$data[1] = html_print_input_text('snmp3_auth_user', $snmp3_auth_user, '', 15, 60, true); +$data[1] = html_print_input_text( + 'snmp3_auth_user', + $snmp3_auth_user, + '', + 15, + 60, + true +); $data[2] = __('Auth password'); -$data[3] = html_print_input_password('snmp3_auth_pass', $snmp3_auth_pass, '', 15, 60, true); -$data[3] .= html_print_input_hidden_extended('active_snmp_v3', 0, 'active_snmp_v3_mncfn', true); +$data[3] = html_print_input_password( + 'snmp3_auth_pass', + $snmp3_auth_pass, + '', + 15, + 60, + true +); +$data[3] .= html_print_input_hidden_extended( + 'active_snmp_v3', + 0, + 'active_snmp_v3_mncfn', + true +); push_table_row($data, 'field_snmpv3_row1'); $data = []; $data[0] = __('Privacy method'); -$data[1] = html_print_select(['DES' => __('DES'), 'AES' => __('AES')], 'snmp3_privacy_method', $snmp3_privacy_method, '', '', '', true); +$data[1] = html_print_select( + [ + 'DES' => __('DES'), + 'AES' => __('AES'), + ], + 'snmp3_privacy_method', + $snmp3_privacy_method, + '', + '', + '', + true +); $data[2] = __('Privacy pass'); -$data[3] = html_print_input_password('snmp3_privacy_pass', $snmp3_privacy_pass, '', 15, 60, true); +$data[3] = html_print_input_password( + 'snmp3_privacy_pass', + $snmp3_privacy_pass, + '', + 15, + 60, + true +); push_table_row($data, 'field_snmpv3_row2'); $data = []; $data[0] = __('Auth method'); -$data[1] = html_print_select(['MD5' => __('MD5'), 'SHA' => __('SHA')], 'snmp3_auth_method', $snmp3_auth_method, '', '', '', true); +$data[1] = html_print_select( + [ + 'MD5' => __('MD5'), + 'SHA' => __('SHA'), + ], + 'snmp3_auth_method', + $snmp3_auth_method, + '', + '', + '', + true +); $data[2] = __('Security level'); $data[3] = html_print_select( [ @@ -110,12 +187,11 @@ $data[1] = html_print_extended_select_for_post_process( false, true ); -$data[2] = $data[3] = ''; +$data[2] = ''; +$data[3] = ''; push_table_row($data, 'field_process'); - - -// Advanced stuff +// Advanced stuff. $data = []; $data[0] = __('TCP send'); $data[1] = html_print_textarea('tcp_send', 2, 65, $tcp_send, '', true); @@ -129,6 +205,64 @@ $data[1] = html_print_textarea('tcp_rcv', 2, 65, $tcp_rcv, '', true); $table->colspan['tcp_receive'][1] = 3; push_table_row($data, 'tcp_receive'); + +$data = []; +$data[0] = __('Command'); +$data[1] = html_print_input_text_extended( + 'command_text', + $command_text, + 'command_text', + '', + 100, + 10000, + $disabledBecauseInPolicy, + '', + $largeClassDisabledBecauseInPolicy, + true +); +$table->colspan['row-cmd-row-1'][1] = 3; +push_table_row($data, 'row-cmd-row-1'); + +require_once $config['homedir'].'/include/class/CredentialStore.class.php'; +$array_credential_identifier = CredentialStore::getKeys(); + +$data[0] = __('Credential identifier'); +$data[1] = html_print_select( + $array_credential_identifier, + 'command_credential_identifier', + $command_credential_identifier, + '', + __('None'), + '', + true, + false, + false, + '', + $disabledBecauseInPolicy +); + +$array_os = [ + 'inherited' => __('Inherited'), + 'linux' => __('Linux'), + 'windows' => __('Windows'), +]; + +$data[2] = __('Target OS'); +$data[3] = html_print_select( + $array_os, + 'command_os', + $command_os, + '', + '', + '', + true, + false, + false, + '', + $disabledBecauseInPolicy +); + +push_table_row($data, 'row-cmd-row-2'); ?> + $2'; } - // Replace bbcode format [url=www.example.org] String [/url] with or without http and slashes + // Replace bbcode format [url=www.example.org] String [/url] with or without http and slashes. $return = preg_replace('/\[url(?|](((?:https?:\/\/)?[^[]+))|(?:=[\'"]?((?:https?:\/\/)?[^]]+?)[\'"]?)](.+?))\[\/url]/', $html_bbcode, $text); } @@ -1405,7 +1405,7 @@ function ui_print_help_icon( [ 'class' => 'img_help', 'title' => __('Help'), - 'onclick' => "open_help ('".$url."')", + 'onclick' => "open_help ('".ui_get_full_url('index.php?sec=view&sec2=general/help_feedback&pure=1&url='.$url)."')", 'id' => $id, ], false, diff --git a/pandora_console/include/styles/help_feedback.css b/pandora_console/include/styles/help_feedback.css new file mode 100644 index 0000000000..40255f839d --- /dev/null +++ b/pandora_console/include/styles/help_feedback.css @@ -0,0 +1,74 @@ +html, +body { + width: 100%; + height: 100%; +} + +div.help_feedback { + position: fixed; + bottom: 0; + background: white; + height: auto; + width: 320px; + padding-left: 10px; + padding-right: 10px; +} + +.btn_sug { + margin-right: 10px; + margin-top: 10px; + margin-left: 10px; +} + +.btn_something { + margin-top: 10px; + margin-left: 10px; +} + +.textarea_feedback { + margin-left: 11px; + max-width: 200px; + margin-top: 10px; + font-weight: bolder; +} + +.email_feedback { + max-width: 200px; + margin-left: 39px; + margin-top: 10px; + margin-bottom: 10px; + font-weight: bolder; +} + +.btn_submit_feed_back { + margin-right: 10px; + margin-top: 5px; + margin-bottom: 10px; +} + +.btn_sug_not_selected { + font-weight: normal; + -moz-border-radius: 2px; + -webkit-border-radius: 2px; + border-radius: 2px; + font-size: 1.2em; + background-color: lightgrey; + background-repeat: no-repeat; + background-position: 92% 10px; + color: #000; + padding-bottom: 10px; + padding-top: 10px; + padding-left: 10px; + border: 1px solid #888; + font-family: "lato", "Open Sans", sans-serif; + cursor: pointer; + margin-right: 20px; + margin-top: 10px; + margin-left: 10px; + background-image: url(../../images/input_tick.png); + padding-right: 30px; +} + +.c { + display: flex; +} From f8636e77cc01debbbc0480d169e831e0f13de664 Mon Sep 17 00:00:00 2001 From: Marcos Alconada Date: Tue, 15 Oct 2019 12:45:40 +0200 Subject: [PATCH 17/81] Update HelpFeedBack.class.php --- pandora_console/include/class/HelpFeedBack.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandora_console/include/class/HelpFeedBack.class.php b/pandora_console/include/class/HelpFeedBack.class.php index aa6bc64155..037117225f 100644 --- a/pandora_console/include/class/HelpFeedBack.class.php +++ b/pandora_console/include/class/HelpFeedBack.class.php @@ -242,7 +242,7 @@ class HelpFeedBack extends Wizard $feedback_text .= ' From '.$feedback_mail.' '; - $res = enterprise_hook('send_email_attachment', ['marcos.alconada@artica.es', $feedback_text, $subject]); + $res = enterprise_hook('send_email_attachment', ['feedback@artica.es', $feedback_text, $subject]); return $res; From 03ada6fb1fa26207fe3783f836291034a5d0401a Mon Sep 17 00:00:00 2001 From: Marcos Alconada Date: Tue, 15 Oct 2019 16:28:12 +0200 Subject: [PATCH 18/81] Update HelpFeedBack.class.php --- pandora_console/include/class/HelpFeedBack.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandora_console/include/class/HelpFeedBack.class.php b/pandora_console/include/class/HelpFeedBack.class.php index 037117225f..29cc81d3f9 100644 --- a/pandora_console/include/class/HelpFeedBack.class.php +++ b/pandora_console/include/class/HelpFeedBack.class.php @@ -135,7 +135,7 @@ class HelpFeedBack extends Wizard [ 'wrapper' => 'div', 'block_id' => 'ejemplo', - 'class' => 'flex movida o lo que quieras', + 'class' => '', 'direct' => 1, 'block_content' => [ [ From d04544fa6614b1fb162613466dd07e5f8bc36025 Mon Sep 17 00:00:00 2001 From: Marcos Alconada Date: Tue, 15 Oct 2019 16:34:01 +0200 Subject: [PATCH 19/81] Update HelpFeedBack.class.php --- pandora_console/include/class/HelpFeedBack.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandora_console/include/class/HelpFeedBack.class.php b/pandora_console/include/class/HelpFeedBack.class.php index 29cc81d3f9..d1b58f9ced 100644 --- a/pandora_console/include/class/HelpFeedBack.class.php +++ b/pandora_console/include/class/HelpFeedBack.class.php @@ -134,7 +134,7 @@ class HelpFeedBack extends Wizard $inputs = [ [ 'wrapper' => 'div', - 'block_id' => 'ejemplo', + 'block_id' => 'btn_section', 'class' => '', 'direct' => 1, 'block_content' => [ From 5a73b67545fe49a9f3f6e93732621348e04e6d4c Mon Sep 17 00:00:00 2001 From: Marcos Alconada Date: Tue, 15 Oct 2019 17:59:22 +0200 Subject: [PATCH 20/81] Update help_feedback.css --- pandora_console/include/styles/help_feedback.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandora_console/include/styles/help_feedback.css b/pandora_console/include/styles/help_feedback.css index 40255f839d..d45cfcf71b 100644 --- a/pandora_console/include/styles/help_feedback.css +++ b/pandora_console/include/styles/help_feedback.css @@ -69,6 +69,6 @@ div.help_feedback { padding-right: 30px; } -.c { +.btn_section { display: flex; } From 43d3f32d0c1aa21a390a7fcccbd9b6a8b511613f Mon Sep 17 00:00:00 2001 From: Marcos Alconada Date: Tue, 15 Oct 2019 18:11:21 +0200 Subject: [PATCH 21/81] Update help_feedback.css --- .../include/styles/help_feedback.css | 37 +++++++++++++++++-- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/pandora_console/include/styles/help_feedback.css b/pandora_console/include/styles/help_feedback.css index d45cfcf71b..3368f5b3d7 100644 --- a/pandora_console/include/styles/help_feedback.css +++ b/pandora_console/include/styles/help_feedback.css @@ -9,7 +9,7 @@ div.help_feedback { bottom: 0; background: white; height: auto; - width: 320px; + width: 365px; padding-left: 10px; padding-right: 10px; } @@ -18,11 +18,43 @@ div.help_feedback { margin-right: 10px; margin-top: 10px; margin-left: 10px; + + font-weight: normal; + -moz-border-radius: 2px; + -webkit-border-radius: 2px; + border-radius: 2px; + font-size: 1.2em; + background-repeat: no-repeat; + background-position: 92% 10px; + color: #000; + padding-bottom: 10px; + padding-top: 10px; + padding-left: 10px; + border: none; + font-family: "lato", "Open Sans", sans-serif; + cursor: pointer; + padding-right: 30px; } .btn_something { margin-top: 10px; margin-left: 10px; + + font-weight: normal; + -moz-border-radius: 2px; + -webkit-border-radius: 2px; + border-radius: 2px; + font-size: 1.2em; + background-repeat: no-repeat; + background-position: 92% 10px; + color: #000; + padding-bottom: 10px; + padding-top: 10px; + padding-left: 10px; + border: none; + font-family: "lato", "Open Sans", sans-serif; + cursor: pointer; + padding-right: 30px; } .textarea_feedback { @@ -41,7 +73,7 @@ div.help_feedback { } .btn_submit_feed_back { - margin-right: 10px; + margin-right: 50px; margin-top: 5px; margin-bottom: 10px; } @@ -52,7 +84,6 @@ div.help_feedback { -webkit-border-radius: 2px; border-radius: 2px; font-size: 1.2em; - background-color: lightgrey; background-repeat: no-repeat; background-position: 92% 10px; color: #000; From 1a77e3e3818b60f662827dc2ee649ab94483ea02 Mon Sep 17 00:00:00 2001 From: Marcos Alconada Date: Tue, 15 Oct 2019 18:11:50 +0200 Subject: [PATCH 22/81] Update HelpFeedBack.class.php --- .../include/class/HelpFeedBack.class.php | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/pandora_console/include/class/HelpFeedBack.class.php b/pandora_console/include/class/HelpFeedBack.class.php index d1b58f9ced..e17b3153f5 100644 --- a/pandora_console/include/class/HelpFeedBack.class.php +++ b/pandora_console/include/class/HelpFeedBack.class.php @@ -135,14 +135,14 @@ class HelpFeedBack extends Wizard [ 'wrapper' => 'div', 'block_id' => 'btn_section', - 'class' => '', + 'class' => 'btn_section', 'direct' => 1, 'block_content' => [ [ 'arguments' => [ 'label' => __('Sugesstion'), 'type' => 'button', - 'attributes' => 'class="sub ok btn_sug"', + 'attributes' => 'class="btn_sug"', 'name' => 'option_1', 'id' => 'option_1', 'script' => 'change_option1()', @@ -152,7 +152,7 @@ class HelpFeedBack extends Wizard 'arguments' => [ 'label' => __('Something is not quite right'), 'type' => 'button', - 'attributes' => 'class="sub ok btn_something"', + 'attributes' => 'class="btn_something"', 'name' => 'option_2', 'id' => 'option_2', 'script' => 'change_option2()', @@ -258,16 +258,17 @@ class HelpFeedBack extends Wizard var option_selected = ""; function change_option1() { option_selected = ""; - document.getElementById("button-option_2").className = "btn_sug_not_selected"; - document.getElementById("button-option_1").className = "sub ok btn_sug"; + document.getElementById("button-option_1").className = "btn_sug_not_selected"; + document.getElementById("button-option_2").className = "btn_sug"; +; } function change_option2() { option_selected = ""; - document.getElementById("button-option_1").className = "btn_sug_not_selected"; - document.getElementById("button-option_2").className = "sub ok btn_sug"; + document.getElementById("button-option_2").className = "btn_sug_not_selected"; + document.getElementById("button-option_1").className = "btn_sug"; } From e7a948bb719725f867b131534e2c707adbc1def9 Mon Sep 17 00:00:00 2001 From: Marcos Alconada Date: Wed, 16 Oct 2019 11:03:21 +0200 Subject: [PATCH 23/81] Update HelpFeedBack.class.php --- pandora_console/include/class/HelpFeedBack.class.php | 1 - 1 file changed, 1 deletion(-) diff --git a/pandora_console/include/class/HelpFeedBack.class.php b/pandora_console/include/class/HelpFeedBack.class.php index e17b3153f5..074f3d8df2 100644 --- a/pandora_console/include/class/HelpFeedBack.class.php +++ b/pandora_console/include/class/HelpFeedBack.class.php @@ -272,7 +272,6 @@ class HelpFeedBack extends Wizard } - console.log(option_selected); // Set values to data. $("#feedback_form").on('submit', function() { // Make the AJAX call to send mails. From 4e56f6751ac9955926a9ef1508df6877af3215e5 Mon Sep 17 00:00:00 2001 From: Daniel Barbero Martin Date: Thu, 17 Oct 2019 15:17:28 +0200 Subject: [PATCH 24/81] Continue work diagnostics --- .../include/class/Diagnostics.class.php | 873 +++++++++++++----- pandora_console/include/functions.php | 4 +- pandora_console/include/functions_ui.php | 22 +- pandora_console/include/javascript/pandora.js | 25 +- pandora_console/include/styles/pandora.css | 46 + 5 files changed, 752 insertions(+), 218 deletions(-) diff --git a/pandora_console/include/class/Diagnostics.class.php b/pandora_console/include/class/Diagnostics.class.php index 211ae3ea9a..320c62fc3f 100644 --- a/pandora_console/include/class/Diagnostics.class.php +++ b/pandora_console/include/class/Diagnostics.class.php @@ -4,7 +4,7 @@ * * @category Console Class * @package Pandora FMS - * @subpackage Supervisor + * @subpackage Diagnostics * @version 1.0.0 * @license See below * @@ -37,16 +37,81 @@ require_once $config['homedir'].'/include/functions_io.php'; class Diagnostics { + /** + * Ajax controller page. + * + * @var string + */ + public $ajaxController; + /** - * Constructor. + * Constructor * - * @return class This object + * @param string $page Page. + * + * @return void */ - public function __construct() + public function __construct(string $page) { - echo 'hola'; - return $this; + global $config; + + // Check access. + check_login(); + + // Check Acl. + if (!check_acl($config['id_user'], 0, 'PM')) { + db_pandora_audit( + 'ACL Violation', + 'Trying to access diagnostic info' + ); + + if (is_ajax()) { + echo json_encode(['error' => 'noaccess']); + } + + include 'general/noaccess.php'; + exit; + } + + $this->ajaxController = $page; + } + + + /** + * Allowed methods to be called using AJAX request. + * + * @var array + */ + public $AJAXMethods = [ + 'getStatusInfo', + 'getPHPSetup', + 'getDatabaseSizeStats', + 'getDatabaseHealthStatus', + 'getDatabaseStatusInfo', + 'getSystemInfo', + 'getMySQLPerformanceMetrics', + 'getTablesFragmentation', + 'getPandoraFMSLogsDates', + 'getLicenceInformation', + 'getAttachmentFolder', + 'getInfoTagenteDatos', + 'getServerThreads', + 'datatablesDraw', + 'getChartAjax', + ]; + + + /** + * Checks if target method is available to be called using AJAX. + * + * @param string $method Target method. + * + * @return boolean True allowed, false not. + */ + public function ajaxMethod(string $method):bool + { + return in_array($method, $this->AJAXMethods); } @@ -59,167 +124,218 @@ class Diagnostics { global $config; + $textPdf = ''; + $textPdf .= html_print_image( + 'images/pdf.png', + true, + ['title' => __('PDF Report')] + ); + $textPdf .= ''; + + $textCsv = ''; + $textCsv .= html_print_image( + 'images/csv.png', + true, + ['title' => __('Csv Report')] + ); + $textCsv .= ''; + + $buttonsHeader = [ + 'diagnosticsPdf' => [ + 'text' => $textPdf, + 'active' => false, + ], + 'diagnosticsCsv' => [ + 'text' => $textCsv, + 'active' => false, + ], + ]; + + // Header. + ui_print_page_header( + __('Pandora FMS Diagnostic tool'), + 'images/gm_massive_operations.png', + false, + 'diagnostic_tool_tab', + true, + $buttonsHeader, + true + ); + /* * Info status pandoraFms. - */ - - $statusInfo = $this->getStatusInfo(); - - /* - * Print table in this case info. - */ - - $this->printTable($statusInfo); - - /* * PHP setup. - */ - - $phpSetup = $this->getPHPSetup(); - - /* - * Print table in this case PHP SETUP. - */ - - $this->printTable($phpSetup); - - /* * Database size stats. - */ - - $dataBaseSizeStats = $this->getDatabaseSizeStats(); - - /* - * Print table in this case Database size stats. - */ - - $this->printTable($dataBaseSizeStats); - - /* * Database health status. - */ - - $databaseHealthStatus = $this->getDatabaseHealthStatus(); - - /* - * Print table in this case Database health status. - */ - - $this->printTable($databaseHealthStatus); - - /* - * Database health status. - */ - - $getDatabaseStatusInfo = $this->getDatabaseStatusInfo(); - - /* - * Print table in this case Database status info. - */ - - $this->printTable($getDatabaseStatusInfo); - - if (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN') { - /* - * System Info. - */ - - $getSystemInfo = $this->getSystemInfo(); - - /* - * Print table in this case System Info. - */ - - $this->printTable($getSystemInfo); - } - - /* + * Database status info. * System Info. - */ - - $getMySQLPerformanceMetrics = $this->getMySQLPerformanceMetrics(); - - /* - * Print table in this case System Info. - */ - - $this->printTable($getMySQLPerformanceMetrics); - - /* + * MySQL Performance metrics. * Tables fragmentation in the Pandora FMS database. - */ - - $getTablesFragmentation = $this->getTablesFragmentation(); - - /* - * Print table in this case Tables fragmentation in - * the Pandora FMS database. - */ - - $this->printTable($getTablesFragmentation); - - /* - * Tables fragmentation in the Pandora FMS database. - */ - - $getPandoraFMSLogsDates = $this->getPandoraFMSLogsDates(); - - /* - * Print table in this case Tables fragmentation in - * the Pandora FMS database. - */ - - $this->printTable($getPandoraFMSLogsDates); - - /* + * Pandora FMS logs dates. * Pandora FMS Licence Information. - */ - - $getLicenceInformation = $this->getLicenceInformation(); - - /* - * Print table in this case Pandora FMS Licence Information. - */ - - $this->printTable($getLicenceInformation); - - /* * Status of the attachment folder. - */ - - $getAttachmentFolder = $this->getAttachmentFolder(); - - /* - * Print table in this case Status of the attachment folder. - */ - - $this->printTable($getAttachmentFolder); - - /* * Information from the tagente_datos table. + * Pandora FMS server threads. */ - $getInfoTagenteDatos = $this->getInfoTagenteDatos(); + foreach ($this->AJAXMethods as $key => $method) { + switch ($method) { + case 'getStatusInfo': + $title = __('Info status pandoraFms'); + break; + + case 'getPHPSetup': + $title = __('PHP setup'); + break; + + case 'getDatabaseSizeStats': + $title = __('Database size stats'); + break; + + case 'getDatabaseHealthStatus': + $title = __('Database health status'); + break; + + case 'getDatabaseStatusInfo': + $title = __('Database status info'); + break; + + case 'getSystemInfo': + $title = __('System Info'); + break; + + case 'getMySQLPerformanceMetrics': + $title = __('MySQL Performance metrics'); + break; + + case 'getTablesFragmentation': + $title = __( + 'Tables fragmentation in the Pandora FMS database' + ); + break; + + case 'getPandoraFMSLogsDates': + $title = __('Pandora FMS logs dates'); + break; + + case 'getLicenceInformation': + $title = __('Pandora FMS Licence Information'); + break; + + case 'getAttachmentFolder': + $title = __('Status of the attachment folder'); + break; + + case 'getInfoTagenteDatos': + $title = __('Information from the tagente_datos table'); + break; + + case 'getServerThreads': + $title = __('Pandora FMS server threads'); + break; + + default: + // Not possible. + $title = ''; + break; + } + + if ($method !== 'datatablesDraw' && $method !== 'getChartAjax') { + echo '
'; + $this->printData($method, $title); + echo '
'; + } + } /* - * Print table in this case Information from the tagente_datos table. + * Agent id with name Master Server. */ - $this->printTable($getInfoTagenteDatos); + $agentIdMasterServer = $this->getAgentIdMasterServer(); - if (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN') { - /* - * Pandora FMS server threads. - */ - - $getServerThreads = $this->getServerThreads(); + if ($agentIdMasterServer !== 0) { + $agentMonitoring = [ + 'chartAgentsUnknown' => [ + 'title' => __( + 'Graph of the Agents Unknown module.' + ), + 'nameModule' => 'Agents_Unknown', + 'idAgent' => $agentIdMasterServer, + ], + 'chartDatabaseMain' => [ + 'title' => __( + 'Graph of the Database Maintenance module.' + ), + 'nameModule' => 'Database Maintenance', + 'idAgent' => $agentIdMasterServer, + ], + 'chartFreeDiskSpoolDir' => [ + 'title' => __( + 'Graph of the Free Disk Spool Dir module.' + ), + 'nameModule' => 'FreeDisk_SpoolDir', + 'idAgent' => $agentIdMasterServer, + ], + 'chartFreeRAM' => [ + 'title' => __('Graph of the Free RAM module.'), + 'nameModule' => 'Free_RAM', + 'idAgent' => $agentIdMasterServer, + ], + 'chartQueuedModules' => [ + 'title' => __( + 'Graph of the Queued Modules module.' + ), + 'nameModule' => 'Queued_Modules', + 'idAgent' => $agentIdMasterServer, + ], + 'chartStatus' => [ + 'title' => __('Graph of the Status module.'), + 'nameModule' => 'Status', + 'idAgent' => $agentIdMasterServer, + ], + 'chartSystemLoadAVG' => [ + 'title' => __( + 'Graph of the System Load AVG module.' + ), + 'nameModule' => 'System_Load_AVG', + 'idAgent' => $agentIdMasterServer, + ], + 'chartExecutionTime' => [ + 'title' => __( + 'Graph of the Execution Time module.' + ), + 'nameModule' => 'Execution_time', + 'idAgent' => $agentIdMasterServer, + ], + ]; /* - * Print table in this case Pandora FMS server threads. + * Print table graps: + * Graph of the Agents Unknown module. + * Graph of the Database Maintenance module. + * Graph of the Free Disk Spool Dir module. + * Graph of the Free RAM module. + * Graph of the Queued Modules module. + * Graph of the Status module. + * Graph of the System Load AVG module. + * Graph of the Execution Time module. */ - $this->printTable($getServerThreads); + echo '
'; + echo __('Graphs modules that represent the self-monitoring system'); + echo '
'; + echo '
'; + foreach ($agentMonitoring as $key => $value) { + $this->printDataCharts($value); + } + + echo '
'; } + + echo ''; + } @@ -531,23 +647,26 @@ class Diagnostics { global $config; - $cpuModelName = 'cat /proc/cpuinfo | grep "model name" | tail -1 | cut -f 2 -d ":"'; - $cpuProcessor = 'cat /proc/cpuinfo | grep "processor" | wc -l'; - $ramMemTotal = 'cat /proc/meminfo | grep "MemTotal"'; + $result = []; + if (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN') { + $cpuModelName = 'cat /proc/cpuinfo | grep "model name" | tail -1 | cut -f 2 -d ":"'; + $cpuProcessor = 'cat /proc/cpuinfo | grep "processor" | wc -l'; + $ramMemTotal = 'cat /proc/meminfo | grep "MemTotal"'; - $result = [ - 'error' => false, - 'data' => [ - 'cpuInfo' => [ - 'name' => __('CPU'), - 'value' => exec($cpuModelName).' x '.exec($cpuProcessor), + $result = [ + 'error' => false, + 'data' => [ + 'cpuInfo' => [ + 'name' => __('CPU'), + 'value' => exec($cpuModelName).' x '.exec($cpuProcessor), + ], + 'ramInfo' => [ + 'name' => __('RAM'), + 'value' => exec($ramMemTotal), + ], ], - 'ramInfo' => [ - 'name' => __('RAM'), - 'value' => exec($ramMemTotal), - ], - ], - ]; + ]; + } return json_encode($result); } @@ -562,13 +681,20 @@ class Diagnostics { global $config; - $variablesMsql = db_get_all_rows_sql('SHOW variables'); + $variablesMsql = db_get_all_rows_sql('SHOW VARIABLES'); $variablesMsql = array_reduce( $variablesMsql, function ($carry, $item) { $bytes = 1048576; $mega = 1024; switch ($item['Variable_name']) { + case 'sql_mode': + $name = __('Sql mode'); + $value = ($item['Value']); + $status = (empty($item['Value']) === true) ? 1 : 0; + $message = __('Must be empty'); + break; + case 'innodb_log_file_size': $name = __('InnoDB log file size'); $value = ($item['Value'] / $bytes); @@ -594,20 +720,16 @@ class Diagnostics $name = __('Maximun allowed packet'); $value = ($item['Value'] / $bytes); $status = (($item['Value'] / $bytes) >= 32) ? 1 : 0; - $message = __('Min. Recommended Value').' 32'; + $message = __('Min. Recommended Value').' 32M'; break; case 'innodb_buffer_pool_size': - if (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN') { - $min = shell_exec( - "cat /proc/meminfo | grep -i total | head -1 | awk '{print $(NF-1)*0.4/1024}'" - ); - } - $name = __('InnoDB buffer pool size'); $value = ($item['Value'] / $mega); - $status = (($item['Value'] / $bytes) >= $min) ? 1 : 0; - $message = __('Min. Recommended Value').' '.$min; + $status = (($item['Value'] / $mega) >= 250) ? 1 : 0; + $message = __( + 'It has to be 40% of the server memory not recommended to be greater or less' + ); break; case 'sort_buffer_size': @@ -634,22 +756,22 @@ class Diagnostics case 'query_cache_size': $name = __('Query cache size'); $value = ($item['Value'] / $bytes); - $status = (($item['Value'] / $bytes) >= 24) ? 1 : 0; - $message = __('Min. Recommended Value').' 24'; + $status = (($item['Value'] / $bytes) >= 32) ? 1 : 0; + $message = __('Min. Recommended Value').' 32MB'; break; case 'query_cache_limit': $name = __('Query cache limit'); $value = ($item['Value'] / $bytes); - $status = (($item['Value'] / $bytes) >= 2) ? 1 : 0; - $message = __('Min. Recommended Value').' 2'; + $status = (($item['Value'] / $bytes) >= 256) ? 1 : 0; + $message = __('Min. Recommended Value').' 256K'; break; case 'innodb_lock_wait_timeout': $name = __('InnoDB lock wait timeout'); $value = $item['Value']; - $status = (($item['Value'] / $bytes) >= 120) ? 1 : 0; - $message = __('Min. Recommended Value').' 120'; + $status = (($item['Value'] / $bytes) >= 90) ? 1 : 0; + $message = __('Min. Recommended Value').' 90s'; break; case 'thread_cache_size': @@ -663,14 +785,14 @@ class Diagnostics $name = __('Thread stack'); $value = ($item['Value'] / $bytes); $status = (($item['Value'] / $bytes) >= 256) ? 1 : 0; - $message = __('Min. Recommended Value').' 256'; + $message = __('Min. Recommended Value').' 256K'; break; case 'max_connections': $name = __('Maximun connections'); $value = $item['Value']; - $status = (($item['Value'] / $bytes) >= 150) ? 1 : 0; - $message = __('Min. Recommended Value').' 150'; + $status = (($item['Value'] / $bytes) >= 90) ? 1 : 0; + $message = __('Min. Recommended Value').' 90'; break; case 'key_buffer_size': @@ -698,14 +820,14 @@ class Diagnostics $name = __('Query cache min-res-unit'); $value = ($item['Value'] / $bytes); $status = (($item['Value'] / $bytes) >= 2) ? 1 : 0; - $message = __('Min. Recommended Value').' 2'; + $message = __('Min. Recommended Value').' 2k'; break; case 'innodb_file_per_table': $name = __('InnoDB file per table'); $value = $item['Value']; - $status = (($item['Value'] / $bytes) >= 1) ? 1 : 0; - $message = __('Min. Recommended Value').' 1'; + $status = ($item['Value'] === 'ON') ? 1 : 0; + $message = __('Recommended ON'); break; default: @@ -912,10 +1034,15 @@ class Diagnostics WHERE id_tipo_modulo BETWEEN 6 AND 18' ); - $averageTime = number_format( - ((int) $totalModuleIntervalTime / (int) $totalNetworkModules), - 3 - ); + + $averageTime = 0; + if ($totalModuleIntervalTime !== false) { + $averageTime = number_format( + ((int) $totalModuleIntervalTime / (int) $totalNetworkModules), + 3 + ); + } + $moduleNetworkmsg = __( sprintf( 'The system is not overloaded (average time %d)', @@ -1075,32 +1202,18 @@ class Diagnostics $taStatus = 1; } - /* - $times = db_get_all_rows_sql('SELECT datos FROM tagente_datos WHERE id_agente_modulo = 29 ORDER BY utimestamp DESC LIMIT 2'); - hd($times); - if ($times[0]['datos'] > ($times[1]['datos'] * 1.2)) { - __('The execution time could be degrading. For a more extensive information of this data consult the Execution Time graph'); - } else { - __('The execution time is correct. For more information about this data, check the Execution Time graph'); - } - */ - $result = [ 'error' => false, 'data' => [ - 'agentDataCount' => [ + 'agentDataCount' => [ 'name' => __('Total data in tagente_datos table'), 'value' => $agentDataCount, ], - 'agentDataStatus' => [ + 'agentDataStatus' => [ 'name' => __('Tagente_datos table status'), 'value' => $taMsg, 'status' => $taStatus, ], - 'agentDataExecution' => [ - 'name' => __('Execution time degradation when executing a count'), - 'value' => 1, - ], ], ]; @@ -1117,6 +1230,10 @@ class Diagnostics { global $config; + if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { + return []; + } + $totalServerThreads = shell_exec( 'ps -T aux | grep pandora_server | grep -v grep | wc -l' ); @@ -1130,7 +1247,7 @@ class Diagnostics $result = [ 'error' => false, 'data' => [ - 'totalServerThreads' => [ + [ 'name' => __('Total server threads'), 'value' => $totalServerThreads, ], @@ -1150,17 +1267,252 @@ class Diagnostics /** - * Paint table. + * Agent Id whit name is equal to Server Name. * - * @param string $statusInfo Json width status info. - * - * @return void + * @return integer Id agent module. */ - public function printTable(string $statusInfo): void + public function getAgentIdMasterServer(): int { global $config; - hd($statusInfo); + $serverName = db_get_value_sql( + 'SELECT `name` + FROM tserver + WHERE `name` IS NOT NULL + AND `master` > 0 + ORDER BY `master` DESC' + ); + $agentId = (int) db_get_value_sql( + sprintf( + 'SELECT id_agente + FROM tagente + WHERE nombre = "%s"', + $serverName + ) + ); + + if (isset($agentId) === false || is_numeric($agentId) === false) { + $agentId = 0; + } + + return $agentId; + } + + + /** + * Graph. + * + * @param integer $id Id agent. + * @param string $name Name module. + * @param boolean $image Chart interactive or only image. + * @param boolean $base64 Image or base64. + * + * @return string + */ + public function getChart( + int $id, + string $name, + bool $image=false, + bool $base64=false + ): string { + global $config; + + include_once $config['homedir'].'/include/functions_graph.php'; + $data = modules_get_agentmodule_id($name, $id); + $params = [ + 'agent_module_id' => $data['id_agente_modulo'], + 'period' => SECONDS_1MONTH, + 'date' => time(), + 'height' => '200', + 'only_image' => $image, + 'return_img_base_64' => $base64, + ]; + + return grafico_modulo_sparse($params); + } + + + /** + * Check pandoradb installed. + * + * @return string + */ + public function checkPandoraDB(): string + { + global $config; + $result = ''; + + if (isset($config['db_maintenance']) === false) { + $result .= '(*) '; + $result .= __( + 'Please check your Pandora Server setup and make sure that the database maintenance daemon is running.' + ); + $result .= ' '; + $result .= __( + 'It\' is very important to keep the database up-to-date to get the best performance and results in Pandora' + ); + } + + return $result; + } + + + /** + * Draw table. + * + * @param string $method Method. + * @param string $title Title. + * + * @return void + */ + public function printData(string $method, string $title): void + { + global $config; + + if (is_ajax()) { + // TODO: Call method. + echo $method; + } else { + // Datatables list. + try { + $columns = [ + [ + 'class' => 'datatables-td-title', + 'text' => 'name', + ], + [ + 'class' => 'datatables-td-max', + 'text' => 'value', + ], + 'message', + ]; + + $columnNames = [ + [ + 'style' => 'display:none;', + 'text' => '', + ], + [ + 'style' => 'display:none', + 'text' => '', + ], + [ + 'style' => 'display:none', + 'text' => '', + ], + ]; + + $tableId = $method.'_'.uniqid(); + // Load datatables user interface. + ui_print_datatable( + [ + 'id' => $tableId, + 'class' => 'info_table caption_table', + 'style' => 'width: 100%', + 'columns' => $columns, + 'column_names' => $columnNames, + 'ajax_data' => [ + 'method' => 'datatablesDraw', + 'name' => $method, + ], + 'ajax_url' => $this->ajaxController, + 'paging' => 0, + 'no_sortable_columns' => [-1], + 'caption' => $title, + ] + ); + } catch (Exception $e) { + echo $e->getMessage(); + } + } + } + + + /** + * Prepare params for getCarts. + * + * @return void + */ + public function getChartAjax():void + { + global $config; + + $params = json_decode( + io_safe_output(get_parameter('params', '')), + true + ); + + $return = ''; + if (isset($params['idAgent']) === true + && empty($params['idAgent']) === false + && isset($params['nameModule']) + && empty($params['nameModule']) === false + ) { + $return = $this->getChart( + $params['idAgent'], + $params['nameModule'] + ); + } + + exit($return); + } + + + /** + * Paint table with charts. + * + * @param array $params Info charts. + * + * @return void + */ + public function printDataCharts(array $params): void + { + global $config; + + if (!$params) { + $params = get_parameter('params'); + } + + if (is_ajax()) { + // TODO: Call method. + echo $method; + } else { + // Datatables list. + try { + $id = str_replace( + ' ', + '', + io_safe_output($params['nameModule']) + ); + echo '
'; + $settings = [ + 'type' => 'POST', + 'dataType' => 'html', + 'url' => ui_get_full_url( + 'ajax.php', + false, + false, + false + ), + 'data' => [ + 'page' => $this->ajaxController, + 'method' => 'getChartAjax', + 'params' => json_encode($params), + ], + ]; + + ?> + + getMessage(); + } + } } @@ -1209,4 +1561,107 @@ class Diagnostics } + /** + * Transforms a json object into a Datatables format. + * + * @return void + */ + public function datatablesDraw() + { + $method = get_parameter('name', ''); + if (method_exists($this, $method) === true) { + $data = json_decode($this->{$method}(), true); + } + + if (isset($data) === true && is_array($data) === true) { + $items = $data['data']; + $dataReduce = array_reduce( + array_keys($data['data']), + function ($carry, $key) use ($items) { + // Transforms array of arrays $data into an array + // of objects, making a post-process of certain fields. + if (isset($items[$key]['status']) === true) { + $acumValue = $items[$key]['value']; + if ($items[$key]['status'] === 1) { + $items[$key]['value'] = html_print_image( + 'images/exito.png', + true, + [ + 'title' => __('Succesfuly'), + 'style' => 'width:15px;', + ] + ); + } else { + $items[$key]['value'] = html_print_image( + 'images/error_1.png', + true, + [ + 'title' => __('Error'), + 'style' => 'width:15px;', + ] + ); + } + + $items[$key]['value'] .= ' '.$acumValue; + } + + // FIX for customer key. + if ($key === 'customerKey') { + $spanValue = ''.$items[$key]['value'].''; + $items[$key]['value'] = $spanValue; + } + + if (isset($items[$key]['message']) === false) { + $items[$key]['message'] = ''; + } + + $carry[] = (object) $items[$key]; + return $carry; + } + ); + } + + // Datatables format: RecordsTotal && recordsfiltered. + echo json_encode( + [ + 'data' => $dataReduce, + 'recordsTotal' => count($dataReduce), + 'recordsFiltered' => count($dataReduce), + ] + ); + } + + + /** + * Transforms a json object into a Datatables format. + * + * @return void + */ + public function exportPDF() + { + // TODO: TO BE CONTINUED. + $pdf = new PDFTranslator(); + + // Set font from font defined in report. + $pdf->custom_font = $report['custom_font']; + + $product_name = io_safe_output(get_product_name()); + $pdf->setMetadata( + __('Diagnostics Info'), + $product_name.' Enteprise', + $product_name, + __('Automated %s report for user defined report', $product_name) + ); + + $filename = ''; + + if ($filename !== '') { + $pdfObject->writePDFfile($filename); + } else { + $pdfObject->showPDF(); + } + + } + + } diff --git a/pandora_console/include/functions.php b/pandora_console/include/functions.php index 70eb7b8728..4ce47bac09 100644 --- a/pandora_console/include/functions.php +++ b/pandora_console/include/functions.php @@ -3881,11 +3881,11 @@ function generator_chart_to_pdf($type_graph_pdf, $params, $params_combined=false $img_content = join("\n", $result); if ($params['return_img_base_64']) { - // To be used in alerts + // To be used in alerts. $width_img = 500; return $img_content; } else { - // to be used in PDF files + // to be used in PDF files. $config['temp_images'][] = $img_path; return ''; } diff --git a/pandora_console/include/functions_ui.php b/pandora_console/include/functions_ui.php index 577e8e11ff..0c20dcafe8 100755 --- a/pandora_console/include/functions_ui.php +++ b/pandora_console/include/functions_ui.php @@ -2996,6 +2996,10 @@ function ui_print_datatable(array $parameters) $parameters['default_pagination'] = $config['block_size']; } + if (!isset($parameters['paging'])) { + $parameters['paging'] = true; + } + $no_sortable_columns = []; if (isset($parameters['no_sortable_columns'])) { $no_sortable_columns = json_encode($parameters['no_sortable_columns']); @@ -3156,7 +3160,7 @@ function ui_print_datatable(array $parameters) $table = ''; - $table .= ''; + $table .= ''; if (isset($parameters['column_names']) && is_array($parameters['column_names']) @@ -3205,7 +3209,7 @@ function ui_print_datatable(array $parameters) }, processing: true, serverSide: true, - paging: true, + paging: '.$parameters['paging'].', pageLength: '.$parameters['default_pagination'].', searching: false, responsive: true, @@ -3305,10 +3309,18 @@ function ui_print_datatable(array $parameters) $("#'.$form_id.'_search_bt").click(function (){ dt_'.$table_id.'.draw().page(0) - }); - }); + });'; -'; + if (isset($parameters['caption']) === true + && empty($parameters['caption']) === false + ) { + $js .= '$("#'.$table_id.'").append("");'; + $js .= '$(".datatables_thead_tr").css("height", 0);'; + } + + $js .= '});'; + + $js .= ''; // Order. $err_msg = '
'; diff --git a/pandora_console/include/javascript/pandora.js b/pandora_console/include/javascript/pandora.js index 33ab956a1f..b38ff66a30 100644 --- a/pandora_console/include/javascript/pandora.js +++ b/pandora_console/include/javascript/pandora.js @@ -1,3 +1,6 @@ +/* global $ */ +/* exported load_modal */ + var ENTERPRISE_DIR = "enterprise"; /* Function to hide/unhide a specific Div id */ @@ -1872,8 +1875,6 @@ function logo_preview(icon_name, icon_path, incoming_options) { } // Advanced Form control. -/* global $ */ -/* exported load_modal */ function load_modal(settings) { var AJAX_RUNNING = 0; var data = new FormData(); @@ -1987,3 +1988,23 @@ function load_modal(settings) { } }); } + +/** + * Function for AJAX request. + * + * @param {string} id Id container append data. + * @param {json} settings Json with settings. + * + * @return {void} + */ +function ajaxRequest(id, settings) { + $.ajax({ + type: settings.type, + dataType: settings.html, + url: settings.url, + data: settings.data, + success: function(data) { + $("#" + id).append(data); + } + }); +} diff --git a/pandora_console/include/styles/pandora.css b/pandora_console/include/styles/pandora.css index 459cc5c54d..71afe6b6f3 100644 --- a/pandora_console/include/styles/pandora.css +++ b/pandora_console/include/styles/pandora.css @@ -5903,3 +5903,49 @@ table.table_modal_alternate tr td:first-child { .flot-text { width: 101%; } + +.title-self-monitoring, +.caption_table caption { + text-align: center; + font-size: 1.5em; + font-weight: bolder; + color: #fff; + background: #282828; + padding: 8px; +} + +.datatables-td-title { + width: 25% !important; + font-weight: bolder; +} + +.datatables-td-max { + display: flex; + flex-direction: row; + flex-wrap: wrap; +} + +.datatables-td-max img { + margin-right: 10px; +} + +.datatables-td-max span { + width: 400px; + display: inline-block; + word-wrap: break-word; +} + +.container-self-monitoring { + display: flex; + flex-direction: row; + flex-wrap: wrap; +} + +.element-self-monitoring { + flex: 2 1 600px; +} + +.footer-self-monitoring { + margin: 30px; + font-style: italic; +} From 353246f9f6d4e54224db03f70554a4c648ee1606 Mon Sep 17 00:00:00 2001 From: marcos Date: Fri, 18 Oct 2019 10:30:19 +0200 Subject: [PATCH 25/81] first changed to welcome window --- .../new_installation_welcome_window.php | 77 ++++ pandora_console/general/register.php | 12 + .../godmode/wizards/Wizard.main.php | 67 ++- .../NewInstallationWelcomeWindow.class.php | 423 ++++++++++++++++++ pandora_console/include/javascript/pandora.js | 127 +++--- .../new_installation_welcome_window.css | 144 ++++++ 6 files changed, 780 insertions(+), 70 deletions(-) create mode 100644 pandora_console/general/new_installation_welcome_window.php create mode 100644 pandora_console/include/class/NewInstallationWelcomeWindow.class.php create mode 100644 pandora_console/include/styles/new_installation_welcome_window.css diff --git a/pandora_console/general/new_installation_welcome_window.php b/pandora_console/general/new_installation_welcome_window.php new file mode 100644 index 0000000000..5509292bc9 --- /dev/null +++ b/pandora_console/general/new_installation_welcome_window.php @@ -0,0 +1,77 @@ + '[NewInstallationWelcomeWindow]'.$e->getMessage() ]); + exit; + } else { + echo '[NewInstallationWelcomeWindow]'.$e->getMessage(); + } + + // Stop this execution, but continue 'globally'. + return; +} + +// Ajax controller. +if (is_ajax()) { + $method = get_parameter('method', ''); + + if (method_exists($welcome_actions, $method) === true) { + if ($welcome_actions->ajaxMethod($method) === true) { + $welcome_actions->{$method}(); + } else { + $welcome_actions->error('Unavailable method.'); + } + } else { + $welcome_actions->error('Method not found. ['.$method.']'); + } + + + // Stop any execution. + exit; +} else { + // Run. + $welcome_actions->run(); +} diff --git a/pandora_console/general/register.php b/pandora_console/general/register.php index b1d58aada4..a938e4983d 100644 --- a/pandora_console/general/register.php +++ b/pandora_console/general/register.php @@ -30,6 +30,7 @@ global $config; require_once $config['homedir'].'/include/functions_update_manager.php'; +require_once $config['homedir'].'/include/class/NewInstallationWelcomeWindow.class.php'; if (is_ajax()) { @@ -122,6 +123,8 @@ if (is_ajax()) { exit(); } + + ui_require_css_file('register'); $initial = isset($config['initial_wizard']) !== true @@ -170,6 +173,15 @@ if (!$config['disabled_newsletter']) { } } +$welcome = !$registration && $initial; +$welcome = true; +if ($welcome && users_is_admin()) { + $welcome = new NewInstallationWelcomeWindow( + 'general/new_installation_welcome_window' + ); + $welcome->run(); +} + $newsletter = null; ?> diff --git a/pandora_console/godmode/wizards/Wizard.main.php b/pandora_console/godmode/wizards/Wizard.main.php index cb29d78c06..5ffeb716d9 100644 --- a/pandora_console/godmode/wizards/Wizard.main.php +++ b/pandora_console/godmode/wizards/Wizard.main.php @@ -404,13 +404,42 @@ class Wizard /** * Print a block of inputs. + * Example, using direct to 'anidate' inputs directly to wrapper: + * [ + * 'wrapper' => 'div', + * 'block_id' => 'example_id', + * 'class' => 'your class', + * 'direct' => 1, + * 'block_content' => [ + * [ + * 'arguments' => [ + * 'label' => __('Sugesstion'), + * 'type' => 'button', + * 'attributes' => 'class="sub ok btn_sug"', + * 'name' => 'option_1', + * 'id' => 'option_1', + * 'script' => 'change_option1()', + * ], + * ], + * [ + * 'arguments' => [ + * 'label' => __('Something is not quite right'), + * 'type' => 'button', + * 'attributes' => 'class="sub ok btn_something"', + * 'name' => 'option_2', + * 'id' => 'option_2', + * 'script' => 'change_option2()', + * ], + * ], + * ], + * ]. * * @param array $input Definition of target block to be printed. * @param boolean $return Return as string or direct output. * * @return string HTML content. */ - public function printBlock(array $input, bool $return=false) + public function printBlock(array $input, bool $return=false, bool $not_direct=false) { $output = ''; if ($input['hidden'] == 1) { @@ -424,33 +453,47 @@ class Wizard } if (is_array($input['block_content']) === true) { + $not_direct = (bool) $input['direct']; + // Print independent block of inputs. + $output .= '
  • '; + if ($input['wrapper']) { - $output .= '
  • '; $output .= '<'.$input['wrapper'].' id="'.$input['block_id'].'" class="'.$class.'">'; - } else { - $output .= '
  • '; } - $output .= '
      '; + if (!$not_direct) { + // Avoid encapsulation if input is direct => 1. + $output .= '
        '; + } + foreach ($input['block_content'] as $input) { - $output .= $this->printBlock($input, $return); + $output .= $this->printBlock($input, $return, (bool) $not_direct); } // Close block. - if ($input['wrapper']) { - $output .= '
      '; - } else { - $output .= '
  • '; + if (!$not_direct) { + $output .= ''; } + + if ($input['wrapper']) { + $output .= ''; + } + + $output .= ''; } else { if ($input['arguments']['type'] != 'hidden') { - $output .= '
  • '; + if (!$not_direct) { + $output .= '
  • '; + } + $output .= ''; $output .= $this->printInput($input['arguments']); // Allow dynamic content. $output .= $input['extra']; - $output .= '
  • '; + if (!$not_direct) { + $output .= ''; + } } else { $output .= $this->printInput($input['arguments']); // Allow dynamic content. diff --git a/pandora_console/include/class/NewInstallationWelcomeWindow.class.php b/pandora_console/include/class/NewInstallationWelcomeWindow.class.php new file mode 100644 index 0000000000..9f4f0202f5 --- /dev/null +++ b/pandora_console/include/class/NewInstallationWelcomeWindow.class.php @@ -0,0 +1,423 @@ + 'noaccess']); + } + + include 'general/noaccess.php'; + exit; + } + + return in_array($method, $this->AJAXMethods); + } + + + /** + * Constructor. + * + * @param string $ajax_controller Controller. + * + * @return object + */ + public function __construct($ajax_controller) + { + $this->ajaxController = $ajax_controller; + return $this; + } + + + /** + * Main method. + * + * @return void + */ + public function run() + { + ui_require_css_file('new_installation_welcome_window'); + + echo ''; + // Button for feedback pandora. + if (enterprise_installed()) { + $header_feedback = '
    '; + $header_feedback .= ''; + $header_feedback .= html_print_image( + '/images/icono_warning.png', + true, + [ + 'title' => __('Feedback'), + 'id' => 'feedback-header', + 'alt' => __('Feedback'), + 'style' => 'cursor: pointer; width: 28px;', + ] + ); + $header_feedback .= '
    '; + } + // Support. - if (defined('PANDORA_ENTERPRISE')) { + if (enterprise_installed()) { $header_support_link = 'https://support.artica.es/'; } else { $header_support_link = 'https://pandorafms.com/forums/'; @@ -388,9 +405,9 @@ if ($config['menu_type'] == 'classic') { echo '
    '.$config['custom_title_header'].''.$config['custom_subtitle_header'].'
    '.$header_searchbar.'
    -
    '.$header_chat, $header_autorefresh, $header_autorefresh_counter, $header_discovery, $servers_list, $header_support, $header_docu, $header_user, $header_logout.'
    '; +
    '.$header_chat, $header_autorefresh, $header_autorefresh_counter, $header_discovery, $servers_list, $header_feedback, $header_support, $header_docu, $header_user, $header_logout.'
    '; ?> - + @@ -612,6 +629,44 @@ if ($config['menu_type'] == 'classic') { var fixed_header = ; var new_chat = ; + + /** + * Loads modal from AJAX to add feedback. + */ + function show_feedback() { + + var btn_ok_text = ''; + var btn_cancel_text = ''; + var title = ''; + var url = ''; + + console.log('entra'); + + load_modal({ + target: $('#modal-feedback-form'), + form: 'modal_form_feedback', + url: '', + modal: { + title: title, + ok: btn_ok_text, + cancel: btn_cancel_text, + }, + onshow: { + page: url, + method: 'formFeedback', + }, + onsubmit: { + page: url, + method: 'createdScheduleFeedbackTask', + } + }); + + } + $(document).ready (function () { // Check new notifications on a periodic way @@ -661,7 +716,12 @@ if ($config['menu_type'] == 'classic') { $("#ui_close_dialog_titlebar").click(function () { $("#agent_access").css("display",""); }); - + + // Feedback. + $("#feedback-header").click(function () { + show_feedback(); + }); + function blinkpubli(){ $(".publienterprise").delay(100).fadeTo(300,0.2).delay(100).fadeTo(300,1, blinkpubli); } diff --git a/pandora_console/include/class/Diagnostics.class.php b/pandora_console/include/class/Diagnostics.class.php index afb41c016b..9a5cc4190a 100644 --- a/pandora_console/include/class/Diagnostics.class.php +++ b/pandora_console/include/class/Diagnostics.class.php @@ -30,11 +30,12 @@ global $config; require_once $config['homedir'].'/include/functions_db.php'; require_once $config['homedir'].'/include/functions_io.php'; +require_once $config['homedir'].'/godmode/wizards/Wizard.main.php'; /** * Base class Diagnostics. */ -class Diagnostics +class Diagnostics extends Wizard { /** @@ -44,15 +45,21 @@ class Diagnostics */ public $ajaxController; + /** + * Print Html or Pdf view. + * + * @var boolean + */ + public $pdf; + /** - * Constructor + * Constructor. * - * @param string $page Page. - * - * @return void + * @param string $page Page. + * @param boolean $pdf PDF View. */ - public function __construct(string $page) + public function __construct(string $page, bool $pdf) { global $config; @@ -75,6 +82,7 @@ class Diagnostics } $this->ajaxController = $page; + $this->pdf = $pdf; } @@ -99,6 +107,8 @@ class Diagnostics 'getServerThreads', 'datatablesDraw', 'getChartAjax', + 'formFeedback', + 'createdScheduleFeedbackTask', ]; @@ -165,23 +175,58 @@ class Diagnostics true ); - /* - * Info status pandoraFms. - * PHP setup. - * Database size stats. - * Database health status. - * Database status info. - * System Info. - * MySQL Performance metrics. - * Tables fragmentation in the Pandora FMS database. - * Pandora FMS logs dates. - * Pandora FMS Licence Information. - * Status of the attachment folder. - * Information from the tagente_datos table. - * Pandora FMS server threads. - */ + // Print all Methods Diagnostic Info. + echo $this->printMethodsDiagnostigsInfo(); - foreach ($this->AJAXMethods as $key => $method) { + // Print all charts Monitoring. + echo $this->printCharts(); + + echo ''; + + } + + + /** + * Print Methods: + * Info status pandoraFms. + * PHP setup. + * Database size stats. + * Database health status. + * Database status info. + * System Info. + * MySQL Performance metrics. + * Tables fragmentation in the Pandora FMS database. + * Pandora FMS logs dates. + * Pandora FMS Licence Information. + * Status of the attachment folder. + * Information from the tagente_datos table. + * Pandora FMS server threads. + * + * @return string Html. + */ + public function printMethodsDiagnostigsInfo():string + { + $infoMethods = [ + 'getStatusInfo', + 'getPHPSetup', + 'getDatabaseSizeStats', + 'getDatabaseHealthStatus', + 'getDatabaseStatusInfo', + 'getSystemInfo', + 'getMySQLPerformanceMetrics', + 'getTablesFragmentation', + 'getPandoraFMSLogsDates', + 'getLicenceInformation', + 'getAttachmentFolder', + 'getInfoTagenteDatos', + 'getServerThreads', + ]; + + $return = ''; + + foreach ($infoMethods as $key => $method) { switch ($method) { case 'getStatusInfo': $title = __('Info status pandoraFms'); @@ -243,19 +288,37 @@ class Diagnostics break; } - if ($method !== 'datatablesDraw' && $method !== 'getChartAjax') { - echo '
    '; - $this->printData($method, $title); - echo '
    '; - } + $return .= '
    '; + $return .= $this->printData($method, $title); + $return .= '
    '; } + return $return; + } + + + /** + * Print table graps: + * Graph of the Agents Unknown module. + * Graph of the Database Maintenance module. + * Graph of the Free Disk Spool Dir module. + * Graph of the Free RAM module. + * Graph of the Queued Modules module. + * Graph of the Status module. + * Graph of the System Load AVG module. + * Graph of the Execution Time module. + * + * @return string + */ + public function printCharts() + { /* * Agent id with name Master Server. */ $agentIdMasterServer = $this->getAgentIdMasterServer(); + $result = ''; if ($agentIdMasterServer !== 0) { $agentMonitoring = [ 'chartAgentsUnknown' => [ @@ -312,33 +375,18 @@ class Diagnostics ], ]; - /* - * Print table graps: - * Graph of the Agents Unknown module. - * Graph of the Database Maintenance module. - * Graph of the Free Disk Spool Dir module. - * Graph of the Free RAM module. - * Graph of the Queued Modules module. - * Graph of the Status module. - * Graph of the System Load AVG module. - * Graph of the Execution Time module. - */ - - echo '
    '; - echo __('Graphs modules that represent the self-monitoring system'); - echo '
    '; - echo '
    '; + $return .= '
    '; + $return .= __('Graphs modules that represent the self-monitoring system'); + $return .= '
    '; + $return .= '
    '; foreach ($agentMonitoring as $key => $value) { - $this->printDataCharts($value); + $return .= $this->printDataCharts($value); } - echo '
    '; + $return .= '
    '; } - echo ''; - + return $return; } @@ -1366,15 +1414,15 @@ class Diagnostics * @param string $method Method. * @param string $title Title. * - * @return void + * @return string Return html. */ - public function printData(string $method, string $title): void + public function printData(string $method, string $title): string { global $config; if (is_ajax()) { // TODO: Call method. - echo $method; + $result = $method; } else { // Datatables list. try { @@ -1407,27 +1455,57 @@ class Diagnostics $tableId = $method.'_'.uniqid(); // Load datatables user interface. - ui_print_datatable( - [ - 'id' => $tableId, - 'class' => 'info_table caption_table', - 'style' => 'width: 100%', - 'columns' => $columns, - 'column_names' => $columnNames, - 'ajax_data' => [ - 'method' => 'datatablesDraw', - 'name' => $method, - ], - 'ajax_url' => $this->ajaxController, - 'paging' => 0, - 'no_sortable_columns' => [-1], - 'caption' => $title, - ] - ); + if ($this->pdf === false) { + $result = ui_print_datatable( + [ + 'id' => $tableId, + 'class' => 'info_table caption_table', + 'style' => 'width: 100%', + 'columns' => $columns, + 'column_names' => $columnNames, + 'ajax_data' => [ + 'method' => 'datatablesDraw', + 'name' => $method, + ], + 'ajax_url' => $this->ajaxController, + 'paging' => 0, + 'no_sortable_columns' => [-1], + 'caption' => $title, + 'print' => true, + ] + ); + } else { + $data = json_decode( + $this->datatablesDraw($method, true), + true + ); + + $table = new stdClass(); + $table->width = '100%'; + $table->class = ''; + $table->head = []; + $table->head_colspan[0] = 3; + $table->head[0] = $title; + $table->data = []; + + if (isset($data) === true && is_array($data) === true) { + $i = 0; + foreach ($data['data'] as $key => $value) { + $table->data[$i][0] = $value['name']; + $table->data[$i][1] = $value['value']; + $table->data[$i][2] = $value['message']; + $i++; + } + } + + $result = html_print_table($table, true); + } } catch (Exception $e) { - echo $e->getMessage(); + $result = $e->getMessage(); } } + + return $result; } @@ -1466,9 +1544,9 @@ class Diagnostics * * @param array $params Info charts. * - * @return void + * @return string Html. */ - public function printDataCharts(array $params): void + public function printDataCharts(array $params): string { global $config; @@ -1478,7 +1556,7 @@ class Diagnostics if (is_ajax()) { // TODO: Call method. - echo $method; + $return = $method; } else { // Datatables list. try { @@ -1487,35 +1565,49 @@ class Diagnostics '', io_safe_output($params['nameModule']) ); - echo '
    '; - $settings = [ - 'type' => 'POST', - 'dataType' => 'html', - 'url' => ui_get_full_url( - 'ajax.php', - false, - false, - false - ), - 'data' => [ - 'page' => $this->ajaxController, - 'method' => 'getChartAjax', - 'params' => json_encode($params), - ], - ]; - ?> - - pdf === false) { + $return = '
    '; + $settings = [ + 'type' => 'POST', + 'dataType' => 'html', + 'url' => ui_get_full_url( + 'ajax.php', + false, + false, + false + ), + 'data' => [ + 'page' => $this->ajaxController, + 'method' => 'getChartAjax', + 'params' => json_encode($params), + ], + ]; + + ?> + + '; + $return .= $this->getChart( + $params['idAgent'], + $params['nameModule'], + true, + false + ); + $return .= ''; + } } catch (Exception $e) { - echo $e->getMessage(); + $return = $e->getMessage(); } } + + return $return; } @@ -1565,13 +1657,21 @@ class Diagnostics /** - * Transforms a json object into a Datatables format. + * Undocumented function * - * @return void + * @param string|null $method Method data requested. + * @param boolean $return Type return. + * + * @return string|null */ - public function datatablesDraw() - { - $method = get_parameter('name', ''); + public function datatablesDraw( + ?string $method=null, + bool $return=false + ):?string { + if (isset($method) === false) { + $method = get_parameter('name', ''); + } + if (method_exists($this, $method) === true) { $data = json_decode($this->{$method}(), true); } @@ -1624,34 +1724,162 @@ class Diagnostics ); } - // Datatables format: RecordsTotal && recordsfiltered. - echo json_encode( + $result = json_encode( [ 'data' => $dataReduce, 'recordsTotal' => count($dataReduce), 'recordsFiltered' => count($dataReduce), ] ); + + // Datatables format: RecordsTotal && recordsfiltered. + if ($return === false) { + echo $result; + return null; + } else { + return $result; + } + } + + + public function createdScheduleFeedbackTask() + { + global $config; + + $email = 'daniel.barbero@artica.es'; + $subject = 'PandoraFMS Report '.$config['pandora_uid']; + $text = get_parameter('what-happened', ''); + $type = get_parameter('include-installation-data', ''); + + $idUserTask = db_get_value( + 'id', + 'tuser_task', + 'function_name', + 'cron_task_feedback_send_mail' + ); + + $parameters = [ + 0 => '0', + 1 => $email, + 2 => $subject, + 3 => $text, + 4 => $type, + 'first_execution' => strtotime('now'), + ]; + + $values = [ + 'id_usuario' => $config['id_user'], + 'id_user_task' => $idUserTask, + 'args' => serialize($parameters), + 'scheduled' => 'no', + 'id_grupo' => 0, + ]; + + $result = db_process_sql_insert('tuser_task_scheduled', $values); } /** - * Transforms a json object into a Datatables format. + * Print Diagnostics PDF report. * * @return void */ - public function exportPDF() + public static function exportPDF($filename=false) { global $config; - // TODO: TO BE CONTINUED. enterprise_include_once('/include/class/Pdf.class.php'); $pdf = new Pdf([]); - $pdf->setMetadata('el titulo', 'daniel', 'pepe', 'el sujeto'); - $pdf->setHeaderHTML('esto es el codigo html del header'); - $pdf->writeHTML('esto es el html del contenido'); - $pdf->setFooterHTML('esto es el footer'); - $pdf->writePDFfile(); + $diagnostics = new Diagnostics('tools/diagnostics', true); + $product_name = io_safe_output(get_product_name()); + $pdf->setMetadata( + __('Diagnostics Info'), + $product_name.' Enteprise', + $product_name, + __( + 'Automated %s report for user defined report', + $product_name + ) + ); + $pdf->setHeaderHTML(__('Diagnostics Info')); + + $pdf->addHTML( + $diagnostics->printMethodsDiagnostigsInfo() + ); + + $pdf->addHTML( + $diagnostics->printCharts() + ); + + $pdf->setFooterHTML(); + $pdf->writePDFfile($filename); + } + + + /** + * Print Diagnostics Form feedback. + * + * @return void + */ + public function formFeedback(): void + { + $form = [ + 'action' => '#', + 'id' => 'modal_form_feedback', + 'onsubmit' => 'return false;', + 'class' => 'modal', + ]; + + $inputs = []; + + $inputs[] = [ + 'label' => __('What happened').'?', + 'id' => 'div-what-happened', + 'class' => 'flex-row', + 'arguments' => [ + 'name' => 'what-happened', + 'type' => 'textarea', + 'value' => '', + 'return' => true, + 'rows' => 1, + 'columns' => 1, + 'size' => 25, + ], + ]; + + $inputs[] = [ + 'label' => __('Your email'), + 'class' => 'flex-row-baseline', + 'arguments' => [ + 'name' => 'email', + 'id' => 'email', + 'type' => 'text', + 'return' => true, + 'size' => 40, + ], + ]; + + $inputs[] = [ + 'label' => __('include installation data'), + 'class' => 'flex-row-vcenter', + 'arguments' => [ + 'name' => 'include-installation-data', + 'id' => 'include-installation-data', + 'type' => 'switch', + 'return' => true, + 'value' => 1, + ], + ]; + + exit( + $this->printForm( + [ + 'form' => $form, + 'inputs' => $inputs, + ], + true + ) + ); } diff --git a/pandora_console/include/functions_ui.php b/pandora_console/include/functions_ui.php index 0c20dcafe8..2a264bf0c1 100755 --- a/pandora_console/include/functions_ui.php +++ b/pandora_console/include/functions_ui.php @@ -3336,7 +3336,7 @@ function ui_print_datatable(array $parameters) $output = $include.$output; // Print datatable if needed. - if (!(isset($parameters['print']) && $parameters['print'] === false)) { + if (isset($parameters['print']) === false || $parameters['print'] === false) { echo $output; } diff --git a/pandora_console/include/styles/pandora.css b/pandora_console/include/styles/pandora.css index 71afe6b6f3..06ac52dad8 100644 --- a/pandora_console/include/styles/pandora.css +++ b/pandora_console/include/styles/pandora.css @@ -544,6 +544,13 @@ select:-internal-list-box { align-items: baseline; } +.flex-row-vcenter { + display: flex; + flex-direction: row; + flex-wrap: wrap; + align-items: center; +} + .nowrap { flex-wrap: nowrap; } diff --git a/pandora_console/tools/diagnostics.php b/pandora_console/tools/diagnostics.php index ad97d8b742..30be89efc4 100644 --- a/pandora_console/tools/diagnostics.php +++ b/pandora_console/tools/diagnostics.php @@ -32,11 +32,13 @@ global $config; require_once $config['homedir'].'/include/class/Diagnostics.class.php'; $ajaxPage = 'tools/diagnostics'; +$pdf = false; + // Control call flow. try { // User access and validation is being processed on class constructor. - $cs = new Diagnostics($ajaxPage); + $cs = new Diagnostics($ajaxPage, $pdf); } catch (Exception $e) { if (is_ajax()) { echo json_encode(['error' => '[Diagnostics]'.$e->getMessage() ]); From ee97ed8a5ec96f91e8425846227539d2979b8b9a Mon Sep 17 00:00:00 2001 From: marcos Date: Mon, 21 Oct 2019 18:36:02 +0200 Subject: [PATCH 28/81] segunda ronda --- pandora_console/general/register.php | 10 +- .../godmode/agentes/configurar_agente.php | 4 + .../godmode/agentes/module_manager_editor.php | 3 + .../NewInstallationWelcomeWindow.class.php | 143 ++++++++++++++---- .../new_installation_welcome_window.css | 39 +++-- 5 files changed, 145 insertions(+), 54 deletions(-) diff --git a/pandora_console/general/register.php b/pandora_console/general/register.php index a938e4983d..db92829a2a 100644 --- a/pandora_console/general/register.php +++ b/pandora_console/general/register.php @@ -173,13 +173,9 @@ if (!$config['disabled_newsletter']) { } } -$welcome = !$registration && $initial; -$welcome = true; -if ($welcome && users_is_admin()) { - $welcome = new NewInstallationWelcomeWindow( - 'general/new_installation_welcome_window' - ); - $welcome->run(); +$welcome = !$registration && !$initial; +if ($welcome) { + $welcome = NewInstallationWelcomeWindow::actions_done($welcome); } $newsletter = null; diff --git a/pandora_console/godmode/agentes/configurar_agente.php b/pandora_console/godmode/agentes/configurar_agente.php index 55116f940a..1bbf1384c8 100644 --- a/pandora_console/godmode/agentes/configurar_agente.php +++ b/pandora_console/godmode/agentes/configurar_agente.php @@ -2266,6 +2266,10 @@ if ($updateGIS) { // ----------------------------------- // Load page depending on tab selected // ----------------------------------- +if (!$_SESSION['create_module']) { + $edit_module = true; +} + switch ($tab) { case 'main': include 'agent_manager.php'; diff --git a/pandora_console/godmode/agentes/module_manager_editor.php b/pandora_console/godmode/agentes/module_manager_editor.php index 13c313892a..feb52a945c 100644 --- a/pandora_console/godmode/agentes/module_manager_editor.php +++ b/pandora_console/godmode/agentes/module_manager_editor.php @@ -321,6 +321,9 @@ if ($id_agent_module) { } else { if (!isset($moduletype)) { $moduletype = (string) get_parameter('moduletype'); + if (!$_SESSION['create_module']) { + $moduletype = 'networkserver'; + } // Clean up specific network modules fields $name = ''; diff --git a/pandora_console/include/class/NewInstallationWelcomeWindow.class.php b/pandora_console/include/class/NewInstallationWelcomeWindow.class.php index 9f4f0202f5..7eab288cc6 100644 --- a/pandora_console/include/class/NewInstallationWelcomeWindow.class.php +++ b/pandora_console/include/class/NewInstallationWelcomeWindow.class.php @@ -108,7 +108,7 @@ class NewInstallationWelcomeWindow extends Wizard { ui_require_css_file('new_installation_welcome_window'); - echo '
    '; - echo "'; - echo "'; - echo ''; - } -} - - -function get_value_sum($arr) -{ - foreach ($arr as $clave) { - foreach ($clave as $valor) { - if (is_numeric($valor) === true) { - $result += $valor; - } - } - } - - return $result; -} - - -function execution_time() -{ - $times = db_get_all_rows_sql('SELECT datos FROM tagente_datos WHERE id_agente_modulo = 29 ORDER BY utimestamp DESC LIMIT 2'); - if ($times[0]['datos'] > ($times[1]['datos'] * 1.2)) { - return "Warning Status   The execution time could be degrading. For a more extensive information of this data consult the Execution Time graph"; - } else { - return "Normal Status   The execution time is correct. For more information about this data, check the Execution Time graph"; - } -} - - -function get_logs_size($file) -{ - $file_name = '/var'.$file.''; - $size_server_log = filesize($file_name); - return $size_server_log; - -} - - -function get_status_logs($path) -{ - $status_server_log = ''; - $size_server_log = number_format(get_logs_size($path)); - $size_server_log = (0 + str_replace(',', '', $size_server_log)); - if ($size_server_log <= 10485760) { - $status_server_log = "Normal Status   You have less than 10 MB of logs"; - } else { - $status_server_log = "Warning Status   You have more than 10 MB of logs"; - } - - return $status_server_log; -} - - -function percentage_modules_per_agent() -{ - $status_average_modules = ''; - $total_agents = db_get_value_sql('SELECT count(*) FROM tagente'); - $total_modules = db_get_value_sql('SELECT count(*) FROM tagente_modulo'); - $average_modules_per_agent = ($total_modules / $total_agents); - if ($average_modules_per_agent <= 40) { - $status_average_modules = "Normal Status   The average of modules per agent is less than 40"; - } else { - $status_average_modules = "Warning Status  The average of modules per agent is more than 40. You can have performance problems"; - } - - return $status_average_modules; -} - - -function license_capacity() -{ - $license = enterprise_hook('license_get_info'); - $license_limit = $license['limit']; - $status_license_capacity = ''; - $current_count = db_get_value_sql('SELECT count(*) FROM tagente'); - if ($current_count > ($license_limit * 90 / 100)) { - $status_license_capacity = "Warning Status   License capacity exceeds 90 percent"; - } else { - $status_license_capacity = "Normal Status   License capacity is less than 90 percent"; - } - - return $status_license_capacity; -} - - -function status_license_params($license_param) -{ - $status_license_par = ''; - if ($license_param <= 0) { - $status_license_par = 'OFF'; - } else { - $status_license_par = 'ON'; - } - - return $status_license_par; -} - - -function interval_average_of_network_modules() -{ - $total_network_modules = db_get_value_sql('SELECT count(*) FROM tagente_modulo WHERE id_tipo_modulo BETWEEN 6 AND 18'); - $total_module_interval_time = db_get_value_sql('SELECT SUM(module_interval) FROM tagente_modulo WHERE id_tipo_modulo BETWEEN 6 AND 18'); - $average_time = ((int) $total_module_interval_time / $total_network_modules); - - if ($average_time < 180) { - $status_average_modules = "Warning Status   The system is overloaded (average time $average_time) and a very fine configuration is required"; - } else { - $status_average_modules = "Normal Status   The system is not overloaded (average time $average_time) "; - } - - if ($average_time == 0) { - $status_average_modules = "Normal Status   The system has no load"; - } - - return $status_average_modules; -} - - -$attachment_total_files = count(glob($config['homedir'].'/attachment/{*.*}', GLOB_BRACE)); - - -function files_attachment_folder($total_files) -{ - if ($total_files <= 700) { - $status_total_files = "Normal Status   The attached folder contains less than 700 files."; - } else { - $status_total_files = "Warning Status   The attached folder contains more than 700 files."; - } - - return $status_total_files; -} - - -$tagente_datos_size = db_get_value_sql('SELECT COUNT(*) FROM tagente_datos'); - - -function status_tagente_datos($tagente_datos_size) -{ - if ($tagente_datos_size <= 3000000) { - $tagente_datos_size = "Normal Status   The tagente_datos table contains an acceptable amount of data."; - } else { - $tagente_datos_size = "Warning Status   The tagente_datos table contains too much data. A historical database is recommended."; - } - - return $tagente_datos_size; -} - - -function status_values($val_rec, $val) -{ - if ($val_rec <= $val) { - return $val." (Min. Recommended Value ".$val_rec.')'; - } else { - return $val." (Min. Recommended Value ".$val_rec.") Warning Status"; - } -} - - -$tables_fragmentation = db_get_sql( - "SELECT (data_free/(index_length+data_length)) -as frag_ratio from information_schema.tables where DATA_FREE > 0 and table_name='tagente_datos' and table_schema='pandora'" -); -$db_size = db_get_all_rows_sql( - 'SELECT table_schema, -ROUND(SUM(data_length+index_length)/1024/1024,3) -FROM information_schema.TABLES -GROUP BY table_schema;' -); - -if (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN') { - $total_server_threads = shell_exec('ps -T aux | grep pandora_server | grep -v grep | wc -l'); - $percentage_threads_ram = shell_exec("ps axo pmem,cmd | grep pandora_server | awk '{sum+=$1} END {print sum}'"); - $percentage_threads_cpu = shell_exec("ps axo pcpu,cmd | grep pandora_server | awk '{sum+=$1} END {print sum}'"); - $innodb_buffer_pool_size_min_rec_value = shell_exec("cat /proc/meminfo | grep -i total | head -1 | awk '{print $(NF-1)*0.4/1024}'"); -} - -$path_server_logs = '/log/pandora/pandora_server.log'; -$path_err_logs = '/log/pandora/pandora_server.error'; -$path_console_logs = '/www/html/pandora_console/pandora_console.log'; -$innodb_log_file_size_min_rec_value = '64M'; -$innodb_log_buffer_size_min_rec_value = '16M'; -$innodb_flush_log_at_trx_commit_min_rec_value = 0; -$query_cache_limit_min_rec_value = 2; -$max_allowed_packet_min_rec_value = 32; -$innodb_buffer_pool_size_min_rec_value = shell_exec("cat /proc/meminfo | grep -i total | head -1 | awk '{print $(NF-1)*0.4/1024}'"); -$sort_buffer_size_min_rec_value = 32; -$join_buffer_size_min_rec_value = 265; -$query_cache_type_min_rec_value = 'ON'; -$query_cache_size_min_rec_value = 24; -$innodb_lock_wait_timeout_max_rec_value = 120; -$tables_fragmentation_max_rec_value = 10; -$thread_cache_size_max_rec_value = 8; -$thread_stack_min_rec_value = 256; -$max_connections_max_rec_value = 150; -$key_buffer_size_min_rec_value = 256; -$read_buffer_size_min_rec_value = 32; -$read_rnd_buffer_size_min_rec_value = 32; -$query_cache_min_res_unit_min_rec_value = 2; -$innodb_file_per_table_min_rec_value = 1; - - -function status_fragmentation_tables($tables_fragmentation_max_rec_value, $tables_fragmentation) -{ - $status_tables_frag = ''; - if ($tables_fragmentation > $tables_fragmentation_max_rec_value) { - $status_tables_frag = "Warning Status   Table fragmentation is higher than recommended. They should be defragmented."; - } else { - $status_tables_frag = "Normal Status   Table fragmentation is correct."; - } - - return $status_tables_frag; -} - - -$console_mode = 1; -if (!isset($argc)) { - $console_mode = 0; -} - -if ($console_mode == 1) { - echo "\nPandora FMS PHP diagnostic tool v3.2 (c) Artica ST 2009-2010 \n"; - - if ($argc == 1 || in_array($argv[1], ['--help', '-help', '-h', '-?'])) { - echo "\nThis command line script contains information about Pandora FMS database. - This program can only be executed from the console, and it needs a parameter, the - full path to Pandora FMS 'config.php' file. - - Usage: - php pandora_diag.php path_to_pandora_console - - Example: - php pandora_diag.php /var/www/pandora_console - -"; - exit; - } - - if (preg_match('/[^a-zA-Z0-9_\/\.]|(\/\/)|(\.\.)/', $argv[1])) { - echo "Invalid path: $argv[1]. Always use absolute paths."; - exit; - } - - include $argv[1].'/include/config.php'; -} else { - if (file_exists('../include/config.php')) { - include '../include/config.php'; - } - - // Not from console, this is a web session. - if ((!isset($config['id_user'])) || (!check_acl($config['id_user'], 0, 'PM'))) { - echo "

    You don't have privileges to use diagnostic tool

    "; - echo '

    Please login with an administrator account before try to use this tool

    '; - exit; - } - - // Header. - ui_print_page_header( - __('Pandora FMS Diagnostic tool'), - '', - false, - 'diagnostic_tool_tab', - true - ); - - echo "
    '.$parameters['caption'].'
    ".$label; - echo '
    ".$data; - echo '
    "; - echo "'; -} - -render_row($build_version, 'Pandora FMS Build'); -render_row($pandora_version, 'Pandora FMS Version'); -render_info_data("SELECT value FROM tconfig where token ='MR'", 'Minor Release'); -render_row($config['homedir'], 'Homedir'); -render_row($config['homeurl'], 'HomeUrl'); -render_info_data( - "SELECT `value` - FROM tconfig - WHERE `token` = 'enterprise_installed'", - 'Enterprise installed' -); - - $full_key = db_get_sql( - "SELECT value - FROM tupdate_settings - WHERE `key` = 'customer_key'" - ); - - $compressed_key = substr($full_key, 0, 5).'...'.substr($full_key, -5); - - render_row($compressed_key, 'Update Key'); - - render_info_data( - "SELECT value - FROM tupdate_settings - WHERE `key` = 'updating_code_path'", - 'Updating code path' - ); - - render_info_data( - "SELECT value - FROM tupdate_settings - WHERE `key` = 'current_update'", - 'Current Update #' - ); - - - echo "'; - - - render_row(phpversion(), 'PHP Version'); - - render_row(ini_get('max_execution_time').' seconds', 'PHP Max execution time'); - - render_row(ini_get('max_input_time').' seconds', 'PHP Max input time'); - - render_row(ini_get('memory_limit'), 'PHP Memory limit'); - - render_row(ini_get('session.cookie_lifetime'), 'Session cookie lifetime'); - - echo "'; - - render_info_data('SELECT COUNT(*) FROM tagente', 'Total agents'); - render_info_data('SELECT COUNT(*) FROM tagente_modulo', 'Total modules'); - render_info_data('SELECT COUNT(*) FROM tgrupo', 'Total groups'); - render_info_data('SELECT COUNT(*) FROM tagente_datos', 'Total module data records'); - render_info_data('SELECT COUNT(*) FROM tagent_access', 'Total agent access record'); - render_info_data('SELECT COUNT(*) FROM tevento', 'Total events'); - - if ($config['enterprise_installed']) { - render_info_data('SELECT COUNT(*) FROM ttrap', 'Total traps'); - } - - render_info_data('SELECT COUNT(*) FROM tusuario', 'Total users'); - render_info_data('SELECT COUNT(*) FROM tsesion', 'Total sessions'); - - echo "'; - - render_info_data( - 'SELECT COUNT( DISTINCT tagente.id_agente) - FROM tagente_estado, tagente, tagente_modulo - WHERE tagente.disabled = 0 - AND tagente_modulo.id_agente_modulo = tagente_estado.id_agente_modulo - AND tagente_modulo.disabled = 0 - AND tagente_estado.id_agente = tagente.id_agente - AND tagente_estado.estado = 3', - 'Total unknown agents' - ); - - render_info_data( - 'SELECT COUNT(tagente_estado.estado) - FROM tagente_estado - WHERE tagente_estado.estado = 4', - 'Total not-init modules' - ); - - - $last_run_difference = ''; - - $diferencia = (time() - date( - db_get_sql( - "SELECT `value` - FROM tconfig - WHERE `token` = 'db_maintance'" - ) - )); - - $last_run_difference_months = 0; - $last_run_difference_weeks = 0; - $last_run_difference_days = 0; - $last_run_difference_minutos = 0; - $last_run_difference_seconds = 0; - - while ($diferencia >= 2419200) { - $diferencia -= 2419200; - $last_run_difference_months++; - } - - while ($diferencia >= 604800) { - $diferencia -= 604800; - $last_run_difference_weeks++; - } - - while ($diferencia >= 86400) { - $diferencia -= 86400; - $last_run_difference_days++; - } - - while ($diferencia >= 3600) { - $diferencia -= 3600; - $last_run_difference_hours++; - } - - while ($diferencia >= 60) { - $diferencia -= 60; - $last_run_difference_minutes++; - } - - $last_run_difference_seconds = $diferencia; - - if ($last_run_difference_months > 0) { - $last_run_difference .= $last_run_difference_months.'month/s '; - } - - if ($last_run_difference_weeks > 0) { - $last_run_difference .= $last_run_difference_weeks.' week/s '; - } - - if ($last_run_difference_days > 0) { - $last_run_difference .= $last_run_difference_days.' day/s '; - } - - if ($last_run_difference_hours > 0) { - $last_run_difference .= $last_run_difference_hours.' hour/s '; - } - - if ($last_run_difference_minutes > 0) { - $last_run_difference .= $last_run_difference_minutes.' minute/s '; - } - - $last_run_difference .= $last_run_difference_seconds.' second/s ago'; - - render_row( - date( - 'Y/m/d H:i:s', - db_get_sql( - "SELECT `value` - FROM tconfig - WHERE `token` = 'db_maintance'" - ) - ).' ('.$last_run_difference.')'.' *', - 'PandoraDB Last run' - ); - - echo "'; - - switch ($config['dbtype']) { - case 'mysql': - render_info_data( - "SELECT `value` - FROM tconfig - WHERE `token` = 'db_scheme_first_version'", - 'DB Schema Version (first installed)' - ); - render_info_data( - "SELECT `value` - FROM tconfig - WHERE `token` = 'db_scheme_version'", - 'DB Schema Version (actual)' - ); - render_info_data( - "SELECT `value` - FROM tconfig - WHERE `token` = 'db_scheme_build'", - 'DB Schema Build' - ); - - render_row(get_value_sum($db_size).'M', 'DB Size'); - - - if (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN') { - echo "'; - - $output = 'cat /proc/cpuinfo | grep "model name" | tail -1 | cut -f 2 -d ":"'; - $output2 = 'cat /proc/cpuinfo | grep "processor" | wc -l'; - - render_row(exec($output).' x '.exec($output2), 'CPU'); - - $output = 'cat /proc/meminfo | grep "MemTotal"'; - - render_row(exec($output), 'RAM'); - } - break; - - case 'postgresql': - render_info_data( - "SELECT \"value\" - FROM tconfig - WHERE \"token\" = 'db_scheme_version'", - 'DB Schema Version' - ); - render_info_data( - "SELECT \"value\" - FROM tconfig - WHERE \"token\" = 'db_scheme_build'", - 'DB Schema Build' - ); - render_info_data( - "SELECT \"value\" - FROM tconfig - WHERE \"token\" = 'enterprise_installed'", - 'Enterprise installed' - ); - render_row( - date( - 'Y/m/d H:i:s', - db_get_sql( - "SELECT \"value\" - FROM tconfig WHERE \"token\" = 'db_maintance'" - ) - ), - 'PandoraDB Last run' - ); - - render_info_data( - "SELECT value - FROM tupdate_settings - WHERE \"key\" = 'customer_key';", - 'Update Key' - ); - render_info_data( - "SELECT value - FROM tupdate_settings - WHERE \"key\" = 'updating_code_path'", - 'Updating code path' - ); - render_info_data( - "SELECT value - FROM tupdate_settings - WHERE \"key\" = 'current_update'", - 'Current Update #' - ); - break; - - case 'oracle': - render_info_data( - "SELECT value - FROM tconfig - WHERE token = 'db_scheme_version'", - 'DB Schema Version' - ); - render_info_data( - "SELECT value - FROM tconfig - WHERE token = 'db_scheme_build'", - 'DB Schema Build' - ); - render_info_data( - "SELECT value - FROM tconfig - WHERE token = 'enterprise_installed'", - 'Enterprise installed' - ); - render_row( - db_get_sql( - "SELECT value - FROM tconfig - WHERE token = 'db_maintance'" - ), - 'PandoraDB Last run' - ); - - render_info_data( - 'SELECT '.db_escape_key_identifier('value')." FROM tupdate_settings - WHERE \"key\" = 'customer_key'", - 'Update Key' - ); - render_info_data( - 'SELECT '.db_escape_key_identifier('value')." FROM tupdate_settings - WHERE \"key\" = 'updating_code_path'", - 'Updating code path' - ); - render_info_data( - 'SELECT '.db_escape_key_identifier('value')." FROM tupdate_settings - WHERE \"key\" = 'current_update'", - 'Current Update #' - ); - break; - } - - $innodb_log_file_size = (db_get_value_sql('SELECT @@innodb_log_file_size') / 1048576); - $innodb_log_buffer_size = (db_get_value_sql('SELECT @@innodb_log_buffer_size') / 1048576); - $innodb_flush_log_at_trx_commit = db_get_value_sql('SELECT @@innodb_flush_log_at_trx_commit'); - $max_allowed_packet = (db_get_value_sql('SELECT @@max_allowed_packet') / 1048576); - $innodb_buffer_pool_size = (db_get_value_sql('SELECT @@innodb_buffer_pool_size') / 1024); - $sort_buffer_size = number_format((db_get_value_sql('SELECT @@sort_buffer_size') / 1024), 2); - $join_buffer_size = (db_get_value_sql('SELECT @@join_buffer_size') / 1024); - $query_cache_type = db_get_value_sql('SELECT @@query_cache_type'); - $query_cache_size = (db_get_value_sql('SELECT @@query_cache_size') / 1048576); - $query_cache_limit = (db_get_value_sql('SELECT @@query_cache_limit') / 1048576); - $innodb_lock_wait_timeout = db_get_value_sql('SELECT @@innodb_lock_wait_timeout'); - $thread_cache_size = db_get_value_sql('SELECT @@thread_cache_size'); - $thread_stack = (db_get_value_sql('SELECT @@thread_stack') / 1024); - $max_connections = db_get_value_sql('SELECT @@max_connections'); - $key_buffer_size = (db_get_value_sql('SELECT @@key_buffer_size') / 1024); - $read_buffer_size = (db_get_value_sql('SELECT @@read_buffer_size') / 1024); - $read_rnd_buffer_size = (db_get_value_sql('SELECT @@read_rnd_buffer_size') / 1024); - $query_cache_min_res_unit = (db_get_value_sql('SELECT @@query_cache_min_res_unit') / 1024); - $innodb_file_per_table = db_get_value_sql('SELECT @@innodb_file_per_table'); - echo "'; - - render_row(status_values($innodb_log_file_size_min_rec_value, $innodb_log_file_size), 'InnoDB log file size ', 'InnoDB log file size '); - render_row(status_values($innodb_log_buffer_size_min_rec_value, $innodb_log_buffer_size), 'InnoDB log buffer size ', 'InnoDB log buffer size '); - render_row(status_values($innodb_flush_log_at_trx_commit_min_rec_value, $innodb_flush_log_at_trx_commit), 'InnoDB flush log at trx-commit ', 'InnoDB flush log at trx-commit '); - render_row(status_values($max_allowed_packet_min_rec_value, $max_allowed_packet), 'Maximun allowed packet ', 'Maximun allowed packet '); - render_row(status_values($innodb_buffer_pool_size_min_rec_value, $innodb_buffer_pool_size), 'InnoDB buffer pool size ', 'InnoDB buffer pool size '); - render_row(status_values($sort_buffer_size_min_rec_value, $sort_buffer_size), 'Sort buffer size ', 'Sort buffer size '); - render_row(status_values($join_buffer_size_min_rec_value, $join_buffer_size), 'Join buffer size ', 'Join buffer size '); - render_row(status_values($query_cache_type_min_rec_value, $query_cache_type), 'Query cache type ', 'Query cache type '); - render_row(status_values($query_cache_size_min_rec_value, $query_cache_size), 'Query cache size ', 'Query cache size '); - render_row(status_values($query_cache_limit_min_rec_value, $query_cache_limit), 'Query cache limit ', 'Query cache limit '); - render_row(status_values($innodb_lock_wait_timeout_max_rec_value, $innodb_lock_wait_timeout), 'InnoDB lock wait timeout ', 'InnoDB lock wait timeout '); - render_row(status_values($thread_cache_size_max_rec_value, $thread_cache_size), 'Thread cache size ', 'Thread cache size '); - render_row(status_values($thread_stack_min_rec_value, $thread_stack), 'Thread stack ', 'Thread stack '); - render_row(status_values($max_connections_max_rec_value, $max_connections), 'Maximum connections ', 'Maximun connections '); - render_row(status_values($key_buffer_size_min_rec_value, $key_buffer_size), 'Key buffer size ', 'Key buffer size '); - render_row(status_values($read_buffer_size_min_rec_value, $read_buffer_size), 'Read buffer size ', 'Read buffer size '); - render_row(status_values($read_rnd_buffer_size_min_rec_value, $read_rnd_buffer_size), 'Read rnd-buffer size ', 'Read rnd-buffer size '); - render_row(status_values($query_cache_min_res_unit_min_rec_value, $query_cache_min_res_unit), 'Query cache min-res-unit ', 'Query cache min-res-unit '); - render_row(status_values($innodb_file_per_table_min_rec_value, $innodb_file_per_table), 'InnoDB file per table ', 'InnoDB file per table '); - echo "'; - - - - render_row($tables_fragmentation_max_rec_value.'%', 'Tables fragmentation (maximum recommended value)'); - render_row(number_format($tables_fragmentation, 2).'%', 'Tables fragmentation (current value)'); - render_row(status_fragmentation_tables($tables_fragmentation_max_rec_value, $tables_fragmentation), 'Table fragmentation status'); - - echo "'; - - render_row(number_format((get_logs_size($path_server_logs) / 1048576), 3).'M', 'Size server logs (current value)'); - render_row(get_status_logs($path_server_logs), 'Status server logs'); - render_row(number_format((get_logs_size($path_err_logs) / 1048576), 3).'M', 'Size error logs (current value)'); - render_row(get_status_logs($path_err_logs), 'Status error logs'); - render_row(number_format((get_logs_size($path_console_logs) / 1048576), 3).'M', 'Size console logs (current value)'); - render_row(get_status_logs($path_console_logs), 'Status console logs'); - - echo "'; - - render_row(html_print_textarea('keys[customer_key]', 10, 255, $settings->customer_key, 'style="height:40px; width:450px;"', true), 'Customer key'); - render_row($license['expiry_date'], $license['expiry_caption']); - render_row($license['limit'].' agents', 'Platform Limit'); - render_row($license['count'].' agents', 'Current Platform Count'); - render_row($license['count_enabled'].' agents', 'Current Platform Count (enabled: items)'); - render_row($license['count_disabled'].' agents', 'Current Platform Count (disabled: items)'); - render_row($license['license_mode'], 'License Mode'); - render_row(status_license_params($license['nms']), 'Network Management System'); - render_row(status_license_params($license['dhpm']), 'Satellite'); - render_row($license['licensed_to'], 'Licensed to'); - render_row(license_capacity(), 'Status of agents capacity'); - render_row(percentage_modules_per_agent(), 'Status of average modules per agent'); - render_row(interval_average_of_network_modules(), 'Interval average of the network modules'); - - echo "'; - - render_row($attachment_total_files, 'Total files in the attached folder'); - render_row(files_attachment_folder($attachment_total_files), 'Status of the attachment folder'); - - echo "'; - - render_row($tagente_datos_size, 'Total data in tagente_datos table'); - render_row(status_tagente_datos($tagente_datos_size), 'Tangente_datos table status'); - render_row(execution_time(), 'Execution time degradation when executing a count'); - - echo "'; - - render_row($total_server_threads, 'Total server threads'); - render_row($percentage_threads_ram.'%', 'Percentage of threads used by the RAM'); - render_row($percentage_threads_cpu.'%', 'Percentage of threads used by the CPU'); - - echo "'; - - $server_name = db_get_value_sql('SELECT name FROM tserver WHERE master = 1'); - $agent_id = db_get_value_sql("SELECT id_agente FROM tagente WHERE nombre = '$server_name'"); - - $id_modules = agents_get_modules($agent_id); - - $id_modules = [ - modules_get_agentmodule_id('Agents_Unknown', $agent_id), - modules_get_agentmodule_id('Database Maintenance', $agent_id), - modules_get_agentmodule_id('FreeDisk_SpoolDir', $agent_id), - modules_get_agentmodule_id('Free_RAM', $agent_id), - modules_get_agentmodule_id('Queued_Modules', $agent_id), - modules_get_agentmodule_id('Status', $agent_id), - modules_get_agentmodule_id('System_Load_AVG', $agent_id), - modules_get_agentmodule_id('Execution_time', $agent_id), - ]; - - foreach ($id_modules as $id_module) { - $params = [ - 'agent_module_id' => $id_module['id_agente_modulo'], - 'period' => SECONDS_1MONTH, - 'date' => time(), - 'height' => '150', - ]; - render_row(grafico_modulo_sparse($params), 'Graph of the '.$id_module['nombre'].' module.'); - } - - if ($console_mode == 0) { - echo '
    ".__('Pandora status info').'
    ".__('PHP setup').'
    ".__('Database size stats').'
    ".__('Database sanity').'
    ".__('Database status info').'
    ".__('System info').'
    ".__('MySQL Performance metrics').' '.ui_print_help_icon('performance_metrics_tab', true).'
    ".__('Tables fragmentation in the Pandora FMS database').'
    ".__(' Pandora FMS logs dates').'
    ".__(' Pandora FMS Licence Information').'
    ".__(' Status of the attachment folder').'
    ".__(' Information from the tagente_datos table').'
    ".__(' Pandora FMS server threads').'
    ".__(' Graphs modules that represent the self-monitoring system').'
    '; - } - - echo "
    "; - - echo ''.__( - '(*) Please check your Pandora Server setup and make sure that the database maintenance daemon is running. It\' is very important to - keep the database up-to-date to get the best performance and results in Pandora' - ).'


    '; +// remove file. diff --git a/pandora_console/general/header.php b/pandora_console/general/header.php index fa90cd9659..70978bbcb5 100644 --- a/pandora_console/general/header.php +++ b/pandora_console/general/header.php @@ -332,6 +332,7 @@ if ($config['menu_type'] == 'classic') { if (enterprise_installed()) { $header_feedback = '
    '; $header_feedback .= ''; + $header_feedback .= ''; $header_feedback .= html_print_image( '/images/icono_warning.png', true, @@ -627,7 +628,7 @@ if ($config['menu_type'] == 'classic') { }); var fixed_header = ; - + var new_chat = ; /** @@ -644,8 +645,6 @@ if ($config['menu_type'] == 'classic') { var title = ''; var url = ''; - console.log('entra'); - load_modal({ target: $('#modal-feedback-form'), form: 'modal_form_feedback', @@ -662,9 +661,11 @@ if ($config['menu_type'] == 'classic') { onsubmit: { page: url, method: 'createdScheduleFeedbackTask', - } + dataType: 'json', + }, + ajax_callback: generalShowMsg, + idMsgCallback: 'msg-header', }); - } $(document).ready (function () { @@ -719,6 +720,9 @@ if ($config['menu_type'] == 'classic') { // Feedback. $("#feedback-header").click(function () { + // Clean DOM. + $("#feedback-header").empty(); + // Function charge Modal. show_feedback(); }); diff --git a/pandora_console/include/class/Diagnostics.class.php b/pandora_console/include/class/Diagnostics.class.php index 9a5cc4190a..5fdeafa934 100644 --- a/pandora_console/include/class/Diagnostics.class.php +++ b/pandora_console/include/class/Diagnostics.class.php @@ -59,8 +59,10 @@ class Diagnostics extends Wizard * @param string $page Page. * @param boolean $pdf PDF View. */ - public function __construct(string $page, bool $pdf) - { + public function __construct( + string $page='tools/diagnostics', + bool $pdf=false + ) { global $config; // Check access. @@ -105,6 +107,7 @@ class Diagnostics extends Wizard 'getAttachmentFolder', 'getInfoTagenteDatos', 'getServerThreads', + 'getShowEngine', 'datatablesDraw', 'getChartAjax', 'formFeedback', @@ -134,35 +137,7 @@ class Diagnostics extends Wizard { global $config; - $urlPdf = ui_get_full_url(false, false, false, false); - $urlPdf .= 'enterprise/operation/reporting/reporting_viewer_pdf.php'; - $textPdf = ''; - - $textPdf .= html_print_image( - 'images/pdf.png', - true, - ['title' => __('PDF Report')] - ); - $textPdf .= ''; - - $textCsv = ''; - $textCsv .= html_print_image( - 'images/csv.png', - true, - ['title' => __('Csv Report')] - ); - $textCsv .= ''; - - $buttonsHeader = [ - 'diagnosticsPdf' => [ - 'text' => $textPdf, - 'active' => false, - ], - 'diagnosticsCsv' => [ - 'text' => $textCsv, - 'active' => false, - ], - ]; + ui_require_css_file('diagnostics'); // Header. ui_print_page_header( @@ -170,8 +145,6 @@ class Diagnostics extends Wizard 'images/gm_massive_operations.png', false, 'diagnostic_tool_tab', - true, - $buttonsHeader, true ); @@ -184,7 +157,6 @@ class Diagnostics extends Wizard echo ''; - } @@ -224,6 +196,10 @@ class Diagnostics extends Wizard 'getServerThreads', ]; + if ($this->pdf === true) { + $infoMethods[] = 'getShowEngine'; + } + $return = ''; foreach ($infoMethods as $key => $method) { @@ -282,6 +258,10 @@ class Diagnostics extends Wizard $title = __('Pandora FMS server threads'); break; + case 'getShowEngine': + $title = __('SQL show engine innodb status'); + break; + default: // Not possible. $title = ''; @@ -376,7 +356,9 @@ class Diagnostics extends Wizard ]; $return .= '
    '; - $return .= __('Graphs modules that represent the self-monitoring system'); + $return .= __( + 'Graphs modules that represent the self-monitoring system' + ); $return .= '
    '; $return .= '
    '; foreach ($agentMonitoring as $key => $value) { @@ -1298,7 +1280,7 @@ class Diagnostics extends Wizard $result = [ 'error' => false, 'data' => [ - [ + 'totalServerThreads' => [ 'name' => __('Total server threads'), 'value' => $totalServerThreads, ], @@ -1317,6 +1299,52 @@ class Diagnostics extends Wizard } + /** + * SQL show engine innodb status. + * + * @return string + */ + public function getShowEngine(): string + { + global $config; + + try { + // Trick to avoid showing error in case + // you don't have enough permissions. + $backup = error_reporting(); + error_reporting(0); + $innodb = db_get_all_rows_sql('show engine innodb status'); + error_reporting($backup); + } catch (Exception $e) { + $innodb['Status'] = $e->getMessage(); + } + + $result = []; + if (isset($innodb[0]['Status']) === true + && $innodb[0]['Status'] !== false + ) { + $lenght = strlen($innodb[0]['Status']); + + $data = []; + for ($i = 0; $i < $lenght; $i = ($i + 500)) { + $str = substr($innodb[0]['Status'], $i, ($i + 500)); + $data['showEngine-'.$i] = [ + 'name' => '', + 'value' => '
    '.$str.'
    ', + ]; + } + + $result = [ + 'error' => false, + 'data' => $data, + 'id' => 'showEngine', + ]; + } + + return json_encode($result); + } + + /** * Agent Id whit name is equal to Server Name. * @@ -1482,13 +1510,26 @@ class Diagnostics extends Wizard $table = new stdClass(); $table->width = '100%'; - $table->class = ''; + $table->class = 'pdf-report'; + $table->style = []; + $table->style[0] = 'font-weight: bolder;'; + + // FIX tables break content. + if ($data['idTable'] === 'showEngine') { + $table->styleTable = 'page-break-inside: auto;'; + } else { + $table->autosize = 1; + } + $table->head = []; $table->head_colspan[0] = 3; $table->head[0] = $title; $table->data = []; - if (isset($data) === true && is_array($data) === true) { + if (isset($data) === true + && is_array($data) === true + && count($data) > 0 + ) { $i = 0; foreach ($data['data'] as $key => $value) { $table->data[$i][0] = $value['name']; @@ -1676,7 +1717,11 @@ class Diagnostics extends Wizard $data = json_decode($this->{$method}(), true); } - if (isset($data) === true && is_array($data) === true) { + $result = []; + if (isset($data) === true + && is_array($data) === true + && count($data) > 0 + ) { $items = $data['data']; $dataReduce = array_reduce( array_keys($data['data']), @@ -1711,6 +1756,17 @@ class Diagnostics extends Wizard // FIX for customer key. if ($key === 'customerKey') { $spanValue = ''.$items[$key]['value'].''; + if ($this->pdf === true) { + $spanValue = ''; + $spanValue .= wordwrap( + $items[$key]['value'], + 10, + "\n", + true + ); + $spanValue .= ''; + } + $items[$key]['value'] = $spanValue; } @@ -1722,34 +1778,37 @@ class Diagnostics extends Wizard return $carry; } ); - } - $result = json_encode( - [ + $result = [ 'data' => $dataReduce, 'recordsTotal' => count($dataReduce), 'recordsFiltered' => count($dataReduce), - ] - ); + 'idTable' => (isset($data['id']) === true) ? $data['id'] : '', + ]; + } // Datatables format: RecordsTotal && recordsfiltered. if ($return === false) { - echo $result; + echo json_encode($result); return null; } else { - return $result; + return json_encode($result); } } - public function createdScheduleFeedbackTask() + /** + * Create cron task form feedback. + * + * @return void Json result AJAX request. + */ + public function createdScheduleFeedbackTask():void { global $config; - $email = 'daniel.barbero@artica.es'; $subject = 'PandoraFMS Report '.$config['pandora_uid']; $text = get_parameter('what-happened', ''); - $type = get_parameter('include-installation-data', ''); + $attachment = get_parameter_switch('include_installation_data', 0); $idUserTask = db_get_value( 'id', @@ -1758,15 +1817,17 @@ class Diagnostics extends Wizard 'cron_task_feedback_send_mail' ); + // Params for send mail with cron. $parameters = [ 0 => '0', 1 => $email, 2 => $subject, 3 => $text, - 4 => $type, + 4 => $attachment, 'first_execution' => strtotime('now'), ]; + // Values insert task cron. $values = [ 'id_usuario' => $config['id_user'], 'id_user_task' => $idUserTask, @@ -1775,24 +1836,54 @@ class Diagnostics extends Wizard 'id_grupo' => 0, ]; - $result = db_process_sql_insert('tuser_task_scheduled', $values); + $result = db_process_sql_insert( + 'tuser_task_scheduled', + $values + ); + + $error = 1; + if ($result === false) { + $error = 0; + } + + $return = [ + 'error' => $error, + 'title' => [ + __('Failed'), + __('Success'), + ], + 'text' => [ + ui_print_error_message(__('Mal'), '', true), + ui_print_success_message(__('bien'), '', true), + ], + ]; + + exit(json_encode($return)); } /** * Print Diagnostics PDF report. * + * @param string|null $filename Filename. + * * @return void */ - public static function exportPDF($filename=false) + public function exportPDF(?string $filename=null):void { global $config; + $this->pdf = true; + enterprise_include_once('/include/class/Pdf.class.php'); - $pdf = new Pdf([]); - $diagnostics = new Diagnostics('tools/diagnostics', true); + $mpdf = new Pdf([]); + + // ADD style. + $mpdf->addStyle($config['homedir'].'/include/styles/diagnostics.css'); + + // ADD Metadata. $product_name = io_safe_output(get_product_name()); - $pdf->setMetadata( + $mpdf->setMetadata( __('Diagnostics Info'), $product_name.' Enteprise', $product_name, @@ -1801,18 +1892,24 @@ class Diagnostics extends Wizard $product_name ) ); - $pdf->setHeaderHTML(__('Diagnostics Info')); - $pdf->addHTML( - $diagnostics->printMethodsDiagnostigsInfo() + // ADD Header. + $mpdf->setHeaderHTML(__('Diagnostics Info')); + + // ADD content to report. + $mpdf->addHTML( + $this->printMethodsDiagnostigsInfo() ); - $pdf->addHTML( - $diagnostics->printCharts() + $mpdf->addHTML( + $this->printCharts() ); - $pdf->setFooterHTML(); - $pdf->writePDFfile($filename); + // ADD Footer. + $mpdf->setFooterHTML(); + + // Write html filename. + $mpdf->writePDFfile($filename); } @@ -1860,14 +1957,13 @@ class Diagnostics extends Wizard ]; $inputs[] = [ - 'label' => __('include installation data'), + 'label' => __('Include installation data'), 'class' => 'flex-row-vcenter', 'arguments' => [ - 'name' => 'include-installation-data', - 'id' => 'include-installation-data', - 'type' => 'switch', - 'return' => true, - 'value' => 1, + 'name' => 'include_installation_data', + 'id' => 'include_installation_data', + 'type' => 'switch', + 'value' => 1, ], ]; @@ -1883,4 +1979,67 @@ class Diagnostics extends Wizard } + /** + * Send Csv md5 files. + * + * @return string + */ + public function csvMd5Files():string + { + global $config; + + // Extract files. + $files = $this->recursiveDirValidation($config['homedir']); + + // Type divider. + $divider = html_entity_decode($config['csv_divider']); + + // BOM. + $result = pack('C*', 0xEF, 0xBB, 0xBF); + + $result .= __('Path').$divider.__('MD5')."\n"; + foreach ($files as $key => $value) { + $result .= $key.$divider.$value."\n"; + } + + return $result; + } + + + /** + * Function to return array with name file -> MD%. + * + * @param string $dir Directory. + * + * @return array Result all files in directory recursively. + */ + private function recursiveDirValidation(string $dir):array + { + $result = []; + + $dir_content = scandir($dir); + + // Dont check attachment. + if (strpos($dir, $config['homedir'].'/attachment') === false) { + if (is_array($dir_content) === true) { + foreach (scandir($dir) as $file) { + if ('.' === $file || '..' === $file) { + continue; + } + + if (is_dir($dir.'/'.$file) === true) { + $result += $this->recursiveDirValidation( + $dir.'/'.$file + ); + } else { + $result[$dir.'/'.$file] = md5_file($dir.'/'.$file); + } + } + } + } + + return $result; + } + + } diff --git a/pandora_console/include/functions_html.php b/pandora_console/include/functions_html.php index ab3aad9c7a..5ae28f8e27 100644 --- a/pandora_console/include/functions_html.php +++ b/pandora_console/include/functions_html.php @@ -1898,6 +1898,7 @@ function html_get_predefined_table($model='transparent', $columns=4) * $table->titlestyle - Title style * $table->titleclass - Title class * $table->styleTable - Table style + * $table->autosize - Autosize * $table->caption - Table title * @param bool Whether to return an output string or echo now * @@ -2008,6 +2009,12 @@ function html_print_table(&$table, $return=false) // $table->width = '80%'; } + if (isset($table->autosize) === true) { + $table->autosize = 'autosize = "1"'; + } else { + $table->autosize = ''; + } + if (empty($table->border)) { if (empty($table)) { $table = new stdClass(); @@ -2042,9 +2049,9 @@ function html_print_table(&$table, $return=false) $tableid = empty($table->id) ? 'table'.$table_count : $table->id; if (!empty($table->width)) { - $output .= 'width.'; '.$styleTable.' '.$table->tablealign; } else { - $output .= '
    tablealign; } $output .= ' cellpadding="'.$table->cellpadding.'" cellspacing="'.$table->cellspacing.'"'; @@ -3003,23 +3010,24 @@ function html_print_csrf_error() /** - * Print an swith button + * Print an swith button. * - * @param array $atributes. Valid params: - * name: Usefull to handle in forms - * value: If is checked or not - * disabled: Disabled. Cannot be pressed. - * id: Optional id for the switch. - * class: Additional classes (string). - * @return string with HTML of button + * @param array $attributes Valid params. + * name: Usefull to handle in forms. + * value: If is checked or not. + * disabled: Disabled. Cannot be pressed. + * id: Optional id for the switch. + * class: Additional classes (string). + * + * @return string with HTML of button. */ function html_print_switch($attributes=[]) { $html_expand = ''; // Check the load values on status. - $html_expand .= (bool) $attributes['value'] ? ' checked' : ''; - $html_expand .= (bool) $attributes['disabled'] ? ' disabled' : ''; + $html_expand .= (bool) ($attributes['value']) ? ' checked' : ''; + $html_expand .= (bool) ($attributes['disabled']) ? ' disabled' : ''; // Only load the valid attributes. $valid_attrs = [ @@ -3042,7 +3050,7 @@ function html_print_switch($attributes=[]) } return ""; } diff --git a/pandora_console/include/javascript/pandora.js b/pandora_console/include/javascript/pandora.js index b38ff66a30..09a97ef24e 100644 --- a/pandora_console/include/javascript/pandora.js +++ b/pandora_console/include/javascript/pandora.js @@ -1944,6 +1944,10 @@ function load_modal(settings) { if (settings.onsubmit.preaction != undefined) { settings.onsubmit.preaction(); } + if (settings.onsubmit.dataType == undefined) { + settings.onsubmit.dataType = "html"; + } + var formdata = new FormData(); if (settings.extradata) { settings.extradata.forEach(function(item) { @@ -1960,7 +1964,13 @@ function load_modal(settings) { formdata.append(this.name, $(this).prop("files")[0]); } } else { - formdata.append(this.name, $(this).val()); + if ($(this).attr("type") == "checkbox") { + if (this.checked) { + formdata.append(this.name, "on"); + } + } else { + formdata.append(this.name, $(this).val()); + } } }); @@ -1970,9 +1980,14 @@ function load_modal(settings) { processData: false, contentType: false, data: formdata, + dataType: settings.onsubmit.dataType, success: function(data) { if (settings.ajax_callback != undefined) { - settings.ajax_callback(data); + if (settings.idMsgCallback != undefined) { + settings.ajax_callback(data, settings.idMsgCallback); + } else { + settings.ajax_callback(data); + } } AJAX_RUNNING = 0; } @@ -1989,6 +2004,58 @@ function load_modal(settings) { }); } +/** + * Function to show modal with message Validation. + * + * @param {json} data Json example: + * $return = [ + * 'error' => 0 or 1, + * 'title' => [ + * Failed, + * Success, + * ], + * 'text' => [ + * Failed, + * Success, + * ], + *]; + * @param {string} idMsg ID div charge modal. + * + * @return {void} + */ +function generalShowMsg(data, idMsg) { + var title = data.title[data.error]; + var text = data.text[data.error]; + var failed = !data.error; + + $("#" + idMsg).empty(); + $("#" + idMsg).html(text); + $("#" + idMsg).dialog({ + width: 450, + position: { + my: "center", + at: "center", + of: window, + collision: "fit" + }, + title: title, + buttons: [ + { + class: + "ui-widget ui-state-default ui-corner-all ui-button-text-only sub ok submit-next", + text: "OK", + click: function(e) { + if (!failed) { + $(".ui-dialog-content").dialog("close"); + } else { + $(this).dialog("close"); + } + } + } + ] + }); +} + /** * Function for AJAX request. * diff --git a/pandora_console/include/styles/diagnostics.css b/pandora_console/include/styles/diagnostics.css new file mode 100644 index 0000000000..3b541ac523 --- /dev/null +++ b/pandora_console/include/styles/diagnostics.css @@ -0,0 +1,58 @@ +.pdf-report { + page-break-inside: avoid; +} + +.pdf-report th, +.title-self-monitoring, +.caption_table caption { + text-align: center; + font-size: 1.5em; + font-weight: bolder; + color: #fff; + background: #282828; + padding: 8px; +} + +.pdf-report tr { + text-align: justify; +} + +.datatables-td-title { + width: 25% !important; + font-weight: bolder; +} + +.datatables-td-max { + display: flex; + flex-direction: row; + flex-wrap: wrap; +} + +.datatables-td-max img { + margin-right: 10px; +} + +.datatables-td-max span { + width: 400px; + display: inline-block; + word-wrap: break-word; +} + +.pdf-report td { + font-size: 1.2em; +} + +.container-self-monitoring { + display: flex; + flex-direction: row; + flex-wrap: wrap; +} + +.element-self-monitoring { + flex: 2 1 600px; +} + +.footer-self-monitoring { + margin: 30px; + font-style: italic; +} diff --git a/pandora_console/include/styles/pandora.css b/pandora_console/include/styles/pandora.css index 06ac52dad8..758114e12d 100644 --- a/pandora_console/include/styles/pandora.css +++ b/pandora_console/include/styles/pandora.css @@ -5910,49 +5910,3 @@ table.table_modal_alternate tr td:first-child { .flot-text { width: 101%; } - -.title-self-monitoring, -.caption_table caption { - text-align: center; - font-size: 1.5em; - font-weight: bolder; - color: #fff; - background: #282828; - padding: 8px; -} - -.datatables-td-title { - width: 25% !important; - font-weight: bolder; -} - -.datatables-td-max { - display: flex; - flex-direction: row; - flex-wrap: wrap; -} - -.datatables-td-max img { - margin-right: 10px; -} - -.datatables-td-max span { - width: 400px; - display: inline-block; - word-wrap: break-word; -} - -.container-self-monitoring { - display: flex; - flex-direction: row; - flex-wrap: wrap; -} - -.element-self-monitoring { - flex: 2 1 600px; -} - -.footer-self-monitoring { - margin: 30px; - font-style: italic; -} From e725a0185bfc822c20b26363a832d6d3c8d141df Mon Sep 17 00:00:00 2001 From: marcos Date: Thu, 24 Oct 2019 16:56:13 +0200 Subject: [PATCH 33/81] cambios semi finales --- .../new_installation_welcome_window.php | 12 +- pandora_console/general/register.php | 9 +- .../include/ajax/welcome_window.php | 63 ++++ ...ndow.class.php => WelcomeWindow.class.php} | 351 ++++++++++-------- pandora_console/include/functions_config.php | 4 + .../new_installation_welcome_window.css | 127 +------ 6 files changed, 288 insertions(+), 278 deletions(-) create mode 100644 pandora_console/include/ajax/welcome_window.php rename pandora_console/include/class/{NewInstallationWelcomeWindow.class.php => WelcomeWindow.class.php} (58%) diff --git a/pandora_console/general/new_installation_welcome_window.php b/pandora_console/general/new_installation_welcome_window.php index 5509292bc9..79fbee6d79 100644 --- a/pandora_console/general/new_installation_welcome_window.php +++ b/pandora_console/general/new_installation_welcome_window.php @@ -2,7 +2,7 @@ /** * Credential store * - * @category NewInstallationWelcomeWindow + * @category WelcomeWindow * @package Pandora FMS * @subpackage New Installation Welcome Window * @version 1.0.0 @@ -29,25 +29,25 @@ // Begin. /** - * Class NewInstallationWelcomeWindow. + * Class WelcomeWindow. */ global $config; -require_once $config['homedir'].'/include/class/NewInstallationWelcomeWindow.class.php'; +require_once $config['homedir'].'/include/class/WelcomeWindow.class.php'; $ajaxPage = 'general/new_installation_welcome_window'; // Control call flow. try { // User access and validation is being processed on class constructor. - $welcome_actions = new NewInstallationWelcomeWindow($ajaxPage); + $welcome_actions = new WelcomeWindow($ajaxPage); } catch (Exception $e) { if (is_ajax()) { - echo json_encode(['error' => '[NewInstallationWelcomeWindow]'.$e->getMessage() ]); + echo json_encode(['error' => '[WelcomeWindow]'.$e->getMessage() ]); exit; } else { - echo '[NewInstallationWelcomeWindow]'.$e->getMessage(); + echo '[WelcomeWindow]'.$e->getMessage(); } // Stop this execution, but continue 'globally'. diff --git a/pandora_console/general/register.php b/pandora_console/general/register.php index db92829a2a..41996a31ef 100644 --- a/pandora_console/general/register.php +++ b/pandora_console/general/register.php @@ -30,7 +30,7 @@ global $config; require_once $config['homedir'].'/include/functions_update_manager.php'; -require_once $config['homedir'].'/include/class/NewInstallationWelcomeWindow.class.php'; +require_once $config['homedir'].'/include/class/WelcomeWindow.class.php'; if (is_ajax()) { @@ -173,9 +173,10 @@ if (!$config['disabled_newsletter']) { } } -$welcome = !$registration && !$initial; -if ($welcome) { - $welcome = NewInstallationWelcomeWindow::actions_done($welcome); +$welcome = !$registration && !$show_newsletter && !$initial; +$welcome_window = WelcomeWindow::initialize($welcome); +if ($welcome_window && $config['welcome_started'] === 1) { + $welcome_window->run(); } $newsletter = null; diff --git a/pandora_console/include/ajax/welcome_window.php b/pandora_console/include/ajax/welcome_window.php new file mode 100644 index 0000000000..d72809fd99 --- /dev/null +++ b/pandora_console/include/ajax/welcome_window.php @@ -0,0 +1,63 @@ + '[WelcomeWindow]'.$e->getMessage() ]); + exit; +} + +// Ajax controller. +$method = get_parameter('method', ''); + +if (method_exists($welcome_actions, $method) === true) { + if ($welcome_actions->ajaxMethod($method) === true) { + $welcome_actions->{$method}(); + } else { + $welcome_actions->error('Unavailable method.'); + } +} else { + $welcome_actions->error('Method not found. ['.$method.']'); +} + + +// Stop any execution. +exit; diff --git a/pandora_console/include/class/NewInstallationWelcomeWindow.class.php b/pandora_console/include/class/WelcomeWindow.class.php similarity index 58% rename from pandora_console/include/class/NewInstallationWelcomeWindow.class.php rename to pandora_console/include/class/WelcomeWindow.class.php index 6d369c7003..43fa894642 100644 --- a/pandora_console/include/class/NewInstallationWelcomeWindow.class.php +++ b/pandora_console/include/class/WelcomeWindow.class.php @@ -29,12 +29,18 @@ // Begin. global $config; + +defined('WELCOME_STARTED') || define('WELCOME_STARTED', 1); +defined('WELCOME_FINISHED') || define('WELCOME_FINISHED', 2); + + + require_once $config['homedir'].'/godmode/wizards/Wizard.main.php'; ui_require_css_file('pandora'); /** - * Class NewInstallationWelcomeWindow. + * Class WelcomeWindow. */ -class NewInstallationWelcomeWindow extends Wizard +class WelcomeWindow extends Wizard { /** @@ -51,6 +57,14 @@ class NewInstallationWelcomeWindow extends Wizard */ public $ajaxController; + /** + * Current step. + * + * @var string + */ + public $step; + + /** * Checks if target method is available to be called using AJAX. * @@ -58,8 +72,6 @@ class NewInstallationWelcomeWindow extends Wizard * * @return boolean True allowed, false not. */ - - public function ajaxMethod($method) { global $config; @@ -92,8 +104,9 @@ class NewInstallationWelcomeWindow extends Wizard * * @return object */ - public function __construct($ajax_controller) - { + public function __construct( + $ajax_controller='include/ajax/welcome_window' + ) { $this->ajaxController = $ajax_controller; return $this; } @@ -120,6 +133,7 @@ class NewInstallationWelcomeWindow extends Wizard modal: { title: "", ok: '', + cancel: '', }, onshow: { page: 'ajaxController; ?>', @@ -143,6 +157,43 @@ class NewInstallationWelcomeWindow extends Wizard public function loadWelcomeWindow() { global $config; + $btn_configure_mail_class = ''; + $btn_create_agent_class = ''; + $btn_create_module_class = ''; + $btn_create_alert_class = ''; + $btn_create_discovery_class = ''; + $action = ''; + + if (($_SESSION['step'] === 'create_mail') || $_SESSION['step'] === null) { + // Pending mail. + $btn_configure_mail_class = ' pending'; + } else if ($_SESSION['step'] === 'create_agent') { + $this->step = 'create_agent'; + $btn_configure_mail_class = ' completed'; + $btn_create_agent_class = ' pending'; + } else if ($_SESSION['step'] === 'create_module') { + $btn_configure_mail_class = ' completed'; + $btn_create_agent_class = ' completed'; + $btn_create_module_class = ' pending'; + } else if ($_SESSION['step'] === 'create_alert') { + $btn_configure_mail_class = ' completed'; + $btn_create_agent_class = ' completed'; + $btn_create_module_class = ' completed'; + $btn_create_alert_class = ' pending'; + } else if ($_SESSION['step'] === 'create_discovery') { + $btn_configure_mail_class = ' completed'; + $btn_create_agent_class = ' completed'; + $btn_create_module_class = ' completed'; + $btn_create_alert_class = ' completed'; + $btn_create_discovery_class = ' pending'; + } else if ($_SESSION['step'] === 'end') { + // Nothing left to do. + $btn_configure_mail_class = ' completed'; + $btn_create_agent_class = ' completed'; + $btn_create_module_class = ' completed'; + $btn_create_alert_class = ' completed'; + $btn_create_discovery_class = ' completed'; + } $form = [ 'action' => '#', @@ -155,7 +206,7 @@ class NewInstallationWelcomeWindow extends Wizard [ 'wrapper' => 'div', 'block_id' => 'div_configure_mail', - 'class' => 'content_position', + 'class' => 'flex-row w100p', 'direct' => 1, 'block_content' => [ [ @@ -168,19 +219,18 @@ class NewInstallationWelcomeWindow extends Wizard ], [ 'arguments' => [ - 'label' => __(''), + 'label' => '', 'type' => 'button', - 'attributes' => 'class="btn_email_conf"', + 'attributes' => 'class="go '.$btn_configure_mail_class.'"', 'name' => 'btn_email_conf', 'id' => 'btn_email_conf', - 'script' => 'configureEmail()', ], ], ], ],[ 'wrapper' => 'div', 'block_id' => 'div_create_agent', - 'class' => 'content_position', + 'class' => 'flex-row w100p', 'direct' => 1, 'block_content' => [ [ @@ -193,12 +243,11 @@ class NewInstallationWelcomeWindow extends Wizard ], [ 'arguments' => [ - 'label' => __(''), + 'label' => '', 'type' => 'button', - 'attributes' => 'class="btn_agent"', + 'attributes' => 'class="go '.$btn_create_agent_class.'"', 'name' => 'btn_create_agent', 'id' => 'btn_create_agent', - 'script' => 'createNewAgent()', ], ], ], @@ -214,7 +263,7 @@ class NewInstallationWelcomeWindow extends Wizard [ 'wrapper' => 'div', 'block_id' => 'div_monitor_actions', - 'class' => 'learn_content_position', + 'class' => 'learn_content_indented flex-row w100p', 'direct' => 1, 'block_content' => [ [ @@ -227,12 +276,11 @@ class NewInstallationWelcomeWindow extends Wizard ], [ 'arguments' => [ - 'label' => __(''), + 'label' => '', 'type' => 'button', - 'attributes' => 'class="btn_agent_online"', - 'name' => 'btn_check_agent', - 'id' => 'btn_check_agent', - 'script' => 'checkAgentOnline()', + 'attributes' => 'class="go '.$btn_create_module_class.'"', + 'name' => 'btn_create_module', + 'id' => 'btn_create_module', ], ], ], @@ -240,7 +288,7 @@ class NewInstallationWelcomeWindow extends Wizard [ 'wrapper' => 'div', 'block_id' => 'div_monitor_actions', - 'class' => 'learn_content_position', + 'class' => 'learn_content_indented flex-row w100p', 'direct' => 1, 'block_content' => [ [ @@ -253,12 +301,11 @@ class NewInstallationWelcomeWindow extends Wizard ], [ 'arguments' => [ - 'label' => __(''), + 'label' => '', 'type' => 'button', - 'attributes' => 'class="btn_alert_module"', + 'attributes' => 'class="go '.$btn_create_alert_class.'"', 'name' => 'btn_create_alert', 'id' => 'btn_create_alert', - 'script' => 'createAlertModule()', ], ], ], @@ -267,7 +314,7 @@ class NewInstallationWelcomeWindow extends Wizard [ 'wrapper' => 'div', 'block_id' => 'div_monitor_actions', - 'class' => 'learn_content_position', + 'class' => 'learn_content_indented flex-row w100p', 'direct' => 1, 'block_content' => [ [ @@ -280,12 +327,11 @@ class NewInstallationWelcomeWindow extends Wizard ], [ 'arguments' => [ - 'label' => __(''), + 'label' => '', 'type' => 'button', - 'attributes' => 'class="btn_remote-command"', + 'attributes' => 'class="go '.$btn_create.'"', 'name' => 'btn_monitor_commmands', 'id' => 'btn_monitor_commmands', - 'script' => 'monitorRemoteCommands()', ], ], ], @@ -293,7 +339,7 @@ class NewInstallationWelcomeWindow extends Wizard [ 'wrapper' => 'div', 'block_id' => 'div_discover', - 'class' => 'content_position', + 'class' => 'flex-row w100p', 'direct' => 1, 'block_content' => [ [ @@ -306,12 +352,11 @@ class NewInstallationWelcomeWindow extends Wizard ], [ 'arguments' => [ - 'label' => __(''), + 'label' => '', 'type' => 'button', - 'attributes' => 'class="btn_discover"', + 'attributes' => 'class="go '.$btn_create_discovery_class.'"', 'name' => 'btn_discover_devices', 'id' => 'btn_discover_devices', - 'script' => 'discoverDevicesNetwork()', ], ], ], @@ -320,7 +365,7 @@ class NewInstallationWelcomeWindow extends Wizard [ 'wrapper' => 'div', 'block_id' => 'div_not_working', - 'class' => 'content_position', + 'class' => 'flex-row w100p', 'direct' => 1, 'block_content' => [ [ @@ -333,12 +378,11 @@ class NewInstallationWelcomeWindow extends Wizard ], [ 'arguments' => [ - 'label' => __(''), + 'label' => '', 'type' => 'button', - 'attributes' => 'class="btn_is_not_ok"', + 'attributes' => 'class="go pending '.$btn_create.'"', 'name' => 'btn_not_working', 'id' => 'btn_not_working', - 'script' => 'reportIsNotWorking()', ], ], ], @@ -361,162 +405,171 @@ class NewInstallationWelcomeWindow extends Wizard } - public static function actions_done() + /** + * Esto es un constructor realmente... + * se llama desde la navegación normal , no ajax + */ + public static function initialize($must_run) { + global $config; + + if ($must_run === false) { + // Do not start unless already started. + if ($config['welcome_started'] != WELCOME_STARTED) { + return false; + } + } + + // Calculate steps. $sec2 = get_parameter('sec2', ''); $mail_user = get_parameter('email_username', ''); $mail_configured = db_get_value('value', 'tconfig', 'token', 'email_username'); - $_SESSION['agente'] = ''; - if ($sec2 == '' && $config['initial_wizard'] == false) { - $welcome = new NewInstallationWelcomeWindow( - 'general/new_installation_welcome_window' - ); - $welcome->run(); - } - - if (($mail_user !== '' || $mail_configured ) && $sec2 === 'godmode/setup/setup') { - $welcome = new NewInstallationWelcomeWindow( - 'general/new_installation_welcome_window' - ); - $welcome->run(); - $_SESSION['mail_configured'] = true; - } - $create_agent = (bool) get_parameter('create_agent'); - if ($create_agent && $sec2 === 'godmode/agentes/configurar_agente') { - $welcome = new NewInstallationWelcomeWindow( - 'general/new_installation_welcome_window' - ); + $create_module = (bool) get_parameter('create_module'); + $sec2_url = explode('&', ui_get_full_url()); + $create_alert = (int) get_parameter('create_alert', 0); + $task_id = get_parameter('task', null); + $_SESSION['agent'] = db_get_value( + 'MAX(id_agente)', + 'tagente' + ); + + if ($sec2 === '') { + $welcome = new WelcomeWindow(); + $welcome->run(); + // Nothing done yet. Launch mail. + $_SESSION['step'] = null; + } else if (($mail_user !== '' + || $mail_configured ) + && $sec2 === 'godmode/setup/setup' + ) { + $welcome = new WelcomeWindow(); $welcome->run(); $_SESSION['create_agent'] = true; - } - - $create_module = (bool) get_parameter('create_module'); - $sec2_module = explode('&', ui_get_full_url()); - - if ($create_module && $sec2_module[2] == 'tab=module') { - $welcome = new NewInstallationWelcomeWindow( - 'general/new_installation_welcome_window' - ); + $_SESSION['step'] = 'create_agent'; + // Mail configured. + } else if ($create_agent + && $sec2 === 'godmode/agentes/configurar_agente' + ) { + $welcome = new WelcomeWindow(); $welcome->run(); + // Agent created. + // Store id_agent created. $_SESSION['create_module'] = true; - } - - $sec2_alert = explode('&', ui_get_full_url()); - - $create_alert = (int) get_parameter('create_alert', 0); - - // $check_module = db_get_value('MAX(id_module)', 'tmodule'); - if ($create_alert && $sec2_alert[2] == 'tab=alert') { - $welcome = new NewInstallationWelcomeWindow( - 'general/new_installation_welcome_window' - ); + $_SESSION['step'] = 'create_module'; + } else if ($create_module + && $sec2_url[2] == 'tab=module' + ) { + $welcome = new WelcomeWindow(); $welcome->run(); + // Module created. $_SESSION['create_alert'] = true; - } - - $sec2_discover = explode('&', ui_get_full_url()); - $task_id = get_parameter('task', null); - if ($sec2_discover[4] === 'mode=netscan') { - $welcome = new NewInstallationWelcomeWindow( - 'general/new_installation_welcome_window' - ); + $_SESSION['step'] = 'create_alert'; + } else if ($create_alert && $sec2_url[2] == 'tab=alert') { + $welcome = new WelcomeWindow(); $welcome->run(); - $_SESSION['discover'] = true; + // Alert created. + $_SESSION['create_discovery']; + $_SESSION['step'] = 'create_discovery'; + } else if ($sec2_url[3] === 'mode=netscan') { + // Discovery task created. + $_SESSION['step'] = 'end'; + + // Welcome is finished. + config_update_value('welcome_started', WELCOME_FINISHED); + + // No more 'welcomes' to show. + return false; + } else { + // No step found. Retrieve from session. + $_SESSION['step'] = null; + if (empty($_SESSION['create_mail'] === true)) { + $_SESSION['step'] = 'create_mail'; + } + + if (empty($_SESSION['create_mail']) === false) { + $_SESSION['step'] = 'create_agent'; + } + + if (empty($_SESSION['create_agent']) === false) { + $_SESSION['step'] = 'create_module'; + } + + if (empty($_SESSION['create_module']) === false) { + $_SESSION['step'] = 'create_alert'; + } + + if (empty($_SESSION['create_alert']) === false) { + $_SESSION['step'] = 'create_discovery'; + } + + if (empty($_SESSION['create_discovery']) === false) { + // No more 'welcomes' to show. + return false; + } } + // Return a reference to the new object. + return $welcome; } + /** + * DOCUMENTA!!! + */ public function loadJS() { ob_start(); ?> '; - $return .= $this->getChart( + $table = new stdClass(); + $table->width = '100%'; + $table->class = 'pdf-report'; + $table->style = []; + $table->style[0] = 'font-weight: bolder;'; + $table->autosize = 1; + + $table->head = []; + $table->head[0] = $params['nameModule']; + + $table->data = []; + $table->data[0] = $this->getChart( $params['idAgent'], $params['nameModule'], true, false ); - $return .= ''; + + $return = html_print_table($table, true); } } catch (Exception $e) { $return = $e->getMessage(); @@ -1796,212 +1789,6 @@ class Diagnostics extends Wizard } - /** - * Create cron task form feedback. - * - * @return void Json result AJAX request. - */ - public function createdScheduleFeedbackTask():void - { - global $config; - - // TODO: feedback@artica.es - $mail_feedback = 'feedback@artica.es'; - $email = 'daniel.barbero@artica.es'; - $subject = 'PandoraFMS Report '.$config['pandora_uid']; - $text = get_parameter('what-happened', ''); - $attachment = get_parameter_switch('include_installation_data', 0); - $email_from = get_parameter_switch('email', ''); - - if (!check_acl($config['id_user'], 0, 'PM')) { - // TODO: MAIL TO ADMIN. - $email = get_mail_admin(); - $email = 'daniel.barbero@artica.es'; - $product_name = io_safe_output(get_product_name()); - $name_admin = get_name_admin(); - - $subject = __('Feedback').' '.$product_name.' '.$config['pandora_uid']; - - $title = __('Hello').' '.$name_admin; - $p1 = __( - 'User %s is reporting an issue in its %s experience', - $email_from, - $product_name - ); - $p1 .= ':'; - - $p2 = $text; - - if ($attachment === 1) { - $msg_attch = __('Find some files attached to this mail'); - $msg_attch .= '. '; - $msg_attch .= __( - 'PDF is the diagnostic information retrieved at report time' - ); - $msg_attch .= '. '; - $msg_attch .= __('CSV contains the statuses of every product file'); - $msg_attch .= '. '; - } - - $p3 = __( - 'If you think this report must be escalated, feel free to forward this mail to "%s"', - $mail_feedback - ); - - $legal = __('LEGAL WARNING'); - $legal1 = __( - 'The information contained in this transmission is privileged and confidential information intended only for the use of the individual or entity named above' - ); - $legal1 .= '. '; - $legal2 = __( - 'If the reader of this message is not the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited' - ); - $legal2 .= '. '; - $legal3 = __( - 'If you have received this transmission in error, do not read it' - ); - $legal3 .= '. '; - $legal4 = __( - 'Please immediately reply to the sender that you have received this communication in error and then delete it' - ); - $legal4 .= '.'; - - $patterns = [ - '/__title__/', - '/__p1__/', - '/__p2__/', - '/__attachment__/', - '/__p3__/', - '/__legal__/', - '/__legal1__/', - '/__legal2__/', - '/__legal3__/', - '/__legal4__/', - ]; - - $substitutions = [ - $title, - $p1, - $p2, - $msg_attch, - $p3, - $legal, - $legal1, - $legal2, - $legal3, - $legal4, - ]; - - $html_template = file_get_contents( - $config['homedir'].'/include/templates/feedback_send_mail.html' - ); - - $text = preg_replace($patterns, $substitutions, $html_template); - } - - $idUserTask = db_get_value( - 'id', - 'tuser_task', - 'function_name', - 'cron_task_feedback_send_mail' - ); - - // Params for send mail with cron. - $parameters = [ - 0 => '0', - 1 => $email, - 2 => $subject, - 3 => $text, - 4 => $attachment, - 'first_execution' => strtotime('now'), - ]; - - // Values insert task cron. - $values = [ - 'id_usuario' => $config['id_user'], - 'id_user_task' => $idUserTask, - 'args' => serialize($parameters), - 'scheduled' => 'no', - 'id_grupo' => 0, - ]; - - $result = db_process_sql_insert( - 'tuser_task_scheduled', - $values - ); - - $error = 1; - if ($result === false) { - $error = 0; - } - - $return = [ - 'error' => $error, - 'title' => [ - __('Failed'), - __('Success'), - ], - 'text' => [ - ui_print_error_message(__('Mal'), '', true), - ui_print_success_message(__('bien'), '', true), - ], - ]; - - exit(json_encode($return)); - } - - - /** - * Print Diagnostics PDF report. - * - * @param string|null $filename Filename. - * - * @return void - */ - public function exportPDF(?string $filename=null):void - { - global $config; - - $this->pdf = true; - - enterprise_include_once('/include/class/Pdf.class.php'); - $mpdf = new Pdf([]); - - // ADD style. - $mpdf->addStyle($config['homedir'].'/include/styles/diagnostics.css'); - - // ADD Metadata. - $product_name = io_safe_output(get_product_name()); - $mpdf->setMetadata( - __('Diagnostics Info'), - $product_name.' Enteprise', - $product_name, - __( - 'Automated %s report for user defined report', - $product_name - ) - ); - - // ADD Header. - $mpdf->setHeaderHTML(__('Diagnostics Info')); - - // ADD content to report. - $mpdf->addHTML( - $this->printMethodsDiagnostigsInfo() - ); - - $mpdf->addHTML( - $this->printCharts() - ); - - // ADD Footer. - $mpdf->setFooterHTML(); - - // Write html filename. - $mpdf->writePDFfile($filename); - } - - /** * Print Diagnostics Form feedback. * @@ -2068,6 +1855,215 @@ class Diagnostics extends Wizard } + /** + * Create cron task form feedback. + * + * @return void Json result AJAX request. + */ + public function createdScheduleFeedbackTask():void + { + global $config; + + // TODO: feedback@artica.es + $mail_feedback = 'feedback@artica.es'; + $email = 'daniel.barbero@artica.es'; + $subject = 'PandoraFMS Report '.$config['pandora_uid']; + $text = get_parameter('what-happened', ''); + $attachment = get_parameter_switch('include_installation_data', 0); + $email_from = get_parameter_switch('email', ''); + $title = __('Hello Feedback-Men'); + + $product_name = io_safe_output(get_product_name()); + + if (check_acl($config['id_user'], 0, 'PM') !== 1) { + // TODO: MAIL TO ADMIN. + $email = get_mail_admin(); + $email = 'daniel.barbero@artica.es'; + $name_admin = get_name_admin(); + + $subject = __('Feedback').' '.$product_name.' '.$config['pandora_uid']; + + $title = __('Hello').' '.$name_admin; + } + + $p1 = __( + 'User %s is reporting an issue in its %s experience', + $email_from, + $product_name + ); + $p1 .= ':'; + + $p2 = $text; + + if ($attachment === 1) { + $msg_attch = __('Find some files attached to this mail'); + $msg_attch .= '. '; + $msg_attch .= __( + 'PDF is the diagnostic information retrieved at report time' + ); + $msg_attch .= '. '; + $msg_attch .= __('CSV contains the statuses of every product file'); + $msg_attch .= '. '; + } + + $p3 = __( + 'If you think this report must be escalated, feel free to forward this mail to "%s"', + $mail_feedback + ); + + $legal = __('LEGAL WARNING'); + $legal1 = __( + 'The information contained in this transmission is privileged and confidential information intended only for the use of the individual or entity named above' + ); + $legal1 .= '. '; + $legal2 = __( + 'If the reader of this message is not the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited' + ); + $legal2 .= '. '; + $legal3 = __( + 'If you have received this transmission in error, do not read it' + ); + $legal3 .= '. '; + $legal4 = __( + 'Please immediately reply to the sender that you have received this communication in error and then delete it' + ); + $legal4 .= '.'; + + $patterns = [ + '/__title__/', + '/__p1__/', + '/__p2__/', + '/__attachment__/', + '/__p3__/', + '/__legal__/', + '/__legal1__/', + '/__legal2__/', + '/__legal3__/', + '/__legal4__/', + ]; + + $substitutions = [ + $title, + $p1, + $p2, + $msg_attch, + $p3, + $legal, + $legal1, + $legal2, + $legal3, + $legal4, + ]; + + $html_template = file_get_contents( + $config['homedir'].'/include/templates/feedback_send_mail.html' + ); + + $text = preg_replace($patterns, $substitutions, $html_template); + + $idUserTask = db_get_value( + 'id', + 'tuser_task', + 'function_name', + 'cron_task_feedback_send_mail' + ); + + // Params for send mail with cron. + $parameters = [ + 0 => '0', + 1 => $email, + 2 => $subject, + 3 => $text, + 4 => $attachment, + 'first_execution' => strtotime('now'), + ]; + + // Values insert task cron. + $values = [ + 'id_usuario' => $config['id_user'], + 'id_user_task' => $idUserTask, + 'args' => serialize($parameters), + 'scheduled' => 'no', + 'id_grupo' => 0, + ]; + + $result = db_process_sql_insert( + 'tuser_task_scheduled', + $values + ); + + $error = 1; + if ($result === false) { + $error = 0; + } + + $return = [ + 'error' => $error, + 'title' => [ + __('Failed'), + __('Success'), + ], + 'text' => [ + ui_print_error_message(__('Invalid cron task'), '', true), + ui_print_success_message(__('Cron task generated'), '', true), + ], + ]; + + exit(json_encode($return)); + } + + + /** + * Print Diagnostics PDF report. + * + * @param string|null $filename Filename. + * + * @return void + */ + public function exportPDF(?string $filename=null):void + { + global $config; + + $this->pdf = true; + + enterprise_include_once('/include/class/Pdf.class.php'); + $mpdf = new Pdf([]); + + // ADD style. + $mpdf->addStyle($config['homedir'].'/include/styles/diagnostics.css'); + + // ADD Metadata. + $product_name = io_safe_output(get_product_name()); + $mpdf->setMetadata( + __('Diagnostics Info'), + $product_name.' Enteprise', + $product_name, + __( + 'Automated %s report for user defined report', + $product_name + ) + ); + + // ADD Header. + $mpdf->setHeaderHTML(__('Diagnostics Info')); + + // ADD content to report. + $mpdf->addHTML( + $this->printMethodsDiagnostigsInfo() + ); + + $mpdf->addHTML( + $this->printCharts() + ); + + // ADD Footer. + $mpdf->setFooterHTML(); + + // Write html filename. + $mpdf->writePDFfile($filename); + } + + /** * Send Csv md5 files. * @@ -2131,4 +2127,51 @@ class Diagnostics extends Wizard } + /** + * Send PHP info in report. + * + * @param string $filename Download dir report. + * + * @return void + */ + public function phpInfoReports(string $filename) + { + global $config; + + $this->pdf = true; + + // Extract info PHP. + ob_start(); + phpinfo(); + $php_info = ob_get_clean(); + + enterprise_include_once('/include/class/Pdf.class.php'); + $mpdf = new Pdf([]); + + // ADD Metadata. + $product_name = io_safe_output(get_product_name()); + $mpdf->setMetadata( + __('PHP Info'), + $product_name.' Enteprise', + $product_name, + __( + 'Automated %s report for user defined report', + $product_name + ) + ); + + // ADD Header. + $mpdf->setHeaderHTML(__('PHP Info')); + + // ADD content to report. + $mpdf->addHTML($php_info); + + // ADD Footer. + $mpdf->setFooterHTML(); + + // Write html filename. + $mpdf->writePDFfile($filename); + } + + } diff --git a/pandora_console/include/templates/feedback_send_mail.html b/pandora_console/include/templates/feedback_send_mail.html new file mode 100644 index 0000000000..e06b68f246 --- /dev/null +++ b/pandora_console/include/templates/feedback_send_mail.html @@ -0,0 +1,58 @@ + + + + + + + Feedback + + + +

    __title__

    +
    +

    __p1__

    +

    __p2__

    +

    __attachment__

    +

    __p3__

    +
    +
    __legal__
    + + + + + + From c4aea1ac5918a4812b98bdb4c19997d3e8862429 Mon Sep 17 00:00:00 2001 From: Daniel Barbero Date: Fri, 25 Oct 2019 13:28:01 +0200 Subject: [PATCH 36/81] add styles validation form of modal --- .../include/class/Diagnostics.class.php | 17 ++++++------ pandora_console/include/javascript/pandora.js | 10 +++++-- pandora_console/include/styles/discovery.css | 27 +++++++++++++++++++ pandora_console/include/styles/pandora.css | 4 --- 4 files changed, 44 insertions(+), 14 deletions(-) diff --git a/pandora_console/include/class/Diagnostics.class.php b/pandora_console/include/class/Diagnostics.class.php index 6f1898f14e..b839851421 100644 --- a/pandora_console/include/class/Diagnostics.class.php +++ b/pandora_console/include/class/Diagnostics.class.php @@ -1810,13 +1810,14 @@ class Diagnostics extends Wizard 'id' => 'div-what-happened', 'class' => 'flex-row', 'arguments' => [ - 'name' => 'what-happened', - 'type' => 'textarea', - 'value' => '', - 'return' => true, - 'rows' => 1, - 'columns' => 1, - 'size' => 25, + 'name' => 'what-happened', + 'type' => 'textarea', + 'value' => '', + 'return' => true, + 'rows' => 1, + 'columns' => 1, + 'size' => 25, + 'attributes' => 'required="required"', ], ]; @@ -1827,7 +1828,7 @@ class Diagnostics extends Wizard 'name' => 'email', 'id' => 'email', 'type' => 'email', - 'size' => 40, + 'size' => 42, 'required' => 'required', ], ]; diff --git a/pandora_console/include/javascript/pandora.js b/pandora_console/include/javascript/pandora.js index 886d680c73..f3737eabdf 100644 --- a/pandora_console/include/javascript/pandora.js +++ b/pandora_console/include/javascript/pandora.js @@ -1959,10 +1959,16 @@ function load_modal(settings) { formdata.append("method", settings.onsubmit.method); var flagError = false; + $("#" + settings.form + " :input").each(function() { if (this.checkValidity() === false) { - // TODO: Tooltip msg. - console.log(this.validationMessage); + $(this).prop("title", this.validationMessage); + $(this).tooltip({ + tooltipClass: "uitooltip", + position: { my: "right bottom", at: "right bottom" }, + show: { duration: 200 } + }); + $(this).tooltip("open"); flagError = true; } diff --git a/pandora_console/include/styles/discovery.css b/pandora_console/include/styles/discovery.css index 82b022050f..2095e98b8e 100644 --- a/pandora_console/include/styles/discovery.css +++ b/pandora_console/include/styles/discovery.css @@ -205,6 +205,7 @@ label { } li > input[type="text"], +li > input[type="email"], li > input[type="password"], .discovery_text_input > input[type="password"], .discovery_text_input > input[type="text"], @@ -270,3 +271,29 @@ a.ext_link { margin-left: 1em; font-size: 8pt; } + +input:invalid, +input[type="email"]:invalid { + border-bottom-color: #fb4444; +} + +textarea:invalid { + border-color: #fb4444; +} + +div.ui-tooltip.ui-corner-all.ui-widget-shadow.ui-widget.ui-widget-content.uitooltip { + background: grey; + opacity: 0.9; + border-radius: 4px; + box-shadow: 0 0 0px #fff; + padding: 6px; +} + +.ui-tooltip-content { + background: transparent; + color: #fff; + font-weight: bold; + font-family: "lato-lighter", "Open Sans", sans-serif; + letter-spacing: 0.03pt; + font-size: 8pt; +} diff --git a/pandora_console/include/styles/pandora.css b/pandora_console/include/styles/pandora.css index a0cf338114..758114e12d 100644 --- a/pandora_console/include/styles/pandora.css +++ b/pandora_console/include/styles/pandora.css @@ -5910,7 +5910,3 @@ table.table_modal_alternate tr td:first-child { .flot-text { width: 101%; } - -input:invalid { - border-color: #c00; -} From d6681cedd126866437fc3a0b11cf9dbf3c9b82f8 Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Mon, 28 Oct 2019 12:18:13 +0100 Subject: [PATCH 37/81] 33 => 34 --- pandora_console/extras/mr/34.sql | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 pandora_console/extras/mr/34.sql diff --git a/pandora_console/extras/mr/34.sql b/pandora_console/extras/mr/34.sql new file mode 100644 index 0000000000..eeca8ed5d7 --- /dev/null +++ b/pandora_console/extras/mr/34.sql @@ -0,0 +1,9 @@ +START TRANSACTION; + +INSERT INTO `ttipo_modulo` VALUES +(34,'remote_cmd', 10, 'Remote execution, numeric data', 'mod_remote_cmd.png'), +(35,'remote_cmd_proc', 10, 'Remote execution, boolean data', 'mod_remote_cmd_proc.png'), +(36,'remote_cmd_string', 10, 'Remote execution, alphanumeric data', 'mod_remote_cmd_string.png'), +(37,'remote_cmd_inc', 10, 'Remote execution, incremental data', 'mod_remote_cmd_inc.png'); + +COMMIT; \ No newline at end of file From 74007ebf7013eefed636d388ba02fad1510bce9b Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Mon, 28 Oct 2019 12:18:56 +0100 Subject: [PATCH 38/81] 33 => 34, cleanup --- pandora_console/extras/mr/33.sql | 9 --------- 1 file changed, 9 deletions(-) delete mode 100644 pandora_console/extras/mr/33.sql diff --git a/pandora_console/extras/mr/33.sql b/pandora_console/extras/mr/33.sql deleted file mode 100644 index eeca8ed5d7..0000000000 --- a/pandora_console/extras/mr/33.sql +++ /dev/null @@ -1,9 +0,0 @@ -START TRANSACTION; - -INSERT INTO `ttipo_modulo` VALUES -(34,'remote_cmd', 10, 'Remote execution, numeric data', 'mod_remote_cmd.png'), -(35,'remote_cmd_proc', 10, 'Remote execution, boolean data', 'mod_remote_cmd_proc.png'), -(36,'remote_cmd_string', 10, 'Remote execution, alphanumeric data', 'mod_remote_cmd_string.png'), -(37,'remote_cmd_inc', 10, 'Remote execution, incremental data', 'mod_remote_cmd_inc.png'); - -COMMIT; \ No newline at end of file From 7d5b845e1fa213d10718f39a12d2d84cf2d243b1 Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Mon, 28 Oct 2019 18:37:01 +0100 Subject: [PATCH 39/81] minor fixes --- .../godmode/agentes/module_manager_editor.php | 39 +++++++++++++++++++ .../include/javascript/pandora_modules.js | 22 +++++++---- 2 files changed, 54 insertions(+), 7 deletions(-) diff --git a/pandora_console/godmode/agentes/module_manager_editor.php b/pandora_console/godmode/agentes/module_manager_editor.php index d3ff659ff0..9db5fa0ed3 100644 --- a/pandora_console/godmode/agentes/module_manager_editor.php +++ b/pandora_console/godmode/agentes/module_manager_editor.php @@ -57,11 +57,50 @@ if (is_ajax()) { $component['plugin_pass'] ); + if ($component['type'] >= 15 + && $component['type'] <= 18 + ) { + // New support for snmp v3. + $component['snmp_version'] = $component['tcp_send']; + $component['snmp3_auth_user'] = io_safe_output( + $component['plugin_user'] + ); + // Must use io_output_password. + $component['snmp3_auth_pass'] = io_safe_output( + $component['plugin_pass'] + ); + $component['snmp3_auth_method'] = io_safe_output( + $component['plugin_parameter'] + ); + $component['snmp3_privacy_method'] = io_safe_output( + $component['custom_string_1'] + ); + $component['snmp3_privacy_pass'] = io_safe_output( + $component['custom_string_2'] + ); + $component['snmp3_security_level'] = io_safe_output( + $component['custom_string_3'] + ); + } else if ($component['type'] >= 34 + && $component['type'] <= 37 + ) { + $component['command_text'] = io_safe_output( + $component['tcp_send'] + ); + $component['command_credential_identifier'] = io_safe_output( + $component['custom_string_1'] + ); + $component['command_os'] = io_safe_output( + $component['custom_string_2'] + ); + } + $component['str_warning'] = io_safe_output($component['str_warning']); $component['str_critical'] = io_safe_output($component['str_critical']); $component['warning_inverse'] = (bool) $component['warning_inverse']; $component['critical_inverse'] = (bool) $component['critical_inverse']; + hd($component, true); echo io_json_mb_encode($component); return; } diff --git a/pandora_console/include/javascript/pandora_modules.js b/pandora_console/include/javascript/pandora_modules.js index d04c3d2bd6..0ba0eb5515 100644 --- a/pandora_console/include/javascript/pandora_modules.js +++ b/pandora_console/include/javascript/pandora_modules.js @@ -541,13 +541,13 @@ function configure_modules_form() { } if (data["type"] >= 15 && data["type"] <= 18) { - $("#snmp_version").val(data["tcp_send"]); - $("#text-snmp3_auth_user").val(data["plugin_user"]); - $("#password-snmp3_auth_pass").val(data["plugin_pass"]); - $("#snmp3_auth_method").val(data["plugin_parameter"]); - $("#snmp3_privacy_method").val(data["custom_string_1"]); - $("#password-snmp3_privacy_pass").val(data["custom_string_2"]); - $("#snmp3_security_level").val(data["custom_string_3"]); + $("#snmp_version").val(data["snmp_version"]); + $("#text-snmp3_auth_user").val(data["snmp3_auth_user"]); + $("#password-snmp3_auth_pass").val(data["snmp3_auth_pass"]); + $("#snmp3_auth_method").val(data["snmp3_auth_method"]); + $("#snmp3_privacy_method").val(data["snmp3_privacy_method"]); + $("#password-snmp3_privacy_pass").val(data["snmp3_privacy_pass"]); + $("#snmp3_security_level").val(data["snmp3_security_level"]); if (data["tcp_send"] == "3") { $("#simple-field_snmpv3_row1").attr("style", ""); @@ -564,6 +564,14 @@ function configure_modules_form() { if (data["id_plugin"] != undefined) { $("#id_plugin").trigger("change"); } + + if (data["type"] >= 34 && data["type"] <= 37) { + $("#command_text").val(data["command_text"]); + $("#command_credential_identifier").val( + data["command_credential_identifier"] + ); + $("#command_os").val(data["command_os"]); + } }, "json" ); From 6d21f7161710ca54fd1e45bed358def33d7ac7d9 Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Mon, 28 Oct 2019 18:38:56 +0100 Subject: [PATCH 40/81] removed trace --- pandora_console/godmode/agentes/module_manager_editor.php | 1 - 1 file changed, 1 deletion(-) diff --git a/pandora_console/godmode/agentes/module_manager_editor.php b/pandora_console/godmode/agentes/module_manager_editor.php index 9db5fa0ed3..874fe3a9d1 100644 --- a/pandora_console/godmode/agentes/module_manager_editor.php +++ b/pandora_console/godmode/agentes/module_manager_editor.php @@ -100,7 +100,6 @@ if (is_ajax()) { $component['warning_inverse'] = (bool) $component['warning_inverse']; $component['critical_inverse'] = (bool) $component['critical_inverse']; - hd($component, true); echo io_json_mb_encode($component); return; } From 57bfc364aead6b49cb3500f1f5444d7d428e016f Mon Sep 17 00:00:00 2001 From: marcos Date: Mon, 28 Oct 2019 18:57:10 +0100 Subject: [PATCH 41/81] add modal confirmation window --- pandora_console/general/register.php | 2 +- .../godmode/agentes/configurar_agente.php | 2 +- .../godmode/agentes/module_manager_editor.php | 2 +- .../include/class/WelcomeWindow.class.php | 77 ++++++++++++---- pandora_console/include/javascript/pandora.js | 92 ++++++++++++++++++- 5 files changed, 151 insertions(+), 24 deletions(-) diff --git a/pandora_console/general/register.php b/pandora_console/general/register.php index 41996a31ef..a07504a6bd 100644 --- a/pandora_console/general/register.php +++ b/pandora_console/general/register.php @@ -175,7 +175,7 @@ if (!$config['disabled_newsletter']) { $welcome = !$registration && !$show_newsletter && !$initial; $welcome_window = WelcomeWindow::initialize($welcome); -if ($welcome_window && $config['welcome_started'] === 1) { +if ($welcome_window) { $welcome_window->run(); } diff --git a/pandora_console/godmode/agentes/configurar_agente.php b/pandora_console/godmode/agentes/configurar_agente.php index 1bbf1384c8..f1830744af 100644 --- a/pandora_console/godmode/agentes/configurar_agente.php +++ b/pandora_console/godmode/agentes/configurar_agente.php @@ -2266,7 +2266,7 @@ if ($updateGIS) { // ----------------------------------- // Load page depending on tab selected // ----------------------------------- -if (!$_SESSION['create_module']) { +if ($_SESSION['create_module'] && $config['welcome_started'] == 1) { $edit_module = true; } diff --git a/pandora_console/godmode/agentes/module_manager_editor.php b/pandora_console/godmode/agentes/module_manager_editor.php index feb52a945c..18a1da00ff 100644 --- a/pandora_console/godmode/agentes/module_manager_editor.php +++ b/pandora_console/godmode/agentes/module_manager_editor.php @@ -321,7 +321,7 @@ if ($id_agent_module) { } else { if (!isset($moduletype)) { $moduletype = (string) get_parameter('moduletype'); - if (!$_SESSION['create_module']) { + if ($_SESSION['create_module'] && $config['welcome_started'] == 1) { $moduletype = 'networkserver'; } diff --git a/pandora_console/include/class/WelcomeWindow.class.php b/pandora_console/include/class/WelcomeWindow.class.php index 43fa894642..0ccb8b4617 100644 --- a/pandora_console/include/class/WelcomeWindow.class.php +++ b/pandora_console/include/class/WelcomeWindow.class.php @@ -48,7 +48,10 @@ class WelcomeWindow extends Wizard * * @var array */ - public $AJAXMethods = ['loadWelcomeWindow']; + public $AJAXMethods = [ + 'loadWelcomeWindow', + 'cancelWelcome', + ]; /** * Url of controller. @@ -65,6 +68,21 @@ class WelcomeWindow extends Wizard public $step; + /** + * Generates a JSON error. + * + * @param string $msg Error message. + * + * @return void + */ + public function error($msg) + { + echo json_encode( + ['error' => $msg] + ); + } + + /** * Checks if target method is available to be called using AJAX. * @@ -137,9 +155,30 @@ class WelcomeWindow extends Wizard }, onshow: { page: 'ajaxController; ?>', - method: 'loadWelcomeWindow' + method: 'loadWelcomeWindow', }, + oncancel: { + page: 'ajaxController; ?>', + title: "", + method: 'cancelWelcome', + confirm: function (fn) { + confirmDialog({ + title: '', + message: '', + ok: '', + cancel: '', + onAccept: function() { + // Continue execution. + fn(); + } + }) + }, + callback: function(data) { + console.log(data); + } + } }); + step = 'create_agent'; @@ -406,18 +454,16 @@ class WelcomeWindow extends Wizard /** - * Esto es un constructor realmente... - * se llama desde la navegación normal , no ajax + * This function acts as a constructor. + * Receive the condition to check with the global config (welcome_started) if continues */ public static function initialize($must_run) { global $config; - if ($must_run === false) { + if ($must_run === false || $config['welcome_started'] != WELCOME_STARTED) { // Do not start unless already started. - if ($config['welcome_started'] != WELCOME_STARTED) { return false; - } } // Calculate steps. @@ -515,25 +561,22 @@ class WelcomeWindow extends Wizard /** - * DOCUMENTA!!! + * function that enables the functions to the buttons when its action is completed. + * * Assign the url of each button */ public function loadJS() { ob_start(); ?> ' + settings.message + "" + ); + $("#confirm_" + randomStr); + $("#confirm_" + randomStr) + .dialog({ + title: settings.title, + close: false, + width: 350, + modal: true, + buttons: [ + { + text: "Cancel", + class: + "ui-widget ui-state-default ui-corner-all ui-button-text-only sub upd submit-cancel", + click: function() { + $(this).dialog("close"); + if (typeof settings.onDeny == "function") settings.onDeny(); + } + }, + { + text: "Ok", + class: + "ui-widget ui-state-default ui-corner-all ui-button-text-only sub ok submit-next", + click: function() { + $(this).dialog("close"); + if (typeof settings.onAccept == "function") settings.onAccept(); + } + } + ] + }) + .show(); +} From 2e629af15c7bf9c4ac4d7205886b2d86f467ef13 Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Mon, 28 Oct 2019 20:43:36 +0100 Subject: [PATCH 42/81] Simplified log message avoid extra symbols "*" --- pandora_server/lib/PandoraFMS/Tools.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandora_server/lib/PandoraFMS/Tools.pm b/pandora_server/lib/PandoraFMS/Tools.pm index ba15f03d24..3a3e1904a0 100755 --- a/pandora_server/lib/PandoraFMS/Tools.pm +++ b/pandora_server/lib/PandoraFMS/Tools.pm @@ -657,7 +657,7 @@ sub logger ($$;$) { if (defined $parent_caller) { $parent_caller = (split '/', $parent_caller)[-1]; $parent_caller =~ s/\.[^.]+$//; - $parent_caller = " ** " . $parent_caller . " **: "; + $parent_caller = " " . $parent_caller . ": "; } else { $parent_caller = " "; } From f6fd5cc21fd75ce884094bf4b0553ede8ac787ed Mon Sep 17 00:00:00 2001 From: Daniel Barbero Martin Date: Tue, 29 Oct 2019 09:13:48 +0100 Subject: [PATCH 43/81] Add image feedback --- pandora_console/general/header.php | 4 ++-- pandora_console/include/class/Diagnostics.class.php | 5 +---- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/pandora_console/general/header.php b/pandora_console/general/header.php index 70978bbcb5..e060cf96f6 100644 --- a/pandora_console/general/header.php +++ b/pandora_console/general/header.php @@ -334,13 +334,13 @@ if ($config['menu_type'] == 'classic') { $header_feedback .= ''; $header_feedback .= ''; $header_feedback .= html_print_image( - '/images/icono_warning.png', + '/images/feedback-header.png', true, [ 'title' => __('Feedback'), 'id' => 'feedback-header', 'alt' => __('Feedback'), - 'style' => 'cursor: pointer; width: 28px;', + 'style' => 'cursor: pointer; width: 27px;', ] ); $header_feedback .= ''; diff --git a/pandora_console/include/class/Diagnostics.class.php b/pandora_console/include/class/Diagnostics.class.php index b839851421..43f3d948b4 100644 --- a/pandora_console/include/class/Diagnostics.class.php +++ b/pandora_console/include/class/Diagnostics.class.php @@ -1865,9 +1865,8 @@ class Diagnostics extends Wizard { global $config; - // TODO: feedback@artica.es $mail_feedback = 'feedback@artica.es'; - $email = 'daniel.barbero@artica.es'; + $email = $mail_feedback; $subject = 'PandoraFMS Report '.$config['pandora_uid']; $text = get_parameter('what-happened', ''); $attachment = get_parameter_switch('include_installation_data', 0); @@ -1877,9 +1876,7 @@ class Diagnostics extends Wizard $product_name = io_safe_output(get_product_name()); if (check_acl($config['id_user'], 0, 'PM') !== 1) { - // TODO: MAIL TO ADMIN. $email = get_mail_admin(); - $email = 'daniel.barbero@artica.es'; $name_admin = get_name_admin(); $subject = __('Feedback').' '.$product_name.' '.$config['pandora_uid']; From 6ff85d2abb61c37f0052851e789256d86c70e16c Mon Sep 17 00:00:00 2001 From: Daniel Barbero Martin Date: Tue, 29 Oct 2019 09:21:08 +0100 Subject: [PATCH 44/81] fixed image --- pandora_console/images/feedback-header.png | Bin 0 -> 578 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 pandora_console/images/feedback-header.png diff --git a/pandora_console/images/feedback-header.png b/pandora_console/images/feedback-header.png new file mode 100644 index 0000000000000000000000000000000000000000..c77ff461e419a416a030d1e4d70568c5b93619d5 GIT binary patch literal 578 zcmV-I0=@l-P)5(?Fc7pg6yOd*8pybV zm{*>G3W6&ze(?)Ke!MUh5GugmynqU#q=Bder-R&OR+&Q>*(Sry9Gozy{IFOoN*_k(0bT-}ZBPE;gfVGCZpc?eRJ0->a0XqISLAcr`0A;U zs~VGMAR1A;IZHqr#sFu~oPsO6_VRXT+f_Y3e3mstTeNXN`}7F`1#!7M2B&~j0s#Dr zJi@DjNb;Jt?m%*DlT%`GTL%t{1vuNp4FKQ(tzFyq%Gr3EN1ZL9{S!RB;|Ya08q*Yu zJA9-|1yAGTKOPYXxn+CD%_c2J*}444Trpo%&XBC^bsL_!k7sCwMsVqB6#yCJN&F!& zX!Qa2%P4G^ Date: Tue, 29 Oct 2019 10:38:22 +0100 Subject: [PATCH 45/81] add help option in welcome window --- pandora_console/images/feedback-header.png | Bin 0 -> 578 bytes .../include/class/WelcomeWindow.class.php | 16 +++++----------- 2 files changed, 5 insertions(+), 11 deletions(-) create mode 100644 pandora_console/images/feedback-header.png diff --git a/pandora_console/images/feedback-header.png b/pandora_console/images/feedback-header.png new file mode 100644 index 0000000000000000000000000000000000000000..c77ff461e419a416a030d1e4d70568c5b93619d5 GIT binary patch literal 578 zcmV-I0=@l-P)5(?Fc7pg6yOd*8pybV zm{*>G3W6&ze(?)Ke!MUh5GugmynqU#q=Bder-R&OR+&Q>*(Sry9Gozy{IFOoN*_k(0bT-}ZBPE;gfVGCZpc?eRJ0->a0XqISLAcr`0A;U zs~VGMAR1A;IZHqr#sFu~oPsO6_VRXT+f_Y3e3mstTeNXN`}7F`1#!7M2B&~j0s#Dr zJi@DjNb;Jt?m%*DlT%`GTL%t{1vuNp4FKQ(tzFyq%Gr3EN1ZL9{S!RB;|Ya08q*Yu zJA9-|1yAGTKOPYXxn+CD%_c2J*}444Trpo%&XBC^bsL_!k7sCwMsVqB6#yCJN&F!& zX!Qa2%P4G^ 'div', 'block_id' => 'div_not_working', 'class' => 'flex-row w100p', 'direct' => 1, 'block_content' => [ [ - 'label' => __('If something is not working as expected... Report!'), + 'label' => __('If something is not working as expected, look for this icon and report!'), 'arguments' => [ 'class' => 'first_lbl', 'name' => 'lbl_not_working', @@ -425,16 +424,11 @@ class WelcomeWindow extends Wizard ], ], [ - 'arguments' => [ - 'label' => '', - 'type' => 'button', - 'attributes' => 'class="go pending '.$btn_create.'"', - 'name' => 'btn_not_working', - 'id' => 'btn_not_working', - ], + 'label' => html_print_image('images/feedback-header.png', true), + ], ], - ],*/ + ], ]; $output = $this->printForm( From f3fdcb4de030331546f3c6af34cf6765427219e3 Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Tue, 29 Oct 2019 16:06:34 +0100 Subject: [PATCH 46/81] MR update --- pandora_console/extras/mr/{34.sql => 33.sql} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename pandora_console/extras/mr/{34.sql => 33.sql} (100%) diff --git a/pandora_console/extras/mr/34.sql b/pandora_console/extras/mr/33.sql similarity index 100% rename from pandora_console/extras/mr/34.sql rename to pandora_console/extras/mr/33.sql From 3eb0a6bb9513953b2ab455c9db5879d01eb421d7 Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Wed, 30 Oct 2019 18:33:33 +0100 Subject: [PATCH 47/81] minor fixes after internal meeting --- .../include/class/WelcomeWindow.class.php | 125 +++++++++--------- pandora_console/include/javascript/pandora.js | 121 +++++++++-------- .../new_installation_welcome_window.css | 62 ++++----- 3 files changed, 151 insertions(+), 157 deletions(-) diff --git a/pandora_console/include/class/WelcomeWindow.class.php b/pandora_console/include/class/WelcomeWindow.class.php index 1dcdf61377..4381323439 100644 --- a/pandora_console/include/class/WelcomeWindow.class.php +++ b/pandora_console/include/class/WelcomeWindow.class.php @@ -142,7 +142,8 @@ class WelcomeWindow extends Wizard url: '', modal: { title: "", - cancel: '', + cancel: '', + ok: '' }, onshow: { page: 'ajaxController; ?>', @@ -251,11 +252,11 @@ class WelcomeWindow extends Wizard public function loadWelcomeWindow() { global $config; - $btn_configure_mail_class = ''; - $btn_create_agent_class = ''; + $btn_configure_mail_class = 'pending'; + $btn_create_agent_class = 'pending'; $btn_create_module_class = ''; $btn_create_alert_class = ''; - $btn_create_discovery_class = ''; + $btn_create_discovery_class = 'pending'; switch ($this->step) { case W_CREATE_AGENT: @@ -455,7 +456,14 @@ class WelcomeWindow extends Wizard ], ], [ - 'label' => html_print_image('images/feedback-header.png', true), + 'label' => html_print_image( + 'images/feedback-header.png', + true, + [ + 'onclick' => '$(\'#feedback-header\').click()', + 'style' => 'cursor: pointer;', + ] + ), ], ], @@ -490,25 +498,23 @@ class WelcomeWindow extends Wizard { global $config; + if (isset($config['welcome_state']) === false) { + $this->setStep(W_CONFIGURE_MAIL); + } + + // Check current page. + $sec2 = get_parameter('sec2', ''); + if ($must_run === false - || (isset($config['welcome_state']) === true - && $config['welcome_state'] === WELCOME_FINISHED) + || $config['welcome_state'] === WELCOME_FINISHED ) { - // Do not start unless not finished. + // Do not show if finished. return false; } - $sec2 = get_parameter('sec2', ''); $this->step = $this->getStep(); $this->agent = $this->getWelcomeAgent(); - if ($sec2 === '') { - // Unless finished. - if ($this->step !== WELCOME_FINISHED) { - return true; - } - } - /* * Configure mail. Control current flow. * @@ -530,8 +536,8 @@ class WelcomeWindow extends Wizard ) { // Mail configuration is being processed. return false; - } else { - // Any other page, show welcome. + } else if (empty($sec2) === true) { + // If at main page, show welcome. return true; } } @@ -561,8 +567,8 @@ class WelcomeWindow extends Wizard } else if ($sec2 === 'godmode/agentes/configurar_agente') { // Agent is being created. return false; - } else { - // Any other page, show welcome. + } else if (empty($sec2) === true) { + // If at main page, show welcome. return true; } } @@ -589,8 +595,8 @@ class WelcomeWindow extends Wizard ) { // Module is being created. return false; - } else { - // Any other page, show welcome. + } else if (empty($sec2) === true) { + // If at main page, show welcome. return true; } } @@ -617,8 +623,8 @@ class WelcomeWindow extends Wizard ) { // Alert is being created. return false; - } else { - // Any other page, show welcome. + } else if (empty($sec2) === true) { + // If at main page, show welcome. return true; } } @@ -645,8 +651,8 @@ class WelcomeWindow extends Wizard } else if ($sec2 == 'godmode/servers/discovery') { // Discovery task is being created. return false; - } else { - // Any other page, show welcome. + } else if (empty($sec2) === true) { + // If at main page, show welcome. return true; } } @@ -675,59 +681,46 @@ class WelcomeWindow extends Wizard ?>