summaryrefslogtreecommitdiff
path: root/phlox/main.go
diff options
context:
space:
mode:
Diffstat (limited to 'phlox/main.go')
-rw-r--r--phlox/main.go17
1 files changed, 15 insertions, 2 deletions
diff --git a/phlox/main.go b/phlox/main.go
index f2946c8..da52654 100644
--- a/phlox/main.go
+++ b/phlox/main.go
@@ -3,6 +3,7 @@ package main
import (
"fmt"
"io"
+ "time"
"strings"
"errors"
"flag"
@@ -45,6 +46,15 @@ func main() {
InitLogin()
+ c := time.Tick(5 * time.Minute)
+ go (func() {
+ p := &P
+ for ;; {
+ _ = <-c // wait for 5 minutes
+ p.CleanSessions(time.Hour)
+ }
+ })()
+
log.Infof("serving on %v", addr)
log.Fatal(http.ListenAndServe(addr, nil))
}
@@ -93,10 +103,13 @@ func proxy(w http.ResponseWriter, req *http.Request, end Endpoint) {
return
}
if !check {
- w.WriteHeader(http.StatusUnauthorized)
- fmt.Fprintf(w, "unauthorized")
+ // not logged in
+ w.Header().Set("Location", "/login")
+ w.WriteHeader(http.StatusTemporaryRedirect)
return
}
+ // update modified time
+ p.TouchSessionId(cookie.Value)
response := proxyRequest(w, req, end)
if response != nil {