/** * Class Constructor * * @param GlobalMainCfg $MAINCFG * @param GlobalMapCfg $MAPCFG * @author Lars Michelsen <*****@*****.**> */ public function __construct($MAPCFG, $getState = GET_STATE, $bIsView = IS_VIEW) { global $_BACKEND; $this->MAPCFG = $MAPCFG; if ($getState === GET_STATE) { $this->MAPOBJ = new NagVisMapObj($MAPCFG, $bIsView); // FIXME: needed? $this->MAPOBJ->setConfiguration($this->MAPCFG->getTypeDefaults('global')); $objConf = $MAPCFG->getMapObject(0); unset($objConf['type']); $this->MAPOBJ->setConfiguration($objConf); log_mem('postmapinit'); $this->MAPOBJ->fetchMapObjects(); log_mem('map ' . $this->MAPCFG->getName() . ' ' . count($this->MAPOBJ->getMembers())); log_mem('postmapobjects'); if ($bIsView === IS_VIEW) { $this->MAPOBJ->queueState(GET_STATE, GET_SINGLE_MEMBER_STATES); $_BACKEND->execute(); $this->MAPOBJ->applyState(); log_mem('postmapstate'); } else { $this->MAPOBJ->queueState(GET_STATE, DONT_GET_SINGLE_MEMBER_STATES); log_mem('postmapstatequeue'); } } }
public function parse($orig_name) { global $CORE; ob_start(); if (is_action()) { try { $name = post('name'); if (!$name) { throw new FieldInputError('name', l('Please provide a map name.')); } if (!preg_match(MATCH_MAP_NAME, $name)) { throw new FieldInputError('name', l('This is not a valid map name (need to match [M])', array('M' => MATCH_MAP_NAME))); } if (count($CORE->getAvailableMaps('/^' . $name . '$/')) > 0) { throw new FieldInputError('name', l('A map with this name already exists.')); } // Read the old config $MAPCFG = new GlobalMapCfg($orig_name); $MAPCFG->readMapConfig(); // Create a new map config $NEW = new GlobalMapCfg($name); $NEW->createMapConfig(); foreach ($MAPCFG->getMapObjects() as $object_id => $cfg) { $NEW->addElement($cfg['type'], $cfg, $perm = true, $object_id); } success(l('The map has been created.')); reload(cfg('paths', 'htmlbase') . '/frontend/nagvis-js/index.php?mod=Map&show=' . $name, 1); } catch (FieldInputError $e) { form_error($e->field, $e->msg); } catch (NagVisException $e) { form_error(null, $e->message()); } catch (Exception $e) { if (isset($e->msg)) { form_error(null, $e->msg); } else { throw $e; } } } echo $this->error; echo '<div class="simple_form">' . N; js_form_start('to_new_map'); input('name'); submit(l('Save')); focus('name'); // Keep the view parameters the users has set $params = ltrim(req('view_params'), '&'); if ($params) { $parts = explode('&', $params); foreach ($parts as $part) { list($key, $val) = explode('=', $part); hidden($key, $val); } } form_end(); echo '</div>' . N; return ob_get_clean(); }
public function parseWithMap($e, $map_name) { $MAPCFG = new GlobalMapCfg($map_name); try { $MAPCFG->readMapConfig(ONLY_GLOBAL); } catch (MapCfgInvalid $e) { } return $this->parse($e, $MAPCFG); }
private function showViewDialog() { global $AUTHORISATION; // Initialize map configuration $MAPCFG = new GlobalMapCfg($this->name); // Read the map configuration file (Only global section!) $MAPCFG->readMapConfig(ONLY_GLOBAL); // Get all source parameters $opts = $MAPCFG->getSourceParams(); // Build index template $INDEX = new NagVisIndexView($this->CORE); // Need to load the custom stylesheet? $customStylesheet = $MAPCFG->getValue(0, 'stylesheet'); if ($customStylesheet !== '') { $INDEX->setCustomStylesheet(path('html', 'global', 'styles', $customStylesheet)); } // Need to parse the header menu by config or url value? if (isset($opts['header_menu']) && $opts['header_menu']) { // Parse the header menu $HEADER = new NagVisHeaderMenu($MAPCFG->getValue(0, 'header_template'), $MAPCFG); // Put rotation information to header menu if ($this->rotation != '') { $HEADER->setRotationEnabled(); } $INDEX->setHeaderMenu($HEADER->__toString()); } // Initialize map view $this->VIEW = new NagVisMapView($this->CORE, $this->name); $this->VIEW->setParams($opts); // The user is searching for an object $this->VIEW->setSearch($this->search); // Enable edit mode for all objects if ($this->sAction == 'edit') { $this->VIEW->setEditMode(); } // Maybe it is needed to handle the requested rotation if ($this->rotation != '') { // Only allow the rotation if the user is permitted to use it if ($AUTHORISATION->isPermitted('Rotation', 'view', $this->rotation)) { $ROTATION = new FrontendRotation($this->rotation); $ROTATION->setStep('map', $this->name, $this->rotationStep); $this->VIEW->setRotation($ROTATION->getRotationProperties()); } } $INDEX->setContent($this->VIEW->parse()); return $INDEX->parse(); }
public function handleAction() { global $CORE; $sReturn = ''; if ($this->offersAction($this->sAction)) { switch ($this->sAction) { case 'custom_action': $aOpts = array('map' => MATCH_MAP_NAME, 'object_id' => MATCH_OBJECTID, 'cmd' => MATCH_STRING_NO_SPACE); $attrs = $this->getCustomOptions($aOpts, array()); // Input validations // - Valid custom action? $actions = $CORE->getDefinedCustomActions(); if (!isset($actions[$attrs['cmd']])) { throw new NagVisException(l('The given custom action is not defined.')); } // - does the map exist? if (count($CORE->getAvailableMaps('/^' . $attrs['map'] . '$/')) <= 0) { throw new NagVisException(l('The map does not exist.')); } // - does the object exist on the map? $MAPCFG = new GlobalMapCfg($attrs['map']); $MAPCFG->skipSourceErrors(); $MAPCFG->readMapConfig(); if (!isset($attrs['object_id']) && $attrs['object_id'] == '') { throw new NagVisException(l('The object_id value is missing.')); } if (!$MAPCFG->objExists($attrs['object_id'])) { throw new NagVisException(l('The object does not exist.')); } $objId = $attrs['object_id']; $func = 'handle_action_' . $attrs['cmd']; if (!function_exists($func)) { throw new NagVisException(l('Action handler not implemented.')); } $func($MAPCFG, $objId); break; case 'acknowledge': $VIEW = new ViewAck(); $sReturn = json_encode(array('code' => $VIEW->parse())); break; } } return $sReturn; }
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); }
/** * Loads the valid configuration definitions from the mapcfg files. * Those files define the options which are available for the different * object types. The Infos fetched from these files contain all data about * the options like variable format, validation regexes and so on. */ private function fetchValidConfig() { global $CORE; self::$validConfig = array(); // Holds all registered config vars $mapConfigVars = array(); // Maps the config vars to the object types $mapConfigVarMap = array(); $path = cfg('paths', 'server') . '/mapcfg'; $files = $CORE->listDirectory($path, MATCH_PHP_FILE); foreach ($files as $f) { include_once realpath($path . '/' . $f); } // Now register the variables for the object types $this->registerConfigVars($mapConfigVars, $mapConfigVarMap); }
private function deleteForm() { global $CORE; echo '<h2>' . l('Delete Map') . '</h2>'; if (is_action() && post('mode') == 'delete') { try { $name = post('name'); if (!$name) { throw new FieldInputError('name', l('Please choose a map')); } if (count($CORE->getAvailableMaps('/^' . preg_quote($name) . '$/')) == 0) { throw new FieldInputError('name', l('The given map name is invalid')); } $MAPCFG = new GlobalMapCfg($name); try { $MAPCFG->readMapConfig(); } catch (MapCfgInvalid $e) { } $MAPCFG->deleteMapConfig(); success(l('The map has been deleted.')); $cur_map = post('current_map'); if ($cur_map && $cur_map == $name) { reload('index.php', 1); } // change to overview page when current map has been deleted } 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_map'); hidden('mode', 'delete'); // eventual currently open map, needed for redirecting the user if the // renamed map is currently open hidden('current_map', ''); js('document.getElementById(\'current_map\').value = oPageProperties.map_name;'); echo '<table class="mytable">'; echo '<tr><td class="tdlabel">' . l('Map') . '</td>'; echo '<td class="tdfield">'; $maps = array('' => l('Choose a map')); foreach ($CORE->getAvailableMaps() as $map) { $maps[$map] = $map; } select('name', $maps); echo '</td></tr>'; echo '</table>'; submit(l('Delete')); form_end(); }
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 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(); }
private function deleteForm() { global $CORE; echo '<h2>' . l('Delete Template') . '</h2>'; $map_name = req('show'); if (!$map_name) { throw new NagVisException(l('Map name missing')); } if (count($CORE->getAvailableMaps('/^' . preg_quote($map_name) . '$/')) == 0) { throw new NagVisException(l('A map with this name does not exists')); } $MAPCFG = new GlobalMapCfg($map_name); $MAPCFG->readMapConfig(!ONLY_GLOBAL, false, false); if (is_action() && post('mode') == 'delete') { try { $name = post('name'); if (count($MAPCFG->getTemplateNames('/^' . $name . '$/')) == 0) { throw new FieldInputError('name', l('A template with this name does not exist.')); } $obj_id = $MAPCFG->getTemplateIdByName($name); $MAPCFG->deleteElement($obj_id, true); success(l('The template has been deleted.')); } catch (FieldInputError $e) { form_error($e->field, $e->msg); } catch (NagVisException $e) { form_error(null, $e->message()); } 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('Name') . '</td>'; echo '<td class="tdfield">'; $choices = array('' => l('Please choose')); foreach (array_keys($MAPCFG->getTemplateNames()) as $tmpl_name) { $choices[$tmpl_name] = $tmpl_name; } select('name', $choices, '', 'updateForm(this.form)'); echo '</td></tr>'; echo '</table>'; submit(l('Delete')); form_end(); }
public function parse() { global $CORE, $_BACKEND, $AUTH; ob_start(); $map = req('map'); if (!$map || count($CORE->getAvailableMaps('/^' . $map . '$/')) == 0) { throw new NagVisException(l('Please provide a valid map name.')); } $object_id = req('object_id'); if (!$object_id || !preg_match(MATCH_OBJECTID, $object_id)) { throw new NagVisException(l('Please provide a valid object id.')); } $MAPCFG = new GlobalMapCfg($map); $MAPCFG->skipSourceErrors(); $MAPCFG->readMapConfig(); if (!$MAPCFG->objExists($object_id)) { throw new NagVisException(l('The object does not exist.')); } $backendIds = $MAPCFG->getValue($object_id, 'backend_id'); foreach ($backendIds as $backendId) { if (!$_BACKEND->checkBackendFeature($backendId, 'actionAcknowledge', false)) { return '<div class=err>' . l('The requested feature is not available for this backend. ' . 'The MKLivestatus backend supports this feature.') . '</div>'; } } if (is_action()) { try { $type = $MAPCFG->getValue($object_id, 'type'); if ($type == 'host') { $spec = $MAPCFG->getValue($object_id, 'host_name'); } else { $spec = $MAPCFG->getValue($object_id, 'host_name') . ';' . $MAPCFG->getValue($object_id, 'service_description'); } $comment = post('comment'); if (!$comment) { throw new FieldInputError('comment', l('You need to provide a comment.')); } $sticky = get_checkbox('sticky'); $notify = get_checkbox('notify'); $persist = get_checkbox('persist'); // Now send the acknowledgement foreach ($backendIds as $backendId) { $BACKEND = $_BACKEND->getBackend($backendId); $BACKEND->actionAcknowledge($type, $spec, $comment, $sticky, $notify, $persist, $AUTH->getUser()); } success(l('The problem has been acknowledged.')); js('window.setTimeout(function() {' . 'popupWindowClose(); refreshMapObject(null, \'' . $object_id . '\');}, 2000);'); } catch (FieldInputError $e) { form_error($e->field, $e->msg); } catch (NagVisException $e) { form_error(null, $e->message()); } catch (Exception $e) { if (isset($e->msg)) { form_error(null, $e->msg); } else { throw $e; } } } echo $this->error; js_form_start('acknowledge'); echo '<label>' . l('Comment'); input('comment'); echo '</label>'; echo '<label>'; checkbox('sticky', cfg('global', 'dialog_ack_sticky')); echo l('Sticky') . '</label>'; echo '<label>'; checkbox('notify', cfg('global', 'dialog_ack_notify')); echo l('Notify contacts') . '</label>'; echo '<label>'; checkbox('persist', cfg('global', 'dialog_ack_persist')); echo l('Persist comment') . '</label>'; submit(l('Acknowledge')); form_end(); focus('comment'); return ob_get_clean(); }
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; }
private function getObjectStates() { $aOpts = array('ty' => MATCH_GET_OBJECT_TYPE, 'i' => MATCH_STRING_NO_SPACE_EMPTY, 'f' => MATCH_STRING_NO_SPACE_EMPTY); $aVals = $this->getCustomOptions($aOpts, array(), true); // Is this request asked to check file ages? if (isset($aVals['f']) && isset($aVals['f'][0]) && $aVals['f'] != '') { $result = $this->checkFilesChanged($aVals['f']); if ($result !== null) { return $result; } } // Initialize map configuration (Needed in getMapObjConf) $MAPCFG = new GlobalMapCfg($this->name); $MAPCFG->readMapConfig(); // i might not be set when all map objects should be fetched or when only // the summary of the map is called if (isset($aVals['i']) && $aVals['i'] != '') { $MAPCFG->filterMapObjects($aVals['i']); } $MAP = new NagVisMap($MAPCFG, GET_STATE, IS_VIEW); return $MAP->parseObjectsJson($aVals['ty']); }
/** * 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); }
/** * Is called with an array of files and timestamps to check if the file ages * have changed since these timestamps. * * Returns null when nothing changed or a structure of the changed objects */ protected function checkFilesChanged($files) { global $AUTHORISATION, $CORE; $changed = array(); foreach ($files as $file) { $parts = explode(',', $file); // Skip invalid requested files if (count($parts) != 3) { continue; } list($ty, $name, $age) = $parts; $age = (int) $age; // Try to fetch the current age of the requested file $cur_age = null; if ($ty == 'maincfg') { $cur_age = $CORE->getMainCfg()->getConfigFileAge(); } elseif ($ty == 'map') { if ($AUTHORISATION->isPermitted('Map', 'view', $name)) { $MAPCFG = new GlobalMapCfg($name); $MAPCFG->readMapConfig(); $cur_age = $MAPCFG->getFileModificationTime($age); } } // Check if the file has changed; Reply with the changed timestamps if ($cur_age !== null && $cur_age > $age) { $changed[$name] = $cur_age; } } if (count($changed) > 0) { return json_encode(array('status' => 'CHANGED', 'data' => $changed)); } else { return null; } }
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); }