{if $authInsufficient}
<woltlab-core-notice type="warning">{lang}wcf.acp.package.update.authInsufficient{/lang}</woltlab-core-notice>
{else}
- <woltlab-core-notice type="{if $serverReply[statusCode] == 401}error{else}warning{/if}">{lang}wcf.acp.package.update.errorCode.{@$serverReply[statusCode]}{/lang}</woltlab-core-notice>
+ <woltlab-core-notice type="{if $responseStatusCode == 401}error{else}warning{/if}">{lang}wcf.acp.package.update.errorCode.{$responseStatusCode}{/lang}</woltlab-core-notice>
{/if}
{/if}
{/if}
<dl>
<dt>{lang}wcf.acp.package.update.server.url{/lang}</dt>
- <dd>{@$updateServer->getHighlightedURL()}</dd>
+ <dd>{unsafe:$updateServer->getHighlightedURL()}</dd>
</dl>
<dl>
<dt>{lang}wcf.acp.package.update.server.message{/lang}</dt>
- <dd>{$serverReply[body]}</dd>
+ <dd>{$responseMessage}</dd>
</dl>
</section>
</section>
<div class="formSubmit">
- <button type="button" class="button buttonPrimary" data-type="submit" data-package-update-server-id="{@$updateServer->packageUpdateServerID}">{lang}wcf.global.button.submit{/lang}</button>
+ <button type="button" class="button buttonPrimary" data-type="submit" data-package-update-server-id="{$updateServer->packageUpdateServerID}">{lang}wcf.global.button.submit{/lang}</button>
</div>
namespace wcf\system\package;
+use GuzzleHttp\Exception\ClientException;
+use GuzzleHttp\Psr7\Request;
+use GuzzleHttp\RequestOptions;
use wcf\data\package\Package;
use wcf\data\package\PackageCache;
use wcf\data\package\update\PackageUpdate;
use wcf\data\package\update\server\PackageUpdateServer;
use wcf\system\database\util\PreparedStatementConditionBuilder;
-use wcf\system\exception\HTTPUnauthorizedException;
use wcf\system\exception\NamedUserException;
use wcf\system\exception\SystemException;
-use wcf\system\io\File;
+use wcf\system\io\HttpFactory;
use wcf\system\package\exception\IncoherentUpdatePath;
use wcf\system\package\exception\UnknownUpdatePath;
use wcf\system\WCF;
use wcf\util\FileUtil;
-use wcf\util\HTTPRequest;
/**
* Contains business logic related to preparation of package installations.
foreach ($packageUpdateVersions as $packageUpdateVersion) {
// get auth data
$authData = $this->getAuthData($packageUpdateVersion);
+ $options = [];
+ if (!empty($authData)) {
+ $options[RequestOptions::AUTH] = [
+ $authData['username'],
+ $authData['password'],
+ ];
+ }
+ $client = HttpFactory::makeClient($options);
if ($packageUpdateVersion['filename']) {
- $request = new HTTPRequest(
+ $request = new Request(
+ 'POST',
$packageUpdateVersion['filename'],
- (!empty($authData) ? ['auth' => $authData] : []),
- [
- 'apiVersion' => PackageUpdate::API_VERSION,
- ]
+ ['Content-Type' => 'application/x-www-form-urlencoded'],
+ \http_build_query(
+ ['apiVersion' => PackageUpdate::API_VERSION],
+ '',
+ '&',
+ \PHP_QUERY_RFC1738
+ )
);
} else {
$parameters = [
$parameters['instanceId'] = \hash_hmac('sha256', 'api.woltlab.com', \WCF_UUID);
}
- $request = new HTTPRequest(
+ $request = new Request(
+ 'POST',
$this->packageUpdateServers[$packageUpdateVersion['packageUpdateServerID']]->getDownloadURL(),
- (!empty($authData) ? ['auth' => $authData] : []),
- $parameters
+ ['Content-Type' => 'application/x-www-form-urlencoded'],
+ \http_build_query(
+ $parameters,
+ '',
+ '&',
+ \PHP_QUERY_RFC1738
+ )
);
}
try {
- $request->execute();
- } catch (HTTPUnauthorizedException $e) {
+ $response = $client->send($request);
+ } catch (ClientException $e) {
throw new PackageUpdateUnauthorizedException(
- $request,
+ $e->getResponse()->getStatusCode(),
+ $e->getResponse()->getHeaders(),
+ $e->getResponse()->getBody(),
$this->packageUpdateServers[$packageUpdateVersion['packageUpdateServerID']],
$packageUpdateVersion
);
}
- $response = $request->getReply();
-
// check response
- if ($response['statusCode'] != 200) {
+ if ($response->getStatusCode() !== 200) {
throw new SystemException(WCF::getLanguage()->getDynamicVariable(
'wcf.acp.package.error.downloadFailed',
['__downloadPackage' => $package]
- ) . ' (' . $response['body'] . ')');
+ ) . ' (' . $response->getBody() . ')');
}
// write content to tmp file
$filename = FileUtil::getTemporaryFilename('package_');
- \file_put_contents($filename, $response['body']);
- unset($response['body']);
+ \file_put_contents($filename, $response->getBody());
+ unset($response);
// test package
$archive = new PackageArchive($filename);
namespace wcf\system\package;
+use GuzzleHttp\Exception\ClientException;
use GuzzleHttp\Psr7\Request;
+use GuzzleHttp\RequestOptions;
use Psr\Http\Client\ClientExceptionInterface;
use wcf\data\package\Package;
use wcf\data\package\update\server\PackageUpdateServer;
use wcf\system\cache\builder\PackageUpdateCacheBuilder;
use wcf\system\database\util\PreparedStatementConditionBuilder;
use wcf\system\event\EventHandler;
-use wcf\system\exception\HTTPUnauthorizedException;
use wcf\system\exception\SystemException;
use wcf\system\io\HttpFactory;
use wcf\system\package\validation\PackageValidationException;
use wcf\system\SingletonFactory;
use wcf\system\WCF;
-use wcf\util\HTTPRequest;
use wcf\util\JSON;
use wcf\util\StringUtil;
use wcf\util\XML;
} catch (SystemException $e) {
$errorMessage = $e->getMessage();
} catch (PackageUpdateUnauthorizedException $e) {
- $body = $e->getRequest()->getReply()['body'];
+ $body = $e->getResponseMessage();
// Try to find the page <title>.
if (\preg_match('~<title>(?<title>.*?)</title>~', $body, $matches)) {
*/
private function getPackageUpdateXML(PackageUpdateServer $updateServer)
{
- $settings = [];
$authData = $updateServer->getAuthData();
- if ($authData) {
- $settings['auth'] = $authData;
+ $options = [];
+ if (!empty($authData)) {
+ $options[RequestOptions::AUTH] = [
+ $authData['username'],
+ $authData['password'],
+ ];
}
-
- $request = new HTTPRequest($updateServer->getListURL(), $settings);
+ $client = HttpFactory::makeClient($options);
+ $headers = [];
$requestedVersion = \wcf\getMinorVersion();
if (PackageUpdateServer::isUpgradeOverrideEnabled()) {
$requestedVersion = WCF::AVAILABLE_UPGRADE_VERSION;
}
-
- $request->addHeader(
- 'requested-woltlab-suite-version',
- $requestedVersion
- );
+ $headers['requested-woltlab-suite-version'] = $requestedVersion;
$apiVersion = $updateServer->apiVersion;
if (\in_array($apiVersion, ['2.1', '3.1'])) {
) {
$metaData = $updateServer->getMetaData();
if (isset($metaData['list']['etag'])) {
- $request->addHeader('if-none-match', $metaData['list']['etag']);
+ $headers['if-none-match'] = $metaData['list']['etag'];
}
if (isset($metaData['list']['lastModified'])) {
- $request->addHeader('if-modified-since', $metaData['list']['lastModified']);
+ $headers['if-modified-since'] = $metaData['list']['lastModified'];
}
}
}
- try {
- $request->execute();
- $reply = $request->getReply();
- } catch (HTTPUnauthorizedException $e) {
- throw new PackageUpdateUnauthorizedException($request, $updateServer);
- } catch (SystemException $e) {
- $reply = $request->getReply();
+ $request = new Request(
+ 'GET',
+ $updateServer->getListURL(),
+ $headers
+ );
- $statusCode = \is_array($reply['statusCode']) ? \reset($reply['statusCode']) : $reply['statusCode'];
+ try {
+ $response = $client->send($request);
+ } catch (ClientException $e) {
+ throw new PackageUpdateUnauthorizedException(
+ $e->getResponse()->getStatusCode(),
+ $e->getResponse()->getHeaders(),
+ $e->getResponse()->getBody(),
+ $updateServer,
+ );
+ }
+ if ($response->getStatusCode() !== 200 && $response->getStatusCode() !== 304) {
throw new SystemException(
- WCF::getLanguage()->get('wcf.acp.package.update.error.listNotFound') . ' (' . $statusCode . ')'
+ WCF::getLanguage()->get('wcf.acp.package.update.error.listNotFound') . ' (' . $response->getStatusCode() . ')'
);
}
];
// check if server indicates support for a newer API
- if ($updateServer->apiVersion !== '3.1' && !empty($reply['httpHeaders']['wcf-update-server-api'])) {
- $apiVersions = \explode(' ', \reset($reply['httpHeaders']['wcf-update-server-api']));
+ if ($updateServer->apiVersion !== '3.1' && !empty($response->getHeaders()['wcf-update-server-api'])) {
+ $apiVersions = \explode(' ', \reset($response->getHeaders()['wcf-update-server-api']));
if (\in_array('3.1', $apiVersions)) {
$apiVersion = $data['apiVersion'] = '3.1';
} elseif (\in_array('2.1', $apiVersions)) {
// parse given package update xml
$allNewPackages = false;
- if ($apiVersion === '2.0' || $reply['statusCode'] != 304) {
- $allNewPackages = $this->parsePackageUpdateXML($updateServer, $reply['body'], $apiVersion);
+ if ($apiVersion === '2.0' || $response->getStatusCode() != 304) {
+ $allNewPackages = $this->parsePackageUpdateXML($updateServer, $response->getBody(), $apiVersion);
}
$metaData = [];
if (\in_array($apiVersion, ['2.1', '3.1'])) {
- if (empty($reply['httpHeaders']['etag']) && empty($reply['httpHeaders']['last-modified'])) {
+ if (empty($response->getHeaders()['etag']) && empty($response->getHeaders()['last-modified'])) {
throw new SystemException("Missing required HTTP headers 'etag' and 'last-modified'.");
}
$metaData['list'] = [];
- if (!empty($reply['httpHeaders']['etag'])) {
- $metaData['list']['etag'] = \reset($reply['httpHeaders']['etag']);
+ if (!empty($response->getHeaders()['etag'])) {
+ $metaData['list']['etag'] = \reset($response->getHeaders()['etag']);
}
- if (!empty($reply['httpHeaders']['last-modified'])) {
- $metaData['list']['lastModified'] = \reset($reply['httpHeaders']['last-modified']);
+ if (!empty($response->getHeaders()['last-modified'])) {
+ $metaData['list']['lastModified'] = \reset($response->getHeaders()['last-modified']);
}
}
$data['metaData'] = \serialize($metaData);
- unset($request, $reply);
+ unset($request, $response);
if ($allNewPackages !== false) {
// purge package list
use wcf\data\package\update\server\PackageUpdateServer;
use wcf\system\exception\UserException;
use wcf\system\WCF;
-use wcf\util\HTTPRequest;
/**
- * Credentials for update server are either missing or invalid.
+ * Handles the case that the credentials for update server are either missing or invalid.
*
- * @author Alexander Ebert
- * @copyright 2001-2019 WoltLab GmbH
- * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @author Alexander Ebert
+ * @copyright 2001-2024 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
*/
-class PackageUpdateUnauthorizedException extends UserException
+final class PackageUpdateUnauthorizedException extends UserException
{
/**
- * package update version
- * @var array
- */
- protected $packageUpdateVersion = [];
-
- /**
- * HTTP request object
- * @var HTTPRequest
- */
- protected $request;
-
- /**
- * package update server object
- * @var PackageUpdateServer
- */
- protected $updateServer;
-
- /**
- * Creates a new PackageUpdateUnauthorizedException object.
- *
- * @param HTTPRequest $request
- * @param PackageUpdateServer $updateServer
- * @param array $packageUpdateVersion
+ * @param string[] $responseHeaders
+ * @param mixed[] $packageUpdateVersion
*/
public function __construct(
- HTTPRequest $request,
- PackageUpdateServer $updateServer,
- array $packageUpdateVersion = []
+ private readonly int $responseStatusCode,
+ private readonly array $responseHeaders,
+ private readonly string $responseMessage,
+ private readonly PackageUpdateServer $updateServer,
+ private readonly array $packageUpdateVersion = []
) {
- $this->request = $request;
- $this->updateServer = $updateServer;
- $this->packageUpdateVersion = $packageUpdateVersion;
}
/**
* Returns the rendered template.
- *
- * @return string
*/
- public function getRenderedTemplate()
+ public function getRenderedTemplate(): string
{
- $serverReply = $this->request->getReply();
-
$requiresPaidUpgrade = false;
if ($this->updateServer->isWoltLabStoreServer() && !empty($this->packageUpdateVersion['pluginStoreFileID'])) {
- $requiresPaidUpgrade = ($serverReply['httpHeaders']['wcf-update-server-requires-paid-upgrade'][0] ?? '') === 'true';
+ $requiresPaidUpgrade = ($this->responseHeaders['wcf-update-server-requires-paid-upgrade'][0] ?? '') === 'true';
}
if ($requiresPaidUpgrade) {
return WCF::getTPL()->fetch('packageUpdateUnauthorizedPaidUpgrade');
}
- $authInsufficient = (($serverReply['httpHeaders']['wcf-update-server-auth'][0] ?? '') === 'unauthorized');
+ $authInsufficient = (($this->responseHeaders['wcf-update-server-auth'][0] ?? '') === 'unauthorized');
if ($authInsufficient && !empty($this->packageUpdateVersion['pluginStoreFileID'])) {
$hasOnlyTrustedServers = true;
foreach (PackageUpdateServer::getActiveUpdateServers() as $updateServer) {
WCF::getTPL()->assign([
'authInsufficient' => $authInsufficient,
'packageUpdateVersion' => $this->packageUpdateVersion,
- 'request' => $this->request,
'updateServer' => $this->updateServer,
'serverAuthData' => $this->updateServer->getAuthData(),
- 'serverReply' => $serverReply,
'requiresPaidUpgrade' => $requiresPaidUpgrade,
+ 'responseStatusCode' => $this->responseStatusCode,
+ 'responseHeaders' => $this->responseHeaders,
+ 'responseMessage' => $this->responseMessage,
]);
return WCF::getTPL()->fetch('packageUpdateUnauthorized');
}
- /**
- * Returns package update version.
- *
- * @return array
- */
- public function getPackageUpdateVersion()
- {
- return $this->packageUpdateVersion;
- }
-
- /**
- * Returns the HTTP request object.
- *
- * @return HTTPRequest
- */
- public function getRequest()
- {
- return $this->request;
- }
-
- /**
- * Returns package update server object.
- *
- * @return PackageUpdateServer
- */
- public function getUpdateServer()
+ public function getResponseMessage(): string
{
- return $this->updateServer;
+ return $this->responseMessage;
}
}
* @author Tim Duesterhus
* @copyright 2001-2019 WoltLab GmbH
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
- * @deprecated 5.3 - Use Guzzle via \wcf\system\io\HttpFactory.
+ * @deprecated 5.3 - Use Guzzle via \wcf\system\io\HttpFactory. Will be removed with 7.0.
*/
final class HTTPRequest
{
* @copyright 2001-2019 WoltLab GmbH
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
* @since 3.0
- * @deprecated 5.3 This exception is intimately tied to HTTPRequest which is deprecated.
+ * @deprecated 5.3 This exception is intimately tied to HTTPRequest which is deprecated. Will be removed with 7.0.
*/
class HTTPException extends SystemException implements IExtraInformationException
{