Example #1
0
 /**
  * Run application
  *
  * @return \Magento\Framework\App\ResponseInterface
  * @throws \LogicException
  */
 public function launch()
 {
     if (!$this->_mediaDirectory) {
         $config = $this->_objectManager->create('Magento\\Core\\Model\\File\\Storage\\Config', ['cacheFile' => $this->_configCacheFile]);
         $config->save();
         $this->_mediaDirectory = str_replace($this->_workingDirectory, '', $config->getMediaDirectory());
         $allowedResources = $config->getAllowedResources();
         $this->_relativeFileName = str_replace($this->_mediaDirectory . '/', '', $this->_request->getPathInfo());
         $isAllowed = $this->_isAllowed;
         if (!$isAllowed($this->_relativeFileName, $allowedResources)) {
             throw new \LogicException('The specified path is not allowed.');
         }
     }
     if (0 !== stripos($this->_request->getPathInfo(), $this->_mediaDirectory . '/')) {
         throw new \LogicException('The specified path is not within media directory.');
     }
     $sync = $this->_objectManager->get('Magento\\Core\\Model\\File\\Storage\\Synchronization');
     $sync->synchronize($this->_relativeFileName, $this->_request->getFilePath());
     if ($this->directory->isReadable($this->directory->getRelativePath($this->_request->getFilePath()))) {
         $this->_response->setFilePath($this->_request->getFilePath());
     } else {
         $this->_response->setHttpResponseCode(404);
     }
     return $this->_response;
 }
Example #2
0
 /**
  * Run application
  *
  * @return \Magento\Framework\App\ResponseInterface
  */
 public function launch()
 {
     try {
         if (!$this->_applicationState->isInstalled()) {
             $this->_response->setHttpResponseCode(404);
             return $this->_response;
         }
         if (!$this->_mediaDirectory) {
             $config = $this->_objectManager->create('Magento\\Core\\Model\\File\\Storage\\Config', array('cacheFile' => $this->_configCacheFile));
             $config->save();
             $this->_mediaDirectory = str_replace($this->_workingDirectory, '', $config->getMediaDirectory());
             $allowedResources = $config->getAllowedResources();
             $this->_relativeFileName = str_replace($this->_mediaDirectory . '/', '', $this->_request->getPathInfo());
             $isAllowed = $this->_isAllowed;
             if (!$isAllowed($this->_relativeFileName, $allowedResources)) {
                 $this->_response->setHttpResponseCode(404);
                 return $this->_response;
             }
         }
         if (0 !== stripos($this->_request->getPathInfo(), $this->_mediaDirectory . '/')) {
             $this->_response->setHttpResponseCode(404);
             return $this->_response;
         }
         $sync = $this->_objectManager->get('Magento\\Core\\Model\\File\\Storage\\Synchronization');
         $sync->synchronize($this->_relativeFileName, $this->_request->getFilePath());
         if ($this->directory->isReadable($this->directory->getRelativePath($this->_request->getFilePath()))) {
             $this->_response->setFilePath($this->_request->getFilePath());
         } else {
             $this->_response->setHttpResponseCode(404);
         }
         return $this->_response;
     } catch (\Exception $e) {
         $this->_response->setHttpResponseCode(404);
         return $this->_response;
     }
 }