TYPO3 CMS  TYPO3_7-6
PharStreamWrapperInterceptor.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Core\IO;
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 
20 
21 class PharStreamWrapperInterceptor implements \TYPO3\PharStreamWrapper\Assertable
22 {
32  public function assert($path, $command)
33  {
34  if ($this->isAllowed($path) === true) {
35  return true;
36  }
37  throw new Exception(
38  sprintf('Executing %s is denied', $path),
39  1530103998
40  );
41  }
42 
47  protected function isAllowed($path)
48  {
49  $path = $this->determineBaseFile($path);
50  if (!GeneralUtility::isAbsPath($path)) {
51  $path = PATH_site . $path;
52  }
53 
56  $path,
57  PATH_site . 'typo3conf/ext/'
58  )
59  ) {
60  return true;
61  }
62 
63  return false;
64  }
65 
73  protected function normalizePath($path)
74  {
75  return rtrim(
78  $this->removePharPrefix($path)
79  )
80  ),
81  '/'
82  );
83  }
84 
89  protected function removePharPrefix($path)
90  {
91  return preg_replace('#^phar://#i', '', $path);
92  }
93 
102  protected function determineBaseFile($path)
103  {
104  $parts = explode('/', $this->normalizePath($path));
105 
106  while (count($parts)) {
107  $currentPath = implode('/', $parts);
108  if (@file_exists($currentPath)) {
109  return $currentPath;
110  }
111  array_pop($parts);
112  }
113 
114  return null;
115  }
116 }
static isFirstPartOfStr($str, $partStr)