NoAuth for Caddy plugins

This commit is contained in:
Henrique Dias 2017-08-02 14:49:15 +01:00
parent a3710efe19
commit b5961b6b63
No known key found for this signature in database
GPG Key ID: 936F5EB68D786730
2 changed files with 28 additions and 0 deletions

View File

@ -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, "/"))

View File

@ -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)