diff --git a/README.md b/README.md index 1133dea..f1fc3bc 100644 --- a/README.md +++ b/README.md @@ -18,4 +18,11 @@ browsers that really know how to dance! - Simple Captcha (Including Sound) - [hCaptcha](https://www.hcaptcha.com/) - [reCatpcha](https://developers.google.com/recaptcha?hl=de) -- [Turnstile](https://developers.cloudflare.com/turnstile/) \ No newline at end of file +- [Turnstile](https://developers.cloudflare.com/turnstile/) + +## Example setup with HAProxy +To start berghain locally you can follow these easy steps: + +1. Run `npm run build` inside `web/` +2. Run `haproxy -f examples/haproxy/haproxy.cfg` +3. Run `go run ./cmd/spop/. -config cmd/spop/config.yaml` \ No newline at end of file diff --git a/berghain.go b/berghain.go index 9304e96..0a841df 100644 --- a/berghain.go +++ b/berghain.go @@ -4,6 +4,7 @@ import ( "crypto/hmac" "crypto/sha256" "hash" + "log" "sync" "time" ) @@ -43,13 +44,16 @@ func (b *Berghain) releaseHMAC(h hash.Hash) { } func (b *Berghain) LevelConfig(level uint8) *LevelConfig { + if level == 0 { - panic("level cannot be zero") + log.Println("level cannot be zero. correcting to 1") } if level > uint8(len(b.Levels)) { - panic("level overflows") + log.Printf("level too high. correcting to %d", len(b.Levels)) } + level = min(uint8(len(b.Levels)), max(1, level)) + return b.Levels[level-1] } diff --git a/cmd/spop/config.yaml b/cmd/spop/config.yaml index 942d23a..0637cdc 100644 --- a/cmd/spop/config.yaml +++ b/cmd/spop/config.yaml @@ -3,9 +3,7 @@ secret: JMal0XJRROOMsMdPqggG2tR56CTkpgN3r47GgUN/WSQ= default: - duration: 24h type: none - - duration: 1h - type: pow - - duration: 60s + - duration: 30m type: pow frontend: diff --git a/examples/haproxy/haproxy.cfg b/examples/haproxy/haproxy.cfg index 096efac..d27974e 100644 --- a/examples/haproxy/haproxy.cfg +++ b/examples/haproxy/haproxy.cfg @@ -25,7 +25,6 @@ frontend test http-request set-var(req.berghain.level) int(1) if { sc1_http_req_rate gt 5 } http-request set-var(req.berghain.level) int(2) if { sc1_http_req_rate gt 10 } - http-request set-var(req.berghain.level) int(3) if { sc1_http_req_rate gt 15 } acl berghain_active var(req.berghain.level) -m found diff --git a/web/src/challange/challanges.js b/web/src/challange/challanges.js index e316427..483ad48 100644 --- a/web/src/challange/challanges.js +++ b/web/src/challange/challanges.js @@ -64,7 +64,9 @@ export async function challengeFingerprinting() { * @return {Promise} */ export async function challengeNone() { - return; + return new Promise((resolve) => { + setTimeout(resolve, 3000); + }); } /** diff --git a/web/src/main.js b/web/src/main.js index 1501982..49a9db1 100644 --- a/web/src/main.js +++ b/web/src/main.js @@ -13,5 +13,9 @@ import * as loader from "./challange/loader.js"; loader.start(); const result = await doChallenge() loader.stop(!!result); + + if (!result) { + setTimeout(() => {window.location.reload();}, 1000); + } }); })();