mirror of
https://gitee.com/IrisVega/frp.git
synced 2024-11-01 22:31:29 +08:00
dashboard: fix dashboard auth error, fix #339
This commit is contained in:
parent
93461e0094
commit
7bc6c72844
@ -66,6 +66,7 @@ func (l *Listener) Close() error {
|
|||||||
defer l.mu.Unlock()
|
defer l.mu.Unlock()
|
||||||
if !l.closed {
|
if !l.closed {
|
||||||
close(l.conns)
|
close(l.conns)
|
||||||
|
l.closed = true
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -84,7 +84,7 @@ type AuthWraper struct {
|
|||||||
|
|
||||||
func (aw *AuthWraper) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
func (aw *AuthWraper) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
user, passwd, hasAuth := r.BasicAuth()
|
user, passwd, hasAuth := r.BasicAuth()
|
||||||
if (aw.user == "" && aw.passwd == "") || (hasAuth && user == aw.user || passwd == aw.passwd) {
|
if (aw.user == "" && aw.passwd == "") || (hasAuth && user == aw.user && passwd == aw.passwd) {
|
||||||
aw.h.ServeHTTP(w, r)
|
aw.h.ServeHTTP(w, r)
|
||||||
} else {
|
} else {
|
||||||
w.Header().Set("WWW-Authenticate", `Basic realm="Restricted"`)
|
w.Header().Set("WWW-Authenticate", `Basic realm="Restricted"`)
|
||||||
@ -104,7 +104,7 @@ func basicAuth(h http.HandlerFunc) http.HandlerFunc {
|
|||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
user, passwd, hasAuth := r.BasicAuth()
|
user, passwd, hasAuth := r.BasicAuth()
|
||||||
if (config.ServerCommonCfg.DashboardUser == "" && config.ServerCommonCfg.DashboardPwd == "") ||
|
if (config.ServerCommonCfg.DashboardUser == "" && config.ServerCommonCfg.DashboardPwd == "") ||
|
||||||
(hasAuth && user == config.ServerCommonCfg.DashboardUser || passwd == config.ServerCommonCfg.DashboardPwd) {
|
(hasAuth && user == config.ServerCommonCfg.DashboardUser && passwd == config.ServerCommonCfg.DashboardPwd) {
|
||||||
h.ServeHTTP(w, r)
|
h.ServeHTTP(w, r)
|
||||||
} else {
|
} else {
|
||||||
w.Header().Set("WWW-Authenticate", `Basic realm="Restricted"`)
|
w.Header().Set("WWW-Authenticate", `Basic realm="Restricted"`)
|
||||||
@ -117,7 +117,7 @@ func httprouterBasicAuth(h httprouter.Handle) httprouter.Handle {
|
|||||||
return func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
return func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||||
user, passwd, hasAuth := r.BasicAuth()
|
user, passwd, hasAuth := r.BasicAuth()
|
||||||
if (config.ServerCommonCfg.DashboardUser == "" && config.ServerCommonCfg.DashboardPwd == "") ||
|
if (config.ServerCommonCfg.DashboardUser == "" && config.ServerCommonCfg.DashboardPwd == "") ||
|
||||||
(hasAuth && user == config.ServerCommonCfg.DashboardUser || passwd == config.ServerCommonCfg.DashboardPwd) {
|
(hasAuth && user == config.ServerCommonCfg.DashboardUser && passwd == config.ServerCommonCfg.DashboardPwd) {
|
||||||
h(w, r, ps)
|
h(w, r, ps)
|
||||||
} else {
|
} else {
|
||||||
w.Header().Set("WWW-Authenticate", `Basic realm="Restricted"`)
|
w.Header().Set("WWW-Authenticate", `Basic realm="Restricted"`)
|
||||||
|
Loading…
Reference in New Issue
Block a user