public function initialize(AgaviContext $context, array $parameters = array()) { parent::initialize($context, $parameters); $this->config = (include AgaviConfigCache::checkConfig(AgaviToolkit::expandDirectives('%core.module_dir%/Api/config/icingaCommands.xml'))); $this->user = $context->getUser(); if ($this->user->getNsmUser()->hasTarget('IcingaCommandRestrictions')) { $this->filterCommandsByUser($this->config); } }
public function onMatched(array &$parameters, AgaviExecutionContainer $container) { $validation = $container->getValidationManager(); $errors = array(); if (isset($parameters['authkey'])) { $container->setAttribute('flag', true, 'org.icinga.api.auth'); try { $this->user->doAuthKeyLogin($parameters['authkey']); } catch (AgaviSecurityException $e) { $errors[] = 'Log in failed by authkey'; } } if ($this->checkAuthorisation() == false) { $errors[] = self::INSUFFICIENT_MSG; } if (count($errors)) { $container->setAttributeByRef('errors', $errors, 'org.icinga.api.auth'); $container->setAttribute('success', false, 'org.icinga.api.auth'); return false; } $container->setAttribute('success', true, 'org.icinga.api.auth'); return true; }
/** * Create of update a category * @param array $cat * @return Ambigous <NULL, CronkCategory> */ public function createCategory(array $cat) { AppKitArrayUtil::swapKeys($cat, self::$cat_map, true); $category = null; if ($this->agaviUser->hasCredential('icinga.cronk.category.admin') && isset($cat['cc_uid'])) { $category = AppKitDoctrineUtil::createQuery()->from('CronkCategory cc')->andWhere('cc.cc_uid=?', $cat['cc_uid'])->execute()->getFirst(); } if (!$category instanceof CronkCategory || !$category->cc_id > 0) { $category = new CronkCategory(); } $category->fromArray($cat); $category->save(); return $category; }
public function deleteCronkRecord($cronkid, $cronkname, $own = true) { if ($this->agaviUser->hasCredential('icinga.cronk.custom') === false && $this->agaviUser->hasCredential('icinga.cronk.admin') === false) { throw new AppKitModelException('No access to delete cronks!'); } $q = AppKitDoctrineUtil::createQuery()->select('c.*')->from('Cronk c')->where('c.cronk_uid=?', array($cronkid)); if ($own == true && $this->agaviUser->hasCredential('icinga.cronk.admin') === false) { $q->andWhere('c.cronk_user_id=?', array($this->user->user_id)); } $cronk = $q->execute()->getFirst(); if ($cronk instanceof Cronk && $cronk->cronk_id > 0) { AppKitDoctrineUtil::getConnection()->beginTransaction(); $params = array($cronk->cronk_id); AppKitDoctrineUtil::createQuery()->delete('CronkCategoryCronk c')->andWhere('c.ccc_cronk_id=?')->execute($params); AppKitDoctrineUtil::createQuery()->delete('CronkPrincipalCronk c')->andWhere('c.cpc_cronk_id=?')->execute($params); AppKitDoctrineUtil::getConnection()->commit(); $cronk->delete(); return true; } else { throw new AppKitModelException('Could not delete cronk: ' . $cronkid); } }
private function getCacheFile() { $prefix = 'cache_' . $this->uniqueCacheIdentifier . '_' . $this->user->getNsmUser()->user_name . '_' . sha1($this->getCacheKey()) . '.json'; return $this->cacheDir . '/' . $prefix; }
private function getNewFilename($extension) { $username = $this->__user->getNsmUser()->user_name; $md5 = md5($username . '-' . microtime(true) . '-' . getmypid()); return sprintf('%s_%s.%s', $username, $md5, $extension); }