2013-07-03 10:50:50 +02:00
< ? php
// Pandora FMS - http://pandorafms.com
// ==================================================
// Copyright (c) 2005-2010 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.
require_once ( '../include/functions_networkmap.php' );
class Networkmap {
private $correct_acl = false ;
private $acl = " AR " ;
private $id = 0 ;
private $network_map = null ;
2015-03-31 12:26:29 +02:00
function __construct ( $id = false ) {
2013-07-03 10:50:50 +02:00
$system = System :: getInstance ();
2015-03-31 12:26:29 +02:00
if ( $id === false )
$this -> getFilters ();
else
$this -> id = $id ;
$store_group = db_get_value ( 'store_group' ,
'tnetwork_map' , 'id_networkmap' , $this -> id );
if ( $store_group !== false
&& $system -> checkACL ( $this -> acl , $store_group ))
2013-07-03 10:50:50 +02:00
$this -> correct_acl = true ;
}
public function ajax ( $parameter2 = false ) {
$system = System :: getInstance ();
if ( ! $this -> correct_acl ) {
return ;
}
else {
switch ( $parameter2 ) {
case 'xxx' :
//$this->getFilters();
//$page = $system->getRequest('page', 0);
break ;
}
}
}
private function getFilters () {
$system = System :: getInstance ();
$this -> id = ( int ) $system -> getRequest ( 'id' , 0 );
}
public function show () {
if ( ! $this -> correct_acl ) {
$this -> show_fail_acl ();
}
else {
$this -> getFilters ();
$this -> networkmap = db_get_row ( 'tnetwork_map' ,
'id_networkmap' , $this -> id );
$this -> show_networkmap ();
}
}
private function show_fail_acl () {
2014-10-15 18:12:51 +02:00
$error [ 'type' ] = 'onStart' ;
2013-07-03 10:50:50 +02:00
$error [ 'title_text' ] = __ ( 'You don\'t have access to this page' );
$error [ 'content_text' ] = __ ( 'Access to this page is restricted to authorized users only, please contact system administrator if you need assistance. <br><br>Please know that all attempts to access this page are recorded in security logs of Pandora System Database' );
2014-10-15 18:12:51 +02:00
if ( class_exists ( " HomeEnterprise " ))
$home = new HomeEnterprise ();
else
$home = new Home ();
2013-07-03 10:50:50 +02:00
$home -> show ( $error );
}
private function show_networkmap () {
$ui = Ui :: getInstance ();
$system = System :: getInstance ();
$ui -> createPage ();
2013-07-03 Miguel de Dios <miguel.dedios@artica.es>
* mobile/operation/events.php, mobile/operation/module_graph.php,
mobile/operation/modules.php, mobile/operation/networkmaps.php,
mobile/operation/groups.php, mobile/operation/agents.php,
mobile/operation/tactical.php, mobile/operation/networkmap.php,
mobile/operation/alerts.php, mobile/operation/agent.php,
mobile/include/ui.class.php: added the back button in the head and
impoved the source code style to make more easy the merges with
the last branch.
* include/functions_graph.php: fixed PHP notices.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@8468 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2013-07-03 15:59:38 +02:00
$ui -> createDefaultHeader (
2013-11-28 17:54:18 +01:00
sprintf ( " %s " ,
2014-02-06 18:39:39 +01:00
$this -> networkmap [ 'name' ]),
2013-07-03 Miguel de Dios <miguel.dedios@artica.es>
* mobile/operation/events.php, mobile/operation/module_graph.php,
mobile/operation/modules.php, mobile/operation/networkmaps.php,
mobile/operation/groups.php, mobile/operation/agents.php,
mobile/operation/tactical.php, mobile/operation/networkmap.php,
mobile/operation/alerts.php, mobile/operation/agent.php,
mobile/include/ui.class.php: added the back button in the head and
impoved the source code style to make more easy the merges with
the last branch.
* include/functions_graph.php: fixed PHP notices.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@8468 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2013-07-03 15:59:38 +02:00
$ui -> createHeaderButton (
array ( 'icon' => 'back' ,
'pos' => 'left' ,
'text' => __ ( 'Back' ),
'href' => 'index.php?page=networkmaps' )));
2013-07-03 10:50:50 +02:00
$ui -> showFooter ( false );
$ui -> beginContent ();
//Hack for mobile
global $hack_networkmap_mobile ;
$hack_networkmap_mobile = true ;
switch ( $this -> networkmap [ 'type' ]) {
case 'groups' :
$graph = networkmap_generate_dot_groups (
__ ( 'Pandora FMS' ),
$this -> networkmap [ 'id_group' ],
$this -> networkmap [ 'simple' ],
$this -> networkmap [ 'font_size' ],
$this -> networkmap [ 'layout' ],
( bool ) $this -> networkmap [ 'nooverlap' ],
$this -> networkmap [ 'zoom' ],
$this -> networkmap [ 'distance_nodes' ],
$this -> networkmap [ 'center' ], 1 , 0 ,
$this -> networkmap [ 'only_modules_with_alerts' ],
$this -> networkmap [ 'id_module_group' ],
$this -> networkmap [ 'hide_policy_modules' ],
$this -> networkmap [ 'depth' ],
$this -> networkmap [ 'id_networkmap' ]);
break ;
case 'policies' :
$enterprise = enterprise_include ( '/include/functions_policies.php' );
if ( $enterprise != ENTERPRISE_NOT_HOOK ) {
$graph = policies_generate_dot_graph ( __ ( 'Pandora FMS' ),
$this -> networkmap [ 'id_group' ],
$this -> networkmap [ 'simple' ],
$this -> networkmap [ 'font_size' ],
$this -> networkmap [ 'layout' ],
( bool ) $this -> networkmap [ 'nooverlap' ],
$this -> networkmap [ 'zoom' ],
$this -> networkmap [ 'distance_nodes' ],
$this -> networkmap [ 'center' ], 1 , 0 ,
$this -> networkmap [ 'only_modules_with_alerts' ],
$this -> networkmap [ 'id_module_group' ],
$this -> networkmap [ 'depth' ],
$this -> networkmap [ 'id_networkmap' ]);
}
break ;
default :
case 'topology' :
$graph = networkmap_generate_dot ( __ ( 'Pandora FMS' ),
$this -> networkmap [ 'id_group' ],
$this -> networkmap [ 'simple' ],
$this -> networkmap [ 'font_size' ],
$this -> networkmap [ 'layout' ],
( bool ) $this -> networkmap [ 'nooverlap' ],
$this -> networkmap [ 'zoom' ],
$this -> networkmap [ 'distance_nodes' ],
$this -> networkmap [ 'center' ], 1 , 0 ,
$this -> networkmap [ 'id_networkmap' ],
$this -> networkmap [ 'show_snmp_modules' ], true ,
true );
break ;
}
if ( $graph === false ) {
$ui -> contentAddHtml ( '<p style="color: #ff0000;">' . __ ( 'No networkmaps' ) . '</p>' );
$ui -> endContent ();
$ui -> showPage ();
return ;
}
$filter = networkmap_get_filter ( $this -> networkmap [ 'layout' ]);
// Generate image and map
// If image was generated just a few minutes ago, then don't regenerate (it takes long) unless regen checkbox is set
$filename_map = safe_url_extraclean (
$system -> getConfig ( 'attachment_store' )) . " /networkmap_ " . $filter ;
$filename_img = safe_url_extraclean (
$system -> getConfig ( 'attachment_store' )) . " /networkmap_ " .
$filter . " _ " . $this -> networkmap [ 'font_size' ];
2013-07-30 12:25:49 +02:00
$url_img = " ../attachment/networkmap_ " .
2013-07-03 10:50:50 +02:00
$filter . " _ " . $this -> networkmap [ 'font_size' ];
$filename_dot = safe_url_extraclean (
$system -> getConfig ( " attachment_store " )) . " /networkmap_ " . $filter ;
if ( $this -> networkmap [ 'simple' ]) {
$filename_map .= " _simple " ;
$filename_img .= " _simple " ;
$url_img .= " _simple " ;
$filename_dot .= " _simple " ;
}
if ( $this -> networkmap [ 'nooverlap' ]) {
$filename_map .= " _nooverlap " ;
$filename_img .= " _nooverlap " ;
$url_img .= " _nooverlap " ;
$filename_dot .= " _nooverlap " ;
}
$filename_map .= " _ " . $this -> networkmap [ 'id_networkmap' ] . " .map " ;
$filename_img .= " _ " . $this -> networkmap [ 'id_networkmap' ] . " .png " ;
$url_img .= " _ " . $this -> networkmap [ 'id_networkmap' ] . " .png " ;
$filename_dot .= " _ " . $this -> networkmap [ 'id_networkmap' ] . " .dot " ;
if ( $this -> networkmap [ 'regenerate' ] != 1 && file_exists ( $filename_img ) && filemtime ( $filename_img ) > get_system_time () - 300 ) {
$result = true ;
}
else {
$fh = @ fopen ( $filename_dot , 'w' );
if ( $fh === false ) {
$result = false ;
}
else {
fwrite ( $fh , $graph );
$cmd = $filter . " -Tcmapx -o " . $filename_map . " -Tpng -o " . $filename_img . " " . $filename_dot ;
$result = system ( $cmd );
fclose ( $fh );
//unlink ($filename_dot);
}
}
if ( $result !== false ) {
if ( ! file_exists ( $filename_map )) {
$ui -> contentAddHtml ( '<p style="color: #ff0000;">' . __ ( 'Map could not be generated' ) . '</p>' );
$ui -> endContent ();
$ui -> showPage ();
return ;
}
2013-07-03 12:19:31 +02:00
$ui -> contentAddHtml ( '<div style="width: auto; overflow-x: auto; text-align: center;">' );
2014-02-05 17:38:05 +01:00
$ui -> contentAddHtml ( '<img style="width: 90%;" src="' . $url_img . '" />' );
2013-07-03 12:19:31 +02:00
$ui -> contentAddHtml ( '</div>' );
2013-07-03 10:50:50 +02:00
}
else {
$ui -> contentAddHtml ( '<p style="color: #ff0000;">' . __ ( 'Map could not be generated' ) . '</p>' );
$ui -> endContent ();
$ui -> showPage ();
return ;
}
$ui -> endContent ();
$ui -> showPage ();
}
}
2013-11-28 17:54:18 +01:00
?>