Example #1
0
 /**
  * Create a new syslog log writer
  *
  * @param   ConfigObject    $config
  */
 public function __construct(ConfigObject $config)
 {
     $this->ident = $config->get('application', 'icingaweb2');
     $configuredFacility = $config->get('facility', 'user');
     if (!isset(static::$facilities[$configuredFacility])) {
         throw new ConfigurationError('Invalid logging facility: "%s" (expected one of: %s)', $configuredFacility, implode(', ', array_keys(static::$facilities)));
     }
     $this->facility = static::$facilities[$configuredFacility];
 }
Example #2
0
 /**
  * Create a new logger object
  *
  * @param   ConfigObject  $config
  *
  * @throws  ConfigurationError  If the logging configuration directive 'log' is missing or if the logging level is
  *                              not defined
  */
 public function __construct(ConfigObject $config)
 {
     if ($config->log === null) {
         throw new ConfigurationError('Required logging configuration directive \'log\' missing');
     }
     $this->setLevel($config->get('level', static::ERROR));
     if (strtolower($config->get('log', 'syslog')) !== 'none') {
         $this->writer = $this->createWriter($config);
     }
 }
 /**
  * Get this backend's internal resource
  *
  * @return mixed
  */
 public function getResource()
 {
     if ($this->resource === null) {
         $this->resource = ResourceFactory::create($this->config->get('resource'));
         if ($this->is('ido') && $this->resource->getDbType() !== 'oracle') {
             // TODO(el): The resource should set the table prefix
             $this->resource->setTablePrefix('icinga_');
         }
     }
     return $this->resource;
 }
Example #4
0
 /**
  * Create a new connection
  */
 private function connect()
 {
     $genericAdapterOptions = self::$genericAdapterOptions;
     $driverOptions = self::$driverOptions;
     $adapterParamaters = array('host' => $this->config->host, 'username' => $this->config->username, 'password' => $this->config->password, 'dbname' => $this->config->dbname, 'options' => &$genericAdapterOptions, 'driver_options' => &$driverOptions);
     $this->dbType = strtolower($this->config->get('db', 'mysql'));
     switch ($this->dbType) {
         case 'mysql':
             $adapter = 'Pdo_Mysql';
             /*
              * Set MySQL server SQL modes to behave as closely as possible to Oracle and PostgreSQL. Note that the
              * ONLY_FULL_GROUP_BY mode is left on purpose because MySQL requires you to specify all non-aggregate
              * columns in the group by list even if the query is grouped by the master table's primary key which is
              * valid ANSI SQL though. Further in that case the query plan would suffer if you add more columns to
              * the group by list.
              */
             $driverOptions[PDO::MYSQL_ATTR_INIT_COMMAND] = 'SET SESSION SQL_MODE=\'STRICT_ALL_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,' . 'NO_AUTO_CREATE_USER,ANSI_QUOTES,PIPES_AS_CONCAT,NO_ENGINE_SUBSTITUTION\';';
             $adapterParamaters['port'] = $this->config->get('port', 3306);
             break;
         case 'pgsql':
             $adapter = 'Pdo_Pgsql';
             $adapterParamaters['port'] = $this->config->get('port', 5432);
             if ($adapterParamaters['host'] === '') {
                 unset($adapterParamaters['host']);
             }
             break;
             /*case 'oracle':
               if ($this->dbtype === 'oracle') {
                   $attributes['persistent'] = true;
               }
               $this->db = ZfDb::factory($adapter, $attributes);
               if ($adapter === 'Oracle') {
                   $this->db->setLobAsString(false);
               }
               break;*/
         /*case 'oracle':
           if ($this->dbtype === 'oracle') {
               $attributes['persistent'] = true;
           }
           $this->db = ZfDb::factory($adapter, $attributes);
           if ($adapter === 'Oracle') {
               $this->db->setLobAsString(false);
           }
           break;*/
         default:
             throw new ConfigurationError('Backend "%s" is not supported', $this->dbType);
     }
     $this->dbAdapter = Zend_Db::factory($adapter, $adapterParamaters);
     $this->dbAdapter->setFetchMode(Zend_Db::FETCH_OBJ);
     // TODO(el/tg): The profiler is disabled per default, why do we disable the profiler explicitly?
     $this->dbAdapter->getProfiler()->setEnabled(false);
 }
Example #5
0
 /**
  * @depends testWhetherConfigObjectsCanBeConvertedToArrays
  */
 public function testWhetherItIsPossibleToMergeConfigObjects()
 {
     $config = new ConfigObject(array('a' => 'b'));
     $config->merge(array('a' => 'bb', 'c' => 'd', 'e' => array('f' => 'g')));
     $this->assertEquals(array('a' => 'bb', 'c' => 'd', 'e' => array('f' => 'g')), $config->toArray(), 'ConfigObjects cannot be extended with arrays');
     $config->merge(new ConfigObject(array('c' => array('d' => 'ee'), 'e' => array('h' => 'i'))));
     $this->assertEquals(array('a' => 'bb', 'c' => array('d' => 'ee'), 'e' => array('f' => 'g', 'h' => 'i')), $config->toArray(), 'ConfigObjects cannot be extended with other ConfigObjects');
 }
Example #6
0
 /**
  * Return the given section
  *
  * @param   string  $name   The section's name
  *
  * @return  ConfigObject
  */
 public function getSection($name)
 {
     $section = $this->config->get($name);
     return $section !== null ? $section : new ConfigObject();
 }
Example #7
0
 /**
  * Create a new connection object
  *
  * @param   ConfigObject    $config
  */
 public function __construct(ConfigObject $config)
 {
     $this->hostname = $config->hostname;
     $this->bindDn = $config->bind_dn;
     $this->bindPw = $config->bind_pw;
     $this->rootDn = $config->root_dn;
     $this->port = $config->get('port', 389);
     $this->encryption = $config->encryption;
     if ($this->encryption !== null) {
         $this->encryption = strtolower($this->encryption);
     }
 }
Example #8
0
 /**
  * Create new authentication backend of type "external"
  *
  * @param ConfigObject $config
  */
 public function __construct(ConfigObject $config)
 {
     $this->stripUsernameRegexp = $config->get('strip_username_regexp');
 }
Example #9
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);
 }
Example #10
0
 /**
  * Create a new pane with the title $title from the given configuration
  *
  * @param $title                The title for this pane
  * @param ConfigObject  $config The configuration to use for setup
  *
  * @return Pane
  */
 public static function fromIni($title, ConfigObject $config)
 {
     $pane = new Pane($title);
     if ($config->get('title', false)) {
         $pane->setTitle($config->get('title'));
     }
     return $pane;
 }
Example #11
0
 /**
  * Create a new connection
  */
 private function connect()
 {
     $genericAdapterOptions = self::$genericAdapterOptions;
     $driverOptions = self::$driverOptions;
     $adapterParamaters = array('host' => $this->config->host, 'username' => $this->config->username, 'password' => $this->config->password, 'dbname' => $this->config->dbname, 'charset' => $this->config->charset ?: null, 'persistent' => (bool) $this->config->get('persistent', false), 'options' => &$genericAdapterOptions, 'driver_options' => &$driverOptions);
     $this->dbType = strtolower($this->config->get('db', 'mysql'));
     switch ($this->dbType) {
         case 'mssql':
             $adapter = 'Pdo_Mssql';
             $adapterParamaters['pdoType'] = $this->config->get('pdoType', 'dblib');
             break;
         case 'mysql':
             $adapter = 'Pdo_Mysql';
             if ($this->config->use_ssl) {
                 # The presence of these keys as empty strings or null cause non-ssl connections to fail
                 if ($this->config->ssl_key) {
                     $adapterParamaters['driver_options'][PDO::MYSQL_ATTR_SSL_KEY] = $this->config->ssl_key;
                 }
                 if ($this->config->ssl_cert) {
                     $adapterParamaters['driver_options'][PDO::MYSQL_ATTR_SSL_CERT] = $this->config->ssl_cert;
                 }
                 if ($this->config->ssl_ca) {
                     $adapterParamaters['driver_options'][PDO::MYSQL_ATTR_SSL_CA] = $this->config->ssl_ca;
                 }
                 if ($this->config->ssl_capath) {
                     $adapterParamaters['driver_options'][PDO::MYSQL_ATTR_SSL_CAPATH] = $this->config->ssl_capath;
                 }
                 if ($this->config->ssl_cipher) {
                     $adapterParamaters['driver_options'][PDO::MYSQL_ATTR_SSL_CIPHER] = $this->config->ssl_cipher;
                 }
             }
             /*
              * Set MySQL server SQL modes to behave as closely as possible to Oracle and PostgreSQL. Note that the
              * ONLY_FULL_GROUP_BY mode is left on purpose because MySQL requires you to specify all non-aggregate
              * columns in the group by list even if the query is grouped by the master table's primary key which is
              * valid ANSI SQL though. Further in that case the query plan would suffer if you add more columns to
              * the group by list.
              */
             $driverOptions[PDO::MYSQL_ATTR_INIT_COMMAND] = 'SET SESSION SQL_MODE=\'STRICT_ALL_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,' . 'NO_AUTO_CREATE_USER,ANSI_QUOTES,PIPES_AS_CONCAT,NO_ENGINE_SUBSTITUTION\'';
             if (isset($adapterParamaters['charset'])) {
                 $driverOptions[PDO::MYSQL_ATTR_INIT_COMMAND] .= ', NAMES ' . $adapterParamaters['charset'];
                 unset($adapterParamaters['charset']);
             }
             $driverOptions[PDO::MYSQL_ATTR_INIT_COMMAND] .= ';';
             $adapterParamaters['port'] = $this->config->get('port', 3306);
             break;
         case 'oci':
             $adapter = 'Oracle';
             unset($adapterParamaters['options']);
             unset($adapterParamaters['driver_options']);
             $adapterParamaters['driver_options'] = array('lob_as_string' => true);
             break;
         case 'oracle':
             $adapter = 'Pdo_Oci';
             break;
         case 'pgsql':
             $adapter = 'Pdo_Pgsql';
             $adapterParamaters['port'] = $this->config->get('port', 5432);
             break;
         default:
             throw new ConfigurationError('Backend "%s" is not supported', $this->dbType);
     }
     $this->dbAdapter = Zend_Db::factory($adapter, $adapterParamaters);
     $this->dbAdapter->setFetchMode(Zend_Db::FETCH_OBJ);
     // TODO(el/tg): The profiler is disabled per default, why do we disable the profiler explicitly?
     $this->dbAdapter->getProfiler()->setEnabled(false);
 }
Example #12
0
 /**
  * Create a new syslog log writer
  *
  * @param   ConfigObject    $config
  */
 public function __construct(ConfigObject $config)
 {
     $this->ident = $config->get('application', 'icingaweb2');
     $this->facility = static::$facilities['user'];
 }
Example #13
0
 /**
  * Create a @see Dashlet instance from the given Zend config, using the provided title
  *
  * @param $title                The title for this dashlet
  * @param ConfigObject $config  The configuration defining url, parameters, height, width, etc.
  * @param Pane $pane            The pane this dashlet belongs to
  *
  * @return Dashlet        A newly created Dashlet for use in the Dashboard
  */
 public static function fromIni($title, ConfigObject $config, Pane $pane)
 {
     $height = null;
     $width = null;
     $url = $config->get('url');
     $parameters = $config->toArray();
     unset($parameters['url']);
     // otherwise there's an url = parameter in the Url
     $cmp = new Dashlet($title, Url::fromPath($url, $parameters), $pane);
     return $cmp;
 }
 /**
  * Before-update trigger (per row)
  *
  * @param   ConfigObject    $old    The original data as currently stored
  * @param   ConfigObject    $new    The original data to update
  *
  * @return  ConfigObject            The eventually modified data to update
  */
 protected function onUpdateAnnouncement(ConfigObject $old, ConfigObject $new)
 {
     if ($new->message !== $old->message) {
         $announcement = new Announcement($new->toArray());
         $new->hash = $announcement->getHash();
     }
     return $new;
 }
Example #15
0
 /**
  * Create a new instance of MenuItemRenderer
  *
  * Is is possible to configure the link target using the option 'target'
  *
  * @param ConfigObject|null $configuration
  */
 public function __construct(ConfigObject $configuration = null)
 {
     if ($configuration !== null) {
         $this->target = $configuration->get('target', null);
     }
 }
 /**
  * Apply the given configuration on this backend
  *
  * @param   ConfigObject    $config
  *
  * @return  $this
  *
  * @throws  ConfigurationError      In case a linked user backend does not exist or is invalid
  */
 public function setConfig(ConfigObject $config)
 {
     if ($config->backend === 'ldap') {
         $defaults = $this->getOpenLdapDefaults();
     } elseif ($config->backend === 'msldap') {
         $defaults = $this->getActiveDirectoryDefaults();
     } else {
         $defaults = new ConfigObject();
     }
     if ($config->user_backend && $config->user_backend !== 'none') {
         $userBackend = UserBackend::create($config->user_backend);
         if (!$userBackend instanceof LdapUserBackend) {
             throw new ConfigurationError('User backend "%s" is not of type LDAP', $config->user_backend);
         }
         if ($this->ds->getHostname() !== $userBackend->getDataSource()->getHostname() || $this->ds->getPort() !== $userBackend->getDataSource()->getPort()) {
             // TODO(jom): Elaborate whether it makes sense to link directories on different hosts
             throw new ConfigurationError('It is required that a linked user backend refers to the ' . 'same directory as it\'s user group backend counterpart');
         }
         $this->setUserBackend($userBackend);
         $defaults->merge(array('user_base_dn' => $userBackend->getBaseDn(), 'user_class' => $userBackend->getUserClass(), 'user_name_attribute' => $userBackend->getUserNameAttribute(), 'user_filter' => $userBackend->getFilter()));
     }
     return $this->setGroupBaseDn($config->base_dn)->setUserBaseDn($config->get('user_base_dn', $this->getGroupBaseDn()))->setGroupClass($config->get('group_class', $defaults->group_class))->setUserClass($config->get('user_class', $defaults->user_class))->setGroupNameAttribute($config->get('group_name_attribute', $defaults->group_name_attribute))->setUserNameAttribute($config->get('user_name_attribute', $defaults->user_name_attribute))->setGroupMemberAttribute($config->get('group_member_attribute', $defaults->group_member_attribute))->setGroupFilter($config->filter)->setUserFilter($config->user_filter);
 }
 /**
  * The amount of problems
  */
 public function __construct(ConfigObject $configuration)
 {
     $this->state = $configuration->get('state', self::STATE_CRITICAL);
 }