+ "--glinet" command-line argument: Run in GL-Inet compatibility mode
Close #1853 Squashed commit of the following: commit 3730cafabe8fa1dbf2bf75915079d2effe4ff9a3 Merge: 533ae3c26b134469Author: Simon Zolin <s.zolin@adguard.com> Date: Fri Jul 3 19:21:08 2020 +0300 Merge remote-tracking branch 'origin/master' into 1853-glinet commit 533ae3c2678cd6cfd26bf9560bee4eb5a015a615 Merge: 3521992b21dfb5ffAuthor: Simon Zolin <s.zolin@adguard.com> Date: Fri Jul 3 19:14:45 2020 +0300 Merge remote-tracking branch 'origin/master' into 1853-glinet commit 3521992b4609fa3400942c89f7a7546dade459bc Author: Simon Zolin <s.zolin@adguard.com> Date: Fri Jul 3 18:04:53 2020 +0300 logs commit 3e0258782b1a14c08156fe65940ae7b661a42b54 Author: Simon Zolin <s.zolin@adguard.com> Date: Fri Jul 3 17:11:47 2020 +0300 fix commit bb814db9df1c770d0ea02eafd12bedd122bef894 Author: Simon Zolin <s.zolin@adguard.com> Date: Fri Jul 3 16:58:37 2020 +0300 minor commit b161bbc5749ce76b16600e0153120935ad20077e Author: Simon Zolin <s.zolin@adguard.com> Date: Fri Jul 3 16:53:22 2020 +0300 move code commit c506e81265bdee140c0f61255f927c13738efc1a Author: Simon Zolin <s.zolin@adguard.com> Date: Thu Jul 2 10:50:56 2020 +0300 test commit c09f201cbd88498a2328be332197e4d96e5fb115 Author: Simon Zolin <s.zolin@adguard.com> Date: Thu Jul 2 10:42:23 2020 +0300 + "--glinet" command-line argument: Run in GL-Inet compatibility mode
This commit is contained in:
20
home/auth.go
20
home/auth.go
@@ -365,6 +365,7 @@ func parseCookie(cookie string) string {
|
||||
return ""
|
||||
}
|
||||
|
||||
// nolint(gocyclo)
|
||||
func optionalAuth(handler func(http.ResponseWriter, *http.Request)) func(http.ResponseWriter, *http.Request) {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
@@ -391,7 +392,11 @@ func optionalAuth(handler func(http.ResponseWriter, *http.Request)) func(http.Re
|
||||
// redirect to login page if not authenticated
|
||||
ok := false
|
||||
cookie, err := r.Cookie(sessionCookieName)
|
||||
if err == nil {
|
||||
|
||||
if glProcessCookie(r) {
|
||||
log.Debug("Auth: authentification was handled by GL-Inet submodule")
|
||||
|
||||
} else if err == nil {
|
||||
r := Context.auth.CheckSession(cookie.Value)
|
||||
if r == 0 {
|
||||
ok = true
|
||||
@@ -412,8 +417,13 @@ func optionalAuth(handler func(http.ResponseWriter, *http.Request)) func(http.Re
|
||||
}
|
||||
if !ok {
|
||||
if r.URL.Path == "/" || r.URL.Path == "/index.html" {
|
||||
w.Header().Set("Location", "/login.html")
|
||||
w.WriteHeader(http.StatusFound)
|
||||
if glProcessRedirect(w, r) {
|
||||
log.Debug("Auth: redirected to login page by GL-Inet submodule")
|
||||
|
||||
} else {
|
||||
w.Header().Set("Location", "/login.html")
|
||||
w.WriteHeader(http.StatusFound)
|
||||
}
|
||||
} else {
|
||||
w.WriteHeader(http.StatusForbidden)
|
||||
_, _ = w.Write([]byte("Forbidden"))
|
||||
@@ -510,6 +520,10 @@ func (a *Auth) GetUsers() []User {
|
||||
|
||||
// AuthRequired - if authentication is required
|
||||
func (a *Auth) AuthRequired() bool {
|
||||
if GLMode {
|
||||
return true
|
||||
}
|
||||
|
||||
a.lock.Lock()
|
||||
r := (len(a.users) != 0)
|
||||
a.lock.Unlock()
|
||||
|
||||
Reference in New Issue
Block a user