예제 #1
0
 private function errorPage($e)
 {
     global $_MAINCFG;
     ob_start();
     $USERCFG = new CoreUserCfg();
     js('oGeneralProperties = ' . $_MAINCFG->parseGeneralProperties() . ';' . N . 'oUserProperties = ' . $USERCFG->doGetAsJson() . ';' . N);
     echo '<div id="page">';
     js('frontendMessage({' . N . '    "type"    : "error",' . N . '    "closable": false,' . N . '    "title"   : "' . l('Error') . '",' . N . '    "message" : "' . htmlentities($e->getMessage(), ENT_COMPAT, 'UTF-8') . '"' . N . '});');
     echo '</div>';
     return ob_get_clean();
 }
예제 #2
0
 /**
  * Parses the information for json
  *
  * @return	String 	String with Html Code
  * @author 	Lars Michelsen <*****@*****.**>
  */
 public function parse()
 {
     global $_MAINCFG, $CORE;
     // Initialize template system
     $TMPL = new FrontendTemplateSystem();
     $TMPLSYS = $TMPL->getTmplSys();
     $USERCFG = new CoreUserCfg();
     $maps = cfg('index', 'showmaps') == 1 ? $CORE->getListMaps() : array();
     $rotations = cfg('index', 'showrotations') == 1 ? array_keys($CORE->getPermittedRotationPools()) : array();
     $aData = array('generalProperties' => $_MAINCFG->parseGeneralProperties(), 'workerProperties' => $_MAINCFG->parseWorkerProperties(), 'stateProperties' => json_encode($_MAINCFG->getStateWeightJS()), 'userProperties' => $USERCFG->doGetAsJson(), 'pageProperties' => json_encode($this->getProperties()), 'fileAges' => json_encode(array('maincfg' => $_MAINCFG->getConfigFileAge())), 'locales' => json_encode($CORE->getGeneralJSLocales()), 'rotation_names' => json_encode($rotations), 'map_names' => json_encode($maps));
     // Build page based on the template file and the data array
     return $TMPLSYS->get($TMPL->getTmplFile(cfg('defaults', 'view_template'), 'overview'), $aData);
 }
예제 #3
0
 /**
  * Parses the map and the objects for the nagvis-js frontend
  *
  * @return	String 	String with JS Code
  * @author 	Lars Michelsen <*****@*****.**>
  */
 public function parse()
 {
     global $_MAINCFG, $CORE;
     // Initialize template system
     $TMPL = new FrontendTemplateSystem();
     $TMPLSYS = $TMPL->getTmplSys();
     $USERCFG = new CoreUserCfg();
     $this->MAPCFG = new GlobalMapCfg($this->name);
     $this->MAPCFG->readMapConfig(ONLY_GLOBAL, true, true, true);
     $aData = array('generalProperties' => $_MAINCFG->parseGeneralProperties(), 'workerProperties' => $_MAINCFG->parseWorkerProperties(), 'rotationProperties' => json_encode($this->aRotation), 'viewProperties' => $this->parseViewProperties(), 'stateProperties' => json_encode($_MAINCFG->getStateWeightJS()), 'pageProperties' => json_encode($this->MAPCFG->getMapProperties()), 'userProperties' => $USERCFG->doGetAsJson(), 'mapName' => $this->name, 'zoomFill' => $this->MAPCFG->getValue(0, 'zoom') == 'fill', 'fileAges' => json_encode(array('maincfg' => $_MAINCFG->getConfigFileAge(), $this->name => $this->MAPCFG->getFileModificationTime())), 'locales' => json_encode($CORE->getGeneralJSLocales()));
     // Build page based on the template file and the data array
     return $TMPLSYS->get($TMPL->getTmplFile(cfg('defaults', 'view_template'), 'map'), $aData);
 }
예제 #4
0
 private function handleAddModify()
 {
     $perm = get_checkbox('perm');
     $perm_user = get_checkbox('perm_user');
     $show_dialog = false;
     // Modification/Creation?
     // The object_id is known on modification. When it is not known 'type' is set
     // to create new objects
     if ($this->object_id !== null) {
         // The handler has been called in "view_params" mode. In this case the user has
         // less options and the options to
         // 1. modify these parameters only for the current open view
         // 2. Save the changes for himselfs
         // 3. Save the changes to the map config (-> Use default code below)
         if ($this->mode == 'view_params' && !$perm && !$perm_user) {
             // This is the 1. case -> redirect the user to a well formated url
             $attrs = array_merge($this->attrs, $this->attrs_filtered);
             unset($attrs['object_id']);
             js('document.getElementById("_submit").disabled = true;' . 'window.location.href = makeuri(' . json_encode($attrs) . ');');
             $show_dialog = true;
         } elseif ($this->mode == 'view_params' && !$perm && $perm_user) {
             // This is the 2. case -> saving the options only for the user
             $USERCFG = new CoreUserCfg();
             $attrs = $this->attrs;
             unset($attrs['object_id']);
             $USERCFG->doSet(array('params-' . $this->MAPCFG->getName() => $attrs));
             scroll_up();
             // On success, always scroll to top of page
             success(l('Personal settings saved.'));
             js('document.getElementById("_submit").disabled = true;' . 'window.setTimeout(function() { window.location.reload(); }, 2000);');
             $show_dialog = true;
         } else {
             if (!$this->MAPCFG->objExists($this->object_id)) {
                 throw new NagVisException(l('The object does not exist.'));
             }
             $this->validateAttributes();
             // Update the map configuration
             if ($this->mode == 'view_params') {
                 // Only modify/add the given attributes. Don't remove any
                 // set options in the array
                 foreach ($this->attrs as $key => $val) {
                     $this->MAPCFG->setValue($this->object_id, $key, $val);
                 }
                 $this->MAPCFG->storeUpdateElement($this->object_id);
             } else {
                 // add/modify case: Rewrite whole object with the given attributes
                 $this->MAPCFG->updateElement($this->object_id, $this->attrs, true);
             }
             $t = $this->object_type == 'global' ? l('map configuration') : $this->object_type;
             $result = array(2, null, l('The [TYPE] has been modified. Reloading in 2 seconds.', array('TYPE' => $t)));
             js('popupWindowClose();' . 'refreshMapObject(null, "' . $this->object_id . '", false);');
         }
     } else {
         // Create the new object
         $this->validateAttributes();
         // append a new object definition to the map configuration
         $obj_id = $this->MAPCFG->addElement($this->object_type, $this->attrs, true);
         js('popupWindowClose();' . 'refreshMapObject(null, "' . $obj_id . '", false);');
     }
     // delete map lock
     if (!$this->MAPCFG->deleteMapLock()) {
         throw new NagVisException(l('mapLockNotDeleted'));
     }
     return $show_dialog;
 }
예제 #5
0
 public function getSourceParam($key, $only_user_supplied = false, $only_customized = false)
 {
     // Allow _GET or _POST (_POST is needed for add/modify dialog submission)
     if (isset($_REQUEST[$key])) {
         // Only get options which differ from the defaults
         // Maybe convert the type, if requested
         if (isset(self::$validConfig['global'][$key]['array']) && self::$validConfig['global'][$key]['array'] === true) {
             if ($_REQUEST[$key] !== '') {
                 $val = explode(',', $_REQUEST[$key]);
             } else {
                 $val = array();
             }
         } else {
             $val = $_REQUEST[$key];
         }
         if (!$only_customized || $val != $this->getValue(0, $key)) {
             return $val;
         }
     } else {
         // Try to use the user profile
         $USERCFG = new CoreUserCfg();
         $userParams = $USERCFG->getValue('params-' . $this->name);
         if (isset($userParams[$key])) {
             return $userParams[$key];
         } elseif (!$only_user_supplied) {
             // Otherwise use the map global value (if allowed)
             return $this->getValue(0, $key);
         }
     }
     return null;
 }
예제 #6
0
 protected function doSet($a)
 {
     $CFG = new CoreUserCfg();
     return $CFG->doSet($a['opts']);
 }
예제 #7
0
 /**
  * PRIVATE getMacros()
  *
  * Returns all macros for the header template
  *
  * @author	Lars Michelsen <*****@*****.**>
  */
 private function getMacros()
 {
     global $CORE, $AUTH, $AUTHORISATION, $UHANDLER;
     // First get all static macros
     $this->aMacros = $this->getStaticMacros();
     // Save the page
     $this->aMacros['mod'] = $UHANDLER->get('mod');
     $this->aMacros['act'] = $UHANDLER->get('act');
     // In rotation?
     $this->aMacros['bRotation'] = $this->bRotation;
     $this->aMacros['permittedOverview'] = $AUTHORISATION->isPermitted('Overview', 'view', '*');
     // Check if the user is permitted to edit the current map
     $this->aMacros['permittedView'] = $AUTHORISATION->isPermitted($this->aMacros['mod'], 'view', $UHANDLER->get('show'));
     $this->aMacros['permittedEdit'] = $AUTHORISATION->isPermitted($this->aMacros['mod'], 'edit', $UHANDLER->get('show'));
     // Permissions for the option menu
     $this->aMacros['permittedSearch'] = $AUTHORISATION->isPermitted('Search', 'view', '*');
     $this->aMacros['permittedEditMainCfg'] = $AUTHORISATION->isPermitted('MainCfg', 'edit', '*');
     $this->aMacros['permittedManageShapes'] = $AUTHORISATION->isPermitted('ManageShapes', 'manage', '*');
     $this->aMacros['permittedManageBackgrounds'] = $AUTHORISATION->isPermitted('ManageBackgrounds', 'manage', '*');
     $this->aMacros['permittedManageBackgrounds'] = $AUTHORISATION->isPermitted('ManageBackgrounds', 'manage', '*');
     $this->aMacros['permittedManageMaps'] = $AUTHORISATION->isPermitted('Map', 'add', '*') && $AUTHORISATION->isPermitted('Map', 'edit', '*');
     $this->aMacros['currentUser'] = $AUTH->getUser();
     $this->aMacros['permittedChangePassword'] = $AUTHORISATION->isPermitted('ChangePassword', 'change', '*');
     $this->aMacros['permittedLogout'] = $AUTH->logoutSupported() & $AUTHORISATION->isPermitted('Auth', 'logout', '*');
     // Replace some special macros for maps
     if ($this->OBJ !== null && $this->aMacros['mod'] == 'Map') {
         $this->aMacros['currentMap'] = $this->OBJ->getName();
         $this->aMacros['currentMapAlias'] = $this->OBJ->getValue(0, 'alias');
         $this->aMacros['usesSources'] = count($this->OBJ->getValue(0, 'sources')) > 0;
         $this->aMacros['zoombar'] = $this->OBJ->getValue(0, 'zoombar');
         $this->aMacros['canAddObjects'] = !in_array('automap', $this->OBJ->getValue(0, 'sources')) && !in_array('geomap', $this->OBJ->getValue(0, 'sources'));
         $this->aMacros['canEditObjects'] = !in_array('automap', $this->OBJ->getValue(0, 'sources'));
         $this->aMacros['canMoveObjects'] = !in_array('automap', $this->OBJ->getValue(0, 'sources')) && !in_array('geomap', $this->OBJ->getValue(0, 'sources'));
         $this->aMacros['isWorldmap'] = in_array('worldmap', $this->OBJ->getValue(0, 'sources'));
     } else {
         $this->aMacros['currentMap'] = '';
         $this->aMacros['currentMapAlias'] = '';
         $this->aMacros['usesSources'] = false;
         $this->aMacros['zoombar'] = false;
         $this->aMacros['canAddObjects'] = false;
         $this->aMacros['canEditObjects'] = false;
         $this->aMacros['canMoveObjects'] = false;
         $this->aMacros['isWorldmap'] = true;
     }
     // Add permitted rotations
     $this->aMacros['rotations'] = array();
     foreach ($CORE->getDefinedRotationPools() as $poolName) {
         if ($AUTHORISATION->isPermitted('Rotation', 'view', $poolName)) {
             $this->aMacros['rotations'][] = $poolName;
         }
     }
     list($this->aMacros['maps'], $this->aMacros['permittedEditAnyMap']) = $this->getMapList();
     $this->aMacros['langs'] = $this->getLangList();
     // Specific information for special templates
     if ($this->templateName == 'on-demand-filter') {
         global $_BACKEND;
         $this->aMacros['hostgroups'] = $_BACKEND->getBackend($_GET['backend_id'])->getObjects('hostgroup', '', '');
         usort($this->aMacros['hostgroups'], array($this, 'sortHostgroups'));
         array_unshift($this->aMacros['hostgroups'], array('name1' => '', 'name2' => ''));
         $default = '';
         $USERCFG = new CoreUserCfg();
         $cfg = $USERCFG->doGet();
         if (isset($cfg['params-']) && isset($cfg['params-']['filter_group'])) {
             $default = $cfg['params-']['filter_group'];
         }
         $this->aMacros['filter_group'] = isset($_GET['filter_group']) ? htmlspecialchars($_GET['filter_group']) : $default;
     }
     $this->aMacros['mapNames'] = json_encode($CORE->getListMaps());
 }