Working in the code of new networkmaps.

This commit is contained in:
mdtrooper 2016-02-08 13:47:46 +01:00
parent 87b07ee5ef
commit fe863f61df
6 changed files with 173 additions and 64 deletions

View File

@ -22,31 +22,60 @@
*/
abstract class Map {
protected $status = STATUS_OK;
protected $id = null;
protected $type = null;
protected $subtype = null;
protected $id_group = null;
protected $nodes = null;
protected $requires_js = null;
public function __construct($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->requires_js[] = "include/javascript/d3.3.5.14.js";
$this->requires_js[] = "include/javascript/map/MapController.js";
$this->id_group = (int)$dbValues['id_group'];
html_debug(111);
}
private function loadDB() {
$row = db_get_row_filter('tmap', array('id' => $this->id));
$this->type = $row['type'];
$this->subtype = $row['subtype'];
if (empty($row))
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() {
@ -62,7 +91,11 @@ abstract class Map {
</div>
<?php
$this->print_js_init();
$this->printJSInit();
}
public function getType() {
return $this->type;
}
}
?>

View File

@ -21,18 +21,128 @@
* @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 {
protected $show_snmp_modules = false;
public function __construct($id) {
parent::__construct($id);
$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() {
$this->getNodes();
parent::show();
}
public function print_js_init() {
public function printJSInit() {
echo "<h1>Networkmap</h1>";
?>
<script type="text/javascript">

View File

@ -461,6 +461,10 @@ define("OPTION_SINGLE_SELECT_TIME", 7);
define("OPTION_CUSTOM_INPUT", 8);
define("OPTION_AGENT_AUTOCOMPLETE", 9);
/* Other constants */
define("STATUS_OK", 0);
define("STATUS_ERROR", 1);
/* Maps (new networkmaps and new visualmaps) */
define("MAP_TYPE_NETWORKMAP", 0);
define("MAP_TYPE_VISUALMAP", 1);

View File

@ -129,52 +129,4 @@ function maps_update_map ($id, $values) {
$result = db_process_sql_update('tmap', $values, $where);
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();
}
?>

View File

@ -16,11 +16,11 @@
var MapController = function(target) {
this._target = target;
console.log(this._id);
this._id = $(target).data('id');
}
// Atributes
MapController.prototype._id = 333;
MapController.prototype._id = null;
// Methods

View File

@ -39,6 +39,8 @@ if (!$networkmaps_read && !$networkmaps_write && !$networkmaps_manage) {
$id = (int)get_parameter('id', 0);
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,
'text' => '<a href="index.php?sec=network&sec2=operation/maps/networkmap_list">' .
@ -70,11 +72,19 @@ if (empty($id)) {
return;
}
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>