File tree Expand file tree Collapse file tree 1 file changed +25
-0
lines changed
Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change 44 "fmt"
55 "net/http"
66 "proxy-go/internal/security"
7+ "strings"
78 "time"
89
910 "github.com/woodchen-ink/go-web-utils/iputil"
@@ -21,11 +22,35 @@ func NewSecurityMiddleware(banManager *security.IPBanManager) *SecurityMiddlewar
2122 }
2223}
2324
25+ // isAdminPath 判断是否是管理后台路径
26+ func isAdminPath (path string ) bool {
27+ // 管理后台路径前缀
28+ adminPrefixes := []string {
29+ "/admin/" ,
30+ "/admin" ,
31+ }
32+
33+ for _ , prefix := range adminPrefixes {
34+ if strings .HasPrefix (path , prefix ) {
35+ return true
36+ }
37+ }
38+
39+ return false
40+ }
41+
2442// IPBanMiddleware IP封禁中间件
2543func (sm * SecurityMiddleware ) IPBanMiddleware (next http.Handler ) http.Handler {
2644 return http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
2745 clientIP := iputil .GetClientIP (r )
2846
47+ // 管理后台路径不受IP封禁限制
48+ if isAdminPath (r .URL .Path ) {
49+ // 直接放行管理后台请求
50+ next .ServeHTTP (w , r )
51+ return
52+ }
53+
2954 // 检查IP是否被封禁
3055 if sm .banManager .IsIPBanned (clientIP ) {
3156 banned , banEndTime := sm .banManager .GetBanInfo (clientIP )
You can’t perform that action at this time.
0 commit comments