Ejemplo n.º 1
0
 /**
  * Creates the mocked filesystem used in the tests
  */
 public function setUp()
 {
     \vfsStreamWrapper::register();
     \vfsStreamWrapper::setRoot(new \vfsStreamDirectory('Foo'));
     $this->mockEnvironment = $this->getMock('TYPO3\\FLOW3\\Utility\\Environment', array(), array(), '', FALSE);
     $this->mockEnvironment->expects($this->any())->method('getPathToTemporaryDirectory')->will($this->returnValue('vfs://Foo/'));
     $this->mockEnvironment->expects($this->any())->method('getMaximumPathLength')->will($this->returnValue(1024));
 }
Ejemplo n.º 2
0
 /**
  * Initializes the manager
  *
  * @return void
  */
 public function initializeObject()
 {
     $this->lockPathAndFilename = $this->environment->getPathToTemporaryDirectory() . 'FLOW3.lock';
     if (file_exists($this->lockPathAndFilename)) {
         if (filemtime($this->lockPathAndFilename) < time() - self::LOCKFILE_MAXIMUM_AGE) {
             unlink($this->lockPathAndFilename);
         } else {
             $this->siteLocked = TRUE;
         }
     }
 }
Ejemplo n.º 3
0
 /**
  * Factory method which creates an EntityManager.
  *
  * @return \Doctrine\ORM\EntityManager
  */
 public function create()
 {
     $config = new \Doctrine\ORM\Configuration();
     $config->setClassMetadataFactoryName('TYPO3\\FLOW3\\Persistence\\Doctrine\\Mapping\\ClassMetadataFactory');
     if (class_exists($this->settings['doctrine']['cacheImplementation'])) {
         // safeguard against apc being disabled in CLI...
         if ($this->settings['doctrine']['cacheImplementation'] !== 'Doctrine\\Common\\Cache\\ApcCache' || function_exists('apc_fetch')) {
             $cache = new $this->settings['doctrine']['cacheImplementation']();
             $config->setMetadataCacheImpl($cache);
             $config->setQueryCacheImpl($cache);
         }
     }
     if (class_exists($this->settings['doctrine']['sqlLogger'])) {
         $config->setSQLLogger(new $this->settings['doctrine']['sqlLogger']());
     }
     // must use ObjectManager in compile phase...
     $flow3AnnotationDriver = $this->objectManager->get('TYPO3\\FLOW3\\Persistence\\Doctrine\\Mapping\\Driver\\Flow3AnnotationDriver');
     $config->setMetadataDriverImpl($flow3AnnotationDriver);
     $proxyDirectory = \TYPO3\FLOW3\Utility\Files::concatenatePaths(array($this->environment->getPathToTemporaryDirectory(), 'Doctrine/Proxies'));
     \TYPO3\FLOW3\Utility\Files::createDirectoryRecursively($proxyDirectory);
     $config->setProxyDir($proxyDirectory);
     $config->setProxyNamespace('TYPO3\\FLOW3\\Persistence\\Doctrine\\Proxies');
     $config->setAutoGenerateProxyClasses(FALSE);
     $entityManager = \Doctrine\ORM\EntityManager::create($this->settings['backendOptions'], $config);
     $flow3AnnotationDriver->setEntityManager($entityManager);
     return $entityManager;
 }
Ejemplo n.º 4
0
 /**
  * Initializes the PHP session according to the settings provided.
  *
  * @return void
  */
 public function initializeObject()
 {
     if (!empty($this->settings['session']['PhpSession']['name'])) {
         session_name($this->settings['session']['PhpSession']['name']);
     }
     $cookieParameters = session_get_cookie_params();
     if (!empty($this->settings['session']['PhpSession']['cookie']['domain'])) {
         $cookieParameters['domain'] = $this->settings['session']['PhpSession']['cookie']['domain'];
     }
     if (!empty($this->settings['session']['PhpSession']['cookie']['lifetime'])) {
         $cookieParameters['lifetime'] = $this->settings['session']['PhpSession']['cookie']['lifetime'];
     }
     if (!empty($this->settings['session']['PhpSession']['cookie']['path'])) {
         $cookieParameters['path'] = $this->settings['session']['PhpSession']['cookie']['path'];
     }
     if (!empty($this->settings['session']['PhpSession']['cookie']['secure'])) {
         $cookieParameters['secure'] = $this->settings['session']['PhpSession']['cookie']['secure'];
     }
     if (!empty($this->settings['session']['PhpSession']['cookie']['httponly'])) {
         $cookieParameters['httponly'] = $this->settings['session']['PhpSession']['cookie']['httponly'];
     }
     session_set_cookie_params($cookieParameters['lifetime'], $cookieParameters['path'], $cookieParameters['domain'], $cookieParameters['secure'], $cookieParameters['httponly']);
     if (empty($this->settings['session']['PhpSession']['savePath'])) {
         $sessionsPath = \TYPO3\FLOW3\Utility\Files::concatenatePaths(array($this->environment->getPathToTemporaryDirectory(), 'Sessions'));
     } else {
         $sessionsPath = $this->settings['session']['PhpSession']['savePath'];
     }
     if (!file_exists($sessionsPath)) {
         \TYPO3\FLOW3\Utility\Files::createDirectoryRecursively($sessionsPath);
     }
     session_save_path($sessionsPath);
 }
Ejemplo n.º 5
0
    /**
     * Saves the current configuration into a cache file and creates a cache inclusion script
     * in the context's Configuration directory.
     *
     * @return void
     * @throws \TYPO3\FLOW3\Configuration\Exception
     */
    protected function saveConfigurationCache()
    {
        $configurationCachePath = $this->environment->getPathToTemporaryDirectory() . 'Configuration/';
        if (!file_exists($configurationCachePath)) {
            \TYPO3\FLOW3\Utility\Files::createDirectoryRecursively($configurationCachePath);
        }
        $cachePathAndFilename = $configurationCachePath . str_replace('/', '_', (string) $this->context) . 'Configurations.php';
        $flow3RootPath = FLOW3_PATH_ROOT;
        $includeCachedConfigurationsCode = <<<EOD
<?php
if (FLOW3_PATH_ROOT !== '{$flow3RootPath}' || !file_exists('{$cachePathAndFilename}')) {
\tunlink(__FILE__);
\treturn array();
}
return require '{$cachePathAndFilename}';
?>
EOD;
        file_put_contents($cachePathAndFilename, '<?php return ' . var_export($this->configurations, TRUE) . '?>');
        if (!is_dir(dirname($this->includeCachedConfigurationsPathAndFilename)) && !is_link(dirname($this->includeCachedConfigurationsPathAndFilename))) {
            \TYPO3\FLOW3\Utility\Files::createDirectoryRecursively(dirname($this->includeCachedConfigurationsPathAndFilename));
        }
        file_put_contents($this->includeCachedConfigurationsPathAndFilename, $includeCachedConfigurationsCode);
        if (!file_exists($this->includeCachedConfigurationsPathAndFilename)) {
            throw new \TYPO3\FLOW3\Configuration\Exception(sprintf('Could not write configuration cache file "%s". Check file permissions for the parent directory.', $this->includeCachedConfigurationsPathAndFilename), 1323339284);
        }
    }
Ejemplo n.º 6
0
 /**
  * Updates the username and password credentials from the POST vars, if the POST parameters
  * are available. Sets the authentication status to REAUTHENTICATION_NEEDED, if credentials have been sent.
  *
  * @return void
  * @author Andreas Förthner <*****@*****.**>
  */
 public function updateCredentials(\TYPO3\FLOW3\MVC\RequestInterface $request)
 {
     $postArguments = $this->environment->getRawPostArguments();
     if (isset($postArguments['TYPO3\\FLOW3\\Security\\Authentication\\Token\\UsernamePassword::username']) && isset($postArguments['TYPO3\\FLOW3\\Security\\Authentication\\Token\\UsernamePassword::password'])) {
         $this->credentials['username'] = $postArguments['TYPO3\\FLOW3\\Security\\Authentication\\Token\\UsernamePassword::username'];
         $this->credentials['password'] = $postArguments['TYPO3\\FLOW3\\Security\\Authentication\\Token\\UsernamePassword::password'];
         $this->setAuthenticationStatus(self::AUTHENTICATION_NEEDED);
     }
 }
Ejemplo n.º 7
0
 /**
  * Builds the URI
  *
  * @param array $arguments optional URI arguments. Will be merged with $this->arguments with precedence to $arguments
  * @return string The URI
  * @api
  */
 public function build(array $arguments = array())
 {
     $arguments = Arrays::arrayMergeRecursiveOverrule($this->arguments, $arguments);
     $this->mergeArgumentsWithRequestArguments($arguments);
     $uri = $this->router->resolve($arguments);
     $this->lastArguments = $arguments;
     if (!$this->environment->isRewriteEnabled()) {
         $uri = 'index.php/' . $uri;
     }
     if ($this->createAbsoluteUri === TRUE) {
         $uri = $this->request->getHttpRequest()->getBaseUri() . $uri;
     }
     if ($this->section !== '') {
         $uri .= '#' . $this->section;
     }
     return $uri;
 }
Ejemplo n.º 8
0
 /**
  * Imports a resource (file) from the given location as a persistent resource.
  * On a successful import this method returns a Resource object representing the
  * newly imported persistent resource.
  *
  * @param string $uri An URI (can also be a path and filename) pointing to the resource to import
  * @return mixed A resource object representing the imported resource or FALSE if an error occurred.
  * @api
  */
 public function importResource($uri)
 {
     $pathInfo = pathinfo($uri);
     if (isset($pathInfo['extension']) && substr(strtolower($pathInfo['extension']), -3, 3) === 'php') {
         return FALSE;
     }
     $temporaryTargetPathAndFilename = $this->environment->getPathToTemporaryDirectory() . uniqid('FLOW3_ResourceImport_');
     if (copy($uri, $temporaryTargetPathAndFilename) === FALSE) {
         return FALSE;
     }
     $hash = sha1_file($temporaryTargetPathAndFilename);
     $finalTargetPathAndFilename = $this->persistentResourcesStorageBaseUri . $hash;
     if (rename($temporaryTargetPathAndFilename, $finalTargetPathAndFilename) === FALSE) {
         unlink($temporaryTargetPathAndFilename);
         return FALSE;
     }
     $this->fixFilePermissions($finalTargetPathAndFilename);
     $resource = $this->createResourceFromHashAndFilename($hash, $pathInfo['basename']);
     $this->attachImportedResource($resource);
     return $resource;
 }
 /**
  * Returns the publish path and filename to be used to publish the specified persistent resource
  *
  * @FLOW3\Around("method(TYPO3\FLOW3\Resource\Publishing\FileSystemPublishingTarget->buildPersistentResourcePublishPathAndFilename()) && setting(TYPO3.FLOW3.security.enable)")
  * @param \TYPO3\FLOW3\Aop\JoinPointInterface $joinPoint The current join point
  * @return mixed Result of the target method
  */
 public function rewritePersistentResourcePublishPathAndFilenameForPrivateResources(\TYPO3\FLOW3\Aop\JoinPointInterface $joinPoint)
 {
     $resource = $joinPoint->getMethodArgument('resource');
     $configuration = $resource->getPublishingConfiguration();
     $returnFilename = $joinPoint->getMethodArgument('returnFilename');
     if ($configuration === NULL || $configuration instanceof \TYPO3\FLOW3\Security\Authorization\Resource\SecurityPublishingConfiguration === FALSE) {
         return $joinPoint->getAdviceChain()->proceed($joinPoint);
     }
     $publishingPath = FALSE;
     $allowedRoles = $configuration->getAllowedRoles();
     if (count(array_intersect($allowedRoles, $this->securityContext->getRoles())) > 0) {
         $publishingPath = \TYPO3\FLOW3\Utility\Files::concatenatePaths(array($joinPoint->getProxy()->getResourcesPublishingPath(), 'Persistent/', $this->session->getID())) . '/';
         $filename = $resource->getResourcePointer()->getHash() . '.' . $resource->getFileExtension();
         \TYPO3\FLOW3\Utility\Files::createDirectoryRecursively($publishingPath);
         $this->accessRestrictionPublisher->publishAccessRestrictionsForPath($publishingPath);
         if ($this->settings['resource']['publishing']['fileSystem']['mirrorMode'] === 'link') {
             foreach ($allowedRoles as $role) {
                 $roleDirectory = \TYPO3\FLOW3\Utility\Files::concatenatePaths(array($this->environment->getPathToTemporaryDirectory(), 'PrivateResourcePublishing/', $role));
                 \TYPO3\FLOW3\Utility\Files::createDirectoryRecursively($roleDirectory);
                 if (file_exists($publishingPath . $role)) {
                     if (\TYPO3\FLOW3\Utility\Files::is_link(\TYPO3\FLOW3\Utility\Files::concatenatePaths(array($publishingPath, $role))) && realpath(\TYPO3\FLOW3\Utility\Files::concatenatePaths(array($publishingPath, $role))) === $roleDirectory) {
                         continue;
                     }
                     unlink($publishingPath . $role);
                     symlink($roleDirectory, \TYPO3\FLOW3\Utility\Files::concatenatePaths(array($publishingPath, $role)));
                 } else {
                     symlink($roleDirectory, \TYPO3\FLOW3\Utility\Files::concatenatePaths(array($publishingPath, $role)));
                 }
             }
             $publishingPath = \TYPO3\FLOW3\Utility\Files::concatenatePaths(array($publishingPath, $allowedRoles[0])) . '/';
         }
         if ($returnFilename === TRUE) {
             $publishingPath = \TYPO3\FLOW3\Utility\Files::concatenatePaths(array($publishingPath, $filename));
         }
     }
     return $publishingPath;
 }
Ejemplo n.º 10
0
 /**
  * Determines the path to the precompiled reflection data.
  *
  * @return string
  */
 protected function getPrecompiledReflectionStoragePath()
 {
     return Files::concatenatePaths(array($this->environment->getPathToTemporaryDirectory(), 'PrecompiledReflectionData/')) . '/';
 }
Ejemplo n.º 11
0
 /**
  * Compiles the Doctrine proxy class code using the Doctrine ProxyFactory.
  *
  * @return void
  */
 public function compileProxies()
 {
     Files::emptyDirectoryRecursively(Files::concatenatePaths(array($this->environment->getPathToTemporaryDirectory(), 'Doctrine/Proxies')));
     $proxyFactory = $this->entityManager->getProxyFactory();
     $proxyFactory->generateProxyClasses($this->entityManager->getMetadataFactory()->getAllMetadata());
 }