summaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
authorsanine <sanine.not@pm.me>2023-05-14 23:40:55 -0500
committersanine <sanine.not@pm.me>2023-05-14 23:40:55 -0500
commit218e769824cd7c1a411e74e1a63d885627f62320 (patch)
tree6d45a980d2e476e89fb07fe941b7435c8fd5465d /main.go
parenta2f7fd3070513941dded47a7ceb8afce75f337ce (diff)
add login timeout
Diffstat (limited to 'main.go')
-rw-r--r--main.go14
1 files changed, 14 insertions, 0 deletions
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
}