mirror of
https://github.com/maxlerebourg/crowdsec-bouncer-traefik-plugin.git
synced 2026-07-21 11:38:59 +02:00
fix logic
This commit is contained in:
+6
-3
@@ -46,8 +46,8 @@ func CreateConfig() *Config {
|
|||||||
CrowdsecLapiScheme: "http",
|
CrowdsecLapiScheme: "http",
|
||||||
CrowdsecLapiHost: "crowdsec:8080",
|
CrowdsecLapiHost: "crowdsec:8080",
|
||||||
CrowdsecLapiKey: "",
|
CrowdsecLapiKey: "",
|
||||||
UpdateIntervalSeconds: 60,
|
UpdateIntervalSeconds: 10,
|
||||||
DefaultDecisionSeconds: 60,
|
DefaultDecisionSeconds: 10,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -161,6 +161,7 @@ func (a *Bouncer) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
|
|||||||
|
|
||||||
if a.crowdsecMode == "stream" || a.crowdsecMode == "live" {
|
if a.crowdsecMode == "stream" || a.crowdsecMode == "live" {
|
||||||
isBanned, err := getDecision(remoteHost)
|
isBanned, err := getDecision(remoteHost)
|
||||||
|
log.Printf("ip: %v, %v, %s", remoteHost, isBanned, err)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
if isBanned {
|
if isBanned {
|
||||||
rw.WriteHeader(http.StatusForbidden)
|
rw.WriteHeader(http.StatusForbidden)
|
||||||
@@ -218,8 +219,9 @@ func contains(source []string, target string) bool {
|
|||||||
func getDecision(clientIP string) (bool, error) {
|
func getDecision(clientIP string) (bool, error) {
|
||||||
banned, isCached := cache.Get(clientIP)
|
banned, isCached := cache.Get(clientIP)
|
||||||
bannedString, isValid := banned.(string)
|
bannedString, isValid := banned.(string)
|
||||||
|
log.Printf("ip: %v, %v, %v", bannedString == cacheBannedValue, isCached, isValid)
|
||||||
if isCached && isValid && len(bannedString) > 0 {
|
if isCached && isValid && len(bannedString) > 0 {
|
||||||
return bannedString == cacheNoBannedValue, nil
|
return bannedString == cacheBannedValue, nil
|
||||||
}
|
}
|
||||||
return false, fmt.Errorf("no cache data")
|
return false, fmt.Errorf("no cache data")
|
||||||
}
|
}
|
||||||
@@ -299,6 +301,7 @@ func handleStreamCache(a *Bouncer, initialized bool) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
for _, decision := range stream.Deleted {
|
for _, decision := range stream.Deleted {
|
||||||
|
log.Printf("ip deleted: %v", decision.Value)
|
||||||
cache.Del(decision.Value)
|
cache.Del(decision.Value)
|
||||||
}
|
}
|
||||||
a.crowdsecStreamHealthy = true
|
a.crowdsecStreamHealthy = true
|
||||||
|
|||||||
Reference in New Issue
Block a user