mirror of
https://github.com/aljazceru/njump.git
synced 2025-12-17 06:14:22 +01:00
we were using conflicting IP addresses from different sources. fix this.
This commit is contained in:
8
block.go
8
block.go
@@ -1,7 +1,6 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"io"
|
"io"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
@@ -25,20 +24,15 @@ func agentBlock(next http.Handler) http.Handler {
|
|||||||
|
|
||||||
func cloudflareBlock(next http.Handler) http.Handler {
|
func cloudflareBlock(next http.Handler) http.Handler {
|
||||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
ip := net.ParseIP(r.Header.Get("CF-Connecting-IP"))
|
ip := net.ParseIP(actualIP(r))
|
||||||
fmt.Println("should blopccccccccccc?", ip)
|
|
||||||
if ip != nil {
|
if ip != nil {
|
||||||
fmt.Println(" !")
|
|
||||||
for _, ipnet := range cloudflareRanges {
|
for _, ipnet := range cloudflareRanges {
|
||||||
fmt.Println(" range", ipnet)
|
|
||||||
if ipnet.Contains(ip) {
|
if ipnet.Contains(ip) {
|
||||||
fmt.Println(" match")
|
|
||||||
// cloudflare is not allowed
|
// cloudflare is not allowed
|
||||||
log.Debug().Stringer("ip", ip).Msg("cloudflare (attacker) ip blocked")
|
log.Debug().Stringer("ip", ip).Msg("cloudflare (attacker) ip blocked")
|
||||||
http.Redirect(w, r, "https://njump.me/", 302)
|
http.Redirect(w, r, "https://njump.me/", 302)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
fmt.Println(" no match")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ func loggingMiddleware(next http.Handler) http.Handler {
|
|||||||
path += "?" + r.URL.RawQuery
|
path += "?" + r.URL.RawQuery
|
||||||
}
|
}
|
||||||
log.Debug().
|
log.Debug().
|
||||||
Str("ip", r.Header.Get("X-Forwarded-For")).
|
Str("ip", actualIP(r)).
|
||||||
Str("path", path).
|
Str("path", path).
|
||||||
Str("user-agent", r.Header.Get("User-Agent")).
|
Str("user-agent", r.Header.Get("User-Agent")).
|
||||||
Str("referer", r.Header.Get("Referer")).
|
Str("referer", r.Header.Get("Referer")).
|
||||||
|
|||||||
16
ip.go
Normal file
16
ip.go
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
func actualIP(r *http.Request) string {
|
||||||
|
if cf := r.Header.Get("CF-Connecting-IP"); cf != "" {
|
||||||
|
return cf
|
||||||
|
} else if xff := r.Header.Get("X-Forwarded-For"); xff != "" {
|
||||||
|
return strings.Split(xff, ",")[0]
|
||||||
|
} else {
|
||||||
|
return r.RemoteAddr
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user