private function deleteForm() { global $CORE; echo '<h2>' . l('Delete Shape') . '</h2>'; if (is_action() && post('mode') == 'delete') { try { $name = post('name'); if (!$name) { throw new FieldInputError('name', l('Please choose a shape')); } $shapes = $CORE->getAvailableShapes(); if (!isset($shapes[$name])) { throw new FieldInputError('name', l('The shape does not exist.')); } // Check whether or not the shape is in use $using = array(); foreach ($CORE->getAvailableMaps() as $map) { $MAPCFG = new GlobalMapCfg($map); try { $MAPCFG->readMapConfig(); } catch (Exception $e) { continue; // don't fail on broken map configs } foreach ($MAPCFG->getDefinitions('shape') as $key => $obj) { if (isset($obj['icon']) && $obj['icon'] == $name) { $using[] = $MAPCFG->getName(); } } } if ($using) { throw new FieldInputError('name', l('Unable to delete this shape, because it is ' . 'currently used by these maps: [M].', array('M' => implode(',', $using)))); } $path = path('sys', '', 'shapes', $name); if ($path !== '') { unlink($path); } success(l('The shape has been deleted.')); //reload(null, 1); } catch (FieldInputError $e) { form_error($e->field, $e->msg); } catch (Exception $e) { if (isset($e->msg)) { form_error(null, $e->msg); } else { throw $e; } } } echo $this->error; js_form_start('delete_shape'); hidden('mode', 'delete'); echo '<table class="mytable">'; echo '<tr><td class="tdlabel">' . l('Shape') . '</td>'; echo '<td class="tdfield">'; $shapes = array('' => l('Choose a shape')); foreach ($CORE->getAvailableShapes() as $name) { $shapes[$name] = $name; } select('name', $shapes); echo '</td></tr>'; echo '</table>'; submit(l('Delete')); form_end(); }
private function getMaps($maps) { global $_BACKEND, $AUTHORISATION; $aObjs = array(); foreach ($maps as $object_id => $mapName) { $MAPCFG = new GlobalMapCfg($mapName); $config_error = null; $error = null; try { $MAPCFG->readMapConfig(); } catch (MapCfgInvalid $e) { $config_error = $e->getMessage(); } catch (Exception $e) { $error = $e->getMessage(); } if ($MAPCFG->getValue(0, 'show_in_lists') != 1 || $MAPCFG->getValue(0, 'show_in_multisite') != 1) { continue; } $MAP = new NagVisMap($MAPCFG, GET_STATE, !IS_VIEW); // Apply mulitsite snapin related configuration to object $objConf = array('type' => 'map', 'map_name' => $MAPCFG->getName(), 'object_id' => $object_id, 'hover_menu' => 0, 'hover_childs_show' => 0, 'hover_template' => 'default', 'parent_map' => $MAPCFG->getValue(0, 'parent_map')); $MAP->MAPOBJ->setConfiguration($objConf); if ($config_error !== null) { $MAP->MAPOBJ->clearMembers(); $MAP->MAPOBJ->setState(array(ERROR, l('Map Configuration Error: ') . $config_error, null, null, null)); $MAP->MAPOBJ->fetchIcon(); } elseif ($error !== null) { $MAP->MAPOBJ->clearMembers(); $MAP->MAPOBJ->setState(array(ERROR, l('Error: ') . $error, null, null, null)); $MAP->MAPOBJ->fetchIcon(); } elseif ($MAP->MAPOBJ->checkMaintenance(0)) { $MAP->MAPOBJ->fetchIcon(); } else { $MAP->MAPOBJ->clearMembers(); $MAP->MAPOBJ->setState(array(UNKNOWN, l('mapInMaintenance'), null, null, null)); $MAP->MAPOBJ->fetchIcon(); } $MAP->MAPOBJ->queueState(GET_STATE, GET_SINGLE_MEMBER_STATES); $aObjs[] = $MAP->MAPOBJ; } $_BACKEND->execute(); $aMaps = array(); foreach ($aObjs as $MAP) { $MAP->applyState(); $MAP->fetchIcon(); $aMaps[] = $MAP->getObjectInformation(); } usort($aMaps, array('GlobalCore', 'cmpAlias')); return $aMaps; }
/** * 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); } } } }
/** * Returns a list of maps for the header menus macro list * * return Array * @author Lars Michelsen <*****@*****.**> */ private function getMapList() { global $_MAINCFG, $CORE, $AUTHORISATION; // Get all the maps global content and use only those which are needed $filename = cfg('paths', 'var') . 'maplist-full-global.cfg-' . CONST_VERSION . '-cache'; $cfgFiles = $CORE->getAvailableMaps(); $path = $CORE->getMainCfg()->getValue('paths', 'mapcfg'); foreach ($cfgFiles as $name) { $cfgFiles[$name] = $path . $name . ".cfg"; } $CACHE = new GlobalFileCache($cfgFiles, cfg('paths', 'var') . 'maplist-full-global.cfg-' . CONST_VERSION . '-cache'); if ($CACHE->isCached() !== -1 && $_MAINCFG->isCached() !== -1 && $CACHE->isCached() >= $_MAINCFG->isCached()) { // Read the whole list from the cache $list = $CACHE->getCache(); } else { // Get all the maps global config sections and cache them $list = array(); foreach ($CORE->getAvailableMaps() as $mapName) { $MAPCFG = new GlobalMapCfg($mapName); try { $MAPCFG->readMapConfig(ONLY_GLOBAL); } catch (MapCfgInvalid $e) { $map['configError'] = true; } catch (NagVisException $e) { $map['configError'] = true; } // Only show maps which should be shown if ($MAPCFG->getValue(0, 'show_in_lists') != 1) { continue; } $list[$mapName] = array('mapName' => $MAPCFG->getName(), 'mapAlias' => $MAPCFG->getValue(0, 'alias'), 'childs' => array(), 'class' => '', 'parent' => $MAPCFG->getValue(0, 'parent_map')); } // Save the list as cache $CACHE->writeCache($list, 1); } $permEditAnyMap = false; $aMaps = array(); $childMaps = array(); // Perform user specific filtering on the cached data foreach ($list as $map) { // Remove unpermitted maps if (!$AUTHORISATION->isPermitted('Map', 'view', $map['mapName'])) { unset($list[$map['mapName']]); continue; } // Change permission to edit $map['permittedEdit'] = $AUTHORISATION->isPermitted('Map', 'edit', $map['mapName']); $permEditAnyMap |= $map['permittedEdit']; if ($map['parent'] === '') { $aMaps[$map['mapName']] = $map; } else { if (!isset($childMaps[$map['parent']])) { $childMaps[$map['parent']] = array(); } $childMaps[$map['parent']][$map['mapName']] = $map; } } // auto select current map and apply map specific options to the header menu if ($this->OBJ !== null && $this->aMacros['mod'] == 'Map' && isset($list[$this->OBJ->getName()])) { $list[$this->OBJ->getName()]['selected'] = True; } return array($this->mapListToTree($aMaps, $childMaps), $permEditAnyMap); }
private function deleteForm() { global $CORE; echo '<h2>' . l('Delete Background') . '</h2>'; if (is_action() && post('mode') == 'delete') { try { $name = post('name'); if (!$name) { throw new FieldInputError('name', l('Please choose a background')); } if (count($CORE->getAvailableBackgroundImages('/^' . preg_quote($name) . '$/')) == 0) { throw new FieldInputError('name', l('The background does not exist.')); } // Check whether or not the backgroun is in use $using = array(); foreach ($CORE->getAvailableMaps() as $map) { $MAPCFG = new GlobalMapCfg($map); try { $MAPCFG->readMapConfig(ONLY_GLOBAL); } catch (Exception $e) { continue; // don't fail on broken map configs } $bg = $MAPCFG->getValue(0, 'map_image'); if (isset($bg) && $bg == $name) { $using[] = $MAPCFG->getName(); } } if ($using) { throw new FieldInputError('name', l('Unable to delete this background, because it is ' . 'currently used by these maps: [M].', array('M' => implode(',', $using)))); } $BACKGROUND = new GlobalBackground($name); $BACKGROUND->deleteImage(); success(l('The background has been deleted.')); //reload(null, 1); } catch (FieldInputError $e) { form_error($e->field, $e->msg); } catch (Exception $e) { if (isset($e->msg)) { form_error(null, $e->msg); } else { throw $e; } } } echo $this->error; js_form_start('delete'); hidden('mode', 'delete'); echo '<table class="mytable">'; echo '<tr><td class="tdlabel">' . l('Background') . '</td>'; echo '<td class="tdfield">'; $images = array('' => l('Choose a background')); foreach ($CORE->getAvailableBackgroundImages() as $name) { $images[$name] = $name; } select('name', $images); echo '</td></tr>'; echo '</table>'; submit(l('Delete')); form_end(); }