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 .htaccess
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
RewriteRule .* - [env=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteRule ^\.well-known/host-meta /public.php?service=host-meta [QSA,L]
RewriteRule ^\.well-known/host-meta\.json /public.php?service=host-meta-json [QSA,L]
RewriteRule ^\.well-known/webfinger /public.php?service=webfinger [QSA,L]
Copy link
Member

Choose a reason for hiding this comment

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

So I looked into it. And I'm not a fan of this.
Mostly because it redirect to a route that does not follow the appframework route.

All our apps should handle routes via the appframework. This ensures a lot of safety checks and features.

For now I would vote to make it a 301. And just to direct it to the route of the app.

If this becomes an issue we can later always add some wellKnownManager somewhere where apps can register themselfs. But for now this seems a bit of overengineering.

Copy link
Member Author

Choose a reason for hiding this comment

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

Can we keep it like this at least for 15, just returns a 301 in case of no config, or config redirect to an non-existant app, or non-existant php file ?

RewriteRule ^\.well-known/carddav /remote.php/dav/ [R=301,L]
RewriteRule ^\.well-known/caldav /remote.php/dav/ [R=301,L]
RewriteRule ^remote/(.*) remote.php [QSA,L]
Expand Down
9 changes: 7 additions & 2 deletions core/js/setupchecks.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,14 @@
* @param url the URL to test
* @param placeholderUrl the placeholder URL - can be found at oc_defaults.docPlaceholderUrl
* @param {boolean} runCheck if this is set to false the check is skipped and no error is returned
* @param {int} expectedStatus the expected HTTP status to be returned by the URL, 207 by default
* @return $.Deferred object resolved with an array of error messages
*/
checkWellKnownUrl: function(url, placeholderUrl, runCheck) {
checkWellKnownUrl: function(url, placeholderUrl, runCheck, expectedStatus) {
if (expectedStatus === undefined) {
expectedStatus = 207;
}

var deferred = $.Deferred();

if(runCheck === false) {
Expand All @@ -63,7 +68,7 @@
}
var afterCall = function(xhr) {
var messages = [];
if (xhr.status !== 207) {
if (xhr.status !== expectedStatus) {
var docUrl = placeholderUrl.replace('PLACEHOLDER', 'admin-setup-well-known-URL');
messages.push({
msg: t('core', 'Your web server is not properly set up to resolve "{url}". Further information can be found in the <a target="_blank" rel="noreferrer noopener" href="{docLink}">documentation</a>.', { docLink: docUrl, url: url }),
Expand Down
17 changes: 14 additions & 3 deletions core/js/tests/specs/setupchecksSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ describe('OC.SetupChecks tests', function() {
});

describe('checkWellKnownUrl', function() {
it('should fail with another response status code than 207', function(done) {
var async = OC.SetupChecks.checkWellKnownUrl('/.well-known/caldav', 'http://example.org/PLACEHOLDER', true);
it('should fail with another response status code than the expected one', function(done) {
var async = OC.SetupChecks.checkWellKnownUrl('/.well-known/caldav', 'http://example.org/PLACEHOLDER', true, 207);

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

Expand All @@ -75,7 +75,18 @@ describe('OC.SetupChecks tests', function() {
});
});

it('should return no error with a response status code of 207', function(done) {
it('should return no error with the expected response status code', function(done) {
var async = OC.SetupChecks.checkWellKnownUrl('/.well-known/caldav', 'http://example.org/PLACEHOLDER', true, 207);

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

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

it('should return no error with the default expected response status code', function(done) {
var async = OC.SetupChecks.checkWellKnownUrl('/.well-known/caldav', 'http://example.org/PLACEHOLDER', true);

suite.server.requests[0].respond(207);
Expand Down
2 changes: 1 addition & 1 deletion public.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
list($service) = explode('/', $pathInfo);
}
$file = \OC::$server->getConfig()->getAppValue('core', 'public_' . strip_tags($service));
if ($file === null) {
if ($file === '') {
http_response_code(404);
exit;
}
Expand Down
16 changes: 16 additions & 0 deletions settings/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ public function register() {

Util::connectHook('OC_User', 'post_setPassword', $this, 'onChangePassword');
Util::connectHook('OC_User', 'changeUser', $this, 'onChangeInfo');

Util::connectHook('\OCP\Config', 'js', $this, 'extendJsConfig');
}

/**
Expand Down Expand Up @@ -152,4 +154,18 @@ public function onChangeInfo(array $parameters) {
$hooks = $this->getContainer()->query(Hooks::class);
$hooks->onChangeEmail($parameters['user'], $parameters['old_value']);
}

/**
* @param array $settings
*/
public function extendJsConfig(array $settings) {
$appConfig = json_decode($settings['array']['oc_appconfig'], true);

$publicWebFinger = \OC::$server->getConfig()->getAppValue('core', 'public_webfinger', '');
if (!empty($publicWebFinger)) {
$appConfig['core']['public_webfinger'] = $publicWebFinger;
}

$settings['array']['oc_appconfig'] = json_encode($appConfig);
}
}
5 changes: 3 additions & 2 deletions settings/js/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,13 +248,14 @@ $(document).ready(function(){
// run setup checks then gather error messages
$.when(
OC.SetupChecks.checkWebDAV(),
OC.SetupChecks.checkWellKnownUrl('/.well-known/webfinger', oc_defaults.docPlaceholderUrl, $('#postsetupchecks').data('check-wellknown') === true && !!oc_appconfig.core.public_webfinger, 200),
OC.SetupChecks.checkWellKnownUrl('/.well-known/caldav', oc_defaults.docPlaceholderUrl, $('#postsetupchecks').data('check-wellknown') === true),
OC.SetupChecks.checkWellKnownUrl('/.well-known/carddav', oc_defaults.docPlaceholderUrl, $('#postsetupchecks').data('check-wellknown') === true),
OC.SetupChecks.checkSetup(),
OC.SetupChecks.checkGeneric(),
OC.SetupChecks.checkDataProtected()
).then(function(check1, check2, check3, check4, check5, check6) {
var messages = [].concat(check1, check2, check3, check4, check5, check6);
).then(function(check1, check2, check3, check4, check5, check6, check7) {
var messages = [].concat(check1, check2, check3, check4, check5, check6, check7);
var $el = $('#postsetupchecks');
$('#security-warning-state-loading').addClass('hidden');

Expand Down
1 change: 1 addition & 0 deletions tests/data/setUploadLimit/htaccess
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ RewriteEngine on
RewriteRule .* - [env=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteRule ^\.well-known/host-meta /public.php?service=host-meta [QSA,L]
RewriteRule ^\.well-known/host-meta\.json /public.php?service=host-meta-json [QSA,L]
RewriteRule ^\.well-known/webfinger /public.php?service=webfinger [QSA,L]
RewriteRule ^\.well-known/carddav /remote.php/carddav/ [R=301,L]
RewriteRule ^\.well-known/caldav /remote.php/caldav/ [R=301,L]
RewriteRule ^apps/calendar/caldav\.php remote.php/caldav/ [QSA,L]
Expand Down