target discovery task id. * id_group => target group. * network => target CIDR. * graph => target graph (already built). * nodes => target agents or nodes. * relations => target array of relationships. * mode => simple (0) or advanced (1). * map_options => Map options. * * @return object New networkmap manager. */ public function __construct($options=false) { $recreate = true; if (is_array($options)) { if (isset($options['graph'])) { $this->graph = $options['graph']; } if (isset($options['nodes'])) { $this->nodes = $options['nodes']; } if (isset($options['relations'])) { $this->relations = $options['relations']; } if (isset($options['mode'])) { $this->mode = $options['mode']; } if (isset($options['map_options'])) { $this->mapOptions = $options['map_options']; } // Load from Discovery task. if ($options['id_map']) { $this->idMap = $options['id_map']; // Update nodes and relations. $this->loadMap(); if (empty($this->nodes) || empty($this->relations) ) { $this->createMap(); } } else { if ($options['id_group']) { $this->idGroup = $options['id_group']; } if ($options['id_task']) { $this->idTask = $options['id_task']; } if ($options['network']) { $this->network = $options['network']; } $this->createMap(); } } return $this; } /** * Creates a new map based on a target. * * Target is specified from constructor arguments. * options: * - id_task => create a map from task. * - id_group => create a map from group. * - network => create a map from network. * * @return void */ public function createMap() { if ($this->idMap) { $this->loadMap(); return; } if ($this->network) { $this->nodes = networkmap_get_new_nodes_from_ip_mask( $this->network ); } } /** * Loads a map from a target map ID. * * @return void. */ public function loadMap() { if ($this->idMap) { $this->map = db_get_row('tmap', 'id', $this->idMap); // Retrieve or update nodes and relations. $this->getNodes(); $this->getRelations(); // Nodes and relations. $this->graph = networkmap_process_networkmap($this->idMap); } } /** * Return nodes of current map. * * @return array Nodes. */ public function getNodes() { if ($this->nodes) { return $this->nodes; } if ($this->idMap !== false) { if (enterprise_installed()) { // Enterprise environment: LOAD. $this->nodes = enterprise_hook( 'get_nodes_from_db', [$this->idMap] ); } } return $this->nodes; } /** * Return relations of current map. * * @return array Relations. */ public function getRelations() { if ($this->relations) { return $this->relations; } if ($this->idMap !== false) { if (enterprise_installed()) { $this->relations = enterprise_hook( 'get_relations_from_db', [$this->idMap] ); } } return $this->relations; } /** * Transform node information into JS data. * * @return string HTML code with JS data. */ public function loadMapData() { $networkmap = $this->map; $networkmap['filter'] = json_decode( $networkmap['filter'], true ); // Hardcoded. $networkmap['filter']['holding_area'] = [ 500, 500, ]; $this->graph['relations'] = clean_duplicate_links( $this->graph['relations'] ); $output .= ''; return $output; } /** * Show an advanced interface to manage dialogs. * * @return string HTML code with dialogs. */ public function loadAdvancedInterface() { $list_networkmaps = get_networkmaps($this->idMap); if (empty($list_networkmaps)) { $list_networkmaps = []; } $output .= ''; $output .= ''; $output .= ''; $output .= ''; return $output; } /** * Loads advanced map controller (JS). * * @return string HTML code for advanced controller. */ public function loadController() { $output = ''; // Generate JS for advanced controller. $output .= ' '; if ($return === false) { echo $output; } return $output; } /** * Load networkmap HTML skel and JS requires. * * @return string HTML code for skel. */ public function loadMapSkel() { global $config; ui_require_css_file('networkmap'); ui_require_css_file('jquery.contextMenu', 'include/styles/js/'); $output = ''; $hide_minimap = ''; if ($dashboard_mode) { $hide_minimap = 'none'; } $networkmap = $this->map; $networkmap['filter'] = json_decode($networkmap['filter'], true); $networkmap['filter']['l2_network_interfaces'] = 1; $output .= ''; $output .= ''; $output .= ''; // Open networkconsole_id div. $output .= '
'; $output .= ''; $output .= ''; $output .= ''; $output .= '
'; $output .= '
idMap)) { $output .= $this->loadMapSkel(); $output .= $this->loadMapData(); $output .= $this->loadController(); $output .= $this->loadAdvancedInterface(); } if ($return === false) { echo $output; } return $output; } }