From 6231beefc5cbddbfda1d772284047bdaa2cb25a5 Mon Sep 17 00:00:00 2001 From: Chaitanya Bankanhal Date: Sat, 29 Aug 2020 23:45:09 +0530 Subject: [PATCH] webui: Fix broken webui because of plugins redirection --- fs/rc/rcserver/rcserver.go | 2 +- fs/rc/webgui/plugins.go | 23 ++++++++++++----------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/fs/rc/rcserver/rcserver.go b/fs/rc/rcserver/rcserver.go index c46501db2..6204c4810 100644 --- a/fs/rc/rcserver/rcserver.go +++ b/fs/rc/rcserver/rcserver.go @@ -389,7 +389,7 @@ func (s *Server) handleGet(w http.ResponseWriter, r *http.Request, path string) case s.files != nil: pluginsMatchResult := webgui.PluginsMatch.FindStringSubmatch(path) - if s.opt.WebUI && pluginsMatchResult != nil { + if s.opt.WebUI && pluginsMatchResult != nil && len(pluginsMatchResult) > 2 { ok := webgui.ServePluginOK(w, r, pluginsMatchResult) if !ok { r.URL.Path = fmt.Sprintf("/%s/%s/app/build/%s", pluginsMatchResult[1], pluginsMatchResult[2], pluginsMatchResult[3]) diff --git a/fs/rc/webgui/plugins.go b/fs/rc/webgui/plugins.go index 78fe3b2d9..fda4896df 100644 --- a/fs/rc/webgui/plugins.go +++ b/fs/rc/webgui/plugins.go @@ -293,19 +293,20 @@ func ServePluginWithReferrerOK(w http.ResponseWriter, r *http.Request, path stri referrer := r.Referer() referrerPathMatch := referrerPathReg.FindStringSubmatch(referrer) - if referrerPathMatch != nil { + if referrerPathMatch != nil && len(referrerPathMatch) > 3 { referrerPluginMatch := PluginsMatch.FindStringSubmatch(referrerPathMatch[4]) - pluginKey := fmt.Sprintf("%s/%s", referrerPluginMatch[1], referrerPluginMatch[2]) - currentPlugin, err := loadedPlugins.GetPluginByName(pluginKey) - if err != nil { - return false - } - if referrerPluginMatch != nil && currentPlugin.Rclone.RedirectReferrer { - path = fmt.Sprintf("/plugins/%s/%s/%s", referrerPluginMatch[1], referrerPluginMatch[2], path) + if referrerPluginMatch != nil && len(referrerPluginMatch) > 2 { + pluginKey := fmt.Sprintf("%s/%s", referrerPluginMatch[1], referrerPluginMatch[2]) + currentPlugin, err := loadedPlugins.GetPluginByName(pluginKey) + if err != nil { + return false + } + if currentPlugin.Rclone.RedirectReferrer { + path = fmt.Sprintf("/plugins/%s/%s/%s", referrerPluginMatch[1], referrerPluginMatch[2], path) - http.Redirect(w, r, path, http.StatusMovedPermanently) - //s.pluginsHandler.ServeHTTP(w, r) - return true + http.Redirect(w, r, path, http.StatusMovedPermanently) + return true + } } } return false