From 218e769824cd7c1a411e74e1a63d885627f62320 Mon Sep 17 00:00:00 2001 From: sanine Date: Sun, 14 May 2023 23:40:55 -0500 Subject: add login timeout --- config.json | 1 + config/config.go | 1 + main.go | 14 ++++++++++++++ page/default.go | 2 +- 4 files changed, 17 insertions(+), 1 deletion(-) diff --git a/config.json b/config.json index cb1b493..ac7d54e 100644 --- a/config.json +++ b/config.json @@ -1,6 +1,7 @@ { "ListenAddress": "localhost:3333", "AssetDirectory": "", + "LoginTimeout": 3600, "Users": [ { "Name": "kate", diff --git a/config/config.go b/config/config.go index fe574a7..a371beb 100644 --- a/config/config.go +++ b/config/config.go @@ -22,6 +22,7 @@ type Endpoint struct { type Config struct { ListenAddress string AssetDirectory string + LoginTimeout int Users []User Endpoints []Endpoint } 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 } diff --git a/page/default.go b/page/default.go index d13689b..822f310 100644 --- a/page/default.go +++ b/page/default.go @@ -50,7 +50,7 @@ func DefaultLogin() (string, error) {
- +
-- cgit v1.2.1