‪TYPO3CMS  10.4
TerUtility.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
22 
30 {
41  public function ‪fetchExtension($extensionKey, $version, $expectedMd5, $mirrorUrl)
42  {
43  if (
44  (bool)GeneralUtility::makeInstance(ExtensionConfiguration::class)->get('extensionmanager', 'offlineMode')
46  ) {
47  throw new ‪ExtensionManagerException('Extension Manager is in offline mode. No TER connection available.', 1437078620);
48  }
49  $extensionPath = strtolower($extensionKey);
50  $mirrorUrl .= $extensionPath[0] . '/' . $extensionPath[1] . '/' . $extensionPath . '_' . $version . '.t3x';
51  $t3x = ‪GeneralUtility::getUrl($mirrorUrl);
52  $md5 = md5($t3x);
53  if ($t3x === false) {
54  throw new ‪ExtensionManagerException(sprintf('The T3X file "%s" could not be fetched. Possible reasons: network problems, allow_url_fopen is off, cURL is not enabled in Install Tool.', $mirrorUrl), 1334426097);
55  }
56  if ($md5 === $expectedMd5) {
57  // Fetch and return:
58  $extensionData = $this->‪decodeExchangeData($t3x);
59  } else {
60  throw new ‪ExtensionManagerException('Error: MD5 hash of downloaded file not as expected: ' . $md5 . ' != ' . $expectedMd5, 1334426098);
61  }
62  return $extensionData;
63  }
64 
73  public function ‪decodeExchangeData($stream)
74  {
75  $parts = explode(':', $stream, 3);
76  if ($parts[1] === 'gzcompress') {
77  if (function_exists('gzuncompress')) {
78  $parts[2] = (string)gzuncompress($parts[2]);
79  } else {
80  throw new ‪ExtensionManagerException('Decoding Error: No decompressor available for compressed content. gzcompress()/gzuncompress() functions are not available!', 1344761814);
81  }
82  }
83  if (hash_equals($parts[0], md5($parts[2]))) {
84  ‪$output = unserialize($parts[2], ['allowed_classes' => false]);
85  if (!is_array(‪$output)) {
86  throw new ‪ExtensionManagerException('Error: Content could not be unserialized to an array. Strange (since MD5 hashes match!)', 1344761938);
87  }
88  } else {
89  throw new ‪ExtensionManagerException('Error: MD5 mismatch. Maybe the extension file was downloaded and saved as a text file by the browser and thereby corrupted!? (Always select "All" filetype when saving extensions)', 1344761991);
90  }
91  return ‪$output;
92  }
93 }
‪TYPO3\CMS\Core\Configuration\ExtensionConfiguration
Definition: ExtensionConfiguration.php:45
‪TYPO3\CMS\Core\Utility\GeneralUtility\getUrl
‪static mixed getUrl($url, $includeHeader=0, $requestHeaders=null, &$report=null)
Definition: GeneralUtility.php:1748
‪TYPO3\CMS\Extensionmanager\Utility\Connection\TerUtility
Definition: TerUtility.php:30
‪TYPO3\CMS\Extensionmanager\Utility\Connection\TerUtility\fetchExtension
‪array fetchExtension($extensionKey, $version, $expectedMd5, $mirrorUrl)
Definition: TerUtility.php:41
‪TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException
Definition: ExtensionManagerException.php:24
‪$output
‪$output
Definition: annotationChecker.php:119
‪TYPO3\CMS\Extensionmanager\Utility\Connection
Definition: TerUtility.php:16
‪TYPO3\CMS\Core\Core\Environment\isComposerMode
‪static bool isComposerMode()
Definition: Environment.php:144
‪TYPO3\CMS\Core\Core\Environment
Definition: Environment.php:40
‪TYPO3\CMS\Extensionmanager\Utility\Connection\TerUtility\decodeExchangeData
‪array decodeExchangeData($stream)
Definition: TerUtility.php:73
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46