示例#1
0
 public function getListMaps()
 {
     $list = array();
     $maps = $this->getPermittedMaps();
     foreach ($maps as $mapName) {
         $MAPCFG = new GlobalMapCfg($mapName);
         $MAPCFG->checkMapConfigExists(true);
         try {
             $MAPCFG->readMapConfig(ONLY_GLOBAL);
         } catch (MapCfgInvalid $e) {
             continue;
             // skip configs with broken global sections
         } catch (NagVisException $e) {
             continue;
             // skip e.g. not read config files
         }
         if ($MAPCFG->getValue(0, 'show_in_lists') == 1) {
             $list[$mapName] = $MAPCFG->getAlias();
         }
     }
     natcasesort($list);
     return array_keys($list);
 }
示例#2
0
 private function parseMapJson($objectId, $mapName, $what)
 {
     global $AUTHORISATION;
     // Check if the user is permitted to view this
     if (!$AUTHORISATION->isPermitted('Map', 'view', $mapName)) {
         return null;
     }
     // If the parameter filterUser is set, filter the maps by the username
     // given in this parameter. This is a mechanism to be authed as generic
     // user but see the maps of another user. This feature is disabled by
     // default but could be enabled if you need it.
     if (cfg('global', 'user_filtering') && isset($_GET['filterUser']) && $_GET['filterUser'] != '') {
         $AUTHORISATION2 = new CoreAuthorisationHandler();
         $AUTHORISATION2->parsePermissions($_GET['filterUser']);
         if (!$AUTHORISATION2->isPermitted('Map', 'view', $mapName)) {
             return null;
         }
         // Switch the auth cookie to this user
         global $SHANDLER;
         $SHANDLER->aquire();
         $SHANDLER->set('authCredentials', array('user' => $_GET['filterUser'], 'password' => ''));
         $SHANDLER->set('authTrusted', true);
         $SHANDLER->commit();
     }
     $map = array('object_id' => $objectId);
     $MAPCFG = new GlobalMapCfg($mapName);
     $MAPCFG->checkMapConfigExists(true);
     $MAPCFG->readMapConfig();
     // Only perform this check with a valid config
     if ($MAPCFG->getValue(0, 'show_in_lists') != 1) {
         return null;
     }
     $MAP = new NagVisMap($MAPCFG, GET_STATE, !IS_VIEW);
     // Apply overview related configuration to object
     $MAP->MAPOBJ->setConfiguration($this->getMapDefaultOpts($mapName, $MAPCFG->getAlias()));
     if ($MAP->MAPOBJ->checkMaintenance(0)) {
         $map['overview_url'] = $this->htmlBase . '/index.php?mod=Map&act=view&show=' . $mapName;
         $map['overview_class'] = '';
     } else {
         $map['overview_class'] = 'disabled';
         $map['overview_url'] = 'javascript:alert(\'' . l('The map is in maintenance mode. Please be patient.') . '\');';
         $map['summary_output'] = l('The map is in maintenance mode. Please be patient.');
         $MAP->MAPOBJ->clearMembers();
         $MAP->MAPOBJ->setSummaryState('UNKNOWN');
         $MAP->MAPOBJ->fetchIcon();
     }
     if (cfg('index', 'showmapthumbs') == 1) {
         $map['overview_image'] = $this->renderMapThumb($MAPCFG);
     }
     return array($MAP->MAPOBJ, $map);
 }
示例#3
0
 /**
  * Gets all objects of the map
  *
  * @author	Thomas Casteleyn <*****@*****.**>
  * @author 	Lars Michelsen <*****@*****.**>
  */
 public function fetchMapObjects(&$arrMapNames = array(), $depth = 0)
 {
     foreach ($this->MAPCFG->getMapObjects() as $objConf) {
         $type = $objConf['type'];
         if ($type == 'global' || $type == 'template') {
             continue;
         }
         log_mem('preconf');
         $typeDefs = $this->MAPCFG->getTypeDefaults($type);
         // merge with "global" settings
         foreach ($typeDefs as $key => $default) {
             if (!isset($objConf[$key])) {
                 $objConf[$key] = $default;
             }
         }
         switch ($type) {
             case 'host':
                 log_mem('prehost');
                 $OBJ = new NagVisHost($objConf['backend_id'], $objConf['host_name']);
                 break;
             case 'service':
                 $OBJ = new NagVisService($objConf['backend_id'], $objConf['host_name'], $objConf['service_description']);
                 break;
             case 'hostgroup':
                 $OBJ = new NagVisHostgroup($objConf['backend_id'], $objConf['hostgroup_name']);
                 break;
             case 'servicegroup':
                 $OBJ = new NagVisServicegroup($objConf['backend_id'], $objConf['servicegroup_name']);
                 break;
             case 'dyngroup':
                 $OBJ = new NagVisDynGroup($objConf['backend_id'], $objConf['name']);
                 break;
             case 'aggr':
                 $OBJ = new NagVisAggr($objConf['backend_id'], $objConf['name']);
                 break;
             case 'map':
                 // Initialize map configuration
                 $SUBMAPCFG = new GlobalMapCfg($objConf['map_name']);
                 $mapCfgInvalid = null;
                 if ($SUBMAPCFG->checkMapConfigExists(0)) {
                     try {
                         $SUBMAPCFG->readMapConfig();
                     } catch (MapCfgInvalid $e) {
                         $mapCfgInvalid = l('Map Configuration Error: [ERR]', array('ERR' => $e->getMessage()));
                     } catch (Exception $e) {
                         $mapCfgInvalid = l('Problem while processing map: [ERR]', array('ERR' => (string) $e));
                     }
                 }
                 $OBJ = new NagVisMapObj($SUBMAPCFG, !IS_VIEW);
                 if ($mapCfgInvalid) {
                     $OBJ->setProblem($mapCfgInvalid);
                 }
                 if (!$SUBMAPCFG->checkMapConfigExists(0)) {
                     $OBJ->setProblem(l('mapCfgNotExists', 'MAP~' . $objConf['map_name']));
                 }
                 /**
                  * When the current map object is a summary object skip the map
                  * child for preventing a loop
                  */
                 if ($this->MAPCFG->getName() == $SUBMAPCFG->getName() && $this->isSummaryObject == true) {
                     continue 2;
                 }
                 /**
                  * This occurs when someone creates a map icon which links to itself
                  *
                  * The object will be marked as summary object and is ignored on next level.
                  * See the code above.
                  */
                 if ($this->MAPCFG->getName() == $SUBMAPCFG->getName()) {
                     $OBJ->isSummaryObject = true;
                 }
                 /**
                  * All maps which were seen before are stored in the list once. If
                  * they are already in the list and depth is more than 3 levels,
                  * skip them to prevent loops.
                  */
                 if (isset($arrMapNames[$SUBMAPCFG->getName()]) && $depth > 3) {
                     $OBJ->isLoopingBacklink = true;
                     continue 2;
                 }
                 // Store this map in the mapNames list
                 $arrMapNames[$SUBMAPCFG->getName()] = true;
                 // Skip this map when the user is not permitted toview this map
                 if (!$this->isPermitted($OBJ)) {
                     continue 2;
                 }
                 break;
             case 'shape':
                 $OBJ = new NagVisShape($objConf['icon']);
                 break;
             case 'textbox':
                 $OBJ = new NagVisTextbox();
                 break;
             case 'container':
                 $OBJ = new NagVisContainer();
                 break;
             case 'line':
                 $OBJ = new NagVisLine();
                 break;
             default:
                 throw new NagVisException(l('unknownObject', array('TYPE' => $type, 'MAPNAME' => $this->getName())));
                 break;
         }
         log_mem('preconf');
         // Apply default configuration to object
         $OBJ->setConfiguration($objConf);
         // Skip object by exclude filter? => Totally exclude (exclude_members)
         if ($this->hasExcludeFilters(!COUNT_QUERY) && $this->excludeMapObject($OBJ, !COUNT_QUERY)) {
             continue;
         }
         // Write member to object array
         $this->members[] = $OBJ;
         log_mem('posthost');
     }
     // Now dig into the next map level. This has to be done here to fight
     // the loops at this level and not at the single branches of map links.
     foreach ($this->members as $OBJ) {
         $sType = $OBJ->getType();
         if ($sType == 'map') {
             /**
              * When the current map object is a summary object skip the map
              * child for preventing a loop
              */
             if ($sType == 'map' && $this->MAPCFG->getName() == $OBJ->MAPCFG->getName() && $this->isSummaryObject == true) {
                 continue;
             }
             /**
              * All maps which produce a loop by linking back to earlier maps
              * need to be skipped here.
              */
             if ($sType == 'map' && $OBJ->isLoopingBacklink) {
                 continue;
             }
             if (!$OBJ->hasProblem()) {
                 $OBJ->fetchMapObjects($arrMapNames, $depth + 1);
             }
         }
     }
 }