summaryrefslogtreecommitdiff
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
parenta2f7fd3070513941dded47a7ceb8afce75f337ce (diff)
add login timeout
-rw-r--r--config.json1
-rw-r--r--config/config.go1
-rw-r--r--main.go14
-rw-r--r--page/default.go2
4 files changed, 17 insertions, 1 deletions
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) {
<input type="text" id="username" name="username">
<br>
<label for="password">Password</label>
- <input type="text" id="password" name="password">
+ <input type="password" id="password" name="password">
<br>
<input type="submit" value="Submit">
</form>