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
6 changes: 3 additions & 3 deletions apps/files/appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@

/** @var $this \OC\Route\Router */

$this->create('files_ajax_download', 'ajax/download.php')
$this->create('files_ajax_download', 'ajax/download')
->actionInclude('files/ajax/download.php');
$this->create('files_ajax_getstoragestats', 'ajax/getstoragestats.php')
$this->create('files_ajax_getstoragestats', 'ajax/getstoragestats')
->actionInclude('files/ajax/getstoragestats.php');
$this->create('files_ajax_list', 'ajax/list.php')
$this->create('files_ajax_list', 'ajax/list')
->actionInclude('files/ajax/list.php');

$this->create('download', 'download{file}')
Expand Down
4 changes: 2 additions & 2 deletions apps/files/js/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
state.call.abort();
}
state.dir = currentDir;
state.call = $.getJSON(OC.filePath('files','ajax','getstoragestats.php') + '?dir=' + encodeURIComponent(currentDir),function(response) {
state.call = $.getJSON(OC.generateUrl('/apps/files/ajax/getstoragestats') + '?dir=' + encodeURIComponent(currentDir),function(response) {
state.dir = null;
state.call = null;
Files.updateMaxUploadFilesize(response);
Expand Down Expand Up @@ -200,7 +200,7 @@
if (params) {
q = '?' + OC.buildQueryString(params);
}
return OC.filePath('files', 'ajax', action + '.php') + q;
return OC.generateUrl('/apps/files/ajax/' + action) + q;
},

/**
Expand Down
10 changes: 5 additions & 5 deletions apps/files/tests/js/filelistSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1684,11 +1684,11 @@ describe('OCA.Files.FileList tests', function() {
});
it('returns correct download URL for multiple files', function() {
expect(fileList.getDownloadUrl(['a b c.txt', 'd e f.txt']))
.toEqual(OC.webroot + '/index.php/apps/files/ajax/download.php?dir=%2Fsubdir&files[]=a%20b%20c.txt&files[]=d%20e%20f.txt');
.toEqual(OC.webroot + '/index.php/apps/files/ajax/download?dir=%2Fsubdir&files[]=a%20b%20c.txt&files[]=d%20e%20f.txt');
});
it('returns the correct ajax URL', function() {
expect(fileList.getAjaxUrl('test', {a:1, b:'x y'}))
.toEqual(OC.webroot + '/index.php/apps/files/ajax/test.php?a=1&b=x%20y');
.toEqual(OC.webroot + '/index.php/apps/files/ajax/test?a=1&b=x%20y');
});
});
describe('Upload Url', function() {
Expand Down Expand Up @@ -2083,7 +2083,7 @@ describe('OCA.Files.FileList tests', function() {
it('Opens download URL when clicking "Download"', function() {
$('.selectedActions .download').click();
expect(redirectStub.calledOnce).toEqual(true);
expect(redirectStub.getCall(0).args[0]).toContain(OC.webroot + '/index.php/apps/files/ajax/download.php?' +
expect(redirectStub.getCall(0).args[0]).toContain(OC.webroot + '/index.php/apps/files/ajax/download?' +
'dir=%2Fsubdir&files[]=One.txt&files[]=Three.pdf&files[]=somedir');
redirectStub.restore();
});
Expand All @@ -2092,13 +2092,13 @@ describe('OCA.Files.FileList tests', function() {
$('.select-all').click();
$('.selectedActions .download').click();
expect(redirectStub.calledOnce).toEqual(true);
expect(redirectStub.getCall(0).args[0]).toContain(OC.webroot + '/index.php/apps/files/ajax/download.php?dir=%2F&files=');
expect(redirectStub.getCall(0).args[0]).toContain(OC.webroot + '/index.php/apps/files/ajax/download?dir=%2F&files=');
});
it('Downloads parent folder when all selected in subfolder', function() {
$('.select-all').click();
$('.selectedActions .download').click();
expect(redirectStub.calledOnce).toEqual(true);
expect(redirectStub.getCall(0).args[0]).toContain(OC.webroot + '/index.php/apps/files/ajax/download.php?dir=%2F&files=subdir');
expect(redirectStub.getCall(0).args[0]).toContain(OC.webroot + '/index.php/apps/files/ajax/download?dir=%2F&files=subdir');
});
});
describe('Delete', function() {
Expand Down
2 changes: 1 addition & 1 deletion apps/files/tests/js/filesSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ describe('OCA.Files.Files tests', function() {
});
it('returns the ajax download URL when multiple files specified', function() {
var url = Files.getDownloadUrl(['test file.txt', 'abc.txt'], '/subdir');
expect(url).toEqual(OC.webroot + '/index.php/apps/files/ajax/download.php?dir=%2Fsubdir&files[]=test%20file.txt&files[]=abc.txt');
expect(url).toEqual(OC.webroot + '/index.php/apps/files/ajax/download?dir=%2Fsubdir&files[]=test%20file.txt&files[]=abc.txt');
});
});
describe('handleDownload', function() {
Expand Down
4 changes: 1 addition & 3 deletions apps/files_external/appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,7 @@
]
);

$this->create('files_external_oauth1', 'ajax/oauth1.php')
->actionInclude('files_external/ajax/oauth1.php');
Comment on lines -65 to -66

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Note: this was existing crud, oath1.php no longer exists.

$this->create('files_external_oauth2', 'ajax/oauth2.php')
$this->create('files_external_oauth2', 'ajax/oauth2')
->actionInclude('files_external/ajax/oauth2.php');

$this->create('files_external_list_applicable', '/applicable')
Expand Down
2 changes: 1 addition & 1 deletion apps/files_external/js/gdrive.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
$(document).ready(function() {
var backendId = 'googledrive';
var backendUrl = OC.generateUrl('/index.php/apps/files_external/ajax/oauth2.php');
var backendUrl = OC.generateUrl('/apps/files_external/ajax/oauth2');

function generateUrl($tr) {
// no mapping between client ID and Google 'project', so we always load the same URL
Expand Down
4 changes: 1 addition & 3 deletions apps/files_sharing/appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,7 @@ function () {
}
);

$this->create('files_sharing_ajax_list', 'ajax/list.php')
->actionInclude('files_sharing/ajax/list.php');
Comment on lines -147 to -148

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Note: this was existing crud, list.php does not exist.

$this->create('files_sharing_ajax_publicpreview', 'ajax/publicpreview.php')
$this->create('files_sharing_ajax_publicpreview', 'ajax/publicpreview')
->actionInclude('files_sharing/ajax/publicpreview.php');
$this->create('sharing_external_shareinfo', '/shareinfo')
->actionInclude('files_sharing/ajax/shareinfo.php');
Expand Down
8 changes: 4 additions & 4 deletions apps/files_sharing/js/public.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,14 +154,14 @@ OCA.Sharing.PublicApp = {
} else if ((previewSupported === 'true' && mimetype.substr(0, mimetype.indexOf('/')) !== 'video') ||
mimetype.substr(0, mimetype.indexOf('/')) === 'image' &&
mimetype !== 'image/svg+xml') {
img.attr('src', OC.filePath('files_sharing', 'ajax', 'publicpreview.php') + '?' + OC.buildQueryString(params));
img.attr('src', OC.generateUrl('/apps/files_sharing/ajax/publicpreview') + '?' + OC.buildQueryString(params));
img.appendTo('#imgframe');
} else if (mimetype.substr(0, mimetype.indexOf('/')) !== 'video') {
img.attr('src', OC.Util.replaceSVGIcon(mimetypeIcon));
img.attr('width', 128);
img.appendTo('#imgframe');
} else if (previewSupported === 'true') {
$('#imgframe > video').attr('poster', OC.filePath('files_sharing', 'ajax', 'publicpreview.php') + '?' + OC.buildQueryString(params));
$('#imgframe > video').attr('poster', OC.generateUrl('/apps/files_sharing/ajax/publicpreview') + '?' + OC.buildQueryString(params));
}

if (this.fileList) {
Expand Down Expand Up @@ -208,7 +208,7 @@ OCA.Sharing.PublicApp = {
this.fileList.getAjaxUrl = function (action, params) {
params = params || {};
params.t = token;
return OC.filePath('files_sharing', 'ajax', action + '.php') + '?' + OC.buildQueryString(params);
return OC.generateUrl('/apps/files_sharing/ajax/' + action) + '?' + OC.buildQueryString(params);
};

this.fileList.linkTo = function (dir) {
Expand All @@ -228,7 +228,7 @@ OCA.Sharing.PublicApp = {
urlSpec.x = Math.ceil(urlSpec.x);
urlSpec.y = Math.ceil(urlSpec.y);
urlSpec.t = $('#dirToken').val();
return OC.generateUrl('/index.php/apps/files_sharing/ajax/publicpreview.php') + '?' + $.param(urlSpec);
return OC.generateUrl('/apps/files_sharing/ajax/publicpreview') + '?' + $.param(urlSpec);
};

this.fileList.updateEmptyContent = function () {
Expand Down
2 changes: 1 addition & 1 deletion apps/files_sharing/tests/js/publicAppSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ describe('OCA.Sharing.PublicApp tests', function() {
});
it('returns the correct ajax URL', function() {
expect(fileList.getAjaxUrl('test', {a:1, b:'x y'}))
.toEqual(OC.getRootPath() + '/index.php/apps/files_sharing/ajax/test.php?a=1&b=x%20y&t=sh4tok');
.toEqual(OC.getRootPath() + '/index.php/apps/files_sharing/ajax/test?a=1&b=x%20y&t=sh4tok');
});
it('returns correct download URL for downloading everything', function() {
expect(fileList.getDownloadUrl())
Expand Down
10 changes: 5 additions & 5 deletions apps/files_trashbin/appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@

$application = new Application();

$this->create('core_ajax_trashbin_preview', 'ajax/preview.php')
$this->create('core_ajax_trashbin_preview', 'ajax/preview')
->actionInclude('files_trashbin/ajax/preview.php');
$this->create('files_trashbin_ajax_delete', 'ajax/delete.php')
$this->create('files_trashbin_ajax_delete', 'ajax/delete')
->actionInclude('files_trashbin/ajax/delete.php');
$this->create('files_trashbin_ajax_isEmpty', 'ajax/isEmpty.php')
$this->create('files_trashbin_ajax_isEmpty', 'ajax/isEmpty')
->actionInclude('files_trashbin/ajax/isEmpty.php');
$this->create('files_trashbin_ajax_list', 'ajax/list.php')
$this->create('files_trashbin_ajax_list', 'ajax/list')
->actionInclude('files_trashbin/ajax/list.php');
$this->create('files_trashbin_ajax_undelete', 'ajax/undelete.php')
$this->create('files_trashbin_ajax_undelete', 'ajax/undelete')
->actionInclude('files_trashbin/ajax/undelete.php');
4 changes: 2 additions & 2 deletions apps/files_trashbin/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ OCA.Trashbin.App = {
var deleteAction = tr.children("td.date").children(".action.delete");
deleteAction.removeClass('icon-delete').addClass('icon-loading-small');
fileList.disableActions();
$.post(OC.filePath('files_trashbin', 'ajax', 'undelete.php'), {
$.post(OC.generateUrl('/apps/files_trashbin/ajax/undelete'), {
files: JSON.stringify([filename]),
dir: fileList.getCurrentDirectory()
},
Expand Down Expand Up @@ -86,7 +86,7 @@ OCA.Trashbin.App = {
var deleteAction = tr.children("td.date").children(".action.delete");
deleteAction.removeClass('icon-delete').addClass('icon-loading-small');
fileList.disableActions();
$.post(OC.filePath('files_trashbin', 'ajax', 'delete.php'), {
$.post(OC.generateUrl('/apps/files_trashbin/ajax/delete'), {
files: JSON.stringify([filename]),
dir: fileList.getCurrentDirectory()
},
Expand Down
8 changes: 4 additions & 4 deletions apps/files_trashbin/js/filelist.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
if (params) {
q = '?' + OC.buildQueryString(params);
}
return OC.filePath('files_trashbin', 'ajax', action + '.php') + q;
return OC.generateUrl('/apps/files_trashbin/ajax/' + action) + q;
},

setupUploadEvents: function() {
Expand Down Expand Up @@ -205,7 +205,7 @@
};
}

$.post(OC.filePath('files_trashbin', 'ajax', 'undelete.php'),
$.post(OC.generateUrl('/apps/files_trashbin/ajax/undelete'),
params,
function(result) {
if (allFiles) {
Expand Down Expand Up @@ -255,7 +255,7 @@
}
}

$.post(OC.filePath('files_trashbin', 'ajax', 'delete.php'),
$.post(OC.generateUrl('/apps/files_trashbin/ajax/delete'),
params,
function(result) {
if (allFiles) {
Expand All @@ -275,7 +275,7 @@
},

generatePreviewUrl: function(urlSpec) {
return OC.generateUrl('/index.php/apps/files_trashbin/ajax/preview.php') + '?' + $.param(urlSpec);
return OC.generateUrl('/apps/files_trashbin/ajax/preview') + '?' + $.param(urlSpec);
},

getDownloadUrl: function() {
Expand Down
14 changes: 7 additions & 7 deletions apps/files_trashbin/tests/js/filelistSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ describe('OCA.Trashbin.FileList tests', function() {
permissions: 1
}
};
fakeServer.respondWith(/\/index\.php\/apps\/files_trashbin\/ajax\/list.php\?dir=%2Fsubdir/, [
fakeServer.respondWith(/\/index\.php\/apps\/files_trashbin\/ajax\/list\?dir=%2Fsubdir/, [
200, {
"Content-Type": "application/json"
},
Expand Down Expand Up @@ -266,7 +266,7 @@ describe('OCA.Trashbin.FileList tests', function() {
$('.selectedActions .delete-selected').click();
expect(fakeServer.requests.length).toEqual(1);
request = fakeServer.requests[0];
expect(request.url).toEqual(OC.webroot + '/index.php/apps/files_trashbin/ajax/delete.php');
expect(request.url).toEqual(OC.webroot + '/index.php/apps/files_trashbin/ajax/delete');
expect(OC.parseQueryString(request.requestBody))
.toEqual({'dir': '/', files: '["One.txt.d11111","Three.pdf.d33333","somedir.d99999"]'});
fakeServer.requests[0].respond(
Expand Down Expand Up @@ -296,7 +296,7 @@ describe('OCA.Trashbin.FileList tests', function() {
$('.selectedActions .delete-selected').click();
expect(fakeServer.requests.length).toEqual(1);
request = fakeServer.requests[0];
expect(request.url).toEqual(OC.webroot + '/index.php/apps/files_trashbin/ajax/delete.php');
expect(request.url).toEqual(OC.webroot + '/index.php/apps/files_trashbin/ajax/delete');
expect(OC.parseQueryString(request.requestBody))
.toEqual({'dir': '/', files: '["One.txt.d11111","somedir.d99999"]'});
fakeServer.requests[0].respond(
Expand All @@ -323,7 +323,7 @@ describe('OCA.Trashbin.FileList tests', function() {
$('.selectedActions .delete-selected').click();
expect(fakeServer.requests.length).toEqual(1);
request = fakeServer.requests[0];
expect(request.url).toEqual(OC.webroot + '/index.php/apps/files_trashbin/ajax/delete.php');
expect(request.url).toEqual(OC.webroot + '/index.php/apps/files_trashbin/ajax/delete');
expect(OC.parseQueryString(request.requestBody))
.toEqual({'dir': '/', allfiles: 'true'});
fakeServer.requests[0].respond(
Expand All @@ -340,7 +340,7 @@ describe('OCA.Trashbin.FileList tests', function() {
$('.selectedActions .undelete').click();
expect(fakeServer.requests.length).toEqual(1);
request = fakeServer.requests[0];
expect(request.url).toEqual(OC.webroot + '/index.php/apps/files_trashbin/ajax/undelete.php');
expect(request.url).toEqual(OC.webroot + '/index.php/apps/files_trashbin/ajax/undelete');
expect(OC.parseQueryString(request.requestBody))
.toEqual({'dir': '/', files: '["One.txt.d11111","Three.pdf.d33333","somedir.d99999"]'});
fakeServer.requests[0].respond(
Expand Down Expand Up @@ -370,7 +370,7 @@ describe('OCA.Trashbin.FileList tests', function() {
$('.selectedActions .undelete').click();
expect(fakeServer.requests.length).toEqual(1);
request = fakeServer.requests[0];
expect(request.url).toEqual(OC.webroot + '/index.php/apps/files_trashbin/ajax/undelete.php');
expect(request.url).toEqual(OC.webroot + '/index.php/apps/files_trashbin/ajax/undelete');
expect(OC.parseQueryString(request.requestBody))
.toEqual({'dir': '/', files: '["One.txt.d11111","somedir.d99999"]'});
fakeServer.requests[0].respond(
Expand All @@ -397,7 +397,7 @@ describe('OCA.Trashbin.FileList tests', function() {
$('.selectedActions .undelete').click();
expect(fakeServer.requests.length).toEqual(1);
request = fakeServer.requests[0];
expect(request.url).toEqual(OC.webroot + '/index.php/apps/files_trashbin/ajax/undelete.php');
expect(request.url).toEqual(OC.webroot + '/index.php/apps/files_trashbin/ajax/undelete');
expect(OC.parseQueryString(request.requestBody))
.toEqual({'dir': '/', allfiles: 'true'});
fakeServer.requests[0].respond(
Expand Down
23 changes: 23 additions & 0 deletions changelog/unreleased/41742
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Bugfix: Rewire legacy ajax routes to extension-free urls

The front controller rewrite only forwards a request to index.php when the
requested path does not exist on disk. A legacy route whose declared url was
itself a real file - for example /settings/ajax/setlanguage.php - therefore
never reached the router: the web server executed the script directly, without
the bootstrap index.php would have performed, and the request died with
`Class "OC" not found` (HTTP 500). Changing the personal language setting, the
share dialog e-mail lookup, the trashbin and public link preview thumbnails and
the Google Drive OAuth entry point were affected.

Every such route url has lost its .php suffix so that no route url resolves to
a file on disk any more, and the affected javascript callers now build routed
urls through OC.generateUrl(). Route names are unchanged, so linkToRoute()
callers keep working. The legacy .php urls are gone and no alias is provided -
an alias would re-introduce the very shadowing this change removes.
/core/ajax/update.php keeps its suffix by design: it bootstraps itself and is
excluded from the rewrite. Five routes whose include target no longer existed
were removed. Third-party apps posting to their own shadowed .php route urls
need the same treatment.

https://github.com/owncloud/core/issues/41740
https://github.com/owncloud/core/pull/41742
2 changes: 1 addition & 1 deletion core/js/js.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function escapeHTML(s) {
* @deprecated use Files.getDownloadURL() instead
*/
function fileDownloadPath(dir, file) {
return OC.filePath('files', 'ajax', 'download.php') + '?files=' + encodeURIComponent(file) + '&dir=' + encodeURIComponent(dir);
return OC.generateUrl('/apps/files/ajax/download') + '?files=' + encodeURIComponent(file) + '&dir=' + encodeURIComponent(dir);
}

/** @namespace */
Expand Down
2 changes: 1 addition & 1 deletion core/js/oc-dialogs.js
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,7 @@ var OCdialogs = {
}

return $.getJSON(
OC.filePath('files', 'ajax', 'list.php'),
OC.generateUrl('/apps/files/ajax/list'),
{
dir: dir,
mimetypes: JSON.stringify(mimeType)
Expand Down
6 changes: 3 additions & 3 deletions core/js/share.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ OC.Share = _.extend(OC.Share || {}, {
} else {
var checkShares = true;
}
$.ajax({type: 'GET', url: OC.filePath('core', 'ajax', 'share.php'), data: { fetch: 'getItem', itemType: itemType, itemSource: itemSource, checkReshare: checkReshare, checkShares: checkShares }, async: async, success: function(result) {
$.ajax({type: 'GET', url: OC.generateUrl('/core/ajax/share'), data: { fetch: 'getItem', itemType: itemType, itemSource: itemSource, checkReshare: checkReshare, checkShares: checkShares }, async: async, success: function(result) {
if (result && result.status === 'success') {
data = result.data;
} else {
Expand Down Expand Up @@ -327,7 +327,7 @@ OC.Share = _.extend(OC.Share || {}, {
);
}

return $.post(OC.filePath('core', 'ajax', 'share.php'),
return $.post(OC.generateUrl('/core/ajax/share'),
{
action: 'share',
itemType: itemType,
Expand Down Expand Up @@ -357,7 +357,7 @@ OC.Share = _.extend(OC.Share || {}, {
);
},
unshare:function(itemType, itemSource, shareType, shareWith, callback) {
$.post(OC.filePath('core', 'ajax', 'share.php'), { action: 'unshare', itemType: itemType, itemSource: itemSource, shareType: shareType, shareWith: shareWith }, function(result) {
$.post(OC.generateUrl('/core/ajax/share'), { action: 'unshare', itemType: itemType, itemSource: itemSource, shareType: shareType, shareWith: shareWith }, function(result) {
if (result && result.status === 'success') {
if (callback) {
callback();
Expand Down
2 changes: 1 addition & 1 deletion core/js/sharedialogmailview.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@
if (this.xhr != null)
this.xhr.abort();

var xhr = $.get(OC.generateUrl('/index.php/core/ajax/share.php'), {
var xhr = $.get(OC.generateUrl('/core/ajax/share'), {
'fetch' : 'getShareWithEmail',
'search': query.term
}).done(function(result) {
Expand Down
7 changes: 5 additions & 2 deletions core/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,18 @@
$this->create('search_ajax_search', '/core/search')
->actionInclude('core/search/ajax/search.php');
// AppConfig
$this->create('core_ajax_appconfig', '/core/ajax/appconfig.php')
$this->create('core_ajax_appconfig', '/core/ajax/appconfig')
->actionInclude('core/ajax/appconfig.php');
// Share
$this->create('core_ajax_share', '/core/ajax/share.php')
$this->create('core_ajax_share', '/core/ajax/share')
->actionInclude('core/ajax/share.php');
// oC JS config
$this->create('js_config', '/core/js/oc.js')
->actionInclude('core/js/config.php');
// Routing
// This url intentionally keeps the .php suffix: update.php bootstraps itself and
// is excluded from the front controller rewrite, see \OC\Setup::updateHtaccess()
// and OC::checkMaintenanceMode().
$this->create('core_ajax_update', '/core/ajax/update.php')
->actionInclude('core/ajax/update.php');

Expand Down
Loading