/**
  * @dataProvider provideMergeData
  */
 public function testMerge($conf, $props, $value, $expectedReturnValue, $expectedConf)
 {
     $conf = new MockArrayConf($conf);
     $propAccess = new PropertyAccess($conf);
     $this->assertSame($expectedReturnValue, $propAccess->merge($props, $value));
     $this->assertSame($expectedConf, $conf->getConfig());
 }
 /**
  * Creates a setup form. Set data if a configuration is given.
  *
  * @param PropertyAccess $conf
  *
  * @return FormInterface
  */
 public function createForm(PropertyAccess $conf = null)
 {
     $form = $this->factory->create(new MainConfigurationFormType($this->translator, $this->languages));
     $currentConf = $conf ? $conf->get('registry') ?: [] : [];
     $data = array_replace_recursive($this->getDefaultData(), $currentConf);
     $form->setData($data);
     return $form;
 }
 /**
  * Registers mime type guessers given the configuration
  */
 public function register()
 {
     $guesser = MimeTypeGuesser::getInstance();
     $guesser->register(new RawImageMimeTypeGuesser());
     $guesser->register(new PostScriptMimeTypeGuesser());
     $guesser->register(new AudioMimeTypeGuesser());
     $guesser->register(new VideoMimeTypeGuesser());
     $guesser->register(new CustomExtensionGuesser($this->conf->get(['border-manager', 'extension-mapping'], [])));
 }
Example #4
0
 public static function apache_tokenize(PropertyAccess $conf, $file)
 {
     $ret = false;
     if ($conf->get(['registry', 'executables', 'h264-streaming-enabled']) && is_file($file)) {
         if (mb_strpos($file, $conf->get(['registry', 'executables', 'auth-token-directory-path'])) === false) {
             return false;
         }
         $server = new system_server();
         if ($server->is_nginx()) {
             $fileToProtect = mb_substr($file, mb_strlen($conf->get(['registry', 'executables', 'auth-token-directory-path'])));
             $secret = $conf->get(['registry', 'executables', 'auth-token-passphrase']);
             $protectedPath = p4string::addFirstSlash(p4string::delEndSlash($conf->get(['registry', 'executables', 'auth-token-directory'])));
             $hexTime = strtoupper(dechex(time() + 3600));
             $token = md5($protectedPath . $fileToProtect . '/' . $secret . '/' . $hexTime);
             $url = $protectedPath . $fileToProtect . '/' . $token . '/' . $hexTime;
             $ret = $url;
         } elseif ($server->is_apache()) {
             $fileToProtect = mb_substr($file, mb_strlen($conf->get(['registry', 'executables', 'auth-token-directory-path'])));
             $secret = $conf->get(['registry', 'executables', 'auth-token-passphrase']);
             // Same as AuthTokenSecret
             $protectedPath = p4string::addEndSlash(p4string::delFirstSlash($conf->get(['registry', 'executables', 'auth-token-directory'])));
             // Same as AuthTokenPrefix
             $hexTime = dechex(time());
             // Time in Hexadecimal
             $token = md5($secret . $fileToProtect . $hexTime);
             // We build the url
             $url = '/' . $protectedPath . $token . "/" . $hexTime . $fileToProtect;
             $ret = $url;
         }
     }
     return $ret;
 }
 public function __construct(PropertyAccess $conf)
 {
     parent::__construct();
     $baseDir = realpath(__DIR__ . '/../../../../../');
     $paths = [$baseDir . '/config/configuration.yml'];
     foreach ($paths as $path) {
         $this->addRecommendation("00" === substr(sprintf('%o', fileperms($path)), -2), "{$path} should not be readable or writeable for other users, current mode is (" . substr(sprintf('%o', fileperms($path)), -4) . ")", "Change the permissions of the \"<strong>{$path}</strong>\" file to 0600");
     }
     if ($conf->has(['main', 'storage', 'subdefs', 'default-dir'])) {
         $paths[] = $conf->get(['main', 'storage', 'subdefs', 'default-dir']);
     }
     foreach ($paths as $path) {
         $this->addRequirement(is_writable($path), "{$path} directory must be writable", "Change the permissions of the \"<strong>{$path}</strong>\" directory so that the web server can write into it.");
     }
 }
 /**
  * Merge default user settings and configuration customisation.
  */
 private function loadUsersSettings()
 {
     if (null !== $this->usersSettings) {
         return;
     }
     $this->usersSettings = array_replace(self::$defaultUserSettings, array_intersect_key($this->conf->get(['user-settings'], []), self::$defaultUserSettings));
 }
 /**
  * Creates a SessionHandlerInterface given a conf.
  *
  * @param PropertyAccess $conf
  *
  * @return \SessionHandlerInterface
  *
  * @throws \Alchemy\Phrasea\Exception\RuntimeException
  */
 public function create(PropertyAccess $conf)
 {
     $type = $conf->get(['main', 'session', 'type'], 'file');
     $options = $conf->get(['main', 'session', 'options'], []);
     $serverOpts = ['expiretime' => $conf->get(['main', 'session', 'ttl'], 86400), 'prefix' => $conf->get(['main', 'key'])];
     switch (strtolower($type)) {
         case 'memcache':
             return new WriteCheckSessionHandler(new MemcacheSessionHandler($this->connectionFactory->getMemcacheConnection($options, $serverOpts)));
         case 'memcached':
             return new WriteCheckSessionHandler(new MemcachedSessionHandler($this->connectionFactory->getMemcachedConnection($options, $serverOpts)));
         case 'file':
             return new NativeFileSessionHandler(isset($options['save-path']) ? $options['save-path'] : null);
         case 'redis':
             return new WriteCheckSessionHandler(new RedisSessionHandler($this->connectionFactory->getRedisConnection($options, $serverOpts)));
     }
     throw new RuntimeException(sprintf('Unable to create the specified session handler "%s"', $type));
 }
 /**
  * @param $authorizedCollections
  * @param $user
  * @return mixed
  * @throws \Exception
  */
 private function applyAclsToUser(array $authorizedCollections, User $user)
 {
     $acl = $this->aclProvider->get($user);
     if ($this->configuration->get(['registry', 'registration', 'auto-register-enabled'])) {
         $template_user = $this->userRepository->findByLogin(User::USER_AUTOREGISTER);
         $acl->apply_model($template_user, array_keys($authorizedCollections));
     }
 }
    /**
     * {@inheritdoc}
     */
    public function getDefaultSettings(PropertyAccess $config = null)
    {
        if (null !== $config) {
            return '<?xml version="1.0" encoding="UTF-8"?>
<tasksettings>
    <host>' . $config->get(['main', 'database', 'host']) . '</host>
    <port>' . $config->get(['main', 'database', 'port']) . '</port>
    <base>' . $config->get(['main', 'database', 'dbname']) . '</base>
    <user>' . $config->get(['main', 'database', 'user']) . '</user>
    <password>' . $config->get(['main', 'database', 'password']) . '</password>
    <socket>25200</socket>
    <nolog>0</nolog>
    <clng></clng>
    <winsvc_run>0</winsvc_run>
    <charset>utf8</charset>
</tasksettings>';
        }
        return <<<EOF
<?xml version="1.0" encoding="UTF-8"?>
<tasksettings>
    <host></host>
    <port></port>
    <base></base>
    <user></user>
    <password></password>
    <socket>25200</socket>
    <nolog>0</nolog>
    <clng></clng>
    <winsvc_run>0</winsvc_run>
    <charset>utf8</charset>
</tasksettings>
EOF;
    }