File tree Expand file tree Collapse file tree 2 files changed +15
-2
lines changed
Expand file tree Collapse file tree 2 files changed +15
-2
lines changed Original file line number Diff line number Diff line change @@ -66,7 +66,7 @@ func setWebStatic(rootRouter *gin.RouterGroup) {
6666}
6767
6868func Routers () * gin.Engine {
69- Router = gin .Default ()
69+ Router = gin .New ()
7070 Router .Use (i18n .UseI18n ())
7171 Router .Use (middleware .WhiteAllow ())
7272 Router .Use (middleware .BindDomain ())
Original file line number Diff line number Diff line change @@ -2,22 +2,35 @@ package middleware
22
33import (
44 "github.com/1Panel-dev/1Panel/core/utils/common"
5+ "net"
56 "strings"
67
78 "github.com/1Panel-dev/1Panel/core/app/api/v2/helper"
89 "github.com/1Panel-dev/1Panel/core/app/repo"
910 "github.com/gin-gonic/gin"
1011)
1112
13+ func getRealClientIP (c * gin.Context ) string {
14+ addr := c .Request .RemoteAddr
15+ if ip , _ , err := net .SplitHostPort (addr ); err == nil {
16+ return ip
17+ }
18+ return addr
19+ }
20+
1221func WhiteAllow () gin.HandlerFunc {
1322 return func (c * gin.Context ) {
1423 tokenString := c .GetHeader ("X-Panel-Local-Token" )
15- clientIP := c . ClientIP ( )
24+ clientIP := getRealClientIP ( c )
1625 if clientIP == "127.0.0.1" && tokenString != "" && c .Request .URL .Path == "/api/v2/core/xpack/sync/ssl" {
1726 c .Set ("LOCAL_REQUEST" , true )
1827 c .Next ()
1928 return
2029 }
30+ if clientIP == "127.0.0.1" || clientIP == "::1" {
31+ c .Next ()
32+ return
33+ }
2134
2235 settingRepo := repo .NewISettingRepo ()
2336 status , err := settingRepo .Get (repo .WithByKey ("AllowIPs" ))
You can’t perform that action at this time.
0 commit comments