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
1 change: 1 addition & 0 deletions apps/dav/composer/composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@
'OCA\\DAV\\Settings\\AvailabilitySettings' => $baseDir . '/../lib/Settings/AvailabilitySettings.php',
'OCA\\DAV\\Settings\\CalDAVSettings' => $baseDir . '/../lib/Settings/CalDAVSettings.php',
'OCA\\DAV\\SetupChecks\\NeedsSystemAddressBookSync' => $baseDir . '/../lib/SetupChecks/NeedsSystemAddressBookSync.php',
'OCA\\DAV\\SetupChecks\\WebdavEndpoint' => $baseDir . '/../lib/SetupChecks/WebdavEndpoint.php',
'OCA\\DAV\\Storage\\PublicOwnerWrapper' => $baseDir . '/../lib/Storage/PublicOwnerWrapper.php',
'OCA\\DAV\\SystemTag\\SystemTagList' => $baseDir . '/../lib/SystemTag/SystemTagList.php',
'OCA\\DAV\\SystemTag\\SystemTagMappingNode' => $baseDir . '/../lib/SystemTag/SystemTagMappingNode.php',
Expand Down
1 change: 1 addition & 0 deletions apps/dav/composer/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@ class ComposerStaticInitDAV
'OCA\\DAV\\Settings\\AvailabilitySettings' => __DIR__ . '/..' . '/../lib/Settings/AvailabilitySettings.php',
'OCA\\DAV\\Settings\\CalDAVSettings' => __DIR__ . '/..' . '/../lib/Settings/CalDAVSettings.php',
'OCA\\DAV\\SetupChecks\\NeedsSystemAddressBookSync' => __DIR__ . '/..' . '/../lib/SetupChecks/NeedsSystemAddressBookSync.php',
'OCA\\DAV\\SetupChecks\\WebdavEndpoint' => __DIR__ . '/..' . '/../lib/SetupChecks/WebdavEndpoint.php',
'OCA\\DAV\\Storage\\PublicOwnerWrapper' => __DIR__ . '/..' . '/../lib/Storage/PublicOwnerWrapper.php',
'OCA\\DAV\\SystemTag\\SystemTagList' => __DIR__ . '/..' . '/../lib/SystemTag/SystemTagList.php',
'OCA\\DAV\\SystemTag\\SystemTagMappingNode' => __DIR__ . '/..' . '/../lib/SystemTag/SystemTagMappingNode.php',
Expand Down
2 changes: 2 additions & 0 deletions apps/dav/lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
use OCA\DAV\Search\EventsSearchProvider;
use OCA\DAV\Search\TasksSearchProvider;
use OCA\DAV\SetupChecks\NeedsSystemAddressBookSync;
use OCA\DAV\SetupChecks\WebdavEndpoint;
use OCA\DAV\UserMigration\CalendarMigrator;
use OCA\DAV\UserMigration\ContactsMigrator;
use OCP\Accounts\UserUpdatedEvent;
Expand Down Expand Up @@ -211,6 +212,7 @@ public function register(IRegistrationContext $context): void {
$context->registerUserMigrator(ContactsMigrator::class);

$context->registerSetupCheck(NeedsSystemAddressBookSync::class);
$context->registerSetupCheck(WebdavEndpoint::class);
}

public function boot(IBootContext $context): void {
Expand Down
93 changes: 93 additions & 0 deletions apps/dav/lib/SetupChecks/WebdavEndpoint.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<?php

declare(strict_types=1);

/**
* @copyright Copyright (c) 2024 Côme Chilliet <[email protected]>
*
* @author Côme Chilliet <[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\DAV\SetupChecks;

use OCA\Settings\SetupChecks\CheckServerResponseTrait;
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;

class WebdavEndpoint 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('WebDAV endpoint');
}

public function run(): SetupResult {
$urls = [
['propfind', '/remote.php/webdav', [207, 401]],
];

foreach ($urls as [$verb,$url,$validStatuses]) {
$works = null;
foreach ($this->runRequest($verb, $url, ['httpErrors' => false]) as $response) {
// Check that the response status matches
$works = in_array($response->getStatusCode(), $validStatuses);
// Skip the other requests if one works
if ($works === true) {
break;
}
}
// If 'works' is null then we could not connect to the server
if ($works === null) {
return SetupResult::info(
$this->l10n->t('Could not check that your web server is properly set up to allow file synchronization over WebDAV. Please check manually.') . "\n" . $this->serverConfigHelp(),
$this->urlGenerator->linkToDocs('admin-setup-well-known-URL'),
);
}
// Otherwise if we fail we can abort here
if ($works === false) {
return SetupResult::error(
$this->l10n->t('Your web server is not yet properly set up to allow file synchronization, because the WebDAV interface seems to be broken.') . "\n" . $this->serverConfigHelp(),
);
}
}
return SetupResult::success(
$this->l10n->t('Your web server is properly set up to allow file synchronization over WebDAV.')
);
}
}
4 changes: 1 addition & 3 deletions apps/settings/src/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,8 @@ window.addEventListener('DOMContentLoaded', () => {
const setupChecks = () => {
// run setup checks then gather error messages
$.when(
OC.SetupChecks.checkWebDAV(),
OC.SetupChecks.checkSetup(),
).then((check1, check2) => {
const messages = [].concat(check1, check2)
).then((messages) => {
const $el = $('#postsetupchecks')
$('#security-warning-state-loading').addClass('hidden')

Expand Down
31 changes: 0 additions & 31 deletions core/js/setupchecks.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,37 +15,6 @@
MESSAGE_TYPE_INFO:0,
MESSAGE_TYPE_WARNING:1,
MESSAGE_TYPE_ERROR:2,
/**
* Check whether the WebDAV connection works.
*
* @return $.Deferred object resolved with an array of error messages
*/
checkWebDAV: function() {
var deferred = $.Deferred();
var afterCall = function(xhr) {
var messages = [];
if (xhr.status !== 207 && xhr.status !== 401) {
messages.push({
msg: t('core', 'Your web server is not yet properly set up to allow file synchronization, because the WebDAV interface seems to be broken.'),
type: OC.SetupChecks.MESSAGE_TYPE_ERROR
});
}
deferred.resolve(messages);
};

$.ajax({
type: 'PROPFIND',
url: OC.linkToRemoteBase('webdav'),
data: '<?xml version="1.0"?>' +
'<d:propfind xmlns:d="DAV:">' +
'<d:prop><d:resourcetype/></d:prop>' +
'</d:propfind>',
contentType: 'application/xml; charset=utf-8',
complete: afterCall,
allowAuthErrors: true
});
return deferred.promise();
},

/**
* Runs setup checks on the server side
Expand Down
38 changes: 0 additions & 38 deletions core/js/tests/specs/setupchecksSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,44 +22,6 @@ describe('OC.SetupChecks tests', function() {
protocolStub.restore();
});

describe('checkWebDAV', function() {
it('should fail with another response status code than 201 or 207', function(done) {
var async = OC.SetupChecks.checkWebDAV();

suite.server.requests[0].respond(200);

async.done(function( data, s, x ){
expect(data).toEqual([{
msg: 'Your web server is not yet properly set up to allow file synchronization, because the WebDAV interface seems to be broken.',
type: OC.SetupChecks.MESSAGE_TYPE_ERROR
}]);
done();
});
});

it('should return no error with a response status code of 207', function(done) {
var async = OC.SetupChecks.checkWebDAV();

suite.server.requests[0].respond(207);

async.done(function( data, s, x ){
expect(data).toEqual([]);
done();
});
});

it('should return no error with a response status code of 401', function(done) {
var async = OC.SetupChecks.checkWebDAV();

suite.server.requests[0].respond(401);

async.done(function( data, s, x ){
expect(data).toEqual([]);
done();
});
});
});

describe('checkSetup', function() {
it('should return an error if server has no internet connection', function(done) {
var async = OC.SetupChecks.checkSetup();
Expand Down
4 changes: 2 additions & 2 deletions dist/settings-legacy-admin.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading