mirror of
https://github.com/aljazceru/njump.git
synced 2026-02-23 06:54:20 +01:00
block more bots.
This commit is contained in:
10
block.go
10
block.go
@@ -20,6 +20,10 @@ func agentBlock(next http.HandlerFunc) http.HandlerFunc {
|
||||
"DotBot",
|
||||
"ClaudeBot",
|
||||
"GPTBot",
|
||||
"bingbot",
|
||||
"MJ12Bot",
|
||||
"PetalBot",
|
||||
"Applebot",
|
||||
} {
|
||||
if strings.Contains(ua, bua) {
|
||||
// log.Debug().Str("ua", ua).Msg("user-agent blocked")
|
||||
@@ -34,7 +38,7 @@ func agentBlock(next http.HandlerFunc) http.HandlerFunc {
|
||||
func ipBlock(next http.HandlerFunc) http.HandlerFunc {
|
||||
ranges := make([]*net.IPNet, 0, 18)
|
||||
|
||||
for _, line := range []string{
|
||||
for _, cidr := range []string{
|
||||
// alicloud
|
||||
"47.52.0.0/16",
|
||||
"47.76.0.0/16",
|
||||
@@ -56,9 +60,9 @@ func ipBlock(next http.HandlerFunc) http.HandlerFunc {
|
||||
"172.64.0.0/13",
|
||||
"131.0.72.0/22",
|
||||
} {
|
||||
_, ipnet, err := net.ParseCIDR(strings.TrimSpace(line))
|
||||
_, ipnet, err := net.ParseCIDR(cidr)
|
||||
if err != nil {
|
||||
log.Error().Str("line", line).Err(err).Msg("failed to parse cloudflare ip range")
|
||||
log.Error().Str("cidr", cidr).Err(err).Msg("failed to parse cloudflare ip range")
|
||||
continue
|
||||
}
|
||||
ranges = append(ranges, ipnet)
|
||||
|
||||
@@ -23,6 +23,18 @@ Disallow: /
|
||||
User-agent: dotbot
|
||||
Disallow: /
|
||||
|
||||
User-agent: bingbot
|
||||
Disallow: /
|
||||
|
||||
User-agent: MJ12bot
|
||||
Disallow: /
|
||||
|
||||
User-agent: PetalBot
|
||||
Disallow: /
|
||||
|
||||
User-agent: Applebot
|
||||
Disallow: /
|
||||
|
||||
User-agent: *
|
||||
Allow: /
|
||||
|
||||
|
||||
Reference in New Issue
Block a user