From 218e769824cd7c1a411e74e1a63d885627f62320 Mon Sep 17 00:00:00 2001 From: sanine Date: Sun, 14 May 2023 23:40:55 -0500 Subject: add login timeout --- main.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'main.go') diff --git a/main.go b/main.go index 37c0fdc..b61e237 100644 --- a/main.go +++ b/main.go @@ -4,6 +4,7 @@ import ( "os" "fmt" "flag" + "time" "errors" "strings" "path/filepath" @@ -52,6 +53,15 @@ func main() { addEndpoint(sessions, pages, e) } + // timer for inactivity log out + c := time.Tick(time.Millisecond) + go (func() { + for ;; { + _ = <-c + sessions.CleanSessions(time.Duration(conf.LoginTimeout)*time.Second) + } + })() + log.Infof("listening on %v", conf.ListenAddress) log.Fatal(http.ListenAndServe(conf.ListenAddress, nil)) } @@ -104,6 +114,10 @@ func loadConfig(filename string) config.Config { fmt.Fprintf(os.Stderr, "failed to load configuration file: %v\n", err.Error()) os.Exit(1) } + + if conf.LoginTimeout == 0 { + conf.LoginTimeout = 3600 + } return conf } -- cgit v1.2.1