mirror of
https://github.com/pandorafms/pandorafms.git
synced 2025-07-31 01:35:36 +02:00
Working in the code of new networkmaps.
This commit is contained in:
parent
87b07ee5ef
commit
fe863f61df
@ -22,31 +22,60 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
abstract class Map {
|
abstract class Map {
|
||||||
|
protected $status = STATUS_OK;
|
||||||
|
|
||||||
protected $id = null;
|
protected $id = null;
|
||||||
|
|
||||||
protected $type = null;
|
protected $type = null;
|
||||||
protected $subtype = null;
|
protected $subtype = null;
|
||||||
|
protected $id_group = null;
|
||||||
|
|
||||||
|
protected $nodes = null;
|
||||||
|
|
||||||
protected $requires_js = null;
|
protected $requires_js = null;
|
||||||
|
|
||||||
public function __construct($id) {
|
public function __construct($id) {
|
||||||
$this->id = $id;
|
$this->id = $id;
|
||||||
|
|
||||||
$this->loadDB();
|
if (!$this->loadDB()) {
|
||||||
|
$this->status = STATUS_ERROR;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$this->requires_js = array();
|
||||||
|
$this->requires_js[] = "include/javascript/d3.3.5.14.js";
|
||||||
|
$this->requires_js[] = "include/javascript/map/MapController.js";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function processDBValues($dbValues) {
|
||||||
|
$this->type = (int)$dbValues['type'];
|
||||||
|
$this->subtype = (int)$dbValues['subtype'];
|
||||||
|
|
||||||
$this->requires_js = array();
|
$this->id_group = (int)$dbValues['id_group'];
|
||||||
$this->requires_js[] = "include/javascript/d3.3.5.14.js";
|
|
||||||
$this->requires_js[] = "include/javascript/map/MapController.js";
|
html_debug(111);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function loadDB() {
|
private function loadDB() {
|
||||||
$row = db_get_row_filter('tmap', array('id' => $this->id));
|
$row = db_get_row_filter('tmap', array('id' => $this->id));
|
||||||
|
|
||||||
$this->type = $row['type'];
|
if (empty($row))
|
||||||
$this->subtype = $row['subtype'];
|
return false;
|
||||||
|
|
||||||
|
switch (get_class($this)) {
|
||||||
|
case 'Networkmap':
|
||||||
|
Networkmap::processDBValues($row);
|
||||||
|
break;
|
||||||
|
case 'NetworkmapEnterprise':
|
||||||
|
NetworkmapEnterprise::processDBValues($row);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
$this->processDBValues($row);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract function print_js_init();
|
abstract function printJSInit();
|
||||||
|
|
||||||
public function show() {
|
public function show() {
|
||||||
|
|
||||||
@ -62,7 +91,11 @@ abstract class Map {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
$this->print_js_init();
|
$this->printJSInit();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getType() {
|
||||||
|
return $this->type;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
@ -21,18 +21,128 @@
|
|||||||
* @subpackage Networkmap
|
* @subpackage Networkmap
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
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");
|
||||||
|
|
||||||
class Networkmap extends Map {
|
class Networkmap extends Map {
|
||||||
|
protected $show_snmp_modules = false;
|
||||||
|
|
||||||
public function __construct($id) {
|
public function __construct($id) {
|
||||||
parent::__construct($id);
|
parent::__construct($id);
|
||||||
|
|
||||||
$this->requires_js[] = "include/javascript/map/NetworkmapController.js";
|
$this->requires_js[] = "include/javascript/map/NetworkmapController.js";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function processDBValues($dbValues) {
|
||||||
|
$filter = json_decode($dbValues, true);
|
||||||
|
|
||||||
|
$this->show_snmp_modules = true;
|
||||||
|
|
||||||
|
parent::processDBValues($dbValues);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function generateDot() {
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function temp_parseParameters_generateDot() {
|
||||||
|
$return = array();
|
||||||
|
|
||||||
|
$return['id_group'] = $this->id_group;
|
||||||
|
$return['simple'] = 12; // HARD CODED
|
||||||
|
$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;
|
||||||
|
$return['show_snmp_modules'] = $this->show_snmp_modules;
|
||||||
|
$return['l2_network_interfaces'] = null;
|
||||||
|
$return['ip_mask'] = null;
|
||||||
|
$return['dont_show_subgroups'] = null;
|
||||||
|
$return['old_mode'] = null;
|
||||||
|
$return['filter'] = null;
|
||||||
|
$return['simple'] = 0; // HARD CODED
|
||||||
|
|
||||||
|
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']);
|
||||||
|
|
||||||
|
|
||||||
|
$filename_dot = sys_get_temp_dir() . "/networkmap_" . $parameters['filter'];
|
||||||
|
if ($parameters['simple']) {
|
||||||
|
$filename_dot .= "_simple";
|
||||||
|
}
|
||||||
|
if ($nooverlap) {
|
||||||
|
$filename_dot .= "_nooverlap";
|
||||||
|
}
|
||||||
|
$filename_dot .= "_" . $id . ".dot";
|
||||||
|
|
||||||
|
file_put_contents($filename_dot, $graph);
|
||||||
|
|
||||||
|
$filename_plain = sys_get_temp_dir() . "/plain.txt";
|
||||||
|
|
||||||
|
$cmd = "$filter -Tplain -o " . $filename_plain . " " .
|
||||||
|
$filename_dot;
|
||||||
|
|
||||||
|
system ($cmd);
|
||||||
|
|
||||||
|
unlink($filename_dot);
|
||||||
|
|
||||||
|
$nodes = networkmap_enterprise_loadfile($id, $filename_plain,
|
||||||
|
$relation_nodes, $graph, $l2_network_interfaces);
|
||||||
|
//~ html_debug_print($graph);
|
||||||
|
//~ html_debug_print($nodes);
|
||||||
|
//~ html_debug_print($relation_nodes);
|
||||||
|
|
||||||
|
// ----- END DEPRECATED CODE--------------------------------
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function show() {
|
public function show() {
|
||||||
|
$this->getNodes();
|
||||||
parent::show();
|
parent::show();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function print_js_init() {
|
public function printJSInit() {
|
||||||
echo "<h1>Networkmap</h1>";
|
echo "<h1>Networkmap</h1>";
|
||||||
?>
|
?>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
|
@ -461,6 +461,10 @@ define("OPTION_SINGLE_SELECT_TIME", 7);
|
|||||||
define("OPTION_CUSTOM_INPUT", 8);
|
define("OPTION_CUSTOM_INPUT", 8);
|
||||||
define("OPTION_AGENT_AUTOCOMPLETE", 9);
|
define("OPTION_AGENT_AUTOCOMPLETE", 9);
|
||||||
|
|
||||||
|
/* Other constants */
|
||||||
|
define("STATUS_OK", 0);
|
||||||
|
define("STATUS_ERROR", 1);
|
||||||
|
|
||||||
/* Maps (new networkmaps and new visualmaps) */
|
/* Maps (new networkmaps and new visualmaps) */
|
||||||
define("MAP_TYPE_NETWORKMAP", 0);
|
define("MAP_TYPE_NETWORKMAP", 0);
|
||||||
define("MAP_TYPE_VISUALMAP", 1);
|
define("MAP_TYPE_VISUALMAP", 1);
|
||||||
|
@ -129,52 +129,4 @@ function maps_update_map ($id, $values) {
|
|||||||
$result = db_process_sql_update('tmap', $values, $where);
|
$result = db_process_sql_update('tmap', $values, $where);
|
||||||
return (int)$result;
|
return (int)$result;
|
||||||
}
|
}
|
||||||
|
|
||||||
function maps_is_networkmap($id) {
|
|
||||||
$return = db_get_value('type', 'tmap', 'id', $id);
|
|
||||||
|
|
||||||
if ($return === false)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if ($return == MAP_TYPE_NETWORKMAP)
|
|
||||||
return true;
|
|
||||||
else
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
function maps_is_visualmap($id) {
|
|
||||||
$return = db_get_value('type', 'tmap', 'id', $id);
|
|
||||||
|
|
||||||
if ($return === false) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($return == MAP_TYPE_VISUALMAP) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function maps_show($id) {
|
|
||||||
require_once("include/class/Map.class.php");
|
|
||||||
|
|
||||||
if (maps_is_networkmap($id)) {
|
|
||||||
require_once("include/class/Networkmap.class.php");
|
|
||||||
enterprise_include_once("include/class/NetworkmapEnterprise.class.php");
|
|
||||||
|
|
||||||
if (enterprise_installed()) {
|
|
||||||
$map = new NetworkmapEnterprise($id);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$map = new Networkmap($id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
//~ $map = new Map($id);
|
|
||||||
}
|
|
||||||
|
|
||||||
$map->show();
|
|
||||||
}
|
|
||||||
?>
|
?>
|
||||||
|
@ -16,11 +16,11 @@
|
|||||||
var MapController = function(target) {
|
var MapController = function(target) {
|
||||||
this._target = target;
|
this._target = target;
|
||||||
|
|
||||||
console.log(this._id);
|
this._id = $(target).data('id');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Atributes
|
// Atributes
|
||||||
MapController.prototype._id = 333;
|
MapController.prototype._id = null;
|
||||||
|
|
||||||
|
|
||||||
// Methods
|
// Methods
|
||||||
|
@ -39,6 +39,8 @@ if (!$networkmaps_read && !$networkmaps_write && !$networkmaps_manage) {
|
|||||||
$id = (int)get_parameter('id', 0);
|
$id = (int)get_parameter('id', 0);
|
||||||
|
|
||||||
require_once('include/functions_migration.php');
|
require_once('include/functions_migration.php');
|
||||||
|
require_once('include/class/Networkmap.class.php');
|
||||||
|
enterprise_include('include/class/NetworkmapEnterprise.class.php');
|
||||||
|
|
||||||
$buttons['list'] = array('active' => false,
|
$buttons['list'] = array('active' => false,
|
||||||
'text' => '<a href="index.php?sec=network&sec2=operation/maps/networkmap_list">' .
|
'text' => '<a href="index.php?sec=network&sec2=operation/maps/networkmap_list">' .
|
||||||
@ -70,11 +72,19 @@ if (empty($id)) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
maps_show($id);
|
if (enterprise_installed()) {
|
||||||
|
$networkmap = new NetworkmapEnterprise($id);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$networkmap = new Networkmap($id);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (MAP_TYPE_NETWORKMAP === $networkmap->getType()) {
|
||||||
|
$networkmap->show();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
ui_print_error_message(__('Not found networkmap.'));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
||||||
|
|
||||||
<script type="text/javascript">
|
|
||||||
</script>
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user