protected function onSetup()
 {
     if ($this->hasBeenSubmitted()) {
         // Do not hinder the form from being stored
         return;
     }
     if ($this->hasBeenSent() && $this->isValidPartial($this->getRequest()->getPost())) {
         $resourceName = $this->getValue('resource');
     } else {
         $resourceName = $this->config()->get('db', 'resource');
     }
     if ($resourceName) {
         $resourceConfig = ResourceFactory::getResourceConfig($resourceName);
         if (!isset($resourceConfig->charset) || $resourceConfig->charset !== 'utf8') {
             $this->getElement('resource')->addError('Please change the encodig for the director database to utf8')->removeDecorator('description');
         }
         $resource = ResourceFactory::create($resourceName);
         $db = $resource->getDbAdapter();
         try {
             $query = $db->select()->from('director_dbversion', 'COUNT(*)');
             $db->fetchOne($query);
             if (!$this->hasBeenSent()) {
                 $hint = $this->translate('Configuration looks good, you should be ready to %s' . ' Icinga Director');
                 $link = $this->getView()->qlink($this->translate('start using'), 'director', null, array('data-base-target' => '_main'));
                 $this->addHtmlHint(sprintf($hint, $link));
             }
         } catch (Exception $e) {
             $this->getElement('resource')->addError('Could not fetch: ' . $e->getMessage())->removeDecorator('description');
             $hint = $this->translate('Please make sure that your database grants enough permissions' . ' and that you deployed the correct %s.');
             $link = $this->getView()->qlink($this->translate('database schema'), 'director/schema/' . $resource->getDbType(), null, array('data-base-target' => '_next'));
             $this->addHtmlHint(sprintf($hint, $link));
         }
     }
 }
Пример #2
0
 public static function fromResourceName($name)
 {
     return new static(ResourceFactory::getResourceConfig($name));
 }
Пример #3
0
 /**
  * Return the configuration for the chosen resource
  *
  * @return  ConfigObject
  */
 public function getResourceConfig()
 {
     return ResourceFactory::getResourceConfig($this->getValue('resource'));
 }
Пример #4
0
 /**
  * Return whether the given values are valid
  *
  * @param   array   $formData   The data to validate
  *
  * @return  bool
  */
 public function isValid($formData)
 {
     if (!parent::isValid($formData)) {
         return false;
     }
     if (($el = $this->getElement('skip_validation')) === null || false === $el->isChecked()) {
         $resourceConfig = ResourceFactory::getResourceConfig($this->getValue('resource'));
         if (!self::isValidIdoSchema($this, $resourceConfig) || !self::isValidIdoInstance($this, $resourceConfig)) {
             if ($el === null) {
                 $this->addSkipValidationCheckbox();
             }
             return false;
         }
     }
     return true;
 }
Пример #5
0
 /**
  * Use a given resource to set the user and the key
  *
  * @param string
  *
  * @throws ConfigurationError
  */
 public function setResource($resource = null)
 {
     $config = ResourceFactory::getResourceConfig($resource);
     if (!isset($config->user)) {
         throw new ConfigurationError(t("Can't send external Icinga Command. Remote user is missing"));
     }
     if (!isset($config->private_key)) {
         throw new ConfigurationError(t("Can't send external Icinga Command. The private key for the remote user is missing"));
     }
     $this->setUser($config->user);
     $this->setPrivateKey($config->private_key);
 }
Пример #6
0
 public static function create($name, Zend_Config $backendConfig)
 {
     if ($backendConfig->name !== null) {
         $name = $backendConfig->name;
     }
     if (isset($backendConfig->class)) {
         // Use a custom backend class, this is only useful for testing
         if (!class_exists($backendConfig->class)) {
             throw new ConfigurationError('Authentication configuration for backend "' . $name . '" defines an invalid backend' . ' class. Backend class "' . $backendConfig->class . '" not found');
         }
         return new $backendConfig->class($backendConfig);
     }
     if ($name === 'autologin') {
         $backend = new AutoLoginBackend($backendConfig);
         $backend->setName($name);
         return $backend;
     }
     if ($backendConfig->resource === null) {
         throw new ConfigurationError('Authentication configuration for backend "' . $name . '" is missing the resource directive');
     }
     if (($backendType = $backendConfig->backend) === null) {
         throw new ConfigurationError('Authentication configuration for backend "' . $name . '" is missing the backend directive');
     }
     try {
         $resourceConfig = ResourceFactory::getResourceConfig($backendConfig->resource);
     } catch (ProgrammingError $e) {
         throw new ConfigurationError('Resources not set up. Please contact your Icinga Web administrator');
     }
     $resource = ResourceFactory::createResource($resourceConfig);
     switch (strtolower($backendType)) {
         case 'db':
             $backend = new DbUserBackend($resource);
             break;
         case 'msldap':
             $backend = new LdapUserBackend($resource, $backendConfig->get('user_class', 'user'), $backendConfig->get('user_name_attribute', 'sAMAccountName'));
             break;
         case 'ldap':
             if (($userClass = $backendConfig->user_class) === null) {
                 throw new ConfigurationError('Authentication configuration for backend "' . $name . '" is missing the user_class directive');
             }
             if (($userNameAttribute = $backendConfig->user_name_attribute) === null) {
                 throw new ConfigurationError('Authentication configuration for backend "' . $name . '" is missing the user_name_attribute directive');
             }
             $backend = new LdapUserBackend($resource, $userClass, $userNameAttribute);
             break;
         default:
             throw new ConfigurationError('Authentication configuration for backend "' . $name . '" defines an invalid backend' . ' type. Backend type "' . $backendType . '" is not supported');
     }
     $backend->setName($name);
     return $backend;
 }
 /**
  * Create preferences storage adapter from config
  *
  * @param   Zend_Config     $config     The config for the adapter
  * @param   User            $user       The user to which these preferences belong
  *
  * @return  self
  *
  * @throws  ConfigurationError          When the configuration defines an invalid storage type
  */
 public static function create(Zend_Config $config, User $user)
 {
     if (($type = $config->type) === null) {
         throw new ConfigurationError('Preferences configuration is missing the type directive');
     }
     $type = ucfirst(strtolower($type));
     $storeClass = 'Icinga\\User\\Preferences\\Store\\' . $type . 'Store';
     if (!class_exists($storeClass)) {
         throw new ConfigurationError('Preferences configuration defines an invalid storage type. Storage type ' . $type . ' not found');
     }
     if ($type === 'Ini') {
         $config->location = $config->config_path;
     } elseif ($type === 'Db') {
         $config->connection = new DbConnection(ResourceFactory::getResourceConfig($config->resource));
     }
     return new $storeClass($config, $user);
 }
Пример #8
0
 /**
  * Create preferences storage adapter from config
  *
  * @param   ConfigObject    $config     The config for the adapter
  * @param   User            $user       The user to which these preferences belong
  *
  * @return  self
  *
  * @throws  ConfigurationError          When the configuration defines an invalid storage type
  */
 public static function create(ConfigObject $config, User $user)
 {
     $type = ucfirst(strtolower($config->get('store', 'ini')));
     $storeClass = 'Icinga\\User\\Preferences\\Store\\' . $type . 'Store';
     if (!class_exists($storeClass)) {
         throw new ConfigurationError('Preferences configuration defines an invalid storage type. Storage type %s not found', $type);
     }
     if ($type === 'Ini') {
         $config->location = Config::resolvePath('preferences');
     } elseif ($type === 'Db') {
         $config->connection = new DbConnection(ResourceFactory::getResourceConfig($config->resource));
     }
     return new $storeClass($config, $user);
 }
Пример #9
0
 /**
  * Return whether the given values are valid
  *
  * @param   array   $formData   The data to validate
  *
  * @return  bool
  */
 public function isValid($formData)
 {
     if (!parent::isValid($formData)) {
         return false;
     }
     $resourceConfig = ResourceFactory::getResourceConfig($this->getValue('resource'));
     if (!self::isValidIdoSchema($this, $resourceConfig) || !self::isValidIdoInstance($this, $resourceConfig)) {
         $this->addSkipValidationCheckbox();
         return false;
     }
     return true;
 }