diff --git a/handlers/new_session.go b/handlers/new_session.go index e0e8cd0..5831c74 100644 --- a/handlers/new_session.go +++ b/handlers/new_session.go @@ -9,6 +9,7 @@ import ( ) func NewSession(rw http.ResponseWriter, req *http.Request) { + req.ParseForm() if !services.IsHuman(req) { // User it not a human rw.WriteHeader(http.StatusConflict) @@ -16,7 +17,10 @@ func NewSession(rw http.ResponseWriter, req *http.Request) { return } - s, err := services.NewSession() + reqDur := req.Form.Get("session-duration") + + duration := services.GetDuration(reqDur) + s, err := services.NewSession(duration) if err != nil { log.Println(err) //TODO: Return some error code diff --git a/services/recaptcha.go b/services/recaptcha.go index eb420dd..500897d 100644 --- a/services/recaptcha.go +++ b/services/recaptcha.go @@ -35,7 +35,6 @@ func IsHuman(req *http.Request) bool { if os.Getenv("GOOGLE_RECAPTCHA_DISABLED") != "" { return true } - req.ParseForm() challenge := req.Form.Get("g-recaptcha-response") // Of X-Forwarded-For exists, it means we are behind a loadbalancer and we should use the real IP address of the user diff --git a/services/session.go b/services/session.go index bc7eed3..993a8aa 100644 --- a/services/session.go +++ b/services/session.go @@ -8,7 +8,6 @@ import ( "net" "net/http" "os" - "strconv" "strings" "sync" "time" @@ -202,24 +201,26 @@ func CloseSession(s *Session) error { return nil } -// Todo: this handles minimum viable product and removes hard-coding of hours value :) -// For future enhance to return time.Duration and parse a string / flag. -func getExpiryHours() int { - hours := 4 - override := os.Getenv("EXPIRY") - if len(override) > 0 { - value, err := strconv.Atoi(override) - if err == nil { - hours = value +var defaultDuration = 4 * time.Hour + +func GetDuration(reqDur string) time.Duration { + if reqDur != "" { + if dur, err := time.ParseDuration(reqDur); err == nil { + return dur } + return defaultDuration + } - return hours + + envDur := os.Getenv("EXPIRY") + if dur, err := time.ParseDuration(envDur); err == nil { + return dur + } + + return defaultDuration } -func NewSession() (*Session, error) { - hours := getExpiryHours() - duration := time.Duration(hours) * time.Hour - +func NewSession(duration time.Duration) (*Session, error) { s := &Session{} s.Id = uuid.NewV4().String() s.Instances = map[string]*Instance{} diff --git a/www/assets/app.js b/www/assets/app.js index e6015dc..94d2c52 100644 --- a/www/assets/app.js +++ b/www/assets/app.js @@ -7,8 +7,7 @@ // Controller keeps code/logic separate from the HTML app.controller("BypassController", ['$scope', '$log', '$http', '$location', '$timeout', function($scope, $log, $http, $location, $timeout) { setTimeout(function() { - var el = document.querySelector("#submit"); - el.click(); + document.getElementById("welcomeFormBypass").submit(); }, 500); }]); diff --git a/www/bypass.html b/www/bypass.html index 7a3b723..62f1037 100644 --- a/www/bypass.html +++ b/www/bypass.html @@ -10,7 +10,7 @@

Welcome!

We're bypassing the Captcha and redirecting you now..

- +
diff --git a/www/welcome.html b/www/welcome.html index 6a2b0c8..efa55cc 100644 --- a/www/welcome.html +++ b/www/welcome.html @@ -13,6 +13,7 @@

Before starting we need to verify you are a human

+