mirror of
https://github.com/pandorafms/pandorafms.git
synced 2025-07-28 16:24:54 +02:00
WIP: Unified class NetworkMapClass
Former-commit-id: 6e6f4afb70be008602f51dfbd383bb855613e084
This commit is contained in:
parent
00283a5c6a
commit
3e39e727b6
201
pandora_console/include/class/NetworkMap.class.php
Normal file
201
pandora_console/include/class/NetworkMap.class.php
Normal file
@ -0,0 +1,201 @@
|
|||||||
|
<?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;
|
||||||
|
|
||||||
|
require_once $config['homedir'].'/include/functions_pandora_networkmap.php';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Manage networkmaps in Pandora FMS
|
||||||
|
*/
|
||||||
|
class NetworkMap
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Target map Id.
|
||||||
|
*
|
||||||
|
* @var integer
|
||||||
|
*/
|
||||||
|
public $idMap;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Graph definition
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
public $graph;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
* @param array $options Could define:
|
||||||
|
* id_map => target map to be painted.
|
||||||
|
* graph => target graph (already built)
|
||||||
|
* nodes => target agents or nodes.
|
||||||
|
* relations => target array of relationships.
|
||||||
|
* mode => simple (0) or advanced (1)
|
||||||
|
* map_options => ?
|
||||||
|
*
|
||||||
|
* @return object New networkmap manager.
|
||||||
|
*/
|
||||||
|
public function __construct($options=[])
|
||||||
|
{
|
||||||
|
if (is_array($options)) {
|
||||||
|
if (isset($options['id_map'])) {
|
||||||
|
$this->idMap = $options['id_map'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($options['graph'])) {
|
||||||
|
$this->graph = $options['graph'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($options['nodes'])) {
|
||||||
|
$this->nodes = $options['nodes'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($options['relations'])) {
|
||||||
|
$this->relations = $options['relations'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($options['mode'])) {
|
||||||
|
$this->mode = $options['mode'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($options['map_options'])) {
|
||||||
|
$this->mapOptions = $options['map_options'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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)) {
|
||||||
|
$graph = networkmap_process_networkmap($this->idMap);
|
||||||
|
|
||||||
|
ob_start();
|
||||||
|
|
||||||
|
ui_require_css_file('networkmap');
|
||||||
|
show_networkmap(
|
||||||
|
$this->idMap,
|
||||||
|
$user_readonly,
|
||||||
|
$graph,
|
||||||
|
get_parameter('pure', 0)
|
||||||
|
);
|
||||||
|
|
||||||
|
$output = ob_get_clean();
|
||||||
|
} else if (isset($this->graph)) {
|
||||||
|
// Build graph based on direct graph definition.
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($return === false) {
|
||||||
|
echo $output;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $output;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -1674,44 +1674,6 @@ function show_networkmap($id=0, $user_readonly=false, $nodes_and_relations=[], $
|
|||||||
echo '</div>';
|
echo '</div>';
|
||||||
|
|
||||||
?>
|
?>
|
||||||
<style type="text/css">
|
|
||||||
.node {
|
|
||||||
stroke: #fff;
|
|
||||||
stroke-width: 1px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.node_over {
|
|
||||||
stroke: #999;
|
|
||||||
}
|
|
||||||
|
|
||||||
.node_selected {
|
|
||||||
stroke:#343434;
|
|
||||||
stroke-width:5;
|
|
||||||
}
|
|
||||||
|
|
||||||
.node_children {
|
|
||||||
stroke: #00f;
|
|
||||||
}
|
|
||||||
|
|
||||||
.link {
|
|
||||||
stroke-opacity: .6;
|
|
||||||
}
|
|
||||||
|
|
||||||
.link_over {
|
|
||||||
stroke: #000;
|
|
||||||
stroke-opacity: .6;
|
|
||||||
}
|
|
||||||
|
|
||||||
.holding_area {
|
|
||||||
stroke: #0f0;
|
|
||||||
stroke-dasharray: 12,3;
|
|
||||||
}
|
|
||||||
|
|
||||||
.holding_area_link {
|
|
||||||
stroke-dasharray: 12,3;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
<?php
|
<?php
|
||||||
networkmap_write_js_array($id, $nodes_and_relations, $map_dash_details);
|
networkmap_write_js_array($id, $nodes_and_relations, $map_dash_details);
|
||||||
|
35
pandora_console/include/styles/networkmap.css
Normal file
35
pandora_console/include/styles/networkmap.css
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
.node {
|
||||||
|
stroke: #fff;
|
||||||
|
stroke-width: 1px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.node_over {
|
||||||
|
stroke: #999;
|
||||||
|
}
|
||||||
|
|
||||||
|
.node_selected {
|
||||||
|
stroke: #343434;
|
||||||
|
stroke-width: 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
.node_children {
|
||||||
|
stroke: #00f;
|
||||||
|
}
|
||||||
|
|
||||||
|
.link {
|
||||||
|
stroke-opacity: 0.6;
|
||||||
|
}
|
||||||
|
|
||||||
|
.link_over {
|
||||||
|
stroke: #000;
|
||||||
|
stroke-opacity: 0.6;
|
||||||
|
}
|
||||||
|
|
||||||
|
.holding_area {
|
||||||
|
stroke: #0f0;
|
||||||
|
stroke-dasharray: 12, 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
.holding_area_link {
|
||||||
|
stroke-dasharray: 12, 3;
|
||||||
|
}
|
@ -763,11 +763,7 @@ if (is_ajax()) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// --------------END AJAX------------------------------------------------
|
// --------------END AJAX------------------------------------------------
|
||||||
if (_id_ != '_id_') {
|
|
||||||
$id = _id_;
|
|
||||||
} else {
|
|
||||||
$id = (int) get_parameter('id_networkmap', 0);
|
$id = (int) get_parameter('id_networkmap', 0);
|
||||||
}
|
|
||||||
|
|
||||||
// Print some params to handle it in js
|
// Print some params to handle it in js
|
||||||
html_print_input_hidden('product_name', get_product_name());
|
html_print_input_hidden('product_name', get_product_name());
|
||||||
@ -886,9 +882,20 @@ if ($networkmap === false) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
$nodes_and_relations = networkmap_process_networkmap($id);
|
$nodes_and_relations = networkmap_process_networkmap($id);
|
||||||
|
|
||||||
show_networkmap($id, $user_readonly, $nodes_and_relations, $dash_mode, $map_dash_details);
|
show_networkmap($id, $user_readonly, $nodes_and_relations, $dash_mode, $map_dash_details);
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
include_once $config['homedir'].'/include/class/NetworkMap.class.php';
|
||||||
|
echo 'generado por clase';
|
||||||
|
$map_manager = new NetworkMap(
|
||||||
|
[ 'id_map' => $networkmap['id']]
|
||||||
|
);
|
||||||
|
|
||||||
|
$map_manager->printMap();
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user