mirror of
https://github.com/hacdias/webdav.git
synced 2026-09-26 21:21:54 +08:00
feat: allow no auth mode
License: MIT Signed-off-by: Henrique Dias <[email protected]>
This commit is contained in:
+11
-4
@@ -163,6 +163,7 @@ type cfg struct {
|
|||||||
address string
|
address string
|
||||||
port string
|
port string
|
||||||
tls bool
|
tls bool
|
||||||
|
noAuth bool
|
||||||
cert string
|
cert string
|
||||||
key string
|
key string
|
||||||
auth map[string]string
|
auth map[string]string
|
||||||
@@ -176,6 +177,7 @@ func parseConfig() *cfg {
|
|||||||
Port string `json:"port" yaml:"port"`
|
Port string `json:"port" yaml:"port"`
|
||||||
TLS bool `json:"tls" yaml:"tls"`
|
TLS bool `json:"tls" yaml:"tls"`
|
||||||
Cert string `json:"cert" yaml:"cert"`
|
Cert string `json:"cert" yaml:"cert"`
|
||||||
|
NoAuth bool `json:"noauth" yaml:"noauth"`
|
||||||
Key string `json:"key" yaml:"key"`
|
Key string `json:"key" yaml:"key"`
|
||||||
Scope string `json:"scope" yaml:"scope"`
|
Scope string `json:"scope" yaml:"scope"`
|
||||||
Modify bool `json:"modify" yaml:"modify"`
|
Modify bool `json:"modify" yaml:"modify"`
|
||||||
@@ -188,6 +190,7 @@ func parseConfig() *cfg {
|
|||||||
Cert: "cert.pem",
|
Cert: "cert.pem",
|
||||||
Key: "key.pem",
|
Key: "key.pem",
|
||||||
Scope: "./",
|
Scope: "./",
|
||||||
|
NoAuth: false,
|
||||||
Modify: true,
|
Modify: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -208,6 +211,7 @@ func parseConfig() *cfg {
|
|||||||
tls: data.TLS,
|
tls: data.TLS,
|
||||||
cert: data.Cert,
|
cert: data.Cert,
|
||||||
key: data.Key,
|
key: data.Key,
|
||||||
|
noAuth: data.NoAuth,
|
||||||
auth: map[string]string{},
|
auth: map[string]string{},
|
||||||
webdav: &webdav.Config{
|
webdav: &webdav.Config{
|
||||||
User: &webdav.User{
|
User: &webdav.User{
|
||||||
@@ -223,10 +227,6 @@ func parseConfig() *cfg {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(data.Users) == 0 {
|
|
||||||
log.Fatal("no user defined")
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(data.Rules) != 0 {
|
if len(data.Rules) != 0 {
|
||||||
config.webdav.User.Rules = parseRules(data.Rules)
|
config.webdav.User.Rules = parseRules(data.Rules)
|
||||||
}
|
}
|
||||||
@@ -236,6 +236,12 @@ func parseConfig() *cfg {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func basicAuth(c *cfg) http.Handler {
|
func basicAuth(c *cfg) http.Handler {
|
||||||
|
if c.noAuth {
|
||||||
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
c.webdav.ServeHTTP(w, r)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
w.Header().Set("WWW-Authenticate", `Basic realm="Restricted"`)
|
w.Header().Set("WWW-Authenticate", `Basic realm="Restricted"`)
|
||||||
|
|
||||||
@@ -273,6 +279,7 @@ func checkPassword(saved, input string) bool {
|
|||||||
func main() {
|
func main() {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
cfg := parseConfig()
|
cfg := parseConfig()
|
||||||
|
|
||||||
handler := basicAuth(cfg)
|
handler := basicAuth(cfg)
|
||||||
|
|
||||||
// Builds the address and a listener.
|
// Builds the address and a listener.
|
||||||
|
|||||||
Reference in New Issue
Block a user