diff --git a/pandora_console/include/class/NetworkMap.class.php b/pandora_console/include/class/NetworkMap.class.php index 4656ad39f4..7829610a60 100644 --- a/pandora_console/include/class/NetworkMap.class.php +++ b/pandora_console/include/class/NetworkMap.class.php @@ -1727,7 +1727,10 @@ class NetworkMap $item['image_height'] = 0; if (empty($node['style']['image']) === false) { $item['image_url'] = ui_get_full_url( - $node['style']['image'] + $node['style']['image'], + false, + false, + false ); $image_size = getimagesize( $config['homedir'].'/'.$node['style']['image'] @@ -3391,7 +3394,7 @@ class NetworkMap && isset($this->useTooltipster) && $this->useTooltipster == true ) { - $output .= ''; $output .= ''; + $output .= ''; + if (isset($this->map['__simulated']) === false) { // Load context menu if manageable networkmap. - $output .= ''; + $output .= ''; } - $output .= ''; + $output .= ''; // Open networkconsole_id div. $output .= '
. + * @param boolean $meta_fields If true, then id_agente is returned instead id_tagente. * * @return array An array with all agents in the group or an empty array */ @@ -1096,7 +1097,8 @@ function agents_get_group_agents( $serialized=false, $separator='|', $add_alert_bulk_op=false, - $force_serialized=false + $force_serialized=false, + $meta_fields=false ) { global $config; @@ -1268,11 +1270,19 @@ function agents_get_group_agents( if (is_metaconsole()) { $table_name = 'tmetaconsole_agent ta LEFT JOIN tmetaconsole_agent_secondary_group tasg ON ta.id_agente = tasg.id_agent'; - $fields = [ - 'ta.id_tagente AS id_agente', - 'alias', - 'ta.id_tmetaconsole_setup AS id_server', - ]; + if ($meta_fields === true) { + $fields = [ + 'id_agente', + 'alias', + 'ta.id_tmetaconsole_setup AS id_server', + ]; + } else { + $fields = [ + 'ta.id_tagente AS id_agente', + 'alias', + 'ta.id_tmetaconsole_setup AS id_server', + ]; + } } else { $table_name = 'tagente LEFT JOIN tagent_secondary_group ON id_agente=id_agent'; @@ -3253,6 +3263,7 @@ function agents_get_agent_custom_field($agent_id, $custom_field_name) * @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. + * @param boolean $pure_return Return as retrieved from DB. * * @return array With modules or null if error. */ @@ -3261,7 +3272,8 @@ function select_modules_for_agent_group( $id_agents, $selection, $return=true, - $index_by_name=false + $index_by_name=false, + $pure_return=false ) { global $config; $agents = (empty($id_agents)) ? [] : implode(',', $id_agents); @@ -3341,6 +3353,10 @@ function select_modules_for_agent_group( return; } + if ($pure_return === true) { + return $modules; + } + $modules_array = []; foreach ($modules as $value) { if ($index_by_name) { diff --git a/pandora_console/include/functions_custom_graphs.php b/pandora_console/include/functions_custom_graphs.php index 17f52de0f1..bab64dd5fe 100644 --- a/pandora_console/include/functions_custom_graphs.php +++ b/pandora_console/include/functions_custom_graphs.php @@ -133,9 +133,14 @@ function custom_graphs_get_user($id_user=0, $only_names=false, $returnAllGroup=t continue; } - $all_graph = db_get_all_rows_in_table('tgraph', 'name'); - if ($all_graph !== false) { - $all_graphs = array_merge($all_graphs, $all_graph); + $tmp_graphs = db_get_all_rows_in_table('tgraph', 'name'); + if ($tmp_graphs !== false) { + foreach ($tmp_graphs as $g) { + $g['id_tgraph'] = $g['id_graph']; + $g['id_graph'] = $connection['id'].'|'.$g['id_graph']; + $g['name'] = $g['name'].' ('.$connection['server_name'].')'; + $all_graphs[] = $g; + } } metaconsole_restore_db(); @@ -168,10 +173,15 @@ function custom_graphs_get_user($id_user=0, $only_names=false, $returnAllGroup=t $graphs[$graph['id_graph']] = $graph['name']; } else { $graphs[$graph['id_graph']] = $graph; + $id_graph = 'id_graph'; + if ((bool) is_metaconsole() === true) { + $id_graph = 'id_tgraph'; + } + $graphsCount = db_get_value_sql( 'SELECT COUNT(id_gs) FROM tgraph_source - WHERE id_graph = '.$graph['id_graph'] + WHERE id_graph = '.$graph[$id_graph] ); $graphs[$graph['id_graph']]['graphs_count'] = $graphsCount; } diff --git a/pandora_console/include/functions_events.php b/pandora_console/include/functions_events.php index e82365bf89..9a8f2b8a1c 100644 --- a/pandora_console/include/functions_events.php +++ b/pandora_console/include/functions_events.php @@ -712,6 +712,7 @@ function events_update_status($id_evento, $status, $filter=null, $history=false) * @param boolean $validatedEvents If true, evaluate validated events. * @param boolean $recursiveGroups If true, filtered groups and their children * will be search. + * @param boolean $nodeConnected Already connected to node (uses tevento). * * @return array Events. * @throws Exception On error. @@ -727,7 +728,8 @@ function events_get_all( $return_sql=false, $having='', $validatedEvents=false, - $recursiveGroups=true + $recursiveGroups=true, + $nodeConnected=false ) { global $config; @@ -1017,7 +1019,10 @@ function events_get_all( ); } - $table = events_get_events_table(is_metaconsole(), $history); + $table = events_get_events_table( + (is_metaconsole() && $nodeConnected === false), + $history + ); $tevento = sprintf( ' %s te', $table @@ -1028,7 +1033,7 @@ function events_get_all( $tagente_table = 'tagente'; $tagente_field = 'id_agente'; $conditionMetaconsole = ''; - if (is_metaconsole()) { + if (is_metaconsole() && $nodeConnected === false) { $tagente_table = 'tmetaconsole_agent'; $tagente_field = 'id_tagente'; $conditionMetaconsole = ' AND ta.id_tmetaconsole_setup = te.server_id '; @@ -1075,7 +1080,7 @@ function events_get_all( ); } - if (is_metaconsole()) { + if (is_metaconsole() && $nodeConnected === false) { // Id source event. if (!empty($filter['id_source_event'])) { $sql_filters[] = sprintf( @@ -1239,7 +1244,7 @@ function events_get_all( // Query_table. '', // Meta. - is_metaconsole(), + is_metaconsole() && $nodeConnected === false, // Childrens_ids. [], // Force_group_and_tag. @@ -1265,7 +1270,7 @@ function events_get_all( // Query_table. '', // Meta. - is_metaconsole(), + is_metaconsole() && $nodeConnected === false, // Childrens_ids. [], // Force_group_and_tag. @@ -1291,7 +1296,7 @@ function events_get_all( // Query_table. '', // Meta. - is_metaconsole(), + is_metaconsole() && $nodeConnected === false, // Childrens_ids. [], // Force_group_and_tag. @@ -1312,7 +1317,7 @@ function events_get_all( // Module search. $agentmodule_join = 'LEFT JOIN tagente_modulo am ON te.id_agentmodule = am.id_agente_modulo'; - if (is_metaconsole()) { + if (is_metaconsole() && $nodeConnected === false) { $agentmodule_join = ''; } else if (!empty($filter['module_search'])) { $agentmodule_join = 'INNER JOIN tagente_modulo am ON te.id_agentmodule = am.id_agente_modulo'; @@ -1339,7 +1344,7 @@ function events_get_all( } $extra = ''; - if (is_metaconsole()) { + if (is_metaconsole() && $nodeConnected === false) { $extra = ', server_id'; } @@ -1405,7 +1410,7 @@ function events_get_all( } $server_join = ''; - if (is_metaconsole()) { + if (is_metaconsole() && $nodeConnected === false) { $server_join = ' LEFT JOIN tmetaconsole_setup ts ON ts.id = te.server_id'; if (!empty($filter['server_id'])) { diff --git a/pandora_console/include/functions_html.php b/pandora_console/include/functions_html.php index 0bce00abfa..b4cc07e6cd 100644 --- a/pandora_console/include/functions_html.php +++ b/pandora_console/include/functions_html.php @@ -1391,7 +1391,29 @@ function html_print_select_multiple_modules_filtered(array $data):string $output .= '
'; // Agent. - $agents = agents_get_group_agents($data['mGroup']); + $agents = agents_get_group_agents( + // Id_group. + $data['mGroup'], + // Search. + false, + // Case. + 'lower', + // NoACL. + false, + // ChildGroups. + false, + // Serialized. + false, + // Separator. + '|', + // Add_alert_bulk_op. + false, + // Force_serialized. + false, + // Meta_fields. + $data['mMetaFields'] + ); + if ((empty($agents)) === true || $agents == -1) { $agents = []; } @@ -4414,8 +4436,10 @@ function html_print_input($data, $wrapper='div', $input_only=false) return ''; } + enterprise_include_once('include/functions_metaconsole.php'); + if ($config['style'] === 'pandora_black') { - $style = 'style="color: white"'; + $style = 'style="color: white"'; } $output = ''; diff --git a/pandora_console/include/functions_networkmap.php b/pandora_console/include/functions_networkmap.php index 64a0dbbfe3..ed76a6b880 100644 --- a/pandora_console/include/functions_networkmap.php +++ b/pandora_console/include/functions_networkmap.php @@ -31,6 +31,7 @@ require_once 'functions_agents.php'; require_once $config['homedir'].'/include/functions_modules.php'; require_once $config['homedir'].'/include/functions_groups.php'; enterprise_include_once('include/functions_networkmap.php'); +enterprise_include_once('include/functions_metaconsole.php'); // Check if a node descends from a given node function networkmap_is_descendant($node, $ascendant, $parents) @@ -1228,7 +1229,7 @@ function networkmap_get_networkmap($id_networkmap, $filter=false, $fields=false, * @param array Extra filter. * @param array Fields to get. * - * @return Networkmap with the given id. False if not available or readable. + * @return array Networkmap with the given id. False if not available or readable. */ function networkmap_get_networkmaps( $id_user=null, @@ -1243,10 +1244,16 @@ function networkmap_get_networkmaps( $id_user = $config['id_user']; } - // Configure filters + // Configure filters. $where = []; $where['type'] = MAP_TYPE_NETWORKMAP; - $where['id_group'] = array_keys(users_get_groups($id_user, 'AR', $return_all_group)); + $where['id_group'] = array_keys( + users_get_groups( + $id_user, + 'AR', + $return_all_group + ) + ); if (!empty($type)) { $where['subtype'] = $type; } @@ -1256,7 +1263,30 @@ function networkmap_get_networkmaps( $where['order'][1]['field'] = 'name'; $where['order'][1]['order'] = 'ASC'; - $networkmaps_raw = db_get_all_rows_filter('tmap', $where); + if ((bool) is_metaconsole() === true) { + $servers = metaconsole_get_connection_names(); + foreach ($servers as $key => $server) { + $connection = metaconsole_get_connection($server); + if (metaconsole_connect($connection) != NOERR) { + continue; + } + + $tmp_maps = db_get_all_rows_filter('tmap', $where); + if ($tmp_maps !== false) { + foreach ($tmp_maps as $g) { + $g['id_t'] = $g['id']; + $g['id'] = $connection['id'].'_'.$g['id']; + $g['name'] = $g['name'].' ('.$connection['server_name'].')'; + $networkmaps_raw[] = $g; + } + } + + metaconsole_restore_db(); + } + } else { + $networkmaps_raw = db_get_all_rows_filter('tmap', $where); + } + if (empty($networkmaps_raw)) { return []; } diff --git a/pandora_console/include/graphs/functions_d3.php b/pandora_console/include/graphs/functions_d3.php index e195d3b1d4..abba81ea72 100644 --- a/pandora_console/include/graphs/functions_d3.php +++ b/pandora_console/include/graphs/functions_d3.php @@ -21,13 +21,32 @@ function include_javascript_d3($return=false) if (!$is_include_javascript) { $is_include_javascript = true; - if (is_metaconsole()) { - $output .= ''; - $output .= ''; - } else { - $output .= ''; - $output .= ''; - } + $output .= ''; + + $output .= ''; + + $output .= ''; } if (!$return) { diff --git a/pandora_console/include/javascript/pandora_dashboards.js b/pandora_console/include/javascript/pandora_dashboards.js index d992a9d5fa..a322dbe4d7 100644 --- a/pandora_console/include/javascript/pandora_dashboards.js +++ b/pandora_console/include/javascript/pandora_dashboards.js @@ -304,7 +304,7 @@ function initialiceLayout(data) { }, dataType: "html", success: function(data) { - console.log(data); + return data; }, error: function(error) { console.error(error); @@ -782,7 +782,8 @@ function dashboardLoadNetworkMap(settings) { auth_class: settings.auth_class, auth_hash: settings.auth_hash, id_user: settings.id_user, - ignore_acl: 1 + ignore_acl: 1, + node: settings.node }, dataType: "html", success: function(data) { diff --git a/pandora_console/include/lib/Dashboard/Cell.php b/pandora_console/include/lib/Dashboard/Cell.php index fdc6b3366d..964d43e668 100644 --- a/pandora_console/include/lib/Dashboard/Cell.php +++ b/pandora_console/include/lib/Dashboard/Cell.php @@ -216,8 +216,6 @@ class Cell */ public static function getCells(int $dashboardId):array { - global $config; - $cells = db_get_all_rows_filter( 'twidget_dashboard', [ diff --git a/pandora_console/include/lib/Dashboard/Manager.php b/pandora_console/include/lib/Dashboard/Manager.php index a9a1f5051e..be87ef8732 100644 --- a/pandora_console/include/lib/Dashboard/Manager.php +++ b/pandora_console/include/lib/Dashboard/Manager.php @@ -178,6 +178,7 @@ class Manager 'saveWidgetIntoCell', 'imageIconDashboardAjax', 'formSlides', + 'callWidgetMethod', ]; @@ -1014,6 +1015,10 @@ class Manager // Header. if ($this->slides === 0) { + if ((bool) \is_metaconsole() === true) { + open_meta_frame(); + } + View::render( 'dashboard/header', [ @@ -1098,6 +1103,13 @@ class Manager 'dashboard/jsLayout', ['dashboardId' => $this->dashboardId] ); + + if ((bool) \is_metaconsole() === true + && $this->slides === 0 + ) { + close_meta_frame(); + } + return null; } @@ -1490,4 +1502,25 @@ class Manager } + /** + * Call widget method (ajax only). + * + * @param string $method Method to be invoked. + * + * @return boolean Executed or not. + */ + public function callWidgetMethod(string $method):bool + { + $widget = $this->instanceWidget(); + + if (method_exists($widget, $method) === true) { + $widget->$method(); + return true; + } + + return false; + + } + + } diff --git a/pandora_console/include/lib/Dashboard/Widget.php b/pandora_console/include/lib/Dashboard/Widget.php index 794a7e36cc..2100428b6e 100644 --- a/pandora_console/include/lib/Dashboard/Widget.php +++ b/pandora_console/include/lib/Dashboard/Widget.php @@ -14,7 +14,7 @@ class Widget * * @var integer */ - private $dashboardId; + protected $dashboardId; /** * Cell ID. @@ -28,7 +28,7 @@ class Widget * * @var integer */ - private $widgetId; + protected $widgetId; /** * Values widget. @@ -37,6 +37,20 @@ class Widget */ private $values; + /** + * Target node Id. + * + * @var integer + */ + protected $nodeId; + + /** + * Should we show select node in metaconsole environments? + * + * @var boolean + */ + private $showSelectNodeMeta; + /** * Contructor widget. @@ -56,10 +70,14 @@ class Widget $this->cellId = $cellId; $this->dashboardId = $dashboardId; $this->fields = $this->get(); + $this->className = $this->fields['class_name']; $cellClass = new Cell($this->cellId, $this->dashboardId); $this->dataCell = $cellClass->get(); $this->values = $this->decoders($this->getOptionsWidget()); + if (isset($this->values['node']) === true) { + $this->nodeId = $this->values['node']; + } } return $this; @@ -73,8 +91,6 @@ class Widget */ public function get() { - global $config; - $sql = sprintf( 'SELECT * FROM twidget @@ -417,6 +433,24 @@ class Widget $output = ''; + if ((bool) \is_metaconsole() === true) { + \enterprise_include_once('include/functions_metaconsole.php'); + if ($this->nodeId > 0) { + if (\metaconsole_connect(null, $this->nodeId) !== NOERR) { + $output .= '
'; + $output .= \ui_print_info_message( + __('Failed to connect to node %d', $this->nodeId), + '', + true + ); + $output .= '
'; + return $output; + } + + $config['metaconsole'] = false; + } + } + if ($this->configurationRequired === true) { $output .= '
'; $output .= \ui_print_info_message( @@ -438,6 +472,13 @@ class Widget $output .= $this->load(); } + if ((bool) \is_metaconsole() === true) { + if ($this->nodeId > 0) { + \metaconsole_restore_db(); + $config['metaconsole'] = true; + } + } + return $output; } @@ -508,6 +549,38 @@ class Widget ], ]; + if ((bool) \is_metaconsole() === true + && $this->shouldSelectNode() === true + ) { + \enterprise_include_once('include/functions_metaconsole.php'); + $servers = \metaconsole_get_servers(); + if (is_array($servers) === true) { + $servers = array_reduce( + $servers, + function ($carry, $item) { + $carry[$item['id']] = $item['server_name']; + return $carry; + } + ); + } else { + $servers = []; + } + + $inputs[] = [ + 'label' => __('Node'), + 'arguments' => [ + 'wrapper' => 'div', + 'name' => 'node', + 'type' => 'select', + 'fields' => $servers, + 'selected' => $values['node'], + 'nothing' => __('This metaconsole'), + 'nothing_value' => -1, + 'return' => true, + ], + ]; + } + return $inputs; } @@ -522,6 +595,13 @@ class Widget $values = []; $values['title'] = \get_parameter('title', ''); $values['background'] = \get_parameter('background', '#ffffff'); + if ((bool) \is_metaconsole() === true) { + if ($this->shouldSelectNode() === true) { + $values['node'] = \get_parameter('node', null); + } else { + $values['node'] = \get_parameter('metaconsoleId', null); + } + } return $values; @@ -551,6 +631,10 @@ class Widget $values['background'] = $decoder['background']; } + if (isset($decoder['node']) === true) { + $values['node'] = $decoder['node']; + } + return $values; } @@ -589,6 +673,34 @@ class Widget } + /** + * Should select for nodes been shown while in metaconsole environment? + * + * @return boolean + */ + protected function shouldSelectNode():bool + { + if ($this->showSelectNodeMeta !== null) { + return (bool) $this->showSelectNodeMeta; + } + + switch ($this->className) { + case 'EventsListWidget': + case 'ReportsWidget': + case 'MapsMadeByUser': + case 'AlertsFiredWidget': + $this->showSelectNodeMeta = true; + break; + + default: + $this->showSelectNodeMeta = false; + break; + } + + return (bool) $this->showSelectNodeMeta; + } + + /** * Get description should be implemented for each child. * diff --git a/pandora_console/include/lib/Dashboard/Widgets/agent_module.php b/pandora_console/include/lib/Dashboard/Widgets/agent_module.php index b736c0e409..a06a730141 100644 --- a/pandora_console/include/lib/Dashboard/Widgets/agent_module.php +++ b/pandora_console/include/lib/Dashboard/Widgets/agent_module.php @@ -266,6 +266,7 @@ class AgentModuleWidget extends Widget 'mModules' => $this->values['mModules'], 'mShowSelectedOtherGroups' => true, 'mReturnAllGroup' => $return_all_group, + 'mMetaFields' => ((bool) is_metaconsole()), ], ]; @@ -329,7 +330,7 @@ class AgentModuleWidget extends Widget $name = $module; $modules_by_name[$cont]['name'] = $name; $modules_by_name[$cont]['id'][] = $key; - $cont ++; + $cont++; } } @@ -351,7 +352,10 @@ class AgentModuleWidget extends Widget $agent_modules = db_get_all_rows_sql($sql); - $agent_modules = array_combine(array_column($agent_modules, 'id_agente_modulo'), array_column($agent_modules, 'nombre')); + $agent_modules = array_combine( + array_column($agent_modules, 'id_agente_modulo'), + array_column($agent_modules, 'nombre') + ); $row['modules'] = []; foreach ($modules_by_name as $module) { @@ -449,6 +453,10 @@ class AgentModuleWidget extends Widget $table_data .= $file_name; $table_data .= ''; + if ($row['modules'] === null) { + $row['modules'] = []; + } + foreach ($row['modules'] as $module_name => $module) { if ($module === null) { if (in_array($module_name, $allModules) === true) { @@ -591,6 +599,7 @@ class AgentModuleWidget extends Widget { global $config; + $output = ''; if (check_acl($config['id_user'], 0, 'AR') === 0) { $output .= '
'; $output .= ui_print_error_message( @@ -602,27 +611,44 @@ class AgentModuleWidget extends Widget return $output; } - // Estract info all modules selected. + // Extract info all modules selected. $target_modules = explode(',', $this->values['mModules']); $all_modules = Module::search( ['id_agente_modulo' => $target_modules] ); - $reduceAllModules = array_reduce( - $all_modules, - function ($carry, $item) { - $carry[$item->name()] = null; - return $carry; - } - ); - - \ksort($reduceAllModules); + if ($all_modules !== null) { + $reduceAllModules = array_reduce( + $all_modules, + function ($carry, $item) { + $carry[$item->name()] = null; + return $carry; + } + ); + } else { + $reduceAllModules = []; + } $visualData = []; - // Estract info agents selected. + // Extract info agents selected. $target_agents = explode(',', $this->values['mAgents']); foreach ($target_agents as $agent_id) { try { - $agent = new Agent($agent_id); + $id_agente = $agent_id; + if ((bool) is_metaconsole() === true) { + $tmeta_agent = db_get_row_filter( + 'tmetaconsole_agent', + [ 'id_agente' => $id_agente ] + ); + + $id_agente = $tmeta_agent['id_tagente']; + $tserver = $tmeta_agent['id_tmetaconsole_setup']; + + if (metaconsole_connect(null, $tserver) !== NOERR) { + continue; + } + } + + $agent = new Agent((int) $id_agente); $visualData[$agent_id]['agent_status'] = $agent->lastStatus(); $visualData[$agent_id]['agent_name'] = $agent->name(); $visualData[$agent_id]['agent_alias'] = $agent->alias(); @@ -633,14 +659,27 @@ class AgentModuleWidget extends Widget $visualData[$agent_id]['modules'] = $reduceAllModules; foreach ($modules as $module) { + if ((bool) is_metaconsole() === true) { + $reduceAllModules[$module->name()] = null; + } + $visualData[$agent_id]['modules'][$module->name()] = $module->getStatus()->estado(); } - } catch (Exception $e) { - echo 'Error: '.$e->getMessage(); + + if ((bool) is_metaconsole() === true) { + metaconsole_restore_db(); + } + } catch (\Exception $e) { + echo 'Error: ['.$agent_id.']'.$e->getMessage(); } } + ksort($reduceAllModules); $allModules = array_keys($reduceAllModules); + if ($allModules === null) { + $allModules = []; + } + $output = $this->generateViewAgentModule( $visualData, $allModules diff --git a/pandora_console/include/lib/Dashboard/Widgets/custom_graph.php b/pandora_console/include/lib/Dashboard/Widgets/custom_graph.php index 0913cf212b..ea07f711dd 100644 --- a/pandora_console/include/lib/Dashboard/Widgets/custom_graph.php +++ b/pandora_console/include/lib/Dashboard/Widgets/custom_graph.php @@ -200,6 +200,10 @@ class CustomGraphWidget extends Widget $values['id_graph'] = $decoder['id_graph']; } + if (isset($decoder['node']) === true) { + $values['node'] = $decoder['node']; + } + if (isset($decoder['stacked']) === true) { $values['type'] = $decoder['stacked']; } @@ -252,21 +256,47 @@ class CustomGraphWidget extends Widget // Custom graph. $fields = \custom_graphs_get_user(0, false, $return_all_group); + if ((bool) is_metaconsole() === true) { + $selected = $values['node'].'|'.$values['id_graph']; + } else { + $selected = $values['id_graph']; + } + // If currently selected graph is not included in fields array // (it belongs to a group over which user has no permissions), - // then add it to fields array. - // This is aimed to avoid overriding this value when a user - // with narrower permissions edits widget configuration. + // then user has no grants over this item. if ($values['id_graph'] !== null - && array_key_exists($values['id_graph'], $fields) === false + && array_key_exists($selected, $fields) === false ) { - $selected_graph = db_get_row( + if ((bool) is_metaconsole() === true) { + $server_name = \db_get_value( + 'server_name', + 'tmetaconsole_setup', + 'id', + $values['node'] + ); + + metaconsole_connect(null, $values['node']); + } + + $name = \db_get_value( + 'name', 'tgraph', 'id_graph', $values['id_graph'] ); - $fields[$values['id_graph']] = $selected_graph; + if ((bool) is_metaconsole() === true) { + metaconsole_restore_db(); + } + + if ($name === false) { + $name = \__('This graph has been deleted.'); + } else { + $name .= ' ('.$server_name.')'; + } + + $fields[$selected] = $name; } $inputs[] = [ @@ -275,7 +305,7 @@ class CustomGraphWidget extends Widget 'type' => 'select', 'fields' => $fields, 'name' => 'id_graph', - 'selected' => $values['id_graph'], + 'selected' => $selected, 'return' => true, ], ]; @@ -340,8 +370,49 @@ class CustomGraphWidget extends Widget { // Retrieve global - common inputs. $values = parent::getPost(); + $id_graph = \get_parameter('id_graph', null); + + if ($id_graph !== null) { + $values['id_graph'] = $id_graph; + + if ((bool) is_metaconsole() === true) { + $mc_stuff = explode('|', $values['id_graph']); + $values['node'] = $mc_stuff[0]; + $values['id_graph'] = $mc_stuff[1]; + } + + // VERIFY ACCESS. + $return_all_group = false; + + if (users_can_manage_group_all('RM') === true) { + $return_all_group = true; + } + + $availables = \custom_graphs_get_user(0, false, $return_all_group); + + if ((bool) is_metaconsole() === true) { + $selected = $values['node'].'|'.$values['id_graph']; + } else { + $selected = $values['id_graph']; + } + + // If currently selected graph is not included in fields array + // (it belongs to a group over which user has no permissions), + // then user has no grants over this item. + if ($values['id_graph'] !== null + && array_key_exists($selected, $availables) === false + ) { + // User has no access to this graph. + // Keep previous definition if not grant over desired item. + $values['node'] = $this->values['node']; + $values['id_graph'] = $this->values['id_graph']; + } + } else { + // Keep previous definition if not grant over desired item. + $values['node'] = $this->values['node']; + $values['id_graph'] = $this->values['id_graph']; + } - $values['id_graph'] = \get_parameter('id_graph', 0); $values['type'] = \get_parameter('type', 0); $values['period'] = \get_parameter('period', 0); $values['showLegend'] = \get_parameter_switch('showLegend'); diff --git a/pandora_console/include/lib/Dashboard/Widgets/events_list.php b/pandora_console/include/lib/Dashboard/Widgets/events_list.php index 85ef5978d1..77f1cb34e5 100644 --- a/pandora_console/include/lib/Dashboard/Widgets/events_list.php +++ b/pandora_console/include/lib/Dashboard/Widgets/events_list.php @@ -603,7 +603,10 @@ class EventsListWidget extends Widget 'ta.alias as agent_name', 'tg.nombre as group_name', ]; - if ((bool) \is_metaconsole() === false) { + + if ((bool) \is_metaconsole() === false + || $this->nodeId > 0 + ) { $fields[] = 'am.nombre as module_name'; $fields[] = 'am.id_agente_modulo as id_agentmodule'; $fields[] = 'am.custom_id as module_custom_id'; @@ -636,7 +639,9 @@ class EventsListWidget extends Widget // ValidatedEvents. false, // Recursive Groups. - (bool) $this->values['groupRecursion'] + (bool) $this->values['groupRecursion'], + // Already connected. + ($this->nodeId > 0) ); if ($events === false) { diff --git a/pandora_console/include/lib/Dashboard/Widgets/maps_made_by_user.php b/pandora_console/include/lib/Dashboard/Widgets/maps_made_by_user.php index b861a606d0..32a095e132 100644 --- a/pandora_console/include/lib/Dashboard/Widgets/maps_made_by_user.php +++ b/pandora_console/include/lib/Dashboard/Widgets/maps_made_by_user.php @@ -213,6 +213,81 @@ class MapsMadeByUser extends Widget } + /** + * Dumps consoles list in json to fullfill select for consoles. + * + * @return void + */ + public function getVisualConsolesList(): void + { + $node_id = \get_parameter('nodeId', $this->nodeId); + if (\is_metaconsole() === true && $node_id > 0) { + if (\metaconsole_connect(null, $node_id) !== NOERR) { + echo json_encode( + ['error' => __('Failed to connect to node %d', $node_id) ] + ); + } + } + + echo json_encode( + $this->getVisualConsoles(), + 1 + ); + + if (\is_metaconsole() === true && $node_id > 0) { + \metaconsole_restore_db(); + } + } + + + /** + * Retrieve visual consoles. + * + * @return array + */ + private function getVisualConsoles() + { + global $config; + + $return_all_group = false; + + if (users_can_manage_group_all('RM')) { + $return_all_group = true; + } + + $fields = \visual_map_get_user_layouts( + $config['id_user'], + true, + ['can_manage_group_all' => $return_all_group], + $return_all_group + ); + + foreach ($fields as $k => $v) { + $fields[$k] = \io_safe_output($v); + } + + // If currently selected graph is not included in fields array + // (it belongs to a group over which user has no permissions), then add + // it to fields array. + // This is aimed to avoid overriding this value when a user with + // narrower permissions edits widget configuration. + if ($this->values['vcId'] !== null + && array_key_exists($this->values['vcId'], $fields) === false + ) { + $selected_vc = db_get_value( + 'name', + 'tlayout', + 'id', + $this->values['vcId'] + ); + + $fields[$this->values['vcId']] = $selected_vc; + } + + return $fields; + } + + /** * Generates inputs for form (specific). * @@ -229,31 +304,13 @@ class MapsMadeByUser extends Widget // Retrieve global - common inputs. $inputs = parent::getFormInputs(); - $return_all_group = false; - - if (users_can_manage_group_all('RM')) { - $return_all_group = true; - } - - $fields = \visual_map_get_user_layouts( - $config['id_user'], - true, - ['can_manage_group_all' => $return_all_group], - $return_all_group - ); - - // If currently selected graph is not included in fields array (it belongs to a group over which user has no permissions), then add it to fields array. - // This is aimed to avoid overriding this value when a user with narrower permissions edits widget configuration. - if ($values['vcId'] !== null && !array_key_exists($values['vcId'], $fields)) { - $selected_vc = db_get_value('name', 'tlayout', 'id', $values['vcId']); - - $fields[$values['vcId']] = $selected_vc; - } + $fields = $this->getVisualConsoles(); // Visual console. $inputs[] = [ 'label' => __('Visual console'), 'arguments' => [ + 'id' => 'vcId', 'type' => 'select', 'fields' => $fields, 'name' => 'vcId', @@ -476,4 +533,51 @@ class MapsMadeByUser extends Widget } + /** + * Return aux javascript code for forms. + * + * @return string + */ + public function getFormJS() + { + ob_start(); + ?> + $('#node').on('change', function() { + $.ajax({ + method: "POST", + url: '', + data: { + page: 'operation/dashboard/dashboard', + dashboardId: 'dashboardId; ?>', + widgetId: 'widgetId; ?>', + cellId: 'cellId; ?>', + class: '', + method: 'getVisualConsolesList', + nodeId: $('#node').val() + }, + dataType: 'JSON', + success: function(data) { + console.log(data); + $('#vcId').empty(); + Object.entries(data).forEach(e => { + key = e[0]; + value = e[1]; + $('#vcId').append($('