‪TYPO3CMS  9.5
TerUtility.php
Go to the documentation of this file.
1 <?php
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 
21 
29 {
33  public ‪$wsdlUrl;
34 
45  public function ‪fetchExtension($extensionKey, $version, $expectedMd5, $mirrorUrl)
46  {
47  if (
48  (bool)GeneralUtility::makeInstance(ExtensionConfiguration::class)->get('extensionmanager', 'offlineMode')
50  ) {
51  throw new ‪ExtensionManagerException('Extension Manager is in offline mode. No TER connection available.', 1437078620);
52  }
53  $extensionPath = strtolower($extensionKey);
54  $mirrorUrl .= $extensionPath[0] . '/' . $extensionPath[1] . '/' . $extensionPath . '_' . $version . '.t3x';
55  $t3x = \TYPO3\CMS\Core\Utility\GeneralUtility::getUrl($mirrorUrl);
56  $md5 = md5($t3x);
57  if ($t3x === false) {
58  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);
59  }
60  if ($md5 === $expectedMd5) {
61  // Fetch and return:
62  $extensionData = $this->‪decodeExchangeData($t3x);
63  } else {
64  throw new ‪ExtensionManagerException('Error: MD5 hash of downloaded file not as expected: ' . $md5 . ' != ' . $expectedMd5, 1334426098);
65  }
66  return $extensionData;
67  }
68 
81  public function ‪decodeServerData($externalData)
82  {
83  $parts = explode(':', $externalData, 4);
84  $dat = base64_decode($parts[2]);
85  gzuncompress($dat);
86  // compare hashes ignoring any leading whitespace. See bug #0000365.
87  if (ltrim($parts[0]) == md5($dat)) {
88  if ($parts[1] === 'gzcompress') {
89  if (function_exists('gzuncompress')) {
90  $dat = gzuncompress($dat);
91  } else {
92  throw new ‪ExtensionManagerException('Decoding Error: No decompressor available for compressed content. gzuncompress() function is not available!', 1342859463);
93  }
94  }
95  $listArr = unserialize($dat, ['allowed_classes' => false]);
96  if (!is_array($listArr)) {
97  throw new ‪ExtensionManagerException('Error: Unserialized information was not an array - strange!', 1342859489);
98  }
99  } else {
100  throw new ‪ExtensionManagerException('Error: MD5 hashes in T3X data did not match!', 1342859505);
101  }
102  return $listArr;
103  }
104 
113  public function ‪decodeExchangeData($stream)
114  {
115  $parts = explode(':', $stream, 3);
116  if ($parts[1] === 'gzcompress') {
117  if (function_exists('gzuncompress')) {
118  $parts[2] = gzuncompress($parts[2]);
119  } else {
120  throw new ‪ExtensionManagerException('Decoding Error: No decompressor available for compressed content. gzcompress()/gzuncompress() ' . 'functions are not available!', 1344761814);
121  }
122  }
123  if (hash_equals($parts[0], md5($parts[2]))) {
124  ‪$output = unserialize($parts[2], ['allowed_classes' => false]);
125  if (!is_array(‪$output)) {
126  throw new ‪ExtensionManagerException('Error: Content could not be unserialized to an array. Strange (since MD5 hashes match!)', 1344761938);
127  }
128  } else {
129  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);
130  }
131  return ‪$output;
132  }
133 }
‪TYPO3\CMS\Core\Configuration\ExtensionConfiguration
Definition: ExtensionConfiguration.php:42
‪TYPO3\CMS\Extensionmanager\Utility\Connection\TerUtility
Definition: TerUtility.php:29
‪TYPO3\CMS\Extensionmanager\Utility\Connection\TerUtility\decodeServerData
‪array decodeServerData($externalData)
Definition: TerUtility.php:80
‪TYPO3\CMS\Extensionmanager\Utility\Connection\TerUtility\fetchExtension
‪array fetchExtension($extensionKey, $version, $expectedMd5, $mirrorUrl)
Definition: TerUtility.php:44
‪TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException
Definition: ExtensionManagerException.php:23
‪$output
‪$output
Definition: annotationChecker.php:113
‪TYPO3\CMS\Extensionmanager\Utility\Connection
Definition: TerUtility.php:2
‪TYPO3\CMS\Core\Core\Environment\isComposerMode
‪static bool isComposerMode()
Definition: Environment.php:117
‪TYPO3\CMS\Core\Core\Environment
Definition: Environment.php:39
‪TYPO3\CMS\Extensionmanager\Utility\Connection\TerUtility\decodeExchangeData
‪array decodeExchangeData($stream)
Definition: TerUtility.php:112
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Extensionmanager\Utility\Connection\TerUtility\$wsdlUrl
‪string $wsdlUrl
Definition: TerUtility.php:32