2019-03-07 18:57:48 +01:00
< ? php
/**
* Class to manage networkmaps in Pandora FMS
*
* @ category Class
* @ package Pandora FMS
* @ subpackage NetworkMap manager
* @ version 1.0 . 0
* @ license See below
*
* ______ ___ _______ _______ ________
* | __ \ .-----.--.--.--| |.-----.----.-----. | ___ | | | __ |
* | __ /| _ | | _ || _ | _ | _ | | ___ | | __ |
* | ___ | | ___ . _ | __ | __ | _____ || _____ | __ | | ___ . _ | | ___ | | __ | _ | __ | _______ |
*
* ============================================================================
* Copyright ( c ) 2005 - 2019 Artica Soluciones Tecnologicas
* Please see http :// pandorafms . org for full contribution list
* This program is free software ; you can redistribute it and / or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation for version 2.
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
* ============================================================================
*/
// Begin.
global $config ;
2019-03-11 20:10:08 +01:00
require_once $config [ 'homedir' ] . '/include/functions_networkmap.php' ;
2019-03-13 11:38:03 +01:00
enterprise_include_once ( 'include/functions_networkmap.php' );
2019-03-11 20:10:08 +01:00
2019-03-12 16:22:28 +01:00
define ( 'SOURCE_GROUP' , 0 );
define ( 'SOURCE_TASK' , 1 );
define ( 'SOURCE_NETWORK' , 2 );
2019-03-07 18:57:48 +01:00
/**
* Manage networkmaps in Pandora FMS
*/
class NetworkMap
{
/**
* Target map Id .
*
* @ var integer
*/
public $idMap ;
2019-03-11 15:09:31 +01:00
/**
* Content of tmap .
*
* @ var array
*/
public $map ;
/**
* Data origin , network .
*
* @ var string
*/
public $network ;
/**
* Data origin , group id .
*
* @ var integer
*/
public $idGroup ;
/**
* Data origin , Discovery task .
*
* @ var integer
*/
public $idTask ;
2019-03-07 18:57:48 +01:00
/**
* Graph definition
*
* @ var array
*/
public $graph ;
2019-03-11 20:10:08 +01:00
/**
* Dot string with graph definition .
*
* @ var string
*/
public $dotGraph ;
2019-03-07 18:57:48 +01:00
/**
* Node list .
*
* @ var array
*/
public $nodes ;
/**
* Relationship map .
*
* @ var array
*/
public $relations ;
/**
* Mode simple or advanced .
*
* @ var integer
*/
public $mode ;
/**
* Array of map options
* height
* width
*
* @ var array
*/
public $mapOptions ;
/**
* Base constructor .
*
2019-03-11 15:09:31 +01:00
* @ param mixed $options Could define in array as :
* id_map => target discovery task id .
* id_group => target group .
* network => target CIDR .
* graph => target graph ( already built ) .
2019-03-07 18:57:48 +01:00
* nodes => target agents or nodes .
* relations => target array of relationships .
2019-03-11 15:09:31 +01:00
* mode => simple ( 0 ) or advanced ( 1 ) .
* map_options => Map options .
2019-03-07 18:57:48 +01:00
*
* @ return object New networkmap manager .
*/
2019-03-11 15:09:31 +01:00
public function __construct ( $options = false )
2019-03-07 18:57:48 +01:00
{
2019-03-11 20:10:08 +01:00
// Default mapOptions values.
2019-03-12 16:22:28 +01:00
// Defines the command to generate positions.
$this -> mapOptions [ 'generation_method' ] = LAYOUT_SPRING1 ;
2019-03-11 20:10:08 +01:00
$this -> mapOptions [ 'simple' ] = 0 ;
$this -> mapOptions [ 'font_size' ] = 12 ;
$this -> mapOptions [ 'nooverlap' ] = 1 ;
2019-03-12 16:22:28 +01:00
$this -> mapOptions [ 'z_dash' ] = 0.5 ;
2019-03-12 18:32:55 +01:00
$this -> mapOptions [ 'ranksep' ] = 3 ;
2019-03-11 20:10:08 +01:00
$this -> mapOptions [ 'center' ] = 0 ;
$this -> mapOptions [ 'regen' ] = 0 ;
2019-03-12 18:32:55 +01:00
$this -> mapOptions [ 'pure' ] = 0 ;
2019-03-11 20:10:08 +01:00
$this -> mapOptions [ 'show_snmp_modules' ] = false ;
$this -> mapOptions [ 'cut_names' ] = false ;
$this -> mapOptions [ 'relative' ] = true ;
$this -> mapOptions [ 'text_filter' ] = '' ;
$this -> mapOptions [ 'dont_show_subgroups' ] = false ;
$this -> mapOptions [ 'strict_user' ] = false ;
$this -> mapOptions [ 'size_canvas' ] = null ;
$this -> mapOptions [ 'old_mode' ] = false ;
$this -> mapOptions [ 'map_filter' ] = [
2019-03-12 10:29:19 +01:00
'dont_show_subgroups' => 0 ,
'node_radius' => 40 ,
'x_offs' => 0 ,
'y_offs' => 0 ,
'z_dash' => 0.5 ,
'node_sep' => 0.1 ,
2019-03-12 16:22:28 +01:00
'rank_sep' => 0.1 ,
2019-03-12 10:29:19 +01:00
'mindist' => 1 ,
'kval' => 0.1 ,
2019-03-11 20:10:08 +01:00
];
2019-03-07 18:57:48 +01:00
if ( is_array ( $options )) {
2019-03-12 12:05:54 +01:00
// Previously nodes_and_relations.
2019-03-07 18:57:48 +01:00
if ( isset ( $options [ 'graph' ])) {
$this -> graph = $options [ 'graph' ];
}
2019-03-12 12:05:54 +01:00
// String dotmap.
if ( isset ( $options [ 'dot_graph' ])) {
$this -> dotGraph = $options [ 'dot_graph' ];
}
// Array of nodes, agents, virtual, etc.
2019-03-07 18:57:48 +01:00
if ( isset ( $options [ 'nodes' ])) {
$this -> nodes = $options [ 'nodes' ];
}
2019-03-12 12:05:54 +01:00
// Array of relations.
2019-03-07 18:57:48 +01:00
if ( isset ( $options [ 'relations' ])) {
$this -> relations = $options [ 'relations' ];
}
2019-03-12 12:05:54 +01:00
// User interface type. Simple or advanced.
2019-03-07 18:57:48 +01:00
if ( isset ( $options [ 'mode' ])) {
$this -> mode = $options [ 'mode' ];
}
2019-03-12 18:32:55 +01:00
// Show interface elements or dashboard style.
if ( isset ( $options [ 'pure' ])) {
$this -> mapOptions [ 'pure' ] = $options [ 'pure' ];
}
2019-03-12 12:05:54 +01:00
// Map options, check default values above.
// This is only used while generating new maps using
// (generateDotGraph).
2019-03-11 20:10:08 +01:00
if ( is_array ( $options [ 'map_options' ])) {
foreach ( $options [ 'map_options' ] as $k => $v ) {
$this -> mapOptions [ $k ] = $v ;
}
2019-03-07 18:57:48 +01:00
}
2019-03-11 15:09:31 +01:00
2019-03-12 12:05:54 +01:00
// Load from tmap.
2019-03-11 15:09:31 +01:00
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 {
2019-03-12 12:05:54 +01:00
// Generate from group, task or network.
2019-03-11 15:09:31 +01:00
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 ();
}
2019-03-07 18:57:48 +01:00
}
return $this ;
}
2019-03-11 15:09:31 +01:00
/**
* 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 ()
{
2019-03-12 12:05:54 +01:00
// If exists, load from DB.
2019-03-11 15:09:31 +01:00
if ( $this -> idMap ) {
$this -> loadMap ();
return ;
}
2019-03-12 12:05:54 +01:00
// Simulated map.
$this -> idMap = uniqid ();
// No tmap definition. Paint data.
if ( $this -> idTask ) {
$recon_task = db_get_row_filter (
'trecon_task' ,
2019-03-12 16:22:28 +01:00
[ 'id_rt' => $this -> idTask ]
2019-03-11 15:09:31 +01:00
);
2019-03-12 12:05:54 +01:00
$this -> network = $recon_task [ 'subnet' ];
2019-03-11 15:09:31 +01:00
}
2019-03-11 20:10:08 +01:00
2019-03-12 12:05:54 +01:00
// Simulate map entry.
$this -> map = [
'id' => $this -> idMap ,
'__simulated' => 1 ,
'background' => '' ,
'background_options' => 0 ,
'source_period' => 60 ,
'filter' => $this -> mapOptions [ 'map_filter' ],
2019-03-12 16:22:28 +01:00
'width' => 0 ,
'height' => 0 ,
'center_x' => 0 ,
'center_y' => 0 ,
2019-03-12 12:05:54 +01:00
];
2019-03-12 16:22:28 +01:00
// Will be stored in $this->graph.
$this -> generateNetworkMap ();
2019-03-12 12:05:54 +01:00
2019-03-11 15:09:31 +01:00
}
/**
* Loads a map from a target map ID .
*
* @ return void .
*/
public function loadMap ()
{
2019-03-12 16:22:28 +01:00
if ( $this -> map ) {
// Already loaded.
return ;
}
2019-03-11 15:09:31 +01:00
if ( $this -> idMap ) {
$this -> map = db_get_row ( 'tmap' , 'id' , $this -> idMap );
2019-03-12 16:22:28 +01:00
$this -> mapOptions [ 'map_filter' ] = json_decode (
$this -> map [ 'filter' ],
true
);
foreach ( $this -> map as $k => $v ) {
$this -> mapOptions [ $k ] = $v ;
}
// Retrieve data origin.
$this -> network = null ;
$this -> idTask = null ;
$this -> idGroup = $this -> map [ 'id_group' ];
switch ( $this -> map [ 'source' ]) {
case SOURCE_GROUP :
$this -> idGroup = $this -> map [ 'source_data' ];
break ;
case SOURCE_TASK :
$this -> idTask = $this -> map [ 'source_data' ];
break ;
case SOURCE_NETWORK :
$this -> network = $this -> map [ 'source_data' ];
break ;
default :
// Ignore.
break ;
}
if ( $this -> idTask ) {
$recon_task = db_get_row_filter (
'trecon_task' ,
[ 'id_rt' => $networkmap [ 'source_data' ]]
);
$this -> network = $recon_task [ 'subnet' ];
}
2019-03-11 15:09:31 +01:00
// Retrieve or update nodes and relations.
$this -> getNodes ();
$this -> getRelations ();
2019-03-12 16:22:28 +01:00
// Nodes and relations will be stored in $this->graph.
$this -> loadGraph ();
2019-03-11 15:09:31 +01:00
}
}
/**
* 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 ;
}
2019-03-12 16:22:28 +01:00
/**
* 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 ;
}
/**
* Generates or loads nodes & relations array from data load
* and stores it in $this -> graph .
*
* @ return void
*/
public function loadGraph ()
{
$nodes = $this -> nodes ;
$relations = $this -> relations ;
// Generate if there's no data in DB about nodes or relations.
if ( empty ( $nodes ) || empty ( $relations )) {
$this -> generateNetworkMap ();
return ;
}
$nodes_and_relations = [];
$nodes_and_relations [ 'nodes' ] = [];
$index_nodes = 0 ;
foreach ( $nodes as $node ) {
if ( ! $node [ 'deleted' ]) {
$nodes_and_relations [ 'nodes' ][ $index_nodes ][ 'id_map' ] = $node [ 'id_map' ];
$nodes_and_relations [ 'nodes' ][ $index_nodes ][ 'x' ] = $node [ 'x' ];
$nodes_and_relations [ 'nodes' ][ $index_nodes ][ 'y' ] = $node [ 'y' ];
$nodes_and_relations [ 'nodes' ][ $index_nodes ][ 'source_data' ] = $node [ 'source_data' ];
$nodes_and_relations [ 'nodes' ][ $index_nodes ][ 'type' ] = $node [ 'type' ];
$style_node = json_decode ( $node [ 'style' ], true );
$style = [];
$style [ 'shape' ] = $style_node [ 'shape' ];
$style [ 'image' ] = $style_node [ 'image' ];
$style [ 'width' ] = $style_node [ 'width' ];
$style [ 'height' ] = $style_node [ 'height' ];
$style [ 'label' ] = $style_node [ 'label' ];
$style [ 'id_networkmap' ] = $style_node [ 'networkmap' ];
$nodes_and_relations [ 'nodes' ][ $index_nodes ][ 'style' ] = json_encode ( $style );
if ( $node [ 'type' ] == 1 ) {
$nodes_and_relations [ 'nodes' ][ $index_nodes ][ 'id_agent' ] = $style_node [ 'id_agent' ];
}
$nodes_and_relations [ 'nodes' ][ $index_nodes ][ 'id_in_db' ] = $node [ 'id' ];
$index_nodes ++ ;
}
}
$nodes_and_relations [ 'relations' ] = [];
$index_relations = 0 ;
foreach ( $relations as $relation ) {
$nodes_and_relations [ 'relations' ][ $index_relations ][ 'id_map' ] = $relation [ 'id_map' ];
$nodes_and_relations [ 'relations' ][ $index_relations ][ 'id_parent' ] = $relation [ 'id_parent' ];
$nodes_and_relations [ 'relations' ][ $index_relations ][ 'id_child' ] = $relation [ 'id_child' ];
$nodes_and_relations [ 'relations' ][ $index_relations ][ 'parent_type' ] = $relation [ 'parent_type' ];
$nodes_and_relations [ 'relations' ][ $index_relations ][ 'child_type' ] = $relation [ 'child_type' ];
$nodes_and_relations [ 'relations' ][ $index_relations ][ 'id_parent_source_data' ] = $relation [ 'id_parent_source_data' ];
$nodes_and_relations [ 'relations' ][ $index_relations ][ 'id_child_source_data' ] = $relation [ 'id_child_source_data' ];
$index_relations ++ ;
}
$this -> graph = $nodes_and_relations ;
}
2019-03-12 12:05:54 +01:00
/**
* Generate a graphviz string structure to be used later .
*
* @ return void
*/
public function generateDotGraph ()
{
if ( ! isset ( $this -> dotGraph )) {
// Generate dot file.
$this -> dotGraph = networkmap_generate_dot (
get_product_name (),
$this -> idGroup ,
$this -> mapOptions [ 'simple' ],
$this -> mapOptions [ 'font_size' ],
$this -> mapOptions [ 'layout' ],
$this -> mapOptions [ 'nooverlap' ],
2019-03-12 16:22:28 +01:00
$this -> mapOptions [ 'z_dash' ],
2019-03-12 12:05:54 +01:00
$this -> mapOptions [ 'ranksep' ],
$this -> mapOptions [ 'center' ],
$this -> mapOptions [ 'regen' ],
$this -> mapOptions [ 'pure' ],
$this -> mapOptions [ 'id' ],
$this -> mapOptions [ 'show_snmp_modules' ],
$this -> mapOptions [ 'cut_names' ],
$this -> mapOptions [ 'relative' ],
$this -> mapOptions [ 'text_filter' ],
$this -> network ,
$this -> mapOptions [ 'dont_show_subgroups' ],
// Strict user (strict_user).
false ,
// Canvas size (size_canvas).
null ,
$this -> mapOptions [ 'old_mode' ],
$this -> mapOptions [ 'map_filter' ]
);
}
}
2019-03-12 16:22:28 +01:00
/**
* Creates an empty dot graph ( with only base node )
*
* @ return void
*/
public function generateEmptyDotGraph ()
{
// Create an empty map dot structure.
$graph = networkmap_open_graph (
$this -> mapOptions [ 'layout' ],
$this -> mapOptions [ 'nooverlap' ],
$this -> mapOptions [ 'pure' ],
$this -> mapOptions [ 'z_dash' ],
$this -> mapOptions [ 'ranksep' ],
$this -> mapOptions [ 'font_size' ],
null
);
$graph .= networkmap_create_pandora_node (
get_product_name (),
$this -> mapOptions [ 'font_size' ],
$this -> mapOptions [ 'simple' ]
);
$graph .= networkmap_close_graph ();
$this -> dotGraph = $graph ;
}
2019-03-11 20:10:08 +01:00
/**
* Generates a nodes - relationships array using graphviz dot
2019-03-12 16:22:28 +01:00
* schema and stores nodes & relations into $this -> graph .
2019-03-11 20:10:08 +01:00
*
2019-03-12 16:22:28 +01:00
* @ return void
2019-03-11 20:10:08 +01:00
*/
public function generateNetworkMap ()
{
2019-03-12 16:22:28 +01:00
global $config ;
include_once 'include/functions_os.php' ;
$map_filter = json_decode (
$this -> map [ 'filter' ],
true
);
2019-03-12 12:05:54 +01:00
2019-03-11 20:10:08 +01:00
/*
* Let graphviz place the nodes .
*/
switch ( $this -> mapOptions [ 'generation_method' ]) {
2019-03-12 16:22:28 +01:00
case LAYOUT_CIRCULAR :
2019-03-11 20:10:08 +01:00
$filter = 'circo' ;
2019-03-12 16:22:28 +01:00
$this -> mapOptions [ 'layout' ] = 'circular' ;
2019-03-11 20:10:08 +01:00
break ;
2019-03-12 16:22:28 +01:00
case LAYOUT_FLAT :
2019-03-12 12:05:54 +01:00
$filter = 'dot' ;
2019-03-12 16:22:28 +01:00
$this -> mapOptions [ 'layout' ] = 'flat' ;
2019-03-11 20:10:08 +01:00
break ;
2019-03-12 16:22:28 +01:00
case LAYOUT_RADIAL :
2019-03-12 12:05:54 +01:00
$filter = 'twopi' ;
2019-03-12 16:22:28 +01:00
$this -> mapOptions [ 'layout' ] = 'radial' ;
2019-03-11 20:10:08 +01:00
break ;
2019-03-12 16:22:28 +01:00
case LAYOUT_SPRING1 :
2019-03-11 20:10:08 +01:00
default :
2019-03-12 12:05:54 +01:00
$filter = 'neato' ;
2019-03-12 16:22:28 +01:00
$this -> mapOptions [ 'layout' ] = 'spring1' ;
2019-03-11 20:10:08 +01:00
break ;
2019-03-12 16:22:28 +01:00
case LAYOUT_SPRING2 :
2019-03-12 12:05:54 +01:00
$filter = 'fdp' ;
2019-03-12 16:22:28 +01:00
$this -> mapOptions [ 'layout' ] = 'spring2' ;
2019-03-11 20:10:08 +01:00
break ;
}
2019-03-12 16:22:28 +01:00
if ( $map_filter [ 'empty_map' ]) {
$this -> generateEmptyDotGraph ();
} else if ( ! isset ( $this -> dotGraph )) {
$this -> generateDotGraph ();
}
2019-03-11 20:10:08 +01:00
switch ( PHP_OS ) {
case 'WIN32' :
case 'WINNT' :
case 'Windows' :
$filename_dot = sys_get_temp_dir () . " \\ networkmap_ " . $filter ;
break ;
default :
$filename_dot = sys_get_temp_dir () . '/networkmap_' . $filter ;
break ;
}
if ( $simple ) {
$filename_dot .= '_simple' ;
}
if ( $nooverlap ) {
$filename_dot .= '_nooverlap' ;
}
2019-03-12 18:17:18 +01:00
$filename_dot .= uniqid () . '_' . $this -> idMap . '.dot' ;
2019-03-11 20:10:08 +01:00
2019-03-12 12:05:54 +01:00
file_put_contents ( $filename_dot , $this -> dotGraph );
2019-03-11 20:10:08 +01:00
2019-03-12 18:17:18 +01:00
$plain_file = 'plain' . uniqid () . '.txt' ;
2019-03-11 20:10:08 +01:00
switch ( PHP_OS ) {
case 'WIN32' :
case 'WINNT' :
case 'Windows' :
2019-03-12 18:17:18 +01:00
$filename_plain = sys_get_temp_dir () . '\\' . $plain_file ;
2019-03-11 20:10:08 +01:00
$cmd = io_safe_output (
$config [ 'graphviz_bin_dir' ] . '\\' . $filter . '.exe -Tplain -o ' . $filename_plain . ' ' . $filename_dot
);
break ;
default :
2019-03-12 18:17:18 +01:00
$filename_plain = sys_get_temp_dir () . '/' . $plain_file ;
2019-03-11 20:10:08 +01:00
$cmd = $filter . ' -Tplain -o ' . $filename_plain . ' ' . $filename_dot ;
break ;
}
2019-03-12 18:17:18 +01:00
$retval = 0 ;
$r = system ( $cmd , $retval );
if ( $retval != 0 ) {
ui_print_error_message (
__ ( 'Failed to generate dotmap, please select different layout schema' )
);
return ;
}
2019-03-11 20:10:08 +01:00
unlink ( $filename_dot );
$nodes = networkmap_loadfile (
$this -> idMap ,
$filename_plain ,
$relation_nodes ,
2019-03-12 12:05:54 +01:00
$this -> dotGraph
2019-03-11 20:10:08 +01:00
);
unlink ( $filename_plain );
/*
* Graphviz section ends here .
*/
/*
* Calculate references .
*/
// Set the position of modules.
foreach ( $nodes as $key => $node ) {
if ( $node [ 'type' ] == 'module' ) {
// Search the agent of this module for to get the
// position.
foreach ( $nodes as $key2 => $node2 ) {
if ( $node2 [ 'id_agent' ] != 0 && $node2 [ 'type' ] == 'agent' ) {
if ( $node2 [ 'id_agent' ] == $node [ 'id_agent' ]) {
$nodes [ $key ][ 'coords' ][ 0 ] = ( $nodes [ $key2 ][ 'coords' ][ 0 ] + $node [ 'height' ] / 2 );
$nodes [ $key ][ 'coords' ][ 1 ] = ( $nodes [ $key2 ][ 'coords' ][ 1 ] + $node [ 'width' ] / 2 );
}
}
}
}
}
$nodes_and_relations [ 'nodes' ] = [];
$index = 0 ;
$node_center = [];
foreach ( $nodes as $key => $node ) {
$nodes_and_relations [ 'nodes' ][ $index ][ 'id' ] = $node [ 'id' ];
2019-03-12 12:05:54 +01:00
$nodes_and_relations [ 'nodes' ][ $index ][ 'id_map' ] = $this -> idMap ;
2019-03-11 20:10:08 +01:00
$children_count = 0 ;
foreach ( $relation_nodes as $relation ) {
if (( $relation [ 'parent_type' ] == 'agent' ) || ( $relation [ 'parent_type' ] == '' )) {
if ( $nodes [ $relation [ 'id_parent' ]][ 'id_agent' ] == $node [ 'id_agent' ]) {
$children_count ++ ;
}
} else if ( $relation [ 'parent_type' ] == 'module' ) {
if ( $nodes [ $relation [ 'id_parent' ]][ 'id_module' ] == $node [ 'id_module' ]) {
$children_count ++ ;
}
}
}
if ( empty ( $node_center ) || $node_center [ 'counter' ] < $children_count ) {
$node_center [ 'x' ] = ( int ) $node [ 'coords' ][ 0 ];
$node_center [ 'y' ] = ( int ) $node [ 'coords' ][ 1 ];
$node_center [ 'counter' ] = $children_count ;
}
$nodes_and_relations [ 'nodes' ][ $index ][ 'x' ] = ( int ) $node [ 'coords' ][ 0 ];
$nodes_and_relations [ 'nodes' ][ $index ][ 'y' ] = ( int ) $node [ 'coords' ][ 1 ];
if (( $node [ 'type' ] == 'agent' ) || ( $node [ 'type' ] == '' )) {
$nodes_and_relations [ 'nodes' ][ $index ][ 'source_data' ] = $node [ 'id_agent' ];
$nodes_and_relations [ 'nodes' ][ $index ][ 'type' ] = 0 ;
} else {
$nodes_and_relations [ 'nodes' ][ $index ][ 'source_data' ] = $node [ 'id_module' ];
$nodes_and_relations [ 'nodes' ][ $index ][ 'id_agent' ] = $node [ 'id_agent' ];
$nodes_and_relations [ 'nodes' ][ $index ][ 'type' ] = 1 ;
}
$style = [];
$style [ 'shape' ] = 'circle' ;
$style [ 'image' ] = $node [ 'image' ];
$style [ 'width' ] = $node [ 'width' ];
$style [ 'height' ] = $node [ 'height' ];
$style [ 'label' ] = $node [ 'text' ];
$nodes_and_relations [ 'nodes' ][ $index ][ 'style' ] = json_encode ( $style );
$index ++ ;
}
$nodes_and_relations [ 'relations' ] = [];
$index = 0 ;
2019-03-12 16:22:28 +01:00
2019-03-11 20:10:08 +01:00
foreach ( $relation_nodes as $relation ) {
2019-03-12 12:05:54 +01:00
$nodes_and_relations [ 'relations' ][ $index ][ 'id_map' ] = $this -> idMap ;
2019-03-11 20:10:08 +01:00
if (( $relation [ 'parent_type' ] == 'agent' ) || ( $relation [ 'parent_type' ] == '' )) {
$nodes_and_relations [ 'relations' ][ $index ][ 'id_parent' ] = $relation [ 'id_parent' ];
$nodes_and_relations [ 'relations' ][ $index ][ 'id_parent_source_data' ] = $nodes [ $relation [ 'id_parent' ]][ 'id_agent' ];
$nodes_and_relations [ 'relations' ][ $index ][ 'parent_type' ] = 0 ;
} else if ( $relation [ 'parent_type' ] == 'module' ) {
$nodes_and_relations [ 'relations' ][ $index ][ 'id_parent' ] = $relation [ 'id_parent' ];
$nodes_and_relations [ 'relations' ][ $index ][ 'id_parent_source_data' ] = $nodes [ $relation [ 'id_parent' ]][ 'id_module' ];
$nodes_and_relations [ 'relations' ][ $index ][ 'parent_type' ] = 1 ;
} else {
$nodes_and_relations [ 'relations' ][ $index ][ 'id_parent' ] = $relation [ 'id_parent' ];
$nodes_and_relations [ 'relations' ][ $index ][ 'id_child_source_data' ] = - 2 ;
$nodes_and_relations [ 'relations' ][ $index ][ 'parent_type' ] = 3 ;
}
if (( $relation [ 'child_type' ] == 'agent' ) || ( $relation [ 'child_type' ] == '' )) {
$nodes_and_relations [ 'relations' ][ $index ][ 'id_child' ] = $relation [ 'id_child' ];
$nodes_and_relations [ 'relations' ][ $index ][ 'id_child_source_data' ] = $nodes [ $relation [ 'id_child' ]][ 'id_agent' ];
$nodes_and_relations [ 'relations' ][ $index ][ 'child_type' ] = 0 ;
} else if ( $relation [ 'child_type' ] == 'module' ) {
$nodes_and_relations [ 'relations' ][ $index ][ 'id_child' ] = $relation [ 'id_child' ];
$nodes_and_relations [ 'relations' ][ $index ][ 'id_child_source_data' ] = $nodes [ $relation [ 'id_child' ]][ 'id_module' ];
$nodes_and_relations [ 'relations' ][ $index ][ 'child_type' ] = 1 ;
} else {
$nodes_and_relations [ 'relations' ][ $index ][ 'id_child' ] = $relation [ 'id_child' ];
$nodes_and_relations [ 'relations' ][ $index ][ 'id_child_source_data' ] = - 2 ;
$nodes_and_relations [ 'relations' ][ $index ][ 'child_type' ] = 3 ;
}
$index ++ ;
}
2019-03-12 12:05:54 +01:00
if ( $this -> idMap > 0 && ( ! isset ( $this -> map [ '__simulated' ]))) {
2019-03-12 16:22:28 +01:00
if ( enterprise_installed ()) {
$nodes_and_relations = enterprise_hook (
'save_generate_nodes' ,
[
$this -> idMap ,
$nodes_and_relations ,
]
);
}
2019-03-11 20:10:08 +01:00
$center = [
'x' => $node_center [ 'x' ],
'y' => $node_center [ 'y' ],
];
2019-03-12 12:05:54 +01:00
$this -> map [ 'center_x' ] = $center [ 'x' ];
$this -> map [ 'center_y' ] = $center [ 'y' ];
2019-03-11 20:10:08 +01:00
db_process_sql_update (
'tmap' ,
[
2019-03-12 12:05:54 +01:00
'center_x' => $this -> map [ 'center_x' ],
'center_y' => $this -> map [ 'center_y' ],
2019-03-11 20:10:08 +01:00
],
2019-03-12 12:05:54 +01:00
[ 'id' => $this -> idMap ]
2019-03-11 20:10:08 +01:00
);
} else {
2019-03-12 12:05:54 +01:00
$this -> map [ 'center_x' ] = $node_center [ 'x' ];
$this -> map [ 'center_y' ] = $node_center [ 'y' ];
2019-03-11 20:10:08 +01:00
}
2019-03-12 16:22:28 +01:00
$this -> graph = $nodes_and_relations ;
2019-03-11 15:09:31 +01:00
}
/**
* Transform node information into JS data .
*
* @ return string HTML code with JS data .
*/
public function loadMapData ()
{
$networkmap = $this -> map ;
2019-03-12 12:05:54 +01:00
$simulate = false ;
2019-03-12 10:29:19 +01:00
if ( ! isset ( $networkmap [ '__simulated' ])) {
$networkmap [ 'filter' ] = json_decode (
$networkmap [ 'filter' ],
true
);
2019-03-12 16:22:28 +01:00
$networkmap [ 'filter' ][ 'holding_area' ] = [
500 ,
500 ,
];
$holding_area_title = __ ( 'Holding Area' );
2019-03-12 12:05:54 +01:00
} else {
$simulate = true ;
2019-03-12 16:22:28 +01:00
$holding_area_title = '' ;
$networkmap [ 'filter' ][ 'holding_area' ] = [
0 ,
0 ,
];
2019-03-11 20:10:08 +01:00
}
2019-03-11 15:10:22 +01:00
$this -> graph [ 'relations' ] = clean_duplicate_links (
2019-03-11 15:09:31 +01:00
$this -> graph [ 'relations' ]
2019-03-11 15:10:22 +01:00
);
2019-03-12 10:29:19 +01:00
// Print some params to handle it in js.
html_print_input_hidden ( 'product_name' , get_product_name ());
html_print_input_hidden ( 'center_logo' , ui_get_full_url ( ui_get_logo_to_center_networkmap ()));
2019-03-11 15:09:31 +01:00
$output .= ' < script type = " text/javascript " >
////////////////////////////////////////////////////////////////////
// VARS FROM THE DB
////////////////////////////////////////////////////////////////////
var url_background_grid = " '.ui_get_full_url('images/background_grid.png').' " ;
2019-03-11 20:10:08 +01:00
' ;
2019-03-12 10:29:19 +01:00
$output .= 'var networkmap_id = "' . $this -> idMap . " \" ; \n " ;
2019-03-11 20:10:08 +01:00
2019-03-11 16:57:54 +01:00
if ( ! empty ( $networkmap [ 'filter' ])) {
if ( empty ( $networkmap [ 'filter' ][ 'x_offs' ])) {
$output .= " var x_offs =null; \n " ;
} else {
$output .= 'var x_offs =' . $networkmap [ 'filter' ][ 'x_offs' ] . " ; \n " ;
}
if ( empty ( $networkmap [ 'filter' ][ 'y_offs' ])) {
$output .= " var y_offs =null; \n " ;
} else {
$output .= 'var y_offs =' . $networkmap [ 'filter' ][ 'y_offs' ] . " ; \n " ;
}
2019-03-11 15:09:31 +01:00
2019-03-11 20:10:08 +01:00
if ( empty ( $networkmap [ 'filter' ][ 'y_offs' ])) {
$output .= " var z_dash =null; \n " ;
} else {
$output .= 'var z_dash = ' . $networkmap [ 'filter' ][ 'z_dash' ] . " ; \n " ;
}
2019-03-11 15:09:31 +01:00
} else {
$output .= " var x_offs = null; \n " ;
$output .= " var y_offs = null; \n " ;
$output .= " var z_dash = null; \n " ;
}
$output .= 'var networkmap_refresh_time = 1000 * ' . $networkmap [ 'source_period' ] . " ; \n " ;
$output .= 'var networkmap_center = [ ' . $networkmap [ 'center_x' ] . ', ' . $networkmap [ 'center_y' ] . " ]; \n " ;
$output .= 'var networkmap_dimensions = [ ' . $networkmap [ 'width' ] . ', ' . $networkmap [ 'height' ] . " ]; \n " ;
$output .= 'var enterprise_installed = ' . (( int ) enterprise_installed ()) . " ; \n " ;
$output .= 'var node_radius = ' . $networkmap [ 'filter' ][ 'node_radius' ] . " ; \n " ;
$output .= 'var networkmap_holding_area_dimensions = ' . json_encode ( $networkmap [ 'filter' ][ 'holding_area' ]) . " ; \n " ;
$output .= " var networkmap = { 'nodes': [], 'links': []}; \n " ;
$nodes = $this -> graph [ '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 ,
2019-03-12 12:05:54 +01:00
$count_item_holding_area ,
$simulate
2019-03-11 15:09:31 +01:00
);
if ( $item [ 'deleted' ]) {
continue ;
}
$output .= 'networkmap.nodes.push(' . json_encode ( $item ) . " ); \n " ;
$nodes_graph [ $item [ 'id' ]] = $item ;
}
$relations = $this -> graph [ 'relations' ];
if ( $relations === false ) {
$relations = [];
}
// Clean the relations and transform the module relations into
// interfaces.
networkmap_clean_relations_for_js ( $relations );
2019-03-12 12:05:54 +01:00
$links_js = networkmap_links_to_js_links (
$relations ,
$nodes_graph ,
$simulate
);
2019-03-11 15:09:31 +01:00
$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' ) {
$output .= '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 {
$output .= 'networkmap.links.push(' . json_encode ( $link_js ) . " ); \n " ;
}
}
$output .= '
////////////////////////////////////////////////////////////////////
// INTERFACE STATUS COLORS
////////////////////////////////////////////////////////////////////
' ;
$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 ;
$output .= 'var module_color_status = ' . json_encode ( $module_color_status ) . " ; \n " ;
$output .= " var module_color_status_unknown = ' " . $module_color_status_unknown . " '; \n " ;
$output .= '
////////////////////////////////////////////////////////////////////
// Other vars
////////////////////////////////////////////////////////////////////
' ;
$output .= " var translation_none = ' " . __ ( 'None' ) . " '; \n " ;
$output .= " var dialog_node_edit_title = ' " . __ ( 'Edit node %s' ) . " '; \n " ;
2019-03-12 16:22:28 +01:00
$output .= " var holding_area_title = ' " . $holding_area_title . " '; \n " ;
2019-03-11 15:09:31 +01:00
$output .= " var edit_menu = ' " . __ ( 'Show details and options' ) . " '; \n " ;
$output .= " var interface_link_add = ' " . __ ( 'Add a interface link' ) . " '; \n " ;
$output .= " var set_parent_link = ' " . __ ( 'Set parent interface' ) . " '; \n " ;
$output .= " var set_as_children_menu = ' " . __ ( 'Set as children' ) . " '; \n " ;
$output .= " var set_parent_menu = ' " . __ ( 'Set parent' ) . " '; \n " ;
$output .= " var abort_relationship_menu = ' " . __ ( 'Abort the action of set relationship' ) . " '; \n " ;
$output .= " var delete_menu = ' " . __ ( 'Delete' ) . " '; \n " ;
$output .= " var add_node_menu = ' " . __ ( 'Add node' ) . " '; \n " ;
$output .= " var set_center_menu = ' " . __ ( 'Set center' ) . " '; \n " ;
$output .= " var refresh_menu = ' " . __ ( 'Refresh' ) . " '; \n " ;
$output .= " var refresh_holding_area_menu = ' " . __ ( 'Refresh Holding area' ) . " '; \n " ;
$output .= " var ok_button = ' " . __ ( 'Proceed' ) . " '; \n " ;
$output .= " var message_to_confirm = ' " . __ ( 'Resetting the map will delete all customizations you have done, including manual relationships between elements, new items, etc.' ) . " '; \n " ;
$output .= " var warning_message = ' " . __ ( 'WARNING' ) . " '; \n " ;
$output .= " var ok_button = ' " . __ ( 'Proceed' ) . " '; \n " ;
$output .= " var cancel_button = ' " . __ ( 'Cancel' ) . " '; \n " ;
$output .= " var restart_map_menu = ' " . __ ( 'Restart map' ) . " '; \n " ;
$output .= " var abort_relationship_interface = ' " . __ ( 'Abort the interface relationship' ) . " '; \n " ;
$output .= " var abort_relationship_menu = ' " . __ ( 'Abort the action of set relationship' ) . " '; \n " ;
$output .= '</script>' ;
return $output ;
}
/**
* Show an advanced interface to manage dialogs .
*
* @ return string HTML code with dialogs .
*/
2019-03-11 15:37:08 +01:00
public function loadAdvancedInterface ()
2019-03-11 15:09:31 +01:00
{
$list_networkmaps = get_networkmaps ( $this -> idMap );
if ( empty ( $list_networkmaps )) {
$list_networkmaps = [];
}
$output .= '<div id="open_version_dialog" style="display: none;">' ;
$output .= __ (
'In the Open version of %s can not be edited nodes or map' ,
get_product_name ()
);
$output .= '</div>' ;
$output .= '<div id="dialog_node_edit" style="display: none;" title="' ;
$output .= __ ( 'Edit node' ) . '">' ;
$output .= '<div style="text-align: left; width: 100%;">' ;
2019-03-11 15:37:08 +01:00
$table = new StdClass ();
2019-03-11 15:09:31 +01:00
$table -> id = 'node_details' ;
$table -> width = '100%' ;
$table -> data = [];
$table -> data [ 0 ][ 0 ] = '<strong>' . __ ( 'Agent' ) . '</strong>' ;
$table -> data [ 0 ][ 1 ] = '' ;
$table -> data [ 1 ][ 0 ] = '<strong>' . __ ( 'Adresses' ) . '</strong>' ;
$table -> data [ 1 ][ 1 ] = '' ;
$table -> data [ 2 ][ 0 ] = '<strong>' . __ ( 'OS type' ) . '</strong>' ;
$table -> data [ 2 ][ 1 ] = '' ;
$table -> data [ 3 ][ 0 ] = '<strong>' . __ ( 'Group' ) . '</strong>' ;
$table -> data [ 3 ][ 1 ] = '' ;
$output .= ui_toggle (
html_print_table ( $table , true ),
__ ( 'Node Details' ),
__ ( 'Node Details' ),
false ,
true
);
2019-03-11 15:37:08 +01:00
$table = new StdClass ();
2019-03-11 15:09:31 +01:00
$table -> id = 'interface_information' ;
$table -> width = '100%' ;
$table -> head [ 'interface_name' ] = __ ( 'Name' );
$table -> head [ 'interface_status' ] = __ ( 'Status' );
$table -> head [ 'interface_graph' ] = __ ( 'Graph' );
$table -> head [ 'interface_ip' ] = __ ( 'Ip' );
$table -> head [ 'interface_mac' ] = __ ( 'MAC' );
$table -> data = [];
$table -> rowstyle [ 'template_row' ] = 'display: none;' ;
$table -> data [ 'template_row' ][ 'interface_name' ] = '' ;
$table -> data [ 'template_row' ][ 'interface_status' ] = '' ;
$table -> data [ 'template_row' ][ 'interface_graph' ] = '' ;
$table -> data [ 'template_row' ][ 'interface_ip' ] = '' ;
$table -> data [ 'template_row' ][ 'interface_mac' ] = '' ;
$output .= ui_toggle (
html_print_table ( $table , true ),
__ ( 'Interface Information (SNMP)' ),
__ ( 'Interface Information (SNMP)' ),
true ,
true
);
2019-03-11 15:37:08 +01:00
$table = new StdClass ();
2019-03-11 15:09:31 +01:00
$table -> id = 'node_options' ;
$table -> width = '100%' ;
$table -> data = [];
$table -> data [ 0 ][ 0 ] = __ ( 'Shape' );
$table -> data [ 0 ][ 1 ] = html_print_select (
[
'circle' => __ ( 'Circle' ),
'square' => __ ( 'Square' ),
'rhombus' => __ ( 'Rhombus' ),
],
'shape' ,
'' ,
'javascript:' ,
'' ,
0 ,
true
) . ' <span id="shape_icon_in_progress" style="display: none;">' . html_print_image ( 'images/spinner.gif' , true ) . '</span><span id="shape_icon_correct" style="display: none;">' . html_print_image ( 'images/dot_green.png' , true ) . '</span><span id="shape_icon_fail" style="display: none;">' . html_print_image ( 'images/dot_red.png' , true ) . '</span>' ;
$table -> data [ 'node_name' ][ 0 ] = __ ( 'Name' );
$table -> data [ 'node_name' ][ 1 ] = html_print_input_text (
'edit_name_node' ,
'' ,
__ ( 'name node' ),
'20' ,
'50' ,
true
);
$table -> data [ 'node_name' ][ 2 ] = html_print_button (
__ ( 'Update node' ),
'' ,
false ,
'' ,
'class="sub"' ,
true
);
$table -> data [ 'fictional_node_name' ][ 0 ] = __ ( 'Name' );
$table -> data [ 'fictional_node_name' ][ 1 ] = html_print_input_text (
'edit_name_fictional_node' ,
'' ,
__ ( 'name fictional node' ),
'20' ,
'50' ,
true
);
$table -> data [ 'fictional_node_networkmap_link' ][ 0 ] = __ ( 'Networkmap to link' );
$table -> data [ 'fictional_node_networkmap_link' ][ 1 ] = html_print_select (
$list_networkmaps ,
'edit_networkmap_to_link' ,
'' ,
'' ,
'' ,
0 ,
true
);
$table -> data [ 'fictional_node_update_button' ][ 0 ] = '' ;
$table -> data [ 'fictional_node_update_button' ][ 1 ] = html_print_button (
__ ( 'Update fictional node' ),
'' ,
false ,
'add_fictional_node();' ,
'class="sub"' ,
true
);
$output .= ui_toggle (
html_print_table ( $table , true ),
__ ( 'Node options' ),
__ ( 'Node options' ),
true ,
true
);
2019-03-11 15:37:08 +01:00
$table = new StdClass ();
2019-03-11 15:09:31 +01:00
$table -> id = 'relations_table' ;
$table -> width = '100%' ;
$table -> head = [];
$table -> head [ 'node_source' ] = __ ( 'Node source' );
$table -> head [ 'interface_source' ] = __ ( 'Interface source' );
$table -> head [ 'interface_target' ] = __ ( 'Interface Target' );
$table -> head [ 'node_target' ] = __ ( 'Node target' );
$table -> head [ 'edit' ] = '<span title="' . __ ( 'Edit' ) . '">' . __ ( 'E.' ) . '</span>' ;
$table -> data = [];
$table -> rowstyle [ 'template_row' ] = 'display: none;' ;
$table -> data [ 'template_row' ][ 'node_source' ] = '' ;
$table -> data [ 'template_row' ][ 'interface_source' ] = html_print_select (
[],
'interface_source' ,
'' ,
'' ,
__ ( 'None' ),
0 ,
true
);
$table -> data [ 'template_row' ][ 'interface_target' ] = html_print_select (
[],
'interface_target' ,
'' ,
'' ,
__ ( 'None' ),
0 ,
true
);
$table -> data [ 'template_row' ][ 'node_target' ] = '' ;
$table -> data [ 'template_row' ][ 'edit' ] = '' ;
$table -> data [ 'template_row' ][ 'edit' ] .= '<span class="edit_icon_correct" style="display: none;">' . html_print_image ( 'images/dot_green.png' , true ) . '</span><span class="edit_icon_fail" style="display: none;">' . html_print_image ( 'images/dot_red.png' , true ) . '</span><span class="edit_icon_progress" style="display: none;">' . html_print_image ( 'images/spinner.gif' , true ) . '</span><span class="edit_icon"><a class="edit_icon_link" title="' . __ ( 'Update' ) . '" href="#">' . html_print_image ( 'images/config.png' , true ) . '</a></span>' ;
$table -> data [ 'template_row' ][ 'edit' ] .= '<a class="delete_icon" href="#">' . html_print_image ( 'images/delete.png' , true ) . '</a>' ;
$table -> colspan [ 'no_relations' ][ '0' ] = 5 ;
$table -> cellstyle [ 'no_relations' ][ '0' ] = 'text-align: center;' ;
$table -> data [ 'no_relations' ][ '0' ] = __ ( 'There are not relations' );
$table -> colspan [ 'loading' ][ '0' ] = 5 ;
$table -> cellstyle [ 'loading' ][ '0' ] = 'text-align: center;' ;
$table -> data [ 'loading' ][ '0' ] = html_print_image (
'images/wait.gif' ,
true
);
$output .= ui_toggle (
html_print_table ( $table , true ),
__ ( 'Relations' ),
__ ( 'Relations' ),
true ,
true
);
$output .= '</div></div>' ;
$output .= '<div id="dialog_interface_link" style="display: none;" title="Interface link">' ;
$output .= '<div style="text-align: left; width: 100%;">' ;
$table = new stdClass ();
$table -> id = 'interface_link_table' ;
$table -> width = '100%' ;
$table -> head [ 'node_source_interface' ] = __ ( 'Node source' );
$table -> head [ 'interface_source_select' ] = __ ( 'Interface source' );
$table -> head [ 'interface_target_select' ] = __ ( 'Interface Target' );
$table -> head [ 'node_target_interface' ] = __ ( 'Node target' );
$table -> data = [];
$table -> data [ 'interface_row' ][ 'node_source_interface' ] = html_print_label ( '' , 'node_source_interface' );
$table -> data [ 'interface_row' ][ 'interface_source_select' ] = html_print_select (
[],
'interface_source_select' ,
'' ,
'' ,
__ ( 'None' ),
0 ,
true
);
$table -> data [ 'interface_row' ][ 'interface_target_select' ] = html_print_select (
[],
'interface_target_select' ,
'' ,
'' ,
__ ( 'None' ),
0 ,
true
);
$table -> data [ 'interface_row' ][ 'node_target_interface' ] = html_print_label (
'' ,
'node_target_interface'
);
$output .= 'br><br>' ;
$table -> data [ 'interface_row' ][ 'interface_link_button' ] = html_print_button (
__ ( 'Add interface link' ),
'' ,
false ,
'add_interface_link_js();' ,
'class="sub"' ,
true
);
$output .= html_print_table ( $table , true );
$output .= '</div></div>' ;
$output .= '<div id="dialog_node_add" style="display: none;" title="' ;
$output .= __ ( 'Add node' ) . '">' ;
$output .= '<div style="text-align: left; width: 100%;">' ;
2019-03-11 15:37:08 +01:00
$table = new StdClass ();
2019-03-11 15:09:31 +01:00
$table -> width = '100%' ;
$table -> data = [];
$table -> data [ 0 ][ 0 ] = __ ( 'Agent' );
$params = [];
$params [ 'return' ] = true ;
$params [ 'show_helptip' ] = true ;
$params [ 'input_name' ] = 'agent_name' ;
$params [ 'input_id' ] = 'agent_name' ;
$params [ 'print_hidden_input_idagent' ] = true ;
$params [ 'hidden_input_idagent_name' ] = 'id_agent' ;
$params [ 'disabled_javascript_on_blur_function' ] = true ;
$table -> data [ 0 ][ 1 ] = ui_print_agent_autocomplete_input ( $params );
$table -> data [ 1 ][ 0 ] = '' ;
$table -> data [ 1 ][ 1 ] = html_print_button (
__ ( 'Add agent node' ),
'' ,
false ,
'add_agent_node();' ,
'class="sub"' ,
true
) . html_print_image (
'images/error_red.png' ,
true ,
[
'id' => 'error_red' ,
'style' => 'vertical-align: bottom;display: none;' ,
'class' => 'forced_title' ,
2019-03-12 19:23:40 +01:00
'alt' => '' ,
2019-03-11 15:09:31 +01:00
'data-title' => 'data-use_title_for_force_title:1' ,
],
false
);
$add_agent_node_html = html_print_table ( $table , true );
$output .= ui_toggle (
$add_agent_node_html ,
__ ( 'Add agent node' ),
__ ( 'Add agent node' ),
false ,
true
);
2019-03-11 15:37:08 +01:00
$table = new StdClass ();
2019-03-11 15:09:31 +01:00
$table -> width = '100%' ;
$table -> data = [];
$table -> data [ 0 ][ 0 ] = __ ( 'Group' );
$table -> data [ 0 ][ 1 ] = html_print_select_groups (
false ,
'IW' ,
false ,
'group_for_show_agents' ,
- 1 ,
'choose_group_for_show_agents()' ,
__ ( 'None' ),
- 1 ,
true
);
$table -> data [ 1 ][ 0 ] = __ ( 'Agents' );
$table -> data [ 1 ][ 1 ] = html_print_select (
[ - 1 => __ ( 'None' )],
'agents_filter_group' ,
- 1 ,
'' ,
'' ,
0 ,
true ,
true ,
true ,
'' ,
false ,
'width: 170px;' ,
false ,
5
);
$table -> data [ 2 ][ 0 ] = '' ;
$table -> data [ 2 ][ 1 ] = html_print_button (
__ ( 'Add agent node' ),
'' ,
false ,
'add_agent_node_from_the_filter_group();' ,
'class="sub"' ,
true
);
$add_agent_node_html = html_print_table ( $table , true );
$output .= ui_toggle (
$add_agent_node_html ,
__ ( 'Add agent node (filter by group)' ),
__ ( 'Add agent node' ),
true ,
true
);
2019-03-11 15:37:08 +01:00
$table = new StdClass ();
2019-03-11 15:09:31 +01:00
$table -> width = '100%' ;
$table -> data = [];
$table -> data [ 0 ][ 0 ] = __ ( 'Name' );
$table -> data [ 0 ][ 1 ] = html_print_input_text (
'name_fictional_node' ,
'' ,
__ ( 'name fictional node' ),
'20' ,
'50' ,
true
);
$table -> data [ 1 ][ 0 ] = __ ( 'Networkmap to link' );
$table -> data [ 1 ][ 1 ] = html_print_select (
$list_networkmaps ,
'networkmap_to_link' ,
'' ,
'' ,
'' ,
0 ,
true
);
$table -> data [ 2 ][ 0 ] = '' ;
$table -> data [ 2 ][ 1 ] = html_print_button (
__ ( 'Add fictional node' ),
'' ,
false ,
'add_fictional_node();' ,
'class="sub"' ,
true
);
$add_agent_node_html = html_print_table ( $table , true );
$output .= ui_toggle (
$add_agent_node_html ,
__ ( 'Add fictional point' ),
__ ( 'Add agent node' ),
true ,
true
);
$output .= '</div></div>' ;
return $output ;
}
/**
* Loads advanced map controller ( JS ) .
*
* @ return string HTML code for advanced controller .
*/
public function loadController ()
{
$output = '' ;
// Generate JS for advanced controller.
$output .= '
< script type = " text/javascript " >
////////////////////////////////////////////////////////////////////////
// document ready
////////////////////////////////////////////////////////////////////////
$ ( document ) . ready ( function () {
init_graph ({
graph : networkmap ,
networkmap_center : networkmap_center ,
networkmap_dimensions : networkmap_dimensions ,
enterprise_installed : enterprise_installed ,
node_radius : node_radius ,
holding_area_dimensions : networkmap_holding_area_dimensions ,
url_background_grid : url_background_grid
});
init_drag_and_drop ();
init_minimap ();
function_open_minimap ();
$ ( document . body ) . on ( " mouseleave " ,
" .context-menu-list " ,
function ( e ) {
try {
$ ( " #networkconsole_'. $this->idMap .' " ) . contextMenu ( " hide " );
}
catch ( err ) {
}
}
);
});
</ script > ' ;
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 = '' ;
2019-03-12 16:22:28 +01:00
$minimap_display = '' ;
if ( $this -> mapOptions [ 'pure' ]) {
$minimap_display = 'none' ;
2019-03-11 15:09:31 +01:00
}
$networkmap = $this -> map ;
$networkmap [ 'filter' ] = json_decode ( $networkmap [ 'filter' ], true );
$networkmap [ 'filter' ][ 'l2_network_interfaces' ] = 1 ;
$output .= '<script type="text/javascript" src="' . $config [ 'homeurl' ] . 'include/javascript/d3.3.5.14.js" charset="utf-8"></script>' ;
$output .= '<script type="text/javascript" src="' . $config [ 'homeurl' ] . 'include/javascript/jquery.contextMenu.js"></script>' ;
$output .= '<script type="text/javascript" src="' . $config [ 'homeurl' ] . 'include/javascript/functions_pandora_networkmap.js"></script>' ;
// Open networkconsole_id div.
$output .= '<div id="networkconsole_' . $networkmap [ 'id' ] . '"' ;
$output .= ' style="position: relative; overflow: hidden; background: #FAFAFA">' ;
2019-03-12 16:22:28 +01:00
$output .= '<div style="display: ' . $minimap_display . ';">' ;
2019-03-11 15:09:31 +01:00
$output .= '<canvas id="minimap_' . $networkmap [ 'id' ] . '"' ;
$output .= ' style="position: absolute; left: 0px; top: 0px; border: 1px solid #bbbbbb;">' ;
$output .= '</canvas>' ;
$output .= '<div id="arrow_minimap_' . $networkmap [ 'id' ] . '"' ;
$output .= ' style="position: absolute; left: 0px; top: 0px;">' ;
$output .= '<a title="' . __ ( 'Open Minimap' ) . '" href="javascript: toggle_minimap();">' ;
$output .= '<img id="image_arrow_minimap_' . $networkmap [ 'id' ] . '"' ;
$output .= ' src="images/minimap_open_arrow.png" />' ;
$output .= '</a><div></div></div>' ;
$output .= '<div id="hide_labels_' . $networkmap [ 'id' ] . '"' ;
$output .= ' style="position: absolute; right: 10px; top: 10px;">' ;
$output .= '<a title="' . __ ( 'Hide Labels' ) . '" href="javascript: hide_labels();">' ;
$output .= '<img id="image_hide_show_labels" src="images/icono_borrar.png" />' ;
$output .= '</a></div>' ;
$output .= '<div id="holding_spinner_' . $networkmap [ 'id' ] . '" ' ;
$output .= ' style="display: none; position: absolute; right: 50px; top: 20px;">' ;
$output .= '<img id="image_hide_show_labels" src="images/spinner.gif" />' ;
$output .= '</div>' ;
// Close networkconsole_id div.
$output .= " </div> \n " ;
return $output ;
}
2019-03-07 18:57:48 +01:00
/**
* Print all components required to visualizate a network map .
*
* @ param boolean $return Return as string or not .
*
* @ return string HTML code .
*/
public function printMap ( $return = false )
{
global $config ;
// ACL.
$networkmap_read = check_acl (
$config [ 'id_user' ],
$networkmap [ 'id_group' ],
'MR'
);
$networkmap_write = check_acl (
$config [ 'id_user' ],
$networkmap [ 'id_group' ],
'MW'
);
$networkmap_manage = check_acl (
$config [ 'id_user' ],
$networkmap [ 'id_group' ],
'MM'
);
if ( ! $networkmap_read
&& ! $networkmap_write
&& ! $networkmap_manage
) {
db_pandora_audit (
'ACL Violation' ,
'Trying to access networkmap'
);
include 'general/noaccess.php' ;
return '' ;
}
$user_readonly = ! $networkmap_write && ! $networkmap_manage ;
if ( isset ( $this -> idMap )) {
2019-03-11 15:09:31 +01:00
$output .= $this -> loadMapSkel ();
$output .= $this -> loadMapData ();
$output .= $this -> loadController ();
2019-03-11 15:37:08 +01:00
$output .= $this -> loadAdvancedInterface ();
2019-03-11 20:10:08 +01:00
} else {
2019-03-12 12:05:54 +01:00
// Simulated, no tmap entries.
2019-03-11 20:10:08 +01:00
$output .= $this -> loadMapSkel ();
$output .= $this -> loadMapData ();
$output .= $this -> loadController ();
2019-03-07 18:57:48 +01:00
}
if ( $return === false ) {
echo $output ;
}
return $output ;
}
}