From 53039e6102abec2d2b9c1a83a7a1a707a0c39c3f Mon Sep 17 00:00:00 2001 From: Tim Schuster Date: Thu, 16 Mar 2017 20:08:15 +0100 Subject: [PATCH] Added Insecure HTTP Mode --- http/admin/login.go | 2 +- http/middle/session.go | 8 ++++++-- http/server.go | 9 +-------- 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/http/admin/login.go b/http/admin/login.go index 12a9d28..b4df1fd 100644 --- a/http/admin/login.go +++ b/http/admin/login.go @@ -47,4 +47,4 @@ func handleLogin(w http.ResponseWriter, r *http.Request) { session.Add(sess, w) http.Redirect(w, r, "/admin/panel.html", http.StatusSeeOther) -} +} \ No newline at end of file diff --git a/http/middle/session.go b/http/middle/session.go index 580d778..54b0610 100644 --- a/http/middle/session.go +++ b/http/middle/session.go @@ -2,12 +2,16 @@ package middle import ( "github.com/icza/session" + "go.rls.moe/nyx/config" "net/http" ) -func init() { +func SetupSessionManager(c *config.Config) { session.Global.Close() - session.Global = session.NewCookieManager(session.NewInMemStore()) + session.Global = session.NewCookieManagerOptions(session.NewInMemStore(), + &session.CookieMngrOptions{ + AllowHTTP: c.DisableSecurity, + }) } func GetSession(r *http.Request) session.Session { diff --git a/http/server.go b/http/server.go index 4f41c83..ad9d6f9 100644 --- a/http/server.go +++ b/http/server.go @@ -14,14 +14,6 @@ import ( "time" ) -var riceConf = rice.Config{ - LocateOrder: []rice.LocateMethod{ - rice.LocateWorkingDirectory, - rice.LocateEmbedded, - rice.LocateAppended, - }, -} - func Start(config *config.Config) error { err := admin.LoadTemplates() if err != nil { @@ -35,6 +27,7 @@ func Start(config *config.Config) error { if err != nil { return err } + middle.SetupSessionManager(config) r := chi.NewRouter()