mirror of
https://github.com/pandorafms/pandorafms.git
synced 2025-07-28 00:04:37 +02:00
Improvements. networkmap class
Former-commit-id: b2e940cbb28112fe2ac9088ce2e76fd5b48239f9
This commit is contained in:
parent
6fb6963501
commit
95d2259236
@ -113,13 +113,20 @@ class NetworkMap
|
|||||||
public $dotGraph;
|
public $dotGraph;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Node list.
|
* Node list processed by NetworkMap class.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
public $nodes;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Node list RAW.
|
||||||
* A simple list of nodes, could content information of agents, modules...
|
* A simple list of nodes, could content information of agents, modules...
|
||||||
* Is the 'raw' information.
|
* Is the 'raw' information.
|
||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
public $nodes;
|
public $rawNodes;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Useful to translate id_node to id_agent or id_module.
|
* Useful to translate id_node to id_agent or id_module.
|
||||||
@ -215,11 +222,13 @@ class NetworkMap
|
|||||||
*/
|
*/
|
||||||
public function __construct($options=false)
|
public function __construct($options=false)
|
||||||
{
|
{
|
||||||
|
global $config;
|
||||||
|
|
||||||
// Default mapOptions values.
|
// Default mapOptions values.
|
||||||
// Defines the command to generate positions.
|
// Defines the command to generate positions.
|
||||||
$this->mapOptions['generation_method'] = LAYOUT_SPRING1;
|
$this->mapOptions['generation_method'] = LAYOUT_SPRING1;
|
||||||
$this->mapOptions['width'] = 0;
|
$this->mapOptions['width'] = $config['networkmap_max_width'];
|
||||||
$this->mapOptions['height'] = 0;
|
$this->mapOptions['height'] = $config['networkmap_max_width'];
|
||||||
$this->mapOptions['simple'] = 0;
|
$this->mapOptions['simple'] = 0;
|
||||||
$this->mapOptions['font_size'] = 12;
|
$this->mapOptions['font_size'] = 12;
|
||||||
$this->mapOptions['nooverlap'] = 1;
|
$this->mapOptions['nooverlap'] = 1;
|
||||||
@ -241,7 +250,7 @@ class NetworkMap
|
|||||||
'x_offs' => 0,
|
'x_offs' => 0,
|
||||||
'y_offs' => 0,
|
'y_offs' => 0,
|
||||||
'z_dash' => 0.5,
|
'z_dash' => 0.5,
|
||||||
'node_sep' => 3,
|
'node_sep' => 5,
|
||||||
'rank_sep' => 5,
|
'rank_sep' => 5,
|
||||||
'mindist' => 1,
|
'mindist' => 1,
|
||||||
'kval' => 0.1,
|
'kval' => 0.1,
|
||||||
@ -260,7 +269,7 @@ class NetworkMap
|
|||||||
|
|
||||||
// Array of nodes, agents, virtual, etc.
|
// Array of nodes, agents, virtual, etc.
|
||||||
if (isset($options['nodes'])) {
|
if (isset($options['nodes'])) {
|
||||||
$this->nodes = $options['nodes'];
|
$this->rawNodes = $options['nodes'];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Array of relations.
|
// Array of relations.
|
||||||
@ -362,8 +371,8 @@ class NetworkMap
|
|||||||
'background_options' => 0,
|
'background_options' => 0,
|
||||||
'source_period' => 60,
|
'source_period' => 60,
|
||||||
'filter' => $this->mapOptions['map_filter'],
|
'filter' => $this->mapOptions['map_filter'],
|
||||||
'width' => 0,
|
'width' => $config['networkmap_max_width'],
|
||||||
'height' => 0,
|
'height' => $config['networkmap_max_width'],
|
||||||
'center_x' => 0,
|
'center_x' => 0,
|
||||||
'center_y' => 0,
|
'center_y' => 0,
|
||||||
];
|
];
|
||||||
@ -815,11 +824,16 @@ class NetworkMap
|
|||||||
// Handmade ones.
|
// Handmade ones.
|
||||||
// Add also parent relationship.
|
// Add also parent relationship.
|
||||||
$parent_id = $node['id_parent'];
|
$parent_id = $node['id_parent'];
|
||||||
$parent_node = $this->nodes[$parent_id]['id_node'];
|
$parent_node = $this->getNodeData($parent_id, 'id_node');
|
||||||
|
|
||||||
// Store relationship.
|
// Store relationship.
|
||||||
if ($parent_node) {
|
if ($parent_node) {
|
||||||
$relations[$parent_node] = $node['id_node'];
|
$relations[] = [
|
||||||
|
'id_parent' => $parent_node,
|
||||||
|
'parent_type' => NODE_GENERIC,
|
||||||
|
'id_child' => $node['id_node'],
|
||||||
|
'child_type' => NODE_GENERIC,
|
||||||
|
];
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -1421,7 +1435,13 @@ class NetworkMap
|
|||||||
|
|
||||||
case NODE_GENERIC:
|
case NODE_GENERIC:
|
||||||
default:
|
default:
|
||||||
$item['color'] = $node['color'];
|
foreach ($source_data as $k => $v) {
|
||||||
|
$node[$k] = $v;
|
||||||
|
}
|
||||||
|
|
||||||
|
$node['style']['label'] = $node['name'];
|
||||||
|
$node['style']['shape'] = 'circle';
|
||||||
|
$item['color'] = self::getColorByStatus($node['status']);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1645,7 +1665,7 @@ class NetworkMap
|
|||||||
}
|
}
|
||||||
|
|
||||||
$edge = "\n".$data['from'].' -- '.$data['to'];
|
$edge = "\n".$data['from'].' -- '.$data['to'];
|
||||||
$edge .= '[len='.$this->mapOptions['map_filter']['rank_sep'];
|
$edge .= '[len='.$this->mapOptions['map_filter']['node_sep'];
|
||||||
$edge .= ', color="#BDBDBD", headclip=false, tailclip=false,';
|
$edge .= ', color="#BDBDBD", headclip=false, tailclip=false,';
|
||||||
$edge .= ' edgeURL=""];'."\n";
|
$edge .= ' edgeURL=""];'."\n";
|
||||||
|
|
||||||
@ -1690,8 +1710,12 @@ class NetworkMap
|
|||||||
$graph = '';
|
$graph = '';
|
||||||
|
|
||||||
if ($nodes === false) {
|
if ($nodes === false) {
|
||||||
// Search for nodes.
|
if ($this->rawNodes) {
|
||||||
$nodes = $this->calculateNodes();
|
$nodes = $this->rawNodes;
|
||||||
|
} else {
|
||||||
|
// Search for nodes.
|
||||||
|
$nodes = $this->calculateNodes();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Search for relations.
|
// Search for relations.
|
||||||
@ -1718,8 +1742,10 @@ class NetworkMap
|
|||||||
$i = 1;
|
$i = 1;
|
||||||
$orphans = [];
|
$orphans = [];
|
||||||
foreach ($nodes as $k => $node) {
|
foreach ($nodes as $k => $node) {
|
||||||
if (isset($node['id_agente']) === true
|
if (isset($node['type']) && $node['type'] == NODE_AGENTE
|
||||||
&& $node['id_agente'] > 0
|
|| (isset($node['type']) === false
|
||||||
|
&& isset($node['id_agente']) === true
|
||||||
|
&& $node['id_agente'] > 0)
|
||||||
) {
|
) {
|
||||||
// Origin is agent or module.
|
// Origin is agent or module.
|
||||||
if (isset($node['id_agente_modulo']) === true
|
if (isset($node['id_agente_modulo']) === true
|
||||||
@ -1852,6 +1878,8 @@ class NetworkMap
|
|||||||
*/
|
*/
|
||||||
private function parseGraphvizMapFile($graphviz_file)
|
private function parseGraphvizMapFile($graphviz_file)
|
||||||
{
|
{
|
||||||
|
global $config;
|
||||||
|
|
||||||
if (isset($graphviz_file) === false
|
if (isset($graphviz_file) === false
|
||||||
|| is_file($graphviz_file) === false
|
|| is_file($graphviz_file) === false
|
||||||
) {
|
) {
|
||||||
@ -1869,9 +1897,16 @@ class NetworkMap
|
|||||||
if (preg_match('/^graph.*$/', $line) != 0) {
|
if (preg_match('/^graph.*$/', $line) != 0) {
|
||||||
// Graph definition.
|
// Graph definition.
|
||||||
$fields = explode(' ', $line);
|
$fields = explode(' ', $line);
|
||||||
|
$this->map['width'] = ($fields[2] * 10 * GRAPHVIZ_RADIUS_CONVERSION_FACTOR);
|
||||||
|
$this->map['height'] = ($fields[3] * 10 * GRAPHVIZ_RADIUS_CONVERSION_FACTOR);
|
||||||
|
|
||||||
$this->map['width'] = 0;
|
if ($this->map['width'] > $config['networkmap_max_width']) {
|
||||||
$this->map['height'] = 0;
|
$this->map['width'] = $config['networkmap_max_width'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->map['height'] > $config['networkmap_max_width']) {
|
||||||
|
$this->map['height'] = $config['networkmap_max_width'];
|
||||||
|
}
|
||||||
} else if (preg_match('/^node.*$/', $line) != 0) {
|
} else if (preg_match('/^node.*$/', $line) != 0) {
|
||||||
// Node.
|
// Node.
|
||||||
$fields = explode(' ', $line);
|
$fields = explode(' ', $line);
|
||||||
@ -2425,6 +2460,49 @@ class NetworkMap
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generates a simple interface to interact with nodes.
|
||||||
|
*
|
||||||
|
* @return string HTML code for simple interface.
|
||||||
|
*/
|
||||||
|
public function loadSimpleInterface()
|
||||||
|
{
|
||||||
|
$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%;">';
|
||||||
|
|
||||||
|
$table = new StdClass();
|
||||||
|
$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
|
||||||
|
);
|
||||||
|
return $output;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Show an advanced interface to manage dialogs.
|
* Show an advanced interface to manage dialogs.
|
||||||
*
|
*
|
||||||
@ -2899,7 +2977,6 @@ class NetworkMap
|
|||||||
$minimap_display = '';
|
$minimap_display = '';
|
||||||
if ($this->mapOptions['pure']) {
|
if ($this->mapOptions['pure']) {
|
||||||
$minimap_display = 'none';
|
$minimap_display = 'none';
|
||||||
$minimap_display = '';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$networkmap = $this->map;
|
$networkmap = $this->map;
|
||||||
@ -3001,7 +3078,7 @@ class NetworkMap
|
|||||||
$output .= $this->loadMapSkel();
|
$output .= $this->loadMapSkel();
|
||||||
$output .= $this->loadMapData();
|
$output .= $this->loadMapData();
|
||||||
$output .= $this->loadController();
|
$output .= $this->loadController();
|
||||||
$output .= $this->loadAdvancedInterface();
|
$output .= $this->loadSimpleInterface();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($return === false) {
|
if ($return === false) {
|
||||||
|
@ -1,5 +1,33 @@
|
|||||||
|
/* global jQuery */
|
||||||
|
/* global $ */
|
||||||
|
/* global context_minimap */
|
||||||
|
/* global minimap_w */
|
||||||
|
/* global minimap_h */
|
||||||
|
/* global minimap_relation */
|
||||||
|
/* global graph */
|
||||||
|
/* global translation */
|
||||||
|
/* global scale */
|
||||||
|
/* global width_svg */
|
||||||
|
/* global height_svg */
|
||||||
|
/* global networkmap_dimensions */
|
||||||
|
/* global node_radius */
|
||||||
|
/* global holding_area_dimensions */
|
||||||
|
/* global networkmap_id */
|
||||||
|
/* global enterprise_installed */
|
||||||
|
/* global force */
|
||||||
|
/* global layer_graph_nodes */
|
||||||
|
/* global layer_graph_links */
|
||||||
|
/* global ellipsize */
|
||||||
|
/* global d3 */
|
||||||
|
/* global node_selected */
|
||||||
|
|
||||||
|
/* exported delete_link */
|
||||||
|
/* exported update_fictional_node */
|
||||||
|
/* exported update_node_name */
|
||||||
|
/* exported change_shape */
|
||||||
|
|
||||||
function draw_minimap() {
|
function draw_minimap() {
|
||||||
//Clean the canvas
|
// Clean the canvas.
|
||||||
context_minimap.clearRect(0, 0, minimap_w, minimap_h);
|
context_minimap.clearRect(0, 0, minimap_w, minimap_h);
|
||||||
|
|
||||||
context_minimap.beginPath();
|
context_minimap.beginPath();
|
||||||
@ -20,6 +48,9 @@ function draw_minimap() {
|
|||||||
jQuery.each(graph.nodes, function(key, value) {
|
jQuery.each(graph.nodes, function(key, value) {
|
||||||
if (typeof value == "undefined") return;
|
if (typeof value == "undefined") return;
|
||||||
|
|
||||||
|
var center_orig_x;
|
||||||
|
var center_orig_y;
|
||||||
|
|
||||||
context_minimap.beginPath();
|
context_minimap.beginPath();
|
||||||
//Paint the item
|
//Paint the item
|
||||||
if (graph.nodes.length > 100) {
|
if (graph.nodes.length > 100) {
|
||||||
@ -96,11 +127,11 @@ function inner_minimap_box(param_x, param_y) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
function set_center(id, event) {
|
function set_center(id) {
|
||||||
pos_x = width_svg / 2 - translation[0] / scale;
|
var pos_x = width_svg / 2 - translation[0] / scale;
|
||||||
pos_y = height_svg / 2 - translation[1] / scale;
|
var pos_y = height_svg / 2 - translation[1] / scale;
|
||||||
|
|
||||||
var params = [];
|
var params = [];
|
||||||
|
|
||||||
params.push("set_center=1");
|
params.push("set_center=1");
|
||||||
params.push("id=" + id);
|
params.push("id=" + id);
|
||||||
params.push("x=" + pos_x);
|
params.push("x=" + pos_x);
|
||||||
@ -111,11 +142,7 @@ function set_center(id, event) {
|
|||||||
data: params.join("&"),
|
data: params.join("&"),
|
||||||
dataType: "json",
|
dataType: "json",
|
||||||
type: "POST",
|
type: "POST",
|
||||||
url: (action = "ajax.php"),
|
url: "ajax.php"
|
||||||
success: function(data) {
|
|
||||||
if (data["correct"]) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -164,7 +191,7 @@ function delete_link(
|
|||||||
data: params.join("&"),
|
data: params.join("&"),
|
||||||
dataType: "json",
|
dataType: "json",
|
||||||
type: "POST",
|
type: "POST",
|
||||||
url: (action = "ajax.php"),
|
url: "ajax.php",
|
||||||
success: function(data) {
|
success: function(data) {
|
||||||
if (data["correct"]) {
|
if (data["correct"]) {
|
||||||
var found = -1;
|
var found = -1;
|
||||||
@ -222,7 +249,7 @@ function update_fictional_node(id_db_node) {
|
|||||||
data: params.join("&"),
|
data: params.join("&"),
|
||||||
dataType: "json",
|
dataType: "json",
|
||||||
type: "POST",
|
type: "POST",
|
||||||
url: (action = "ajax.php"),
|
url: "ajax.php",
|
||||||
success: function(data) {
|
success: function(data) {
|
||||||
if (data["correct"]) {
|
if (data["correct"]) {
|
||||||
$("#dialog_node_edit").dialog("close");
|
$("#dialog_node_edit").dialog("close");
|
||||||
@ -262,7 +289,7 @@ function update_node_name(id_db_node) {
|
|||||||
data: params.join("&"),
|
data: params.join("&"),
|
||||||
dataType: "json",
|
dataType: "json",
|
||||||
type: "POST",
|
type: "POST",
|
||||||
url: (action = "ajax.php"),
|
url: "ajax.php",
|
||||||
success: function(data) {
|
success: function(data) {
|
||||||
if (data["correct"]) {
|
if (data["correct"]) {
|
||||||
$("#dialog_node_edit").dialog("close");
|
$("#dialog_node_edit").dialog("close");
|
||||||
@ -308,13 +335,13 @@ function change_shape(id_db_node) {
|
|||||||
data: params.join("&"),
|
data: params.join("&"),
|
||||||
dataType: "json",
|
dataType: "json",
|
||||||
type: "POST",
|
type: "POST",
|
||||||
url: (action = "ajax.php"),
|
url: "ajax.php",
|
||||||
success: function(data) {
|
success: function(data) {
|
||||||
$("#shape_icon_in_progress").css("display", "none");
|
$("#shape_icon_in_progress").css("display", "none");
|
||||||
if (data["correct"]) {
|
if (data["correct"]) {
|
||||||
$("#shape_icon_correct").css("display", "");
|
$("#shape_icon_correct").css("display", "");
|
||||||
|
|
||||||
count = graph.nodes.length;
|
var count = graph.nodes.length;
|
||||||
|
|
||||||
jQuery.each(graph.nodes, function(i, element) {
|
jQuery.each(graph.nodes, function(i, element) {
|
||||||
if (element.id_db == id_db_node) {
|
if (element.id_db == id_db_node) {
|
||||||
@ -364,6 +391,7 @@ function change_shape(id_db_node) {
|
|||||||
return d.y - d.image_height / 2;
|
return d.y - d.image_height / 2;
|
||||||
})
|
})
|
||||||
.attr("width", function(d) {
|
.attr("width", function(d) {
|
||||||
|
console.log(d);
|
||||||
return node_radius / 0.8;
|
return node_radius / 0.8;
|
||||||
})
|
})
|
||||||
.attr("height", function(d) {
|
.attr("height", function(d) {
|
||||||
@ -585,7 +613,7 @@ function update_link(row_index, id_link) {
|
|||||||
data: params.join("&"),
|
data: params.join("&"),
|
||||||
dataType: "json",
|
dataType: "json",
|
||||||
type: "POST",
|
type: "POST",
|
||||||
url: (action = "ajax.php"),
|
url: "ajax.php",
|
||||||
success: function(data) {
|
success: function(data) {
|
||||||
$(".edit_icon_progress_" + row_index).css("display", "none");
|
$(".edit_icon_progress_" + row_index).css("display", "none");
|
||||||
|
|
||||||
@ -607,12 +635,10 @@ function update_link(row_index, id_link) {
|
|||||||
"']"
|
"']"
|
||||||
).prop("selected", true);
|
).prop("selected", true);
|
||||||
|
|
||||||
var id = "";
|
|
||||||
var index = -1;
|
var index = -1;
|
||||||
$.each(graph.links, function(j, link) {
|
$.each(graph.links, function(j, link) {
|
||||||
if (link["id_db"] == id_link) {
|
if (link["id_db"] == id_link) {
|
||||||
index = j;
|
index = j;
|
||||||
id = String(id_link);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -706,7 +732,7 @@ function move_to_networkmap(node) {
|
|||||||
data: params.join("&"),
|
data: params.join("&"),
|
||||||
dataType: "json",
|
dataType: "json",
|
||||||
type: "POST",
|
type: "POST",
|
||||||
url: (action = "ajax.php"),
|
url: "ajax.php",
|
||||||
success: function(data) {
|
success: function(data) {
|
||||||
if (data["correct"]) {
|
if (data["correct"]) {
|
||||||
window.location =
|
window.location =
|
||||||
@ -726,6 +752,7 @@ function edit_node(data_node, dblClick) {
|
|||||||
|
|
||||||
//Only select one node
|
//Only select one node
|
||||||
var selection = d3.selectAll(".node_selected");
|
var selection = d3.selectAll(".node_selected");
|
||||||
|
var id;
|
||||||
|
|
||||||
if (selection[0].length == 1) {
|
if (selection[0].length == 1) {
|
||||||
edit_node = selection[0].pop();
|
edit_node = selection[0].pop();
|
||||||
@ -746,8 +773,8 @@ function edit_node(data_node, dblClick) {
|
|||||||
.select(edit_node)
|
.select(edit_node)
|
||||||
.attr("id")
|
.attr("id")
|
||||||
.replace("id_node_", "");
|
.replace("id_node_", "");
|
||||||
id_networkmap_lenght = networkmap_id.toString().length;
|
var id_networkmap_lenght = networkmap_id.toString().length;
|
||||||
id_node_length = id.length - id_networkmap_lenght;
|
var id_node_length = id.length - id_networkmap_lenght;
|
||||||
id = id.substring(0, id_node_length);
|
id = id.substring(0, id_node_length);
|
||||||
node_selected = graph.nodes[id];
|
node_selected = graph.nodes[id];
|
||||||
|
|
||||||
|
@ -70,8 +70,8 @@ if (enterprise_installed()) {
|
|||||||
$name = (string) get_parameter('name', '');
|
$name = (string) get_parameter('name', '');
|
||||||
|
|
||||||
// Default size values
|
// Default size values
|
||||||
$width = 4000;
|
$width = $config['networkmap_max_width'];
|
||||||
$height = 4000;
|
$height = $config['networkmap_max_width'];
|
||||||
|
|
||||||
$method = (string) get_parameter('method', 'fdp');
|
$method = (string) get_parameter('method', 'fdp');
|
||||||
|
|
||||||
@ -232,8 +232,8 @@ if ($new_networkmap || $save_networkmap) {
|
|||||||
$name = (string) get_parameter('name', '');
|
$name = (string) get_parameter('name', '');
|
||||||
|
|
||||||
// Default size values
|
// Default size values
|
||||||
$width = 4000;
|
$width = $config['networkmap_max_width'];
|
||||||
$height = 4000;
|
$height = $config['networkmap_max_width'];
|
||||||
|
|
||||||
$method = (string) get_parameter('method', 'fdp');
|
$method = (string) get_parameter('method', 'fdp');
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user