From a8f6ef80f91aed81f56622a4dad60a4726ee6206 Mon Sep 17 00:00:00 2001 From: David Christofas Date: Thu, 12 Aug 2021 13:03:16 +0200 Subject: [PATCH] implement url translation for legacy urls --- .../unreleased/legacy-path-translations.md | 5 +++ .../http/services/owncloud/ocdav/ocdav.go | 17 ++++++++-- .../http/services/owncloud/ocdav/redirect.go | 32 +++++++++++++++++++ 3 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 changelog/unreleased/legacy-path-translations.md create mode 100644 internal/http/services/owncloud/ocdav/redirect.go diff --git a/changelog/unreleased/legacy-path-translations.md b/changelog/unreleased/legacy-path-translations.md new file mode 100644 index 0000000000..70463698d0 --- /dev/null +++ b/changelog/unreleased/legacy-path-translations.md @@ -0,0 +1,5 @@ +Enhancement: Add redirects from OC10 URL formats + +Added redirectors for ownCloud 10 URLs. This allows users to continue to use their bookmarks from ownCloud 10 in ocis. + +https://github.com/cs3org/reva/pull/1989 diff --git a/internal/http/services/owncloud/ocdav/ocdav.go b/internal/http/services/owncloud/ocdav/ocdav.go index ff98568842..812040b6b4 100644 --- a/internal/http/services/owncloud/ocdav/ocdav.go +++ b/internal/http/services/owncloud/ocdav/ocdav.go @@ -153,7 +153,7 @@ func (s *svc) Close() error { } func (s *svc) Unprotected() []string { - return []string{"/status.php", "/remote.php/dav/public-files/"} + return []string{"/status.php", "/remote.php/dav/public-files/", "/apps/files/", "/index.php/f/", "/index.php/s/"} } func (s *svc) Handler() http.Handler { @@ -187,7 +187,20 @@ func (s *svc) Handler() http.Handler { // yet, add it to baseURI base = path.Join(base, "remote.php") - + case "apps": + head, r.URL.Path = router.ShiftPath(r.URL.Path) + if head == "files" { + s.handleLegacyPath(w, r) + return + } + case "index.php": + head, r.URL.Path = router.ShiftPath(r.URL.Path) + if head == "s" { + token := r.URL.Path + url := s.c.PublicURL + path.Join("#", head, token) + http.Redirect(w, r, url, http.StatusMovedPermanently) + return + } } switch head { // the old `/webdav` endpoint uses remote.php/webdav/$path diff --git a/internal/http/services/owncloud/ocdav/redirect.go b/internal/http/services/owncloud/ocdav/redirect.go new file mode 100644 index 0000000000..0e3d0bc9c3 --- /dev/null +++ b/internal/http/services/owncloud/ocdav/redirect.go @@ -0,0 +1,32 @@ +// Copyright 2018-2021 CERN +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// In applying this license, CERN does not waive the privileges and immunities +// granted to it by virtue of its status as an Intergovernmental Organization +// or submit itself to any jurisdiction. + +package ocdav + +import ( + "net/http" + "net/url" + "path" +) + +func (s *svc) handleLegacyPath(w http.ResponseWriter, r *http.Request) { + query := r.URL.Query() + dir := query.Get("dir") + url := s.c.PublicURL + path.Join("#", "/files/list/all", url.PathEscape(dir)) + http.Redirect(w, r, url, http.StatusMovedPermanently) +}