예제 #1
0
 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();
 }
예제 #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
파일: ViewAck.php 프로젝트: rbarraud/nagvis
 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();
 }
예제 #4
0
 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;
 }
예제 #5
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);
 }
예제 #6
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);
 }
예제 #7
0
 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();
 }