Skip to content

Commit d5574cf

Browse files
author
Julien Veyssier
committed
allow adding protocol to domains in 'connectivity_check_domains' config
Signed-off-by: Julien Veyssier <[email protected]>
1 parent c2d759d commit d5574cf

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

apps/settings/lib/Controller/CheckSetupController.php

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -198,19 +198,24 @@ private function hasInternetConnectivityProblems(): bool {
198198
}
199199

200200
/**
201-
* Checks if the Nextcloud server can connect to a specific URL using both HTTPS and HTTP
201+
* Checks if the Nextcloud server can connect to a specific URL
202+
* @param string $site site domain or full URL with http/https protocol
202203
* @return bool
203204
*/
204-
private function isSiteReachable($sitename) {
205-
$httpSiteName = 'http://' . $sitename . '/';
206-
$httpsSiteName = 'https://' . $sitename . '/';
207-
205+
private function isSiteReachable(string $site): bool {
208206
try {
209207
$client = $this->clientService->newClient();
210-
$client->get($httpSiteName);
211-
$client->get($httpsSiteName);
208+
// if there is no protocol, test http:// AND https://
209+
if (preg_match('/^https?:\/\//', $site) !== 1) {
210+
$httpSite = 'http://' . $site . '/';
211+
$client->get($httpSite);
212+
$httpsSite = 'https://' . $site . '/';
213+
$client->get($httpsSite);
214+
} else {
215+
$client->get($site);
216+
}
212217
} catch (\Exception $e) {
213-
$this->logger->error('Cannot connect to: ' . $sitename, [
218+
$this->logger->error('Cannot connect to: ' . $site, [
214219
'app' => 'internet_connection_check',
215220
'exception' => $e,
216221
]);

config/config.sample.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -767,6 +767,10 @@
767767
* connection. If none of these hosts are reachable, the administration panel
768768
* will show a warning. Set to an empty list to not do any such checks (warning
769769
* will still be shown).
770+
* If no protocol is provided, both http and https will be tested.
771+
* For example, 'http://www.nextcloud.com' and 'https://www.nextcloud.com'
772+
* will be tested for 'www.nextcloud.com'
773+
* If a protocol is provided, only this one will be tested.
770774
*
771775
* Defaults to the following domains:
772776
*

0 commit comments

Comments
 (0)