Example #1
0
 private function renderMapThumb($MAPCFG)
 {
     global $CORE;
     $imgPath = $MAPCFG->BACKGROUND->getFile(GET_PHYSICAL_PATH);
     // Check if
     // a) PHP supports gd
     // b) The image is a local one
     // c) The image exists
     // When one is not OK, then use the large map image
     if (!$CORE->checkGd(0) || !$MAPCFG->BACKGROUND->getFileType() == 'local' || !file_exists($imgPath)) {
         return $MAPCFG->BACKGROUND->getFile();
     }
     $sThumbFile = $MAPCFG->getName() . '-thumb.' . $this->getFileType($imgPath);
     $sThumbPath = cfg('paths', 'sharedvar') . $sThumbFile;
     $sThumbPathHtml = cfg('paths', 'htmlsharedvar') . $sThumbFile;
     // Only create a new thumb when there is no cached one
     $FCACHE = new GlobalFileCache($imgPath, $sThumbPath);
     if ($FCACHE->isCached() === -1) {
         $image = $this->createThumbnail($imgPath, $sThumbPath);
     }
     return $sThumbPathHtml;
 }
Example #2
0
 /**
  * A source can modify the map configuration before it is used for further processing.
  * Such a source is a key which points to a "process", "params" and "changed" function
  * which can
  *  1. modify the map config array
  *  2. gather all the parameters used in this source
  *  3. tell the source processing that the data used in this source has changed and the
  *     source needs processed again
  */
 private function processSources()
 {
     global $_MAINCFG;
     $sources = $this->getValue(0, 'sources');
     if (!$sources) {
         return;
     }
     // 1.  Check if there is a cache file for a query with this params
     $params = $this->getSourceParams();
     // FIXME: Add a flag to exclude options from cache file naming
     if (isset($params['source_file'])) {
         unset($params['source_file']);
     }
     $param_values = $this->paramsToString($params);
     $cacheFile = cfg('paths', 'var') . 'source-' . $this->name . '.cfg-' . $param_values . '-' . CONST_VERSION . '.cache';
     $CACHE = new GlobalFileCache(array(), $cacheFile);
     // 2a. Check if the cache file exists
     // 2b. Check if the cache file is newer than the latest changed source
     $cache_sources = $CACHE->isCached();
     $cache_map = $this->CACHE->isCached();
     $cache_maincfg = $_MAINCFG->isCached();
     if ($cache_sources != -1 && $cache_map != -1 && $cache_maincfg != -1 && $cache_sources >= $cache_maincfg && $cache_sources >= $cache_map && !$this->sourcesChanged($cache_sources)) {
         // 3a. Use the cache
         $this->mapConfig = $CACHE->getCache();
         return;
     }
     $cacheable = true;
     // 3b. Process all the sources
     foreach ($sources as $source) {
         $func = 'process_' . $source;
         if (!function_exists($func)) {
             throw new NagVisException(l('Requested source "[S]" does not exist', array('S' => $source)));
         }
         try {
             $cacheable &= $func($this, $this->name, $this->mapConfig);
         } catch (Exception $e) {
             if (!$this->ignoreSourceErrors) {
                 throw $e;
             }
         }
     }
     // Call process filter implicit if not already done
     process_filter($this, $this->name, $this->mapConfig);
     if ($cacheable) {
         $CACHE->writeCache($this->mapConfig, 1);
     }
     // FIXME: Invalidate/remove cache files on changed configurations
 }
Example #3
0
 private function getMapsCached()
 {
     $maps = $this->CORE->getPermittedMaps();
     $cache_file = cfg('paths', 'var') . 'snapin-' . md5(json_encode(array_keys($maps))) . '-' . CONST_VERSION . '.cache';
     $CACHE = new GlobalFileCache(array(), $cache_file);
     $cached = $CACHE->isCached();
     if ($cached != -1 && time() - $cached < 15) {
         return $CACHE->getCache();
     } else {
         $result = $this->getMaps($maps);
         $CACHE->writeCache($result);
         return $result;
     }
 }
Example #4
0
 /**
  * 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);
 }