-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #43588 from nextcloud/feat/woff2-check-setupcheck
- Loading branch information
Showing
11 changed files
with
214 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
apps/settings/lib/SetupChecks/CheckServerResponseTrait.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* @copyright Copyright (c) 2024 Ferdinand Thiessen <[email protected]> | ||
* | ||
* @author Ferdinand Thiessen <[email protected]> | ||
* | ||
* @license AGPL-3.0-or-later | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
namespace OCA\Settings\SetupChecks; | ||
|
||
use Generator; | ||
use OCP\Http\Client\IClientService; | ||
use OCP\Http\Client\IResponse; | ||
use OCP\IConfig; | ||
use OCP\IL10N; | ||
use OCP\IURLGenerator; | ||
|
||
/** | ||
* Common trait for setup checks that need to use requests to the same server and check the response | ||
*/ | ||
trait CheckServerResponseTrait { | ||
protected IConfig $config; | ||
protected IURLGenerator $urlGenerator; | ||
protected IClientService $clientService; | ||
protected IL10N $l10n; | ||
|
||
/** | ||
* Common helper string in case a check could not fetch any results | ||
*/ | ||
protected function serverConfigHelp(): string { | ||
return $this->l10n->t('To allow this check to run you have to make sure that your webserver can connect to itself. Therefor it must be able to resolve and connect to at least one its `trusted_domains` or the `overwrite.cli.url`.'); | ||
} | ||
|
||
/** | ||
* Get all possible URLs that need to be checked for a local request test. | ||
* This takes all `trusted_domains` and the CLI overwrite URL into account. | ||
* | ||
* @param string $url The relative URL to test | ||
* @return string[] List of possible absolute URLs | ||
*/ | ||
protected function getTestUrls(string $url): array { | ||
$hosts = $this->config->getSystemValue('trusted_domains', []); | ||
$cliUrl = $this->config->getSystemValue('overwrite.cli.url', ''); | ||
if ($cliUrl !== '') { | ||
$hosts[] = $cliUrl; | ||
} | ||
|
||
$testUrls = array_merge( | ||
[$this->urlGenerator->getAbsoluteURL($url)], | ||
array_map(fn (string $host): string => $host . $url, $hosts), | ||
); | ||
|
||
return $testUrls; | ||
} | ||
|
||
/** | ||
* Run a HEAD request to check header | ||
* @param string $url The relative URL to check | ||
* @param bool $ignoreSSL Ignore SSL certificates | ||
* @return Generator<int, IResponse> | ||
*/ | ||
protected function runHEAD(string $url, bool $ignoreSSL = true): Generator { | ||
$client = $this->clientService->newClient(); | ||
$requestOptions = $this->getRequestOptions($ignoreSSL); | ||
|
||
foreach ($this->getTestUrls($url) as $testURL) { | ||
try { | ||
yield $client->head($testURL, $requestOptions); | ||
} catch (\Throwable $e) { | ||
$this->logger->debug('Can not connect to local server for running setup checks', ['exception' => $e, 'url' => $testURL]); | ||
} | ||
} | ||
} | ||
|
||
protected function getRequestOptions(bool $ignoreSSL): array { | ||
$requestOptions = [ | ||
'connect_timeout' => 10, | ||
'nextcloud' => [ | ||
'allow_local_address' => true, | ||
], | ||
]; | ||
if ($ignoreSSL) { | ||
$requestOptions['verify'] = false; | ||
} | ||
return $requestOptions; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* @copyright Copyright (c) 2024 Ferdinand Thiessen <[email protected]> | ||
* | ||
* @author Ferdinand Thiessen <[email protected]> | ||
* | ||
* @license AGPL-3.0-or-later | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
namespace OCA\Settings\SetupChecks; | ||
|
||
use OCP\Http\Client\IClientService; | ||
use OCP\IConfig; | ||
use OCP\IL10N; | ||
use OCP\IURLGenerator; | ||
use OCP\SetupCheck\ISetupCheck; | ||
use OCP\SetupCheck\SetupResult; | ||
use Psr\Log\LoggerInterface; | ||
|
||
/** | ||
* Check whether the WOFF2 URLs works | ||
*/ | ||
class Woff2Loading implements ISetupCheck { | ||
use CheckServerResponseTrait; | ||
|
||
public function __construct( | ||
protected IL10N $l10n, | ||
protected IConfig $config, | ||
protected IURLGenerator $urlGenerator, | ||
protected IClientService $clientService, | ||
protected LoggerInterface $logger, | ||
) { | ||
} | ||
|
||
public function getCategory(): string { | ||
return 'network'; | ||
} | ||
|
||
public function getName(): string { | ||
return $this->l10n->t('WOFF2 file loading'); | ||
} | ||
|
||
public function run(): SetupResult { | ||
$url = $this->urlGenerator->linkTo('', 'core/fonts/NotoSans-Regular-latin.woff2'); | ||
$noResponse = true; | ||
$responses = $this->runHEAD($url); | ||
foreach ($responses as $response) { | ||
$noResponse = false; | ||
if ($response->getStatusCode() === 200) { | ||
return SetupResult::success(); | ||
} | ||
} | ||
|
||
if ($noResponse) { | ||
return SetupResult::info( | ||
$this->l10n->t('Could not check for WOFF2 loading support. Please check manually if your webserver serves `.woff2` files.') . "\n" . $this->serverConfigHelp(), | ||
$this->urlGenerator->linkToDocs('admin-nginx'), | ||
); | ||
} | ||
return SetupResult::warning( | ||
$this->l10n->t('Your web server is not properly set up to deliver .woff2 files. This is typically an issue with the Nginx configuration. For Nextcloud 15 it needs an adjustement to also deliver .woff2 files. Compare your Nginx configuration to the recommended configuration in our documentation.'), | ||
$this->urlGenerator->linkToDocs('admin-nginx'), | ||
); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.