2016-02-04 12:06:45 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
// Pandora FMS - http://pandorafms.com
|
|
|
|
// ==================================================
|
|
|
|
// Copyright (c) 2005-2011 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.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @package Include
|
|
|
|
* @subpackage Networkmap
|
|
|
|
*/
|
|
|
|
|
2016-02-08 13:47:46 +01:00
|
|
|
require_once ('include/functions_os.php');
|
|
|
|
require_once ('include/functions_networkmap.php');
|
|
|
|
enterprise_include("include/functions_networkmap_enterprise.php");
|
|
|
|
|
|
|
|
require_once("include/class/Map.class.php");
|
|
|
|
|
2016-02-04 12:06:45 +01:00
|
|
|
class Networkmap extends Map {
|
2016-02-12 16:28:07 +01:00
|
|
|
protected $filter = array();
|
|
|
|
|
2016-02-09 13:52:03 +01:00
|
|
|
protected $source_group = 0;
|
|
|
|
protected $source_ip_mask = "";
|
2016-02-08 13:47:46 +01:00
|
|
|
|
2016-02-04 12:06:45 +01:00
|
|
|
public function __construct($id) {
|
|
|
|
parent::__construct($id);
|
2016-02-04 16:59:40 +01:00
|
|
|
|
2016-02-05 15:53:59 +01:00
|
|
|
$this->requires_js[] = "include/javascript/map/NetworkmapController.js";
|
2016-02-04 12:06:45 +01:00
|
|
|
}
|
|
|
|
|
2016-02-08 13:47:46 +01:00
|
|
|
public function processDBValues($dbValues) {
|
2016-02-09 13:52:03 +01:00
|
|
|
$filter = json_decode($dbValues['filter'], true);
|
2016-02-08 13:47:46 +01:00
|
|
|
|
2016-02-12 16:28:07 +01:00
|
|
|
$this->filter = $filter;
|
2016-02-17 15:36:44 +01:00
|
|
|
if (!isset($this->filter['only_snmp_modules']))
|
|
|
|
$this->filter['only_snmp_modules'] = false;
|
2016-02-09 13:52:03 +01:00
|
|
|
|
|
|
|
switch ($dbValues['source_data']) {
|
|
|
|
case MAP_SOURCE_GROUP:
|
|
|
|
$this->source_group = $dbValues['source'];
|
|
|
|
$this->source_ip_mask = "";
|
|
|
|
break;
|
|
|
|
case MAP_SOURCE_IP_MASK:
|
|
|
|
$this->source_group = $dbValues['source'];
|
|
|
|
$this->source_ip_mask = "";
|
|
|
|
break;
|
|
|
|
}
|
2016-02-08 13:47:46 +01:00
|
|
|
|
|
|
|
parent::processDBValues($dbValues);
|
|
|
|
}
|
|
|
|
|
2016-02-17 12:25:03 +01:00
|
|
|
protected function generateDot($graph, $positions) {
|
2016-02-15 12:15:16 +01:00
|
|
|
$graph = preg_replace('/^graph .*/', '', $graph);
|
|
|
|
|
|
|
|
$nodes_and_edges = explode("];", $graph);
|
|
|
|
|
|
|
|
$nodes = array();
|
|
|
|
$edges = array();
|
2016-02-22 13:02:06 +01:00
|
|
|
$last_graph_id = 0;
|
2016-02-15 12:15:16 +01:00
|
|
|
foreach ($nodes_and_edges as $node_or_edge) {
|
|
|
|
$node_or_edge = trim($node_or_edge);
|
|
|
|
|
|
|
|
$chunks = explode("[", $node_or_edge);
|
|
|
|
|
2016-02-17 12:25:03 +01:00
|
|
|
if (strstr($chunks[0], "--") !== false) {
|
2016-02-15 12:15:16 +01:00
|
|
|
// EDGE
|
2016-02-17 12:25:03 +01:00
|
|
|
$graphviz_ids = explode("--", $chunks[0]);
|
2016-02-15 12:15:16 +01:00
|
|
|
|
|
|
|
$edges[] = array(
|
|
|
|
'to' => trim($graphviz_ids[0]),
|
|
|
|
'from' => trim($graphviz_ids[1]));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// NODE
|
2016-02-17 12:25:03 +01:00
|
|
|
$graphviz_id = trim($chunks[0]);
|
2016-02-15 12:15:16 +01:00
|
|
|
|
2016-02-17 12:25:03 +01:00
|
|
|
// Avoid the weird nodes.
|
|
|
|
if (!is_numeric($graphviz_id))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
|
|
$chunks = explode("ajax.php?", $chunks[1]);
|
|
|
|
|
|
|
|
if (strstr($chunks[1], "&id_module=") !== false) {
|
2016-02-15 12:15:16 +01:00
|
|
|
// MODULE
|
2016-02-17 12:25:03 +01:00
|
|
|
preg_match("/id_module=([0-9]*)/", $chunks[1], $matches);
|
|
|
|
$id = $matches[1];
|
|
|
|
$type = ITEM_TYPE_MODULE_NETWORKMAP;
|
2016-02-15 12:15:16 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
// AGENT
|
2016-02-17 12:25:03 +01:00
|
|
|
preg_match("/id_agent=([0-9]*)/", $chunks[1], $matches);
|
|
|
|
$id = $matches[1];
|
|
|
|
$type = ITEM_TYPE_AGENT_NETWORKMAP;
|
2016-02-15 12:15:16 +01:00
|
|
|
}
|
2016-02-17 12:25:03 +01:00
|
|
|
|
2016-02-22 13:02:06 +01:00
|
|
|
$nodes[] = array('graph_id' => $graphviz_id,
|
|
|
|
'id' => $id, 'type' => $type);
|
|
|
|
|
2016-03-01 16:37:10 +01:00
|
|
|
if ($last_graph_id < $graphviz_id)
|
|
|
|
$last_graph_id = $graphviz_id;
|
2016-02-15 12:15:16 +01:00
|
|
|
}
|
2016-02-17 12:25:03 +01:00
|
|
|
}
|
|
|
|
|
2016-02-22 13:02:06 +01:00
|
|
|
|
|
|
|
|
2016-02-17 12:25:03 +01:00
|
|
|
foreach ($positions as $line) {
|
|
|
|
//clean line a long spaces for one space caracter
|
|
|
|
$line = preg_replace('/[ ]+/', ' ', $line);
|
2016-02-15 12:15:16 +01:00
|
|
|
|
2016-02-17 12:25:03 +01:00
|
|
|
if (preg_match('/^node.*$/', $line) != 0) {
|
2016-02-17 15:36:44 +01:00
|
|
|
$items = explode(' ', $line);
|
2016-02-17 12:25:03 +01:00
|
|
|
$graphviz_id = $items[1];
|
|
|
|
|
2016-02-22 13:02:06 +01:00
|
|
|
// We need a binary tree...in some future time.
|
|
|
|
|
|
|
|
foreach ($nodes as $i => $node) {
|
|
|
|
if ($node['graph_id'] == $graphviz_id) {
|
|
|
|
$nodes[$i]['x'] = $items[2] * 100; //200 is for show more big
|
|
|
|
$nodes[$i]['y'] = $items[3] * 100;
|
|
|
|
}
|
|
|
|
}
|
2016-02-17 12:25:03 +01:00
|
|
|
}
|
2016-02-15 12:15:16 +01:00
|
|
|
}
|
|
|
|
|
2016-02-22 13:02:06 +01:00
|
|
|
foreach ($edges as $i => $edge) {
|
2016-03-03 15:08:05 +01:00
|
|
|
$graph_id = ++$last_graph_id;
|
2016-02-22 13:02:06 +01:00
|
|
|
|
2016-03-01 16:37:10 +01:00
|
|
|
$nodes[] = array(
|
2016-02-22 13:02:06 +01:00
|
|
|
'graph_id' => $graph_id,
|
|
|
|
'type' => ITEM_TYPE_EDGE_NETWORKMAP);
|
2016-03-01 16:37:10 +01:00
|
|
|
$edges[$i]['graph_id'] = $graph_id;
|
2016-02-22 13:02:06 +01:00
|
|
|
|
2016-02-17 12:25:03 +01:00
|
|
|
}
|
2016-02-15 12:15:16 +01:00
|
|
|
|
2016-02-22 13:02:06 +01:00
|
|
|
$this->nodes = $nodes;
|
|
|
|
$this->edges = $edges;
|
2016-02-08 13:47:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
protected function temp_parseParameters_generateDot() {
|
|
|
|
$return = array();
|
|
|
|
|
2016-02-09 13:52:03 +01:00
|
|
|
$return['id_group'] = $this->source_group;
|
2016-02-12 17:22:44 +01:00
|
|
|
$return['simple'] = 0; // HARD CODED
|
2016-02-08 13:47:46 +01:00
|
|
|
$return['font_size'] = null;
|
|
|
|
$return['layout'] = null;
|
|
|
|
$return['nooverlap'] = false; // HARD CODED
|
|
|
|
$return['zoom'] = 1; // HARD CODED
|
|
|
|
$return['ranksep'] = 2.5; // HARD CODED
|
|
|
|
$return['center'] = 0; // HARD CODED
|
|
|
|
$return['regen'] = 0; // HARD CODED
|
|
|
|
$return['pure'] = 0; // HARD CODED
|
|
|
|
$return['id'] = $this->id;
|
2016-02-12 16:28:07 +01:00
|
|
|
$return['show_snmp_modules'] = $this->filter['only_snmp_modules'];
|
2016-02-09 13:52:03 +01:00
|
|
|
$return['l2_network_interfaces'] = true; // HARD CODED
|
|
|
|
$return['ip_mask'] = $this->source_ip_mask;
|
2016-02-12 16:28:07 +01:00
|
|
|
$return['dont_show_subgroups'] = false;
|
2016-02-09 13:52:03 +01:00
|
|
|
$return['old_mode'] = false;
|
2016-02-12 16:28:07 +01:00
|
|
|
$return['filter'] = $this->filter['text'];
|
2016-02-08 13:47:46 +01:00
|
|
|
|
|
|
|
return $return;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function getNodes() {
|
|
|
|
if (empty($this->nodes)) {
|
|
|
|
|
|
|
|
// ----- INI DEPRECATED CODE--------------------------------
|
|
|
|
// I hope this code to change for any some better and
|
|
|
|
// rewrote the old function.
|
|
|
|
|
|
|
|
$parameters = $this->temp_parseParameters_generateDot();
|
|
|
|
|
|
|
|
// Generate dot file
|
|
|
|
$graph = networkmap_generate_dot (__('Pandora FMS'),
|
|
|
|
$parameters['id_group'],
|
|
|
|
$parameters['simple'],
|
|
|
|
$parameters['font_size'],
|
|
|
|
$parameters['layout'],
|
|
|
|
$parameters['nooverlap'],
|
|
|
|
$parameters['zoom'],
|
|
|
|
$parameters['ranksep'],
|
|
|
|
$parameters['center'],
|
|
|
|
$parameters['regen'],
|
|
|
|
$parameters['pure'],
|
|
|
|
$parameters['id'],
|
|
|
|
$parameters['show_snmp_modules'],
|
|
|
|
false, //cut_names
|
|
|
|
true, // relative
|
|
|
|
'',
|
|
|
|
$parameters['l2_network_interfaces'],
|
|
|
|
$parameters['ip_mask'],
|
|
|
|
$parameters['dont_show_subgroups'],
|
|
|
|
false,
|
|
|
|
null,
|
|
|
|
$parameters['old_mode']);
|
|
|
|
|
|
|
|
|
2016-02-09 13:52:03 +01:00
|
|
|
|
|
|
|
$filename_dot = sys_get_temp_dir() . "/networkmap" . uniqid() . ".dot";
|
2016-02-08 13:47:46 +01:00
|
|
|
|
|
|
|
file_put_contents($filename_dot, $graph);
|
|
|
|
|
|
|
|
$filename_plain = sys_get_temp_dir() . "/plain.txt";
|
|
|
|
|
2016-02-09 13:52:03 +01:00
|
|
|
switch ($this->generation_method) {
|
|
|
|
case MAP_GENERATION_CIRCULAR:
|
|
|
|
$graphviz_command = "circo";
|
|
|
|
break;
|
|
|
|
case MAP_GENERATION_PLANO:
|
|
|
|
$graphviz_command = "dot";
|
|
|
|
break;
|
|
|
|
case MAP_GENERATION_RADIAL:
|
|
|
|
$graphviz_command = "twopi";
|
|
|
|
break;
|
|
|
|
case MAP_GENERATION_SPRING1:
|
|
|
|
$graphviz_command = "spring1";
|
|
|
|
break;
|
|
|
|
case MAP_GENERATION_SPRING2:
|
|
|
|
$graphviz_command = "spring2";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-02-10 14:01:10 +01:00
|
|
|
$cmd = "$graphviz_command " .
|
|
|
|
"-Tpng -o /tmp/caca.png -Tplain -o " . $filename_plain . " " .
|
2016-02-08 13:47:46 +01:00
|
|
|
$filename_dot;
|
|
|
|
|
|
|
|
system ($cmd);
|
|
|
|
|
|
|
|
|
2016-02-10 14:01:10 +01:00
|
|
|
|
2016-02-17 12:25:03 +01:00
|
|
|
$this->generateDot($graph, file($filename_plain));
|
2016-02-10 14:01:10 +01:00
|
|
|
|
2016-02-17 12:25:03 +01:00
|
|
|
unlink($filename_dot);
|
|
|
|
unlink($filename_plain);
|
2016-02-08 13:47:46 +01:00
|
|
|
// ----- END DEPRECATED CODE--------------------------------
|
2016-02-17 12:25:03 +01:00
|
|
|
|
|
|
|
switch (get_class($this)) {
|
|
|
|
case 'NetworkmapEnterprise':
|
|
|
|
NetworkmapEnterprise::dbSaveNodes();
|
|
|
|
break;
|
|
|
|
}
|
2016-02-08 13:47:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-04 12:06:45 +01:00
|
|
|
public function show() {
|
2016-02-08 13:47:46 +01:00
|
|
|
$this->getNodes();
|
2016-02-09 13:52:03 +01:00
|
|
|
|
2016-02-04 12:06:45 +01:00
|
|
|
parent::show();
|
|
|
|
}
|
2016-02-04 16:59:40 +01:00
|
|
|
|
2016-02-08 13:47:46 +01:00
|
|
|
public function printJSInit() {
|
2016-02-04 16:59:40 +01:00
|
|
|
echo "<h1>Networkmap</h1>";
|
|
|
|
?>
|
|
|
|
<script type="text/javascript">
|
|
|
|
$(function() {
|
|
|
|
// map = new js_networkmap();
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
<?php
|
|
|
|
}
|
2016-02-04 12:06:45 +01:00
|
|
|
}
|
|
|
|
?>
|