From 4f3375ee8d836a6825d4340a2405ef94312600dd Mon Sep 17 00:00:00 2001 From: Henrique Dias Date: Wed, 2 Aug 2017 14:49:15 +0100 Subject: [PATCH] NoAuth for Caddy plugins Former-commit-id: 5b8306eb527c9f21d14736c97e67b8689e69d025 [formerly 42d1b7035277e06aecc9a812ea4d92022a36c2a6] [formerly 31905bebcc8f337bc8f6815425778bfc652f43e4 [formerly b5961b6b63b082874f54308c2719a1640f8c2be7]] Former-commit-id: 44aa1bc7df6ffa633b333b75a5045c612db44aae [formerly d22761bb6f49156f7889e28f3af8edb439c7e023] Former-commit-id: 5a8a899a97bb7ec4c9433723c7d53f87163cccac --- caddy/filemanager/filemanager.go | 14 ++++++++++++++ caddy/hugo/hugo.go | 14 ++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/caddy/filemanager/filemanager.go b/caddy/filemanager/filemanager.go index 948de73d..75cbb128 100644 --- a/caddy/filemanager/filemanager.go +++ b/caddy/filemanager/filemanager.go @@ -10,6 +10,7 @@ import ( "net/http" "os" "path/filepath" + "strconv" "strings" . "github.com/hacdias/filemanager" @@ -73,6 +74,7 @@ func parse(c *caddy.Controller) ([]*config, error) { baseURL := "/" baseScope := "." database := "" + noAuth := false // Get the baseURL and baseScope args := c.RemainingArgs() @@ -93,6 +95,17 @@ func parse(c *caddy.Controller) ([]*config, error) { } database = c.Val() + case "no_auth": + if !c.NextArg() { + noAuth = true + continue + } + + var err error + noAuth, err = strconv.ParseBool(c.Val()) + if err != nil { + return nil, err + } } } @@ -143,6 +156,7 @@ func parse(c *caddy.Controller) ([]*config, error) { return nil, err } + fm.NoAuth = noAuth m := &config{FileManager: fm} m.SetBaseURL(baseURL) m.SetPrefixURL(strings.TrimSuffix(caddyConf.Addr.Path, "/")) diff --git a/caddy/hugo/hugo.go b/caddy/hugo/hugo.go index 7da39d58..871d0fb0 100644 --- a/caddy/hugo/hugo.go +++ b/caddy/hugo/hugo.go @@ -7,6 +7,7 @@ import ( "net/http" "os" "path/filepath" + "strconv" "strings" "github.com/hacdias/filemanager" @@ -42,6 +43,7 @@ func parse(c *caddy.Controller) ([]*filemanager.FileManager, error) { directory := "." admin := "/admin" database := "" + noAuth := false // Get the baseURL and baseScope args := c.RemainingArgs() @@ -62,6 +64,17 @@ func parse(c *caddy.Controller) ([]*filemanager.FileManager, error) { } database = c.Val() + case "no_auth": + if !c.NextArg() { + noAuth = true + continue + } + + var err error + noAuth, err = strconv.ParseBool(c.Val()) + if err != nil { + return nil, err + } } } @@ -132,6 +145,7 @@ func parse(c *caddy.Controller) ([]*filemanager.FileManager, error) { return nil, err } + m.NoAuth = noAuth m.SetBaseURL(admin) m.SetPrefixURL(strings.TrimSuffix(caddyConf.Addr.Path, "/")) configs = append(configs, m)