diff --git a/server/plugin/index.go b/server/plugin/index.go index 0266f5d5..f23f16fb 100644 --- a/server/plugin/index.go +++ b/server/plugin/index.go @@ -5,6 +5,7 @@ import ( _ "github.com/mickael-kerjean/filestash/server/plugin/plg_authenticate_admin" _ "github.com/mickael-kerjean/filestash/server/plugin/plg_authenticate_ldap" _ "github.com/mickael-kerjean/filestash/server/plugin/plg_authenticate_openid" + _ "github.com/mickael-kerjean/filestash/server/plugin/plg_authenticate_passthrough" _ "github.com/mickael-kerjean/filestash/server/plugin/plg_authenticate_saml" _ "github.com/mickael-kerjean/filestash/server/plugin/plg_backend_backblaze" _ "github.com/mickael-kerjean/filestash/server/plugin/plg_backend_dav" diff --git a/server/plugin/plg_authenticate_admin/index.go b/server/plugin/plg_authenticate_admin/index.go index 8852f8d8..d115a351 100644 --- a/server/plugin/plg_authenticate_admin/index.go +++ b/server/plugin/plg_authenticate_admin/index.go @@ -2,7 +2,6 @@ package plg_authenticate_admin import ( "fmt" - "github.com/gorilla/mux" . "github.com/mickael-kerjean/filestash/server/common" "golang.org/x/crypto/bcrypt" "net/http" @@ -10,7 +9,6 @@ import ( func init() { Hooks.Register.AuthenticationMiddleware("admin", Admin{}) - Hooks.Register.HttpEndpoint(LoginPage()) } type Admin struct{} @@ -34,39 +32,26 @@ func (this Admin) Setup() Form { } func (this Admin) EntryPoint(req *http.Request, res http.ResponseWriter) { - http.Redirect( - res, req, - "/admin/plugin/authenticate_admin", - http.StatusTemporaryRedirect, - ) -} - -func LoginPage() func(r *mux.Router, _ *App) error { - return func(r *mux.Router, _ *App) error { - r.HandleFunc("/admin/plugin/authenticate_admin", func(w http.ResponseWriter, r *http.Request) { - getFlash := func() string { - c, err := r.Cookie("flash") - if err != nil { - return "" - } - http.SetCookie(w, &http.Cookie{ - Name: "flash", - MaxAge: -1, - Path: "/", - }) - return fmt.Sprintf("%s", c.Value) - } - w.Header().Set("Content-Type", "text/html; charset=utf-8") - w.WriteHeader(http.StatusOK) - w.Write([]byte(Page(` -
- -
`))) + getFlash := func() string { + c, err := req.Cookie("flash") + if err != nil { + return "" + } + http.SetCookie(res, &http.Cookie{ + Name: "flash", + MaxAge: -1, + Path: "/", }) - return nil + return fmt.Sprintf("%s", c.Value) } + res.Header().Set("Content-Type", "text/html; charset=utf-8") + res.WriteHeader(http.StatusOK) + res.Write([]byte(Page(` +
+ +
`))) } func (this Admin) Callback(formData map[string]string, idpParams map[string]string, res http.ResponseWriter) (map[string]string, error) { diff --git a/server/plugin/plg_authenticate_passthrough/index.go b/server/plugin/plg_authenticate_passthrough/index.go new file mode 100644 index 00000000..ead2b030 --- /dev/null +++ b/server/plugin/plg_authenticate_passthrough/index.go @@ -0,0 +1,40 @@ +package plg_authenticate_passthrough + +import ( + . "github.com/mickael-kerjean/filestash/server/common" + "net/http" +) + +func init() { + Hooks.Register.AuthenticationMiddleware("passthrough", Admin{}) +} + +type Admin struct{} + +func (this Admin) Setup() Form { + return Form{ + Elmnts: []FormElement{ + { + Name: "type", + Type: "hidden", + Value: "passthrough", + }, + { + Name: "hint", + Type: "text", + ReadOnly: true, + Value: "You will be redirected to the selected backend", + }, + }, + } +} + +func (this Admin) EntryPoint(req *http.Request, res http.ResponseWriter) { + res.Header().Set("Content-Type", "text/html; charset=utf-8") + res.WriteHeader(http.StatusOK) + res.Write([]byte(Page(`

PASSTHROUGH

`))) +} + +func (this Admin) Callback(formData map[string]string, idpParams map[string]string, res http.ResponseWriter) (map[string]string, error) { + return map[string]string{}, nil +}