Skip to content
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
4 changes: 2 additions & 2 deletions apps/federation/lib/Controller/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ protected function checkServer($url) {
}

if ($this->trustedServers->isOwnCloudServer($url) === false) {
$message = 'No server to federate found';
$hint = $this->l->t('No server to federate found');
$message = 'No server to federate with found';
$hint = $this->l->t('No server to federate with found');
throw new HintException($message, $hint);
}

Expand Down
2 changes: 1 addition & 1 deletion apps/federation/lib/DbHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public function addServer($url) {
if ($result) {
return (int)$this->connection->lastInsertId('*PREFIX*'.$this->dbTable);
} else {
$message = 'Internal failure, Could not add ownCloud as trusted server: ' . $url;
$message = 'Internal failure, Could not add trusted server: ' . $url;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could not add trusted server = The server is trusted but you were not able to add
Could not add **as** trusted server = The server could not be added because there is a problem with the trust

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The server could not be added because there is a problem with the trust

There is no problem with the trust, the error happens most likely if you point to a URL which doesn't run a Nextcloud/ownCloud. So you could for example argue that if you add your webapage it is a page you trust, but well it is no Nextcloud so it can't be added. Anyway, this is just a log message to identify the code path which failed.

$message_t = $this->IL10N->t('Could not add server');
throw new HintException($message, $message_t);
}
Expand Down
26 changes: 16 additions & 10 deletions apps/federation/lib/TrustedServers.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,23 +211,29 @@ public function getServerStatus($url) {
}

/**
* check if URL point to a ownCloud server
* check if URL point to a ownCloud/Nextcloud server
*
* @param string $url
* @return bool
*/
public function isOwnCloudServer($url) {
$isValidOwnCloud = false;
$client = $this->httpClientService->newClient();
$result = $client->get(
$url . '/status.php',
[
'timeout' => 3,
'connect_timeout' => 3,
]
);
if ($result->getStatusCode() === Http::STATUS_OK) {
$isValidOwnCloud = $this->checkOwnCloudVersion($result->getBody());
try {
$result = $client->get(
$url . '/status.php',
[
'timeout' => 3,
'connect_timeout' => 3,
]
);
if ($result->getStatusCode() === Http::STATUS_OK) {
$isValidOwnCloud = $this->checkOwnCloudVersion($result->getBody());

}
} catch (\Exception $e) {
$this->logger->debug('No Nextcloud server: ' . $e->getMessage());
return false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we somehow log the error message here? This would make it a lot easier to debug when needed (so debug log level is enough)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added, please review 😃

}

return $isValidOwnCloud;
Expand Down
3 changes: 1 addition & 2 deletions apps/federation/tests/TrustedServersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,6 @@ public function dataTestIsOwnCloudServer() {
}

/**
* @expectedException \Exception
* @expectedExceptionMessage simulated exception
*/
public function testIsOwnCloudServerFail() {
Expand All @@ -323,7 +322,7 @@ public function testIsOwnCloudServerFail() {
throw new \Exception('simulated exception');
});

$this->trustedServers->isOwnCloudServer($server);
$this->assertFalse($this->trustedServers->isOwnCloudServer($server));
}

/**
Expand Down