Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connectivity check: test https OR ELSE http #31426

Merged
merged 1 commit into from
Mar 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions apps/settings/lib/Controller/CheckSetupController.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,19 +198,24 @@ private function hasInternetConnectivityProblems(): bool {
}

/**
* Checks if the Nextcloud server can connect to a specific URL using both HTTPS and HTTP
* Checks if the Nextcloud server can connect to a specific URL
* @param string $site site domain or full URL with http/https protocol
* @return bool
*/
private function isSiteReachable($sitename) {
$httpSiteName = 'http://' . $sitename . '/';
$httpsSiteName = 'https://' . $sitename . '/';

private function isSiteReachable(string $site): bool {
try {
$client = $this->clientService->newClient();
$client->get($httpSiteName);
$client->get($httpsSiteName);
// if there is no protocol, test http:// AND https://
if (preg_match('/^https?:\/\//', $site) !== 1) {
$httpSite = 'http://' . $site . '/';
$client->get($httpSite);
$httpsSite = 'https://' . $site . '/';
$client->get($httpsSite);
} else {
$client->get($site);
}
} catch (\Exception $e) {
$this->logger->error('Cannot connect to: ' . $sitename, [
$this->logger->error('Cannot connect to: ' . $site, [
'app' => 'internet_connection_check',
'exception' => $e,
]);
Expand Down
4 changes: 4 additions & 0 deletions config/config.sample.php
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,10 @@
* connection. If none of these hosts are reachable, the administration panel
* will show a warning. Set to an empty list to not do any such checks (warning
* will still be shown).
* If no protocol is provided, both http and https will be tested.
* For example, 'http://www.nextcloud.com' and 'https://www.nextcloud.com'
* will be tested for 'www.nextcloud.com'
* If a protocol is provided, only this one will be tested.
*
* Defaults to the following domains:
*
Expand Down