From 8fd3f7788ac56e7d0ca0f89ff0fdc06dc1134b3b Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Thu, 21 Mar 2019 18:38:31 +0100 Subject: [PATCH] networkmap functions ligth cleanup Former-commit-id: 51d7eaa9dee0d58eb8e01f4043149766145df20d --- .../include/functions_networkmap.php | 369 ------------------ 1 file changed, 369 deletions(-) diff --git a/pandora_console/include/functions_networkmap.php b/pandora_console/include/functions_networkmap.php index 82a1e957b5..49d3e7e1c4 100644 --- a/pandora_console/include/functions_networkmap.php +++ b/pandora_console/include/functions_networkmap.php @@ -1957,375 +1957,6 @@ function networkmap_links_to_js_links( } -function networkmap_write_js_array($id, $nodes_and_relations=[], $map_dash_details=[]) -{ - global $config; - - db_clean_cache(); - - $ent_installed = (int) enterprise_installed(); - - $networkmap = db_get_row('tmap', 'id', $id); - - $networkmap['filter'] = json_decode($networkmap['filter'], true); - - // Hardcoded - $networkmap['filter']['holding_area'] = [ - 500, - 500, - ]; - - echo "\n"; - echo "////////////////////////////////////////////////////////////////////\n"; - echo "// VARS FROM THE DB\n"; - echo "////////////////////////////////////////////////////////////////////\n"; - echo "\n"; - echo "var url_background_grid = '".ui_get_full_url( - 'images/background_grid.png' - )."'\n"; - echo 'var networkmap_id = '.$id.";\n"; - - if (!empty($map_dash_details)) { - echo 'var x_offs = '.$map_dash_details['x_offs'].";\n"; - echo 'var y_offs = '.$map_dash_details['y_offs'].";\n"; - echo 'var z_dash = '.$map_dash_details['z_dash'].";\n"; - } else { - echo "var x_offs = null;\n"; - echo "var y_offs = null;\n"; - echo "var z_dash = null;\n"; - } - - echo 'var networkmap_refresh_time = 1000 * '.$networkmap['source_period'].";\n"; - echo 'var networkmap_center = [ '.$networkmap['center_x'].', '.$networkmap['center_y']."];\n"; - echo 'var networkmap_dimensions = [ '.$networkmap['width'].', '.$networkmap['height']."];\n"; - - echo 'var enterprise_installed = '.$ent_installed.";\n"; - - echo 'var node_radius = '.$networkmap['filter']['node_radius'].";\n"; - - echo 'var networkmap_holding_area_dimensions = '.json_encode($networkmap['filter']['holding_area']).";\n"; - - echo "var networkmap = {'nodes': [], 'links': []};\n"; - - $nodes = $nodes_and_relations['nodes']; - - if (empty($nodes)) { - $nodes = []; - } - - $count_item_holding_area = 0; - $count = 0; - $nodes_graph = []; - - foreach ($nodes as $key => $node) { - $style = json_decode($node['style'], true); - $node['style'] = json_decode($node['style'], true); - - // Only agents can be show - if (isset($node['type'])) { - if ($node['type'] == 1) { - continue; - } - } else { - $node['type'] = ''; - } - - $item = networkmap_db_node_to_js_node( - $node, - $count, - $count_item_holding_area - ); - if ($item['deleted']) { - continue; - } - - echo 'networkmap.nodes.push('.json_encode($item).");\n"; - $nodes_graph[$item['id']] = $item; - } - - $relations = $nodes_and_relations['relations']; - - if ($relations === false) { - $relations = []; - } - - // Clean the relations and transform the module relations into - // interfaces - networkmap_clean_relations_for_js($relations); - - $links_js = networkmap_links_to_js_links($relations, $nodes_graph); - - $array_aux = []; - foreach ($links_js as $link_js) { - if ($link_js['deleted']) { - unset($links_js[$link_js['id']]); - } - - if ($link_js['target'] == -1) { - unset($links_js[$link_js['id']]); - } - - if ($link_js['source'] == -1) { - unset($links_js[$link_js['id']]); - } - - if ($link_js['target'] == $link_js['source']) { - unset($links_js[$link_js['id']]); - } - - if ($link_js['arrow_start'] == 'module' && $link_js['arrow_end'] == 'module') { - echo 'networkmap.links.push('.json_encode($link_js).");\n"; - $array_aux[$link_js['id_agent_start']] = 1; - unset($links_js[$link_js['id']]); - } - } - - foreach ($links_js as $link_js) { - if (($link_js['id_agent_end'] === 0) && $array_aux[$link_js['id_agent_start']] === 1) { - continue; - } else { - echo 'networkmap.links.push('.json_encode($link_js).");\n"; - } - } - - echo "\n"; - echo "\n"; - - echo "////////////////////////////////////////////////////////////////////\n"; - echo "// INTERFACE STATUS COLORS\n"; - echo "////////////////////////////////////////////////////////////////////\n"; - - $module_color_status = []; - $module_color_status[] = [ - 'status_code' => AGENT_MODULE_STATUS_NORMAL, - 'color' => COL_NORMAL, - ]; - $module_color_status[] = [ - 'status_code' => AGENT_MODULE_STATUS_CRITICAL_BAD, - 'color' => COL_CRITICAL, - ]; - $module_color_status[] = [ - 'status_code' => AGENT_MODULE_STATUS_WARNING, - 'color' => COL_WARNING, - ]; - $module_color_status[] = [ - 'status_code' => AGENT_STATUS_ALERT_FIRED, - 'color' => COL_ALERTFIRED, - ]; - $module_color_status_unknown = COL_UNKNOWN; - - echo 'var module_color_status = '.json_encode($module_color_status).";\n"; - echo "var module_color_status_unknown = '".$module_color_status_unknown."';\n"; - - echo "\n"; - echo "\n"; - - echo "////////////////////////////////////////////////////////////////////\n"; - echo "// Other vars\n"; - echo "////////////////////////////////////////////////////////////////////\n"; - - echo "var translation_none = '".__('None')."';\n"; - echo "var dialog_node_edit_title = '".__('Edit node %s')."';\n"; - echo "var holding_area_title = '".__('Holding Area')."';\n"; - echo "var edit_menu = '".__('Show details and options')."';\n"; - echo "var interface_link_add = '".__('Add a interface link')."';\n"; - echo "var set_parent_link = '".__('Set parent interface')."';\n"; - echo "var set_as_children_menu = '".__('Set as children')."';\n"; - echo "var set_parent_menu = '".__('Set parent')."';\n"; - echo "var abort_relationship_menu = '".__('Abort the action of set relationship')."';\n"; - echo "var delete_menu = '".__('Delete')."';\n"; - echo "var add_node_menu = '".__('Add node')."';\n"; - echo "var set_center_menu = '".__('Set center')."';\n"; - echo "var refresh_menu = '".__('Refresh')."';\n"; - echo "var refresh_holding_area_menu = '".__('Refresh Holding area')."';\n"; - echo "var ok_button = '".__('Proceed')."';\n"; - echo "var message_to_confirm = '".__('Resetting the map will delete all customizations you have done, including manual relationships between elements, new items, etc.')."';\n"; - echo "var warning_message = '".__('WARNING')."';\n"; - echo "var ok_button = '".__('Proceed')."';\n"; - echo "var cancel_button = '".__('Cancel')."';\n"; - echo "var restart_map_menu = '".__('Restart map')."';\n"; - echo "var abort_relationship_interface = '".__('Abort the interface relationship')."';\n"; - echo "var abort_relationship_menu = '".__('Abort the action of set relationship')."';\n"; - - echo "\n"; - echo "\n"; -} - - -function networkmap_loadfile( - $id=0, - $file='', - &$relations_param, - $graph -) { - global $config; - - $height_map = 200; - if ((int) $id > 0) { - $height_map = db_get_value('height', 'tmap', 'id', $id); - } - - $networkmap_nodes = []; - - $relations = []; - - $other_file = file($file); - - // Remove the graph head - $graph = preg_replace('/^graph .*/', '', $graph); - // Cut in nodes the graph - $graph = explode(']', $graph); - - $ids = []; - foreach ($graph as $node) { - $line = str_replace("\n", ' ', $node); - - if (preg_match('/([0-9]+) \[.*tooltip.*id_module=([0-9]+)/', $line, $match) != 0) { - $ids[$match[1]] = [ - 'type' => 'module', - 'id_module' => $match[2], - ]; - } else if (preg_match('/([0-9]+) \[.*tooltip.*id_agent=([0-9]+)/', $line, $match) != 0) { - $ids[$match[1]] = [ - 'type' => 'agent', - 'id_agent' => $match[2], - ]; - } - } - - foreach ($other_file as $key => $line) { - // clean line a long spaces for one space caracter - $line = preg_replace('/[ ]+/', ' ', $line); - - $data = []; - - if (preg_match('/^node.*$/', $line) != 0) { - $items = explode(' ', $line); - $node_id = $items[1]; - - // 200 for larger maps - $node_x = ($items[2] * 100); - $node_y = ($height_map - $items[3] * 100); - // 200 for larger maps - $data['id'] = $node_id; - $data['text'] = ''; - $data['image'] = ''; - $data['width'] = 10; - $data['height'] = 10; - $data['id_agent'] = 0; - - if (preg_match('/ $line_orig, - 'dest' => $line_dest, - ]; - } - } - - $relations_param = []; - - foreach ($relations as $rel) { - if (strpos($rel['orig'], 'transp_') !== false) { - // removed the transparent nodes - continue; - } - - if (strpos($rel['dest'], 'transp_') !== false) { - // removed the transparent nodes - continue; - } - - $row = [ - 'id_child' => $rel['orig'], - 'child_type' => $networkmap_nodes[$rel['orig']]['type'], - 'id_parent' => $rel['dest'], - 'parent_type' => $networkmap_nodes[$rel['dest']]['type'], - ]; - $relations_param[] = $row; - } - - return [ - 'nodes' => $networkmap_nodes, - 'relations' => $relations_param, - ]; -} - - function get_status_color_module_networkmap($id_agente_modulo) { $status = modules_get_agentmodule_status($id_agente_modulo);