Merge branch 'ent-7514-pasar-networkmaps-a-open' into 'develop'

Ent 7514 pasar networkmaps a open

Closes pandora_enterprise#7514

See merge request artica/pandorafms!4416
This commit is contained in:
Daniel Rodriguez 2021-09-24 07:14:14 +00:00
commit 4420ecec2c
12 changed files with 4863 additions and 1862 deletions

View File

@ -106,3 +106,9 @@ enterprise/godmode/alerts/alert_events.php
enterprise/godmode/alerts/alert_events_list.php
enterprise/godmode/alerts/alert_events_rules.php
enterprise/godmode/alerts/configure_alert_rule.php
enterprise/include/functions_networkmap.php
enterprise/operation/agentes/pandora_networkmap.view.php
enterprise/include/ajax/map_enterprise.ajax.php
enterprise/include/javascript/SimpleMapController.js
enterprise/include/javascript/tooltipster.bundle.min.js
enterprise/include/styles/tooltipster.bundle.min.css

View File

@ -0,0 +1,195 @@
<?php
/**
* Empty Network map editor.
*
* @category View
* @package Pandora FMS
* @subpackage Enterprise
* @version 1.0.0
* @license See below
*
* ______ ___ _______ _______ ________
* | __ \.-----.--.--.--| |.-----.----.-----. | ___| | | __|
* | __/| _ | | _ || _ | _| _ | | ___| |__ |
* |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______|
*
* ============================================================================
* Copyright (c) 2005-2021 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;
// Check user credentials
check_login();
$id = (int) get_parameter('id_networkmap', 0);
$new_empty_networkmap = (bool) get_parameter('new_empty_networkmap', false);
$edit_networkmap = (bool) get_parameter('edit_networkmap', false);
$not_found = false;
if (empty($id)) {
$new_empty_networkmap = true;
$edit_networkmap = false;
}
if ($new_empty_networkmap) {
$name = '';
$id_group = 0;
$node_radius = 40;
$description = '';
}
if ($edit_networkmap) {
if (enterprise_installed()) {
$disabled_generation_method_select = true;
}
$disabled_source = true;
$values = db_get_row('tmap', 'id', $id);
$not_found = false;
if ($values === false) {
$not_found = true;
} else {
$id_group = $values['id_group'];
// ACL for the network map
// $networkmap_read = check_acl ($config['id_user'], $id_group, "MR");
$networkmap_write = check_acl($config['id_user'], $id_group, 'MW');
$networkmap_manage = check_acl($config['id_user'], $id_group, 'MM');
if (!$networkmap_write && !$networkmap_manage) {
db_pandora_audit(
'ACL Violation',
'Trying to access networkmap'
);
include 'general/noaccess.php';
return;
}
$name = io_safe_output($values['name']);
$description = $values['description'];
$filter = json_decode($values['filter'], true);
$node_radius = $filter['node_radius'];
}
}
// Header.
ui_print_standard_header(
__('Empty Network maps editor'),
'images/bricks.png',
false,
'network_map_enterprise_edit',
false,
[],
[
[
'link' => '',
'label' => __('Topology maps'),
],
[
'link' => '',
'label' => __('Networkmap'),
],
]
);
if ($not_found) {
ui_print_error_message(__('Not found networkmap.'));
} else {
$table = new StdClass();
$table->id = 'form_editor';
$table->width = '98%';
$table->class = 'databox_color';
$table->head = [];
$table->size = [];
$table->size[0] = '30%';
$table->style = [];
$table->style[0] = 'font-weight: bold; width: 150px;';
$table->data = [];
$table->data[0][0] = __('Name');
$table->data[0][1] = html_print_input_text(
'name',
$name,
'',
30,
100,
true
);
$table->data[1][0] = __('Group');
$table->data[1][1] = '<div class="w250px">'.html_print_select_groups(
false,
'AR',
true,
'id_group',
$id_group,
'',
'',
0,
true
).'</div>';
$table->data[2][0] = __('Node radius');
$table->data[2][1] = html_print_input_text(
'node_radius',
$node_radius,
'',
2,
10,
true
);
$table->data[3][0] = __('Description');
$table->data[3][1] = html_print_textarea('description', 7, 25, $description, '', true);
echo '<form method="post" action="index.php?sec=network&amp;sec2=operation/agentes/pandora_networkmap">';
html_print_table($table);
echo "<div style='width: ".$table->width."; text-align: right; margin-top:20px;'>";
if ($new_empty_networkmap) {
html_print_input_hidden('save_empty_networkmap', 1);
html_print_submit_button(
__('Save networkmap'),
'crt',
false,
'class="sub next"'
);
}
if ($edit_networkmap) {
html_print_input_hidden('id_networkmap', $id);
html_print_input_hidden('update_empty_networkmap', 1);
html_print_submit_button(
__('Update networkmap'),
'crt',
false,
'class="sub upd"'
);
}
echo '</form>';
echo '</div>';
}

View File

@ -1801,7 +1801,7 @@ if ($get_list_events_agents) {
$date_to = get_parameter('date_to');
$time_to = get_parameter('time_to', '23:59:59');
$id_user = $config['id_user'];
hd('hollllaa', true);
$returned_sql = events_sql_events_grouped_agents(
$id_agent,
$server_id,

View File

@ -0,0 +1,102 @@
<?php
// ______ __ _______ _______ _______
// | __ \.---.-.-----.--| |.-----.----.---.-. | ___| | | __|
// | __/| _ | | _ || _ | _| _ | | ___| |__ |
// |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______|
//
// ============================================================================
// Copyright (c) 2007-2021 Artica Soluciones Tecnologicas, http://www.artica.es
// This code is NOT free software. This code is NOT licenced under GPL2 licence
// You cannnot redistribute it without written permission of copyright holder.
// ============================================================================
$networkmap = get_parameter('networkmap', false);
global $config;
require_once $config['homedir'].'/include/class/NetworkMap.class.php';
if ((bool) is_metaconsole() === true) {
$node = get_parameter('node', 0);
if ($node > 0) {
metaconsole_connect(null, $node);
}
}
if ($networkmap) {
$networkmap_id = get_parameter('networkmap_id', 0);
$x_offset = get_parameter('x_offset', 0);
$y_offset = get_parameter('y_offset', 0);
$zoom_dash = get_parameter('zoom_dash', 0.5);
// Dashboard mode.
$ignore_acl = (bool) get_parameter('ignore_acl', 0);
$networkmap = db_get_row_filter('tmap', ['id' => $networkmap_id]);
if ($ignore_acl === false) {
// ACL for the network map.
$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';
if ($node > 0) {
metaconsole_restore_db();
}
return;
}
}
ob_start();
if ($networkmap['generation_method'] == LAYOUT_RADIAL_DYNAMIC) {
$data['name'] = '<a href="index.php?'.'sec=network&'.'sec2=operation/agentes/networkmap.dinamic&'.'activeTab=radial_dynamic&'.'id_networkmap='.$networkmap['id'].'">'.$networkmap['name'].'</a>';
global $id_networkmap;
$id_networkmap = $networkmap['id'];
$tab = 'radial_dynamic';
include_once 'operation/agentes/networkmap.dinamic.php';
} else {
$map = new NetworkMap(
[
'id_map' => $networkmap_id,
'widget' => 1,
'pure' => 1,
'no_popup' => 1,
'map_options' => [
'x_offs' => $x_offset,
'y_offs' => $y_offset,
'z_dash' => $zoom_dash,
],
]
);
$map->printMap(false, $ignore_acl);
}
$return = ob_get_clean();
echo $return;
if ($node > 0) {
metaconsole_restore_db();
}
return;
}
if ($node > 0) {
metaconsole_restore_db();
}

View File

@ -30,7 +30,6 @@
global $config;
require_once $config['homedir'].'/include/functions_networkmap.php';
enterprise_include_once('include/functions_networkmap.php');
enterprise_include_once('include/functions_discovery.php');
// Avoid node overlapping.
@ -723,13 +722,7 @@ class NetworkMap
}
if ($this->idMap !== false) {
if (enterprise_installed()) {
// Enterprise environment: LOAD.
$this->nodes = enterprise_hook(
'get_nodes_from_db',
[$this->idMap]
);
}
$this->nodes = get_nodes_from_db($this->idMap);
}
return $this->nodes;
@ -762,12 +755,7 @@ class NetworkMap
}
if ($this->idMap !== false) {
if (enterprise_installed()) {
$this->relations = enterprise_hook(
'get_relations_from_db',
[$this->idMap]
);
}
$this->relations = get_relations_from_db($this->idMap);
}
return $this->relations;
@ -786,12 +774,9 @@ class NetworkMap
// Calculate.
// Search.
if (enterprise_installed() && $this->idTask) {
if ($this->idTask) {
// Network map, based on discovery task.
return enterprise_hook(
'get_discovery_agents',
[$this->idTask]
);
return get_discovery_agents($this->idTask);
}
if ($this->network) {
@ -1101,18 +1086,14 @@ class NetworkMap
$relations = $this->relations;
// Generate if there's no data in DB about nodes or relations.
if (empty($nodes) && empty($relations)) {
if (empty($nodes) === true && empty($relations) === true) {
$this->generateNetworkMap();
return;
}
$graph = enterprise_hook(
'networkmap_load_map',
[$this]
);
$graph = networkmap_load_map($this);
if ($graph === ENTERPRISE_NOT_HOOK) {
// Method not available, regenerate.
if (empty($graph) === true) {
$this->generateNetworkMap();
return;
}
@ -2607,15 +2588,7 @@ class NetworkMap
// Save data.
if ($this->idMap > 0 && (isset($this->map['__simulated']) === false)) {
if (enterprise_installed()) {
$graph = enterprise_hook(
'save_generate_nodes',
[
$this->idMap,
$graph,
]
);
}
$graph = save_generate_nodes($this->idMap, $graph);
db_process_sql_update(
'tmap',
@ -2733,7 +2706,6 @@ class NetworkMap
$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 networkmap_write = '.$networkmap_write.";\n";
$output .= 'var node_radius = '.$networkmap['filter']['node_radius'].";\n";
$output .= 'var networkmap_holding_area_dimensions = '.json_encode($networkmap['filter']['holding_area']).";\n";
@ -2883,22 +2855,14 @@ class NetworkMap
public function loadAdvancedInterface()
{
$list_networkmaps = get_networkmaps($this->idMap);
if (empty($list_networkmaps)) {
if (empty($list_networkmaps) === true) {
$list_networkmaps = [];
}
$id = 'dialog_node_edit';
if (!enterprise_installed()) {
$id = 'open_version_dialog';
$output = '<div id="open_version" style="display: none" title="'.__('Warning').'">';
$output .= '<div class="center mrgn_top_20px w90p font_13px">'.__(
'In the Open version of %s can not be edited nodes or map',
get_product_name()
);
$output .= '</div></div>';
}
$output .= '<div id="'.$id.'" class="invisible" title="';
$output = '<div id="'.$id.'" class="invisible" title="';
$output .= __('Edit node').'">';
$output .= '<div class="left w100p">';
@ -3017,16 +2981,14 @@ class NetworkMap
true
);
if (enterprise_installed()) {
$output .= ui_toggle(
html_print_table($table, true),
__('Node options'),
__('Node options'),
'',
true,
true
);
}
$output .= ui_toggle(
html_print_table($table, true),
__('Node options'),
__('Node options'),
'',
true,
true
);
$table = new StdClass();
$table->id = 'relations_table';
@ -3109,16 +3071,14 @@ class NetworkMap
true
);
if (enterprise_installed()) {
$output .= ui_toggle(
html_print_table($table, true),
__('Relations'),
__('Relations'),
'',
true,
true
);
}
$output .= ui_toggle(
html_print_table($table, true),
__('Relations'),
__('Relations'),
'',
true,
true
);
$output .= '</div></div>';
@ -3340,8 +3300,7 @@ class NetworkMap
{
$output = '';
if (enterprise_installed()
&& $this->useTooltipster
if ($this->useTooltipster
) {
$output .= '<script type="text/javascript">
$(function() {
@ -3376,7 +3335,7 @@ class NetworkMap
graph: networkmap,
networkmap_center: networkmap_center,
networkmap_dimensions: networkmap_dimensions,
enterprise_installed: enterprise_installed,
enterprise_installed: 1,
node_radius: node_radius,
holding_area_dimensions: networkmap_holding_area_dimensions,
url_background_grid: url_background_grid,
@ -3419,18 +3378,17 @@ class NetworkMap
{
global $config;
if (enterprise_installed()
&& isset($this->useTooltipster)
&& $this->useTooltipster == true
if (isset($this->useTooltipster) === true
&& (bool) $this->useTooltipster === true
) {
$output = '<script type="text/javascript" src="'.ui_get_full_url(
'include/javascript/d3.3.5.14.js'
).'" charset="utf-8"></script>';
$output .= '<script type="text/javascript" src="'.ui_get_full_url(
'enterprise/include/javascript/SimpleMapController.js'
'include/javascript/SimpleMapController.js'
).'"></script>';
$output .= '<script type="text/javascript" src="'.ui_get_full_url(
'enterprise/include/javascript/tooltipster.bundle.min.js'
'include/javascript/tooltipster.bundle.min.js'
).'"></script>';
$output .= '<script type="text/javascript" src="'.ui_get_full_url(
'include/javascript/jquery.svg.js'
@ -3439,7 +3397,7 @@ class NetworkMap
'include/javascript/jquery.svgdom.js'
).'"></script>';
$output .= '<link rel="stylesheet" type="text/css" href="'.ui_get_full_url(
'/enterprise/include/styles/tooltipster.bundle.min.css'
'include/styles/tooltipster.bundle.min.css'
).'" />'."\n";
$output .= '<div id="simple_map" data-id="'.$this->idMap.'" ';

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,459 @@
// Pandora FMS - http://pandorafms.com
// ==================================================
// Copyright (c) 2005-2021 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 Lesser General Public License
// as published by the Free Software Foundation; 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.
/* globals d3 */
/* globals jQuery */
/* globals $ */
/*-----------------------------------------------*/
/*-------------------Constants-------------------*/
/*-----------------------------------------------*/
var MAX_ZOOM_LEVEL = 5;
/*-----------------------------------------------*/
/*------------------Constructor------------------*/
/*-----------------------------------------------*/
var SimpleMapController = function(params) {
if (!params) {
console.log("[SimpleMapController]: No params received");
return this;
}
this._target = params["target"];
if (typeof params["map_width"] == "undefined") {
this.map_width = 0;
} else {
this.map_width = params["map_width"];
}
if (typeof params["map_height"] == "undefined") {
this.map_height = 0;
} else {
this.map_height = params["map_height"];
}
if (typeof params["font_size"] == "undefined") {
this.font_size = 20;
} else {
this.font_size = params["font_size"];
}
if (typeof params["homedir"] == "undefined") {
this.homedir = "";
} else {
this.homedir = params["homedir"];
}
if (typeof params["custom_params"] == "undefined") {
this.custom_params = "";
} else {
this.custom_params = params["custom_params"];
}
if (typeof params["center_x"] == "undefined") {
this.center_x = 0;
} else {
this.center_x = params["center_x"];
}
if (typeof params["center_y"] == "undefined") {
this.center_y = 0;
} else {
this.center_y = params["center_y"];
}
if (typeof params["z_dash"] == "undefined") {
this.z_dash = 0.5;
} else {
this.z_dash = params["z_dash"];
}
if (typeof params["nodes"] == "undefined") {
this.nodes = [];
} else {
this.nodes = params["nodes"];
}
if (typeof params["arrows"] == "undefined") {
this.arrows = [];
} else {
this.arrows = params["arrows"];
}
var factor = $(this._target).width() / $(this._target).height();
// Center is about complete SVG map not only central node.
// Calculus is to leave same space on left-right (width)
// and top-bottom (height).
this.center_x = ($(this._target).width() - this.map_width * factor) / 2;
this.center_y = ($(this._target).height() - this.map_height * factor) / 2;
};
/*-----------------------------------------------*/
/*------------------Atributes--------------------*/
/*-----------------------------------------------*/
SimpleMapController.prototype._viewport = null;
SimpleMapController.prototype._zoomManager = null;
/*-----------------------------------------------*/
/*--------------------Methods--------------------*/
/*-----------------------------------------------*/
/**
* Function init_trans_map
* Return void
* This function init the transactional map
*/
SimpleMapController.prototype.init_map = function() {
var self = this;
var svg = d3.select(self._target + " svg");
self._zoomManager = d3.behavior
.zoom()
.scale(self.z_dash)
.scaleExtent([1 / MAX_ZOOM_LEVEL, MAX_ZOOM_LEVEL])
.on("zoom", zoom);
self._viewport = svg
.call(self._zoomManager)
.append("g")
.attr("class", "viewport")
.attr("transform", "translate(0, 0) scale(" + self.z_dash + ")");
self._slider = d3
.select(self._target + " .zoom_controller .vertical_range")
.property("value", 0)
.property("min", -Math.log(MAX_ZOOM_LEVEL))
.property("max", Math.log(MAX_ZOOM_LEVEL))
.property("step", (Math.log(MAX_ZOOM_LEVEL) * 2) / MAX_ZOOM_LEVEL)
.on("input", slided);
/**
* Function zoom
* Return void
* This function manages the zoom
*/
function zoom() {
self.last_event = "zoom";
var zoom_level = d3.event.scale;
self._slider.property("value", Math.log(zoom_level));
self._viewport.attr(
"transform",
"translate(" + d3.event.translate + ") scale(" + zoom_level + ")"
);
}
/**
* Function slided
* Return void
* This function manages the slide (zoom system)
*/
function slided() {
var slider_value = parseFloat(self._slider.property("value"));
var zoom_level = Math.exp(slider_value);
/*----------------------------------------------------------------*/
/*-Code to translate the map with the zoom for to hold the center-*/
/*----------------------------------------------------------------*/
var center = [
parseFloat(d3.select(self._target).style("width")) / 2,
parseFloat(d3.select(self._target).style("height")) / 2
];
var old_translate = self._zoomManager.translate();
var old_scale = self._zoomManager.scale();
var temp1 = [
(center[0] - old_translate[0]) / old_scale,
(center[1] - old_translate[1]) / old_scale
];
var temp2 = [
temp1[0] * zoom_level + old_translate[0],
temp1[1] * zoom_level + old_translate[1]
];
var new_translation = [
old_translate[0] + center[0] - temp2[0],
old_translate[1] + center[1] - temp2[1]
];
self._zoomManager
.scale(zoom_level)
.translate(new_translation)
.event(self._viewport);
}
self.paint_arrows();
self.paint_nodes();
};
SimpleMapController.prototype.paint_nodes = function() {
var self = this;
if (self.nodes != null) {
// Initialize objects.
var circle_elem = self._viewport
.selectAll(".node")
.data(self.nodes)
.enter()
.append("g")
.attr("id", function(d) {
return "node_" + d["id"];
})
.attr("transform", function(d) {
return "translate(" + d["x"] + ", " + d["y"] + ")";
})
.attr("class", "draggable node")
.attr("image", function(d) {
return d["image"];
})
.attr("style", function(d) {
return (
"fill: " + d["color"] + "; " + "stroke: " + d["stroke-color"] + ";"
);
})
.attr("stroke-width", function(d) {
return d["stroke-width"];
})
.style("cursor", function(d) {
if (d["id"] === "0") {
return "default";
} else {
return "pointer";
}
});
// Node size in map.
circle_elem
.append("circle")
.attr("cx", self.center_x)
.attr("cy", function(d) {
return self.center_y + d["radius"];
})
.attr("r", function(d) {
return d["radius"];
});
circle_elem.each(function(node, index) {
if (Array.isArray(node["label"])) {
node["label"].forEach(function(value, index2) {
d3.selectAll("#node_" + index)
.append("text")
.attr("dx", function(d) {
if (typeof d["label_x_offset"] == "undefined") {
d["label_x_offset"] = 0;
}
return self.center_x + d["label_x_offset"];
})
.attr("dy", function(d) {
if (typeof d["font_size"] == "undefined") {
d["font_size"] = self.font_size;
}
if (typeof d["label_y_offset"] == "undefined") {
d["label_y_offset"] = d["radius"] + d["font_size"];
}
return (
self.center_y +
d["radius"] +
d["label_y_offset"] +
index2 * d["font_size"]
);
})
.style("text-anchor", "middle")
.style("font-size", function(d) {
if (typeof d["font_size"] == "undefined") {
d["font_size"] = self.font_size;
}
return d["font_size"] + "px";
})
.style("stroke-width", 0)
.attr("fill", "black")
.text(value);
});
} else {
circle_elem
.append("text")
.attr("dx", function(d) {
if (typeof d["label_x_offset"] == "undefined") {
d["label_x_offset"] = 0;
}
return self.center_x + d["label_x_offset"];
})
.attr("dy", function(d) {
if (typeof d["font_size"] == "undefined") {
d["font_size"] = self.font_size;
}
if (typeof d["label_y_offset"] == "undefined") {
d["label_y_offset"] = d["radius"] + d["font_size"];
}
return self.center_y + d["radius"] + d["label_y_offset"];
})
.style("text-anchor", "middle")
.style("font-size", function(d) {
if (typeof d["font_size"] == "undefined") {
d["font_size"] = self.font_size;
}
return d["font_size"] + "px";
})
.style("stroke-width", 0)
.attr("fill", "black")
.text(function(d) {
return d["label"];
});
}
});
}
// Node image.
circle_elem
.append("svg:image")
.attr("class", "node_image")
.attr("xlink:href", function(d) {
return d["image"];
})
.attr("x", function(d) {
if (typeof d["size_image"] != "undefined") {
return self.center_x - d["size_image"] / 2;
} else {
return self.center_x - 52 / 2;
}
})
.attr("y", function(d) {
if (typeof size_image != "undefined") {
return self.center_y + d["radius"] - d["size_image"] / 2;
} else {
return self.center_y + d["radius"] - 52 / 2;
}
})
.attr("width", function(d) {
return d["image_width"];
})
.attr("height", function(d) {
return d["image_height"];
});
// Tooltipster. This could be dynamic.
self.nodes.forEach(function(node) {
if (node["id_agent"] != 0) {
$("#node_" + node["id"]).tooltipster({
contentAsHTML: true,
onlyOne: true,
updateAnimation: null,
interactive: true,
trigger: "click",
content: $('<img src="' + self.homedir + '/images/spinner.gif"/>'),
functionReady: function() {
$("#node_" + node["id"]).tooltipster("open");
$(".tooltipster-content").css("background", "#FFF");
$(".tooltipster-content").css("color", "#000");
var params = self.custom_params;
// Add data node click.
params.node_data = node;
params["id_agent"] = node["id_agent"];
jQuery.ajax({
data: params,
dataType: "html",
type: "POST",
url: self.homedir + "/ajax.php",
success: function(data) {
$(".tooltipster-content").css("min-height", "330px");
$(".tooltipster-content").css("max-height", "500px");
$("#node_" + node["id"]).tooltipster("content", data);
}
});
}
});
}
});
};
SimpleMapController.prototype.paint_arrows = function() {
var self = this;
if (self.arrows != null) {
self._viewport
.selectAll(".arrow")
.data(self.arrows)
.enter()
.append("g")
.attr("class", "arrow")
.attr("to", function(d) {
return d["dest"];
})
.attr("from", function(d) {
return d["orig"];
})
.attr("style", "fill: rgb(50, 50, 128);")
.append("line")
.attr("stroke", "#373737")
.attr("stroke-width", 3)
.attr("x1", function(d) {
return self.center_x + self.getFirstPoint(d["orig"], "x");
})
.attr("y1", function(d) {
return self.center_y + self.getFirstPoint(d["orig"], "y");
})
.attr("x2", function(d) {
return self.center_x + self.getSecondPoint(d["dest"], "x");
})
.attr("y2", function(d) {
return self.center_y + self.getSecondPoint(d["dest"], "y");
});
}
};
SimpleMapController.prototype.getFirstPoint = function(orig, coord) {
var self = this;
var point = 0;
self.nodes.forEach(function(node) {
if (node["id"] === orig) {
if (coord == "x") {
point = parseFloat(node["x"]);
return;
} else {
point = parseFloat(node["y"]) + node["radius"];
return;
}
}
});
return point;
};
SimpleMapController.prototype.getSecondPoint = function(dest, coord) {
var self = this;
var point = 0;
self.nodes.forEach(function(node) {
if (node["id"] === dest) {
if (coord == "x") {
point = parseFloat(node["x"]);
return;
} else {
point = parseFloat(node["y"]) + node["radius"];
return;
}
}
});
return point;
};

File diff suppressed because one or more lines are too long

View File

@ -285,7 +285,6 @@ class NetworkMapWidget extends Widget
null,
null,
true,
false,
$return_all_group
);
@ -438,7 +437,7 @@ class NetworkMapWidget extends Widget
$settings = \json_encode(
[
'cellId' => $this->cellId,
'page' => 'enterprise/include/ajax/map_enterprise.ajax',
'page' => 'include/ajax/map_enterprise.ajax',
'url' => ui_get_full_url('ajax.php'),
'networkmap_id' => $id_networkmap,
'x_offset' => $x_offset,

File diff suppressed because one or more lines are too long

View File

@ -31,13 +31,14 @@ global $config;
// Check user credentials.
check_login();
// error_reporting(E_ALL);
// ini_set("display_errors", 1);
// General ACL for the network maps.
$networkmaps_read = check_acl($config['id_user'], 0, 'MR');
$networkmaps_write = check_acl($config['id_user'], 0, 'MW');
$networkmaps_manage = check_acl($config['id_user'], 0, 'MM');
$networkmaps_read = (bool) check_acl($config['id_user'], 0, 'MR');
$networkmaps_write = (bool) check_acl($config['id_user'], 0, 'MW');
$networkmaps_manage = (bool) check_acl($config['id_user'], 0, 'MM');
if (!$networkmaps_read && !$networkmaps_write && !$networkmaps_manage) {
if ($networkmaps_read === false && $networkmaps_write === false && $networkmaps_manage === false) {
db_pandora_audit(
'ACL Violation',
'Trying to access networkmap'
@ -48,179 +49,174 @@ if (!$networkmaps_read && !$networkmaps_write && !$networkmaps_manage) {
require_once 'include/functions_networkmap.php';
$new_networkmap = (bool) get_parameter('new_networkmap', false);
$save_networkmap = (bool) get_parameter('save_networkmap', false);
$save_empty_networkmap = (bool) get_parameter('save_empty_networkmap', false);
$new_networkmap = (bool) get_parameter('new_networkmap', false);
$save_networkmap = (bool) get_parameter('save_networkmap', false);
$save_empty_networkmap = (bool) get_parameter('save_empty_networkmap', false);
$update_empty_networkmap = (bool) get_parameter('update_empty_networkmap', false);
$update_networkmap = (bool) get_parameter('update_networkmap', false);
$copy_networkmap = (bool) get_parameter('copy_networkmap', false);
$delete = (bool) get_parameter('delete', false);
$tab = (string) get_parameter('tab', 'list');
$new_empty_networkmap = get_parameter('new_empty_networkmap', false);
$update_networkmap = (bool) get_parameter('update_networkmap', false);
$copy_networkmap = (bool) get_parameter('copy_networkmap', false);
$delete = (bool) get_parameter('delete', false);
$tab = (string) get_parameter('tab', 'list');
$new_empty_networkmap = (bool) get_parameter('new_empty_networkmap', false);
if (enterprise_installed()) {
if ($new_empty_networkmap) {
if ($networkmaps_write || $networkmaps_manage) {
enterprise_include(
'godmode/agentes/pandora_networkmap_empty.editor.php'
);
return;
}
if ($new_empty_networkmap === true) {
if ($networkmaps_write === true || $networkmaps_manage === true) {
include_once 'godmode/agentes/pandora_networkmap_empty.editor.php';
return;
}
}
if ($save_empty_networkmap === true) {
$id_group = (int) get_parameter('id_group', 0);
$id_group_map = (int) get_parameter('id_group_map', 0);
// ACL for the network map.
$networkmap_write = (bool) check_acl_restricted_all($config['id_user'], $id_group_map, 'MW');
$networkmap_manage = (bool) check_acl_restricted_all($config['id_user'], $id_group_map, 'MM');
if ($networkmap_write === false && $networkmap_manage === false) {
db_pandora_audit(
'ACL Violation',
'Trying to access networkmap'
);
include 'general/noaccess.php';
return;
}
if ($save_empty_networkmap) {
$id_group = (int) get_parameter('id_group', 0);
$id_group_map = (int) get_parameter('id_group_map', 0);
$name = (string) get_parameter('name', '');
// ACL for the network map.
// $networkmap_read = check_acl ($config['id_user'], $id_group, "MR");
$networkmap_write = check_acl_restricted_all($config['id_user'], $id_group_map, 'MW');
$networkmap_manage = check_acl_restricted_all($config['id_user'], $id_group_map, 'MM');
// Default size values.
$width = $config['networkmap_max_width'];
$height = $config['networkmap_max_width'];
if (!$networkmap_write && !$networkmap_manage) {
db_pandora_audit(
'ACL Violation',
'Trying to access networkmap'
);
include 'general/noaccess.php';
return;
}
$method = (string) get_parameter('method', 'fdp');
$name = (string) get_parameter('name', '');
$dont_show_subgroups = (int) get_parameter_checkbox(
'dont_show_subgroups',
0
);
$node_radius = (int) get_parameter('node_radius', 40);
$description = get_parameter('description', '');
// Default size values
$width = $config['networkmap_max_width'];
$height = $config['networkmap_max_width'];
$values = [];
$values['name'] = $name;
$values['id_group'] = $id_group;
$values['source_period'] = 60;
$values['width'] = $width;
$values['height'] = $height;
$values['id_user'] = $config['id_user'];
$values['description'] = $description;
$values['source'] = 0;
$values['source_data'] = $id_group;
$values['id_group_map'] = $id_group_map;
$method = (string) get_parameter('method', 'fdp');
$dont_show_subgroups = (int) get_parameter_checkbox(
'dont_show_subgroups',
0
if (!$networkmap_write && !$networkmap_manage) {
db_pandora_audit(
'ACL Violation',
'Trying to access networkmap'
);
$node_radius = (int) get_parameter('node_radius', 40);
$description = get_parameter('description', '');
include 'general/noaccess.php';
return;
}
$values = [];
$values['name'] = $name;
$values['id_group'] = $id_group;
$values['source_period'] = 60;
$values['width'] = $width;
$values['height'] = $height;
$values['id_user'] = $config['id_user'];
$values['description'] = $description;
$values['source'] = 0;
$values['source_data'] = $id_group;
$values['id_group_map'] = $id_group_map;
$filter = [];
$filter['dont_show_subgroups'] = $dont_show_subgroups;
$filter['node_radius'] = $node_radius;
$filter['empty_map'] = 1;
$values['filter'] = json_encode($filter);
if (!$networkmap_write && !$networkmap_manage) {
db_pandora_audit(
'ACL Violation',
'Trying to access networkmap'
);
include 'general/noaccess.php';
return;
}
$filter = [];
$filter['dont_show_subgroups'] = $dont_show_subgroups;
$filter['node_radius'] = $node_radius;
$filter['empty_map'] = 1;
$values['filter'] = json_encode($filter);
$result = false;
if (!empty($name)) {
$result = db_process_sql_insert(
'tmap',
$values
);
}
$result_txt = ui_print_result_message(
$result,
__('Succesfully created'),
__('Could not be created'),
'',
true
);
$id = $result;
define('_id_', $id);
if ($result !== false) {
$tab = 'view';
header(
'Location: '.ui_get_full_url(
'index.php?sec=network&sec2=operation/agentes/pandora_networkmap&tab='.$tab.'&id_networkmap='.$id
)
);
}
} else if ($update_empty_networkmap) {
$id_group = (int) get_parameter('id_group', 0);
$id_group_map = (int) get_parameter('id_group_map', 0);
// ACL for the new network map
$networkmap_write_new = check_acl_restricted_all($config['id_user'], $id_group_map, 'MW');
$networkmap_manage_new = check_acl_restricted_all($config['id_user'], $id_group_map, 'MM');
if (!$networkmap_write && !$networkmap_manage) {
db_pandora_audit(
'ACL Violation',
'Trying to access networkmap'
);
include 'general/noaccess.php';
return;
}
$name = (string) get_parameter('name', '');
$recon_task_id = (int) get_parameter(
'recon_task_id',
0
);
$source = (string) get_parameter('source', 'group');
$values = [];
$values['name'] = $name;
$values['id_group'] = $id_group;
$values['generation_method'] = 4;
$description = get_parameter('description', '');
$values['description'] = $description;
$dont_show_subgroups = (int) get_parameter_checkbox(
'dont_show_subgroups',
0
);
$node_radius = (int) get_parameter('node_radius', 40);
$row = db_get_row('tmap', 'id', $id);
$filter = json_decode($row['filter'], true);
$filter['dont_show_subgroups'] = $dont_show_subgroups;
$filter['node_radius'] = $node_radius;
$values['filter'] = json_encode($filter);
$result = false;
if (!empty($name)) {
$result = db_process_sql_update(
'tmap',
$values,
['id' => $id]
);
}
$result_txt = ui_print_result_message(
$result,
__('Succesfully updated'),
__('Could not be updated'),
'',
true
$result = false;
if (!empty($name)) {
$result = db_process_sql_insert(
'tmap',
$values
);
}
$result_txt = ui_print_result_message(
$result,
__('Succesfully created'),
__('Could not be created'),
'',
true
);
$id = $result;
define('_id_', $id);
if ($result !== false) {
$tab = 'view';
header(
'Location: '.ui_get_full_url(
'index.php?sec=network&sec2=operation/agentes/pandora_networkmap&tab='.$tab.'&id_networkmap='.$id
)
);
}
} else if ($update_empty_networkmap) {
$id_group = (int) get_parameter('id_group', 0);
$id_group_map = (int) get_parameter('id_group_map', 0);
// ACL for the new network map
$networkmap_write_new = (bool) check_acl_restricted_all($config['id_user'], $id_group_map, 'MW');
$networkmap_manage_new = (bool) check_acl_restricted_all($config['id_user'], $id_group_map, 'MM');
if (!$networkmap_write && !$networkmap_manage) {
db_pandora_audit(
'ACL Violation',
'Trying to access networkmap'
);
include 'general/noaccess.php';
return;
}
$name = (string) get_parameter('name', '');
$recon_task_id = (int) get_parameter(
'recon_task_id',
0
);
$source = (string) get_parameter('source', 'group');
$values = [];
$values['name'] = $name;
$values['id_group'] = $id_group;
$values['generation_method'] = 4;
$description = get_parameter('description', '');
$values['description'] = $description;
$dont_show_subgroups = (int) get_parameter_checkbox(
'dont_show_subgroups',
0
);
$node_radius = (int) get_parameter('node_radius', 40);
$row = db_get_row('tmap', 'id', $id);
$filter = json_decode($row['filter'], true);
$filter['dont_show_subgroups'] = $dont_show_subgroups;
$filter['node_radius'] = $node_radius;
$values['filter'] = json_encode($filter);
$result = false;
if (empty($name) === false) {
$result = db_process_sql_update(
'tmap',
$values,
['id' => $id]
);
}
$result_txt = ui_print_result_message(
$result,
__('Succesfully updated'),
__('Could not be updated'),
'',
true
);
}
// The networkmap doesn't exist yet
@ -245,12 +241,11 @@ if ($new_networkmap || $save_networkmap) {
$id_group_map = (int) get_parameter('id_group_map', 0);
// ACL for the network map
// $networkmap_read = check_acl ($config['id_user'], $id_group, "MR");
$networkmap_write = check_acl_restricted_all($config['id_user'], $id_group_map, 'MW');
$networkmap_manage = check_acl_restricted_all($config['id_user'], $id_group_map, 'MM');
// ACL for the network map.
$networkmap_write = (bool) check_acl_restricted_all($config['id_user'], $id_group_map, 'MW');
$networkmap_manage = (bool) check_acl_restricted_all($config['id_user'], $id_group_map, 'MM');
if (!$networkmap_write && !$networkmap_manage) {
if ($networkmap_write === false && $networkmap_manage === false) {
db_pandora_audit(
'ACL Violation',
'Trying to access networkmap'
@ -259,9 +254,9 @@ if ($new_networkmap || $save_networkmap) {
return;
}
$name = (string) get_parameter('name', '');
$name = (string) get_parameter('name');
// Default size values
// Default size values.
$width = $config['networkmap_max_width'];
$height = $config['networkmap_max_width'];
@ -288,11 +283,7 @@ if ($new_networkmap || $save_networkmap) {
$scale_z = get_parameter('scale_z', 0.5);
$node_sep = get_parameter('node_sep', '0.25');
if ($method == 'twopi') {
$rank_sep = get_parameter('rank_sep', '1.0');
} else {
$rank_sep = get_parameter('rank_sep', '0.5');
}
$rank_sep = get_parameter('rank_sep', ($method === 'twopi') ? '1.0' : '0.5');
$mindist = get_parameter('mindist', '1.0');
$kval = get_parameter('kval', '0.3');
@ -348,7 +339,7 @@ if ($new_networkmap || $save_networkmap) {
$values['source_data'] = $ip_mask;
}
if (!$networkmap_write && !$networkmap_manage) {
if ($networkmap_write === false && $networkmap_manage === false) {
db_pandora_audit(
'ACL Violation',
'Trying to access networkmap'
@ -437,10 +428,10 @@ else if ($update_networkmap || $copy_networkmap || $delete) {
return;
}
$networkmap_write = check_acl_restricted_all($config['id_user'], $id_group_map_old, 'MW');
$networkmap_manage = check_acl_restricted_all($config['id_user'], $id_group_map_old, 'MM');
$networkmap_write = (bool) check_acl_restricted_all($config['id_user'], $id_group_map_old, 'MW');
$networkmap_manage = (bool) check_acl_restricted_all($config['id_user'], $id_group_map_old, 'MM');
if (!$networkmap_write && !$networkmap_manage) {
if ($networkmap_write === false && $networkmap_manage === false) {
db_pandora_audit(
'ACL Violation',
'Trying to access networkmap'
@ -455,12 +446,12 @@ else if ($update_networkmap || $copy_networkmap || $delete) {
$id_group_old = db_get_value('id_group', 'tmap', 'id', $id);
// ACL for the new network map
$id_group_map = (int) get_parameter('id_group_map', 0);
$networkmap_write_new = check_acl_restricted_all($config['id_user'], $id_group_map, 'MW');
$networkmap_manage_new = check_acl_restricted_all($config['id_user'], $id_group_map, 'MM');
// ACL for the new network map.
$id_group_map = (int) get_parameter('id_group_map', 0);
$networkmap_write_new = (bool) check_acl_restricted_all($config['id_user'], $id_group_map, 'MW');
$networkmap_manage_new = (bool) check_acl_restricted_all($config['id_user'], $id_group_map, 'MM');
if (!$networkmap_write && !$networkmap_manage) {
if ($networkmap_write === false && $networkmap_manage === false) {
db_pandora_audit(
'ACL Violation',
'Trying to access networkmap'
@ -503,7 +494,7 @@ else if ($update_networkmap || $copy_networkmap || $delete) {
$values['filter'] = json_encode($filter);
$result = false;
if (!empty($name)) {
if (empty($name) === false) {
$result = db_process_sql_update(
'tmap',
$values,
@ -577,11 +568,9 @@ switch ($tab) {
$old_networkmaps_enterprise = [];
$old_networkmaps_open = [];
if (enterprise_installed()) {
$old_networkmaps_enterprise = db_get_all_rows_sql('SELECT * FROM tnetworkmap_enterprise');
if ($old_networkmaps_enterprise === false) {
$old_networkmaps_enterprise = [];
}
$old_networkmaps_enterprise = db_get_all_rows_sql('SELECT * FROM tnetworkmap_enterprise');
if ($old_networkmaps_enterprise === false) {
$old_networkmaps_enterprise = [];
}
$old_networkmaps_open = db_get_all_rows_sql('SELECT * FROM tnetwork_map');
@ -590,13 +579,13 @@ switch ($tab) {
foreach ($old_networkmaps_enterprise as $old_map_ent) {
$old_map_options = json_decode($old_map_ent['options'], true);
if (!isset($old_map_options['migrated'])) {
if (isset($old_map_options['migrated']) === false) {
$ent_maps_to_migrate[] = $old_map_ent['id'];
}
}
$open_maps_to_migrate = [];
if (isset($old_networkmaps_open) && is_array($old_networkmaps_open)) {
if (isset($old_networkmaps_open) === true && is_array($old_networkmaps_open) === true) {
foreach ($old_networkmaps_open as $old_map_open) {
$text_filter = $old_map_open['text_filter'];
if ($text_filter != 'migrated') {
@ -605,7 +594,7 @@ switch ($tab) {
}
}
if (!empty($ent_maps_to_migrate) || !empty($open_maps_to_migrate)) {
if (empty($ent_maps_to_migrate) === false || empty($open_maps_to_migrate) === false) {
?>
<div id="migration_dialog" class="center">
<p class="center"><strong>Networkmaps are not migrated, wait while migration is processed...</strong></p>
@ -694,12 +683,10 @@ switch ($tab) {
$table->style = [];
$table->style['name'] = '';
if (enterprise_installed()) {
$table->style['nodes'] = 'text-align: center;';
}
$table->style['nodes'] = 'text-align: center;';
$table->style['groups'] = 'text-align: left;';
if ($networkmaps_write || $networkmaps_manage) {
if ($networkmaps_write === true || $networkmaps_manage === true) {
$table->style['copy'] = 'text-align: center;';
$table->style['edit'] = 'text-align: center;';
$table->style['delete'] = 'text-align: center;';
@ -707,12 +694,10 @@ switch ($tab) {
$table->size = [];
$table->size['name'] = '60%';
if (enterprise_installed()) {
$table->size['nodes'] = '30px';
}
$table->size['nodes'] = '30px';
$table->size['groups'] = '400px';
if ($networkmaps_write || $networkmaps_manage) {
if ($networkmaps_write === true || $networkmaps_manage === true) {
$table->size['copy'] = '30px';
$table->size['edit'] = '30px';
$table->size['delete'] = '30px';
@ -720,12 +705,10 @@ switch ($tab) {
$table->head = [];
$table->head['name'] = __('Name');
if (enterprise_installed()) {
$table->head['nodes'] = __('Nodes');
}
$table->head['nodes'] = __('Nodes');
$table->head['groups'] = __('Groups');
if ($networkmaps_write || $networkmaps_manage) {
if ($networkmaps_write === true || $networkmaps_manage === true) {
$table->head['copy'] = __('Copy');
$table->head['edit'] = __('Edit');
$table->head['delete'] = __('Delete');
@ -755,19 +738,10 @@ switch ($tab) {
$table->data = [];
foreach ($network_maps as $network_map) {
// ACL for the network map
$networkmap_read = check_acl_restricted_all($config['id_user'], $network_map['id_group_map'], 'MR');
$networkmap_write = check_acl_restricted_all($config['id_user'], $network_map['id_group_map'], 'MW');
$networkmap_manage = check_acl_restricted_all($config['id_user'], $network_map['id_group_map'], 'MM');
if (!$networkmap_read && !$networkmap_write && !$networkmap_manage) {
db_pandora_audit(
'ACL Violation',
'Trying to access networkmap enterprise'
);
include 'general/noaccess.php';
continue;
}
// ACL for the network map.
$networkmap_read = (bool) check_acl_restricted_all($config['id_user'], $network_map['id_group_map'], 'MR');
$networkmap_write = (bool) check_acl_restricted_all($config['id_user'], $network_map['id_group_map'], 'MW');
$networkmap_manage = (bool) check_acl_restricted_all($config['id_user'], $network_map['id_group_map'], 'MM');
$data = [];
if ($network_map['generation_method'] == 6) {
@ -797,19 +771,17 @@ switch ($tab) {
$count = 0;
}
if (enterprise_installed()) {
if (($count == 0) && ($network_map['source'] != 'empty')) {
if ($network_map['generated']) {
$data['nodes'] = __('Empty map');
} else if ($network_map['generation_method'] == LAYOUT_RADIAL_DYNAMIC) {
$data['nodes'] = __('Dynamic');
} else {
$data['nodes'] = __('Pending to generate');
}
if (($count == 0) && ($network_map['source'] != 'empty')) {
if ($network_map['generated']) {
$data['nodes'] = __('Empty map');
} else if ($network_map['generation_method'] == LAYOUT_RADIAL_DYNAMIC) {
$data['nodes'] = __('Dynamic');
} else {
$data['nodes'] = ($network_map['id_group'] == 0) ? ($count - 1) : $count;
// PandoraFMS node is not an agent
$data['nodes'] = __('Pending to generate');
}
} else {
$data['nodes'] = ($network_map['id_group'] == 0) ? ($count - 1) : $count;
// PandoraFMS node is not an agent
}
$data['groups'] = ui_print_group_icon($network_map['id_group_map'], true);
@ -847,14 +819,12 @@ switch ($tab) {
echo '</form>';
echo '</div>';
if (enterprise_installed()) {
echo "<div style='width: ".$table->width."; margin-top: 5px;'>";
echo '<form method="post" action="index.php?sec=network&amp;sec2=operation/agentes/pandora_networkmap">';
html_print_input_hidden('new_empty_networkmap', 1);
html_print_submit_button(__('Create empty network map'), 'crt', false, 'class="sub next float-right mrgn_right_20px"');
echo '</form>';
echo '</div>';
}
echo "<div style='width: ".$table->width."; margin-top: 5px;'>";
echo '<form method="post" action="index.php?sec=network&amp;sec2=operation/agentes/pandora_networkmap">';
html_print_input_hidden('new_empty_networkmap', 1);
html_print_submit_button(__('Create empty network map'), 'crt', false, 'class="sub next float-right mrgn_right_20px"');
echo '</form>';
echo '</div>';
}
break;
}