mirror of
https://github.com/bingohuang/docker-labs.git
synced 2025-07-13 17:42:53 +08:00
Allow to override session timeout. (#86)
* Allow to override session timeout. This comes useful as it can be overriden from the SDK now * Fix comments
This commit is contained in:
parent
1d37f98efd
commit
a5d1e5c207
@ -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
|
||||
|
@ -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
|
||||
|
@ -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{}
|
||||
|
@ -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);
|
||||
}]);
|
||||
|
||||
|
@ -10,7 +10,7 @@
|
||||
<h1>Welcome!</h1>
|
||||
<h2>We're bypassing the Captcha and redirecting you now..</h2>
|
||||
<form id="welcomeFormBypass" method="POST" action="/">
|
||||
<button id="submit" type="submit">Start Session</button>
|
||||
<button id="start" type="submit">Start Session</button>
|
||||
</form>
|
||||
</div>
|
||||
</body>
|
||||
|
@ -13,6 +13,7 @@
|
||||
<h2>Before starting we need to verify you are a human</h2>
|
||||
<form id="welcomeForm" method="POST" action="/">
|
||||
<div class="g-recaptcha" data-callback="iAmHuman" data-sitekey="{{.}}"></div>
|
||||
<input type="hidden" name="session-duration" value="1h"/>
|
||||
</form>
|
||||
<img src="/assets/large_h.png" />
|
||||
</div>
|
||||
|
Loading…
x
Reference in New Issue
Block a user