コード例 #1
0
 /**
  * Create a new PHPSession object using the provided options (if any)
  *
  * @param   array   $options    An optional array of ini options to set
  *
  * @throws  ConfigurationError
  * @see     http://php.net/manual/en/session.configuration.php
  */
 public function __construct(array $options = null)
 {
     if ($options !== null) {
         $options = array_merge(self::$defaultCookieOptions, $options);
     } else {
         $options = self::$defaultCookieOptions;
     }
     if (array_key_exists('test_session_name', $options)) {
         $this->sessionName = $options['test_session_name'];
         unset($options['test_session_name']);
     }
     foreach ($options as $sessionVar => $value) {
         if (ini_set("session." . $sessionVar, $value) === false) {
             Logger::warning('Could not set php.ini setting %s = %s. This might affect your sessions behaviour.', $sessionVar, $value);
         }
     }
     if (!is_writable(session_save_path())) {
         throw new ConfigurationError('Can\'t save session');
     }
     $this->read();
 }
コード例 #2
0
ファイル: Manager.php プロジェクト: vbereza/icinga2-migration
 /**
  * Detect installed modules from every path provided in modulePaths
  *
  * @return self
  */
 public function detectInstalledModules()
 {
     foreach ($this->modulePaths as $basedir) {
         $canonical = realpath($basedir);
         if ($canonical === false) {
             Logger::warning('Module path "%s" does not exist', $basedir);
             continue;
         }
         if (!is_dir($canonical)) {
             Logger::error('Module path "%s" is not a directory', $canonical);
             continue;
         }
         if (!is_readable($canonical)) {
             Logger::error('Module path "%s" is not readable', $canonical);
             continue;
         }
         if (($dh = opendir($canonical)) !== false) {
             while (($file = readdir($dh)) !== false) {
                 if ($file[0] === '.') {
                     continue;
                 }
                 if (is_dir($canonical . '/' . $file)) {
                     if (!array_key_exists($file, $this->installedBaseDirs)) {
                         $this->installedBaseDirs[$file] = $canonical . '/' . $file;
                     } else {
                         Logger::debug('Module "%s" already exists in installation path "%s" and is ignored.', $canonical . '/' . $file, $this->installedBaseDirs[$file]);
                     }
                 }
             }
             closedir($dh);
         }
     }
     ksort($this->installedBaseDirs);
     return $this;
 }
コード例 #3
0
ファイル: Module.php プロジェクト: vbereza/icinga2-migration
 /**
  * Register module
  *
  * @return bool
  */
 public function register()
 {
     $this->registerAutoloader()->registerWebIntegration();
     try {
         $this->launchRunScript();
     } catch (Exception $e) {
         Logger::warning('Launching the run script %s for module %s failed with the following exception: %s', $this->runScript, $this->name, $e->getMessage());
         return false;
     }
     return true;
 }
コード例 #4
0
ファイル: Web.php プロジェクト: vbereza/icinga2-migration
 /**
  * Setup internationalization using gettext
  *
  * Uses the preferred user language or the configured default and system default, respectively.
  *
  * @return  self
  */
 protected function setupInternationalization()
 {
     parent::setupInternationalization();
     if ($this->user !== null && $this->user->getPreferences() !== null && ($locale = $this->user->getPreferences()->get('app.language') !== null)) {
         try {
             Translator::setupLocale($locale);
         } catch (Exception $error) {
             Logger::warning('Cannot set locale "' . $locale . '" configured in ' . 'preferences of user "' . $this->user->getUsername() . '"');
         }
     }
     return $this;
 }
コード例 #5
0
 protected function prepareNewConnection()
 {
     $use_tls = false;
     $force_tls = true;
     $force_tls = false;
     if ($use_tls) {
         $this->prepareTlsEnvironment();
     }
     $ds = ldap_connect($this->hostname, $this->port);
     $cap = $this->discoverCapabilities($ds);
     $this->capabilities = $cap;
     if ($use_tls) {
         if ($cap->starttls) {
             if (@ldap_start_tls($ds)) {
                 Logger::debug('LDAP STARTTLS succeeded');
             } else {
                 Logger::debug('LDAP STARTTLS failed: %s', ldap_error($ds));
                 throw new \Exception(sprintf('LDAP STARTTLS failed: %s', ldap_error($ds)));
             }
         } elseif ($force_tls) {
             throw new \Exception(sprintf('TLS is required but not announced by %s', $this->host_name));
         } else {
             // TODO: Log noticy -> TLS enabled but not announced
         }
     }
     // ldap_rename requires LDAPv3:
     if ($cap->ldapv3) {
         if (!ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3)) {
             throw new Exception('LDAPv3 is required');
         }
     } else {
         // TODO: remove this -> FORCING v3 for now
         ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
         Logger::warning('No LDAPv3 support detected');
     }
     // Not setting this results in "Operations error" on AD when using the
     // whole domain as search base:
     ldap_set_option($ds, LDAP_OPT_REFERRALS, 0);
     // ldap_set_option($ds, LDAP_OPT_DEREF, LDAP_DEREF_NEVER);
     return $ds;
 }
コード例 #6
0
ファイル: Reader.php プロジェクト: vbereza/icinga2-migration
 /**
  * Initialize the internal caches if enabled
  *
  * @throws ConfigurationError
  */
 private function initializeCaches()
 {
     $defaultCachePath = self::STATUSDAT_DEFAULT_CACHE_PATH;
     $cachePath = $this->config->get('cache_path', $defaultCachePath);
     $maxCacheLifetime = intval($this->config->get('cache_path', self::DEFAULT_CACHE_LIFETIME));
     $cachingEnabled = true;
     if (!is_writeable($cachePath)) {
         Logger::warning('Can\'t cache Status.dat backend; make sure cachepath %s is writable by the web user. ' . 'Caching is now disabled', $cachePath);
         $cachePath = null;
     }
     $backendOptions = array('cache_dir' => $cachePath);
     // the object cache might exist for months and is still valid
     $this->objectCache = $this->initCache($this->config->object_file, $backendOptions, null, $cachingEnabled);
     $this->statusCache = $this->initCache($this->config->status_file, $backendOptions, $maxCacheLifetime, $cachingEnabled);
 }