TYPO3  7.6
FileDumpController.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Core\Controller;
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
24 
29 {
43  {
44  $parameters = array('eID' => 'dumpFile');
45  $t = $this->getGetOrPost($request, 't');
46  if ($t) {
47  $parameters['t'] = $t;
48  }
49  $f = $this->getGetOrPost($request, 'f');
50  if ($f) {
51  $parameters['f'] = $f;
52  }
53  $p = $this->getGetOrPost($request, 'p');
54  if ($p) {
55  $parameters['p'] = $p;
56  }
57 
58  if (GeneralUtility::hmac(implode('|', $parameters), 'resourceStorageDumpFile') === $this->getGetOrPost($request, 'token')) {
59  if (isset($parameters['f'])) {
60  $file = ResourceFactory::getInstance()->getFileObject($parameters['f']);
61  if ($file->isDeleted() || $file->isMissing()) {
62  $file = null;
63  }
64  } else {
65  $file = GeneralUtility::makeInstance(ProcessedFileRepository::class)->findByUid($parameters['p']);
66  if ($file->isDeleted()) {
67  $file = null;
68  }
69  }
70 
71  if ($file === null) {
73  }
74 
75  // Hook: allow some other process to do some security/access checks. Hook should issue 403 if access is rejected
76  if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['FileDumpEID.php']['checkFileAccess'])) {
77  foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['FileDumpEID.php']['checkFileAccess'] as $classRef) {
78  $hookObject = GeneralUtility::getUserObj($classRef);
79  if (!$hookObject instanceof FileDumpEIDHookInterface) {
80  throw new \UnexpectedValueException('FileDump hook object must implement interface ' . FileDumpEIDHookInterface::class, 1394442417);
81  }
82  $hookObject->checkFileAccess($file);
83  }
84  }
85  $file->getStorage()->dumpFileContents($file);
86  // @todo Refactor FAL to not echo directly, but to implement a stream for output here and use response
87  return null;
88  } else {
89  return $response->withStatus(403);
90  }
91  }
92 
98  protected function getGetOrPost(ServerRequestInterface $request, $parameter)
99  {
100  return isset($request->getParsedBody()[$parameter])
101  ? $request->getParsedBody()[$parameter]
102  : (isset($request->getQueryParams()[$parameter]) ? $request->getQueryParams()[$parameter] : null);
103  }
104 }