diff --git a/pandora_console/extras/delete_files/delete_files.txt b/pandora_console/extras/delete_files/delete_files.txt index b18abb678d..8964458b93 100644 --- a/pandora_console/extras/delete_files/delete_files.txt +++ b/pandora_console/extras/delete_files/delete_files.txt @@ -3,4 +3,15 @@ operation/users/webchat.php include/javascript/webchat.js attachment/pandora_chat.log.json.txt attachment/pandora_chat.user_list.json.txt -attachment/pandora_chat.global_counter.txt \ No newline at end of file +attachment/pandora_chat.global_counter.txt +enterprise/godmode/reporting/cluster_agent_check.php +enterprise/godmode/reporting/cluster_builder.main.php +enterprise/godmode/reporting/cluster_builder.php +enterprise/godmode/reporting/cluster_force.php +enterprise/godmode/reporting/cluster_list.php +enterprise/godmode/reporting/cluster_name_agents.php +enterprise/godmode/reporting/cluster_view.php +enterprise/include/ajax/clustermap.php +enterprise/include/functions_clustermap.php +enterprise/include/functions_clusters.php +enterprise/include/javascript/ClusterMapController.js \ No newline at end of file diff --git a/pandora_console/general/first_task/cluster_builder.php b/pandora_console/general/first_task/cluster_builder.php index e80d4e4b15..1b67906aa7 100644 --- a/pandora_console/general/first_task/cluster_builder.php +++ b/pandora_console/general/first_task/cluster_builder.php @@ -52,7 +52,7 @@ ui_print_info_message(['no_close' => true, 'message' => __('There are no cluster if (check_acl($config['id_user'], 0, 'AW')) { ?> -
+
diff --git a/pandora_console/general/noaccess.php b/pandora_console/general/noaccess.php index c091215829..4a048e905e 100644 --- a/pandora_console/general/noaccess.php +++ b/pandora_console/general/noaccess.php @@ -139,7 +139,9 @@ font-size:10pt; echo '

'; echo __('Please know that all attempts to access this page are recorded in security logs of %s System Database', get_product_name()); if ($config['logged'] == false) { - session_destroy(); + if (session_status() === PHP_SESSION_ACTIVE) { + session_destroy(); + } } ?> diff --git a/pandora_console/godmode/agentes/modificar_agente.php b/pandora_console/godmode/agentes/modificar_agente.php index 244e1d8618..9d69e1148e 100644 --- a/pandora_console/godmode/agentes/modificar_agente.php +++ b/pandora_console/godmode/agentes/modificar_agente.php @@ -556,9 +556,18 @@ if ($agents !== false) { $agent['alias'] = $agent['nombre']; } - if ($agent['id_os'] == 100) { - $cluster = db_get_row_sql('select id from tcluster where id_agent = '.$agent['id_agente']); - echo ''.$agent['alias'].''; + if ($agent['id_os'] == CLUSTER_OS_ID) { + if (enterprise_installed()) { + $cluster = PandoraFMS\Enterprise\Cluster::loadFromAgentId( + $agent['id_agente'] + ); + $url = 'index.php?sec=reporting&sec2='.ENTERPRISE_DIR; + $url .= '/operation/cluster/cluster'; + $url = ui_get_full_url( + $url.'&op=update&id='.$cluster->id() + ); + echo ''.$agent['alias'].''; + } } else { echo ''; @@ -654,14 +661,14 @@ class HTML $output .= ''; } } else { - $output .= $this->printInput($input['arguments']); + $output .= self::printInput($input['arguments']); } // Allow dynamic content. $output .= $input['extra']; $output .= ''; } else { - $output .= $this->printInput($input['arguments']); + $output .= self::printInput($input['arguments']); // Allow dynamic content. $output .= $input['extra']; } @@ -683,7 +690,7 @@ class HTML * * @return string HTML content. */ - public function printBlockAsList(array $input, bool $return=false) + public static function printBlockAsList(array $input, bool $return=false) { $output = ''; if ($input['hidden'] == 1) { @@ -701,7 +708,7 @@ class HTML $output .= '
  • '; $output .= '
  • '; @@ -711,12 +718,12 @@ class HTML ) { $output .= '
  • '; $output .= ''; - $output .= $this->printInput($input['arguments']); + $output .= self::printInput($input['arguments']); // Allow dynamic content. $output .= $input['extra']; $output .= '
  • '; } else { - $output .= $this->printInput($input['arguments']); + $output .= self::printInput($input['arguments']); // Allow dynamic content. $output .= $input['extra']; } @@ -739,7 +746,7 @@ class HTML * * @return string HTML code. */ - public function printForm( + public static function printForm( array $data, bool $return=false, bool $print_white_box=false @@ -752,7 +759,12 @@ class HTML $cb_function = $data['cb_function']; $cb_args = $data['cb_args']; - $output_head = '
    '; if ($return === false) { @@ -781,9 +793,9 @@ class HTML foreach ($inputs as $input) { if ($input['arguments']['type'] != 'submit') { - $output .= $this->printBlock($input, true); + $output .= self::printBlock($input, true); } else { - $output_submit .= $this->printBlock($input, true); + $output_submit .= self::printBlock($input, true); } } @@ -822,7 +834,7 @@ class HTML * * @return string HTML code. */ - public function printFormAsGrid(array $data, bool $return=false) + public static function printFormAsGrid(array $data, bool $return=false) { $form = $data['form']; @@ -886,9 +898,9 @@ class HTML foreach ($column['inputs'] as $input) { if (is_array($input)) { if ($input['arguments']['type'] != 'submit') { - $output .= $this->printBlockAsGrid($input, true); + $output .= self::printBlockAsGrid($input, true); } else { - $output_submit .= $this->printBlockAsGrid($input, true); + $output_submit .= self::printBlockAsGrid($input, true); } } else { $output .= $input; @@ -933,7 +945,7 @@ class HTML * * @return string HTML code. */ - public function printFormAsList(array $data, bool $return=false) + public static function printFormAsList(array $data, bool $return=false) { $form = $data['form']; $inputs = $data['inputs']; @@ -966,9 +978,9 @@ class HTML foreach ($inputs as $input) { if ($input['arguments']['type'] != 'submit') { - $output .= $this->printBlockAsList($input, true); + $output .= self::printBlockAsList($input, true); } else { - $output_submit .= $this->printBlockAsList($input, true); + $output_submit .= self::printBlockAsList($input, true); } } diff --git a/pandora_console/include/class/NetworkMap.class.php b/pandora_console/include/class/NetworkMap.class.php index ce50b487de..e23b148c68 100644 --- a/pandora_console/include/class/NetworkMap.class.php +++ b/pandora_console/include/class/NetworkMap.class.php @@ -514,6 +514,8 @@ class NetworkMap */ public function createMap() { + global $config; + // If exists, load from DB. if ($this->idMap) { $this->loadMap(); @@ -1025,13 +1027,17 @@ class NetworkMap // Handmade ones. // Add also parent relationship. if (isset($node['id_parent'])) { - $parent_id = $node['id_parent']; + $parent_id = NODE_AGENT.'_'.$node['id_parent']; + $parent_node = $this->nodes[$parent_id]['id_node']; - if ((int) $parent_id >= 0) { - $parent_node = $this->getNodeData( - (int) $parent_id, - 'id_node' - ); + if ($parent_node === null) { + $parent_id = NODE_MODULE.'_'.$node['id_parent']; + $parent_node = $this->nodes[$parent_id]['id_node']; + } + + if ($parent_node === null) { + $parent_id = NODE_GENERIC.'_'.$node['id_parent']; + $parent_node = $this->nodes[$parent_id]['id_node']; } // Store relationship. @@ -1130,6 +1136,7 @@ class NetworkMap $map_filter = $this->mapOptions['map_filter']; $nooverlap = $this->mapOptions['nooverlap']; $zoom = $this->mapOptions['zoom']; + $layout = $this->mapOptions['layout']; if (isset($this->mapOptions['width']) && isset($this->mapOptions['height']) @@ -1152,7 +1159,7 @@ class NetworkMap $size = $size_x.','.$size_y; - if ($size_canvas === null) { + if ($this->mapOptions['size_canvas'] !== null) { $size = ($this->mapOptions['size_canvas']['x'] / 100); $size .= ','.($this->mapOptions['size_canvas']['y'] / 100); } @@ -1274,12 +1281,7 @@ class NetworkMap $radius /= GRAPHVIZ_CONVERSION_FACTOR; if (is_array($label)) { - $label = array_reduce( - function ($carry, $item) { - $carry .= $item; - return $carry; - } - ); + $label = join('', $label); } if (strlen($label) > 16) { @@ -1295,7 +1297,7 @@ class NetworkMap // retrieve X,Y positions from graphviz no for personalization. $dot_str = $data['id_node'].' [ parent="'.$data['id_parent'].'"'; $dot_str .= ', color="'.$color.'", fontsize='.$font_size; - $dot_str .= ', shape="doublecircle"'.$url_node_link; + $dot_str .= ', shape="doublecircle"'.$data['url_node_link']; $dot_str .= ', style="filled", fixedsize=true, width='.$radius; $dot_str .= ', height='.$radius.', label="'.$label.'"]'."\n"; @@ -1535,14 +1537,15 @@ class NetworkMap /** * Returns target color to be used based on the status received. * - * @param integer $status Source information. + * @param integer $status Source information. + * @param boolean $force_module It's a module. * * @return string HTML tag for color. */ - public static function getColorByStatus($status) + public static function getColorByStatus($status, ?bool $force_module=false) { include_once __DIR__.'/../functions_modules.php'; - return modules_get_color_status($status); + return modules_get_color_status($status, $force_module); } @@ -1596,6 +1599,7 @@ class NetworkMap global $config; $return = []; + $count_item_holding_area = 0; foreach ($nodes as $node) { $item = []; $item['id'] = $node['id']; @@ -1658,6 +1662,10 @@ class NetworkMap case NODE_MODULE: $item['id_module'] = $node['source_data']; + $item['color'] = self::getColorByStatus( + $source_data['status'], + true + ); break; case NODE_PANDORA: @@ -1669,8 +1677,11 @@ class NetworkMap default: foreach ($source_data as $k => $v) { $node[$k] = $v; + $item[$k] = $v; } + $item['id_agent'] = $node['id_agente']; + if (!empty($node['text'])) { $node['style']['label'] = $node['text']; } else { @@ -1681,7 +1692,8 @@ class NetworkMap $item['color'] = $source_data['color']; } else { $item['color'] = self::getColorByStatus( - $node['status'] + $node['status'], + (bool) $node['id_module'] ); } break; @@ -2193,6 +2205,7 @@ class NetworkMap $nodes = []; $relations = []; + foreach ($content as $key => $line) { // Reduce blank spaces. $line = preg_replace('/\ +/', ' ', $line); @@ -2232,12 +2245,12 @@ class NetworkMap } $relations[] = [ - 'id_parent' => $target_node['id_node'], + 'id_parent' => $fields[1], 'parent_type' => NODE_GENERIC, - 'id_parent_source_data' => $mod_rel['module_b'], - 'id_child' => $node['id_node'], + 'id_parent_source_data' => $fields[3], + 'id_child' => $fields[2], 'child_type' => NODE_GENERIC, - 'id_child_source_data' => $mod_rel['module_a'], + 'id_child_source_data' => null, ]; } } @@ -2268,11 +2281,11 @@ class NetworkMap case 'WIN32': case 'WINNT': case 'Windows': - $filename_dot = sys_get_temp_dir()."\\networkmap_".$filter; + $filename_dot = sys_get_temp_dir()."\\networkmap_".$this->filter; break; default: - $filename_dot = sys_get_temp_dir().'/networkmap_'.$filter; + $filename_dot = sys_get_temp_dir().'/networkmap_'.$this->filter; break; } @@ -2395,36 +2408,6 @@ class NetworkMap } - /** - * Returns the most representative ID based on the tipe of node received. - * - * @param array $node Source data. - * - * @return integer Source id. - */ - private function auxGetIdByType($node) - { - if (!is_array($node)) { - return 0; - } - - switch ($to_source['node_type']) { - case NODE_MODULE: - return $node['id_agente_modulo']; - - case NODE_AGENT: - return $node['id_agente']; - - case NODE_GENERIC: - return $node['id_node']; - - case NODE_PANDORA: - default: - return 0; - } - } - - /** * Generates a nodes - relationships array using graphviz dot * schema and stores nodes&relations into $this->graph. @@ -2551,6 +2534,7 @@ class NetworkMap $node_tmp['id_agent'] = $source['id_agente']; $node_tmp['id_module'] = $source['id_agente_modulo']; $node_tmp['source_data'] = $source['id_source']; + $node_tmp['image'] = $source['image']; break; } @@ -3314,9 +3298,11 @@ class NetworkMap /** * Loads advanced map controller (JS). * + * @param boolean $return Dumps to output if false. + * * @return string HTML code for advanced controller. */ - public function loadController() + public function loadController(?bool $return=true) { $output = ''; @@ -3482,7 +3468,7 @@ class NetworkMap $output .= ' style="position: absolute; left: 0px; top: 0px;">'; $output .= ''; $output .= html_print_image('/images/minimap_open_arrow.png', true, ['id' => 'arrow_minimap_'.$networkmap['id']]); - $output .= '
    '; + $output .= ''; $output .= '
    map; + // ACL. $networkmap_read = check_acl( $config['id_user'], diff --git a/pandora_console/include/constants.php b/pandora_console/include/constants.php index e6c4108615..25674080d0 100644 --- a/pandora_console/include/constants.php +++ b/pandora_console/include/constants.php @@ -356,6 +356,9 @@ define('MODULE_PREDICTION_CLUSTER', 5); define('MODULE_PREDICTION_CLUSTER_AA', 6); define('MODULE_PREDICTION_CLUSTER_AP', 7); +// Forced agent OS ID for cluster agents. +define('CLUSTER_OS_ID', 100); + // Type of Webserver Modules. define('MODULE_WEBSERVER_CHECK_LATENCY', 30); define('MODULE_WEBSERVER_CHECK_SERVER_RESPONSE', 31); diff --git a/pandora_console/include/functions_agents.php b/pandora_console/include/functions_agents.php index fdb12fac59..6c1bcbc331 100644 --- a/pandora_console/include/functions_agents.php +++ b/pandora_console/include/functions_agents.php @@ -19,7 +19,29 @@ require_once $config['homedir'].'/include/functions.php'; require_once $config['homedir'].'/include/functions_modules.php'; -require_once $config['homedir'].'/include/functions_users.php'; +require_once $config['homedir'].'/include/functions_users.php';/** + * Return the agent if exists in the DB. + * + * @param integer $id_agent The agent id. + * @param boolean $show_disabled Show the agent found althought it is disabled. By default false. + * @param boolean $force_meta + * + * @return boolean The result to check if the agent is in the DB. + */ + + +function agents_get_agent($id_agent, $show_disabled=true, $force_meta=false) +{ + $agent = db_get_row_filter( + $force_meta ? 'tmetaconsole_agent' : 'tagente', + [ + 'id_agente' => $id_agent, + 'disabled' => !$show_disabled, + ] + ); + + return $agent; +} /** @@ -3093,6 +3115,17 @@ function agents_get_agent_custom_field($agent_id, $custom_field_name) } +/** + * Unverified documentation. + * + * @param integer $id_group Module group. + * @param array $id_agents Array of agent ids. + * @param boolean $selection Show common (false) or all modules (true). + * @param boolean $return Return (false) or dump to output (true). + * @param boolean $index_by_name Use module name as key. + * + * @return array With modules or null if error. + */ function select_modules_for_agent_group( $id_group, $id_agents, diff --git a/pandora_console/include/functions_html.php b/pandora_console/include/functions_html.php index adf978d13f..f8d5fc91f8 100644 --- a/pandora_console/include/functions_html.php +++ b/pandora_console/include/functions_html.php @@ -605,22 +605,24 @@ function html_print_select( $output .= '