TYPO3 CMS  TYPO3_7-6
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 
19 
26 {
30  public $wsdlUrl;
31 
36 
40  public function injectConfigurationUtility(\TYPO3\CMS\Extensionmanager\Utility\ConfigurationUtility $configurationUtility)
41  {
42  $this->configurationUtility = $configurationUtility;
43  }
44 
55  public function fetchExtension($extensionKey, $version, $expectedMd5, $mirrorUrl)
56  {
57  if (
58  !empty($this->configurationUtility->getCurrentConfiguration('extensionmanager')['offlineMode']['value'])
60  ) {
61  throw new ExtensionManagerException('Extension Manager is in offline mode. No TER connection available.', 1437078620);
62  }
63  $extensionPath = \TYPO3\CMS\Core\Utility\GeneralUtility::strtolower($extensionKey);
64  $mirrorUrl .= $extensionPath[0] . '/' . $extensionPath[1] . '/' . $extensionPath . '_' . $version . '.t3x';
65  $t3x = \TYPO3\CMS\Core\Utility\GeneralUtility::getUrl($mirrorUrl, 0, [TYPO3_user_agent]);
66  $md5 = md5($t3x);
67  if ($t3x === false) {
68  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);
69  }
70  if ($md5 === $expectedMd5) {
71  // Fetch and return:
72  $extensionData = $this->decodeExchangeData($t3x);
73  } else {
74  throw new ExtensionManagerException('Error: MD5 hash of downloaded file not as expected: ' . $md5 . ' != ' . $expectedMd5, 1334426098);
75  }
76  return $extensionData;
77  }
78 
91  public function decodeServerData($externalData)
92  {
93  $parts = explode(':', $externalData, 4);
94  $dat = base64_decode($parts[2]);
95  gzuncompress($dat);
96  // compare hashes ignoring any leading whitespace. See bug #0000365.
97  if (ltrim($parts[0]) == md5($dat)) {
98  if ($parts[1] == 'gzcompress') {
99  if (function_exists('gzuncompress')) {
100  $dat = gzuncompress($dat);
101  } else {
102  throw new ExtensionManagerException('Decoding Error: No decompressor available for compressed content. gzuncompress() function is not available!', 1342859463);
103  }
104  }
105  $listArr = unserialize($dat);
106  if (!is_array($listArr)) {
107  throw new ExtensionManagerException('Error: Unserialized information was not an array - strange!', 1342859489);
108  }
109  } else {
110  throw new ExtensionManagerException('Error: MD5 hashes in T3X data did not match!', 1342859505);
111  }
112  return $listArr;
113  }
114 
123  public function decodeExchangeData($stream)
124  {
125  $parts = explode(':', $stream, 3);
126  if ($parts[1] == 'gzcompress') {
127  if (function_exists('gzuncompress')) {
128  $parts[2] = gzuncompress($parts[2]);
129  } else {
130  throw new ExtensionManagerException('Decoding Error: No decompressor available for compressed content. gzcompress()/gzuncompress() ' . 'functions are not available!', 1344761814);
131  }
132  }
133  if (md5($parts[2]) === $parts[0]) {
134  $output = unserialize($parts[2]);
135  if (!is_array($output)) {
136  throw new ExtensionManagerException('Error: Content could not be unserialized to an array. Strange (since MD5 hashes match!)', 1344761938);
137  }
138  } else {
139  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);
140  }
141  return $output;
142  }
143 }
fetchExtension($extensionKey, $version, $expectedMd5, $mirrorUrl)
Definition: TerUtility.php:55
injectConfigurationUtility(\TYPO3\CMS\Extensionmanager\Utility\ConfigurationUtility $configurationUtility)
Definition: TerUtility.php:40
static getUrl($url, $includeHeader=0, $requestHeaders=false, &$report=null)